Blacken openstackclient.compute
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: I9af45c062d179ab3dc2a5e969e1c467932753a2b Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
This commit is contained in:
parent
5cb16aebcc
commit
28ffa2bf9f
@ -51,11 +51,13 @@ def make_client(instance):
|
||||
else:
|
||||
version = instance._api_version[API_NAME]
|
||||
from novaclient import api_versions
|
||||
|
||||
# convert to APIVersion object
|
||||
version = api_versions.get_api_version(version)
|
||||
|
||||
if version.is_latest():
|
||||
import novaclient
|
||||
|
||||
# NOTE(RuiChen): executing version discovery make sense, but that need
|
||||
# an initialized REST client, it's not available now,
|
||||
# fallback to use the max version of novaclient side.
|
||||
@ -73,8 +75,11 @@ def make_client(instance):
|
||||
# Set client http_log_debug to True if verbosity level is high enough
|
||||
http_log_debug = utils.get_effective_log_level() <= logging.DEBUG
|
||||
|
||||
extensions = [ext for ext in nova_client.discover_extensions(version)
|
||||
if ext.name == "list_extensions"]
|
||||
extensions = [
|
||||
ext
|
||||
for ext in nova_client.discover_extensions(version)
|
||||
if ext.name == "list_extensions"
|
||||
]
|
||||
|
||||
# Remember interface only if it is set
|
||||
kwargs = utils.build_kwargs_dict('endpoint_type', instance.interface)
|
||||
@ -96,7 +101,7 @@ def make_client(instance):
|
||||
COMPUTE_API_TYPE,
|
||||
region_name=instance.region_name,
|
||||
interface=instance.interface,
|
||||
)
|
||||
),
|
||||
)
|
||||
|
||||
return client
|
||||
@ -108,8 +113,10 @@ def build_option_parser(parser):
|
||||
'--os-compute-api-version',
|
||||
metavar='<compute-api-version>',
|
||||
default=utils.env('OS_COMPUTE_API_VERSION'),
|
||||
help=_("Compute API version, default=%s "
|
||||
"(Env: OS_COMPUTE_API_VERSION)") % DEFAULT_API_VERSION
|
||||
help=_(
|
||||
"Compute API version, default=%s " "(Env: OS_COMPUTE_API_VERSION)"
|
||||
)
|
||||
% DEFAULT_API_VERSION,
|
||||
)
|
||||
return parser
|
||||
|
||||
|
@ -37,36 +37,20 @@ class CreateAgent(command.ShowOne):
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(CreateAgent, self).get_parser(prog_name)
|
||||
parser.add_argument(
|
||||
"os",
|
||||
metavar="<os>",
|
||||
help=_("Type of OS")
|
||||
)
|
||||
parser.add_argument("os", metavar="<os>", help=_("Type of OS"))
|
||||
parser.add_argument(
|
||||
"architecture",
|
||||
metavar="<architecture>",
|
||||
help=_("Type of architecture")
|
||||
)
|
||||
parser.add_argument(
|
||||
"version",
|
||||
metavar="<version>",
|
||||
help=_("Version")
|
||||
)
|
||||
parser.add_argument(
|
||||
"url",
|
||||
metavar="<url>",
|
||||
help=_("URL")
|
||||
)
|
||||
parser.add_argument(
|
||||
"md5hash",
|
||||
metavar="<md5hash>",
|
||||
help=_("MD5 hash")
|
||||
help=_("Type of architecture"),
|
||||
)
|
||||
parser.add_argument("version", metavar="<version>", help=_("Version"))
|
||||
parser.add_argument("url", metavar="<url>", help=_("URL"))
|
||||
parser.add_argument("md5hash", metavar="<md5hash>", help=_("MD5 hash"))
|
||||
parser.add_argument(
|
||||
"hypervisor",
|
||||
metavar="<hypervisor>",
|
||||
default="xen",
|
||||
help=_("Type of hypervisor")
|
||||
help=_("Type of hypervisor"),
|
||||
)
|
||||
return parser
|
||||
|
||||
@ -78,7 +62,7 @@ class CreateAgent(command.ShowOne):
|
||||
parsed_args.version,
|
||||
parsed_args.url,
|
||||
parsed_args.md5hash,
|
||||
parsed_args.hypervisor
|
||||
parsed_args.hypervisor,
|
||||
)
|
||||
agent = compute_client.agents.create(*args)._info.copy()
|
||||
return zip(*sorted(agent.items()))
|
||||
@ -95,10 +79,7 @@ class DeleteAgent(command.Command):
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(DeleteAgent, self).get_parser(prog_name)
|
||||
parser.add_argument(
|
||||
"id",
|
||||
metavar="<id>",
|
||||
nargs='+',
|
||||
help=_("ID of agent(s) to delete")
|
||||
"id", metavar="<id>", nargs='+', help=_("ID of agent(s) to delete")
|
||||
)
|
||||
return parser
|
||||
|
||||
@ -110,13 +91,17 @@ class DeleteAgent(command.Command):
|
||||
compute_client.agents.delete(id)
|
||||
except Exception as e:
|
||||
result += 1
|
||||
LOG.error(_("Failed to delete agent with ID '%(id)s': %(e)s"),
|
||||
{'id': id, 'e': e})
|
||||
LOG.error(
|
||||
_("Failed to delete agent with ID '%(id)s': %(e)s"),
|
||||
{'id': id, 'e': e},
|
||||
)
|
||||
|
||||
if result > 0:
|
||||
total = len(parsed_args.id)
|
||||
msg = (_("%(result)s of %(total)s agents failed "
|
||||
"to delete.") % {'result': result, 'total': total})
|
||||
msg = _("%(result)s of %(total)s agents failed " "to delete.") % {
|
||||
'result': result,
|
||||
'total': total,
|
||||
}
|
||||
raise exceptions.CommandError(msg)
|
||||
|
||||
|
||||
@ -133,7 +118,7 @@ class ListAgent(command.Lister):
|
||||
parser.add_argument(
|
||||
"--hypervisor",
|
||||
metavar="<hypervisor>",
|
||||
help=_("Type of hypervisor")
|
||||
help=_("Type of hypervisor"),
|
||||
)
|
||||
return parser
|
||||
|
||||
@ -146,13 +131,19 @@ class ListAgent(command.Lister):
|
||||
"Architecture",
|
||||
"Version",
|
||||
"Md5Hash",
|
||||
"URL"
|
||||
"URL",
|
||||
)
|
||||
data = compute_client.agents.list(parsed_args.hypervisor)
|
||||
return (columns,
|
||||
(utils.get_item_properties(
|
||||
s, columns,
|
||||
) for s in data))
|
||||
return (
|
||||
columns,
|
||||
(
|
||||
utils.get_item_properties(
|
||||
s,
|
||||
columns,
|
||||
)
|
||||
for s in data
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
class SetAgent(command.Command):
|
||||
@ -165,26 +156,18 @@ class SetAgent(command.Command):
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(SetAgent, self).get_parser(prog_name)
|
||||
parser.add_argument(
|
||||
"id",
|
||||
metavar="<id>",
|
||||
help=_("ID of the agent")
|
||||
)
|
||||
parser.add_argument("id", metavar="<id>", help=_("ID of the agent"))
|
||||
parser.add_argument(
|
||||
"--agent-version",
|
||||
dest="version",
|
||||
metavar="<version>",
|
||||
help=_("Version of the agent")
|
||||
help=_("Version of the agent"),
|
||||
)
|
||||
parser.add_argument(
|
||||
"--url",
|
||||
metavar="<url>",
|
||||
help=_("URL of the agent")
|
||||
"--url", metavar="<url>", help=_("URL of the agent")
|
||||
)
|
||||
parser.add_argument(
|
||||
"--md5hash",
|
||||
metavar="<md5hash>",
|
||||
help=_("MD5 hash of the agent")
|
||||
"--md5hash", metavar="<md5hash>", help=_("MD5 hash of the agent")
|
||||
)
|
||||
return parser
|
||||
|
||||
|
@ -47,7 +47,8 @@ def _get_aggregate_columns(item):
|
||||
}
|
||||
hidden_columns = ['links', 'location']
|
||||
return utils.get_osc_show_columns_for_sdk_resource(
|
||||
item, column_map, hidden_columns)
|
||||
item, column_map, hidden_columns
|
||||
)
|
||||
|
||||
|
||||
class AddAggregateHost(command.ShowOne):
|
||||
@ -58,12 +59,10 @@ class AddAggregateHost(command.ShowOne):
|
||||
parser.add_argument(
|
||||
'aggregate',
|
||||
metavar='<aggregate>',
|
||||
help=_("Aggregate (name or ID)")
|
||||
help=_("Aggregate (name or ID)"),
|
||||
)
|
||||
parser.add_argument(
|
||||
'host',
|
||||
metavar='<host>',
|
||||
help=_("Host to add to <aggregate>")
|
||||
'host', metavar='<host>', help=_("Host to add to <aggregate>")
|
||||
)
|
||||
return parser
|
||||
|
||||
@ -71,14 +70,17 @@ class AddAggregateHost(command.ShowOne):
|
||||
compute_client = self.app.client_manager.sdk_connection.compute
|
||||
|
||||
aggregate = compute_client.find_aggregate(
|
||||
parsed_args.aggregate, ignore_missing=False)
|
||||
parsed_args.aggregate, ignore_missing=False
|
||||
)
|
||||
|
||||
aggregate = compute_client.add_host_to_aggregate(
|
||||
aggregate.id, parsed_args.host)
|
||||
aggregate.id, parsed_args.host
|
||||
)
|
||||
|
||||
display_columns, columns = _get_aggregate_columns(aggregate)
|
||||
data = utils.get_item_properties(
|
||||
aggregate, columns, formatters=_aggregate_formatters)
|
||||
aggregate, columns, formatters=_aggregate_formatters
|
||||
)
|
||||
return (display_columns, data)
|
||||
|
||||
|
||||
@ -88,22 +90,22 @@ class CreateAggregate(command.ShowOne):
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(CreateAggregate, self).get_parser(prog_name)
|
||||
parser.add_argument(
|
||||
"name",
|
||||
metavar="<name>",
|
||||
help=_("New aggregate name")
|
||||
"name", metavar="<name>", help=_("New aggregate name")
|
||||
)
|
||||
parser.add_argument(
|
||||
"--zone",
|
||||
metavar="<availability-zone>",
|
||||
help=_("Availability zone name")
|
||||
help=_("Availability zone name"),
|
||||
)
|
||||
parser.add_argument(
|
||||
"--property",
|
||||
metavar="<key=value>",
|
||||
action=parseractions.KeyValueAction,
|
||||
dest="properties",
|
||||
help=_("Property to add to this aggregate "
|
||||
"(repeat option to set multiple properties)")
|
||||
help=_(
|
||||
"Property to add to this aggregate "
|
||||
"(repeat option to set multiple properties)"
|
||||
),
|
||||
)
|
||||
return parser
|
||||
|
||||
@ -125,7 +127,8 @@ class CreateAggregate(command.ShowOne):
|
||||
|
||||
display_columns, columns = _get_aggregate_columns(aggregate)
|
||||
data = utils.get_item_properties(
|
||||
aggregate, columns, formatters=_aggregate_formatters)
|
||||
aggregate, columns, formatters=_aggregate_formatters
|
||||
)
|
||||
return (display_columns, data)
|
||||
|
||||
|
||||
@ -138,7 +141,7 @@ class DeleteAggregate(command.Command):
|
||||
'aggregate',
|
||||
metavar='<aggregate>',
|
||||
nargs='+',
|
||||
help=_("Aggregate(s) to delete (name or ID)")
|
||||
help=_("Aggregate(s) to delete (name or ID)"),
|
||||
)
|
||||
return parser
|
||||
|
||||
@ -148,19 +151,26 @@ class DeleteAggregate(command.Command):
|
||||
for a in parsed_args.aggregate:
|
||||
try:
|
||||
aggregate = compute_client.find_aggregate(
|
||||
a, ignore_missing=False)
|
||||
a, ignore_missing=False
|
||||
)
|
||||
compute_client.delete_aggregate(
|
||||
aggregate.id, ignore_missing=False)
|
||||
aggregate.id, ignore_missing=False
|
||||
)
|
||||
except Exception as e:
|
||||
result += 1
|
||||
LOG.error(_("Failed to delete aggregate with name or "
|
||||
"ID '%(aggregate)s': %(e)s"),
|
||||
{'aggregate': a, 'e': e})
|
||||
LOG.error(
|
||||
_(
|
||||
"Failed to delete aggregate with name or "
|
||||
"ID '%(aggregate)s': %(e)s"
|
||||
),
|
||||
{'aggregate': a, 'e': e},
|
||||
)
|
||||
|
||||
if result > 0:
|
||||
total = len(parsed_args.aggregate)
|
||||
msg = (_("%(result)s of %(total)s aggregates failed "
|
||||
"to delete.") % {'result': result, 'total': total})
|
||||
msg = _(
|
||||
"%(result)s of %(total)s aggregates failed " "to delete."
|
||||
) % {'result': result, 'total': total}
|
||||
raise exceptions.CommandError(msg)
|
||||
|
||||
|
||||
@ -173,7 +183,7 @@ class ListAggregate(command.Lister):
|
||||
'--long',
|
||||
action='store_true',
|
||||
default=False,
|
||||
help=_("List additional fields in output")
|
||||
help=_("List additional fields in output"),
|
||||
)
|
||||
return parser
|
||||
|
||||
@ -212,7 +222,9 @@ class ListAggregate(command.Lister):
|
||||
data = (
|
||||
utils.get_item_properties(
|
||||
s, columns, formatters=_aggregate_formatters
|
||||
) for s in aggregates)
|
||||
)
|
||||
for s in aggregates
|
||||
)
|
||||
return (column_headers, data)
|
||||
|
||||
|
||||
@ -224,12 +236,10 @@ class RemoveAggregateHost(command.ShowOne):
|
||||
parser.add_argument(
|
||||
'aggregate',
|
||||
metavar='<aggregate>',
|
||||
help=_("Aggregate (name or ID)")
|
||||
help=_("Aggregate (name or ID)"),
|
||||
)
|
||||
parser.add_argument(
|
||||
'host',
|
||||
metavar='<host>',
|
||||
help=_("Host to remove from <aggregate>")
|
||||
'host', metavar='<host>', help=_("Host to remove from <aggregate>")
|
||||
)
|
||||
return parser
|
||||
|
||||
@ -237,14 +247,17 @@ class RemoveAggregateHost(command.ShowOne):
|
||||
compute_client = self.app.client_manager.sdk_connection.compute
|
||||
|
||||
aggregate = compute_client.find_aggregate(
|
||||
parsed_args.aggregate, ignore_missing=False)
|
||||
parsed_args.aggregate, ignore_missing=False
|
||||
)
|
||||
|
||||
aggregate = compute_client.remove_host_from_aggregate(
|
||||
aggregate.id, parsed_args.host)
|
||||
aggregate.id, parsed_args.host
|
||||
)
|
||||
|
||||
display_columns, columns = _get_aggregate_columns(aggregate)
|
||||
data = utils.get_item_properties(
|
||||
aggregate, columns, formatters=_aggregate_formatters)
|
||||
aggregate, columns, formatters=_aggregate_formatters
|
||||
)
|
||||
return (display_columns, data)
|
||||
|
||||
|
||||
@ -256,40 +269,42 @@ class SetAggregate(command.Command):
|
||||
parser.add_argument(
|
||||
'aggregate',
|
||||
metavar='<aggregate>',
|
||||
help=_("Aggregate to modify (name or ID)")
|
||||
help=_("Aggregate to modify (name or ID)"),
|
||||
)
|
||||
parser.add_argument(
|
||||
'--name',
|
||||
metavar='<name>',
|
||||
help=_("Set aggregate name")
|
||||
'--name', metavar='<name>', help=_("Set aggregate name")
|
||||
)
|
||||
parser.add_argument(
|
||||
"--zone",
|
||||
metavar="<availability-zone>",
|
||||
help=_("Set availability zone name")
|
||||
help=_("Set availability zone name"),
|
||||
)
|
||||
parser.add_argument(
|
||||
"--property",
|
||||
metavar="<key=value>",
|
||||
action=parseractions.KeyValueAction,
|
||||
dest="properties",
|
||||
help=_("Property to set on <aggregate> "
|
||||
"(repeat option to set multiple properties)")
|
||||
help=_(
|
||||
"Property to set on <aggregate> "
|
||||
"(repeat option to set multiple properties)"
|
||||
),
|
||||
)
|
||||
parser.add_argument(
|
||||
"--no-property",
|
||||
action="store_true",
|
||||
help=_("Remove all properties from <aggregate> "
|
||||
"(specify both --property and --no-property to "
|
||||
"overwrite the current properties)"),
|
||||
help=_(
|
||||
"Remove all properties from <aggregate> "
|
||||
"(specify both --property and --no-property to "
|
||||
"overwrite the current properties)"
|
||||
),
|
||||
)
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
|
||||
compute_client = self.app.client_manager.sdk_connection.compute
|
||||
aggregate = compute_client.find_aggregate(
|
||||
parsed_args.aggregate, ignore_missing=False)
|
||||
parsed_args.aggregate, ignore_missing=False
|
||||
)
|
||||
|
||||
kwargs = {}
|
||||
if parsed_args.name:
|
||||
@ -303,10 +318,13 @@ class SetAggregate(command.Command):
|
||||
if parsed_args.no_property:
|
||||
# NOTE(RuiChen): "availability_zone" can not be unset from
|
||||
# properties. It is already excluded from show and create output.
|
||||
properties.update({
|
||||
key: None for key in aggregate.metadata.keys()
|
||||
if key != 'availability_zone'
|
||||
})
|
||||
properties.update(
|
||||
{
|
||||
key: None
|
||||
for key in aggregate.metadata.keys()
|
||||
if key != 'availability_zone'
|
||||
}
|
||||
)
|
||||
|
||||
if parsed_args.properties:
|
||||
properties.update(parsed_args.properties)
|
||||
@ -323,15 +341,15 @@ class ShowAggregate(command.ShowOne):
|
||||
parser.add_argument(
|
||||
'aggregate',
|
||||
metavar='<aggregate>',
|
||||
help=_("Aggregate to display (name or ID)")
|
||||
help=_("Aggregate to display (name or ID)"),
|
||||
)
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
|
||||
compute_client = self.app.client_manager.sdk_connection.compute
|
||||
aggregate = compute_client.find_aggregate(
|
||||
parsed_args.aggregate, ignore_missing=False)
|
||||
parsed_args.aggregate, ignore_missing=False
|
||||
)
|
||||
|
||||
# Remove availability_zone from metadata because Nova doesn't
|
||||
if 'availability_zone' in aggregate.metadata:
|
||||
@ -339,7 +357,8 @@ class ShowAggregate(command.ShowOne):
|
||||
|
||||
display_columns, columns = _get_aggregate_columns(aggregate)
|
||||
data = utils.get_item_properties(
|
||||
aggregate, columns, formatters=_aggregate_formatters)
|
||||
aggregate, columns, formatters=_aggregate_formatters
|
||||
)
|
||||
return (display_columns, data)
|
||||
|
||||
|
||||
@ -351,7 +370,7 @@ class UnsetAggregate(command.Command):
|
||||
parser.add_argument(
|
||||
"aggregate",
|
||||
metavar="<aggregate>",
|
||||
help=_("Aggregate to modify (name or ID)")
|
||||
help=_("Aggregate to modify (name or ID)"),
|
||||
)
|
||||
parser.add_argument(
|
||||
"--property",
|
||||
@ -359,15 +378,18 @@ class UnsetAggregate(command.Command):
|
||||
action="append",
|
||||
default=[],
|
||||
dest="properties",
|
||||
help=_("Property to remove from aggregate "
|
||||
"(repeat option to remove multiple properties)")
|
||||
help=_(
|
||||
"Property to remove from aggregate "
|
||||
"(repeat option to remove multiple properties)"
|
||||
),
|
||||
)
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
compute_client = self.app.client_manager.sdk_connection.compute
|
||||
aggregate = compute_client.find_aggregate(
|
||||
parsed_args.aggregate, ignore_missing=False)
|
||||
parsed_args.aggregate, ignore_missing=False
|
||||
)
|
||||
|
||||
properties = {key: None for key in parsed_args.properties}
|
||||
|
||||
@ -385,14 +407,16 @@ class CacheImageForAggregate(command.Command):
|
||||
parser.add_argument(
|
||||
'aggregate',
|
||||
metavar='<aggregate>',
|
||||
help=_("Aggregate (name or ID)")
|
||||
help=_("Aggregate (name or ID)"),
|
||||
)
|
||||
parser.add_argument(
|
||||
'image',
|
||||
metavar='<image>',
|
||||
nargs='+',
|
||||
help=_("Image ID to request caching for aggregate (name or ID). "
|
||||
"May be specified multiple times.")
|
||||
help=_(
|
||||
"Image ID to request caching for aggregate (name or ID). "
|
||||
"May be specified multiple times."
|
||||
),
|
||||
)
|
||||
return parser
|
||||
|
||||
@ -407,12 +431,14 @@ class CacheImageForAggregate(command.Command):
|
||||
raise exceptions.CommandError(msg)
|
||||
|
||||
aggregate = compute_client.find_aggregate(
|
||||
parsed_args.aggregate, ignore_missing=False)
|
||||
parsed_args.aggregate, ignore_missing=False
|
||||
)
|
||||
|
||||
images = []
|
||||
for img in parsed_args.image:
|
||||
image = self.app.client_manager.sdk_connection.image.find_image(
|
||||
img, ignore_missing=False)
|
||||
img, ignore_missing=False
|
||||
)
|
||||
images.append(image.id)
|
||||
|
||||
compute_client.aggregate_precache_images(aggregate.id, images)
|
||||
|
@ -28,7 +28,8 @@ def _get_console_columns(item):
|
||||
column_map = {}
|
||||
hidden_columns = ['id', 'links', 'location', 'name']
|
||||
return utils.get_osc_show_columns_for_sdk_resource(
|
||||
item, column_map, hidden_columns)
|
||||
item, column_map, hidden_columns
|
||||
)
|
||||
|
||||
|
||||
class ShowConsoleLog(command.Command):
|
||||
@ -39,7 +40,7 @@ class ShowConsoleLog(command.Command):
|
||||
parser.add_argument(
|
||||
'server',
|
||||
metavar='<server>',
|
||||
help=_("Server to show console log (name or ID)")
|
||||
help=_("Server to show console log (name or ID)"),
|
||||
)
|
||||
parser.add_argument(
|
||||
'--lines',
|
||||
@ -47,8 +48,10 @@ class ShowConsoleLog(command.Command):
|
||||
type=int,
|
||||
default=None,
|
||||
action=parseractions.NonNegativeAction,
|
||||
help=_("Number of lines to display from the end of the log "
|
||||
"(default=all)")
|
||||
help=_(
|
||||
"Number of lines to display from the end of the log "
|
||||
"(default=all)"
|
||||
),
|
||||
)
|
||||
return parser
|
||||
|
||||
@ -56,12 +59,12 @@ class ShowConsoleLog(command.Command):
|
||||
compute_client = self.app.client_manager.sdk_connection.compute
|
||||
|
||||
server = compute_client.find_server(
|
||||
name_or_id=parsed_args.server,
|
||||
ignore_missing=False
|
||||
name_or_id=parsed_args.server, ignore_missing=False
|
||||
)
|
||||
|
||||
output = compute_client.get_server_console_output(
|
||||
server.id, length=parsed_args.lines)
|
||||
server.id, length=parsed_args.lines
|
||||
)
|
||||
data = None
|
||||
if output:
|
||||
data = output.get('output', None)
|
||||
@ -79,7 +82,7 @@ class ShowConsoleURL(command.ShowOne):
|
||||
parser.add_argument(
|
||||
'server',
|
||||
metavar='<server>',
|
||||
help=_("Server to show URL (name or ID)")
|
||||
help=_("Server to show URL (name or ID)"),
|
||||
)
|
||||
type_group = parser.add_mutually_exclusive_group()
|
||||
type_group.add_argument(
|
||||
@ -88,21 +91,21 @@ class ShowConsoleURL(command.ShowOne):
|
||||
action='store_const',
|
||||
const='novnc',
|
||||
default='novnc',
|
||||
help=_("Show noVNC console URL (default)")
|
||||
help=_("Show noVNC console URL (default)"),
|
||||
)
|
||||
type_group.add_argument(
|
||||
'--xvpvnc',
|
||||
dest='url_type',
|
||||
action='store_const',
|
||||
const='xvpvnc',
|
||||
help=_("Show xvpvnc console URL")
|
||||
help=_("Show xvpvnc console URL"),
|
||||
)
|
||||
type_group.add_argument(
|
||||
'--spice',
|
||||
dest='url_type',
|
||||
action='store_const',
|
||||
const='spice-html5',
|
||||
help=_("Show SPICE console URL")
|
||||
help=_("Show SPICE console URL"),
|
||||
)
|
||||
type_group.add_argument(
|
||||
'--rdp',
|
||||
@ -130,11 +133,12 @@ class ShowConsoleURL(command.ShowOne):
|
||||
def take_action(self, parsed_args):
|
||||
compute_client = self.app.client_manager.sdk_connection.compute
|
||||
server = compute_client.find_server(
|
||||
parsed_args.server,
|
||||
ignore_missing=False)
|
||||
parsed_args.server, ignore_missing=False
|
||||
)
|
||||
|
||||
data = compute_client.create_console(server.id,
|
||||
console_type=parsed_args.url_type)
|
||||
data = compute_client.create_console(
|
||||
server.id, console_type=parsed_args.url_type
|
||||
)
|
||||
|
||||
display_columns, columns = _get_console_columns(data)
|
||||
data = utils.get_dict_properties(data, columns)
|
||||
|
@ -34,7 +34,7 @@ LOG = logging.getLogger(__name__)
|
||||
|
||||
_formatters = {
|
||||
'extra_specs': format_columns.DictColumn,
|
||||
'properties': format_columns.DictColumn
|
||||
'properties': format_columns.DictColumn,
|
||||
}
|
||||
|
||||
|
||||
@ -45,12 +45,12 @@ def _get_flavor_columns(item):
|
||||
'extra_specs': 'properties',
|
||||
'ephemeral': 'OS-FLV-EXT-DATA:ephemeral',
|
||||
'is_disabled': 'OS-FLV-DISABLED:disabled',
|
||||
'is_public': 'os-flavor-access:is_public'
|
||||
|
||||
'is_public': 'os-flavor-access:is_public',
|
||||
}
|
||||
hidden_columns = ['links', 'location', 'original_name']
|
||||
return utils.get_osc_show_columns_for_sdk_resource(
|
||||
item, column_map, hidden_columns)
|
||||
item, column_map, hidden_columns
|
||||
)
|
||||
|
||||
|
||||
class CreateFlavor(command.ShowOne):
|
||||
@ -59,56 +59,50 @@ class CreateFlavor(command.ShowOne):
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(CreateFlavor, self).get_parser(prog_name)
|
||||
parser.add_argument(
|
||||
"name",
|
||||
metavar="<flavor-name>",
|
||||
help=_("New flavor name")
|
||||
)
|
||||
parser.add_argument(
|
||||
"--id",
|
||||
metavar="<id>",
|
||||
help=_("Unique flavor ID")
|
||||
"name", metavar="<flavor-name>", help=_("New flavor name")
|
||||
)
|
||||
parser.add_argument("--id", metavar="<id>", help=_("Unique flavor ID"))
|
||||
parser.add_argument(
|
||||
"--ram",
|
||||
type=int,
|
||||
metavar="<size-mb>",
|
||||
default=256,
|
||||
help=_("Memory size in MB (default 256M)")
|
||||
help=_("Memory size in MB (default 256M)"),
|
||||
)
|
||||
parser.add_argument(
|
||||
"--disk",
|
||||
type=int,
|
||||
metavar="<size-gb>",
|
||||
default=0,
|
||||
help=_("Disk size in GB (default 0G)")
|
||||
help=_("Disk size in GB (default 0G)"),
|
||||
)
|
||||
parser.add_argument(
|
||||
"--ephemeral",
|
||||
type=int,
|
||||
metavar="<size-gb>",
|
||||
default=0,
|
||||
help=_("Ephemeral disk size in GB (default 0G)")
|
||||
help=_("Ephemeral disk size in GB (default 0G)"),
|
||||
)
|
||||
parser.add_argument(
|
||||
"--swap",
|
||||
type=int,
|
||||
metavar="<size-mb>",
|
||||
default=0,
|
||||
help=_("Additional swap space size in MB (default 0M)")
|
||||
help=_("Additional swap space size in MB (default 0M)"),
|
||||
)
|
||||
parser.add_argument(
|
||||
"--vcpus",
|
||||
type=int,
|
||||
metavar="<vcpus>",
|
||||
default=1,
|
||||
help=_("Number of vcpus (default 1)")
|
||||
help=_("Number of vcpus (default 1)"),
|
||||
)
|
||||
parser.add_argument(
|
||||
"--rxtx-factor",
|
||||
type=float,
|
||||
metavar="<factor>",
|
||||
default=1.0,
|
||||
help=_("RX/TX factor (default 1.0)")
|
||||
help=_("RX/TX factor (default 1.0)"),
|
||||
)
|
||||
public_group = parser.add_mutually_exclusive_group()
|
||||
public_group.add_argument(
|
||||
@ -116,33 +110,39 @@ class CreateFlavor(command.ShowOne):
|
||||
dest="public",
|
||||
action="store_true",
|
||||
default=True,
|
||||
help=_("Flavor is available to other projects (default)")
|
||||
help=_("Flavor is available to other projects (default)"),
|
||||
)
|
||||
public_group.add_argument(
|
||||
"--private",
|
||||
dest="public",
|
||||
action="store_false",
|
||||
help=_("Flavor is not available to other projects")
|
||||
help=_("Flavor is not available to other projects"),
|
||||
)
|
||||
parser.add_argument(
|
||||
"--property",
|
||||
metavar="<key=value>",
|
||||
action=parseractions.KeyValueAction,
|
||||
dest="properties",
|
||||
help=_("Property to add for this flavor "
|
||||
"(repeat option to set multiple properties)")
|
||||
help=_(
|
||||
"Property to add for this flavor "
|
||||
"(repeat option to set multiple properties)"
|
||||
),
|
||||
)
|
||||
parser.add_argument(
|
||||
'--project',
|
||||
metavar='<project>',
|
||||
help=_("Allow <project> to access private flavor (name or ID) "
|
||||
"(Must be used with --private option)"),
|
||||
help=_(
|
||||
"Allow <project> to access private flavor (name or ID) "
|
||||
"(Must be used with --private option)"
|
||||
),
|
||||
)
|
||||
parser.add_argument(
|
||||
'--description',
|
||||
metavar='<description>',
|
||||
help=_("Description for the flavor.(Supported by API versions "
|
||||
"'2.55' - '2.latest'")
|
||||
help=_(
|
||||
"Description for the flavor.(Supported by API versions "
|
||||
"'2.55' - '2.latest'"
|
||||
),
|
||||
)
|
||||
identity_common.add_project_domain_option_to_parser(parser)
|
||||
return parser
|
||||
@ -186,22 +186,25 @@ class CreateFlavor(command.ShowOne):
|
||||
parsed_args.project,
|
||||
parsed_args.project_domain,
|
||||
).id
|
||||
compute_client.flavor_add_tenant_access(
|
||||
flavor.id, project_id)
|
||||
compute_client.flavor_add_tenant_access(flavor.id, project_id)
|
||||
except Exception as e:
|
||||
msg = _("Failed to add project %(project)s access to "
|
||||
"flavor: %(e)s")
|
||||
msg = _(
|
||||
"Failed to add project %(project)s access to "
|
||||
"flavor: %(e)s"
|
||||
)
|
||||
LOG.error(msg, {'project': parsed_args.project, 'e': e})
|
||||
if parsed_args.properties:
|
||||
try:
|
||||
flavor = compute_client.create_flavor_extra_specs(
|
||||
flavor, parsed_args.properties)
|
||||
flavor, parsed_args.properties
|
||||
)
|
||||
except Exception as e:
|
||||
LOG.error(_("Failed to set flavor properties: %s"), e)
|
||||
|
||||
display_columns, columns = _get_flavor_columns(flavor)
|
||||
data = utils.get_dict_properties(flavor, columns,
|
||||
formatters=_formatters)
|
||||
data = utils.get_dict_properties(
|
||||
flavor, columns, formatters=_formatters
|
||||
)
|
||||
|
||||
return (display_columns, data)
|
||||
|
||||
@ -215,7 +218,7 @@ class DeleteFlavor(command.Command):
|
||||
"flavor",
|
||||
metavar="<flavor>",
|
||||
nargs='+',
|
||||
help=_("Flavor(s) to delete (name or ID)")
|
||||
help=_("Flavor(s) to delete (name or ID)"),
|
||||
)
|
||||
return parser
|
||||
|
||||
@ -228,13 +231,20 @@ class DeleteFlavor(command.Command):
|
||||
compute_client.delete_flavor(flavor.id)
|
||||
except Exception as e:
|
||||
result += 1
|
||||
LOG.error(_("Failed to delete flavor with name or "
|
||||
"ID '%(flavor)s': %(e)s"), {'flavor': f, 'e': e})
|
||||
LOG.error(
|
||||
_(
|
||||
"Failed to delete flavor with name or "
|
||||
"ID '%(flavor)s': %(e)s"
|
||||
),
|
||||
{'flavor': f, 'e': e},
|
||||
)
|
||||
|
||||
if result > 0:
|
||||
total = len(parsed_args.flavor)
|
||||
msg = (_("%(result)s of %(total)s flavors failed "
|
||||
"to delete.") % {'result': result, 'total': total})
|
||||
msg = _("%(result)s of %(total)s flavors failed " "to delete.") % {
|
||||
'result': result,
|
||||
'total': total,
|
||||
}
|
||||
raise exceptions.CommandError(msg)
|
||||
|
||||
|
||||
@ -249,20 +259,20 @@ class ListFlavor(command.Lister):
|
||||
dest="public",
|
||||
action="store_true",
|
||||
default=True,
|
||||
help=_("List only public flavors (default)")
|
||||
help=_("List only public flavors (default)"),
|
||||
)
|
||||
public_group.add_argument(
|
||||
"--private",
|
||||
dest="public",
|
||||
action="store_false",
|
||||
help=_("List only private flavors")
|
||||
help=_("List only private flavors"),
|
||||
)
|
||||
public_group.add_argument(
|
||||
"--all",
|
||||
dest="all",
|
||||
action="store_true",
|
||||
default=False,
|
||||
help=_("List all flavors, whether public or private")
|
||||
help=_("List all flavors, whether public or private"),
|
||||
)
|
||||
parser.add_argument(
|
||||
'--min-disk',
|
||||
@ -280,12 +290,12 @@ class ListFlavor(command.Lister):
|
||||
'--long',
|
||||
action='store_true',
|
||||
default=False,
|
||||
help=_("List additional fields in output")
|
||||
help=_("List additional fields in output"),
|
||||
)
|
||||
parser.add_argument(
|
||||
'--marker',
|
||||
metavar="<flavor-id>",
|
||||
help=_("The last flavor ID of the previous page")
|
||||
help=_("The last flavor ID of the previous page"),
|
||||
)
|
||||
parser.add_argument(
|
||||
'--limit',
|
||||
@ -308,9 +318,7 @@ class ListFlavor(command.Lister):
|
||||
# and flavors from their own projects only.
|
||||
is_public = None if parsed_args.all else parsed_args.public
|
||||
|
||||
query_attrs = {
|
||||
'is_public': is_public
|
||||
}
|
||||
query_attrs = {'is_public': is_public}
|
||||
|
||||
if parsed_args.marker:
|
||||
query_attrs['marker'] = parsed_args.marker
|
||||
@ -343,7 +351,7 @@ class ListFlavor(command.Lister):
|
||||
"disk",
|
||||
"ephemeral",
|
||||
"vcpus",
|
||||
"is_public"
|
||||
"is_public",
|
||||
)
|
||||
if parsed_args.long:
|
||||
columns += (
|
||||
@ -359,7 +367,7 @@ class ListFlavor(command.Lister):
|
||||
"Disk",
|
||||
"Ephemeral",
|
||||
"VCPUs",
|
||||
"Is Public"
|
||||
"Is Public",
|
||||
)
|
||||
if parsed_args.long:
|
||||
column_headers += (
|
||||
@ -385,36 +393,43 @@ class SetFlavor(command.Command):
|
||||
parser.add_argument(
|
||||
"flavor",
|
||||
metavar="<flavor>",
|
||||
help=_("Flavor to modify (name or ID)")
|
||||
help=_("Flavor to modify (name or ID)"),
|
||||
)
|
||||
parser.add_argument(
|
||||
"--no-property",
|
||||
action="store_true",
|
||||
help=_("Remove all properties from this flavor "
|
||||
"(specify both --no-property and --property"
|
||||
" to remove the current properties before setting"
|
||||
" new properties.)"),
|
||||
help=_(
|
||||
"Remove all properties from this flavor "
|
||||
"(specify both --no-property and --property"
|
||||
" to remove the current properties before setting"
|
||||
" new properties.)"
|
||||
),
|
||||
)
|
||||
parser.add_argument(
|
||||
"--property",
|
||||
metavar="<key=value>",
|
||||
action=parseractions.KeyValueAction,
|
||||
dest="properties",
|
||||
help=_("Property to add or modify for this flavor "
|
||||
"(repeat option to set multiple properties)")
|
||||
help=_(
|
||||
"Property to add or modify for this flavor "
|
||||
"(repeat option to set multiple properties)"
|
||||
),
|
||||
)
|
||||
parser.add_argument(
|
||||
'--project',
|
||||
metavar='<project>',
|
||||
help=_('Set flavor access to project (name or ID) '
|
||||
'(admin only)'),
|
||||
help=_(
|
||||
'Set flavor access to project (name or ID) ' '(admin only)'
|
||||
),
|
||||
)
|
||||
identity_common.add_project_domain_option_to_parser(parser)
|
||||
parser.add_argument(
|
||||
'--description',
|
||||
metavar='<description>',
|
||||
help=_("Set description for the flavor.(Supported by API "
|
||||
"versions '2.55' - '2.latest'")
|
||||
help=_(
|
||||
"Set description for the flavor.(Supported by API "
|
||||
"versions '2.55' - '2.latest'"
|
||||
),
|
||||
)
|
||||
|
||||
return parser
|
||||
@ -425,9 +440,8 @@ class SetFlavor(command.Command):
|
||||
|
||||
try:
|
||||
flavor = compute_client.find_flavor(
|
||||
parsed_args.flavor,
|
||||
get_extra_specs=True,
|
||||
ignore_missing=False)
|
||||
parsed_args.flavor, get_extra_specs=True, ignore_missing=False
|
||||
)
|
||||
except sdk_exceptions.ResourceNotFound as e:
|
||||
raise exceptions.CommandError(e.message)
|
||||
|
||||
@ -440,14 +454,16 @@ class SetFlavor(command.Command):
|
||||
raise exceptions.CommandError(msg)
|
||||
|
||||
compute_client.update_flavor(
|
||||
flavor=flavor.id, description=parsed_args.description)
|
||||
flavor=flavor.id, description=parsed_args.description
|
||||
)
|
||||
|
||||
result = 0
|
||||
if parsed_args.no_property:
|
||||
try:
|
||||
for key in flavor.extra_specs.keys():
|
||||
compute_client.delete_flavor_extra_specs_property(
|
||||
flavor.id, key)
|
||||
flavor.id, key
|
||||
)
|
||||
except Exception as e:
|
||||
LOG.error(_("Failed to clear flavor properties: %s"), e)
|
||||
result += 1
|
||||
@ -455,7 +471,8 @@ class SetFlavor(command.Command):
|
||||
if parsed_args.properties:
|
||||
try:
|
||||
compute_client.create_flavor_extra_specs(
|
||||
flavor.id, parsed_args.properties)
|
||||
flavor.id, parsed_args.properties
|
||||
)
|
||||
except Exception as e:
|
||||
LOG.error(_("Failed to set flavor properties: %s"), e)
|
||||
result += 1
|
||||
@ -472,14 +489,16 @@ class SetFlavor(command.Command):
|
||||
parsed_args.project_domain,
|
||||
).id
|
||||
compute_client.flavor_add_tenant_access(
|
||||
flavor.id, project_id)
|
||||
flavor.id, project_id
|
||||
)
|
||||
except Exception as e:
|
||||
LOG.error(_("Failed to set flavor access to project: %s"), e)
|
||||
result += 1
|
||||
|
||||
if result > 0:
|
||||
raise exceptions.CommandError(_("Command Failed: One or more of"
|
||||
" the operations failed"))
|
||||
raise exceptions.CommandError(
|
||||
_("Command Failed: One or more of" " the operations failed")
|
||||
)
|
||||
|
||||
|
||||
class ShowFlavor(command.ShowOne):
|
||||
@ -490,27 +509,32 @@ class ShowFlavor(command.ShowOne):
|
||||
parser.add_argument(
|
||||
"flavor",
|
||||
metavar="<flavor>",
|
||||
help=_("Flavor to display (name or ID)")
|
||||
help=_("Flavor to display (name or ID)"),
|
||||
)
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
compute_client = self.app.client_manager.sdk_connection.compute
|
||||
flavor = compute_client.find_flavor(
|
||||
parsed_args.flavor, get_extra_specs=True, ignore_missing=False)
|
||||
parsed_args.flavor, get_extra_specs=True, ignore_missing=False
|
||||
)
|
||||
|
||||
access_projects = None
|
||||
# get access projects list of this flavor
|
||||
if not flavor.is_public:
|
||||
try:
|
||||
flavor_access = compute_client.get_flavor_access(
|
||||
flavor=flavor.id)
|
||||
flavor=flavor.id
|
||||
)
|
||||
access_projects = [
|
||||
utils.get_field(access, 'tenant_id')
|
||||
for access in flavor_access]
|
||||
for access in flavor_access
|
||||
]
|
||||
except Exception as e:
|
||||
msg = _("Failed to get access projects list "
|
||||
"for flavor '%(flavor)s': %(e)s")
|
||||
msg = _(
|
||||
"Failed to get access projects list "
|
||||
"for flavor '%(flavor)s': %(e)s"
|
||||
)
|
||||
LOG.error(msg, {'flavor': parsed_args.flavor, 'e': e})
|
||||
|
||||
# Since we need to inject "access_project_id" into resource - convert
|
||||
@ -520,7 +544,8 @@ class ShowFlavor(command.ShowOne):
|
||||
|
||||
display_columns, columns = _get_flavor_columns(flavor)
|
||||
data = utils.get_dict_properties(
|
||||
flavor, columns, formatters=_formatters)
|
||||
flavor, columns, formatters=_formatters
|
||||
)
|
||||
|
||||
return (display_columns, data)
|
||||
|
||||
@ -533,21 +558,25 @@ class UnsetFlavor(command.Command):
|
||||
parser.add_argument(
|
||||
"flavor",
|
||||
metavar="<flavor>",
|
||||
help=_("Flavor to modify (name or ID)")
|
||||
help=_("Flavor to modify (name or ID)"),
|
||||
)
|
||||
parser.add_argument(
|
||||
"--property",
|
||||
metavar="<key>",
|
||||
action='append',
|
||||
dest="properties",
|
||||
help=_("Property to remove from flavor "
|
||||
"(repeat option to unset multiple properties)")
|
||||
help=_(
|
||||
"Property to remove from flavor "
|
||||
"(repeat option to unset multiple properties)"
|
||||
),
|
||||
)
|
||||
parser.add_argument(
|
||||
'--project',
|
||||
metavar='<project>',
|
||||
help=_('Remove flavor access from project (name or ID) '
|
||||
'(admin only)'),
|
||||
help=_(
|
||||
'Remove flavor access from project (name or ID) '
|
||||
'(admin only)'
|
||||
),
|
||||
)
|
||||
identity_common.add_project_domain_option_to_parser(parser)
|
||||
|
||||
@ -559,9 +588,8 @@ class UnsetFlavor(command.Command):
|
||||
|
||||
try:
|
||||
flavor = compute_client.find_flavor(
|
||||
parsed_args.flavor,
|
||||
get_extra_specs=True,
|
||||
ignore_missing=False)
|
||||
parsed_args.flavor, get_extra_specs=True, ignore_missing=False
|
||||
)
|
||||
except sdk_exceptions.ResourceNotFound as e:
|
||||
raise exceptions.CommandError(_(e.message))
|
||||
|
||||
@ -570,7 +598,8 @@ class UnsetFlavor(command.Command):
|
||||
for key in parsed_args.properties:
|
||||
try:
|
||||
compute_client.delete_flavor_extra_specs_property(
|
||||
flavor.id, key)
|
||||
flavor.id, key
|
||||
)
|
||||
except sdk_exceptions.SDKException as e:
|
||||
LOG.error(_("Failed to unset flavor property: %s"), e)
|
||||
result += 1
|
||||
@ -587,12 +616,15 @@ class UnsetFlavor(command.Command):
|
||||
parsed_args.project_domain,
|
||||
).id
|
||||
compute_client.flavor_remove_tenant_access(
|
||||
flavor.id, project_id)
|
||||
flavor.id, project_id
|
||||
)
|
||||
except Exception as e:
|
||||
LOG.error(_("Failed to remove flavor access from project: %s"),
|
||||
e)
|
||||
LOG.error(
|
||||
_("Failed to remove flavor access from project: %s"), e
|
||||
)
|
||||
result += 1
|
||||
|
||||
if result > 0:
|
||||
raise exceptions.CommandError(_("Command Failed: One or more of"
|
||||
" the operations failed"))
|
||||
raise exceptions.CommandError(
|
||||
_("Command Failed: One or more of" " the operations failed")
|
||||
)
|
||||
|
@ -29,17 +29,13 @@ class ListHost(command.Lister):
|
||||
parser.add_argument(
|
||||
"--zone",
|
||||
metavar="<zone>",
|
||||
help=_("Only return hosts in the availability zone")
|
||||
help=_("Only return hosts in the availability zone"),
|
||||
)
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
compute_client = self.app.client_manager.sdk_connection.compute
|
||||
columns = (
|
||||
"Host Name",
|
||||
"Service",
|
||||
"Zone"
|
||||
)
|
||||
columns = ("Host Name", "Service", "Zone")
|
||||
|
||||
self.log.warning(
|
||||
"API has been deprecated. "
|
||||
@ -48,9 +44,11 @@ class ListHost(command.Lister):
|
||||
|
||||
# doing this since openstacksdk has decided not to support this
|
||||
# deprecated command
|
||||
hosts = compute_client.get(
|
||||
'/os-hosts', microversion='2.1'
|
||||
).json().get('hosts')
|
||||
hosts = (
|
||||
compute_client.get('/os-hosts', microversion='2.1')
|
||||
.json()
|
||||
.get('hosts')
|
||||
)
|
||||
|
||||
if parsed_args.zone is not None:
|
||||
filtered_hosts = []
|
||||
@ -69,31 +67,25 @@ class SetHost(command.Command):
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(SetHost, self).get_parser(prog_name)
|
||||
parser.add_argument(
|
||||
"host",
|
||||
metavar="<host>",
|
||||
help=_("Host to modify (name only)")
|
||||
"host", metavar="<host>", help=_("Host to modify (name only)")
|
||||
)
|
||||
status = parser.add_mutually_exclusive_group()
|
||||
status.add_argument(
|
||||
'--enable',
|
||||
action='store_true',
|
||||
help=_("Enable the host")
|
||||
'--enable', action='store_true', help=_("Enable the host")
|
||||
)
|
||||
status.add_argument(
|
||||
'--disable',
|
||||
action='store_true',
|
||||
help=_("Disable the host")
|
||||
'--disable', action='store_true', help=_("Disable the host")
|
||||
)
|
||||
maintenance = parser.add_mutually_exclusive_group()
|
||||
maintenance.add_argument(
|
||||
'--enable-maintenance',
|
||||
action='store_true',
|
||||
help=_("Enable maintenance mode for the host")
|
||||
help=_("Enable maintenance mode for the host"),
|
||||
)
|
||||
maintenance.add_argument(
|
||||
'--disable-maintenance',
|
||||
action='store_true',
|
||||
help=_("Disable maintenance mode for the host")
|
||||
help=_("Disable maintenance mode for the host"),
|
||||
)
|
||||
return parser
|
||||
|
||||
@ -111,10 +103,7 @@ class SetHost(command.Command):
|
||||
|
||||
compute_client = self.app.client_manager.compute
|
||||
|
||||
compute_client.api.host_set(
|
||||
parsed_args.host,
|
||||
**kwargs
|
||||
)
|
||||
compute_client.api.host_set(parsed_args.host, **kwargs)
|
||||
|
||||
|
||||
class ShowHost(command.Lister):
|
||||
@ -122,22 +111,12 @@ class ShowHost(command.Lister):
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super().get_parser(prog_name)
|
||||
parser.add_argument(
|
||||
"host",
|
||||
metavar="<host>",
|
||||
help=_("Name of host")
|
||||
)
|
||||
parser.add_argument("host", metavar="<host>", help=_("Name of host"))
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
compute_client = self.app.client_manager.sdk_connection.compute
|
||||
columns = (
|
||||
"Host",
|
||||
"Project",
|
||||
"CPU",
|
||||
"Memory MB",
|
||||
"Disk GB"
|
||||
)
|
||||
columns = ("Host", "Project", "CPU", "Memory MB", "Disk GB")
|
||||
|
||||
self.log.warning(
|
||||
"API has been deprecated. "
|
||||
@ -146,10 +125,13 @@ class ShowHost(command.Lister):
|
||||
|
||||
# doing this since openstacksdk has decided not to support this
|
||||
# deprecated command
|
||||
resources = compute_client.get(
|
||||
'/os-hosts/' + parsed_args.host,
|
||||
microversion='2.1'
|
||||
).json().get('host')
|
||||
resources = (
|
||||
compute_client.get(
|
||||
'/os-hosts/' + parsed_args.host, microversion='2.1'
|
||||
)
|
||||
.json()
|
||||
.get('host')
|
||||
)
|
||||
|
||||
data = []
|
||||
if resources is not None:
|
||||
|
@ -33,32 +33,37 @@ def _get_hypervisor_columns(item, client):
|
||||
hidden_columns = ['location', 'servers']
|
||||
|
||||
if sdk_utils.supports_microversion(client, '2.88'):
|
||||
hidden_columns.extend([
|
||||
'current_workload',
|
||||
'disk_available',
|
||||
'local_disk_free',
|
||||
'local_disk_size',
|
||||
'local_disk_used',
|
||||
'memory_free',
|
||||
'memory_size',
|
||||
'memory_used',
|
||||
'running_vms',
|
||||
'vcpus_used',
|
||||
'vcpus',
|
||||
])
|
||||
hidden_columns.extend(
|
||||
[
|
||||
'current_workload',
|
||||
'disk_available',
|
||||
'local_disk_free',
|
||||
'local_disk_size',
|
||||
'local_disk_used',
|
||||
'memory_free',
|
||||
'memory_size',
|
||||
'memory_used',
|
||||
'running_vms',
|
||||
'vcpus_used',
|
||||
'vcpus',
|
||||
]
|
||||
)
|
||||
else:
|
||||
column_map.update({
|
||||
'disk_available': 'disk_available_least',
|
||||
'local_disk_free': 'free_disk_gb',
|
||||
'local_disk_size': 'local_gb',
|
||||
'local_disk_used': 'local_gb_used',
|
||||
'memory_free': 'free_ram_mb',
|
||||
'memory_used': 'memory_mb_used',
|
||||
'memory_size': 'memory_mb',
|
||||
})
|
||||
column_map.update(
|
||||
{
|
||||
'disk_available': 'disk_available_least',
|
||||
'local_disk_free': 'free_disk_gb',
|
||||
'local_disk_size': 'local_gb',
|
||||
'local_disk_used': 'local_gb_used',
|
||||
'memory_free': 'free_ram_mb',
|
||||
'memory_used': 'memory_mb_used',
|
||||
'memory_size': 'memory_mb',
|
||||
}
|
||||
)
|
||||
|
||||
return utils.get_osc_show_columns_for_sdk_resource(
|
||||
item, column_map, hidden_columns)
|
||||
item, column_map, hidden_columns
|
||||
)
|
||||
|
||||
|
||||
class ListHypervisor(command.Lister):
|
||||
@ -73,7 +78,7 @@ class ListHypervisor(command.Lister):
|
||||
"Filter hypervisors using <hostname> substring"
|
||||
"Hypervisor Type and Host IP are not returned "
|
||||
"when using microversion 2.52 or lower"
|
||||
)
|
||||
),
|
||||
)
|
||||
parser.add_argument(
|
||||
'--marker',
|
||||
@ -99,7 +104,7 @@ class ListHypervisor(command.Lister):
|
||||
parser.add_argument(
|
||||
'--long',
|
||||
action='store_true',
|
||||
help=_("List additional fields in output")
|
||||
help=_("List additional fields in output"),
|
||||
)
|
||||
return parser
|
||||
|
||||
@ -109,9 +114,7 @@ class ListHypervisor(command.Lister):
|
||||
list_opts = {}
|
||||
|
||||
if parsed_args.matching and (parsed_args.marker or parsed_args.limit):
|
||||
msg = _(
|
||||
'--matching is not compatible with --marker or --limit'
|
||||
)
|
||||
msg = _('--matching is not compatible with --marker or --limit')
|
||||
raise exceptions.CommandError(msg)
|
||||
|
||||
if parsed_args.marker:
|
||||
@ -140,15 +143,9 @@ class ListHypervisor(command.Lister):
|
||||
"Hypervisor Hostname",
|
||||
"Hypervisor Type",
|
||||
"Host IP",
|
||||
"State"
|
||||
)
|
||||
columns = (
|
||||
'id',
|
||||
'name',
|
||||
'hypervisor_type',
|
||||
'host_ip',
|
||||
'state'
|
||||
"State",
|
||||
)
|
||||
columns = ('id', 'name', 'hypervisor_type', 'host_ip', 'state')
|
||||
|
||||
if parsed_args.long:
|
||||
if not sdk_utils.supports_microversion(compute_client, '2.88'):
|
||||
@ -156,13 +153,13 @@ class ListHypervisor(command.Lister):
|
||||
'vCPUs Used',
|
||||
'vCPUs',
|
||||
'Memory MB Used',
|
||||
'Memory MB'
|
||||
'Memory MB',
|
||||
)
|
||||
columns += (
|
||||
'vcpus_used',
|
||||
'vcpus',
|
||||
'memory_used',
|
||||
'memory_size'
|
||||
'memory_size',
|
||||
)
|
||||
|
||||
data = compute_client.hypervisors(**list_opts, details=True)
|
||||
@ -181,14 +178,15 @@ class ShowHypervisor(command.ShowOne):
|
||||
parser.add_argument(
|
||||
"hypervisor",
|
||||
metavar="<hypervisor>",
|
||||
help=_("Hypervisor to display (name or ID)")
|
||||
help=_("Hypervisor to display (name or ID)"),
|
||||
)
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
compute_client = self.app.client_manager.sdk_connection.compute
|
||||
hypervisor = compute_client.find_hypervisor(
|
||||
parsed_args.hypervisor, ignore_missing=False).copy()
|
||||
parsed_args.hypervisor, ignore_missing=False
|
||||
).copy()
|
||||
|
||||
# Some of the properties in the hypervisor object need to be processed
|
||||
# before they get reported to the user. We spend this section
|
||||
@ -208,14 +206,18 @@ class ShowHypervisor(command.ShowOne):
|
||||
|
||||
if cell:
|
||||
# The host aggregates are also prefixed by "<cell>@"
|
||||
member_of = [aggregate.name
|
||||
for aggregate in aggregates
|
||||
if cell in aggregate.name and
|
||||
service_host in aggregate.hosts]
|
||||
member_of = [
|
||||
aggregate.name
|
||||
for aggregate in aggregates
|
||||
if cell in aggregate.name
|
||||
and service_host in aggregate.hosts
|
||||
]
|
||||
else:
|
||||
member_of = [aggregate.name
|
||||
for aggregate in aggregates
|
||||
if service_host in aggregate.hosts]
|
||||
member_of = [
|
||||
aggregate.name
|
||||
for aggregate in aggregates
|
||||
if service_host in aggregate.hosts
|
||||
]
|
||||
hypervisor['aggregates'] = member_of
|
||||
|
||||
try:
|
||||
@ -225,14 +227,16 @@ class ShowHypervisor(command.ShowOne):
|
||||
else:
|
||||
del hypervisor['uptime']
|
||||
uptime = compute_client.get_hypervisor_uptime(
|
||||
hypervisor['id'])['uptime']
|
||||
hypervisor['id']
|
||||
)['uptime']
|
||||
# Extract data from uptime value
|
||||
# format: 0 up 0, 0 users, load average: 0, 0, 0
|
||||
# example: 17:37:14 up 2:33, 3 users,
|
||||
# load average: 0.33, 0.36, 0.34
|
||||
m = re.match(
|
||||
r"\s*(.+)\sup\s+(.+),\s+(.+)\susers?,\s+load average:\s(.+)",
|
||||
uptime)
|
||||
uptime,
|
||||
)
|
||||
if m:
|
||||
hypervisor['host_time'] = m.group(1)
|
||||
hypervisor['uptime'] = m.group(2)
|
||||
@ -250,11 +254,14 @@ class ShowHypervisor(command.ShowOne):
|
||||
# string; on earlier fields, do this manually
|
||||
hypervisor['cpu_info'] = json.loads(hypervisor['cpu_info'] or '{}')
|
||||
display_columns, columns = _get_hypervisor_columns(
|
||||
hypervisor, compute_client)
|
||||
hypervisor, compute_client
|
||||
)
|
||||
data = utils.get_dict_properties(
|
||||
hypervisor, columns,
|
||||
hypervisor,
|
||||
columns,
|
||||
formatters={
|
||||
'cpu_info': format_columns.DictColumn,
|
||||
})
|
||||
},
|
||||
)
|
||||
|
||||
return display_columns, data
|
||||
|
@ -29,11 +29,11 @@ def _get_hypervisor_stat_columns(item):
|
||||
'memory_free': 'free_ram_mb',
|
||||
'memory_size': 'memory_mb',
|
||||
'memory_used': 'memory_mb_used',
|
||||
|
||||
}
|
||||
hidden_columns = ['id', 'links', 'location', 'name']
|
||||
return utils.get_osc_show_columns_for_sdk_resource(
|
||||
item, column_map, hidden_columns)
|
||||
item, column_map, hidden_columns
|
||||
)
|
||||
|
||||
|
||||
class ShowHypervisorStats(command.ShowOne):
|
||||
@ -41,19 +41,17 @@ class ShowHypervisorStats(command.ShowOne):
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
# The command is deprecated since it is being dropped in Nova.
|
||||
self.log.warning(
|
||||
_("This command is deprecated.")
|
||||
)
|
||||
self.log.warning(_("This command is deprecated."))
|
||||
compute_client = self.app.client_manager.sdk_connection.compute
|
||||
# We do API request directly cause this deprecated method is not and
|
||||
# will not be supported by OpenStackSDK.
|
||||
response = compute_client.get(
|
||||
'/os-hypervisors/statistics',
|
||||
microversion='2.1')
|
||||
'/os-hypervisors/statistics', microversion='2.1'
|
||||
)
|
||||
hypervisor_stats = response.json().get('hypervisor_statistics')
|
||||
|
||||
display_columns, columns = _get_hypervisor_stat_columns(
|
||||
hypervisor_stats)
|
||||
data = utils.get_dict_properties(
|
||||
hypervisor_stats, columns)
|
||||
hypervisor_stats
|
||||
)
|
||||
data = utils.get_dict_properties(hypervisor_stats, columns)
|
||||
return (display_columns, data)
|
||||
|
@ -45,12 +45,15 @@ def _generate_keypair():
|
||||
private_key = key.private_bytes(
|
||||
serialization.Encoding.PEM,
|
||||
serialization.PrivateFormat.OpenSSH,
|
||||
serialization.NoEncryption()
|
||||
).decode()
|
||||
public_key = key.public_key().public_bytes(
|
||||
serialization.Encoding.OpenSSH,
|
||||
serialization.PublicFormat.OpenSSH
|
||||
serialization.NoEncryption(),
|
||||
).decode()
|
||||
public_key = (
|
||||
key.public_key()
|
||||
.public_bytes(
|
||||
serialization.Encoding.OpenSSH, serialization.PublicFormat.OpenSSH
|
||||
)
|
||||
.decode()
|
||||
)
|
||||
|
||||
return Keypair(private_key, public_key)
|
||||
|
||||
@ -65,7 +68,8 @@ def _get_keypair_columns(item, hide_pub_key=False, hide_priv_key=False):
|
||||
if hide_priv_key:
|
||||
hidden_columns.append('private_key')
|
||||
return utils.get_osc_show_columns_for_sdk_resource(
|
||||
item, column_map, hidden_columns)
|
||||
item, column_map, hidden_columns
|
||||
)
|
||||
|
||||
|
||||
class CreateKeypair(command.ShowOne):
|
||||
@ -74,9 +78,7 @@ class CreateKeypair(command.ShowOne):
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(CreateKeypair, self).get_parser(prog_name)
|
||||
parser.add_argument(
|
||||
'name',
|
||||
metavar='<name>',
|
||||
help=_("New public or private key name")
|
||||
'name', metavar='<name>', help=_("New public or private key name")
|
||||
)
|
||||
key_group = parser.add_mutually_exclusive_group()
|
||||
key_group.add_argument(
|
||||
@ -96,7 +98,7 @@ class CreateKeypair(command.ShowOne):
|
||||
help=_(
|
||||
"Filename for private key to save. "
|
||||
"If not used, print private key in console."
|
||||
)
|
||||
),
|
||||
)
|
||||
parser.add_argument(
|
||||
'--type',
|
||||
@ -122,9 +124,7 @@ class CreateKeypair(command.ShowOne):
|
||||
compute_client = self.app.client_manager.sdk_connection.compute
|
||||
identity_client = self.app.client_manager.identity
|
||||
|
||||
kwargs = {
|
||||
'name': parsed_args.name
|
||||
}
|
||||
kwargs = {'name': parsed_args.name}
|
||||
|
||||
if parsed_args.public_key:
|
||||
generated_keypair = None
|
||||
@ -134,7 +134,8 @@ class CreateKeypair(command.ShowOne):
|
||||
except IOError as e:
|
||||
msg = _("Key file %(public_key)s not found: %(exception)s")
|
||||
raise exceptions.CommandError(
|
||||
msg % {
|
||||
msg
|
||||
% {
|
||||
"public_key": parsed_args.public_key,
|
||||
"exception": e,
|
||||
}
|
||||
@ -158,7 +159,8 @@ class CreateKeypair(command.ShowOne):
|
||||
"%(exception)s"
|
||||
)
|
||||
raise exceptions.CommandError(
|
||||
msg % {
|
||||
msg
|
||||
% {
|
||||
"private_key": parsed_args.private_key,
|
||||
"exception": e,
|
||||
}
|
||||
@ -195,7 +197,8 @@ class CreateKeypair(command.ShowOne):
|
||||
# For now, duplicate nova keypair-add command output
|
||||
if parsed_args.public_key or parsed_args.private_key:
|
||||
display_columns, columns = _get_keypair_columns(
|
||||
keypair, hide_pub_key=True, hide_priv_key=True)
|
||||
keypair, hide_pub_key=True, hide_priv_key=True
|
||||
)
|
||||
data = utils.get_item_properties(keypair, columns)
|
||||
|
||||
return (display_columns, data)
|
||||
@ -213,7 +216,7 @@ class DeleteKeypair(command.Command):
|
||||
'name',
|
||||
metavar='<key>',
|
||||
nargs='+',
|
||||
help=_("Name of key(s) to delete (name only)")
|
||||
help=_("Name of key(s) to delete (name only)"),
|
||||
)
|
||||
parser.add_argument(
|
||||
'--user',
|
||||
@ -250,16 +253,21 @@ class DeleteKeypair(command.Command):
|
||||
for n in parsed_args.name:
|
||||
try:
|
||||
compute_client.delete_keypair(
|
||||
n, **kwargs, ignore_missing=False)
|
||||
n, **kwargs, ignore_missing=False
|
||||
)
|
||||
except Exception as e:
|
||||
result += 1
|
||||
LOG.error(_("Failed to delete key with name "
|
||||
"'%(name)s': %(e)s"), {'name': n, 'e': e})
|
||||
LOG.error(
|
||||
_("Failed to delete key with name " "'%(name)s': %(e)s"),
|
||||
{'name': n, 'e': e},
|
||||
)
|
||||
|
||||
if result > 0:
|
||||
total = len(parsed_args.name)
|
||||
msg = (_("%(result)s of %(total)s keys failed "
|
||||
"to delete.") % {'result': result, 'total': total})
|
||||
msg = _("%(result)s of %(total)s keys failed " "to delete.") % {
|
||||
'result': result,
|
||||
'total': total,
|
||||
}
|
||||
raise exceptions.CommandError(msg)
|
||||
|
||||
|
||||
@ -337,9 +345,7 @@ class ListKeypair(command.Lister):
|
||||
# NOTE(stephenfin): Because we're doing this client-side, we
|
||||
# can't really rely on the marker, because we don't know what
|
||||
# user the marker is associated with
|
||||
msg = _(
|
||||
'--project is not compatible with --marker'
|
||||
)
|
||||
msg = _('--project is not compatible with --marker')
|
||||
|
||||
# NOTE(stephenfin): This is done client side because nova doesn't
|
||||
# currently support doing so server-side. If this is slow, we can
|
||||
@ -374,13 +380,10 @@ class ListKeypair(command.Lister):
|
||||
else:
|
||||
data = compute_client.keypairs(**kwargs)
|
||||
|
||||
columns = (
|
||||
"Name",
|
||||
"Fingerprint"
|
||||
)
|
||||
columns = ("Name", "Fingerprint")
|
||||
|
||||
if sdk_utils.supports_microversion(compute_client, '2.2'):
|
||||
columns += ("Type", )
|
||||
columns += ("Type",)
|
||||
|
||||
return (
|
||||
columns,
|
||||
@ -396,13 +399,13 @@ class ShowKeypair(command.ShowOne):
|
||||
parser.add_argument(
|
||||
'name',
|
||||
metavar='<key>',
|
||||
help=_("Public or private key to display (name only)")
|
||||
help=_("Public or private key to display (name only)"),
|
||||
)
|
||||
parser.add_argument(
|
||||
'--public-key',
|
||||
action='store_true',
|
||||
default=False,
|
||||
help=_("Show only bare public key paired with the generated key")
|
||||
help=_("Show only bare public key paired with the generated key"),
|
||||
)
|
||||
parser.add_argument(
|
||||
'--user',
|
||||
@ -436,11 +439,13 @@ class ShowKeypair(command.ShowOne):
|
||||
).id
|
||||
|
||||
keypair = compute_client.find_keypair(
|
||||
parsed_args.name, **kwargs, ignore_missing=False)
|
||||
parsed_args.name, **kwargs, ignore_missing=False
|
||||
)
|
||||
|
||||
if not parsed_args.public_key:
|
||||
display_columns, columns = _get_keypair_columns(
|
||||
keypair, hide_pub_key=True)
|
||||
keypair, hide_pub_key=True
|
||||
)
|
||||
data = utils.get_item_properties(keypair, columns)
|
||||
return (display_columns, data)
|
||||
else:
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -66,7 +66,6 @@ class CreateServerBackup(command.ShowOne):
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
|
||||
def _show_progress(progress):
|
||||
if progress:
|
||||
self.app.stderr.write('\rProgress: %s' % progress)
|
||||
|
@ -95,7 +95,7 @@ class ListServerEvent(command.Lister):
|
||||
'--long',
|
||||
action='store_true',
|
||||
default=False,
|
||||
help=_("List additional fields in output")
|
||||
help=_("List additional fields in output"),
|
||||
)
|
||||
parser.add_argument(
|
||||
'--changes-since',
|
||||
@ -196,8 +196,7 @@ class ListServerEvent(command.Lister):
|
||||
|
||||
try:
|
||||
server_id = compute_client.find_server(
|
||||
parsed_args.server,
|
||||
ignore_missing=False
|
||||
parsed_args.server, ignore_missing=False
|
||||
).id
|
||||
except sdk_exceptions.ResourceNotFound:
|
||||
# If we fail to find the resource, it is possible the server is
|
||||
@ -282,11 +281,13 @@ class ShowServerEvent(command.ShowOne):
|
||||
raise
|
||||
|
||||
server_action = compute_client.get_server_action(
|
||||
parsed_args.request_id, server_id,
|
||||
parsed_args.request_id,
|
||||
server_id,
|
||||
)
|
||||
|
||||
column_headers, columns = _get_server_event_columns(
|
||||
server_action, compute_client,
|
||||
server_action,
|
||||
compute_client,
|
||||
)
|
||||
|
||||
return (
|
||||
|
@ -48,7 +48,8 @@ def _get_server_group_columns(item, client):
|
||||
hidden_columns.append('rules')
|
||||
|
||||
return utils.get_osc_show_columns_for_sdk_resource(
|
||||
item, column_map, hidden_columns)
|
||||
item, column_map, hidden_columns
|
||||
)
|
||||
|
||||
|
||||
class CreateServerGroup(command.ShowOne):
|
||||
@ -167,8 +168,7 @@ class DeleteServerGroup(command.Command):
|
||||
total = len(parsed_args.server_group)
|
||||
msg = _("%(result)s of %(total)s server groups failed to delete.")
|
||||
raise exceptions.CommandError(
|
||||
msg % {"result": result,
|
||||
"total": total}
|
||||
msg % {"result": result, "total": total}
|
||||
)
|
||||
|
||||
|
||||
@ -261,8 +261,11 @@ class ListServerGroup(command.Lister):
|
||||
column_headers,
|
||||
(
|
||||
utils.get_item_properties(
|
||||
s, columns, formatters=_formatters,
|
||||
) for s in data
|
||||
s,
|
||||
columns,
|
||||
formatters=_formatters,
|
||||
)
|
||||
for s in data
|
||||
),
|
||||
)
|
||||
|
||||
|
@ -67,7 +67,6 @@ class CreateServerImage(command.ShowOne):
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
|
||||
def _show_progress(progress):
|
||||
if progress:
|
||||
self.app.stdout.write('\rProgress: %s' % progress)
|
||||
@ -77,7 +76,8 @@ class CreateServerImage(command.ShowOne):
|
||||
image_client = self.app.client_manager.image
|
||||
|
||||
server = compute_client.find_server(
|
||||
parsed_args.server, ignore_missing=False,
|
||||
parsed_args.server,
|
||||
ignore_missing=False,
|
||||
)
|
||||
|
||||
if parsed_args.name:
|
||||
@ -100,7 +100,8 @@ class CreateServerImage(command.ShowOne):
|
||||
self.app.stdout.write('\n')
|
||||
else:
|
||||
LOG.error(
|
||||
_('Error creating server image: %s'), parsed_args.server)
|
||||
_('Error creating server image: %s'), parsed_args.server
|
||||
)
|
||||
raise exceptions.CommandError
|
||||
|
||||
image = image_client.find_image(image_id, ignore_missing=False)
|
||||
|
@ -31,27 +31,26 @@ class ListMigration(command.Lister):
|
||||
parser.add_argument(
|
||||
'--server',
|
||||
metavar='<server>',
|
||||
help=_(
|
||||
'Filter migrations by server (name or ID)'
|
||||
)
|
||||
help=_('Filter migrations by server (name or ID)'),
|
||||
)
|
||||
parser.add_argument(
|
||||
'--host',
|
||||
metavar='<host>',
|
||||
help=_(
|
||||
'Filter migrations by source or destination host'
|
||||
),
|
||||
help=_('Filter migrations by source or destination host'),
|
||||
)
|
||||
parser.add_argument(
|
||||
'--status',
|
||||
metavar='<status>',
|
||||
help=_('Filter migrations by status')
|
||||
help=_('Filter migrations by status'),
|
||||
)
|
||||
parser.add_argument(
|
||||
'--type',
|
||||
metavar='<type>',
|
||||
choices=[
|
||||
'evacuation', 'live-migration', 'cold-migration', 'resize',
|
||||
'evacuation',
|
||||
'live-migration',
|
||||
'cold-migration',
|
||||
'resize',
|
||||
],
|
||||
help=_('Filter migrations by type'),
|
||||
)
|
||||
@ -121,17 +120,33 @@ class ListMigration(command.Lister):
|
||||
|
||||
def print_migrations(self, parsed_args, compute_client, migrations):
|
||||
column_headers = [
|
||||
'Source Node', 'Dest Node', 'Source Compute', 'Dest Compute',
|
||||
'Dest Host', 'Status', 'Server UUID', 'Old Flavor', 'New Flavor',
|
||||
'Created At', 'Updated At',
|
||||
'Source Node',
|
||||
'Dest Node',
|
||||
'Source Compute',
|
||||
'Dest Compute',
|
||||
'Dest Host',
|
||||
'Status',
|
||||
'Server UUID',
|
||||
'Old Flavor',
|
||||
'New Flavor',
|
||||
'Created At',
|
||||
'Updated At',
|
||||
]
|
||||
|
||||
# Response fields coming back from the REST API are not always exactly
|
||||
# the same as the column header names.
|
||||
columns = [
|
||||
'source_node', 'dest_node', 'source_compute', 'dest_compute',
|
||||
'dest_host', 'status', 'server_id', 'old_flavor_id',
|
||||
'new_flavor_id', 'created_at', 'updated_at',
|
||||
'source_node',
|
||||
'dest_node',
|
||||
'source_compute',
|
||||
'dest_compute',
|
||||
'dest_host',
|
||||
'status',
|
||||
'server_id',
|
||||
'old_flavor_id',
|
||||
'new_flavor_id',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
]
|
||||
|
||||
# Insert migrations UUID after ID
|
||||
@ -260,9 +275,7 @@ def _get_migration_by_uuid(compute_client, server_id, migration_uuid):
|
||||
return migration
|
||||
break
|
||||
else:
|
||||
msg = _(
|
||||
'In-progress live migration %s is not found for server %s.'
|
||||
)
|
||||
msg = _('In-progress live migration %s is not found for server %s.')
|
||||
raise exceptions.CommandError(msg % (migration_uuid, server_id))
|
||||
|
||||
|
||||
@ -302,9 +315,7 @@ class ShowMigration(command.ShowOne):
|
||||
try:
|
||||
uuid.UUID(parsed_args.migration)
|
||||
except ValueError:
|
||||
msg = _(
|
||||
'The <migration> argument must be an ID or UUID'
|
||||
)
|
||||
msg = _('The <migration> argument must be an ID or UUID')
|
||||
raise exceptions.CommandError(msg)
|
||||
|
||||
if not sdk_utils.supports_microversion(compute_client, '2.59'):
|
||||
@ -324,7 +335,9 @@ class ShowMigration(command.ShowOne):
|
||||
# migrations - the responses are identical
|
||||
if not parsed_args.migration.isdigit():
|
||||
server_migration = _get_migration_by_uuid(
|
||||
compute_client, server.id, parsed_args.migration,
|
||||
compute_client,
|
||||
server.id,
|
||||
parsed_args.migration,
|
||||
)
|
||||
else:
|
||||
server_migration = compute_client.get_server_migration(
|
||||
@ -417,9 +430,7 @@ class AbortMigration(command.Command):
|
||||
try:
|
||||
uuid.UUID(parsed_args.migration)
|
||||
except ValueError:
|
||||
msg = _(
|
||||
'The <migration> argument must be an ID or UUID'
|
||||
)
|
||||
msg = _('The <migration> argument must be an ID or UUID')
|
||||
raise exceptions.CommandError(msg)
|
||||
|
||||
if not sdk_utils.supports_microversion(compute_client, '2.59'):
|
||||
@ -440,7 +451,9 @@ class AbortMigration(command.Command):
|
||||
migration_id = parsed_args.migration
|
||||
if not parsed_args.migration.isdigit():
|
||||
migration_id = _get_migration_by_uuid(
|
||||
compute_client, server.id, parsed_args.migration,
|
||||
compute_client,
|
||||
server.id,
|
||||
parsed_args.migration,
|
||||
).id
|
||||
|
||||
compute_client.abort_server_migration(
|
||||
@ -464,9 +477,7 @@ class ForceCompleteMigration(command.Command):
|
||||
help=_('Server (name or ID)'),
|
||||
)
|
||||
parser.add_argument(
|
||||
'migration',
|
||||
metavar='<migration>',
|
||||
help=_('Migration (ID)')
|
||||
'migration', metavar='<migration>', help=_('Migration (ID)')
|
||||
)
|
||||
return parser
|
||||
|
||||
@ -484,9 +495,7 @@ class ForceCompleteMigration(command.Command):
|
||||
try:
|
||||
uuid.UUID(parsed_args.migration)
|
||||
except ValueError:
|
||||
msg = _(
|
||||
'The <migration> argument must be an ID or UUID'
|
||||
)
|
||||
msg = _('The <migration> argument must be an ID or UUID')
|
||||
raise exceptions.CommandError(msg)
|
||||
|
||||
if not sdk_utils.supports_microversion(compute_client, '2.59'):
|
||||
@ -507,9 +516,9 @@ class ForceCompleteMigration(command.Command):
|
||||
migration_id = parsed_args.migration
|
||||
if not parsed_args.migration.isdigit():
|
||||
migration_id = _get_migration_by_uuid(
|
||||
compute_client, server.id, parsed_args.migration,
|
||||
compute_client,
|
||||
server.id,
|
||||
parsed_args.migration,
|
||||
).id
|
||||
|
||||
compute_client.force_complete_server_migration(
|
||||
migration_id, server.id
|
||||
)
|
||||
compute_client.force_complete_server_migration(migration_id, server.id)
|
||||
|
@ -37,15 +37,17 @@ class DeleteService(command.Command):
|
||||
"service",
|
||||
metavar="<service>",
|
||||
nargs='+',
|
||||
help=_("Compute service(s) to delete (ID only). If using "
|
||||
"``--os-compute-api-version`` 2.53 or greater, the ID is "
|
||||
"a UUID which can be retrieved by listing compute services "
|
||||
"using the same 2.53+ microversion. "
|
||||
"If deleting a compute service, be sure to stop the actual "
|
||||
"compute process on the physical host before deleting the "
|
||||
"service with this command. Failing to do so can lead to "
|
||||
"the running service re-creating orphaned compute_nodes "
|
||||
"table records in the database.")
|
||||
help=_(
|
||||
"Compute service(s) to delete (ID only). If using "
|
||||
"``--os-compute-api-version`` 2.53 or greater, the ID is "
|
||||
"a UUID which can be retrieved by listing compute services "
|
||||
"using the same 2.53+ microversion. "
|
||||
"If deleting a compute service, be sure to stop the actual "
|
||||
"compute process on the physical host before deleting the "
|
||||
"service with this command. Failing to do so can lead to "
|
||||
"the running service re-creating orphaned compute_nodes "
|
||||
"table records in the database."
|
||||
),
|
||||
)
|
||||
return parser
|
||||
|
||||
@ -54,47 +56,54 @@ class DeleteService(command.Command):
|
||||
result = 0
|
||||
for s in parsed_args.service:
|
||||
try:
|
||||
compute_client.delete_service(
|
||||
s,
|
||||
ignore_missing=False
|
||||
)
|
||||
compute_client.delete_service(s, ignore_missing=False)
|
||||
except Exception as e:
|
||||
result += 1
|
||||
LOG.error(_("Failed to delete compute service with "
|
||||
"ID '%(service)s': %(e)s"), {'service': s, 'e': e})
|
||||
LOG.error(
|
||||
_(
|
||||
"Failed to delete compute service with "
|
||||
"ID '%(service)s': %(e)s"
|
||||
),
|
||||
{'service': s, 'e': e},
|
||||
)
|
||||
|
||||
if result > 0:
|
||||
total = len(parsed_args.service)
|
||||
msg = (_("%(result)s of %(total)s compute services failed "
|
||||
"to delete.") % {'result': result, 'total': total})
|
||||
msg = _(
|
||||
"%(result)s of %(total)s compute services failed " "to delete."
|
||||
) % {'result': result, 'total': total}
|
||||
raise exceptions.CommandError(msg)
|
||||
|
||||
|
||||
class ListService(command.Lister):
|
||||
_description = _("""List compute services.
|
||||
_description = _(
|
||||
"""List compute services.
|
||||
|
||||
Using ``--os-compute-api-version`` 2.53 or greater will return the ID as a UUID
|
||||
value which can be used to uniquely identify the service in a multi-cell
|
||||
deployment.""")
|
||||
deployment."""
|
||||
)
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(ListService, self).get_parser(prog_name)
|
||||
parser.add_argument(
|
||||
"--host",
|
||||
metavar="<host>",
|
||||
help=_("List services on specified host (name only)")
|
||||
help=_("List services on specified host (name only)"),
|
||||
)
|
||||
parser.add_argument(
|
||||
"--service",
|
||||
metavar="<service>",
|
||||
help=_("List only specified service binaries (name only). For "
|
||||
"example, ``nova-compute``, ``nova-conductor``, etc.")
|
||||
help=_(
|
||||
"List only specified service binaries (name only). For "
|
||||
"example, ``nova-compute``, ``nova-conductor``, etc."
|
||||
),
|
||||
)
|
||||
parser.add_argument(
|
||||
"--long",
|
||||
action="store_true",
|
||||
default=False,
|
||||
help=_("List additional fields in output")
|
||||
help=_("List additional fields in output"),
|
||||
)
|
||||
return parser
|
||||
|
||||
@ -126,12 +135,11 @@ deployment.""")
|
||||
column_headers += ("Forced Down",)
|
||||
|
||||
data = compute_client.services(
|
||||
host=parsed_args.host,
|
||||
binary=parsed_args.service
|
||||
host=parsed_args.host, binary=parsed_args.service
|
||||
)
|
||||
return (
|
||||
column_headers,
|
||||
(utils.get_item_properties(s, columns) for s in data)
|
||||
(utils.get_item_properties(s, columns) for s in data),
|
||||
)
|
||||
|
||||
|
||||
@ -140,47 +148,47 @@ class SetService(command.Command):
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(SetService, self).get_parser(prog_name)
|
||||
parser.add_argument(
|
||||
"host",
|
||||
metavar="<host>",
|
||||
help=_("Name of host")
|
||||
)
|
||||
parser.add_argument("host", metavar="<host>", help=_("Name of host"))
|
||||
parser.add_argument(
|
||||
"service",
|
||||
metavar="<service>",
|
||||
help=_("Name of service (Binary name), for example "
|
||||
"``nova-compute``")
|
||||
help=_(
|
||||
"Name of service (Binary name), for example "
|
||||
"``nova-compute``"
|
||||
),
|
||||
)
|
||||
enabled_group = parser.add_mutually_exclusive_group()
|
||||
enabled_group.add_argument(
|
||||
"--enable",
|
||||
action="store_true",
|
||||
help=_("Enable service")
|
||||
"--enable", action="store_true", help=_("Enable service")
|
||||
)
|
||||
enabled_group.add_argument(
|
||||
"--disable",
|
||||
action="store_true",
|
||||
help=_("Disable service")
|
||||
"--disable", action="store_true", help=_("Disable service")
|
||||
)
|
||||
parser.add_argument(
|
||||
"--disable-reason",
|
||||
default=None,
|
||||
metavar="<reason>",
|
||||
help=_("Reason for disabling the service (in quotes). "
|
||||
"Should be used with --disable option.")
|
||||
help=_(
|
||||
"Reason for disabling the service (in quotes). "
|
||||
"Should be used with --disable option."
|
||||
),
|
||||
)
|
||||
up_down_group = parser.add_mutually_exclusive_group()
|
||||
up_down_group.add_argument(
|
||||
'--up',
|
||||
action='store_true',
|
||||
help=_('Force up service. Requires ``--os-compute-api-version`` '
|
||||
'2.11 or greater.'),
|
||||
help=_(
|
||||
'Force up service. Requires ``--os-compute-api-version`` '
|
||||
'2.11 or greater.'
|
||||
),
|
||||
)
|
||||
up_down_group.add_argument(
|
||||
'--down',
|
||||
action='store_true',
|
||||
help=_('Force down service. Requires ``--os-compute-api-version`` '
|
||||
'2.11 or greater.'),
|
||||
help=_(
|
||||
'Force down service. Requires ``--os-compute-api-version`` '
|
||||
'2.11 or greater.'
|
||||
),
|
||||
)
|
||||
return parser
|
||||
|
||||
@ -196,45 +204,49 @@ class SetService(command.Command):
|
||||
services = list(compute_client.services(host=host, binary=binary))
|
||||
# Did we find anything?
|
||||
if not len(services):
|
||||
msg = _('Compute service for host "%(host)s" and binary '
|
||||
'"%(binary)s" not found.') % {
|
||||
'host': host, 'binary': binary}
|
||||
msg = _(
|
||||
'Compute service for host "%(host)s" and binary '
|
||||
'"%(binary)s" not found.'
|
||||
) % {'host': host, 'binary': binary}
|
||||
raise exceptions.CommandError(msg)
|
||||
# Did we find more than one result? This should not happen but let's
|
||||
# be safe.
|
||||
if len(services) > 1:
|
||||
# TODO(mriedem): If we have an --id option for 2.53+ then we can
|
||||
# say to use that option to uniquely identify the service.
|
||||
msg = _('Multiple compute services found for host "%(host)s" and '
|
||||
'binary "%(binary)s". Unable to proceed.') % {
|
||||
'host': host, 'binary': binary}
|
||||
msg = _(
|
||||
'Multiple compute services found for host "%(host)s" and '
|
||||
'binary "%(binary)s". Unable to proceed.'
|
||||
) % {'host': host, 'binary': binary}
|
||||
raise exceptions.CommandError(msg)
|
||||
return services[0]
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
compute_client = self.app.client_manager.sdk_connection.compute
|
||||
|
||||
if (parsed_args.enable or not parsed_args.disable) and \
|
||||
parsed_args.disable_reason:
|
||||
msg = _("Cannot specify option --disable-reason without "
|
||||
"--disable specified.")
|
||||
if (
|
||||
parsed_args.enable or not parsed_args.disable
|
||||
) and parsed_args.disable_reason:
|
||||
msg = _(
|
||||
"Cannot specify option --disable-reason without "
|
||||
"--disable specified."
|
||||
)
|
||||
raise exceptions.CommandError(msg)
|
||||
|
||||
# Starting with microversion 2.53, there is a single
|
||||
# PUT /os-services/{service_id} API for updating nova-compute
|
||||
# services. If 2.53+ is used we need to find the nova-compute
|
||||
# service using the --host and --service (binary) values.
|
||||
requires_service_id = (
|
||||
sdk_utils.supports_microversion(compute_client, '2.53'))
|
||||
requires_service_id = sdk_utils.supports_microversion(
|
||||
compute_client, '2.53'
|
||||
)
|
||||
service_id = None
|
||||
if requires_service_id:
|
||||
# TODO(mriedem): Add an --id option so users can pass the service
|
||||
# id (as a uuid) directly rather than make us look it up using
|
||||
# host/binary.
|
||||
service_id = SetService._find_service_by_host_and_binary(
|
||||
compute_client,
|
||||
parsed_args.host,
|
||||
parsed_args.service
|
||||
compute_client, parsed_args.host, parsed_args.service
|
||||
).id
|
||||
|
||||
result = 0
|
||||
@ -248,16 +260,14 @@ class SetService(command.Command):
|
||||
if enabled is not None:
|
||||
if enabled:
|
||||
compute_client.enable_service(
|
||||
service_id,
|
||||
parsed_args.host,
|
||||
parsed_args.service
|
||||
service_id, parsed_args.host, parsed_args.service
|
||||
)
|
||||
else:
|
||||
compute_client.disable_service(
|
||||
service_id,
|
||||
parsed_args.host,
|
||||
parsed_args.service,
|
||||
parsed_args.disable_reason
|
||||
parsed_args.disable_reason,
|
||||
)
|
||||
except Exception:
|
||||
status = "enabled" if enabled else "disabled"
|
||||
@ -271,15 +281,16 @@ class SetService(command.Command):
|
||||
force_down = False
|
||||
if force_down is not None:
|
||||
if not sdk_utils.supports_microversion(compute_client, '2.11'):
|
||||
msg = _('--os-compute-api-version 2.11 or later is '
|
||||
'required')
|
||||
msg = _(
|
||||
'--os-compute-api-version 2.11 or later is ' 'required'
|
||||
)
|
||||
raise exceptions.CommandError(msg)
|
||||
try:
|
||||
compute_client.update_service_forced_down(
|
||||
service_id,
|
||||
parsed_args.host,
|
||||
parsed_args.service,
|
||||
force_down
|
||||
force_down,
|
||||
)
|
||||
except Exception:
|
||||
state = "down" if force_down else "up"
|
||||
@ -287,7 +298,8 @@ class SetService(command.Command):
|
||||
result += 1
|
||||
|
||||
if result > 0:
|
||||
msg = _("Compute service %(service)s of host %(host)s failed to "
|
||||
"set.") % {"service": parsed_args.service,
|
||||
"host": parsed_args.host}
|
||||
msg = _(
|
||||
"Compute service %(service)s of host %(host)s failed to "
|
||||
"set."
|
||||
) % {"service": parsed_args.service, "host": parsed_args.host}
|
||||
raise exceptions.CommandError(msg)
|
||||
|
@ -54,13 +54,11 @@ class ProjectColumn(cliff_columns.FormattableColumn):
|
||||
|
||||
|
||||
class CountColumn(cliff_columns.FormattableColumn):
|
||||
|
||||
def human_readable(self):
|
||||
return len(self._value) if self._value is not None else None
|
||||
|
||||
|
||||
class FloatColumn(cliff_columns.FormattableColumn):
|
||||
|
||||
def human_readable(self):
|
||||
return float("%.2f" % self._value)
|
||||
|
||||
@ -68,7 +66,8 @@ class FloatColumn(cliff_columns.FormattableColumn):
|
||||
def _formatters(project_cache):
|
||||
return {
|
||||
'project_id': functools.partial(
|
||||
ProjectColumn, project_cache=project_cache),
|
||||
ProjectColumn, project_cache=project_cache
|
||||
),
|
||||
'server_usages': CountColumn,
|
||||
'total_memory_mb_usage': FloatColumn,
|
||||
'total_vcpus_usage': FloatColumn,
|
||||
@ -115,19 +114,20 @@ class ListUsage(command.Lister):
|
||||
"--start",
|
||||
metavar="<start>",
|
||||
default=None,
|
||||
help=_("Usage range start date, ex 2012-01-20"
|
||||
" (default: 4 weeks ago)")
|
||||
help=_(
|
||||
"Usage range start date, ex 2012-01-20"
|
||||
" (default: 4 weeks ago)"
|
||||
),
|
||||
)
|
||||
parser.add_argument(
|
||||
"--end",
|
||||
metavar="<end>",
|
||||
default=None,
|
||||
help=_("Usage range end date, ex 2012-01-20 (default: tomorrow)")
|
||||
help=_("Usage range end date, ex 2012-01-20 (default: tomorrow)"),
|
||||
)
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
|
||||
def _format_project(project):
|
||||
if not project:
|
||||
return ""
|
||||
@ -142,14 +142,14 @@ class ListUsage(command.Lister):
|
||||
"server_usages",
|
||||
"total_memory_mb_usage",
|
||||
"total_vcpus_usage",
|
||||
"total_local_gb_usage"
|
||||
"total_local_gb_usage",
|
||||
)
|
||||
column_headers = (
|
||||
"Project",
|
||||
"Servers",
|
||||
"RAM MB-Hours",
|
||||
"CPU Hours",
|
||||
"Disk GB-Hours"
|
||||
"Disk GB-Hours",
|
||||
)
|
||||
|
||||
date_cli_format = "%Y-%m-%d"
|
||||
@ -158,7 +158,8 @@ class ListUsage(command.Lister):
|
||||
|
||||
if parsed_args.start:
|
||||
start = datetime.datetime.strptime(
|
||||
parsed_args.start, date_cli_format)
|
||||
parsed_args.start, date_cli_format
|
||||
)
|
||||
else:
|
||||
start = now - datetime.timedelta(weeks=4)
|
||||
|
||||
@ -167,10 +168,13 @@ class ListUsage(command.Lister):
|
||||
else:
|
||||
end = now + datetime.timedelta(days=1)
|
||||
|
||||
usage_list = list(compute_client.usages(
|
||||
start=start.strftime(date_api_format),
|
||||
end=end.strftime(date_api_format),
|
||||
detailed=True))
|
||||
usage_list = list(
|
||||
compute_client.usages(
|
||||
start=start.strftime(date_api_format),
|
||||
end=end.strftime(date_api_format),
|
||||
detailed=True,
|
||||
)
|
||||
)
|
||||
|
||||
# Cache the project list
|
||||
project_cache = {}
|
||||
@ -182,18 +186,23 @@ class ListUsage(command.Lister):
|
||||
pass
|
||||
|
||||
if parsed_args.formatter == 'table' and len(usage_list) > 0:
|
||||
self.app.stdout.write(_("Usage from %(start)s to %(end)s: \n") % {
|
||||
"start": start.strftime(date_cli_format),
|
||||
"end": end.strftime(date_cli_format),
|
||||
})
|
||||
self.app.stdout.write(
|
||||
_("Usage from %(start)s to %(end)s: \n")
|
||||
% {
|
||||
"start": start.strftime(date_cli_format),
|
||||
"end": end.strftime(date_cli_format),
|
||||
}
|
||||
)
|
||||
|
||||
return (
|
||||
column_headers,
|
||||
(
|
||||
utils.get_item_properties(
|
||||
s, columns,
|
||||
s,
|
||||
columns,
|
||||
formatters=_formatters(project_cache),
|
||||
) for s in usage_list
|
||||
)
|
||||
for s in usage_list
|
||||
),
|
||||
)
|
||||
|
||||
@ -207,20 +216,22 @@ class ShowUsage(command.ShowOne):
|
||||
"--project",
|
||||
metavar="<project>",
|
||||
default=None,
|
||||
help=_("Name or ID of project to show usage for")
|
||||
help=_("Name or ID of project to show usage for"),
|
||||
)
|
||||
parser.add_argument(
|
||||
"--start",
|
||||
metavar="<start>",
|
||||
default=None,
|
||||
help=_("Usage range start date, ex 2012-01-20"
|
||||
" (default: 4 weeks ago)")
|
||||
help=_(
|
||||
"Usage range start date, ex 2012-01-20"
|
||||
" (default: 4 weeks ago)"
|
||||
),
|
||||
)
|
||||
parser.add_argument(
|
||||
"--end",
|
||||
metavar="<end>",
|
||||
default=None,
|
||||
help=_("Usage range end date, ex 2012-01-20 (default: tomorrow)")
|
||||
help=_("Usage range end date, ex 2012-01-20 (default: tomorrow)"),
|
||||
)
|
||||
return parser
|
||||
|
||||
@ -233,7 +244,8 @@ class ShowUsage(command.ShowOne):
|
||||
|
||||
if parsed_args.start:
|
||||
start = datetime.datetime.strptime(
|
||||
parsed_args.start, date_cli_format)
|
||||
parsed_args.start, date_cli_format
|
||||
)
|
||||
else:
|
||||
start = now - datetime.timedelta(weeks=4)
|
||||
|
||||
@ -252,33 +264,37 @@ class ShowUsage(command.ShowOne):
|
||||
project = self.app.client_manager.auth_ref.project_id
|
||||
|
||||
usage = compute_client.get_usage(
|
||||
project=project, start=start.strftime(date_api_format),
|
||||
end=end.strftime(date_api_format))
|
||||
project=project,
|
||||
start=start.strftime(date_api_format),
|
||||
end=end.strftime(date_api_format),
|
||||
)
|
||||
|
||||
if parsed_args.formatter == 'table':
|
||||
self.app.stdout.write(_(
|
||||
"Usage from %(start)s to %(end)s on project %(project)s: \n"
|
||||
) % {
|
||||
"start": start.strftime(date_cli_format),
|
||||
"end": end.strftime(date_cli_format),
|
||||
"project": project,
|
||||
})
|
||||
self.app.stdout.write(
|
||||
_("Usage from %(start)s to %(end)s on project %(project)s: \n")
|
||||
% {
|
||||
"start": start.strftime(date_cli_format),
|
||||
"end": end.strftime(date_cli_format),
|
||||
"project": project,
|
||||
}
|
||||
)
|
||||
|
||||
columns = (
|
||||
"project_id",
|
||||
"server_usages",
|
||||
"total_memory_mb_usage",
|
||||
"total_vcpus_usage",
|
||||
"total_local_gb_usage"
|
||||
"total_local_gb_usage",
|
||||
)
|
||||
column_headers = (
|
||||
"Project",
|
||||
"Servers",
|
||||
"RAM MB-Hours",
|
||||
"CPU Hours",
|
||||
"Disk GB-Hours"
|
||||
"Disk GB-Hours",
|
||||
)
|
||||
|
||||
data = utils.get_item_properties(
|
||||
usage, columns, formatters=_formatters(None))
|
||||
usage, columns, formatters=_formatters(None)
|
||||
)
|
||||
return column_headers, data
|
||||
|
@ -53,9 +53,10 @@ class ComputeTestCase(base.TestCase):
|
||||
images = cls.openstack("image list", parse_output=True)
|
||||
server_image = None
|
||||
for image in images:
|
||||
if (image['Name'].startswith('cirros-') and
|
||||
(image['Name'].endswith('-uec') or
|
||||
image['Name'].endswith('-disk'))):
|
||||
if image['Name'].startswith('cirros-') and (
|
||||
image['Name'].endswith('-uec')
|
||||
or image['Name'].endswith('-disk')
|
||||
):
|
||||
server_image = image['Name']
|
||||
break
|
||||
return server_image
|
||||
@ -83,12 +84,17 @@ class ComputeTestCase(base.TestCase):
|
||||
self.network_arg = self.get_network()
|
||||
name = name or uuid.uuid4().hex
|
||||
cmd_output = self.openstack(
|
||||
'server create ' +
|
||||
'--flavor ' + self.flavor_name + ' ' +
|
||||
'--image ' + self.image_name + ' ' +
|
||||
self.network_arg + ' ' +
|
||||
'--wait ' +
|
||||
name,
|
||||
'server create '
|
||||
+ '--flavor '
|
||||
+ self.flavor_name
|
||||
+ ' '
|
||||
+ '--image '
|
||||
+ self.image_name
|
||||
+ ' '
|
||||
+ self.network_arg
|
||||
+ ' '
|
||||
+ '--wait '
|
||||
+ name,
|
||||
parse_output=True,
|
||||
)
|
||||
self.assertIsNotNone(cmd_output["id"])
|
||||
@ -106,11 +112,11 @@ class ComputeTestCase(base.TestCase):
|
||||
self.assertOutput('', raw_output)
|
||||
|
||||
def wait_for_status(
|
||||
self,
|
||||
name,
|
||||
expected_status='ACTIVE',
|
||||
wait=900,
|
||||
interval=10,
|
||||
self,
|
||||
name,
|
||||
expected_status='ACTIVE',
|
||||
wait=900,
|
||||
interval=10,
|
||||
):
|
||||
"""Wait until server reaches expected status"""
|
||||
# TODO(thowe): Add a server wait command to osc
|
||||
@ -118,24 +124,24 @@ class ComputeTestCase(base.TestCase):
|
||||
total_sleep = 0
|
||||
while total_sleep < wait:
|
||||
cmd_output = self.openstack(
|
||||
'server show ' +
|
||||
name,
|
||||
'server show ' + name,
|
||||
parse_output=True,
|
||||
)
|
||||
status = cmd_output['status']
|
||||
if status == expected_status:
|
||||
print('Server {} now has status {}'.format(
|
||||
name, status))
|
||||
print('Server {} now has status {}'.format(name, status))
|
||||
break
|
||||
print('Server {}: Waiting for {}, current status: {}'.format(
|
||||
name, expected_status, status))
|
||||
print(
|
||||
'Server {}: Waiting for {}, current status: {}'.format(
|
||||
name, expected_status, status
|
||||
)
|
||||
)
|
||||
self.assertNotIn(status, failures)
|
||||
time.sleep(interval)
|
||||
total_sleep += interval
|
||||
|
||||
cmd_output = self.openstack(
|
||||
'server show ' +
|
||||
name,
|
||||
'server show ' + name,
|
||||
parse_output=True,
|
||||
)
|
||||
status = cmd_output['status']
|
||||
|
@ -27,24 +27,12 @@ class AggregateTests(base.TestCase):
|
||||
fail_ok=True,
|
||||
)
|
||||
cmd_output = self.openstack(
|
||||
'aggregate create ' +
|
||||
'--zone nova ' +
|
||||
'--property a=b ' +
|
||||
name1,
|
||||
'aggregate create ' + '--zone nova ' + '--property a=b ' + name1,
|
||||
parse_output=True,
|
||||
)
|
||||
self.assertEqual(
|
||||
name1,
|
||||
cmd_output['name']
|
||||
)
|
||||
self.assertEqual(
|
||||
'nova',
|
||||
cmd_output['availability_zone']
|
||||
)
|
||||
self.assertIn(
|
||||
'a',
|
||||
cmd_output['properties']
|
||||
)
|
||||
self.assertEqual(name1, cmd_output['name'])
|
||||
self.assertEqual('nova', cmd_output['availability_zone'])
|
||||
self.assertIn('a', cmd_output['properties'])
|
||||
cmd_output = self.openstack(
|
||||
'aggregate show ' + name1,
|
||||
parse_output=True,
|
||||
@ -58,19 +46,11 @@ class AggregateTests(base.TestCase):
|
||||
fail_ok=True,
|
||||
)
|
||||
cmd_output = self.openstack(
|
||||
'aggregate create ' +
|
||||
'--zone external ' +
|
||||
name2,
|
||||
'aggregate create ' + '--zone external ' + name2,
|
||||
parse_output=True,
|
||||
)
|
||||
self.assertEqual(
|
||||
name2,
|
||||
cmd_output['name']
|
||||
)
|
||||
self.assertEqual(
|
||||
'external',
|
||||
cmd_output['availability_zone']
|
||||
)
|
||||
self.assertEqual(name2, cmd_output['name'])
|
||||
self.assertEqual('external', cmd_output['availability_zone'])
|
||||
cmd_output = self.openstack(
|
||||
'aggregate show ' + name2,
|
||||
parse_output=True,
|
||||
@ -85,36 +65,25 @@ class AggregateTests(base.TestCase):
|
||||
fail_ok=True,
|
||||
)
|
||||
raw_output = self.openstack(
|
||||
'aggregate set ' +
|
||||
'--name ' + name3 + ' ' +
|
||||
'--zone internal ' +
|
||||
'--no-property ' +
|
||||
'--property c=d ' +
|
||||
name1
|
||||
'aggregate set '
|
||||
+ '--name '
|
||||
+ name3
|
||||
+ ' '
|
||||
+ '--zone internal '
|
||||
+ '--no-property '
|
||||
+ '--property c=d '
|
||||
+ name1
|
||||
)
|
||||
self.assertOutput('', raw_output)
|
||||
|
||||
cmd_output = self.openstack(
|
||||
'aggregate show ' +
|
||||
name3,
|
||||
'aggregate show ' + name3,
|
||||
parse_output=True,
|
||||
)
|
||||
self.assertEqual(
|
||||
name3,
|
||||
cmd_output['name']
|
||||
)
|
||||
self.assertEqual(
|
||||
'internal',
|
||||
cmd_output['availability_zone']
|
||||
)
|
||||
self.assertIn(
|
||||
'c',
|
||||
cmd_output['properties']
|
||||
)
|
||||
self.assertNotIn(
|
||||
'a',
|
||||
cmd_output['properties']
|
||||
)
|
||||
self.assertEqual(name3, cmd_output['name'])
|
||||
self.assertEqual('internal', cmd_output['availability_zone'])
|
||||
self.assertIn('c', cmd_output['properties'])
|
||||
self.assertNotIn('a', cmd_output['properties'])
|
||||
|
||||
# Test aggregate list
|
||||
cmd_output = self.openstack(
|
||||
@ -145,28 +114,18 @@ class AggregateTests(base.TestCase):
|
||||
|
||||
# Test unset
|
||||
raw_output = self.openstack(
|
||||
'aggregate unset ' +
|
||||
'--property c ' +
|
||||
name3
|
||||
'aggregate unset ' + '--property c ' + name3
|
||||
)
|
||||
self.assertOutput('', raw_output)
|
||||
|
||||
cmd_output = self.openstack(
|
||||
'aggregate show ' +
|
||||
name3,
|
||||
'aggregate show ' + name3,
|
||||
parse_output=True,
|
||||
)
|
||||
self.assertNotIn(
|
||||
"c='d'",
|
||||
cmd_output['properties']
|
||||
)
|
||||
self.assertNotIn("c='d'", cmd_output['properties'])
|
||||
|
||||
# test aggregate delete
|
||||
del_output = self.openstack(
|
||||
'aggregate delete ' +
|
||||
name3 + ' ' +
|
||||
name2
|
||||
)
|
||||
del_output = self.openstack('aggregate delete ' + name3 + ' ' + name2)
|
||||
self.assertOutput('', del_output)
|
||||
|
||||
def test_aggregate_add_and_remove_host(self):
|
||||
@ -185,31 +144,18 @@ class AggregateTests(base.TestCase):
|
||||
|
||||
name = uuid.uuid4().hex
|
||||
self.addCleanup(self.openstack, 'aggregate delete ' + name)
|
||||
self.openstack(
|
||||
'aggregate create ' +
|
||||
name
|
||||
)
|
||||
self.openstack('aggregate create ' + name)
|
||||
|
||||
# Test add host
|
||||
cmd_output = self.openstack(
|
||||
'aggregate add host ' +
|
||||
name + ' ' +
|
||||
host_name,
|
||||
'aggregate add host ' + name + ' ' + host_name,
|
||||
parse_output=True,
|
||||
)
|
||||
self.assertIn(
|
||||
host_name,
|
||||
cmd_output['hosts']
|
||||
)
|
||||
self.assertIn(host_name, cmd_output['hosts'])
|
||||
|
||||
# Test remove host
|
||||
cmd_output = self.openstack(
|
||||
'aggregate remove host ' +
|
||||
name + ' ' +
|
||||
host_name,
|
||||
'aggregate remove host ' + name + ' ' + host_name,
|
||||
parse_output=True,
|
||||
)
|
||||
self.assertNotIn(
|
||||
host_name,
|
||||
cmd_output['hosts']
|
||||
)
|
||||
self.assertNotIn(host_name, cmd_output['hosts'])
|
||||
|
@ -42,21 +42,25 @@ class FlavorTests(base.TestCase):
|
||||
"""Test create w/project, delete multiple"""
|
||||
name1 = uuid.uuid4().hex
|
||||
cmd_output = self.openstack(
|
||||
"flavor create " +
|
||||
"--project " + self.PROJECT_NAME + " " +
|
||||
"--private " +
|
||||
name1,
|
||||
"flavor create "
|
||||
+ "--project "
|
||||
+ self.PROJECT_NAME
|
||||
+ " "
|
||||
+ "--private "
|
||||
+ name1,
|
||||
parse_output=True,
|
||||
)
|
||||
self.assertIsNotNone(cmd_output["id"])
|
||||
|
||||
name2 = uuid.uuid4().hex
|
||||
cmd_output = self.openstack(
|
||||
"flavor create " +
|
||||
"--id qaz " +
|
||||
"--project " + self.PROJECT_NAME + " " +
|
||||
"--private " +
|
||||
name2,
|
||||
"flavor create "
|
||||
+ "--id qaz "
|
||||
+ "--project "
|
||||
+ self.PROJECT_NAME
|
||||
+ " "
|
||||
+ "--private "
|
||||
+ name2,
|
||||
parse_output=True,
|
||||
)
|
||||
self.assertIsNotNone(cmd_output["id"])
|
||||
@ -74,10 +78,7 @@ class FlavorTests(base.TestCase):
|
||||
"""Test create defaults, list filters, delete"""
|
||||
name1 = uuid.uuid4().hex
|
||||
cmd_output = self.openstack(
|
||||
"flavor create " +
|
||||
"--property a=b " +
|
||||
"--property c=d " +
|
||||
name1,
|
||||
"flavor create " + "--property a=b " + "--property c=d " + name1,
|
||||
parse_output=True,
|
||||
)
|
||||
self.addCleanup(self.openstack, "flavor delete " + name1)
|
||||
@ -89,13 +90,13 @@ class FlavorTests(base.TestCase):
|
||||
|
||||
name2 = uuid.uuid4().hex
|
||||
cmd_output = self.openstack(
|
||||
"flavor create " +
|
||||
"--id qaz " +
|
||||
"--ram 123 " +
|
||||
"--private " +
|
||||
"--property a=b2 " +
|
||||
"--property b=d2 " +
|
||||
name2,
|
||||
"flavor create "
|
||||
+ "--id qaz "
|
||||
+ "--ram 123 "
|
||||
+ "--private "
|
||||
+ "--property a=b2 "
|
||||
+ "--property b=d2 "
|
||||
+ name2,
|
||||
parse_output=True,
|
||||
)
|
||||
self.addCleanup(self.openstack, "flavor delete " + name2)
|
||||
@ -135,8 +136,7 @@ class FlavorTests(base.TestCase):
|
||||
|
||||
# Test list --long
|
||||
cmd_output = self.openstack(
|
||||
"flavor list " +
|
||||
"--long",
|
||||
"flavor list " + "--long",
|
||||
parse_output=True,
|
||||
)
|
||||
# We have list of complex json objects
|
||||
@ -154,8 +154,7 @@ class FlavorTests(base.TestCase):
|
||||
|
||||
# Test list --public
|
||||
cmd_output = self.openstack(
|
||||
"flavor list " +
|
||||
"--public",
|
||||
"flavor list " + "--public",
|
||||
parse_output=True,
|
||||
)
|
||||
col_name = [x["Name"] for x in cmd_output]
|
||||
@ -164,8 +163,7 @@ class FlavorTests(base.TestCase):
|
||||
|
||||
# Test list --private
|
||||
cmd_output = self.openstack(
|
||||
"flavor list " +
|
||||
"--private",
|
||||
"flavor list " + "--private",
|
||||
parse_output=True,
|
||||
)
|
||||
col_name = [x["Name"] for x in cmd_output]
|
||||
@ -174,8 +172,7 @@ class FlavorTests(base.TestCase):
|
||||
|
||||
# Test list --all
|
||||
cmd_output = self.openstack(
|
||||
"flavor list " +
|
||||
"--all",
|
||||
"flavor list " + "--all",
|
||||
parse_output=True,
|
||||
)
|
||||
col_name = [x["Name"] for x in cmd_output]
|
||||
@ -186,14 +183,14 @@ class FlavorTests(base.TestCase):
|
||||
"""Test create defaults, list filters, delete"""
|
||||
name1 = uuid.uuid4().hex
|
||||
cmd_output = self.openstack(
|
||||
"flavor create " +
|
||||
"--id qaz " +
|
||||
"--ram 123 " +
|
||||
"--disk 20 " +
|
||||
"--private " +
|
||||
"--property a=first " +
|
||||
"--property b=second " +
|
||||
name1,
|
||||
"flavor create "
|
||||
+ "--id qaz "
|
||||
+ "--ram 123 "
|
||||
+ "--disk 20 "
|
||||
+ "--private "
|
||||
+ "--property a=first "
|
||||
+ "--property b=second "
|
||||
+ name1,
|
||||
parse_output=True,
|
||||
)
|
||||
self.addCleanup(self.openstack, "flavor delete " + name1)
|
||||
@ -223,42 +220,30 @@ class FlavorTests(base.TestCase):
|
||||
)
|
||||
|
||||
raw_output = self.openstack(
|
||||
"flavor set " +
|
||||
"--property a='third and 10' " +
|
||||
"--property g=fourth " +
|
||||
name1
|
||||
"flavor set "
|
||||
+ "--property a='third and 10' "
|
||||
+ "--property g=fourth "
|
||||
+ name1
|
||||
)
|
||||
self.assertEqual('', raw_output)
|
||||
|
||||
cmd_output = self.openstack(
|
||||
"flavor show " +
|
||||
name1,
|
||||
"flavor show " + name1,
|
||||
parse_output=True,
|
||||
)
|
||||
self.assertEqual(
|
||||
"qaz",
|
||||
cmd_output["id"],
|
||||
)
|
||||
self.assertEqual(
|
||||
'third and 10',
|
||||
cmd_output['properties']['a'])
|
||||
self.assertEqual(
|
||||
'second',
|
||||
cmd_output['properties']['b'])
|
||||
self.assertEqual(
|
||||
'fourth',
|
||||
cmd_output['properties']['g'])
|
||||
self.assertEqual('third and 10', cmd_output['properties']['a'])
|
||||
self.assertEqual('second', cmd_output['properties']['b'])
|
||||
self.assertEqual('fourth', cmd_output['properties']['g'])
|
||||
|
||||
raw_output = self.openstack(
|
||||
"flavor unset " +
|
||||
"--property b " +
|
||||
name1
|
||||
)
|
||||
raw_output = self.openstack("flavor unset " + "--property b " + name1)
|
||||
self.assertEqual('', raw_output)
|
||||
|
||||
cmd_output = self.openstack(
|
||||
"flavor show " +
|
||||
name1,
|
||||
"flavor show " + name1,
|
||||
parse_output=True,
|
||||
)
|
||||
|
||||
|
@ -21,32 +21,32 @@ class HypervisorTests(base.TestCase):
|
||||
def test_hypervisor_list(self):
|
||||
"""Test create defaults, list filters, delete"""
|
||||
# Test list
|
||||
cmd_output = json.loads(self.openstack(
|
||||
"hypervisor list -f json --os-compute-api-version 2.1"
|
||||
))
|
||||
cmd_output = json.loads(
|
||||
self.openstack(
|
||||
"hypervisor list -f json --os-compute-api-version 2.1"
|
||||
)
|
||||
)
|
||||
ids1 = [x["ID"] for x in cmd_output]
|
||||
self.assertIsNotNone(cmd_output)
|
||||
|
||||
cmd_output = json.loads(self.openstack(
|
||||
"hypervisor list -f json"
|
||||
))
|
||||
cmd_output = json.loads(self.openstack("hypervisor list -f json"))
|
||||
ids2 = [x["ID"] for x in cmd_output]
|
||||
self.assertIsNotNone(cmd_output)
|
||||
|
||||
# Show test - old microversion
|
||||
for i in ids1:
|
||||
cmd_output = json.loads(self.openstack(
|
||||
"hypervisor show %s -f json "
|
||||
" --os-compute-api-version 2.1"
|
||||
% (i)
|
||||
))
|
||||
cmd_output = json.loads(
|
||||
self.openstack(
|
||||
"hypervisor show %s -f json "
|
||||
" --os-compute-api-version 2.1" % (i)
|
||||
)
|
||||
)
|
||||
self.assertIsNotNone(cmd_output)
|
||||
# When we list hypervisors with older MV we get ids as integers. We
|
||||
# need to verify that show finds resources independently
|
||||
# Show test - latest microversion
|
||||
for i in ids2:
|
||||
cmd_output = json.loads(self.openstack(
|
||||
"hypervisor show %s -f json"
|
||||
% (i)
|
||||
))
|
||||
cmd_output = json.loads(
|
||||
self.openstack("hypervisor show %s -f json" % (i))
|
||||
)
|
||||
self.assertIsNotNone(cmd_output)
|
||||
|
@ -68,8 +68,11 @@ class KeypairTests(KeypairBase):
|
||||
1) Create keypair in setUp
|
||||
2) Try to create duplicate keypair with the same name
|
||||
"""
|
||||
self.assertRaises(exceptions.CommandFailed,
|
||||
self.openstack, 'keypair create ' + self.KPName)
|
||||
self.assertRaises(
|
||||
exceptions.CommandFailed,
|
||||
self.openstack,
|
||||
'keypair create ' + self.KPName,
|
||||
)
|
||||
|
||||
def test_keypair_create_noname(self):
|
||||
"""Try to create keypair without name.
|
||||
@ -77,8 +80,9 @@ class KeypairTests(KeypairBase):
|
||||
Test steps:
|
||||
1) Try to create keypair without a name
|
||||
"""
|
||||
self.assertRaises(exceptions.CommandFailed,
|
||||
self.openstack, 'keypair create')
|
||||
self.assertRaises(
|
||||
exceptions.CommandFailed, self.openstack, 'keypair create'
|
||||
)
|
||||
|
||||
def test_keypair_create_public_key(self):
|
||||
"""Test for create keypair with --public-key option.
|
||||
@ -118,11 +122,13 @@ class KeypairTests(KeypairBase):
|
||||
self.assertIsNotNone(cmd_output.get('fingerprint'))
|
||||
pk_content = f.read()
|
||||
self.assertInOutput(
|
||||
'-----BEGIN OPENSSH PRIVATE KEY-----', pk_content,
|
||||
'-----BEGIN OPENSSH PRIVATE KEY-----',
|
||||
pk_content,
|
||||
)
|
||||
self.assertRegex(pk_content, "[0-9A-Za-z+/]+[=]{0,3}\n")
|
||||
self.assertInOutput(
|
||||
'-----END OPENSSH PRIVATE KEY-----', pk_content,
|
||||
'-----END OPENSSH PRIVATE KEY-----',
|
||||
pk_content,
|
||||
)
|
||||
|
||||
def test_keypair_create(self):
|
||||
@ -148,8 +154,11 @@ class KeypairTests(KeypairBase):
|
||||
1) Create keypair in setUp
|
||||
2) Try to delete not existing keypair
|
||||
"""
|
||||
self.assertRaises(exceptions.CommandFailed,
|
||||
self.openstack, 'keypair delete not_existing')
|
||||
self.assertRaises(
|
||||
exceptions.CommandFailed,
|
||||
self.openstack,
|
||||
'keypair delete not_existing',
|
||||
)
|
||||
|
||||
def test_keypair_delete(self):
|
||||
"""Test keypair delete command.
|
||||
|
@ -52,16 +52,14 @@ class ServerTests(common.ComputeTestCase):
|
||||
self.assertEqual("", raw_output)
|
||||
self.wait_for_status(name2, "PAUSED")
|
||||
cmd_output = self.openstack(
|
||||
'server list ' +
|
||||
'--status ACTIVE',
|
||||
'server list ' + '--status ACTIVE',
|
||||
parse_output=True,
|
||||
)
|
||||
col_name = [x["Name"] for x in cmd_output]
|
||||
self.assertIn(name1, col_name)
|
||||
self.assertNotIn(name2, col_name)
|
||||
cmd_output = self.openstack(
|
||||
'server list ' +
|
||||
'--status PAUSED',
|
||||
'server list ' + '--status PAUSED',
|
||||
parse_output=True,
|
||||
)
|
||||
col_name = [x["Name"] for x in cmd_output]
|
||||
@ -112,8 +110,9 @@ class ServerTests(common.ComputeTestCase):
|
||||
parse_output=True,
|
||||
)
|
||||
except exceptions.CommandFailed as e:
|
||||
self.assertIn('marker [%s] not found' % (name2),
|
||||
e.stderr.decode('utf-8'))
|
||||
self.assertIn(
|
||||
'marker [%s] not found' % (name2), e.stderr.decode('utf-8')
|
||||
)
|
||||
|
||||
def test_server_list_with_changes_before(self):
|
||||
"""Test server list.
|
||||
@ -132,8 +131,7 @@ class ServerTests(common.ComputeTestCase):
|
||||
server_name3 = cmd_output['name']
|
||||
|
||||
cmd_output = self.openstack(
|
||||
'--os-compute-api-version 2.66 ' +
|
||||
'server list '
|
||||
'--os-compute-api-version 2.66 ' + 'server list '
|
||||
'--changes-before ' + updated_at2,
|
||||
parse_output=True,
|
||||
)
|
||||
@ -158,8 +156,7 @@ class ServerTests(common.ComputeTestCase):
|
||||
server_name3 = cmd_output['name']
|
||||
|
||||
cmd_output = self.openstack(
|
||||
'server list '
|
||||
'--changes-since ' + updated_at2,
|
||||
'server list ' '--changes-since ' + updated_at2,
|
||||
parse_output=True,
|
||||
)
|
||||
|
||||
@ -184,10 +181,12 @@ class ServerTests(common.ComputeTestCase):
|
||||
updated_at3 = cmd_output['updated']
|
||||
|
||||
cmd_output = self.openstack(
|
||||
'--os-compute-api-version 2.66 ' +
|
||||
'server list ' +
|
||||
'--changes-since ' + updated_at2 +
|
||||
' --changes-before ' + updated_at3,
|
||||
'--os-compute-api-version 2.66 '
|
||||
+ 'server list '
|
||||
+ '--changes-since '
|
||||
+ updated_at2
|
||||
+ ' --changes-before '
|
||||
+ updated_at3,
|
||||
parse_output=True,
|
||||
)
|
||||
|
||||
@ -204,8 +203,7 @@ class ServerTests(common.ComputeTestCase):
|
||||
|
||||
# Have a look at some other fields
|
||||
flavor = self.openstack(
|
||||
'flavor show ' +
|
||||
self.flavor_name,
|
||||
'flavor show ' + self.flavor_name,
|
||||
parse_output=True,
|
||||
)
|
||||
self.assertEqual(
|
||||
@ -217,8 +215,7 @@ class ServerTests(common.ComputeTestCase):
|
||||
cmd_output["flavor"],
|
||||
)
|
||||
image = self.openstack(
|
||||
'image show ' +
|
||||
self.image_name,
|
||||
'image show ' + self.image_name,
|
||||
parse_output=True,
|
||||
)
|
||||
self.assertEqual(
|
||||
@ -232,15 +229,12 @@ class ServerTests(common.ComputeTestCase):
|
||||
|
||||
# Test properties set
|
||||
raw_output = self.openstack(
|
||||
'server set ' +
|
||||
'--property a=b --property c=d ' +
|
||||
name
|
||||
'server set ' + '--property a=b --property c=d ' + name
|
||||
)
|
||||
self.assertOutput('', raw_output)
|
||||
|
||||
cmd_output = self.openstack(
|
||||
'server show ' +
|
||||
name,
|
||||
'server show ' + name,
|
||||
parse_output=True,
|
||||
)
|
||||
# Really, shouldn't this be a list?
|
||||
@ -249,14 +243,9 @@ class ServerTests(common.ComputeTestCase):
|
||||
cmd_output['properties'],
|
||||
)
|
||||
|
||||
raw_output = self.openstack(
|
||||
'server unset ' +
|
||||
'--property a ' +
|
||||
name
|
||||
)
|
||||
raw_output = self.openstack('server unset ' + '--property a ' + name)
|
||||
cmd_output = self.openstack(
|
||||
'server show ' +
|
||||
name,
|
||||
'server show ' + name,
|
||||
parse_output=True,
|
||||
)
|
||||
self.assertEqual(
|
||||
@ -267,14 +256,11 @@ class ServerTests(common.ComputeTestCase):
|
||||
# Test set --name
|
||||
new_name = uuid.uuid4().hex
|
||||
raw_output = self.openstack(
|
||||
'server set ' +
|
||||
'--name ' + new_name + ' ' +
|
||||
name
|
||||
'server set ' + '--name ' + new_name + ' ' + name
|
||||
)
|
||||
self.assertOutput("", raw_output)
|
||||
cmd_output = self.openstack(
|
||||
'server show ' +
|
||||
new_name,
|
||||
'server show ' + new_name,
|
||||
parse_output=True,
|
||||
)
|
||||
self.assertEqual(
|
||||
@ -283,9 +269,7 @@ class ServerTests(common.ComputeTestCase):
|
||||
)
|
||||
# Put it back so we clean up properly
|
||||
raw_output = self.openstack(
|
||||
'server set ' +
|
||||
'--name ' + name + ' ' +
|
||||
new_name
|
||||
'server set ' + '--name ' + name + ' ' + new_name
|
||||
)
|
||||
self.assertOutput("", raw_output)
|
||||
|
||||
@ -295,25 +279,25 @@ class ServerTests(common.ComputeTestCase):
|
||||
name = cmd_output['name']
|
||||
|
||||
# Simple show
|
||||
cmd_output = json.loads(self.openstack(
|
||||
f'server show -f json {name}'
|
||||
))
|
||||
cmd_output = json.loads(self.openstack(f'server show -f json {name}'))
|
||||
self.assertEqual(
|
||||
name,
|
||||
cmd_output["name"],
|
||||
)
|
||||
|
||||
# Show diagnostics
|
||||
cmd_output = json.loads(self.openstack(
|
||||
f'server show -f json {name} --diagnostics'
|
||||
))
|
||||
cmd_output = json.loads(
|
||||
self.openstack(f'server show -f json {name} --diagnostics')
|
||||
)
|
||||
self.assertIn('driver', cmd_output)
|
||||
|
||||
# Show topology
|
||||
cmd_output = json.loads(self.openstack(
|
||||
f'server show -f json {name} --topology '
|
||||
f'--os-compute-api-version 2.78'
|
||||
))
|
||||
cmd_output = json.loads(
|
||||
self.openstack(
|
||||
f'server show -f json {name} --topology '
|
||||
f'--os-compute-api-version 2.78'
|
||||
)
|
||||
)
|
||||
self.assertIn('topology', cmd_output)
|
||||
|
||||
def test_server_actions(self):
|
||||
@ -358,8 +342,9 @@ class ServerTests(common.ComputeTestCase):
|
||||
self.wait_for_status(name, "ACTIVE")
|
||||
|
||||
# rescue with image
|
||||
raw_output = self.openstack('server rescue --image ' +
|
||||
self.image_name + ' ' + name)
|
||||
raw_output = self.openstack(
|
||||
'server rescue --image ' + self.image_name + ' ' + name
|
||||
)
|
||||
self.assertEqual("", raw_output)
|
||||
self.wait_for_status(name, "RESCUE")
|
||||
|
||||
@ -403,8 +388,7 @@ class ServerTests(common.ComputeTestCase):
|
||||
|
||||
# attach ip
|
||||
cmd_output = self.openstack(
|
||||
'floating ip create ' +
|
||||
'public',
|
||||
'floating ip create ' + 'public',
|
||||
parse_output=True,
|
||||
)
|
||||
|
||||
@ -419,14 +403,11 @@ class ServerTests(common.ComputeTestCase):
|
||||
self.assertNotEqual('', cmd_output['id'])
|
||||
self.assertNotEqual('', floating_ip)
|
||||
self.addCleanup(
|
||||
self.openstack,
|
||||
'floating ip delete ' + str(cmd_output['id'])
|
||||
self.openstack, 'floating ip delete ' + str(cmd_output['id'])
|
||||
)
|
||||
|
||||
raw_output = self.openstack(
|
||||
'server add floating ip ' +
|
||||
name + ' ' +
|
||||
floating_ip
|
||||
'server add floating ip ' + name + ' ' + floating_ip
|
||||
)
|
||||
self.assertEqual("", raw_output)
|
||||
|
||||
@ -436,8 +417,7 @@ class ServerTests(common.ComputeTestCase):
|
||||
wait_time = 0
|
||||
while wait_time < 60:
|
||||
cmd_output = self.openstack(
|
||||
'server show ' +
|
||||
name,
|
||||
'server show ' + name,
|
||||
parse_output=True,
|
||||
)
|
||||
if floating_ip not in _chain_addresses(cmd_output['addresses']):
|
||||
@ -455,9 +435,7 @@ class ServerTests(common.ComputeTestCase):
|
||||
|
||||
# detach ip
|
||||
raw_output = self.openstack(
|
||||
'server remove floating ip ' +
|
||||
name + ' ' +
|
||||
floating_ip
|
||||
'server remove floating ip ' + name + ' ' + floating_ip
|
||||
)
|
||||
self.assertEqual("", raw_output)
|
||||
|
||||
@ -467,8 +445,7 @@ class ServerTests(common.ComputeTestCase):
|
||||
wait_time = 0
|
||||
while wait_time < 60:
|
||||
cmd_output = self.openstack(
|
||||
'server show ' +
|
||||
name,
|
||||
'server show ' + name,
|
||||
parse_output=True,
|
||||
)
|
||||
if floating_ip in _chain_addresses(cmd_output['addresses']):
|
||||
@ -480,8 +457,7 @@ class ServerTests(common.ComputeTestCase):
|
||||
break
|
||||
|
||||
cmd_output = self.openstack(
|
||||
'server show ' +
|
||||
name,
|
||||
'server show ' + name,
|
||||
parse_output=True,
|
||||
)
|
||||
self.assertNotIn(
|
||||
@ -506,8 +482,7 @@ class ServerTests(common.ComputeTestCase):
|
||||
|
||||
# get image size
|
||||
cmd_output = self.openstack(
|
||||
'image show ' +
|
||||
self.image_name,
|
||||
'image show ' + self.image_name,
|
||||
parse_output=True,
|
||||
)
|
||||
try:
|
||||
@ -520,10 +495,14 @@ class ServerTests(common.ComputeTestCase):
|
||||
# create volume from image
|
||||
volume_name = uuid.uuid4().hex
|
||||
cmd_output = self.openstack(
|
||||
'volume create ' +
|
||||
'--image ' + self.image_name + ' ' +
|
||||
'--size ' + str(image_size) + ' ' +
|
||||
volume_name,
|
||||
'volume create '
|
||||
+ '--image '
|
||||
+ self.image_name
|
||||
+ ' '
|
||||
+ '--size '
|
||||
+ str(image_size)
|
||||
+ ' '
|
||||
+ volume_name,
|
||||
parse_output=True,
|
||||
)
|
||||
self.assertIsNotNone(cmd_output["id"])
|
||||
@ -537,9 +516,11 @@ class ServerTests(common.ComputeTestCase):
|
||||
# create empty volume
|
||||
empty_volume_name = uuid.uuid4().hex
|
||||
cmd_output = self.openstack(
|
||||
'volume create ' +
|
||||
'--size ' + str(image_size) + ' ' +
|
||||
empty_volume_name,
|
||||
'volume create '
|
||||
+ '--size '
|
||||
+ str(image_size)
|
||||
+ ' '
|
||||
+ empty_volume_name,
|
||||
parse_output=True,
|
||||
)
|
||||
self.assertIsNotNone(cmd_output["id"])
|
||||
@ -553,13 +534,20 @@ class ServerTests(common.ComputeTestCase):
|
||||
# create server
|
||||
server_name = uuid.uuid4().hex
|
||||
server = self.openstack(
|
||||
'server create ' +
|
||||
'--flavor ' + self.flavor_name + ' ' +
|
||||
'--volume ' + volume_name + ' ' +
|
||||
'--block-device-mapping vdb=' + empty_volume_name + ' ' +
|
||||
self.network_arg + ' ' +
|
||||
'--wait ' +
|
||||
server_name,
|
||||
'server create '
|
||||
+ '--flavor '
|
||||
+ self.flavor_name
|
||||
+ ' '
|
||||
+ '--volume '
|
||||
+ volume_name
|
||||
+ ' '
|
||||
+ '--block-device-mapping vdb='
|
||||
+ empty_volume_name
|
||||
+ ' '
|
||||
+ self.network_arg
|
||||
+ ' '
|
||||
+ '--wait '
|
||||
+ server_name,
|
||||
parse_output=True,
|
||||
)
|
||||
self.assertIsNotNone(server["id"])
|
||||
@ -579,15 +567,11 @@ class ServerTests(common.ComputeTestCase):
|
||||
'server list',
|
||||
parse_output=True,
|
||||
)
|
||||
self.assertEqual(
|
||||
v2_server.IMAGE_STRING_FOR_BFV,
|
||||
servers[0]['Image']
|
||||
)
|
||||
self.assertEqual(v2_server.IMAGE_STRING_FOR_BFV, servers[0]['Image'])
|
||||
|
||||
# check volumes
|
||||
cmd_output = self.openstack(
|
||||
'volume show ' +
|
||||
volume_name,
|
||||
'volume show ' + volume_name,
|
||||
parse_output=True,
|
||||
)
|
||||
attachments = cmd_output['attachments']
|
||||
@ -609,8 +593,7 @@ class ServerTests(common.ComputeTestCase):
|
||||
# present on the command line. Now we should see the
|
||||
# attachment.
|
||||
cmd_output = self.openstack(
|
||||
'volume show ' +
|
||||
empty_volume_name,
|
||||
'volume show ' + empty_volume_name,
|
||||
parse_output=True,
|
||||
)
|
||||
attachments = cmd_output['attachments']
|
||||
@ -635,9 +618,7 @@ class ServerTests(common.ComputeTestCase):
|
||||
# create source empty volume
|
||||
volume_name = uuid.uuid4().hex
|
||||
cmd_output = self.openstack(
|
||||
'volume create ' +
|
||||
'--size 1 ' +
|
||||
volume_name,
|
||||
'volume create ' + '--size 1 ' + volume_name,
|
||||
parse_output=True,
|
||||
)
|
||||
volume_id = cmd_output["id"]
|
||||
@ -658,13 +639,19 @@ class ServerTests(common.ComputeTestCase):
|
||||
# create server
|
||||
server_name = uuid.uuid4().hex
|
||||
server = self.openstack(
|
||||
'server create ' +
|
||||
'--flavor ' + self.flavor_name + ' ' +
|
||||
'--image ' + self.image_name + ' ' +
|
||||
bdm_arg + ' ' +
|
||||
self.network_arg + ' ' +
|
||||
'--wait ' +
|
||||
server_name,
|
||||
'server create '
|
||||
+ '--flavor '
|
||||
+ self.flavor_name
|
||||
+ ' '
|
||||
+ '--image '
|
||||
+ self.image_name
|
||||
+ ' '
|
||||
+ bdm_arg
|
||||
+ ' '
|
||||
+ self.network_arg
|
||||
+ ' '
|
||||
+ '--wait '
|
||||
+ server_name,
|
||||
parse_output=True,
|
||||
)
|
||||
self.assertIsNotNone(server["id"])
|
||||
@ -677,8 +664,7 @@ class ServerTests(common.ComputeTestCase):
|
||||
# check server volumes_attached, format is
|
||||
# {"volumes_attached": "id='2518bc76-bf0b-476e-ad6b-571973745bb5'",}
|
||||
cmd_output = self.openstack(
|
||||
'server show ' +
|
||||
server_name,
|
||||
'server show ' + server_name,
|
||||
parse_output=True,
|
||||
)
|
||||
volumes_attached = cmd_output['volumes_attached']
|
||||
@ -686,8 +672,7 @@ class ServerTests(common.ComputeTestCase):
|
||||
|
||||
# check volumes
|
||||
cmd_output = self.openstack(
|
||||
'volume show ' +
|
||||
volume_name,
|
||||
'volume show ' + volume_name,
|
||||
parse_output=True,
|
||||
)
|
||||
attachments = cmd_output['attachments']
|
||||
@ -723,9 +708,7 @@ class ServerTests(common.ComputeTestCase):
|
||||
# create source empty volume
|
||||
empty_volume_name = uuid.uuid4().hex
|
||||
cmd_output = self.openstack(
|
||||
'volume create ' +
|
||||
'--size 1 ' +
|
||||
empty_volume_name,
|
||||
'volume create ' + '--size 1 ' + empty_volume_name,
|
||||
parse_output=True,
|
||||
)
|
||||
self.assertIsNotNone(cmd_output["id"])
|
||||
@ -736,9 +719,11 @@ class ServerTests(common.ComputeTestCase):
|
||||
# create snapshot of source empty volume
|
||||
empty_snapshot_name = uuid.uuid4().hex
|
||||
cmd_output = self.openstack(
|
||||
'volume snapshot create ' +
|
||||
'--volume ' + empty_volume_name + ' ' +
|
||||
empty_snapshot_name,
|
||||
'volume snapshot create '
|
||||
+ '--volume '
|
||||
+ empty_volume_name
|
||||
+ ' '
|
||||
+ empty_snapshot_name,
|
||||
parse_output=True,
|
||||
)
|
||||
empty_snapshot_id = cmd_output["id"]
|
||||
@ -746,10 +731,12 @@ class ServerTests(common.ComputeTestCase):
|
||||
# Deleting volume snapshot take time, so we need to wait until the
|
||||
# snapshot goes. Entries registered by self.addCleanup will be called
|
||||
# in the reverse order, so we need to register wait_for_delete first.
|
||||
self.addCleanup(volume_wait_for_delete,
|
||||
'volume snapshot', empty_snapshot_name)
|
||||
self.addCleanup(self.openstack,
|
||||
'volume snapshot delete ' + empty_snapshot_name)
|
||||
self.addCleanup(
|
||||
volume_wait_for_delete, 'volume snapshot', empty_snapshot_name
|
||||
)
|
||||
self.addCleanup(
|
||||
self.openstack, 'volume snapshot delete ' + empty_snapshot_name
|
||||
)
|
||||
self.assertEqual(
|
||||
empty_snapshot_name,
|
||||
cmd_output['name'],
|
||||
@ -772,13 +759,19 @@ class ServerTests(common.ComputeTestCase):
|
||||
# create server with bdm snapshot
|
||||
server_name = uuid.uuid4().hex
|
||||
server = self.openstack(
|
||||
'server create ' +
|
||||
'--flavor ' + self.flavor_name + ' ' +
|
||||
'--image ' + self.image_name + ' ' +
|
||||
bdm_arg + ' ' +
|
||||
self.network_arg + ' ' +
|
||||
'--wait ' +
|
||||
server_name,
|
||||
'server create '
|
||||
+ '--flavor '
|
||||
+ self.flavor_name
|
||||
+ ' '
|
||||
+ '--image '
|
||||
+ self.image_name
|
||||
+ ' '
|
||||
+ bdm_arg
|
||||
+ ' '
|
||||
+ self.network_arg
|
||||
+ ' '
|
||||
+ '--wait '
|
||||
+ server_name,
|
||||
parse_output=True,
|
||||
)
|
||||
self.assertIsNotNone(server["id"])
|
||||
@ -791,8 +784,7 @@ class ServerTests(common.ComputeTestCase):
|
||||
# check server volumes_attached, format is
|
||||
# {"volumes_attached": "id='2518bc76-bf0b-476e-ad6b-571973745bb5'",}
|
||||
cmd_output = self.openstack(
|
||||
'server show ' +
|
||||
server_name,
|
||||
'server show ' + server_name,
|
||||
parse_output=True,
|
||||
)
|
||||
volumes_attached = cmd_output['volumes_attached']
|
||||
@ -801,8 +793,7 @@ class ServerTests(common.ComputeTestCase):
|
||||
|
||||
# check the volume that attached on server
|
||||
cmd_output = self.openstack(
|
||||
'volume show ' +
|
||||
attached_volume_id,
|
||||
'volume show ' + attached_volume_id,
|
||||
parse_output=True,
|
||||
)
|
||||
attachments = cmd_output['attachments']
|
||||
@ -826,9 +817,11 @@ class ServerTests(common.ComputeTestCase):
|
||||
'volume list',
|
||||
parse_output=True,
|
||||
)
|
||||
target_volume = [each_volume
|
||||
for each_volume in cmd_output
|
||||
if each_volume['ID'] == attached_volume_id]
|
||||
target_volume = [
|
||||
each_volume
|
||||
for each_volume in cmd_output
|
||||
if each_volume['ID'] == attached_volume_id
|
||||
]
|
||||
if target_volume:
|
||||
# check the attached volume is 'deleting' status
|
||||
self.assertEqual('deleting', target_volume[0]['Status'])
|
||||
@ -865,8 +858,7 @@ class ServerTests(common.ComputeTestCase):
|
||||
else:
|
||||
# get image ID
|
||||
cmd_output = self.openstack(
|
||||
'image show ' +
|
||||
self.image_name,
|
||||
'image show ' + self.image_name,
|
||||
parse_output=True,
|
||||
)
|
||||
image_id = cmd_output['id']
|
||||
@ -889,13 +881,19 @@ class ServerTests(common.ComputeTestCase):
|
||||
# that volume to the server.
|
||||
server_name = uuid.uuid4().hex
|
||||
server = self.openstack(
|
||||
'server create ' +
|
||||
'--flavor ' + self.flavor_name + ' ' +
|
||||
'--image ' + self.image_name + ' ' +
|
||||
bdm_arg + ' ' +
|
||||
self.network_arg + ' ' +
|
||||
'--wait ' +
|
||||
server_name,
|
||||
'server create '
|
||||
+ '--flavor '
|
||||
+ self.flavor_name
|
||||
+ ' '
|
||||
+ '--image '
|
||||
+ self.image_name
|
||||
+ ' '
|
||||
+ bdm_arg
|
||||
+ ' '
|
||||
+ self.network_arg
|
||||
+ ' '
|
||||
+ '--wait '
|
||||
+ server_name,
|
||||
parse_output=True,
|
||||
)
|
||||
self.assertIsNotNone(server["id"])
|
||||
@ -908,8 +906,7 @@ class ServerTests(common.ComputeTestCase):
|
||||
# check server volumes_attached, format is
|
||||
# {"volumes_attached": "id='2518bc76-bf0b-476e-ad6b-571973745bb5'",}
|
||||
cmd_output = self.openstack(
|
||||
'server show ' +
|
||||
server_name,
|
||||
'server show ' + server_name,
|
||||
parse_output=True,
|
||||
)
|
||||
volumes_attached = cmd_output['volumes_attached']
|
||||
@ -918,8 +915,7 @@ class ServerTests(common.ComputeTestCase):
|
||||
|
||||
# check the volume that attached on server
|
||||
cmd_output = self.openstack(
|
||||
'volume show ' +
|
||||
attached_volume_id,
|
||||
'volume show ' + attached_volume_id,
|
||||
parse_output=True,
|
||||
)
|
||||
attachments = cmd_output['attachments']
|
||||
@ -950,9 +946,11 @@ class ServerTests(common.ComputeTestCase):
|
||||
'volume list',
|
||||
parse_output=True,
|
||||
)
|
||||
target_volume = [each_volume
|
||||
for each_volume in cmd_output
|
||||
if each_volume['ID'] == attached_volume_id]
|
||||
target_volume = [
|
||||
each_volume
|
||||
for each_volume in cmd_output
|
||||
if each_volume['ID'] == attached_volume_id
|
||||
]
|
||||
if target_volume:
|
||||
# check the attached volume is 'deleting' status
|
||||
self.assertEqual('deleting', target_volume[0]['Status'])
|
||||
@ -975,13 +973,18 @@ class ServerTests(common.ComputeTestCase):
|
||||
# and not delete the volume when the server is deleted.
|
||||
server_name = uuid.uuid4().hex
|
||||
server = self.openstack(
|
||||
'server create ' +
|
||||
'--flavor ' + self.flavor_name + ' ' +
|
||||
'--image ' + self.image_name + ' ' +
|
||||
'--boot-from-volume 1 ' + # create a 1GB volume from the image
|
||||
self.network_arg + ' ' +
|
||||
'--wait ' +
|
||||
server_name,
|
||||
'server create '
|
||||
+ '--flavor '
|
||||
+ self.flavor_name
|
||||
+ ' '
|
||||
+ '--image '
|
||||
+ self.image_name
|
||||
+ ' '
|
||||
+ '--boot-from-volume 1 '
|
||||
+ self.network_arg # create a 1GB volume from the image
|
||||
+ ' '
|
||||
+ '--wait '
|
||||
+ server_name,
|
||||
parse_output=True,
|
||||
)
|
||||
self.assertIsNotNone(server["id"])
|
||||
@ -994,8 +997,7 @@ class ServerTests(common.ComputeTestCase):
|
||||
# check server volumes_attached, format is
|
||||
# {"volumes_attached": "id='2518bc76-bf0b-476e-ad6b-571973745bb5'",}
|
||||
cmd_output = self.openstack(
|
||||
'server show ' +
|
||||
server_name,
|
||||
'server show ' + server_name,
|
||||
parse_output=True,
|
||||
)
|
||||
volumes_attached = cmd_output['volumes_attached']
|
||||
@ -1012,8 +1014,7 @@ class ServerTests(common.ComputeTestCase):
|
||||
|
||||
# check the volume that attached on server
|
||||
cmd_output = self.openstack(
|
||||
'volume show ' +
|
||||
volumes_attached[0]["id"],
|
||||
'volume show ' + volumes_attached[0]["id"],
|
||||
parse_output=True,
|
||||
)
|
||||
# The volume size should be what we specified on the command line.
|
||||
@ -1043,8 +1044,7 @@ class ServerTests(common.ComputeTestCase):
|
||||
# delete server, then check the attached volume was not deleted
|
||||
self.openstack('server delete --wait ' + server_name)
|
||||
cmd_output = self.openstack(
|
||||
'volume show ' +
|
||||
attached_volume_id,
|
||||
'volume show ' + attached_volume_id,
|
||||
parse_output=True,
|
||||
)
|
||||
# check the volume is in 'available' status
|
||||
@ -1055,12 +1055,16 @@ class ServerTests(common.ComputeTestCase):
|
||||
server_name = uuid.uuid4().hex
|
||||
server = self.openstack(
|
||||
# auto/none enable in nova micro version (v2.37+)
|
||||
'--os-compute-api-version 2.37 ' +
|
||||
'server create ' +
|
||||
'--flavor ' + self.flavor_name + ' ' +
|
||||
'--image ' + self.image_name + ' ' +
|
||||
'--nic none ' +
|
||||
server_name,
|
||||
'--os-compute-api-version 2.37 '
|
||||
+ 'server create '
|
||||
+ '--flavor '
|
||||
+ self.flavor_name
|
||||
+ ' '
|
||||
+ '--image '
|
||||
+ self.image_name
|
||||
+ ' '
|
||||
+ '--nic none '
|
||||
+ server_name,
|
||||
parse_output=True,
|
||||
)
|
||||
self.assertIsNotNone(server["id"])
|
||||
@ -1099,14 +1103,24 @@ class ServerTests(common.ComputeTestCase):
|
||||
|
||||
server_name = uuid.uuid4().hex
|
||||
server = self.openstack(
|
||||
'server create ' +
|
||||
'--flavor ' + self.flavor_name + ' ' +
|
||||
'--image ' + self.image_name + ' ' +
|
||||
'server create '
|
||||
+ '--flavor '
|
||||
+ self.flavor_name
|
||||
+ ' '
|
||||
+ '--image '
|
||||
+ self.image_name
|
||||
+ ' '
|
||||
+
|
||||
# Security group id is integer in nova-network, convert to string
|
||||
'--security-group ' + str(security_group1['id']) + ' ' +
|
||||
'--security-group ' + security_group2['name'] + ' ' +
|
||||
self.network_arg + ' ' +
|
||||
server_name,
|
||||
'--security-group '
|
||||
+ str(security_group1['id'])
|
||||
+ ' '
|
||||
+ '--security-group '
|
||||
+ security_group2['name']
|
||||
+ ' '
|
||||
+ self.network_arg
|
||||
+ ' '
|
||||
+ server_name,
|
||||
parse_output=True,
|
||||
)
|
||||
self.addCleanup(self.openstack, 'server delete --wait ' + server_name)
|
||||
@ -1136,29 +1150,38 @@ class ServerTests(common.ComputeTestCase):
|
||||
try:
|
||||
self.openstack(
|
||||
# auto/none enable in nova micro version (v2.37+)
|
||||
'--os-compute-api-version 2.37 ' +
|
||||
'server create ' +
|
||||
'--flavor ' + self.flavor_name + ' ' +
|
||||
'--image ' + self.image_name + ' ' +
|
||||
server_name
|
||||
'--os-compute-api-version 2.37 '
|
||||
+ 'server create '
|
||||
+ '--flavor '
|
||||
+ self.flavor_name
|
||||
+ ' '
|
||||
+ '--image '
|
||||
+ self.image_name
|
||||
+ ' '
|
||||
+ server_name
|
||||
)
|
||||
except exceptions.CommandFailed as e:
|
||||
# If we got here, it shouldn't be because a nics value wasn't
|
||||
# provided to the server; it is likely due to something else in
|
||||
# the functional tests like there being multiple available
|
||||
# networks and the test didn't specify a specific network.
|
||||
self.assertNotIn('nics are required after microversion 2.36',
|
||||
e.stderr)
|
||||
self.assertNotIn(
|
||||
'nics are required after microversion 2.36', e.stderr
|
||||
)
|
||||
|
||||
def test_server_add_remove_network(self):
|
||||
name = uuid.uuid4().hex
|
||||
cmd_output = self.openstack(
|
||||
'server create ' +
|
||||
'--network private ' +
|
||||
'--flavor ' + self.flavor_name + ' ' +
|
||||
'--image ' + self.image_name + ' ' +
|
||||
'--wait ' +
|
||||
name,
|
||||
'server create '
|
||||
+ '--network private '
|
||||
+ '--flavor '
|
||||
+ self.flavor_name
|
||||
+ ' '
|
||||
+ '--image '
|
||||
+ self.image_name
|
||||
+ ' '
|
||||
+ '--wait '
|
||||
+ name,
|
||||
parse_output=True,
|
||||
)
|
||||
|
||||
@ -1167,8 +1190,7 @@ class ServerTests(common.ComputeTestCase):
|
||||
self.addCleanup(self.openstack, 'server delete --wait ' + name)
|
||||
|
||||
# add network and check 'public' is in server show
|
||||
self.openstack(
|
||||
'server add network ' + name + ' public')
|
||||
self.openstack('server add network ' + name + ' public')
|
||||
|
||||
wait_time = 0
|
||||
while wait_time < 60:
|
||||
@ -1209,12 +1231,16 @@ class ServerTests(common.ComputeTestCase):
|
||||
def test_server_add_remove_port(self):
|
||||
name = uuid.uuid4().hex
|
||||
cmd_output = self.openstack(
|
||||
'server create ' +
|
||||
'--network private ' +
|
||||
'--flavor ' + self.flavor_name + ' ' +
|
||||
'--image ' + self.image_name + ' ' +
|
||||
'--wait ' +
|
||||
name,
|
||||
'server create '
|
||||
+ '--network private '
|
||||
+ '--flavor '
|
||||
+ self.flavor_name
|
||||
+ ' '
|
||||
+ '--image '
|
||||
+ self.image_name
|
||||
+ ' '
|
||||
+ '--wait '
|
||||
+ name,
|
||||
parse_output=True,
|
||||
)
|
||||
|
||||
@ -1232,8 +1258,7 @@ class ServerTests(common.ComputeTestCase):
|
||||
self.assertNotIn(port_name, cmd_output)
|
||||
|
||||
cmd_output = self.openstack(
|
||||
'port create ' +
|
||||
'--network private ' + port_name,
|
||||
'port create ' + '--network private ' + port_name,
|
||||
parse_output=True,
|
||||
)
|
||||
self.assertIsNotNone(cmd_output['id'])
|
||||
@ -1281,12 +1306,16 @@ class ServerTests(common.ComputeTestCase):
|
||||
def test_server_add_fixed_ip(self):
|
||||
name = uuid.uuid4().hex
|
||||
cmd_output = self.openstack(
|
||||
'server create ' +
|
||||
'--network private ' +
|
||||
'--flavor ' + self.flavor_name + ' ' +
|
||||
'--image ' + self.image_name + ' ' +
|
||||
'--wait ' +
|
||||
name,
|
||||
'server create '
|
||||
+ '--network private '
|
||||
+ '--flavor '
|
||||
+ self.flavor_name
|
||||
+ ' '
|
||||
+ '--image '
|
||||
+ self.image_name
|
||||
+ ' '
|
||||
+ '--wait '
|
||||
+ name,
|
||||
parse_output=True,
|
||||
)
|
||||
|
||||
@ -1306,8 +1335,7 @@ class ServerTests(common.ComputeTestCase):
|
||||
self.assertNotIn(port_name, cmd_output)
|
||||
|
||||
cmd_output = self.openstack(
|
||||
'port create ' +
|
||||
'--network private ' + port_name,
|
||||
'port create ' + '--network private ' + port_name,
|
||||
parse_output=True,
|
||||
)
|
||||
self.assertIsNotNone(cmd_output['id'])
|
||||
@ -1315,8 +1343,13 @@ class ServerTests(common.ComputeTestCase):
|
||||
self.openstack('port delete ' + port_name)
|
||||
|
||||
# add fixed ip to server, assert the ip address appears
|
||||
self.openstack('server add fixed ip --fixed-ip-address ' + ip_address +
|
||||
' ' + name + ' private')
|
||||
self.openstack(
|
||||
'server add fixed ip --fixed-ip-address '
|
||||
+ ip_address
|
||||
+ ' '
|
||||
+ name
|
||||
+ ' private'
|
||||
)
|
||||
|
||||
wait_time = 0
|
||||
while wait_time < 60:
|
||||
@ -1339,12 +1372,16 @@ class ServerTests(common.ComputeTestCase):
|
||||
|
||||
server_name = uuid.uuid4().hex
|
||||
cmd_output = self.openstack(
|
||||
'server create ' +
|
||||
'--network private ' +
|
||||
'--flavor ' + self.flavor_name + ' ' +
|
||||
'--image ' + self.image_name + ' ' +
|
||||
'--wait ' +
|
||||
server_name,
|
||||
'server create '
|
||||
+ '--network private '
|
||||
+ '--flavor '
|
||||
+ self.flavor_name
|
||||
+ ' '
|
||||
+ '--image '
|
||||
+ self.image_name
|
||||
+ ' '
|
||||
+ '--wait '
|
||||
+ server_name,
|
||||
parse_output=True,
|
||||
)
|
||||
|
||||
@ -1355,9 +1392,7 @@ class ServerTests(common.ComputeTestCase):
|
||||
|
||||
volume_name = uuid.uuid4().hex
|
||||
cmd_output = self.openstack(
|
||||
'volume create ' +
|
||||
'--size 1 ' +
|
||||
volume_name,
|
||||
'volume create ' + '--size 1 ' + volume_name,
|
||||
parse_output=True,
|
||||
)
|
||||
|
||||
@ -1368,10 +1403,12 @@ class ServerTests(common.ComputeTestCase):
|
||||
volume_id = cmd_output['id']
|
||||
|
||||
cmd_output = self.openstack(
|
||||
'server add volume ' +
|
||||
server_name + ' ' +
|
||||
volume_name + ' ' +
|
||||
'--tag bar',
|
||||
'server add volume '
|
||||
+ server_name
|
||||
+ ' '
|
||||
+ volume_name
|
||||
+ ' '
|
||||
+ '--tag bar',
|
||||
parse_output=True,
|
||||
)
|
||||
|
||||
@ -1379,8 +1416,7 @@ class ServerTests(common.ComputeTestCase):
|
||||
self.assertEqual(volume_id, cmd_output['Volume ID'])
|
||||
|
||||
cmd_output = self.openstack(
|
||||
'server volume list ' +
|
||||
server_name,
|
||||
'server volume list ' + server_name,
|
||||
parse_output=True,
|
||||
)
|
||||
|
||||
@ -1390,8 +1426,7 @@ class ServerTests(common.ComputeTestCase):
|
||||
volume_wait_for('volume', volume_name, 'in-use')
|
||||
|
||||
cmd_output = self.openstack(
|
||||
'server event list ' +
|
||||
server_name,
|
||||
'server event list ' + server_name,
|
||||
parse_output=True,
|
||||
)
|
||||
self.assertEqual(2, len(cmd_output))
|
||||
@ -1403,8 +1438,7 @@ class ServerTests(common.ComputeTestCase):
|
||||
volume_wait_for('volume', volume_name, 'available')
|
||||
|
||||
cmd_output = self.openstack(
|
||||
'server event list ' +
|
||||
server_name,
|
||||
'server event list ' + server_name,
|
||||
parse_output=True,
|
||||
)
|
||||
self.assertEqual(3, len(cmd_output))
|
||||
|
@ -93,8 +93,7 @@ class ServerEventTests(common.ComputeTestCase):
|
||||
# And verify we can get the event list after it's deleted
|
||||
# Test 'server event list' for deleting
|
||||
cmd_output = self.openstack(
|
||||
'--os-compute-api-version 2.21 '
|
||||
'server event list ' + server_id,
|
||||
'--os-compute-api-version 2.21 ' 'server event list ' + server_id,
|
||||
parse_output=True,
|
||||
)
|
||||
request_id = None
|
||||
|
@ -23,37 +23,22 @@ class ServerGroupTests(base.TestCase):
|
||||
name1 = uuid.uuid4().hex
|
||||
name2 = uuid.uuid4().hex
|
||||
cmd_output = self.openstack(
|
||||
'server group create ' +
|
||||
'--policy affinity ' +
|
||||
name1,
|
||||
'server group create ' + '--policy affinity ' + name1,
|
||||
parse_output=True,
|
||||
)
|
||||
self.assertEqual(
|
||||
name1,
|
||||
cmd_output['name']
|
||||
)
|
||||
self.assertEqual(
|
||||
'affinity',
|
||||
cmd_output['policy']
|
||||
)
|
||||
self.assertEqual(name1, cmd_output['name'])
|
||||
self.assertEqual('affinity', cmd_output['policy'])
|
||||
|
||||
cmd_output = self.openstack(
|
||||
'server group create ' +
|
||||
'--policy anti-affinity ' +
|
||||
name2,
|
||||
'server group create ' + '--policy anti-affinity ' + name2,
|
||||
parse_output=True,
|
||||
)
|
||||
self.assertEqual(
|
||||
name2,
|
||||
cmd_output['name']
|
||||
)
|
||||
self.assertEqual(
|
||||
'anti-affinity',
|
||||
cmd_output['policy']
|
||||
)
|
||||
self.assertEqual(name2, cmd_output['name'])
|
||||
self.assertEqual('anti-affinity', cmd_output['policy'])
|
||||
|
||||
del_output = self.openstack(
|
||||
'server group delete ' + name1 + ' ' + name2)
|
||||
'server group delete ' + name1 + ' ' + name2
|
||||
)
|
||||
self.assertOutput('', del_output)
|
||||
|
||||
def test_server_group_show_and_list(self):
|
||||
@ -63,9 +48,7 @@ class ServerGroupTests(base.TestCase):
|
||||
|
||||
# test server group show
|
||||
cmd_output = self.openstack(
|
||||
'server group create ' +
|
||||
'--policy affinity ' +
|
||||
name1,
|
||||
'server group create ' + '--policy affinity ' + name1,
|
||||
parse_output=True,
|
||||
)
|
||||
self.addCleanup(self.openstack, 'server group delete ' + name1)
|
||||
@ -73,19 +56,11 @@ class ServerGroupTests(base.TestCase):
|
||||
'server group show ' + name1,
|
||||
parse_output=True,
|
||||
)
|
||||
self.assertEqual(
|
||||
name1,
|
||||
cmd_output['name']
|
||||
)
|
||||
self.assertEqual(
|
||||
'affinity',
|
||||
cmd_output['policy']
|
||||
)
|
||||
self.assertEqual(name1, cmd_output['name'])
|
||||
self.assertEqual('affinity', cmd_output['policy'])
|
||||
|
||||
cmd_output = self.openstack(
|
||||
'server group create ' +
|
||||
'--policy anti-affinity ' +
|
||||
name2,
|
||||
'server group create ' + '--policy anti-affinity ' + name2,
|
||||
parse_output=True,
|
||||
)
|
||||
self.addCleanup(self.openstack, 'server group delete ' + name2)
|
||||
@ -93,14 +68,8 @@ class ServerGroupTests(base.TestCase):
|
||||
'server group show ' + name2,
|
||||
parse_output=True,
|
||||
)
|
||||
self.assertEqual(
|
||||
name2,
|
||||
cmd_output['name']
|
||||
)
|
||||
self.assertEqual(
|
||||
'anti-affinity',
|
||||
cmd_output['policy']
|
||||
)
|
||||
self.assertEqual(name2, cmd_output['name'])
|
||||
self.assertEqual('anti-affinity', cmd_output['policy'])
|
||||
|
||||
# test server group list
|
||||
cmd_output = self.openstack(
|
||||
|
@ -68,7 +68,7 @@ QUOTA = {
|
||||
'secgroup_rules': secgroup_rule_num,
|
||||
'secgroups': secgroup_num,
|
||||
'server-groups': servgroup_num,
|
||||
'server-group-members': servgroup_members_num
|
||||
'server-group-members': servgroup_members_num,
|
||||
}
|
||||
|
||||
QUOTA_columns = tuple(sorted(QUOTA))
|
||||
@ -98,15 +98,15 @@ class FakeAggregate(object):
|
||||
"metadata": {
|
||||
"availability_zone": "ag_zone",
|
||||
"key1": "value1",
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
# Overwrite default attributes.
|
||||
aggregate_info.update(attrs)
|
||||
|
||||
aggregate = fakes.FakeResource(
|
||||
info=copy.deepcopy(aggregate_info),
|
||||
loaded=True)
|
||||
info=copy.deepcopy(aggregate_info), loaded=True
|
||||
)
|
||||
return aggregate
|
||||
|
||||
@staticmethod
|
||||
@ -147,7 +147,6 @@ class FakeAggregate(object):
|
||||
|
||||
|
||||
class FakeComputev2Client(object):
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
self.agents = mock.Mock()
|
||||
self.agents.resource_class = fakes.FakeResource(None, {})
|
||||
@ -222,7 +221,6 @@ class FakeComputev2Client(object):
|
||||
|
||||
|
||||
class TestComputev2(utils.TestCommand):
|
||||
|
||||
def setUp(self):
|
||||
super(TestComputev2, self).setUp()
|
||||
|
||||
@ -286,8 +284,7 @@ class FakeAgent(object):
|
||||
# Overwrite default attributes.
|
||||
agent_info.update(attrs)
|
||||
|
||||
agent = fakes.FakeResource(info=copy.deepcopy(agent_info),
|
||||
loaded=True)
|
||||
agent = fakes.FakeResource(info=copy.deepcopy(agent_info), loaded=True)
|
||||
return agent
|
||||
|
||||
@staticmethod
|
||||
@ -326,21 +323,24 @@ class FakeExtension(object):
|
||||
extension_info = {
|
||||
'name': 'name-' + uuid.uuid4().hex,
|
||||
'namespace': (
|
||||
'http://docs.openstack.org/compute/ext/multinic/api/v1.1'),
|
||||
'http://docs.openstack.org/compute/ext/multinic/api/v1.1'
|
||||
),
|
||||
'description': 'description-' + uuid.uuid4().hex,
|
||||
'updated': '2014-01-07T12:00:0-00:00',
|
||||
'alias': 'NMN',
|
||||
'links': ('[{"href":'
|
||||
'"https://github.com/openstack/compute-api", "type":'
|
||||
' "text/html", "rel": "describedby"}]')
|
||||
'links': (
|
||||
'[{"href":'
|
||||
'"https://github.com/openstack/compute-api", "type":'
|
||||
' "text/html", "rel": "describedby"}]'
|
||||
),
|
||||
}
|
||||
|
||||
# Overwrite default attributes.
|
||||
extension_info.update(attrs)
|
||||
|
||||
extension = fakes.FakeResource(
|
||||
info=copy.deepcopy(extension_info),
|
||||
loaded=True)
|
||||
info=copy.deepcopy(extension_info), loaded=True
|
||||
)
|
||||
return extension
|
||||
|
||||
|
||||
@ -385,7 +385,8 @@ class FakeSecurityGroup(object):
|
||||
security_groups = []
|
||||
for i in range(0, count):
|
||||
security_groups.append(
|
||||
FakeSecurityGroup.create_one_security_group(attrs))
|
||||
FakeSecurityGroup.create_one_security_group(attrs)
|
||||
)
|
||||
|
||||
return security_groups
|
||||
|
||||
@ -453,7 +454,8 @@ class FakeSecurityGroupRule(object):
|
||||
security_group_rules = []
|
||||
for i in range(0, count):
|
||||
security_group_rules.append(
|
||||
FakeSecurityGroupRule.create_one_security_group_rule(attrs))
|
||||
FakeSecurityGroupRule.create_one_security_group_rule(attrs)
|
||||
)
|
||||
|
||||
return security_group_rules
|
||||
|
||||
@ -492,9 +494,9 @@ class FakeServer(object):
|
||||
# Overwrite default attributes.
|
||||
server_info.update(attrs)
|
||||
|
||||
server = fakes.FakeResource(info=copy.deepcopy(server_info),
|
||||
methods=methods,
|
||||
loaded=True)
|
||||
server = fakes.FakeResource(
|
||||
info=copy.deepcopy(server_info), methods=methods, loaded=True
|
||||
)
|
||||
return server
|
||||
|
||||
@staticmethod
|
||||
@ -611,13 +613,15 @@ def create_one_server_action(attrs=None):
|
||||
"action": "create",
|
||||
"message": None,
|
||||
"project_id": "project-id-" + uuid.uuid4().hex,
|
||||
"events": [{
|
||||
"finish_time": "2017-02-27T07:47:25.000000",
|
||||
"start_time": "2017-02-27T07:47:15.000000",
|
||||
"traceback": None,
|
||||
"event": "compute__do_build_and_run_instance",
|
||||
"result": "Success"
|
||||
}]
|
||||
"events": [
|
||||
{
|
||||
"finish_time": "2017-02-27T07:47:25.000000",
|
||||
"start_time": "2017-02-27T07:47:15.000000",
|
||||
"traceback": None,
|
||||
"event": "compute__do_build_and_run_instance",
|
||||
"result": "Success",
|
||||
}
|
||||
],
|
||||
}
|
||||
# Overwrite default attributes
|
||||
server_action_info.update(attrs)
|
||||
@ -784,7 +788,8 @@ class FakeFlavorAccess(object):
|
||||
flavor_access_info.update(attrs)
|
||||
|
||||
flavor_access = fakes.FakeResource(
|
||||
info=copy.deepcopy(flavor_access_info), loaded=True)
|
||||
info=copy.deepcopy(flavor_access_info), loaded=True
|
||||
)
|
||||
|
||||
return flavor_access
|
||||
|
||||
@ -809,14 +814,15 @@ class FakeKeypair(object):
|
||||
'type': 'ssh',
|
||||
'fingerprint': 'dummy',
|
||||
'public_key': 'dummy',
|
||||
'user_id': 'user'
|
||||
'user_id': 'user',
|
||||
}
|
||||
|
||||
# Overwrite default attributes.
|
||||
keypair_info.update(attrs)
|
||||
|
||||
keypair = fakes.FakeResource(info=copy.deepcopy(keypair_info),
|
||||
loaded=True)
|
||||
keypair = fakes.FakeResource(
|
||||
info=copy.deepcopy(keypair_info), loaded=True
|
||||
)
|
||||
|
||||
return keypair
|
||||
|
||||
@ -879,19 +885,23 @@ class FakeAvailabilityZone(object):
|
||||
availability_zone = {
|
||||
'zoneName': uuid.uuid4().hex,
|
||||
'zoneState': {'available': True},
|
||||
'hosts': {host_name: {service_name: {
|
||||
'available': True,
|
||||
'active': True,
|
||||
'updated_at': service_updated_at,
|
||||
}}},
|
||||
'hosts': {
|
||||
host_name: {
|
||||
service_name: {
|
||||
'available': True,
|
||||
'active': True,
|
||||
'updated_at': service_updated_at,
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
# Overwrite default attributes.
|
||||
availability_zone.update(attrs)
|
||||
|
||||
availability_zone = fakes.FakeResource(
|
||||
info=copy.deepcopy(availability_zone),
|
||||
loaded=True)
|
||||
info=copy.deepcopy(availability_zone), loaded=True
|
||||
)
|
||||
return availability_zone
|
||||
|
||||
@staticmethod
|
||||
@ -907,8 +917,9 @@ class FakeAvailabilityZone(object):
|
||||
"""
|
||||
availability_zones = []
|
||||
for i in range(0, count):
|
||||
availability_zone = \
|
||||
availability_zone = (
|
||||
FakeAvailabilityZone.create_one_availability_zone(attrs)
|
||||
)
|
||||
availability_zones.append(availability_zone)
|
||||
|
||||
return availability_zones
|
||||
@ -1200,16 +1211,15 @@ class FakeUsage(object):
|
||||
'instance_id': uuid.uuid4().hex,
|
||||
'state': 'active',
|
||||
'uptime': 3600,
|
||||
'vcpus': 1
|
||||
'vcpus': 1,
|
||||
}
|
||||
]
|
||||
],
|
||||
}
|
||||
|
||||
# Overwrite default attributes.
|
||||
usage_info.update(attrs)
|
||||
|
||||
usage = fakes.FakeResource(info=copy.deepcopy(usage_info),
|
||||
loaded=True)
|
||||
usage = fakes.FakeResource(info=copy.deepcopy(usage_info), loaded=True)
|
||||
|
||||
return usage
|
||||
|
||||
@ -1252,13 +1262,13 @@ class FakeQuota(object):
|
||||
'metadata_items': 10,
|
||||
'ram': 51200,
|
||||
'server_groups': 10,
|
||||
'server_group_members': 10
|
||||
'server_group_members': 10,
|
||||
}
|
||||
|
||||
quota_attrs.update(attrs)
|
||||
quota = fakes.FakeResource(
|
||||
info=copy.deepcopy(quota_attrs),
|
||||
loaded=True)
|
||||
info=copy.deepcopy(quota_attrs), loaded=True
|
||||
)
|
||||
|
||||
quota.project_id = quota_attrs['id']
|
||||
|
||||
@ -1282,13 +1292,13 @@ class FakeQuota(object):
|
||||
'metadata_items': 10,
|
||||
'ram': 51200,
|
||||
'server_groups': 10,
|
||||
'server_group_members': 10
|
||||
'server_group_members': 10,
|
||||
}
|
||||
|
||||
quota_attrs.update(attrs)
|
||||
quota = fakes.FakeResource(
|
||||
info=copy.deepcopy(quota_attrs),
|
||||
loaded=True)
|
||||
info=copy.deepcopy(quota_attrs), loaded=True
|
||||
)
|
||||
|
||||
quota.project_id = quota_attrs['id']
|
||||
|
||||
@ -1306,21 +1316,27 @@ class FakeQuota(object):
|
||||
'fixed_ips': {'reserved': 0, 'in_use': 0, 'limit': 30},
|
||||
'injected_files': {'reserved': 0, 'in_use': 0, 'limit': 100},
|
||||
'injected_file_content_bytes': {
|
||||
'reserved': 0, 'in_use': 0, 'limit': 10240},
|
||||
'reserved': 0,
|
||||
'in_use': 0,
|
||||
'limit': 10240,
|
||||
},
|
||||
'injected_file_path_bytes': {
|
||||
'reserved': 0, 'in_use': 0, 'limit': 255},
|
||||
'reserved': 0,
|
||||
'in_use': 0,
|
||||
'limit': 255,
|
||||
},
|
||||
'instances': {'reserved': 0, 'in_use': 0, 'limit': 50},
|
||||
'key_pairs': {'reserved': 0, 'in_use': 0, 'limit': 20},
|
||||
'metadata_items': {'reserved': 0, 'in_use': 0, 'limit': 10},
|
||||
'ram': {'reserved': 0, 'in_use': 0, 'limit': 51200},
|
||||
'server_groups': {'reserved': 0, 'in_use': 0, 'limit': 10},
|
||||
'server_group_members': {'reserved': 0, 'in_use': 0, 'limit': 10}
|
||||
'server_group_members': {'reserved': 0, 'in_use': 0, 'limit': 10},
|
||||
}
|
||||
|
||||
quota_attrs.update(attrs)
|
||||
quota = fakes.FakeResource(
|
||||
info=copy.deepcopy(quota_attrs),
|
||||
loaded=True)
|
||||
info=copy.deepcopy(quota_attrs), loaded=True
|
||||
)
|
||||
|
||||
quota.project_id = quota_attrs['id']
|
||||
|
||||
@ -1355,41 +1371,43 @@ class FakeLimits(object):
|
||||
absolute_attrs = absolute_attrs or {}
|
||||
self.absolute_limits_attrs.update(absolute_attrs)
|
||||
|
||||
self.rate_limits_attrs = [{
|
||||
"uri": "*",
|
||||
"limit": [
|
||||
{
|
||||
"value": 10,
|
||||
"verb": "POST",
|
||||
"remaining": 2,
|
||||
"unit": "MINUTE",
|
||||
"next-available": "2011-12-15T22:42:45Z"
|
||||
},
|
||||
{
|
||||
"value": 10,
|
||||
"verb": "PUT",
|
||||
"remaining": 2,
|
||||
"unit": "MINUTE",
|
||||
"next-available": "2011-12-15T22:42:45Z"
|
||||
},
|
||||
{
|
||||
"value": 100,
|
||||
"verb": "DELETE",
|
||||
"remaining": 100,
|
||||
"unit": "MINUTE",
|
||||
"next-available": "2011-12-15T22:42:45Z"
|
||||
}
|
||||
]
|
||||
}]
|
||||
self.rate_limits_attrs = [
|
||||
{
|
||||
"uri": "*",
|
||||
"limit": [
|
||||
{
|
||||
"value": 10,
|
||||
"verb": "POST",
|
||||
"remaining": 2,
|
||||
"unit": "MINUTE",
|
||||
"next-available": "2011-12-15T22:42:45Z",
|
||||
},
|
||||
{
|
||||
"value": 10,
|
||||
"verb": "PUT",
|
||||
"remaining": 2,
|
||||
"unit": "MINUTE",
|
||||
"next-available": "2011-12-15T22:42:45Z",
|
||||
},
|
||||
{
|
||||
"value": 100,
|
||||
"verb": "DELETE",
|
||||
"remaining": 100,
|
||||
"unit": "MINUTE",
|
||||
"next-available": "2011-12-15T22:42:45Z",
|
||||
},
|
||||
],
|
||||
}
|
||||
]
|
||||
|
||||
@property
|
||||
def absolute(self):
|
||||
for (name, value) in self.absolute_limits_attrs.items():
|
||||
for name, value in self.absolute_limits_attrs.items():
|
||||
yield FakeAbsoluteLimit(name, value)
|
||||
|
||||
def absolute_limits(self):
|
||||
reference_data = []
|
||||
for (name, value) in self.absolute_limits_attrs.items():
|
||||
for name, value in self.absolute_limits_attrs.items():
|
||||
reference_data.append((name, value))
|
||||
return reference_data
|
||||
|
||||
@ -1398,18 +1416,30 @@ class FakeLimits(object):
|
||||
for group in self.rate_limits_attrs:
|
||||
uri = group['uri']
|
||||
for rate in group['limit']:
|
||||
yield FakeRateLimit(rate['verb'], uri, rate['value'],
|
||||
rate['remaining'], rate['unit'],
|
||||
rate['next-available'])
|
||||
yield FakeRateLimit(
|
||||
rate['verb'],
|
||||
uri,
|
||||
rate['value'],
|
||||
rate['remaining'],
|
||||
rate['unit'],
|
||||
rate['next-available'],
|
||||
)
|
||||
|
||||
def rate_limits(self):
|
||||
reference_data = []
|
||||
for group in self.rate_limits_attrs:
|
||||
uri = group['uri']
|
||||
for rate in group['limit']:
|
||||
reference_data.append((rate['verb'], uri, rate['value'],
|
||||
rate['remaining'], rate['unit'],
|
||||
rate['next-available']))
|
||||
reference_data.append(
|
||||
(
|
||||
rate['verb'],
|
||||
uri,
|
||||
rate['value'],
|
||||
rate['remaining'],
|
||||
rate['unit'],
|
||||
rate['next-available'],
|
||||
)
|
||||
)
|
||||
return reference_data
|
||||
|
||||
|
||||
@ -1424,8 +1454,7 @@ class FakeAbsoluteLimit(object):
|
||||
class FakeRateLimit(object):
|
||||
"""Data model that represents a flattened view of a single rate limit"""
|
||||
|
||||
def __init__(self, verb, uri, value, remain,
|
||||
unit, next_available):
|
||||
def __init__(self, verb, uri, value, remain, unit, next_available):
|
||||
self.verb = verb
|
||||
self.uri = uri
|
||||
self.value = value
|
||||
@ -1534,8 +1563,7 @@ def create_server_migrations(attrs=None, methods=None, count=2):
|
||||
"""
|
||||
migrations = []
|
||||
for i in range(0, count):
|
||||
migrations.append(
|
||||
create_one_server_migration(attrs, methods))
|
||||
migrations.append(create_one_server_migration(attrs, methods))
|
||||
|
||||
return migrations
|
||||
|
||||
|
@ -24,7 +24,6 @@ from openstackclient.tests.unit import utils as tests_utils
|
||||
|
||||
|
||||
class TestAgent(compute_fakes.TestComputev2):
|
||||
|
||||
attr = {}
|
||||
attr['agent_id'] = 1
|
||||
fake_agent = compute_fakes.FakeAgent.create_one_agent(attr)
|
||||
@ -57,7 +56,6 @@ class TestAgent(compute_fakes.TestComputev2):
|
||||
|
||||
|
||||
class TestAgentCreate(TestAgent):
|
||||
|
||||
def setUp(self):
|
||||
super(TestAgentCreate, self).setUp()
|
||||
|
||||
@ -84,19 +82,20 @@ class TestAgentCreate(TestAgent):
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
self.agents_mock.create.assert_called_with(parsed_args.os,
|
||||
parsed_args.architecture,
|
||||
parsed_args.version,
|
||||
parsed_args.url,
|
||||
parsed_args.md5hash,
|
||||
parsed_args.hypervisor)
|
||||
self.agents_mock.create.assert_called_with(
|
||||
parsed_args.os,
|
||||
parsed_args.architecture,
|
||||
parsed_args.version,
|
||||
parsed_args.url,
|
||||
parsed_args.md5hash,
|
||||
parsed_args.hypervisor,
|
||||
)
|
||||
|
||||
self.assertEqual(self.columns, columns)
|
||||
self.assertEqual(self.data, data)
|
||||
|
||||
|
||||
class TestAgentDelete(TestAgent):
|
||||
|
||||
fake_agents = compute_fakes.FakeAgent.create_agents(count=2)
|
||||
|
||||
def setUp(self):
|
||||
@ -106,9 +105,7 @@ class TestAgentDelete(TestAgent):
|
||||
self.cmd = agent.DeleteAgent(self.app, None)
|
||||
|
||||
def test_delete_one_agent(self):
|
||||
arglist = [
|
||||
self.fake_agents[0].agent_id
|
||||
]
|
||||
arglist = [self.fake_agents[0].agent_id]
|
||||
|
||||
verifylist = [
|
||||
('id', [self.fake_agents[0].agent_id]),
|
||||
@ -117,7 +114,8 @@ class TestAgentDelete(TestAgent):
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
result = self.cmd.take_action(parsed_args)
|
||||
self.agents_mock.delete.assert_called_with(
|
||||
self.fake_agents[0].agent_id)
|
||||
self.fake_agents[0].agent_id
|
||||
)
|
||||
self.assertIsNone(result)
|
||||
|
||||
def test_delete_multiple_agents(self):
|
||||
@ -149,15 +147,12 @@ class TestAgentDelete(TestAgent):
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
ret_delete = [
|
||||
None,
|
||||
None,
|
||||
exceptions.NotFound('404')
|
||||
]
|
||||
ret_delete = [None, None, exceptions.NotFound('404')]
|
||||
self.agents_mock.delete = mock.Mock(side_effect=ret_delete)
|
||||
|
||||
self.assertRaises(exceptions.CommandError, self.cmd.take_action,
|
||||
parsed_args)
|
||||
self.assertRaises(
|
||||
exceptions.CommandError, self.cmd.take_action, parsed_args
|
||||
)
|
||||
calls = [
|
||||
call(self.fake_agents[0].agent_id),
|
||||
call(self.fake_agents[1].agent_id),
|
||||
@ -167,15 +162,16 @@ class TestAgentDelete(TestAgent):
|
||||
def test_agent_delete_no_input(self):
|
||||
arglist = []
|
||||
verifylist = None
|
||||
self.assertRaises(tests_utils.ParserException,
|
||||
self.check_parser,
|
||||
self.cmd,
|
||||
arglist,
|
||||
verifylist)
|
||||
self.assertRaises(
|
||||
tests_utils.ParserException,
|
||||
self.check_parser,
|
||||
self.cmd,
|
||||
arglist,
|
||||
verifylist,
|
||||
)
|
||||
|
||||
|
||||
class TestAgentList(TestAgent):
|
||||
|
||||
agents = compute_fakes.FakeAgent.create_agents(count=3)
|
||||
list_columns = (
|
||||
"Agent ID",
|
||||
@ -189,25 +185,25 @@ class TestAgentList(TestAgent):
|
||||
|
||||
list_data = []
|
||||
for _agent in agents:
|
||||
list_data.append((
|
||||
_agent.agent_id,
|
||||
_agent.hypervisor,
|
||||
_agent.os,
|
||||
_agent.architecture,
|
||||
_agent.version,
|
||||
_agent.md5hash,
|
||||
_agent.url,
|
||||
))
|
||||
list_data.append(
|
||||
(
|
||||
_agent.agent_id,
|
||||
_agent.hypervisor,
|
||||
_agent.os,
|
||||
_agent.architecture,
|
||||
_agent.version,
|
||||
_agent.md5hash,
|
||||
_agent.url,
|
||||
)
|
||||
)
|
||||
|
||||
def setUp(self):
|
||||
|
||||
super(TestAgentList, self).setUp()
|
||||
|
||||
self.agents_mock.list.return_value = self.agents
|
||||
self.cmd = agent.ListAgent(self.app, None)
|
||||
|
||||
def test_agent_list(self):
|
||||
|
||||
arglist = []
|
||||
verifylist = []
|
||||
|
||||
@ -218,7 +214,6 @@ class TestAgentList(TestAgent):
|
||||
self.assertEqual(self.list_data, list(data))
|
||||
|
||||
def test_agent_list_with_hypervisor(self):
|
||||
|
||||
arglist = [
|
||||
'--hypervisor',
|
||||
'hypervisor',
|
||||
@ -235,7 +230,6 @@ class TestAgentList(TestAgent):
|
||||
|
||||
|
||||
class TestAgentSet(TestAgent):
|
||||
|
||||
def setUp(self):
|
||||
super(TestAgentSet, self).setUp()
|
||||
|
||||
@ -253,16 +247,19 @@ class TestAgentSet(TestAgent):
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
result = self.cmd.take_action(parsed_args)
|
||||
|
||||
self.agents_mock.update.assert_called_with(parsed_args.id,
|
||||
self.fake_agent.version,
|
||||
self.fake_agent.url,
|
||||
self.fake_agent.md5hash)
|
||||
self.agents_mock.update.assert_called_with(
|
||||
parsed_args.id,
|
||||
self.fake_agent.version,
|
||||
self.fake_agent.url,
|
||||
self.fake_agent.md5hash,
|
||||
)
|
||||
self.assertIsNone(result)
|
||||
|
||||
def test_agent_set_version(self):
|
||||
arglist = [
|
||||
'1',
|
||||
'--agent-version', 'new-version',
|
||||
'--agent-version',
|
||||
'new-version',
|
||||
]
|
||||
|
||||
verifylist = [
|
||||
@ -273,16 +270,19 @@ class TestAgentSet(TestAgent):
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
result = self.cmd.take_action(parsed_args)
|
||||
|
||||
self.agents_mock.update.assert_called_with(parsed_args.id,
|
||||
parsed_args.version,
|
||||
self.fake_agent.url,
|
||||
self.fake_agent.md5hash)
|
||||
self.agents_mock.update.assert_called_with(
|
||||
parsed_args.id,
|
||||
parsed_args.version,
|
||||
self.fake_agent.url,
|
||||
self.fake_agent.md5hash,
|
||||
)
|
||||
self.assertIsNone(result)
|
||||
|
||||
def test_agent_set_url(self):
|
||||
arglist = [
|
||||
'1',
|
||||
'--url', 'new-url',
|
||||
'--url',
|
||||
'new-url',
|
||||
]
|
||||
|
||||
verifylist = [
|
||||
@ -293,16 +293,19 @@ class TestAgentSet(TestAgent):
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
result = self.cmd.take_action(parsed_args)
|
||||
|
||||
self.agents_mock.update.assert_called_with(parsed_args.id,
|
||||
self.fake_agent.version,
|
||||
parsed_args.url,
|
||||
self.fake_agent.md5hash)
|
||||
self.agents_mock.update.assert_called_with(
|
||||
parsed_args.id,
|
||||
self.fake_agent.version,
|
||||
parsed_args.url,
|
||||
self.fake_agent.md5hash,
|
||||
)
|
||||
self.assertIsNone(result)
|
||||
|
||||
def test_agent_set_md5hash(self):
|
||||
arglist = [
|
||||
'1',
|
||||
'--md5hash', 'new-md5hash',
|
||||
'--md5hash',
|
||||
'new-md5hash',
|
||||
]
|
||||
|
||||
verifylist = [
|
||||
@ -313,8 +316,10 @@ class TestAgentSet(TestAgent):
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
result = self.cmd.take_action(parsed_args)
|
||||
|
||||
self.agents_mock.update.assert_called_with(parsed_args.id,
|
||||
self.fake_agent.version,
|
||||
self.fake_agent.url,
|
||||
parsed_args.md5hash)
|
||||
self.agents_mock.update.assert_called_with(
|
||||
parsed_args.id,
|
||||
self.fake_agent.version,
|
||||
self.fake_agent.url,
|
||||
parsed_args.md5hash,
|
||||
)
|
||||
self.assertIsNone(result)
|
||||
|
@ -27,7 +27,6 @@ from openstackclient.tests.unit.image.v2 import fakes as image_fakes
|
||||
|
||||
|
||||
class TestAggregate(compute_fakes.TestComputev2):
|
||||
|
||||
fake_ag = compute_fakes.FakeAggregate.create_one_aggregate()
|
||||
|
||||
columns = (
|
||||
@ -64,7 +63,6 @@ class TestAggregate(compute_fakes.TestComputev2):
|
||||
|
||||
|
||||
class TestAggregateAddHost(TestAggregate):
|
||||
|
||||
def setUp(self):
|
||||
super(TestAggregateAddHost, self).setUp()
|
||||
|
||||
@ -84,15 +82,16 @@ class TestAggregateAddHost(TestAggregate):
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
self.sdk_client.find_aggregate.assert_called_once_with(
|
||||
parsed_args.aggregate, ignore_missing=False)
|
||||
parsed_args.aggregate, ignore_missing=False
|
||||
)
|
||||
self.sdk_client.add_host_to_aggregate.assert_called_once_with(
|
||||
self.fake_ag.id, parsed_args.host)
|
||||
self.fake_ag.id, parsed_args.host
|
||||
)
|
||||
self.assertEqual(self.columns, columns)
|
||||
self.assertCountEqual(self.data, data)
|
||||
|
||||
|
||||
class TestAggregateCreate(TestAggregate):
|
||||
|
||||
def setUp(self):
|
||||
super(TestAggregateCreate, self).setUp()
|
||||
|
||||
@ -110,13 +109,15 @@ class TestAggregateCreate(TestAggregate):
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
self.sdk_client.create_aggregate.assert_called_once_with(
|
||||
name=parsed_args.name)
|
||||
name=parsed_args.name
|
||||
)
|
||||
self.assertEqual(self.columns, columns)
|
||||
self.assertCountEqual(self.data, data)
|
||||
|
||||
def test_aggregate_create_with_zone(self):
|
||||
arglist = [
|
||||
'--zone', 'zone1',
|
||||
'--zone',
|
||||
'zone1',
|
||||
'ag1',
|
||||
]
|
||||
verifylist = [
|
||||
@ -127,14 +128,17 @@ class TestAggregateCreate(TestAggregate):
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
self.sdk_client.create_aggregate.assert_called_once_with(
|
||||
name=parsed_args.name, availability_zone=parsed_args.zone)
|
||||
name=parsed_args.name, availability_zone=parsed_args.zone
|
||||
)
|
||||
self.assertEqual(self.columns, columns)
|
||||
self.assertCountEqual(self.data, data)
|
||||
|
||||
def test_aggregate_create_with_property(self):
|
||||
arglist = [
|
||||
'--property', 'key1=value1',
|
||||
'--property', 'key2=value2',
|
||||
'--property',
|
||||
'key1=value1',
|
||||
'--property',
|
||||
'key2=value2',
|
||||
'ag1',
|
||||
]
|
||||
verifylist = [
|
||||
@ -144,37 +148,39 @@ class TestAggregateCreate(TestAggregate):
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
self.sdk_client.create_aggregate.assert_called_once_with(
|
||||
name=parsed_args.name)
|
||||
name=parsed_args.name
|
||||
)
|
||||
self.sdk_client.set_aggregate_metadata.assert_called_once_with(
|
||||
self.fake_ag.id, parsed_args.properties)
|
||||
self.fake_ag.id, parsed_args.properties
|
||||
)
|
||||
self.assertEqual(self.columns, columns)
|
||||
self.assertCountEqual(self.data, data)
|
||||
|
||||
|
||||
class TestAggregateDelete(TestAggregate):
|
||||
|
||||
fake_ags = compute_fakes.FakeAggregate.create_aggregates(count=2)
|
||||
|
||||
def setUp(self):
|
||||
super(TestAggregateDelete, self).setUp()
|
||||
|
||||
self.sdk_client.find_aggregate = (
|
||||
compute_fakes.FakeAggregate.get_aggregates(self.fake_ags))
|
||||
compute_fakes.FakeAggregate.get_aggregates(self.fake_ags)
|
||||
)
|
||||
self.cmd = aggregate.DeleteAggregate(self.app, None)
|
||||
|
||||
def test_aggregate_delete(self):
|
||||
arglist = [
|
||||
self.fake_ags[0].id
|
||||
]
|
||||
arglist = [self.fake_ags[0].id]
|
||||
verifylist = [
|
||||
('aggregate', [self.fake_ags[0].id]),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
self.cmd.take_action(parsed_args)
|
||||
self.sdk_client.find_aggregate.assert_called_once_with(
|
||||
self.fake_ags[0].id, ignore_missing=False)
|
||||
self.fake_ags[0].id, ignore_missing=False
|
||||
)
|
||||
self.sdk_client.delete_aggregate.assert_called_once_with(
|
||||
self.fake_ags[0].id, ignore_missing=False)
|
||||
self.fake_ags[0].id, ignore_missing=False
|
||||
)
|
||||
|
||||
def test_delete_multiple_aggregates(self):
|
||||
arglist = []
|
||||
@ -205,24 +211,25 @@ class TestAggregateDelete(TestAggregate):
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
self.sdk_client.find_aggregate.side_effect = [
|
||||
self.fake_ags[0], sdk_exceptions.NotFoundException]
|
||||
self.fake_ags[0],
|
||||
sdk_exceptions.NotFoundException,
|
||||
]
|
||||
try:
|
||||
self.cmd.take_action(parsed_args)
|
||||
self.fail('CommandError should be raised.')
|
||||
except exceptions.CommandError as e:
|
||||
self.assertEqual('1 of 2 aggregates failed to delete.',
|
||||
str(e))
|
||||
self.assertEqual('1 of 2 aggregates failed to delete.', str(e))
|
||||
|
||||
calls = []
|
||||
for a in arglist:
|
||||
calls.append(call(a, ignore_missing=False))
|
||||
self.sdk_client.find_aggregate.assert_has_calls(calls)
|
||||
self.sdk_client.delete_aggregate.assert_called_with(
|
||||
self.fake_ags[0].id, ignore_missing=False)
|
||||
self.fake_ags[0].id, ignore_missing=False
|
||||
)
|
||||
|
||||
|
||||
class TestAggregateList(TestAggregate):
|
||||
|
||||
list_columns = (
|
||||
"ID",
|
||||
"Name",
|
||||
@ -237,23 +244,29 @@ class TestAggregateList(TestAggregate):
|
||||
"Hosts",
|
||||
)
|
||||
|
||||
list_data = ((
|
||||
TestAggregate.fake_ag.id,
|
||||
TestAggregate.fake_ag.name,
|
||||
TestAggregate.fake_ag.availability_zone,
|
||||
), )
|
||||
list_data = (
|
||||
(
|
||||
TestAggregate.fake_ag.id,
|
||||
TestAggregate.fake_ag.name,
|
||||
TestAggregate.fake_ag.availability_zone,
|
||||
),
|
||||
)
|
||||
|
||||
list_data_long = ((
|
||||
TestAggregate.fake_ag.id,
|
||||
TestAggregate.fake_ag.name,
|
||||
TestAggregate.fake_ag.availability_zone,
|
||||
format_columns.DictColumn({
|
||||
key: value
|
||||
for key, value in TestAggregate.fake_ag.metadata.items()
|
||||
if key != 'availability_zone'
|
||||
}),
|
||||
format_columns.ListColumn(TestAggregate.fake_ag.hosts),
|
||||
), )
|
||||
list_data_long = (
|
||||
(
|
||||
TestAggregate.fake_ag.id,
|
||||
TestAggregate.fake_ag.name,
|
||||
TestAggregate.fake_ag.availability_zone,
|
||||
format_columns.DictColumn(
|
||||
{
|
||||
key: value
|
||||
for key, value in TestAggregate.fake_ag.metadata.items()
|
||||
if key != 'availability_zone'
|
||||
}
|
||||
),
|
||||
format_columns.ListColumn(TestAggregate.fake_ag.hosts),
|
||||
),
|
||||
)
|
||||
|
||||
def setUp(self):
|
||||
super(TestAggregateList, self).setUp()
|
||||
@ -262,7 +275,6 @@ class TestAggregateList(TestAggregate):
|
||||
self.cmd = aggregate.ListAggregate(self.app, None)
|
||||
|
||||
def test_aggregate_list(self):
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, [], [])
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
|
||||
@ -284,7 +296,6 @@ class TestAggregateList(TestAggregate):
|
||||
|
||||
|
||||
class TestAggregateRemoveHost(TestAggregate):
|
||||
|
||||
def setUp(self):
|
||||
super(TestAggregateRemoveHost, self).setUp()
|
||||
|
||||
@ -304,15 +315,16 @@ class TestAggregateRemoveHost(TestAggregate):
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
self.sdk_client.find_aggregate.assert_called_once_with(
|
||||
parsed_args.aggregate, ignore_missing=False)
|
||||
parsed_args.aggregate, ignore_missing=False
|
||||
)
|
||||
self.sdk_client.remove_host_from_aggregate.assert_called_once_with(
|
||||
self.fake_ag.id, parsed_args.host)
|
||||
self.fake_ag.id, parsed_args.host
|
||||
)
|
||||
self.assertEqual(self.columns, columns)
|
||||
self.assertCountEqual(self.data, data)
|
||||
|
||||
|
||||
class TestAggregateSet(TestAggregate):
|
||||
|
||||
def setUp(self):
|
||||
super(TestAggregateSet, self).setUp()
|
||||
|
||||
@ -330,14 +342,16 @@ class TestAggregateSet(TestAggregate):
|
||||
result = self.cmd.take_action(parsed_args)
|
||||
|
||||
self.sdk_client.find_aggregate.assert_called_once_with(
|
||||
parsed_args.aggregate, ignore_missing=False)
|
||||
parsed_args.aggregate, ignore_missing=False
|
||||
)
|
||||
self.assertNotCalled(self.sdk_client.update_aggregate)
|
||||
self.assertNotCalled(self.sdk_client.set_aggregate_metadata)
|
||||
self.assertIsNone(result)
|
||||
|
||||
def test_aggregate_set_with_name(self):
|
||||
arglist = [
|
||||
'--name', 'new_name',
|
||||
'--name',
|
||||
'new_name',
|
||||
'ag1',
|
||||
]
|
||||
verifylist = [
|
||||
@ -348,15 +362,18 @@ class TestAggregateSet(TestAggregate):
|
||||
result = self.cmd.take_action(parsed_args)
|
||||
|
||||
self.sdk_client.find_aggregate.assert_called_once_with(
|
||||
parsed_args.aggregate, ignore_missing=False)
|
||||
parsed_args.aggregate, ignore_missing=False
|
||||
)
|
||||
self.sdk_client.update_aggregate.assert_called_once_with(
|
||||
self.fake_ag.id, name=parsed_args.name)
|
||||
self.fake_ag.id, name=parsed_args.name
|
||||
)
|
||||
self.assertNotCalled(self.sdk_client.set_aggregate_metadata)
|
||||
self.assertIsNone(result)
|
||||
|
||||
def test_aggregate_set_with_zone(self):
|
||||
arglist = [
|
||||
'--zone', 'new_zone',
|
||||
'--zone',
|
||||
'new_zone',
|
||||
'ag1',
|
||||
]
|
||||
verifylist = [
|
||||
@ -367,16 +384,20 @@ class TestAggregateSet(TestAggregate):
|
||||
result = self.cmd.take_action(parsed_args)
|
||||
|
||||
self.sdk_client.find_aggregate.assert_called_once_with(
|
||||
parsed_args.aggregate, ignore_missing=False)
|
||||
parsed_args.aggregate, ignore_missing=False
|
||||
)
|
||||
self.sdk_client.update_aggregate.assert_called_once_with(
|
||||
self.fake_ag.id, availability_zone=parsed_args.zone)
|
||||
self.fake_ag.id, availability_zone=parsed_args.zone
|
||||
)
|
||||
self.assertNotCalled(self.sdk_client.set_aggregate_metadata)
|
||||
self.assertIsNone(result)
|
||||
|
||||
def test_aggregate_set_with_property(self):
|
||||
arglist = [
|
||||
'--property', 'key1=value1',
|
||||
'--property', 'key2=value2',
|
||||
'--property',
|
||||
'key1=value1',
|
||||
'--property',
|
||||
'key2=value2',
|
||||
'ag1',
|
||||
]
|
||||
verifylist = [
|
||||
@ -387,16 +408,19 @@ class TestAggregateSet(TestAggregate):
|
||||
result = self.cmd.take_action(parsed_args)
|
||||
|
||||
self.sdk_client.find_aggregate.assert_called_once_with(
|
||||
parsed_args.aggregate, ignore_missing=False)
|
||||
parsed_args.aggregate, ignore_missing=False
|
||||
)
|
||||
self.assertNotCalled(self.sdk_client.update_aggregate)
|
||||
self.sdk_client.set_aggregate_metadata.assert_called_once_with(
|
||||
self.fake_ag.id, parsed_args.properties)
|
||||
self.fake_ag.id, parsed_args.properties
|
||||
)
|
||||
self.assertIsNone(result)
|
||||
|
||||
def test_aggregate_set_with_no_property_and_property(self):
|
||||
arglist = [
|
||||
'--no-property',
|
||||
'--property', 'key2=value2',
|
||||
'--property',
|
||||
'key2=value2',
|
||||
'ag1',
|
||||
]
|
||||
verifylist = [
|
||||
@ -407,10 +431,12 @@ class TestAggregateSet(TestAggregate):
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
result = self.cmd.take_action(parsed_args)
|
||||
self.sdk_client.find_aggregate.assert_called_once_with(
|
||||
parsed_args.aggregate, ignore_missing=False)
|
||||
parsed_args.aggregate, ignore_missing=False
|
||||
)
|
||||
self.assertNotCalled(self.sdk_client.update_aggregate)
|
||||
self.sdk_client.set_aggregate_metadata.assert_called_once_with(
|
||||
self.fake_ag.id, {'key1': None, 'key2': 'value2'})
|
||||
self.fake_ag.id, {'key1': None, 'key2': 'value2'}
|
||||
)
|
||||
self.assertIsNone(result)
|
||||
|
||||
def test_aggregate_set_with_no_property(self):
|
||||
@ -425,15 +451,18 @@ class TestAggregateSet(TestAggregate):
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
result = self.cmd.take_action(parsed_args)
|
||||
self.sdk_client.find_aggregate.assert_called_once_with(
|
||||
parsed_args.aggregate, ignore_missing=False)
|
||||
parsed_args.aggregate, ignore_missing=False
|
||||
)
|
||||
self.assertNotCalled(self.sdk_client.update_aggregate)
|
||||
self.sdk_client.set_aggregate_metadata.assert_called_once_with(
|
||||
self.fake_ag.id, {'key1': None})
|
||||
self.fake_ag.id, {'key1': None}
|
||||
)
|
||||
self.assertIsNone(result)
|
||||
|
||||
def test_aggregate_set_with_zone_and_no_property(self):
|
||||
arglist = [
|
||||
'--zone', 'new_zone',
|
||||
'--zone',
|
||||
'new_zone',
|
||||
'--no-property',
|
||||
'ag1',
|
||||
]
|
||||
@ -445,16 +474,18 @@ class TestAggregateSet(TestAggregate):
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
result = self.cmd.take_action(parsed_args)
|
||||
self.sdk_client.find_aggregate.assert_called_once_with(
|
||||
parsed_args.aggregate, ignore_missing=False)
|
||||
parsed_args.aggregate, ignore_missing=False
|
||||
)
|
||||
self.sdk_client.update_aggregate.assert_called_once_with(
|
||||
self.fake_ag.id, availability_zone=parsed_args.zone)
|
||||
self.fake_ag.id, availability_zone=parsed_args.zone
|
||||
)
|
||||
self.sdk_client.set_aggregate_metadata.assert_called_once_with(
|
||||
self.fake_ag.id, {'key1': None})
|
||||
self.fake_ag.id, {'key1': None}
|
||||
)
|
||||
self.assertIsNone(result)
|
||||
|
||||
|
||||
class TestAggregateShow(TestAggregate):
|
||||
|
||||
columns = (
|
||||
'availability_zone',
|
||||
'hosts',
|
||||
@ -468,11 +499,13 @@ class TestAggregateShow(TestAggregate):
|
||||
format_columns.ListColumn(TestAggregate.fake_ag.hosts),
|
||||
TestAggregate.fake_ag.id,
|
||||
TestAggregate.fake_ag.name,
|
||||
format_columns.DictColumn({
|
||||
key: value
|
||||
for key, value in TestAggregate.fake_ag.metadata.items()
|
||||
if key != 'availability_zone'
|
||||
}),
|
||||
format_columns.DictColumn(
|
||||
{
|
||||
key: value
|
||||
for key, value in TestAggregate.fake_ag.metadata.items()
|
||||
if key != 'availability_zone'
|
||||
}
|
||||
),
|
||||
)
|
||||
|
||||
def setUp(self):
|
||||
@ -491,14 +524,14 @@ class TestAggregateShow(TestAggregate):
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
self.sdk_client.find_aggregate.assert_called_once_with(
|
||||
parsed_args.aggregate, ignore_missing=False)
|
||||
parsed_args.aggregate, ignore_missing=False
|
||||
)
|
||||
|
||||
self.assertEqual(self.columns, columns)
|
||||
self.assertCountEqual(self.data, tuple(data))
|
||||
|
||||
|
||||
class TestAggregateUnset(TestAggregate):
|
||||
|
||||
def setUp(self):
|
||||
super(TestAggregateUnset, self).setUp()
|
||||
|
||||
@ -507,7 +540,8 @@ class TestAggregateUnset(TestAggregate):
|
||||
|
||||
def test_aggregate_unset(self):
|
||||
arglist = [
|
||||
'--property', 'unset_key',
|
||||
'--property',
|
||||
'unset_key',
|
||||
'ag1',
|
||||
]
|
||||
verifylist = [
|
||||
@ -518,13 +552,16 @@ class TestAggregateUnset(TestAggregate):
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
result = self.cmd.take_action(parsed_args)
|
||||
self.sdk_client.set_aggregate_metadata.assert_called_once_with(
|
||||
self.fake_ag.id, {'unset_key': None})
|
||||
self.fake_ag.id, {'unset_key': None}
|
||||
)
|
||||
self.assertIsNone(result)
|
||||
|
||||
def test_aggregate_unset_multiple_properties(self):
|
||||
arglist = [
|
||||
'--property', 'unset_key1',
|
||||
'--property', 'unset_key2',
|
||||
'--property',
|
||||
'unset_key1',
|
||||
'--property',
|
||||
'unset_key2',
|
||||
'ag1',
|
||||
]
|
||||
verifylist = [
|
||||
@ -535,7 +572,8 @@ class TestAggregateUnset(TestAggregate):
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
result = self.cmd.take_action(parsed_args)
|
||||
self.sdk_client.set_aggregate_metadata.assert_called_once_with(
|
||||
self.fake_ag.id, {'unset_key1': None, 'unset_key2': None})
|
||||
self.fake_ag.id, {'unset_key1': None, 'unset_key2': None}
|
||||
)
|
||||
self.assertIsNone(result)
|
||||
|
||||
def test_aggregate_unset_no_option(self):
|
||||
@ -553,7 +591,6 @@ class TestAggregateUnset(TestAggregate):
|
||||
|
||||
|
||||
class TestAggregateCacheImage(TestAggregate):
|
||||
|
||||
images = image_fakes.create_images(count=2)
|
||||
|
||||
def setUp(self):
|
||||
@ -561,34 +598,27 @@ class TestAggregateCacheImage(TestAggregate):
|
||||
|
||||
self.sdk_client.find_aggregate.return_value = self.fake_ag
|
||||
self.find_image_mock = mock.Mock(side_effect=self.images)
|
||||
self.app.client_manager.sdk_connection.image.find_image = \
|
||||
self.app.client_manager.sdk_connection.image.find_image = (
|
||||
self.find_image_mock
|
||||
)
|
||||
|
||||
self.cmd = aggregate.CacheImageForAggregate(self.app, None)
|
||||
|
||||
@mock.patch.object(sdk_utils, 'supports_microversion', return_value=False)
|
||||
def test_aggregate_not_supported(self, sm_mock):
|
||||
arglist = [
|
||||
'ag1',
|
||||
'im1'
|
||||
]
|
||||
arglist = ['ag1', 'im1']
|
||||
verifylist = [
|
||||
('aggregate', 'ag1'),
|
||||
('image', ['im1']),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
self.assertRaises(
|
||||
exceptions.CommandError,
|
||||
self.cmd.take_action,
|
||||
parsed_args
|
||||
exceptions.CommandError, self.cmd.take_action, parsed_args
|
||||
)
|
||||
|
||||
@mock.patch.object(sdk_utils, 'supports_microversion', return_value=True)
|
||||
def test_aggregate_add_single_image(self, sm_mock):
|
||||
arglist = [
|
||||
'ag1',
|
||||
'im1'
|
||||
]
|
||||
arglist = ['ag1', 'im1']
|
||||
verifylist = [
|
||||
('aggregate', 'ag1'),
|
||||
('image', ['im1']),
|
||||
@ -596,9 +626,11 @@ class TestAggregateCacheImage(TestAggregate):
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
self.cmd.take_action(parsed_args)
|
||||
self.sdk_client.find_aggregate.assert_called_once_with(
|
||||
parsed_args.aggregate, ignore_missing=False)
|
||||
parsed_args.aggregate, ignore_missing=False
|
||||
)
|
||||
self.sdk_client.aggregate_precache_images.assert_called_once_with(
|
||||
self.fake_ag.id, [self.images[0].id])
|
||||
self.fake_ag.id, [self.images[0].id]
|
||||
)
|
||||
|
||||
@mock.patch.object(sdk_utils, 'supports_microversion', return_value=True)
|
||||
def test_aggregate_add_multiple_images(self, sm_mock):
|
||||
@ -614,6 +646,8 @@ class TestAggregateCacheImage(TestAggregate):
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
self.cmd.take_action(parsed_args)
|
||||
self.sdk_client.find_aggregate.assert_called_once_with(
|
||||
parsed_args.aggregate, ignore_missing=False)
|
||||
parsed_args.aggregate, ignore_missing=False
|
||||
)
|
||||
self.sdk_client.aggregate_precache_images.assert_called_once_with(
|
||||
self.fake_ag.id, [self.images[0].id, self.images[1].id])
|
||||
self.fake_ag.id, [self.images[0].id, self.images[1].id]
|
||||
)
|
||||
|
@ -21,7 +21,6 @@ from openstackclient.tests.unit import utils
|
||||
|
||||
|
||||
class TestConsole(compute_fakes.TestComputev2):
|
||||
|
||||
def setUp(self):
|
||||
super(TestConsole, self).setUp()
|
||||
|
||||
@ -44,62 +43,48 @@ class TestConsoleLog(TestConsole):
|
||||
self.cmd = console.ShowConsoleLog(self.app, None)
|
||||
|
||||
def test_show_no_args(self):
|
||||
arglist = [
|
||||
]
|
||||
verifylist = [
|
||||
]
|
||||
self.assertRaises(utils.ParserException,
|
||||
self.check_parser,
|
||||
self.cmd,
|
||||
arglist,
|
||||
verifylist)
|
||||
arglist = []
|
||||
verifylist = []
|
||||
self.assertRaises(
|
||||
utils.ParserException,
|
||||
self.check_parser,
|
||||
self.cmd,
|
||||
arglist,
|
||||
verifylist,
|
||||
)
|
||||
|
||||
def test_show(self):
|
||||
arglist = [
|
||||
'fake_server'
|
||||
]
|
||||
verifylist = [
|
||||
('server', 'fake_server')
|
||||
]
|
||||
arglist = ['fake_server']
|
||||
verifylist = [('server', 'fake_server')]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
output = {
|
||||
'output': '1st line\n2nd line\n'
|
||||
}
|
||||
output = {'output': '1st line\n2nd line\n'}
|
||||
self.sdk_client.get_server_console_output.return_value = output
|
||||
self.cmd.take_action(parsed_args)
|
||||
|
||||
self.sdk_client.find_server.assert_called_with(
|
||||
name_or_id='fake_server', ignore_missing=False)
|
||||
name_or_id='fake_server', ignore_missing=False
|
||||
)
|
||||
self.sdk_client.get_server_console_output.assert_called_with(
|
||||
self._server.id,
|
||||
length=None
|
||||
self._server.id, length=None
|
||||
)
|
||||
stdout = self.app.stdout.content
|
||||
self.assertEqual(stdout[0], output['output'])
|
||||
|
||||
def test_show_lines(self):
|
||||
arglist = [
|
||||
'fake_server',
|
||||
'--lines', '15'
|
||||
]
|
||||
verifylist = [
|
||||
('server', 'fake_server'),
|
||||
('lines', 15)
|
||||
]
|
||||
arglist = ['fake_server', '--lines', '15']
|
||||
verifylist = [('server', 'fake_server'), ('lines', 15)]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
output = {
|
||||
'output': '1st line\n2nd line'
|
||||
}
|
||||
output = {'output': '1st line\n2nd line'}
|
||||
self.sdk_client.get_server_console_output.return_value = output
|
||||
self.cmd.take_action(parsed_args)
|
||||
|
||||
self.sdk_client.find_server.assert_called_with(
|
||||
name_or_id='fake_server', ignore_missing=False)
|
||||
name_or_id='fake_server', ignore_missing=False
|
||||
)
|
||||
self.sdk_client.get_server_console_output.assert_called_with(
|
||||
self._server.id,
|
||||
length=15
|
||||
self._server.id, length=15
|
||||
)
|
||||
|
||||
|
||||
@ -109,11 +94,14 @@ class TestConsoleUrlShow(TestConsole):
|
||||
def setUp(self):
|
||||
super(TestConsoleUrlShow, self).setUp()
|
||||
self.sdk_client.find_server.return_value = self._server
|
||||
fake_console_data = {'url': 'http://localhost',
|
||||
'protocol': 'fake_protocol',
|
||||
'type': 'fake_type'}
|
||||
fake_console_data = {
|
||||
'url': 'http://localhost',
|
||||
'protocol': 'fake_protocol',
|
||||
'type': 'fake_type',
|
||||
}
|
||||
self.sdk_client.create_console = mock.Mock(
|
||||
return_value=fake_console_data)
|
||||
return_value=fake_console_data
|
||||
)
|
||||
|
||||
self.columns = (
|
||||
'protocol',
|
||||
@ -123,7 +111,7 @@ class TestConsoleUrlShow(TestConsole):
|
||||
self.data = (
|
||||
fake_console_data['protocol'],
|
||||
fake_console_data['type'],
|
||||
fake_console_data['url']
|
||||
fake_console_data['url'],
|
||||
)
|
||||
|
||||
self.cmd = console.ShowConsoleURL(self.app, None)
|
||||
@ -139,8 +127,8 @@ class TestConsoleUrlShow(TestConsole):
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
self.sdk_client.create_console.assert_called_once_with(
|
||||
self._server.id,
|
||||
console_type='novnc')
|
||||
self._server.id, console_type='novnc'
|
||||
)
|
||||
self.assertEqual(self.columns, columns)
|
||||
self.assertEqual(self.data, data)
|
||||
|
||||
@ -156,8 +144,8 @@ class TestConsoleUrlShow(TestConsole):
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
self.sdk_client.create_console.assert_called_once_with(
|
||||
self._server.id,
|
||||
console_type='novnc')
|
||||
self._server.id, console_type='novnc'
|
||||
)
|
||||
self.assertEqual(self.columns, columns)
|
||||
self.assertEqual(self.data, data)
|
||||
|
||||
@ -173,8 +161,8 @@ class TestConsoleUrlShow(TestConsole):
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
self.sdk_client.create_console.assert_called_once_with(
|
||||
self._server.id,
|
||||
console_type='xvpvnc')
|
||||
self._server.id, console_type='xvpvnc'
|
||||
)
|
||||
self.assertEqual(self.columns, columns)
|
||||
self.assertEqual(self.data, data)
|
||||
|
||||
@ -190,8 +178,8 @@ class TestConsoleUrlShow(TestConsole):
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
self.sdk_client.create_console.assert_called_once_with(
|
||||
self._server.id,
|
||||
console_type='spice-html5')
|
||||
self._server.id, console_type='spice-html5'
|
||||
)
|
||||
self.assertEqual(self.columns, columns)
|
||||
self.assertEqual(self.data, data)
|
||||
|
||||
@ -207,8 +195,8 @@ class TestConsoleUrlShow(TestConsole):
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
self.sdk_client.create_console.assert_called_once_with(
|
||||
self._server.id,
|
||||
console_type='rdp-html5')
|
||||
self._server.id, console_type='rdp-html5'
|
||||
)
|
||||
self.assertEqual(self.columns, columns)
|
||||
self.assertEqual(self.data, data)
|
||||
|
||||
@ -224,8 +212,8 @@ class TestConsoleUrlShow(TestConsole):
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
self.sdk_client.create_console.assert_called_once_with(
|
||||
self._server.id,
|
||||
console_type='serial')
|
||||
self._server.id, console_type='serial'
|
||||
)
|
||||
self.assertEqual(self.columns, columns)
|
||||
self.assertEqual(self.data, data)
|
||||
|
||||
@ -241,7 +229,7 @@ class TestConsoleUrlShow(TestConsole):
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
self.sdk_client.create_console.assert_called_once_with(
|
||||
self._server.id,
|
||||
console_type='webmks')
|
||||
self._server.id, console_type='webmks'
|
||||
)
|
||||
self.assertEqual(self.columns, columns)
|
||||
self.assertEqual(self.data, data)
|
||||
|
@ -27,7 +27,6 @@ from openstackclient.tests.unit import utils as tests_utils
|
||||
|
||||
|
||||
class TestFlavor(compute_fakes.TestComputev2):
|
||||
|
||||
def setUp(self):
|
||||
super(TestFlavor, self).setUp()
|
||||
|
||||
@ -50,9 +49,9 @@ class TestFlavor(compute_fakes.TestComputev2):
|
||||
|
||||
|
||||
class TestFlavorCreate(TestFlavor):
|
||||
|
||||
flavor = compute_fakes.FakeFlavor.create_one_flavor(
|
||||
attrs={'links': 'flavor-links'})
|
||||
attrs={'links': 'flavor-links'}
|
||||
)
|
||||
project = identity_fakes.FakeProject.create_one_project()
|
||||
|
||||
columns = (
|
||||
@ -67,7 +66,7 @@ class TestFlavorCreate(TestFlavor):
|
||||
'ram',
|
||||
'rxtx_factor',
|
||||
'swap',
|
||||
'vcpus'
|
||||
'vcpus',
|
||||
)
|
||||
|
||||
data = (
|
||||
@ -108,10 +107,7 @@ class TestFlavorCreate(TestFlavor):
|
||||
self.cmd = flavor.CreateFlavor(self.app, None)
|
||||
|
||||
def test_flavor_create_default_options(self):
|
||||
|
||||
arglist = [
|
||||
self.flavor.name
|
||||
]
|
||||
arglist = [self.flavor.name]
|
||||
verifylist = [
|
||||
('name', self.flavor.name),
|
||||
]
|
||||
@ -136,18 +132,26 @@ class TestFlavorCreate(TestFlavor):
|
||||
self.assertCountEqual(self.data, data)
|
||||
|
||||
def test_flavor_create_all_options(self):
|
||||
|
||||
arglist = [
|
||||
'--id', self.flavor.id,
|
||||
'--ram', str(self.flavor.ram),
|
||||
'--disk', str(self.flavor.disk),
|
||||
'--ephemeral', str(self.flavor.ephemeral),
|
||||
'--swap', str(self.flavor.swap),
|
||||
'--vcpus', str(self.flavor.vcpus),
|
||||
'--rxtx-factor', str(self.flavor.rxtx_factor),
|
||||
'--id',
|
||||
self.flavor.id,
|
||||
'--ram',
|
||||
str(self.flavor.ram),
|
||||
'--disk',
|
||||
str(self.flavor.disk),
|
||||
'--ephemeral',
|
||||
str(self.flavor.ephemeral),
|
||||
'--swap',
|
||||
str(self.flavor.swap),
|
||||
'--vcpus',
|
||||
str(self.flavor.vcpus),
|
||||
'--rxtx-factor',
|
||||
str(self.flavor.rxtx_factor),
|
||||
'--public',
|
||||
'--description', str(self.flavor.description),
|
||||
'--property', 'property=value',
|
||||
'--description',
|
||||
str(self.flavor.description),
|
||||
'--property',
|
||||
'property=value',
|
||||
self.flavor.name,
|
||||
]
|
||||
verifylist = [
|
||||
@ -175,7 +179,7 @@ class TestFlavorCreate(TestFlavor):
|
||||
'swap': self.flavor.swap,
|
||||
'rxtx_factor': self.flavor.rxtx_factor,
|
||||
'is_public': self.flavor.is_public,
|
||||
'description': self.flavor.description
|
||||
'description': self.flavor.description,
|
||||
}
|
||||
|
||||
props = {'property': 'value'}
|
||||
@ -190,36 +194,49 @@ class TestFlavorCreate(TestFlavor):
|
||||
cmp_data = list(self.data)
|
||||
cmp_data[7] = format_columns.DictColumn(props)
|
||||
self.sdk_client.create_flavor.return_value = create_flavor
|
||||
self.sdk_client.create_flavor_extra_specs.return_value = \
|
||||
self.sdk_client.create_flavor_extra_specs.return_value = (
|
||||
expected_flavor
|
||||
)
|
||||
|
||||
with mock.patch.object(sdk_utils, 'supports_microversion',
|
||||
return_value=True):
|
||||
with mock.patch.object(
|
||||
sdk_utils, 'supports_microversion', return_value=True
|
||||
):
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
self.sdk_client.create_flavor.assert_called_once_with(**args)
|
||||
self.sdk_client.create_flavor_extra_specs.assert_called_once_with(
|
||||
create_flavor, props)
|
||||
create_flavor, props
|
||||
)
|
||||
self.sdk_client.get_flavor_access.assert_not_called()
|
||||
|
||||
self.assertEqual(self.columns, columns)
|
||||
self.assertCountEqual(tuple(cmp_data), data)
|
||||
|
||||
def test_flavor_create_other_options(self):
|
||||
|
||||
self.flavor.is_public = False
|
||||
arglist = [
|
||||
'--id', 'auto',
|
||||
'--ram', str(self.flavor.ram),
|
||||
'--disk', str(self.flavor.disk),
|
||||
'--ephemeral', str(self.flavor.ephemeral),
|
||||
'--swap', str(self.flavor.swap),
|
||||
'--vcpus', str(self.flavor.vcpus),
|
||||
'--rxtx-factor', str(self.flavor.rxtx_factor),
|
||||
'--id',
|
||||
'auto',
|
||||
'--ram',
|
||||
str(self.flavor.ram),
|
||||
'--disk',
|
||||
str(self.flavor.disk),
|
||||
'--ephemeral',
|
||||
str(self.flavor.ephemeral),
|
||||
'--swap',
|
||||
str(self.flavor.swap),
|
||||
'--vcpus',
|
||||
str(self.flavor.vcpus),
|
||||
'--rxtx-factor',
|
||||
str(self.flavor.rxtx_factor),
|
||||
'--private',
|
||||
'--description', str(self.flavor.description),
|
||||
'--project', self.project.id,
|
||||
'--property', 'key1=value1',
|
||||
'--property', 'key2=value2',
|
||||
'--description',
|
||||
str(self.flavor.description),
|
||||
'--project',
|
||||
self.project.id,
|
||||
'--property',
|
||||
'key1=value1',
|
||||
'--property',
|
||||
'key2=value2',
|
||||
self.flavor.name,
|
||||
]
|
||||
verifylist = [
|
||||
@ -247,7 +264,7 @@ class TestFlavorCreate(TestFlavor):
|
||||
'swap': self.flavor.swap,
|
||||
'rxtx_factor': self.flavor.rxtx_factor,
|
||||
'is_public': False,
|
||||
'description': self.flavor.description
|
||||
'description': self.flavor.description,
|
||||
}
|
||||
|
||||
props = {'key1': 'value1', 'key2': 'value2'}
|
||||
@ -263,11 +280,13 @@ class TestFlavorCreate(TestFlavor):
|
||||
cmp_data = list(self.data_private)
|
||||
cmp_data[7] = format_columns.DictColumn(props)
|
||||
self.sdk_client.create_flavor.return_value = create_flavor
|
||||
self.sdk_client.create_flavor_extra_specs.return_value = \
|
||||
self.sdk_client.create_flavor_extra_specs.return_value = (
|
||||
expected_flavor
|
||||
)
|
||||
|
||||
with mock.patch.object(sdk_utils, 'supports_microversion',
|
||||
return_value=True):
|
||||
with mock.patch.object(
|
||||
sdk_utils, 'supports_microversion', return_value=True
|
||||
):
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
self.sdk_client.create_flavor.assert_called_once_with(**args)
|
||||
self.sdk_client.flavor_add_tenant_access.assert_called_with(
|
||||
@ -275,13 +294,15 @@ class TestFlavorCreate(TestFlavor):
|
||||
self.project.id,
|
||||
)
|
||||
self.sdk_client.create_flavor_extra_specs.assert_called_with(
|
||||
create_flavor, props)
|
||||
create_flavor, props
|
||||
)
|
||||
self.assertEqual(self.columns, columns)
|
||||
self.assertCountEqual(cmp_data, data)
|
||||
|
||||
def test_public_flavor_create_with_project(self):
|
||||
arglist = [
|
||||
'--project', self.project.id,
|
||||
'--project',
|
||||
self.project.id,
|
||||
self.flavor.name,
|
||||
]
|
||||
verifylist = [
|
||||
@ -290,30 +311,40 @@ class TestFlavorCreate(TestFlavor):
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
self.assertRaises(exceptions.CommandError,
|
||||
self.cmd.take_action,
|
||||
parsed_args)
|
||||
self.assertRaises(
|
||||
exceptions.CommandError, self.cmd.take_action, parsed_args
|
||||
)
|
||||
|
||||
def test_flavor_create_no_options(self):
|
||||
arglist = []
|
||||
verifylist = None
|
||||
self.assertRaises(tests_utils.ParserException,
|
||||
self.check_parser,
|
||||
self.cmd,
|
||||
arglist,
|
||||
verifylist)
|
||||
self.assertRaises(
|
||||
tests_utils.ParserException,
|
||||
self.check_parser,
|
||||
self.cmd,
|
||||
arglist,
|
||||
verifylist,
|
||||
)
|
||||
|
||||
def test_flavor_create_with_description_api_newer(self):
|
||||
arglist = [
|
||||
'--id', self.flavor.id,
|
||||
'--ram', str(self.flavor.ram),
|
||||
'--disk', str(self.flavor.disk),
|
||||
'--ephemeral', str(self.flavor.ephemeral),
|
||||
'--swap', str(self.flavor.swap),
|
||||
'--vcpus', str(self.flavor.vcpus),
|
||||
'--rxtx-factor', str(self.flavor.rxtx_factor),
|
||||
'--id',
|
||||
self.flavor.id,
|
||||
'--ram',
|
||||
str(self.flavor.ram),
|
||||
'--disk',
|
||||
str(self.flavor.disk),
|
||||
'--ephemeral',
|
||||
str(self.flavor.ephemeral),
|
||||
'--swap',
|
||||
str(self.flavor.swap),
|
||||
'--vcpus',
|
||||
str(self.flavor.vcpus),
|
||||
'--rxtx-factor',
|
||||
str(self.flavor.rxtx_factor),
|
||||
'--private',
|
||||
'--description', 'fake description',
|
||||
'--description',
|
||||
'fake description',
|
||||
self.flavor.name,
|
||||
]
|
||||
verifylist = [
|
||||
@ -329,9 +360,9 @@ class TestFlavorCreate(TestFlavor):
|
||||
('name', self.flavor.name),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
with mock.patch.object(sdk_utils, 'supports_microversion',
|
||||
return_value=True):
|
||||
|
||||
with mock.patch.object(
|
||||
sdk_utils, 'supports_microversion', return_value=True
|
||||
):
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
|
||||
args = {
|
||||
@ -344,7 +375,7 @@ class TestFlavorCreate(TestFlavor):
|
||||
'swap': self.flavor.swap,
|
||||
'rxtx_factor': self.flavor.rxtx_factor,
|
||||
'is_public': self.flavor.is_public,
|
||||
'description': 'fake description'
|
||||
'description': 'fake description',
|
||||
}
|
||||
|
||||
self.sdk_client.create_flavor.assert_called_once_with(**args)
|
||||
@ -354,10 +385,14 @@ class TestFlavorCreate(TestFlavor):
|
||||
|
||||
def test_flavor_create_with_description_api_older(self):
|
||||
arglist = [
|
||||
'--id', self.flavor.id,
|
||||
'--ram', str(self.flavor.ram),
|
||||
'--vcpus', str(self.flavor.vcpus),
|
||||
'--description', 'description',
|
||||
'--id',
|
||||
self.flavor.id,
|
||||
'--ram',
|
||||
str(self.flavor.ram),
|
||||
'--vcpus',
|
||||
str(self.flavor.vcpus),
|
||||
'--description',
|
||||
'description',
|
||||
self.flavor.name,
|
||||
]
|
||||
verifylist = [
|
||||
@ -368,14 +403,15 @@ class TestFlavorCreate(TestFlavor):
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
with mock.patch.object(sdk_utils, 'supports_microversion',
|
||||
return_value=False):
|
||||
self.assertRaises(exceptions.CommandError, self.cmd.take_action,
|
||||
parsed_args)
|
||||
with mock.patch.object(
|
||||
sdk_utils, 'supports_microversion', return_value=False
|
||||
):
|
||||
self.assertRaises(
|
||||
exceptions.CommandError, self.cmd.take_action, parsed_args
|
||||
)
|
||||
|
||||
|
||||
class TestFlavorDelete(TestFlavor):
|
||||
|
||||
flavors = compute_fakes.FakeFlavor.create_flavors(count=2)
|
||||
|
||||
def setUp(self):
|
||||
@ -386,9 +422,7 @@ class TestFlavorDelete(TestFlavor):
|
||||
self.cmd = flavor.DeleteFlavor(self.app, None)
|
||||
|
||||
def test_flavor_delete(self):
|
||||
arglist = [
|
||||
self.flavors[0].id
|
||||
]
|
||||
arglist = [self.flavors[0].id]
|
||||
verifylist = [
|
||||
('flavor', [self.flavors[0].id]),
|
||||
]
|
||||
@ -398,8 +432,9 @@ class TestFlavorDelete(TestFlavor):
|
||||
|
||||
result = self.cmd.take_action(parsed_args)
|
||||
|
||||
self.sdk_client.find_flavor.assert_called_with(self.flavors[0].id,
|
||||
ignore_missing=False)
|
||||
self.sdk_client.find_flavor.assert_called_with(
|
||||
self.flavors[0].id, ignore_missing=False
|
||||
)
|
||||
self.sdk_client.delete_flavor.assert_called_with(self.flavors[0].id)
|
||||
self.assertIsNone(result)
|
||||
|
||||
@ -430,14 +465,12 @@ class TestFlavorDelete(TestFlavor):
|
||||
self.flavors[0].id,
|
||||
'unexist_flavor',
|
||||
]
|
||||
verifylist = [
|
||||
('flavor', [self.flavors[0].id, 'unexist_flavor'])
|
||||
]
|
||||
verifylist = [('flavor', [self.flavors[0].id, 'unexist_flavor'])]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
self.sdk_client.find_flavor.side_effect = [
|
||||
self.flavors[0],
|
||||
sdk_exceptions.ResourceNotFound
|
||||
sdk_exceptions.ResourceNotFound,
|
||||
]
|
||||
|
||||
try:
|
||||
@ -456,7 +489,6 @@ class TestFlavorDelete(TestFlavor):
|
||||
|
||||
|
||||
class TestFlavorList(TestFlavor):
|
||||
|
||||
_flavor = compute_fakes.FakeFlavor.create_one_flavor()
|
||||
|
||||
columns = (
|
||||
@ -468,32 +500,36 @@ class TestFlavorList(TestFlavor):
|
||||
'VCPUs',
|
||||
'Is Public',
|
||||
)
|
||||
columns_long = columns + (
|
||||
'Swap',
|
||||
'RXTX Factor',
|
||||
'Properties'
|
||||
)
|
||||
columns_long = columns + ('Swap', 'RXTX Factor', 'Properties')
|
||||
|
||||
data = ((
|
||||
_flavor.id,
|
||||
_flavor.name,
|
||||
_flavor.ram,
|
||||
_flavor.disk,
|
||||
_flavor.ephemeral,
|
||||
_flavor.vcpus,
|
||||
_flavor.is_public,
|
||||
),)
|
||||
data_long = (data[0] + (
|
||||
_flavor.swap,
|
||||
_flavor.rxtx_factor,
|
||||
format_columns.DictColumn(_flavor.extra_specs)
|
||||
), )
|
||||
data = (
|
||||
(
|
||||
_flavor.id,
|
||||
_flavor.name,
|
||||
_flavor.ram,
|
||||
_flavor.disk,
|
||||
_flavor.ephemeral,
|
||||
_flavor.vcpus,
|
||||
_flavor.is_public,
|
||||
),
|
||||
)
|
||||
data_long = (
|
||||
data[0]
|
||||
+ (
|
||||
_flavor.swap,
|
||||
_flavor.rxtx_factor,
|
||||
format_columns.DictColumn(_flavor.extra_specs),
|
||||
),
|
||||
)
|
||||
|
||||
def setUp(self):
|
||||
super(TestFlavorList, self).setUp()
|
||||
|
||||
self.api_mock = mock.Mock()
|
||||
self.api_mock.side_effect = [[self._flavor], [], ]
|
||||
self.api_mock.side_effect = [
|
||||
[self._flavor],
|
||||
[],
|
||||
]
|
||||
|
||||
self.sdk_client.flavors = self.api_mock
|
||||
|
||||
@ -520,9 +556,7 @@ class TestFlavorList(TestFlavor):
|
||||
'is_public': True,
|
||||
}
|
||||
|
||||
self.sdk_client.flavors.assert_called_with(
|
||||
**kwargs
|
||||
)
|
||||
self.sdk_client.flavors.assert_called_with(**kwargs)
|
||||
self.sdk_client.fetch_flavor_extra_specs.assert_not_called()
|
||||
|
||||
self.assertEqual(self.columns, columns)
|
||||
@ -548,9 +582,7 @@ class TestFlavorList(TestFlavor):
|
||||
'is_public': None,
|
||||
}
|
||||
|
||||
self.sdk_client.flavors.assert_called_with(
|
||||
**kwargs
|
||||
)
|
||||
self.sdk_client.flavors.assert_called_with(**kwargs)
|
||||
self.sdk_client.fetch_flavor_extra_specs.assert_not_called()
|
||||
|
||||
self.assertEqual(self.columns, columns)
|
||||
@ -576,9 +608,7 @@ class TestFlavorList(TestFlavor):
|
||||
'is_public': False,
|
||||
}
|
||||
|
||||
self.sdk_client.flavors.assert_called_with(
|
||||
**kwargs
|
||||
)
|
||||
self.sdk_client.flavors.assert_called_with(**kwargs)
|
||||
self.sdk_client.fetch_flavor_extra_specs.assert_not_called()
|
||||
|
||||
self.assertEqual(self.columns, columns)
|
||||
@ -604,9 +634,7 @@ class TestFlavorList(TestFlavor):
|
||||
'is_public': True,
|
||||
}
|
||||
|
||||
self.sdk_client.flavors.assert_called_with(
|
||||
**kwargs
|
||||
)
|
||||
self.sdk_client.flavors.assert_called_with(**kwargs)
|
||||
self.sdk_client.fetch_flavor_extra_specs.assert_not_called()
|
||||
|
||||
self.assertEqual(self.columns, columns)
|
||||
@ -632,9 +660,7 @@ class TestFlavorList(TestFlavor):
|
||||
'is_public': True,
|
||||
}
|
||||
|
||||
self.sdk_client.flavors.assert_called_with(
|
||||
**kwargs
|
||||
)
|
||||
self.sdk_client.flavors.assert_called_with(**kwargs)
|
||||
self.sdk_client.fetch_flavor_extra_specs.assert_not_called()
|
||||
|
||||
self.assertEqual(self.columns_long, columns)
|
||||
@ -643,22 +669,31 @@ class TestFlavorList(TestFlavor):
|
||||
def test_flavor_list_long_no_extra_specs(self):
|
||||
# use flavor with no extra specs for this test
|
||||
flavor = compute_fakes.FakeFlavor.create_one_flavor(
|
||||
attrs={"extra_specs": {}})
|
||||
self.data = ((
|
||||
flavor.id,
|
||||
flavor.name,
|
||||
flavor.ram,
|
||||
flavor.disk,
|
||||
flavor.ephemeral,
|
||||
flavor.vcpus,
|
||||
flavor.is_public,
|
||||
),)
|
||||
self.data_long = (self.data[0] + (
|
||||
flavor.swap,
|
||||
flavor.rxtx_factor,
|
||||
format_columns.DictColumn(flavor.extra_specs)
|
||||
),)
|
||||
self.api_mock.side_effect = [[flavor], [], ]
|
||||
attrs={"extra_specs": {}}
|
||||
)
|
||||
self.data = (
|
||||
(
|
||||
flavor.id,
|
||||
flavor.name,
|
||||
flavor.ram,
|
||||
flavor.disk,
|
||||
flavor.ephemeral,
|
||||
flavor.vcpus,
|
||||
flavor.is_public,
|
||||
),
|
||||
)
|
||||
self.data_long = (
|
||||
self.data[0]
|
||||
+ (
|
||||
flavor.swap,
|
||||
flavor.rxtx_factor,
|
||||
format_columns.DictColumn(flavor.extra_specs),
|
||||
),
|
||||
)
|
||||
self.api_mock.side_effect = [
|
||||
[flavor],
|
||||
[],
|
||||
]
|
||||
|
||||
self.sdk_client.flavors = self.api_mock
|
||||
self.sdk_client.fetch_flavor_extra_specs = mock.Mock(return_value=None)
|
||||
@ -682,19 +717,20 @@ class TestFlavorList(TestFlavor):
|
||||
'is_public': True,
|
||||
}
|
||||
|
||||
self.sdk_client.flavors.assert_called_with(
|
||||
**kwargs
|
||||
)
|
||||
self.sdk_client.flavors.assert_called_with(**kwargs)
|
||||
self.sdk_client.fetch_flavor_extra_specs.assert_called_once_with(
|
||||
flavor)
|
||||
flavor
|
||||
)
|
||||
|
||||
self.assertEqual(self.columns_long, columns)
|
||||
self.assertCountEqual(self.data_long, tuple(data))
|
||||
|
||||
def test_flavor_list_min_disk_min_ram(self):
|
||||
arglist = [
|
||||
'--min-disk', '10',
|
||||
'--min-ram', '2048',
|
||||
'--min-disk',
|
||||
'10',
|
||||
'--min-ram',
|
||||
'2048',
|
||||
]
|
||||
verifylist = [
|
||||
('min_disk', 10),
|
||||
@ -715,9 +751,7 @@ class TestFlavorList(TestFlavor):
|
||||
'min_ram': 2048,
|
||||
}
|
||||
|
||||
self.sdk_client.flavors.assert_called_with(
|
||||
**kwargs
|
||||
)
|
||||
self.sdk_client.flavors.assert_called_with(**kwargs)
|
||||
self.sdk_client.fetch_flavor_extra_specs.assert_not_called()
|
||||
|
||||
self.assertEqual(self.columns, columns)
|
||||
@ -725,10 +759,10 @@ class TestFlavorList(TestFlavor):
|
||||
|
||||
|
||||
class TestFlavorSet(TestFlavor):
|
||||
|
||||
# Return value of self.sdk_client.find_flavor().
|
||||
flavor = compute_fakes.FakeFlavor.create_one_flavor(
|
||||
attrs={'os-flavor-access:is_public': False})
|
||||
attrs={'os-flavor-access:is_public': False}
|
||||
)
|
||||
project = identity_fakes.FakeProject.create_one_project()
|
||||
|
||||
def setUp(self):
|
||||
@ -740,51 +774,40 @@ class TestFlavorSet(TestFlavor):
|
||||
self.cmd = flavor.SetFlavor(self.app, None)
|
||||
|
||||
def test_flavor_set_property(self):
|
||||
arglist = [
|
||||
'--property', 'FOO="B A R"',
|
||||
'baremetal'
|
||||
]
|
||||
arglist = ['--property', 'FOO="B A R"', 'baremetal']
|
||||
verifylist = [
|
||||
('properties', {'FOO': '"B A R"'}),
|
||||
('flavor', 'baremetal')
|
||||
('flavor', 'baremetal'),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
result = self.cmd.take_action(parsed_args)
|
||||
self.sdk_client.find_flavor.assert_called_with(
|
||||
parsed_args.flavor,
|
||||
get_extra_specs=True,
|
||||
ignore_missing=False
|
||||
parsed_args.flavor, get_extra_specs=True, ignore_missing=False
|
||||
)
|
||||
self.sdk_client.create_flavor_extra_specs.assert_called_with(
|
||||
self.flavor.id,
|
||||
{'FOO': '"B A R"'})
|
||||
self.flavor.id, {'FOO': '"B A R"'}
|
||||
)
|
||||
self.assertIsNone(result)
|
||||
|
||||
def test_flavor_set_no_property(self):
|
||||
arglist = [
|
||||
'--no-property',
|
||||
'baremetal'
|
||||
]
|
||||
verifylist = [
|
||||
('no_property', True),
|
||||
('flavor', 'baremetal')
|
||||
]
|
||||
arglist = ['--no-property', 'baremetal']
|
||||
verifylist = [('no_property', True), ('flavor', 'baremetal')]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
result = self.cmd.take_action(parsed_args)
|
||||
self.sdk_client.find_flavor.assert_called_with(
|
||||
parsed_args.flavor,
|
||||
get_extra_specs=True,
|
||||
ignore_missing=False
|
||||
parsed_args.flavor, get_extra_specs=True, ignore_missing=False
|
||||
)
|
||||
self.sdk_client.delete_flavor_extra_specs_property.assert_called_with(
|
||||
self.flavor.id, 'property')
|
||||
self.flavor.id, 'property'
|
||||
)
|
||||
self.assertIsNone(result)
|
||||
|
||||
def test_flavor_set_project(self):
|
||||
arglist = [
|
||||
'--project', self.project.id,
|
||||
'--project',
|
||||
self.project.id,
|
||||
self.flavor.id,
|
||||
]
|
||||
verifylist = [
|
||||
@ -796,9 +819,7 @@ class TestFlavorSet(TestFlavor):
|
||||
result = self.cmd.take_action(parsed_args)
|
||||
|
||||
self.sdk_client.find_flavor.assert_called_with(
|
||||
parsed_args.flavor,
|
||||
get_extra_specs=True,
|
||||
ignore_missing=False
|
||||
parsed_args.flavor, get_extra_specs=True, ignore_missing=False
|
||||
)
|
||||
self.sdk_client.flavor_add_tenant_access.assert_called_with(
|
||||
self.flavor.id,
|
||||
@ -816,18 +837,29 @@ class TestFlavorSet(TestFlavor):
|
||||
('project', None),
|
||||
('flavor', self.flavor.id),
|
||||
]
|
||||
self.assertRaises(tests_utils.ParserException, self.check_parser,
|
||||
self.cmd, arglist, verifylist)
|
||||
self.assertRaises(
|
||||
tests_utils.ParserException,
|
||||
self.check_parser,
|
||||
self.cmd,
|
||||
arglist,
|
||||
verifylist,
|
||||
)
|
||||
|
||||
def test_flavor_set_no_flavor(self):
|
||||
arglist = [
|
||||
'--project', self.project.id,
|
||||
'--project',
|
||||
self.project.id,
|
||||
]
|
||||
verifylist = [
|
||||
('project', self.project.id),
|
||||
]
|
||||
self.assertRaises(tests_utils.ParserException, self.check_parser,
|
||||
self.cmd, arglist, verifylist)
|
||||
self.assertRaises(
|
||||
tests_utils.ParserException,
|
||||
self.check_parser,
|
||||
self.cmd,
|
||||
arglist,
|
||||
verifylist,
|
||||
)
|
||||
|
||||
def test_flavor_set_with_unexist_flavor(self):
|
||||
self.sdk_client.find_flavor.side_effect = [
|
||||
@ -835,7 +867,8 @@ class TestFlavorSet(TestFlavor):
|
||||
]
|
||||
|
||||
arglist = [
|
||||
'--project', self.project.id,
|
||||
'--project',
|
||||
self.project.id,
|
||||
'unexist_flavor',
|
||||
]
|
||||
verifylist = [
|
||||
@ -844,9 +877,9 @@ class TestFlavorSet(TestFlavor):
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
self.assertRaises(exceptions.CommandError,
|
||||
self.cmd.take_action,
|
||||
parsed_args)
|
||||
self.assertRaises(
|
||||
exceptions.CommandError, self.cmd.take_action, parsed_args
|
||||
)
|
||||
|
||||
def test_flavor_set_nothing(self):
|
||||
arglist = [
|
||||
@ -859,16 +892,15 @@ class TestFlavorSet(TestFlavor):
|
||||
result = self.cmd.take_action(parsed_args)
|
||||
|
||||
self.sdk_client.find_flavor.assert_called_with(
|
||||
parsed_args.flavor,
|
||||
get_extra_specs=True,
|
||||
ignore_missing=False
|
||||
parsed_args.flavor, get_extra_specs=True, ignore_missing=False
|
||||
)
|
||||
self.sdk_client.flavor_add_tenant_access.assert_not_called()
|
||||
self.assertIsNone(result)
|
||||
|
||||
def test_flavor_set_description_api_newer(self):
|
||||
arglist = [
|
||||
'--description', 'description',
|
||||
'--description',
|
||||
'description',
|
||||
self.flavor.id,
|
||||
]
|
||||
verifylist = [
|
||||
@ -877,17 +909,19 @@ class TestFlavorSet(TestFlavor):
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
self.app.client_manager.compute.api_version = 2.55
|
||||
with mock.patch.object(sdk_utils,
|
||||
'supports_microversion',
|
||||
return_value=True):
|
||||
with mock.patch.object(
|
||||
sdk_utils, 'supports_microversion', return_value=True
|
||||
):
|
||||
result = self.cmd.take_action(parsed_args)
|
||||
self.sdk_client.update_flavor.assert_called_with(
|
||||
flavor=self.flavor.id, description='description')
|
||||
flavor=self.flavor.id, description='description'
|
||||
)
|
||||
self.assertIsNone(result)
|
||||
|
||||
def test_flavor_set_description_api_older(self):
|
||||
arglist = [
|
||||
'--description', 'description',
|
||||
'--description',
|
||||
'description',
|
||||
self.flavor.id,
|
||||
]
|
||||
verifylist = [
|
||||
@ -896,15 +930,17 @@ class TestFlavorSet(TestFlavor):
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
self.app.client_manager.compute.api_version = 2.54
|
||||
with mock.patch.object(sdk_utils,
|
||||
'supports_microversion',
|
||||
return_value=False):
|
||||
self.assertRaises(exceptions.CommandError, self.cmd.take_action,
|
||||
parsed_args)
|
||||
with mock.patch.object(
|
||||
sdk_utils, 'supports_microversion', return_value=False
|
||||
):
|
||||
self.assertRaises(
|
||||
exceptions.CommandError, self.cmd.take_action, parsed_args
|
||||
)
|
||||
|
||||
def test_flavor_set_description_using_name_api_newer(self):
|
||||
arglist = [
|
||||
'--description', 'description',
|
||||
'--description',
|
||||
'description',
|
||||
self.flavor.name,
|
||||
]
|
||||
verifylist = [
|
||||
@ -914,17 +950,19 @@ class TestFlavorSet(TestFlavor):
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
self.app.client_manager.compute.api_version = 2.55
|
||||
|
||||
with mock.patch.object(sdk_utils,
|
||||
'supports_microversion',
|
||||
return_value=True):
|
||||
with mock.patch.object(
|
||||
sdk_utils, 'supports_microversion', return_value=True
|
||||
):
|
||||
result = self.cmd.take_action(parsed_args)
|
||||
self.sdk_client.update_flavor.assert_called_with(
|
||||
flavor=self.flavor.id, description='description')
|
||||
flavor=self.flavor.id, description='description'
|
||||
)
|
||||
self.assertIsNone(result)
|
||||
|
||||
def test_flavor_set_description_using_name_api_older(self):
|
||||
arglist = [
|
||||
'--description', 'description',
|
||||
'--description',
|
||||
'description',
|
||||
self.flavor.name,
|
||||
]
|
||||
verifylist = [
|
||||
@ -934,15 +972,15 @@ class TestFlavorSet(TestFlavor):
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
self.app.client_manager.compute.api_version = 2.54
|
||||
|
||||
with mock.patch.object(sdk_utils,
|
||||
'supports_microversion',
|
||||
return_value=False):
|
||||
self.assertRaises(exceptions.CommandError, self.cmd.take_action,
|
||||
parsed_args)
|
||||
with mock.patch.object(
|
||||
sdk_utils, 'supports_microversion', return_value=False
|
||||
):
|
||||
self.assertRaises(
|
||||
exceptions.CommandError, self.cmd.take_action, parsed_args
|
||||
)
|
||||
|
||||
|
||||
class TestFlavorShow(TestFlavor):
|
||||
|
||||
# Return value of self.sdk_client.find_flavor().
|
||||
flavor_access = compute_fakes.FakeFlavorAccess.create_one_flavor_access()
|
||||
flavor = compute_fakes.FakeFlavor.create_one_flavor()
|
||||
@ -960,7 +998,7 @@ class TestFlavorShow(TestFlavor):
|
||||
'ram',
|
||||
'rxtx_factor',
|
||||
'swap',
|
||||
'vcpus'
|
||||
'vcpus',
|
||||
)
|
||||
|
||||
data = (
|
||||
@ -992,8 +1030,13 @@ class TestFlavorShow(TestFlavor):
|
||||
verifylist = []
|
||||
|
||||
# Missing required args should boil here
|
||||
self.assertRaises(tests_utils.ParserException, self.check_parser,
|
||||
self.cmd, arglist, verifylist)
|
||||
self.assertRaises(
|
||||
tests_utils.ParserException,
|
||||
self.check_parser,
|
||||
self.cmd,
|
||||
arglist,
|
||||
verifylist,
|
||||
)
|
||||
|
||||
def test_public_flavor_show(self):
|
||||
arglist = [
|
||||
@ -1046,16 +1089,17 @@ class TestFlavorShow(TestFlavor):
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
|
||||
self.sdk_client.get_flavor_access.assert_called_with(
|
||||
flavor=private_flavor.id)
|
||||
flavor=private_flavor.id
|
||||
)
|
||||
self.assertEqual(self.columns, columns)
|
||||
self.assertCountEqual(data_with_project, data)
|
||||
|
||||
|
||||
class TestFlavorUnset(TestFlavor):
|
||||
|
||||
# Return value of self.sdk_client.find_flavor().
|
||||
flavor = compute_fakes.FakeFlavor.create_one_flavor(
|
||||
attrs={'os-flavor-access:is_public': False})
|
||||
attrs={'os-flavor-access:is_public': False}
|
||||
)
|
||||
project = identity_fakes.FakeProject.create_one_project()
|
||||
|
||||
def setUp(self):
|
||||
@ -1069,10 +1113,7 @@ class TestFlavorUnset(TestFlavor):
|
||||
self.mock_shortcut = self.sdk_client.delete_flavor_extra_specs_property
|
||||
|
||||
def test_flavor_unset_property(self):
|
||||
arglist = [
|
||||
'--property', 'property',
|
||||
'baremetal'
|
||||
]
|
||||
arglist = ['--property', 'property', 'baremetal']
|
||||
verifylist = [
|
||||
('properties', ['property']),
|
||||
('flavor', 'baremetal'),
|
||||
@ -1081,19 +1122,19 @@ class TestFlavorUnset(TestFlavor):
|
||||
|
||||
result = self.cmd.take_action(parsed_args)
|
||||
self.sdk_client.find_flavor.assert_called_with(
|
||||
parsed_args.flavor,
|
||||
get_extra_specs=True,
|
||||
ignore_missing=False)
|
||||
self.mock_shortcut.assert_called_with(
|
||||
self.flavor.id, 'property')
|
||||
parsed_args.flavor, get_extra_specs=True, ignore_missing=False
|
||||
)
|
||||
self.mock_shortcut.assert_called_with(self.flavor.id, 'property')
|
||||
self.sdk_client.flavor_remove_tenant_access.assert_not_called()
|
||||
self.assertIsNone(result)
|
||||
|
||||
def test_flavor_unset_properties(self):
|
||||
arglist = [
|
||||
'--property', 'property1',
|
||||
'--property', 'property2',
|
||||
'baremetal'
|
||||
'--property',
|
||||
'property1',
|
||||
'--property',
|
||||
'property2',
|
||||
'baremetal',
|
||||
]
|
||||
verifylist = [
|
||||
('properties', ['property1', 'property2']),
|
||||
@ -1103,29 +1144,26 @@ class TestFlavorUnset(TestFlavor):
|
||||
|
||||
self.cmd.take_action(parsed_args)
|
||||
self.sdk_client.find_flavor.assert_called_with(
|
||||
parsed_args.flavor,
|
||||
get_extra_specs=True,
|
||||
ignore_missing=False)
|
||||
parsed_args.flavor, get_extra_specs=True, ignore_missing=False
|
||||
)
|
||||
calls = [
|
||||
mock.call(self.flavor.id, 'property1'),
|
||||
mock.call(self.flavor.id, 'property2')
|
||||
mock.call(self.flavor.id, 'property2'),
|
||||
]
|
||||
self.mock_shortcut.assert_has_calls(
|
||||
calls)
|
||||
self.mock_shortcut.assert_has_calls(calls)
|
||||
|
||||
# A bit tricky way to ensure we do not unset other properties
|
||||
calls.append(mock.call(self.flavor.id, 'property'))
|
||||
self.assertRaises(
|
||||
AssertionError,
|
||||
self.mock_shortcut.assert_has_calls,
|
||||
calls
|
||||
AssertionError, self.mock_shortcut.assert_has_calls, calls
|
||||
)
|
||||
|
||||
self.sdk_client.flavor_remove_tenant_access.assert_not_called()
|
||||
|
||||
def test_flavor_unset_project(self):
|
||||
arglist = [
|
||||
'--project', self.project.id,
|
||||
'--project',
|
||||
self.project.id,
|
||||
self.flavor.id,
|
||||
]
|
||||
verifylist = [
|
||||
@ -1138,8 +1176,8 @@ class TestFlavorUnset(TestFlavor):
|
||||
self.assertIsNone(result)
|
||||
|
||||
self.sdk_client.find_flavor.assert_called_with(
|
||||
parsed_args.flavor, get_extra_specs=True,
|
||||
ignore_missing=False)
|
||||
parsed_args.flavor, get_extra_specs=True, ignore_missing=False
|
||||
)
|
||||
self.sdk_client.flavor_remove_tenant_access.assert_called_with(
|
||||
self.flavor.id,
|
||||
self.project.id,
|
||||
@ -1156,18 +1194,29 @@ class TestFlavorUnset(TestFlavor):
|
||||
('project', None),
|
||||
('flavor', self.flavor.id),
|
||||
]
|
||||
self.assertRaises(tests_utils.ParserException, self.check_parser,
|
||||
self.cmd, arglist, verifylist)
|
||||
self.assertRaises(
|
||||
tests_utils.ParserException,
|
||||
self.check_parser,
|
||||
self.cmd,
|
||||
arglist,
|
||||
verifylist,
|
||||
)
|
||||
|
||||
def test_flavor_unset_no_flavor(self):
|
||||
arglist = [
|
||||
'--project', self.project.id,
|
||||
'--project',
|
||||
self.project.id,
|
||||
]
|
||||
verifylist = [
|
||||
('project', self.project.id),
|
||||
]
|
||||
self.assertRaises(tests_utils.ParserException, self.check_parser,
|
||||
self.cmd, arglist, verifylist)
|
||||
self.assertRaises(
|
||||
tests_utils.ParserException,
|
||||
self.check_parser,
|
||||
self.cmd,
|
||||
arglist,
|
||||
verifylist,
|
||||
)
|
||||
|
||||
def test_flavor_unset_with_unexist_flavor(self):
|
||||
self.sdk_client.find_flavor.side_effect = [
|
||||
@ -1175,7 +1224,8 @@ class TestFlavorUnset(TestFlavor):
|
||||
]
|
||||
|
||||
arglist = [
|
||||
'--project', self.project.id,
|
||||
'--project',
|
||||
self.project.id,
|
||||
'unexist_flavor',
|
||||
]
|
||||
verifylist = [
|
||||
@ -1183,8 +1233,9 @@ class TestFlavorUnset(TestFlavor):
|
||||
('flavor', 'unexist_flavor'),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
self.assertRaises(exceptions.CommandError, self.cmd.take_action,
|
||||
parsed_args)
|
||||
self.assertRaises(
|
||||
exceptions.CommandError, self.cmd.take_action, parsed_args
|
||||
)
|
||||
|
||||
def test_flavor_unset_nothing(self):
|
||||
arglist = [
|
||||
|
@ -22,7 +22,6 @@ from openstackclient.tests.unit import utils as tests_utils
|
||||
|
||||
|
||||
class TestHost(compute_fakes.TestComputev2):
|
||||
|
||||
def setUp(self):
|
||||
super(TestHost, self).setUp()
|
||||
|
||||
@ -33,11 +32,8 @@ class TestHost(compute_fakes.TestComputev2):
|
||||
self.sdk_client.get = mock.Mock()
|
||||
|
||||
|
||||
@mock.patch(
|
||||
'openstackclient.api.compute_v2.APIv2.host_list'
|
||||
)
|
||||
@mock.patch('openstackclient.api.compute_v2.APIv2.host_list')
|
||||
class TestHostList(TestHost):
|
||||
|
||||
_host = compute_fakes.FakeHost.create_one_host()
|
||||
|
||||
def setUp(self):
|
||||
@ -47,15 +43,15 @@ class TestHostList(TestHost):
|
||||
data={'hosts': [self._host]}
|
||||
)
|
||||
|
||||
self.columns = (
|
||||
'Host Name', 'Service', 'Zone'
|
||||
)
|
||||
self.columns = ('Host Name', 'Service', 'Zone')
|
||||
|
||||
self.data = [(
|
||||
self._host['host_name'],
|
||||
self._host['service'],
|
||||
self._host['zone'],
|
||||
)]
|
||||
self.data = [
|
||||
(
|
||||
self._host['host_name'],
|
||||
self._host['service'],
|
||||
self._host['zone'],
|
||||
)
|
||||
]
|
||||
|
||||
self.cmd = host.ListHost(self.app, None)
|
||||
|
||||
@ -75,7 +71,8 @@ class TestHostList(TestHost):
|
||||
def test_host_list_with_option(self, h_mock):
|
||||
h_mock.return_value = [self._host]
|
||||
arglist = [
|
||||
'--zone', self._host['zone'],
|
||||
'--zone',
|
||||
self._host['zone'],
|
||||
]
|
||||
verifylist = [
|
||||
('zone', self._host['zone']),
|
||||
@ -90,11 +87,8 @@ class TestHostList(TestHost):
|
||||
self.assertEqual(self.data, list(data))
|
||||
|
||||
|
||||
@mock.patch(
|
||||
'openstackclient.api.compute_v2.APIv2.host_set'
|
||||
)
|
||||
@mock.patch('openstackclient.api.compute_v2.APIv2.host_set')
|
||||
class TestHostSet(TestHost):
|
||||
|
||||
def setUp(self):
|
||||
super(TestHostSet, self).setUp()
|
||||
|
||||
@ -138,27 +132,27 @@ class TestHostSet(TestHost):
|
||||
result = self.cmd.take_action(parsed_args)
|
||||
self.assertIsNone(result)
|
||||
|
||||
h_mock.assert_called_with(self.host['host'], status='enable',
|
||||
maintenance_mode='disable')
|
||||
h_mock.assert_called_with(
|
||||
self.host['host'], status='enable', maintenance_mode='disable'
|
||||
)
|
||||
|
||||
|
||||
@mock.patch(
|
||||
'openstackclient.api.compute_v2.APIv2.host_show'
|
||||
)
|
||||
@mock.patch('openstackclient.api.compute_v2.APIv2.host_show')
|
||||
class TestHostShow(TestHost):
|
||||
|
||||
_host = compute_fakes.FakeHost.create_one_host()
|
||||
|
||||
def setUp(self):
|
||||
super(TestHostShow, self).setUp()
|
||||
|
||||
output_data = {"resource": {
|
||||
"host": self._host['host'],
|
||||
"project": self._host['project'],
|
||||
"cpu": self._host['cpu'],
|
||||
"memory_mb": self._host['memory_mb'],
|
||||
"disk_gb": self._host['disk_gb']
|
||||
}}
|
||||
output_data = {
|
||||
"resource": {
|
||||
"host": self._host['host'],
|
||||
"project": self._host['project'],
|
||||
"cpu": self._host['cpu'],
|
||||
"memory_mb": self._host['memory_mb'],
|
||||
"disk_gb": self._host['disk_gb'],
|
||||
}
|
||||
}
|
||||
|
||||
self.sdk_client.get.return_value = fakes.FakeResponse(
|
||||
data={'host': [output_data]}
|
||||
@ -172,13 +166,15 @@ class TestHostShow(TestHost):
|
||||
'Disk GB',
|
||||
)
|
||||
|
||||
self.data = [(
|
||||
self._host['host'],
|
||||
self._host['project'],
|
||||
self._host['cpu'],
|
||||
self._host['memory_mb'],
|
||||
self._host['disk_gb'],
|
||||
)]
|
||||
self.data = [
|
||||
(
|
||||
self._host['host'],
|
||||
self._host['project'],
|
||||
self._host['cpu'],
|
||||
self._host['memory_mb'],
|
||||
self._host['disk_gb'],
|
||||
)
|
||||
]
|
||||
|
||||
self.cmd = host.ShowHost(self.app, None)
|
||||
|
||||
@ -188,8 +184,13 @@ class TestHostShow(TestHost):
|
||||
verifylist = []
|
||||
|
||||
# Missing required args should bail here
|
||||
self.assertRaises(tests_utils.ParserException, self.check_parser,
|
||||
self.cmd, arglist, verifylist)
|
||||
self.assertRaises(
|
||||
tests_utils.ParserException,
|
||||
self.check_parser,
|
||||
self.cmd,
|
||||
arglist,
|
||||
verifylist,
|
||||
)
|
||||
|
||||
def test_host_show_with_option(self, h_mock):
|
||||
h_mock.return_value = [self._host]
|
||||
@ -205,8 +206,7 @@ class TestHostShow(TestHost):
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
|
||||
self.sdk_client.get.assert_called_with(
|
||||
'/os-hosts/' + self._host['host_name'],
|
||||
microversion='2.1'
|
||||
'/os-hosts/' + self._host['host_name'], microversion='2.1'
|
||||
)
|
||||
self.assertEqual(self.columns, columns)
|
||||
self.assertEqual(self.data, list(data))
|
||||
|
@ -26,7 +26,6 @@ from openstackclient.tests.unit.compute.v2 import fakes as compute_fakes
|
||||
|
||||
|
||||
class TestHypervisor(compute_fakes.TestComputev2):
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
|
||||
@ -37,7 +36,6 @@ class TestHypervisor(compute_fakes.TestComputev2):
|
||||
|
||||
|
||||
class TestHypervisorList(TestHypervisor):
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
|
||||
@ -50,7 +48,7 @@ class TestHypervisorList(TestHypervisor):
|
||||
"Hypervisor Hostname",
|
||||
"Hypervisor Type",
|
||||
"Host IP",
|
||||
"State"
|
||||
"State",
|
||||
)
|
||||
self.columns_long = (
|
||||
"ID",
|
||||
@ -61,7 +59,7 @@ class TestHypervisorList(TestHypervisor):
|
||||
"vCPUs Used",
|
||||
"vCPUs",
|
||||
"Memory MB Used",
|
||||
"Memory MB"
|
||||
"Memory MB",
|
||||
)
|
||||
self.data = (
|
||||
(
|
||||
@ -69,14 +67,14 @@ class TestHypervisorList(TestHypervisor):
|
||||
self.hypervisors[0].name,
|
||||
self.hypervisors[0].hypervisor_type,
|
||||
self.hypervisors[0].host_ip,
|
||||
self.hypervisors[0].state
|
||||
self.hypervisors[0].state,
|
||||
),
|
||||
(
|
||||
self.hypervisors[1].id,
|
||||
self.hypervisors[1].name,
|
||||
self.hypervisors[1].hypervisor_type,
|
||||
self.hypervisors[1].host_ip,
|
||||
self.hypervisors[1].state
|
||||
self.hypervisors[1].state,
|
||||
),
|
||||
)
|
||||
|
||||
@ -90,7 +88,7 @@ class TestHypervisorList(TestHypervisor):
|
||||
self.hypervisors[0].vcpus_used,
|
||||
self.hypervisors[0].vcpus,
|
||||
self.hypervisors[0].memory_used,
|
||||
self.hypervisors[0].memory_size
|
||||
self.hypervisors[0].memory_size,
|
||||
),
|
||||
(
|
||||
self.hypervisors[1].id,
|
||||
@ -101,7 +99,7 @@ class TestHypervisorList(TestHypervisor):
|
||||
self.hypervisors[1].vcpus_used,
|
||||
self.hypervisors[1].vcpus,
|
||||
self.hypervisors[1].memory_used,
|
||||
self.hypervisors[1].memory_size
|
||||
self.hypervisors[1].memory_size,
|
||||
),
|
||||
)
|
||||
# Get the command object to test
|
||||
@ -123,7 +121,8 @@ class TestHypervisorList(TestHypervisor):
|
||||
|
||||
def test_hypervisor_list_matching_option_found(self):
|
||||
arglist = [
|
||||
'--matching', self.hypervisors[0].name,
|
||||
'--matching',
|
||||
self.hypervisors[0].name,
|
||||
]
|
||||
verifylist = [
|
||||
('matching', self.hypervisors[0].name),
|
||||
@ -149,14 +148,15 @@ class TestHypervisorList(TestHypervisor):
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
|
||||
self.sdk_client.hypervisors.assert_called_with(
|
||||
hypervisor_hostname_pattern=self.hypervisors[0].name,
|
||||
details=True)
|
||||
hypervisor_hostname_pattern=self.hypervisors[0].name, details=True
|
||||
)
|
||||
self.assertEqual(self.columns, columns)
|
||||
self.assertEqual(self.data, tuple(data))
|
||||
|
||||
def test_hypervisor_list_matching_option_not_found(self):
|
||||
arglist = [
|
||||
'--matching', 'xxx',
|
||||
'--matching',
|
||||
'xxx',
|
||||
]
|
||||
verifylist = [
|
||||
('matching', 'xxx'),
|
||||
@ -164,20 +164,23 @@ class TestHypervisorList(TestHypervisor):
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
# Fake exception raised from search()
|
||||
self.sdk_client.hypervisors.side_effect = \
|
||||
exceptions.NotFound(None)
|
||||
self.sdk_client.hypervisors.side_effect = exceptions.NotFound(None)
|
||||
|
||||
self.assertRaises(exceptions.NotFound,
|
||||
self.cmd.take_action,
|
||||
parsed_args)
|
||||
self.assertRaises(
|
||||
exceptions.NotFound, self.cmd.take_action, parsed_args
|
||||
)
|
||||
|
||||
@mock.patch.object(sdk_utils, 'supports_microversion', return_value=False)
|
||||
def test_hypervisor_list_with_matching_and_pagination_options(
|
||||
self, sm_mock):
|
||||
self, sm_mock
|
||||
):
|
||||
arglist = [
|
||||
'--matching', self.hypervisors[0].name,
|
||||
'--limit', '1',
|
||||
'--marker', self.hypervisors[0].name,
|
||||
'--matching',
|
||||
self.hypervisors[0].name,
|
||||
'--limit',
|
||||
'1',
|
||||
'--marker',
|
||||
self.hypervisors[0].name,
|
||||
]
|
||||
verifylist = [
|
||||
('matching', self.hypervisors[0].name),
|
||||
@ -187,12 +190,12 @@ class TestHypervisorList(TestHypervisor):
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
ex = self.assertRaises(
|
||||
exceptions.CommandError,
|
||||
self.cmd.take_action,
|
||||
parsed_args)
|
||||
exceptions.CommandError, self.cmd.take_action, parsed_args
|
||||
)
|
||||
|
||||
self.assertIn(
|
||||
'--matching is not compatible with --marker or --limit', str(ex))
|
||||
'--matching is not compatible with --marker or --limit', str(ex)
|
||||
)
|
||||
|
||||
@mock.patch.object(sdk_utils, 'supports_microversion', return_value=False)
|
||||
def test_hypervisor_list_long_option(self, sm_mock):
|
||||
@ -216,7 +219,8 @@ class TestHypervisorList(TestHypervisor):
|
||||
@mock.patch.object(sdk_utils, 'supports_microversion', return_value=True)
|
||||
def test_hypervisor_list_with_limit(self, sm_mock):
|
||||
arglist = [
|
||||
'--limit', '1',
|
||||
'--limit',
|
||||
'1',
|
||||
]
|
||||
verifylist = [
|
||||
('limit', 1),
|
||||
@ -230,7 +234,8 @@ class TestHypervisorList(TestHypervisor):
|
||||
@mock.patch.object(sdk_utils, 'supports_microversion', return_value=False)
|
||||
def test_hypervisor_list_with_limit_pre_v233(self, sm_mock):
|
||||
arglist = [
|
||||
'--limit', '1',
|
||||
'--limit',
|
||||
'1',
|
||||
]
|
||||
verifylist = [
|
||||
('limit', 1),
|
||||
@ -238,17 +243,18 @@ class TestHypervisorList(TestHypervisor):
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
ex = self.assertRaises(
|
||||
exceptions.CommandError,
|
||||
self.cmd.take_action,
|
||||
parsed_args)
|
||||
exceptions.CommandError, self.cmd.take_action, parsed_args
|
||||
)
|
||||
|
||||
self.assertIn(
|
||||
'--os-compute-api-version 2.33 or greater is required', str(ex))
|
||||
'--os-compute-api-version 2.33 or greater is required', str(ex)
|
||||
)
|
||||
|
||||
@mock.patch.object(sdk_utils, 'supports_microversion', return_value=True)
|
||||
def test_hypervisor_list_with_marker(self, sm_mock):
|
||||
arglist = [
|
||||
'--marker', 'test_hyp',
|
||||
'--marker',
|
||||
'test_hyp',
|
||||
]
|
||||
verifylist = [
|
||||
('marker', 'test_hyp'),
|
||||
@ -258,12 +264,14 @@ class TestHypervisorList(TestHypervisor):
|
||||
self.cmd.take_action(parsed_args)
|
||||
|
||||
self.sdk_client.hypervisors.assert_called_with(
|
||||
marker='test_hyp', details=True)
|
||||
marker='test_hyp', details=True
|
||||
)
|
||||
|
||||
@mock.patch.object(sdk_utils, 'supports_microversion', return_value=False)
|
||||
def test_hypervisor_list_with_marker_pre_v233(self, sm_mock):
|
||||
arglist = [
|
||||
'--marker', 'test_hyp',
|
||||
'--marker',
|
||||
'test_hyp',
|
||||
]
|
||||
verifylist = [
|
||||
('marker', 'test_hyp'),
|
||||
@ -271,26 +279,29 @@ class TestHypervisorList(TestHypervisor):
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
ex = self.assertRaises(
|
||||
exceptions.CommandError,
|
||||
self.cmd.take_action,
|
||||
parsed_args)
|
||||
exceptions.CommandError, self.cmd.take_action, parsed_args
|
||||
)
|
||||
|
||||
self.assertIn(
|
||||
'--os-compute-api-version 2.33 or greater is required', str(ex))
|
||||
'--os-compute-api-version 2.33 or greater is required', str(ex)
|
||||
)
|
||||
|
||||
|
||||
class TestHypervisorShow(TestHypervisor):
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
|
||||
uptime_string = (' 01:28:24 up 3 days, 11:15, 1 user, '
|
||||
' load average: 0.94, 0.62, 0.50\n')
|
||||
uptime_string = (
|
||||
' 01:28:24 up 3 days, 11:15, 1 user, '
|
||||
' load average: 0.94, 0.62, 0.50\n'
|
||||
)
|
||||
|
||||
# Fake hypervisors to be listed up
|
||||
self.hypervisor = compute_fakes.create_one_hypervisor(attrs={
|
||||
'uptime': uptime_string,
|
||||
})
|
||||
self.hypervisor = compute_fakes.create_one_hypervisor(
|
||||
attrs={
|
||||
'uptime': uptime_string,
|
||||
}
|
||||
)
|
||||
|
||||
# Return value of compute_client.find_hypervisor
|
||||
self.sdk_client.find_hypervisor.return_value = self.hypervisor
|
||||
@ -422,8 +433,9 @@ class TestHypervisorShow(TestHypervisor):
|
||||
self.assertEqual(self.columns_v288, columns)
|
||||
self.assertCountEqual(self.data_v288, data)
|
||||
|
||||
@mock.patch.object(sdk_utils, 'supports_microversion',
|
||||
side_effect=[False, True, False])
|
||||
@mock.patch.object(
|
||||
sdk_utils, 'supports_microversion', side_effect=[False, True, False]
|
||||
)
|
||||
def test_hypervisor_show_pre_v288(self, sm_mock):
|
||||
arglist = [
|
||||
self.hypervisor.name,
|
||||
@ -445,8 +457,7 @@ class TestHypervisorShow(TestHypervisor):
|
||||
def test_hypervisor_show_pre_v228(self, sm_mock):
|
||||
# before microversion 2.28, nova returned a stringified version of this
|
||||
# field
|
||||
self.hypervisor.cpu_info = json.dumps(
|
||||
self.hypervisor.cpu_info)
|
||||
self.hypervisor.cpu_info = json.dumps(self.hypervisor.cpu_info)
|
||||
self.sdk_client.find_hypervisor.return_value = self.hypervisor
|
||||
|
||||
arglist = [
|
||||
@ -465,8 +476,9 @@ class TestHypervisorShow(TestHypervisor):
|
||||
self.assertEqual(self.columns, columns)
|
||||
self.assertCountEqual(self.data, data)
|
||||
|
||||
@mock.patch.object(sdk_utils, 'supports_microversion',
|
||||
side_effect=[False, True, False])
|
||||
@mock.patch.object(
|
||||
sdk_utils, 'supports_microversion', side_effect=[False, True, False]
|
||||
)
|
||||
def test_hypervisor_show_uptime_not_implemented(self, sm_mock):
|
||||
arglist = [
|
||||
self.hypervisor.name,
|
||||
@ -477,7 +489,8 @@ class TestHypervisorShow(TestHypervisor):
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
self.sdk_client.get_hypervisor_uptime.side_effect = (
|
||||
nova_exceptions.HTTPNotImplemented(501))
|
||||
nova_exceptions.HTTPNotImplemented(501)
|
||||
)
|
||||
|
||||
# In base command class ShowOne in cliff, abstract method take_action()
|
||||
# returns a two-part tuple with a tuple of column names and a tuple of
|
||||
|
@ -20,7 +20,6 @@ from openstackclient.tests.unit import fakes
|
||||
|
||||
|
||||
class TestHypervisorStats(compute_fakes.TestComputev2):
|
||||
|
||||
def setUp(self):
|
||||
super(TestHypervisorStats, self).setUp()
|
||||
|
||||
@ -33,6 +32,7 @@ class TestHypervisorStats(compute_fakes.TestComputev2):
|
||||
|
||||
# Not in fakes.py because hypervisor stats has been deprecated
|
||||
|
||||
|
||||
def create_one_hypervisor_stats(attrs=None):
|
||||
"""Create a fake hypervisor stats.
|
||||
|
||||
@ -66,14 +66,14 @@ def create_one_hypervisor_stats(attrs=None):
|
||||
|
||||
|
||||
class TestHypervisorStatsShow(TestHypervisorStats):
|
||||
|
||||
_stats = create_one_hypervisor_stats()
|
||||
|
||||
def setUp(self):
|
||||
super(TestHypervisorStatsShow, self).setUp()
|
||||
|
||||
self.sdk_client.get.return_value = fakes.FakeResponse(
|
||||
data={'hypervisor_statistics': self._stats})
|
||||
data={'hypervisor_statistics': self._stats}
|
||||
)
|
||||
|
||||
self.cmd = hypervisor_stats.ShowHypervisorStats(self.app, None)
|
||||
|
||||
|
@ -30,7 +30,6 @@ from openstackclient.tests.unit import utils as tests_utils
|
||||
|
||||
|
||||
class TestKeypair(compute_fakes.TestComputev2):
|
||||
|
||||
def setUp(self):
|
||||
super(TestKeypair, self).setUp()
|
||||
|
||||
@ -53,23 +52,17 @@ class TestKeypair(compute_fakes.TestComputev2):
|
||||
|
||||
|
||||
class TestKeypairCreate(TestKeypair):
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
|
||||
self.keypair = compute_fakes.FakeKeypair.create_one_keypair()
|
||||
|
||||
self.columns = (
|
||||
'fingerprint',
|
||||
'name',
|
||||
'type',
|
||||
'user_id'
|
||||
)
|
||||
self.columns = ('fingerprint', 'name', 'type', 'user_id')
|
||||
self.data = (
|
||||
self.keypair.fingerprint,
|
||||
self.keypair.name,
|
||||
self.keypair.type,
|
||||
self.keypair.user_id
|
||||
self.keypair.user_id,
|
||||
)
|
||||
|
||||
# Get the command object to test
|
||||
@ -78,7 +71,8 @@ class TestKeypairCreate(TestKeypair):
|
||||
self.sdk_client.create_keypair.return_value = self.keypair
|
||||
|
||||
@mock.patch.object(
|
||||
keypair, '_generate_keypair',
|
||||
keypair,
|
||||
'_generate_keypair',
|
||||
return_value=keypair.Keypair('private', 'public'),
|
||||
)
|
||||
def test_key_pair_create_no_options(self, mock_generate):
|
||||
@ -105,11 +99,12 @@ class TestKeypairCreate(TestKeypair):
|
||||
self.keypair.fingerprint,
|
||||
self.keypair.name,
|
||||
self.keypair.type,
|
||||
self.keypair.user_id
|
||||
self.keypair.user_id,
|
||||
)
|
||||
|
||||
arglist = [
|
||||
'--public-key', self.keypair.public_key,
|
||||
'--public-key',
|
||||
self.keypair.public_key,
|
||||
self.keypair.name,
|
||||
]
|
||||
verifylist = [
|
||||
@ -135,13 +130,15 @@ class TestKeypairCreate(TestKeypair):
|
||||
self.assertEqual(self.data, data)
|
||||
|
||||
@mock.patch.object(
|
||||
keypair, '_generate_keypair',
|
||||
keypair,
|
||||
'_generate_keypair',
|
||||
return_value=keypair.Keypair('private', 'public'),
|
||||
)
|
||||
def test_keypair_create_private_key(self, mock_generate):
|
||||
tmp_pk_file = '/tmp/kp-file-' + uuid.uuid4().hex
|
||||
arglist = [
|
||||
'--private-key', tmp_pk_file,
|
||||
'--private-key',
|
||||
tmp_pk_file,
|
||||
self.keypair.name,
|
||||
]
|
||||
verifylist = [
|
||||
@ -182,9 +179,11 @@ class TestKeypairCreate(TestKeypair):
|
||||
self.keypair.user_id,
|
||||
)
|
||||
arglist = [
|
||||
'--public-key', self.keypair.public_key,
|
||||
'--public-key',
|
||||
self.keypair.public_key,
|
||||
self.keypair.name,
|
||||
'--type', key_type,
|
||||
'--type',
|
||||
key_type,
|
||||
]
|
||||
verifylist = [
|
||||
('public_key', self.keypair.public_key),
|
||||
@ -212,9 +211,11 @@ class TestKeypairCreate(TestKeypair):
|
||||
def test_keypair_create_with_key_type_pre_v22(self, sm_mock):
|
||||
for key_type in ['x509', 'ssh']:
|
||||
arglist = [
|
||||
'--public-key', self.keypair.public_key,
|
||||
'--public-key',
|
||||
self.keypair.public_key,
|
||||
self.keypair.name,
|
||||
'--type', 'ssh',
|
||||
'--type',
|
||||
'ssh',
|
||||
]
|
||||
verifylist = [
|
||||
('public_key', self.keypair.public_key),
|
||||
@ -229,22 +230,23 @@ class TestKeypairCreate(TestKeypair):
|
||||
m_file.read.return_value = 'dummy'
|
||||
|
||||
ex = self.assertRaises(
|
||||
exceptions.CommandError,
|
||||
self.cmd.take_action,
|
||||
parsed_args)
|
||||
exceptions.CommandError, self.cmd.take_action, parsed_args
|
||||
)
|
||||
|
||||
self.assertIn(
|
||||
'--os-compute-api-version 2.2 or greater is required',
|
||||
str(ex))
|
||||
'--os-compute-api-version 2.2 or greater is required', str(ex)
|
||||
)
|
||||
|
||||
@mock.patch.object(
|
||||
keypair, '_generate_keypair',
|
||||
keypair,
|
||||
'_generate_keypair',
|
||||
return_value=keypair.Keypair('private', 'public'),
|
||||
)
|
||||
@mock.patch.object(sdk_utils, 'supports_microversion', return_value=True)
|
||||
def test_key_pair_create_with_user(self, sm_mock, mock_generate):
|
||||
arglist = [
|
||||
'--user', identity_fakes.user_name,
|
||||
'--user',
|
||||
identity_fakes.user_name,
|
||||
self.keypair.name,
|
||||
]
|
||||
verifylist = [
|
||||
@ -267,7 +269,8 @@ class TestKeypairCreate(TestKeypair):
|
||||
@mock.patch.object(sdk_utils, 'supports_microversion', return_value=False)
|
||||
def test_key_pair_create_with_user_pre_v210(self, sm_mock):
|
||||
arglist = [
|
||||
'--user', identity_fakes.user_name,
|
||||
'--user',
|
||||
identity_fakes.user_name,
|
||||
self.keypair.name,
|
||||
]
|
||||
verifylist = [
|
||||
@ -277,15 +280,14 @@ class TestKeypairCreate(TestKeypair):
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
ex = self.assertRaises(
|
||||
exceptions.CommandError,
|
||||
self.cmd.take_action,
|
||||
parsed_args)
|
||||
exceptions.CommandError, self.cmd.take_action, parsed_args
|
||||
)
|
||||
self.assertIn(
|
||||
'--os-compute-api-version 2.10 or greater is required', str(ex))
|
||||
'--os-compute-api-version 2.10 or greater is required', str(ex)
|
||||
)
|
||||
|
||||
|
||||
class TestKeypairDelete(TestKeypair):
|
||||
|
||||
keypairs = compute_fakes.FakeKeypair.create_keypairs(count=2)
|
||||
|
||||
def setUp(self):
|
||||
@ -294,9 +296,7 @@ class TestKeypairDelete(TestKeypair):
|
||||
self.cmd = keypair.DeleteKeypair(self.app, None)
|
||||
|
||||
def test_keypair_delete(self):
|
||||
arglist = [
|
||||
self.keypairs[0].name
|
||||
]
|
||||
arglist = [self.keypairs[0].name]
|
||||
verifylist = [
|
||||
('name', [self.keypairs[0].name]),
|
||||
]
|
||||
@ -307,7 +307,8 @@ class TestKeypairDelete(TestKeypair):
|
||||
|
||||
self.assertIsNone(ret)
|
||||
self.sdk_client.delete_keypair.assert_called_with(
|
||||
self.keypairs[0].name, ignore_missing=False)
|
||||
self.keypairs[0].name, ignore_missing=False
|
||||
)
|
||||
|
||||
def test_delete_multiple_keypairs(self):
|
||||
arglist = []
|
||||
@ -338,7 +339,9 @@ class TestKeypairDelete(TestKeypair):
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
self.sdk_client.delete_keypair.side_effect = [
|
||||
None, exceptions.CommandError]
|
||||
None,
|
||||
exceptions.CommandError,
|
||||
]
|
||||
try:
|
||||
self.cmd.take_action(parsed_args)
|
||||
self.fail('CommandError should be raised.')
|
||||
@ -352,10 +355,7 @@ class TestKeypairDelete(TestKeypair):
|
||||
|
||||
@mock.patch.object(sdk_utils, 'supports_microversion', return_value=True)
|
||||
def test_keypair_delete_with_user(self, sm_mock):
|
||||
arglist = [
|
||||
'--user', identity_fakes.user_name,
|
||||
self.keypairs[0].name
|
||||
]
|
||||
arglist = ['--user', identity_fakes.user_name, self.keypairs[0].name]
|
||||
verifylist = [
|
||||
('user', identity_fakes.user_name),
|
||||
('name', [self.keypairs[0].name]),
|
||||
@ -368,19 +368,16 @@ class TestKeypairDelete(TestKeypair):
|
||||
self.sdk_client.delete_keypair.assert_called_with(
|
||||
self.keypairs[0].name,
|
||||
user_id=identity_fakes.user_id,
|
||||
ignore_missing=False
|
||||
ignore_missing=False,
|
||||
)
|
||||
|
||||
@mock.patch.object(sdk_utils, 'supports_microversion', return_value=False)
|
||||
def test_keypair_delete_with_user_pre_v210(self, sm_mock):
|
||||
self.app.client_manager.compute.api_version = api_versions.APIVersion(
|
||||
'2.9'
|
||||
)
|
||||
|
||||
self.app.client_manager.compute.api_version = \
|
||||
api_versions.APIVersion('2.9')
|
||||
|
||||
arglist = [
|
||||
'--user', identity_fakes.user_name,
|
||||
self.keypairs[0].name
|
||||
]
|
||||
arglist = ['--user', identity_fakes.user_name, self.keypairs[0].name]
|
||||
verifylist = [
|
||||
('user', identity_fakes.user_name),
|
||||
('name', [self.keypairs[0].name]),
|
||||
@ -388,15 +385,14 @@ class TestKeypairDelete(TestKeypair):
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
ex = self.assertRaises(
|
||||
exceptions.CommandError,
|
||||
self.cmd.take_action,
|
||||
parsed_args)
|
||||
exceptions.CommandError, self.cmd.take_action, parsed_args
|
||||
)
|
||||
self.assertIn(
|
||||
'--os-compute-api-version 2.10 or greater is required', str(ex))
|
||||
'--os-compute-api-version 2.10 or greater is required', str(ex)
|
||||
)
|
||||
|
||||
|
||||
class TestKeypairList(TestKeypair):
|
||||
|
||||
# Return value of self.sdk_client.keypairs().
|
||||
keypairs = compute_fakes.FakeKeypair.create_keypairs(count=1)
|
||||
|
||||
@ -426,8 +422,8 @@ class TestKeypairList(TestKeypair):
|
||||
|
||||
self.assertEqual(('Name', 'Fingerprint'), columns)
|
||||
self.assertEqual(
|
||||
((self.keypairs[0].name, self.keypairs[0].fingerprint), ),
|
||||
tuple(data)
|
||||
((self.keypairs[0].name, self.keypairs[0].fingerprint),),
|
||||
tuple(data),
|
||||
)
|
||||
|
||||
@mock.patch.object(sdk_utils, 'supports_microversion', return_value=True)
|
||||
@ -448,17 +444,18 @@ class TestKeypairList(TestKeypair):
|
||||
|
||||
self.assertEqual(('Name', 'Fingerprint', 'Type'), columns)
|
||||
self.assertEqual(
|
||||
((
|
||||
self.keypairs[0].name,
|
||||
self.keypairs[0].fingerprint,
|
||||
self.keypairs[0].type,
|
||||
), ),
|
||||
tuple(data)
|
||||
(
|
||||
(
|
||||
self.keypairs[0].name,
|
||||
self.keypairs[0].fingerprint,
|
||||
self.keypairs[0].type,
|
||||
),
|
||||
),
|
||||
tuple(data),
|
||||
)
|
||||
|
||||
@mock.patch.object(sdk_utils, 'supports_microversion', return_value=True)
|
||||
def test_keypair_list_with_user(self, sm_mock):
|
||||
|
||||
users_mock = self.app.client_manager.identity.users
|
||||
users_mock.reset_mock()
|
||||
users_mock.get.return_value = fakes.FakeResource(
|
||||
@ -468,7 +465,8 @@ class TestKeypairList(TestKeypair):
|
||||
)
|
||||
|
||||
arglist = [
|
||||
'--user', identity_fakes.user_name,
|
||||
'--user',
|
||||
identity_fakes.user_name,
|
||||
]
|
||||
verifylist = [
|
||||
('user', identity_fakes.user_name),
|
||||
@ -484,19 +482,21 @@ class TestKeypairList(TestKeypair):
|
||||
|
||||
self.assertEqual(('Name', 'Fingerprint', 'Type'), columns)
|
||||
self.assertEqual(
|
||||
((
|
||||
self.keypairs[0].name,
|
||||
self.keypairs[0].fingerprint,
|
||||
self.keypairs[0].type,
|
||||
), ),
|
||||
tuple(data)
|
||||
(
|
||||
(
|
||||
self.keypairs[0].name,
|
||||
self.keypairs[0].fingerprint,
|
||||
self.keypairs[0].type,
|
||||
),
|
||||
),
|
||||
tuple(data),
|
||||
)
|
||||
|
||||
@mock.patch.object(sdk_utils, 'supports_microversion', return_value=False)
|
||||
def test_keypair_list_with_user_pre_v210(self, sm_mock):
|
||||
|
||||
arglist = [
|
||||
'--user', identity_fakes.user_name,
|
||||
'--user',
|
||||
identity_fakes.user_name,
|
||||
]
|
||||
verifylist = [
|
||||
('user', identity_fakes.user_name),
|
||||
@ -504,15 +504,14 @@ class TestKeypairList(TestKeypair):
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
ex = self.assertRaises(
|
||||
exceptions.CommandError,
|
||||
self.cmd.take_action,
|
||||
parsed_args)
|
||||
exceptions.CommandError, self.cmd.take_action, parsed_args
|
||||
)
|
||||
self.assertIn(
|
||||
'--os-compute-api-version 2.10 or greater is required', str(ex))
|
||||
'--os-compute-api-version 2.10 or greater is required', str(ex)
|
||||
)
|
||||
|
||||
@mock.patch.object(sdk_utils, 'supports_microversion', return_value=True)
|
||||
def test_keypair_list_with_project(self, sm_mock):
|
||||
|
||||
projects_mock = self.app.client_manager.identity.tenants
|
||||
projects_mock.reset_mock()
|
||||
projects_mock.get.return_value = fakes.FakeResource(
|
||||
@ -545,44 +544,52 @@ class TestKeypairList(TestKeypair):
|
||||
|
||||
self.assertEqual(('Name', 'Fingerprint', 'Type'), columns)
|
||||
self.assertEqual(
|
||||
((
|
||||
self.keypairs[0].name,
|
||||
self.keypairs[0].fingerprint,
|
||||
self.keypairs[0].type,
|
||||
), ),
|
||||
tuple(data)
|
||||
(
|
||||
(
|
||||
self.keypairs[0].name,
|
||||
self.keypairs[0].fingerprint,
|
||||
self.keypairs[0].type,
|
||||
),
|
||||
),
|
||||
tuple(data),
|
||||
)
|
||||
|
||||
@mock.patch.object(sdk_utils, 'supports_microversion', return_value=False)
|
||||
def test_keypair_list_with_project_pre_v210(self, sm_mock):
|
||||
|
||||
arglist = ['--project', identity_fakes.project_name]
|
||||
verifylist = [('project', identity_fakes.project_name)]
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
ex = self.assertRaises(
|
||||
exceptions.CommandError,
|
||||
self.cmd.take_action,
|
||||
parsed_args)
|
||||
exceptions.CommandError, self.cmd.take_action, parsed_args
|
||||
)
|
||||
self.assertIn(
|
||||
'--os-compute-api-version 2.10 or greater is required', str(ex))
|
||||
'--os-compute-api-version 2.10 or greater is required', str(ex)
|
||||
)
|
||||
|
||||
def test_keypair_list_conflicting_user_options(self):
|
||||
|
||||
arglist = [
|
||||
'--user', identity_fakes.user_name,
|
||||
'--project', identity_fakes.project_name,
|
||||
'--user',
|
||||
identity_fakes.user_name,
|
||||
'--project',
|
||||
identity_fakes.project_name,
|
||||
]
|
||||
|
||||
self.assertRaises(
|
||||
tests_utils.ParserException,
|
||||
self.check_parser, self.cmd, arglist, None)
|
||||
self.check_parser,
|
||||
self.cmd,
|
||||
arglist,
|
||||
None,
|
||||
)
|
||||
|
||||
@mock.patch.object(
|
||||
sdk_utils, 'supports_microversion', new=mock.Mock(return_value=True))
|
||||
sdk_utils, 'supports_microversion', new=mock.Mock(return_value=True)
|
||||
)
|
||||
def test_keypair_list_with_limit(self):
|
||||
arglist = [
|
||||
'--limit', '1',
|
||||
'--limit',
|
||||
'1',
|
||||
]
|
||||
verifylist = [
|
||||
('limit', 1),
|
||||
@ -594,10 +601,12 @@ class TestKeypairList(TestKeypair):
|
||||
self.sdk_client.keypairs.assert_called_with(limit=1)
|
||||
|
||||
@mock.patch.object(
|
||||
sdk_utils, 'supports_microversion', new=mock.Mock(return_value=False))
|
||||
sdk_utils, 'supports_microversion', new=mock.Mock(return_value=False)
|
||||
)
|
||||
def test_keypair_list_with_limit_pre_v235(self):
|
||||
arglist = [
|
||||
'--limit', '1',
|
||||
'--limit',
|
||||
'1',
|
||||
]
|
||||
verifylist = [
|
||||
('limit', 1),
|
||||
@ -605,18 +614,20 @@ class TestKeypairList(TestKeypair):
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
ex = self.assertRaises(
|
||||
exceptions.CommandError,
|
||||
self.cmd.take_action,
|
||||
parsed_args)
|
||||
exceptions.CommandError, self.cmd.take_action, parsed_args
|
||||
)
|
||||
|
||||
self.assertIn(
|
||||
'--os-compute-api-version 2.35 or greater is required', str(ex))
|
||||
'--os-compute-api-version 2.35 or greater is required', str(ex)
|
||||
)
|
||||
|
||||
@mock.patch.object(
|
||||
sdk_utils, 'supports_microversion', new=mock.Mock(return_value=True))
|
||||
sdk_utils, 'supports_microversion', new=mock.Mock(return_value=True)
|
||||
)
|
||||
def test_keypair_list_with_marker(self):
|
||||
arglist = [
|
||||
'--marker', 'test_kp',
|
||||
'--marker',
|
||||
'test_kp',
|
||||
]
|
||||
verifylist = [
|
||||
('marker', 'test_kp'),
|
||||
@ -628,10 +639,12 @@ class TestKeypairList(TestKeypair):
|
||||
self.sdk_client.keypairs.assert_called_with(marker='test_kp')
|
||||
|
||||
@mock.patch.object(
|
||||
sdk_utils, 'supports_microversion', new=mock.Mock(return_value=False))
|
||||
sdk_utils, 'supports_microversion', new=mock.Mock(return_value=False)
|
||||
)
|
||||
def test_keypair_list_with_marker_pre_v235(self):
|
||||
arglist = [
|
||||
'--marker', 'test_kp',
|
||||
'--marker',
|
||||
'test_kp',
|
||||
]
|
||||
verifylist = [
|
||||
('marker', 'test_kp'),
|
||||
@ -639,16 +652,15 @@ class TestKeypairList(TestKeypair):
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
ex = self.assertRaises(
|
||||
exceptions.CommandError,
|
||||
self.cmd.take_action,
|
||||
parsed_args)
|
||||
exceptions.CommandError, self.cmd.take_action, parsed_args
|
||||
)
|
||||
|
||||
self.assertIn(
|
||||
'--os-compute-api-version 2.35 or greater is required', str(ex))
|
||||
'--os-compute-api-version 2.35 or greater is required', str(ex)
|
||||
)
|
||||
|
||||
|
||||
class TestKeypairShow(TestKeypair):
|
||||
|
||||
keypair = compute_fakes.FakeKeypair.create_one_keypair()
|
||||
|
||||
def setUp(self):
|
||||
@ -658,28 +670,27 @@ class TestKeypairShow(TestKeypair):
|
||||
|
||||
self.cmd = keypair.ShowKeypair(self.app, None)
|
||||
|
||||
self.columns = (
|
||||
"fingerprint",
|
||||
"name",
|
||||
"type",
|
||||
"user_id"
|
||||
)
|
||||
self.columns = ("fingerprint", "name", "type", "user_id")
|
||||
|
||||
self.data = (
|
||||
self.keypair.fingerprint,
|
||||
self.keypair.name,
|
||||
self.keypair.type,
|
||||
self.keypair.user_id
|
||||
self.keypair.user_id,
|
||||
)
|
||||
|
||||
def test_keypair_show_no_options(self):
|
||||
|
||||
arglist = []
|
||||
verifylist = []
|
||||
|
||||
# Missing required args should boil here
|
||||
self.assertRaises(tests_utils.ParserException, self.check_parser,
|
||||
self.cmd, arglist, verifylist)
|
||||
self.assertRaises(
|
||||
tests_utils.ParserException,
|
||||
self.check_parser,
|
||||
self.cmd,
|
||||
arglist,
|
||||
verifylist,
|
||||
)
|
||||
|
||||
def test_keypair_show(self):
|
||||
self.sdk_client.find_keypair.return_value = self.keypair
|
||||
@ -688,36 +699,25 @@ class TestKeypairShow(TestKeypair):
|
||||
self.keypair.fingerprint,
|
||||
self.keypair.name,
|
||||
self.keypair.type,
|
||||
self.keypair.user_id
|
||||
self.keypair.user_id,
|
||||
)
|
||||
|
||||
arglist = [
|
||||
self.keypair.name
|
||||
]
|
||||
verifylist = [
|
||||
('name', self.keypair.name)
|
||||
]
|
||||
arglist = [self.keypair.name]
|
||||
verifylist = [('name', self.keypair.name)]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
|
||||
self.sdk_client.find_keypair.assert_called_with(
|
||||
self.keypair.name,
|
||||
ignore_missing=False
|
||||
self.keypair.name, ignore_missing=False
|
||||
)
|
||||
|
||||
self.assertEqual(self.columns, columns)
|
||||
self.assertEqual(self.data, data)
|
||||
|
||||
def test_keypair_show_public(self):
|
||||
arglist = [
|
||||
'--public-key',
|
||||
self.keypair.name
|
||||
]
|
||||
verifylist = [
|
||||
('public_key', True),
|
||||
('name', self.keypair.name)
|
||||
]
|
||||
arglist = ['--public-key', self.keypair.name]
|
||||
verifylist = [('public_key', True), ('name', self.keypair.name)]
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
@ -734,16 +734,17 @@ class TestKeypairShow(TestKeypair):
|
||||
self.keypair.fingerprint,
|
||||
self.keypair.name,
|
||||
self.keypair.type,
|
||||
self.keypair.user_id
|
||||
self.keypair.user_id,
|
||||
)
|
||||
|
||||
arglist = [
|
||||
'--user', identity_fakes.user_name,
|
||||
'--user',
|
||||
identity_fakes.user_name,
|
||||
self.keypair.name,
|
||||
]
|
||||
verifylist = [
|
||||
('user', identity_fakes.user_name),
|
||||
('name', self.keypair.name)
|
||||
('name', self.keypair.name),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
@ -753,7 +754,7 @@ class TestKeypairShow(TestKeypair):
|
||||
self.sdk_client.find_keypair.assert_called_with(
|
||||
self.keypair.name,
|
||||
ignore_missing=False,
|
||||
user_id=identity_fakes.user_id
|
||||
user_id=identity_fakes.user_id,
|
||||
)
|
||||
|
||||
self.assertEqual(self.columns, columns)
|
||||
@ -761,20 +762,20 @@ class TestKeypairShow(TestKeypair):
|
||||
|
||||
@mock.patch.object(sdk_utils, 'supports_microversion', return_value=False)
|
||||
def test_keypair_show_with_user_pre_v210(self, sm_mock):
|
||||
|
||||
arglist = [
|
||||
'--user', identity_fakes.user_name,
|
||||
'--user',
|
||||
identity_fakes.user_name,
|
||||
self.keypair.name,
|
||||
]
|
||||
verifylist = [
|
||||
('user', identity_fakes.user_name),
|
||||
('name', self.keypair.name)
|
||||
('name', self.keypair.name),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
ex = self.assertRaises(
|
||||
exceptions.CommandError,
|
||||
self.cmd.take_action,
|
||||
parsed_args)
|
||||
exceptions.CommandError, self.cmd.take_action, parsed_args
|
||||
)
|
||||
self.assertIn(
|
||||
'--os-compute-api-version 2.10 or greater is required', str(ex))
|
||||
'--os-compute-api-version 2.10 or greater is required', str(ex)
|
||||
)
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -23,7 +23,6 @@ from openstackclient.tests.unit.image.v2 import fakes as image_fakes
|
||||
|
||||
|
||||
class TestServerBackup(compute_fakes.TestComputev2):
|
||||
|
||||
def setUp(self):
|
||||
super(TestServerBackup, self).setUp()
|
||||
|
||||
@ -58,12 +57,17 @@ class TestServerBackup(compute_fakes.TestComputev2):
|
||||
|
||||
|
||||
class TestServerBackupCreate(TestServerBackup):
|
||||
|
||||
# Just return whatever Image is testing with these days
|
||||
def image_columns(self, image):
|
||||
# columnlist = tuple(sorted(image.keys()))
|
||||
columnlist = (
|
||||
'id', 'name', 'owner', 'protected', 'status', 'tags', 'visibility'
|
||||
'id',
|
||||
'name',
|
||||
'owner',
|
||||
'protected',
|
||||
'status',
|
||||
'tags',
|
||||
'visibility',
|
||||
)
|
||||
return columnlist
|
||||
|
||||
@ -146,9 +150,12 @@ class TestServerBackupCreate(TestServerBackup):
|
||||
images = self.setup_images_mock(count=1, servers=servers)
|
||||
|
||||
arglist = [
|
||||
'--name', 'image',
|
||||
'--type', 'daily',
|
||||
'--rotate', '2',
|
||||
'--name',
|
||||
'image',
|
||||
'--type',
|
||||
'daily',
|
||||
'--rotate',
|
||||
'2',
|
||||
servers[0].id,
|
||||
]
|
||||
verifylist = [
|
||||
@ -183,8 +190,10 @@ class TestServerBackupCreate(TestServerBackup):
|
||||
)
|
||||
|
||||
arglist = [
|
||||
'--name', 'image',
|
||||
'--type', 'daily',
|
||||
'--name',
|
||||
'image',
|
||||
'--type',
|
||||
'daily',
|
||||
'--wait',
|
||||
servers[0].id,
|
||||
]
|
||||
@ -210,9 +219,7 @@ class TestServerBackupCreate(TestServerBackup):
|
||||
)
|
||||
|
||||
mock_wait_for_status.assert_called_once_with(
|
||||
self.images_mock.get_image,
|
||||
images[0].id,
|
||||
callback=mock.ANY
|
||||
self.images_mock.get_image, images[0].id, callback=mock.ANY
|
||||
)
|
||||
|
||||
@mock.patch.object(common_utils, 'wait_for_status', return_value=True)
|
||||
@ -225,8 +232,10 @@ class TestServerBackupCreate(TestServerBackup):
|
||||
)
|
||||
|
||||
arglist = [
|
||||
'--name', 'image',
|
||||
'--type', 'daily',
|
||||
'--name',
|
||||
'image',
|
||||
'--type',
|
||||
'daily',
|
||||
'--wait',
|
||||
servers[0].id,
|
||||
]
|
||||
@ -251,9 +260,7 @@ class TestServerBackupCreate(TestServerBackup):
|
||||
)
|
||||
|
||||
mock_wait_for_status.assert_called_once_with(
|
||||
self.images_mock.get_image,
|
||||
images[0].id,
|
||||
callback=mock.ANY
|
||||
self.images_mock.get_image, images[0].id, callback=mock.ANY
|
||||
)
|
||||
|
||||
self.assertEqual(self.image_columns(images[0]), columns)
|
||||
|
@ -24,7 +24,6 @@ from openstackclient.tests.unit.compute.v2 import fakes as compute_fakes
|
||||
|
||||
|
||||
class TestServerEvent(compute_fakes.TestComputev2):
|
||||
|
||||
fake_server = compute_fakes.FakeServer.create_one_server()
|
||||
|
||||
def setUp(self):
|
||||
@ -39,24 +38,25 @@ class TestServerEvent(compute_fakes.TestComputev2):
|
||||
self.sdk_client.reset_mock()
|
||||
|
||||
patcher = mock.patch.object(
|
||||
sdk_utils, 'supports_microversion', return_value=True)
|
||||
sdk_utils, 'supports_microversion', return_value=True
|
||||
)
|
||||
self.addCleanup(patcher.stop)
|
||||
self.supports_microversion_mock = patcher.start()
|
||||
self._set_mock_microversion(
|
||||
self.app.client_manager.compute.api_version.get_string())
|
||||
self.app.client_manager.compute.api_version.get_string()
|
||||
)
|
||||
|
||||
def _set_mock_microversion(self, mock_v):
|
||||
"""Set a specific microversion for the mock supports_microversion()."""
|
||||
self.supports_microversion_mock.reset_mock(return_value=True)
|
||||
|
||||
self.supports_microversion_mock.side_effect = (
|
||||
lambda _, v:
|
||||
api_versions.APIVersion(v) <= api_versions.APIVersion(mock_v)
|
||||
lambda _, v: api_versions.APIVersion(v)
|
||||
<= api_versions.APIVersion(mock_v)
|
||||
)
|
||||
|
||||
|
||||
class TestListServerEvent(TestServerEvent):
|
||||
|
||||
fake_event = compute_fakes.create_one_server_action()
|
||||
|
||||
columns = (
|
||||
@ -65,12 +65,14 @@ class TestListServerEvent(TestServerEvent):
|
||||
'Action',
|
||||
'Start Time',
|
||||
)
|
||||
data = ((
|
||||
fake_event.request_id,
|
||||
fake_event.server_id,
|
||||
fake_event.action,
|
||||
fake_event.start_time,
|
||||
), )
|
||||
data = (
|
||||
(
|
||||
fake_event.request_id,
|
||||
fake_event.server_id,
|
||||
fake_event.action,
|
||||
fake_event.start_time,
|
||||
),
|
||||
)
|
||||
|
||||
long_columns = (
|
||||
'Request ID',
|
||||
@ -81,21 +83,25 @@ class TestListServerEvent(TestServerEvent):
|
||||
'Project ID',
|
||||
'User ID',
|
||||
)
|
||||
long_data = ((
|
||||
fake_event.request_id,
|
||||
fake_event.server_id,
|
||||
fake_event.action,
|
||||
fake_event.start_time,
|
||||
fake_event.message,
|
||||
fake_event.project_id,
|
||||
fake_event.user_id,
|
||||
), )
|
||||
long_data = (
|
||||
(
|
||||
fake_event.request_id,
|
||||
fake_event.server_id,
|
||||
fake_event.action,
|
||||
fake_event.start_time,
|
||||
fake_event.message,
|
||||
fake_event.project_id,
|
||||
fake_event.user_id,
|
||||
),
|
||||
)
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
|
||||
self.sdk_client.find_server.return_value = self.fake_server
|
||||
self.sdk_client.server_actions.return_value = [self.fake_event, ]
|
||||
self.sdk_client.server_actions.return_value = [
|
||||
self.fake_event,
|
||||
]
|
||||
|
||||
self.cmd = server_event.ListServerEvent(self.app, None)
|
||||
|
||||
@ -146,7 +152,8 @@ class TestListServerEvent(TestServerEvent):
|
||||
self._set_mock_microversion('2.58')
|
||||
|
||||
arglist = [
|
||||
'--changes-since', '2016-03-04T06:27:59Z',
|
||||
'--changes-since',
|
||||
'2016-03-04T06:27:59Z',
|
||||
self.fake_server.name,
|
||||
]
|
||||
verifylist = [
|
||||
@ -171,12 +178,14 @@ class TestListServerEvent(TestServerEvent):
|
||||
|
||||
@mock.patch.object(iso8601, 'parse_date', side_effect=iso8601.ParseError)
|
||||
def test_server_event_list_with_changes_since_invalid(
|
||||
self, mock_parse_isotime,
|
||||
self,
|
||||
mock_parse_isotime,
|
||||
):
|
||||
self._set_mock_microversion('2.58')
|
||||
|
||||
arglist = [
|
||||
'--changes-since', 'Invalid time value',
|
||||
'--changes-since',
|
||||
'Invalid time value',
|
||||
self.fake_server.name,
|
||||
]
|
||||
verifylist = [
|
||||
@ -192,15 +201,14 @@ class TestListServerEvent(TestServerEvent):
|
||||
)
|
||||
|
||||
self.assertIn('Invalid changes-since value:', str(ex))
|
||||
mock_parse_isotime.assert_called_once_with(
|
||||
'Invalid time value'
|
||||
)
|
||||
mock_parse_isotime.assert_called_once_with('Invalid time value')
|
||||
|
||||
def test_server_event_list_with_changes_since_pre_v258(self):
|
||||
self._set_mock_microversion('2.57')
|
||||
|
||||
arglist = [
|
||||
'--changes-since', '2016-03-04T06:27:59Z',
|
||||
'--changes-since',
|
||||
'2016-03-04T06:27:59Z',
|
||||
self.fake_server.name,
|
||||
]
|
||||
verifylist = [
|
||||
@ -216,14 +224,16 @@ class TestListServerEvent(TestServerEvent):
|
||||
)
|
||||
|
||||
self.assertIn(
|
||||
'--os-compute-api-version 2.58 or greater is required', str(ex),
|
||||
'--os-compute-api-version 2.58 or greater is required',
|
||||
str(ex),
|
||||
)
|
||||
|
||||
def test_server_event_list_with_changes_before(self):
|
||||
self._set_mock_microversion('2.66')
|
||||
|
||||
arglist = [
|
||||
'--changes-before', '2016-03-04T06:27:59Z',
|
||||
'--changes-before',
|
||||
'2016-03-04T06:27:59Z',
|
||||
self.fake_server.name,
|
||||
]
|
||||
verifylist = [
|
||||
@ -248,12 +258,14 @@ class TestListServerEvent(TestServerEvent):
|
||||
|
||||
@mock.patch.object(iso8601, 'parse_date', side_effect=iso8601.ParseError)
|
||||
def test_server_event_list_with_changes_before_invalid(
|
||||
self, mock_parse_isotime,
|
||||
self,
|
||||
mock_parse_isotime,
|
||||
):
|
||||
self._set_mock_microversion('2.66')
|
||||
|
||||
arglist = [
|
||||
'--changes-before', 'Invalid time value',
|
||||
'--changes-before',
|
||||
'Invalid time value',
|
||||
self.fake_server.name,
|
||||
]
|
||||
verifylist = [
|
||||
@ -263,20 +275,18 @@ class TestListServerEvent(TestServerEvent):
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
ex = self.assertRaises(
|
||||
exceptions.CommandError,
|
||||
self.cmd.take_action,
|
||||
parsed_args)
|
||||
exceptions.CommandError, self.cmd.take_action, parsed_args
|
||||
)
|
||||
|
||||
self.assertIn('Invalid changes-before value:', str(ex))
|
||||
mock_parse_isotime.assert_called_once_with(
|
||||
'Invalid time value'
|
||||
)
|
||||
mock_parse_isotime.assert_called_once_with('Invalid time value')
|
||||
|
||||
def test_server_event_list_with_changes_before_pre_v266(self):
|
||||
self._set_mock_microversion('2.65')
|
||||
|
||||
arglist = [
|
||||
'--changes-before', '2016-03-04T06:27:59Z',
|
||||
'--changes-before',
|
||||
'2016-03-04T06:27:59Z',
|
||||
self.fake_server.name,
|
||||
]
|
||||
verifylist = [
|
||||
@ -286,9 +296,8 @@ class TestListServerEvent(TestServerEvent):
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
ex = self.assertRaises(
|
||||
exceptions.CommandError,
|
||||
self.cmd.take_action,
|
||||
parsed_args)
|
||||
exceptions.CommandError, self.cmd.take_action, parsed_args
|
||||
)
|
||||
|
||||
self.assertIn(
|
||||
'--os-compute-api-version 2.66 or greater is required',
|
||||
@ -299,7 +308,8 @@ class TestListServerEvent(TestServerEvent):
|
||||
self._set_mock_microversion('2.58')
|
||||
|
||||
arglist = [
|
||||
'--limit', '1',
|
||||
'--limit',
|
||||
'1',
|
||||
self.fake_server.name,
|
||||
]
|
||||
verifylist = [
|
||||
@ -320,7 +330,8 @@ class TestListServerEvent(TestServerEvent):
|
||||
self._set_mock_microversion('2.57')
|
||||
|
||||
arglist = [
|
||||
'--limit', '1',
|
||||
'--limit',
|
||||
'1',
|
||||
self.fake_server.name,
|
||||
]
|
||||
verifylist = [
|
||||
@ -344,7 +355,8 @@ class TestListServerEvent(TestServerEvent):
|
||||
self._set_mock_microversion('2.58')
|
||||
|
||||
arglist = [
|
||||
'--marker', 'test_event',
|
||||
'--marker',
|
||||
'test_event',
|
||||
self.fake_server.name,
|
||||
]
|
||||
verifylist = [
|
||||
@ -364,7 +376,8 @@ class TestListServerEvent(TestServerEvent):
|
||||
self._set_mock_microversion('2.57')
|
||||
|
||||
arglist = [
|
||||
'--marker', 'test_event',
|
||||
'--marker',
|
||||
'test_event',
|
||||
self.fake_server.name,
|
||||
]
|
||||
verifylist = [
|
||||
@ -374,16 +387,15 @@ class TestListServerEvent(TestServerEvent):
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
ex = self.assertRaises(
|
||||
exceptions.CommandError,
|
||||
self.cmd.take_action,
|
||||
parsed_args)
|
||||
exceptions.CommandError, self.cmd.take_action, parsed_args
|
||||
)
|
||||
|
||||
self.assertIn(
|
||||
'--os-compute-api-version 2.58 or greater is required', str(ex))
|
||||
'--os-compute-api-version 2.58 or greater is required', str(ex)
|
||||
)
|
||||
|
||||
|
||||
class TestShowServerEvent(TestServerEvent):
|
||||
|
||||
fake_event = compute_fakes.create_one_server_action()
|
||||
columns = (
|
||||
'action',
|
||||
|
@ -25,7 +25,6 @@ from openstackclient.tests.unit import utils as tests_utils
|
||||
|
||||
|
||||
class TestServerGroup(compute_fakes.TestComputev2):
|
||||
|
||||
fake_server_group = compute_fakes.create_one_server_group()
|
||||
|
||||
columns = (
|
||||
@ -58,18 +57,19 @@ class TestServerGroup(compute_fakes.TestComputev2):
|
||||
|
||||
|
||||
class TestServerGroupCreate(TestServerGroup):
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
|
||||
self.sdk_client.create_server_group.return_value = \
|
||||
self.sdk_client.create_server_group.return_value = (
|
||||
self.fake_server_group
|
||||
)
|
||||
self.cmd = server_group.CreateServerGroup(self.app, None)
|
||||
|
||||
@mock.patch.object(sdk_utils, 'supports_microversion', return_value=True)
|
||||
def test_server_group_create(self, sm_mock):
|
||||
arglist = [
|
||||
'--policy', 'anti-affinity',
|
||||
'--policy',
|
||||
'anti-affinity',
|
||||
'affinity_group',
|
||||
]
|
||||
verifylist = [
|
||||
@ -89,7 +89,8 @@ class TestServerGroupCreate(TestServerGroup):
|
||||
@mock.patch.object(sdk_utils, 'supports_microversion', return_value=True)
|
||||
def test_server_group_create_with_soft_policies(self, sm_mock):
|
||||
arglist = [
|
||||
'--policy', 'soft-anti-affinity',
|
||||
'--policy',
|
||||
'soft-anti-affinity',
|
||||
'affinity_group',
|
||||
]
|
||||
verifylist = [
|
||||
@ -109,7 +110,8 @@ class TestServerGroupCreate(TestServerGroup):
|
||||
@mock.patch.object(sdk_utils, 'supports_microversion', return_value=False)
|
||||
def test_server_group_create_with_soft_policies_pre_v215(self, sm_mock):
|
||||
arglist = [
|
||||
'--policy', 'soft-anti-affinity',
|
||||
'--policy',
|
||||
'soft-anti-affinity',
|
||||
'affinity_group',
|
||||
]
|
||||
verifylist = [
|
||||
@ -118,18 +120,19 @@ class TestServerGroupCreate(TestServerGroup):
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
ex = self.assertRaises(
|
||||
exceptions.CommandError,
|
||||
self.cmd.take_action,
|
||||
parsed_args)
|
||||
exceptions.CommandError, self.cmd.take_action, parsed_args
|
||||
)
|
||||
self.assertIn(
|
||||
'--os-compute-api-version 2.15 or greater is required',
|
||||
str(ex))
|
||||
'--os-compute-api-version 2.15 or greater is required', str(ex)
|
||||
)
|
||||
|
||||
@mock.patch.object(sdk_utils, 'supports_microversion', return_value=True)
|
||||
def test_server_group_create_with_rules(self, sm_mock):
|
||||
arglist = [
|
||||
'--policy', 'soft-anti-affinity',
|
||||
'--rule', 'max_server_per_host=2',
|
||||
'--policy',
|
||||
'soft-anti-affinity',
|
||||
'--rule',
|
||||
'max_server_per_host=2',
|
||||
'affinity_group',
|
||||
]
|
||||
verifylist = [
|
||||
@ -149,11 +152,14 @@ class TestServerGroupCreate(TestServerGroup):
|
||||
self.assertCountEqual(self.data, data)
|
||||
|
||||
@mock.patch.object(
|
||||
sdk_utils, 'supports_microversion', side_effect=[True, False])
|
||||
sdk_utils, 'supports_microversion', side_effect=[True, False]
|
||||
)
|
||||
def test_server_group_create_with_rules_pre_v264(self, sm_mock):
|
||||
arglist = [
|
||||
'--policy', 'soft-anti-affinity',
|
||||
'--rule', 'max_server_per_host=2',
|
||||
'--policy',
|
||||
'soft-anti-affinity',
|
||||
'--rule',
|
||||
'max_server_per_host=2',
|
||||
'affinity_group',
|
||||
]
|
||||
verifylist = [
|
||||
@ -164,16 +170,14 @@ class TestServerGroupCreate(TestServerGroup):
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
ex = self.assertRaises(
|
||||
exceptions.CommandError,
|
||||
self.cmd.take_action,
|
||||
parsed_args)
|
||||
exceptions.CommandError, self.cmd.take_action, parsed_args
|
||||
)
|
||||
self.assertIn(
|
||||
'--os-compute-api-version 2.64 or greater is required',
|
||||
str(ex))
|
||||
'--os-compute-api-version 2.64 or greater is required', str(ex)
|
||||
)
|
||||
|
||||
|
||||
class TestServerGroupDelete(TestServerGroup):
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
|
||||
@ -198,10 +202,7 @@ class TestServerGroupDelete(TestServerGroup):
|
||||
self.assertIsNone(result)
|
||||
|
||||
def test_server_group_multiple_delete(self):
|
||||
arglist = [
|
||||
'affinity_group',
|
||||
'anti_affinity_group'
|
||||
]
|
||||
arglist = ['affinity_group', 'anti_affinity_group']
|
||||
verifylist = [
|
||||
('server_group', ['affinity_group', 'anti_affinity_group']),
|
||||
]
|
||||
@ -221,24 +222,25 @@ class TestServerGroupDelete(TestServerGroup):
|
||||
def test_server_group_delete_no_input(self):
|
||||
arglist = []
|
||||
verifylist = None
|
||||
self.assertRaises(tests_utils.ParserException,
|
||||
self.check_parser,
|
||||
self.cmd,
|
||||
arglist,
|
||||
verifylist)
|
||||
self.assertRaises(
|
||||
tests_utils.ParserException,
|
||||
self.check_parser,
|
||||
self.cmd,
|
||||
arglist,
|
||||
verifylist,
|
||||
)
|
||||
|
||||
def test_server_group_multiple_delete_with_exception(self):
|
||||
arglist = [
|
||||
'affinity_group',
|
||||
'anti_affinity_group'
|
||||
]
|
||||
arglist = ['affinity_group', 'anti_affinity_group']
|
||||
verifylist = [
|
||||
('server_group', ['affinity_group', 'anti_affinity_group']),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
self.sdk_client.find_server_group.side_effect = [
|
||||
self.fake_server_group, exceptions.CommandError]
|
||||
self.fake_server_group,
|
||||
exceptions.CommandError,
|
||||
]
|
||||
try:
|
||||
self.cmd.take_action(parsed_args)
|
||||
self.fail('CommandError should be raised.')
|
||||
@ -256,7 +258,6 @@ class TestServerGroupDelete(TestServerGroup):
|
||||
|
||||
|
||||
class TestServerGroupList(TestServerGroup):
|
||||
|
||||
list_columns = (
|
||||
'ID',
|
||||
'Name',
|
||||
@ -287,43 +288,51 @@ class TestServerGroupList(TestServerGroup):
|
||||
'User Id',
|
||||
)
|
||||
|
||||
list_data = ((
|
||||
TestServerGroup.fake_server_group.id,
|
||||
TestServerGroup.fake_server_group.name,
|
||||
format_columns.ListColumn(
|
||||
TestServerGroup.fake_server_group.policies
|
||||
list_data = (
|
||||
(
|
||||
TestServerGroup.fake_server_group.id,
|
||||
TestServerGroup.fake_server_group.name,
|
||||
format_columns.ListColumn(
|
||||
TestServerGroup.fake_server_group.policies
|
||||
),
|
||||
),
|
||||
),)
|
||||
)
|
||||
|
||||
list_data_long = ((
|
||||
TestServerGroup.fake_server_group.id,
|
||||
TestServerGroup.fake_server_group.name,
|
||||
format_columns.ListColumn(
|
||||
TestServerGroup.fake_server_group.policies
|
||||
list_data_long = (
|
||||
(
|
||||
TestServerGroup.fake_server_group.id,
|
||||
TestServerGroup.fake_server_group.name,
|
||||
format_columns.ListColumn(
|
||||
TestServerGroup.fake_server_group.policies
|
||||
),
|
||||
format_columns.ListColumn(
|
||||
TestServerGroup.fake_server_group.member_ids
|
||||
),
|
||||
TestServerGroup.fake_server_group.project_id,
|
||||
TestServerGroup.fake_server_group.user_id,
|
||||
),
|
||||
format_columns.ListColumn(
|
||||
TestServerGroup.fake_server_group.member_ids
|
||||
),
|
||||
TestServerGroup.fake_server_group.project_id,
|
||||
TestServerGroup.fake_server_group.user_id,
|
||||
),)
|
||||
)
|
||||
|
||||
list_data_v264 = ((
|
||||
TestServerGroup.fake_server_group.id,
|
||||
TestServerGroup.fake_server_group.name,
|
||||
TestServerGroup.fake_server_group.policy,
|
||||
),)
|
||||
|
||||
list_data_v264_long = ((
|
||||
TestServerGroup.fake_server_group.id,
|
||||
TestServerGroup.fake_server_group.name,
|
||||
TestServerGroup.fake_server_group.policy,
|
||||
format_columns.ListColumn(
|
||||
TestServerGroup.fake_server_group.member_ids
|
||||
list_data_v264 = (
|
||||
(
|
||||
TestServerGroup.fake_server_group.id,
|
||||
TestServerGroup.fake_server_group.name,
|
||||
TestServerGroup.fake_server_group.policy,
|
||||
),
|
||||
TestServerGroup.fake_server_group.project_id,
|
||||
TestServerGroup.fake_server_group.user_id,
|
||||
),)
|
||||
)
|
||||
|
||||
list_data_v264_long = (
|
||||
(
|
||||
TestServerGroup.fake_server_group.id,
|
||||
TestServerGroup.fake_server_group.name,
|
||||
TestServerGroup.fake_server_group.policy,
|
||||
format_columns.ListColumn(
|
||||
TestServerGroup.fake_server_group.member_ids
|
||||
),
|
||||
TestServerGroup.fake_server_group.project_id,
|
||||
TestServerGroup.fake_server_group.user_id,
|
||||
),
|
||||
)
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
@ -363,7 +372,8 @@ class TestServerGroupList(TestServerGroup):
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
self.sdk_client.server_groups.assert_called_once_with(
|
||||
all_projects=True)
|
||||
all_projects=True
|
||||
)
|
||||
|
||||
self.assertCountEqual(self.list_columns_long, columns)
|
||||
self.assertCountEqual(self.list_data_long, tuple(data))
|
||||
@ -371,7 +381,8 @@ class TestServerGroupList(TestServerGroup):
|
||||
@mock.patch.object(sdk_utils, 'supports_microversion', return_value=True)
|
||||
def test_server_group_list_with_limit(self, sm_mock):
|
||||
arglist = [
|
||||
'--limit', '1',
|
||||
'--limit',
|
||||
'1',
|
||||
]
|
||||
verifylist = [
|
||||
('all_projects', False),
|
||||
@ -388,7 +399,8 @@ class TestServerGroupList(TestServerGroup):
|
||||
@mock.patch.object(sdk_utils, 'supports_microversion', return_value=True)
|
||||
def test_server_group_list_with_offset(self, sm_mock):
|
||||
arglist = [
|
||||
'--offset', '5',
|
||||
'--offset',
|
||||
'5',
|
||||
]
|
||||
verifylist = [
|
||||
('all_projects', False),
|
||||
@ -429,14 +441,14 @@ class TestServerGroupList(TestServerGroup):
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
self.sdk_client.server_groups.assert_called_once_with(
|
||||
all_projects=True)
|
||||
all_projects=True
|
||||
)
|
||||
|
||||
self.assertCountEqual(self.list_columns_v264_long, columns)
|
||||
self.assertCountEqual(self.list_data_v264_long, tuple(data))
|
||||
|
||||
|
||||
class TestServerGroupShow(TestServerGroup):
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
|
||||
|
@ -22,7 +22,6 @@ from openstackclient.tests.unit.image.v2 import fakes as image_fakes
|
||||
|
||||
|
||||
class TestServerImage(compute_fakes.TestComputev2):
|
||||
|
||||
def setUp(self):
|
||||
super(TestServerImage, self).setUp()
|
||||
|
||||
@ -57,11 +56,16 @@ class TestServerImage(compute_fakes.TestComputev2):
|
||||
|
||||
|
||||
class TestServerImageCreate(TestServerImage):
|
||||
|
||||
def image_columns(self, image):
|
||||
# columnlist = tuple(sorted(image.keys()))
|
||||
columnlist = (
|
||||
'id', 'name', 'owner', 'protected', 'status', 'tags', 'visibility'
|
||||
'id',
|
||||
'name',
|
||||
'owner',
|
||||
'protected',
|
||||
'status',
|
||||
'tags',
|
||||
'visibility',
|
||||
)
|
||||
return columnlist
|
||||
|
||||
@ -141,8 +145,10 @@ class TestServerImageCreate(TestServerImage):
|
||||
images = self.setup_images_mock(count=1, servers=servers)
|
||||
|
||||
arglist = [
|
||||
'--name', 'img-nam',
|
||||
'--property', 'key=value',
|
||||
'--name',
|
||||
'img-nam',
|
||||
'--property',
|
||||
'key=value',
|
||||
servers[0].id,
|
||||
]
|
||||
verifylist = [
|
||||
@ -194,9 +200,7 @@ class TestServerImageCreate(TestServerImage):
|
||||
)
|
||||
|
||||
mock_wait_for_status.assert_called_once_with(
|
||||
self.images_mock.get_image,
|
||||
images[0].id,
|
||||
callback=mock.ANY
|
||||
self.images_mock.get_image, images[0].id, callback=mock.ANY
|
||||
)
|
||||
|
||||
@mock.patch.object(common_utils, 'wait_for_status', return_value=True)
|
||||
@ -226,9 +230,7 @@ class TestServerImageCreate(TestServerImage):
|
||||
)
|
||||
|
||||
mock_wait_for_status.assert_called_once_with(
|
||||
self.images_mock.get_image,
|
||||
images[0].id,
|
||||
callback=mock.ANY
|
||||
self.images_mock.get_image, images[0].id, callback=mock.ANY
|
||||
)
|
||||
|
||||
self.assertEqual(self.image_columns(images[0]), columns)
|
||||
|
@ -23,7 +23,6 @@ from openstackclient.tests.unit.identity.v3 import fakes as identity_fakes
|
||||
|
||||
|
||||
class TestServerMigration(compute_fakes.TestComputev2):
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
|
||||
@ -32,8 +31,9 @@ class TestServerMigration(compute_fakes.TestComputev2):
|
||||
self.servers_mock.reset_mock()
|
||||
|
||||
# Get a shortcut to the compute client ServerMigrationsManager Mock
|
||||
self.server_migrations_mock = \
|
||||
self.server_migrations_mock = (
|
||||
self.app.client_manager.compute.server_migrations
|
||||
)
|
||||
self.server_migrations_mock.reset_mock()
|
||||
|
||||
self.app.client_manager.sdk_connection = mock.Mock()
|
||||
@ -41,7 +41,8 @@ class TestServerMigration(compute_fakes.TestComputev2):
|
||||
self.sdk_client = self.app.client_manager.sdk_connection.compute
|
||||
|
||||
patcher = mock.patch.object(
|
||||
sdk_utils, 'supports_microversion', return_value=True)
|
||||
sdk_utils, 'supports_microversion', return_value=True
|
||||
)
|
||||
self.addCleanup(patcher.stop)
|
||||
self.supports_microversion_mock = patcher.start()
|
||||
|
||||
@ -49,23 +50,40 @@ class TestServerMigration(compute_fakes.TestComputev2):
|
||||
"""Set a specific microversion for the mock supports_microversion()."""
|
||||
self.supports_microversion_mock.reset_mock(return_value=True)
|
||||
self.supports_microversion_mock.side_effect = (
|
||||
lambda _, v:
|
||||
api_versions.APIVersion(v) <= api_versions.APIVersion(mock_v))
|
||||
lambda _, v: api_versions.APIVersion(v)
|
||||
<= api_versions.APIVersion(mock_v)
|
||||
)
|
||||
|
||||
|
||||
class TestListMigration(TestServerMigration):
|
||||
"""Test fetch all migrations."""
|
||||
|
||||
MIGRATION_COLUMNS = [
|
||||
'Source Node', 'Dest Node', 'Source Compute',
|
||||
'Dest Compute', 'Dest Host', 'Status', 'Server UUID',
|
||||
'Old Flavor', 'New Flavor', 'Created At', 'Updated At'
|
||||
'Source Node',
|
||||
'Dest Node',
|
||||
'Source Compute',
|
||||
'Dest Compute',
|
||||
'Dest Host',
|
||||
'Status',
|
||||
'Server UUID',
|
||||
'Old Flavor',
|
||||
'New Flavor',
|
||||
'Created At',
|
||||
'Updated At',
|
||||
]
|
||||
|
||||
MIGRATION_FIELDS = [
|
||||
'source_node', 'dest_node', 'source_compute',
|
||||
'dest_compute', 'dest_host', 'status', 'server_id', 'old_flavor_id',
|
||||
'new_flavor_id', 'created_at', 'updated_at'
|
||||
'source_node',
|
||||
'dest_node',
|
||||
'source_compute',
|
||||
'dest_compute',
|
||||
'dest_host',
|
||||
'status',
|
||||
'server_id',
|
||||
'old_flavor_id',
|
||||
'new_flavor_id',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
]
|
||||
|
||||
def setUp(self):
|
||||
@ -79,8 +97,10 @@ class TestListMigration(TestServerMigration):
|
||||
self.migrations = compute_fakes.create_migrations(count=3)
|
||||
self.sdk_client.migrations.return_value = self.migrations
|
||||
|
||||
self.data = (common_utils.get_item_properties(
|
||||
s, self.MIGRATION_FIELDS) for s in self.migrations)
|
||||
self.data = (
|
||||
common_utils.get_item_properties(s, self.MIGRATION_FIELDS)
|
||||
for s in self.migrations
|
||||
)
|
||||
|
||||
# Get the command object to test
|
||||
self.cmd = server_migration.ListMigration(self.app, None)
|
||||
@ -102,10 +122,14 @@ class TestListMigration(TestServerMigration):
|
||||
|
||||
def test_server_migration_list(self):
|
||||
arglist = [
|
||||
'--server', 'server1',
|
||||
'--host', 'host1',
|
||||
'--status', 'migrating',
|
||||
'--type', 'cold-migration',
|
||||
'--server',
|
||||
'server1',
|
||||
'--host',
|
||||
'host1',
|
||||
'--status',
|
||||
'migrating',
|
||||
'--type',
|
||||
'cold-migration',
|
||||
]
|
||||
verifylist = [
|
||||
('server', 'server1'),
|
||||
@ -131,19 +155,39 @@ class TestListMigration(TestServerMigration):
|
||||
|
||||
|
||||
class TestListMigrationV223(TestListMigration):
|
||||
"""Test fetch all migrations. """
|
||||
"""Test fetch all migrations."""
|
||||
|
||||
MIGRATION_COLUMNS = [
|
||||
'Id', 'Source Node', 'Dest Node', 'Source Compute', 'Dest Compute',
|
||||
'Dest Host', 'Status', 'Server UUID', 'Old Flavor', 'New Flavor',
|
||||
'Type', 'Created At', 'Updated At'
|
||||
'Id',
|
||||
'Source Node',
|
||||
'Dest Node',
|
||||
'Source Compute',
|
||||
'Dest Compute',
|
||||
'Dest Host',
|
||||
'Status',
|
||||
'Server UUID',
|
||||
'Old Flavor',
|
||||
'New Flavor',
|
||||
'Type',
|
||||
'Created At',
|
||||
'Updated At',
|
||||
]
|
||||
|
||||
# These are the Migration object fields.
|
||||
MIGRATION_FIELDS = [
|
||||
'id', 'source_node', 'dest_node', 'source_compute', 'dest_compute',
|
||||
'dest_host', 'status', 'server_id', 'old_flavor_id',
|
||||
'new_flavor_id', 'migration_type', 'created_at', 'updated_at'
|
||||
'id',
|
||||
'source_node',
|
||||
'dest_node',
|
||||
'source_compute',
|
||||
'dest_compute',
|
||||
'dest_host',
|
||||
'status',
|
||||
'server_id',
|
||||
'old_flavor_id',
|
||||
'new_flavor_id',
|
||||
'migration_type',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
]
|
||||
|
||||
def setUp(self):
|
||||
@ -152,12 +196,8 @@ class TestListMigrationV223(TestListMigration):
|
||||
self._set_mock_microversion('2.23')
|
||||
|
||||
def test_server_migration_list(self):
|
||||
arglist = [
|
||||
'--status', 'migrating'
|
||||
]
|
||||
verifylist = [
|
||||
('status', 'migrating')
|
||||
]
|
||||
arglist = ['--status', 'migrating']
|
||||
verifylist = [('status', 'migrating')]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
|
||||
@ -173,20 +213,41 @@ class TestListMigrationV223(TestListMigration):
|
||||
|
||||
|
||||
class TestListMigrationV259(TestListMigration):
|
||||
"""Test fetch all migrations. """
|
||||
"""Test fetch all migrations."""
|
||||
|
||||
MIGRATION_COLUMNS = [
|
||||
'Id', 'UUID', 'Source Node', 'Dest Node', 'Source Compute',
|
||||
'Dest Compute', 'Dest Host', 'Status', 'Server UUID',
|
||||
'Old Flavor', 'New Flavor', 'Type', 'Created At', 'Updated At'
|
||||
'Id',
|
||||
'UUID',
|
||||
'Source Node',
|
||||
'Dest Node',
|
||||
'Source Compute',
|
||||
'Dest Compute',
|
||||
'Dest Host',
|
||||
'Status',
|
||||
'Server UUID',
|
||||
'Old Flavor',
|
||||
'New Flavor',
|
||||
'Type',
|
||||
'Created At',
|
||||
'Updated At',
|
||||
]
|
||||
|
||||
# These are the Migration object fields.
|
||||
MIGRATION_FIELDS = [
|
||||
'id', 'uuid', 'source_node', 'dest_node', 'source_compute',
|
||||
'dest_compute', 'dest_host', 'status', 'server_id',
|
||||
'old_flavor_id', 'new_flavor_id', 'migration_type',
|
||||
'created_at', 'updated_at'
|
||||
'id',
|
||||
'uuid',
|
||||
'source_node',
|
||||
'dest_node',
|
||||
'source_compute',
|
||||
'dest_compute',
|
||||
'dest_host',
|
||||
'status',
|
||||
'server_id',
|
||||
'old_flavor_id',
|
||||
'new_flavor_id',
|
||||
'migration_type',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
]
|
||||
|
||||
def setUp(self):
|
||||
@ -196,16 +257,20 @@ class TestListMigrationV259(TestListMigration):
|
||||
|
||||
def test_server_migration_list(self):
|
||||
arglist = [
|
||||
'--status', 'migrating',
|
||||
'--limit', '1',
|
||||
'--marker', 'test_kp',
|
||||
'--changes-since', '2019-08-09T08:03:25Z'
|
||||
'--status',
|
||||
'migrating',
|
||||
'--limit',
|
||||
'1',
|
||||
'--marker',
|
||||
'test_kp',
|
||||
'--changes-since',
|
||||
'2019-08-09T08:03:25Z',
|
||||
]
|
||||
verifylist = [
|
||||
('status', 'migrating'),
|
||||
('limit', 1),
|
||||
('marker', 'test_kp'),
|
||||
('changes_since', '2019-08-09T08:03:25Z')
|
||||
('changes_since', '2019-08-09T08:03:25Z'),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
@ -226,77 +291,85 @@ class TestListMigrationV259(TestListMigration):
|
||||
|
||||
def test_server_migration_list_with_limit_pre_v259(self):
|
||||
self._set_mock_microversion('2.58')
|
||||
arglist = [
|
||||
'--status', 'migrating',
|
||||
'--limit', '1'
|
||||
]
|
||||
verifylist = [
|
||||
('status', 'migrating'),
|
||||
('limit', 1)
|
||||
]
|
||||
arglist = ['--status', 'migrating', '--limit', '1']
|
||||
verifylist = [('status', 'migrating'), ('limit', 1)]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
ex = self.assertRaises(
|
||||
exceptions.CommandError,
|
||||
self.cmd.take_action,
|
||||
parsed_args)
|
||||
exceptions.CommandError, self.cmd.take_action, parsed_args
|
||||
)
|
||||
self.assertIn(
|
||||
'--os-compute-api-version 2.59 or greater is required',
|
||||
str(ex))
|
||||
'--os-compute-api-version 2.59 or greater is required', str(ex)
|
||||
)
|
||||
|
||||
def test_server_migration_list_with_marker_pre_v259(self):
|
||||
self._set_mock_microversion('2.58')
|
||||
arglist = [
|
||||
'--status', 'migrating',
|
||||
'--marker', 'test_kp'
|
||||
]
|
||||
verifylist = [
|
||||
('status', 'migrating'),
|
||||
('marker', 'test_kp')
|
||||
]
|
||||
arglist = ['--status', 'migrating', '--marker', 'test_kp']
|
||||
verifylist = [('status', 'migrating'), ('marker', 'test_kp')]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
ex = self.assertRaises(
|
||||
exceptions.CommandError,
|
||||
self.cmd.take_action,
|
||||
parsed_args)
|
||||
exceptions.CommandError, self.cmd.take_action, parsed_args
|
||||
)
|
||||
self.assertIn(
|
||||
'--os-compute-api-version 2.59 or greater is required',
|
||||
str(ex))
|
||||
'--os-compute-api-version 2.59 or greater is required', str(ex)
|
||||
)
|
||||
|
||||
def test_server_migration_list_with_changes_since_pre_v259(self):
|
||||
self._set_mock_microversion('2.58')
|
||||
arglist = [
|
||||
'--status', 'migrating',
|
||||
'--changes-since', '2019-08-09T08:03:25Z'
|
||||
'--status',
|
||||
'migrating',
|
||||
'--changes-since',
|
||||
'2019-08-09T08:03:25Z',
|
||||
]
|
||||
verifylist = [
|
||||
('status', 'migrating'),
|
||||
('changes_since', '2019-08-09T08:03:25Z')
|
||||
('changes_since', '2019-08-09T08:03:25Z'),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
ex = self.assertRaises(
|
||||
exceptions.CommandError,
|
||||
self.cmd.take_action,
|
||||
parsed_args)
|
||||
exceptions.CommandError, self.cmd.take_action, parsed_args
|
||||
)
|
||||
self.assertIn(
|
||||
'--os-compute-api-version 2.59 or greater is required',
|
||||
str(ex))
|
||||
'--os-compute-api-version 2.59 or greater is required', str(ex)
|
||||
)
|
||||
|
||||
|
||||
class TestListMigrationV266(TestListMigration):
|
||||
"""Test fetch all migrations by changes-before. """
|
||||
"""Test fetch all migrations by changes-before."""
|
||||
|
||||
MIGRATION_COLUMNS = [
|
||||
'Id', 'UUID', 'Source Node', 'Dest Node', 'Source Compute',
|
||||
'Dest Compute', 'Dest Host', 'Status', 'Server UUID',
|
||||
'Old Flavor', 'New Flavor', 'Type', 'Created At', 'Updated At'
|
||||
'Id',
|
||||
'UUID',
|
||||
'Source Node',
|
||||
'Dest Node',
|
||||
'Source Compute',
|
||||
'Dest Compute',
|
||||
'Dest Host',
|
||||
'Status',
|
||||
'Server UUID',
|
||||
'Old Flavor',
|
||||
'New Flavor',
|
||||
'Type',
|
||||
'Created At',
|
||||
'Updated At',
|
||||
]
|
||||
|
||||
# These are the Migration object fields.
|
||||
MIGRATION_FIELDS = [
|
||||
'id', 'uuid', 'source_node', 'dest_node', 'source_compute',
|
||||
'dest_compute', 'dest_host', 'status', 'server_id',
|
||||
'old_flavor_id', 'new_flavor_id', 'migration_type',
|
||||
'created_at', 'updated_at'
|
||||
'id',
|
||||
'uuid',
|
||||
'source_node',
|
||||
'dest_node',
|
||||
'source_compute',
|
||||
'dest_compute',
|
||||
'dest_host',
|
||||
'status',
|
||||
'server_id',
|
||||
'old_flavor_id',
|
||||
'new_flavor_id',
|
||||
'migration_type',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
]
|
||||
|
||||
def setUp(self):
|
||||
@ -306,18 +379,23 @@ class TestListMigrationV266(TestListMigration):
|
||||
|
||||
def test_server_migration_list_with_changes_before(self):
|
||||
arglist = [
|
||||
'--status', 'migrating',
|
||||
'--limit', '1',
|
||||
'--marker', 'test_kp',
|
||||
'--changes-since', '2019-08-07T08:03:25Z',
|
||||
'--changes-before', '2019-08-09T08:03:25Z'
|
||||
'--status',
|
||||
'migrating',
|
||||
'--limit',
|
||||
'1',
|
||||
'--marker',
|
||||
'test_kp',
|
||||
'--changes-since',
|
||||
'2019-08-07T08:03:25Z',
|
||||
'--changes-before',
|
||||
'2019-08-09T08:03:25Z',
|
||||
]
|
||||
verifylist = [
|
||||
('status', 'migrating'),
|
||||
('limit', 1),
|
||||
('marker', 'test_kp'),
|
||||
('changes_since', '2019-08-07T08:03:25Z'),
|
||||
('changes_before', '2019-08-09T08:03:25Z')
|
||||
('changes_before', '2019-08-09T08:03:25Z'),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
@ -340,38 +418,60 @@ class TestListMigrationV266(TestListMigration):
|
||||
def test_server_migration_list_with_changes_before_pre_v266(self):
|
||||
self._set_mock_microversion('2.65')
|
||||
arglist = [
|
||||
'--status', 'migrating',
|
||||
'--changes-before', '2019-08-09T08:03:25Z'
|
||||
'--status',
|
||||
'migrating',
|
||||
'--changes-before',
|
||||
'2019-08-09T08:03:25Z',
|
||||
]
|
||||
verifylist = [
|
||||
('status', 'migrating'),
|
||||
('changes_before', '2019-08-09T08:03:25Z')
|
||||
('changes_before', '2019-08-09T08:03:25Z'),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
ex = self.assertRaises(
|
||||
exceptions.CommandError,
|
||||
self.cmd.take_action,
|
||||
parsed_args)
|
||||
exceptions.CommandError, self.cmd.take_action, parsed_args
|
||||
)
|
||||
self.assertIn(
|
||||
'--os-compute-api-version 2.66 or greater is required',
|
||||
str(ex))
|
||||
'--os-compute-api-version 2.66 or greater is required', str(ex)
|
||||
)
|
||||
|
||||
|
||||
class TestListMigrationV280(TestListMigration):
|
||||
"""Test fetch all migrations by user-id and/or project-id. """
|
||||
"""Test fetch all migrations by user-id and/or project-id."""
|
||||
|
||||
MIGRATION_COLUMNS = [
|
||||
'Id', 'UUID', 'Source Node', 'Dest Node', 'Source Compute',
|
||||
'Dest Compute', 'Dest Host', 'Status', 'Server UUID',
|
||||
'Old Flavor', 'New Flavor', 'Type', 'Created At', 'Updated At'
|
||||
'Id',
|
||||
'UUID',
|
||||
'Source Node',
|
||||
'Dest Node',
|
||||
'Source Compute',
|
||||
'Dest Compute',
|
||||
'Dest Host',
|
||||
'Status',
|
||||
'Server UUID',
|
||||
'Old Flavor',
|
||||
'New Flavor',
|
||||
'Type',
|
||||
'Created At',
|
||||
'Updated At',
|
||||
]
|
||||
|
||||
# These are the Migration object fields.
|
||||
MIGRATION_FIELDS = [
|
||||
'id', 'uuid', 'source_node', 'dest_node', 'source_compute',
|
||||
'dest_compute', 'dest_host', 'status', 'server_id',
|
||||
'old_flavor_id', 'new_flavor_id', 'migration_type',
|
||||
'created_at', 'updated_at'
|
||||
'id',
|
||||
'uuid',
|
||||
'source_node',
|
||||
'dest_node',
|
||||
'source_compute',
|
||||
'dest_compute',
|
||||
'dest_host',
|
||||
'status',
|
||||
'server_id',
|
||||
'old_flavor_id',
|
||||
'new_flavor_id',
|
||||
'migration_type',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
]
|
||||
|
||||
project = identity_fakes.FakeProject.create_one_project()
|
||||
@ -393,12 +493,18 @@ class TestListMigrationV280(TestListMigration):
|
||||
|
||||
def test_server_migration_list_with_project(self):
|
||||
arglist = [
|
||||
'--status', 'migrating',
|
||||
'--limit', '1',
|
||||
'--marker', 'test_kp',
|
||||
'--changes-since', '2019-08-07T08:03:25Z',
|
||||
'--changes-before', '2019-08-09T08:03:25Z',
|
||||
'--project', self.project.id
|
||||
'--status',
|
||||
'migrating',
|
||||
'--limit',
|
||||
'1',
|
||||
'--marker',
|
||||
'test_kp',
|
||||
'--changes-since',
|
||||
'2019-08-07T08:03:25Z',
|
||||
'--changes-before',
|
||||
'2019-08-09T08:03:25Z',
|
||||
'--project',
|
||||
self.project.id,
|
||||
]
|
||||
verifylist = [
|
||||
('status', 'migrating'),
|
||||
@ -406,7 +512,7 @@ class TestListMigrationV280(TestListMigration):
|
||||
('marker', 'test_kp'),
|
||||
('changes_since', '2019-08-07T08:03:25Z'),
|
||||
('changes_before', '2019-08-09T08:03:25Z'),
|
||||
('project', self.project.id)
|
||||
('project', self.project.id),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
@ -425,9 +531,11 @@ class TestListMigrationV280(TestListMigration):
|
||||
self.sdk_client.migrations.assert_called_with(**kwargs)
|
||||
|
||||
self.MIGRATION_COLUMNS.insert(
|
||||
len(self.MIGRATION_COLUMNS) - 2, "Project")
|
||||
len(self.MIGRATION_COLUMNS) - 2, "Project"
|
||||
)
|
||||
self.MIGRATION_FIELDS.insert(
|
||||
len(self.MIGRATION_FIELDS) - 2, "project_id")
|
||||
len(self.MIGRATION_FIELDS) - 2, "project_id"
|
||||
)
|
||||
self.assertEqual(self.MIGRATION_COLUMNS, columns)
|
||||
self.assertEqual(tuple(self.data), tuple(data))
|
||||
# Clean up global variables MIGRATION_COLUMNS
|
||||
@ -438,32 +546,40 @@ class TestListMigrationV280(TestListMigration):
|
||||
def test_get_migrations_with_project_pre_v280(self):
|
||||
self._set_mock_microversion('2.79')
|
||||
arglist = [
|
||||
'--status', 'migrating',
|
||||
'--changes-before', '2019-08-09T08:03:25Z',
|
||||
'--project', '0c2accde-644a-45fa-8c10-e76debc7fbc3'
|
||||
'--status',
|
||||
'migrating',
|
||||
'--changes-before',
|
||||
'2019-08-09T08:03:25Z',
|
||||
'--project',
|
||||
'0c2accde-644a-45fa-8c10-e76debc7fbc3',
|
||||
]
|
||||
verifylist = [
|
||||
('status', 'migrating'),
|
||||
('changes_before', '2019-08-09T08:03:25Z'),
|
||||
('project', '0c2accde-644a-45fa-8c10-e76debc7fbc3')
|
||||
('project', '0c2accde-644a-45fa-8c10-e76debc7fbc3'),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
ex = self.assertRaises(
|
||||
exceptions.CommandError,
|
||||
self.cmd.take_action,
|
||||
parsed_args)
|
||||
exceptions.CommandError, self.cmd.take_action, parsed_args
|
||||
)
|
||||
self.assertIn(
|
||||
'--os-compute-api-version 2.80 or greater is required',
|
||||
str(ex))
|
||||
'--os-compute-api-version 2.80 or greater is required', str(ex)
|
||||
)
|
||||
|
||||
def test_server_migration_list_with_user(self):
|
||||
arglist = [
|
||||
'--status', 'migrating',
|
||||
'--limit', '1',
|
||||
'--marker', 'test_kp',
|
||||
'--changes-since', '2019-08-07T08:03:25Z',
|
||||
'--changes-before', '2019-08-09T08:03:25Z',
|
||||
'--user', self.user.id,
|
||||
'--status',
|
||||
'migrating',
|
||||
'--limit',
|
||||
'1',
|
||||
'--marker',
|
||||
'test_kp',
|
||||
'--changes-since',
|
||||
'2019-08-07T08:03:25Z',
|
||||
'--changes-before',
|
||||
'2019-08-09T08:03:25Z',
|
||||
'--user',
|
||||
self.user.id,
|
||||
]
|
||||
verifylist = [
|
||||
('status', 'migrating'),
|
||||
@ -490,10 +606,8 @@ class TestListMigrationV280(TestListMigration):
|
||||
|
||||
self.sdk_client.migrations.assert_called_with(**kwargs)
|
||||
|
||||
self.MIGRATION_COLUMNS.insert(
|
||||
len(self.MIGRATION_COLUMNS) - 2, "User")
|
||||
self.MIGRATION_FIELDS.insert(
|
||||
len(self.MIGRATION_FIELDS) - 2, "user_id")
|
||||
self.MIGRATION_COLUMNS.insert(len(self.MIGRATION_COLUMNS) - 2, "User")
|
||||
self.MIGRATION_FIELDS.insert(len(self.MIGRATION_FIELDS) - 2, "user_id")
|
||||
self.assertEqual(self.MIGRATION_COLUMNS, columns)
|
||||
self.assertEqual(tuple(self.data), tuple(data))
|
||||
# Clean up global variables MIGRATION_COLUMNS
|
||||
@ -504,9 +618,12 @@ class TestListMigrationV280(TestListMigration):
|
||||
def test_get_migrations_with_user_pre_v280(self):
|
||||
self._set_mock_microversion('2.79')
|
||||
arglist = [
|
||||
'--status', 'migrating',
|
||||
'--changes-before', '2019-08-09T08:03:25Z',
|
||||
'--user', self.user.id,
|
||||
'--status',
|
||||
'migrating',
|
||||
'--changes-before',
|
||||
'2019-08-09T08:03:25Z',
|
||||
'--user',
|
||||
self.user.id,
|
||||
]
|
||||
verifylist = [
|
||||
('status', 'migrating'),
|
||||
@ -515,21 +632,26 @@ class TestListMigrationV280(TestListMigration):
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
ex = self.assertRaises(
|
||||
exceptions.CommandError,
|
||||
self.cmd.take_action,
|
||||
parsed_args)
|
||||
exceptions.CommandError, self.cmd.take_action, parsed_args
|
||||
)
|
||||
self.assertIn(
|
||||
'--os-compute-api-version 2.80 or greater is required',
|
||||
str(ex))
|
||||
'--os-compute-api-version 2.80 or greater is required', str(ex)
|
||||
)
|
||||
|
||||
def test_server_migration_list_with_project_and_user(self):
|
||||
arglist = [
|
||||
'--status', 'migrating',
|
||||
'--limit', '1',
|
||||
'--changes-since', '2019-08-07T08:03:25Z',
|
||||
'--changes-before', '2019-08-09T08:03:25Z',
|
||||
'--project', self.project.id,
|
||||
'--user', self.user.id,
|
||||
'--status',
|
||||
'migrating',
|
||||
'--limit',
|
||||
'1',
|
||||
'--changes-since',
|
||||
'2019-08-07T08:03:25Z',
|
||||
'--changes-before',
|
||||
'2019-08-09T08:03:25Z',
|
||||
'--project',
|
||||
self.project.id,
|
||||
'--user',
|
||||
self.user.id,
|
||||
]
|
||||
verifylist = [
|
||||
('status', 'migrating'),
|
||||
@ -556,13 +678,13 @@ class TestListMigrationV280(TestListMigration):
|
||||
self.sdk_client.migrations.assert_called_with(**kwargs)
|
||||
|
||||
self.MIGRATION_COLUMNS.insert(
|
||||
len(self.MIGRATION_COLUMNS) - 2, "Project")
|
||||
len(self.MIGRATION_COLUMNS) - 2, "Project"
|
||||
)
|
||||
self.MIGRATION_FIELDS.insert(
|
||||
len(self.MIGRATION_FIELDS) - 2, "project_id")
|
||||
self.MIGRATION_COLUMNS.insert(
|
||||
len(self.MIGRATION_COLUMNS) - 2, "User")
|
||||
self.MIGRATION_FIELDS.insert(
|
||||
len(self.MIGRATION_FIELDS) - 2, "user_id")
|
||||
len(self.MIGRATION_FIELDS) - 2, "project_id"
|
||||
)
|
||||
self.MIGRATION_COLUMNS.insert(len(self.MIGRATION_COLUMNS) - 2, "User")
|
||||
self.MIGRATION_FIELDS.insert(len(self.MIGRATION_FIELDS) - 2, "user_id")
|
||||
self.assertEqual(self.MIGRATION_COLUMNS, columns)
|
||||
self.assertEqual(tuple(self.data), tuple(data))
|
||||
# Clean up global variables MIGRATION_COLUMNS
|
||||
@ -574,29 +696,31 @@ class TestListMigrationV280(TestListMigration):
|
||||
def test_get_migrations_with_project_and_user_pre_v280(self):
|
||||
self._set_mock_microversion('2.79')
|
||||
arglist = [
|
||||
'--status', 'migrating',
|
||||
'--changes-before', '2019-08-09T08:03:25Z',
|
||||
'--project', self.project.id,
|
||||
'--user', self.user.id,
|
||||
'--status',
|
||||
'migrating',
|
||||
'--changes-before',
|
||||
'2019-08-09T08:03:25Z',
|
||||
'--project',
|
||||
self.project.id,
|
||||
'--user',
|
||||
self.user.id,
|
||||
]
|
||||
verifylist = [
|
||||
('status', 'migrating'),
|
||||
('changes_before', '2019-08-09T08:03:25Z'),
|
||||
('project', self.project.id),
|
||||
('user', self.user.id)
|
||||
('user', self.user.id),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
ex = self.assertRaises(
|
||||
exceptions.CommandError,
|
||||
self.cmd.take_action,
|
||||
parsed_args)
|
||||
exceptions.CommandError, self.cmd.take_action, parsed_args
|
||||
)
|
||||
self.assertIn(
|
||||
'--os-compute-api-version 2.80 or greater is required',
|
||||
str(ex))
|
||||
'--os-compute-api-version 2.80 or greater is required', str(ex)
|
||||
)
|
||||
|
||||
|
||||
class TestServerMigrationShow(TestServerMigration):
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
|
||||
@ -604,8 +728,9 @@ class TestServerMigrationShow(TestServerMigration):
|
||||
self.sdk_client.find_server.return_value = self.server
|
||||
|
||||
self.server_migration = compute_fakes.create_one_server_migration()
|
||||
self.sdk_client.get_server_migration.return_value =\
|
||||
self.sdk_client.get_server_migration.return_value = (
|
||||
self.server_migration
|
||||
)
|
||||
self.sdk_client.server_migrations.return_value = iter(
|
||||
[self.server_migration]
|
||||
)
|
||||
@ -665,9 +790,11 @@ class TestServerMigrationShow(TestServerMigration):
|
||||
self.assertEqual(self.data, data)
|
||||
|
||||
self.sdk_client.find_server.assert_called_with(
|
||||
self.server.id, ignore_missing=False)
|
||||
self.server.id, ignore_missing=False
|
||||
)
|
||||
self.sdk_client.get_server_migration.assert_called_with(
|
||||
self.server.id, '2', ignore_missing=False)
|
||||
self.server.id, '2', ignore_missing=False
|
||||
)
|
||||
|
||||
def test_server_migration_show(self):
|
||||
self._set_mock_microversion('2.24')
|
||||
@ -705,12 +832,11 @@ class TestServerMigrationShow(TestServerMigration):
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
ex = self.assertRaises(
|
||||
exceptions.CommandError,
|
||||
self.cmd.take_action,
|
||||
parsed_args)
|
||||
exceptions.CommandError, self.cmd.take_action, parsed_args
|
||||
)
|
||||
self.assertIn(
|
||||
'--os-compute-api-version 2.24 or greater is required',
|
||||
str(ex))
|
||||
'--os-compute-api-version 2.24 or greater is required', str(ex)
|
||||
)
|
||||
|
||||
def test_server_migration_show_by_uuid(self):
|
||||
self._set_mock_microversion('2.59')
|
||||
@ -735,7 +861,8 @@ class TestServerMigrationShow(TestServerMigration):
|
||||
self.assertEqual(self.data, data)
|
||||
|
||||
self.sdk_client.find_server.assert_called_with(
|
||||
self.server.id, ignore_missing=False)
|
||||
self.server.id, ignore_missing=False
|
||||
)
|
||||
self.sdk_client.server_migrations.assert_called_with(self.server.id)
|
||||
self.sdk_client.get_server_migration.assert_not_called()
|
||||
|
||||
@ -751,12 +878,12 @@ class TestServerMigrationShow(TestServerMigration):
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
ex = self.assertRaises(
|
||||
exceptions.CommandError,
|
||||
self.cmd.take_action,
|
||||
parsed_args)
|
||||
exceptions.CommandError, self.cmd.take_action, parsed_args
|
||||
)
|
||||
self.assertIn(
|
||||
'In-progress live migration 69f95745-bfe3-4302-90f7-5b0022cba1ce',
|
||||
str(ex))
|
||||
str(ex),
|
||||
)
|
||||
|
||||
def test_server_migration_show_by_uuid_pre_v259(self):
|
||||
self._set_mock_microversion('2.58')
|
||||
@ -769,12 +896,11 @@ class TestServerMigrationShow(TestServerMigration):
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
ex = self.assertRaises(
|
||||
exceptions.CommandError,
|
||||
self.cmd.take_action,
|
||||
parsed_args)
|
||||
exceptions.CommandError, self.cmd.take_action, parsed_args
|
||||
)
|
||||
self.assertIn(
|
||||
'--os-compute-api-version 2.59 or greater is required',
|
||||
str(ex))
|
||||
'--os-compute-api-version 2.59 or greater is required', str(ex)
|
||||
)
|
||||
|
||||
def test_server_migration_show_invalid_id(self):
|
||||
self._set_mock_microversion('2.24')
|
||||
@ -787,16 +913,14 @@ class TestServerMigrationShow(TestServerMigration):
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
ex = self.assertRaises(
|
||||
exceptions.CommandError,
|
||||
self.cmd.take_action,
|
||||
parsed_args)
|
||||
exceptions.CommandError, self.cmd.take_action, parsed_args
|
||||
)
|
||||
self.assertIn(
|
||||
'The <migration> argument must be an ID or UUID',
|
||||
str(ex))
|
||||
'The <migration> argument must be an ID or UUID', str(ex)
|
||||
)
|
||||
|
||||
|
||||
class TestServerMigrationAbort(TestServerMigration):
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
|
||||
@ -821,9 +945,11 @@ class TestServerMigrationAbort(TestServerMigration):
|
||||
result = self.cmd.take_action(parsed_args)
|
||||
|
||||
self.sdk_client.find_server.assert_called_with(
|
||||
self.server.id, ignore_missing=False)
|
||||
self.server.id, ignore_missing=False
|
||||
)
|
||||
self.sdk_client.abort_server_migration.assert_called_with(
|
||||
'2', self.server.id, ignore_missing=False)
|
||||
'2', self.server.id, ignore_missing=False
|
||||
)
|
||||
self.assertIsNone(result)
|
||||
|
||||
def test_migration_abort_pre_v224(self):
|
||||
@ -837,12 +963,11 @@ class TestServerMigrationAbort(TestServerMigration):
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
ex = self.assertRaises(
|
||||
exceptions.CommandError,
|
||||
self.cmd.take_action,
|
||||
parsed_args)
|
||||
exceptions.CommandError, self.cmd.take_action, parsed_args
|
||||
)
|
||||
self.assertIn(
|
||||
'--os-compute-api-version 2.24 or greater is required',
|
||||
str(ex))
|
||||
'--os-compute-api-version 2.24 or greater is required', str(ex)
|
||||
)
|
||||
|
||||
def test_server_migration_abort_by_uuid(self):
|
||||
self._set_mock_microversion('2.59')
|
||||
@ -862,18 +987,18 @@ class TestServerMigrationAbort(TestServerMigration):
|
||||
result = self.cmd.take_action(parsed_args)
|
||||
|
||||
self.sdk_client.find_server.assert_called_with(
|
||||
self.server.id, ignore_missing=False)
|
||||
self.server.id, ignore_missing=False
|
||||
)
|
||||
self.sdk_client.server_migrations.assert_called_with(self.server.id)
|
||||
self.sdk_client.abort_server_migration.assert_called_with(
|
||||
self.server_migration.id, self.server.id, ignore_missing=False)
|
||||
self.server_migration.id, self.server.id, ignore_missing=False
|
||||
)
|
||||
self.assertIsNone(result)
|
||||
|
||||
def test_server_migration_abort_by_uuid_no_matches(self):
|
||||
self._set_mock_microversion('2.59')
|
||||
|
||||
self.sdk_client.server_migrations.return_value = iter(
|
||||
[]
|
||||
)
|
||||
self.sdk_client.server_migrations.return_value = iter([])
|
||||
|
||||
arglist = [
|
||||
self.server.id,
|
||||
@ -883,12 +1008,12 @@ class TestServerMigrationAbort(TestServerMigration):
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
ex = self.assertRaises(
|
||||
exceptions.CommandError,
|
||||
self.cmd.take_action,
|
||||
parsed_args)
|
||||
exceptions.CommandError, self.cmd.take_action, parsed_args
|
||||
)
|
||||
self.assertIn(
|
||||
'In-progress live migration 69f95745-bfe3-4302-90f7-5b0022cba1ce',
|
||||
str(ex))
|
||||
str(ex),
|
||||
)
|
||||
|
||||
def test_server_migration_abort_by_uuid_pre_v259(self):
|
||||
self._set_mock_microversion('2.58')
|
||||
@ -901,16 +1026,14 @@ class TestServerMigrationAbort(TestServerMigration):
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
ex = self.assertRaises(
|
||||
exceptions.CommandError,
|
||||
self.cmd.take_action,
|
||||
parsed_args)
|
||||
exceptions.CommandError, self.cmd.take_action, parsed_args
|
||||
)
|
||||
self.assertIn(
|
||||
'--os-compute-api-version 2.59 or greater is required',
|
||||
str(ex))
|
||||
'--os-compute-api-version 2.59 or greater is required', str(ex)
|
||||
)
|
||||
|
||||
|
||||
class TestServerMigrationForceComplete(TestServerMigration):
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
|
||||
@ -935,9 +1058,11 @@ class TestServerMigrationForceComplete(TestServerMigration):
|
||||
result = self.cmd.take_action(parsed_args)
|
||||
|
||||
self.sdk_client.find_server.assert_called_with(
|
||||
self.server.id, ignore_missing=False)
|
||||
self.sdk_client.force_complete_server_migration\
|
||||
.assert_called_with('2', self.server.id)
|
||||
self.server.id, ignore_missing=False
|
||||
)
|
||||
self.sdk_client.force_complete_server_migration.assert_called_with(
|
||||
'2', self.server.id
|
||||
)
|
||||
self.assertIsNone(result)
|
||||
|
||||
def test_migration_force_complete_pre_v222(self):
|
||||
@ -951,12 +1076,11 @@ class TestServerMigrationForceComplete(TestServerMigration):
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
ex = self.assertRaises(
|
||||
exceptions.CommandError,
|
||||
self.cmd.take_action,
|
||||
parsed_args)
|
||||
exceptions.CommandError, self.cmd.take_action, parsed_args
|
||||
)
|
||||
self.assertIn(
|
||||
'--os-compute-api-version 2.22 or greater is required',
|
||||
str(ex))
|
||||
'--os-compute-api-version 2.22 or greater is required', str(ex)
|
||||
)
|
||||
|
||||
def test_server_migration_force_complete_by_uuid(self):
|
||||
self._set_mock_microversion('2.59')
|
||||
@ -976,10 +1100,12 @@ class TestServerMigrationForceComplete(TestServerMigration):
|
||||
result = self.cmd.take_action(parsed_args)
|
||||
|
||||
self.sdk_client.find_server.assert_called_with(
|
||||
self.server.id, ignore_missing=False)
|
||||
self.server.id, ignore_missing=False
|
||||
)
|
||||
self.sdk_client.server_migrations.assert_called_with(self.server.id)
|
||||
self.sdk_client.force_complete_server_migration.\
|
||||
assert_called_with(self.server_migration.id, self.server.id)
|
||||
self.sdk_client.force_complete_server_migration.assert_called_with(
|
||||
self.server_migration.id, self.server.id
|
||||
)
|
||||
self.assertIsNone(result)
|
||||
|
||||
def test_server_migration_force_complete_by_uuid_no_matches(self):
|
||||
@ -995,12 +1121,12 @@ class TestServerMigrationForceComplete(TestServerMigration):
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
ex = self.assertRaises(
|
||||
exceptions.CommandError,
|
||||
self.cmd.take_action,
|
||||
parsed_args)
|
||||
exceptions.CommandError, self.cmd.take_action, parsed_args
|
||||
)
|
||||
self.assertIn(
|
||||
'In-progress live migration 69f95745-bfe3-4302-90f7-5b0022cba1ce',
|
||||
str(ex))
|
||||
str(ex),
|
||||
)
|
||||
|
||||
def test_server_migration_force_complete_by_uuid_pre_v259(self):
|
||||
self._set_mock_microversion('2.58')
|
||||
@ -1013,9 +1139,8 @@ class TestServerMigrationForceComplete(TestServerMigration):
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
ex = self.assertRaises(
|
||||
exceptions.CommandError,
|
||||
self.cmd.take_action,
|
||||
parsed_args)
|
||||
exceptions.CommandError, self.cmd.take_action, parsed_args
|
||||
)
|
||||
self.assertIn(
|
||||
'--os-compute-api-version 2.59 or greater is required',
|
||||
str(ex))
|
||||
'--os-compute-api-version 2.59 or greater is required', str(ex)
|
||||
)
|
||||
|
@ -23,7 +23,6 @@ from openstackclient.tests.unit.volume.v2 import fakes as volume_fakes
|
||||
|
||||
|
||||
class TestServerVolume(compute_fakes.TestComputev2):
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
|
||||
@ -35,7 +34,6 @@ class TestServerVolume(compute_fakes.TestComputev2):
|
||||
|
||||
|
||||
class TestServerVolumeList(TestServerVolume):
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
|
||||
@ -44,15 +42,17 @@ class TestServerVolumeList(TestServerVolume):
|
||||
|
||||
self.compute_client.find_server.return_value = self.server
|
||||
self.compute_client.volume_attachments.return_value = (
|
||||
self.volume_attachments)
|
||||
self.volume_attachments
|
||||
)
|
||||
|
||||
# Get the command object to test
|
||||
self.cmd = server_volume.ListServerVolume(self.app, None)
|
||||
|
||||
@mock.patch.object(sdk_utils, 'supports_microversion')
|
||||
def test_server_volume_list(self, sm_mock):
|
||||
self.app.client_manager.compute.api_version = \
|
||||
api_versions.APIVersion('2.1')
|
||||
self.app.client_manager.compute.api_version = api_versions.APIVersion(
|
||||
'2.1'
|
||||
)
|
||||
sm_mock.side_effect = [False, False, False, False]
|
||||
|
||||
arglist = [
|
||||
@ -102,7 +102,14 @@ class TestServerVolumeList(TestServerVolume):
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
|
||||
self.assertEqual(
|
||||
('ID', 'Device', 'Server ID', 'Volume ID', 'Tag',), columns,
|
||||
(
|
||||
'ID',
|
||||
'Device',
|
||||
'Server ID',
|
||||
'Volume ID',
|
||||
'Tag',
|
||||
),
|
||||
columns,
|
||||
)
|
||||
self.assertEqual(
|
||||
(
|
||||
@ -142,7 +149,11 @@ class TestServerVolumeList(TestServerVolume):
|
||||
|
||||
self.assertEqual(
|
||||
(
|
||||
'ID', 'Device', 'Server ID', 'Volume ID', 'Tag',
|
||||
'ID',
|
||||
'Device',
|
||||
'Server ID',
|
||||
'Volume ID',
|
||||
'Tag',
|
||||
'Delete On Termination?',
|
||||
),
|
||||
columns,
|
||||
@ -174,7 +185,6 @@ class TestServerVolumeList(TestServerVolume):
|
||||
|
||||
@mock.patch.object(sdk_utils, 'supports_microversion')
|
||||
def test_server_volume_list_with_attachment_ids(self, sm_mock):
|
||||
|
||||
sm_mock.side_effect = [True, True, True, True]
|
||||
arglist = [
|
||||
self.server.id,
|
||||
@ -188,8 +198,12 @@ class TestServerVolumeList(TestServerVolume):
|
||||
|
||||
self.assertEqual(
|
||||
(
|
||||
'Device', 'Server ID', 'Volume ID', 'Tag',
|
||||
'Delete On Termination?', 'Attachment ID',
|
||||
'Device',
|
||||
'Server ID',
|
||||
'Volume ID',
|
||||
'Tag',
|
||||
'Delete On Termination?',
|
||||
'Attachment ID',
|
||||
'BlockDeviceMapping UUID',
|
||||
),
|
||||
columns,
|
||||
@ -203,8 +217,7 @@ class TestServerVolumeList(TestServerVolume):
|
||||
self.volume_attachments[0].tag,
|
||||
self.volume_attachments[0].delete_on_termination,
|
||||
self.volume_attachments[0].attachment_id,
|
||||
self.volume_attachments[0].bdm_id
|
||||
|
||||
self.volume_attachments[0].bdm_id,
|
||||
),
|
||||
(
|
||||
self.volume_attachments[1].device,
|
||||
@ -213,7 +226,7 @@ class TestServerVolumeList(TestServerVolume):
|
||||
self.volume_attachments[1].tag,
|
||||
self.volume_attachments[1].delete_on_termination,
|
||||
self.volume_attachments[1].attachment_id,
|
||||
self.volume_attachments[1].bdm_id
|
||||
self.volume_attachments[1].bdm_id,
|
||||
),
|
||||
),
|
||||
tuple(data),
|
||||
@ -224,7 +237,6 @@ class TestServerVolumeList(TestServerVolume):
|
||||
|
||||
|
||||
class TestServerVolumeUpdate(TestServerVolume):
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
|
||||
@ -299,15 +311,14 @@ class TestServerVolumeUpdate(TestServerVolume):
|
||||
result = self.cmd.take_action(parsed_args)
|
||||
|
||||
self.compute_client.update_volume_attachment.assert_called_once_with(
|
||||
self.server,
|
||||
self.volume,
|
||||
delete_on_termination=False
|
||||
self.server, self.volume, delete_on_termination=False
|
||||
)
|
||||
self.assertIsNone(result)
|
||||
|
||||
@mock.patch.object(sdk_utils, 'supports_microversion')
|
||||
def test_server_volume_update_with_delete_on_termination_pre_v285(
|
||||
self, sm_mock,
|
||||
self,
|
||||
sm_mock,
|
||||
):
|
||||
sm_mock.return_value = False
|
||||
|
||||
@ -332,7 +343,8 @@ class TestServerVolumeUpdate(TestServerVolume):
|
||||
|
||||
@mock.patch.object(sdk_utils, 'supports_microversion')
|
||||
def test_server_volume_update_with_preserve_on_termination_pre_v285(
|
||||
self, sm_mock,
|
||||
self,
|
||||
sm_mock,
|
||||
):
|
||||
sm_mock.return_value = False
|
||||
|
||||
|
@ -25,7 +25,6 @@ from openstackclient.tests.unit.compute.v2 import fakes as compute_fakes
|
||||
|
||||
|
||||
class TestService(compute_fakes.TestComputev2):
|
||||
|
||||
def setUp(self):
|
||||
super(TestService, self).setUp()
|
||||
|
||||
@ -35,7 +34,6 @@ class TestService(compute_fakes.TestComputev2):
|
||||
|
||||
|
||||
class TestServiceDelete(TestService):
|
||||
|
||||
services = compute_fakes.FakeService.create_services(count=2)
|
||||
|
||||
def setUp(self):
|
||||
@ -58,8 +56,7 @@ class TestServiceDelete(TestService):
|
||||
result = self.cmd.take_action(parsed_args)
|
||||
|
||||
self.sdk_client.delete_service.assert_called_with(
|
||||
self.services[0].binary,
|
||||
ignore_missing=False
|
||||
self.services[0].binary, ignore_missing=False
|
||||
)
|
||||
self.assertIsNone(result)
|
||||
|
||||
@ -85,14 +82,12 @@ class TestServiceDelete(TestService):
|
||||
self.services[0].binary,
|
||||
'unexist_service',
|
||||
]
|
||||
verifylist = [
|
||||
('service', arglist)
|
||||
]
|
||||
verifylist = [('service', arglist)]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
delete_mock_result = [None, exceptions.CommandError]
|
||||
self.sdk_client.delete_service = (
|
||||
mock.Mock(side_effect=delete_mock_result)
|
||||
self.sdk_client.delete_service = mock.Mock(
|
||||
side_effect=delete_mock_result
|
||||
)
|
||||
|
||||
try:
|
||||
@ -100,20 +95,18 @@ class TestServiceDelete(TestService):
|
||||
self.fail('CommandError should be raised.')
|
||||
except exceptions.CommandError as e:
|
||||
self.assertEqual(
|
||||
'1 of 2 compute services failed to delete.', str(e))
|
||||
'1 of 2 compute services failed to delete.', str(e)
|
||||
)
|
||||
|
||||
self.sdk_client.delete_service.assert_any_call(
|
||||
self.services[0].binary,
|
||||
ignore_missing=False
|
||||
self.services[0].binary, ignore_missing=False
|
||||
)
|
||||
self.sdk_client.delete_service.assert_any_call(
|
||||
'unexist_service',
|
||||
ignore_missing=False
|
||||
'unexist_service', ignore_missing=False
|
||||
)
|
||||
|
||||
|
||||
class TestServiceList(TestService):
|
||||
|
||||
service = compute_fakes.FakeService.create_one_service()
|
||||
|
||||
columns = (
|
||||
@ -125,20 +118,20 @@ class TestServiceList(TestService):
|
||||
'State',
|
||||
'Updated At',
|
||||
)
|
||||
columns_long = columns + (
|
||||
'Disabled Reason',
|
||||
)
|
||||
columns_long = columns + ('Disabled Reason',)
|
||||
|
||||
data = [(
|
||||
service.id,
|
||||
service.binary,
|
||||
service.host,
|
||||
service.availability_zone,
|
||||
service.status,
|
||||
service.state,
|
||||
service.updated_at,
|
||||
)]
|
||||
data_long = [data[0] + (service.disabled_reason, )]
|
||||
data = [
|
||||
(
|
||||
service.id,
|
||||
service.binary,
|
||||
service.host,
|
||||
service.availability_zone,
|
||||
service.status,
|
||||
service.state,
|
||||
service.updated_at,
|
||||
)
|
||||
]
|
||||
data_long = [data[0] + (service.disabled_reason,)]
|
||||
|
||||
def setUp(self):
|
||||
super(TestServiceList, self).setUp()
|
||||
@ -150,8 +143,10 @@ class TestServiceList(TestService):
|
||||
|
||||
def test_service_list(self):
|
||||
arglist = [
|
||||
'--host', self.service.host,
|
||||
'--service', self.service.binary,
|
||||
'--host',
|
||||
self.service.host,
|
||||
'--service',
|
||||
self.service.binary,
|
||||
]
|
||||
verifylist = [
|
||||
('host', self.service.host),
|
||||
@ -177,14 +172,16 @@ class TestServiceList(TestService):
|
||||
sm_mock.return_value = False
|
||||
|
||||
arglist = [
|
||||
'--host', self.service.host,
|
||||
'--service', self.service.binary,
|
||||
'--long'
|
||||
'--host',
|
||||
self.service.host,
|
||||
'--service',
|
||||
self.service.binary,
|
||||
'--long',
|
||||
]
|
||||
verifylist = [
|
||||
('host', self.service.host),
|
||||
('service', self.service.binary),
|
||||
('long', True)
|
||||
('long', True),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
@ -206,18 +203,21 @@ class TestServiceList(TestService):
|
||||
sm_mock.return_value = True
|
||||
|
||||
arglist = [
|
||||
'--host', self.service.host,
|
||||
'--service', self.service.binary,
|
||||
'--long'
|
||||
'--host',
|
||||
self.service.host,
|
||||
'--service',
|
||||
self.service.binary,
|
||||
'--long',
|
||||
]
|
||||
verifylist = [
|
||||
('host', self.service.host),
|
||||
('service', self.service.binary),
|
||||
('long', True)
|
||||
('long', True),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
self.app.client_manager.compute.api_version = api_versions.APIVersion(
|
||||
'2.11')
|
||||
'2.11'
|
||||
)
|
||||
|
||||
# In base command class Lister in cliff, abstract method take_action()
|
||||
# returns a tuple containing the column names and an iterable
|
||||
@ -238,7 +238,6 @@ class TestServiceList(TestService):
|
||||
|
||||
|
||||
class TestServiceSet(TestService):
|
||||
|
||||
def setUp(self):
|
||||
super(TestServiceSet, self).setUp()
|
||||
|
||||
@ -285,9 +284,7 @@ class TestServiceSet(TestService):
|
||||
result = self.cmd.take_action(parsed_args)
|
||||
|
||||
self.sdk_client.enable_service.assert_called_with(
|
||||
None,
|
||||
self.service.host,
|
||||
self.service.binary
|
||||
None, self.service.host, self.service.binary
|
||||
)
|
||||
self.assertIsNone(result)
|
||||
|
||||
@ -309,10 +306,7 @@ class TestServiceSet(TestService):
|
||||
result = self.cmd.take_action(parsed_args)
|
||||
|
||||
self.sdk_client.disable_service.assert_called_with(
|
||||
None,
|
||||
self.service.host,
|
||||
self.service.binary,
|
||||
None
|
||||
None, self.service.host, self.service.binary, None
|
||||
)
|
||||
self.assertIsNone(result)
|
||||
|
||||
@ -322,7 +316,8 @@ class TestServiceSet(TestService):
|
||||
reason = 'earthquake'
|
||||
arglist = [
|
||||
'--disable',
|
||||
'--disable-reason', reason,
|
||||
'--disable-reason',
|
||||
reason,
|
||||
self.service.host,
|
||||
self.service.binary,
|
||||
]
|
||||
@ -337,10 +332,7 @@ class TestServiceSet(TestService):
|
||||
result = self.cmd.take_action(parsed_args)
|
||||
|
||||
self.sdk_client.disable_service.assert_called_with(
|
||||
None,
|
||||
self.service.host,
|
||||
self.service.binary,
|
||||
reason
|
||||
None, self.service.host, self.service.binary, reason
|
||||
)
|
||||
self.assertIsNone(result)
|
||||
|
||||
@ -349,7 +341,8 @@ class TestServiceSet(TestService):
|
||||
sm_mock.return_value = False
|
||||
reason = 'earthquake'
|
||||
arglist = [
|
||||
'--disable-reason', reason,
|
||||
'--disable-reason',
|
||||
reason,
|
||||
self.service.host,
|
||||
self.service.binary,
|
||||
]
|
||||
@ -363,8 +356,11 @@ class TestServiceSet(TestService):
|
||||
self.cmd.take_action(parsed_args)
|
||||
self.fail("CommandError should be raised.")
|
||||
except exceptions.CommandError as e:
|
||||
self.assertEqual("Cannot specify option --disable-reason without "
|
||||
"--disable specified.", str(e))
|
||||
self.assertEqual(
|
||||
"Cannot specify option --disable-reason without "
|
||||
"--disable specified.",
|
||||
str(e),
|
||||
)
|
||||
|
||||
@mock.patch.object(sdk_utils, 'supports_microversion')
|
||||
def test_service_set_enable_with_disable_reason(self, sm_mock):
|
||||
@ -372,7 +368,8 @@ class TestServiceSet(TestService):
|
||||
reason = 'earthquake'
|
||||
arglist = [
|
||||
'--enable',
|
||||
'--disable-reason', reason,
|
||||
'--disable-reason',
|
||||
reason,
|
||||
self.service.host,
|
||||
self.service.binary,
|
||||
]
|
||||
@ -387,8 +384,11 @@ class TestServiceSet(TestService):
|
||||
self.cmd.take_action(parsed_args)
|
||||
self.fail("CommandError should be raised.")
|
||||
except exceptions.CommandError as e:
|
||||
self.assertEqual("Cannot specify option --disable-reason without "
|
||||
"--disable specified.", str(e))
|
||||
self.assertEqual(
|
||||
"Cannot specify option --disable-reason without "
|
||||
"--disable specified.",
|
||||
str(e),
|
||||
)
|
||||
|
||||
@mock.patch.object(sdk_utils, 'supports_microversion')
|
||||
def test_service_set_state_up(self, sm_mock):
|
||||
@ -406,10 +406,7 @@ class TestServiceSet(TestService):
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
result = self.cmd.take_action(parsed_args)
|
||||
self.sdk_client.update_service_forced_down.assert_called_once_with(
|
||||
None,
|
||||
self.service.host,
|
||||
self.service.binary,
|
||||
False
|
||||
None, self.service.host, self.service.binary, False
|
||||
)
|
||||
self.assertNotCalled(self.sdk_client.enable_service)
|
||||
self.assertNotCalled(self.sdk_client.disable_service)
|
||||
@ -431,10 +428,7 @@ class TestServiceSet(TestService):
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
result = self.cmd.take_action(parsed_args)
|
||||
self.sdk_client.update_service_forced_down.assert_called_once_with(
|
||||
None,
|
||||
self.service.host,
|
||||
self.service.binary,
|
||||
True
|
||||
None, self.service.host, self.service.binary, True
|
||||
)
|
||||
self.assertNotCalled(self.sdk_client.enable_service)
|
||||
self.assertNotCalled(self.sdk_client.disable_service)
|
||||
@ -458,15 +452,10 @@ class TestServiceSet(TestService):
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
result = self.cmd.take_action(parsed_args)
|
||||
self.sdk_client.enable_service.assert_called_once_with(
|
||||
None,
|
||||
self.service.host,
|
||||
self.service.binary
|
||||
None, self.service.host, self.service.binary
|
||||
)
|
||||
self.sdk_client.update_service_forced_down.assert_called_once_with(
|
||||
None,
|
||||
self.service.host,
|
||||
self.service.binary,
|
||||
True
|
||||
None, self.service.host, self.service.binary, True
|
||||
)
|
||||
self.assertIsNone(result)
|
||||
|
||||
@ -487,15 +476,14 @@ class TestServiceSet(TestService):
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
with mock.patch.object(self.sdk_client, 'enable_service',
|
||||
side_effect=Exception()):
|
||||
self.assertRaises(exceptions.CommandError,
|
||||
self.cmd.take_action, parsed_args)
|
||||
with mock.patch.object(
|
||||
self.sdk_client, 'enable_service', side_effect=Exception()
|
||||
):
|
||||
self.assertRaises(
|
||||
exceptions.CommandError, self.cmd.take_action, parsed_args
|
||||
)
|
||||
self.sdk_client.update_service_forced_down.assert_called_once_with(
|
||||
None,
|
||||
self.service.host,
|
||||
self.service.binary,
|
||||
True
|
||||
None, self.service.host, self.service.binary, True
|
||||
)
|
||||
|
||||
@mock.patch.object(sdk_utils, 'supports_microversion')
|
||||
@ -520,16 +508,11 @@ class TestServiceSet(TestService):
|
||||
self.sdk_client.services.return_value = [mock.Mock(id=service_id)]
|
||||
result = self.cmd.take_action(parsed_args)
|
||||
self.sdk_client.disable_service.assert_called_once_with(
|
||||
service_id,
|
||||
self.service.host,
|
||||
self.service.binary,
|
||||
None
|
||||
service_id, self.service.host, self.service.binary, None
|
||||
)
|
||||
self.sdk_client.update_service_forced_down.assert_called_once_with(
|
||||
service_id,
|
||||
self.service.host,
|
||||
self.service.binary,
|
||||
True)
|
||||
service_id, self.service.host, self.service.binary, True
|
||||
)
|
||||
self.assertIsNone(result)
|
||||
|
||||
@mock.patch.object(sdk_utils, 'supports_microversion')
|
||||
@ -540,7 +523,8 @@ class TestServiceSet(TestService):
|
||||
reason = 'earthquake'
|
||||
arglist = [
|
||||
'--disable',
|
||||
'--disable-reason', reason,
|
||||
'--disable-reason',
|
||||
reason,
|
||||
self.service.host,
|
||||
self.service.binary,
|
||||
]
|
||||
@ -555,10 +539,7 @@ class TestServiceSet(TestService):
|
||||
self.sdk_client.services.return_value = [mock.Mock(id=service_id)]
|
||||
result = self.cmd.take_action(parsed_args)
|
||||
self.sdk_client.disable_service.assert_called_once_with(
|
||||
service_id,
|
||||
self.service.host,
|
||||
self.service.binary,
|
||||
reason
|
||||
service_id, self.service.host, self.service.binary, reason
|
||||
)
|
||||
self.assertIsNone(result)
|
||||
|
||||
@ -584,33 +565,41 @@ class TestServiceSet(TestService):
|
||||
self.sdk_client.services.return_value = [mock.Mock(id=service_id)]
|
||||
result = self.cmd.take_action(parsed_args)
|
||||
self.sdk_client.enable_service.assert_called_once_with(
|
||||
service_id,
|
||||
self.service.host,
|
||||
self.service.binary
|
||||
service_id, self.service.host, self.service.binary
|
||||
)
|
||||
self.sdk_client.update_service_forced_down.assert_called_once_with(
|
||||
service_id,
|
||||
self.service.host,
|
||||
self.service.binary,
|
||||
False
|
||||
service_id, self.service.host, self.service.binary, False
|
||||
)
|
||||
self.assertIsNone(result)
|
||||
|
||||
def test_service_set_find_service_by_host_and_binary_no_results(self):
|
||||
# Tests that no compute services are found by host and binary.
|
||||
self.sdk_client.services.return_value = []
|
||||
ex = self.assertRaises(exceptions.CommandError,
|
||||
self.cmd._find_service_by_host_and_binary,
|
||||
self.sdk_client, 'fake-host', 'nova-compute')
|
||||
self.assertIn('Compute service for host "fake-host" and binary '
|
||||
'"nova-compute" not found.', str(ex))
|
||||
ex = self.assertRaises(
|
||||
exceptions.CommandError,
|
||||
self.cmd._find_service_by_host_and_binary,
|
||||
self.sdk_client,
|
||||
'fake-host',
|
||||
'nova-compute',
|
||||
)
|
||||
self.assertIn(
|
||||
'Compute service for host "fake-host" and binary '
|
||||
'"nova-compute" not found.',
|
||||
str(ex),
|
||||
)
|
||||
|
||||
def test_service_set_find_service_by_host_and_binary_many_results(self):
|
||||
# Tests that more than one compute service is found by host and binary.
|
||||
self.sdk_client.services.return_value = [mock.Mock(), mock.Mock()]
|
||||
ex = self.assertRaises(exceptions.CommandError,
|
||||
self.cmd._find_service_by_host_and_binary,
|
||||
self.sdk_client, 'fake-host', 'nova-compute')
|
||||
self.assertIn('Multiple compute services found for host "fake-host" '
|
||||
'and binary "nova-compute". Unable to proceed.',
|
||||
str(ex))
|
||||
ex = self.assertRaises(
|
||||
exceptions.CommandError,
|
||||
self.cmd._find_service_by_host_and_binary,
|
||||
self.sdk_client,
|
||||
'fake-host',
|
||||
'nova-compute',
|
||||
)
|
||||
self.assertIn(
|
||||
'Multiple compute services found for host "fake-host" '
|
||||
'and binary "nova-compute". Unable to proceed.',
|
||||
str(ex),
|
||||
)
|
||||
|
@ -19,7 +19,6 @@ from openstackclient.tests.unit.identity.v3 import fakes as identity_fakes
|
||||
|
||||
|
||||
class TestUsage(compute_fakes.TestComputev2):
|
||||
|
||||
def setUp(self):
|
||||
super(TestUsage, self).setUp()
|
||||
|
||||
@ -32,27 +31,29 @@ class TestUsage(compute_fakes.TestComputev2):
|
||||
|
||||
|
||||
class TestUsageList(TestUsage):
|
||||
|
||||
project = identity_fakes.FakeProject.create_one_project()
|
||||
# Return value of self.usage_mock.list().
|
||||
usages = compute_fakes.FakeUsage.create_usages(
|
||||
attrs={'project_id': project.name}, count=1)
|
||||
attrs={'project_id': project.name}, count=1
|
||||
)
|
||||
|
||||
columns = (
|
||||
"Project",
|
||||
"Servers",
|
||||
"RAM MB-Hours",
|
||||
"CPU Hours",
|
||||
"Disk GB-Hours"
|
||||
"Disk GB-Hours",
|
||||
)
|
||||
|
||||
data = [(
|
||||
usage_cmds.ProjectColumn(usages[0].project_id),
|
||||
usage_cmds.CountColumn(usages[0].server_usages),
|
||||
usage_cmds.FloatColumn(usages[0].total_memory_mb_usage),
|
||||
usage_cmds.FloatColumn(usages[0].total_vcpus_usage),
|
||||
usage_cmds.FloatColumn(usages[0].total_local_gb_usage),
|
||||
)]
|
||||
data = [
|
||||
(
|
||||
usage_cmds.ProjectColumn(usages[0].project_id),
|
||||
usage_cmds.CountColumn(usages[0].server_usages),
|
||||
usage_cmds.FloatColumn(usages[0].total_memory_mb_usage),
|
||||
usage_cmds.FloatColumn(usages[0].total_vcpus_usage),
|
||||
usage_cmds.FloatColumn(usages[0].total_local_gb_usage),
|
||||
)
|
||||
]
|
||||
|
||||
def setUp(self):
|
||||
super(TestUsageList, self).setUp()
|
||||
@ -64,7 +65,6 @@ class TestUsageList(TestUsage):
|
||||
self.cmd = usage_cmds.ListUsage(self.app, None)
|
||||
|
||||
def test_usage_list_no_options(self):
|
||||
|
||||
arglist = []
|
||||
verifylist = [
|
||||
('start', None),
|
||||
@ -82,8 +82,10 @@ class TestUsageList(TestUsage):
|
||||
|
||||
def test_usage_list_with_options(self):
|
||||
arglist = [
|
||||
'--start', '2016-11-11',
|
||||
'--end', '2016-12-20',
|
||||
'--start',
|
||||
'2016-11-11',
|
||||
'--end',
|
||||
'2016-12-20',
|
||||
]
|
||||
verifylist = [
|
||||
('start', '2016-11-11'),
|
||||
@ -98,7 +100,8 @@ class TestUsageList(TestUsage):
|
||||
self.sdk_client.usages.assert_called_with(
|
||||
start='2016-11-11T00:00:00',
|
||||
end='2016-12-20T00:00:00',
|
||||
detailed=True)
|
||||
detailed=True,
|
||||
)
|
||||
|
||||
self.assertCountEqual(self.columns, columns)
|
||||
self.assertCountEqual(tuple(self.data), tuple(data))
|
||||
@ -115,19 +118,19 @@ class TestUsageList(TestUsage):
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
|
||||
self.projects_mock.list.assert_called_with()
|
||||
self.sdk_client.usages.assert_has_calls([
|
||||
mock.call(start=mock.ANY, end=mock.ANY, detailed=True)
|
||||
])
|
||||
self.sdk_client.usages.assert_has_calls(
|
||||
[mock.call(start=mock.ANY, end=mock.ANY, detailed=True)]
|
||||
)
|
||||
self.assertCountEqual(self.columns, columns)
|
||||
self.assertCountEqual(tuple(self.data), tuple(data))
|
||||
|
||||
|
||||
class TestUsageShow(TestUsage):
|
||||
|
||||
project = identity_fakes.FakeProject.create_one_project()
|
||||
# Return value of self.usage_mock.list().
|
||||
usage = compute_fakes.FakeUsage.create_one_usage(
|
||||
attrs={'project_id': project.name})
|
||||
attrs={'project_id': project.name}
|
||||
)
|
||||
|
||||
columns = (
|
||||
'Project',
|
||||
@ -155,7 +158,6 @@ class TestUsageShow(TestUsage):
|
||||
self.cmd = usage_cmds.ShowUsage(self.app, None)
|
||||
|
||||
def test_usage_show_no_options(self):
|
||||
|
||||
self.app.client_manager.auth_ref = mock.Mock()
|
||||
self.app.client_manager.auth_ref.project_id = self.project.id
|
||||
|
||||
@ -174,11 +176,13 @@ class TestUsageShow(TestUsage):
|
||||
self.assertEqual(self.data, data)
|
||||
|
||||
def test_usage_show_with_options(self):
|
||||
|
||||
arglist = [
|
||||
'--project', self.project.id,
|
||||
'--start', '2016-11-11',
|
||||
'--end', '2016-12-20',
|
||||
'--project',
|
||||
self.project.id,
|
||||
'--start',
|
||||
'2016-11-11',
|
||||
'--end',
|
||||
'2016-12-20',
|
||||
]
|
||||
verifylist = [
|
||||
('project', self.project.id),
|
||||
@ -193,7 +197,8 @@ class TestUsageShow(TestUsage):
|
||||
self.sdk_client.get_usage.assert_called_with(
|
||||
project=self.project.id,
|
||||
start='2016-11-11T00:00:00',
|
||||
end='2016-12-20T00:00:00')
|
||||
end='2016-12-20T00:00:00',
|
||||
)
|
||||
|
||||
self.assertEqual(self.columns, columns)
|
||||
self.assertEqual(self.data, data)
|
||||
|
Loading…
x
Reference in New Issue
Block a user