From 22e8f839d198b6930faa2759c136f3b279010fd8 Mon Sep 17 00:00:00 2001 From: Lin Hua Cheng Date: Tue, 8 Oct 2013 14:08:38 -0700 Subject: [PATCH] Use HEAD when retrieving Container details Change-Id: I0bb41bbf2ec8b0a515aa8a9ee9eba63761a60122 Closes-bug: 1236677 --- openstack_dashboard/api/swift.py | 9 +++++-- .../dashboards/project/containers/tests.py | 3 ++- .../dashboards/project/containers/views.py | 3 ++- .../test/api_tests/swift_tests.py | 24 +++++++++++++++++++ 4 files changed, 35 insertions(+), 4 deletions(-) diff --git a/openstack_dashboard/api/swift.py b/openstack_dashboard/api/swift.py index 5a331829c0..55d99d78be 100644 --- a/openstack_dashboard/api/swift.py +++ b/openstack_dashboard/api/swift.py @@ -132,8 +132,12 @@ def swift_get_containers(request, marker=None): return (container_objs, False) -def swift_get_container(request, container_name): - headers, data = swift_api(request).get_object(container_name, "") +def swift_get_container(request, container_name, with_data=True): + if with_data: + headers, data = swift_api(request).get_object(container_name, "") + else: + data = None + headers = swift_api(request).head_container(container_name) timestamp = None try: ts_float = float(headers.get('x-timestamp')) @@ -145,6 +149,7 @@ def swift_get_container(request, container_name): 'container_object_count': headers.get('x-container-object-count'), 'container_bytes_used': headers.get('x-container-bytes-used'), 'timestamp': timestamp, + 'data': data, } return Container(container_info) diff --git a/openstack_dashboard/dashboards/project/containers/tests.py b/openstack_dashboard/dashboards/project/containers/tests.py index b5a575270a..840e4b9428 100644 --- a/openstack_dashboard/dashboards/project/containers/tests.py +++ b/openstack_dashboard/dashboards/project/containers/tests.py @@ -236,7 +236,8 @@ class SwiftTests(test.TestCase): container = self.containers.first() api.swift.swift_get_container(IsA(http.HttpRequest), - container.name) \ + container.name, + with_data=False) \ .AndReturn(container) self.mox.ReplayAll() diff --git a/openstack_dashboard/dashboards/project/containers/views.py b/openstack_dashboard/dashboards/project/containers/views.py index 2fa1285892..45adc3f53a 100644 --- a/openstack_dashboard/dashboards/project/containers/views.py +++ b/openstack_dashboard/dashboards/project/containers/views.py @@ -234,7 +234,8 @@ class ContainerDetailView(forms.ModalFormMixin, generic.TemplateView): try: self._object = api.swift.swift_get_container( self.request, - self.kwargs["container_name"]) + self.kwargs["container_name"], + with_data=False) except Exception: redirect = reverse("horizon:project:containers:index") exceptions.handle(self.request, diff --git a/openstack_dashboard/test/api_tests/swift_tests.py b/openstack_dashboard/test/api_tests/swift_tests.py index 18b7f23fca..6c7361d789 100644 --- a/openstack_dashboard/test/api_tests/swift_tests.py +++ b/openstack_dashboard/test/api_tests/swift_tests.py @@ -42,6 +42,30 @@ class SwiftApiTests(test.APITestCase): self.assertEqual(len(conts), len(containers)) self.assertFalse(more) + def test_swift_get_container_with_data(self): + container = self.containers.first() + objects = self.objects.list() + swift_api = self.stub_swiftclient() + swift_api.get_object(container.name, "") \ + .AndReturn((container, objects)) + self.mox.ReplayAll() + + cont = api.swift.swift_get_container(self.request, container.name) + self.assertEqual(cont.name, container.name) + self.assertEqual(len(cont.data), len(objects)) + + def test_swift_get_container_without_data(self): + container = self.containers.first() + swift_api = self.stub_swiftclient() + swift_api.head_container(container.name).AndReturn(container) + self.mox.ReplayAll() + + cont = api.swift.swift_get_container(self.request, + container.name, + with_data=False) + self.assertEqual(cont.name, container.name) + self.assertIsNone(cont.data) + def test_swift_create_duplicate_container(self): container = self.containers.first() swift_api = self.stub_swiftclient(expected_calls=2)