diff options
28 files changed, 106 insertions, 93 deletions
diff --git a/nova/test.py b/nova/test.py index d9f68cc76..3ba38eef4 100644 --- a/nova/test.py +++ b/nova/test.py @@ -220,6 +220,7 @@ class TestCase(testtools.TestCase): self.addCleanup(self._clear_attrs) self.useFixture(fixtures.EnvironmentVariable('http_proxy')) self.policy = self.useFixture(policy_fixture.PolicyFixture()) + CONF.set_override('fatal_exception_format_errors', True) def _clear_attrs(self): # Delete attributes that don't start with _ so they don't pin diff --git a/nova/tests/api/ec2/test_cloud.py b/nova/tests/api/ec2/test_cloud.py index 831143326..eef03379f 100644 --- a/nova/tests/api/ec2/test_cloud.py +++ b/nova/tests/api/ec2/test_cloud.py @@ -2125,7 +2125,6 @@ class CloudTestCase(test.TestCase): def fake_show(self, context, id_): LOG.debug("id_ %s", id_) - print id_ prop = {} if id_ == 'ami-3': diff --git a/nova/tests/api/openstack/compute/contrib/test_admin_actions.py b/nova/tests/api/openstack/compute/contrib/test_admin_actions.py index c121e3afb..99f00e07c 100644 --- a/nova/tests/api/openstack/compute/contrib/test_admin_actions.py +++ b/nova/tests/api/openstack/compute/contrib/test_admin_actions.py @@ -54,7 +54,9 @@ def fake_compute_api(*args, **kwargs): def fake_compute_api_raises_invalid_state(*args, **kwargs): - raise exception.InstanceInvalidState + raise exception.InstanceInvalidState(attr='fake_attr', + state='fake_state', method='fake_method', + instance_uuid='fake') def fake_compute_api_get(self, context, instance_id): @@ -124,7 +126,7 @@ class AdminActionsTest(test.TestCase): req.content_type = 'application/json' res = req.get_response(app) self.assertEqual(res.status_int, 409) - self.assertIn("invalid state for '%(_action)s'" % locals(), + self.assertIn("Cannot \'%(_action)s\' while instance" % locals(), res.body) def test_migrate_live_enabled(self): @@ -345,7 +347,7 @@ class ResetStateTests(test.TestCase): def fake_get(inst, context, instance_id): if self.exists: return dict(id=1, uuid=instance_id, vm_state=vm_states.ACTIVE) - raise exception.InstanceNotFound() + raise exception.InstanceNotFound(instance_id=instance_id) def fake_update(inst, context, instance, **kwargs): self.kwargs = kwargs diff --git a/nova/tests/api/openstack/compute/contrib/test_aggregates.py b/nova/tests/api/openstack/compute/contrib/test_aggregates.py index 41a87ac6a..0f60b8128 100644 --- a/nova/tests/api/openstack/compute/contrib/test_aggregates.py +++ b/nova/tests/api/openstack/compute/contrib/test_aggregates.py @@ -78,7 +78,7 @@ class AggregateTestCase(test.TestCase): def test_create_with_duplicate_aggregate_name(self): def stub_create_aggregate(context, name, availability_zone): - raise exception.AggregateNameExists + raise exception.AggregateNameExists(aggregate_name=name) self.stubs.Set(self.controller.api, "create_aggregate", stub_create_aggregate) @@ -232,7 +232,8 @@ class AggregateTestCase(test.TestCase): def test_add_host_with_already_added_host(self): def stub_add_host_to_aggregate(context, aggregate, host): - raise exception.AggregateHostExists() + raise exception.AggregateHostExists(aggregate_id=aggregate, + host=host) self.stubs.Set(self.controller.api, "add_host_to_aggregate", stub_add_host_to_aggregate) @@ -242,7 +243,7 @@ class AggregateTestCase(test.TestCase): def test_add_host_with_bad_aggregate(self): def stub_add_host_to_aggregate(context, aggregate, host): - raise exception.AggregateNotFound() + raise exception.AggregateNotFound(aggregate_id=aggregate) self.stubs.Set(self.controller.api, "add_host_to_aggregate", stub_add_host_to_aggregate) @@ -252,7 +253,7 @@ class AggregateTestCase(test.TestCase): def test_add_host_with_bad_host(self): def stub_add_host_to_aggregate(context, aggregate, host): - raise exception.ComputeHostNotFound() + raise exception.ComputeHostNotFound(host=host) self.stubs.Set(self.controller.api, "add_host_to_aggregate", stub_add_host_to_aggregate) @@ -262,7 +263,9 @@ class AggregateTestCase(test.TestCase): def test_add_host_with_host_in_wrong_availability_zone(self): def stub_add_host_to_aggregate(context, aggregate, host): - raise exception.InvalidAggregateAction() + raise exception.InvalidAggregateAction(action='create_aggregate', + aggregate_id="'N/A'", + reason='wrong zone') self.stubs.Set(self.controller.api, "add_host_to_aggregate", stub_add_host_to_aggregate) @@ -290,7 +293,7 @@ class AggregateTestCase(test.TestCase): def test_remove_host_with_bad_aggregate(self): def stub_remove_host_from_aggregate(context, aggregate, host): - raise exception.AggregateNotFound() + raise exception.AggregateNotFound(aggregate_id=aggregate) self.stubs.Set(self.controller.api, "remove_host_from_aggregate", stub_remove_host_from_aggregate) @@ -301,7 +304,8 @@ class AggregateTestCase(test.TestCase): def test_remove_host_with_bad_host(self): def stub_remove_host_from_aggregate(context, aggregate, host): - raise exception.AggregateHostNotFound() + raise exception.AggregateHostNotFound(aggregate_id=aggregate, + host=host) self.stubs.Set(self.controller.api, "remove_host_from_aggregate", stub_remove_host_from_aggregate) @@ -339,7 +343,7 @@ class AggregateTestCase(test.TestCase): body = {"set_metadata": {"metadata": {"foo": "bar"}}} def stub_update_aggregate(context, aggregate, metadata): - raise exception.AggregateNotFound() + raise exception.AggregateNotFound(aggregate_id=aggregate) self.stubs.Set(self.controller.api, "update_aggregate_metadata", stub_update_aggregate) @@ -370,7 +374,7 @@ class AggregateTestCase(test.TestCase): def test_delete_aggregate_with_bad_aggregate(self): def stub_delete_aggregate(context, aggregate): - raise exception.AggregateNotFound() + raise exception.AggregateNotFound(aggregate_id=aggregate) self.stubs.Set(self.controller.api, "delete_aggregate", stub_delete_aggregate) diff --git a/nova/tests/api/openstack/compute/contrib/test_deferred_delete.py b/nova/tests/api/openstack/compute/contrib/test_deferred_delete.py index e7da8f191..eba4154e2 100644 --- a/nova/tests/api/openstack/compute/contrib/test_deferred_delete.py +++ b/nova/tests/api/openstack/compute/contrib/test_deferred_delete.py @@ -61,9 +61,13 @@ class DeferredDeleteExtensionTest(test.TestCase): compute_api.API.get(self.fake_context, self.fake_uuid).AndReturn( fake_instance) + + exc = exception.InstanceInvalidState(attr='fake_attr', + state='fake_state', method='fake_method', + instance_uuid='fake') + compute_api.API.force_delete(self.fake_context, fake_instance)\ - .AndRaise( - exception.InstanceInvalidState) + .AndRaise(exc) self.mox.ReplayAll() self.assertRaises(webob.exc.HTTPConflict, @@ -90,11 +94,14 @@ class DeferredDeleteExtensionTest(test.TestCase): self.mox.StubOutWithMock(compute_api.API, 'restore') fake_instance = 'fake_instance' + exc = exception.InstanceInvalidState(attr='fake_attr', + state='fake_state', method='fake_method', + instance_uuid='fake') compute_api.API.get(self.fake_context, self.fake_uuid).AndReturn( fake_instance) compute_api.API.restore(self.fake_context, fake_instance).AndRaise( - exception.InstanceInvalidState) + exc) self.mox.ReplayAll() self.assertRaises(webob.exc.HTTPConflict, self.extension._restore, diff --git a/nova/tests/api/openstack/compute/contrib/test_extended_server_attributes.py b/nova/tests/api/openstack/compute/contrib/test_extended_server_attributes.py index 036c240d4..63e1b6126 100644 --- a/nova/tests/api/openstack/compute/contrib/test_extended_server_attributes.py +++ b/nova/tests/api/openstack/compute/contrib/test_extended_server_attributes.py @@ -100,7 +100,7 @@ class ExtendedServerAttributesTest(test.TestCase): def test_no_instance_passthrough_404(self): def fake_compute_get(*args, **kwargs): - raise exception.InstanceNotFound() + raise exception.InstanceNotFound(instance_id='fake') self.stubs.Set(compute.api.API, 'get', fake_compute_get) url = '/v2/fake/servers/70f6db34-de8d-4fbd-aafb-4065bdfa6115' diff --git a/nova/tests/api/openstack/compute/contrib/test_extended_status.py b/nova/tests/api/openstack/compute/contrib/test_extended_status.py index f9d4cb43a..e368c5986 100644 --- a/nova/tests/api/openstack/compute/contrib/test_extended_status.py +++ b/nova/tests/api/openstack/compute/contrib/test_extended_status.py @@ -98,7 +98,7 @@ class ExtendedStatusTest(test.TestCase): def test_no_instance_passthrough_404(self): def fake_compute_get(*args, **kwargs): - raise exception.InstanceNotFound() + raise exception.InstanceNotFound(instance_id='fake') self.stubs.Set(compute.api.API, 'get', fake_compute_get) url = '/v2/fake/servers/70f6db34-de8d-4fbd-aafb-4065bdfa6115' diff --git a/nova/tests/api/openstack/compute/contrib/test_flavor_access.py b/nova/tests/api/openstack/compute/contrib/test_flavor_access.py index 0bf1f1b66..0818dfdd3 100644 --- a/nova/tests/api/openstack/compute/contrib/test_flavor_access.py +++ b/nova/tests/api/openstack/compute/contrib/test_flavor_access.py @@ -226,7 +226,8 @@ class FlavorAccessTest(test.TestCase): def test_add_tenant_access_with_already_added_access(self): def stub_add_instance_type_access(flavorid, projectid, ctxt=None): - raise exception.FlavorAccessExists() + raise exception.FlavorAccessExists(flavor_id=flavorid, + project_id=projectid) self.stubs.Set(instance_types, 'add_instance_type_access', stub_add_instance_type_access) body = {'addTenantAccess': {'tenant': 'proj2'}} @@ -238,22 +239,8 @@ class FlavorAccessTest(test.TestCase): def test_remove_tenant_access_with_bad_access(self): def stub_remove_instance_type_access(flavorid, projectid, ctxt=None): - self.assertEqual('3', flavorid, "flavorid") - self.assertEqual("proj2", projectid, "projectid") - expected = {'flavor_access': [ - {'flavor_id': '3', 'tenant_id': 'proj3'}]} - self.stubs.Set(instance_types, 'remove_instance_type_access', - stub_remove_instance_type_access) - body = {'removeTenantAccess': {'tenant': 'proj2'}} - req = fakes.HTTPRequest.blank('/v2/fake/flavors/2/action', - use_admin_context=True) - result = self.flavor_action_controller.\ - _addTenantAccess(req, '3', body) - self.assertEqual(result, expected) - - def test_remove_tenant_access_with_bad_access(self): - def stub_remove_instance_type_access(flavorid, projectid, ctxt=None): - raise exception.FlavorAccessNotFound() + raise exception.FlavorAccessNotFound(flavor_id=flavorid, + project_id=projectid) self.stubs.Set(instance_types, 'remove_instance_type_access', stub_remove_instance_type_access) body = {'removeTenantAccess': {'tenant': 'proj2'}} diff --git a/nova/tests/api/openstack/compute/contrib/test_flavor_manage.py b/nova/tests/api/openstack/compute/contrib/test_flavor_manage.py index 3df9f956b..9b58e7b74 100644 --- a/nova/tests/api/openstack/compute/contrib/test_flavor_manage.py +++ b/nova/tests/api/openstack/compute/contrib/test_flavor_manage.py @@ -208,7 +208,7 @@ class FlavorManageTest(test.TestCase): def fake_create(name, memory_mb, vcpus, root_gb, ephemeral_gb, flavorid, swap, rxtx_factor, is_public): - raise exception.InstanceTypeExists() + raise exception.InstanceTypeExists(name=name) self.stubs.Set(instance_types, "create", fake_create) url = '/v2/fake/flavors' diff --git a/nova/tests/api/openstack/compute/contrib/test_floating_ips.py b/nova/tests/api/openstack/compute/contrib/test_floating_ips.py index d67682a4f..a72430fd9 100644 --- a/nova/tests/api/openstack/compute/contrib/test_floating_ips.py +++ b/nova/tests/api/openstack/compute/contrib/test_floating_ips.py @@ -229,7 +229,7 @@ class FloatingIpTest(test.TestCase): def test_floating_ip_show_not_found(self): def fake_get_floating_ip(*args, **kwargs): - raise exception.FloatingIpNotFound() + raise exception.FloatingIpNotFound(id='fake') self.stubs.Set(network.api.API, "get_floating_ip", fake_get_floating_ip) @@ -379,7 +379,8 @@ class FloatingIpTest(test.TestCase): fixed_address=None): floating_ips = ["10.10.10.10", "10.10.10.11"] if floating_address not in floating_ips: - raise exception.FloatingIpNotFoundForAddress() + raise exception.FloatingIpNotFoundForAddress( + address=flaoting_address) self.stubs.Set(network.api.API, "associate_floating_ip", fake_network_api_associate) @@ -395,7 +396,8 @@ class FloatingIpTest(test.TestCase): floating_address): floating_ips = ["10.10.10.10", "10.10.10.11"] if floating_address not in floating_ips: - raise exception.FloatingIpNotFoundForAddress() + raise exception.FloatingIpNotFoundForAddress( + address=floating_address) self.stubs.Set(network.api.API, "get_floating_ip_by_address", network_api_get_floating_ip_by_address) diff --git a/nova/tests/api/openstack/compute/contrib/test_hide_server_addresses.py b/nova/tests/api/openstack/compute/contrib/test_hide_server_addresses.py index 7991bc27f..804decdff 100644 --- a/nova/tests/api/openstack/compute/contrib/test_hide_server_addresses.py +++ b/nova/tests/api/openstack/compute/contrib/test_hide_server_addresses.py @@ -124,7 +124,7 @@ class HideServerAddressesTest(test.TestCase): def test_no_instance_passthrough_404(self): def fake_compute_get(*args, **kwargs): - raise exception.InstanceNotFound() + raise exception.InstanceNotFound(instance_id='fake') self.stubs.Set(compute.api.API, 'get', fake_compute_get) res = self._make_request('/v2/fake/servers/' + fakes.get_fake_uuid()) diff --git a/nova/tests/api/openstack/compute/contrib/test_hypervisors.py b/nova/tests/api/openstack/compute/contrib/test_hypervisors.py index 740477ca3..4e4d214cc 100644 --- a/nova/tests/api/openstack/compute/contrib/test_hypervisors.py +++ b/nova/tests/api/openstack/compute/contrib/test_hypervisors.py @@ -91,7 +91,7 @@ def fake_compute_node_get(context, compute_id): for hyper in TEST_HYPERS: if hyper['id'] == compute_id: return hyper - raise exception.ComputeHostNotFound + raise exception.ComputeHostNotFound(host=compute_id) def fake_compute_node_statistics(context): diff --git a/nova/tests/api/openstack/compute/contrib/test_networks.py b/nova/tests/api/openstack/compute/contrib/test_networks.py index bab6cef68..5cd522f72 100644 --- a/nova/tests/api/openstack/compute/contrib/test_networks.py +++ b/nova/tests/api/openstack/compute/contrib/test_networks.py @@ -103,14 +103,14 @@ class FakeNetworkAPI(object): if network['id'] == network_id: del self.networks[0] return True - raise exception.NetworkNotFoundForUUID() + raise exception.NetworkNotFoundForUUID(uuid=network_id) def disassociate(self, context, network_uuid): for network in self.networks: if network.get('uuid') == network_uuid: network['project_id'] = None return True - raise exception.NetworkNotFound() + raise exception.NetworkNotFound(network_id=network_uuid) def associate(self, context, network_uuid, host=_sentinel, project=_sentinel): @@ -121,7 +121,7 @@ class FakeNetworkAPI(object): if project is not FakeNetworkAPI._sentinel: network['project_id'] = project return True - raise exception.NetworkNotFound() + raise exception.NetworkNotFound(network_id=network_uuid) def add_network_to_project(self, context, project_id, network_uuid=None): @@ -143,7 +143,7 @@ class FakeNetworkAPI(object): for network in self.networks: if network.get('uuid') == network_id: return network - raise exception.NetworkNotFound() + raise exception.NetworkNotFound(network_id=network_id) def create(self, context, **kwargs): subnet_bits = int(math.ceil(math.log(kwargs.get( diff --git a/nova/tests/api/openstack/compute/contrib/test_security_groups.py b/nova/tests/api/openstack/compute/contrib/test_security_groups.py index 2e5a22835..ccb58f858 100644 --- a/nova/tests/api/openstack/compute/contrib/test_security_groups.py +++ b/nova/tests/api/openstack/compute/contrib/test_security_groups.py @@ -1370,7 +1370,7 @@ class SecurityGroupsOutputTest(test.TestCase): def test_no_instance_passthrough_404(self): def fake_compute_get(*args, **kwargs): - raise exception.InstanceNotFound() + raise exception.InstanceNotFound(instance_id='fake') self.stubs.Set(compute.api.API, 'get', fake_compute_get) url = '/v2/fake/servers/70f6db34-de8d-4fbd-aafb-4065bdfa6115' diff --git a/nova/tests/api/openstack/compute/test_flavors.py b/nova/tests/api/openstack/compute/test_flavors.py index da633d371..050384aa2 100644 --- a/nova/tests/api/openstack/compute/test_flavors.py +++ b/nova/tests/api/openstack/compute/test_flavors.py @@ -77,7 +77,7 @@ def empty_instance_type_get_all(inactive=False, filters=None): def return_instance_type_not_found(flavor_id): - raise exception.InstanceTypeNotFound(flavor_id=flavor_id) + raise exception.InstanceTypeNotFound(instance_type_id=flavor_id) class FlavorsTest(test.TestCase): diff --git a/nova/tests/api/openstack/compute/test_server_actions.py b/nova/tests/api/openstack/compute/test_server_actions.py index 157ac0e8d..fc65fa2bb 100644 --- a/nova/tests/api/openstack/compute/test_server_actions.py +++ b/nova/tests/api/openstack/compute/test_server_actions.py @@ -184,7 +184,9 @@ class ServerActionsControllerTest(test.TestCase): body = dict(reboot=dict(type="HARD")) def fake_reboot(*args, **kwargs): - raise exception.InstanceInvalidState + raise exception.InstanceInvalidState(attr='fake_attr', + state='fake_state', method='fake_method', + instance_uuid='fake') self.stubs.Set(compute_api.API, 'reboot', fake_reboot) @@ -306,7 +308,9 @@ class ServerActionsControllerTest(test.TestCase): } def fake_rebuild(*args, **kwargs): - raise exception.InstanceInvalidState + raise exception.InstanceInvalidState(attr='fake_attr', + state='fake_state', method='fake_method', + instance_uuid='fake') self.stubs.Set(compute_api.API, 'rebuild', fake_rebuild) @@ -604,7 +608,9 @@ class ServerActionsControllerTest(test.TestCase): body = dict(resize=dict(flavorRef="http://localhost/3")) def fake_resize(*args, **kwargs): - raise exception.InstanceInvalidState + raise exception.InstanceInvalidState(attr='fake_attr', + state='fake_state', method='fake_method', + instance_uuid='fake') self.stubs.Set(compute_api.API, 'resize', fake_resize) @@ -648,7 +654,9 @@ class ServerActionsControllerTest(test.TestCase): body = dict(confirmResize=None) def fake_confirm_resize(*args, **kwargs): - raise exception.InstanceInvalidState + raise exception.InstanceInvalidState(attr='fake_attr', + state='fake_state', method='fake_method', + instance_uuid='fake') self.stubs.Set(compute_api.API, 'confirm_resize', fake_confirm_resize) @@ -693,7 +701,9 @@ class ServerActionsControllerTest(test.TestCase): body = dict(revertResize=None) def fake_revert_resize(*args, **kwargs): - raise exception.InstanceInvalidState + raise exception.InstanceInvalidState(attr='fake_attr', + state='fake_state', method='fake_method', + instance_uuid='fake') self.stubs.Set(compute_api.API, 'revert_resize', fake_revert_resize) @@ -896,7 +906,9 @@ class ServerActionsControllerTest(test.TestCase): def test_create_image_raises_conflict_on_invalid_state(self): def snapshot(*args, **kwargs): - raise exception.InstanceInvalidState + raise exception.InstanceInvalidState(attr='fake_attr', + state='fake_state', method='fake_method', + instance_uuid='fake') self.stubs.Set(compute_api.API, 'snapshot', snapshot) body = { diff --git a/nova/tests/api/openstack/compute/test_server_metadata.py b/nova/tests/api/openstack/compute/test_server_metadata.py index 78e3f866b..529bf58a3 100644 --- a/nova/tests/api/openstack/compute/test_server_metadata.py +++ b/nova/tests/api/openstack/compute/test_server_metadata.py @@ -86,7 +86,7 @@ def return_server_by_uuid(context, server_uuid): def return_server_nonexistent(context, server_id): - raise exception.InstanceNotFound() + raise exception.InstanceNotFound(instance_id=server_id) def fake_change_instance_metadata(self, context, instance, diff): diff --git a/nova/tests/api/openstack/compute/test_servers.py b/nova/tests/api/openstack/compute/test_servers.py index 58989ab00..734297501 100644 --- a/nova/tests/api/openstack/compute/test_servers.py +++ b/nova/tests/api/openstack/compute/test_servers.py @@ -522,7 +522,7 @@ class ServersControllerTest(test.TestCase): def test_get_server_addresses_nonexistent_server(self): def fake_instance_get(*args, **kwargs): - raise exception.InstanceNotFound() + raise exception.InstanceNotFound(instance_id='fake') self.stubs.Set(db, 'instance_get_by_uuid', fake_instance_get) @@ -1250,7 +1250,7 @@ class ServersControllerTest(test.TestCase): def test_update_server_not_found(self): def fake_get(*args, **kwargs): - raise exception.InstanceNotFound() + raise exception.InstanceNotFound(instance_id='fake') self.stubs.Set(compute_api.API, 'get', fake_get) req = fakes.HTTPRequest.blank('/v2/fake/servers/%s' % FAKE_UUID) @@ -1263,7 +1263,7 @@ class ServersControllerTest(test.TestCase): def test_update_server_not_found_on_update(self): def fake_update(*args, **kwargs): - raise exception.InstanceNotFound() + raise exception.InstanceNotFound(instance_id='fake') self.stubs.Set(compute_api.API, 'update', fake_update) req = fakes.HTTPRequest.blank('/v2/fake/servers/%s' % FAKE_UUID) diff --git a/nova/tests/api/openstack/fakes.py b/nova/tests/api/openstack/fakes.py index 465cf63dc..9b939b324 100644 --- a/nova/tests/api/openstack/fakes.py +++ b/nova/tests/api/openstack/fakes.py @@ -403,7 +403,7 @@ def fake_instance_get_all_by_filters(num_servers=5, **kwargs): found_marker = True servers_list = [] if not marker is None and not found_marker: - raise exc.MarkerNotFound(marker) + raise exc.MarkerNotFound(marker=marker) if not limit is None: servers_list = servers_list[:limit] return servers_list diff --git a/nova/tests/api/openstack/test_common.py b/nova/tests/api/openstack/test_common.py index 4ebd49ca2..28bbb3d25 100644 --- a/nova/tests/api/openstack/test_common.py +++ b/nova/tests/api/openstack/test_common.py @@ -284,9 +284,9 @@ class MiscFunctionsTest(test.TestCase): self.assertEqual(actual, expected) def test_raise_http_conflict_for_instance_invalid_state(self): - # Correct args exc = exception.InstanceInvalidState(attr='fake_attr', - state='fake_state', method='fake_method') + state='fake_state', method='fake_method', + instance_uuid='fake') try: common.raise_http_conflict_for_instance_invalid_state(exc, 'meow') @@ -296,17 +296,6 @@ class MiscFunctionsTest(test.TestCase): else: self.fail("webob.exc.HTTPConflict was not raised") - # Incorrect args - exc = exception.InstanceInvalidState() - try: - common.raise_http_conflict_for_instance_invalid_state(exc, - 'meow') - except webob.exc.HTTPConflict as e: - self.assertEqual(unicode(e), - "Instance is in an invalid state for 'meow'") - else: - self.fail("webob.exc.HTTPConflict was not raised") - def test_check_img_metadata_properties_quota_valid_metadata(self): ctxt = test_utils.get_test_admin_context() metadata1 = {"key": "value"} diff --git a/nova/tests/compute/test_compute.py b/nova/tests/compute/test_compute.py index 8263529b1..8d9d9fadd 100644 --- a/nova/tests/compute/test_compute.py +++ b/nova/tests/compute/test_compute.py @@ -283,7 +283,7 @@ class ComputeTestCase(BaseTestCase): @compute_manager.wrap_instance_fault def failer(self2, context, instance_uuid): - raise exception.InstanceNotFound() + raise exception.InstanceNotFound(instance_id=instance_uuid) self.assertRaises(exception.InstanceNotFound, failer, self.compute, self.context, inst_uuid) @@ -618,7 +618,7 @@ class ComputeTestCase(BaseTestCase): instance = self._create_instance() def fake(*args, **kwargs): - raise exception.InstanceNotFound() + raise exception.InstanceNotFound(instance_id="fake") self.stubs.Set(self.compute.driver, 'spawn', fake) self.mox.StubOutWithMock(self.compute, '_deallocate_network') @@ -723,7 +723,9 @@ class ComputeTestCase(BaseTestCase): self.mox.StubOutWithMock(self.compute, '_get_instance_nw_info') self.compute._get_instance_nw_info( mox.IgnoreArg(), - mox.IgnoreArg()).AndRaise(exception.NetworkNotFound()) + mox.IgnoreArg()).AndRaise( + exception.NetworkNotFound(network_id='fake') + ) self.mox.ReplayAll() self.compute.terminate_instance(self.context, instance=instance) @@ -2790,7 +2792,7 @@ class ComputeTestCase(BaseTestCase): def fake_instance_get_by_uuid(context, instance_uuid): if instance_uuid not in instance_map: - raise exception.InstanceNotFound + raise exception.InstanceNotFound(instance_id=instance_uuid) call_info['get_by_uuid'] += 1 return instance_map[instance_uuid] @@ -4024,7 +4026,7 @@ class ComputeAPITestCase(BaseTestCase): """ def fake_show(*args): - raise exception.ImageNotFound + raise exception.ImageNotFound(image_id="fake") self.stubs.Set(fake_image._FakeImageService, 'show', fake_show) diff --git a/nova/tests/fake_network.py b/nova/tests/fake_network.py index f9cd459b1..896b11216 100644 --- a/nova/tests/fake_network.py +++ b/nova/tests/fake_network.py @@ -116,7 +116,7 @@ class FakeNetworkManager(network_manager.NetworkManager): dict(address='10.0.0.2')] def network_get_by_cidr(self, context, cidr): - raise exception.NetworkNotFoundForCidr() + raise exception.NetworkNotFoundForCidr(cidr=cidr) def network_create_safe(self, context, net): fakenet = dict(net) @@ -127,7 +127,7 @@ class FakeNetworkManager(network_manager.NetworkManager): return {'cidr_v6': '2001:db8:69:%x::/64' % network_id} def network_get_by_uuid(self, context, network_uuid): - raise exception.NetworkNotFoundForUUID() + raise exception.NetworkNotFoundForUUID(uuid=network_uuid) def network_get_all(self, context): raise exception.NoNetworksFound() diff --git a/nova/tests/network/test_api.py b/nova/tests/network/test_api.py index ef97a4982..3339764b5 100644 --- a/nova/tests/network/test_api.py +++ b/nova/tests/network/test_api.py @@ -152,7 +152,7 @@ class ApiTestCase(test.TestCase): def test_is_multi_host_instance_has_no_fixed_ip(self): def fake_fixed_ip_get_by_instance(ctxt, uuid): - raise exception.FixedIpNotFoundForInstance + raise exception.FixedIpNotFoundForInstance(instance_uuid=uuid) self.stubs.Set(self.network_api.db, 'fixed_ip_get_by_instance', fake_fixed_ip_get_by_instance) instance = {'uuid': FAKE_UUID} diff --git a/nova/tests/network/test_manager.py b/nova/tests/network/test_manager.py index c2aa1dbbb..e80ea3936 100644 --- a/nova/tests/network/test_manager.py +++ b/nova/tests/network/test_manager.py @@ -791,7 +791,7 @@ class VlanNetworkTestCase(test.TestCase): def fixed_ip_get(_context, fixed_ip_id): if fixed_ip_id == 1: return {'address': 'fakefixed'} - raise exception.FixedIpNotFound() + raise exception.FixedIpNotFound(id=fixed_ip_id) self.stubs.Set(self.network.db, 'fixed_ip_get', fixed_ip_get) self.mox.StubOutWithMock(self.network.l3driver, 'add_floating_ip') @@ -1482,7 +1482,9 @@ class CommonNetworkTestCase(test.TestCase): self.mox.StubOutWithMock(manager.db, 'network_get_by_uuid') manager.db.network_get_by_uuid( mox.IgnoreArg(), - mox.IgnoreArg()).AndRaise(exception.NetworkNotFoundForUUID) + mox.IgnoreArg()).AndRaise( + exception.NetworkNotFoundForUUID(uuid='fake') + ) self.mox.ReplayAll() uuid = 'eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee' self.assertRaises(exception.NetworkNotFound, @@ -1517,7 +1519,9 @@ class CommonNetworkTestCase(test.TestCase): self.mox.StubOutWithMock(manager.db, 'network_get_by_uuid') manager.db.network_get_by_uuid( mox.IgnoreArg(), - mox.IgnoreArg()).AndRaise(exception.NetworkNotFoundForUUID) + mox.IgnoreArg()).AndRaise( + exception.NetworkNotFoundForUUID(uuid='fake') + ) self.mox.ReplayAll() uuid = 'eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee' self.assertRaises(exception.NetworkNotFound, @@ -1940,7 +1944,7 @@ class FloatingIPTestCase(test.TestCase): self.mox.StubOutWithMock(self.network.db, 'floating_ip_get_by_address') self.network.db.floating_ip_get_by_address( self.context, '1.2.3.4').AndRaise( - exception.FloatingIpNotFoundForAddress) + exception.FloatingIpNotFoundForAddress(address='fake')) self.mox.ReplayAll() self.assertRaises(rpc_common.ClientException, self.network.deallocate_floating_ip, @@ -1951,7 +1955,7 @@ class FloatingIPTestCase(test.TestCase): self.mox.StubOutWithMock(self.network.db, 'floating_ip_get_by_address') self.network.db.floating_ip_get_by_address( self.context, '1.2.3.4').AndRaise( - exception.FloatingIpNotFoundForAddress) + exception.FloatingIpNotFoundForAddress(address='fake')) self.mox.ReplayAll() self.assertRaises(rpc_common.ClientException, self.network.associate_floating_ip, @@ -1962,7 +1966,7 @@ class FloatingIPTestCase(test.TestCase): self.mox.StubOutWithMock(self.network.db, 'floating_ip_get_by_address') self.network.db.floating_ip_get_by_address( self.context, '1.2.3.4').AndRaise( - exception.FloatingIpNotFoundForAddress) + exception.FloatingIpNotFoundForAddress(address='fake')) self.mox.ReplayAll() self.assertRaises(rpc_common.ClientException, self.network.disassociate_floating_ip, @@ -1972,7 +1976,7 @@ class FloatingIPTestCase(test.TestCase): """Ensure that FloatingIpNotFoundForAddress is wrapped""" self.mox.StubOutWithMock(self.network.db, 'floating_ip_get') self.network.db.floating_ip_get(self.context, 'fake-id').AndRaise( - exception.FloatingIpNotFound) + exception.FloatingIpNotFound(id='fake')) self.mox.ReplayAll() self.assertRaises(rpc_common.ClientException, self.network.get_floating_ip, diff --git a/nova/tests/test_exception.py b/nova/tests/test_exception.py index f7e4bc037..9e34f287c 100644 --- a/nova/tests/test_exception.py +++ b/nova/tests/test_exception.py @@ -117,8 +117,8 @@ class NovaExceptionTestCase(test.TestCase): class FakeNovaException(exception.NovaException): message = "default message: %(mispelled_code)s" - exc = FakeNovaException(code=500) - self.assertEquals(unicode(exc), 'default message: %(mispelled_code)s') + exc = FakeNovaException(code=500, mispelled_code='blah') + self.assertEquals(unicode(exc), 'default message: blah') def test_default_error_code(self): class FakeNovaException(exception.NovaException): diff --git a/nova/tests/test_libvirt.py b/nova/tests/test_libvirt.py index 3dfc0c2e9..fc8e01728 100644 --- a/nova/tests/test_libvirt.py +++ b/nova/tests/test_libvirt.py @@ -2036,7 +2036,9 @@ class LibvirtConnTestCase(test.TestCase): self.mox.StubOutWithMock(conn, '_compare_cpu') - conn._compare_cpu("asdf").AndRaise(exception.InvalidCPUInfo) + conn._compare_cpu("asdf").AndRaise(exception.InvalidCPUInfo( + reason='foo') + ) self.mox.ReplayAll() self.assertRaises(exception.InvalidCPUInfo, @@ -2628,7 +2630,7 @@ class LibvirtConnTestCase(test.TestCase): def test_immediate_delete(self): def fake_lookup_by_name(instance_name): - raise exception.InstanceNotFound() + raise exception.InstanceNotFound(instance_id=instance_name) conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False) self.stubs.Set(conn, '_lookup_by_name', fake_lookup_by_name) @@ -2731,7 +2733,7 @@ class LibvirtConnTestCase(test.TestCase): return mock def fake_get_info(instance_name): - raise exception.InstanceNotFound() + raise exception.InstanceNotFound(instance_id=instance_name) conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False) self.stubs.Set(conn, '_lookup_by_name', fake_lookup_by_name) @@ -2750,7 +2752,7 @@ class LibvirtConnTestCase(test.TestCase): self.stubs.Set(conn, 'list_instances', list_instances) def get_info(instance_name): - raise exception.InstanceNotFound() + raise exception.InstanceNotFound(instance_id='fake') self.stubs.Set(conn, 'get_instance_disk_info', get_info) result = conn.get_disk_available_least() diff --git a/nova/tests/test_misc.py b/nova/tests/test_misc.py index d815678f4..6732c4007 100644 --- a/nova/tests/test_misc.py +++ b/nova/tests/test_misc.py @@ -27,6 +27,8 @@ class ExceptionTestCase(test.TestCase): raise exc() def test_exceptions_raise(self): + # NOTE(dprince): disable format errors since we are not passing kwargs + self.flags(fatal_exception_format_errors=False) for name in dir(exception): exc = getattr(exception, name) if isinstance(exc, type): diff --git a/nova/tests/test_quota.py b/nova/tests/test_quota.py index a5a2539cd..50e5d6d8f 100644 --- a/nova/tests/test_quota.py +++ b/nova/tests/test_quota.py @@ -1315,7 +1315,7 @@ class DbQuotaDriverTestCase(test.TestCase): calls.append(('quota_usage_update', context, project_id, resource, kwargs)) if resource == 'nonexist': - raise exception.QuotaUsageNotFound() + raise exception.QuotaUsageNotFound(project_id=project_id) self.stubs.Set(db, 'quota_usage_update', fake_quota_usage_update) ctx = FakeContext('test_project', 'test_class') |