From 1565819d597b1abbd3934c6b2ec3d4e10a4a0549 Mon Sep 17 00:00:00 2001 From: Masco Kaliyamoorthy Date: Thu, 11 Sep 2014 17:21:46 +0530 Subject: [PATCH] wrong message while deleting non empty pseudo folder while try to delete a pseudo folder which contains some objects is showing the success message but the folder is not actually deleted added a check similar to delete container, the new check will verify the pseudo folder is empty before call the swift client call. if the folder is not empty it will throw a exception with a appropriate error message and the message will be shown to the user in the pop up message box. Change-Id: I0bbea6ef6ac26ef357240610535b9d84053a89c2 Closes-Bug: #1347598 --- openstack_dashboard/api/swift.py | 19 +++++++++++++++++-- .../dashboards/project/containers/tests.py | 2 +- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/openstack_dashboard/api/swift.py b/openstack_dashboard/api/swift.py index b822560ea1..ee8064f4b7 100644 --- a/openstack_dashboard/api/swift.py +++ b/openstack_dashboard/api/swift.py @@ -197,8 +197,8 @@ def swift_delete_container(request, name): # be done in swiftclient instead of Horizon. objects, more = swift_get_objects(request, name) if objects: - error_msg = unicode(_("The container cannot be deleted " - "since it's not empty.")) + error_msg = _("The container cannot be deleted " + "since it is not empty.") exc = exceptions.Conflict(error_msg) exc._safe_message = error_msg raise exc @@ -304,6 +304,21 @@ def swift_create_pseudo_folder(request, container_name, pseudo_folder_name): def swift_delete_object(request, container_name, object_name): + objects, more = swift_get_objects(request, container_name, + prefix=object_name) + # In case the given object is pseudo folder, + # it can be deleted only if it is empty. + # swift_get_objects will return at least + # one object (i.e container_name) even if the + # given pseudo folder is empty. So if swift_get_objects + # returns more than one object then only it will be + # considered as non empty folder. + if len(objects) > 1: + error_msg = _("The pseudo folder cannot be deleted " + "since it is not empty.") + exc = exceptions.Conflict(error_msg) + exc._safe_message = error_msg + raise exc swift_api(request).delete_object(container_name, object_name) return True diff --git a/openstack_dashboard/dashboards/project/containers/tests.py b/openstack_dashboard/dashboards/project/containers/tests.py index e3b161b1a3..73adde730c 100644 --- a/openstack_dashboard/dashboards/project/containers/tests.py +++ b/openstack_dashboard/dashboards/project/containers/tests.py @@ -94,7 +94,7 @@ class SwiftTests(test.TestCase): self.assertEqual(unicode(list(req._messages)[0].message), u"The container cannot be deleted " - u"since it's not empty.") + u"since it is not empty.") def test_create_container_get(self): res = self.client.get(reverse('horizon:project:containers:create'))