def test_load_config(self): conf = get_fixture('eapi.conf') pyeapi.client.load_config(conf) self.assertEqual(len(pyeapi.client.config.sections()), 3) for name in ['localhost', 'test1', 'test2']: name = 'connection:%s' % name self.assertIn(name, pyeapi.client.config.sections())
def test_load_config_for_connection_with_filename(self): conf = get_fixture('eapi.conf') pyeapi.client.load_config(filename=conf) cfg = pyeapi.client.config.get_connection('test1') self.assertEqual(cfg['host'], '192.168.1.16') self.assertEqual(cfg['username'], 'eapi') self.assertEqual(cfg['password'], 'password')
def test_node_returns_cached_startup_confgi(self): node = pyeapi.client.Node(None) config_file = open(get_fixture('running_config.text')) config = config_file.read() config_file.close() node._startup_config = config self.assertEqual(node.startup_config, config)
def test_node_returns_startup_config(self): node = pyeapi.client.Node(None) get_config_mock = Mock(name='get_config') config = open(get_fixture('running_config.text')).read() get_config_mock.return_value = config node.get_config = get_config_mock self.assertIsInstance(node.startup_config, str)
def test_load_config_for_connection_with_env(self): os.environ['EAPI_CONF'] = get_fixture('eapi.conf') pyeapi.client.load_config(random_string()) cfg = pyeapi.client.config.get_connection('test1') self.assertEqual(cfg['host'], '192.168.1.16') self.assertEqual(cfg['username'], 'eapi') self.assertEqual(cfg['password'], 'password')
def test_load_config_for_connection_with_filename(self): conf = get_fixture('eapi.conf') pyeapi.client.load_config(filename=conf) cfg = pyeapi.client.config.get_connection('test1') self.assertEqual(cfg['host'], '192.168.1.16') self.assertEqual(cfg['username'], 'eapi') self.assertEqual(cfg['password'], 'password') self.assertEqual(cfg['enablepwd'], 'enablepwd')
def test_load_config_for_connection_with_env(self): os.environ['EAPI_CONF'] = get_fixture('eapi.conf') pyeapi.client.load_config(random_string()) cfg = pyeapi.client.config.get_connection('test1') self.assertEqual(cfg['host'], '192.168.1.16') self.assertEqual(cfg['username'], 'eapi') self.assertEqual(cfg['password'], 'password') self.assertEqual(cfg['enablepwd'], 'enablepwd')
def setUp(self): pyeapi.client.load_config(filename=get_fixture('dut.conf')) config = pyeapi.client.config self.duts = list() for name in config.sections(): if name.startswith('connection:') and 'localhost' not in name: name = name.split(':')[1] self.duts.append(pyeapi.client.connect_to(name))
def test_connect_to_with_config(self): transport = Mock() with patch.dict(pyeapi.client.TRANSPORTS, {'https': transport}): conf = get_fixture('eapi.conf') pyeapi.client.load_config(filename=conf) pyeapi.client.connect_to('test1') kwargs = dict(host='192.168.1.16', username='******', password='******', port=None) transport.assert_called_once_with(**kwargs)
def test_node_returns_startup_config(self): node = pyeapi.client.Node(None) get_config_mock = Mock(name='get_config') config_file = open(get_fixture('running_config.text')) config = config_file.read() config_file.close() get_config_mock.return_value = config node.get_config = get_config_mock self.assertIsInstance(node.startup_config, str)
def test_connect_to_with_config(self): transport = Mock() with patch.dict(pyeapi.client.TRANSPORTS, {'https': transport}): conf = get_fixture('eapi.conf') pyeapi.client.load_config(filename=conf) node = pyeapi.client.connect_to('test1') kwargs = dict(host='192.168.1.16', username='******', password='******', port=None, key_file=None, cert_file=None, ca_file=None, timeout=60) transport.assert_called_once_with(**kwargs) self.assertEqual(node._enablepwd, 'enablepwd')
def test_connect_return_node(self): transport = Mock() with patch.dict(pyeapi.client.TRANSPORTS, {'https': transport}): conf = get_fixture('eapi.conf') pyeapi.client.load_config(filename=conf) node = pyeapi.client.connect(host='192.168.1.16', username='******', password='******', port=None, timeout=60, return_node=True) kwargs = dict(host='192.168.1.16', username='******', password='******', port=None, timeout=60) transport.assert_called_once_with(**kwargs) self.assertIsNone(node._enablepwd)
def setUp(self): pyeapi.client.load_config(filename=get_fixture('dut.conf')) config = pyeapi.client.config self.duts = list() for name in config.sections(): if name.startswith('connection:') and 'localhost' not in name: name = name.split(':')[1] dut = pyeapi.client.connect_to(name) self.duts.append(dut) if dut._enablepwd is not None: # If enable password defined for dut, set the # enable password on the dut and clear it on tearDown dut.config("enable secret %s" % dut._enablepwd)
def __init__(self, *args, **kwargs): super(TestApiIpinterfaces, self).__init__(*args, **kwargs) self.instance = pyeapi.api.ipinterfaces.instance(None) self.config = open(get_fixture('running_config.text')).read()
def __init__(self, *args, **kwargs): super(TestApiNtp, self).__init__(*args, **kwargs) self.instance = pyeapi.api.ntp.Ntp(None) self.config = open(get_fixture('running_config.text')).read()
def __init__(self, *args, **kwargs): super(TestApiBgp, self).__init__(*args, **kwargs) self.instance = pyeapi.api.bgp.instance(None) self.config = open(get_fixture('running_config.bgp')).read()
def test_config_for_replaces_host_w_name(self): conf = get_fixture('nohost.conf') pyeapi.client.load_config(conf) cfg = pyeapi.config_for('test') self.assertEqual(cfg['host'], 'test')
def __init__(self, *args, **kwargs): super(TestApiPortchannelInterface, self).__init__(*args, **kwargs) self.instance = pyeapi.api.interfaces.PortchannelInterface(None) self.config = open(get_fixture('running_config.portchannel')).read()
def __init__(self, *args, **kwargs): super(TestApiVarpInterfaces, self).__init__(*args, **kwargs) self.instance = pyeapi.api.varp.VarpInterfaces(None) self.config = open(get_fixture('running_config.varp')).read()
def test_load_config_env_path(self): os.environ['EAPI_CONF'] = get_fixture('env_path.conf') pyeapi.client.config.autoload() self.assertIn('connection:env_path', pyeapi.client.config.sections())
def get_running_config(): return get_fixture('running_config.text')
def __init__(self, *args, **kwargs): super(TestApiSwitchports, self).__init__(*args, **kwargs) self.instance = pyeapi.api.switchports.instance(None) self.config = open(get_fixture('running_config.text')).read()
def test_load_config_yaml(self): conf = get_fixture('eapi.conf.yaml') pyeapi.client.load_config(filename=conf) conns = pyeapi.client.config.connections self.assertEqual(conns, ['localhost'])
def __init__(self, *args, **kwargs): super(TestApiBgpNeighbor, self).__init__(*args, **kwargs) self.instance = pyeapi.api.bgp.BgpNeighbors(None) self.config = open(get_fixture('running_config.bgp')).read()
def setUp(self): super(TestApiPortchannelInterface, self).setUp() response = open(get_fixture('show_portchannel.json')) self.node.enable.return_value = json.load(response) response.close()
def __init__(self, *args, **kwargs): super(TestApiStandardAcls, self).__init__(*args, **kwargs) self.instance = pyeapi.api.acl.StandardAcls(None) self.config = open(get_fixture('running_config.text')).read()
def __init__(self, *args, **kwargs): super(TestApiRoutemaps, self).__init__(*args, **kwargs) self.instance = pyeapi.api.routemaps.Routemaps(None) self.config = open(get_fixture('running_config.routemaps')).read()
def test_connections_property(self): conf = get_fixture('eapi.conf') pyeapi.client.load_config(conf) connections = ['test1', 'test2', 'localhost'] result = pyeapi.client.config.connections self.assertEqual(sorted(connections), sorted(result))
def test_hosts_for_tag_returns_names(self): conf = get_fixture('eapi.conf') pyeapi.client.load_config(conf) result = pyeapi.client.hosts_for_tag('tag1') self.assertEqual(sorted(['test1', 'test2']), sorted(result))
def __init__(self, *args, **kwargs): super(TestApiStaticroute, self).__init__(*args, **kwargs) self.instance = pyeapi.api.staticroute.StaticRoute(None) self.config = open(get_fixture('running_config.text')).read()
def __init__(self, *args, **kwargs): super(TestApiVrrp, self).__init__(*args, **kwargs) self.instance = pyeapi.api.vrrp.Vrrp(None) self.config = open(get_fixture('running_config.vrrp')).read()