Skip to content

Commit 2c2df48

Browse files
CyrilRoelandteNovancePranaliDeore
authored andcommitted
image: add --store-preference to "image save"
Users can use this option (one or multiple times) to download an image from a specific store. Assisted-By: Claude Sonnet 4.5 Change-Id: I8f5ded403be4fd8911169ec62a6f32a45145f00f Signed-off-by: Cyril Roelandt <cyril@redhat.com>
1 parent 6ef4d93 commit 2c2df48

3 files changed

Lines changed: 83 additions & 2 deletions

File tree

openstackclient/image/v2/image.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,6 +1142,17 @@ def get_parser(self, prog_name: str) -> argparse.ArgumentParser:
11421142
dest="filename",
11431143
help=_("Downloaded image save filename (default: stdout)"),
11441144
)
1145+
parser.add_argument(
1146+
"--store-preference",
1147+
metavar="<store>",
1148+
dest="store_preferences",
1149+
action="append",
1150+
help=_(
1151+
"Preferred store to download the image from "
1152+
"(repeat option to specify multiple store preferences in "
1153+
"order)"
1154+
),
1155+
)
11451156
parser.add_argument(
11461157
"image",
11471158
metavar="<image>",
@@ -1165,6 +1176,7 @@ def take_action(self, parsed_args: argparse.Namespace) -> None:
11651176
stream=True,
11661177
output=output_file,
11671178
chunk_size=parsed_args.chunk_size,
1179+
store_preferences=parsed_args.store_preferences,
11681180
)
11691181

11701182

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

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2504,7 +2504,11 @@ def test_save_data(self):
25042504
self.cmd.take_action(parsed_args)
25052505

25062506
self.image_client.download_image.assert_called_once_with(
2507-
self.image.id, output='/path/to/file', stream=True, chunk_size=1024
2507+
self.image.id,
2508+
stream=True,
2509+
output='/path/to/file',
2510+
chunk_size=1024,
2511+
store_preferences=None,
25082512
)
25092513

25102514
def test_save_data_with_chunk_size(self):
@@ -2526,7 +2530,65 @@ def test_save_data_with_chunk_size(self):
25262530
self.cmd.take_action(parsed_args)
25272531

25282532
self.image_client.download_image.assert_called_once_with(
2529-
self.image.id, output='/path/to/file', stream=True, chunk_size=2048
2533+
self.image.id,
2534+
stream=True,
2535+
output='/path/to/file',
2536+
chunk_size=2048,
2537+
store_preferences=None,
2538+
)
2539+
2540+
def test_save_data_with_single_store_preference(self):
2541+
arglist = [
2542+
'--file',
2543+
'/path/to/file',
2544+
'--store-preference',
2545+
'ceph',
2546+
self.image.id,
2547+
]
2548+
2549+
verifylist = [
2550+
('filename', '/path/to/file'),
2551+
('store_preferences', ['ceph']),
2552+
('image', self.image.id),
2553+
]
2554+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
2555+
2556+
self.cmd.take_action(parsed_args)
2557+
2558+
self.image_client.download_image.assert_called_once_with(
2559+
self.image.id,
2560+
output='/path/to/file',
2561+
stream=True,
2562+
chunk_size=1024,
2563+
store_preferences=['ceph'],
2564+
)
2565+
2566+
def test_save_data_with_multiple_store_preferences(self):
2567+
arglist = [
2568+
'--file',
2569+
'/path/to/file',
2570+
'--store-preference',
2571+
'ceph',
2572+
'--store-preference',
2573+
's3',
2574+
self.image.id,
2575+
]
2576+
2577+
verifylist = [
2578+
('filename', '/path/to/file'),
2579+
('store_preferences', ['ceph', 's3']),
2580+
('image', self.image.id),
2581+
]
2582+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
2583+
2584+
self.cmd.take_action(parsed_args)
2585+
2586+
self.image_client.download_image.assert_called_once_with(
2587+
self.image.id,
2588+
output='/path/to/file',
2589+
stream=True,
2590+
chunk_size=1024,
2591+
store_preferences=['ceph', 's3'],
25302592
)
25312593

25322594

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
features:
3+
- |
4+
Add ``--store-preference`` option to ``image save`` command to specify
5+
the preferred backend store(s) to download the image from when using
6+
Glance with multiple backend stores. This option can be repeated to
7+
specify multiple store preferences in order.

0 commit comments

Comments
 (0)