Fix 'project purge' deletes ALL images problem
Closes-Bug: #1717130 Change-Id: I33c6fc7897dfee85d1c197a1267bde4abfa5bbd9
This commit is contained in:
parent
953d74b5d6
commit
254dbf3294
@ -95,7 +95,14 @@ class ProjectPurge(command.Command):
|
||||
# images
|
||||
try:
|
||||
image_client = self.app.client_manager.image
|
||||
data = image_client.images.list(owner=project_id)
|
||||
api_version = int(image_client.version)
|
||||
if api_version == 1:
|
||||
data = image_client.images.list(owner=project_id)
|
||||
elif api_version == 2:
|
||||
kwargs = {'filters': {'owner': project_id}}
|
||||
data = image_client.images.list(**kwargs)
|
||||
else:
|
||||
raise NotImplementedError
|
||||
self.delete_objects(
|
||||
image_client.images.delete, data, 'image', dry_run)
|
||||
except Exception:
|
||||
|
@ -118,8 +118,8 @@ class TestProjectPurge(TestProjectPurgeInit):
|
||||
self.projects_mock.delete.assert_called_once_with(self.project.id)
|
||||
self.servers_mock.list.assert_called_once_with(
|
||||
search_opts={'tenant_id': self.project.id})
|
||||
self.images_mock.list.assert_called_once_with(
|
||||
owner=self.project.id)
|
||||
kwargs = {'filters': {'owner': self.project.id}}
|
||||
self.images_mock.list.assert_called_once_with(**kwargs)
|
||||
volume_search_opts = {'project_id': self.project.id}
|
||||
self.volumes_mock.list.assert_called_once_with(
|
||||
search_opts=volume_search_opts)
|
||||
@ -153,8 +153,8 @@ class TestProjectPurge(TestProjectPurgeInit):
|
||||
self.projects_mock.delete.assert_not_called()
|
||||
self.servers_mock.list.assert_called_once_with(
|
||||
search_opts={'tenant_id': self.project.id})
|
||||
self.images_mock.list.assert_called_once_with(
|
||||
owner=self.project.id)
|
||||
kwargs = {'filters': {'owner': self.project.id}}
|
||||
self.images_mock.list.assert_called_once_with(**kwargs)
|
||||
volume_search_opts = {'project_id': self.project.id}
|
||||
self.volumes_mock.list.assert_called_once_with(
|
||||
search_opts=volume_search_opts)
|
||||
@ -188,8 +188,8 @@ class TestProjectPurge(TestProjectPurgeInit):
|
||||
self.projects_mock.delete.assert_not_called()
|
||||
self.servers_mock.list.assert_called_once_with(
|
||||
search_opts={'tenant_id': self.project.id})
|
||||
self.images_mock.list.assert_called_once_with(
|
||||
owner=self.project.id)
|
||||
kwargs = {'filters': {'owner': self.project.id}}
|
||||
self.images_mock.list.assert_called_once_with(**kwargs)
|
||||
volume_search_opts = {'project_id': self.project.id}
|
||||
self.volumes_mock.list.assert_called_once_with(
|
||||
search_opts=volume_search_opts)
|
||||
@ -224,8 +224,8 @@ class TestProjectPurge(TestProjectPurgeInit):
|
||||
self.projects_mock.delete.assert_called_once_with(self.project.id)
|
||||
self.servers_mock.list.assert_called_once_with(
|
||||
search_opts={'tenant_id': self.project.id})
|
||||
self.images_mock.list.assert_called_once_with(
|
||||
owner=self.project.id)
|
||||
kwargs = {'filters': {'owner': self.project.id}}
|
||||
self.images_mock.list.assert_called_once_with(**kwargs)
|
||||
volume_search_opts = {'project_id': self.project.id}
|
||||
self.volumes_mock.list.assert_called_once_with(
|
||||
search_opts=volume_search_opts)
|
||||
@ -260,8 +260,8 @@ class TestProjectPurge(TestProjectPurgeInit):
|
||||
self.projects_mock.delete.assert_called_once_with(self.project.id)
|
||||
self.servers_mock.list.assert_called_once_with(
|
||||
search_opts={'tenant_id': self.project.id})
|
||||
self.images_mock.list.assert_called_once_with(
|
||||
owner=self.project.id)
|
||||
kwargs = {'filters': {'owner': self.project.id}}
|
||||
self.images_mock.list.assert_called_once_with(**kwargs)
|
||||
volume_search_opts = {'project_id': self.project.id}
|
||||
self.volumes_mock.list.assert_called_once_with(
|
||||
search_opts=volume_search_opts)
|
||||
@ -296,8 +296,8 @@ class TestProjectPurge(TestProjectPurgeInit):
|
||||
self.projects_mock.delete.assert_called_once_with(self.project.id)
|
||||
self.servers_mock.list.assert_called_once_with(
|
||||
search_opts={'tenant_id': self.project.id})
|
||||
self.images_mock.list.assert_called_once_with(
|
||||
owner=self.project.id)
|
||||
kwargs = {'filters': {'owner': self.project.id}}
|
||||
self.images_mock.list.assert_called_once_with(**kwargs)
|
||||
volume_search_opts = {'project_id': self.project.id}
|
||||
self.volumes_mock.list.assert_called_once_with(
|
||||
search_opts=volume_search_opts)
|
||||
|
@ -64,6 +64,7 @@ class FakeImagev1Client(object):
|
||||
self.images.resource_class = fakes.FakeResource(None, {})
|
||||
self.auth_token = kwargs['token']
|
||||
self.management_url = kwargs['endpoint']
|
||||
self.version = 1.0
|
||||
|
||||
|
||||
class TestImagev1(utils.TestCommand):
|
||||
|
@ -156,6 +156,7 @@ class FakeImagev2Client(object):
|
||||
self.image_tags.resource_class = fakes.FakeResource(None, {})
|
||||
self.auth_token = kwargs['token']
|
||||
self.management_url = kwargs['endpoint']
|
||||
self.version = 2.0
|
||||
|
||||
|
||||
class TestImagev2(utils.TestCommand):
|
||||
|
6
releasenotes/notes/bug-1717130-029211b60f74b4c4.yaml
Normal file
6
releasenotes/notes/bug-1717130-029211b60f74b4c4.yaml
Normal file
@ -0,0 +1,6 @@
|
||||
---
|
||||
fixes:
|
||||
- |
|
||||
Fix the ``project purge`` command to correctly delete only images owned by the
|
||||
specified project ID when run by an administrative user.
|
||||
[Bug `1717130 <https://bugs.launchpad.net/python-openstackclient/+bug/1717130>`_]
|
Loading…
Reference in New Issue
Block a user