From d60141525987bc973802b4ec9a3b027e071d1966 Mon Sep 17 00:00:00 2001 From: Sean McGinnis Date: Tue, 10 Apr 2018 14:32:33 -0500 Subject: [PATCH] Clean up W503 and E402 pep8 errors pycodestyle 2.40 and later enforce these rules that were not previously enforced. Rather than just skipping them, this cleans up the trivial instances of these violations. This does also include some other updates that were not triggering errors in an attempt to keep some of the style consistent. Change-Id: Id7c0a6b8f1f835e69d844b000e3ed751852ada63 Closes-bug: #1762803 --- openstackclient/__init__.py | 4 +- openstackclient/common/extension.py | 6 +- openstackclient/identity/v3/role.py | 8 +- openstackclient/image/v1/image.py | 10 +- openstackclient/network/v2/router.py | 4 +- .../functional/network/v2/test_network.py | 70 ++++---- .../network/v2/test_network_agent.py | 45 ++--- .../network/v2/test_network_flavor.py | 6 +- .../network/v2/test_network_qos_rule.py | 154 +++++++++--------- .../tests/functional/network/v2/test_port.py | 90 +++++----- .../tests/functional/object/v1/test_object.py | 32 ++-- .../functional/volume/v1/test_volume_type.py | 26 +-- .../functional/volume/v2/test_volume_type.py | 32 ++-- 13 files changed, 232 insertions(+), 255 deletions(-) diff --git a/openstackclient/__init__.py b/openstackclient/__init__.py index 89deee32ea..e6e7f7c031 100644 --- a/openstackclient/__init__.py +++ b/openstackclient/__init__.py @@ -11,10 +11,10 @@ # under the License. # -__all__ = ['__version__'] - import pbr.version +__all__ = ['__version__'] + version_info = pbr.version.VersionInfo('python-openstackclient') try: __version__ = version_info.version_string() diff --git a/openstackclient/common/extension.py b/openstackclient/common/extension.py index 139f43abf2..7120661880 100644 --- a/openstackclient/common/extension.py +++ b/openstackclient/common/extension.py @@ -75,8 +75,10 @@ class ListExtension(command.Lister): # by default we want to show everything, unless the # user specifies one or more of the APIs to show # for now, only identity and compute are supported. - show_all = (not parsed_args.identity and not parsed_args.compute - and not parsed_args.volume and not parsed_args.network) + show_all = (not parsed_args.identity and + not parsed_args.compute and + not parsed_args.volume and + not parsed_args.network) if parsed_args.identity or show_all: identity_client = self.app.client_manager.identity diff --git a/openstackclient/identity/v3/role.py b/openstackclient/identity/v3/role.py index 1bbf5f07b0..2828a34928 100644 --- a/openstackclient/identity/v3/role.py +++ b/openstackclient/identity/v3/role.py @@ -126,8 +126,8 @@ class AddRole(command.Command): def take_action(self, parsed_args): identity_client = self.app.client_manager.identity - if (not parsed_args.user and not parsed_args.domain - and not parsed_args.group and not parsed_args.project): + if (not parsed_args.user and not parsed_args.domain and + not parsed_args.group and not parsed_args.project): msg = _("Role not added, incorrect set of arguments " "provided. See openstack --help for more details") raise exceptions.CommandError(msg) @@ -399,8 +399,8 @@ class RemoveRole(command.Command): def take_action(self, parsed_args): identity_client = self.app.client_manager.identity - if (not parsed_args.user and not parsed_args.domain - and not parsed_args.group and not parsed_args.project): + if (not parsed_args.user and not parsed_args.domain and + not parsed_args.group and not parsed_args.project): msg = _("Incorrect set of arguments provided. " "See openstack --help for more details") raise exceptions.CommandError(msg) diff --git a/openstackclient/image/v1/image.py b/openstackclient/image/v1/image.py index 7a8e67bfca..7ecaa3efed 100644 --- a/openstackclient/image/v1/image.py +++ b/openstackclient/image/v1/image.py @@ -21,11 +21,6 @@ import logging import os import sys -if os.name == "nt": - import msvcrt -else: - msvcrt = None - from glanceclient.common import utils as gc_utils from osc_lib.cli import parseractions from osc_lib.command import command @@ -35,6 +30,11 @@ import six from openstackclient.api import utils as api_utils from openstackclient.i18n import _ +if os.name == "nt": + import msvcrt +else: + msvcrt = None + CONTAINER_CHOICES = ["ami", "ari", "aki", "bare", "docker", "ova", "ovf"] DEFAULT_CONTAINER_FORMAT = 'bare' diff --git a/openstackclient/network/v2/router.py b/openstackclient/network/v2/router.py index caf3236ab5..f0a5196744 100644 --- a/openstackclient/network/v2/router.py +++ b/openstackclient/network/v2/router.py @@ -86,8 +86,8 @@ def _get_attrs(client_manager, parsed_args): attrs['distributed'] = False if parsed_args.distributed: attrs['distributed'] = True - if ('availability_zone_hints' in parsed_args - and parsed_args.availability_zone_hints is not None): + if ('availability_zone_hints' in parsed_args and + parsed_args.availability_zone_hints is not None): attrs['availability_zone_hints'] = parsed_args.availability_zone_hints if parsed_args.description is not None: attrs['description'] = parsed_args.description diff --git a/openstackclient/tests/functional/network/v2/test_network.py b/openstackclient/tests/functional/network/v2/test_network.py index 40fb382a9e..9cef135fe7 100644 --- a/openstackclient/tests/functional/network/v2/test_network.py +++ b/openstackclient/tests/functional/network/v2/test_network.py @@ -209,7 +209,7 @@ class NetworkTests(common.NetworkTagTests): cmd_output["description"], ) - del_output = self.openstack('network delete ' + name1 + ' ' + name2) + del_output = self.openstack('network delete %s %s' % (name1, name2)) self.assertOutput('', del_output) def test_network_list(self): @@ -224,7 +224,7 @@ class NetworkTests(common.NetworkTagTests): network_options + name1 )) - self.addCleanup(self.openstack, 'network delete ' + name1) + self.addCleanup(self.openstack, 'network delete %s' % name1) self.assertIsNotNone(cmd_output["id"]) if self.haz_network: self.assertEqual( @@ -264,10 +264,8 @@ class NetworkTests(common.NetworkTagTests): else: network_options = '--subnet 4.5.6.7/28 ' cmd_output = json.loads(self.openstack( - 'network create -f json ' + - '--share ' + - network_options + - name2 + 'network create -f json --share %s%s' % + (network_options, name2) )) self.addCleanup(self.openstack, 'network delete ' + name2) self.assertIsNotNone(cmd_output["id"]) @@ -313,8 +311,7 @@ class NetworkTests(common.NetworkTagTests): # Test list --long if self.haz_network: cmd_output = json.loads(self.openstack( - "network list -f json " + - "--long" + "network list -f json --long" )) col_name = [x["Name"] for x in cmd_output] self.assertIn(name1, col_name) @@ -323,9 +320,7 @@ class NetworkTests(common.NetworkTagTests): # Test list --long --enable if self.haz_network: cmd_output = json.loads(self.openstack( - "network list -f json " + - "--enable " + - "--long" + "network list -f json --enable --long" )) col_name = [x["Name"] for x in cmd_output] self.assertIn(name1, col_name) @@ -334,9 +329,7 @@ class NetworkTests(common.NetworkTagTests): # Test list --long --disable if self.haz_network: cmd_output = json.loads(self.openstack( - "network list -f json " + - "--disable " + - "--long" + "network list -f json --disable --long" )) col_name = [x["Name"] for x in cmd_output] self.assertNotIn(name1, col_name) @@ -345,8 +338,7 @@ class NetworkTests(common.NetworkTagTests): # Test list --share if self.haz_network: cmd_output = json.loads(self.openstack( - "network list -f json " + - "--share " + "network list -f json --share " )) col_name = [x["Name"] for x in cmd_output] self.assertNotIn(name1, col_name) @@ -355,8 +347,7 @@ class NetworkTests(common.NetworkTagTests): # Test list --no-share if self.haz_network: cmd_output = json.loads(self.openstack( - "network list -f json " + - "--no-share " + "network list -f json --no-share " )) col_name = [x["Name"] for x in cmd_output] self.assertIn(name1, col_name) @@ -368,12 +359,10 @@ class NetworkTests(common.NetworkTagTests): name1 = uuid.uuid4().hex cmd_output1 = json.loads(self.openstack( - 'network create -f json ' + - '--description aaaa ' + - name1 + 'network create -f json --description aaaa %s' % name1 )) - self.addCleanup(self.openstack, 'network delete ' + name1) + self.addCleanup(self.openstack, 'network delete %s' % name1) # Get network ID network_id = cmd_output1['id'] @@ -386,20 +375,19 @@ class NetworkTests(common.NetworkTagTests): # Add Agent to Network self.openstack( - 'network agent add network --dhcp ' - + agent_id + ' ' + network_id + 'network agent add network --dhcp %s %s' % (agent_id, network_id) ) # Test network list --agent cmd_output3 = json.loads(self.openstack( - 'network list -f json --agent ' + agent_id + 'network list -f json --agent %s' % agent_id )) # Cleanup # Remove Agent from Network self.openstack( - 'network agent remove network --dhcp ' - + agent_id + ' ' + network_id + 'network agent remove network --dhcp %s %s' % + (agent_id, network_id) ) # Assert @@ -415,16 +403,16 @@ class NetworkTests(common.NetworkTagTests): name = uuid.uuid4().hex cmd_output = json.loads(self.openstack( - 'network create -f json ' + - '--description aaaa ' + - '--enable ' + - '--no-share ' + - '--internal ' + - '--no-default ' + - '--enable-port-security ' + + 'network create -f json ' + '--description aaaa ' + '--enable ' + '--no-share ' + '--internal ' + '--no-default ' + '--enable-port-security %s' % name )) - self.addCleanup(self.openstack, 'network delete ' + name) + self.addCleanup(self.openstack, 'network delete %s' % name) self.assertIsNotNone(cmd_output["id"]) self.assertEqual( 'aaaa', @@ -453,12 +441,12 @@ class NetworkTests(common.NetworkTagTests): ) raw_output = self.openstack( - 'network set ' + - '--description cccc ' + - '--disable ' + - '--share ' + - '--external ' + - '--disable-port-security ' + + 'network set ' + '--description cccc ' + '--disable ' + '--share ' + '--external ' + '--disable-port-security %s' % 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 0c74ea1d05..86769e0c8d 100644 --- a/openstackclient/tests/functional/network/v2/test_network_agent.py +++ b/openstackclient/tests/functional/network/v2/test_network_agent.py @@ -42,8 +42,7 @@ class NetworkAgentTests(common.NetworkTests): # agent show cmd_output = json.loads(self.openstack( - 'network agent show -f json ' + - agent_ids[0] + 'network agent show -f json %s' % agent_ids[0] )) self.assertEqual( agent_ids[0], @@ -52,15 +51,12 @@ class NetworkAgentTests(common.NetworkTests): # agent set raw_output = self.openstack( - 'network agent set ' + - '--disable ' + - agent_ids[0] + 'network agent set --disable %s' % agent_ids[0] ) self.assertOutput('', raw_output) cmd_output = json.loads(self.openstack( - 'network agent show -f json ' + - agent_ids[0] + 'network agent show -f json %s' % agent_ids[0] )) self.assertEqual( "DOWN", @@ -68,15 +64,12 @@ class NetworkAgentTests(common.NetworkTests): ) raw_output = self.openstack( - 'network agent set ' + - '--enable ' + - agent_ids[0] + 'network agent set --enable %s' % agent_ids[0] ) self.assertOutput('', raw_output) cmd_output = json.loads(self.openstack( - 'network agent show -f json ' + - agent_ids[0] + 'network agent show -f json %s' % agent_ids[0] )) self.assertEqual( "UP", @@ -98,12 +91,10 @@ class NetworkAgentListTests(common.NetworkTests): name1 = uuid.uuid4().hex cmd_output1 = json.loads(self.openstack( - 'network create -f json ' + - '--description aaaa ' + - name1 + 'network create -f json --description aaaa %s' % name1 )) - self.addCleanup(self.openstack, 'network delete ' + name1) + self.addCleanup(self.openstack, 'network delete %s' % name1) # Get network ID network_id = cmd_output1['id'] @@ -116,20 +107,20 @@ class NetworkAgentListTests(common.NetworkTests): # Add Agent to Network self.openstack( - 'network agent add network --dhcp ' - + agent_id + ' ' + network_id + 'network agent add network --dhcp %s %s' % + (agent_id, network_id) ) # Test network agent list --network cmd_output3 = json.loads(self.openstack( - 'network agent list -f json --network ' + network_id + 'network agent list -f json --network %s' % network_id )) # Cleanup # Remove Agent from Network self.openstack( - 'network agent remove network --dhcp ' - + agent_id + ' ' + network_id + 'network agent remove network --dhcp %s %s' % + (agent_id, network_id) ) # Assert @@ -142,9 +133,9 @@ class NetworkAgentListTests(common.NetworkTests): """Add agent to router, list agents on router, delete.""" name = uuid.uuid4().hex cmd_output = json.loads(self.openstack( - 'router create -f json ' + name)) + 'router create -f json %s' % name)) - self.addCleanup(self.openstack, 'router delete ' + name) + self.addCleanup(self.openstack, 'router delete %s' % name) # Get router ID router_id = cmd_output['id'] # Get l3 agent id @@ -157,19 +148,19 @@ class NetworkAgentListTests(common.NetworkTests): # Add router to agent self.openstack( - 'network agent add router --l3 ' + agent_id + ' ' + router_id) + 'network agent add router --l3 %s %s' % (agent_id, router_id)) # Test router list --agent cmd_output = json.loads(self.openstack( - 'network agent list -f json --router ' + router_id)) + 'network agent list -f json --router %s' % router_id)) agent_ids = [x['ID'] for x in cmd_output] self.assertIn(agent_id, agent_ids) # Remove router from agent self.openstack( - 'network agent remove router --l3 ' + agent_id + ' ' + router_id) + 'network agent remove router --l3 %s %s' % (agent_id, router_id)) cmd_output = json.loads(self.openstack( - 'network agent list -f json --router ' + router_id)) + 'network agent list -f json --router %s' % router_id)) agent_ids = [x['ID'] for x in cmd_output] self.assertNotIn(agent_id, agent_ids) diff --git a/openstackclient/tests/functional/network/v2/test_network_flavor.py b/openstackclient/tests/functional/network/v2/test_network_flavor.py index 47e7b44057..ba3de2cdb5 100644 --- a/openstackclient/tests/functional/network/v2/test_network_flavor.py +++ b/openstackclient/tests/functional/network/v2/test_network_flavor.py @@ -39,13 +39,13 @@ class NetworkFlavorTests(common.NetworkTests): # Create Service Flavor cmd_output2 = json.loads(self.openstack( 'network flavor profile create -f json --description ' - + 'fakedescription' + ' --enable --metainfo ' + 'Extrainfo' + 'fakedescription --enable --metainfo Extrainfo' )) service_profile_id = cmd_output2.get('id') - self.addCleanup(self.openstack, 'network flavor delete ' + + self.addCleanup(self.openstack, 'network flavor delete %s' % flavor_id) - self.addCleanup(self.openstack, 'network flavor profile delete ' + + self.addCleanup(self.openstack, 'network flavor profile delete %s' % service_profile_id) # Add flavor to service profile 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 770abe94fc..5d235405c5 100644 --- a/openstackclient/tests/functional/network/v2/test_network_qos_rule.py +++ b/openstackclient/tests/functional/network/v2/test_network_qos_rule.py @@ -28,62 +28,60 @@ class NetworkQosRuleTestsMinimumBandwidth(common.NetworkTests): if not self.haz_network: self.skipTest("No Network service present") - self.QOS_POLICY_NAME = 'qos_policy_' + uuid.uuid4().hex + self.QOS_POLICY_NAME = 'qos_policy_%s' % uuid.uuid4().hex self.openstack( - 'network qos policy create ' + - self.QOS_POLICY_NAME + 'network qos policy create %s' % self.QOS_POLICY_NAME ) self.addCleanup(self.openstack, - 'network qos policy delete ' + self.QOS_POLICY_NAME) + 'network qos policy delete %s' % self.QOS_POLICY_NAME) cmd_output = json.loads(self.openstack( - 'network qos rule create -f json ' + - '--type minimum-bandwidth ' + - '--min-kbps 2800 ' + - '--egress ' + + 'network qos rule create -f json ' + '--type minimum-bandwidth ' + '--min-kbps 2800 ' + '--egress %s' % self.QOS_POLICY_NAME )) self.RULE_ID = cmd_output['id'] self.addCleanup(self.openstack, - 'network qos rule delete ' + - self.QOS_POLICY_NAME + ' ' + - self.RULE_ID) + 'network qos rule delete %s %s' % + (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 -f json ' + policy_name) + self.openstack('network qos policy create -f json %s' % policy_name) self.addCleanup(self.openstack, - 'network qos policy delete ' + policy_name) + 'network qos policy delete %s' % policy_name) rule = json.loads(self.openstack( - 'network qos rule create -f json ' + - '--type minimum-bandwidth ' + - '--min-kbps 2800 ' + - '--egress ' + policy_name + 'network qos rule create -f json ' + '--type minimum-bandwidth ' + '--min-kbps 2800 ' + '--egress %s' % policy_name )) raw_output = self.openstack( - 'network qos rule delete ' + - policy_name + ' ' + rule['id']) + 'network qos rule delete %s %s' % + (policy_name, rule['id'])) self.assertEqual('', raw_output) def test_qos_rule_list(self): cmd_output = json.loads(self.openstack( - 'network qos rule list -f json ' + self.QOS_POLICY_NAME)) + 'network qos rule list -f json %s' % self.QOS_POLICY_NAME)) self.assertIn(self.RULE_ID, [rule['ID'] for rule in cmd_output]) def test_qos_rule_show(self): cmd_output = json.loads(self.openstack( - 'network qos rule show -f json ' + - self.QOS_POLICY_NAME + ' ' + self.RULE_ID)) + 'network qos rule show -f json %s %s' % + (self.QOS_POLICY_NAME, self.RULE_ID))) self.assertEqual(self.RULE_ID, cmd_output['id']) def test_qos_rule_set(self): - self.openstack('network qos rule set --min-kbps 7500 ' + - self.QOS_POLICY_NAME + ' ' + self.RULE_ID) + self.openstack('network qos rule set --min-kbps 7500 %s %s' % + (self.QOS_POLICY_NAME, self.RULE_ID)) cmd_output = json.loads(self.openstack( - 'network qos rule show -f json ' + - self.QOS_POLICY_NAME + ' ' + self.RULE_ID)) + 'network qos rule show -f json %s %s' % + (self.QOS_POLICY_NAME, self.RULE_ID))) self.assertEqual(7500, cmd_output['min_kbps']) @@ -96,58 +94,57 @@ class NetworkQosRuleTestsDSCPMarking(common.NetworkTests): if not self.haz_network: self.skipTest("No Network service present") - self.QOS_POLICY_NAME = 'qos_policy_' + uuid.uuid4().hex + self.QOS_POLICY_NAME = 'qos_policy_%s' % uuid.uuid4().hex self.openstack( - 'network qos policy create ' + - self.QOS_POLICY_NAME + 'network qos policy create %s' % self.QOS_POLICY_NAME ) self.addCleanup(self.openstack, - 'network qos policy delete ' + self.QOS_POLICY_NAME) + 'network qos policy delete %s' % self.QOS_POLICY_NAME) cmd_output = json.loads(self.openstack( - 'network qos rule create -f json ' + - '--type dscp-marking ' + - '--dscp-mark 8 ' + + 'network qos rule create -f json ' + '--type dscp-marking ' + '--dscp-mark 8 %s' % self.QOS_POLICY_NAME )) self.RULE_ID = cmd_output['id'] self.addCleanup(self.openstack, - 'network qos rule delete ' + - self.QOS_POLICY_NAME + ' ' + self.RULE_ID) + 'network qos rule delete %s %s' % + (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 -f json ' + policy_name) + self.openstack('network qos policy create -f json %s' % policy_name) self.addCleanup(self.openstack, - 'network qos policy delete ' + policy_name) + 'network qos policy delete %s' % policy_name) rule = json.loads(self.openstack( - 'network qos rule create -f json ' + - '--type dscp-marking ' + - '--dscp-mark 8 ' + policy_name + 'network qos rule create -f json ' + '--type dscp-marking ' + '--dscp-mark 8 %s' % policy_name )) raw_output = self.openstack( - 'network qos rule delete ' + - policy_name + ' ' + rule['id']) + 'network qos rule delete %s %s' % + (policy_name, rule['id'])) self.assertEqual('', raw_output) def test_qos_rule_list(self): cmd_output = json.loads(self.openstack( - 'network qos rule list -f json ' + self.QOS_POLICY_NAME)) + 'network qos rule list -f json %s' % self.QOS_POLICY_NAME)) self.assertIn(self.RULE_ID, [rule['ID'] for rule in cmd_output]) def test_qos_rule_show(self): cmd_output = json.loads(self.openstack( - 'network qos rule show -f json ' + - self.QOS_POLICY_NAME + ' ' + self.RULE_ID)) + 'network qos rule show -f json %s %s' % + (self.QOS_POLICY_NAME, self.RULE_ID))) self.assertEqual(self.RULE_ID, cmd_output['id']) def test_qos_rule_set(self): - self.openstack('network qos rule set --dscp-mark 32 ' + - self.QOS_POLICY_NAME + ' ' + self.RULE_ID) + self.openstack('network qos rule set --dscp-mark 32 %s %s' % + (self.QOS_POLICY_NAME, self.RULE_ID)) cmd_output = json.loads(self.openstack( - 'network qos rule show -f json ' + - self.QOS_POLICY_NAME + ' ' + self.RULE_ID)) + 'network qos rule show -f json %s %s' % + (self.QOS_POLICY_NAME, self.RULE_ID))) self.assertEqual(32, cmd_output['dscp_mark']) @@ -160,65 +157,64 @@ class NetworkQosRuleTestsBandwidthLimit(common.NetworkTests): if not self.haz_network: self.skipTest("No Network service present") - self.QOS_POLICY_NAME = 'qos_policy_' + uuid.uuid4().hex + self.QOS_POLICY_NAME = 'qos_policy_%s' % uuid.uuid4().hex self.openstack( - 'network qos policy create ' + - self.QOS_POLICY_NAME + 'network qos policy create %s' % self.QOS_POLICY_NAME ) self.addCleanup(self.openstack, - 'network qos policy delete ' + self.QOS_POLICY_NAME) + 'network qos policy delete %s' % self.QOS_POLICY_NAME) cmd_output = json.loads(self.openstack( - 'network qos rule create -f json ' + - '--type bandwidth-limit ' + - '--max-kbps 10000 ' + - '--max-burst-kbits 1400 ' + - '--egress ' + + 'network qos rule create -f json ' + '--type bandwidth-limit ' + '--max-kbps 10000 ' + '--max-burst-kbits 1400 ' + '--egress %s' % self.QOS_POLICY_NAME )) self.RULE_ID = cmd_output['id'] self.addCleanup(self.openstack, - 'network qos rule delete ' + - self.QOS_POLICY_NAME + ' ' + self.RULE_ID) + 'network qos rule delete %s %s' % + (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 -f json ' + policy_name) + self.openstack('network qos policy create -f json %s' % policy_name) self.addCleanup(self.openstack, - 'network qos policy delete ' + policy_name) + 'network qos policy delete %s' % policy_name) rule = json.loads(self.openstack( - 'network qos rule create -f json ' + - '--type bandwidth-limit ' + - '--max-kbps 10000 ' + - '--max-burst-kbits 1400 ' + - '--egress ' + policy_name + 'network qos rule create -f json ' + '--type bandwidth-limit ' + '--max-kbps 10000 ' + '--max-burst-kbits 1400 ' + '--egress %s' % policy_name )) raw_output = self.openstack( - 'network qos rule delete ' + - policy_name + ' ' + rule['id']) + 'network qos rule delete %s %s' % + (policy_name, rule['id'])) self.assertEqual('', raw_output) def test_qos_rule_list(self): cmd_output = json.loads(self.openstack( - 'network qos rule list -f json ' - + self.QOS_POLICY_NAME)) + 'network qos rule list -f json %s' % + self.QOS_POLICY_NAME)) self.assertIn(self.RULE_ID, [rule['ID'] for rule in cmd_output]) def test_qos_rule_show(self): cmd_output = json.loads(self.openstack( - 'network qos rule show -f json ' + - self.QOS_POLICY_NAME + ' ' + self.RULE_ID)) + 'network qos rule show -f json %s %s' % + (self.QOS_POLICY_NAME, self.RULE_ID))) self.assertEqual(self.RULE_ID, cmd_output['id']) def test_qos_rule_set(self): - self.openstack('network qos rule set --max-kbps 15000 ' + - '--max-burst-kbits 1800 ' + - '--ingress ' + - self.QOS_POLICY_NAME + ' ' + self.RULE_ID) + self.openstack('network qos rule set --max-kbps 15000 ' + '--max-burst-kbits 1800 ' + '--ingress %s %s' % + (self.QOS_POLICY_NAME, self.RULE_ID)) cmd_output = json.loads(self.openstack( - 'network qos rule show -f json ' + - self.QOS_POLICY_NAME + ' ' + self.RULE_ID)) + 'network qos rule show -f json %s %s' % + (self.QOS_POLICY_NAME, self.RULE_ID))) self.assertEqual(15000, cmd_output['max_kbps']) self.assertEqual(1800, cmd_output['max_burst_kbps']) self.assertEqual('ingress', cmd_output['direction']) diff --git a/openstackclient/tests/functional/network/v2/test_port.py b/openstackclient/tests/functional/network/v2/test_port.py index 7357c0ed54..e3067d90a3 100644 --- a/openstackclient/tests/functional/network/v2/test_port.py +++ b/openstackclient/tests/functional/network/v2/test_port.py @@ -33,7 +33,7 @@ class PortTests(common.NetworkTagTests): # Create a network for the port tests cls.openstack( - 'network create ' + cls.NETWORK_NAME + 'network create %s' % cls.NETWORK_NAME ) @classmethod @@ -41,7 +41,7 @@ class PortTests(common.NetworkTagTests): try: if cls.haz_network: raw_output = cls.openstack( - 'network delete ' + cls.NETWORK_NAME + 'network delete %s' % cls.NETWORK_NAME ) cls.assertOutput('', raw_output) finally: @@ -56,8 +56,8 @@ class PortTests(common.NetworkTagTests): def test_port_delete(self): """Test create, delete multiple""" json_output = json.loads(self.openstack( - 'port create -f json --network ' + - self.NETWORK_NAME + ' ' + self.NAME + 'port create -f json --network %s %s' % + (self.NETWORK_NAME, self.NAME) )) id1 = json_output.get('id') self.assertIsNotNone(id1) @@ -65,8 +65,8 @@ class PortTests(common.NetworkTagTests): self.assertEqual(self.NAME, json_output.get('name')) json_output = json.loads(self.openstack( - 'port create -f json --network ' + self.NETWORK_NAME + ' ' + - self.NAME + 'x' + 'port create -f json --network %s %sx' % + (self.NETWORK_NAME, self.NAME) )) id2 = json_output.get('id') self.assertIsNotNone(id2) @@ -74,31 +74,31 @@ class PortTests(common.NetworkTagTests): self.assertEqual(self.NAME + 'x', json_output.get('name')) # Clean up after ourselves - raw_output = self.openstack('port delete ' + id1 + ' ' + id2) + raw_output = self.openstack('port delete %s %s' % (id1, id2)) self.assertOutput('', raw_output) def test_port_list(self): """Test create defaults, list, delete""" json_output = json.loads(self.openstack( - 'port create -f json --network ' + self.NETWORK_NAME + ' ' + - self.NAME + 'port create -f json --network %s %s' % + (self.NETWORK_NAME, self.NAME) )) id1 = json_output.get('id') self.assertIsNotNone(id1) mac1 = json_output.get('mac_address') self.assertIsNotNone(mac1) - self.addCleanup(self.openstack, 'port delete ' + id1) + self.addCleanup(self.openstack, 'port delete %s' % id1) self.assertEqual(self.NAME, json_output.get('name')) json_output = json.loads(self.openstack( - 'port create -f json --network ' + self.NETWORK_NAME + ' ' + - self.NAME + 'x' + 'port create -f json --network %s %sx' % + (self.NETWORK_NAME, self.NAME) )) id2 = json_output.get('id') self.assertIsNotNone(id2) mac2 = json_output.get('mac_address') self.assertIsNotNone(mac2) - self.addCleanup(self.openstack, 'port delete ' + id2) + self.addCleanup(self.openstack, 'port delete %s' % id2) self.assertEqual(self.NAME + 'x', json_output.get('name')) # Test list @@ -122,7 +122,7 @@ class PortTests(common.NetworkTagTests): # Test list --mac-address json_output = json.loads(self.openstack( - 'port list -f json --mac-address ' + mac2 + 'port list -f json --mac-address %s' % mac2 )) item_map = {item.get('ID'): item.get('MAC Address') for item in json_output} @@ -145,26 +145,26 @@ class PortTests(common.NetworkTagTests): """Test create, set, show, delete""" name = uuid.uuid4().hex json_output = json.loads(self.openstack( - 'port create -f json ' + - '--network ' + self.NETWORK_NAME + ' ' + - '--description xyzpdq ' + - '--disable ' + - name + 'port create -f json ' + '--network %s ' + '--description xyzpdq ' + '--disable %s' % + (self.NETWORK_NAME, name) )) id1 = json_output.get('id') - self.addCleanup(self.openstack, 'port delete ' + id1) + self.addCleanup(self.openstack, 'port delete %s' % id1) self.assertEqual(name, json_output.get('name')) self.assertEqual('xyzpdq', json_output.get('description')) self.assertEqual('DOWN', json_output.get('admin_state_up')) raw_output = self.openstack( - 'port set ' + '--enable ' + + 'port set --enable %s' % name ) self.assertOutput('', raw_output) json_output = json.loads(self.openstack( - 'port show -f json ' + name + 'port show -f json %s' % name )) sg_id = json_output.get('security_group_ids') @@ -174,30 +174,30 @@ class PortTests(common.NetworkTagTests): self.assertIsNotNone(json_output.get('mac_address')) raw_output = self.openstack( - 'port unset --security-group ' + sg_id + ' ' + id1) + 'port unset --security-group %s %s' % (sg_id, id1)) self.assertOutput('', raw_output) json_output = json.loads(self.openstack( - 'port show -f json ' + name + 'port show -f json %s' % name )) self.assertEqual('', json_output.get('security_group_ids')) def test_port_admin_set(self): """Test create, set (as admin), show, delete""" json_output = json.loads(self.openstack( - 'port create -f json ' + - '--network ' + self.NETWORK_NAME + ' ' + self.NAME + 'port create -f json ' + '--network %s %s' % (self.NETWORK_NAME, self.NAME) )) id_ = json_output.get('id') - self.addCleanup(self.openstack, 'port delete ' + id_) + self.addCleanup(self.openstack, 'port delete %s' % id_) raw_output = self.openstack( '--os-username admin ' - + 'port set --mac-address 11:22:33:44:55:66 ' - + self.NAME) + 'port set --mac-address 11:22:33:44:55:66 %s' % + self.NAME) self.assertOutput('', raw_output) json_output = json.loads(self.openstack( - 'port show -f json ' + self.NAME + 'port show -f json %s' % self.NAME )) self.assertEqual(json_output.get('mac_address'), '11:22:33:44:55:66') @@ -205,41 +205,41 @@ class PortTests(common.NetworkTagTests): """Test create, set, show, delete""" sg_name1 = uuid.uuid4().hex json_output = json.loads(self.openstack( - 'security group create -f json ' + + 'security group create -f json %s' % sg_name1 )) sg_id1 = json_output.get('id') - self.addCleanup(self.openstack, 'security group delete ' + sg_id1) + self.addCleanup(self.openstack, 'security group delete %s' % sg_id1) sg_name2 = uuid.uuid4().hex json_output = json.loads(self.openstack( - 'security group create -f json ' + + 'security group create -f json %s' % sg_name2 )) sg_id2 = json_output.get('id') - self.addCleanup(self.openstack, 'security group delete ' + sg_id2) + self.addCleanup(self.openstack, 'security group delete %s' % sg_id2) name = uuid.uuid4().hex json_output = json.loads(self.openstack( - 'port create -f json ' + - '--network ' + self.NETWORK_NAME + ' ' + - '--security-group ' + sg_name1 + ' ' + - name + 'port create -f json ' + '--network %s ' + '--security-group %s %s' % + (self.NETWORK_NAME, sg_name1, name) )) id1 = json_output.get('id') - self.addCleanup(self.openstack, 'port delete ' + id1) + self.addCleanup(self.openstack, 'port delete %s' % 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 ' + sg_name2 + ' ' + - name + 'port set ' + '--security-group %s %s' % + (sg_name2, name) ) self.assertOutput('', raw_output) json_output = json.loads(self.openstack( - 'port show -f json ' + name + 'port show -f json %s' % name )) self.assertEqual(name, json_output.get('name')) self.assertIn( @@ -254,11 +254,11 @@ class PortTests(common.NetworkTagTests): ) raw_output = self.openstack( - 'port unset --security-group ' + sg_id1 + ' ' + id1) + 'port unset --security-group %s %s' % (sg_id1, id1)) self.assertOutput('', raw_output) json_output = json.loads(self.openstack( - 'port show -f json ' + name + 'port show -f json %s' % name )) self.assertEqual( # TODO(dtroyer): output formatters should do this on JSON! diff --git a/openstackclient/tests/functional/object/v1/test_object.py b/openstackclient/tests/functional/object/v1/test_object.py index d1a73c54db..226ef8adbd 100644 --- a/openstackclient/tests/functional/object/v1/test_object.py +++ b/openstackclient/tests/functional/object/v1/test_object.py @@ -53,39 +53,39 @@ class ObjectTests(common.ObjectStoreTests): self.openstack('container save ' + self.CONTAINER_NAME) # TODO(stevemar): Assert returned fields - raw_output = self.openstack('object create ' + self.CONTAINER_NAME - + ' ' + object_file) + raw_output = self.openstack('object create %s %s' % + (self.CONTAINER_NAME, object_file)) items = self.parse_listing(raw_output) self.assert_show_fields(items, OBJECT_FIELDS) - raw_output = self.openstack('object list ' + self.CONTAINER_NAME) + raw_output = self.openstack('object list %s' % self.CONTAINER_NAME) items = self.parse_listing(raw_output) self.assert_table_structure(items, BASIC_LIST_HEADERS) - self.openstack('object save ' + self.CONTAINER_NAME - + ' ' + object_file) + self.openstack('object save %s %s' % + (self.CONTAINER_NAME, object_file)) # TODO(stevemar): Assert returned fields tmp_file = 'tmp.txt' self.addCleanup(os.remove, tmp_file) - self.openstack('object save ' + self.CONTAINER_NAME - + ' ' + object_file + ' --file ' + tmp_file) + self.openstack('object save %s %s --file %s' % + (self.CONTAINER_NAME, object_file, tmp_file)) # TODO(stevemar): Assert returned fields - raw_output = self.openstack('object save ' + self.CONTAINER_NAME - + ' ' + object_file + ' --file -') + raw_output = self.openstack('object save %s %s --file -' % + (self.CONTAINER_NAME, object_file)) self.assertEqual(raw_output, 'test content') - self.openstack('object show ' + self.CONTAINER_NAME - + ' ' + object_file) + self.openstack('object show %s %s' % + (self.CONTAINER_NAME, object_file)) # TODO(stevemar): Assert returned fields - raw_output = self.openstack('object delete ' + self.CONTAINER_NAME - + ' ' + object_file) + raw_output = self.openstack('object delete %s %s' % + (self.CONTAINER_NAME, object_file)) self.assertEqual(0, len(raw_output)) - self.openstack('object create ' + self.CONTAINER_NAME - + ' ' + object_file) - raw_output = self.openstack('container delete -r ' + + self.openstack('object create %s %s' % + (self.CONTAINER_NAME, object_file)) + raw_output = self.openstack('container delete -r %s' % self.CONTAINER_NAME) self.assertEqual(0, len(raw_output)) diff --git a/openstackclient/tests/functional/volume/v1/test_volume_type.py b/openstackclient/tests/functional/volume/v1/test_volume_type.py index 74e1407003..c5886a696a 100644 --- a/openstackclient/tests/functional/volume/v1/test_volume_type.py +++ b/openstackclient/tests/functional/volume/v1/test_volume_type.py @@ -26,13 +26,13 @@ class VolumeTypeTests(common.BaseVolumeTests): def setUpClass(cls): super(VolumeTypeTests, cls).setUpClass() cmd_output = json.loads(cls.openstack( - 'volume type create -f json ' + cls.NAME)) + 'volume type create -f json %s' % cls.NAME)) cls.assertOutput(cls.NAME, cmd_output['name']) @classmethod def tearDownClass(cls): try: - raw_output = cls.openstack('volume type delete ' + cls.NAME) + raw_output = cls.openstack('volume type delete %s' % cls.NAME) cls.assertOutput('', raw_output) finally: super(VolumeTypeTests, cls).tearDownClass() @@ -43,47 +43,47 @@ class VolumeTypeTests(common.BaseVolumeTests): def test_volume_type_show(self): cmd_output = json.loads(self.openstack( - 'volume type show -f json ' + self.NAME)) + 'volume type show -f json %s' % self.NAME)) self.assertEqual(self.NAME, cmd_output['name']) def test_volume_type_set_unset_properties(self): raw_output = self.openstack( - 'volume type set --property a=b --property c=d ' + self.NAME) + 'volume type set --property a=b --property c=d %s' % self.NAME) self.assertEqual("", raw_output) cmd_output = json.loads(self.openstack( 'volume type show -f json ' + self.NAME)) self.assertEqual("a='b', c='d'", cmd_output['properties']) - raw_output = self.openstack('volume type unset --property a ' - + self.NAME) + raw_output = self.openstack('volume type unset --property a %s' % + self.NAME) self.assertEqual("", raw_output) cmd_output = json.loads(self.openstack( - 'volume type show -f json ' + self.NAME)) + 'volume type show -f json %s' % self.NAME)) self.assertEqual("c='d'", cmd_output['properties']) def test_volume_type_set_unset_multiple_properties(self): raw_output = self.openstack( - 'volume type set --property a=b --property c=d ' + self.NAME) + 'volume type set --property a=b --property c=d %s' % self.NAME) self.assertEqual("", raw_output) cmd_output = json.loads(self.openstack( - 'volume type show -f json ' + self.NAME)) + 'volume type show -f json %s' % self.NAME)) self.assertEqual("a='b', c='d'", cmd_output['properties']) raw_output = self.openstack( - 'volume type unset --property a --property c ' + self.NAME) + 'volume type unset --property a --property c %s' % self.NAME) self.assertEqual("", raw_output) cmd_output = json.loads(self.openstack( - 'volume type show -f json ' + self.NAME)) + 'volume type show -f json %s' % self.NAME)) self.assertEqual("", cmd_output['properties']) def test_multi_delete(self): vol_type1 = uuid.uuid4().hex vol_type2 = uuid.uuid4().hex - self.openstack('volume type create ' + vol_type1) + self.openstack('volume type create %s' % vol_type1) time.sleep(5) - self.openstack('volume type create ' + vol_type2) + self.openstack('volume type create %s' % vol_type2) time.sleep(5) cmd = 'volume type delete %s %s' % (vol_type1, vol_type2) raw_output = self.openstack(cmd) diff --git a/openstackclient/tests/functional/volume/v2/test_volume_type.py b/openstackclient/tests/functional/volume/v2/test_volume_type.py index 99630e6b04..5c551ca945 100644 --- a/openstackclient/tests/functional/volume/v2/test_volume_type.py +++ b/openstackclient/tests/functional/volume/v2/test_volume_type.py @@ -26,13 +26,13 @@ class VolumeTypeTests(common.BaseVolumeTests): def setUpClass(cls): super(VolumeTypeTests, cls).setUpClass() cmd_output = json.loads(cls.openstack( - 'volume type create -f json --private ' + cls.NAME)) + 'volume type create -f json --private %s' % cls.NAME)) cls.assertOutput(cls.NAME, cmd_output['name']) @classmethod def tearDownClass(cls): try: - raw_output = cls.openstack('volume type delete ' + cls.NAME) + raw_output = cls.openstack('volume type delete %s' % cls.NAME) cls.assertOutput('', raw_output) finally: super(VolumeTypeTests, cls).tearDownClass() @@ -49,55 +49,55 @@ class VolumeTypeTests(common.BaseVolumeTests): def test_volume_type_show(self): cmd_output = json.loads(self.openstack( - 'volume type show -f json ' + self.NAME)) + 'volume type show -f json %s' % self.NAME)) self.assertEqual(self.NAME, cmd_output['name']) def test_volume_type_set_unset_properties(self): raw_output = self.openstack( - 'volume type set --property a=b --property c=d ' + self.NAME) + 'volume type set --property a=b --property c=d %s' % self.NAME) self.assertEqual("", raw_output) cmd_output = json.loads(self.openstack( - 'volume type show -f json ' + self.NAME)) + 'volume type show -f json %s' % self.NAME)) # TODO(amotoki): properties output should be machine-readable self.assertEqual("a='b', c='d'", cmd_output['properties']) - raw_output = self.openstack('volume type unset --property a ' - + self.NAME) + raw_output = self.openstack('volume type unset --property a %s' % + self.NAME) self.assertEqual("", raw_output) cmd_output = json.loads(self.openstack( - 'volume type show -f json ' + self.NAME)) + 'volume type show -f json %s' % self.NAME)) self.assertEqual("c='d'", cmd_output['properties']) def test_volume_type_set_unset_multiple_properties(self): raw_output = self.openstack( - 'volume type set --property a=b --property c=d ' + self.NAME) + 'volume type set --property a=b --property c=d %s' % self.NAME) self.assertEqual("", raw_output) cmd_output = json.loads(self.openstack( - 'volume type show -f json ' + self.NAME)) + 'volume type show -f json %s' % self.NAME)) self.assertEqual("a='b', c='d'", cmd_output['properties']) raw_output = self.openstack( - 'volume type unset --property a --property c ' + self.NAME) + 'volume type unset --property a --property c %s' % self.NAME) self.assertEqual("", raw_output) cmd_output = json.loads(self.openstack( - 'volume type show -f json ' + self.NAME)) + 'volume type show -f json %s' % self.NAME)) self.assertEqual("", cmd_output['properties']) def test_volume_type_set_unset_project(self): raw_output = self.openstack( - 'volume type set --project admin ' + self.NAME) + 'volume type set --project admin %s' % self.NAME) self.assertEqual("", raw_output) raw_output = self.openstack( - 'volume type unset --project admin ' + self.NAME) + 'volume type unset --project admin %s' % self.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 ' + vol_type1) + self.openstack('volume type create %s' % vol_type1) time.sleep(5) - self.openstack('volume type create ' + vol_type2) + self.openstack('volume type create %s' % vol_type2) time.sleep(5) cmd = 'volume type delete %s %s' % (vol_type1, vol_type2) raw_output = self.openstack(cmd)