Merge "Fix openstack image import --method web-download --uri 'invalid value'"
This commit is contained in:
@@ -22,6 +22,7 @@ import logging
|
|||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import typing as ty
|
import typing as ty
|
||||||
|
import urllib.parse
|
||||||
|
|
||||||
from openstack import exceptions as sdk_exceptions
|
from openstack import exceptions as sdk_exceptions
|
||||||
from openstack.image import image_signer
|
from openstack.image import image_signer
|
||||||
@@ -1744,6 +1745,12 @@ class ImportImage(command.ShowOne):
|
|||||||
"'--method=web-download'"
|
"'--method=web-download'"
|
||||||
)
|
)
|
||||||
raise exceptions.CommandError(msg)
|
raise exceptions.CommandError(msg)
|
||||||
|
_parsed = urllib.parse.urlparse(parsed_args.uri)
|
||||||
|
if not all({_parsed.scheme, _parsed.netloc}):
|
||||||
|
msg = _("'%(uri)s' is not a valid url")
|
||||||
|
raise exceptions.CommandError(
|
||||||
|
msg % {'uri': parsed_args.uri},
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
if parsed_args.uri:
|
if parsed_args.uri:
|
||||||
msg = _(
|
msg = _(
|
||||||
|
@@ -2039,6 +2039,36 @@ class TestImageImport(TestImage):
|
|||||||
|
|
||||||
self.image_client.import_image.assert_not_called()
|
self.image_client.import_image.assert_not_called()
|
||||||
|
|
||||||
|
def test_import_image__web_download_invalid_url(self):
|
||||||
|
arglist = [
|
||||||
|
self.image.name,
|
||||||
|
'--method',
|
||||||
|
'web-download',
|
||||||
|
'--uri',
|
||||||
|
'invalid:1234',
|
||||||
|
]
|
||||||
|
|
||||||
|
verifylist = [
|
||||||
|
('image', self.image.name),
|
||||||
|
('import_method', 'web-download'),
|
||||||
|
('uri', 'invalid:1234'),
|
||||||
|
]
|
||||||
|
|
||||||
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
|
|
||||||
|
exc = self.assertRaises(
|
||||||
|
exceptions.CommandError,
|
||||||
|
self.cmd.take_action,
|
||||||
|
parsed_args,
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertIn(
|
||||||
|
"'invalid:1234' is not a valid url",
|
||||||
|
str(exc),
|
||||||
|
)
|
||||||
|
|
||||||
|
self.image_client.import_image.assert_not_called()
|
||||||
|
|
||||||
def test_import_image__web_download_invalid_image_state(self):
|
def test_import_image__web_download_invalid_image_state(self):
|
||||||
self.image.status = 'uploading' # != 'queued'
|
self.image.status = 'uploading' # != 'queued'
|
||||||
arglist = [
|
arglist = [
|
||||||
|
Reference in New Issue
Block a user