Skip to content

Commit 388bbba

Browse files
author
Steve Martinelli
committed
Fix issues with object related commands
1) Can't create instance of swiftclient. Since we now create an API instance, creating a swiftclient instance won't work. Trying to do any object related command fails. 2) Listing objects in a container fails, we depend on the data returned in a specific way, during the API transition this must have slipped through. Needs regression/funcitonal tests to mame sure this doesn't happen again. Change-Id: I69079a0dc9f32b84e6f9307729d3dbbba549ac5e
1 parent 0cb204e commit 388bbba

3 files changed

Lines changed: 94 additions & 8 deletions

File tree

functional/tests/test_object.py

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
2+
# not use this file except in compliance with the License. You may obtain
3+
# a copy of the License at
4+
#
5+
# http://www.apache.org/licenses/LICENSE-2.0
6+
#
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10+
# License for the specific language governing permissions and limitations
11+
# under the License.
12+
13+
import uuid
14+
15+
from functional.common import test
16+
17+
BASIC_LIST_HEADERS = ['Name']
18+
CONTAINER_FIELDS = ['account', 'container', 'x-trans-id']
19+
OBJECT_FIELDS = ['object', 'container', 'etag']
20+
21+
22+
class ObjectV1Tests(test.TestCase):
23+
"""Functional tests for Object V1 commands. """
24+
25+
CONTAINER_NAME = uuid.uuid4().hex
26+
OBJECT_NAME = uuid.uuid4().hex
27+
28+
# NOTE(stevemar): Not using setUp since we only want this to run once
29+
with open(OBJECT_NAME, 'w') as f:
30+
f.write('test content')
31+
32+
def test_container_create(self):
33+
raw_output = self.openstack('container create ' + self.CONTAINER_NAME)
34+
items = self.parse_listing(raw_output)
35+
self.assert_show_fields(items, CONTAINER_FIELDS)
36+
37+
def test_container_delete(self):
38+
container_tmp = uuid.uuid4().hex
39+
self.openstack('container create ' + container_tmp)
40+
raw_output = self.openstack('container delete ' + container_tmp)
41+
self.assertEqual(0, len(raw_output))
42+
43+
def test_container_list(self):
44+
raw_output = self.openstack('container list')
45+
items = self.parse_listing(raw_output)
46+
self.assert_table_structure(items, BASIC_LIST_HEADERS)
47+
48+
def test_container_show(self):
49+
self.openstack('container show ' + self.CONTAINER_NAME)
50+
# TODO(stevemar): Assert returned fields
51+
52+
def test_container_save(self):
53+
self.openstack('container save ' + self.CONTAINER_NAME)
54+
# TODO(stevemar): Assert returned fields
55+
56+
def test_object_create(self):
57+
raw_output = self.openstack('object create ' + self.CONTAINER_NAME
58+
+ ' ' + self.OBJECT_NAME)
59+
items = self.parse_listing(raw_output)
60+
self.assert_show_fields(items, OBJECT_FIELDS)
61+
62+
def test_object_delete(self):
63+
raw_output = self.openstack('object delete ' + self.CONTAINER_NAME
64+
+ ' ' + self.OBJECT_NAME)
65+
self.assertEqual(0, len(raw_output))
66+
67+
def test_object_list(self):
68+
raw_output = self.openstack('object list ' + self.CONTAINER_NAME)
69+
items = self.parse_listing(raw_output)
70+
self.assert_table_structure(items, BASIC_LIST_HEADERS)
71+
72+
def test_object_save(self):
73+
self.openstack('object create ' + self.CONTAINER_NAME
74+
+ ' ' + self.OBJECT_NAME)
75+
self.openstack('object save ' + self.CONTAINER_NAME
76+
+ ' ' + self.OBJECT_NAME)
77+
# TODO(stevemar): Assert returned fields
78+
79+
def test_object_save_with_filename(self):
80+
self.openstack('object create ' + self.CONTAINER_NAME
81+
+ ' ' + self.OBJECT_NAME)
82+
self.openstack('object save ' + self.CONTAINER_NAME
83+
+ ' ' + self.OBJECT_NAME + ' --file tmp.txt')
84+
# TODO(stevemar): Assert returned fields
85+
86+
def test_object_show(self):
87+
self.openstack('object create ' + self.CONTAINER_NAME
88+
+ ' ' + self.OBJECT_NAME)
89+
self.openstack('object show ' + self.CONTAINER_NAME
90+
+ ' ' + self.OBJECT_NAME)
91+
# TODO(stevemar): Assert returned fields

openstackclient/api/object_store_v1.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ def object_list(
252252
if container is None or object is None:
253253
return None
254254

255+
params['format'] = 'json'
255256
if all_data:
256257
data = listing = self.object_list(
257258
container=container,
@@ -280,7 +281,6 @@ def object_list(
280281
data.extend(listing)
281282
return data
282283

283-
params = {}
284284
if limit:
285285
params['limit'] = limit
286286
if marker:
@@ -320,7 +320,8 @@ def object_save(
320320
)
321321
if response.status_code == 200:
322322
if not os.path.exists(os.path.dirname(file)):
323-
os.makedirs(os.path.dirname(file))
323+
if len(os.path.dirname(file)) > 0:
324+
os.makedirs(os.path.dirname(file))
324325
with open(file, 'wb') as f:
325326
for chunk in response.iter_content():
326327
f.write(chunk)

openstackclient/object/client.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,6 @@
3333
def make_client(instance):
3434
"""Returns an object-store API client."""
3535

36-
object_client = utils.get_client_class(
37-
API_NAME,
38-
instance._api_version[API_NAME],
39-
API_VERSIONS)
40-
LOG.debug('Instantiating object client: %s', object_client)
41-
4236
if instance._url:
4337
endpoint = instance._url
4438
else:

0 commit comments

Comments
 (0)