Skip to content

Commit c04ec16

Browse files
committed
Expose flag for forcing use of import for images
openstacksdk added support for using image import as a fallback which is transparently supported here, but also provides an override flag to allow a user to force use of import. Expose that here. Depends-On: https://review.opendev.org/737608 Change-Id: Ied938a8f63f305305a20ace42e9f4c84b0a5c00e
1 parent 8b7a2c8 commit c04ec16

5 files changed

Lines changed: 40 additions & 2 deletions

File tree

lower-constraints.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ msgpack-python==0.4.0
5050
munch==2.1.0
5151
netaddr==0.7.18
5252
netifaces==0.10.4
53-
openstacksdk==0.44.0
53+
openstacksdk==0.48.0
5454
os-service-types==1.7.0
5555
os-testr==1.0.0
5656
osc-lib==2.0.0

openstackclient/image/v2/image.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,14 @@ def get_parser(self, prog_name):
324324
metavar="<project>",
325325
help=_("Set an alternate project on this image (name or ID)"),
326326
)
327+
parser.add_argument(
328+
"--import",
329+
dest="use_import",
330+
action="store_true",
331+
help=_(
332+
"Force the use of glance image import instead of"
333+
" direct upload")
334+
)
327335
common.add_project_domain_option_to_parser(parser)
328336
for deadopt in self.deadopts:
329337
parser.add_argument(
@@ -388,6 +396,9 @@ def take_action(self, parsed_args):
388396
parsed_args.project_domain,
389397
).id
390398

399+
if parsed_args.use_import:
400+
kwargs['use_import'] = True
401+
391402
# open the file first to ensure any failures are handled before the
392403
# image is created. Get the file name (if it is file, and not stdin)
393404
# for easier further handling.

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,28 @@ def test_image_create_dead_options(self):
271271
exceptions.CommandError,
272272
self.cmd.take_action, parsed_args)
273273

274+
@mock.patch('sys.stdin', side_effect=[None])
275+
def test_image_create_import(self, raw_input):
276+
277+
arglist = [
278+
'--import',
279+
self.new_image.name,
280+
]
281+
verifylist = [
282+
('name', self.new_image.name),
283+
]
284+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
285+
286+
columns, data = self.cmd.take_action(parsed_args)
287+
288+
# ImageManager.create(name=, **)
289+
self.client.create_image.assert_called_with(
290+
name=self.new_image.name,
291+
container_format=image.DEFAULT_CONTAINER_FORMAT,
292+
disk_format=image.DEFAULT_DISK_FORMAT,
293+
use_import=True
294+
)
295+
274296

275297
class TestAddProjectToImage(TestImage):
276298

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
features:
3+
- |
4+
Added ``--import`` flag to ``openstack image create`` to allow
5+
the user to force use of the image import codepath.

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ pbr!=2.1.0,>=2.0.0 # Apache-2.0
55
six>=1.10.0 # MIT
66

77
cliff!=2.9.0,>=2.8.0 # Apache-2.0
8-
openstacksdk>=0.44.0 # Apache-2.0
8+
openstacksdk>=0.48.0 # Apache-2.0
99
osc-lib>=2.0.0 # Apache-2.0
1010
oslo.i18n>=3.15.3 # Apache-2.0
1111
oslo.utils>=3.33.0 # Apache-2.0

0 commit comments

Comments
 (0)