Example #1
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])
Example #2
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])
Example #3
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)
Example #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()
Example #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])
Example #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])
Example #7
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()
Example #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/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])
Example #9
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])
Example #10
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()
Example #11
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)