Skip to content

Commit f4c4a73

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Fix openstack image import --method web-download --uri 'invalid value'"
2 parents d5e6392 + 9ad18c4 commit f4c4a73

2 files changed

Lines changed: 37 additions & 0 deletions

File tree

openstackclient/image/v2/image.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import os
2323
import sys
2424
import typing as ty
25+
import urllib.parse
2526

2627
from openstack import exceptions as sdk_exceptions
2728
from openstack.image import image_signer
@@ -1744,6 +1745,12 @@ def take_action(self, parsed_args):
17441745
"'--method=web-download'"
17451746
)
17461747
raise exceptions.CommandError(msg)
1748+
_parsed = urllib.parse.urlparse(parsed_args.uri)
1749+
if not all({_parsed.scheme, _parsed.netloc}):
1750+
msg = _("'%(uri)s' is not a valid url")
1751+
raise exceptions.CommandError(
1752+
msg % {'uri': parsed_args.uri},
1753+
)
17471754
else:
17481755
if parsed_args.uri:
17491756
msg = _(

openstackclient/tests/unit/image/v2/test_image.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2039,6 +2039,36 @@ def test_import_image__web_download_invalid_options(self):
20392039

20402040
self.image_client.import_image.assert_not_called()
20412041

2042+
def test_import_image__web_download_invalid_url(self):
2043+
arglist = [
2044+
self.image.name,
2045+
'--method',
2046+
'web-download',
2047+
'--uri',
2048+
'invalid:1234',
2049+
]
2050+
2051+
verifylist = [
2052+
('image', self.image.name),
2053+
('import_method', 'web-download'),
2054+
('uri', 'invalid:1234'),
2055+
]
2056+
2057+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
2058+
2059+
exc = self.assertRaises(
2060+
exceptions.CommandError,
2061+
self.cmd.take_action,
2062+
parsed_args,
2063+
)
2064+
2065+
self.assertIn(
2066+
"'invalid:1234' is not a valid url",
2067+
str(exc),
2068+
)
2069+
2070+
self.image_client.import_image.assert_not_called()
2071+
20422072
def test_import_image__web_download_invalid_image_state(self):
20432073
self.image.status = 'uploading' # != 'queued'
20442074
arglist = [

0 commit comments

Comments
 (0)