From b11e7ac5094a47c4b9e580cd126efa1c642a5404 Mon Sep 17 00:00:00 2001 From: Lachlan Plant Date: Wed, 31 Oct 2018 10:47:40 -0500 Subject: [PATCH] Fix pep8 and py27 tests in stx-distcloud-client Pep8 and py27 tests are now passing Both are voting in zuul on check and gate Story: 2003862 Task: 26692 Change-Id: Idf8bb3cbe139ac8fbf3755a25f9efd7c76e45d72 Signed-off-by: Lachlan Plant --- .zuul.yaml | 6 ++++-- .../commands/v1/subcloud_manager.py | 10 +++++----- .../commands/v1/sw_update_manager.py | 6 +++--- .../commands/v1/sw_update_options_manager.py | 4 ++-- dcmanagerclient/tests/test_httpclient.py | 4 ++-- dcmanagerclient/tests/test_shell.py | 8 ++++---- tox.ini | 19 +++++++++++++++---- 7 files changed, 35 insertions(+), 22 deletions(-) diff --git a/.zuul.yaml b/.zuul.yaml index c936b46..30b159c 100644 --- a/.zuul.yaml +++ b/.zuul.yaml @@ -6,12 +6,14 @@ jobs: - build-openstack-releasenotes - openstack-tox-linters - - openstack-tox-pep8: - voting: false + - openstack-tox-pep8 + - openstack-tox-py27 gate: jobs: - build-openstack-releasenotes - openstack-tox-linters + - openstack-tox-pep8 + - openstack-tox-py27 post: jobs: - publish-stx-tox diff --git a/dcmanagerclient/commands/v1/subcloud_manager.py b/dcmanagerclient/commands/v1/subcloud_manager.py index 6a20e75..befad2b 100644 --- a/dcmanagerclient/commands/v1/subcloud_manager.py +++ b/dcmanagerclient/commands/v1/subcloud_manager.py @@ -229,7 +229,7 @@ class DeleteSubcloud(command.Command): try: dcmanager_client.subcloud_manager.delete_subcloud(subcloud_ref) except Exception as e: - print (e) + print(e) error_msg = "Unable to delete subcloud %s" % (subcloud_ref) raise exceptions.DCManagerClientException(error_msg) @@ -258,7 +258,7 @@ class UnmanageSubcloud(base.DCManagerShowOne): return dcmanager_client.subcloud_manager.update_subcloud( subcloud_ref, **kwargs) except Exception as e: - print (e) + print(e) error_msg = "Unable to unmanage subcloud %s" % (subcloud_ref) raise exceptions.DCManagerClientException(error_msg) @@ -287,7 +287,7 @@ class ManageSubcloud(base.DCManagerShowOne): return dcmanager_client.subcloud_manager.update_subcloud( subcloud_ref, **kwargs) except Exception as e: - print (e) + print(e) error_msg = "Unable to manage subcloud %s" % (subcloud_ref) raise exceptions.DCManagerClientException(error_msg) @@ -336,7 +336,7 @@ class UpdateSubcloud(base.DCManagerShowOne): return dcmanager_client.subcloud_manager.update_subcloud( subcloud_ref, **kwargs) except Exception as e: - print (e) + print(e) error_msg = "Unable to update subcloud %s" % (subcloud_ref) raise exceptions.DCManagerClientException(error_msg) @@ -467,7 +467,7 @@ class GenerateConfigSubcloud(command.Command): return subcloud_config except Exception as e: - print (e) + print(e) error_msg = "Unable to generate config for subcloud %s" % \ (subcloud_ref) raise exceptions.DCManagerClientException(error_msg) diff --git a/dcmanagerclient/commands/v1/sw_update_manager.py b/dcmanagerclient/commands/v1/sw_update_manager.py index dc705a6..cec42f5 100644 --- a/dcmanagerclient/commands/v1/sw_update_manager.py +++ b/dcmanagerclient/commands/v1/sw_update_manager.py @@ -189,7 +189,7 @@ class DeletePatchStrategy(base.DCManagerShowOne): try: return dcmanager_client.sw_update_manager.delete_patch_strategy() except Exception as e: - print (e) + print(e) error_msg = "Unable to delete patch strategy" raise exceptions.DCManagerClientException(error_msg) @@ -209,7 +209,7 @@ class ApplyPatchStrategy(base.DCManagerShowOne): try: return dcmanager_client.sw_update_manager.apply_patch_strategy() except Exception as e: - print (e) + print(e) error_msg = "Unable to apply patch strategy" raise exceptions.DCManagerClientException(error_msg) @@ -229,7 +229,7 @@ class AbortPatchStrategy(base.DCManagerShowOne): try: return dcmanager_client.sw_update_manager.abort_patch_strategy() except Exception as e: - print (e) + print(e) error_msg = "Unable to abort patch strategy" raise exceptions.DCManagerClientException(error_msg) diff --git a/dcmanagerclient/commands/v1/sw_update_options_manager.py b/dcmanagerclient/commands/v1/sw_update_options_manager.py index a7a00ba..69988f1 100644 --- a/dcmanagerclient/commands/v1/sw_update_options_manager.py +++ b/dcmanagerclient/commands/v1/sw_update_options_manager.py @@ -151,7 +151,7 @@ class UpdateSwUpdateOptions(base.DCManagerShowOne): return dcmanager_client.sw_update_options_manager.\ sw_update_options_update(subcloud_ref, **kwargs) except Exception as e: - print (e) + print(e) error_msg = "Unable to update patch options for subcloud %s" % \ (subcloud_ref) raise exceptions.DCManagerClientException(error_msg) @@ -218,6 +218,6 @@ class DeleteSwUpdateOptions(command.Command): return dcmanager_client.sw_update_options_manager.\ sw_update_options_delete(subcloud_ref) except Exception as e: - print (e) + print(e) error_msg = "Unable to delete patch options" raise exceptions.DCManagerClientException(error_msg) diff --git a/dcmanagerclient/tests/test_httpclient.py b/dcmanagerclient/tests/test_httpclient.py index 66b40cb..2955eee 100644 --- a/dcmanagerclient/tests/test_httpclient.py +++ b/dcmanagerclient/tests/test_httpclient.py @@ -89,6 +89,7 @@ class HTTPClientTest(testtools.TestCase): mock.MagicMock(return_value=FakeResponse('get', EXPECTED_URL, 200)) ) def test_get_request_options(self): + osprofiler.profiler.clean() self.client.get(API_URL) requests.get.assert_called_with( @@ -130,16 +131,15 @@ class HTTPClientTest(testtools.TestCase): mock.MagicMock(return_value=FakeResponse('get', EXPECTED_URL, 200)) ) def test_get_request_options_with_profile_enabled(self): + osprofiler.profiler.clean() osprofiler.profiler.init(PROFILER_HMAC_KEY) data = {'base_id': PROFILER_TRACE_ID, 'parent_id': PROFILER_TRACE_ID} signed_data = osprofiler_utils.signed_pack(data, PROFILER_HMAC_KEY) - headers = { 'X-Trace-Info': signed_data[0], 'X-Trace-HMAC': signed_data[1] } - self.client.get(API_URL) expected_options = copy.deepcopy(EXPECTED_REQ_OPTIONS) diff --git a/dcmanagerclient/tests/test_shell.py b/dcmanagerclient/tests/test_shell.py index a9bf5eb..1cacb16 100644 --- a/dcmanagerclient/tests/test_shell.py +++ b/dcmanagerclient/tests/test_shell.py @@ -33,7 +33,7 @@ class TestShell(base.BaseShellTests): ) self.assertTrue(mock.called) dcmanager_version = mock.call_args - self.assertEqual('v1', dcmanager_version[0][0]) + self.assertEqual('v1.0', dcmanager_version[0][0]) @mock.patch('dcmanagerclient.api.client.determine_client_version') def test_default_dcmanager_version(self, mock): @@ -89,7 +89,7 @@ class TestShell(base.BaseShellTests): @mock.patch('dcmanagerclient.api.client.client') def test_kb_endpoint_type(self, mock): - self.shell('--os-dcmanager-endpoint-type=adminURL quota-defaults') + self.shell('--os-endpoint-type=adminURL quota-defaults') self.assertTrue(mock.called) params = mock.call_args self.assertEqual('adminURL', params[1]['endpoint_type']) @@ -123,11 +123,11 @@ class TestShell(base.BaseShellTests): @mock.patch('dcmanagerclient.api.client.client') def test_command_with_dcmanager_url(self, mock): self.shell( - '--os-dcmanager-url=http://localhost:8118/v1 quota-defaults' + '--dcmanager-url=http://localhost:8118/v1.0 quota-defaults' ) self.assertTrue(mock.called) params = mock.call_args - self.assertEqual('http://localhost:8118/v1', + self.assertEqual('http://localhost:8118/v1.0', params[1]['dcmanager_url']) @mock.patch('dcmanagerclient.api.client.client') diff --git a/tox.ini b/tox.ini index 17903c8..7b859c6 100644 --- a/tox.ini +++ b/tox.ini @@ -3,6 +3,9 @@ minversion = 2.3 envlist = py27,pep8 skipsdist = True +[dcclient] +client_base_dir = . + [testenv] basepython = python3 install_command = pip install -c{env:UPPER_CONSTRAINTS_FILE:https://git.openstack.org/cgit/openstack/requirements/plain/upper-constraints.txt} {opts} {packages} @@ -14,9 +17,17 @@ setenv = # DISCOVER_DIRECTORY=dcmanagerclient/tests deps = -r{toxinidir}/test-requirements.txt -#deps = -r{toxinidir}/requirements.txt -# -r{toxinidir}/test-requirements.txt -#commands = python setup.py testr --slowest --testr-args='{posargs}' + -r{toxinidir}/requirements.txt +whitelist_externals = + rm + find + reno + +[testenv:py27] +basepython = python2.7 +commands = + find {toxinidir} -not -path '{toxinidir}/.tox/*' -name '*.py[c|o]' -delete + stestr --test-path={[dcclient]client_base_dir}/dcmanagerclient/tests run '{posargs}' [testenv:pep8] commands = flake8 {posargs} @@ -33,7 +44,7 @@ commands = oslo_debug_helper {posargs} [flake8] # E123, E125 skipped as they are invalid PEP-8. show-source = True -ignore = E123,E125 +ignore = E123,E125,H102 builtins = _ exclude=.venv,.git,.tox,dist,doc,*lib/python*,*openstack/common*,*egg,build