def _create_test_addresses(self, hostnames, subnet, network_type, start=1, stop=None): ips = itertools.islice(subnet, start, stop) for name in hostnames: dbutils.create_test_address(name=utils.format_address_name( name, network_type), family=subnet.version, prefix=subnet.prefixlen, address=str(next(ips)))
def test_bad_host_state(self): interface = dbutils.create_test_interface( ifname="test0", ifclass=constants.INTERFACE_CLASS_PLATFORM, forihostid=self.worker.id, ihost_uuid=self.worker.uuid) address = dbutils.create_test_address(interface_id=interface.id, name="enptest01", family=self.oam_subnet.version, address=str(self.oam_subnet[25]), prefix=self.oam_subnet.prefixlen) self.assertEqual(address["interface_id"], interface.id) # unlock the worker dbapi = dbutils.db_api.get_instance() worker = dbapi.ihost_update( self.worker.uuid, {"administrative": constants.ADMIN_UNLOCKED}) self.assertEqual(worker['administrative'], constants.ADMIN_UNLOCKED) response = self.delete(self.get_single_url(address.uuid), headers=self.API_HEADERS, expect_errors=True) self.assertEqual(response.content_type, 'application/json') self.assertEqual(response.status_code, http_client.INTERNAL_SERVER_ERROR) self.assertIn("administrative state = unlocked", response.json['error_message'])
def test_orphaned_routes(self): interface = dbutils.create_test_interface( ifname="test0", ifclass=constants.INTERFACE_CLASS_PLATFORM, forihostid=self.worker.id, ihost_uuid=self.worker.uuid) address = dbutils.create_test_address(interface_id=interface.id, name="enptest01", family=self.oam_subnet.version, address=str(self.oam_subnet[25]), prefix=self.oam_subnet.prefixlen) self.assertEqual(address["interface_id"], interface.id) route = dbutils.create_test_route( interface_id=interface.id, family=4, network='10.10.10.0', prefix=24, gateway=str(self.oam_subnet[1]), ) self.assertEqual(route['gateway'], str(self.oam_subnet[1])) response = self.delete(self.get_single_url(address.uuid), headers=self.API_HEADERS, expect_errors=True) self.assertEqual(response.content_type, 'application/json') self.assertEqual(response.status_code, http_client.CONFLICT) self.assertIn( "Address %s is in use by a route to %s/%d via %s" % (address["address"], route["network"], route["prefix"], route["gateway"]), response.json['error_message'])
def test_modify_ptp_transport_valid(self): # With no ptp hosts we should be able to modify ptp transport self.modify_ptp(self.transport_udp) self.modify_ptp(self.transport_l2) # If the host is locked we can set the transport to UDP self.dbapi.ihost_update(self.worker.id, {'clock_synchronization': constants.PTP}) self.modify_ptp(self.transport_udp) self.modify_ptp(self.transport_l2) # If the host is unlocked it must have a ptp interface with an IP to set to UDP self.dbapi.ihost_update(self.worker.id, {'administrative': constants.ADMIN_UNLOCKED}) interface = { 'id': 1, 'uuid': str(uuid.uuid4()), 'forihostid': self.worker.id, 'ifname': 'ptpif', 'iftype': constants.INTERFACE_TYPE_ETHERNET, 'imac': '02:11:22:33:44:11', 'uses': [], 'used_by': [], 'ifclass': constants.INTERFACE_CLASS_PLATFORM, 'ipv4_mode': 'static', 'ptp_role': constants.INTERFACE_PTP_ROLE_MASTER } dbutils.create_test_interface(**interface) address = { 'interface_id': '1', 'family': 4, 'prefix': 24, 'address': '192.168.1.2' } dbutils.create_test_address(**address) self.modify_ptp(self.transport_udp) self.modify_ptp(self.transport_l2)
def test_delete_address_with_interface(self): interface = dbutils.create_test_interface( ifname="test0", ifclass=constants.INTERFACE_CLASS_PLATFORM, forihostid=self.worker.id, ihost_uuid=self.worker.uuid) address = dbutils.create_test_address(interface_id=interface.id, name="enptest01", family=self.oam_subnet.version, address=str(self.oam_subnet[25]), prefix=self.oam_subnet.prefixlen) self.assertEqual(address["interface_id"], interface.id) response = self.delete(self.get_single_url(address.uuid), headers=self.API_HEADERS) self.assertEqual(response.status_code, http_client.NO_CONTENT)
def test_delete_address_from_pool(self): pool = dbutils.create_test_address_pool( name='testpool', network='192.168.204.0', ranges=[['192.168.204.2', '192.168.204.254']], prefix=24) address = dbutils.create_test_address(name="enptest01", family=4, address='192.168.204.4', prefix=24, address_pool_id=pool.id) self.assertEqual(address['pool_uuid'], pool.uuid) with mock.patch('sysinv.common.utils.is_initial_config_complete', lambda: True): response = self.delete(self.get_single_url(address.uuid), headers=self.API_HEADERS, expect_errors=True) self.assertEqual(response.content_type, 'application/json') self.assertEqual(response.status_code, http_client.CONFLICT) self.assertIn( "Address has been allocated from pool; " "cannot be manually deleted", response.json['error_message'])
def setUp(self): super(InterfaceNetworkTestCase, self).setUp() p = mock.patch.object(api_if_v1, '_get_lower_interface_macs') self.mock_lower_macs = p.start() self.mock_lower_macs.return_value = { 'enp0s18': '08:00:27:8a:87:48', 'enp0s19': '08:00:27:ea:93:8e' } self.addCleanup(p.stop) self.system = dbutils.create_test_isystem() self.load = dbutils.create_test_load() self.controller = dbutils.create_test_ihost( id='1', uuid=None, forisystemid=self.system.id, hostname='controller-0', personality=constants.CONTROLLER, subfunctions=constants.CONTROLLER, invprovision=constants.PROVISIONED, ) self.worker = dbutils.create_test_ihost( id='2', uuid=None, forisystemid=self.system.id, hostname='worker-0', personality=constants.WORKER, subfunctions=constants.WORKER, mgmt_mac='01:02.03.04.05.C0', mgmt_ip='192.168.24.12', invprovision=constants.PROVISIONED, ) self.address_pool_mgmt = dbutils.create_test_address_pool( id=1, network='192.168.204.0', name='management', ranges=[['192.168.204.2', '192.168.204.254']], prefix=24) self.mgmt_network = dbutils.create_test_network( id=1, name='mgmt', type=constants.NETWORK_TYPE_MGMT, link_capacity=1000, vlan_id=2, address_pool_id=self.address_pool_mgmt.id) self.address_pool_cluster_host = dbutils.create_test_address_pool( id=2, network='192.168.206.0', name='cluster-host', ranges=[['192.168.206.2', '192.168.206.254']], prefix=24) self.cluster_host_network = dbutils.create_test_network( id=2, name='cluster-host', type=constants.NETWORK_TYPE_CLUSTER_HOST, link_capacity=10000, vlan_id=3, address_pool_id=self.address_pool_cluster_host.id) self.address_pool_oam = dbutils.create_test_address_pool( id=3, network='128.224.150.0', name='oam', ranges=[['128.224.150.1', '128.224.151.254']], prefix=23) self.oam_network = dbutils.create_test_network( id=3, name='oam', type=constants.NETWORK_TYPE_OAM, address_pool_id=self.address_pool_oam.id) self.oam_address = dbutils.create_test_address( family=2, address='10.10.10.3', prefix=24, name='controller-0-oam', address_pool_id=self.address_pool_oam.id) self.address_pool_pxeboot = dbutils.create_test_address_pool( id=4, network='192.168.202.0', name='pxeboot', ranges=[['192.168.202.2', '192.168.202.254']], prefix=23) self.pxeboot_network = dbutils.create_test_network( id=4, type=constants.NETWORK_TYPE_PXEBOOT, address_pool_id=self.address_pool_pxeboot.id) self.pxeboot_address = dbutils.create_test_address( family=2, address='192.168.202.3', prefix=24, name='controller-0-pxeboot', address_pool_id=self.address_pool_pxeboot.id)