def test_get_node_by_port_addresses_not_found(self): node = utils.create_test_node( driver='driver', uuid=uuidutils.generate_uuid()) utils.create_test_port(uuid=uuidutils.generate_uuid(), node_id=node.id, address='aa:bb:cc:dd:ee:ff') self.assertRaisesRegexp(exception.NodeNotFound, 'was not found', self.dbapi.get_node_by_port_addresses, ['11:22:33:44:55:66'])
def test_remove_vifs_from_node(self): db_utils.create_test_port( node_id=self.node.id, address='aa:bb:cc:dd:ee:ff', internal_info={driver_common.TENANT_VIF_KEY: 'test-vif-A'}) db_utils.create_test_portgroup( node_id=self.node.id, address='dd:ee:ff:aa:bb:cc', internal_info={driver_common.TENANT_VIF_KEY: 'test-vif-B'}) with task_manager.acquire(self.context, self.node.uuid) as task: network.remove_vifs_from_node(task) with task_manager.acquire(self.context, self.node.uuid) as task: result = network.get_node_vif_ids(task) self.assertEqual({}, result['ports']) self.assertEqual({}, result['portgroups'])
def test_get_node_vif_ids_two_ports(self): port1 = db_utils.create_test_port(node_id=self.node.id, address='aa:bb:cc:dd:ee:ff', uuid=uuidutils.generate_uuid(), extra={'vif_port_id': 'test-vif-A'}, driver='fake') port2 = db_utils.create_test_port(node_id=self.node.id, address='dd:ee:ff:aa:bb:cc', uuid=uuidutils.generate_uuid(), extra={'vif_port_id': 'test-vif-B'}, driver='fake') expected = {port1.uuid: 'test-vif-A', port2.uuid: 'test-vif-B'} with task_manager.acquire(self.context, self.node.uuid) as task: result = network.get_node_vif_ids(task) self.assertEqual(expected, result)
def test_remove_vifs_from_node_failure(self, mock_unbind): db_utils.create_test_port( node_id=self.node.id, address='aa:bb:cc:dd:ee:ff', internal_info={driver_common.TENANT_VIF_KEY: 'test-vif-A'}) db_utils.create_test_portgroup( node_id=self.node.id, address='dd:ee:ff:aa:bb:cc', internal_info={driver_common.TENANT_VIF_KEY: 'test-vif-B'}) mock_unbind.side_effect = [exception.NetworkError, None] with task_manager.acquire(self.context, self.node.uuid) as task: network.remove_vifs_from_node(task) with task_manager.acquire(self.context, self.node.uuid) as task: result = network.get_node_vif_ids(task) self.assertEqual({}, result['ports']) self.assertEqual({}, result['portgroups']) self.assertEqual(2, mock_unbind.call_count)
def setUp(self): # This method creates a port for every test and # replaces a test for creating a port. super(DbPortTestCase, self).setUp() self.node = db_utils.create_test_node() self.portgroup = db_utils.create_test_portgroup(node_id=self.node.id) self.port = db_utils.create_test_port(node_id=self.node.id, portgroup_id=self.portgroup.id)
def test_ports_get_destroyed_after_destroying_a_node_by_uuid(self): node = utils.create_test_node() port = utils.create_test_port(node_id=node.id) self.dbapi.destroy_node(node.uuid) self.assertRaises(exception.PortNotFound, self.dbapi.get_port_by_id, port.id)
def test_update_port_duplicated_address(self): address1 = self.port.address address2 = 'aa-bb-cc-11-22-33' port2 = db_utils.create_test_port(uuid=uuidutils.generate_uuid(), node_id=self.node.id, address=address2) self.assertRaises(exception.MACAlreadyExists, self.dbapi.update_port, port2.id, {'address': address1})
def test_get_node_vif_ids_two_ports(self): port1 = db_utils.create_test_port( node_id=self.node.id, address="aa:bb:cc:dd:ee:ff", uuid=uuidutils.generate_uuid(), extra={"vif_port_id": "test-vif-A"}, driver="fake", ) port2 = db_utils.create_test_port( node_id=self.node.id, address="dd:ee:ff:aa:bb:cc", uuid=uuidutils.generate_uuid(), extra={"vif_port_id": "test-vif-B"}, driver="fake", ) expected = {"portgroups": {}, "ports": {port1.uuid: "test-vif-A", port2.uuid: "test-vif-B"}} with task_manager.acquire(self.context, self.node.uuid) as task: result = network.get_node_vif_ids(task) self.assertEqual(expected, result)
def test_get_node_by_port_addresses_multiple_found(self): node1 = utils.create_test_node( driver='driver', uuid=uuidutils.generate_uuid()) node2 = utils.create_test_node( driver='driver', uuid=uuidutils.generate_uuid()) addresses = ['52:54:00:cf:2d:4%s' % i for i in (1, 2)] utils.create_test_port(uuid=uuidutils.generate_uuid(), node_id=node1.id, address=addresses[0]) utils.create_test_port(uuid=uuidutils.generate_uuid(), node_id=node2.id, address=addresses[1]) self.assertRaisesRegexp(exception.NodeNotFound, 'Multiple nodes', self.dbapi.get_node_by_port_addresses, addresses)
def test_get_port_list(self): uuids = [] for i in range(1, 6): port = db_utils.create_test_port(uuid=uuidutils.generate_uuid(), address='52:54:00:cf:2d:4%s' % i) uuids.append(six.text_type(port.uuid)) # Also add the uuid for the port created in setUp() uuids.append(six.text_type(self.port.uuid)) res = self.dbapi.get_port_list() res_uuids = [r.uuid for r in res] six.assertCountEqual(self, uuids, res_uuids)
def setUp(self): super(TestMigrateVifPortId, self).setUp() self.vif_id = 'some_uuid' self.db_ports = [] extra = {'vif_port_id': self.vif_id} for i in range(3): port = db_utils.create_test_port(uuid=uuidutils.generate_uuid(), address='52:54:00:cf:2d:3%s' % i, extra=extra, version='1.7') self.db_ports.append(port)
def _test_get_node_vif_ids_multitenancy(self, int_info_key): port = db_utils.create_test_port( node_id=self.node.id, address="aa:bb:cc:dd:ee:ff", internal_info={int_info_key: "test-vif-A"} ) portgroup = db_utils.create_test_portgroup( node_id=self.node.id, address="dd:ee:ff:aa:bb:cc", internal_info={int_info_key: "test-vif-B"} ) expected = {"ports": {port.uuid: "test-vif-A"}, "portgroups": {portgroup.uuid: "test-vif-B"}} with task_manager.acquire(self.context, self.node.uuid) as task: result = network.get_node_vif_ids(task) self.assertEqual(expected, result)
def test_get_node_by_port_addresses(self): wrong_node = utils.create_test_node(driver='driver-one', uuid=uuidutils.generate_uuid()) node = utils.create_test_node(driver='driver-two', uuid=uuidutils.generate_uuid()) addresses = [] for i in (1, 2, 3): address = '52:54:00:cf:2d:4%s' % i utils.create_test_port(uuid=uuidutils.generate_uuid(), node_id=node.id, address=address) if i > 1: addresses.append(address) utils.create_test_port(uuid=uuidutils.generate_uuid(), node_id=wrong_node.id, address='aa:bb:cc:dd:ee:ff') res = self.dbapi.get_node_by_port_addresses(addresses) self.assertEqual(node.uuid, res.uuid) self.assertEqual([], res.traits)
def test_get_node_by_port_addresses(self): wrong_node = utils.create_test_node( driver='driver-one', uuid=uuidutils.generate_uuid()) node = utils.create_test_node( driver='driver-two', uuid=uuidutils.generate_uuid()) addresses = [] for i in (1, 2, 3): address = '52:54:00:cf:2d:4%s' % i utils.create_test_port(uuid=uuidutils.generate_uuid(), node_id=node.id, address=address) if i > 1: addresses.append(address) utils.create_test_port(uuid=uuidutils.generate_uuid(), node_id=wrong_node.id, address='aa:bb:cc:dd:ee:ff') res = self.dbapi.get_node_by_port_addresses(addresses) self.assertEqual(node.uuid, res.uuid)
def setUp(self): super(TestMigrateVifPortId, self).setUp() self.vif_id = 'some_uuid' self.db_ports = [] extra = {'vif_port_id': self.vif_id} for i in range(3): port = db_utils.create_test_port( uuid=uuidutils.generate_uuid(), address='52:54:00:cf:2d:3%s' % i, extra=extra, version='1.7') self.db_ports.append(port)
def _test_get_node_vif_ids_two_ports(self, key): if key == "extra": kwargs1 = {key: {'vif_port_id': 'test-vif-A'}} kwargs2 = {key: {'vif_port_id': 'test-vif-B'}} else: kwargs1 = {key: {'tenant_vif_port_id': 'test-vif-A'}} kwargs2 = {key: {'tenant_vif_port_id': 'test-vif-B'}} port1 = db_utils.create_test_port(node_id=self.node.id, address='aa:bb:cc:dd:ee:ff', uuid=uuidutils.generate_uuid(), **kwargs1) port2 = db_utils.create_test_port(node_id=self.node.id, address='dd:ee:ff:aa:bb:cc', uuid=uuidutils.generate_uuid(), **kwargs2) expected = {'portgroups': {}, 'ports': {port1.uuid: 'test-vif-A', port2.uuid: 'test-vif-B'}} with task_manager.acquire(self.context, self.node.uuid) as task: result = network.get_node_vif_ids(task) self.assertEqual(expected, result)
def test_validate_oneview_resources_compatibility( self, mock_spt_mac_type, mock_port_mac_sh, mock_enclosure, mock_sh_type, mock_sp_template, mock_hponeview): """Validate compatibility of resources. 1) Check _validate_node_server_profile_template method is called 2) Check _validate_node_server_hardware_type method is called 3) Check _validate_node_enclosure_group method is called 4) Check _validate_node_port_mac_server_hardware method is called 5) Check _validate_server_profile_template_mac_type method is called """ oneview_client = mock_hponeview() fake_port = db_utils.create_test_port() fake_port.address = 'AA:BB:CC:DD:EE' fake_device = { 'physicalPorts': [{ 'type': 'Ethernet', 'virtualPorts': [{ 'portFunction': 'a', 'mac': 'AA:BB:CC:DD:EE' }] }] } fake_spt = { 'serverHardwareTypeUri': 'fake_sht_uri', 'enclosureGroupUri': 'fake_eg_uri', 'macType': 'Physical', 'boot': { 'manageBoot': True } } fake_sh = { 'serverHardwareTypeUri': 'fake_sht_uri', 'serverGroupUri': 'fake_eg_uri', 'processorCoreCount': 4, 'processorCount': 2, 'memoryMb': 4096, 'portMap': { 'deviceSlots': [fake_device] } } oneview_client.server_profile_templates.get.return_value = fake_spt oneview_client.server_hardware.get.return_value = fake_sh with task_manager.acquire(self.context, self.node.uuid) as task: task.ports = [fake_port] common.validate_oneview_resources_compatibility(task) self.assertTrue(mock_sp_template.called) self.assertTrue(mock_sh_type.called) self.assertTrue(mock_enclosure.called) self.assertTrue(mock_port_mac_sh.called) self.assertTrue(mock_spt_mac_type.called)
def test_get_node_vif_ids_during_cleaning(self): port = db_utils.create_test_port( node_id=self.node.id, address='aa:bb:cc:dd:ee:ff', internal_info={'cleaning_vif_port_id': 'test-vif-A'}) portgroup = db_utils.create_test_portgroup( node_id=self.node.id, address='dd:ee:ff:aa:bb:cc', internal_info={'cleaning_vif_port_id': 'test-vif-B'}) expected = {'portgroups': {portgroup.uuid: 'test-vif-B'}, 'ports': {port.uuid: 'test-vif-A'}} with task_manager.acquire(self.context, self.node.uuid) as task: result = network.get_node_vif_ids(task) self.assertEqual(expected, result)
def _test_get_node_vif_ids_multitenancy(self, int_info_key): port = db_utils.create_test_port( node_id=self.node.id, address='aa:bb:cc:dd:ee:ff', internal_info={int_info_key: 'test-vif-A'}) portgroup = db_utils.create_test_portgroup( node_id=self.node.id, address='dd:ee:ff:aa:bb:cc', internal_info={int_info_key: 'test-vif-B'}) expected = {'ports': {port.uuid: 'test-vif-A'}, 'portgroups': {portgroup.uuid: 'test-vif-B'}} with task_manager.acquire(self.context, self.node.uuid) as task: result = network.get_node_vif_ids(task) self.assertEqual(expected, result)
def test_get_node_vif_ids_two_ports(self): port1 = db_utils.create_test_port(node_id=self.node.id, address='aa:bb:cc:dd:ee:ff', uuid=uuidutils.generate_uuid(), extra={'vif_port_id': 'test-vif-A'}, driver='fake') port2 = db_utils.create_test_port(node_id=self.node.id, address='dd:ee:ff:aa:bb:cc', uuid=uuidutils.generate_uuid(), extra={'vif_port_id': 'test-vif-B'}, driver='fake') expected = { 'portgroups': {}, 'ports': { port1.uuid: 'test-vif-A', port2.uuid: 'test-vif-B' } } with task_manager.acquire(self.context, self.node.uuid) as task: result = network.get_node_vif_ids(task) self.assertEqual(expected, result)
def test_save_after_refresh(self): # Ensure that it's possible to do object.save() after object.refresh() address = "b2:54:00:cf:2d:40" db_node = db_utils.create_test_node() db_port = db_utils.create_test_port(node_id=db_node.id) p = objects.Port.get_by_uuid(self.context, db_port.uuid) p_copy = objects.Port.get_by_uuid(self.context, db_port.uuid) p.address = address p.save() p_copy.refresh() p_copy.address = 'aa:bb:cc:dd:ee:ff' # Ensure this passes and an exception is not generated p_copy.save()
def test_get_port_list_filter_by_node_project(self): lessee_node = db_utils.create_test_node(uuid=uuidutils.generate_uuid(), lessee=self.node.owner) uuids = [] for i in range(1, 3): port = db_utils.create_test_port(uuid=uuidutils.generate_uuid(), node_id=lessee_node.id, address='52:54:00:cf:2d:4%s' % i) uuids.append(str(port.uuid)) for i in range(4, 6): port = db_utils.create_test_port(uuid=uuidutils.generate_uuid(), address='52:54:00:cf:2d:4%s' % i) for i in range(7, 9): port = db_utils.create_test_port(uuid=uuidutils.generate_uuid(), node_id=self.node.id, address='52:54:00:cf:2d:4%s' % i) uuids.append(str(port.uuid)) # Also add the uuid for the port created in setUp() uuids.append(str(self.port.uuid)) res = self.dbapi.get_port_list(project=self.node.owner) res_uuids = [r.uuid for r in res] self.assertCountEqual(uuids, res_uuids)
def test_get_port_list_sorted(self): uuids = [] for i in range(1, 6): port = db_utils.create_test_port(uuid=uuidutils.generate_uuid(), address='52:54:00:cf:2d:4%s' % i) uuids.append(six.text_type(port.uuid)) # Also add the uuid for the port created in setUp() uuids.append(six.text_type(self.port.uuid)) res = self.dbapi.get_port_list(sort_key='uuid') res_uuids = [r.uuid for r in res] self.assertEqual(sorted(uuids), res_uuids) self.assertRaises(exception.InvalidParameterValue, self.dbapi.get_port_list, sort_key='foo')
def test_get_port_list_sorted(self): uuids = [] for i in range(1, 6): port = db_utils.create_test_port(uuid=uuidutils.generate_uuid(), address='52:54:00:cf:2d:4%s' % i) uuids.append(str(port.uuid)) # Also add the uuid for the port created in setUp() uuids.append(str(self.port.uuid)) res = self.dbapi.get_port_list(sort_key='uuid') res_uuids = [r.uuid for r in res] self.assertEqual(sorted(uuids), res_uuids) self.assertRaises(exception.InvalidParameterValue, self.dbapi.get_port_list, sort_key='foo')
def test__validate_node_port_mac_server_hardware_invalid( self, mock_hponeview): oneview_client = mock_hponeview() fake_device = { 'physicalPorts': [ {'type': 'notEthernet', 'mac': '00:11:22:33:44', 'virtualPorts': [{ 'portFunction': 'a', 'mac': 'AA:BB:CC:DD:EE'}]}, {'type': 'Ethernet', 'mac': '11:22:33:44:55', 'virtualPorts': [{ 'portFunction': 'a', 'mac': 'BB:CC:DD:EE:FF'}]}]} fake_sh = {'portMap': {'deviceSlots': [fake_device]}} fake_port = db_utils.create_test_port(address='AA:BB:CC:DD:EE') oneview_client.server_hardware.get.return_value = fake_sh oneview_info = db_utils.get_test_oneview_driver_info() self.assertRaises(exception.OneViewError, common._validate_node_port_mac_server_hardware, oneview_client, oneview_info, [fake_port])
def test_destroy_portgroup_not_empty(self): self.port = db_utils.create_test_port(node_id=self.node.id, portgroup_id=self.portgroup.id) self.assertRaises(exception.PortgroupNotEmpty, self.dbapi.destroy_portgroup, self.portgroup.id)
def setUp(self): # This method creates a port for every test and # replaces a test for creating a port. super(DbPortTestCase, self).setUp() self.node = db_utils.create_test_node() self.port = db_utils.create_test_port(node_id=self.node.id)
def _create_test_data(self): allocated_node_id = 31 fake_db_allocation = db_utils.create_test_allocation( node_id=allocated_node_id, resource_class="CUSTOM_TEST") fake_db_node = db_utils.create_test_node( chassis_id=None, driver='fake-driverz', owner='z') fake_db_node_alloced = db_utils.create_test_node( id=allocated_node_id, chassis_id=None, allocation_id=fake_db_allocation['id'], uuid='22e26c0b-03f2-4d2e-ae87-c02d7f33c000', driver='fake-driverz', owner='z') fake_vif_port_id = "ee21d58f-5de2-4956-85ff-33935ea1ca00" fake_db_port = db_utils.create_test_port( node_id=fake_db_node['id'], internal_info={'tenant_vif_port_id': fake_vif_port_id}) fake_db_portgroup = db_utils.create_test_portgroup( uuid="6eb02b44-18a3-4659-8c0b-8d2802581ae4", node_id=fake_db_node['id']) fake_db_chassis = db_utils.create_test_chassis( drivers=['fake-hardware', 'fake-driverz', 'fake-driver']) fake_db_deploy_template = db_utils.create_test_deploy_template() fake_db_conductor = db_utils.create_test_conductor() fake_db_volume_target = db_utils.create_test_volume_target( node_id=fake_db_allocation['id']) fake_db_volume_connector = db_utils.create_test_volume_connector( node_id=fake_db_allocation['id']) # Trait name aligns with create_test_node_trait. fake_trait = 'trait' fake_setting = 'FAKE_SETTING' db_utils.create_test_bios_setting( node_id=fake_db_node['id'], name=fake_setting, value=fake_setting) db_utils.create_test_node_trait( node_id=fake_db_node['id']) # dedicated node for portgroup addition test to avoid # false positives with test runners. db_utils.create_test_node( uuid='18a552fb-dcd2-43bf-9302-e4c93287be11') self.format_data.update({ 'node_ident': fake_db_node['uuid'], 'allocated_node_ident': fake_db_node_alloced['uuid'], 'port_ident': fake_db_port['uuid'], 'portgroup_ident': fake_db_portgroup['uuid'], 'chassis_ident': fake_db_chassis['uuid'], 'deploy_template_ident': fake_db_deploy_template['uuid'], 'allocation_ident': fake_db_allocation['uuid'], 'conductor_ident': fake_db_conductor['hostname'], 'vif_ident': fake_vif_port_id, # Can't use the same fake-driver as other tests can # pollute a global method cache in the API that is in the # test runner, resulting in false positives. 'driver_name': 'fake-driverz', 'bios_setting': fake_setting, 'trait': fake_trait, 'volume_target_ident': fake_db_volume_target['uuid'], 'volume_connector_ident': fake_db_volume_connector['uuid'], })
def _create_test_data(self): owner_node_ident = '1ab63b9e-66d7-4cd7-8618-dddd0f9f7881' lessee_node_ident = '38d5abed-c585-4fce-a57e-a2ffc2a2ec6f' owner_project_id = '70e5e25a-2ca2-4cb1-8ae8-7d8739cee205' lessee_project_id = 'f11853c7-fa9c-4db3-a477-c9d8e0dbbf13' unowned_node = db_utils.create_test_node(chassis_id=None) # owned node - since the tests use the same node for # owner/lesse checks owned_node = db_utils.create_test_node( uuid=owner_node_ident, owner=owner_project_id, last_error='meow', reservation='lolcats') owned_node_port = db_utils.create_test_port( uuid='ebe30f19-358d-41e1-8d28-fd7357a0164c', node_id=owned_node['id'], address='00:00:00:00:00:01') db_utils.create_test_port( uuid='21a3c5a7-1e14-44dc-a9dd-0c84d5477a57', node_id=owned_node['id'], address='00:00:00:00:00:02') owner_pgroup = db_utils.create_test_portgroup( uuid='b16efcf3-2990-41a1-bc1d-5e2c16f3d5fc', node_id=owned_node['id'], name='magicfoo', address='01:03:09:ff:01:01') db_utils.create_test_volume_target( uuid='a265e2f0-e97f-4177-b1c0-8298add53086', node_id=owned_node['id']) db_utils.create_test_volume_connector( uuid='65ea0296-219b-4635-b0c8-a6e055da878d', node_id=owned_node['id'], connector_id='iqn.2012-06.org.openstack.magic') fake_owner_allocation = db_utils.create_test_allocation( node_id=owned_node['id'], owner=owner_project_id, resource_class="CUSTOM_TEST") # Leased nodes fake_allocation_id = 61 leased_node = db_utils.create_test_node( allocation_id=fake_allocation_id, uuid=lessee_node_ident, owner=owner_project_id, lessee=lessee_project_id, last_error='meow', reservation='lolcats') fake_db_volume_target = db_utils.create_test_volume_target( node_id=leased_node['id']) fake_db_volume_connector = db_utils.create_test_volume_connector( node_id=leased_node['id']) fake_db_port = db_utils.create_test_port( node_id=leased_node['id']) fake_db_portgroup = db_utils.create_test_portgroup( node_id=leased_node['id']) fake_trait = 'CUSTOM_MEOW' fake_vif_port_id = "0e21d58f-5de2-4956-85ff-33935ea1ca01" fake_leased_allocation = db_utils.create_test_allocation( id=fake_allocation_id, node_id=leased_node['id'], owner=lessee_project_id, resource_class="CUSTOM_LEASED") # Random objects that shouldn't be project visible other_port = db_utils.create_test_port( uuid='abfd8dbb-1732-449a-b760-2224035c6b99', address='00:00:00:00:00:ff') other_node = db_utils.create_test_node( uuid='573208e5-cd41-4e26-8f06-ef44022b3793') other_pgroup = db_utils.create_test_portgroup( uuid='5810f41c-6585-41fc-b9c9-a94f50d421b5', node_id=other_node['id'], name='corgis_rule_the_world', address='ff:ff:ff:ff:ff:0f') self.format_data.update({ 'node_ident': unowned_node['uuid'], 'owner_node_ident': owner_node_ident, 'lessee_node_ident': lessee_node_ident, 'allocated_node_ident': lessee_node_ident, 'volume_target_ident': fake_db_volume_target['uuid'], 'volume_connector_ident': fake_db_volume_connector['uuid'], 'lessee_port_ident': fake_db_port['uuid'], 'lessee_portgroup_ident': fake_db_portgroup['uuid'], 'trait': fake_trait, 'vif_ident': fake_vif_port_id, 'ind_component': 'component', 'ind_ident': 'magic_light', 'owner_port_ident': owned_node_port['uuid'], 'other_port_ident': other_port['uuid'], 'owner_portgroup_ident': owner_pgroup['uuid'], 'other_portgroup_ident': other_pgroup['uuid'], 'driver_name': 'fake-driverz', 'owner_allocation': fake_owner_allocation['uuid'], 'lessee_allocation': fake_leased_allocation['uuid']})