diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 738f7d1920..786c26378d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -14,16 +14,11 @@ repos: - id: check-yaml files: .*\.(yaml|yml)$ args: ['--unsafe'] - - repo: https://github.com/asottile/pyupgrade - rev: v3.17.0 - hooks: - - id: pyupgrade - args: ['--py38-plus'] - repo: https://github.com/astral-sh/ruff-pre-commit rev: v0.6.2 hooks: - id: ruff - args: ['--fix'] + args: ['--fix', '--unsafe-fixes'] - id: ruff-format - repo: https://opendev.org/openstack/hacking rev: 7.0.0 diff --git a/examples/common.py b/examples/common.py index d97bfb55cb..650139ec27 100755 --- a/examples/common.py +++ b/examples/common.py @@ -241,9 +241,9 @@ def run(opts): # Do some basic testing here sys.stdout.write("Default run command\n") - sys.stdout.write("Verbose level: %s\n" % opts.verbose_level) - sys.stdout.write("Debug: %s\n" % opts.debug) - sys.stdout.write("dump_stack_trace: %s\n" % dump_stack_trace) + sys.stdout.write(f"Verbose level: {opts.verbose_level}\n") + sys.stdout.write(f"Debug: {opts.debug}\n") + sys.stdout.write(f"dump_stack_trace: {dump_stack_trace}\n") def setup(): diff --git a/examples/object_api.py b/examples/object_api.py index 577fc052fa..4ff245d4ce 100755 --- a/examples/object_api.py +++ b/examples/object_api.py @@ -101,7 +101,7 @@ def run(opts): o_list = obj_api.object_list(c_list[0]['name']) print("\nObject") for o in o_list: - print("%s" % o) + print(f"{o}") if __name__ == "__main__": diff --git a/examples/osc-lib.py b/examples/osc-lib.py index cc04bc70fe..6bd0347ac7 100755 --- a/examples/osc-lib.py +++ b/examples/osc-lib.py @@ -94,13 +94,13 @@ def run(opts): o_list = client_manager.object_store.object_list(c_list[0]['name']) print("\nObject") for o in o_list: - print("%s" % o) + print(f"{o}") # Look at the compute flavors flavor_list = client_manager.compute.flavors.list() print("\nFlavors:") for f in flavor_list: - print("%s" % f) + print(f"{f}") if __name__ == "__main__": diff --git a/openstackclient/api/api.py b/openstackclient/api/api.py index 838383f027..5f78b0ee54 100644 --- a/openstackclient/api/api.py +++ b/openstackclient/api/api.py @@ -307,7 +307,7 @@ class BaseAPI(KeystoneSession): except ks_exceptions.NotFound: kwargs = {attr: value} try: - ret = self.find_one("/%s/detail" % (path), **kwargs) + ret = self.find_one(f"/{path}/detail", **kwargs) except ks_exceptions.NotFound: msg = _("%s not found") % value raise exceptions.NotFound(msg) diff --git a/openstackclient/api/object_store_v1.py b/openstackclient/api/object_store_v1.py index e7896b1e4f..fd941e4838 100644 --- a/openstackclient/api/object_store_v1.py +++ b/openstackclient/api/object_store_v1.py @@ -256,10 +256,7 @@ class APIv1(api.BaseAPI): # object's name in the container. object_name_str = name if name else object - full_url = "{}/{}".format( - urllib.parse.quote(container), - urllib.parse.quote(object_name_str), - ) + full_url = f"{urllib.parse.quote(container)}/{urllib.parse.quote(object_name_str)}" with open(object, 'rb') as f: response = self.create( full_url, @@ -293,8 +290,7 @@ class APIv1(api.BaseAPI): return self.delete( - "%s/%s" - % (urllib.parse.quote(container), urllib.parse.quote(object)) + f"{urllib.parse.quote(container)}/{urllib.parse.quote(object)}" ) def object_list( @@ -395,8 +391,7 @@ class APIv1(api.BaseAPI): response = self._request( 'GET', - "%s/%s" - % (urllib.parse.quote(container), urllib.parse.quote(object)), + f"{urllib.parse.quote(container)}/{urllib.parse.quote(object)}", stream=True, ) if response.status_code == 200: @@ -431,8 +426,7 @@ class APIv1(api.BaseAPI): headers = self._set_properties(properties, 'X-Object-Meta-%s') if headers: self.create( - "%s/%s" - % (urllib.parse.quote(container), urllib.parse.quote(object)), + f"{urllib.parse.quote(container)}/{urllib.parse.quote(object)}", headers=headers, ) @@ -455,8 +449,7 @@ class APIv1(api.BaseAPI): headers = self._unset_properties(properties, 'X-Remove-Object-Meta-%s') if headers: self.create( - "%s/%s" - % (urllib.parse.quote(container), urllib.parse.quote(object)), + f"{urllib.parse.quote(container)}/{urllib.parse.quote(object)}", headers=headers, ) @@ -480,8 +473,7 @@ class APIv1(api.BaseAPI): response = self._request( 'HEAD', - "%s/%s" - % (urllib.parse.quote(container), urllib.parse.quote(object)), + f"{urllib.parse.quote(container)}/{urllib.parse.quote(object)}", ) data = { diff --git a/openstackclient/common/quota.py b/openstackclient/common/quota.py index b3b04e0b3b..4356cae66f 100644 --- a/openstackclient/common/quota.py +++ b/openstackclient/common/quota.py @@ -507,8 +507,8 @@ class SetQuota(common.NetDetectionMixin, command.Command): ) for k, v, h in self._build_options_list(): parser.add_argument( - '--%s' % v, - metavar='<%s>' % v, + f'--{v}', + metavar=f'<{v}>', dest=k, type=int, help=h, @@ -590,7 +590,7 @@ class SetQuota(common.NetDetectionMixin, command.Command): parsed_args.volume_type and k in IMPACT_VOLUME_TYPE_QUOTAS ): - k = k + '_%s' % parsed_args.volume_type + k = k + f'_{parsed_args.volume_type}' volume_kwargs[k] = value if self.app.client_manager.is_network_endpoint_enabled(): diff --git a/openstackclient/compute/v2/server.py b/openstackclient/compute/v2/server.py index 293e010a72..9cf200f15e 100644 --- a/openstackclient/compute/v2/server.py +++ b/openstackclient/compute/v2/server.py @@ -1504,7 +1504,7 @@ class CreateServer(command.ShowOne): def take_action(self, parsed_args): def _show_progress(progress): if progress: - self.app.stdout.write('\rProgress: %s' % progress) + self.app.stdout.write(f'\rProgress: {progress}') self.app.stdout.flush() compute_client = self.app.client_manager.sdk_connection.compute @@ -2189,7 +2189,7 @@ class DeleteServer(command.Command): def take_action(self, parsed_args): def _show_progress(progress): if progress: - self.app.stdout.write('\rProgress: %s' % progress) + self.app.stdout.write(f'\rProgress: {progress}') self.app.stdout.flush() compute_client = self.app.client_manager.sdk_connection.compute @@ -3198,7 +3198,7 @@ revert to release the new server and restart the old one.""" def take_action(self, parsed_args): def _show_progress(progress): if progress: - self.app.stdout.write('\rProgress: %s' % progress) + self.app.stdout.write(f'\rProgress: {progress}') self.app.stdout.flush() compute_client = self.app.client_manager.sdk_connection.compute @@ -3350,7 +3350,7 @@ class RebootServer(command.Command): def take_action(self, parsed_args): def _show_progress(progress): if progress: - self.app.stdout.write('\rProgress: %s' % progress) + self.app.stdout.write(f'\rProgress: {progress}') self.app.stdout.flush() compute_client = self.app.client_manager.sdk_connection.compute @@ -3555,7 +3555,7 @@ class RebuildServer(command.ShowOne): def take_action(self, parsed_args): def _show_progress(progress): if progress: - self.app.stdout.write('\rProgress: %s' % progress) + self.app.stdout.write(f'\rProgress: {progress}') self.app.stdout.flush() compute_client = self.app.client_manager.sdk_connection.compute @@ -3816,7 +3816,7 @@ host.""" def take_action(self, parsed_args): def _show_progress(progress): if progress: - self.app.stdout.write('\rProgress: %s' % progress) + self.app.stdout.write(f'\rProgress: {progress}') self.app.stdout.flush() compute_client = self.app.client_manager.sdk_connection.compute @@ -4188,7 +4188,7 @@ release the new server and restart the old one.""" def take_action(self, parsed_args): def _show_progress(progress): if progress: - self.app.stdout.write('\rProgress: %s' % progress) + self.app.stdout.write(f'\rProgress: {progress}') self.app.stdout.flush() compute_client = self.app.client_manager.sdk_connection.compute @@ -4584,7 +4584,7 @@ class ShelveServer(command.Command): def take_action(self, parsed_args): def _show_progress(progress): if progress: - self.app.stdout.write('\rProgress: %s' % progress) + self.app.stdout.write(f'\rProgress: {progress}') self.app.stdout.flush() compute_client = self.app.client_manager.sdk_connection.compute @@ -5181,7 +5181,7 @@ class UnshelveServer(command.Command): def take_action(self, parsed_args): def _show_progress(progress): if progress: - self.app.stdout.write('\rProgress: %s' % progress) + self.app.stdout.write(f'\rProgress: {progress}') self.app.stdout.flush() compute_client = self.app.client_manager.sdk_connection.compute diff --git a/openstackclient/compute/v2/server_backup.py b/openstackclient/compute/v2/server_backup.py index 59bd5540e8..96b325b104 100644 --- a/openstackclient/compute/v2/server_backup.py +++ b/openstackclient/compute/v2/server_backup.py @@ -68,7 +68,7 @@ class CreateServerBackup(command.ShowOne): def take_action(self, parsed_args): def _show_progress(progress): if progress: - self.app.stderr.write('\rProgress: %s' % progress) + self.app.stderr.write(f'\rProgress: {progress}') self.app.stderr.flush() compute_client = self.app.client_manager.sdk_connection.compute diff --git a/openstackclient/compute/v2/server_image.py b/openstackclient/compute/v2/server_image.py index 12b45b2854..e49a5d36cd 100644 --- a/openstackclient/compute/v2/server_image.py +++ b/openstackclient/compute/v2/server_image.py @@ -69,7 +69,7 @@ class CreateServerImage(command.ShowOne): def take_action(self, parsed_args): def _show_progress(progress): if progress: - self.app.stdout.write('\rProgress: %s' % progress) + self.app.stdout.write(f'\rProgress: {progress}') self.app.stdout.flush() compute_client = self.app.client_manager.sdk_connection.compute diff --git a/openstackclient/compute/v2/usage.py b/openstackclient/compute/v2/usage.py index 2b3fa6a3f8..27f9335bb5 100644 --- a/openstackclient/compute/v2/usage.py +++ b/openstackclient/compute/v2/usage.py @@ -60,7 +60,7 @@ class CountColumn(cliff_columns.FormattableColumn): class FloatColumn(cliff_columns.FormattableColumn): def human_readable(self): - return float("%.2f" % self._value) + return float(f"{self._value:.2f}") def _formatters(project_cache): diff --git a/openstackclient/identity/common.py b/openstackclient/identity/common.py index 4e5f083de2..50ad2fed67 100644 --- a/openstackclient/identity/common.py +++ b/openstackclient/identity/common.py @@ -34,7 +34,7 @@ def find_service_in_list(service_list, service_id): if service.id == service_id: return service raise exceptions.CommandError( - "No service with a type, name or ID of '%s' exists." % service_id + f"No service with a type, name or ID of '{service_id}' exists." ) diff --git a/openstackclient/image/v2/image.py b/openstackclient/image/v2/image.py index 5390a704ca..094c507b0d 100644 --- a/openstackclient/image/v2/image.py +++ b/openstackclient/image/v2/image.py @@ -421,8 +421,8 @@ class CreateImage(command.ShowOne): identity_common.add_project_domain_option_to_parser(parser) for deadopt in self.deadopts: parser.add_argument( - "--%s" % deadopt, - metavar="<%s>" % deadopt, + f"--{deadopt}", + metavar=f"<{deadopt}>", dest=deadopt.replace('-', '_'), help=argparse.SUPPRESS, ) @@ -488,7 +488,7 @@ class CreateImage(command.ShowOne): fp = open(parsed_args.filename, 'rb') except FileNotFoundError: raise exceptions.CommandError( - '%r is not a valid file' % parsed_args.filename, + f'{parsed_args.filename!r} is not a valid file', ) else: fp = get_data_from_stdin() @@ -1209,8 +1209,8 @@ class SetImage(command.Command): identity_common.add_project_domain_option_to_parser(parser) for deadopt in self.deadopts: parser.add_argument( - "--%s" % deadopt, - metavar="<%s>" % deadopt, + f"--{deadopt}", + metavar=f"<{deadopt}>", dest=f"dead_{deadopt.replace('-', '_')}", help=argparse.SUPPRESS, ) @@ -1575,7 +1575,7 @@ class StageImage(command.Command): fp = open(parsed_args.filename, 'rb') except FileNotFoundError: raise exceptions.CommandError( - '%r is not a valid file' % parsed_args.filename, + f'{parsed_args.filename!r} is not a valid file', ) else: fp = get_data_from_stdin() diff --git a/openstackclient/network/common.py b/openstackclient/network/common.py index 4c01f90ef4..3d5237b1b1 100644 --- a/openstackclient/network/common.py +++ b/openstackclient/network/common.py @@ -120,13 +120,14 @@ class NetDetectionMixin(metaclass=abc.ABCMeta): @staticmethod def split_help(network_help, compute_help): return ( - "*%(network_qualifier)s:*\n %(network_help)s\n\n" - "*%(compute_qualifier)s:*\n %(compute_help)s" - % dict( - network_qualifier=_("Network version 2"), - network_help=network_help, - compute_qualifier=_("Compute version 2"), - compute_help=compute_help, + "*{network_qualifier}:*\n {network_help}\n\n" + "*{compute_qualifier}:*\n {compute_help}".format( + **dict( + network_qualifier=_("Network version 2"), + network_help=network_help, + compute_qualifier=_("Compute version 2"), + compute_help=compute_help, + ) ) ) diff --git a/openstackclient/network/v2/network_agent.py b/openstackclient/network/v2/network_agent.py index d31bd3f561..bccde7ef3a 100644 --- a/openstackclient/network/v2/network_agent.py +++ b/openstackclient/network/v2/network_agent.py @@ -89,9 +89,7 @@ class AddNetworkToAgent(command.Command): try: client.add_dhcp_agent_to_network(agent, network) except Exception: - msg = 'Failed to add {} to {}'.format( - network.name, agent.agent_type - ) + msg = f'Failed to add {network.name} to {agent.agent_type}' exceptions.CommandError(msg) @@ -321,9 +319,7 @@ class RemoveNetworkFromAgent(command.Command): try: client.remove_dhcp_agent_from_network(agent, network) except Exception: - msg = 'Failed to remove {} to {}'.format( - network.name, agent.agent_type - ) + msg = f'Failed to remove {network.name} to {agent.agent_type}' exceptions.CommandError(msg) diff --git a/openstackclient/network/v2/network_qos_rule.py b/openstackclient/network/v2/network_qos_rule.py index 70f4d28432..0b5e06fe5b 100644 --- a/openstackclient/network/v2/network_qos_rule.py +++ b/openstackclient/network/v2/network_qos_rule.py @@ -159,10 +159,7 @@ def _get_item_properties(item, fields): def _rule_action_call(client, action, rule_type): rule_type = rule_type.replace('-', '_') - func_name = '{action}_qos_{rule_type}_rule'.format( - action=action, - rule_type=rule_type, - ) + func_name = f'{action}_qos_{rule_type}_rule' return getattr(client, func_name) @@ -311,7 +308,7 @@ class DeleteNetworkQosRule(command.Command): ) rule_type = _find_rule_type(qos, rule_id) if not rule_type: - raise Exception('Rule %s not found' % rule_id) + raise Exception(f'Rule {rule_id} not found') _rule_action_call(network_client, ACTION_DELETE, rule_type)( rule_id, qos.id ) diff --git a/openstackclient/network/v2/port.py b/openstackclient/network/v2/port.py index b1e60df4e8..84aef47757 100644 --- a/openstackclient/network/v2/port.py +++ b/openstackclient/network/v2/port.py @@ -274,13 +274,13 @@ def _prepare_filter_fixed_ips(client_manager, parsed_args): _subnet = client.find_subnet( subnet_name_id, ignore_missing=False ) - ips.append('subnet_id=%s' % _subnet.id) + ips.append(f'subnet_id={_subnet.id}') if 'ip-address' in ip_spec: - ips.append('ip_address=%s' % ip_spec['ip-address']) + ips.append('ip_address={}'.format(ip_spec['ip-address'])) if 'ip-substring' in ip_spec: - ips.append('ip_address_substr=%s' % ip_spec['ip-substring']) + ips.append('ip_address_substr={}'.format(ip_spec['ip-substring'])) return ips diff --git a/openstackclient/shell.py b/openstackclient/shell.py index 5c64cb7cb1..df60d3c073 100644 --- a/openstackclient/shell.py +++ b/openstackclient/shell.py @@ -96,8 +96,9 @@ class OpenStackShell(shell.OpenStackShell): key=lambda s: list(map(int, s.split('.'))), ) self.log.warning( - "%s version %s is not in supported versions: %s" - % (api, version_opt, ', '.join(sorted_versions)) + "{} version {} is not in supported versions: {}".format( + api, version_opt, ', '.join(sorted_versions) + ) ) # Command groups deal only with major versions diff --git a/openstackclient/tests/functional/common/test_help.py b/openstackclient/tests/functional/common/test_help.py index f1aea8ee98..4ff365b6da 100644 --- a/openstackclient/tests/functional/common/test_help.py +++ b/openstackclient/tests/functional/common/test_help.py @@ -60,15 +60,9 @@ class HelpTests(base.TestCase): """Check server commands in main help message.""" raw_output = self.openstack('help') for command, description in self.SERVER_COMMANDS: - msg = 'Command: {} not found in help output:\n{}'.format( - command, - raw_output, - ) + msg = f'Command: {command} not found in help output:\n{raw_output}' self.assertIn(command, raw_output, msg) - msg = 'Description: {} not found in help output:\n{}'.format( - description, - raw_output, - ) + msg = f'Description: {description} not found in help output:\n{raw_output}' self.assertIn(description, raw_output, msg) def test_server_only_help(self): diff --git a/openstackclient/tests/functional/common/test_module.py b/openstackclient/tests/functional/common/test_module.py index 1506683499..41486d1ff5 100644 --- a/openstackclient/tests/functional/common/test_module.py +++ b/openstackclient/tests/functional/common/test_module.py @@ -59,7 +59,7 @@ class CommandTest(base.TestCase): input_groups = ['volume', 'network', 'image', 'identity', 'compute.v2'] for each_input in input_groups: cmd_output = self.openstack( - 'command list --group %s' % each_input, + f'command list --group {each_input}', parse_output=True, ) group_names = [each.get('Command Group') for each in cmd_output] diff --git a/openstackclient/tests/functional/common/test_quota.py b/openstackclient/tests/functional/common/test_quota.py index 8aa93a9294..677db50367 100644 --- a/openstackclient/tests/functional/common/test_quota.py +++ b/openstackclient/tests/functional/common/test_quota.py @@ -165,8 +165,7 @@ class QuotaTests(base.TestCase): # That will ensure we have at least two networks in the system. for _ in range(2): self.openstack( - 'network create --project %s %s' - % (self.PROJECT_NAME, uuid.uuid4().hex) + f'network create --project {self.PROJECT_NAME} {uuid.uuid4().hex}' ) self.assertRaises( @@ -211,8 +210,7 @@ class QuotaTests(base.TestCase): # That will ensure we have at least two networks in the system. for _ in range(2): self.openstack( - 'network create --project %s %s' - % (self.PROJECT_NAME, uuid.uuid4().hex) + f'network create --project {self.PROJECT_NAME} {uuid.uuid4().hex}' ) self.openstack('quota set --networks 1 --force ' + self.PROJECT_NAME) diff --git a/openstackclient/tests/functional/compute/v2/common.py b/openstackclient/tests/functional/compute/v2/common.py index ef59d458a1..4ada4304cb 100644 --- a/openstackclient/tests/functional/compute/v2/common.py +++ b/openstackclient/tests/functional/compute/v2/common.py @@ -132,9 +132,7 @@ class ComputeTestCase(base.TestCase): print(f'Server {name} now has status {status}') break print( - 'Server {}: Waiting for {}, current status: {}'.format( - name, expected_status, status - ) + f'Server {name}: Waiting for {expected_status}, current status: {status}' ) self.assertNotIn(status, failures) time.sleep(interval) diff --git a/openstackclient/tests/functional/compute/v2/test_hypervisor.py b/openstackclient/tests/functional/compute/v2/test_hypervisor.py index 7e90b743cb..0ed4e904bc 100644 --- a/openstackclient/tests/functional/compute/v2/test_hypervisor.py +++ b/openstackclient/tests/functional/compute/v2/test_hypervisor.py @@ -37,8 +37,8 @@ class HypervisorTests(base.TestCase): for i in ids1: cmd_output = json.loads( self.openstack( - "hypervisor show %s -f json " - " --os-compute-api-version 2.1" % (i) + f"hypervisor show {i} -f json " + " --os-compute-api-version 2.1" ) ) self.assertIsNotNone(cmd_output) @@ -47,6 +47,6 @@ class HypervisorTests(base.TestCase): # Show test - latest microversion for i in ids2: cmd_output = json.loads( - self.openstack("hypervisor show %s -f json" % (i)) + self.openstack(f"hypervisor show {i} -f json") ) self.assertIsNotNone(cmd_output) diff --git a/openstackclient/tests/functional/compute/v2/test_keypair.py b/openstackclient/tests/functional/compute/v2/test_keypair.py index ebc78abdae..4b178cb723 100644 --- a/openstackclient/tests/functional/compute/v2/test_keypair.py +++ b/openstackclient/tests/functional/compute/v2/test_keypair.py @@ -96,7 +96,7 @@ class KeypairTests(KeypairBase): f.flush() raw_output = self.openstack( - 'keypair create --public-key %s tmpkey' % f.name, + f'keypair create --public-key {f.name} tmpkey', ) self.addCleanup( self.openstack, @@ -113,7 +113,7 @@ class KeypairTests(KeypairBase): """ with tempfile.NamedTemporaryFile(mode='w+') as f: cmd_output = self.openstack( - 'keypair create --private-key %s tmpkey' % f.name, + f'keypair create --private-key {f.name} tmpkey', parse_output=True, ) self.addCleanup(self.openstack, 'keypair delete tmpkey') diff --git a/openstackclient/tests/functional/compute/v2/test_server.py b/openstackclient/tests/functional/compute/v2/test_server.py index d6638d2f71..19531da47a 100644 --- a/openstackclient/tests/functional/compute/v2/test_server.py +++ b/openstackclient/tests/functional/compute/v2/test_server.py @@ -111,7 +111,7 @@ class ServerTests(common.ComputeTestCase): ) except exceptions.CommandFailed as e: self.assertIn( - 'marker [%s] not found' % (name2), e.stderr.decode('utf-8') + f'marker [{name2}] not found', e.stderr.decode('utf-8') ) def test_server_list_with_changes_before(self): diff --git a/openstackclient/tests/functional/identity/v2/common.py b/openstackclient/tests/functional/identity/v2/common.py index a78f3b0315..dd2e271933 100644 --- a/openstackclient/tests/functional/identity/v2/common.py +++ b/openstackclient/tests/functional/identity/v2/common.py @@ -67,13 +67,9 @@ class IdentityTests(base.TestCase): cls.openstack( '--os-identity-api-version 2 ' 'project create ' - '--description %(description)s ' + f'--description {cls.project_description} ' '--enable ' - '%(name)s' - % { - 'description': cls.project_description, - 'name': cls.project_name, - } + f'{cls.project_name}' ) except tempest_exceptions.CommandFailed: # Good chance this is due to Identity v2 admin not being enabled @@ -87,7 +83,7 @@ class IdentityTests(base.TestCase): try: cls.openstack( '--os-identity-api-version 2 ' - 'project delete %s' % cls.project_name + f'project delete {cls.project_name}' ) finally: super().tearDownClass() @@ -111,14 +107,13 @@ class IdentityTests(base.TestCase): project_description = data_utils.rand_name('description') raw_output = self.openstack( 'project create ' - '--description %(description)s ' - '--enable %(name)s' - % {'description': project_description, 'name': project_name} + f'--description {project_description} ' + f'--enable {project_name}' ) project = self.parse_show_as_object(raw_output) if add_clean_up: self.addCleanup( - self.openstack, 'project delete %s' % project['id'] + self.openstack, 'project delete {}'.format(project['id']) ) items = self.parse_show(raw_output) self.assert_show_fields(items, self.PROJECT_FIELDS) @@ -130,22 +125,18 @@ class IdentityTests(base.TestCase): email = data_utils.rand_name() + '@example.com' raw_output = self.openstack( 'user create ' - '--project %(project)s ' - '--password %(password)s ' - '--email %(email)s ' + f'--project {self.project_name} ' + f'--password {password} ' + f'--email {email} ' '--enable ' - '%(name)s' - % { - 'project': self.project_name, - 'email': email, - 'password': password, - 'name': username, - } + f'{username}' ) if add_clean_up: self.addCleanup( self.openstack, - 'user delete %s' % self.parse_show_as_object(raw_output)['id'], + 'user delete {}'.format( + self.parse_show_as_object(raw_output)['id'] + ), ) items = self.parse_show(raw_output) self.assert_show_fields(items, self.USER_FIELDS) @@ -153,10 +144,12 @@ class IdentityTests(base.TestCase): def _create_dummy_role(self, add_clean_up=True): role_name = data_utils.rand_name('TestRole') - raw_output = self.openstack('role create %s' % role_name) + raw_output = self.openstack(f'role create {role_name}') role = self.parse_show_as_object(raw_output) if add_clean_up: - self.addCleanup(self.openstack, 'role delete %s' % role['id']) + self.addCleanup( + self.openstack, 'role delete {}'.format(role['id']) + ) items = self.parse_show(raw_output) self.assert_show_fields(items, self.ROLE_FIELDS) self.assertEqual(role_name, role['name']) @@ -168,7 +161,7 @@ class IdentityTests(base.TestCase): access_key = ec2_credentials['access'] if add_clean_up: self.addCleanup( - self.openstack, 'ec2 credentials delete %s' % access_key + self.openstack, f'ec2 credentials delete {access_key}' ) items = self.parse_show(raw_output) self.assert_show_fields(items, self.EC2_CREDENTIALS_FIELDS) @@ -178,7 +171,9 @@ class IdentityTests(base.TestCase): raw_output = self.openstack('token issue') token = self.parse_show_as_object(raw_output) if add_clean_up: - self.addCleanup(self.openstack, 'token revoke %s' % token['id']) + self.addCleanup( + self.openstack, 'token revoke {}'.format(token['id']) + ) items = self.parse_show(raw_output) self.assert_show_fields(items, self.TOKEN_FIELDS) return token['id'] @@ -189,19 +184,14 @@ class IdentityTests(base.TestCase): type_name = data_utils.rand_name('TestType') raw_output = self.openstack( 'service create ' - '--name %(name)s ' - '--description %(description)s ' - '%(type)s' - % { - 'name': service_name, - 'description': description, - 'type': type_name, - } + f'--name {service_name} ' + f'--description {description} ' + f'{type_name}' ) if add_clean_up: service = self.parse_show_as_object(raw_output) self.addCleanup( - self.openstack, 'service delete %s' % service['id'] + self.openstack, 'service delete {}'.format(service['id']) ) items = self.parse_show(raw_output) self.assert_show_fields(items, self.SERVICE_FIELDS) @@ -215,23 +205,16 @@ class IdentityTests(base.TestCase): internal_url = data_utils.rand_url() raw_output = self.openstack( 'endpoint create ' - '--publicurl %(publicurl)s ' - '--adminurl %(adminurl)s ' - '--internalurl %(internalurl)s ' - '--region %(region)s ' - '%(service)s' - % { - 'publicurl': public_url, - 'adminurl': admin_url, - 'internalurl': internal_url, - 'region': region_id, - 'service': service_name, - } + f'--publicurl {public_url} ' + f'--adminurl {admin_url} ' + f'--internalurl {internal_url} ' + f'--region {region_id} ' + f'{service_name}' ) endpoint = self.parse_show_as_object(raw_output) if add_clean_up: self.addCleanup( - self.openstack, 'endpoint delete %s' % endpoint['id'] + self.openstack, 'endpoint delete {}'.format(endpoint['id']) ) items = self.parse_show(raw_output) self.assert_show_fields(items, self.ENDPOINT_FIELDS) diff --git a/openstackclient/tests/functional/identity/v2/test_catalog.py b/openstackclient/tests/functional/identity/v2/test_catalog.py index 1cef314f74..67c6c36945 100644 --- a/openstackclient/tests/functional/identity/v2/test_catalog.py +++ b/openstackclient/tests/functional/identity/v2/test_catalog.py @@ -35,7 +35,7 @@ class CatalogTests(common.IdentityTests): | type | identity | +-----------+-------------------------------------------+ """ - raw_output = self.openstack('catalog show %s' % 'identity') + raw_output = self.openstack('catalog show {}'.format('identity')) items = self.parse_show(raw_output) # items may have multiple endpoint urls with empty key self.assert_show_fields(items, ['endpoints', 'name', 'type', '']) diff --git a/openstackclient/tests/functional/identity/v2/test_ec2_credentials.py b/openstackclient/tests/functional/identity/v2/test_ec2_credentials.py index 6d25bdae2b..b72dc40145 100644 --- a/openstackclient/tests/functional/identity/v2/test_ec2_credentials.py +++ b/openstackclient/tests/functional/identity/v2/test_ec2_credentials.py @@ -20,7 +20,7 @@ class EC2CredentialsTests(common.IdentityTests): def test_ec2_credentials_delete(self): access_key = self._create_dummy_ec2_credentials(add_clean_up=False) raw_output = self.openstack( - 'ec2 credentials delete %s' % access_key, + f'ec2 credentials delete {access_key}', ) self.assertEqual(0, len(raw_output)) @@ -41,7 +41,7 @@ class EC2CredentialsTests(common.IdentityTests): def test_ec2_credentials_show(self): access_key = self._create_dummy_ec2_credentials() show_output = self.openstack( - 'ec2 credentials show %s' % access_key, + f'ec2 credentials show {access_key}', ) items = self.parse_show(show_output) self.assert_show_fields(items, self.EC2_CREDENTIALS_FIELDS) diff --git a/openstackclient/tests/functional/identity/v2/test_endpoint.py b/openstackclient/tests/functional/identity/v2/test_endpoint.py index bafbfdaed9..8a0077b7f2 100644 --- a/openstackclient/tests/functional/identity/v2/test_endpoint.py +++ b/openstackclient/tests/functional/identity/v2/test_endpoint.py @@ -19,7 +19,7 @@ class EndpointTests(common.IdentityTests): def test_endpoint_delete(self): endpoint_id = self._create_dummy_endpoint(add_clean_up=False) - raw_output = self.openstack('endpoint delete %s' % endpoint_id) + raw_output = self.openstack(f'endpoint delete {endpoint_id}') self.assertEqual(0, len(raw_output)) def test_endpoint_multi_delete(self): @@ -39,6 +39,6 @@ class EndpointTests(common.IdentityTests): def test_endpoint_show(self): endpoint_id = self._create_dummy_endpoint() - raw_output = self.openstack('endpoint show %s' % endpoint_id) + raw_output = self.openstack(f'endpoint show {endpoint_id}') items = self.parse_show(raw_output) self.assert_show_fields(items, self.ENDPOINT_FIELDS) diff --git a/openstackclient/tests/functional/identity/v2/test_project.py b/openstackclient/tests/functional/identity/v2/test_project.py index 1ad0edaa31..2dfc95edb8 100644 --- a/openstackclient/tests/functional/identity/v2/test_project.py +++ b/openstackclient/tests/functional/identity/v2/test_project.py @@ -21,13 +21,13 @@ class ProjectTests(common.IdentityTests): description = data_utils.rand_name('description') raw_output = self.openstack( 'project create ' - '--description %(description)s ' + f'--description {description} ' '--enable ' '--property k1=v1 ' '--property k2=v2 ' - '%(name)s' % {'description': description, 'name': project_name} + f'{project_name}' ) - self.addCleanup(self.openstack, 'project delete %s' % project_name) + self.addCleanup(self.openstack, f'project delete {project_name}') items = self.parse_show(raw_output) show_fields = list(self.PROJECT_FIELDS) show_fields.extend(['k1', 'k2']) @@ -38,7 +38,7 @@ class ProjectTests(common.IdentityTests): def test_project_delete(self): project_name = self._create_dummy_project(add_clean_up=False) - raw_output = self.openstack('project delete %s' % project_name) + raw_output = self.openstack(f'project delete {project_name}') self.assertEqual(0, len(raw_output)) def test_project_list(self): @@ -51,14 +51,14 @@ class ProjectTests(common.IdentityTests): new_project_name = data_utils.rand_name('NewTestProject') raw_output = self.openstack( 'project set ' - '--name %(new_name)s ' + f'--name {new_project_name} ' '--disable ' '--property k0=v0 ' - '%(name)s' % {'new_name': new_project_name, 'name': project_name} + f'{project_name}' ) self.assertEqual(0, len(raw_output)) # check project details - raw_output = self.openstack('project show %s' % new_project_name) + raw_output = self.openstack(f'project show {new_project_name}') items = self.parse_show(raw_output) fields = list(self.PROJECT_FIELDS) fields.extend(['properties']) @@ -70,7 +70,7 @@ class ProjectTests(common.IdentityTests): def test_project_show(self): project_name = self._create_dummy_project() - raw_output = self.openstack('project show %s' % project_name) + raw_output = self.openstack(f'project show {project_name}') items = self.parse_show(raw_output) fields = list(self.PROJECT_FIELDS) fields.extend(['properties']) diff --git a/openstackclient/tests/functional/identity/v2/test_role.py b/openstackclient/tests/functional/identity/v2/test_role.py index fb22f0181e..ec6134012f 100644 --- a/openstackclient/tests/functional/identity/v2/test_role.py +++ b/openstackclient/tests/functional/identity/v2/test_role.py @@ -19,7 +19,7 @@ class RoleTests(common.IdentityTests): def test_role_delete(self): role_name = self._create_dummy_role(add_clean_up=False) - raw_output = self.openstack('role delete %s' % role_name) + raw_output = self.openstack(f'role delete {role_name}') self.assertEqual(0, len(raw_output)) def test_role_list(self): @@ -30,7 +30,7 @@ class RoleTests(common.IdentityTests): def test_role_show(self): role_name = self._create_dummy_role() - raw_output = self.openstack('role show %s' % role_name) + raw_output = self.openstack(f'role show {role_name}') items = self.parse_show(raw_output) self.assert_show_fields(items, self.ROLE_FIELDS) @@ -39,26 +39,16 @@ class RoleTests(common.IdentityTests): username = self._create_dummy_user() raw_output = self.openstack( 'role add ' - '--project %(project)s ' - '--user %(user)s ' - '%(role)s' - % { - 'project': self.project_name, - 'user': username, - 'role': role_name, - } + f'--project {self.project_name} ' + f'--user {username} ' + f'{role_name}' ) self.addCleanup( self.openstack, 'role remove ' - '--project %(project)s ' - '--user %(user)s ' - '%(role)s' - % { - 'project': self.project_name, - 'user': username, - 'role': role_name, - }, + f'--project {self.project_name} ' + f'--user {username} ' + f'{role_name}', ) items = self.parse_show(raw_output) self.assert_show_fields(items, self.ROLE_FIELDS) @@ -68,25 +58,15 @@ class RoleTests(common.IdentityTests): username = self._create_dummy_user() add_raw_output = self.openstack( 'role add ' - '--project %(project)s ' - '--user %(user)s ' - '%(role)s' - % { - 'project': self.project_name, - 'user': username, - 'role': role_name, - } + f'--project {self.project_name} ' + f'--user {username} ' + f'{role_name}' ) del_raw_output = self.openstack( 'role remove ' - '--project %(project)s ' - '--user %(user)s ' - '%(role)s' - % { - 'project': self.project_name, - 'user': username, - 'role': role_name, - } + f'--project {self.project_name} ' + f'--user {username} ' + f'{role_name}' ) items = self.parse_show(add_raw_output) self.assert_show_fields(items, self.ROLE_FIELDS) diff --git a/openstackclient/tests/functional/identity/v2/test_service.py b/openstackclient/tests/functional/identity/v2/test_service.py index 7afa967d4b..5f1611cafd 100644 --- a/openstackclient/tests/functional/identity/v2/test_service.py +++ b/openstackclient/tests/functional/identity/v2/test_service.py @@ -19,7 +19,7 @@ class ServiceTests(common.IdentityTests): def test_service_delete(self): service_name = self._create_dummy_service(add_clean_up=False) - raw_output = self.openstack('service delete %s' % service_name) + raw_output = self.openstack(f'service delete {service_name}') self.assertEqual(0, len(raw_output)) def test_service_multi_delete(self): @@ -38,6 +38,6 @@ class ServiceTests(common.IdentityTests): def test_service_show(self): service_name = self._create_dummy_service() - raw_output = self.openstack('service show %s' % service_name) + raw_output = self.openstack(f'service show {service_name}') items = self.parse_show(raw_output) self.assert_show_fields(items, self.SERVICE_FIELDS) diff --git a/openstackclient/tests/functional/identity/v2/test_token.py b/openstackclient/tests/functional/identity/v2/test_token.py index d2ef78e385..51be24319a 100644 --- a/openstackclient/tests/functional/identity/v2/test_token.py +++ b/openstackclient/tests/functional/identity/v2/test_token.py @@ -19,5 +19,5 @@ class TokenTests(common.IdentityTests): def test_token_revoke(self): token_id = self._create_dummy_token(add_clean_up=False) - raw_output = self.openstack('token revoke %s' % token_id) + raw_output = self.openstack(f'token revoke {token_id}') self.assertEqual(0, len(raw_output)) diff --git a/openstackclient/tests/functional/identity/v2/test_user.py b/openstackclient/tests/functional/identity/v2/test_user.py index d30e3c4567..e0d2c956a7 100644 --- a/openstackclient/tests/functional/identity/v2/test_user.py +++ b/openstackclient/tests/functional/identity/v2/test_user.py @@ -22,7 +22,7 @@ class UserTests(common.IdentityTests): def test_user_delete(self): username = self._create_dummy_user(add_clean_up=False) - raw_output = self.openstack('user delete %s' % username) + raw_output = self.openstack(f'user delete {username}') self.assertEqual(0, len(raw_output)) def test_user_list(self): @@ -32,26 +32,24 @@ class UserTests(common.IdentityTests): def test_user_set(self): username = self._create_dummy_user() - raw_output = self.openstack('user show %s' % username) + raw_output = self.openstack(f'user show {username}') user = self.parse_show_as_object(raw_output) new_username = data_utils.rand_name('NewTestUser') new_email = data_utils.rand_name() + '@example.com' raw_output = self.openstack( - 'user set ' - '--email %(email)s ' - '--name %(new_name)s ' - '%(id)s' - % {'email': new_email, 'new_name': new_username, 'id': user['id']} + 'user set ' '--email {email} ' '--name {new_name} ' '{id}'.format( + email=new_email, new_name=new_username, id=user['id'] + ) ) self.assertEqual(0, len(raw_output)) - raw_output = self.openstack('user show %s' % new_username) + raw_output = self.openstack(f'user show {new_username}') new_user = self.parse_show_as_object(raw_output) self.assertEqual(user['id'], new_user['id']) self.assertEqual(new_email, new_user['email']) def test_user_show(self): username = self._create_dummy_user() - raw_output = self.openstack('user show %s' % username) + raw_output = self.openstack(f'user show {username}') items = self.parse_show(raw_output) self.assert_show_fields(items, self.USER_FIELDS) diff --git a/openstackclient/tests/functional/identity/v3/common.py b/openstackclient/tests/functional/identity/v3/common.py index e3c32e35b5..e44f291e5e 100644 --- a/openstackclient/tests/functional/identity/v3/common.py +++ b/openstackclient/tests/functional/identity/v3/common.py @@ -156,10 +156,9 @@ class IdentityTests(base.TestCase): cls.openstack( '--os-identity-api-version 3 ' 'domain create ' - '--description %(description)s ' + f'--description {cls.domain_description} ' '--enable ' - '%(name)s' - % {'description': cls.domain_description, 'name': cls.domain_name} + f'{cls.domain_name}' ) # create dummy project @@ -168,15 +167,10 @@ class IdentityTests(base.TestCase): cls.openstack( '--os-identity-api-version 3 ' 'project create ' - '--domain %(domain)s ' - '--description %(description)s ' + f'--domain {cls.domain_name} ' + f'--description {cls.project_description} ' '--enable ' - '%(name)s' - % { - 'domain': cls.domain_name, - 'description': cls.project_description, - 'name': cls.project_name, - } + f'{cls.project_name}' ) @classmethod @@ -185,16 +179,16 @@ class IdentityTests(base.TestCase): # delete dummy project cls.openstack( '--os-identity-api-version 3 ' - 'project delete %s' % cls.project_name + f'project delete {cls.project_name}' ) # disable and delete dummy domain cls.openstack( '--os-identity-api-version 3 ' - 'domain set --disable %s' % cls.domain_name + f'domain set --disable {cls.domain_name}' ) cls.openstack( '--os-identity-api-version 3 ' - 'domain delete %s' % cls.domain_name + f'domain delete {cls.domain_name}' ) finally: super().tearDownClass() @@ -220,28 +214,21 @@ class IdentityTests(base.TestCase): description = data_utils.rand_name('description') raw_output = self.openstack( 'user create ' - '--domain %(domain)s ' - '--project %(project)s ' - '--project-domain %(project_domain)s ' - '--password %(password)s ' - '--email %(email)s ' - '--description %(description)s ' + f'--domain {self.domain_name} ' + f'--project {self.project_name} ' + f'--project-domain {self.domain_name} ' + f'--password {password} ' + f'--email {email} ' + f'--description {description} ' '--enable ' - '%(name)s' - % { - 'domain': self.domain_name, - 'project': self.project_name, - 'project_domain': self.domain_name, - 'email': email, - 'password': password, - 'description': description, - 'name': username, - } + f'{username}' ) if add_clean_up: self.addCleanup( self.openstack, - 'user delete %s' % self.parse_show_as_object(raw_output)['id'], + 'user delete {}'.format( + self.parse_show_as_object(raw_output)['id'] + ), ) items = self.parse_show(raw_output) self.assert_show_fields(items, self.USER_FIELDS) @@ -249,10 +236,12 @@ class IdentityTests(base.TestCase): def _create_dummy_role(self, add_clean_up=True): role_name = data_utils.rand_name('TestRole') - raw_output = self.openstack('role create %s' % role_name) + raw_output = self.openstack(f'role create {role_name}') role = self.parse_show_as_object(raw_output) if add_clean_up: - self.addCleanup(self.openstack, 'role delete %s' % role['id']) + self.addCleanup( + self.openstack, 'role delete {}'.format(role['id']) + ) items = self.parse_show(raw_output) self.assert_show_fields(items, self.ROLE_FIELDS) self.assertEqual(role_name, role['name']) @@ -263,8 +252,8 @@ class IdentityTests(base.TestCase): implied_role_name = self._create_dummy_role(add_clean_up) self.openstack( 'implied role create ' - '--implied-role %(implied_role)s ' - '%(role)s' % {'implied_role': implied_role_name, 'role': role_name} + f'--implied-role {implied_role_name} ' + f'{role_name}' ) return implied_role_name, role_name @@ -274,21 +263,16 @@ class IdentityTests(base.TestCase): description = data_utils.rand_name('description') raw_output = self.openstack( 'group create ' - '--domain %(domain)s ' - '--description %(description)s ' - '%(name)s' - % { - 'domain': self.domain_name, - 'description': description, - 'name': group_name, - } + f'--domain {self.domain_name} ' + f'--description {description} ' + f'{group_name}' ) if add_clean_up: self.addCleanup( self.openstack, 'group delete ' - '--domain %(domain)s ' - '%(name)s' % {'domain': self.domain_name, 'name': group_name}, + f'--domain {self.domain_name} ' + f'{group_name}', ) items = self.parse_show(raw_output) self.assert_show_fields(items, self.GROUP_FIELDS) @@ -299,14 +283,13 @@ class IdentityTests(base.TestCase): domain_description = data_utils.rand_name('description') self.openstack( 'domain create ' - '--description %(description)s ' - '--enable %(name)s' - % {'description': domain_description, 'name': domain_name} + f'--description {domain_description} ' + f'--enable {domain_name}' ) if add_clean_up: - self.addCleanup(self.openstack, 'domain delete %s' % domain_name) + self.addCleanup(self.openstack, f'domain delete {domain_name}') self.addCleanup( - self.openstack, 'domain set --disable %s' % domain_name + self.openstack, f'domain set --disable {domain_name}' ) return domain_name @@ -315,22 +298,16 @@ class IdentityTests(base.TestCase): project_description = data_utils.rand_name('description') self.openstack( 'project create ' - '--domain %(domain)s ' - '--description %(description)s ' - '--enable %(name)s' - % { - 'domain': self.domain_name, - 'description': project_description, - 'name': project_name, - } + f'--domain {self.domain_name} ' + f'--description {project_description} ' + f'--enable {project_name}' ) if add_clean_up: self.addCleanup( self.openstack, 'project delete ' - '--domain %(domain)s ' - '%(name)s' - % {'domain': self.domain_name, 'name': project_name}, + f'--domain {self.domain_name} ' + f'{project_name}', ) return project_name @@ -339,20 +316,15 @@ class IdentityTests(base.TestCase): description = data_utils.rand_name('description') parent_region_arg = '' if parent_region is not None: - parent_region_arg = '--parent-region %s' % parent_region + parent_region_arg = f'--parent-region {parent_region}' raw_output = self.openstack( 'region create ' - '%(parent_region_arg)s ' - '--description %(description)s ' - '%(id)s' - % { - 'parent_region_arg': parent_region_arg, - 'description': description, - 'id': region_id, - } + f'{parent_region_arg} ' + f'--description {description} ' + f'{region_id}' ) if add_clean_up: - self.addCleanup(self.openstack, 'region delete %s' % region_id) + self.addCleanup(self.openstack, f'region delete {region_id}') items = self.parse_show(raw_output) self.assert_show_fields(items, self.REGION_FIELDS) return region_id @@ -363,20 +335,15 @@ class IdentityTests(base.TestCase): type_name = data_utils.rand_name('TestType') raw_output = self.openstack( 'service create ' - '--name %(name)s ' - '--description %(description)s ' + f'--name {service_name} ' + f'--description {description} ' '--enable ' - '%(type)s' - % { - 'name': service_name, - 'description': description, - 'type': type_name, - } + f'{type_name}' ) if add_clean_up: service = self.parse_show_as_object(raw_output) self.addCleanup( - self.openstack, 'service delete %s' % service['id'] + self.openstack, 'service delete {}'.format(service['id']) ) items = self.parse_show(raw_output) self.assert_show_fields(items, self.SERVICE_FIELDS) @@ -388,22 +355,16 @@ class IdentityTests(base.TestCase): endpoint_url = data_utils.rand_url() raw_output = self.openstack( 'endpoint create ' - '--region %(region)s ' + f'--region {region_id} ' '--enable ' - '%(service)s ' - '%(interface)s ' - '%(url)s' - % { - 'region': region_id, - 'service': service_name, - 'interface': interface, - 'url': endpoint_url, - } + f'{service_name} ' + f'{interface} ' + f'{endpoint_url}' ) endpoint = self.parse_show_as_object(raw_output) if add_clean_up: self.addCleanup( - self.openstack, 'endpoint delete %s' % endpoint['id'] + self.openstack, 'endpoint delete {}'.format(endpoint['id']) ) items = self.parse_show(raw_output) self.assert_show_fields(items, self.ENDPOINT_FIELDS) @@ -414,15 +375,14 @@ class IdentityTests(base.TestCase): description = data_utils.rand_name('description') raw_output = self.openstack( 'identity provider create ' - ' %(name)s ' - '--description %(description)s ' + f' {identity_provider} ' + f'--description {description} ' '--enable ' - % {'name': identity_provider, 'description': description} ) if add_clean_up: self.addCleanup( self.openstack, - 'identity provider delete %s' % identity_provider, + f'identity provider delete {identity_provider}', ) items = self.parse_show(raw_output) self.assert_show_fields(items, self.IDENTITY_PROVIDER_FIELDS) @@ -433,16 +393,15 @@ class IdentityTests(base.TestCase): description = data_utils.rand_name('description') raw_output = self.openstack( 'service provider create ' - ' %(name)s ' - '--description %(description)s ' + f' {service_provider} ' + f'--description {description} ' '--auth-url https://sp.example.com:35357 ' '--service-provider-url https://sp.example.com:5000 ' '--enable ' - % {'name': service_provider, 'description': description} ) if add_clean_up: self.addCleanup( - self.openstack, 'service provider delete %s' % service_provider + self.openstack, f'service provider delete {service_provider}' ) items = self.parse_show(raw_output) self.assert_show_fields(items, self.SERVICE_PROVIDER_FIELDS) @@ -458,9 +417,9 @@ class IdentityTests(base.TestCase): } raw_output = self.openstack( 'registered limit create' - ' --service %(service_name)s' - ' --default-limit %(default_limit)s' - ' %(resource_name)s' % params, + ' --service {service_name}' + ' --default-limit {default_limit}' + ' {resource_name}'.format(**params), cloud=SYSTEM_CLOUD, ) items = self.parse_show(raw_output) @@ -469,7 +428,7 @@ class IdentityTests(base.TestCase): if add_clean_up: self.addCleanup( self.openstack, - 'registered limit delete %s' % registered_limit_id, + f'registered limit delete {registered_limit_id}', cloud=SYSTEM_CLOUD, ) @@ -486,7 +445,7 @@ class IdentityTests(base.TestCase): registered_limit_id = self._create_dummy_registered_limit() raw_output = self.openstack( - 'registered limit show %s' % registered_limit_id, + f'registered limit show {registered_limit_id}', cloud=SYSTEM_CLOUD, ) items = self.parse_show(raw_output) @@ -495,7 +454,7 @@ class IdentityTests(base.TestCase): resource_limit = 15 project_name = self._create_dummy_project() - raw_output = self.openstack('project show %s' % project_name) + raw_output = self.openstack(f'project show {project_name}') items = self.parse_show(raw_output) project_id = self._extract_value_from_items('id', items) @@ -508,10 +467,10 @@ class IdentityTests(base.TestCase): raw_output = self.openstack( 'limit create' - ' --project %(project_id)s' - ' --service %(service_id)s' - ' --resource-limit %(resource_limit)s' - ' %(resource_name)s' % params, + ' --project {project_id}' + ' --service {service_id}' + ' --resource-limit {resource_limit}' + ' {resource_name}'.format(**params), cloud=SYSTEM_CLOUD, ) items = self.parse_show(raw_output) @@ -520,7 +479,7 @@ class IdentityTests(base.TestCase): if add_clean_up: self.addCleanup( self.openstack, - 'limit delete %s' % limit_id, + f'limit delete {limit_id}', cloud=SYSTEM_CLOUD, ) diff --git a/openstackclient/tests/functional/identity/v3/test_application_credential.py b/openstackclient/tests/functional/identity/v3/test_application_credential.py index 22f2b90bb4..4412592784 100644 --- a/openstackclient/tests/functional/identity/v3/test_application_credential.py +++ b/openstackclient/tests/functional/identity/v3/test_application_credential.py @@ -85,34 +85,20 @@ class ApplicationCredentialTests(common.IdentityTests): for role in role1, role2: self.openstack( 'role add' - ' --user %(user)s' - ' --user-domain %(user_domain)s' - ' --project %(project)s' - ' --project-domain %(project_domain)s' - ' %(role)s' - % { - 'user': user, - 'user_domain': user_domain, - 'project': project, - 'project_domain': project_domain, - 'role': role, - } + f' --user {user}' + f' --user-domain {user_domain}' + f' --project {project}' + f' --project-domain {project_domain}' + f' {role}' ) self.addCleanup( self.openstack, 'role remove' - ' --user %(user)s' - ' --user-domain %(user_domain)s' - ' --project %(project)s' - ' --project-domain %(project_domain)s' - ' %(role)s' - % { - 'user': user, - 'user_domain': user_domain, - 'project': project, - 'project_domain': project_domain, - 'role': role, - }, + f' --user {user}' + f' --user-domain {user_domain}' + f' --project {project}' + f' --project-domain {project_domain}' + f' {role}', ) return role1, role2 @@ -125,21 +111,13 @@ class ApplicationCredentialTests(common.IdentityTests): ).strftime('%Y-%m-%dT%H:%M:%S%z') role1, role2 = self._create_role_assignments() raw_output = self.openstack( - 'application credential create %(name)s' - ' --secret %(secret)s' - ' --description %(description)s' - ' --expiration %(tomorrow)s' - ' --role %(role1)s' - ' --role %(role2)s' + f'application credential create {name}' + f' --secret {secret}' + f' --description {description}' + f' --expiration {tomorrow}' + f' --role {role1}' + f' --role {role2}' ' --unrestricted' - % { - 'name': name, - 'secret': secret, - 'description': description, - 'tomorrow': tomorrow, - 'role1': role1, - 'role2': role2, - } ) self.addCleanup( self.openstack, @@ -151,9 +129,7 @@ class ApplicationCredentialTests(common.IdentityTests): def test_application_credential_delete(self): name = data_utils.rand_name('name') self.openstack(f'application credential create {name}') - raw_output = self.openstack( - 'application credential delete ' '%(name)s' % {'name': name} - ) + raw_output = self.openstack('application credential delete ' f'{name}') self.assertEqual(0, len(raw_output)) def test_application_credential_list(self): @@ -170,8 +146,6 @@ class ApplicationCredentialTests(common.IdentityTests): self.openstack, f'application credential delete {name}', ) - raw_output = self.openstack( - 'application credential show ' '%(name)s' % {'name': name} - ) + raw_output = self.openstack('application credential show ' f'{name}') items = self.parse_show(raw_output) self.assert_show_fields(items, self.APPLICATION_CREDENTIAL_FIELDS) diff --git a/openstackclient/tests/functional/identity/v3/test_catalog.py b/openstackclient/tests/functional/identity/v3/test_catalog.py index 9b6df2d194..f4089b7eb8 100644 --- a/openstackclient/tests/functional/identity/v3/test_catalog.py +++ b/openstackclient/tests/functional/identity/v3/test_catalog.py @@ -38,7 +38,7 @@ class CatalogTests(common.IdentityTests): | type | identity | +-----------+----------------------------------------+ """ - raw_output = self.openstack('catalog show %s' % 'identity') + raw_output = self.openstack('catalog show {}'.format('identity')) items = self.parse_show(raw_output) # items may have multiple endpoint urls with empty key self.assert_show_fields(items, ['endpoints', 'name', 'type', '', 'id']) diff --git a/openstackclient/tests/functional/identity/v3/test_domain.py b/openstackclient/tests/functional/identity/v3/test_domain.py index 08e0e07901..867db91df9 100644 --- a/openstackclient/tests/functional/identity/v3/test_domain.py +++ b/openstackclient/tests/functional/identity/v3/test_domain.py @@ -19,12 +19,10 @@ from openstackclient.tests.functional.identity.v3 import common class DomainTests(common.IdentityTests): def test_domain_create(self): domain_name = data_utils.rand_name('TestDomain') - raw_output = self.openstack('domain create %s' % domain_name) + raw_output = self.openstack(f'domain create {domain_name}') # disable domain first before deleting it - self.addCleanup(self.openstack, 'domain delete %s' % domain_name) - self.addCleanup( - self.openstack, 'domain set --disable %s' % domain_name - ) + self.addCleanup(self.openstack, f'domain delete {domain_name}') + self.addCleanup(self.openstack, f'domain set --disable {domain_name}') items = self.parse_show(raw_output) self.assert_show_fields(items, self.DOMAIN_FIELDS) @@ -37,18 +35,18 @@ class DomainTests(common.IdentityTests): def test_domain_delete(self): domain_name = self._create_dummy_domain(add_clean_up=False) # cannot delete enabled domain, disable it first - raw_output = self.openstack('domain set --disable %s' % domain_name) + raw_output = self.openstack(f'domain set --disable {domain_name}') self.assertEqual(0, len(raw_output)) - raw_output = self.openstack('domain delete %s' % domain_name) + raw_output = self.openstack(f'domain delete {domain_name}') self.assertEqual(0, len(raw_output)) def test_domain_multi_delete(self): domain_1 = self._create_dummy_domain(add_clean_up=False) domain_2 = self._create_dummy_domain(add_clean_up=False) # cannot delete enabled domain, disable it first - raw_output = self.openstack('domain set --disable %s' % domain_1) + raw_output = self.openstack(f'domain set --disable {domain_1}') self.assertEqual(0, len(raw_output)) - raw_output = self.openstack('domain set --disable %s' % domain_2) + raw_output = self.openstack(f'domain set --disable {domain_2}') self.assertEqual(0, len(raw_output)) raw_output = self.openstack(f'domain delete {domain_1} {domain_2}') self.assertEqual(0, len(raw_output)) @@ -59,11 +57,11 @@ class DomainTests(common.IdentityTests): self.assertRaises( exceptions.CommandFailed, self.openstack, - 'domain delete %s' % domain_name, + f'domain delete {domain_name}', ) def test_domain_show(self): domain_name = self._create_dummy_domain() - raw_output = self.openstack('domain show %s' % domain_name) + raw_output = self.openstack(f'domain show {domain_name}') items = self.parse_show(raw_output) self.assert_show_fields(items, self.DOMAIN_FIELDS) diff --git a/openstackclient/tests/functional/identity/v3/test_endpoint.py b/openstackclient/tests/functional/identity/v3/test_endpoint.py index 1fff6abeb4..cafab670a3 100644 --- a/openstackclient/tests/functional/identity/v3/test_endpoint.py +++ b/openstackclient/tests/functional/identity/v3/test_endpoint.py @@ -23,7 +23,7 @@ class EndpointTests(common.IdentityTests): def test_endpoint_delete(self): endpoint_id = self._create_dummy_endpoint(add_clean_up=False) - raw_output = self.openstack('endpoint delete %s' % endpoint_id) + raw_output = self.openstack(f'endpoint delete {endpoint_id}') self.assertEqual(0, len(raw_output)) def test_endpoint_multi_delete(self): @@ -45,20 +45,15 @@ class EndpointTests(common.IdentityTests): endpoint_id = self._create_dummy_endpoint(add_clean_up=False) project_id = self._create_dummy_project(add_clean_up=False) raw_output = self.openstack( - 'endpoint add project ' - '%(endpoint_id)s ' - '%(project_id)s' - % {'project_id': project_id, 'endpoint_id': endpoint_id} + 'endpoint add project ' f'{endpoint_id} ' f'{project_id}' ) self.assertEqual(0, len(raw_output)) - raw_output = self.openstack( - 'endpoint list --endpoint %s' % endpoint_id - ) + raw_output = self.openstack(f'endpoint list --endpoint {endpoint_id}') self.assertIn(project_id, raw_output) items = self.parse_listing(raw_output) self.assert_table_structure(items, self.ENDPOINT_LIST_PROJECT_HEADERS) - raw_output = self.openstack('endpoint list --project %s' % project_id) + raw_output = self.openstack(f'endpoint list --project {project_id}') self.assertIn(endpoint_id, raw_output) items = self.parse_listing(raw_output) self.assert_table_structure(items, self.ENDPOINT_LIST_HEADERS) @@ -68,18 +63,17 @@ class EndpointTests(common.IdentityTests): new_endpoint_url = data_utils.rand_url() raw_output = self.openstack( 'endpoint set ' - '--interface %(interface)s ' - '--url %(url)s ' + '--interface {interface} ' + '--url {url} ' '--disable ' - '%(endpoint_id)s' - % { - 'interface': 'admin', - 'url': new_endpoint_url, - 'endpoint_id': endpoint_id, - } + '{endpoint_id}'.format( + interface='admin', + url=new_endpoint_url, + endpoint_id=endpoint_id, + ) ) self.assertEqual(0, len(raw_output)) - raw_output = self.openstack('endpoint show %s' % endpoint_id) + raw_output = self.openstack(f'endpoint show {endpoint_id}') endpoint = self.parse_show_as_object(raw_output) self.assertEqual('admin', endpoint['interface']) self.assertEqual(new_endpoint_url, endpoint['url']) @@ -87,7 +81,7 @@ class EndpointTests(common.IdentityTests): def test_endpoint_show(self): endpoint_id = self._create_dummy_endpoint() - raw_output = self.openstack('endpoint show %s' % endpoint_id) + raw_output = self.openstack(f'endpoint show {endpoint_id}') items = self.parse_show(raw_output) self.assert_show_fields(items, self.ENDPOINT_FIELDS) @@ -95,17 +89,11 @@ class EndpointTests(common.IdentityTests): endpoint_id = self._create_dummy_endpoint(add_clean_up=False) project_id = self._create_dummy_project(add_clean_up=False) raw_output = self.openstack( - 'endpoint add project ' - '%(endpoint_id)s ' - '%(project_id)s' - % {'project_id': project_id, 'endpoint_id': endpoint_id} + 'endpoint add project ' f'{endpoint_id} ' f'{project_id}' ) self.assertEqual(0, len(raw_output)) raw_output = self.openstack( - 'endpoint remove project ' - '%(endpoint_id)s ' - '%(project_id)s' - % {'project_id': project_id, 'endpoint_id': endpoint_id} + 'endpoint remove project ' f'{endpoint_id} ' f'{project_id}' ) self.assertEqual(0, len(raw_output)) diff --git a/openstackclient/tests/functional/identity/v3/test_group.py b/openstackclient/tests/functional/identity/v3/test_group.py index 95d74cb76c..5fc1ed39c3 100644 --- a/openstackclient/tests/functional/identity/v3/test_group.py +++ b/openstackclient/tests/functional/identity/v3/test_group.py @@ -28,9 +28,7 @@ class GroupTests(common.IdentityTests): def test_group_list_with_domain(self): group_name = self._create_dummy_group() - raw_output = self.openstack( - 'group list --domain %s' % self.domain_name - ) + raw_output = self.openstack(f'group list --domain {self.domain_name}') items = self.parse_listing(raw_output) self.assert_table_structure(items, common.BASIC_LIST_HEADERS) self.assertIn(group_name, raw_output) @@ -38,18 +36,14 @@ class GroupTests(common.IdentityTests): def test_group_delete(self): group_name = self._create_dummy_group(add_clean_up=False) raw_output = self.openstack( - 'group delete ' - '--domain %(domain)s ' - '%(name)s' % {'domain': self.domain_name, 'name': group_name} + 'group delete ' f'--domain {self.domain_name} ' f'{group_name}' ) self.assertEqual(0, len(raw_output)) def test_group_show(self): group_name = self._create_dummy_group() raw_output = self.openstack( - 'group show ' - '--domain %(domain)s ' - '%(name)s' % {'domain': self.domain_name, 'name': group_name} + 'group show ' f'--domain {self.domain_name} ' f'{group_name}' ) items = self.parse_show(raw_output) self.assert_show_fields(items, self.GROUP_FIELDS) @@ -59,34 +53,22 @@ class GroupTests(common.IdentityTests): new_group_name = data_utils.rand_name('NewTestGroup') raw_output = self.openstack( 'group set ' - '--domain %(domain)s ' - '--name %(new_group)s ' - '%(group)s' - % { - 'domain': self.domain_name, - 'new_group': new_group_name, - 'group': group_name, - } + f'--domain {self.domain_name} ' + f'--name {new_group_name} ' + f'{group_name}' ) self.assertEqual(0, len(raw_output)) raw_output = self.openstack( - 'group show ' - '--domain %(domain)s ' - '%(group)s' % {'domain': self.domain_name, 'group': new_group_name} + 'group show ' f'--domain {self.domain_name} ' f'{new_group_name}' ) group = self.parse_show_as_object(raw_output) self.assertEqual(new_group_name, group['name']) # reset group name to make sure it will be cleaned up raw_output = self.openstack( 'group set ' - '--domain %(domain)s ' - '--name %(new_group)s ' - '%(group)s' - % { - 'domain': self.domain_name, - 'new_group': group_name, - 'group': new_group_name, - } + f'--domain {self.domain_name} ' + f'--name {group_name} ' + f'{new_group_name}' ) self.assertEqual(0, len(raw_output)) @@ -95,28 +77,16 @@ class GroupTests(common.IdentityTests): username = self._create_dummy_user() raw_output = self.openstack( 'group add user ' - '--group-domain %(group_domain)s ' - '--user-domain %(user_domain)s ' - '%(group)s %(user)s' - % { - 'group_domain': self.domain_name, - 'user_domain': self.domain_name, - 'group': group_name, - 'user': username, - } + f'--group-domain {self.domain_name} ' + f'--user-domain {self.domain_name} ' + f'{group_name} {username}' ) self.addCleanup( self.openstack, 'group remove user ' - '--group-domain %(group_domain)s ' - '--user-domain %(user_domain)s ' - '%(group)s %(user)s' - % { - 'group_domain': self.domain_name, - 'user_domain': self.domain_name, - 'group': group_name, - 'user': username, - }, + f'--group-domain {self.domain_name} ' + f'--user-domain {self.domain_name} ' + f'{group_name} {username}', ) self.assertOutput('', raw_output) @@ -125,45 +95,26 @@ class GroupTests(common.IdentityTests): username = self._create_dummy_user() raw_output = self.openstack( 'group add user ' - '--group-domain %(group_domain)s ' - '--user-domain %(user_domain)s ' - '%(group)s %(user)s' - % { - 'group_domain': self.domain_name, - 'user_domain': self.domain_name, - 'group': group_name, - 'user': username, - } + f'--group-domain {self.domain_name} ' + f'--user-domain {self.domain_name} ' + f'{group_name} {username}' ) self.addCleanup( self.openstack, 'group remove user ' - '--group-domain %(group_domain)s ' - '--user-domain %(user_domain)s ' - '%(group)s %(user)s' - % { - 'group_domain': self.domain_name, - 'user_domain': self.domain_name, - 'group': group_name, - 'user': username, - }, + f'--group-domain {self.domain_name} ' + f'--user-domain {self.domain_name} ' + f'{group_name} {username}', ) self.assertOutput('', raw_output) raw_output = self.openstack( 'group contains user ' - '--group-domain %(group_domain)s ' - '--user-domain %(user_domain)s ' - '%(group)s %(user)s' - % { - 'group_domain': self.domain_name, - 'user_domain': self.domain_name, - 'group': group_name, - 'user': username, - } + f'--group-domain {self.domain_name} ' + f'--user-domain {self.domain_name} ' + f'{group_name} {username}' ) self.assertEqual( - '%(user)s in group %(group)s\n' - % {'user': username, 'group': group_name}, + f'{username} in group {group_name}\n', raw_output, ) @@ -172,27 +123,15 @@ class GroupTests(common.IdentityTests): username = self._create_dummy_user() add_raw_output = self.openstack( 'group add user ' - '--group-domain %(group_domain)s ' - '--user-domain %(user_domain)s ' - '%(group)s %(user)s' - % { - 'group_domain': self.domain_name, - 'user_domain': self.domain_name, - 'group': group_name, - 'user': username, - } + f'--group-domain {self.domain_name} ' + f'--user-domain {self.domain_name} ' + f'{group_name} {username}' ) remove_raw_output = self.openstack( 'group remove user ' - '--group-domain %(group_domain)s ' - '--user-domain %(user_domain)s ' - '%(group)s %(user)s' - % { - 'group_domain': self.domain_name, - 'user_domain': self.domain_name, - 'group': group_name, - 'user': username, - } + f'--group-domain {self.domain_name} ' + f'--user-domain {self.domain_name} ' + f'{group_name} {username}' ) self.assertOutput('', add_raw_output) self.assertOutput('', remove_raw_output) diff --git a/openstackclient/tests/functional/identity/v3/test_idp.py b/openstackclient/tests/functional/identity/v3/test_idp.py index 05f3ee84ee..11275795b2 100644 --- a/openstackclient/tests/functional/identity/v3/test_idp.py +++ b/openstackclient/tests/functional/identity/v3/test_idp.py @@ -24,7 +24,7 @@ class IdentityProviderTests(common.IdentityTests): def test_idp_delete(self): identity_provider = self._create_dummy_idp(add_clean_up=False) raw_output = self.openstack( - 'identity provider delete %s' % identity_provider + f'identity provider delete {identity_provider}' ) self.assertEqual(0, len(raw_output)) @@ -39,7 +39,7 @@ class IdentityProviderTests(common.IdentityTests): def test_idp_show(self): identity_provider = self._create_dummy_idp(add_clean_up=True) raw_output = self.openstack( - 'identity provider show %s' % identity_provider + f'identity provider show {identity_provider}' ) items = self.parse_show(raw_output) self.assert_show_fields(items, self.IDENTITY_PROVIDER_FIELDS) @@ -64,7 +64,7 @@ class IdentityProviderTests(common.IdentityTests): ) self.assertEqual(0, len(raw_output)) raw_output = self.openstack( - 'identity provider show %s' % identity_provider + f'identity provider show {identity_provider}' ) updated_value = self.parse_show_as_object(raw_output) self.assertIn(new_remoteid, updated_value['remote_ids']) diff --git a/openstackclient/tests/functional/identity/v3/test_limit.py b/openstackclient/tests/functional/identity/v3/test_limit.py index 32c65107d0..79213308d2 100644 --- a/openstackclient/tests/functional/identity/v3/test_limit.py +++ b/openstackclient/tests/functional/identity/v3/test_limit.py @@ -23,19 +23,19 @@ class LimitTestCase(common.IdentityTests): def test_limit_create_with_service_name(self): registered_limit_id = self._create_dummy_registered_limit() raw_output = self.openstack( - 'registered limit show %s' % registered_limit_id, + f'registered limit show {registered_limit_id}', cloud=SYSTEM_CLOUD, ) items = self.parse_show(raw_output) service_id = self._extract_value_from_items('service_id', items) resource_name = self._extract_value_from_items('resource_name', items) - raw_output = self.openstack('service show %s' % service_id) + raw_output = self.openstack(f'service show {service_id}') items = self.parse_show(raw_output) service_name = self._extract_value_from_items('name', items) project_name = self._create_dummy_project() - raw_output = self.openstack('project show %s' % project_name) + raw_output = self.openstack(f'project show {project_name}') items = self.parse_show(raw_output) project_id = self._extract_value_from_items('id', items) @@ -47,16 +47,16 @@ class LimitTestCase(common.IdentityTests): } raw_output = self.openstack( 'limit create' - ' --project %(project_id)s' - ' --service %(service_name)s' - ' --resource-limit %(resource_limit)s' - ' %(resource_name)s' % params, + ' --project {project_id}' + ' --service {service_name}' + ' --resource-limit {resource_limit}' + ' {resource_name}'.format(**params), cloud=SYSTEM_CLOUD, ) items = self.parse_show(raw_output) limit_id = self._extract_value_from_items('id', items) self.addCleanup( - self.openstack, 'limit delete %s' % limit_id, cloud=SYSTEM_CLOUD + self.openstack, f'limit delete {limit_id}', cloud=SYSTEM_CLOUD ) self.assert_show_fields(items, self.LIMIT_FIELDS) @@ -64,14 +64,14 @@ class LimitTestCase(common.IdentityTests): def test_limit_create_with_project_name(self): registered_limit_id = self._create_dummy_registered_limit() raw_output = self.openstack( - 'registered limit show %s' % registered_limit_id, + f'registered limit show {registered_limit_id}', cloud=SYSTEM_CLOUD, ) items = self.parse_show(raw_output) service_id = self._extract_value_from_items('service_id', items) resource_name = self._extract_value_from_items('resource_name', items) - raw_output = self.openstack('service show %s' % service_id) + raw_output = self.openstack(f'service show {service_id}') items = self.parse_show(raw_output) service_name = self._extract_value_from_items('name', items) @@ -85,16 +85,16 @@ class LimitTestCase(common.IdentityTests): } raw_output = self.openstack( 'limit create' - ' --project %(project_name)s' - ' --service %(service_name)s' - ' --resource-limit %(resource_limit)s' - ' %(resource_name)s' % params, + ' --project {project_name}' + ' --service {service_name}' + ' --resource-limit {resource_limit}' + ' {resource_name}'.format(**params), cloud=SYSTEM_CLOUD, ) items = self.parse_show(raw_output) limit_id = self._extract_value_from_items('id', items) self.addCleanup( - self.openstack, 'limit delete %s' % limit_id, cloud=SYSTEM_CLOUD + self.openstack, f'limit delete {limit_id}', cloud=SYSTEM_CLOUD ) self.assert_show_fields(items, self.LIMIT_FIELDS) @@ -117,8 +117,8 @@ class LimitTestCase(common.IdentityTests): raw_output = self.openstack( 'registered limit set' - ' %(registered_limit_id)s' - ' --region %(region_id)s' % params, + ' {registered_limit_id}' + ' --region {region_id}'.format(**params), cloud=SYSTEM_CLOUD, ) items = self.parse_show(raw_output) @@ -126,7 +126,7 @@ class LimitTestCase(common.IdentityTests): resource_name = self._extract_value_from_items('resource_name', items) project_name = self._create_dummy_project() - raw_output = self.openstack('project show %s' % project_name) + raw_output = self.openstack(f'project show {project_name}') items = self.parse_show(raw_output) project_id = self._extract_value_from_items('id', items) description = data_utils.arbitrary_string() @@ -141,18 +141,18 @@ class LimitTestCase(common.IdentityTests): } raw_output = self.openstack( 'limit create' - ' --project %(project_id)s' - ' --service %(service_id)s' - ' --resource-limit %(resource_limit)s' - ' --region %(region_id)s' - ' --description %(description)s' - ' %(resource_name)s' % params, + ' --project {project_id}' + ' --service {service_id}' + ' --resource-limit {resource_limit}' + ' --region {region_id}' + ' --description {description}' + ' {resource_name}'.format(**params), cloud=SYSTEM_CLOUD, ) items = self.parse_show(raw_output) limit_id = self._extract_value_from_items('id', items) self.addCleanup( - self.openstack, 'limit delete %s' % limit_id, cloud=SYSTEM_CLOUD + self.openstack, f'limit delete {limit_id}', cloud=SYSTEM_CLOUD ) self.assert_show_fields(items, self.LIMIT_FIELDS) @@ -160,7 +160,7 @@ class LimitTestCase(common.IdentityTests): def test_limit_show(self): limit_id = self._create_dummy_limit() raw_output = self.openstack( - 'limit show %s' % limit_id, cloud=SYSTEM_CLOUD + f'limit show {limit_id}', cloud=SYSTEM_CLOUD ) items = self.parse_show(raw_output) self.assert_show_fields(items, self.LIMIT_FIELDS) @@ -174,9 +174,9 @@ class LimitTestCase(common.IdentityTests): } raw_output = self.openstack( - 'limit set' - ' --description %(description)s' - ' %(limit_id)s' % params, + 'limit set' ' --description {description}' ' {limit_id}'.format( + **params + ), cloud=SYSTEM_CLOUD, ) items = self.parse_show(raw_output) @@ -189,8 +189,8 @@ class LimitTestCase(common.IdentityTests): raw_output = self.openstack( 'limit set' - ' --resource-limit %(resource_limit)s' - ' %(limit_id)s' % params, + ' --resource-limit {resource_limit}' + ' {limit_id}'.format(**params), cloud=SYSTEM_CLOUD, ) items = self.parse_show(raw_output) @@ -205,6 +205,6 @@ class LimitTestCase(common.IdentityTests): def test_limit_delete(self): limit_id = self._create_dummy_limit(add_clean_up=False) raw_output = self.openstack( - 'limit delete %s' % limit_id, cloud=SYSTEM_CLOUD + f'limit delete {limit_id}', cloud=SYSTEM_CLOUD ) self.assertEqual(0, len(raw_output)) diff --git a/openstackclient/tests/functional/identity/v3/test_project.py b/openstackclient/tests/functional/identity/v3/test_project.py index d91ba87a88..9115c0e1af 100644 --- a/openstackclient/tests/functional/identity/v3/test_project.py +++ b/openstackclient/tests/functional/identity/v3/test_project.py @@ -21,23 +21,18 @@ class ProjectTests(common.IdentityTests): description = data_utils.rand_name('description') raw_output = self.openstack( 'project create ' - '--domain %(domain)s ' - '--description %(description)s ' + f'--domain {self.domain_name} ' + f'--description {description} ' '--enable ' '--property k1=v1 ' '--property k2=v2 ' - '%(name)s' - % { - 'domain': self.domain_name, - 'description': description, - 'name': project_name, - } + f'{project_name}' ) self.addCleanup( self.openstack, 'project delete ' - '--domain %(domain)s ' - '%(name)s' % {'domain': self.domain_name, 'name': project_name}, + f'--domain {self.domain_name} ' + f'{project_name}', ) items = self.parse_show(raw_output) show_fields = list(self.PROJECT_FIELDS) @@ -50,9 +45,7 @@ class ProjectTests(common.IdentityTests): def test_project_delete(self): project_name = self._create_dummy_project(add_clean_up=False) raw_output = self.openstack( - 'project delete ' - '--domain %(domain)s ' - '%(name)s' % {'domain': self.domain_name, 'name': project_name} + 'project delete ' f'--domain {self.domain_name} ' f'{project_name}' ) self.assertEqual(0, len(raw_output)) @@ -64,7 +57,7 @@ class ProjectTests(common.IdentityTests): def test_project_list_with_domain(self): project_name = self._create_dummy_project() raw_output = self.openstack( - 'project list --domain %s' % self.domain_name + f'project list --domain {self.domain_name}' ) items = self.parse_listing(raw_output) self.assert_table_structure(items, common.BASIC_LIST_HEADERS) @@ -76,17 +69,17 @@ class ProjectTests(common.IdentityTests): new_project_name = data_utils.rand_name('NewTestProject') raw_output = self.openstack( 'project set ' - '--name %(new_name)s ' + f'--name {new_project_name} ' '--disable ' '--property k0=v0 ' - '%(name)s' % {'new_name': new_project_name, 'name': project_name} + f'{project_name}' ) self.assertEqual(0, len(raw_output)) # check project details raw_output = self.openstack( 'project show ' - '--domain %(domain)s ' - '%(name)s' % {'domain': self.domain_name, 'name': new_project_name} + f'--domain {self.domain_name} ' + f'{new_project_name}' ) items = self.parse_show(raw_output) fields = list(self.PROJECT_FIELDS) @@ -99,17 +92,16 @@ class ProjectTests(common.IdentityTests): # reset project to make sure it will be cleaned up self.openstack( 'project set ' - '--name %(new_name)s ' + f'--name {project_name} ' '--enable ' - '%(name)s' % {'new_name': project_name, 'name': new_project_name} + f'{new_project_name}' ) def test_project_show(self): raw_output = self.openstack( 'project show ' - '--domain %(domain)s ' - '%(name)s' - % {'domain': self.domain_name, 'name': self.project_name} + f'--domain {self.domain_name} ' + f'{self.project_name}' ) items = self.parse_show(raw_output) self.assert_show_fields(items, self.PROJECT_FIELDS) @@ -118,9 +110,8 @@ class ProjectTests(common.IdentityTests): output = self.openstack( 'project show ' '--parents --children ' - '--domain %(domain)s ' - '%(name)s' - % {'domain': self.domain_name, 'name': self.project_name}, + f'--domain {self.domain_name} ' + f'{self.project_name}', parse_output=True, ) for attr_name in self.PROJECT_FIELDS + ['parents', 'subtree']: diff --git a/openstackclient/tests/functional/identity/v3/test_region.py b/openstackclient/tests/functional/identity/v3/test_region.py index 48ca837814..16133f8941 100644 --- a/openstackclient/tests/functional/identity/v3/test_region.py +++ b/openstackclient/tests/functional/identity/v3/test_region.py @@ -23,7 +23,7 @@ class RegionTests(common.IdentityTests): def test_region_delete(self): region_id = self._create_dummy_region(add_clean_up=False) - raw_output = self.openstack('region delete %s' % region_id) + raw_output = self.openstack(f'region delete {region_id}') self.assertEqual(0, len(raw_output)) def test_region_multi_delete(self): @@ -43,27 +43,26 @@ class RegionTests(common.IdentityTests): new_parent_region_id = self._create_dummy_region() region_id = self._create_dummy_region(parent_region_id) # check region details - raw_output = self.openstack('region show %s' % region_id) + raw_output = self.openstack(f'region show {region_id}') region = self.parse_show_as_object(raw_output) self.assertEqual(parent_region_id, region['parent_region']) self.assertEqual(region_id, region['region']) # update parent-region raw_output = self.openstack( 'region set ' - '--parent-region %(parent_region)s ' - '%(region)s' - % {'parent_region': new_parent_region_id, 'region': region_id} + f'--parent-region {new_parent_region_id} ' + f'{region_id}' ) self.assertEqual(0, len(raw_output)) # check updated region details - raw_output = self.openstack('region show %s' % region_id) + raw_output = self.openstack(f'region show {region_id}') region = self.parse_show_as_object(raw_output) self.assertEqual(new_parent_region_id, region['parent_region']) self.assertEqual(region_id, region['region']) def test_region_show(self): region_id = self._create_dummy_region() - raw_output = self.openstack('region show %s' % region_id) + raw_output = self.openstack(f'region show {region_id}') region = self.parse_show_as_object(raw_output) self.assertEqual(region_id, region['region']) self.assertEqual('None', region['parent_region']) diff --git a/openstackclient/tests/functional/identity/v3/test_registered_limit.py b/openstackclient/tests/functional/identity/v3/test_registered_limit.py index 6e3c30aeb0..f91b47fc4b 100644 --- a/openstackclient/tests/functional/identity/v3/test_registered_limit.py +++ b/openstackclient/tests/functional/identity/v3/test_registered_limit.py @@ -25,31 +25,26 @@ class RegisteredLimitTestCase(common.IdentityTests): def test_registered_limit_create_with_service_id(self): service_name = self._create_dummy_service() - raw_output = self.openstack( - 'service show' ' %(service_name)s' % {'service_name': service_name} - ) + raw_output = self.openstack('service show' f' {service_name}') service_items = self.parse_show(raw_output) service_id = self._extract_value_from_items('id', service_items) raw_output = self.openstack( 'registered limit create' - ' --service %(service_id)s' - ' --default-limit %(default_limit)s' - ' %(resource_name)s' - % { - 'service_id': service_id, - 'default_limit': 10, - 'resource_name': 'cores', - }, + ' --service {service_id}' + ' --default-limit {default_limit}' + ' {resource_name}'.format( + service_id=service_id, + default_limit=10, + resource_name='cores', + ), cloud=SYSTEM_CLOUD, ) items = self.parse_show(raw_output) registered_limit_id = self._extract_value_from_items('id', items) self.addCleanup( self.openstack, - 'registered limit delete' - ' %(registered_limit_id)s' - % {'registered_limit_id': registered_limit_id}, + 'registered limit delete' f' {registered_limit_id}', cloud=SYSTEM_CLOUD, ) @@ -68,19 +63,18 @@ class RegisteredLimitTestCase(common.IdentityTests): raw_output = self.openstack( 'registered limit create' - ' --description \'%(description)s\'' - ' --region %(region_id)s' - ' --service %(service_name)s' - ' --default-limit %(default_limit)s' - ' %(resource_name)s' % params, + ' --description \'{description}\'' + ' --region {region_id}' + ' --service {service_name}' + ' --default-limit {default_limit}' + ' {resource_name}'.format(**params), cloud=SYSTEM_CLOUD, ) items = self.parse_show(raw_output) registered_limit_id = self._extract_value_from_items('id', items) self.addCleanup( self.openstack, - 'registered limit delete %(registered_limit_id)s' - % {'registered_limit_id': registered_limit_id}, + f'registered limit delete {registered_limit_id}', cloud=SYSTEM_CLOUD, ) @@ -89,8 +83,7 @@ class RegisteredLimitTestCase(common.IdentityTests): def test_registered_limit_show(self): registered_limit_id = self._create_dummy_registered_limit() raw_output = self.openstack( - 'registered limit show %(registered_limit_id)s' - % {'registered_limit_id': registered_limit_id} + f'registered limit show {registered_limit_id}' ) items = self.parse_show(raw_output) self.assert_show_fields(items, self.REGISTERED_LIMIT_FIELDS) @@ -105,8 +98,8 @@ class RegisteredLimitTestCase(common.IdentityTests): } raw_output = self.openstack( 'registered limit set' - ' %(registered_limit_id)s' - ' --region %(region_id)s' % params, + ' {registered_limit_id}' + ' --region {region_id}'.format(**params), cloud=SYSTEM_CLOUD, ) items = self.parse_show(raw_output) @@ -120,8 +113,8 @@ class RegisteredLimitTestCase(common.IdentityTests): } raw_output = self.openstack( 'registered limit set' - ' %(registered_limit_id)s' - ' --description \'%(description)s\'' % params, + ' {registered_limit_id}' + ' --description \'{description}\''.format(**params), cloud=SYSTEM_CLOUD, ) items = self.parse_show(raw_output) @@ -136,8 +129,8 @@ class RegisteredLimitTestCase(common.IdentityTests): } raw_output = self.openstack( 'registered limit set' - ' %(registered_limit_id)s' - ' --service %(service)s' % params, + ' {registered_limit_id}' + ' --service {service}'.format(**params), cloud=SYSTEM_CLOUD, ) items = self.parse_show(raw_output) @@ -151,8 +144,8 @@ class RegisteredLimitTestCase(common.IdentityTests): } raw_output = self.openstack( 'registered limit set' - ' %(registered_limit_id)s' - ' --default-limit %(default_limit)s' % params, + ' {registered_limit_id}' + ' --default-limit {default_limit}'.format(**params), cloud=SYSTEM_CLOUD, ) items = self.parse_show(raw_output) @@ -167,8 +160,8 @@ class RegisteredLimitTestCase(common.IdentityTests): } raw_output = self.openstack( 'registered limit set' - ' %(registered_limit_id)s' - ' --resource-name %(resource_name)s' % params, + ' {registered_limit_id}' + ' --resource-name {resource_name}'.format(**params), cloud=SYSTEM_CLOUD, ) items = self.parse_show(raw_output) @@ -185,9 +178,7 @@ class RegisteredLimitTestCase(common.IdentityTests): add_clean_up=False ) raw_output = self.openstack( - 'registered limit delete' - ' %(registered_limit_id)s' - % {'registered_limit_id': registered_limit_id}, + 'registered limit delete' f' {registered_limit_id}', cloud=SYSTEM_CLOUD, ) self.assertEqual(0, len(raw_output)) diff --git a/openstackclient/tests/functional/identity/v3/test_role.py b/openstackclient/tests/functional/identity/v3/test_role.py index 9a1aa648f6..16ddc23a3d 100644 --- a/openstackclient/tests/functional/identity/v3/test_role.py +++ b/openstackclient/tests/functional/identity/v3/test_role.py @@ -23,12 +23,10 @@ class RoleTests(common.IdentityTests): role_name = data_utils.rand_name('TestRole') description = data_utils.rand_name('description') raw_output = self.openstack( - 'role create ' - '--description %(description)s ' - '%(name)s' % {'description': description, 'name': role_name} + 'role create ' f'--description {description} ' f'{role_name}' ) role = self.parse_show_as_object(raw_output) - self.addCleanup(self.openstack, 'role delete %s' % role['id']) + self.addCleanup(self.openstack, 'role delete {}'.format(role['id'])) items = self.parse_show(raw_output) self.assert_show_fields(items, self.ROLE_FIELDS) self.assertEqual(description, role['description']) @@ -36,7 +34,7 @@ class RoleTests(common.IdentityTests): def test_role_delete(self): role_name = self._create_dummy_role(add_clean_up=False) - raw_output = self.openstack('role delete %s' % role_name) + raw_output = self.openstack(f'role delete {role_name}') self.assertEqual(0, len(raw_output)) def test_role_list(self): @@ -47,7 +45,7 @@ class RoleTests(common.IdentityTests): def test_role_show(self): role_name = self._create_dummy_role() - raw_output = self.openstack('role show %s' % role_name) + raw_output = self.openstack(f'role show {role_name}') items = self.parse_show(raw_output) self.assert_show_fields(items, self.ROLE_FIELDS) @@ -58,7 +56,7 @@ class RoleTests(common.IdentityTests): f'role set --name {new_role_name} {role_name}' ) self.assertEqual(0, len(raw_output)) - raw_output = self.openstack('role show %s' % new_role_name) + raw_output = self.openstack(f'role show {new_role_name}') role = self.parse_show_as_object(raw_output) self.assertEqual(new_role_name, role['name']) @@ -69,7 +67,7 @@ class RoleTests(common.IdentityTests): f'role set --description {description} {role_name}' ) self.assertEqual(0, len(raw_output)) - raw_output = self.openstack('role show %s' % role_name) + raw_output = self.openstack(f'role show {role_name}') role = self.parse_show_as_object(raw_output) self.assertEqual(description, role['description']) @@ -78,34 +76,20 @@ class RoleTests(common.IdentityTests): username = self._create_dummy_user() raw_output = self.openstack( 'role add ' - '--project %(project)s ' - '--project-domain %(project_domain)s ' - '--user %(user)s ' - '--user-domain %(user_domain)s ' - '%(role)s' - % { - 'project': self.project_name, - 'project_domain': self.domain_name, - 'user': username, - 'user_domain': self.domain_name, - 'role': role_name, - } + f'--project {self.project_name} ' + f'--project-domain {self.domain_name} ' + f'--user {username} ' + f'--user-domain {self.domain_name} ' + f'{role_name}' ) self.addCleanup( self.openstack, 'role remove ' - '--project %(project)s ' - '--project-domain %(project_domain)s ' - '--user %(user)s ' - '--user-domain %(user_domain)s ' - '%(role)s' - % { - 'project': self.project_name, - 'project_domain': self.domain_name, - 'user': username, - 'user_domain': self.domain_name, - 'role': role_name, - }, + f'--project {self.project_name} ' + f'--project-domain {self.domain_name} ' + f'--user {username} ' + f'--user-domain {self.domain_name} ' + f'{role_name}', ) self.assertEqual(0, len(raw_output)) @@ -114,33 +98,19 @@ class RoleTests(common.IdentityTests): username = self._create_dummy_user() add_raw_output = self.openstack( 'role add ' - '--project %(project)s ' - '--project-domain %(project_domain)s ' - '--user %(user)s ' - '--user-domain %(user_domain)s ' - '%(role)s' - % { - 'project': self.project_name, - 'project_domain': self.domain_name, - 'user': username, - 'user_domain': self.domain_name, - 'role': role_name, - } + f'--project {self.project_name} ' + f'--project-domain {self.domain_name} ' + f'--user {username} ' + f'--user-domain {self.domain_name} ' + f'{role_name}' ) remove_raw_output = self.openstack( 'role remove ' - '--project %(project)s ' - '--project-domain %(project_domain)s ' - '--user %(user)s ' - '--user-domain %(user_domain)s ' - '%(role)s' - % { - 'project': self.project_name, - 'project_domain': self.domain_name, - 'user': username, - 'user_domain': self.domain_name, - 'role': role_name, - } + f'--project {self.project_name} ' + f'--project-domain {self.domain_name} ' + f'--user {username} ' + f'--user-domain {self.domain_name} ' + f'{role_name}' ) self.assertEqual(0, len(add_raw_output)) self.assertEqual(0, len(remove_raw_output)) @@ -165,15 +135,15 @@ class RoleTests(common.IdentityTests): implied_role_name = self._create_dummy_role() self.openstack( 'implied role create ' - '--implied-role %(implied_role)s ' - '%(role)s' % {'implied_role': implied_role_name, 'role': role_name} + f'--implied-role {implied_role_name} ' + f'{role_name}' ) def test_implied_role_delete(self): implied_role_name, role_name = self._create_dummy_implied_role() raw_output = self.openstack( 'implied role delete ' - '--implied-role %(implied_role)s ' - '%(role)s' % {'implied_role': implied_role_name, 'role': role_name} + f'--implied-role {implied_role_name} ' + f'{role_name}' ) self.assertEqual(0, len(raw_output)) diff --git a/openstackclient/tests/functional/identity/v3/test_role_assignment.py b/openstackclient/tests/functional/identity/v3/test_role_assignment.py index a3927e7e1e..941563c7bd 100644 --- a/openstackclient/tests/functional/identity/v3/test_role_assignment.py +++ b/openstackclient/tests/functional/identity/v3/test_role_assignment.py @@ -25,43 +25,33 @@ class RoleAssignmentTests(common.IdentityTests): system = 'all' raw_output = self.openstack( 'role add ' - '--user %(user)s ' - '--system %(system)s ' - '%(role)s' - % { - 'user': username, - 'system': system, - 'role': role_name, - } + f'--user {username} ' + f'--system {system} ' + f'{role_name}' ) self.addCleanup( self.openstack, 'role remove ' - '--user %(user)s ' - '--system %(system)s ' - '%(role)s' - % { - 'user': username, - 'system': system, - 'role': role_name, - }, + f'--user {username} ' + f'--system {system} ' + f'{role_name}', ) self.assertEqual(0, len(raw_output)) raw_output = self.openstack( - 'role assignment list ' '--user %(user)s ' % {'user': username} + 'role assignment list ' f'--user {username} ' ) items = self.parse_listing(raw_output) self.assert_table_structure(items, self.ROLE_ASSIGNMENT_LIST_HEADERS) raw_output = self.openstack( - 'role assignment list ' '--role %(role)s ' % {'role': role_name} + 'role assignment list ' f'--role {role_name} ' ) items = self.parse_listing(raw_output) self.assert_table_structure(items, self.ROLE_ASSIGNMENT_LIST_HEADERS) raw_output = self.openstack( - 'role assignment list ' '--system %(system)s ' % {'system': system} + 'role assignment list ' f'--system {system} ' ) items = self.parse_listing(raw_output) self.assert_table_structure(items, self.ROLE_ASSIGNMENT_LIST_HEADERS) @@ -72,30 +62,20 @@ class RoleAssignmentTests(common.IdentityTests): system = 'all' raw_output = self.openstack( 'role add ' - '--group %(group)s ' - '--system %(system)s ' - '%(role)s' - % { - 'group': group, - 'system': system, - 'role': role_name, - } + f'--group {group} ' + f'--system {system} ' + f'{role_name}' ) self.addCleanup( self.openstack, 'role remove ' - '--group %(group)s ' - '--system %(system)s ' - '%(role)s' - % { - 'group': group, - 'system': system, - 'role': role_name, - }, + f'--group {group} ' + f'--system {system} ' + f'{role_name}', ) self.assertEqual(0, len(raw_output)) raw_output = self.openstack( - 'role assignment list ' '--group %(group)s ' % {'group': group} + 'role assignment list ' f'--group {group} ' ) items = self.parse_listing(raw_output) self.assert_table_structure(items, self.ROLE_ASSIGNMENT_LIST_HEADERS) @@ -105,31 +85,20 @@ class RoleAssignmentTests(common.IdentityTests): username = self._create_dummy_user() raw_output = self.openstack( 'role add ' - '--domain %(domain)s ' - '--user %(user)s ' - '%(role)s' - % { - 'domain': self.domain_name, - 'user': username, - 'role': role_name, - } + f'--domain {self.domain_name} ' + f'--user {username} ' + f'{role_name}' ) self.addCleanup( self.openstack, 'role remove ' - '--domain %(domain)s ' - '--user %(user)s ' - '%(role)s' - % { - 'domain': self.domain_name, - 'user': username, - 'role': role_name, - }, + f'--domain {self.domain_name} ' + f'--user {username} ' + f'{role_name}', ) self.assertEqual(0, len(raw_output)) raw_output = self.openstack( - 'role assignment list ' - '--domain %(domain)s ' % {'domain': self.domain_name} + 'role assignment list ' f'--domain {self.domain_name} ' ) items = self.parse_listing(raw_output) self.assert_table_structure(items, self.ROLE_ASSIGNMENT_LIST_HEADERS) @@ -139,31 +108,20 @@ class RoleAssignmentTests(common.IdentityTests): username = self._create_dummy_user() raw_output = self.openstack( 'role add ' - '--project %(project)s ' - '--user %(user)s ' - '%(role)s' - % { - 'project': self.project_name, - 'user': username, - 'role': role_name, - } + f'--project {self.project_name} ' + f'--user {username} ' + f'{role_name}' ) self.addCleanup( self.openstack, 'role remove ' - '--project %(project)s ' - '--user %(user)s ' - '%(role)s' - % { - 'project': self.project_name, - 'user': username, - 'role': role_name, - }, + f'--project {self.project_name} ' + f'--user {username} ' + f'{role_name}', ) self.assertEqual(0, len(raw_output)) raw_output = self.openstack( - 'role assignment list ' - '--project %(project)s ' % {'project': self.project_name} + 'role assignment list ' f'--project {self.project_name} ' ) items = self.parse_listing(raw_output) self.assert_table_structure(items, self.ROLE_ASSIGNMENT_LIST_HEADERS) @@ -188,15 +146,10 @@ class RoleAssignmentTests(common.IdentityTests): username = self._create_dummy_user() raw_output = self.openstack( 'role add ' - '--project %(project)s ' - '--user %(user)s ' + f'--project {self.project_name} ' + f'--user {username} ' '--inherited ' - '%(role)s' - % { - 'project': self.project_name, - 'user': username, - 'role': role_name, - } + f'{role_name}' ) self.assertEqual(0, len(raw_output)) diff --git a/openstackclient/tests/functional/identity/v3/test_service.py b/openstackclient/tests/functional/identity/v3/test_service.py index 98fa349d1e..7e102bacb7 100644 --- a/openstackclient/tests/functional/identity/v3/test_service.py +++ b/openstackclient/tests/functional/identity/v3/test_service.py @@ -21,7 +21,7 @@ class ServiceTests(common.IdentityTests): def test_service_delete(self): service_name = self._create_dummy_service(add_clean_up=False) - raw_output = self.openstack('service delete %s' % service_name) + raw_output = self.openstack(f'service delete {service_name}') self.assertEqual(0, len(raw_output)) def test_service_multi_delete(self): @@ -44,21 +44,15 @@ class ServiceTests(common.IdentityTests): new_service_type = data_utils.rand_name('NewTestType') raw_output = self.openstack( 'service set ' - '--type %(type)s ' - '--name %(name)s ' - '--description %(description)s ' + f'--type {new_service_type} ' + f'--name {new_service_name} ' + f'--description {new_service_description} ' '--disable ' - '%(service)s' - % { - 'type': new_service_type, - 'name': new_service_name, - 'description': new_service_description, - 'service': service_name, - } + f'{service_name}' ) self.assertEqual(0, len(raw_output)) # get service details - raw_output = self.openstack('service show %s' % new_service_name) + raw_output = self.openstack(f'service show {new_service_name}') # assert service details service = self.parse_show_as_object(raw_output) self.assertEqual(new_service_type, service['type']) @@ -67,6 +61,6 @@ class ServiceTests(common.IdentityTests): def test_service_show(self): service_name = self._create_dummy_service() - raw_output = self.openstack('service show %s' % service_name) + raw_output = self.openstack(f'service show {service_name}') items = self.parse_show(raw_output) self.assert_show_fields(items, self.SERVICE_FIELDS) diff --git a/openstackclient/tests/functional/identity/v3/test_service_provider.py b/openstackclient/tests/functional/identity/v3/test_service_provider.py index b7ab14bc43..793223b9d9 100644 --- a/openstackclient/tests/functional/identity/v3/test_service_provider.py +++ b/openstackclient/tests/functional/identity/v3/test_service_provider.py @@ -24,7 +24,7 @@ class ServiceProviderTests(common.IdentityTests): def test_sp_delete(self): service_provider = self._create_dummy_sp(add_clean_up=False) raw_output = self.openstack( - 'service provider delete %s' % service_provider + f'service provider delete {service_provider}' ) self.assertEqual(0, len(raw_output)) @@ -37,7 +37,7 @@ class ServiceProviderTests(common.IdentityTests): def test_sp_show(self): service_provider = self._create_dummy_sp(add_clean_up=True) raw_output = self.openstack( - 'service provider show %s' % service_provider + f'service provider show {service_provider}' ) items = self.parse_show(raw_output) self.assert_show_fields(items, self.SERVICE_PROVIDER_FIELDS) @@ -62,7 +62,7 @@ class ServiceProviderTests(common.IdentityTests): ) self.assertEqual(0, len(raw_output)) raw_output = self.openstack( - 'service provider show %s' % service_provider + f'service provider show {service_provider}' ) updated_value = self.parse_show_as_object(raw_output) self.assertIn(new_description, updated_value['description']) diff --git a/openstackclient/tests/functional/identity/v3/test_user.py b/openstackclient/tests/functional/identity/v3/test_user.py index 917da4a3f6..c32524600c 100644 --- a/openstackclient/tests/functional/identity/v3/test_user.py +++ b/openstackclient/tests/functional/identity/v3/test_user.py @@ -22,9 +22,7 @@ class UserTests(common.IdentityTests): def test_user_delete(self): username = self._create_dummy_user(add_clean_up=False) raw_output = self.openstack( - 'user delete ' - '--domain %(domain)s ' - '%(name)s' % {'domain': self.domain_name, 'name': username} + 'user delete ' f'--domain {self.domain_name} ' f'{username}' ) self.assertEqual(0, len(raw_output)) @@ -36,25 +34,19 @@ class UserTests(common.IdentityTests): def test_user_set(self): username = self._create_dummy_user() raw_output = self.openstack( - 'user show ' - '--domain %(domain)s ' - '%(name)s' % {'domain': self.domain_name, 'name': username} + 'user show ' f'--domain {self.domain_name} ' f'{username}' ) user = self.parse_show_as_object(raw_output) new_username = data_utils.rand_name('NewTestUser') new_email = data_utils.rand_name() + '@example.com' raw_output = self.openstack( - 'user set ' - '--email %(email)s ' - '--name %(new_name)s ' - '%(id)s' - % {'email': new_email, 'new_name': new_username, 'id': user['id']} + 'user set ' '--email {email} ' '--name {new_name} ' '{id}'.format( + email=new_email, new_name=new_username, id=user['id'] + ) ) self.assertEqual(0, len(raw_output)) raw_output = self.openstack( - 'user show ' - '--domain %(domain)s ' - '%(name)s' % {'domain': self.domain_name, 'name': new_username} + 'user show ' f'--domain {self.domain_name} ' f'{new_username}' ) updated_user = self.parse_show_as_object(raw_output) self.assertEqual(user['id'], updated_user['id']) @@ -65,36 +57,29 @@ class UserTests(common.IdentityTests): project_name = self._create_dummy_project() # get original user details raw_output = self.openstack( - 'user show ' - '--domain %(domain)s ' - '%(name)s' % {'domain': self.domain_name, 'name': username} + 'user show ' f'--domain {self.domain_name} ' f'{username}' ) user = self.parse_show_as_object(raw_output) # update user raw_output = self.openstack( 'user set ' - '--project %(project)s ' - '--project-domain %(project_domain)s ' - '%(id)s' - % { - 'project': project_name, - 'project_domain': self.domain_name, - 'id': user['id'], - } + '--project {project} ' + '--project-domain {project_domain} ' + '{id}'.format( + project=project_name, + project_domain=self.domain_name, + id=user['id'], + ) ) self.assertEqual(0, len(raw_output)) # get updated user details raw_output = self.openstack( - 'user show ' - '--domain %(domain)s ' - '%(name)s' % {'domain': self.domain_name, 'name': username} + 'user show ' f'--domain {self.domain_name} ' f'{username}' ) updated_user = self.parse_show_as_object(raw_output) # get project details raw_output = self.openstack( - 'project show ' - '--domain %(domain)s ' - '%(name)s' % {'domain': self.domain_name, 'name': project_name} + 'project show ' f'--domain {self.domain_name} ' f'{project_name}' ) project = self.parse_show_as_object(raw_output) # check updated user details @@ -104,9 +89,7 @@ class UserTests(common.IdentityTests): def test_user_show(self): username = self._create_dummy_user() raw_output = self.openstack( - 'user show ' - '--domain %(domain)s ' - '%(name)s' % {'domain': self.domain_name, 'name': username} + 'user show ' f'--domain {self.domain_name} ' f'{username}' ) items = self.parse_show(raw_output) self.assert_show_fields(items, self.USER_FIELDS) diff --git a/openstackclient/tests/functional/image/v2/test_image.py b/openstackclient/tests/functional/image/v2/test_image.py index 93251ea53b..4d51737c31 100644 --- a/openstackclient/tests/functional/image/v2/test_image.py +++ b/openstackclient/tests/functional/image/v2/test_image.py @@ -30,9 +30,7 @@ class ImageTests(base.BaseImageTests): self.image_tag = 'my_tag' self.image_tag1 = 'random' output = self.openstack( - 'image create --tag {tag} {name}'.format( - tag=self.image_tag, name=self.name - ), + f'image create --tag {self.image_tag} {self.name}', parse_output=True, ) self.image_id = output["id"] diff --git a/openstackclient/tests/functional/network/v2/common.py b/openstackclient/tests/functional/network/v2/common.py index f7c7212a1a..4cd14ebc76 100644 --- a/openstackclient/tests/functional/network/v2/common.py +++ b/openstackclient/tests/functional/network/v2/common.py @@ -80,9 +80,7 @@ class NetworkTagTests(NetworkTests): def _list_tag_check(self, project_id, expected): cmd_output = self.openstack( - '{} list --long --project {}'.format( - self.base_command, project_id - ), + f'{self.base_command} list --long --project {project_id}', parse_output=True, ) for name, tags in expected: diff --git a/openstackclient/tests/functional/network/v2/test_default_security_group_rule.py b/openstackclient/tests/functional/network/v2/test_default_security_group_rule.py index d6ce95c1a8..1481c9a417 100644 --- a/openstackclient/tests/functional/network/v2/test_default_security_group_rule.py +++ b/openstackclient/tests/functional/network/v2/test_default_security_group_rule.py @@ -30,14 +30,9 @@ class SecurityGroupRuleTests(common.NetworkTests): # Create the default security group rule. cmd_output = self.openstack( 'default security group rule create ' - '--protocol %(protocol)s ' - '--dst-port %(port)s:%(port)s ' - '--%(direction)s --ethertype IPv4 ' - % { - 'protocol': self.protocol, - 'port': self.port, - 'direction': self.direction, - }, + f'--protocol {self.protocol} ' + f'--dst-port {self.port}:{self.port} ' + f'--{self.direction} --ethertype IPv4 ', parse_output=True, ) self.addCleanup( diff --git a/openstackclient/tests/functional/network/v2/test_l3_conntrack_helper.py b/openstackclient/tests/functional/network/v2/test_l3_conntrack_helper.py index 510ec8b2dd..95ebb49cea 100644 --- a/openstackclient/tests/functional/network/v2/test_l3_conntrack_helper.py +++ b/openstackclient/tests/functional/network/v2/test_l3_conntrack_helper.py @@ -41,15 +41,14 @@ class L3ConntrackHelperTests(common.NetworkTests): created_helpers = [] for helper in helpers: output = self.openstack( - 'network l3 conntrack helper create %(router)s ' - '--helper %(helper)s --protocol %(protocol)s ' - '--port %(port)s ' - % { - 'router': router_id, - 'helper': helper['helper'], - 'protocol': helper['protocol'], - 'port': helper['port'], - }, + 'network l3 conntrack helper create {router} ' + '--helper {helper} --protocol {protocol} ' + '--port {port} '.format( + router=router_id, + helper=helper['helper'], + protocol=helper['protocol'], + port=helper['port'], + ), parse_output=True, ) self.assertEqual(helper['helper'], output['helper']) @@ -70,8 +69,8 @@ class L3ConntrackHelperTests(common.NetworkTests): ct_ids = " ".join([ct['id'] for ct in created_helpers]) raw_output = self.openstack( - '--debug network l3 conntrack helper delete %(router)s ' - '%(ct_ids)s' % {'router': router_id, 'ct_ids': ct_ids} + f'--debug network l3 conntrack helper delete {router_id} ' + f'{ct_ids}' ) self.assertOutput('', raw_output) @@ -87,7 +86,7 @@ class L3ConntrackHelperTests(common.NetworkTests): router_id = self._create_router() self._create_helpers(router_id, helpers) output = self.openstack( - 'network l3 conntrack helper list %s ' % router_id, + f'network l3 conntrack helper list {router_id} ', parse_output=True, ) for ct in output: @@ -100,12 +99,11 @@ class L3ConntrackHelperTests(common.NetworkTests): router_id = self._create_router() created_helper = self._create_helpers(router_id, [helper])[0] output = self.openstack( - 'network l3 conntrack helper show %(router_id)s %(ct_id)s ' - '-f json' - % { - 'router_id': router_id, - 'ct_id': created_helper['id'], - }, + 'network l3 conntrack helper show {router_id} {ct_id} ' + '-f json'.format( + router_id=router_id, + ct_id=created_helper['id'], + ), parse_output=True, ) self.assertEqual(helper['helper'], output['helper']) @@ -113,23 +111,21 @@ class L3ConntrackHelperTests(common.NetworkTests): self.assertEqual(helper['port'], output['port']) raw_output = self.openstack( - 'network l3 conntrack helper set %(router_id)s %(ct_id)s ' - '--port %(port)s ' - % { - 'router_id': router_id, - 'ct_id': created_helper['id'], - 'port': helper['port'] + 1, - } + 'network l3 conntrack helper set {router_id} {ct_id} ' + '--port {port} '.format( + router_id=router_id, + ct_id=created_helper['id'], + port=helper['port'] + 1, + ) ) self.assertOutput('', raw_output) output = self.openstack( - 'network l3 conntrack helper show %(router_id)s %(ct_id)s ' - '-f json' - % { - 'router_id': router_id, - 'ct_id': created_helper['id'], - }, + 'network l3 conntrack helper show {router_id} {ct_id} ' + '-f json'.format( + router_id=router_id, + ct_id=created_helper['id'], + ), parse_output=True, ) self.assertEqual(helper['port'] + 1, output['port']) diff --git a/openstackclient/tests/functional/network/v2/test_network.py b/openstackclient/tests/functional/network/v2/test_network.py index 8dbe883b6c..a38d88bdac 100644 --- a/openstackclient/tests/functional/network/v2/test_network.py +++ b/openstackclient/tests/functional/network/v2/test_network.py @@ -206,7 +206,7 @@ class NetworkTests(common.NetworkTagTests): 'network create ' + network_options + name1, parse_output=True, ) - self.addCleanup(self.openstack, 'network delete %s' % name1) + self.addCleanup(self.openstack, f'network delete {name1}') self.assertIsNotNone(cmd_output["id"]) if self.haz_network: self.assertEqual( @@ -342,33 +342,30 @@ class NetworkTests(common.NetworkTagTests): name1 = uuid.uuid4().hex cmd_output = self.openstack( - 'network create --description aaaa %s' % name1, + f'network create --description aaaa {name1}', parse_output=True, ) - self.addCleanup(self.openstack, 'network delete %s' % name1) + self.addCleanup(self.openstack, f'network delete {name1}') # Get network ID network_id = cmd_output['id'] # Add Agent to Network self.openstack( - 'network agent add network --dhcp {} {}'.format( - agent_id, network_id - ) + f'network agent add network --dhcp {agent_id} {network_id}' ) # Test network list --agent cmd_output = self.openstack( - 'network list --agent %s' % agent_id, + f'network list --agent {agent_id}', parse_output=True, ) # Cleanup # Remove Agent from Network self.openstack( - 'network agent remove network --dhcp %s %s' - % (agent_id, network_id) + f'network agent remove network --dhcp {agent_id} {network_id}' ) # Assert @@ -388,10 +385,10 @@ class NetworkTests(common.NetworkTagTests): '--no-share ' '--internal ' '--no-default ' - '--enable-port-security %s' % name, + f'--enable-port-security {name}', parse_output=True, ) - self.addCleanup(self.openstack, 'network delete %s' % name) + self.addCleanup(self.openstack, f'network delete {name}') self.assertIsNotNone(cmd_output["id"]) self.assertEqual( 'aaaa', @@ -416,7 +413,7 @@ class NetworkTests(common.NetworkTagTests): '--disable ' '--share ' '--external ' - '--disable-port-security %s' % name + f'--disable-port-security {name}' ) self.assertOutput('', raw_output) diff --git a/openstackclient/tests/functional/network/v2/test_network_agent.py b/openstackclient/tests/functional/network/v2/test_network_agent.py index bbe168aeed..013201a40e 100644 --- a/openstackclient/tests/functional/network/v2/test_network_agent.py +++ b/openstackclient/tests/functional/network/v2/test_network_agent.py @@ -42,7 +42,7 @@ class TestAgent(common.NetworkTests): # agent show cmd_output = self.openstack( - 'network agent show %s' % agent_ids[0], + f'network agent show {agent_ids[0]}', parse_output=True, ) self.assertEqual( @@ -57,12 +57,12 @@ class TestAgent(common.NetworkTests): # agent set raw_output = self.openstack( - 'network agent set --disable %s' % agent_ids[0] + f'network agent set --disable {agent_ids[0]}' ) self.assertOutput('', raw_output) cmd_output = self.openstack( - 'network agent show %s' % agent_ids[0], + f'network agent show {agent_ids[0]}', parse_output=True, ) self.assertEqual( @@ -71,12 +71,12 @@ class TestAgent(common.NetworkTests): ) raw_output = self.openstack( - 'network agent set --enable %s' % agent_ids[0] + f'network agent set --enable {agent_ids[0]}' ) self.assertOutput('', raw_output) cmd_output = self.openstack( - 'network agent show %s' % agent_ids[0], + f'network agent show {agent_ids[0]}', parse_output=True, ) self.assertEqual( @@ -112,33 +112,30 @@ class TestAgentList(common.NetworkTests): name1 = uuid.uuid4().hex cmd_output = self.openstack( - 'network create --description aaaa %s' % name1, + f'network create --description aaaa {name1}', parse_output=True, ) - self.addCleanup(self.openstack, 'network delete %s' % name1) + self.addCleanup(self.openstack, f'network delete {name1}') # Get network ID network_id = cmd_output['id'] # Add Agent to Network self.openstack( - 'network agent add network --dhcp {} {}'.format( - agent_id, network_id - ) + f'network agent add network --dhcp {agent_id} {network_id}' ) # Test network agent list --network cmd_output = self.openstack( - 'network agent list --network %s' % network_id, + f'network agent list --network {network_id}', parse_output=True, ) # Cleanup # Remove Agent from Network self.openstack( - 'network agent remove network --dhcp %s %s' - % (agent_id, network_id) + f'network agent remove network --dhcp {agent_id} {network_id}' ) # Assert @@ -153,11 +150,11 @@ class TestAgentList(common.NetworkTests): name = uuid.uuid4().hex cmd_output = self.openstack( - 'router create %s' % name, + f'router create {name}', parse_output=True, ) - self.addCleanup(self.openstack, 'router delete %s' % name) + self.addCleanup(self.openstack, f'router delete {name}') # Get router ID router_id = cmd_output['id'] # Get l3 agent id @@ -175,7 +172,7 @@ class TestAgentList(common.NetworkTests): # Test router list --agent cmd_output = self.openstack( - 'network agent list --router %s' % router_id, + f'network agent list --router {router_id}', parse_output=True, ) @@ -184,12 +181,10 @@ class TestAgentList(common.NetworkTests): # Remove router from agent self.openstack( - 'network agent remove router --l3 {} {}'.format( - agent_id, router_id - ) + f'network agent remove router --l3 {agent_id} {router_id}' ) cmd_output = self.openstack( - 'network agent list --router %s' % router_id, + f'network agent list --router {router_id}', parse_output=True, ) agent_ids = [x['ID'] for x in cmd_output] diff --git a/openstackclient/tests/functional/network/v2/test_network_flavor.py b/openstackclient/tests/functional/network/v2/test_network_flavor.py index e04d10e805..2b88670378 100644 --- a/openstackclient/tests/functional/network/v2/test_network_flavor.py +++ b/openstackclient/tests/functional/network/v2/test_network_flavor.py @@ -37,10 +37,10 @@ class NetworkFlavorTests(common.NetworkTests): ) service_profile_id = cmd_output2.get('id') - self.addCleanup(self.openstack, 'network flavor delete %s' % flavor_id) + self.addCleanup(self.openstack, f'network flavor delete {flavor_id}') self.addCleanup( self.openstack, - 'network flavor profile delete %s' % service_profile_id, + f'network flavor profile delete {service_profile_id}', ) # Add flavor to service profile self.openstack( diff --git a/openstackclient/tests/functional/network/v2/test_network_ndp_proxy.py b/openstackclient/tests/functional/network/v2/test_network_ndp_proxy.py index d22f297470..11d121a3e8 100644 --- a/openstackclient/tests/functional/network/v2/test_network_ndp_proxy.py +++ b/openstackclient/tests/functional/network/v2/test_network_ndp_proxy.py @@ -31,20 +31,15 @@ class L3NDPProxyTests(common.NetworkTests): self.created_ndp_proxies = [] json_output = self.openstack( - 'address scope create --ip-version 6 ' - '%(address_s_name)s' % {'address_s_name': self.ADDR_SCOPE_NAME}, + 'address scope create --ip-version 6 ' f'{self.ADDR_SCOPE_NAME}', parse_output=True, ) self.assertIsNotNone(json_output['id']) self.ADDRESS_SCOPE_ID = json_output['id'] json_output = self.openstack( - 'subnet pool create %(subnet_p_name)s ' - '--address-scope %(address_scope)s ' - '--pool-prefix 2001:db8::/96 --default-prefix-length 112' - % { - 'subnet_p_name': self.SUBNET_P_NAME, - 'address_scope': self.ADDRESS_SCOPE_ID, - }, + f'subnet pool create {self.SUBNET_P_NAME} ' + f'--address-scope {self.ADDRESS_SCOPE_ID} ' + '--pool-prefix 2001:db8::/96 --default-prefix-length 112', parse_output=True, ) self.assertIsNotNone(json_output['id']) @@ -57,12 +52,7 @@ class L3NDPProxyTests(common.NetworkTests): self.EXT_NET_ID = json_output['id'] json_output = self.openstack( 'subnet create --ip-version 6 --subnet-pool ' - '%(subnet_pool)s --network %(net_id)s %(sub_name)s' - % { - 'subnet_pool': self.SUBNET_POOL_ID, - 'net_id': self.EXT_NET_ID, - 'sub_name': self.EXT_SUB_NAME, - }, + f'{self.SUBNET_POOL_ID} --network {self.EXT_NET_ID} {self.EXT_SUB_NAME}', parse_output=True, ) self.assertIsNotNone(json_output['id']) @@ -74,8 +64,7 @@ class L3NDPProxyTests(common.NetworkTests): self.assertIsNotNone(json_output['id']) self.ROT_ID = json_output['id'] output = self.openstack( - 'router set %(router_id)s --external-gateway %(net_id)s' - % {'router_id': self.ROT_ID, 'net_id': self.EXT_NET_ID} + f'router set {self.ROT_ID} --external-gateway {self.EXT_NET_ID}' ) self.assertEqual('', output) output = self.openstack('router set --enable-ndp-proxy ' + self.ROT_ID) @@ -93,23 +82,14 @@ class L3NDPProxyTests(common.NetworkTests): self.INT_NET_ID = json_output['id'] json_output = self.openstack( 'subnet create --ip-version 6 --subnet-pool ' - '%(subnet_pool)s --network %(net_id)s %(sub_name)s' - % { - 'subnet_pool': self.SUBNET_POOL_ID, - 'net_id': self.INT_NET_ID, - 'sub_name': self.INT_SUB_NAME, - }, + f'{self.SUBNET_POOL_ID} --network {self.INT_NET_ID} {self.INT_SUB_NAME}', parse_output=True, ) self.assertIsNotNone(json_output['id']) self.INT_SUB_ID = json_output['id'] json_output = self.openstack( - 'port create --network %(net_id)s ' - '%(port_name)s' - % { - 'net_id': self.INT_NET_ID, - 'port_name': self.INT_PORT_NAME, - }, + f'port create --network {self.INT_NET_ID} ' + f'{self.INT_PORT_NAME}', parse_output=True, ) self.assertIsNotNone(json_output['id']) @@ -161,14 +141,13 @@ class L3NDPProxyTests(common.NetworkTests): def _create_ndp_proxies(self, ndp_proxies): for ndp_proxy in ndp_proxies: output = self.openstack( - 'router ndp proxy create %(router)s --name %(name)s ' - '--port %(port)s --ip-address %(address)s' - % { - 'router': ndp_proxy['router_id'], - 'name': ndp_proxy['name'], - 'port': ndp_proxy['port_id'], - 'address': ndp_proxy['address'], - }, + 'router ndp proxy create {router} --name {name} ' + '--port {port} --ip-address {address}'.format( + router=ndp_proxy['router_id'], + name=ndp_proxy['name'], + port=ndp_proxy['port_id'], + address=ndp_proxy['address'], + ), parse_output=True, ) self.assertEqual(ndp_proxy['router_id'], output['router_id']) @@ -214,8 +193,7 @@ class L3NDPProxyTests(common.NetworkTests): self._create_ndp_proxies([ndp_proxies]) ndp_proxy_id = self.created_ndp_proxies[0]['id'] output = self.openstack( - 'router ndp proxy set --description %s %s' - % (description, ndp_proxy_id) + f'router ndp proxy set --description {description} {ndp_proxy_id}' ) self.assertEqual('', output) json_output = self.openstack( diff --git a/openstackclient/tests/functional/network/v2/test_network_qos_rule.py b/openstackclient/tests/functional/network/v2/test_network_qos_rule.py index 8db484e2e2..28c38e5a45 100644 --- a/openstackclient/tests/functional/network/v2/test_network_qos_rule.py +++ b/openstackclient/tests/functional/network/v2/test_network_qos_rule.py @@ -32,40 +32,39 @@ class NetworkQosRuleTestsMinimumBandwidth(NetworkQosTests): def setUp(self): super().setUp() - self.QOS_POLICY_NAME = 'qos_policy_%s' % uuid.uuid4().hex + self.QOS_POLICY_NAME = f'qos_policy_{uuid.uuid4().hex}' - self.openstack('network qos policy create %s' % self.QOS_POLICY_NAME) + self.openstack(f'network qos policy create {self.QOS_POLICY_NAME}') self.addCleanup( self.openstack, - 'network qos policy delete %s' % self.QOS_POLICY_NAME, + f'network qos policy delete {self.QOS_POLICY_NAME}', ) cmd_output = self.openstack( 'network qos rule create ' '--type minimum-bandwidth ' '--min-kbps 2800 ' - '--egress %s' % self.QOS_POLICY_NAME, + f'--egress {self.QOS_POLICY_NAME}', parse_output=True, ) self.RULE_ID = cmd_output['id'] self.addCleanup( self.openstack, - 'network qos rule delete %s %s' - % (self.QOS_POLICY_NAME, self.RULE_ID), + f'network qos rule delete {self.QOS_POLICY_NAME} {self.RULE_ID}', ) self.assertTrue(self.RULE_ID) def test_qos_rule_create_delete(self): # This is to check the output of qos rule delete policy_name = uuid.uuid4().hex - self.openstack('network qos policy create %s' % policy_name) + self.openstack(f'network qos policy create {policy_name}') self.addCleanup( - self.openstack, 'network qos policy delete %s' % policy_name + self.openstack, f'network qos policy delete {policy_name}' ) rule = self.openstack( 'network qos rule create ' '--type minimum-bandwidth ' '--min-kbps 2800 ' - '--egress %s' % policy_name, + f'--egress {policy_name}', parse_output=True, ) raw_output = self.openstack( @@ -75,27 +74,24 @@ class NetworkQosRuleTestsMinimumBandwidth(NetworkQosTests): def test_qos_rule_list(self): cmd_output = self.openstack( - 'network qos rule list %s' % self.QOS_POLICY_NAME, + f'network qos rule list {self.QOS_POLICY_NAME}', parse_output=True, ) self.assertIn(self.RULE_ID, [rule['ID'] for rule in cmd_output]) def test_qos_rule_show(self): cmd_output = self.openstack( - 'network qos rule show %s %s' - % (self.QOS_POLICY_NAME, self.RULE_ID), + f'network qos rule show {self.QOS_POLICY_NAME} {self.RULE_ID}', parse_output=True, ) self.assertEqual(self.RULE_ID, cmd_output['id']) def test_qos_rule_set(self): self.openstack( - 'network qos rule set --min-kbps 7500 %s %s' - % (self.QOS_POLICY_NAME, self.RULE_ID) + f'network qos rule set --min-kbps 7500 {self.QOS_POLICY_NAME} {self.RULE_ID}' ) cmd_output = self.openstack( - 'network qos rule show %s %s' - % (self.QOS_POLICY_NAME, self.RULE_ID), + f'network qos rule show {self.QOS_POLICY_NAME} {self.RULE_ID}', parse_output=True, ) self.assertEqual(7500, cmd_output['min_kbps']) @@ -107,40 +103,39 @@ class NetworkQosRuleTestsMinimumPacketRate(NetworkQosTests): def setUp(self): super().setUp() - self.QOS_POLICY_NAME = 'qos_policy_%s' % uuid.uuid4().hex + self.QOS_POLICY_NAME = f'qos_policy_{uuid.uuid4().hex}' - self.openstack('network qos policy create %s' % self.QOS_POLICY_NAME) + self.openstack(f'network qos policy create {self.QOS_POLICY_NAME}') self.addCleanup( self.openstack, - 'network qos policy delete %s' % self.QOS_POLICY_NAME, + f'network qos policy delete {self.QOS_POLICY_NAME}', ) cmd_output = self.openstack( 'network qos rule create ' '--type minimum-packet-rate ' '--min-kpps 2800 ' - '--egress %s' % self.QOS_POLICY_NAME, + f'--egress {self.QOS_POLICY_NAME}', parse_output=True, ) self.RULE_ID = cmd_output['id'] self.addCleanup( self.openstack, - 'network qos rule delete %s %s' - % (self.QOS_POLICY_NAME, self.RULE_ID), + f'network qos rule delete {self.QOS_POLICY_NAME} {self.RULE_ID}', ) self.assertTrue(self.RULE_ID) def test_qos_rule_create_delete(self): # This is to check the output of qos rule delete policy_name = uuid.uuid4().hex - self.openstack('network qos policy create %s' % policy_name) + self.openstack(f'network qos policy create {policy_name}') self.addCleanup( - self.openstack, 'network qos policy delete %s' % policy_name + self.openstack, f'network qos policy delete {policy_name}' ) rule = self.openstack( 'network qos rule create ' '--type minimum-packet-rate ' '--min-kpps 2800 ' - '--egress %s' % policy_name, + f'--egress {policy_name}', parse_output=True, ) raw_output = self.openstack( @@ -150,27 +145,24 @@ class NetworkQosRuleTestsMinimumPacketRate(NetworkQosTests): def test_qos_rule_list(self): cmd_output = self.openstack( - 'network qos rule list %s' % self.QOS_POLICY_NAME, + f'network qos rule list {self.QOS_POLICY_NAME}', parse_output=True, ) self.assertIn(self.RULE_ID, [rule['ID'] for rule in cmd_output]) def test_qos_rule_show(self): cmd_output = self.openstack( - 'network qos rule show %s %s' - % (self.QOS_POLICY_NAME, self.RULE_ID), + f'network qos rule show {self.QOS_POLICY_NAME} {self.RULE_ID}', parse_output=True, ) self.assertEqual(self.RULE_ID, cmd_output['id']) def test_qos_rule_set(self): self.openstack( - 'network qos rule set --min-kpps 7500 --any %s %s' - % (self.QOS_POLICY_NAME, self.RULE_ID) + f'network qos rule set --min-kpps 7500 --any {self.QOS_POLICY_NAME} {self.RULE_ID}' ) cmd_output = self.openstack( - 'network qos rule show %s %s' - % (self.QOS_POLICY_NAME, self.RULE_ID), + f'network qos rule show {self.QOS_POLICY_NAME} {self.RULE_ID}', parse_output=True, ) self.assertEqual(7500, cmd_output['min_kpps']) @@ -183,37 +175,36 @@ class NetworkQosRuleTestsDSCPMarking(NetworkQosTests): def setUp(self): super().setUp() - self.QOS_POLICY_NAME = 'qos_policy_%s' % uuid.uuid4().hex - self.openstack('network qos policy create %s' % self.QOS_POLICY_NAME) + self.QOS_POLICY_NAME = f'qos_policy_{uuid.uuid4().hex}' + self.openstack(f'network qos policy create {self.QOS_POLICY_NAME}') self.addCleanup( self.openstack, - 'network qos policy delete %s' % self.QOS_POLICY_NAME, + f'network qos policy delete {self.QOS_POLICY_NAME}', ) cmd_output = self.openstack( 'network qos rule create ' '--type dscp-marking ' - '--dscp-mark 8 %s' % self.QOS_POLICY_NAME, + f'--dscp-mark 8 {self.QOS_POLICY_NAME}', parse_output=True, ) self.RULE_ID = cmd_output['id'] self.addCleanup( self.openstack, - 'network qos rule delete %s %s' - % (self.QOS_POLICY_NAME, self.RULE_ID), + f'network qos rule delete {self.QOS_POLICY_NAME} {self.RULE_ID}', ) self.assertTrue(self.RULE_ID) def test_qos_rule_create_delete(self): # This is to check the output of qos rule delete policy_name = uuid.uuid4().hex - self.openstack('network qos policy create %s' % policy_name) + self.openstack(f'network qos policy create {policy_name}') self.addCleanup( - self.openstack, 'network qos policy delete %s' % policy_name + self.openstack, f'network qos policy delete {policy_name}' ) rule = self.openstack( 'network qos rule create ' '--type dscp-marking ' - '--dscp-mark 8 %s' % policy_name, + f'--dscp-mark 8 {policy_name}', parse_output=True, ) raw_output = self.openstack( @@ -223,27 +214,24 @@ class NetworkQosRuleTestsDSCPMarking(NetworkQosTests): def test_qos_rule_list(self): cmd_output = self.openstack( - 'network qos rule list %s' % self.QOS_POLICY_NAME, + f'network qos rule list {self.QOS_POLICY_NAME}', parse_output=True, ) self.assertIn(self.RULE_ID, [rule['ID'] for rule in cmd_output]) def test_qos_rule_show(self): cmd_output = self.openstack( - 'network qos rule show %s %s' - % (self.QOS_POLICY_NAME, self.RULE_ID), + f'network qos rule show {self.QOS_POLICY_NAME} {self.RULE_ID}', parse_output=True, ) self.assertEqual(self.RULE_ID, cmd_output['id']) def test_qos_rule_set(self): self.openstack( - 'network qos rule set --dscp-mark 32 %s %s' - % (self.QOS_POLICY_NAME, self.RULE_ID) + f'network qos rule set --dscp-mark 32 {self.QOS_POLICY_NAME} {self.RULE_ID}' ) cmd_output = self.openstack( - 'network qos rule show %s %s' - % (self.QOS_POLICY_NAME, self.RULE_ID), + f'network qos rule show {self.QOS_POLICY_NAME} {self.RULE_ID}', parse_output=True, ) self.assertEqual(32, cmd_output['dscp_mark']) @@ -255,40 +243,39 @@ class NetworkQosRuleTestsBandwidthLimit(NetworkQosTests): def setUp(self): super().setUp() - self.QOS_POLICY_NAME = 'qos_policy_%s' % uuid.uuid4().hex - self.openstack('network qos policy create %s' % self.QOS_POLICY_NAME) + self.QOS_POLICY_NAME = f'qos_policy_{uuid.uuid4().hex}' + self.openstack(f'network qos policy create {self.QOS_POLICY_NAME}') self.addCleanup( self.openstack, - 'network qos policy delete %s' % self.QOS_POLICY_NAME, + f'network qos policy delete {self.QOS_POLICY_NAME}', ) cmd_output = self.openstack( 'network qos rule create ' '--type bandwidth-limit ' '--max-kbps 10000 ' - '--egress %s' % self.QOS_POLICY_NAME, + f'--egress {self.QOS_POLICY_NAME}', parse_output=True, ) self.RULE_ID = cmd_output['id'] self.addCleanup( self.openstack, - 'network qos rule delete %s %s' - % (self.QOS_POLICY_NAME, self.RULE_ID), + f'network qos rule delete {self.QOS_POLICY_NAME} {self.RULE_ID}', ) self.assertTrue(self.RULE_ID) def test_qos_rule_create_delete(self): # This is to check the output of qos rule delete policy_name = uuid.uuid4().hex - self.openstack('network qos policy create %s' % policy_name) + self.openstack(f'network qos policy create {policy_name}') self.addCleanup( - self.openstack, 'network qos policy delete %s' % policy_name + self.openstack, f'network qos policy delete {policy_name}' ) rule = self.openstack( 'network qos rule create ' '--type bandwidth-limit ' '--max-kbps 10000 ' '--max-burst-kbits 1400 ' - '--egress %s' % policy_name, + f'--egress {policy_name}', parse_output=True, ) raw_output = self.openstack( @@ -298,15 +285,14 @@ class NetworkQosRuleTestsBandwidthLimit(NetworkQosTests): def test_qos_rule_list(self): cmd_output = self.openstack( - 'network qos rule list %s' % self.QOS_POLICY_NAME, + f'network qos rule list {self.QOS_POLICY_NAME}', parse_output=True, ) self.assertIn(self.RULE_ID, [rule['ID'] for rule in cmd_output]) def test_qos_rule_show(self): cmd_output = self.openstack( - 'network qos rule show %s %s' - % (self.QOS_POLICY_NAME, self.RULE_ID), + f'network qos rule show {self.QOS_POLICY_NAME} {self.RULE_ID}', parse_output=True, ) self.assertEqual(self.RULE_ID, cmd_output['id']) @@ -315,11 +301,10 @@ class NetworkQosRuleTestsBandwidthLimit(NetworkQosTests): self.openstack( 'network qos rule set --max-kbps 15000 ' '--max-burst-kbits 1800 ' - '--ingress %s %s' % (self.QOS_POLICY_NAME, self.RULE_ID) + f'--ingress {self.QOS_POLICY_NAME} {self.RULE_ID}' ) cmd_output = self.openstack( - 'network qos rule show %s %s' - % (self.QOS_POLICY_NAME, self.RULE_ID), + f'network qos rule show {self.QOS_POLICY_NAME} {self.RULE_ID}', parse_output=True, ) self.assertEqual(15000, cmd_output['max_kbps']) diff --git a/openstackclient/tests/functional/network/v2/test_network_qos_rule_type.py b/openstackclient/tests/functional/network/v2/test_network_qos_rule_type.py index 77ce35716b..745191b8cb 100644 --- a/openstackclient/tests/functional/network/v2/test_network_qos_rule_type.py +++ b/openstackclient/tests/functional/network/v2/test_network_qos_rule_type.py @@ -67,7 +67,7 @@ class NetworkQosRuleTypeTests(common.NetworkTests): def test_qos_rule_type_details(self): for rule_type in self.AVAILABLE_RULE_TYPES: cmd_output = self.openstack( - 'network qos rule type show %s -f json' % rule_type, + f'network qos rule type show {rule_type} -f json', parse_output=True, ) self.assertEqual(rule_type, cmd_output['rule_type_name']) diff --git a/openstackclient/tests/functional/network/v2/test_network_segment_range.py b/openstackclient/tests/functional/network/v2/test_network_segment_range.py index 604ee3cfab..3f07948b5c 100644 --- a/openstackclient/tests/functional/network/v2/test_network_segment_range.py +++ b/openstackclient/tests/functional/network/v2/test_network_segment_range.py @@ -128,8 +128,8 @@ class NetworkSegmentRangeTests(common.NetworkTests): new_minimum = 2020 new_maximum = 2029 cmd_output = self.openstack( - 'network segment range set --minimum {min} --maximum {max} ' - '{name}'.format(min=new_minimum, max=new_maximum, name=name) + f'network segment range set --minimum {new_minimum} --maximum {new_maximum} ' + f'{name}' ) self.assertOutput('', cmd_output) diff --git a/openstackclient/tests/functional/network/v2/test_network_trunk.py b/openstackclient/tests/functional/network/v2/test_network_trunk.py index 7c504286d7..0232943b31 100644 --- a/openstackclient/tests/functional/network/v2/test_network_trunk.py +++ b/openstackclient/tests/functional/network/v2/test_network_trunk.py @@ -32,33 +32,27 @@ class NetworkTrunkTests(common.NetworkTests): self.parent_port_name = uuid.uuid4().hex self.sub_port_name = uuid.uuid4().hex - self.openstack('network create %s' % network_name) - self.addCleanup(self.openstack, 'network delete %s' % network_name) + self.openstack(f'network create {network_name}') + self.addCleanup(self.openstack, f'network delete {network_name}') self.openstack( - 'subnet create %s ' - '--network %s --subnet-range 10.0.0.0/24' - % (subnet_name, network_name) + f'subnet create {subnet_name} ' + f'--network {network_name} --subnet-range 10.0.0.0/24' ) self.openstack( - 'port create %s --network %s' - % (self.parent_port_name, network_name) - ) - self.addCleanup( - self.openstack, 'port delete %s' % self.parent_port_name + f'port create {self.parent_port_name} --network {network_name}' ) + self.addCleanup(self.openstack, f'port delete {self.parent_port_name}') json_out = self.openstack( - 'port create %s --network %s -f json' - % (self.sub_port_name, network_name) + f'port create {self.sub_port_name} --network {network_name} -f json' ) self.sub_port_id = json.loads(json_out)['id'] - self.addCleanup(self.openstack, 'port delete %s' % self.sub_port_name) + self.addCleanup(self.openstack, f'port delete {self.sub_port_name}') def test_network_trunk_create_delete(self): trunk_name = uuid.uuid4().hex self.openstack( - 'network trunk create %s --parent-port %s -f json ' - % (trunk_name, self.parent_port_name) + f'network trunk create {trunk_name} --parent-port {self.parent_port_name} -f json ' ) raw_output = self.openstack('network trunk delete ' + trunk_name) self.assertEqual('', raw_output) @@ -67,8 +61,7 @@ class NetworkTrunkTests(common.NetworkTests): trunk_name = uuid.uuid4().hex json_output = json.loads( self.openstack( - 'network trunk create %s --parent-port %s -f json ' - % (trunk_name, self.parent_port_name) + f'network trunk create {trunk_name} --parent-port {self.parent_port_name} -f json ' ) ) self.addCleanup(self.openstack, 'network trunk delete ' + trunk_name) @@ -81,8 +74,7 @@ class NetworkTrunkTests(common.NetworkTests): trunk_name = uuid.uuid4().hex json_output = json.loads( self.openstack( - 'network trunk create %s --parent-port %s -f json ' - % (trunk_name, self.parent_port_name) + f'network trunk create {trunk_name} --parent-port {self.parent_port_name} -f json ' ) ) self.addCleanup(self.openstack, 'network trunk delete ' + trunk_name) @@ -98,8 +90,7 @@ class NetworkTrunkTests(common.NetworkTests): # Add subport to trunk self.openstack( 'network trunk set ' - + '--subport port=%s,segmentation-type=vlan,segmentation-id=42 ' - % (self.sub_port_name) + + f'--subport port={self.sub_port_name},segmentation-type=vlan,segmentation-id=42 ' + trunk_name ) json_output = json.loads( @@ -132,10 +123,9 @@ class NetworkTrunkTests(common.NetworkTests): trunk_name = uuid.uuid4().hex json_output = json.loads( self.openstack( - 'network trunk create %s --parent-port %s ' - '--subport port=%s,segmentation-type=vlan,segmentation-id=42 ' + f'network trunk create {trunk_name} --parent-port {self.parent_port_name} ' + f'--subport port={self.sub_port_name},segmentation-type=vlan,segmentation-id=42 ' '-f json ' - % (trunk_name, self.parent_port_name, self.sub_port_name) ) ) self.addCleanup(self.openstack, 'network trunk delete ' + trunk_name) @@ -143,7 +133,7 @@ class NetworkTrunkTests(common.NetworkTests): json_output = json.loads( self.openstack( - 'network subport list --trunk %s -f json' % trunk_name + f'network subport list --trunk {trunk_name} -f json' ) ) self.assertEqual( diff --git a/openstackclient/tests/functional/network/v2/test_port.py b/openstackclient/tests/functional/network/v2/test_port.py index 0ba3773417..24fbe0ea16 100644 --- a/openstackclient/tests/functional/network/v2/test_port.py +++ b/openstackclient/tests/functional/network/v2/test_port.py @@ -31,14 +31,14 @@ class PortTests(common.NetworkTagTests): cls.NETWORK_NAME = uuid.uuid4().hex # Create a network for the port tests - cls.openstack('network create %s' % cls.NETWORK_NAME) + cls.openstack(f'network create {cls.NETWORK_NAME}') @classmethod def tearDownClass(cls): try: if cls.haz_network: raw_output = cls.openstack( - 'network delete %s' % cls.NETWORK_NAME + f'network delete {cls.NETWORK_NAME}' ) cls.assertOutput('', raw_output) finally: @@ -56,9 +56,7 @@ class PortTests(common.NetworkTagTests): self.assertEqual(self.NAME, json_output.get('name')) json_output = self.openstack( - 'port create --network {} {}x'.format( - self.NETWORK_NAME, self.NAME - ), + f'port create --network {self.NETWORK_NAME} {self.NAME}x', parse_output=True, ) id2 = json_output.get('id') @@ -80,20 +78,18 @@ class PortTests(common.NetworkTagTests): self.assertIsNotNone(id1) mac1 = json_output.get('mac_address') self.assertIsNotNone(mac1) - self.addCleanup(self.openstack, 'port delete %s' % id1) + self.addCleanup(self.openstack, f'port delete {id1}') self.assertEqual(self.NAME, json_output.get('name')) json_output = self.openstack( - 'port create --network {} {}x'.format( - self.NETWORK_NAME, self.NAME - ), + f'port create --network {self.NETWORK_NAME} {self.NAME}x', parse_output=True, ) id2 = json_output.get('id') self.assertIsNotNone(id2) mac2 = json_output.get('mac_address') self.assertIsNotNone(mac2) - self.addCleanup(self.openstack, 'port delete %s' % id2) + self.addCleanup(self.openstack, f'port delete {id2}') self.assertEqual(self.NAME + 'x', json_output.get('name')) # Test list @@ -120,7 +116,7 @@ class PortTests(common.NetworkTagTests): # Test list --mac-address json_output = self.openstack( - 'port list --mac-address %s' % mac2, + f'port list --mac-address {mac2}', parse_output=True, ) item_map = { @@ -147,22 +143,22 @@ class PortTests(common.NetworkTagTests): name = uuid.uuid4().hex json_output = self.openstack( 'port create ' - '--network %s ' + f'--network {self.NETWORK_NAME} ' '--description xyzpdq ' - '--disable %s' % (self.NETWORK_NAME, name), + f'--disable {name}', parse_output=True, ) id1 = json_output.get('id') - self.addCleanup(self.openstack, 'port delete %s' % id1) + self.addCleanup(self.openstack, f'port delete {id1}') self.assertEqual(name, json_output.get('name')) self.assertEqual('xyzpdq', json_output.get('description')) self.assertEqual(False, json_output.get('admin_state_up')) - raw_output = self.openstack('port set --enable %s' % name) + raw_output = self.openstack(f'port set --enable {name}') self.assertOutput('', raw_output) json_output = self.openstack( - 'port show %s' % name, + f'port show {name}', parse_output=True, ) sg_id = json_output.get('security_group_ids')[0] @@ -178,7 +174,7 @@ class PortTests(common.NetworkTagTests): self.assertOutput('', raw_output) json_output = self.openstack( - 'port show %s' % name, + f'port show {name}', parse_output=True, ) self.assertEqual([], json_output.get('security_group_ids')) @@ -186,19 +182,19 @@ class PortTests(common.NetworkTagTests): def test_port_admin_set(self): """Test create, set (as admin), show, delete""" json_output = self.openstack( - 'port create ' '--network %s %s' % (self.NETWORK_NAME, self.NAME), + 'port create ' f'--network {self.NETWORK_NAME} {self.NAME}', parse_output=True, ) id_ = json_output.get('id') - self.addCleanup(self.openstack, 'port delete %s' % id_) + self.addCleanup(self.openstack, f'port delete {id_}') raw_output = self.openstack( '--os-username admin ' - 'port set --mac-address 11:22:33:44:55:66 %s' % self.NAME + f'port set --mac-address 11:22:33:44:55:66 {self.NAME}' ) self.assertOutput('', raw_output) json_output = self.openstack( - 'port show %s' % self.NAME, + f'port show {self.NAME}', parse_output=True, ) self.assertEqual(json_output.get('mac_address'), '11:22:33:44:55:66') @@ -207,39 +203,39 @@ class PortTests(common.NetworkTagTests): """Test create, set, show, delete""" sg_name1 = uuid.uuid4().hex json_output = self.openstack( - 'security group create %s' % sg_name1, + f'security group create {sg_name1}', parse_output=True, ) sg_id1 = json_output.get('id') - self.addCleanup(self.openstack, 'security group delete %s' % sg_id1) + self.addCleanup(self.openstack, f'security group delete {sg_id1}') sg_name2 = uuid.uuid4().hex json_output = self.openstack( - 'security group create %s' % sg_name2, + f'security group create {sg_name2}', parse_output=True, ) sg_id2 = json_output.get('id') - self.addCleanup(self.openstack, 'security group delete %s' % sg_id2) + self.addCleanup(self.openstack, f'security group delete {sg_id2}') name = uuid.uuid4().hex json_output = self.openstack( 'port create ' - '--network %s ' - '--security-group %s %s' % (self.NETWORK_NAME, sg_name1, name), + f'--network {self.NETWORK_NAME} ' + f'--security-group {sg_name1} {name}', parse_output=True, ) id1 = json_output.get('id') - self.addCleanup(self.openstack, 'port delete %s' % id1) + self.addCleanup(self.openstack, f'port delete {id1}') self.assertEqual(name, json_output.get('name')) self.assertEqual([sg_id1], json_output.get('security_group_ids')) raw_output = self.openstack( - 'port set ' '--security-group %s %s' % (sg_name2, name) + 'port set ' f'--security-group {sg_name2} {name}' ) self.assertOutput('', raw_output) json_output = self.openstack( - 'port show %s' % name, + f'port show {name}', parse_output=True, ) self.assertEqual(name, json_output.get('name')) @@ -256,15 +252,13 @@ class PortTests(common.NetworkTagTests): self.assertOutput('', raw_output) json_output = self.openstack( - 'port show %s' % name, + f'port show {name}', parse_output=True, ) self.assertEqual([sg_id2], json_output.get('security_group_ids')) def _create_resource_for_tag_test(self, name, args): return self.openstack( - '{} create --network {} {} {}'.format( - self.base_command, self.NETWORK_NAME, args, name - ), + f'{self.base_command} create --network {self.NETWORK_NAME} {args} {name}', parse_output=True, ) diff --git a/openstackclient/tests/functional/network/v2/test_router.py b/openstackclient/tests/functional/network/v2/test_router.py index bd4261ac72..89d0652353 100644 --- a/openstackclient/tests/functional/network/v2/test_router.py +++ b/openstackclient/tests/functional/network/v2/test_router.py @@ -275,17 +275,16 @@ class RouterTests(common.NetworkTagTests): subnet_name = uuid.uuid4().hex router_name = uuid.uuid4().hex - self.openstack('network create %s' % network_name) - self.addCleanup(self.openstack, 'network delete %s' % network_name) + self.openstack(f'network create {network_name}') + self.addCleanup(self.openstack, f'network delete {network_name}') self.openstack( - 'subnet create %s ' - '--network %s --subnet-range 10.0.0.0/24' - % (subnet_name, network_name) + f'subnet create {subnet_name} ' + f'--network {network_name} --subnet-range 10.0.0.0/24' ) - self.openstack('router create %s' % router_name) - self.addCleanup(self.openstack, 'router delete %s' % router_name) + self.openstack(f'router create {router_name}') + self.addCleanup(self.openstack, f'router delete {router_name}') self.openstack(f'router add subnet {router_name} {subnet_name}') self.addCleanup( @@ -295,24 +294,20 @@ class RouterTests(common.NetworkTagTests): out1 = ( self.openstack( - 'router add route %s ' - '--route destination=10.0.10.0/24,gateway=10.0.0.10' - % router_name, + f'router add route {router_name} ' + '--route destination=10.0.10.0/24,gateway=10.0.0.10', parse_output=True, ), ) self.assertEqual(1, len(out1[0]['routes'])) - self.addCleanup( - self.openstack, 'router set %s --no-route' % router_name - ) + self.addCleanup(self.openstack, f'router set {router_name} --no-route') out2 = ( self.openstack( - 'router add route %s ' + f'router add route {router_name} ' '--route destination=10.0.10.0/24,gateway=10.0.0.10 ' - '--route destination=10.0.11.0/24,gateway=10.0.0.11' - % router_name, + '--route destination=10.0.11.0/24,gateway=10.0.0.11', parse_output=True, ), ) @@ -320,10 +315,9 @@ class RouterTests(common.NetworkTagTests): out3 = ( self.openstack( - 'router remove route %s ' + f'router remove route {router_name} ' '--route destination=10.0.11.0/24,gateway=10.0.0.11 ' - '--route destination=10.0.12.0/24,gateway=10.0.0.12' - % router_name, + '--route destination=10.0.12.0/24,gateway=10.0.0.12', parse_output=True, ), ) diff --git a/openstackclient/tests/functional/object/v1/test_object.py b/openstackclient/tests/functional/object/v1/test_object.py index 73044de9d1..68ca204337 100644 --- a/openstackclient/tests/functional/object/v1/test_object.py +++ b/openstackclient/tests/functional/object/v1/test_object.py @@ -59,7 +59,7 @@ class ObjectTests(common.ObjectStoreTests): items = self.parse_listing(raw_output) self.assert_show_fields(items, OBJECT_FIELDS) - raw_output = self.openstack('object list %s' % self.CONTAINER_NAME) + raw_output = self.openstack(f'object list {self.CONTAINER_NAME}') items = self.parse_listing(raw_output) self.assert_table_structure(items, BASIC_LIST_HEADERS) @@ -69,15 +69,12 @@ class ObjectTests(common.ObjectStoreTests): tmp_file = 'tmp.txt' self.addCleanup(os.remove, tmp_file) self.openstack( - 'object save %s %s --file %s' - % (self.CONTAINER_NAME, object_file, tmp_file) + f'object save {self.CONTAINER_NAME} {object_file} --file {tmp_file}' ) # TODO(stevemar): Assert returned fields raw_output = self.openstack( - 'object save {} {} --file -'.format( - self.CONTAINER_NAME, object_file - ) + f'object save {self.CONTAINER_NAME} {object_file} --file -' ) self.assertEqual(raw_output, 'test content') @@ -91,6 +88,6 @@ class ObjectTests(common.ObjectStoreTests): self.openstack(f'object create {self.CONTAINER_NAME} {object_file}') raw_output = self.openstack( - 'container delete -r %s' % self.CONTAINER_NAME + f'container delete -r {self.CONTAINER_NAME}' ) self.assertEqual(0, len(raw_output)) diff --git a/openstackclient/tests/functional/volume/base.py b/openstackclient/tests/functional/volume/base.py index ab05642eb1..d1d4ffe00e 100644 --- a/openstackclient/tests/functional/volume/base.py +++ b/openstackclient/tests/functional/volume/base.py @@ -40,21 +40,15 @@ class BaseVolumeTests(base.TestCase): current_status = output['status'] if current_status == desired_status: print( - '{} {} now has status {}'.format( - check_type, check_name, current_status - ) + f'{check_type} {check_name} now has status {current_status}' ) return print( - 'Checking {} {} Waiting for {} current status: {}'.format( - check_type, check_name, desired_status, current_status - ) + f'Checking {check_type} {check_name} Waiting for {desired_status} current status: {current_status}' ) if current_status in failures: raise Exception( - 'Current status {} of {} {} is one of failures {}'.format( - current_status, check_type, check_name, failures - ) + f'Current status {current_status} of {check_type} {check_name} is one of failures {failures}' ) time.sleep(interval) total_sleep += interval @@ -72,15 +66,9 @@ class BaseVolumeTests(base.TestCase): if check_name not in names: print(f'{check_type} {check_name} is now deleted') return - print( - 'Checking {} {} Waiting for deleted'.format( - check_type, check_name - ) - ) + print(f'Checking {check_type} {check_name} Waiting for deleted') time.sleep(interval) total_sleep += interval raise Exception( - 'Timeout: {} {} was not deleted in {} seconds'.format( - check_type, check_name, wait - ) + f'Timeout: {check_type} {check_name} was not deleted in {wait} seconds' ) diff --git a/openstackclient/tests/functional/volume/v1/test_volume_type.py b/openstackclient/tests/functional/volume/v1/test_volume_type.py index 97c8b66c1c..b48dec642e 100644 --- a/openstackclient/tests/functional/volume/v1/test_volume_type.py +++ b/openstackclient/tests/functional/volume/v1/test_volume_type.py @@ -32,7 +32,7 @@ class VolumeTypeTests(common.BaseVolumeTests): self.assertEqual(name, cmd_output['name']) cmd_output = self.openstack( - 'volume type show %s' % name, + f'volume type show {name}', parse_output=True, ) self.assertEqual(self.NAME, cmd_output['name']) @@ -57,19 +57,19 @@ class VolumeTypeTests(common.BaseVolumeTests): self.assertEqual(name, cmd_output['name']) raw_output = self.openstack( - 'volume type set --property a=b --property c=d %s' % name + f'volume type set --property a=b --property c=d {name}' ) self.assertEqual("", raw_output) cmd_output = self.openstack( - 'volume type show %s' % name, + f'volume type show {name}', parse_output=True, ) self.assertEqual({'a': 'b', 'c': 'd'}, cmd_output['properties']) - raw_output = self.openstack('volume type unset --property a %s' % name) + raw_output = self.openstack(f'volume type unset --property a {name}') self.assertEqual("", raw_output) cmd_output = self.openstack( - 'volume type show %s' % name, + f'volume type show {name}', parse_output=True, ) self.assertEqual({'c': 'd'}, cmd_output['properties']) @@ -84,21 +84,21 @@ class VolumeTypeTests(common.BaseVolumeTests): self.assertEqual(name, cmd_output['name']) raw_output = self.openstack( - 'volume type set --property a=b --property c=d %s' % name + f'volume type set --property a=b --property c=d {name}' ) self.assertEqual("", raw_output) cmd_output = self.openstack( - 'volume type show %s' % name, + f'volume type show {name}', parse_output=True, ) self.assertEqual({'a': 'b', 'c': 'd'}, cmd_output['properties']) raw_output = self.openstack( - 'volume type unset --property a --property c %s' % name + f'volume type unset --property a --property c {name}' ) self.assertEqual("", raw_output) cmd_output = self.openstack( - 'volume type show %s' % name, + f'volume type show {name}', parse_output=True, ) self.assertEqual({}, cmd_output['properties']) @@ -106,9 +106,9 @@ class VolumeTypeTests(common.BaseVolumeTests): def test_multi_delete(self): vol_type1 = uuid.uuid4().hex vol_type2 = uuid.uuid4().hex - self.openstack('volume type create %s' % vol_type1) + self.openstack(f'volume type create {vol_type1}') time.sleep(5) - self.openstack('volume type create %s' % vol_type2) + self.openstack(f'volume type create {vol_type2}') time.sleep(5) cmd = f'volume type delete {vol_type1} {vol_type2}' raw_output = self.openstack(cmd) diff --git a/openstackclient/tests/functional/volume/v2/test_volume_backup.py b/openstackclient/tests/functional/volume/v2/test_volume_backup.py index 6bd37f4dc0..7ace71901c 100644 --- a/openstackclient/tests/functional/volume/v2/test_volume_backup.py +++ b/openstackclient/tests/functional/volume/v2/test_volume_backup.py @@ -56,4 +56,4 @@ class VolumeBackupTests(common.BaseVolumeTests): self.wait_for_status( "volume", backup_restored['volume_id'], "available" ) - self.addCleanup(self.openstack, 'volume delete %s' % vol_id) + self.addCleanup(self.openstack, f'volume delete {vol_id}') diff --git a/openstackclient/tests/functional/volume/v2/test_volume_type.py b/openstackclient/tests/functional/volume/v2/test_volume_type.py index bdbced00f6..80bf85a5bb 100644 --- a/openstackclient/tests/functional/volume/v2/test_volume_type.py +++ b/openstackclient/tests/functional/volume/v2/test_volume_type.py @@ -32,7 +32,7 @@ class VolumeTypeTests(common.BaseVolumeTests): self.assertEqual(name, cmd_output['name']) cmd_output = self.openstack( - 'volume type show %s' % name, + f'volume type show {name}', parse_output=True, ) self.assertEqual(name, cmd_output['name']) @@ -57,19 +57,19 @@ class VolumeTypeTests(common.BaseVolumeTests): self.assertEqual(name, cmd_output['name']) raw_output = self.openstack( - 'volume type set --property a=b --property c=d %s' % name + f'volume type set --property a=b --property c=d {name}' ) self.assertEqual("", raw_output) cmd_output = self.openstack( - 'volume type show %s' % name, + f'volume type show {name}', parse_output=True, ) self.assertEqual({'a': 'b', 'c': 'd'}, cmd_output['properties']) - raw_output = self.openstack('volume type unset --property a %s' % name) + raw_output = self.openstack(f'volume type unset --property a {name}') self.assertEqual("", raw_output) cmd_output = self.openstack( - 'volume type show %s' % name, + f'volume type show {name}', parse_output=True, ) self.assertEqual({'c': 'd'}, cmd_output['properties']) @@ -84,21 +84,21 @@ class VolumeTypeTests(common.BaseVolumeTests): self.assertEqual(name, cmd_output['name']) raw_output = self.openstack( - 'volume type set --property a=b --property c=d %s' % name + f'volume type set --property a=b --property c=d {name}' ) self.assertEqual("", raw_output) cmd_output = self.openstack( - 'volume type show %s' % name, + f'volume type show {name}', parse_output=True, ) self.assertEqual({'a': 'b', 'c': 'd'}, cmd_output['properties']) raw_output = self.openstack( - 'volume type unset --property a --property c %s' % name + f'volume type unset --property a --property c {name}' ) self.assertEqual("", raw_output) cmd_output = self.openstack( - 'volume type show %s' % name, + f'volume type show {name}', parse_output=True, ) self.assertEqual({}, cmd_output['properties']) @@ -112,22 +112,20 @@ class VolumeTypeTests(common.BaseVolumeTests): self.addCleanup(self.openstack, 'volume type delete ' + name) self.assertEqual(name, cmd_output['name']) - raw_output = self.openstack( - 'volume type set --project admin %s' % name - ) + raw_output = self.openstack(f'volume type set --project admin {name}') self.assertEqual("", raw_output) raw_output = self.openstack( - 'volume type unset --project admin %s' % name + f'volume type unset --project admin {name}' ) self.assertEqual("", raw_output) def test_multi_delete(self): vol_type1 = uuid.uuid4().hex vol_type2 = uuid.uuid4().hex - self.openstack('volume type create %s' % vol_type1) + self.openstack(f'volume type create {vol_type1}') time.sleep(5) - self.openstack('volume type create %s' % vol_type2) + self.openstack(f'volume type create {vol_type2}') time.sleep(5) cmd = f'volume type delete {vol_type1} {vol_type2}' raw_output = self.openstack(cmd) diff --git a/openstackclient/tests/functional/volume/v3/test_volume_type.py b/openstackclient/tests/functional/volume/v3/test_volume_type.py index 78f9e4063f..421b3224f6 100644 --- a/openstackclient/tests/functional/volume/v3/test_volume_type.py +++ b/openstackclient/tests/functional/volume/v3/test_volume_type.py @@ -32,7 +32,7 @@ class VolumeTypeTests(common.BaseVolumeTests): self.assertEqual(name, cmd_output['name']) cmd_output = self.openstack( - 'volume type show %s' % name, + f'volume type show {name}', parse_output=True, ) self.assertEqual(name, cmd_output['name']) @@ -57,19 +57,19 @@ class VolumeTypeTests(common.BaseVolumeTests): self.assertEqual(name, cmd_output['name']) raw_output = self.openstack( - 'volume type set --property a=b --property c=d %s' % name + f'volume type set --property a=b --property c=d {name}' ) self.assertEqual("", raw_output) cmd_output = self.openstack( - 'volume type show %s' % name, + f'volume type show {name}', parse_output=True, ) self.assertEqual({'a': 'b', 'c': 'd'}, cmd_output['properties']) - raw_output = self.openstack('volume type unset --property a %s' % name) + raw_output = self.openstack(f'volume type unset --property a {name}') self.assertEqual("", raw_output) cmd_output = self.openstack( - 'volume type show %s' % name, + f'volume type show {name}', parse_output=True, ) self.assertEqual({'c': 'd'}, cmd_output['properties']) @@ -84,21 +84,21 @@ class VolumeTypeTests(common.BaseVolumeTests): self.assertEqual(name, cmd_output['name']) raw_output = self.openstack( - 'volume type set --property a=b --property c=d %s' % name + f'volume type set --property a=b --property c=d {name}' ) self.assertEqual("", raw_output) cmd_output = self.openstack( - 'volume type show %s' % name, + f'volume type show {name}', parse_output=True, ) self.assertEqual({'a': 'b', 'c': 'd'}, cmd_output['properties']) raw_output = self.openstack( - 'volume type unset --property a --property c %s' % name + f'volume type unset --property a --property c {name}' ) self.assertEqual("", raw_output) cmd_output = self.openstack( - 'volume type show %s' % name, + f'volume type show {name}', parse_output=True, ) self.assertEqual({}, cmd_output['properties']) @@ -112,22 +112,20 @@ class VolumeTypeTests(common.BaseVolumeTests): self.addCleanup(self.openstack, 'volume type delete ' + name) self.assertEqual(name, cmd_output['name']) - raw_output = self.openstack( - 'volume type set --project admin %s' % name - ) + raw_output = self.openstack(f'volume type set --project admin {name}') self.assertEqual("", raw_output) raw_output = self.openstack( - 'volume type unset --project admin %s' % name + f'volume type unset --project admin {name}' ) self.assertEqual("", raw_output) def test_multi_delete(self): vol_type1 = uuid.uuid4().hex vol_type2 = uuid.uuid4().hex - self.openstack('volume type create %s' % vol_type1) + self.openstack(f'volume type create {vol_type1}') time.sleep(5) - self.openstack('volume type create %s' % vol_type2) + self.openstack(f'volume type create {vol_type2}') time.sleep(5) cmd = f'volume type delete {vol_type1} {vol_type2}' raw_output = self.openstack(cmd) diff --git a/openstackclient/tests/unit/api/test_object_store_v1.py b/openstackclient/tests/unit/api/test_object_store_v1.py index 39bc26a61d..3ff22f5090 100644 --- a/openstackclient/tests/unit/api/test_object_store_v1.py +++ b/openstackclient/tests/unit/api/test_object_store_v1.py @@ -135,16 +135,18 @@ class TestContainer(TestObjectAPIv1): self.requests_mock.register_uri( 'GET', FAKE_URL - + '?marker=%s&limit=1&format=json' - % LIST_CONTAINER_RESP[0]['name'], + + '?marker={}&limit=1&format=json'.format( + LIST_CONTAINER_RESP[0]['name'] + ), json=[LIST_CONTAINER_RESP[1]], status_code=200, ) self.requests_mock.register_uri( 'GET', FAKE_URL - + '?marker=%s&limit=1&format=json' - % LIST_CONTAINER_RESP[1]['name'], + + '?marker={}&limit=1&format=json'.format( + LIST_CONTAINER_RESP[1]['name'] + ), json=[], status_code=200, ) diff --git a/openstackclient/tests/unit/identity/v3/test_group.py b/openstackclient/tests/unit/identity/v3/test_group.py index 04e5a9cf9a..bd983c6180 100644 --- a/openstackclient/tests/unit/identity/v3/test_group.py +++ b/openstackclient/tests/unit/identity/v3/test_group.py @@ -109,12 +109,9 @@ class TestGroupAddUser(TestGroup): self.cmd.take_action(parsed_args) self.fail('CommandError should be raised.') except exceptions.CommandError as e: - msg = "1 of 2 users not added to group %s." % self._group.name + msg = f"1 of 2 users not added to group {self._group.name}." self.assertEqual(msg, str(e)) - msg = ("%(user)s not added to group %(group)s: ") % { - 'user': self.users[0].name, - 'group': self._group.name, - } + msg = f"{self.users[0].name} not added to group {self._group.name}: " mock_error.assert_called_once_with(msg) @@ -561,12 +558,9 @@ class TestGroupRemoveUser(TestGroup): self.cmd.take_action(parsed_args) self.fail('CommandError should be raised.') except exceptions.CommandError as e: - msg = "1 of 2 users not removed from group %s." % self._group.id + msg = f"1 of 2 users not removed from group {self._group.id}." self.assertEqual(msg, str(e)) - msg = ("%(user)s not removed from group %(group)s: ") % { - 'user': self.users[0].id, - 'group': self._group.id, - } + msg = f"{self.users[0].id} not removed from group {self._group.id}: " mock_error.assert_called_once_with(msg) diff --git a/openstackclient/tests/unit/image/v2/test_metadef_objects.py b/openstackclient/tests/unit/image/v2/test_metadef_objects.py index 323d8ea151..4996060d9d 100644 --- a/openstackclient/tests/unit/image/v2/test_metadef_objects.py +++ b/openstackclient/tests/unit/image/v2/test_metadef_objects.py @@ -256,7 +256,6 @@ class TestMetadefObjectPropertyShow(fakes.TestImagev2): parsed_args, ) self.assertIn( - 'Property %s not found in object %s.' - % (parsed_args.property, parsed_args.object), + f'Property {parsed_args.property} not found in object {parsed_args.object}.', str(exc), ) diff --git a/openstackclient/tests/unit/integ/base.py b/openstackclient/tests/unit/integ/base.py index cecf122b2a..e61945a771 100644 --- a/openstackclient/tests/unit/integ/base.py +++ b/openstackclient/tests/unit/integ/base.py @@ -18,7 +18,7 @@ from openstackclient.tests.unit import utils HOST = "192.168.5.41" -URL_BASE = "http://%s/identity" % HOST +URL_BASE = f"http://{HOST}/identity" V2_AUTH_URL = URL_BASE + "/v2.0/" V2_VERSION_RESP = { diff --git a/openstackclient/tests/unit/network/v2/test_network_qos_rule.py b/openstackclient/tests/unit/network/v2/test_network_qos_rule.py index 132902fb31..39e6368735 100644 --- a/openstackclient/tests/unit/network/v2/test_network_qos_rule.py +++ b/openstackclient/tests/unit/network/v2/test_network_qos_rule.py @@ -903,9 +903,9 @@ class TestSetNetworkQosRuleMinimumBandwidth(TestNetworkQosRule): self.cmd.take_action(parsed_args) except exceptions.CommandError as e: msg = ( - 'Failed to set Network QoS rule ID "%(rule)s": Rule type ' + f'Failed to set Network QoS rule ID "{self.new_rule.id}": Rule type ' '"minimum-bandwidth" only requires arguments: direction, ' - 'min_kbps' % {'rule': self.new_rule.id} + 'min_kbps' ) self.assertEqual(msg, str(e)) @@ -1007,9 +1007,9 @@ class TestSetNetworkQosRuleMinimumPacketRate(TestNetworkQosRule): self.cmd.take_action(parsed_args) except exceptions.CommandError as e: msg = ( - 'Failed to set Network QoS rule ID "%(rule)s": Rule type ' + f'Failed to set Network QoS rule ID "{self.new_rule.id}": Rule type ' '"minimum-packet-rate" only requires arguments: direction, ' - 'min_kpps' % {'rule': self.new_rule.id} + 'min_kpps' ) self.assertEqual(msg, str(e)) @@ -1111,9 +1111,8 @@ class TestSetNetworkQosRuleDSCPMarking(TestNetworkQosRule): self.cmd.take_action(parsed_args) except exceptions.CommandError as e: msg = ( - 'Failed to set Network QoS rule ID "%(rule)s": Rule type ' + f'Failed to set Network QoS rule ID "{self.new_rule.id}": Rule type ' '"dscp-marking" only requires arguments: dscp_mark' - % {'rule': self.new_rule.id} ) self.assertEqual(msg, str(e)) @@ -1249,7 +1248,7 @@ class TestSetNetworkQosRuleBandwidthLimit(TestNetworkQosRule): self.addCleanup(self._reset_direction, self.new_rule.direction) arglist = [ - '--%s' % direction, + f'--{direction}', self.new_rule.qos_policy_id, self.new_rule.id, ] @@ -1288,9 +1287,9 @@ class TestSetNetworkQosRuleBandwidthLimit(TestNetworkQosRule): self.cmd.take_action(parsed_args) except exceptions.CommandError as e: msg = ( - 'Failed to set Network QoS rule ID "%(rule)s": Rule type ' + f'Failed to set Network QoS rule ID "{self.new_rule.id}": Rule type ' '"bandwidth-limit" only requires arguments: direction, ' - 'max_burst_kbps, max_kbps' % {'rule': self.new_rule.id} + 'max_burst_kbps, max_kbps' ) self.assertEqual(msg, str(e)) diff --git a/openstackclient/tests/unit/network/v2/test_network_trunk.py b/openstackclient/tests/unit/network/v2/test_network_trunk.py index 153d7f9959..064c44f371 100644 --- a/openstackclient/tests/unit/network/v2/test_network_trunk.py +++ b/openstackclient/tests/unit/network/v2/test_network_trunk.py @@ -143,13 +143,12 @@ class TestCreateNetworkTrunk(TestNetworkTrunk): "--parent-port", self.new_trunk.port_id, "--subport", - 'port=%(port)s,segmentation-type=%(seg_type)s,' - 'segmentation-id=%(seg_id)s' - % { - 'seg_id': subport['segmentation_id'], - 'seg_type': subport['segmentation_type'], - 'port': subport['port_id'], - }, + 'port={port},segmentation-type={seg_type},' + 'segmentation-id={seg_id}'.format( + seg_id=subport['segmentation_id'], + seg_type=subport['segmentation_type'], + port=subport['port_id'], + ), self.new_trunk.name, ] verifylist = [ @@ -194,12 +193,11 @@ class TestCreateNetworkTrunk(TestNetworkTrunk): "--parent-port", self.new_trunk.port_id, "--subport", - "port=%(port)s,segmentation-type=%(seg_type)s," - "segmentation-id=boom" - % { - 'seg_type': subport['segmentation_type'], - 'port': subport['port_id'], - }, + "port={port},segmentation-type={seg_type}," + "segmentation-id=boom".format( + seg_type=subport['segmentation_type'], + port=subport['port_id'], + ), self.new_trunk.name, ] verifylist = [ @@ -265,12 +263,10 @@ class TestCreateNetworkTrunk(TestNetworkTrunk): '--parent-port', self.new_trunk.port_id, '--subport', - 'segmentation-type=%(seg_type)s,' - 'segmentation-id=%(seg_id)s' - % { - 'seg_id': subport['segmentation_id'], - 'seg_type': subport['segmentation_type'], - }, + 'segmentation-type={seg_type},' 'segmentation-id={seg_id}'.format( + seg_id=subport['segmentation_id'], + seg_type=subport['segmentation_type'], + ), self.new_trunk.name, ] verifylist = [ @@ -585,7 +581,7 @@ class TestSetNetworkTrunk(TestNetworkTrunk): def _test_set_network_trunk_attr(self, attr, value): arglist = [ - '--%s' % attr, + f'--{attr}', value, self._trunk[attr], ] @@ -674,13 +670,12 @@ class TestSetNetworkTrunk(TestNetworkTrunk): subport = self._trunk['sub_ports'][0] arglist = [ '--subport', - 'port=%(port)s,segmentation-type=%(seg_type)s,' - 'segmentation-id=%(seg_id)s' - % { - 'seg_id': subport['segmentation_id'], - 'seg_type': subport['segmentation_type'], - 'port': subport['port_id'], - }, + 'port={port},segmentation-type={seg_type},' + 'segmentation-id={seg_id}'.format( + seg_id=subport['segmentation_id'], + seg_type=subport['segmentation_type'], + port=subport['port_id'], + ), self._trunk['name'], ] verifylist = [ @@ -732,12 +727,10 @@ class TestSetNetworkTrunk(TestNetworkTrunk): subport = self._trunk['sub_ports'][0] arglist = [ '--subport', - 'segmentation-type=%(seg_type)s,' - 'segmentation-id=%(seg_id)s' - % { - 'seg_id': subport['segmentation_id'], - 'seg_type': subport['segmentation_type'], - }, + 'segmentation-type={seg_type},' 'segmentation-id={seg_id}'.format( + seg_id=subport['segmentation_id'], + seg_type=subport['segmentation_type'], + ), self._trunk['name'], ] verifylist = [ @@ -776,7 +769,8 @@ class TestSetNetworkTrunk(TestNetworkTrunk): with testtools.ExpectedException(exceptions.CommandError) as e: self.cmd.take_action(parsed_args) self.assertEqual( - "Failed to set trunk '%s': " % self._trunk['name'], str(e) + "Failed to set trunk '{}': ".format(self._trunk['name']), + str(e), ) attrs = {'name': 'reallylongname'} self.network_client.update_trunk.assert_called_once_with( @@ -805,7 +799,9 @@ class TestSetNetworkTrunk(TestNetworkTrunk): with testtools.ExpectedException(exceptions.CommandError) as e: self.cmd.take_action(parsed_args) self.assertEqual( - "Failed to add subports to trunk '%s': " % self._trunk['name'], + "Failed to add subports to trunk '{}': ".format( + self._trunk['name'] + ), str(e), ) self.network_client.update_trunk.assert_called_once_with(self._trunk) diff --git a/openstackclient/tests/unit/network/v2/test_port.py b/openstackclient/tests/unit/network/v2/test_port.py index 7d19636510..d7592e99be 100644 --- a/openstackclient/tests/unit/network/v2/test_port.py +++ b/openstackclient/tests/unit/network/v2/test_port.py @@ -179,7 +179,7 @@ class TestCreatePort(TestPort): '--mac-address', 'aa:aa:aa:aa:aa:aa', '--fixed-ip', - 'subnet=%s,ip-address=10.0.0.2' % self.fake_subnet.id, + f'subnet={self.fake_subnet.id},ip-address=10.0.0.2', '--description', self._port.description, '--device', @@ -866,7 +866,7 @@ class TestCreatePort(TestPort): 'test-port', ] if policy: - arglist += ['--numa-policy-%s' % policy] + arglist += [f'--numa-policy-{policy}'] numa_affinity_policy = None if not policy else policy verifylist = [ @@ -877,7 +877,7 @@ class TestCreatePort(TestPort): ('name', 'test-port'), ] if policy: - verifylist.append(('numa_policy_%s' % policy, True)) + verifylist.append((f'numa_policy_{policy}', True)) parsed_args = self.check_parser(self.cmd, arglist, verifylist) @@ -1418,7 +1418,7 @@ class TestListPort(compute_fakes.FakeClientMixin, TestPort): ip_address = self._ports[0].fixed_ips[0]['ip_address'] arglist = [ '--fixed-ip', - "ip-address=%s" % ip_address, + f"ip-address={ip_address}", ] verifylist = [('fixed_ip', [{'ip-address': ip_address}])] @@ -1428,7 +1428,7 @@ class TestListPort(compute_fakes.FakeClientMixin, TestPort): self.network_client.ports.assert_called_once_with( **{ - 'fixed_ips': ['ip_address=%s' % ip_address], + 'fixed_ips': [f'ip_address={ip_address}'], 'fields': LIST_FIELDS_TO_RETRIEVE, } ) @@ -1439,7 +1439,7 @@ class TestListPort(compute_fakes.FakeClientMixin, TestPort): ip_address_ss = self._ports[0].fixed_ips[0]['ip_address'][:-1] arglist = [ '--fixed-ip', - "ip-substring=%s" % ip_address_ss, + f"ip-substring={ip_address_ss}", ] verifylist = [('fixed_ip', [{'ip-substring': ip_address_ss}])] @@ -1449,7 +1449,7 @@ class TestListPort(compute_fakes.FakeClientMixin, TestPort): self.network_client.ports.assert_called_once_with( **{ - 'fixed_ips': ['ip_address_substr=%s' % ip_address_ss], + 'fixed_ips': [f'ip_address_substr={ip_address_ss}'], 'fields': LIST_FIELDS_TO_RETRIEVE, } ) @@ -1460,7 +1460,7 @@ class TestListPort(compute_fakes.FakeClientMixin, TestPort): subnet_id = self._ports[0].fixed_ips[0]['subnet_id'] arglist = [ '--fixed-ip', - "subnet=%s" % subnet_id, + f"subnet={subnet_id}", ] verifylist = [('fixed_ip', [{'subnet': subnet_id}])] @@ -1475,7 +1475,7 @@ class TestListPort(compute_fakes.FakeClientMixin, TestPort): self.network_client.ports.assert_called_once_with( **{ - 'fixed_ips': ['subnet_id=%s' % subnet_id], + 'fixed_ips': [f'subnet_id={subnet_id}'], 'fields': LIST_FIELDS_TO_RETRIEVE, } ) @@ -1505,8 +1505,8 @@ class TestListPort(compute_fakes.FakeClientMixin, TestPort): self.network_client.ports.assert_called_once_with( **{ 'fixed_ips': [ - 'subnet_id=%s' % subnet_id, - 'ip_address=%s' % ip_address, + f'subnet_id={subnet_id}', + f'ip_address={ip_address}', ], 'fields': LIST_FIELDS_TO_RETRIEVE, } @@ -1519,9 +1519,9 @@ class TestListPort(compute_fakes.FakeClientMixin, TestPort): ip_address = self._ports[0].fixed_ips[0]['ip_address'] arglist = [ '--fixed-ip', - "subnet=%s" % subnet_id, + f"subnet={subnet_id}", '--fixed-ip', - "ip-address=%s" % ip_address, + f"ip-address={ip_address}", ] verifylist = [ ('fixed_ip', [{'subnet': subnet_id}, {'ip-address': ip_address}]) @@ -1542,8 +1542,8 @@ class TestListPort(compute_fakes.FakeClientMixin, TestPort): self.network_client.ports.assert_called_once_with( **{ 'fixed_ips': [ - 'subnet_id=%s' % subnet_id, - 'ip_address=%s' % ip_address, + f'subnet_id={subnet_id}', + f'ip_address={ip_address}', ], 'fields': LIST_FIELDS_TO_RETRIEVE, } @@ -2360,11 +2360,11 @@ class TestSetPort(TestPort): def _test_create_with_numa_affinity_policy(self, policy): arglist = [ - '--numa-policy-%s' % policy, + f'--numa-policy-{policy}', self._port.id, ] verifylist = [ - ('numa_policy_%s' % policy, True), + (f'numa_policy_{policy}', True), ( 'port', self._port.id, diff --git a/openstackclient/tests/unit/utils.py b/openstackclient/tests/unit/utils.py index b9f38f950e..2a39ca4831 100644 --- a/openstackclient/tests/unit/utils.py +++ b/openstackclient/tests/unit/utils.py @@ -62,7 +62,7 @@ class TestCase(testtools.TestCase): if m.called: if not msg: - msg = 'method %s should not have been called' % m + msg = f'method {m} should not have been called' self.fail(msg) @@ -90,7 +90,7 @@ class TestCommand(TestCase): argparse.ArgumentError, ): raise ParserException( - "Argument parse failed: %s" % stderr.getvalue() + f"Argument parse failed: {stderr.getvalue()}" ) for av in verify_args: attr, value = av diff --git a/pyproject.toml b/pyproject.toml index 6b13ff2461..9a30d5bc50 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,7 +6,7 @@ quote-style = "preserve" docstring-code-format = true [tool.ruff.lint] -select = ["E4", "E7", "E9", "F", "S"] +select = ["E4", "E7", "E9", "F", "S", "U"] [tool.ruff.lint.per-file-ignores] "openstackclient/tests/*" = ["S"]