Browse Source

Merge "Expose flag for forcing use of import for images"

changes/79/740379/1
Zuul 1 year ago
committed by Gerrit Code Review
parent
commit
9fb68eca44
  1. 2
      lower-constraints.txt
  2. 11
      openstackclient/image/v2/image.py
  3. 22
      openstackclient/tests/unit/image/v2/test_image.py
  4. 5
      releasenotes/notes/add-image-import-flag-899869dc5a92aea7.yaml
  5. 2
      requirements.txt

2
lower-constraints.txt

@ -49,7 +49,7 @@ msgpack-python==0.4.0
munch==2.1.0
netaddr==0.7.18
netifaces==0.10.4
openstacksdk==0.44.0
openstacksdk==0.48.0
os-service-types==1.7.0
os-testr==1.0.0
osc-lib==2.0.0

11
openstackclient/image/v2/image.py

@ -324,6 +324,14 @@ class CreateImage(command.ShowOne):
metavar="<project>",
help=_("Set an alternate project on this image (name or ID)"),
)
parser.add_argument(
"--import",
dest="use_import",
action="store_true",
help=_(
"Force the use of glance image import instead of"
" direct upload")
)
common.add_project_domain_option_to_parser(parser)
for deadopt in self.deadopts:
parser.add_argument(
@ -388,6 +396,9 @@ class CreateImage(command.ShowOne):
parsed_args.project_domain,
).id
if parsed_args.use_import:
kwargs['use_import'] = True
# open the file first to ensure any failures are handled before the
# image is created. Get the file name (if it is file, and not stdin)
# for easier further handling.

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

@ -271,6 +271,28 @@ class TestImageCreate(TestImage):
exceptions.CommandError,
self.cmd.take_action, parsed_args)
@mock.patch('sys.stdin', side_effect=[None])
def test_image_create_import(self, raw_input):
arglist = [
'--import',
self.new_image.name,
]
verifylist = [
('name', self.new_image.name),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
columns, data = self.cmd.take_action(parsed_args)
# ImageManager.create(name=, **)
self.client.create_image.assert_called_with(
name=self.new_image.name,
container_format=image.DEFAULT_CONTAINER_FORMAT,
disk_format=image.DEFAULT_DISK_FORMAT,
use_import=True
)
class TestAddProjectToImage(TestImage):

5
releasenotes/notes/add-image-import-flag-899869dc5a92aea7.yaml

@ -0,0 +1,5 @@
---
features:
- |
Added ``--import`` flag to ``openstack image create`` to allow
the user to force use of the image import codepath.

2
requirements.txt

@ -5,7 +5,7 @@ pbr!=2.1.0,>=2.0.0 # Apache-2.0
six>=1.10.0 # MIT
cliff!=2.9.0,>=2.8.0 # Apache-2.0
openstacksdk>=0.44.0 # Apache-2.0
openstacksdk>=0.48.0 # Apache-2.0
osc-lib>=2.0.0 # Apache-2.0
oslo.i18n>=3.15.3 # Apache-2.0
oslo.utils>=3.33.0 # Apache-2.0

Loading…
Cancel
Save