trivial: Add missing ignore_missing arguments
This prevents a class of bugs. Change-Id: I96e1cd8ed4a682ef5c95f67f3d1246f7026eada9 Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
This commit is contained in:
@@ -2180,7 +2180,9 @@ class CreateServerDump(command.Command):
|
||||
def take_action(self, parsed_args):
|
||||
compute_client = self.app.client_manager.compute
|
||||
for name_or_id in parsed_args.server:
|
||||
server = compute_client.find_server(name_or_id)
|
||||
server = compute_client.find_server(
|
||||
name_or_id, ignore_missing=False
|
||||
)
|
||||
server.trigger_crash_dump(compute_client)
|
||||
|
||||
|
||||
|
||||
@@ -278,7 +278,7 @@ class DeleteApplicationCredential(command.Command):
|
||||
for ac in parsed_args.application_credential:
|
||||
try:
|
||||
app_cred = identity_client.find_application_credential(
|
||||
user_id, ac
|
||||
user_id, ac, ignore_missing=False
|
||||
)
|
||||
identity_client.delete_application_credential(
|
||||
user_id, app_cred.id
|
||||
|
||||
@@ -107,7 +107,9 @@ class CreateDomain(command.ShowOne):
|
||||
)
|
||||
except sdk_exceptions.ConflictException:
|
||||
if parsed_args.or_show:
|
||||
domain = identity_client.find_domain(parsed_args.name)
|
||||
domain = identity_client.find_domain(
|
||||
parsed_args.name, ignore_missing=False
|
||||
)
|
||||
LOG.info(_('Returning existing domain %s'), domain.name)
|
||||
else:
|
||||
raise
|
||||
@@ -238,7 +240,9 @@ class SetDomain(command.Command):
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
identity_client = self.app.client_manager.sdk_connection.identity
|
||||
domain = identity_client.find_domain(parsed_args.domain)
|
||||
domain = identity_client.find_domain(
|
||||
parsed_args.domain, ignore_missing=False
|
||||
)
|
||||
kwargs = {}
|
||||
if parsed_args.name:
|
||||
kwargs['name'] = parsed_args.name
|
||||
@@ -266,6 +270,8 @@ class ShowDomain(command.ShowOne):
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
identity_client = self.app.client_manager.sdk_connection.identity
|
||||
domain = identity_client.find_domain(parsed_args.domain)
|
||||
domain = identity_client.find_domain(
|
||||
parsed_args.domain, ignore_missing=False
|
||||
)
|
||||
|
||||
return _format_domain(domain)
|
||||
|
||||
@@ -169,7 +169,9 @@ class DeleteEndpoint(command.Command):
|
||||
result = 0
|
||||
for i in parsed_args.endpoint:
|
||||
try:
|
||||
endpoint_id = identity_client.find_endpoint(i).id
|
||||
endpoint_id = identity_client.find_endpoint(
|
||||
i, ignore_missing=False
|
||||
).id
|
||||
identity_client.delete_endpoint(endpoint_id)
|
||||
except Exception as e:
|
||||
result += 1
|
||||
@@ -230,7 +232,9 @@ class ListEndpoint(command.Lister):
|
||||
|
||||
endpoint = None
|
||||
if parsed_args.endpoint:
|
||||
endpoint = identity_client.find_endpoint(parsed_args.endpoint)
|
||||
endpoint = identity_client.find_endpoint(
|
||||
parsed_args.endpoint, ignore_missing=False
|
||||
)
|
||||
|
||||
project_domain_id = None
|
||||
if parsed_args.project_domain:
|
||||
@@ -292,7 +296,9 @@ class ListEndpoint(command.Lister):
|
||||
data = list(identity_client.endpoints(**kwargs))
|
||||
|
||||
for ep in data:
|
||||
service = identity_client.find_service(ep.service_id)
|
||||
service = identity_client.find_service(
|
||||
ep.service_id, ignore_missing=False
|
||||
)
|
||||
ep.service_name = getattr(service, 'name', '')
|
||||
ep.service_type = service.type
|
||||
|
||||
@@ -393,7 +399,9 @@ class SetEndpoint(command.Command):
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
identity_client = self.app.client_manager.sdk_connection.identity
|
||||
endpoint = identity_client.find_endpoint(parsed_args.endpoint)
|
||||
endpoint = identity_client.find_endpoint(
|
||||
parsed_args.endpoint, ignore_missing=False
|
||||
)
|
||||
|
||||
kwargs = {}
|
||||
|
||||
@@ -440,7 +448,9 @@ class ShowEndpoint(command.ShowOne):
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
identity_client = self.app.client_manager.sdk_connection.identity
|
||||
endpoint = identity_client.find_endpoint(parsed_args.endpoint)
|
||||
endpoint = identity_client.find_endpoint(
|
||||
parsed_args.endpoint, ignore_missing=False
|
||||
)
|
||||
|
||||
service = common.find_service_sdk(identity_client, endpoint.service_id)
|
||||
|
||||
|
||||
@@ -211,10 +211,15 @@ class CreateGroup(command.ShowOne):
|
||||
if parsed_args.or_show:
|
||||
if parsed_args.domain:
|
||||
group = identity_client.find_group(
|
||||
parsed_args.name, domain_id=parsed_args.domain
|
||||
parsed_args.name,
|
||||
domain_id=parsed_args.domain,
|
||||
ignore_missing=False,
|
||||
)
|
||||
else:
|
||||
group = identity_client.find_group(parsed_args.name)
|
||||
group = identity_client.find_group(
|
||||
parsed_args.name,
|
||||
ignore_missing=False,
|
||||
)
|
||||
LOG.info(_('Returning existing group %s'), group.name)
|
||||
else:
|
||||
raise
|
||||
|
||||
@@ -410,6 +410,7 @@ class ListRole(command.Lister):
|
||||
if parsed_args.domain:
|
||||
domain = identity_client.find_domain(
|
||||
name_or_id=parsed_args.domain,
|
||||
ignore_missing=False,
|
||||
)
|
||||
data = identity_client.roles(domain_id=domain.id)
|
||||
return (
|
||||
|
||||
@@ -179,7 +179,9 @@ class CreateTrust(command.ShowOne):
|
||||
roles = []
|
||||
for role in parsed_args.roles:
|
||||
try:
|
||||
role_id = identity_client.find_role(role).id
|
||||
role_id = identity_client.find_role(
|
||||
role, ignore_missing=False
|
||||
).id
|
||||
except sdk_exceptions.ForbiddenException:
|
||||
role_id = role
|
||||
roles.append({"id": role_id})
|
||||
|
||||
@@ -441,6 +441,7 @@ class ListUser(command.Lister):
|
||||
if parsed_args.domain:
|
||||
domain = identity_client.find_domain(
|
||||
name_or_id=parsed_args.domain,
|
||||
ignore_missing=False,
|
||||
).id
|
||||
|
||||
group = None
|
||||
|
||||
@@ -119,7 +119,10 @@ class DeleteNetworkTrunk(command.Command):
|
||||
result = 0
|
||||
for trunk in parsed_args.trunk:
|
||||
try:
|
||||
trunk_id = network_client.find_trunk(trunk).id
|
||||
trunk_id = network_client.find_trunk(
|
||||
trunk,
|
||||
ignore_missing=False,
|
||||
).id
|
||||
network_client.delete_trunk(trunk_id)
|
||||
except Exception as e:
|
||||
result += 1
|
||||
@@ -220,7 +223,10 @@ class SetNetworkTrunk(command.Command):
|
||||
def take_action(self, parsed_args):
|
||||
network_client = self.app.client_manager.network
|
||||
identity_client = self.app.client_manager.identity
|
||||
trunk_id = network_client.find_trunk(parsed_args.trunk)
|
||||
trunk_id = network_client.find_trunk(
|
||||
parsed_args.trunk,
|
||||
ignore_missing=False,
|
||||
)
|
||||
attrs = _get_attrs_for_trunk(
|
||||
network_client, identity_client, parsed_args
|
||||
)
|
||||
@@ -258,7 +264,10 @@ class ShowNetworkTrunk(command.ShowOne):
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
network_client = self.app.client_manager.network
|
||||
trunk_id = network_client.find_trunk(parsed_args.trunk).id
|
||||
trunk_id = network_client.find_trunk(
|
||||
parsed_args.trunk,
|
||||
ignore_missing=False,
|
||||
).id
|
||||
obj = network_client.get_trunk(trunk_id)
|
||||
display_columns, columns = _get_columns(obj)
|
||||
data = osc_utils.get_dict_properties(
|
||||
@@ -282,7 +291,10 @@ class ListNetworkSubport(command.Lister):
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
network_client = self.app.client_manager.network
|
||||
trunk_id = network_client.find_trunk(parsed_args.trunk)
|
||||
trunk_id = network_client.find_trunk(
|
||||
parsed_args.trunk,
|
||||
ignore_missing=False,
|
||||
)
|
||||
data = network_client.get_trunk_subports(trunk_id)
|
||||
headers: tuple[str, ...] = (
|
||||
'Port',
|
||||
@@ -332,7 +344,10 @@ class UnsetNetworkTrunk(command.Command):
|
||||
def take_action(self, parsed_args):
|
||||
network_client = self.app.client_manager.network
|
||||
attrs = _get_attrs_for_subports(network_client, parsed_args)
|
||||
trunk_id = network_client.find_trunk(parsed_args.trunk)
|
||||
trunk_id = network_client.find_trunk(
|
||||
parsed_args.trunk,
|
||||
ignore_missing=False,
|
||||
)
|
||||
network_client.delete_trunk_subports(trunk_id, attrs)
|
||||
|
||||
|
||||
@@ -360,7 +375,10 @@ def _get_attrs_for_trunk(network_client, identity_client, parsed_args):
|
||||
if parsed_args.disable:
|
||||
attrs['admin_state_up'] = False
|
||||
if 'parent_port' in parsed_args and parsed_args.parent_port is not None:
|
||||
port_id = network_client.find_port(parsed_args.parent_port)['id']
|
||||
port_id = network_client.find_port(
|
||||
parsed_args.parent_port,
|
||||
ignore_missing=False,
|
||||
).id
|
||||
attrs['port_id'] = port_id
|
||||
if 'add_subports' in parsed_args and parsed_args.add_subports is not None:
|
||||
attrs[SUB_PORTS] = _format_subports(
|
||||
@@ -384,7 +402,10 @@ def _format_subports(network_client, subports):
|
||||
for subport in subports:
|
||||
subport_attrs = {}
|
||||
if subport.get('port'):
|
||||
port_id = network_client.find_port(subport['port'])['id']
|
||||
port_id = network_client.find_port(
|
||||
subport['port'],
|
||||
ignore_missing=False,
|
||||
).id
|
||||
subport_attrs['port_id'] = port_id
|
||||
if subport.get('segmentation-id'):
|
||||
try:
|
||||
@@ -413,11 +434,10 @@ def _get_attrs_for_subports(network_client, parsed_args):
|
||||
):
|
||||
subports_list = []
|
||||
for subport in parsed_args.unset_subports:
|
||||
port_id = network_client.find_port(subport)['id']
|
||||
port_id = network_client.find_port(
|
||||
subport,
|
||||
ignore_missing=False,
|
||||
)['id']
|
||||
subports_list.append({'port_id': port_id})
|
||||
attrs = subports_list
|
||||
return attrs
|
||||
|
||||
|
||||
def _get_id(client, id_or_name, resource):
|
||||
return client.find_resource(resource, str(id_or_name))['id']
|
||||
|
||||
@@ -636,11 +636,11 @@ class CreatePort(command.ShowOne, common.NeutronCommandWithExtraArgs):
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
client = self.app.client_manager.network
|
||||
_network = client.find_network(
|
||||
network_client = self.app.client_manager.network
|
||||
network = network_client.find_network(
|
||||
parsed_args.network, ignore_missing=False
|
||||
)
|
||||
parsed_args.network = _network.id
|
||||
parsed_args.network = network.id
|
||||
_prepare_fixed_ips(self.app.client_manager, parsed_args)
|
||||
attrs = _get_attrs(self.app.client_manager, parsed_args)
|
||||
|
||||
@@ -654,7 +654,7 @@ class CreatePort(command.ShowOne, common.NeutronCommandWithExtraArgs):
|
||||
|
||||
if parsed_args.security_groups is not None:
|
||||
attrs['security_group_ids'] = [
|
||||
client.find_security_group(sg, ignore_missing=False).id
|
||||
network_client.find_security_group(sg, ignore_missing=False).id
|
||||
for sg in parsed_args.security_groups
|
||||
]
|
||||
|
||||
@@ -667,7 +667,7 @@ class CreatePort(command.ShowOne, common.NeutronCommandWithExtraArgs):
|
||||
attrs["extra_dhcp_opts"] = _convert_extra_dhcp_options(parsed_args)
|
||||
|
||||
if parsed_args.qos_policy:
|
||||
attrs['qos_policy_id'] = client.find_qos_policy(
|
||||
attrs['qos_policy_id'] = network_client.find_qos_policy(
|
||||
parsed_args.qos_policy, ignore_missing=False
|
||||
).id
|
||||
|
||||
@@ -675,7 +675,9 @@ class CreatePort(command.ShowOne, common.NeutronCommandWithExtraArgs):
|
||||
_validate_port_hints(parsed_args.hint)
|
||||
expanded_hints = _expand_port_hint_aliases(parsed_args.hint)
|
||||
try:
|
||||
client.find_extension('port-hints', ignore_missing=False)
|
||||
network_client.find_extension(
|
||||
'port-hints', ignore_missing=False
|
||||
)
|
||||
except Exception as e:
|
||||
msg = _('Not supported by Network API: %(e)s') % {'e': e}
|
||||
raise exceptions.CommandError(msg)
|
||||
@@ -686,7 +688,7 @@ class CreatePort(command.ShowOne, common.NeutronCommandWithExtraArgs):
|
||||
in expanded_hints['openvswitch']['other_config']
|
||||
):
|
||||
try:
|
||||
client.find_extension(
|
||||
network_client.find_extension(
|
||||
'port-hint-ovs-tx-steering', ignore_missing=False
|
||||
)
|
||||
except Exception as e:
|
||||
@@ -695,7 +697,9 @@ class CreatePort(command.ShowOne, common.NeutronCommandWithExtraArgs):
|
||||
attrs['hints'] = expanded_hints
|
||||
|
||||
set_tags_in_post = bool(
|
||||
client.find_extension('tag-ports-during-bulk-creation')
|
||||
network_client.find_extension(
|
||||
'tag-ports-during-bulk-creation', ignore_missing=True
|
||||
)
|
||||
)
|
||||
if set_tags_in_post:
|
||||
if parsed_args.no_tag:
|
||||
@@ -707,14 +711,12 @@ class CreatePort(command.ShowOne, common.NeutronCommandWithExtraArgs):
|
||||
self._parse_extra_properties(parsed_args.extra_properties)
|
||||
)
|
||||
|
||||
with common.check_missing_extension_if_error(
|
||||
self.app.client_manager.network, attrs
|
||||
):
|
||||
obj = client.create_port(**attrs)
|
||||
with common.check_missing_extension_if_error(network_client, attrs):
|
||||
obj = network_client.create_port(**attrs)
|
||||
|
||||
if not set_tags_in_post:
|
||||
# tags cannot be set when created, so tags need to be set later.
|
||||
_tag.update_tags_for_set(client, obj, parsed_args)
|
||||
_tag.update_tags_for_set(network_client, obj, parsed_args)
|
||||
|
||||
display_columns, columns = _get_columns(obj)
|
||||
data = utils.get_item_properties(obj, columns, formatters=_formatters)
|
||||
|
||||
@@ -89,7 +89,12 @@ def _get_columns(item):
|
||||
|
||||
|
||||
def is_multiple_gateways_supported(n_client):
|
||||
return n_client.find_extension("external-gateway-multihoming") is not None
|
||||
return (
|
||||
n_client.find_extension(
|
||||
"external-gateway-multihoming", ignore_missing=True
|
||||
)
|
||||
is not None
|
||||
)
|
||||
|
||||
|
||||
def _passed_multiple_gateways(extension_supported, external_gateways):
|
||||
@@ -236,7 +241,9 @@ def _get_attrs(client_manager, parsed_args):
|
||||
|
||||
# "router set" command doesn't support setting flavor_id.
|
||||
if 'flavor_id' in parsed_args and parsed_args.flavor_id is not None:
|
||||
flavor = n_client.find_flavor(parsed_args.flavor_id)
|
||||
flavor = n_client.find_flavor(
|
||||
parsed_args.flavor_id, ignore_missing=False
|
||||
)
|
||||
attrs['flavor_id'] = flavor.id
|
||||
elif 'flavor' in parsed_args and parsed_args.flavor is not None:
|
||||
flavor = n_client.find_flavor(parsed_args.flavor, ignore_missing=False)
|
||||
|
||||
@@ -302,7 +302,7 @@ class TestApplicationCredentialDelete(identity_fakes.TestIdentityv3):
|
||||
|
||||
calls = []
|
||||
for a in arglist:
|
||||
calls.append(call(user_id, a))
|
||||
calls.append(call(user_id, a, ignore_missing=False))
|
||||
|
||||
self.identity_sdk_client.find_application_credential.assert_has_calls(
|
||||
calls
|
||||
|
||||
@@ -520,7 +520,7 @@ class TestDomainShow(identity_fakes.TestIdentityv3):
|
||||
# data to be shown.
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
self.identity_sdk_client.find_domain.assert_called_with(
|
||||
self.domain.id,
|
||||
self.domain.id, ignore_missing=False
|
||||
)
|
||||
|
||||
self.assertEqual(self.columns, columns)
|
||||
|
||||
@@ -678,7 +678,7 @@ class TestEndpointShow(identity_fakes.TestIdentityv3):
|
||||
# data to be shown.
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
self.identity_sdk_client.find_endpoint.assert_called_with(
|
||||
self.endpoint.id,
|
||||
self.endpoint.id, ignore_missing=False
|
||||
)
|
||||
|
||||
collist = (
|
||||
|
||||
@@ -253,7 +253,7 @@ class TestGroupCreate(identity_fakes.TestIdentityv3):
|
||||
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
self.identity_sdk_client.find_group.assert_called_once_with(
|
||||
self.group.name
|
||||
self.group.name, ignore_missing=False
|
||||
)
|
||||
self.assertEqual(self.columns, columns)
|
||||
datalist = (
|
||||
@@ -286,7 +286,9 @@ class TestGroupCreate(identity_fakes.TestIdentityv3):
|
||||
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
self.identity_sdk_client.find_group.assert_called_once_with(
|
||||
self.group_with_options.name, domain_id=self.domain.id
|
||||
self.group_with_options.name,
|
||||
domain_id=self.domain.id,
|
||||
ignore_missing=False,
|
||||
)
|
||||
self.assertEqual(self.columns, columns)
|
||||
datalist = (
|
||||
|
||||
@@ -797,7 +797,9 @@ class TestSetNetworkTrunk(TestNetworkTrunk):
|
||||
exceptions.CommandError
|
||||
)
|
||||
|
||||
self.network_client.find_port.side_effect = [{'id': 'invalid_subport'}]
|
||||
self.network_client.find_port.side_effect = [
|
||||
network_fakes.create_one_port({'id': 'invalid_subport'})
|
||||
]
|
||||
|
||||
with testtools.ExpectedException(exceptions.CommandError) as e:
|
||||
self.cmd.take_action(parsed_args)
|
||||
|
||||
@@ -176,7 +176,7 @@ class TestCreateRouter(TestRouter):
|
||||
|
||||
self.network_client.set_tags.return_value = None
|
||||
self.network_client.find_extension.side_effect = (
|
||||
lambda name: self._extensions.get(name)
|
||||
lambda name, ignore_missing=True: self._extensions.get(name)
|
||||
)
|
||||
# Get the command object to test
|
||||
self.cmd = router.CreateRouter(self.app, None)
|
||||
@@ -1317,7 +1317,7 @@ class TestSetRouter(TestRouter):
|
||||
|
||||
self.network_client.find_subnet.return_value = self._subnet
|
||||
self.network_client.find_extension.side_effect = (
|
||||
lambda name: self._extensions.get(name)
|
||||
lambda name, ignore_missing=True: self._extensions.get(name)
|
||||
)
|
||||
# Get the command object to test
|
||||
self.cmd = router.SetRouter(self.app, None)
|
||||
@@ -1956,7 +1956,7 @@ class TestUnsetRouter(TestRouter):
|
||||
self.network_client.set_tags.return_value = None
|
||||
self._extensions = {'fake': network_fakes.create_one_extension()}
|
||||
self.network_client.find_extension.side_effect = (
|
||||
lambda name: self._extensions.get(name)
|
||||
lambda name, ignore_missing=True: self._extensions.get(name)
|
||||
)
|
||||
self.network_client.remove_external_gateways.return_value = None
|
||||
|
||||
@@ -2158,7 +2158,7 @@ class TestGatewayOps(TestRouter):
|
||||
)
|
||||
}
|
||||
self.network_client.find_extension.side_effect = (
|
||||
lambda name: self._extensions.get(name)
|
||||
lambda name, ignore_missing=True: self._extensions.get(name)
|
||||
)
|
||||
self.network_client.find_router.return_value = self._router
|
||||
|
||||
|
||||
@@ -565,7 +565,9 @@ class TestBackupShow(volume_fakes.TestVolume):
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
self.volume_sdk_client.find_backup.assert_called_with(self.backup.id)
|
||||
self.volume_sdk_client.find_backup.assert_called_with(
|
||||
self.backup.id, ignore_missing=False
|
||||
)
|
||||
|
||||
self.assertEqual(self.columns, columns)
|
||||
self.assertEqual(self.data, data)
|
||||
|
||||
@@ -453,7 +453,9 @@ class ShowVolumeBackup(command.ShowOne):
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
volume_client = self.app.client_manager.sdk_connection.volume
|
||||
backup = volume_client.find_backup(parsed_args.backup)
|
||||
backup = volume_client.find_backup(
|
||||
parsed_args.backup, ignore_missing=False
|
||||
)
|
||||
columns: tuple[str, ...] = (
|
||||
"availability_zone",
|
||||
"container",
|
||||
|
||||
Reference in New Issue
Block a user