Skip to content

Commit 9bdbc60

Browse files
committed
typing: Fixes for typed SDK find_* proxy methods
openstacksdk 4.12.0 added type hints for the find_* proxy methods (change If7d64340224c3510d5d7eb831af29409213a304a). This introduces a few new issues. Address them. Change-Id: Ia404ecfd68639e760fc8b8ad00ed0b4da00650c8 Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
1 parent 32c1e6c commit 9bdbc60

15 files changed

Lines changed: 48 additions & 23 deletions

File tree

openstackclient/common/project_cleanup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ def take_action(self, parsed_args: argparse.Namespace) -> None:
105105
project = identity_client.find_project(
106106
name_or_id=parsed_args.project, ignore_missing=False
107107
)
108-
connection = connection.connect_as_project(project)
108+
# FIXME(stephenfin): The type in SDK is wrong
109+
connection = connection.connect_as_project(project) # type: ignore
109110

110111
if connection:
111112
status_queue: queue.Queue[Any] = queue.Queue()

openstackclient/compute/v2/flavor.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -553,15 +553,15 @@ def take_action(
553553

554554
# Since we need to inject "access_project_id" into resource - convert
555555
# it to dict and treat it respectively
556-
flavor = flavor.to_dict()
557-
flavor['access_project_ids'] = access_projects
556+
flavor_dict = flavor.to_dict()
557+
flavor_dict['access_project_ids'] = access_projects
558558

559-
display_columns, columns = _get_flavor_columns(flavor)
559+
display_columns, columns = _get_flavor_columns(flavor_dict)
560560
data = utils.get_dict_properties(
561-
flavor, columns, formatters=_formatters
561+
flavor_dict, columns, formatters=_formatters
562562
)
563563

564-
return (display_columns, data)
564+
return display_columns, data
565565

566566

567567
class UnsetFlavor(command.Command):

openstackclient/compute/v2/server.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ def take_action(
417417
else:
418418
net_id = parsed_args.network
419419

420-
kwargs = {'net_id': net_id}
420+
kwargs: dict[str, Any] = {'net_id': net_id}
421421
if parsed_args.fixed_ip_address:
422422
kwargs['fixed_ips'] = [
423423
{"ip_address": parsed_args.fixed_ip_address}
@@ -3148,9 +3148,8 @@ def take_action(
31483148
s.image_id = IMAGE_STRING_FOR_BFV
31493149

31503150
if not sdk_utils.supports_microversion(compute_client, '2.47'):
3151-
flavor = flavors.get(s.flavor['id'])
3152-
if flavor:
3153-
s.flavor_name = flavor.name
3151+
if s.flavor['id'] in flavors:
3152+
s.flavor_name = flavors[s.flavor['id']].name
31543153
s.flavor_id = s.flavor['id']
31553154
else:
31563155
s.flavor_name = s.flavor['original_name']

openstackclient/identity/v3/application_credential.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,13 +289,17 @@ def take_action(self, parsed_args: argparse.Namespace) -> None:
289289
identity_client = sdk_utils.ensure_service_version(
290290
self.app.client_manager.sdk_connection.identity, '3'
291291
)
292+
292293
conn = self.app.client_manager.sdk_connection
293294
auth = conn.config.get_auth()
294295
if auth is None:
295296
# this will never happen
296297
raise exceptions.CommandError('invalid authentication info')
297298

298299
user_id = auth.get_user_id(conn.session)
300+
if user_id is None:
301+
msg = _("failed to retrieve auth info for current session")
302+
raise exceptions.CommandError(msg)
299303

300304
errors = 0
301305
for ac in parsed_args.application_credential:
@@ -387,12 +391,17 @@ def take_action(
387391
identity_client = sdk_utils.ensure_service_version(
388392
self.app.client_manager.sdk_connection.identity, '3'
389393
)
394+
390395
conn = self.app.client_manager.sdk_connection
391396
auth = conn.config.get_auth()
392397
if auth is None:
393398
# this will never happen
394399
raise exceptions.CommandError('invalid authentication info')
400+
395401
user_id = auth.get_user_id(conn.session)
402+
if user_id is None:
403+
msg = _("failed to retrieve auth info for current session")
404+
raise exceptions.CommandError(msg)
396405

397406
application_credential = identity_client.find_application_credential(
398407
user_id, parsed_args.application_credential, ignore_missing=False

openstackclient/identity/v3/project.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -556,8 +556,8 @@ def take_action(
556556
if parsed_args.children:
557557
kwargs['subtree_as_ids'] = True
558558

559-
project = identity_client.find_project(
559+
project_obj = identity_client.find_project(
560560
project, **kwargs, ignore_missing=False
561561
)
562562

563-
return _format_project(project)
563+
return _format_project(project_obj)

openstackclient/identity/v3/trust.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def take_action(
123123
self.app.client_manager.sdk_connection.identity, '3'
124124
)
125125

126-
kwargs = {}
126+
kwargs: dict[str, Any] = {}
127127

128128
# NOTE(stevemar): Find the two users, project and roles that
129129
# are necessary for making a trust usable, the API dictates that

openstackclient/identity/v3/user.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ def take_action(
262262
self.app.client_manager.sdk_connection.identity, '3'
263263
)
264264

265-
kwargs = {}
265+
kwargs: dict[str, Any] = {}
266266

267267
domain_id = None
268268
if parsed_args.domain:

openstackclient/image/v2/image.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1533,7 +1533,7 @@ def take_action(self, parsed_args: argparse.Namespace) -> None:
15331533
# out, what was changed inside
15341534
# NOTE: ping gtema to improve that in SDK
15351535
new_props = kwargs.get(
1536-
'properties', image.get('properties').copy()
1536+
'properties', image['properties'].copy()
15371537
)
15381538
new_props.pop(k, None)
15391539
kwargs['properties'] = new_props

openstackclient/network/v2/floating_ip.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,11 +540,13 @@ def get_parser(self, prog_name: str) -> argparse.ArgumentParser:
540540

541541
def take_action(self, parsed_args: argparse.Namespace) -> None:
542542
client = self.app.client_manager.network
543-
attrs = {}
544543
obj = client.find_ip(
545544
parsed_args.floating_ip,
546545
ignore_missing=False,
547546
)
547+
548+
attrs: dict[str, Any] = {}
549+
548550
if parsed_args.port:
549551
port = client.find_port(parsed_args.port, ignore_missing=False)
550552
attrs['port_id'] = port.id

openstackclient/network/v2/floating_ip_port_forwarding.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ def take_action(
325325
'Description',
326326
)
327327

328-
query = {}
328+
query: dict[str, Any] = {}
329329

330330
if parsed_args.port:
331331
port = client.find_port(parsed_args.port, ignore_missing=False)

0 commit comments

Comments
 (0)