示例#1
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])
示例#2
0
 def test_create_transport_object_missing_section(self):
     shutil.copy(
         tools.add_location('examples/config/restconf/no_section.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_debuglog()[0])
示例#3
0
 def test_update_validator_incorrect_model(self, mock_render):
     raw_b_json = tools.exa_raw('invalid_i_model')
     with self.assertRaises(KeyError):
         edit_rib.update_validator(raw_b_json, self.transport)
     # Check the logs.
     self.assertTrue('Not a valid update message type\n',
                     tools.check_debuglog()[0])
     self.assertFalse(mock_render.called)
示例#4
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])
示例#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])
示例#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])
示例#7
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])
示例#8
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])
示例#9
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])
示例#10
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])
示例#11
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])
示例#12
0
 def test_rib_2withdraw(self):
     withdraw_prefixes = [
         '1.1.1.1/32', '1.1.1.2/32', '2.2.2.2/32', '3.3.3.3/32'
     ]
     edit_rib.rib_withdraw(withdraw_prefixes, edit_rib.transport)
     self.assertIn('| WITHDRAW | OK', tools.check_debuglog()[0])
示例#13
0
 def test_render_config_normal_model_eor(self, mock_announce):
     formatted_json = json.loads(tools.exa_raw('announce_eor'))
     #edit_rib.rib_announce = mock_announce
     edit_rib.render_config(formatted_json, self.transport)
     self.assertIn('EOR message\n', tools.check_debuglog()[0])
     self.assertFalse(mock_announce.called)