Blacken openstackclient.image
Black used with the '-l 79 -S' flags. A future change will ignore this commit in git-blame history by adding a 'git-blame-ignore-revs' file. Change-Id: I6420ec6fd550903b03083b9b1f8391511913c86f Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
This commit is contained in:
parent
329296cedd
commit
7ca43885c2
openstackclient
image
tests
functional/image
unit/image
@ -32,7 +32,6 @@ API_VERSIONS = {
|
|||||||
|
|
||||||
|
|
||||||
def make_client(instance):
|
def make_client(instance):
|
||||||
|
|
||||||
LOG.debug(
|
LOG.debug(
|
||||||
'Image client initialized using OpenStack SDK: %s',
|
'Image client initialized using OpenStack SDK: %s',
|
||||||
instance.sdk_connection.image,
|
instance.sdk_connection.image,
|
||||||
@ -46,7 +45,7 @@ def build_option_parser(parser):
|
|||||||
'--os-image-api-version',
|
'--os-image-api-version',
|
||||||
metavar='<image-api-version>',
|
metavar='<image-api-version>',
|
||||||
default=utils.env('OS_IMAGE_API_VERSION'),
|
default=utils.env('OS_IMAGE_API_VERSION'),
|
||||||
help=_('Image API version, default=%s (Env: OS_IMAGE_API_VERSION)') %
|
help=_('Image API version, default=%s (Env: OS_IMAGE_API_VERSION)')
|
||||||
DEFAULT_API_VERSION,
|
% DEFAULT_API_VERSION,
|
||||||
)
|
)
|
||||||
return parser
|
return parser
|
||||||
|
@ -39,29 +39,42 @@ else:
|
|||||||
CONTAINER_CHOICES = ["ami", "ari", "aki", "bare", "docker", "ova", "ovf"]
|
CONTAINER_CHOICES = ["ami", "ari", "aki", "bare", "docker", "ova", "ovf"]
|
||||||
DEFAULT_CONTAINER_FORMAT = 'bare'
|
DEFAULT_CONTAINER_FORMAT = 'bare'
|
||||||
DEFAULT_DISK_FORMAT = 'raw'
|
DEFAULT_DISK_FORMAT = 'raw'
|
||||||
DISK_CHOICES = ["ami", "ari", "aki", "vhd", "vmdk", "raw", "qcow2", "vhdx",
|
DISK_CHOICES = [
|
||||||
"vdi", "iso", "ploop"]
|
"ami",
|
||||||
|
"ari",
|
||||||
|
"aki",
|
||||||
|
"vhd",
|
||||||
|
"vmdk",
|
||||||
|
"raw",
|
||||||
|
"qcow2",
|
||||||
|
"vhdx",
|
||||||
|
"vdi",
|
||||||
|
"iso",
|
||||||
|
"ploop",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def _get_columns(item):
|
def _get_columns(item):
|
||||||
column_map = {
|
column_map = {'is_protected': 'protected', 'owner_id': 'owner'}
|
||||||
'is_protected': 'protected',
|
|
||||||
'owner_id': 'owner'
|
|
||||||
}
|
|
||||||
hidden_columns = [
|
hidden_columns = [
|
||||||
'location', 'checksum', 'copy_from', 'created_at', 'status',
|
'location',
|
||||||
|
'checksum',
|
||||||
|
'copy_from',
|
||||||
|
'created_at',
|
||||||
|
'status',
|
||||||
'updated_at',
|
'updated_at',
|
||||||
]
|
]
|
||||||
return utils.get_osc_show_columns_for_sdk_resource(
|
return utils.get_osc_show_columns_for_sdk_resource(
|
||||||
item.to_dict(), column_map, hidden_columns,
|
item.to_dict(),
|
||||||
|
column_map,
|
||||||
|
hidden_columns,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
_formatters = {
|
_formatters = {}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class HumanReadableSizeColumn(cliff_columns.FormattableColumn):
|
class HumanReadableSizeColumn(cliff_columns.FormattableColumn):
|
||||||
@ -117,25 +130,36 @@ class CreateImage(command.ShowOne):
|
|||||||
default=DEFAULT_CONTAINER_FORMAT,
|
default=DEFAULT_CONTAINER_FORMAT,
|
||||||
metavar="<container-format>",
|
metavar="<container-format>",
|
||||||
choices=CONTAINER_CHOICES,
|
choices=CONTAINER_CHOICES,
|
||||||
help=(_("Image container format. "
|
help=(
|
||||||
|
_(
|
||||||
|
"Image container format. "
|
||||||
"The supported options are: %(option_list)s. "
|
"The supported options are: %(option_list)s. "
|
||||||
"The default format is: %(default_opt)s") %
|
"The default format is: %(default_opt)s"
|
||||||
{'option_list': ', '.join(CONTAINER_CHOICES),
|
)
|
||||||
'default_opt': DEFAULT_CONTAINER_FORMAT})
|
% {
|
||||||
|
'option_list': ', '.join(CONTAINER_CHOICES),
|
||||||
|
'default_opt': DEFAULT_CONTAINER_FORMAT,
|
||||||
|
}
|
||||||
|
),
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--disk-format",
|
"--disk-format",
|
||||||
default=DEFAULT_DISK_FORMAT,
|
default=DEFAULT_DISK_FORMAT,
|
||||||
metavar="<disk-format>",
|
metavar="<disk-format>",
|
||||||
choices=DISK_CHOICES,
|
choices=DISK_CHOICES,
|
||||||
help=_("Image disk format. The supported options are: %s. "
|
help=_(
|
||||||
"The default format is: raw") % ', '.join(DISK_CHOICES)
|
"Image disk format. The supported options are: %s. "
|
||||||
|
"The default format is: raw"
|
||||||
|
)
|
||||||
|
% ', '.join(DISK_CHOICES),
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--size",
|
"--size",
|
||||||
metavar="<size>",
|
metavar="<size>",
|
||||||
help=_("Image size, in bytes (only used with --location and"
|
help=_(
|
||||||
" --copy-from)"),
|
"Image size, in bytes (only used with --location and"
|
||||||
|
" --copy-from)"
|
||||||
|
),
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--min-disk",
|
"--min-disk",
|
||||||
@ -175,8 +199,10 @@ class CreateImage(command.ShowOne):
|
|||||||
dest='force',
|
dest='force',
|
||||||
action='store_true',
|
action='store_true',
|
||||||
default=False,
|
default=False,
|
||||||
help=_("Force image creation if volume is in use "
|
help=_(
|
||||||
"(only meaningful with --volume)"),
|
"Force image creation if volume is in use "
|
||||||
|
"(only meaningful with --volume)"
|
||||||
|
),
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--checksum",
|
"--checksum",
|
||||||
@ -210,8 +236,10 @@ class CreateImage(command.ShowOne):
|
|||||||
dest="properties",
|
dest="properties",
|
||||||
metavar="<key=value>",
|
metavar="<key=value>",
|
||||||
action=parseractions.KeyValueAction,
|
action=parseractions.KeyValueAction,
|
||||||
help=_("Set a property on this image "
|
help=_(
|
||||||
"(repeat option to set multiple properties)"),
|
"Set a property on this image "
|
||||||
|
"(repeat option to set multiple properties)"
|
||||||
|
),
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--project",
|
"--project",
|
||||||
@ -226,10 +254,23 @@ class CreateImage(command.ShowOne):
|
|||||||
# Build an attribute dict from the parsed args, only include
|
# Build an attribute dict from the parsed args, only include
|
||||||
# attributes that were actually set on the command line
|
# attributes that were actually set on the command line
|
||||||
kwargs = {}
|
kwargs = {}
|
||||||
copy_attrs = ('name', 'id', 'store', 'container_format',
|
copy_attrs = (
|
||||||
'disk_format', 'owner', 'size', 'min_disk', 'min_ram',
|
'name',
|
||||||
'location', 'copy_from', 'volume', 'force',
|
'id',
|
||||||
'checksum', 'properties')
|
'store',
|
||||||
|
'container_format',
|
||||||
|
'disk_format',
|
||||||
|
'owner',
|
||||||
|
'size',
|
||||||
|
'min_disk',
|
||||||
|
'min_ram',
|
||||||
|
'location',
|
||||||
|
'copy_from',
|
||||||
|
'volume',
|
||||||
|
'force',
|
||||||
|
'checksum',
|
||||||
|
'properties',
|
||||||
|
)
|
||||||
for attr in copy_attrs:
|
for attr in copy_attrs:
|
||||||
if attr in parsed_args:
|
if attr in parsed_args:
|
||||||
val = getattr(parsed_args, attr, None)
|
val = getattr(parsed_args, attr, None)
|
||||||
@ -295,20 +336,25 @@ class CreateImage(command.ShowOne):
|
|||||||
image = image_client.create_image(**kwargs)
|
image = image_client.create_image(**kwargs)
|
||||||
finally:
|
finally:
|
||||||
# Clean up open files - make sure data isn't a string
|
# Clean up open files - make sure data isn't a string
|
||||||
if ('data' in kwargs and hasattr(kwargs['data'], 'close') and
|
if (
|
||||||
kwargs['data'] != sys.stdin):
|
'data' in kwargs
|
||||||
|
and hasattr(kwargs['data'], 'close')
|
||||||
|
and kwargs['data'] != sys.stdin
|
||||||
|
):
|
||||||
kwargs['data'].close()
|
kwargs['data'].close()
|
||||||
|
|
||||||
if image:
|
if image:
|
||||||
display_columns, columns = _get_columns(image)
|
display_columns, columns = _get_columns(image)
|
||||||
_formatters['properties'] = format_columns.DictColumn
|
_formatters['properties'] = format_columns.DictColumn
|
||||||
data = utils.get_item_properties(image, columns,
|
data = utils.get_item_properties(
|
||||||
formatters=_formatters)
|
image, columns, formatters=_formatters
|
||||||
|
)
|
||||||
return (display_columns, data)
|
return (display_columns, data)
|
||||||
elif info:
|
elif info:
|
||||||
info.update(image._info)
|
info.update(image._info)
|
||||||
info['properties'] = format_columns.DictColumn(
|
info['properties'] = format_columns.DictColumn(
|
||||||
info.get('properties', {}))
|
info.get('properties', {})
|
||||||
|
)
|
||||||
return zip(*sorted(info.items()))
|
return zip(*sorted(info.items()))
|
||||||
|
|
||||||
|
|
||||||
@ -384,9 +430,11 @@ class ListImage(command.Lister):
|
|||||||
'--sort',
|
'--sort',
|
||||||
metavar="<key>[:<direction>]",
|
metavar="<key>[:<direction>]",
|
||||||
default='name:asc',
|
default='name:asc',
|
||||||
help=_("Sort output by selected keys and directions(asc or desc) "
|
help=_(
|
||||||
"(default: name:asc), multiple keys and directions can be "
|
"Sort output by selected keys and directions(asc or desc) "
|
||||||
"specified separated by comma"),
|
"(default: name:asc), multiple keys and directions can be "
|
||||||
|
"specified separated by comma"
|
||||||
|
),
|
||||||
)
|
)
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
@ -447,14 +495,17 @@ class ListImage(command.Lister):
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
column_headers,
|
column_headers,
|
||||||
(utils.get_item_properties(
|
(
|
||||||
s,
|
utils.get_item_properties(
|
||||||
columns,
|
s,
|
||||||
formatters={
|
columns,
|
||||||
'is_public': VisibilityColumn,
|
formatters={
|
||||||
'properties': format_columns.DictColumn,
|
'is_public': VisibilityColumn,
|
||||||
},
|
'properties': format_columns.DictColumn,
|
||||||
) for s in data)
|
},
|
||||||
|
)
|
||||||
|
for s in data
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -517,21 +568,21 @@ class SetImage(command.Command):
|
|||||||
"--container-format",
|
"--container-format",
|
||||||
metavar="<container-format>",
|
metavar="<container-format>",
|
||||||
choices=CONTAINER_CHOICES,
|
choices=CONTAINER_CHOICES,
|
||||||
help=_("Image container format. The supported options are: %s") %
|
help=_("Image container format. The supported options are: %s")
|
||||||
', '.join(CONTAINER_CHOICES)
|
% ', '.join(CONTAINER_CHOICES),
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--disk-format",
|
"--disk-format",
|
||||||
metavar="<disk-format>",
|
metavar="<disk-format>",
|
||||||
choices=DISK_CHOICES,
|
choices=DISK_CHOICES,
|
||||||
help=_("Image disk format. The supported options are: %s.") %
|
help=_("Image disk format. The supported options are: %s.")
|
||||||
', '.join(DISK_CHOICES)
|
% ', '.join(DISK_CHOICES),
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--size",
|
"--size",
|
||||||
metavar="<size>",
|
metavar="<size>",
|
||||||
type=int,
|
type=int,
|
||||||
help=_("Size of image data (in bytes)")
|
help=_("Size of image data (in bytes)"),
|
||||||
)
|
)
|
||||||
protected_group = parser.add_mutually_exclusive_group()
|
protected_group = parser.add_mutually_exclusive_group()
|
||||||
protected_group.add_argument(
|
protected_group.add_argument(
|
||||||
@ -560,8 +611,10 @@ class SetImage(command.Command):
|
|||||||
dest="properties",
|
dest="properties",
|
||||||
metavar="<key=value>",
|
metavar="<key=value>",
|
||||||
action=parseractions.KeyValueAction,
|
action=parseractions.KeyValueAction,
|
||||||
help=_("Set a property on this image "
|
help=_(
|
||||||
"(repeat option to set multiple properties)"),
|
"Set a property on this image "
|
||||||
|
"(repeat option to set multiple properties)"
|
||||||
|
),
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--store",
|
"--store",
|
||||||
@ -593,8 +646,10 @@ class SetImage(command.Command):
|
|||||||
dest='force',
|
dest='force',
|
||||||
action='store_true',
|
action='store_true',
|
||||||
default=False,
|
default=False,
|
||||||
help=_("Force image change if volume is in use "
|
help=_(
|
||||||
"(only meaningful with --volume)"),
|
"Force image change if volume is in use "
|
||||||
|
"(only meaningful with --volume)"
|
||||||
|
),
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--stdin",
|
"--stdin",
|
||||||
@ -619,9 +674,21 @@ class SetImage(command.Command):
|
|||||||
image_client = self.app.client_manager.image
|
image_client = self.app.client_manager.image
|
||||||
|
|
||||||
kwargs = {}
|
kwargs = {}
|
||||||
copy_attrs = ('name', 'owner', 'min_disk', 'min_ram', 'properties',
|
copy_attrs = (
|
||||||
'container_format', 'disk_format', 'size', 'store',
|
'name',
|
||||||
'location', 'copy_from', 'volume', 'checksum')
|
'owner',
|
||||||
|
'min_disk',
|
||||||
|
'min_ram',
|
||||||
|
'properties',
|
||||||
|
'container_format',
|
||||||
|
'disk_format',
|
||||||
|
'size',
|
||||||
|
'store',
|
||||||
|
'location',
|
||||||
|
'copy_from',
|
||||||
|
'volume',
|
||||||
|
'checksum',
|
||||||
|
)
|
||||||
for attr in copy_attrs:
|
for attr in copy_attrs:
|
||||||
if attr in parsed_args:
|
if attr in parsed_args:
|
||||||
val = getattr(parsed_args, attr, None)
|
val = getattr(parsed_args, attr, None)
|
||||||
@ -665,12 +732,16 @@ class SetImage(command.Command):
|
|||||||
source_volume.id,
|
source_volume.id,
|
||||||
parsed_args.force,
|
parsed_args.force,
|
||||||
parsed_args.image,
|
parsed_args.image,
|
||||||
(parsed_args.container_format
|
(
|
||||||
if parsed_args.container_format
|
parsed_args.container_format
|
||||||
else image.container_format),
|
if parsed_args.container_format
|
||||||
(parsed_args.disk_format
|
else image.container_format
|
||||||
if parsed_args.disk_format
|
),
|
||||||
else image.disk_format),
|
(
|
||||||
|
parsed_args.disk_format
|
||||||
|
if parsed_args.disk_format
|
||||||
|
else image.disk_format
|
||||||
|
),
|
||||||
)
|
)
|
||||||
elif parsed_args.file:
|
elif parsed_args.file:
|
||||||
# Send an open file handle to glanceclient so it will
|
# Send an open file handle to glanceclient so it will
|
||||||
@ -687,8 +758,12 @@ class SetImage(command.Command):
|
|||||||
else:
|
else:
|
||||||
kwargs["data"] = sys.stdin
|
kwargs["data"] = sys.stdin
|
||||||
else:
|
else:
|
||||||
LOG.warning(_('Use --stdin to enable read image '
|
LOG.warning(
|
||||||
'data from standard input'))
|
_(
|
||||||
|
'Use --stdin to enable read image '
|
||||||
|
'data from standard input'
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
if image.properties and parsed_args.properties:
|
if image.properties and parsed_args.properties:
|
||||||
image.properties.update(kwargs['properties'])
|
image.properties.update(kwargs['properties'])
|
||||||
@ -697,8 +772,11 @@ class SetImage(command.Command):
|
|||||||
image = image_client.update_image(image.id, **kwargs)
|
image = image_client.update_image(image.id, **kwargs)
|
||||||
finally:
|
finally:
|
||||||
# Clean up open files - make sure data isn't a string
|
# Clean up open files - make sure data isn't a string
|
||||||
if ('data' in kwargs and hasattr(kwargs['data'], 'close') and
|
if (
|
||||||
kwargs['data'] != sys.stdin):
|
'data' in kwargs
|
||||||
|
and hasattr(kwargs['data'], 'close')
|
||||||
|
and kwargs['data'] != sys.stdin
|
||||||
|
):
|
||||||
kwargs['data'].close()
|
kwargs['data'].close()
|
||||||
|
|
||||||
|
|
||||||
@ -728,6 +806,7 @@ class ShowImage(command.ShowOne):
|
|||||||
_formatters['size'] = HumanReadableSizeColumn
|
_formatters['size'] = HumanReadableSizeColumn
|
||||||
display_columns, columns = _get_columns(image)
|
display_columns, columns = _get_columns(image)
|
||||||
_formatters['properties'] = format_columns.DictColumn
|
_formatters['properties'] = format_columns.DictColumn
|
||||||
data = utils.get_item_properties(image, columns,
|
data = utils.get_item_properties(
|
||||||
formatters=_formatters)
|
image, columns, formatters=_formatters
|
||||||
|
)
|
||||||
return (display_columns, data)
|
return (display_columns, data)
|
||||||
|
@ -506,8 +506,8 @@ class CreateImage(command.ShowOne):
|
|||||||
raise exceptions.CommandError(msg)
|
raise exceptions.CommandError(msg)
|
||||||
|
|
||||||
if (
|
if (
|
||||||
len(parsed_args.sign_key_path) < 1 or
|
len(parsed_args.sign_key_path) < 1
|
||||||
len(parsed_args.sign_cert_id) < 1
|
or len(parsed_args.sign_cert_id) < 1
|
||||||
):
|
):
|
||||||
msg = _(
|
msg = _(
|
||||||
"'sign-key-path' and 'sign-cert-id' must both be "
|
"'sign-key-path' and 'sign-cert-id' must both be "
|
||||||
@ -596,10 +596,7 @@ class CreateImage(command.ShowOne):
|
|||||||
)
|
)
|
||||||
kwargs = {}
|
kwargs = {}
|
||||||
if volume_client.api_version < api_versions.APIVersion('3.1'):
|
if volume_client.api_version < api_versions.APIVersion('3.1'):
|
||||||
if (
|
if parsed_args.visibility or parsed_args.is_protected is not None:
|
||||||
parsed_args.visibility or
|
|
||||||
parsed_args.is_protected is not None
|
|
||||||
):
|
|
||||||
msg = _(
|
msg = _(
|
||||||
'--os-volume-api-version 3.1 or greater is required '
|
'--os-volume-api-version 3.1 or greater is required '
|
||||||
'to support the --public, --private, --community, '
|
'to support the --public, --private, --community, '
|
||||||
@ -618,7 +615,7 @@ class CreateImage(command.ShowOne):
|
|||||||
parsed_args.name,
|
parsed_args.name,
|
||||||
parsed_args.container_format,
|
parsed_args.container_format,
|
||||||
parsed_args.disk_format,
|
parsed_args.disk_format,
|
||||||
**kwargs
|
**kwargs,
|
||||||
)
|
)
|
||||||
info = body['os-volume_upload_image']
|
info = body['os-volume_upload_image']
|
||||||
try:
|
try:
|
||||||
@ -659,7 +656,6 @@ class DeleteImage(command.Command):
|
|||||||
return parser
|
return parser
|
||||||
|
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
|
|
||||||
del_result = 0
|
del_result = 0
|
||||||
image_client = self.app.client_manager.image
|
image_client = self.app.client_manager.image
|
||||||
for image in parsed_args.images:
|
for image in parsed_args.images:
|
||||||
|
@ -52,8 +52,9 @@ def _format_namespace(namespace):
|
|||||||
if key in fields_to_show:
|
if key in fields_to_show:
|
||||||
info[key] = namespace.get(key)
|
info[key] = namespace.get(key)
|
||||||
elif key == "resource_type_associations":
|
elif key == "resource_type_associations":
|
||||||
info[key] = [resource_type['name']
|
info[key] = [
|
||||||
for resource_type in namespace.get(key)]
|
resource_type['name'] for resource_type in namespace.get(key)
|
||||||
|
]
|
||||||
elif key == 'properties':
|
elif key == 'properties':
|
||||||
info['properties'] = list(namespace.get(key).keys())
|
info['properties'] = list(namespace.get(key).keys())
|
||||||
|
|
||||||
@ -114,11 +115,7 @@ class CreateMetadefNameSpace(command.ShowOne):
|
|||||||
|
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
image_client = self.app.client_manager.image
|
image_client = self.app.client_manager.image
|
||||||
filter_keys = [
|
filter_keys = ['namespace', 'display_name', 'description']
|
||||||
'namespace',
|
|
||||||
'display_name',
|
|
||||||
'description'
|
|
||||||
]
|
|
||||||
kwargs = {}
|
kwargs = {}
|
||||||
|
|
||||||
for key in filter_keys:
|
for key in filter_keys:
|
||||||
@ -160,15 +157,19 @@ class DeleteMetadefNameSpace(command.Command):
|
|||||||
image_client.delete_metadef_namespace(namespace.id)
|
image_client.delete_metadef_namespace(namespace.id)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
result += 1
|
result += 1
|
||||||
LOG.error(_("Failed to delete namespace with name or "
|
LOG.error(
|
||||||
"ID '%(namespace)s': %(e)s"),
|
_(
|
||||||
{'namespace': i, 'e': e}
|
"Failed to delete namespace with name or "
|
||||||
)
|
"ID '%(namespace)s': %(e)s"
|
||||||
|
),
|
||||||
|
{'namespace': i, 'e': e},
|
||||||
|
)
|
||||||
|
|
||||||
if result > 0:
|
if result > 0:
|
||||||
total = len(parsed_args.namespace_name)
|
total = len(parsed_args.namespace_name)
|
||||||
msg = (_("%(result)s of %(total)s namespace failed "
|
msg = _(
|
||||||
"to delete.") % {'result': result, 'total': total})
|
"%(result)s of %(total)s namespace failed " "to delete."
|
||||||
|
) % {'result': result, 'total': total}
|
||||||
raise exceptions.CommandError(msg)
|
raise exceptions.CommandError(msg)
|
||||||
|
|
||||||
|
|
||||||
@ -203,11 +204,14 @@ class ListMetadefNameSpaces(command.Lister):
|
|||||||
column_headers = columns
|
column_headers = columns
|
||||||
return (
|
return (
|
||||||
column_headers,
|
column_headers,
|
||||||
(utils.get_item_properties(
|
(
|
||||||
s,
|
utils.get_item_properties(
|
||||||
columns,
|
s,
|
||||||
formatters=_formatters,
|
columns,
|
||||||
) for s in data)
|
formatters=_formatters,
|
||||||
|
)
|
||||||
|
for s in data
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -268,11 +272,7 @@ class SetMetadefNameSpace(command.Command):
|
|||||||
|
|
||||||
namespace = parsed_args.namespace
|
namespace = parsed_args.namespace
|
||||||
|
|
||||||
filter_keys = [
|
filter_keys = ['namespace', 'display_name', 'description']
|
||||||
'namespace',
|
|
||||||
'display_name',
|
|
||||||
'description'
|
|
||||||
]
|
|
||||||
kwargs = {}
|
kwargs = {}
|
||||||
|
|
||||||
for key in filter_keys:
|
for key in filter_keys:
|
||||||
|
@ -26,9 +26,7 @@ class ImageTests(base.BaseImageTests):
|
|||||||
if not self.haz_v1_api:
|
if not self.haz_v1_api:
|
||||||
self.skipTest('No Image v1 API present')
|
self.skipTest('No Image v1 API present')
|
||||||
|
|
||||||
ver_fixture = fixtures.EnvironmentVariable(
|
ver_fixture = fixtures.EnvironmentVariable('OS_IMAGE_API_VERSION', '1')
|
||||||
'OS_IMAGE_API_VERSION', '1'
|
|
||||||
)
|
|
||||||
self.useFixture(ver_fixture)
|
self.useFixture(ver_fixture)
|
||||||
|
|
||||||
self.name = uuid.uuid4().hex
|
self.name = uuid.uuid4().hex
|
||||||
@ -46,25 +44,20 @@ class ImageTests(base.BaseImageTests):
|
|||||||
super().tearDown()
|
super().tearDown()
|
||||||
|
|
||||||
def test_image_list(self):
|
def test_image_list(self):
|
||||||
output = self.openstack(
|
output = self.openstack('image list')
|
||||||
'image list'
|
self.assertIn(self.name, [img['Name'] for img in output])
|
||||||
)
|
|
||||||
self.assertIn(
|
|
||||||
self.name,
|
|
||||||
[img['Name'] for img in output]
|
|
||||||
)
|
|
||||||
|
|
||||||
def test_image_attributes(self):
|
def test_image_attributes(self):
|
||||||
"""Test set, unset, show on attributes, tags and properties"""
|
"""Test set, unset, show on attributes, tags and properties"""
|
||||||
|
|
||||||
# Test explicit attributes
|
# Test explicit attributes
|
||||||
self.openstack(
|
self.openstack(
|
||||||
'image set ' +
|
'image set '
|
||||||
'--min-disk 4 ' +
|
+ '--min-disk 4 '
|
||||||
'--min-ram 5 ' +
|
+ '--min-ram 5 '
|
||||||
'--disk-format qcow2 ' +
|
+ '--disk-format qcow2 '
|
||||||
'--public ' +
|
+ '--public '
|
||||||
self.name
|
+ self.name
|
||||||
)
|
)
|
||||||
output = self.openstack(
|
output = self.openstack(
|
||||||
'image show ' + self.name,
|
'image show ' + self.name,
|
||||||
@ -88,11 +81,11 @@ class ImageTests(base.BaseImageTests):
|
|||||||
|
|
||||||
# Test properties
|
# Test properties
|
||||||
self.openstack(
|
self.openstack(
|
||||||
'image set ' +
|
'image set '
|
||||||
'--property a=b ' +
|
+ '--property a=b '
|
||||||
'--property c=d ' +
|
+ '--property c=d '
|
||||||
'--public ' +
|
+ '--public '
|
||||||
self.name
|
+ self.name
|
||||||
)
|
)
|
||||||
output = self.openstack(
|
output = self.openstack(
|
||||||
'image show ' + self.name,
|
'image show ' + self.name,
|
||||||
|
@ -23,9 +23,7 @@ class ImageTests(base.BaseImageTests):
|
|||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(ImageTests, self).setUp()
|
super(ImageTests, self).setUp()
|
||||||
|
|
||||||
ver_fixture = fixtures.EnvironmentVariable(
|
ver_fixture = fixtures.EnvironmentVariable('OS_IMAGE_API_VERSION', '2')
|
||||||
'OS_IMAGE_API_VERSION', '2'
|
|
||||||
)
|
|
||||||
self.useFixture(ver_fixture)
|
self.useFixture(ver_fixture)
|
||||||
|
|
||||||
self.name = uuid.uuid4().hex
|
self.name = uuid.uuid4().hex
|
||||||
@ -33,7 +31,8 @@ class ImageTests(base.BaseImageTests):
|
|||||||
self.image_tag1 = 'random'
|
self.image_tag1 = 'random'
|
||||||
output = self.openstack(
|
output = self.openstack(
|
||||||
'image create --tag {tag} {name}'.format(
|
'image create --tag {tag} {name}'.format(
|
||||||
tag=self.image_tag, name=self.name),
|
tag=self.image_tag, name=self.name
|
||||||
|
),
|
||||||
parse_output=True,
|
parse_output=True,
|
||||||
)
|
)
|
||||||
self.image_id = output["id"]
|
self.image_id = output["id"]
|
||||||
@ -47,57 +46,45 @@ class ImageTests(base.BaseImageTests):
|
|||||||
|
|
||||||
def test_image_list(self):
|
def test_image_list(self):
|
||||||
output = self.openstack('image list', parse_output=True)
|
output = self.openstack('image list', parse_output=True)
|
||||||
self.assertIn(
|
self.assertIn(self.name, [img['Name'] for img in output])
|
||||||
self.name,
|
|
||||||
[img['Name'] for img in output]
|
|
||||||
)
|
|
||||||
|
|
||||||
def test_image_list_with_name_filter(self):
|
def test_image_list_with_name_filter(self):
|
||||||
output = self.openstack(
|
output = self.openstack(
|
||||||
'image list --name ' + self.name,
|
'image list --name ' + self.name,
|
||||||
parse_output=True,
|
parse_output=True,
|
||||||
)
|
)
|
||||||
self.assertIn(
|
self.assertIn(self.name, [img['Name'] for img in output])
|
||||||
self.name,
|
|
||||||
[img['Name'] for img in output]
|
|
||||||
)
|
|
||||||
|
|
||||||
def test_image_list_with_status_filter(self):
|
def test_image_list_with_status_filter(self):
|
||||||
output = self.openstack(
|
output = self.openstack(
|
||||||
'image list --status active',
|
'image list --status active',
|
||||||
parse_output=True,
|
parse_output=True,
|
||||||
)
|
)
|
||||||
self.assertIn(
|
self.assertIn('active', [img['Status'] for img in output])
|
||||||
'active',
|
|
||||||
[img['Status'] for img in output]
|
|
||||||
)
|
|
||||||
|
|
||||||
def test_image_list_with_tag_filter(self):
|
def test_image_list_with_tag_filter(self):
|
||||||
output = self.openstack(
|
output = self.openstack(
|
||||||
'image list --tag ' + self.image_tag + ' --tag ' +
|
'image list --tag '
|
||||||
self.image_tag1 + ' --long',
|
+ self.image_tag
|
||||||
|
+ ' --tag '
|
||||||
|
+ self.image_tag1
|
||||||
|
+ ' --long',
|
||||||
parse_output=True,
|
parse_output=True,
|
||||||
)
|
)
|
||||||
for taglist in [img['Tags'] for img in output]:
|
for taglist in [img['Tags'] for img in output]:
|
||||||
self.assertIn(
|
self.assertIn(self.image_tag, taglist)
|
||||||
self.image_tag,
|
self.assertIn(self.image_tag1, taglist)
|
||||||
taglist
|
|
||||||
)
|
|
||||||
self.assertIn(
|
|
||||||
self.image_tag1,
|
|
||||||
taglist
|
|
||||||
)
|
|
||||||
|
|
||||||
def test_image_attributes(self):
|
def test_image_attributes(self):
|
||||||
"""Test set, unset, show on attributes, tags and properties"""
|
"""Test set, unset, show on attributes, tags and properties"""
|
||||||
|
|
||||||
# Test explicit attributes
|
# Test explicit attributes
|
||||||
self.openstack(
|
self.openstack(
|
||||||
'image set ' +
|
'image set '
|
||||||
'--min-disk 4 ' +
|
+ '--min-disk 4 '
|
||||||
'--min-ram 5 ' +
|
+ '--min-ram 5 '
|
||||||
'--public ' +
|
+ '--public '
|
||||||
self.name
|
+ self.name
|
||||||
)
|
)
|
||||||
output = self.openstack(
|
output = self.openstack(
|
||||||
'image show ' + self.name,
|
'image show ' + self.name,
|
||||||
@ -118,12 +105,12 @@ class ImageTests(base.BaseImageTests):
|
|||||||
|
|
||||||
# Test properties
|
# Test properties
|
||||||
self.openstack(
|
self.openstack(
|
||||||
'image set ' +
|
'image set '
|
||||||
'--property a=b ' +
|
+ '--property a=b '
|
||||||
'--property c=d ' +
|
+ '--property c=d '
|
||||||
'--property hw_rng_model=virtio ' +
|
+ '--property hw_rng_model=virtio '
|
||||||
'--public ' +
|
+ '--public '
|
||||||
self.name
|
+ self.name
|
||||||
)
|
)
|
||||||
output = self.openstack(
|
output = self.openstack(
|
||||||
'image show ' + self.name,
|
'image show ' + self.name,
|
||||||
@ -133,11 +120,11 @@ class ImageTests(base.BaseImageTests):
|
|||||||
self.assertIn("c", output["properties"])
|
self.assertIn("c", output["properties"])
|
||||||
|
|
||||||
self.openstack(
|
self.openstack(
|
||||||
'image unset ' +
|
'image unset '
|
||||||
'--property a ' +
|
+ '--property a '
|
||||||
'--property c ' +
|
+ '--property c '
|
||||||
'--property hw_rng_model ' +
|
+ '--property hw_rng_model '
|
||||||
self.name
|
+ self.name
|
||||||
)
|
)
|
||||||
output = self.openstack(
|
output = self.openstack(
|
||||||
'image show ' + self.name,
|
'image show ' + self.name,
|
||||||
@ -147,37 +134,20 @@ class ImageTests(base.BaseImageTests):
|
|||||||
self.assertNotIn("c", output["properties"])
|
self.assertNotIn("c", output["properties"])
|
||||||
|
|
||||||
# Test tags
|
# Test tags
|
||||||
self.assertNotIn(
|
self.assertNotIn('01', output["tags"])
|
||||||
'01',
|
self.openstack('image set ' + '--tag 01 ' + self.name)
|
||||||
output["tags"]
|
|
||||||
)
|
|
||||||
self.openstack(
|
|
||||||
'image set ' +
|
|
||||||
'--tag 01 ' +
|
|
||||||
self.name
|
|
||||||
)
|
|
||||||
output = self.openstack(
|
output = self.openstack(
|
||||||
'image show ' + self.name,
|
'image show ' + self.name,
|
||||||
parse_output=True,
|
parse_output=True,
|
||||||
)
|
)
|
||||||
self.assertIn(
|
self.assertIn('01', output["tags"])
|
||||||
'01',
|
|
||||||
output["tags"]
|
|
||||||
)
|
|
||||||
|
|
||||||
self.openstack(
|
self.openstack('image unset ' + '--tag 01 ' + self.name)
|
||||||
'image unset ' +
|
|
||||||
'--tag 01 ' +
|
|
||||||
self.name
|
|
||||||
)
|
|
||||||
output = self.openstack(
|
output = self.openstack(
|
||||||
'image show ' + self.name,
|
'image show ' + self.name,
|
||||||
parse_output=True,
|
parse_output=True,
|
||||||
)
|
)
|
||||||
self.assertNotIn(
|
self.assertNotIn('01', output["tags"])
|
||||||
'01',
|
|
||||||
output["tags"]
|
|
||||||
)
|
|
||||||
|
|
||||||
def test_image_set_rename(self):
|
def test_image_set_rename(self):
|
||||||
name = uuid.uuid4().hex
|
name = uuid.uuid4().hex
|
||||||
@ -190,11 +160,7 @@ class ImageTests(base.BaseImageTests):
|
|||||||
name,
|
name,
|
||||||
output["name"],
|
output["name"],
|
||||||
)
|
)
|
||||||
self.openstack(
|
self.openstack('image set ' + '--name ' + name + 'xx ' + image_id)
|
||||||
'image set ' +
|
|
||||||
'--name ' + name + 'xx ' +
|
|
||||||
image_id
|
|
||||||
)
|
|
||||||
output = self.openstack(
|
output = self.openstack(
|
||||||
'image show ' + name + 'xx',
|
'image show ' + name + 'xx',
|
||||||
parse_output=True,
|
parse_output=True,
|
||||||
@ -216,8 +182,7 @@ class ImageTests(base.BaseImageTests):
|
|||||||
my_project_id = output['project_id']
|
my_project_id = output['project_id']
|
||||||
|
|
||||||
output = self.openstack(
|
output = self.openstack(
|
||||||
'image show -f json ' +
|
'image show -f json ' + self.name,
|
||||||
self.name,
|
|
||||||
parse_output=True,
|
parse_output=True,
|
||||||
)
|
)
|
||||||
# NOTE(dtroyer): Until OSC supports --shared flags in create and set
|
# NOTE(dtroyer): Until OSC supports --shared flags in create and set
|
||||||
@ -225,9 +190,7 @@ class ImageTests(base.BaseImageTests):
|
|||||||
# images are shared and sometimes they are not.
|
# images are shared and sometimes they are not.
|
||||||
if output["visibility"] == 'shared':
|
if output["visibility"] == 'shared':
|
||||||
self.openstack(
|
self.openstack(
|
||||||
'image add project ' +
|
'image add project ' + self.name + ' ' + my_project_id
|
||||||
self.name + ' ' +
|
|
||||||
my_project_id
|
|
||||||
)
|
)
|
||||||
# self.addCleanup(
|
# self.addCleanup(
|
||||||
# self.openstack,
|
# self.openstack,
|
||||||
@ -236,29 +199,16 @@ class ImageTests(base.BaseImageTests):
|
|||||||
# my_project_id
|
# my_project_id
|
||||||
# )
|
# )
|
||||||
|
|
||||||
self.openstack(
|
self.openstack('image set ' + '--accept ' + self.name)
|
||||||
'image set ' +
|
|
||||||
'--accept ' +
|
|
||||||
self.name
|
|
||||||
)
|
|
||||||
output = self.openstack(
|
output = self.openstack(
|
||||||
'image list -f json ' +
|
'image list -f json ' + '--shared',
|
||||||
'--shared',
|
|
||||||
parse_output=True,
|
parse_output=True,
|
||||||
)
|
)
|
||||||
self.assertIn(
|
self.assertIn(self.name, [img['Name'] for img in output])
|
||||||
self.name,
|
|
||||||
[img['Name'] for img in output]
|
|
||||||
)
|
|
||||||
|
|
||||||
self.openstack(
|
self.openstack('image set ' + '--reject ' + self.name)
|
||||||
'image set ' +
|
|
||||||
'--reject ' +
|
|
||||||
self.name
|
|
||||||
)
|
|
||||||
output = self.openstack(
|
output = self.openstack(
|
||||||
'image list -f json ' +
|
'image list -f json ' + '--shared',
|
||||||
'--shared',
|
|
||||||
parse_output=True,
|
parse_output=True,
|
||||||
)
|
)
|
||||||
# self.assertNotIn(
|
# self.assertNotIn(
|
||||||
@ -267,9 +217,7 @@ class ImageTests(base.BaseImageTests):
|
|||||||
# )
|
# )
|
||||||
|
|
||||||
self.openstack(
|
self.openstack(
|
||||||
'image remove project ' +
|
'image remove project ' + self.name + ' ' + my_project_id
|
||||||
self.name + ' ' +
|
|
||||||
my_project_id
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# else:
|
# else:
|
||||||
|
@ -23,7 +23,6 @@ from openstackclient.tests.unit.volume.v1 import fakes as volume_fakes
|
|||||||
|
|
||||||
|
|
||||||
class FakeImagev1Client:
|
class FakeImagev1Client:
|
||||||
|
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
self.images = mock.Mock()
|
self.images = mock.Mock()
|
||||||
|
|
||||||
@ -33,7 +32,6 @@ class FakeImagev1Client:
|
|||||||
|
|
||||||
|
|
||||||
class TestImagev1(utils.TestCommand):
|
class TestImagev1(utils.TestCommand):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super().setUp()
|
super().setUp()
|
||||||
|
|
||||||
@ -71,11 +69,8 @@ def create_one_image(attrs=None):
|
|||||||
'min_ram': 0,
|
'min_ram': 0,
|
||||||
'is_public': True,
|
'is_public': True,
|
||||||
'protected': False,
|
'protected': False,
|
||||||
'properties': {
|
'properties': {'Alpha': 'a', 'Beta': 'b', 'Gamma': 'g'},
|
||||||
'Alpha': 'a',
|
'status': 'status' + uuid.uuid4().hex,
|
||||||
'Beta': 'b',
|
|
||||||
'Gamma': 'g'},
|
|
||||||
'status': 'status' + uuid.uuid4().hex
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Overwrite default attributes if there are some attributes set
|
# Overwrite default attributes if there are some attributes set
|
||||||
|
@ -24,12 +24,10 @@ from openstackclient.tests.unit.image.v1 import fakes as image_fakes
|
|||||||
|
|
||||||
|
|
||||||
class TestImage(image_fakes.TestImagev1):
|
class TestImage(image_fakes.TestImagev1):
|
||||||
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class TestImageCreate(TestImage):
|
class TestImageCreate(TestImage):
|
||||||
|
|
||||||
new_image = image_fakes.create_one_image()
|
new_image = image_fakes.create_one_image()
|
||||||
columns = (
|
columns = (
|
||||||
'container_format',
|
'container_format',
|
||||||
@ -42,7 +40,7 @@ class TestImageCreate(TestImage):
|
|||||||
'owner',
|
'owner',
|
||||||
'properties',
|
'properties',
|
||||||
'protected',
|
'protected',
|
||||||
'size'
|
'size',
|
||||||
)
|
)
|
||||||
data = (
|
data = (
|
||||||
new_image.container_format,
|
new_image.container_format,
|
||||||
@ -55,7 +53,7 @@ class TestImageCreate(TestImage):
|
|||||||
new_image.owner_id,
|
new_image.owner_id,
|
||||||
format_columns.DictColumn(new_image.properties),
|
format_columns.DictColumn(new_image.properties),
|
||||||
new_image.is_protected,
|
new_image.is_protected,
|
||||||
new_image.size
|
new_image.size,
|
||||||
)
|
)
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
@ -89,7 +87,7 @@ class TestImageCreate(TestImage):
|
|||||||
self.client.create_image.assert_called_with(
|
self.client.create_image.assert_called_with(
|
||||||
name=self.new_image.name,
|
name=self.new_image.name,
|
||||||
container_format=image.DEFAULT_CONTAINER_FORMAT,
|
container_format=image.DEFAULT_CONTAINER_FORMAT,
|
||||||
disk_format=image.DEFAULT_DISK_FORMAT
|
disk_format=image.DEFAULT_DISK_FORMAT,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Verify update() was not called, if it was show the args
|
# Verify update() was not called, if it was show the args
|
||||||
@ -101,13 +99,18 @@ class TestImageCreate(TestImage):
|
|||||||
@mock.patch('sys.stdin', side_effect=[None])
|
@mock.patch('sys.stdin', side_effect=[None])
|
||||||
def test_image_reserve_options(self, raw_input):
|
def test_image_reserve_options(self, raw_input):
|
||||||
arglist = [
|
arglist = [
|
||||||
'--container-format', 'ovf',
|
'--container-format',
|
||||||
'--disk-format', 'ami',
|
'ovf',
|
||||||
'--min-disk', '10',
|
'--disk-format',
|
||||||
'--min-ram', '4',
|
'ami',
|
||||||
|
'--min-disk',
|
||||||
|
'10',
|
||||||
|
'--min-ram',
|
||||||
|
'4',
|
||||||
'--protected',
|
'--protected',
|
||||||
'--private',
|
'--private',
|
||||||
'--project', 'q',
|
'--project',
|
||||||
|
'q',
|
||||||
self.new_image.name,
|
self.new_image.name,
|
||||||
]
|
]
|
||||||
verifylist = [
|
verifylist = [
|
||||||
@ -154,11 +157,14 @@ class TestImageCreate(TestImage):
|
|||||||
mock_open.read.return_value = self.data
|
mock_open.read.return_value = self.data
|
||||||
|
|
||||||
arglist = [
|
arglist = [
|
||||||
'--file', 'filer',
|
'--file',
|
||||||
|
'filer',
|
||||||
'--unprotected',
|
'--unprotected',
|
||||||
'--public',
|
'--public',
|
||||||
'--property', 'Alpha=1',
|
'--property',
|
||||||
'--property', 'Beta=2',
|
'Alpha=1',
|
||||||
|
'--property',
|
||||||
|
'Beta=2',
|
||||||
self.new_image.name,
|
self.new_image.name,
|
||||||
]
|
]
|
||||||
verifylist = [
|
verifylist = [
|
||||||
@ -205,7 +211,6 @@ class TestImageCreate(TestImage):
|
|||||||
|
|
||||||
|
|
||||||
class TestImageDelete(TestImage):
|
class TestImageDelete(TestImage):
|
||||||
|
|
||||||
_image = image_fakes.create_one_image()
|
_image = image_fakes.create_one_image()
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
@ -234,7 +239,6 @@ class TestImageDelete(TestImage):
|
|||||||
|
|
||||||
|
|
||||||
class TestImageList(TestImage):
|
class TestImageList(TestImage):
|
||||||
|
|
||||||
_image = image_fakes.create_one_image()
|
_image = image_fakes.create_one_image()
|
||||||
|
|
||||||
columns = (
|
columns = (
|
||||||
@ -242,13 +246,7 @@ class TestImageList(TestImage):
|
|||||||
'Name',
|
'Name',
|
||||||
'Status',
|
'Status',
|
||||||
)
|
)
|
||||||
datalist = (
|
datalist = ((_image.id, _image.name, _image.status),)
|
||||||
(
|
|
||||||
_image.id,
|
|
||||||
_image.name,
|
|
||||||
_image.status
|
|
||||||
),
|
|
||||||
)
|
|
||||||
|
|
||||||
# create a image_info as the side_effect of the fake image_list()
|
# create a image_info as the side_effect of the fake image_list()
|
||||||
info = {
|
info = {
|
||||||
@ -270,7 +268,8 @@ class TestImageList(TestImage):
|
|||||||
|
|
||||||
self.client.images = mock.Mock()
|
self.client.images = mock.Mock()
|
||||||
self.client.images.side_effect = [
|
self.client.images.side_effect = [
|
||||||
[self._image], [],
|
[self._image],
|
||||||
|
[],
|
||||||
]
|
]
|
||||||
|
|
||||||
# Get the command object to test
|
# Get the command object to test
|
||||||
@ -368,30 +367,35 @@ class TestImageList(TestImage):
|
|||||||
)
|
)
|
||||||
|
|
||||||
self.assertEqual(collist, columns)
|
self.assertEqual(collist, columns)
|
||||||
datalist = ((
|
datalist = (
|
||||||
self._image.id,
|
(
|
||||||
self._image.name,
|
self._image.id,
|
||||||
self._image.disk_format,
|
self._image.name,
|
||||||
self._image.container_format,
|
self._image.disk_format,
|
||||||
self._image.size,
|
self._image.container_format,
|
||||||
self._image.checksum,
|
self._image.size,
|
||||||
self._image.status,
|
self._image.checksum,
|
||||||
image.VisibilityColumn(self._image.is_public),
|
self._image.status,
|
||||||
self._image.is_protected,
|
image.VisibilityColumn(self._image.is_public),
|
||||||
self._image.owner_id,
|
self._image.is_protected,
|
||||||
format_columns.DictColumn(
|
self._image.owner_id,
|
||||||
{'Alpha': 'a', 'Beta': 'b', 'Gamma': 'g'}),
|
format_columns.DictColumn(
|
||||||
), )
|
{'Alpha': 'a', 'Beta': 'b', 'Gamma': 'g'}
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
self.assertCountEqual(datalist, tuple(data))
|
self.assertCountEqual(datalist, tuple(data))
|
||||||
|
|
||||||
@mock.patch('osc_lib.api.utils.simple_filter')
|
@mock.patch('osc_lib.api.utils.simple_filter')
|
||||||
def test_image_list_property_option(self, sf_mock):
|
def test_image_list_property_option(self, sf_mock):
|
||||||
sf_mock.side_effect = [
|
sf_mock.side_effect = [
|
||||||
[self.image_info], [],
|
[self.image_info],
|
||||||
|
[],
|
||||||
]
|
]
|
||||||
|
|
||||||
arglist = [
|
arglist = [
|
||||||
'--property', 'a=1',
|
'--property',
|
||||||
|
'a=1',
|
||||||
]
|
]
|
||||||
verifylist = [
|
verifylist = [
|
||||||
('property', {'a': '1'}),
|
('property', {'a': '1'}),
|
||||||
@ -416,7 +420,8 @@ class TestImageList(TestImage):
|
|||||||
@mock.patch('osc_lib.utils.sort_items')
|
@mock.patch('osc_lib.utils.sort_items')
|
||||||
def test_image_list_sort_option(self, si_mock):
|
def test_image_list_sort_option(self, si_mock):
|
||||||
si_mock.side_effect = [
|
si_mock.side_effect = [
|
||||||
[self._image], [],
|
[self._image],
|
||||||
|
[],
|
||||||
]
|
]
|
||||||
|
|
||||||
arglist = ['--sort', 'name:asc']
|
arglist = ['--sort', 'name:asc']
|
||||||
@ -428,17 +433,13 @@ class TestImageList(TestImage):
|
|||||||
# containing the data to be listed.
|
# containing the data to be listed.
|
||||||
columns, data = self.cmd.take_action(parsed_args)
|
columns, data = self.cmd.take_action(parsed_args)
|
||||||
self.client.images.assert_called_with()
|
self.client.images.assert_called_with()
|
||||||
si_mock.assert_called_with(
|
si_mock.assert_called_with([self._image], 'name:asc')
|
||||||
[self._image],
|
|
||||||
'name:asc'
|
|
||||||
)
|
|
||||||
|
|
||||||
self.assertEqual(self.columns, columns)
|
self.assertEqual(self.columns, columns)
|
||||||
self.assertEqual(self.datalist, tuple(data))
|
self.assertEqual(self.datalist, tuple(data))
|
||||||
|
|
||||||
|
|
||||||
class TestImageSet(TestImage):
|
class TestImageSet(TestImage):
|
||||||
|
|
||||||
_image = image_fakes.create_one_image()
|
_image = image_fakes.create_one_image()
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
@ -467,13 +468,20 @@ class TestImageSet(TestImage):
|
|||||||
|
|
||||||
def test_image_set_options(self):
|
def test_image_set_options(self):
|
||||||
arglist = [
|
arglist = [
|
||||||
'--name', 'new-name',
|
'--name',
|
||||||
'--min-disk', '2',
|
'new-name',
|
||||||
'--min-ram', '4',
|
'--min-disk',
|
||||||
'--container-format', 'ovf',
|
'2',
|
||||||
'--disk-format', 'vmdk',
|
'--min-ram',
|
||||||
'--size', '35165824',
|
'4',
|
||||||
'--project', 'new-owner',
|
'--container-format',
|
||||||
|
'ovf',
|
||||||
|
'--disk-format',
|
||||||
|
'vmdk',
|
||||||
|
'--size',
|
||||||
|
'35165824',
|
||||||
|
'--project',
|
||||||
|
'new-owner',
|
||||||
self._image.name,
|
self._image.name,
|
||||||
]
|
]
|
||||||
verifylist = [
|
verifylist = [
|
||||||
@ -497,13 +505,10 @@ class TestImageSet(TestImage):
|
|||||||
'min_ram': 4,
|
'min_ram': 4,
|
||||||
'container_format': 'ovf',
|
'container_format': 'ovf',
|
||||||
'disk_format': 'vmdk',
|
'disk_format': 'vmdk',
|
||||||
'size': 35165824
|
'size': 35165824,
|
||||||
}
|
}
|
||||||
# ImageManager.update(image, **kwargs)
|
# ImageManager.update(image, **kwargs)
|
||||||
self.client.update_image.assert_called_with(
|
self.client.update_image.assert_called_with(self._image.id, **kwargs)
|
||||||
self._image.id,
|
|
||||||
**kwargs
|
|
||||||
)
|
|
||||||
self.assertIsNone(result)
|
self.assertIsNone(result)
|
||||||
|
|
||||||
def test_image_set_bools1(self):
|
def test_image_set_bools1(self):
|
||||||
@ -528,10 +533,7 @@ class TestImageSet(TestImage):
|
|||||||
'is_public': False,
|
'is_public': False,
|
||||||
}
|
}
|
||||||
# ImageManager.update(image, **kwargs)
|
# ImageManager.update(image, **kwargs)
|
||||||
self.client.update_image.assert_called_with(
|
self.client.update_image.assert_called_with(self._image.id, **kwargs)
|
||||||
self._image.id,
|
|
||||||
**kwargs
|
|
||||||
)
|
|
||||||
self.assertIsNone(result)
|
self.assertIsNone(result)
|
||||||
|
|
||||||
def test_image_set_bools2(self):
|
def test_image_set_bools2(self):
|
||||||
@ -556,16 +558,15 @@ class TestImageSet(TestImage):
|
|||||||
'is_public': True,
|
'is_public': True,
|
||||||
}
|
}
|
||||||
# ImageManager.update(image, **kwargs)
|
# ImageManager.update(image, **kwargs)
|
||||||
self.client.update_image.assert_called_with(
|
self.client.update_image.assert_called_with(self._image.id, **kwargs)
|
||||||
self._image.id,
|
|
||||||
**kwargs
|
|
||||||
)
|
|
||||||
self.assertIsNone(result)
|
self.assertIsNone(result)
|
||||||
|
|
||||||
def test_image_set_properties(self):
|
def test_image_set_properties(self):
|
||||||
arglist = [
|
arglist = [
|
||||||
'--property', 'Alpha=1',
|
'--property',
|
||||||
'--property', 'Beta=2',
|
'Alpha=1',
|
||||||
|
'--property',
|
||||||
|
'Beta=2',
|
||||||
self._image.name,
|
self._image.name,
|
||||||
]
|
]
|
||||||
verifylist = [
|
verifylist = [
|
||||||
@ -584,10 +585,7 @@ class TestImageSet(TestImage):
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
# ImageManager.update(image, **kwargs)
|
# ImageManager.update(image, **kwargs)
|
||||||
self.client.update_image.assert_called_with(
|
self.client.update_image.assert_called_with(self._image.id, **kwargs)
|
||||||
self._image.id,
|
|
||||||
**kwargs
|
|
||||||
)
|
|
||||||
self.assertIsNone(result)
|
self.assertIsNone(result)
|
||||||
|
|
||||||
def test_image_update_volume(self):
|
def test_image_update_volume(self):
|
||||||
@ -614,8 +612,10 @@ class TestImageSet(TestImage):
|
|||||||
volumes_mock.upload_to_image.return_value = (201, full_response)
|
volumes_mock.upload_to_image.return_value = (201, full_response)
|
||||||
|
|
||||||
arglist = [
|
arglist = [
|
||||||
'--volume', 'volly',
|
'--volume',
|
||||||
'--name', 'updated_image',
|
'volly',
|
||||||
|
'--name',
|
||||||
|
'updated_image',
|
||||||
self._image.name,
|
self._image.name,
|
||||||
]
|
]
|
||||||
verifylist = [
|
verifylist = [
|
||||||
@ -651,8 +651,10 @@ class TestImageSet(TestImage):
|
|||||||
|
|
||||||
def test_image_set_numeric_options_to_zero(self):
|
def test_image_set_numeric_options_to_zero(self):
|
||||||
arglist = [
|
arglist = [
|
||||||
'--min-disk', '0',
|
'--min-disk',
|
||||||
'--min-ram', '0',
|
'0',
|
||||||
|
'--min-ram',
|
||||||
|
'0',
|
||||||
self._image.name,
|
self._image.name,
|
||||||
]
|
]
|
||||||
verifylist = [
|
verifylist = [
|
||||||
@ -669,15 +671,11 @@ class TestImageSet(TestImage):
|
|||||||
'min_ram': 0,
|
'min_ram': 0,
|
||||||
}
|
}
|
||||||
# ImageManager.update(image, **kwargs)
|
# ImageManager.update(image, **kwargs)
|
||||||
self.client.update_image.assert_called_with(
|
self.client.update_image.assert_called_with(self._image.id, **kwargs)
|
||||||
self._image.id,
|
|
||||||
**kwargs
|
|
||||||
)
|
|
||||||
self.assertIsNone(result)
|
self.assertIsNone(result)
|
||||||
|
|
||||||
|
|
||||||
class TestImageShow(TestImage):
|
class TestImageShow(TestImage):
|
||||||
|
|
||||||
_image = image_fakes.create_one_image(attrs={'size': 2000})
|
_image = image_fakes.create_one_image(attrs={'size': 2000})
|
||||||
columns = (
|
columns = (
|
||||||
'container_format',
|
'container_format',
|
||||||
|
@ -28,7 +28,6 @@ from openstackclient.tests.unit import utils
|
|||||||
|
|
||||||
|
|
||||||
class FakeImagev2Client:
|
class FakeImagev2Client:
|
||||||
|
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
self.images = mock.Mock()
|
self.images = mock.Mock()
|
||||||
self.create_image = mock.Mock()
|
self.create_image = mock.Mock()
|
||||||
@ -62,7 +61,6 @@ class FakeImagev2Client:
|
|||||||
|
|
||||||
|
|
||||||
class TestImagev2(utils.TestCommand):
|
class TestImagev2(utils.TestCommand):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super().setUp()
|
super().setUp()
|
||||||
|
|
||||||
@ -162,7 +160,7 @@ def create_one_import_info(attrs=None):
|
|||||||
'web-download',
|
'web-download',
|
||||||
'glance-download',
|
'glance-download',
|
||||||
'copy-image',
|
'copy-image',
|
||||||
]
|
],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
import_info.update(attrs)
|
import_info.update(attrs)
|
||||||
@ -188,10 +186,10 @@ def create_one_task(attrs=None):
|
|||||||
'input': {
|
'input': {
|
||||||
'image_properties': {
|
'image_properties': {
|
||||||
'container_format': 'ovf',
|
'container_format': 'ovf',
|
||||||
'disk_format': 'vhd'
|
'disk_format': 'vhd',
|
||||||
},
|
},
|
||||||
'import_from': 'https://apps.openstack.org/excellent-image',
|
'import_from': 'https://apps.openstack.org/excellent-image',
|
||||||
'import_from_format': 'qcow2'
|
'import_from_format': 'qcow2',
|
||||||
},
|
},
|
||||||
'message': '',
|
'message': '',
|
||||||
'owner': str(uuid.uuid4()),
|
'owner': str(uuid.uuid4()),
|
||||||
@ -237,7 +235,6 @@ def create_tasks(attrs=None, count=2):
|
|||||||
|
|
||||||
|
|
||||||
class FakeMetadefNamespaceClient:
|
class FakeMetadefNamespaceClient:
|
||||||
|
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
self.create_metadef_namespace = mock.Mock()
|
self.create_metadef_namespace = mock.Mock()
|
||||||
self.delete_metadef_namespace = mock.Mock()
|
self.delete_metadef_namespace = mock.Mock()
|
||||||
@ -251,7 +248,6 @@ class FakeMetadefNamespaceClient:
|
|||||||
|
|
||||||
|
|
||||||
class TestMetadefNamespaces(utils.TestCommand):
|
class TestMetadefNamespaces(utils.TestCommand):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super().setUp()
|
super().setUp()
|
||||||
|
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -45,7 +45,7 @@ class TestMetadefNamespaceCreate(TestMetadefNamespaces):
|
|||||||
'owner',
|
'owner',
|
||||||
'resource_type_associations',
|
'resource_type_associations',
|
||||||
'updated_at',
|
'updated_at',
|
||||||
'visibility'
|
'visibility',
|
||||||
)
|
)
|
||||||
expected_data = (
|
expected_data = (
|
||||||
_metadef_namespace.created_at,
|
_metadef_namespace.created_at,
|
||||||
@ -59,25 +59,22 @@ class TestMetadefNamespaceCreate(TestMetadefNamespaces):
|
|||||||
_metadef_namespace.owner,
|
_metadef_namespace.owner,
|
||||||
_metadef_namespace.resource_type_associations,
|
_metadef_namespace.resource_type_associations,
|
||||||
_metadef_namespace.updated_at,
|
_metadef_namespace.updated_at,
|
||||||
_metadef_namespace.visibility
|
_metadef_namespace.visibility,
|
||||||
)
|
)
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super().setUp()
|
super().setUp()
|
||||||
|
|
||||||
self.client.create_metadef_namespace.return_value \
|
self.client.create_metadef_namespace.return_value = (
|
||||||
= self._metadef_namespace
|
self._metadef_namespace
|
||||||
|
)
|
||||||
self.cmd = metadef_namespaces.CreateMetadefNameSpace(self.app, None)
|
self.cmd = metadef_namespaces.CreateMetadefNameSpace(self.app, None)
|
||||||
self.datalist = self._metadef_namespace
|
self.datalist = self._metadef_namespace
|
||||||
|
|
||||||
def test_namespace_create(self):
|
def test_namespace_create(self):
|
||||||
arglist = [
|
arglist = [self._metadef_namespace.namespace]
|
||||||
self._metadef_namespace.namespace
|
|
||||||
]
|
|
||||||
|
|
||||||
verifylist = [
|
verifylist = []
|
||||||
|
|
||||||
]
|
|
||||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
|
|
||||||
columns, data = self.cmd.take_action(parsed_args)
|
columns, data = self.cmd.take_action(parsed_args)
|
||||||
@ -92,19 +89,16 @@ class TestMetadefNamespaceDelete(TestMetadefNamespaces):
|
|||||||
def setUp(self):
|
def setUp(self):
|
||||||
super().setUp()
|
super().setUp()
|
||||||
|
|
||||||
self.client.delete_metadef_namespace.return_value \
|
self.client.delete_metadef_namespace.return_value = (
|
||||||
= self._metadef_namespace
|
self._metadef_namespace
|
||||||
|
)
|
||||||
self.cmd = metadef_namespaces.DeleteMetadefNameSpace(self.app, None)
|
self.cmd = metadef_namespaces.DeleteMetadefNameSpace(self.app, None)
|
||||||
self.datalist = self._metadef_namespace
|
self.datalist = self._metadef_namespace
|
||||||
|
|
||||||
def test_namespace_create(self):
|
def test_namespace_create(self):
|
||||||
arglist = [
|
arglist = [self._metadef_namespace.namespace]
|
||||||
self._metadef_namespace.namespace
|
|
||||||
]
|
|
||||||
|
|
||||||
verifylist = [
|
verifylist = []
|
||||||
|
|
||||||
]
|
|
||||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
|
|
||||||
result = self.cmd.take_action(parsed_args)
|
result = self.cmd.take_action(parsed_args)
|
||||||
@ -115,9 +109,7 @@ class TestMetadefNamespaceDelete(TestMetadefNamespaces):
|
|||||||
class TestMetadefNamespaceList(TestMetadefNamespaces):
|
class TestMetadefNamespaceList(TestMetadefNamespaces):
|
||||||
_metadef_namespace = [md_namespace_fakes.create_one_metadef_namespace()]
|
_metadef_namespace = [md_namespace_fakes.create_one_metadef_namespace()]
|
||||||
|
|
||||||
columns = [
|
columns = ['namespace']
|
||||||
'namespace'
|
|
||||||
]
|
|
||||||
|
|
||||||
datalist = []
|
datalist = []
|
||||||
|
|
||||||
@ -125,7 +117,9 @@ class TestMetadefNamespaceList(TestMetadefNamespaces):
|
|||||||
super().setUp()
|
super().setUp()
|
||||||
|
|
||||||
self.client.metadef_namespaces.side_effect = [
|
self.client.metadef_namespaces.side_effect = [
|
||||||
self._metadef_namespace, []]
|
self._metadef_namespace,
|
||||||
|
[],
|
||||||
|
]
|
||||||
|
|
||||||
# Get the command object to test
|
# Get the command object to test
|
||||||
self.client.metadef_namespaces.return_value = iter(
|
self.client.metadef_namespaces.return_value = iter(
|
||||||
@ -144,8 +138,7 @@ class TestMetadefNamespaceList(TestMetadefNamespaces):
|
|||||||
columns, data = self.cmd.take_action(parsed_args)
|
columns, data = self.cmd.take_action(parsed_args)
|
||||||
|
|
||||||
self.assertEqual(self.columns, columns)
|
self.assertEqual(self.columns, columns)
|
||||||
self.assertEqual(getattr(self.datalist[0], 'namespace'),
|
self.assertEqual(getattr(self.datalist[0], 'namespace'), next(data)[0])
|
||||||
next(data)[0])
|
|
||||||
|
|
||||||
|
|
||||||
class TestMetadefNamespaceSet(TestMetadefNamespaces):
|
class TestMetadefNamespaceSet(TestMetadefNamespaces):
|
||||||
@ -154,15 +147,14 @@ class TestMetadefNamespaceSet(TestMetadefNamespaces):
|
|||||||
def setUp(self):
|
def setUp(self):
|
||||||
super().setUp()
|
super().setUp()
|
||||||
|
|
||||||
self.client.update_metadef_namespace.return_value \
|
self.client.update_metadef_namespace.return_value = (
|
||||||
= self._metadef_namespace
|
self._metadef_namespace
|
||||||
|
)
|
||||||
self.cmd = metadef_namespaces.SetMetadefNameSpace(self.app, None)
|
self.cmd = metadef_namespaces.SetMetadefNameSpace(self.app, None)
|
||||||
self.datalist = self._metadef_namespace
|
self.datalist = self._metadef_namespace
|
||||||
|
|
||||||
def test_namespace_set_no_options(self):
|
def test_namespace_set_no_options(self):
|
||||||
arglist = [
|
arglist = [self._metadef_namespace.namespace]
|
||||||
self._metadef_namespace.namespace
|
|
||||||
]
|
|
||||||
verifylist = [
|
verifylist = [
|
||||||
('namespace', self._metadef_namespace.namespace),
|
('namespace', self._metadef_namespace.namespace),
|
||||||
]
|
]
|
||||||
@ -182,31 +174,28 @@ class TestMetadefNamespaceShow(TestMetadefNamespaces):
|
|||||||
'display_name',
|
'display_name',
|
||||||
'namespace',
|
'namespace',
|
||||||
'owner',
|
'owner',
|
||||||
'visibility'
|
'visibility',
|
||||||
)
|
)
|
||||||
expected_data = (
|
expected_data = (
|
||||||
_metadef_namespace.created_at,
|
_metadef_namespace.created_at,
|
||||||
_metadef_namespace.display_name,
|
_metadef_namespace.display_name,
|
||||||
_metadef_namespace.namespace,
|
_metadef_namespace.namespace,
|
||||||
_metadef_namespace.owner,
|
_metadef_namespace.owner,
|
||||||
_metadef_namespace.visibility
|
_metadef_namespace.visibility,
|
||||||
)
|
)
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super().setUp()
|
super().setUp()
|
||||||
|
|
||||||
self.client.get_metadef_namespace.return_value \
|
self.client.get_metadef_namespace.return_value = (
|
||||||
= self._metadef_namespace
|
self._metadef_namespace
|
||||||
|
)
|
||||||
self.cmd = metadef_namespaces.ShowMetadefNameSpace(self.app, None)
|
self.cmd = metadef_namespaces.ShowMetadefNameSpace(self.app, None)
|
||||||
|
|
||||||
def test_namespace_show_no_options(self):
|
def test_namespace_show_no_options(self):
|
||||||
arglist = [
|
arglist = [self._metadef_namespace.namespace]
|
||||||
self._metadef_namespace.namespace
|
|
||||||
]
|
|
||||||
|
|
||||||
verifylist = [
|
verifylist = []
|
||||||
|
|
||||||
]
|
|
||||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
|
|
||||||
columns, data = self.cmd.take_action(parsed_args)
|
columns, data = self.cmd.take_action(parsed_args)
|
||||||
|
@ -25,7 +25,6 @@ class TestTask(image_fakes.TestImagev2):
|
|||||||
|
|
||||||
|
|
||||||
class TestTaskShow(TestTask):
|
class TestTaskShow(TestTask):
|
||||||
|
|
||||||
task = image_fakes.create_one_task()
|
task = image_fakes.create_one_task()
|
||||||
|
|
||||||
columns = (
|
columns = (
|
||||||
@ -81,7 +80,6 @@ class TestTaskShow(TestTask):
|
|||||||
|
|
||||||
|
|
||||||
class TestTaskList(TestTask):
|
class TestTaskList(TestTask):
|
||||||
|
|
||||||
tasks = image_fakes.create_tasks()
|
tasks = image_fakes.create_tasks()
|
||||||
|
|
||||||
columns = (
|
columns = (
|
||||||
|
Loading…
x
Reference in New Issue
Block a user