Exemple #1
0
 def test_create_transport_object_correct_class_created(self):
     shutil.copy(
         tools.add_location(
             'examples/config/restconf/restconf_good.config'),
         tools.add_location('../../solenoid.config'))
     transport_object = edit_rib.create_transport_object()
     self.assertIsInstance(transport_object, edit_rib.JSONRestCalls)
Exemple #2
0
 def test_create_transport_object_missing_object(self):
     shutil.copy(tools.add_location('examples/config/grpc/no_port.config'),
                 tools.add_location('../../solenoid.config'))
     with self.assertRaises(SystemExit):
         edit_rib.create_transport_object()
     self.assertIn('Something is wrong with your config file:',
                   tools.check_errorlog()[0])
 def test_create_transport_object_no_config_file(self):
     #Remove the config file
     if os.path.isfile(tools.add_location('../../solenoid.config')):
         os.remove(tools.add_location('../../solenoid.config'))
     with self.assertRaises(SystemExit):
         edit_rib.create_transport_object()
     self.assertIn('Something is wrong with your config file:',
                   tools.check_debuglog()[0])
Exemple #4
0
 def setUp(self):
     #Set global variable
     edit_rib.FILEPATH = tools.add_location('examples/filter-empty.txt')
     edit_rib.transport = edit_rib.create_transport_object()
     #Clear out logging files.
     open(tools.add_location('../updates.txt'), 'w').close()
     open(tools.add_location('../logs/debug.log'), 'w').close()
     open(tools.add_location('../logs/errors.log'), 'w').close()
Exemple #5
0
 def test_create_transport_object_multiple_sections(self):
     shutil.copy(
         tools.add_location(
             'examples/config/restconf/multiple_sections.config'),
         tools.add_location('../../solenoid.config'))
     transport_object = edit_rib.create_transport_object()
     self.assertIsInstance(transport_object, edit_rib.JSONRestCalls)
     self.assertIn(
         'Multiple routers not currently supported in the configuration file',
         tools.check_debuglog()[0])
Exemple #6
0
 def test_rib_announce(self, mock_patch):
     shutil.copy(
         tools.add_location('examples/config/grpc/grpc_good.config'),
         tools.add_location('../../solenoid.config'))
     with open(tools.add_location('examples/rendered_announce.txt')) as f:
         rendered_announce = f.read()
     edit_rib.transport = edit_rib.create_transport_object()
     edit_rib.rib_announce(rendered_announce, edit_rib.transport)
     mock_patch.assert_called_with(rendered_announce)
     self.assertIn('| ANNOUNCE | ', tools.check_debuglog()[0])
 def test_filter_all_prefixes(self):
     edit_rib.FILEPATH = tools.add_location(
         'examples/filter/filter-all.txt')
     start_prefixes = ['2.2.2.0/32', '10.2.1.1/24']
     filtered_list = edit_rib.filter_prefixes(start_prefixes)
     end_prefixes = []
     self.assertEqual(filtered_list, end_prefixes)
 def test_render_config_announce_good(self, mock_announce):
     formatted_json = json.loads(tools.exa_raw('announce_g'))
     edit_rib.render_config(formatted_json, self.transport)
     with open(tools.add_location('examples/rendered_announce.txt'),
               'U') as f:
         rendered_announce = f.read()
     mock_announce.assert_called_with(rendered_announce, self.transport)
Exemple #9
0
 def test_rib_1announce(self):
     with open(
             tools.add_location(
                 'examples/integration/rendered_announce.txt')) as f:
         rendered_announce = f.read()
     edit_rib.rib_announce(rendered_announce, edit_rib.transport)
     self.assertIn('| ANNOUNCE | OK', tools.check_debuglog()[0])
Exemple #10
0
 def test_rib_withdraw(self, mock_delete):
     withdraw_prefixes = [
         '1.1.1.8/32', '1.1.1.5/32', '1.1.1.7/32', '1.1.1.9/32',
         '1.1.1.2/32', '1.1.1.1/32', '1.1.1.6/32', '1.1.1.3/32',
         '1.1.1.10/32', '1.1.1.4/32'
     ]
     shutil.copy(
         tools.add_location(
             'examples/config/restconf/restconf_good.config'),
         tools.add_location('../../solenoid.config'))
     transport_object = edit_rib.create_transport_object()
     edit_rib.rib_withdraw(withdraw_prefixes, transport_object)
     url = 'Cisco-IOS-XR-ip-static-cfg:router-static/default-vrf/address-family/vrfipv4/vrf-unicast/vrf-prefixes/vrf-prefix='
     comma_list = [prefix.replace('/', ',') for prefix in withdraw_prefixes]
     calls = map(call, [url + x for x in comma_list])
     mock_delete.assert_has_calls(calls, any_order=True)
     self.assertIn('| WITHDRAW | ', tools.check_debuglog()[0])
Exemple #11
0
 def test_filter_prefix_invalid(self):
     edit_rib.FILEPATH = tools.add_location(
         'examples/filter/filter-invalid.txt')
     start_prefixes = [
         '1.1.1.9/32', '192.168.3.1/28', '1.1.1.2/32', '1.1.1.1/32',
         '10.1.1.1/32', '1.1.1.10/32', '10.1.6.1/24'
     ]
     from netaddr import AddrFormatError
     with self.assertRaises(AddrFormatError):
         edit_rib.filter_prefixes(start_prefixes)
Exemple #12
0
 def test_filter_prefix_good(self):
     edit_rib.FILEPATH = tools.add_location(
         'examples/filter/filter-full.txt')
     start_prefixes = [
         '1.1.1.9/32', '192.168.3.1/28', '1.1.1.2/32', '1.1.1.1/32',
         '10.1.1.1/32', '1.1.1.10/32', '10.1.6.1/24'
     ]
     filtered_list = edit_rib.filter_prefixes(start_prefixes)
     end_prefixes = [
         '1.1.1.9/32', '1.1.1.2/32', '1.1.1.1/32', '1.1.1.10/32',
         '10.1.1.1/32', '10.1.6.1/24'
     ]
     self.assertEqual(filtered_list, end_prefixes)
Exemple #13
0
 def test_rib_withdraw(self, mock_delete):
     withdraw_prefixes = [
         '1.1.1.8/32', '1.1.1.5/32', '1.1.1.7/32', '1.1.1.9/32',
         '1.1.1.2/32', '1.1.1.1/32', '1.1.1.6/32', '1.1.1.3/32',
         '1.1.1.10/32', '1.1.1.4/32'
     ]
     shutil.copy(
         tools.add_location('examples/config/grpc/grpc_good.config'),
         tools.add_location('../../solenoid.config'))
     edit_rib.transport = edit_rib.create_transport_object()
     edit_rib.rib_withdraw(withdraw_prefixes, edit_rib.transport)
     url = '{{"Cisco-IOS-XR-ip-static-cfg:router-static": {{"default-vrf": {{"address-family": {{"vrfipv4": {{"vrf-unicast": {{"vrf-prefixes": {{"vrf-prefix": [{withdraw}]}}}}}}}}}}}}}}'
     prefix_info = '{{"prefix": "{bgp_prefix}","prefix-length": {prefix_length}}}'
     prefix_list = []
     for withdrawn_prefix in withdraw_prefixes:
         bgp_prefix, prefix_length = withdrawn_prefix.split('/')
         prefix_list += [
             prefix_info.format(bgp_prefix=bgp_prefix,
                                prefix_length=prefix_length)
         ]
         prefix_str = ', '.join(prefix_list)
     url = url.format(withdraw=prefix_str)
     mock_delete.assert_called_once_with(url)
     self.assertIn('| WITHDRAW | ', tools.check_debuglog()[0])
Exemple #14
0
 def setUp(self):
     shutil.copy(
         tools.add_location(
             'examples/config/restconf/restconf_good.config'),
         tools.add_location('../../solenoid.config'))
     self.transport = edit_rib.create_transport_object()
     #Set global variable.
     edit_rib.FILEPATH = tools.add_location(
         'examples/filter/filter-empty.txt')
     #Clear out logging files.
     open(tools.add_location('../updates.txt'), 'w').close()
     open(tools.add_location('../logs/debug.log'), 'w').close()
     open(tools.add_location('../logs/errors.log'), 'w').close()
Exemple #15
0
 def test_create_transport_object_missing_object(self):
     shutil.copy(
         tools.add_location('examples/config/restconf/no_port.config'),
         tools.add_location('../../solenoid.config'))
     with self.assertRaises(SystemExit) as cm:
         edit_rib.create_transport_object()
Exemple #16
0
 def test_render_config_prefixes_all_filtered_announce(self, mock_announce):
     edit_rib.FILEPATH = tools.add_location(
         'examples/filter/filter-all.txt')
     formatted_json = json.loads(tools.exa_raw('announce_g'))
     edit_rib.render_config(formatted_json, self.transport)
     mock_announce.assert_not_called()
Exemple #17
0
 def test_rib_5announce_EOR(self):
     with open(tools.add_location('examples/exa/exa-eor.json')) as f:
         exa_announce_eor = f.read()
     edit_rib.render_config(json.loads(exa_announce_eor),
                            edit_rib.transport)
     self.assertIn('EOR message\n', tools.check_debuglog()[0])
Exemple #18
0
 def test_rib_4withdraw_json(self):
     with open(tools.add_location(
             'examples/integration/exa-withdraw.json')) as f:
         exa_withdraw = f.read()
     edit_rib.render_config(json.loads(exa_withdraw), edit_rib.transport)
     self.assertIn('| WITHDRAW | OK', tools.check_debuglog()[0])
Exemple #19
0
 def test_rib_3announce_json(self):
     with open(tools.add_location(
             'examples/integration/exa-announce.json')) as f:
         exa_announce = f.read()
     edit_rib.render_config(json.loads(exa_announce), edit_rib.transport)
     self.assertIn('| ANNOUNCE | OK', tools.check_debuglog()[0])
Exemple #20
0
 def test_update_file(self):
     edit_rib.update_file({'Test': time.ctime()})
     with open(tools.add_location('../updates.txt')) as f:
         self.assertTrue(len(f.readlines()) == 1)
Exemple #21
0
 def test_create_transport_object_correct_class_created(self):
     shutil.copy(
         tools.add_location('examples/config/grpc/grpc_good.config'),
         tools.add_location('../../solenoid.config'))
     transport_object = edit_rib.create_transport_object()
     self.assertIsInstance(transport_object, edit_rib.CiscoGRPCClient)