summaryrefslogtreecommitdiff
path: root/nova/tests/unit/objects
diff options
context:
space:
mode:
authorStephen Finucane <sfinucan@redhat.com>2020-01-23 16:35:00 +0000
committerStephen Finucane <sfinucan@redhat.com>2020-02-18 13:19:43 +0000
commit998475f5bdb1fa1473716d93a60999c66f88dc68 (patch)
tree10092c4214fdf989093362e78e5ecbd93230e8f6 /nova/tests/unit/objects
parent25b7cf23017d83805bf5f2b2626d24323c1f7023 (diff)
downloadnova-998475f5bdb1fa1473716d93a60999c66f88dc68.tar.gz
nova-net: Remove unused nova-network objects
With the removal of the related quotas, the 'FixedIP', 'FloatingIP', 'SecurityGroupRule', 'Network' and 'NetworkList' objects can all be deleted. As noted previously, the 'SecurityGroup' object must be retained until we bump the 'Instance' object version to v3 and drop the 'security_group' field. In addition, we need to make a small change to the object versioning test to ensure we're only testing objects in the nova namespace. If we don't do this, we end up pulling in things like os_vif objects. This was previously noted in change Ica9f217d0318fc7c2db4bcdea12d00aad749c30c. Change-Id: I6aba959eff1e50af4ac040148c7177f235a09a1f Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
Diffstat (limited to 'nova/tests/unit/objects')
-rw-r--r--nova/tests/unit/objects/test_fixed_ip.py382
-rw-r--r--nova/tests/unit/objects/test_floating_ip.py289
-rw-r--r--nova/tests/unit/objects/test_network.py239
-rw-r--r--nova/tests/unit/objects/test_objects.py11
-rw-r--r--nova/tests/unit/objects/test_security_group_rule.py126
5 files changed, 1 insertions, 1046 deletions
diff --git a/nova/tests/unit/objects/test_fixed_ip.py b/nova/tests/unit/objects/test_fixed_ip.py
deleted file mode 100644
index aa0dacf071..0000000000
--- a/nova/tests/unit/objects/test_fixed_ip.py
+++ /dev/null
@@ -1,382 +0,0 @@
-# Copyright 2014 Red Hat, Inc.
-#
-# Licensed under the Apache License, Version 2.0 (the "License"); you may
-# not use this file except in compliance with the License. You may obtain
-# a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-# License for the specific language governing permissions and limitations
-# under the License.
-
-import datetime
-
-import iso8601
-import mock
-import netaddr
-from oslo_utils.fixture import uuidsentinel as uuids
-from oslo_utils import timeutils
-from oslo_versionedobjects import base as ovo_base
-
-from nova import exception
-from nova.objects import fixed_ip
-from nova.objects import instance as instance_obj
-from nova.tests.unit import fake_instance
-from nova.tests.unit.objects import test_network
-from nova.tests.unit.objects import test_objects
-from nova import utils
-
-fake_fixed_ip = {
- 'created_at': None,
- 'updated_at': None,
- 'deleted_at': None,
- 'deleted': False,
- 'id': 123,
- 'address': '192.168.1.100',
- 'network_id': None,
- 'virtual_interface_id': None,
- 'instance_uuid': None,
- 'allocated': False,
- 'leased': False,
- 'reserved': False,
- 'host': None,
- 'network': None,
- 'virtual_interface': None,
- 'floating_ips': [],
- }
-
-
-class _TestFixedIPObject(object):
- def _compare(self, obj, db_obj):
- for field in obj.fields:
- if field in ('default_route', 'floating_ips'):
- continue
- if field in fixed_ip.FIXED_IP_OPTIONAL_ATTRS:
- if obj.obj_attr_is_set(field) and db_obj[field] is not None:
- obj_val = obj[field].uuid
- db_val = db_obj[field]['uuid']
- else:
- continue
- else:
- obj_val = obj[field]
- db_val = db_obj[field]
- if isinstance(obj_val, netaddr.IPAddress):
- obj_val = str(obj_val)
- self.assertEqual(db_val, obj_val)
-
- @mock.patch('nova.db.api.fixed_ip_get')
- def test_get_by_id(self, get):
- get.return_value = fake_fixed_ip
- fixedip = fixed_ip.FixedIP.get_by_id(self.context, 123)
- get.assert_called_once_with(self.context, 123, get_network=False)
- self._compare(fixedip, fake_fixed_ip)
-
- @mock.patch('nova.db.api.fixed_ip_get')
- @mock.patch('nova.db.api.network_get')
- def test_get_by_id_with_extras(self, network_get, fixed_get):
- db_fixed = dict(fake_fixed_ip,
- network=test_network.fake_network)
- fixed_get.return_value = db_fixed
- fixedip = fixed_ip.FixedIP.get_by_id(self.context, 123,
- expected_attrs=['network'])
- fixed_get.assert_called_once_with(self.context, 123, get_network=True)
- self._compare(fixedip, db_fixed)
- self.assertEqual(db_fixed['network']['uuid'], fixedip.network.uuid)
- self.assertFalse(network_get.called)
-
- @mock.patch('nova.db.api.fixed_ip_get_by_address')
- def test_get_by_address(self, get):
- get.return_value = fake_fixed_ip
- fixedip = fixed_ip.FixedIP.get_by_address(self.context, '1.2.3.4')
- get.assert_called_once_with(self.context, '1.2.3.4',
- columns_to_join=[])
- self._compare(fixedip, fake_fixed_ip)
-
- @mock.patch('nova.db.api.fixed_ip_get_by_address')
- @mock.patch('nova.db.api.network_get')
- @mock.patch('nova.db.api.instance_get')
- def test_get_by_address_with_extras(self, instance_get, network_get,
- fixed_get):
- db_fixed = dict(fake_fixed_ip, network=test_network.fake_network,
- instance=fake_instance.fake_db_instance())
- fixed_get.return_value = db_fixed
- fixedip = fixed_ip.FixedIP.get_by_address(self.context, '1.2.3.4',
- expected_attrs=['network',
- 'instance'])
- fixed_get.assert_called_once_with(self.context, '1.2.3.4',
- columns_to_join=['network',
- 'instance'])
- self._compare(fixedip, db_fixed)
- self.assertEqual(db_fixed['network']['uuid'], fixedip.network.uuid)
- self.assertEqual(db_fixed['instance']['uuid'], fixedip.instance.uuid)
- self.assertFalse(network_get.called)
- self.assertFalse(instance_get.called)
-
- @mock.patch('nova.db.api.fixed_ip_get_by_address')
- @mock.patch('nova.db.api.network_get')
- @mock.patch('nova.db.api.instance_get')
- def test_get_by_address_with_extras_deleted_instance(self, instance_get,
- network_get,
- fixed_get):
- db_fixed = dict(fake_fixed_ip, network=test_network.fake_network,
- instance=None)
- fixed_get.return_value = db_fixed
- fixedip = fixed_ip.FixedIP.get_by_address(self.context, '1.2.3.4',
- expected_attrs=['network',
- 'instance'])
- fixed_get.assert_called_once_with(self.context, '1.2.3.4',
- columns_to_join=['network',
- 'instance'])
- self._compare(fixedip, db_fixed)
- self.assertEqual(db_fixed['network']['uuid'], fixedip.network.uuid)
- self.assertIsNone(fixedip.instance)
- self.assertFalse(network_get.called)
- self.assertFalse(instance_get.called)
-
- @mock.patch('nova.db.api.fixed_ip_get_by_floating_address')
- def test_get_by_floating_address(self, get):
- get.return_value = fake_fixed_ip
- fixedip = fixed_ip.FixedIP.get_by_floating_address(self.context,
- '1.2.3.4')
- get.assert_called_once_with(self.context, '1.2.3.4')
- self._compare(fixedip, fake_fixed_ip)
-
- @mock.patch('nova.db.api.fixed_ip_get_by_floating_address')
- def test_get_by_floating_address_none(self, get):
- get.return_value = None
- fixedip = fixed_ip.FixedIP.get_by_floating_address(self.context,
- '1.2.3.4')
- get.assert_called_once_with(self.context, '1.2.3.4')
- self.assertIsNone(fixedip)
-
- @mock.patch('nova.db.api.fixed_ip_get_by_network_host')
- def test_get_by_network_and_host(self, get):
- get.return_value = fake_fixed_ip
- fixedip = fixed_ip.FixedIP.get_by_network_and_host(self.context,
- 123, 'host')
- get.assert_called_once_with(self.context, 123, 'host')
- self._compare(fixedip, fake_fixed_ip)
-
- @mock.patch('nova.db.api.fixed_ip_associate')
- def test_associate(self, associate):
- associate.return_value = fake_fixed_ip
- fixedip = fixed_ip.FixedIP.associate(self.context, '1.2.3.4',
- uuids.instance)
- associate.assert_called_with(self.context, '1.2.3.4', uuids.instance,
- network_id=None, reserved=False,
- virtual_interface_id=None)
- self._compare(fixedip, fake_fixed_ip)
-
- @mock.patch('nova.db.api.fixed_ip_associate')
- def test_associate_with_vif(self, associate):
- associate.return_value = fake_fixed_ip
- fixedip = fixed_ip.FixedIP.associate(self.context, '1.2.3.4',
- uuids.instance,
- vif_id=0)
- associate.assert_called_with(self.context, '1.2.3.4',
- uuids.instance,
- network_id=None, reserved=False,
- virtual_interface_id=0)
- self._compare(fixedip, fake_fixed_ip)
-
- @mock.patch('nova.db.api.fixed_ip_associate_pool')
- def test_associate_pool(self, associate):
- associate.return_value = fake_fixed_ip
- fixedip = fixed_ip.FixedIP.associate_pool(self.context, 123,
- uuids.instance, 'host')
- associate.assert_called_with(self.context, 123,
- instance_uuid=uuids.instance,
- host='host', virtual_interface_id=None)
- self._compare(fixedip, fake_fixed_ip)
-
- @mock.patch('nova.db.api.fixed_ip_associate_pool')
- def test_associate_pool_with_vif(self, associate):
- associate.return_value = fake_fixed_ip
- fixedip = fixed_ip.FixedIP.associate_pool(self.context, 123,
- uuids.instance, 'host',
- vif_id=0)
- associate.assert_called_with(self.context, 123,
- instance_uuid=uuids.instance,
- host='host', virtual_interface_id=0)
- self._compare(fixedip, fake_fixed_ip)
-
- @mock.patch('nova.db.api.fixed_ip_disassociate')
- def test_disassociate_by_address(self, disassociate):
- fixed_ip.FixedIP.disassociate_by_address(self.context, '1.2.3.4')
- disassociate.assert_called_with(self.context, '1.2.3.4')
-
- @mock.patch('nova.db.api.fixed_ip_disassociate_all_by_timeout')
- def test_disassociate_all_by_timeout(self, disassociate):
- now = timeutils.utcnow()
- now_tz = timeutils.parse_isotime(
- utils.isotime(now)).replace(
- tzinfo=iso8601.UTC)
- disassociate.return_value = 123
- result = fixed_ip.FixedIP.disassociate_all_by_timeout(self.context,
- 'host', now)
- self.assertEqual(123, result)
- # NOTE(danms): be pedantic about timezone stuff
- args, kwargs = disassociate.call_args_list[0]
- self.assertEqual(now_tz, args[2])
- self.assertEqual((self.context, 'host'), args[:2])
- self.assertEqual({}, kwargs)
-
- @mock.patch('nova.db.api.fixed_ip_create')
- def test_create(self, create):
- create.return_value = fake_fixed_ip
- fixedip = fixed_ip.FixedIP(context=self.context, address='1.2.3.4')
- fixedip.create()
- create.assert_called_once_with(
- self.context, {'address': '1.2.3.4'})
- self._compare(fixedip, fake_fixed_ip)
-
- @mock.patch('nova.db.api.fixed_ip_update')
- def test_save(self, update):
- update.return_value = fake_fixed_ip
- fixedip = fixed_ip.FixedIP(context=self.context, address='1.2.3.4',
- instance_uuid=uuids.instance)
- self.assertRaises(exception.ObjectActionError, fixedip.save)
- fixedip.obj_reset_changes(['address'])
- fixedip.save()
- update.assert_called_once_with(self.context, '1.2.3.4',
- {'instance_uuid': uuids.instance})
-
- @mock.patch('nova.db.api.fixed_ip_disassociate')
- def test_disassociate(self, disassociate):
- fixedip = fixed_ip.FixedIP(context=self.context, address='1.2.3.4',
- instance_uuid=uuids.instance)
- fixedip.obj_reset_changes()
- fixedip.disassociate()
- disassociate.assert_called_once_with(self.context, '1.2.3.4')
- self.assertIsNone(fixedip.instance_uuid)
-
- @mock.patch('nova.db.api.fixed_ip_get_all')
- def test_get_all(self, get_all):
- get_all.return_value = [fake_fixed_ip]
- fixedips = fixed_ip.FixedIPList.get_all(self.context)
- self.assertEqual(1, len(fixedips))
- get_all.assert_called_once_with(self.context)
- self._compare(fixedips[0], fake_fixed_ip)
-
- @mock.patch('nova.db.api.fixed_ip_get_by_instance')
- def test_get_by_instance(self, get):
- get.return_value = [fake_fixed_ip]
- fixedips = fixed_ip.FixedIPList.get_by_instance_uuid(self.context,
- uuids.instance)
- self.assertEqual(1, len(fixedips))
- get.assert_called_once_with(self.context, uuids.instance)
- self._compare(fixedips[0], fake_fixed_ip)
-
- @mock.patch('nova.db.api.fixed_ip_get_by_host')
- def test_get_by_host(self, get):
- get.return_value = [fake_fixed_ip]
- fixedips = fixed_ip.FixedIPList.get_by_host(self.context, 'host')
- self.assertEqual(1, len(fixedips))
- get.assert_called_once_with(self.context, 'host')
- self._compare(fixedips[0], fake_fixed_ip)
-
- @mock.patch('nova.db.api.fixed_ips_by_virtual_interface')
- def test_get_by_virtual_interface_id(self, get):
- get.return_value = [fake_fixed_ip]
- fixedips = fixed_ip.FixedIPList.get_by_virtual_interface_id(
- self.context, 123)
- self.assertEqual(1, len(fixedips))
- get.assert_called_once_with(self.context, 123)
- self._compare(fixedips[0], fake_fixed_ip)
-
- def test_floating_ips_do_not_lazy_load(self):
- fixedip = fixed_ip.FixedIP()
- self.assertRaises(NotImplementedError, lambda: fixedip.floating_ips)
-
- @mock.patch('nova.db.api.fixed_ip_bulk_create')
- def test_bulk_create(self, bulk):
- fixed_ips = [fixed_ip.FixedIP(address='192.168.1.1'),
- fixed_ip.FixedIP(address='192.168.1.2')]
- fixed_ip.FixedIPList.bulk_create(self.context, fixed_ips)
- bulk.assert_called_once_with(self.context,
- [{'address': '192.168.1.1'},
- {'address': '192.168.1.2'}])
-
- @mock.patch('nova.db.api.network_get_associated_fixed_ips')
- def test_get_by_network(self, get):
- info = {'address': '1.2.3.4',
- 'instance_uuid': uuids.instance,
- 'network_id': 0,
- 'vif_id': 1,
- 'vif_address': 'de:ad:be:ee:f0:00',
- 'instance_hostname': 'fake-host',
- 'instance_updated': datetime.datetime(1955, 11, 5),
- 'instance_created': datetime.datetime(1955, 11, 5),
- 'allocated': True,
- 'leased': True,
- 'default_route': True,
- }
- get.return_value = [info]
- fixed_ips = fixed_ip.FixedIPList.get_by_network(
- self.context, {'id': 0}, host='fake-host')
- get.assert_called_once_with(self.context, 0, host='fake-host')
- self.assertEqual(1, len(fixed_ips))
- fip = fixed_ips[0]
- self.assertEqual('1.2.3.4', str(fip.address))
- self.assertEqual(uuids.instance, fip.instance_uuid)
- self.assertEqual(0, fip.network_id)
- self.assertEqual(1, fip.virtual_interface_id)
- self.assertTrue(fip.allocated)
- self.assertTrue(fip.leased)
- self.assertEqual(uuids.instance, fip.instance.uuid)
- self.assertEqual('fake-host', fip.instance.hostname)
- self.assertIsInstance(fip.instance.created_at, datetime.datetime)
- self.assertIsInstance(fip.instance.updated_at, datetime.datetime)
- self.assertEqual(1, fip.virtual_interface.id)
- self.assertEqual(info['vif_address'], fip.virtual_interface.address)
-
- @mock.patch('nova.db.api.network_get_associated_fixed_ips')
- def test_backport_default_route(self, mock_get):
- info = {'address': '1.2.3.4',
- 'instance_uuid': uuids.instance,
- 'network_id': 0,
- 'vif_id': 1,
- 'vif_address': 'de:ad:be:ee:f0:00',
- 'instance_hostname': 'fake-host',
- 'instance_updated': datetime.datetime(1955, 11, 5),
- 'instance_created': datetime.datetime(1955, 11, 5),
- 'allocated': True,
- 'leased': True,
- 'default_route': True,
- }
- mock_get.return_value = [info]
- fixed_ips = fixed_ip.FixedIPList.get_by_network(
- self.context, {'id': 0}, host='fake-host')
- primitive = fixed_ips[0].obj_to_primitive()
- self.assertIn('default_route', primitive['nova_object.data'])
- versions = ovo_base.obj_tree_get_versions('FixedIP')
- fixed_ips[0].obj_make_compatible_from_manifest(
- primitive['nova_object.data'],
- target_version='1.1',
- version_manifest=versions)
- self.assertNotIn('default_route', primitive['nova_object.data'])
-
- def test_get_count_by_project(self):
- instance = instance_obj.Instance(context=self.context,
- uuid=uuids.instance,
- project_id=self.context.project_id)
- instance.create()
- ip = fixed_ip.FixedIP(context=self.context,
- address='192.168.1.1',
- instance_uuid=instance.uuid)
- ip.create()
- self.assertEqual(1, fixed_ip.FixedIPList.get_count_by_project(
- self.context, self.context.project_id))
-
-
-class TestFixedIPObject(test_objects._LocalTest,
- _TestFixedIPObject):
- pass
-
-
-class TestRemoteFixedIPObject(test_objects._RemoteTest,
- _TestFixedIPObject):
- pass
diff --git a/nova/tests/unit/objects/test_floating_ip.py b/nova/tests/unit/objects/test_floating_ip.py
deleted file mode 100644
index 94291807a5..0000000000
--- a/nova/tests/unit/objects/test_floating_ip.py
+++ /dev/null
@@ -1,289 +0,0 @@
-# Copyright 2014 Red Hat, Inc.
-#
-# Licensed under the Apache License, Version 2.0 (the "License"); you may
-# not use this file except in compliance with the License. You may obtain
-# a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-# License for the specific language governing permissions and limitations
-# under the License.
-
-import mock
-import netaddr
-from oslo_versionedobjects import base as ovo_base
-
-from nova import exception
-from nova import objects
-from nova.objects import floating_ip
-from nova import test
-from nova.tests.unit.api.openstack import fakes
-from nova.tests.unit.objects import test_fixed_ip
-from nova.tests.unit.objects import test_network
-from nova.tests.unit.objects import test_objects
-
-fake_floating_ip = {
- 'created_at': None,
- 'updated_at': None,
- 'deleted_at': None,
- 'deleted': False,
- 'id': 123,
- 'address': '172.17.0.1',
- 'fixed_ip_id': None,
- 'project_id': None,
- 'host': None,
- 'auto_assigned': False,
- 'pool': None,
- 'interface': None,
- 'fixed_ip': None,
-}
-
-
-class _TestFloatingIPObject(object):
- def _compare(self, obj, db_obj):
- for field in obj.fields:
- if field in floating_ip.FLOATING_IP_OPTIONAL_ATTRS:
- if obj.obj_attr_is_set(field):
- obj_val = obj[field].id
- db_val = db_obj[field]['id']
- else:
- continue
- else:
- obj_val = obj[field]
- db_val = db_obj[field]
- if isinstance(obj_val, netaddr.IPAddress):
- obj_val = str(obj_val)
- self.assertEqual(db_val, obj_val)
-
- @mock.patch('nova.db.api.floating_ip_get')
- def test_get_by_id(self, get):
- db_floatingip = dict(fake_floating_ip,
- fixed_ip=test_fixed_ip.fake_fixed_ip)
- get.return_value = db_floatingip
- floatingip = floating_ip.FloatingIP.get_by_id(self.context, 123)
- get.assert_called_once_with(self.context, 123)
- self._compare(floatingip, db_floatingip)
-
- @mock.patch('nova.db.api.floating_ip_get_by_address')
- def test_get_by_address(self, get):
- get.return_value = fake_floating_ip
- floatingip = floating_ip.FloatingIP.get_by_address(self.context,
- '1.2.3.4')
- get.assert_called_once_with(self.context, '1.2.3.4')
- self._compare(floatingip, fake_floating_ip)
-
- @mock.patch('nova.db.api.floating_ip_get_pools')
- def test_get_pool_names(self, get):
- get.return_value = [{'name': 'a'}, {'name': 'b'}]
- self.assertEqual(['a', 'b'],
- floating_ip.FloatingIP.get_pool_names(self.context))
-
- @mock.patch('nova.db.api.floating_ip_allocate_address')
- def test_allocate_address(self, allocate):
- allocate.return_value = '1.2.3.4'
- self.assertEqual('1.2.3.4',
- floating_ip.FloatingIP.allocate_address(self.context,
- 'project',
- 'pool'))
- allocate.assert_called_with(self.context, 'project', 'pool',
- auto_assigned=False)
-
- @mock.patch('nova.db.api.floating_ip_fixed_ip_associate')
- def test_associate(self, associate):
- db_fixed = dict(test_fixed_ip.fake_fixed_ip,
- network=test_network.fake_network)
- associate.return_value = db_fixed
- floatingip = floating_ip.FloatingIP.associate(self.context,
- '172.17.0.1',
- '192.168.1.1',
- 'host')
- associate.assert_called_with(self.context, '172.17.0.1',
- '192.168.1.1', 'host')
- self.assertEqual(db_fixed['id'], floatingip.fixed_ip.id)
- self.assertEqual('172.17.0.1', str(floatingip.address))
- self.assertEqual('host', floatingip.host)
-
- @mock.patch('nova.db.api.floating_ip_deallocate')
- def test_deallocate(self, deallocate):
- floating_ip.FloatingIP.deallocate(self.context, '1.2.3.4')
- deallocate.assert_called_with(self.context, '1.2.3.4')
-
- @mock.patch('nova.db.api.floating_ip_destroy')
- def test_destroy(self, destroy):
- floating_ip.FloatingIP.destroy(self.context, '1.2.3.4')
- destroy.assert_called_with(self.context, '1.2.3.4')
-
- @mock.patch('nova.db.api.floating_ip_disassociate')
- def test_disassociate(self, disassociate):
- db_fixed = dict(test_fixed_ip.fake_fixed_ip,
- network=test_network.fake_network)
- disassociate.return_value = db_fixed
- floatingip = floating_ip.FloatingIP.disassociate(self.context,
- '1.2.3.4')
- disassociate.assert_called_with(self.context, '1.2.3.4')
- self.assertEqual(db_fixed['id'], floatingip.fixed_ip.id)
- self.assertEqual('1.2.3.4', str(floatingip.address))
-
- @mock.patch('nova.db.api.floating_ip_update')
- def test_save(self, update):
- update.return_value = fake_floating_ip
- floatingip = floating_ip.FloatingIP(context=self.context,
- id=123, address='1.2.3.4',
- host='foo')
- floatingip.obj_reset_changes(['address', 'id'])
- floatingip.save()
- self.assertEqual(set(), floatingip.obj_what_changed())
- update.assert_called_with(self.context, '1.2.3.4',
- {'host': 'foo'})
-
- def test_save_errors(self):
- floatingip = floating_ip.FloatingIP(context=self.context,
- id=123, host='foo')
- floatingip.obj_reset_changes()
- floating_ip.address = '1.2.3.4'
- self.assertRaises(exception.ObjectActionError, floatingip.save)
-
- floatingip.obj_reset_changes()
- floatingip.fixed_ip_id = 1
- self.assertRaises(exception.ObjectActionError, floatingip.save)
-
- @mock.patch('nova.db.api.floating_ip_update')
- def test_save_no_fixedip(self, update):
- update.return_value = fake_floating_ip
- floatingip = floating_ip.FloatingIP(context=self.context,
- id=123)
- floatingip.fixed_ip = objects.FixedIP(context=self.context,
- id=456)
- self.assertNotIn('fixed_ip', update.calls[1])
-
- @mock.patch('nova.db.api.floating_ip_get_all')
- def test_get_all(self, get):
- get.return_value = [fake_floating_ip]
- floatingips = floating_ip.FloatingIPList.get_all(self.context)
- self.assertEqual(1, len(floatingips))
- self._compare(floatingips[0], fake_floating_ip)
- get.assert_called_with(self.context)
-
- @mock.patch('nova.db.api.floating_ip_get_all_by_host')
- def test_get_by_host(self, get):
- get.return_value = [fake_floating_ip]
- floatingips = floating_ip.FloatingIPList.get_by_host(self.context,
- 'host')
- self.assertEqual(1, len(floatingips))
- self._compare(floatingips[0], fake_floating_ip)
- get.assert_called_with(self.context, 'host')
-
- @mock.patch('nova.db.api.floating_ip_get_all_by_project')
- def test_get_by_project(self, get):
- get.return_value = [fake_floating_ip]
- floatingips = floating_ip.FloatingIPList.get_by_project(self.context,
- 'project')
- self.assertEqual(1, len(floatingips))
- self._compare(floatingips[0], fake_floating_ip)
- get.assert_called_with(self.context, 'project')
-
- @mock.patch('nova.db.api.floating_ip_get_by_fixed_address')
- def test_get_by_fixed_address(self, get):
- get.return_value = [fake_floating_ip]
- floatingips = floating_ip.FloatingIPList.get_by_fixed_address(
- self.context, '1.2.3.4')
- self.assertEqual(1, len(floatingips))
- self._compare(floatingips[0], fake_floating_ip)
- get.assert_called_with(self.context, '1.2.3.4')
-
- @mock.patch('nova.db.api.floating_ip_get_by_fixed_ip_id')
- def test_get_by_fixed_ip_id(self, get):
- get.return_value = [fake_floating_ip]
- floatingips = floating_ip.FloatingIPList.get_by_fixed_ip_id(
- self.context, 123)
- self.assertEqual(1, len(floatingips))
- self._compare(floatingips[0], fake_floating_ip)
- get.assert_called_with(self.context, 123)
-
- @mock.patch('nova.db.api.instance_floating_address_get_all')
- def test_get_addresses_by_instance(self, get_all):
- expected = ['1.2.3.4', '4.5.6.7']
- get_all.return_value = list(expected)
- ips = floating_ip.FloatingIP.get_addresses_by_instance(
- self.context, {'uuid': '1234'})
- self.assertEqual(expected, ips)
- get_all.assert_called_once_with(self.context, '1234')
-
- def test_make_ip_info(self):
- result = objects.FloatingIPList.make_ip_info('1.2.3.4', 'pool', 'eth0')
- self.assertEqual({'address': '1.2.3.4', 'pool': 'pool',
- 'interface': 'eth0'},
- result)
-
- @mock.patch('nova.db.api.floating_ip_bulk_create')
- def test_bulk_create(self, create_mock):
- def fake_create(ctxt, ip_info, want_result=False):
- return [{'id': 1, 'address': ip['address'], 'fixed_ip_id': 1,
- 'project_id': fakes.FAKE_PROJECT_ID, 'host': 'host',
- 'auto_assigned': False, 'pool': ip['pool'],
- 'interface': ip['interface'], 'fixed_ip': None,
- 'created_at': None, 'updated_at': None,
- 'deleted_at': None, 'deleted': False}
- for ip in ip_info]
-
- create_mock.side_effect = fake_create
- ips = [objects.FloatingIPList.make_ip_info('1.1.1.1', 'pool', 'eth0'),
- objects.FloatingIPList.make_ip_info('1.1.1.2', 'loop', 'eth1')]
- result = objects.FloatingIPList.create(None, ips)
- self.assertIsNone(result)
- result = objects.FloatingIPList.create(None, ips, want_result=True)
- self.assertEqual('1.1.1.1', str(result[0].address))
- self.assertEqual('1.1.1.2', str(result[1].address))
-
- @mock.patch('nova.db.api.floating_ip_bulk_destroy')
- def test_bulk_destroy(self, destroy_mock):
- ips = [{'address': '1.2.3.4'}, {'address': '4.5.6.7'}]
- objects.FloatingIPList.destroy(None, ips)
- destroy_mock.assert_called_once_with(None, ips)
-
- def test_backport_fixedip_1_1(self):
- floating = objects.FloatingIP()
- fixed = objects.FixedIP()
- floating.fixed_ip = fixed
- versions = ovo_base.obj_tree_get_versions('FloatingIP')
- versions['FixedIP'] = '1.1'
- primitive = floating.obj_to_primitive(target_version='1.1',
- version_manifest=versions)
- self.assertEqual('1.1',
- primitive['nova_object.data']['fixed_ip']['nova_object.version'])
-
- def test_get_count_by_project(self):
- ips = [objects.FloatingIPList.make_ip_info('1.1.1.1', 'pool', 'eth0')]
- objects.FloatingIPList.create(self.context, ips)
- floating_ip.FloatingIP.allocate_address(self.context,
- self.context.project_id,
- 'pool')
- self.assertEqual(1, floating_ip.FloatingIPList.get_count_by_project(
- self.context, self.context.project_id))
-
-
-class TestFloatingIPObject(test_objects._LocalTest,
- _TestFloatingIPObject):
- pass
-
-
-class TestRemoteFloatingIPObject(test_objects._RemoteTest,
- _TestFloatingIPObject):
- pass
-
-
-class TestNeutronFloatingIPObject(test.NoDBTestCase):
- def test_create_with_uuid_id(self):
- uuid = 'fc9b4956-fd97-11e5-86aa-5e5517507c66'
- fip = objects.floating_ip.NeutronFloatingIP(id=uuid)
-
- self.assertEqual(uuid, fip.id)
-
- def test_create_with_uuid_fixed_id(self):
- uuid = 'fc9b4c3a-fd97-11e5-86aa-5e5517507c66'
- fip = objects.floating_ip.NeutronFloatingIP(fixed_ip_id=uuid)
-
- self.assertEqual(uuid, fip.fixed_ip_id)
diff --git a/nova/tests/unit/objects/test_network.py b/nova/tests/unit/objects/test_network.py
deleted file mode 100644
index 047ed0c38a..0000000000
--- a/nova/tests/unit/objects/test_network.py
+++ /dev/null
@@ -1,239 +0,0 @@
-# Copyright 2014 Red Hat, Inc.
-#
-# Licensed under the Apache License, Version 2.0 (the "License"); you may
-# not use this file except in compliance with the License. You may obtain
-# a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-# License for the specific language governing permissions and limitations
-# under the License.
-
-import mock
-import netaddr
-from oslo_utils.fixture import uuidsentinel as uuids
-
-from nova.objects import network as network_obj
-from nova.tests.unit.objects import test_objects
-
-
-fake_network = {
- 'deleted': False,
- 'created_at': None,
- 'updated_at': None,
- 'deleted_at': None,
- 'id': 1,
- 'label': 'Fake Network',
- 'injected': False,
- 'cidr': '192.168.1.0/24',
- 'cidr_v6': '1234::/64',
- 'multi_host': False,
- 'netmask': '255.255.255.0',
- 'gateway': '192.168.1.1',
- 'broadcast': '192.168.1.255',
- 'netmask_v6': 64,
- 'gateway_v6': '1234::1',
- 'bridge': 'br100',
- 'bridge_interface': 'eth0',
- 'dns1': '8.8.8.8',
- 'dns2': '8.8.4.4',
- 'vlan': None,
- 'vpn_public_address': None,
- 'vpn_public_port': None,
- 'vpn_private_address': None,
- 'dhcp_start': '192.168.1.10',
- 'rxtx_base': None,
- 'project_id': None,
- 'priority': None,
- 'host': None,
- 'uuid': uuids.network_instance,
- 'mtu': None,
- 'dhcp_server': '192.168.1.1',
- 'enable_dhcp': True,
- 'share_address': False,
-}
-
-
-class _TestNetworkObject(object):
- def _compare(self, obj, db_obj):
- for field in obj.fields:
- db_val = db_obj[field]
- obj_val = obj[field]
- if isinstance(obj_val, netaddr.IPAddress):
- obj_val = str(obj_val)
- if isinstance(obj_val, netaddr.IPNetwork):
- obj_val = str(obj_val)
- if field == 'netmask_v6':
- db_val = str(netaddr.IPNetwork('1::/%i' % db_val).netmask)
- self.assertEqual(db_val, obj_val)
-
- @mock.patch('nova.db.api.network_get')
- def test_get_by_id(self, get):
- get.return_value = fake_network
- network = network_obj.Network.get_by_id(self.context, 'foo')
- self._compare(network, fake_network)
- get.assert_called_once_with(self.context, 'foo',
- project_only='allow_none')
-
- @mock.patch('nova.db.api.network_get_by_uuid')
- def test_get_by_uuid(self, get):
- get.return_value = fake_network
- network = network_obj.Network.get_by_uuid(self.context, 'foo')
- self._compare(network, fake_network)
- get.assert_called_once_with(self.context, 'foo')
-
- @mock.patch('nova.db.api.network_get_by_cidr')
- def test_get_by_cidr(self, get):
- get.return_value = fake_network
- network = network_obj.Network.get_by_cidr(self.context,
- '192.168.1.0/24')
- self._compare(network, fake_network)
- get.assert_called_once_with(self.context, '192.168.1.0/24')
-
- @mock.patch('nova.db.api.network_update')
- @mock.patch('nova.db.api.network_set_host')
- def test_save(self, set_host, update):
- result = dict(fake_network, injected=True)
- network = network_obj.Network._from_db_object(self.context,
- network_obj.Network(),
- fake_network)
- network.obj_reset_changes()
- network.save()
- network.label = 'bar'
- update.return_value = result
- network.save()
- update.assert_called_once_with(self.context, network.id,
- {'label': 'bar'})
- self.assertFalse(set_host.called)
- self._compare(network, result)
-
- @mock.patch('nova.db.api.network_update')
- @mock.patch('nova.db.api.network_set_host')
- @mock.patch('nova.db.api.network_get')
- def test_save_with_host(self, get, set_host, update):
- result = dict(fake_network, injected=True)
- network = network_obj.Network._from_db_object(self.context,
- network_obj.Network(),
- fake_network)
- network.obj_reset_changes()
- network.host = 'foo'
- get.return_value = result
- network.save()
- set_host.assert_called_once_with(self.context, network.id, 'foo')
- self.assertFalse(update.called)
- self._compare(network, result)
-
- @mock.patch('nova.db.api.network_update')
- @mock.patch('nova.db.api.network_set_host')
- def test_save_with_host_and_other(self, set_host, update):
- result = dict(fake_network, injected=True)
- network = network_obj.Network._from_db_object(self.context,
- network_obj.Network(),
- fake_network)
- network.obj_reset_changes()
- network.host = 'foo'
- network.label = 'bar'
- update.return_value = result
- network.save()
- set_host.assert_called_once_with(self.context, network.id, 'foo')
- update.assert_called_once_with(self.context, network.id,
- {'label': 'bar'})
- self._compare(network, result)
-
- @mock.patch('nova.db.api.network_associate')
- def test_associate(self, associate):
- network_obj.Network.associate(self.context, 'project',
- network_id=123)
- associate.assert_called_once_with(self.context, 'project',
- network_id=123, force=False)
-
- @mock.patch('nova.db.api.network_disassociate')
- def test_disassociate(self, disassociate):
- network_obj.Network.disassociate(self.context, 123,
- host=True, project=True)
- disassociate.assert_called_once_with(self.context, 123, True, True)
-
- @mock.patch('nova.db.api.network_create_safe')
- def test_create(self, create):
- create.return_value = fake_network
- network = network_obj.Network(context=self.context, label='foo')
- network.create()
- create.assert_called_once_with(self.context, {'label': 'foo'})
- self._compare(network, fake_network)
-
- @mock.patch('nova.db.api.network_delete_safe')
- def test_destroy(self, delete):
- network = network_obj.Network(context=self.context, id=123)
- network.destroy()
- delete.assert_called_once_with(self.context, 123)
- self.assertTrue(network.deleted)
- self.assertNotIn('deleted', network.obj_what_changed())
-
- @mock.patch('nova.db.api.network_get_all')
- def test_get_all(self, get_all):
- get_all.return_value = [fake_network]
- networks = network_obj.NetworkList.get_all(self.context)
- self.assertEqual(1, len(networks))
- get_all.assert_called_once_with(self.context, 'allow_none')
- self._compare(networks[0], fake_network)
-
- @mock.patch('nova.db.api.network_get_all_by_uuids')
- def test_get_all_by_uuids(self, get_all):
- get_all.return_value = [fake_network]
- networks = network_obj.NetworkList.get_by_uuids(self.context,
- ['foo'])
- self.assertEqual(1, len(networks))
- get_all.assert_called_once_with(self.context, ['foo'], 'allow_none')
- self._compare(networks[0], fake_network)
-
- @mock.patch('nova.db.api.network_get_all_by_host')
- def test_get_all_by_host(self, get_all):
- get_all.return_value = [fake_network]
- networks = network_obj.NetworkList.get_by_host(self.context, 'host')
- self.assertEqual(1, len(networks))
- get_all.assert_called_once_with(self.context, 'host')
- self._compare(networks[0], fake_network)
-
- @mock.patch('nova.db.api.network_in_use_on_host')
- def test_in_use_on_host(self, in_use):
- in_use.return_value = True
- self.assertTrue(network_obj.Network.in_use_on_host(self.context,
- 123, 'foo'))
- in_use.assert_called_once_with(self.context, 123, 'foo')
-
- @mock.patch('nova.db.api.project_get_networks')
- def test_get_all_by_project(self, get_nets):
- get_nets.return_value = [fake_network]
- networks = network_obj.NetworkList.get_by_project(self.context, 123)
- self.assertEqual(1, len(networks))
- get_nets.assert_called_once_with(self.context, 123, associate=True)
- self._compare(networks[0], fake_network)
-
- def test_compat_version_1_1(self):
- network = network_obj.Network._from_db_object(self.context,
- network_obj.Network(),
- fake_network)
- primitive = network.obj_to_primitive(target_version='1.1')
- self.assertNotIn('mtu', primitive['nova_object.data'])
- self.assertNotIn('enable_dhcp', primitive['nova_object.data'])
- self.assertNotIn('dhcp_server', primitive['nova_object.data'])
- self.assertNotIn('share_address', primitive['nova_object.data'])
-
- primitive = network.obj_to_primitive(target_version='1.2')
- self.assertIn('mtu', primitive['nova_object.data'])
- self.assertIn('enable_dhcp', primitive['nova_object.data'])
- self.assertIn('dhcp_server', primitive['nova_object.data'])
- self.assertIn('share_address', primitive['nova_object.data'])
-
-
-class TestNetworkObject(test_objects._LocalTest,
- _TestNetworkObject):
- pass
-
-
-class TestRemoteNetworkObject(test_objects._RemoteTest,
- _TestNetworkObject):
- pass
diff --git a/nova/tests/unit/objects/test_objects.py b/nova/tests/unit/objects/test_objects.py
index d0191e0ffd..70f5670080 100644
--- a/nova/tests/unit/objects/test_objects.py
+++ b/nova/tests/unit/objects/test_objects.py
@@ -1056,12 +1056,8 @@ object_data = {
'DiskMetadata': '1.0-e7a0f1ccccf10d26a76b28e7492f3788',
'EC2Ids': '1.0-474ee1094c7ec16f8ce657595d8c49d9',
'EC2InstanceMapping': '1.0-a4556eb5c5e94c045fe84f49cf71644f',
- 'FixedIP': '1.14-53e1c10b539f1a82fe83b1af4720efae',
- 'FixedIPList': '1.15-07b6261cef836cb09d2d8673f68ece15',
'Flavor': '1.2-4ce99b41327bb230262e5a8f45ff0ce3',
'FlavorList': '1.1-52b5928600e7ca973aa4fc1e46f3934c',
- 'FloatingIP': '1.10-52a67d52d85eb8b3f324a5b7935a335b',
- 'FloatingIPList': '1.12-e4debd21fddb12cf40d36f737225fa9d',
'HVSpec': '1.2-de06bcec472a2f04966b855a49c46b41',
'HostMapping': '1.0-1a3390a696792a552ab7bd31a77ba9ac',
'HostMappingList': '1.1-18ac2bfb8c1eb5545bed856da58a79bc',
@@ -1103,9 +1099,7 @@ object_data = {
'NUMAPagesTopology': '1.1-edab9fa2dc43c117a38d600be54b4542',
'NUMATopology': '1.2-c63fad38be73b6afd04715c9c1b29220',
'NUMATopologyLimits': '1.1-4235c5da7a76c7e36075f0cd2f5cf922',
- 'Network': '1.2-a977ab383aa462a479b2fae8211a5dde',
'NetworkInterfaceMetadata': '1.2-6f3d480b40fe339067b1c0dd4d656716',
- 'NetworkList': '1.2-69eca910d8fa035dfecd8ba10877ee59',
'NetworkMetadata': '1.0-2cb8d21b34f87b0261d3e1d1ae5cf218',
'NetworkRequest': '1.2-af1ff2d986999fbb79377712794d82aa',
'NetworkRequestList': '1.1-15ecf022a68ddbb8c2a6739cfc9f8f5e',
@@ -1130,8 +1124,6 @@ object_data = {
'SchedulerRetries': '1.1-3c9c8b16143ebbb6ad7030e999d14cc0',
'SecurityGroup': '1.2-86d67d8d3ab0c971e1dc86e02f9524a8',
'SecurityGroupList': '1.1-c655ed13298e630f4d398152f7d08d71',
- 'SecurityGroupRule': '1.1-ae1da17b79970012e8536f88cb3c6b29',
- 'SecurityGroupRuleList': '1.2-0005c47fcd0fb78dd6d7fd32a1409f5b',
'Selection': '1.1-548e3c2f04da2a61ceaf9c4e1589f264',
'Service': '1.22-8a740459ab9bf258a19c8fcb875c2d9a',
'ServiceList': '1.19-5325bce13eebcbf22edc9678285270cc',
@@ -1221,8 +1213,7 @@ class TestObjectVersions(test.NoDBTestCase):
init_args = {}
init_kwargs = {}
- checker = fixture.ObjectVersionChecker(
- base.NovaObjectRegistry.obj_classes())
+ checker = fixture.ObjectVersionChecker(get_nova_objects())
checker.test_compatibility_routines(use_manifest=True,
init_args=init_args,
init_kwargs=init_kwargs)
diff --git a/nova/tests/unit/objects/test_security_group_rule.py b/nova/tests/unit/objects/test_security_group_rule.py
deleted file mode 100644
index 9bbe573e43..0000000000
--- a/nova/tests/unit/objects/test_security_group_rule.py
+++ /dev/null
@@ -1,126 +0,0 @@
-# Copyright 2013 Red Hat, Inc.
-#
-# Licensed under the Apache License, Version 2.0 (the "License"); you may
-# not use this file except in compliance with the License. You may obtain
-# a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-# License for the specific language governing permissions and limitations
-# under the License.
-
-import mock
-from oslo_utils.fixture import uuidsentinel as uuids
-from oslo_versionedobjects import exception as ovo_exc
-
-from nova.db import api as db
-from nova import objects
-from nova.tests.unit.objects import test_objects
-from nova.tests.unit.objects import test_security_group
-
-
-fake_rule = {
- 'created_at': None,
- 'updated_at': None,
- 'deleted_at': None,
- 'deleted': False,
- 'id': 1,
- 'protocol': 'tcp',
- 'from_port': 22,
- 'to_port': 22,
- 'cidr': '0.0.0.0/0',
- }
-
-
-class _TestSecurityGroupRuleObject(object):
- def test_get_by_id(self):
- with mock.patch.object(db, 'security_group_rule_get') as sgrg:
- sgrg.return_value = fake_rule
- rule = objects.SecurityGroupRule.get_by_id(
- self.context, 1)
- for field in fake_rule:
- if field == 'cidr':
- self.assertEqual(fake_rule[field], str(getattr(rule,
- field)))
- else:
- self.assertEqual(fake_rule[field], getattr(rule, field))
- sgrg.assert_called_with(self.context, 1)
-
- def test_get_by_security_group(self):
- secgroup = objects.SecurityGroup()
- secgroup.id = 123
- rule = dict(fake_rule)
- rule['grantee_group'] = dict(test_security_group.fake_secgroup, id=123)
- stupid_method = 'security_group_rule_get_by_security_group'
- with mock.patch.object(db, stupid_method) as sgrgbsg:
- sgrgbsg.return_value = [rule]
- rules = (objects.SecurityGroupRuleList.
- get_by_security_group(self.context, secgroup))
- self.assertEqual(1, len(rules))
- self.assertEqual(123, rules[0].grantee_group.id)
-
- @mock.patch.object(db, 'security_group_rule_create',
- return_value=fake_rule)
- def test_create(self, db_mock):
- rule = objects.SecurityGroupRule(context=self.context)
- rule.protocol = 'tcp'
- secgroup = objects.SecurityGroup()
- secgroup.id = 123
- parentgroup = objects.SecurityGroup()
- parentgroup.id = 223
- rule.grantee_group = secgroup
- rule.parent_group = parentgroup
- rule.create()
- updates = db_mock.call_args[0][1]
- self.assertEqual(fake_rule['id'], rule.id)
- self.assertEqual(updates['group_id'], rule.grantee_group.id)
- self.assertEqual(updates['parent_group_id'], rule.parent_group.id)
-
- @mock.patch.object(db, 'security_group_rule_create',
- return_value=fake_rule)
- def test_set_id_failure(self, db_mock):
- rule = objects.SecurityGroupRule(context=self.context)
- rule.create()
- self.assertRaises(ovo_exc.ReadOnlyFieldError, setattr,
- rule, 'id', 124)
-
-
-class TestSecurityGroupRuleObject(test_objects._LocalTest,
- _TestSecurityGroupRuleObject):
- pass
-
-
-class TestSecurityGroupRuleObjectRemote(test_objects._RemoteTest,
- _TestSecurityGroupRuleObject):
- pass
-
-
-fake_rules = [
- dict(fake_rule, id=1, grantee_group=test_security_group.fake_secgroup),
- dict(fake_rule, id=2, grantee_group=test_security_group.fake_secgroup),
-]
-
-
-class _TestSecurityGroupRuleListObject(object):
- @mock.patch('nova.db.api.security_group_rule_get_by_instance')
- def test_get_by_instance(self, mock_get):
- mock_get.return_value = fake_rules
- instance = objects.Instance(uuid=uuids.instance)
- rules = objects.SecurityGroupRuleList.get_by_instance(self.context,
- instance)
- mock_get.assert_called_once_with(self.context, instance.uuid)
- self.assertEqual(2, len(rules))
- self.assertEqual([1, 2], [x.id for x in rules])
-
-
-class TestSecurityGroupRuleListObject(test_objects._LocalTest,
- _TestSecurityGroupRuleListObject):
- pass
-
-
-class TestSecurityGroupRuleListObjectRemote(test_objects._RemoteTest,
- _TestSecurityGroupRuleListObject):
- pass