diff --git a/openstack_dashboard/api/swift.py b/openstack_dashboard/api/swift.py index ec6d912d93..115ee46a0e 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 47bb9a2f74..58eea80e83 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 be00e0bdf2..c063db28ab 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 12636b2bc4..125e6cc509 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)