From 6cd537e2748fa636aa3061812b257d549a6d603f Mon Sep 17 00:00:00 2001 From: Brian Rosmaita Date: Thu, 22 Mar 2018 01:13:38 -0400 Subject: [PATCH] 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 Change-Id: Ic5c81916823ff32f2dbddd32b40e825de0697dc9 --- glanceclient/tests/unit/v2/test_shell_v2.py | 40 +++++++++++++++++++++ glanceclient/v2/shell.py | 2 +- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/glanceclient/tests/unit/v2/test_shell_v2.py b/glanceclient/tests/unit/v2/test_shell_v2.py index 10bf2150..c208f95d 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 2b833047..baf1754b 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():