Merge "typing: Resolve incompatible operand issues"

This commit is contained in:
Zuul 2025-04-01 11:50:55 +00:00 committed by Gerrit Code Review
commit 77143f9bed
12 changed files with 55 additions and 33 deletions

View File

@ -77,8 +77,7 @@ class CreateLimit(command.ShowOne):
) )
region = None region = None
if parsed_args.region: if parsed_args.region:
val = getattr(parsed_args, 'region', None) if 'None' not in parsed_args.region:
if 'None' not in val:
# NOTE (vishakha): Due to bug #1799153 and for any another # NOTE (vishakha): Due to bug #1799153 and for any another
# related case where GET resource API does not support the # related case where GET resource API does not support the
# filter by name, osc_lib.utils.find_resource() method cannot # filter by name, osc_lib.utils.find_resource() method cannot
@ -149,11 +148,7 @@ class ListLimit(command.Lister):
) )
region = None region = None
if parsed_args.region: if parsed_args.region:
region = utils.find_resource( if 'None' not in parsed_args.region:
identity_client.regions, parsed_args.region
)
val = getattr(parsed_args, 'region', None)
if 'None' not in val:
# NOTE (vishakha): Due to bug #1799153 and for any another # NOTE (vishakha): Due to bug #1799153 and for any another
# related case where GET resource API does not support the # related case where GET resource API does not support the
# filter by name, osc_lib.utils.find_resource() method cannot # filter by name, osc_lib.utils.find_resource() method cannot

View File

@ -68,8 +68,7 @@ class CreateRegisteredLimit(command.ShowOne):
) )
region = None region = None
if parsed_args.region: if parsed_args.region:
val = getattr(parsed_args, 'region', None) if 'None' not in parsed_args.region:
if 'None' not in val:
# NOTE (vishakha): Due to bug #1799153 and for any another # NOTE (vishakha): Due to bug #1799153 and for any another
# related case where GET resource API does not support the # related case where GET resource API does not support the
# filter by name, osc_lib.utils.find_resource() method cannot # filter by name, osc_lib.utils.find_resource() method cannot
@ -175,8 +174,7 @@ class ListRegisteredLimit(command.Lister):
) )
region = None region = None
if parsed_args.region: if parsed_args.region:
val = getattr(parsed_args, 'region', None) if 'None' not in parsed_args.region:
if 'None' not in val:
# NOTE (vishakha): Due to bug #1799153 and for any another # NOTE (vishakha): Due to bug #1799153 and for any another
# related case where GET resource API does not support the # related case where GET resource API does not support the
# filter by name, osc_lib.utils.find_resource() method cannot # filter by name, osc_lib.utils.find_resource() method cannot
@ -280,8 +278,7 @@ class SetRegisteredLimit(command.ShowOne):
region = None region = None
if parsed_args.region: if parsed_args.region:
val = getattr(parsed_args, 'region', None) if 'None' not in parsed_args.region:
if 'None' not in val:
# NOTE (vishakha): Due to bug #1799153 and for any another # NOTE (vishakha): Due to bug #1799153 and for any another
# related case where GET resource API does not support the # related case where GET resource API does not support the
# filter by name, osc_lib.utils.find_resource() method cannot # filter by name, osc_lib.utils.find_resource() method cannot

View File

@ -17,6 +17,7 @@ import argparse
import copy import copy
import json import json
import logging import logging
import typing as ty
from cliff import columns as cliff_columns from cliff import columns as cliff_columns
from osc_lib.cli import format_columns from osc_lib.cli import format_columns
@ -39,6 +40,8 @@ class AdminStateColumn(cliff_columns.FormattableColumn):
class SubPortColumn(format_columns.ListDictColumn): class SubPortColumn(format_columns.ListDictColumn):
_value: ty.Any
def _retrieve_subports(self): def _retrieve_subports(self):
if isinstance(self._value, dict): if isinstance(self._value, dict):
self._value = self._value['sub_ports'] self._value = self._value['sub_ports']

View File

@ -25,7 +25,7 @@ class QuotaTests(base.TestCase):
test runs as these may run in parallel and otherwise step on each other. test runs as these may run in parallel and otherwise step on each other.
""" """
PROJECT_NAME = None PROJECT_NAME: str
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):

View File

@ -22,9 +22,9 @@ from openstackclient.tests.functional import base
class ComputeTestCase(base.TestCase): class ComputeTestCase(base.TestCase):
"""Common functional test bits for Compute commands""" """Common functional test bits for Compute commands"""
flavor_name = None flavor_name: str
image_name = None image_name: str
network_arg = None network_arg: str
def setUp(self): def setUp(self):
"""Select common resources""" """Select common resources"""
@ -34,7 +34,7 @@ class ComputeTestCase(base.TestCase):
self.network_arg = self.get_network() self.network_arg = self.get_network()
@classmethod @classmethod
def get_flavor(cls): def get_flavor(cls) -> str:
# NOTE(rtheis): Get cirros256 or m1.tiny flavors since functional # NOTE(rtheis): Get cirros256 or m1.tiny flavors since functional
# tests may create other flavors. # tests may create other flavors.
flavors = cls.openstack("flavor list", parse_output=True) flavors = cls.openstack("flavor list", parse_output=True)
@ -43,10 +43,13 @@ class ComputeTestCase(base.TestCase):
if flavor['Name'] in ['m1.tiny', 'cirros256']: if flavor['Name'] in ['m1.tiny', 'cirros256']:
server_flavor = flavor['Name'] server_flavor = flavor['Name']
break break
assert server_flavor is not None
return server_flavor return server_flavor
@classmethod @classmethod
def get_image(cls): def get_image(cls) -> str:
# NOTE(rtheis): Get first Cirros image since functional tests may # NOTE(rtheis): Get first Cirros image since functional tests may
# create other images. Image may be named '-uec' or # create other images. Image may be named '-uec' or
# '-disk'. # '-disk'.
@ -59,10 +62,13 @@ class ComputeTestCase(base.TestCase):
): ):
server_image = image['Name'] server_image = image['Name']
break break
assert server_image is not None
return server_image return server_image
@classmethod @classmethod
def get_network(cls): def get_network(cls) -> str:
try: try:
# NOTE(rtheis): Get private network since functional tests may # NOTE(rtheis): Get private network since functional tests may
# create other networks. # create other networks.

View File

@ -75,6 +75,10 @@ class AddressGroupTests(common.NetworkTests):
self.assertNotEqual(admin_project_id, demo_project_id) self.assertNotEqual(admin_project_id, demo_project_id)
self.assertEqual(admin_project_id, auth_project_id) self.assertEqual(admin_project_id, auth_project_id)
# type narrow
assert admin_project_id is not None
assert demo_project_id is not None
name1 = uuid.uuid4().hex name1 = uuid.uuid4().hex
cmd_output = self.openstack( cmd_output = self.openstack(
'address group create ' + name1, 'address group create ' + name1,

View File

@ -94,9 +94,14 @@ class L3ConntrackHelperTests(common.NetworkTests):
self.assertIn(ct, expected_helpers) self.assertIn(ct, expected_helpers)
def test_l3_conntrack_helper_set_and_show(self): def test_l3_conntrack_helper_set_and_show(self):
helper = {'helper': 'tftp', 'protocol': 'udp', 'port': 69} helper = 'tftp'
proto = 'udp'
port = 69
router_id = self._create_router() router_id = self._create_router()
created_helper = self._create_helpers(router_id, [helper])[0] created_helper = self._create_helpers(
router_id,
[{'helper': helper, 'protocol': proto, 'port': port}],
)[0]
output = self.openstack( output = self.openstack(
'network l3 conntrack helper show {router_id} {ct_id} ' 'network l3 conntrack helper show {router_id} {ct_id} '
'-f json'.format( '-f json'.format(
@ -105,16 +110,16 @@ class L3ConntrackHelperTests(common.NetworkTests):
), ),
parse_output=True, parse_output=True,
) )
self.assertEqual(helper['helper'], output['helper']) self.assertEqual(port, output['port'])
self.assertEqual(helper['protocol'], output['protocol']) self.assertEqual(helper, output['helper'])
self.assertEqual(helper['port'], output['port']) self.assertEqual(proto, output['protocol'])
raw_output = self.openstack( raw_output = self.openstack(
'network l3 conntrack helper set {router_id} {ct_id} ' 'network l3 conntrack helper set {router_id} {ct_id} '
'--port {port} '.format( '--port {port} '.format(
router_id=router_id, router_id=router_id,
ct_id=created_helper['id'], ct_id=created_helper['id'],
port=helper['port'] + 1, port=port + 1,
) )
) )
self.assertOutput('', raw_output) self.assertOutput('', raw_output)
@ -127,6 +132,6 @@ class L3ConntrackHelperTests(common.NetworkTests):
), ),
parse_output=True, parse_output=True,
) )
self.assertEqual(helper['port'] + 1, output['port']) self.assertEqual(port + 1, output['port'])
self.assertEqual(helper['helper'], output['helper']) self.assertEqual(helper, output['helper'])
self.assertEqual(helper['protocol'], output['protocol']) self.assertEqual(proto, output['protocol'])

View File

@ -77,6 +77,10 @@ class LocalIPTests(common.NetworkTests):
self.assertNotEqual(admin_project_id, demo_project_id) self.assertNotEqual(admin_project_id, demo_project_id)
self.assertEqual(admin_project_id, auth_project_id) self.assertEqual(admin_project_id, auth_project_id)
# type narrow
assert admin_project_id is not None
assert demo_project_id is not None
name1 = uuid.uuid4().hex name1 = uuid.uuid4().hex
cmd_output = self.openstack( cmd_output = self.openstack(
'local ip create ' + name1, 'local ip create ' + name1,

View File

@ -22,8 +22,8 @@ from openstackclient.tests.functional.network.v2 import common
class TestMeterRule(common.NetworkTests): class TestMeterRule(common.NetworkTests):
"""Functional tests for meter rule""" """Functional tests for meter rule"""
METER_ID = None METER_ID: str
METER_RULE_ID = None METER_RULE_ID: str
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):

View File

@ -18,8 +18,8 @@ from openstackclient.tests.functional.network.v2 import common
class NetworkRBACTests(common.NetworkTests): class NetworkRBACTests(common.NetworkTests):
"""Functional tests for network rbac""" """Functional tests for network rbac"""
OBJECT_ID = None OBJECT_ID: str
ID = None ID: str
HEADERS = ['ID'] HEADERS = ['ID']
FIELDS = ['id'] FIELDS = ['id']

View File

@ -106,6 +106,10 @@ class RouterTests(common.NetworkTagTests):
self.assertNotEqual(admin_project_id, demo_project_id) self.assertNotEqual(admin_project_id, demo_project_id)
self.assertEqual(admin_project_id, auth_project_id) self.assertEqual(admin_project_id, auth_project_id)
# type narrow
assert admin_project_id is not None
assert demo_project_id is not None
name1 = uuid.uuid4().hex name1 = uuid.uuid4().hex
name2 = uuid.uuid4().hex name2 = uuid.uuid4().hex
cmd_output = self.openstack( cmd_output = self.openstack(

View File

@ -63,6 +63,10 @@ class SubnetPoolTests(common.NetworkTagTests):
self.assertNotEqual(admin_project_id, demo_project_id) self.assertNotEqual(admin_project_id, demo_project_id)
self.assertEqual(admin_project_id, auth_project_id) self.assertEqual(admin_project_id, auth_project_id)
# type narrow
assert admin_project_id is not None
assert demo_project_id is not None
name1 = uuid.uuid4().hex name1 = uuid.uuid4().hex
name2 = uuid.uuid4().hex name2 = uuid.uuid4().hex