def test_get_node_vif_ids_two_ports(self): port1 = db_utils.create_test_port(node_id=self.node.id, address='aa:bb:cc', uuid=utils.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', uuid=utils.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_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_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_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=ironic_utils.generate_uuid(), node_id=self.node.id, address=address2) self.assertRaises(exception.MACAlreadyExists, self.dbapi.update_port, port2.id, {'address': address1})
def test_get_port_list(self): uuids = [] for i in range(1, 6): port = db_utils.create_test_port(uuid=ironic_utils.generate_uuid(), address='52:54:00:cf:2d:4%s' % i) uuids.append(six.text_type(port.uuid)) res = self.dbapi.get_port_list() res_uuids = [r.uuid for r in res] self.assertEqual(uuids.sort(), res_uuids.sort())
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 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 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)