summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Rosmaita <rosmaita.fossdev@gmail.com>2018-03-22 01:13:38 -0400
committerBrian Rosmaita <rosmaita.fossdev@gmail.com>2018-03-23 18:56:53 +0000
commit91c19dddddd6b7ba4a9c3ab6ec23cab64b481c3c (patch)
treec2ea601b2990f9b0510c812eb28c4a6ad2ee9210
parentbb5465636880af6aec4926fb32fc3dd1c8e80be5 (diff)
downloadpython-glanceclient-91c19dddddd6b7ba4a9c3ab6ec23cab64b481c3c.tar.gz
Check for container,disk_format on web-download
Fail image-create-via-import requests for the web-download import method that don't include values for container_format or disk_format. Closes-bug: #1757927 Depends-on: I0e1d18844f64723608288de473e97710798eb602 Change-Id: Ic5c81916823ff32f2dbddd32b40e825de0697dc9 (cherry picked from commit 6cd537e2748fa636aa3061812b257d549a6d603f)
-rw-r--r--glanceclient/tests/unit/v2/test_shell_v2.py40
-rw-r--r--glanceclient/v2/shell.py2
2 files changed, 41 insertions, 1 deletions
diff --git a/glanceclient/tests/unit/v2/test_shell_v2.py b/glanceclient/tests/unit/v2/test_shell_v2.py
index d75613f..064f5d9 100644
--- a/glanceclient/tests/unit/v2/test_shell_v2.py
+++ b/glanceclient/tests/unit/v2/test_shell_v2.py
@@ -157,6 +157,46 @@ class ShellV2Test(testtools.TestCase):
self.assertEqual('error: Must provide --disk-format when using stdin.',
e.message)
+ @mock.patch('sys.stderr')
+ def test_create_via_import_glance_direct_missing_disk_format(self, __):
+ e = self.assertRaises(exc.CommandError, self._run_command,
+ '--os-image-api-version 2 '
+ 'image-create-via-import '
+ '--file fake_src --container-format bare')
+ self.assertEqual('error: Must provide --disk-format when using '
+ '--file.', e.message)
+
+ @mock.patch('sys.stderr')
+ def test_create_via_import_glance_direct_missing_container_format(
+ self, __):
+ e = self.assertRaises(exc.CommandError, self._run_command,
+ '--os-image-api-version 2 '
+ 'image-create-via-import '
+ '--file fake_src --disk-format qcow2')
+ self.assertEqual('error: Must provide --container-format when '
+ 'using --file.', e.message)
+
+ @mock.patch('sys.stderr')
+ def test_create_via_import_web_download_missing_disk_format(self, __):
+ e = self.assertRaises(exc.CommandError, self._run_command,
+ '--os-image-api-version 2 '
+ 'image-create-via-import ' +
+ '--import-method web-download ' +
+ '--uri fake_uri --container-format bare')
+ self.assertEqual('error: Must provide --disk-format when using '
+ '--uri.', e.message)
+
+ @mock.patch('sys.stderr')
+ def test_create_via_import_web_download_missing_container_format(
+ self, __):
+ e = self.assertRaises(exc.CommandError, self._run_command,
+ '--os-image-api-version 2 '
+ 'image-create-via-import '
+ '--import-method web-download '
+ '--uri fake_uri --disk-format qcow2')
+ self.assertEqual('error: Must provide --container-format when '
+ 'using --uri.', e.message)
+
def test_do_image_list(self):
input = {
'limit': None,
diff --git a/glanceclient/v2/shell.py b/glanceclient/v2/shell.py
index c9f1fe1..4f358bc 100644
--- a/glanceclient/v2/shell.py
+++ b/glanceclient/v2/shell.py
@@ -30,7 +30,7 @@ import os
MEMBER_STATUS_VALUES = image_members.MEMBER_STATUS_VALUES
IMAGE_SCHEMA = None
-DATA_FIELDS = ('location', 'copy_from', 'file')
+DATA_FIELDS = ('location', 'copy_from', 'file', 'uri')
def get_image_schema():