Shows a warning message when deleting a container that contains data.

We cannot delete objects in the container since there may be millions
of objects in that. The batch deletion should be done in swift instead
of Horizon. The batch remove of objects function is only in swift CLI
command now. This commit replace the unclear message with a warning
message that tells the user the container is not empy.

Related bug: https://bugs.launchpad.net/horizon/+bug/1034890

Fixes bug: #1096084

Change-Id: I59b46a3535b8654734c3dae4eec916ab1b53c716
This commit is contained in:
Brooklyn Chen 2013-05-19 18:31:50 +08:00
parent d17fd51359
commit eae19c1a7c
2 changed files with 17 additions and 6 deletions

View File

@ -25,6 +25,8 @@ import swiftclient
from django.conf import settings
from horizon import exceptions
from horizon import messages
from django.utils.translation import ugettext_lazy as _
from openstack_dashboard.api.base import url_for, APIDictWrapper
@ -135,6 +137,13 @@ def swift_create_container(request, name):
def swift_delete_container(request, name):
# It cannot be deleted if it's not empty. The batch remove of objects
# be done in swiftclient instead of Horizon.
objects, more = swift_get_objects(request, name)
if objects:
messages.warning(request,
_("The container cannot be deleted since it's not empty."))
return False
swift_api(request).delete_container(name)
return True

View File

@ -50,7 +50,7 @@ class SwiftTests(test.TestCase):
resp_containers = res.context['table'].data
self.assertEqual(len(resp_containers), len(containers))
@test.create_stubs({api.swift: ('swift_delete_container',)})
@test.create_stubs({api.swift: ('swift_delete_container', )})
def test_delete_container(self):
container = self.containers.get(name=u"container_two\u6346")
api.swift.swift_delete_container(IsA(http.HttpRequest), container.name)
@ -63,13 +63,12 @@ class SwiftTests(test.TestCase):
handled = table.maybe_handle()
self.assertEqual(handled['location'], CONTAINER_INDEX_URL)
@test.create_stubs({api.swift: ('swift_delete_container',)})
@test.create_stubs({api.swift: ('swift_get_objects', )})
def test_delete_container_nonempty(self):
container = self.containers.first()
exc = self.exceptions.swift
exc.silence_logging = True
api.swift.swift_delete_container(IsA(http.HttpRequest),
container.name).AndRaise(exc)
objects = self.objects.list()
api.swift.swift_get_objects(IsA(http.HttpRequest),
container.name).AndReturn([objects, False])
self.mox.ReplayAll()
action_string = u"containers__delete__%s" % container.name
@ -78,6 +77,9 @@ class SwiftTests(test.TestCase):
table = ContainersTable(req, self.containers.list())
handled = table.maybe_handle()
self.assertEqual(handled['location'], CONTAINER_INDEX_URL)
self.assertEqual(unicode(list(req._messages)[0].message),
u"The container cannot be deleted "
u"since it's not empty.")
def test_create_container_get(self):
res = self.client.get(reverse('horizon:project:containers:create'))