summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCyril Roelandt <cyril@redhat.com>2023-04-18 02:40:54 +0200
committerCyril Roelandt <cyril@redhat.com>2023-04-18 03:21:03 +0200
commite2190c4feb7b237c55a5d7df49e0db340a9d342f (patch)
treefe15738197436b6f935329458c6d2d07cbf34ca5
parent52fb6b29d84644c690c0b8566117c4bfb963b09b (diff)
downloadpython-glanceclient-e2190c4feb7b237c55a5d7df49e0db340a9d342f.tar.gz
do_image_import: fix argument retrieval
The argparse module automatically replaces '-' characters with '_' characters when converting an option string to an attribute: «For optional argument actions, the value of dest is normally inferred from the option strings. ArgumentParser generates the value of dest by taking the first long option string and stripping away the initial -- string. If no long option strings were supplied, dest will be derived from the first short option string by stripping the initial - character. Any internal - characters will be converted to _ characters to make sure the string is a valid attribute name.»[1] This means that the value of the "--remote-region" option of the "image-import" command will be available as "args.remote_region"; "remote-region" would not be a valid attribute anyway. We make sure to retrieve the proper value for the following options: --remote-region, --remote-image-id and --remote-service-interface. [1] https://docs.python.org/3/library/argparse.html#dest Change-Id: I1d8c69acd5d61fdc426469cd87d1ace81871e60f Partial-Bug: #2012442
-rw-r--r--glanceclient/tests/unit/v2/test_shell_v2.py6
-rw-r--r--glanceclient/v2/shell.py6
2 files changed, 6 insertions, 6 deletions
diff --git a/glanceclient/tests/unit/v2/test_shell_v2.py b/glanceclient/tests/unit/v2/test_shell_v2.py
index 8acceae..b2a6415 100644
--- a/glanceclient/tests/unit/v2/test_shell_v2.py
+++ b/glanceclient/tests/unit/v2/test_shell_v2.py
@@ -2240,10 +2240,10 @@ class ShellV2Test(testtools.TestCase):
def test_image_import_glance_download(self):
args = self._make_args(
- {'id': 'IMG-01', 'uri': None, 'remote-region': 'REGION2',
- 'remote-image-id': 'IMG-02',
+ {'id': 'IMG-01', 'uri': None, 'remote_region': 'REGION2',
+ 'remote_image_id': 'IMG-02',
'import_method': 'glance-download',
- 'remote-service-interface': 'public'})
+ 'remote_service_interface': 'public'})
with mock.patch.object(self.gc.images, 'image_import') as mock_import:
with mock.patch.object(self.gc.images, 'get') as mocked_get:
with mock.patch.object(self.gc.images,
diff --git a/glanceclient/v2/shell.py b/glanceclient/v2/shell.py
index 93a9377..3b5b248 100644
--- a/glanceclient/v2/shell.py
+++ b/glanceclient/v2/shell.py
@@ -778,9 +778,9 @@ def do_image_import(gc, args):
all_stores = getattr(args, "os_all_stores", None)
allow_failure = getattr(args, "os_allow_failure", True)
uri = getattr(args, "uri", None)
- remote_region = getattr(args, "remote-region", None)
- remote_image_id = getattr(args, "remote-image-id", None)
- remote_service_interface = getattr(args, "remote-service-interface", None)
+ remote_region = getattr(args, "remote_region", None)
+ remote_image_id = getattr(args, "remote_image_id", None)
+ remote_service_interface = getattr(args, "remote_service_interface", None)
if not getattr(args, 'from_create', False):
if (args.store and (stores or all_stores)) or (stores and all_stores):