diff options
author | Hans Lindgren <hanlind@kth.se> | 2015-11-09 19:29:20 +0100 |
---|---|---|
committer | Hans Lindgren <hanlind@kth.se> | 2016-05-19 16:05:19 +0200 |
commit | 43e6a067184127c7f5ab9bfb67c07430f2c7fd14 (patch) | |
tree | 2a94d6995b712248245116327cf68ea4cfbfaf0c /nova/tests/unit/objects/test_flavor.py | |
parent | fe8a119e8d80de35d7f99e0c1d9a9e5095840146 (diff) | |
download | nova-43e6a067184127c7f5ab9bfb67c07430f2c7fd14.tar.gz |
Make flavor-manage api call destroy with Flavor object
The flavor-manage api delete command currently need 3 separate db calls
to remove a flavor from the db. This is due to the use of flavor name to
identify the db flavor when the api command itself take flavorid as
input.
This change reworks this to only issue a single db call that now use
flavorid all way through to the db. It also gets rid of the in between
flavors module by calling destroy on a Flavor object right from the api.
Additional test changes are made to similarily bypass the flavors module
and instead call destroy() directly on the Flavor objects so the flavors
method becomes unused and thus can be removed.
Change-Id: I62bc11887283201be0bcdcfe9fa58b3f6156c754
Diffstat (limited to 'nova/tests/unit/objects/test_flavor.py')
-rw-r--r-- | nova/tests/unit/objects/test_flavor.py | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/nova/tests/unit/objects/test_flavor.py b/nova/tests/unit/objects/test_flavor.py index cffad0f2ee..408ae0499c 100644 --- a/nova/tests/unit/objects/test_flavor.py +++ b/nova/tests/unit/objects/test_flavor.py @@ -353,11 +353,13 @@ class _TestFlavor(object): flavor = flavor_obj.Flavor(id=123) self.assertRaises(exception.ObjectActionError, flavor.save) - def test_destroy(self): - flavor = flavor_obj.Flavor(context=self.context, name='foo') + @mock.patch('nova.objects.Flavor._flavor_destroy') + def test_destroy(self, mock_destroy): + mock_destroy.side_effect = exception.FlavorNotFound(flavor_id='foo') + flavor = flavor_obj.Flavor(context=self.context, flavorid='foo') with mock.patch.object(db, 'flavor_destroy') as destroy: flavor.destroy() - destroy.assert_called_once_with(self.context, flavor.name) + destroy.assert_called_once_with(self.context, flavor.flavorid) @mock.patch('nova.objects.Flavor._flavor_destroy') def test_destroy_api_by_id(self, mock_destroy): @@ -366,10 +368,11 @@ class _TestFlavor(object): mock_destroy.assert_called_once_with(self.context, flavor_id=flavor.id) @mock.patch('nova.objects.Flavor._flavor_destroy') - def test_destroy_api_by_name(self, mock_destroy): - flavor = flavor_obj.Flavor(context=self.context, name='foo') + def test_destroy_api_by_flavorid(self, mock_destroy): + flavor = flavor_obj.Flavor(context=self.context, flavorid='foo') flavor.destroy() - mock_destroy.assert_called_once_with(self.context, name=flavor.name) + mock_destroy.assert_called_once_with(self.context, + flavorid=flavor.flavorid) def test_load_projects(self): flavor = flavor_obj.Flavor(context=self.context, flavorid='foo') |