Skip to content

Commit f15352f

Browse files
stevemarjaspreetsinghrawel
authored andcommitted
clean up image choices and help text
Use choices for image set and image create commands, this aligns with our use of choices in networking commands. Also update the help text to match that of the networking commands, where we iterate through the options. Related-Bug: 1635518 Change-Id: Ib4c66b06e07f1d4e5bfe1b74053f2215cccad890
1 parent 3a7bb85 commit f15352f

File tree

5 files changed

+30
-23
lines changed

5 files changed

+30
-23
lines changed

doc/source/command-objects/image.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ Create/upload an image
7878
7979
.. option:: --disk-format <disk-format>
8080
81-
Image disk format (default: raw)
81+
Image disk format. The supported options are: ami, ari, aki, vhd, vmdk,
82+
raw, qcow2, vhdx, vdi, and iso. The default format is: raw
8283
8384
.. option:: --size <size>
8485
@@ -337,7 +338,8 @@ Set image properties
337338
338339
.. option:: --disk-format <disk-format>
339340
340-
Image disk format (default: raw)
341+
Image disk format. The supported options are: ami, ari, aki, vhd, vmdk,
342+
raw, qcow2, vhdx, vdi, and iso.
341343
342344
.. option:: --size <size>
343345

openstackclient/image/v1/image.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838

3939
DEFAULT_CONTAINER_FORMAT = 'bare'
4040
DEFAULT_DISK_FORMAT = 'raw'
41+
DISK_CHOICES = ["ami", "ari", "aki", "vhd", "vmdk", "raw", "qcow2", "vhdx",
42+
"vdi", "iso"]
4143

4244

4345
LOG = logging.getLogger(__name__)
@@ -89,8 +91,9 @@ def get_parser(self, prog_name):
8991
"--disk-format",
9092
default=DEFAULT_DISK_FORMAT,
9193
metavar="<disk-format>",
92-
help=_("Image disk format "
93-
"(default: %s)") % DEFAULT_DISK_FORMAT,
94+
choices=DISK_CHOICES,
95+
help=_("Image disk format. The supported options are: %s. "
96+
"The default format is: raw") % ', '.join(DISK_CHOICES)
9497
)
9598
parser.add_argument(
9699
"--size",
@@ -502,14 +505,12 @@ def get_parser(self, prog_name):
502505
container_choices,
503506
choices=container_choices
504507
)
505-
disk_choices = ["ami", "ari", "aki", "vhd", "vmdk", "raw", "qcow2",
506-
"vhdx", "vdi", "iso"]
507508
parser.add_argument(
508509
"--disk-format",
509510
metavar="<disk-format>",
510-
help=_("Disk format of image. Acceptable formats: %s") %
511-
disk_choices,
512-
choices=disk_choices
511+
choices=DISK_CHOICES,
512+
help=_("Image disk format. The supported options are: %s.") %
513+
', '.join(DISK_CHOICES)
513514
)
514515
parser.add_argument(
515516
"--size",

openstackclient/image/v2/image.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232

3333
DEFAULT_CONTAINER_FORMAT = 'bare'
3434
DEFAULT_DISK_FORMAT = 'raw'
35+
DISK_CHOICES = ["ami", "ari", "aki", "vhd", "vmdk", "raw", "qcow2", "vhdx",
36+
"vdi", "iso"]
3537

3638

3739
LOG = logging.getLogger(__name__)
@@ -140,9 +142,10 @@ def get_parser(self, prog_name):
140142
parser.add_argument(
141143
"--disk-format",
142144
default=DEFAULT_DISK_FORMAT,
145+
choices=DISK_CHOICES,
143146
metavar="<disk-format>",
144-
help=_("Image disk format "
145-
"(default: %s)") % DEFAULT_DISK_FORMAT,
147+
help=_("Image disk format. The supported options are: %s. "
148+
"The default format is: raw") % ', '.join(DISK_CHOICES)
146149
)
147150
parser.add_argument(
148151
"--min-disk",
@@ -650,8 +653,9 @@ def get_parser(self, prog_name):
650653
parser.add_argument(
651654
"--disk-format",
652655
metavar="<disk-format>",
653-
help=_("Image disk format "
654-
"(default: %s)") % DEFAULT_DISK_FORMAT,
656+
choices=DISK_CHOICES,
657+
help=_("Image disk format. The supported options are: %s") %
658+
', '.join(DISK_CHOICES)
655659
)
656660
protected_group = parser.add_mutually_exclusive_group()
657661
protected_group.add_argument(

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def test_image_reserve_options(self):
116116
self.images_mock.configure_mock(**mock_exception)
117117
arglist = [
118118
'--container-format', 'ovf',
119-
'--disk-format', 'fs',
119+
'--disk-format', 'ami',
120120
'--min-disk', '10',
121121
'--min-ram', '4',
122122
'--protected',
@@ -126,7 +126,7 @@ def test_image_reserve_options(self):
126126
]
127127
verifylist = [
128128
('container_format', 'ovf'),
129-
('disk_format', 'fs'),
129+
('disk_format', 'ami'),
130130
('min_disk', 10),
131131
('min_ram', 4),
132132
('protected', True),
@@ -147,7 +147,7 @@ def test_image_reserve_options(self):
147147
self.images_mock.create.assert_called_with(
148148
name=self.new_image.name,
149149
container_format='ovf',
150-
disk_format='fs',
150+
disk_format='ami',
151151
min_disk=10,
152152
min_ram=4,
153153
protected=True,

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def test_image_reserve_options(self, mock_open):
130130
self.images_mock.configure_mock(**mock_exception)
131131
arglist = [
132132
'--container-format', 'ovf',
133-
'--disk-format', 'fs',
133+
'--disk-format', 'ami',
134134
'--min-disk', '10',
135135
'--min-ram', '4',
136136
('--protected'
@@ -143,7 +143,7 @@ def test_image_reserve_options(self, mock_open):
143143
]
144144
verifylist = [
145145
('container_format', 'ovf'),
146-
('disk_format', 'fs'),
146+
('disk_format', 'ami'),
147147
('min_disk', 10),
148148
('min_ram', 4),
149149
('protected', self.new_image.protected),
@@ -165,7 +165,7 @@ def test_image_reserve_options(self, mock_open):
165165
self.images_mock.create.assert_called_with(
166166
name=self.new_image.name,
167167
container_format='ovf',
168-
disk_format='fs',
168+
disk_format='ami',
169169
min_disk=10,
170170
min_ram=4,
171171
owner=self.project.id,
@@ -193,7 +193,7 @@ def test_image_create_with_unexist_owner(self):
193193

194194
arglist = [
195195
'--container-format', 'ovf',
196-
'--disk-format', 'fs',
196+
'--disk-format', 'ami',
197197
'--min-disk', '10',
198198
'--min-ram', '4',
199199
'--owner', 'unexist_owner',
@@ -203,7 +203,7 @@ def test_image_create_with_unexist_owner(self):
203203
]
204204
verifylist = [
205205
('container_format', 'ovf'),
206-
('disk_format', 'fs'),
206+
('disk_format', 'ami'),
207207
('min_disk', 10),
208208
('min_ram', 4),
209209
('owner', 'unexist_owner'),
@@ -227,7 +227,7 @@ def test_image_create_with_unexist_project(self):
227227

228228
arglist = [
229229
'--container-format', 'ovf',
230-
'--disk-format', 'fs',
230+
'--disk-format', 'ami',
231231
'--min-disk', '10',
232232
'--min-ram', '4',
233233
'--protected',
@@ -237,7 +237,7 @@ def test_image_create_with_unexist_project(self):
237237
]
238238
verifylist = [
239239
('container_format', 'ovf'),
240-
('disk_format', 'fs'),
240+
('disk_format', 'ami'),
241241
('min_disk', 10),
242242
('min_ram', 4),
243243
('protected', True),

0 commit comments

Comments
 (0)