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 6cd537e274)
This commit is contained in:
Brian Rosmaita 2018-03-22 01:13:38 -04:00
parent bb54656368
commit 91c19ddddd
2 changed files with 41 additions and 1 deletions

View File

@ -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,

View File

@ -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():