summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Burke <tim.burke@gmail.com>2016-01-18 14:54:10 -0800
committerTim Burke <tim.burke@gmail.com>2016-02-10 13:25:38 -0800
commit30ca247426c0cc9b64e8b12fbe2b68db8ef5517e (patch)
tree3331c2661cc95ec19126d212cd8d55f44f5a134f
parent8918c292d7def6d4218f2abfc9e68133c2e6f88e (diff)
downloadpython-swiftclient-30ca247426c0cc9b64e8b12fbe2b68db8ef5517e.tar.gz
Display proper name when failing to create segments container
Previously, we displayed the base container's name. Change-Id: I70f1949a44ba61158e31178e4536f229c37aab47
-rwxr-xr-xswiftclient/shell.py2
-rw-r--r--tests/unit/test_shell.py48
2 files changed, 49 insertions, 1 deletions
diff --git a/swiftclient/shell.py b/swiftclient/shell.py
index e427a89..75150ea 100755
--- a/swiftclient/shell.py
+++ b/swiftclient/shell.py
@@ -938,7 +938,7 @@ def st_upload(parser, args, output_manager):
msg = ': %s' % error
output_manager.warning(
'Warning: failed to create container '
- "'%s'%s", container, msg
+ "'%s'%s", r['container'], msg
)
else:
output_manager.error("%s" % error)
diff --git a/tests/unit/test_shell.py b/tests/unit/test_shell.py
index d6e9b1e..d61593a 100644
--- a/tests/unit/test_shell.py
+++ b/tests/unit/test_shell.py
@@ -581,6 +581,7 @@ class TestShell(testtools.TestCase):
upload.return_value = [
{"success": False,
"headers": {},
+ "container": 'container',
"action": 'create_container',
"error": swiftclient.ClientException(
'Container PUT failed',
@@ -2156,6 +2157,53 @@ class TestCrossAccountObjectAccess(TestBase, MockHttpTest):
% self.cont
self.assertEqual(expected_err, out.err.strip())
+ def test_segment_upload_with_write_only_access_segments_container(self):
+ fake_conn = self.fake_http_connection(
+ 403, # PUT c1
+ # HEAD c1 to get storage policy
+ StubResponse(200, headers={'X-Storage-Policy': 'foo'}),
+ 403, # PUT c1_segments
+ 201, # PUT c1_segments/...00
+ 201, # PUT c1_segments/...01
+ 201, # PUT c1/...
+ )
+
+ args, env = self._make_cmd('upload',
+ cmd_args=[self.cont, self.obj,
+ '--leave-segments',
+ '--segment-size=10'])
+ with mock.patch('swiftclient.client._import_keystone_client',
+ self.fake_ks_import):
+ with mock.patch('swiftclient.client.http_connection', fake_conn):
+ with mock.patch.dict(os.environ, env):
+ with CaptureOutput() as out:
+ try:
+ swiftclient.shell.main(args)
+ except SystemExit as e:
+ self.fail('Unexpected SystemExit: %s' % e)
+
+ segment_time = getmtime(self.obj)
+ segment_path_0 = '%s_segments%s/%f/20/10/00000000' % (
+ self.cont_path, self.obj, segment_time)
+ segment_path_1 = '%s_segments%s/%f/20/10/00000001' % (
+ self.cont_path, self.obj, segment_time)
+ # Note that the order of segment PUTs cannot be asserted, so test for
+ # existence in request log individually
+ self.assert_request(('PUT', self.cont_path))
+ self.assert_request(('PUT', self.cont_path + '_segments', '', {
+ 'X-Auth-Token': 'bob_token',
+ 'X-Storage-Policy': 'foo',
+ 'Content-Length': '0',
+ }))
+ self.assert_request(('PUT', segment_path_0))
+ self.assert_request(('PUT', segment_path_1))
+ self.assert_request(('PUT', self.obj_path))
+ self.assertTrue(self.obj[1:] in out.out)
+ expected_err = ("Warning: failed to create container '%s': 403 Fake\n"
+ "Warning: failed to create container '%s': 403 Fake"
+ ) % (self.cont, self.cont + '_segments')
+ self.assertEqual(expected_err, out.err.strip())
+
def test_upload_with_no_access(self):
fake_conn = self.fake_http_connection(403, 403)