Skip to content
Snippets Groups Projects
test_junos_devices_query.py 1.26 KiB
import os
import re

import responses

import inventory_provider
from inventory_provider import juniper
from inventory_provider.tasks import data

TEST_DATA_FILENAME = os.path.realpath(os.path.join(
    inventory_provider.__path__[0],
    '..',
    'test',
    'data',
    'netdash-alldevices.txt'))


@responses.activate
def test_junosspace_devices_parsing(data_config):
    data_config['managed-routers'] = 'http://sabababa'
    with open(TEST_DATA_FILENAME) as f:
        responses.add(
            method=responses.GET,
            url=data_config['managed-routers'],
            body=f.read())

    hostnames = juniper.load_routers_from_netdash(
        data_config['managed-routers'])

    assert 'mx1.ams.nl.geant.net' in hostnames


def test_router_hostname_derivation(mocked_redis):
    """
    test result depends specifically on the test data set containing
    a realistic snapshot

    :param mocked_redis:
    :return:
    """
    config = {
        'redis': {
            'hostname': None,
            'port': None
        },
        'redis-databases': [0, 11]
    }
    hostnames = list(data.derive_router_hostnames(config))
    assert hostnames  # test data is non-empty
    for h in hostnames:
        assert re.match(r'^(rt[12]|mx[12]|qfx|srx[12])\..+\.geant\.net$', h)