diff --git a/nova/tests/unit/api/openstack/fakes.py b/nova/tests/unit/api/openstack/fakes.py index 36d628380c..74f2c4df2f 100644 --- a/nova/tests/unit/api/openstack/fakes.py +++ b/nova/tests/unit/api/openstack/fakes.py @@ -209,23 +209,15 @@ def stub_out_nw_api(test, cls=None, private=None, publics=None): if cls is None: cls = Fake - if CONF.use_neutron: - test.stub_out('nova.network.neutronv2.api.API', cls) - else: - test.stub_out('nova.network.api.API', cls) - fake_network.stub_out_nw_api_get_instance_nw_info(test) + + test.stub_out('nova.network.neutronv2.api.API', cls) def stub_out_secgroup_api(test, security_groups=None): class FakeSecurityGroupAPI(security_group_base.SecurityGroupBase): - """This handles both nova-network and neutron style security group APIs - """ def get_instances_security_groups_bindings( self, context, servers, detailed=False): - # This method shouldn't be called unless using neutron. - if not CONF.use_neutron: - raise Exception('Invalid security group API call for nova-net') instances_security_group_bindings = {} if servers: # we don't get security group information for down cells @@ -239,13 +231,9 @@ def stub_out_secgroup_api(test, security_groups=None): self, context, instance, detailed=False): return security_groups if security_groups is not None else [] - if CONF.use_neutron: - test.stub_out( - 'nova.network.security_group.neutron_driver.SecurityGroupAPI', - FakeSecurityGroupAPI) - else: - test.stub_out( - 'nova.compute.api.SecurityGroupAPI', FakeSecurityGroupAPI) + test.stub_out( + 'nova.network.security_group.neutron_driver.SecurityGroupAPI', + FakeSecurityGroupAPI) class FakeToken(object): diff --git a/nova/tests/unit/compute/test_compute.py b/nova/tests/unit/compute/test_compute.py index fab17e92de..fac031af4d 100644 --- a/nova/tests/unit/compute/test_compute.py +++ b/nova/tests/unit/compute/test_compute.py @@ -240,25 +240,13 @@ class BaseTestCase(test.TestCase): def fake_get_nw_info(cls, ctxt, instance, *args, **kwargs): return network_model.NetworkInfo() - if CONF.use_neutron: - self.stub_out( - 'nova.network.neutronv2.api.API.get_instance_nw_info', - fake_get_nw_info) - self.stub_out( - 'nova.network.neutronv2.api.API.migrate_instance_start', - lambda *args, **kwargs: None) - self.useFixture(fixtures.NeutronFixture(self)) - else: - self.stub_out('nova.network.api.API.get_instance_nw_info', - fake_get_nw_info) - - def fake_allocate_for_instance(cls, ctxt, instance, - *args, **kwargs): - self.assertFalse(ctxt.is_admin) - return fake_network.fake_get_instance_nw_info(self, 1, 1) - - self.stub_out('nova.network.api.API.allocate_for_instance', - fake_allocate_for_instance) + self.stub_out( + 'nova.network.neutronv2.api.API.get_instance_nw_info', + fake_get_nw_info) + self.stub_out( + 'nova.network.neutronv2.api.API.migrate_instance_start', + lambda *args, **kwargs: None) + self.useFixture(fixtures.NeutronFixture(self)) self.compute_api = compute.API() @@ -1704,9 +1692,6 @@ class ComputeTestCase(BaseTestCase, self.assertEqual(17152, cn.local_gb_used) def test_create_multiple_instance_with_neutron_port(self): - def fake_is_neutron(): - return True - self.stub_out('nova.utils.is_neutron', fake_is_neutron) requested_networks = objects.NetworkRequestList( objects=[objects.NetworkRequest(port_id=uuids.port_instance)]) self.assertRaises(exception.MultiplePortsNotApplicable, @@ -6145,11 +6130,9 @@ class ComputeTestCase(BaseTestCase, # Confirm setup_compute_volume is called when volume is mounted. def stupid(*args, **kwargs): return fake_network.fake_get_instance_nw_info(self) - if CONF.use_neutron: - self.stub_out( - 'nova.network.neutronv2.api.API.get_instance_nw_info', stupid) - else: - self.stub_out('nova.network.api.API.get_instance_nw_info', stupid) + + self.stub_out( + 'nova.network.neutronv2.api.API.get_instance_nw_info', stupid) # creating instance testdata instance = self._create_fake_instance_obj({'host': 'dummy'}) @@ -7152,23 +7135,9 @@ class ComputeTestCase(BaseTestCase, CONF.running_deleted_instance_timeout) @mock.patch('nova.network.neutronv2.api.API.list_ports') - @mock.patch.object(nova.utils, 'is_neutron') - def test_require_nw_info_update_not_neutron(self, mock_is_neutron, - mock_list_ports): + def test_require_nw_info_update_host_match(self, mock_list_ports): ctxt = context.get_admin_context() instance = self._create_fake_instance_obj() - mock_is_neutron.return_value = False - val = self.compute._require_nw_info_update(ctxt, instance) - self.assertFalse(val) - mock_list_ports.assert_not_called() - - @mock.patch('nova.network.neutronv2.api.API.list_ports') - @mock.patch.object(nova.utils, 'is_neutron') - def test_require_nw_info_update_host_match(self, mock_is_neutron, - mock_list_ports): - ctxt = context.get_admin_context() - instance = self._create_fake_instance_obj() - mock_is_neutron.return_value = True mock_list_ports.return_value = {'ports': [ {'binding:host_id': self.compute.host, 'binding:vif_type': 'foo'} @@ -7183,12 +7152,9 @@ class ComputeTestCase(BaseTestCase, mock_list_ports.assert_called_once_with(ctxt, **search_opts) @mock.patch('nova.network.neutronv2.api.API.list_ports') - @mock.patch.object(nova.utils, 'is_neutron') - def test_require_nw_info_update_host_mismatch(self, mock_is_neutron, - mock_list_ports): + def test_require_nw_info_update_host_mismatch(self, mock_list_ports): ctxt = context.get_admin_context() instance = self._create_fake_instance_obj() - mock_is_neutron.return_value = True mock_list_ports.return_value = {'ports': [ {'binding:host_id': 'foo', 'binding:vif_type': 'foo'} ]} @@ -7199,12 +7165,9 @@ class ComputeTestCase(BaseTestCase, mock_list_ports.assert_called_once_with(ctxt, **search_opts) @mock.patch('nova.network.neutronv2.api.API.list_ports') - @mock.patch.object(nova.utils, 'is_neutron') - def test_require_nw_info_update_failed_vif_types( - self, mock_is_neutron, mock_list_ports): + def test_require_nw_info_update_failed_vif_types(self, mock_list_ports): ctxt = context.get_admin_context() instance = self._create_fake_instance_obj() - mock_is_neutron.return_value = True search_opts = {'device_id': instance.uuid, 'fields': ['binding:host_id', 'binding:vif_type']} @@ -7313,20 +7276,12 @@ class ComputeTestCase(BaseTestCase, '_require_nw_info_update', fake_require_nw_info_update) - if CONF.use_neutron: - self.stub_out( - 'nova.network.neutronv2.api.API.get_instance_nw_info', - fake_get_instance_nw_info) - self.stub_out( - 'nova.network.neutronv2.api.API.' - 'setup_instance_network_on_host', - fake_setup_instance_network_on_host) - else: - self.stub_out('nova.network.api.API.get_instance_nw_info', - fake_get_instance_nw_info) - self.stub_out( - 'nova.network.api.API.setup_instance_network_on_host', - fake_setup_instance_network_on_host) + self.stub_out( + 'nova.network.neutronv2.api.API.get_instance_nw_info', + fake_get_instance_nw_info) + self.stub_out( + 'nova.network.neutronv2.api.API.setup_instance_network_on_host', + fake_setup_instance_network_on_host) expected_require_nw_info = 0 expect_setup_network = 0 diff --git a/nova/tests/unit/compute/test_compute_api.py b/nova/tests/unit/compute/test_compute_api.py index f482b8e1eb..3aedb485e3 100644 --- a/nova/tests/unit/compute/test_compute_api.py +++ b/nova/tests/unit/compute/test_compute_api.py @@ -318,7 +318,6 @@ class _ComputeAPIUnitTestMixIn(object): # Tests that if port is specified there is only one instance booting # (i.e max_count == 1) as we can't share the same port across multiple # instances. - self.flags(use_neutron=True) port = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa' address = '10.0.0.1' min_count = 1 @@ -353,7 +352,6 @@ class _ComputeAPIUnitTestMixIn(object): requested_networks) def test_specified_ip_and_multiple_instances_neutronv2(self): - self.flags(use_neutron=True) network = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa' address = '10.0.0.1' requested_networks = objects.NetworkRequestList( @@ -6147,7 +6145,6 @@ class _ComputeAPIUnitTestMixIn(object): """Tests that a list of security groups passed in do not actually get stored on with the instance when using neutron. """ - self.flags(use_neutron=True) flavor = self._create_flavor() params = {'display_name': 'fake-instance'} instance = self._create_instance_obj(params, flavor) @@ -6663,8 +6660,8 @@ class ComputeAPIUnitTestCase(_ComputeAPIUnitTestMixIn, test.NoDBTestCase): @mock.patch.object(neutron_api.API, 'list_ports') @mock.patch.object(objects.BuildRequestList, 'get_by_filters', new_callable=mock.NonCallableMock) - def test_get_all_ip_filter_use_neutron(self, mock_buildreq_get, - mock_list_port, mock_check_ext): + def test_get_all_ip_filter(self, mock_buildreq_get, mock_list_port, + mock_check_ext): mock_check_ext.return_value = True cell_instances = self._list_of_instances(2) mock_list_port.return_value = { @@ -6691,8 +6688,8 @@ class ComputeAPIUnitTestCase(_ComputeAPIUnitTestMixIn, test.NoDBTestCase): @mock.patch.object(neutron_api.API, 'list_ports') @mock.patch.object(objects.BuildRequestList, 'get_by_filters', new_callable=mock.NonCallableMock) - def test_get_all_ip6_filter_use_neutron(self, mock_buildreq_get, - mock_list_port, mock_check_ext): + def test_get_all_ip6_filter(self, mock_buildreq_get, mock_list_port, + mock_check_ext): mock_check_ext.return_value = True cell_instances = self._list_of_instances(2) mock_list_port.return_value = { @@ -6719,9 +6716,8 @@ class ComputeAPIUnitTestCase(_ComputeAPIUnitTestMixIn, test.NoDBTestCase): @mock.patch.object(neutron_api.API, 'list_ports') @mock.patch.object(objects.BuildRequestList, 'get_by_filters', new_callable=mock.NonCallableMock) - def test_get_all_ip_and_ip6_filter_use_neutron(self, mock_buildreq_get, - mock_list_port, - mock_check_ext): + def test_get_all_ip_and_ip6_filter(self, mock_buildreq_get, mock_list_port, + mock_check_ext): mock_check_ext.return_value = True cell_instances = self._list_of_instances(2) mock_list_port.return_value = { @@ -6752,8 +6748,7 @@ class ComputeAPIUnitTestCase(_ComputeAPIUnitTestMixIn, test.NoDBTestCase): @mock.patch.object(neutron_api.API, 'has_substr_port_filtering_extension') @mock.patch.object(neutron_api.API, 'list_ports') - def test_get_all_ip6_filter_use_neutron_exc(self, mock_list_port, - mock_check_ext): + def test_get_all_ip6_filter_exc(self, mock_list_port, mock_check_ext): mock_check_ext.return_value = True mock_list_port.side_effect = exception.InternalError('fake') diff --git a/nova/tests/unit/compute/test_compute_mgr.py b/nova/tests/unit/compute/test_compute_mgr.py index e8175e2955..63c067c123 100644 --- a/nova/tests/unit/compute/test_compute_mgr.py +++ b/nova/tests/unit/compute/test_compute_mgr.py @@ -6138,7 +6138,6 @@ class ComputeManagerBuildInstanceTestCase(test.NoDBTestCase): def test_rescheduled_exception(self, mock_hooks, mock_build_run, mock_build, mock_set, mock_nil, mock_save, mock_start, mock_finish): - self.flags(use_neutron=False) self._do_build_instance_update(mock_save, reschedule_update=True) mock_build_run.side_effect = exception.RescheduledException(reason='', instance_uuid=self.instance.uuid) @@ -6166,8 +6165,7 @@ class ComputeManagerBuildInstanceTestCase(test.NoDBTestCase): self.requested_networks, self.security_groups, self.block_device_mapping, self.node, self.limits, self.filter_properties, {}) - mock_clean.assert_called_once_with(self.context, self.instance, - self.compute.host) + mock_clean.assert_not_called() mock_nil.assert_called_once_with(self.instance) mock_build.assert_called_once_with(self.context, [self.instance], self.image, self.filter_properties, @@ -6224,7 +6222,6 @@ class ComputeManagerBuildInstanceTestCase(test.NoDBTestCase): mock_event_finish, mock_event_start, mock_ins_save, mock_build_ins, mock_build_and_run): - self.flags(use_neutron=False) instance = fake_instance.fake_instance_obj(self.context, vm_state=vm_states.ACTIVE, system_metadata={'network_allocated': 'True'}, @@ -6252,8 +6249,7 @@ class ComputeManagerBuildInstanceTestCase(test.NoDBTestCase): self.requested_networks, self.security_groups, self.block_device_mapping, self.node, self.limits, self.filter_properties, {}) - mock_cleanup_network.assert_called_once_with( - self.context, instance, self.compute.host) + mock_cleanup_network.assert_not_called() mock_build_ins.assert_called_once_with(self.context, [instance], self.image, self.filter_properties, self.admin_pass, self.injected_files, self.requested_networks, @@ -6424,7 +6420,6 @@ class ComputeManagerBuildInstanceTestCase(test.NoDBTestCase): mock_build_run, mock_build, mock_deallocate, mock_nil, mock_clean_net, mock_save, mock_start, mock_finish): - self.flags(use_neutron=False) self._do_build_instance_update(mock_save, reschedule_update=True) mock_build_run.side_effect = exception.RescheduledException(reason='', instance_uuid=self.instance.uuid) @@ -6454,8 +6449,7 @@ class ComputeManagerBuildInstanceTestCase(test.NoDBTestCase): self.block_device_mapping, self.node, self.limits, self.filter_properties, {}) mock_deallocate.assert_called_once_with(self.instance) - mock_clean_inst.assert_called_once_with(self.context, self.instance, - self.compute.host) + mock_clean_inst.assert_not_called() mock_nil.assert_called_once_with(self.instance) mock_build.assert_called_once_with(self.context, [self.instance], self.image, self.filter_properties, @@ -6877,7 +6871,6 @@ class ComputeManagerBuildInstanceTestCase(test.NoDBTestCase): def test_reschedule_on_resources_unavailable(self, mock_claim, mock_build, mock_nil, mock_save, mock_start, mock_finish, mock_notify): - self.flags(use_neutron=False) reason = 'resource unavailable' exc = exception.ComputeResourcesUnavailable(reason=reason) mock_claim.side_effect = exc @@ -6911,8 +6904,7 @@ class ComputeManagerBuildInstanceTestCase(test.NoDBTestCase): self.security_groups, self.block_device_mapping, request_spec={}, host_lists=[fake_host_list]) mock_nil.assert_called_once_with(self.instance) - mock_clean.assert_called_once_with(self.context, self.instance, - self.compute.host) + mock_clean.assert_not_called() @mock.patch.object(manager.ComputeManager, '_build_resources') @mock.patch.object(objects.Instance, 'save') @@ -8759,19 +8751,24 @@ class ComputeManagerMigrationTestCase(test.NoDBTestCase, """Tests the various ways that _get_neutron_events_for_live_migration will return an empty list. """ - nw = network_model.NetworkInfo([network_model.VIF(uuids.port1)]) # 1. no timeout self.flags(vif_plugging_timeout=0) - self.assertEqual( - [], self.compute._get_neutron_events_for_live_migration(nw)) - # 2. not neutron - self.flags(vif_plugging_timeout=300, use_neutron=False) - self.assertEqual( - [], self.compute._get_neutron_events_for_live_migration(nw)) - # 3. no VIFs - self.flags(vif_plugging_timeout=300, use_neutron=True) - self.assertEqual( - [], self.compute._get_neutron_events_for_live_migration([])) + + with mock.patch.object(self.instance, 'get_network_info') as nw_info: + nw_info.return_value = network_model.NetworkInfo( + [network_model.VIF(uuids.port1)]) + self.assertEqual( + [], self.compute._get_neutron_events_for_live_migration( + self.instance)) + + # 2. no VIFs + self.flags(vif_plugging_timeout=300) + + with mock.patch.object(self.instance, 'get_network_info') as nw_info: + nw_info.return_value = [] + self.assertEqual( + [], self.compute._get_neutron_events_for_live_migration( + self.instance)) @mock.patch('nova.compute.rpcapi.ComputeAPI.pre_live_migration') @mock.patch('nova.compute.manager.ComputeManager._post_live_migration') diff --git a/nova/tests/unit/test_metadata.py b/nova/tests/unit/test_metadata.py index 7a6ecf3af2..6b5a5d8adf 100644 --- a/nova/tests/unit/test_metadata.py +++ b/nova/tests/unit/test_metadata.py @@ -293,7 +293,7 @@ class MetadataTestCase(test.TestCase): md.get_ec2_metadata(version='2009-04-04').get('user-data', obj), obj) - def _test_security_groups(self): + def test_security_groups(self): inst = self.instance.obj_clone() sgroups = [{'name': name} for name in ('default', 'other')] expected = ['default', 'other'] @@ -302,13 +302,6 @@ class MetadataTestCase(test.TestCase): data = md.get_ec2_metadata(version='2009-04-04') self.assertEqual(data['meta-data']['security-groups'], expected) - def test_security_groups(self): - self._test_security_groups() - - def test_neutron_security_groups(self): - self.flags(use_neutron=True) - self._test_security_groups() - def test_local_hostname(self): self.flags(dhcp_domain=None, group='api') md = fake_InstanceMetadata(self, self.instance.obj_clone()) diff --git a/nova/tests/unit/test_quota.py b/nova/tests/unit/test_quota.py index fa927e7c4f..4b5c103e51 100644 --- a/nova/tests/unit/test_quota.py +++ b/nova/tests/unit/test_quota.py @@ -22,7 +22,6 @@ from six.moves import range from nova.compute import api as compute import nova.conf from nova import context -from nova.db import api as db from nova.db.sqlalchemy import models as sqa_models from nova import exception from nova import objects @@ -152,58 +151,6 @@ class QuotaIntegrationTestCase(test.TestCase): for i in range(3): self._create_instance(flavor_name='m1.xlarge') - @mock.patch('nova.privsep.linux_net.bind_ip') - @mock.patch('nova.privsep.linux_net.iptables_get_rules', - return_value=('', '')) - @mock.patch('nova.privsep.linux_net.iptables_set_rules', - return_value=('', '')) - def test_too_many_addresses(self, mock_iptables_set_rules, - mock_iptables_get_rules, mock_bind_ip): - # This test is specifically relying on nova-network. - self.flags(use_neutron=False, - network_manager='nova.network.manager.FlatDHCPManager') - self.flags(floating_ips=1, group='quota') - # Apparently needed by the RPC tests... - self.network = self.start_service('network', - manager=CONF.network_manager) - address = '192.168.0.100' - db.floating_ip_create(context.get_admin_context(), - {'address': address, - 'pool': 'nova', - 'project_id': self.project_id}) - self.assertRaises(exception.QuotaError, - self.network.allocate_floating_ip, - self.context, - self.project_id) - db.floating_ip_destroy(context.get_admin_context(), address) - - @mock.patch('nova.privsep.linux_net.bind_ip') - @mock.patch('nova.privsep.linux_net.iptables_get_rules', - return_value=('', '')) - @mock.patch('nova.privsep.linux_net.iptables_set_rules', - return_value=('', '')) - def test_auto_assigned(self, mock_iptables_set_rules, - mock_iptables_get_rules, mock_bind_ip): - # This test is specifically relying on nova-network. - self.flags(use_neutron=False, - network_manager='nova.network.manager.FlatDHCPManager') - self.flags(floating_ips=1, group='quota') - # Apparently needed by the RPC tests... - self.network = self.start_service('network', - manager=CONF.network_manager) - address = '192.168.0.100' - db.floating_ip_create(context.get_admin_context(), - {'address': address, - 'pool': 'nova', - 'project_id': self.project_id}) - # auto allocated addresses should not be counted - self.assertRaises(exception.NoMoreFloatingIps, - self.network.allocate_floating_ip, - self.context, - self.project_id, - True) - db.floating_ip_destroy(context.get_admin_context(), address) - def test_too_many_metadata_items(self): metadata = {} for i in range(CONF.quota.metadata_items + 1): diff --git a/nova/tests/unit/utils.py b/nova/tests/unit/utils.py index 8ac1a8163b..d3752ffe8d 100644 --- a/nova/tests/unit/utils.py +++ b/nova/tests/unit/utils.py @@ -166,15 +166,11 @@ def get_test_network_info(count=1): vlan=FAKE_NETWORK_VLAN, bridge_interface=FAKE_NETWORK_INTERFACE, injected=False) - if CONF.use_neutron: - vif_type = network_model.VIF_TYPE_OVS - else: - vif_type = network_model.VIF_TYPE_BRIDGE vif = network_model.VIF( id=FAKE_VIF_UUID, address=FAKE_VIF_MAC, network=network, - type=vif_type, + type=network_model.VIF_TYPE_OVS, devname=None, ovs_interfaceid=None) diff --git a/nova/tests/unit/virt/test_virt_drivers.py b/nova/tests/unit/virt/test_virt_drivers.py index c457b7b89b..4520bece42 100644 --- a/nova/tests/unit/virt/test_virt_drivers.py +++ b/nova/tests/unit/virt/test_virt_drivers.py @@ -895,9 +895,9 @@ class LibvirtConnTestCase(_VirtDriverTestCase, test.TestCase): # This is needed for the live migration tests which spawn off the # operation for monitoring. self.useFixture(nova_fixtures.SpawnIsSynchronousFixture()) - # When using CONF.use_neutron=True and destroying an instance os-vif - # will try to execute some commands which hangs tests so let's just - # stub out the unplug call to os-vif since we don't care about it. + # When destroying an instance, os-vif will try to execute some commands + # which hang tests so let's just stub out the unplug call to os-vif + # since we don't care about it. self.stub_out('os_vif.unplug', lambda a, kw: None) self.stub_out('nova.compute.utils.get_machine_ips', lambda: [])