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 <lachlan.plant@windriver.com>
This commit is contained in:
Lachlan Plant 2018-10-31 10:47:40 -05:00
parent 46d80c8059
commit b11e7ac509
7 changed files with 35 additions and 22 deletions

View File

@ -6,12 +6,14 @@
jobs: jobs:
- build-openstack-releasenotes - build-openstack-releasenotes
- openstack-tox-linters - openstack-tox-linters
- openstack-tox-pep8: - openstack-tox-pep8
voting: false - openstack-tox-py27
gate: gate:
jobs: jobs:
- build-openstack-releasenotes - build-openstack-releasenotes
- openstack-tox-linters - openstack-tox-linters
- openstack-tox-pep8
- openstack-tox-py27
post: post:
jobs: jobs:
- publish-stx-tox - publish-stx-tox

View File

@ -229,7 +229,7 @@ class DeleteSubcloud(command.Command):
try: try:
dcmanager_client.subcloud_manager.delete_subcloud(subcloud_ref) dcmanager_client.subcloud_manager.delete_subcloud(subcloud_ref)
except Exception as e: except Exception as e:
print (e) print(e)
error_msg = "Unable to delete subcloud %s" % (subcloud_ref) error_msg = "Unable to delete subcloud %s" % (subcloud_ref)
raise exceptions.DCManagerClientException(error_msg) raise exceptions.DCManagerClientException(error_msg)
@ -258,7 +258,7 @@ class UnmanageSubcloud(base.DCManagerShowOne):
return dcmanager_client.subcloud_manager.update_subcloud( return dcmanager_client.subcloud_manager.update_subcloud(
subcloud_ref, **kwargs) subcloud_ref, **kwargs)
except Exception as e: except Exception as e:
print (e) print(e)
error_msg = "Unable to unmanage subcloud %s" % (subcloud_ref) error_msg = "Unable to unmanage subcloud %s" % (subcloud_ref)
raise exceptions.DCManagerClientException(error_msg) raise exceptions.DCManagerClientException(error_msg)
@ -287,7 +287,7 @@ class ManageSubcloud(base.DCManagerShowOne):
return dcmanager_client.subcloud_manager.update_subcloud( return dcmanager_client.subcloud_manager.update_subcloud(
subcloud_ref, **kwargs) subcloud_ref, **kwargs)
except Exception as e: except Exception as e:
print (e) print(e)
error_msg = "Unable to manage subcloud %s" % (subcloud_ref) error_msg = "Unable to manage subcloud %s" % (subcloud_ref)
raise exceptions.DCManagerClientException(error_msg) raise exceptions.DCManagerClientException(error_msg)
@ -336,7 +336,7 @@ class UpdateSubcloud(base.DCManagerShowOne):
return dcmanager_client.subcloud_manager.update_subcloud( return dcmanager_client.subcloud_manager.update_subcloud(
subcloud_ref, **kwargs) subcloud_ref, **kwargs)
except Exception as e: except Exception as e:
print (e) print(e)
error_msg = "Unable to update subcloud %s" % (subcloud_ref) error_msg = "Unable to update subcloud %s" % (subcloud_ref)
raise exceptions.DCManagerClientException(error_msg) raise exceptions.DCManagerClientException(error_msg)
@ -467,7 +467,7 @@ class GenerateConfigSubcloud(command.Command):
return subcloud_config return subcloud_config
except Exception as e: except Exception as e:
print (e) print(e)
error_msg = "Unable to generate config for subcloud %s" % \ error_msg = "Unable to generate config for subcloud %s" % \
(subcloud_ref) (subcloud_ref)
raise exceptions.DCManagerClientException(error_msg) raise exceptions.DCManagerClientException(error_msg)

View File

@ -189,7 +189,7 @@ class DeletePatchStrategy(base.DCManagerShowOne):
try: try:
return dcmanager_client.sw_update_manager.delete_patch_strategy() return dcmanager_client.sw_update_manager.delete_patch_strategy()
except Exception as e: except Exception as e:
print (e) print(e)
error_msg = "Unable to delete patch strategy" error_msg = "Unable to delete patch strategy"
raise exceptions.DCManagerClientException(error_msg) raise exceptions.DCManagerClientException(error_msg)
@ -209,7 +209,7 @@ class ApplyPatchStrategy(base.DCManagerShowOne):
try: try:
return dcmanager_client.sw_update_manager.apply_patch_strategy() return dcmanager_client.sw_update_manager.apply_patch_strategy()
except Exception as e: except Exception as e:
print (e) print(e)
error_msg = "Unable to apply patch strategy" error_msg = "Unable to apply patch strategy"
raise exceptions.DCManagerClientException(error_msg) raise exceptions.DCManagerClientException(error_msg)
@ -229,7 +229,7 @@ class AbortPatchStrategy(base.DCManagerShowOne):
try: try:
return dcmanager_client.sw_update_manager.abort_patch_strategy() return dcmanager_client.sw_update_manager.abort_patch_strategy()
except Exception as e: except Exception as e:
print (e) print(e)
error_msg = "Unable to abort patch strategy" error_msg = "Unable to abort patch strategy"
raise exceptions.DCManagerClientException(error_msg) raise exceptions.DCManagerClientException(error_msg)

View File

@ -151,7 +151,7 @@ class UpdateSwUpdateOptions(base.DCManagerShowOne):
return dcmanager_client.sw_update_options_manager.\ return dcmanager_client.sw_update_options_manager.\
sw_update_options_update(subcloud_ref, **kwargs) sw_update_options_update(subcloud_ref, **kwargs)
except Exception as e: except Exception as e:
print (e) print(e)
error_msg = "Unable to update patch options for subcloud %s" % \ error_msg = "Unable to update patch options for subcloud %s" % \
(subcloud_ref) (subcloud_ref)
raise exceptions.DCManagerClientException(error_msg) raise exceptions.DCManagerClientException(error_msg)
@ -218,6 +218,6 @@ class DeleteSwUpdateOptions(command.Command):
return dcmanager_client.sw_update_options_manager.\ return dcmanager_client.sw_update_options_manager.\
sw_update_options_delete(subcloud_ref) sw_update_options_delete(subcloud_ref)
except Exception as e: except Exception as e:
print (e) print(e)
error_msg = "Unable to delete patch options" error_msg = "Unable to delete patch options"
raise exceptions.DCManagerClientException(error_msg) raise exceptions.DCManagerClientException(error_msg)

View File

@ -89,6 +89,7 @@ class HTTPClientTest(testtools.TestCase):
mock.MagicMock(return_value=FakeResponse('get', EXPECTED_URL, 200)) mock.MagicMock(return_value=FakeResponse('get', EXPECTED_URL, 200))
) )
def test_get_request_options(self): def test_get_request_options(self):
osprofiler.profiler.clean()
self.client.get(API_URL) self.client.get(API_URL)
requests.get.assert_called_with( requests.get.assert_called_with(
@ -130,16 +131,15 @@ class HTTPClientTest(testtools.TestCase):
mock.MagicMock(return_value=FakeResponse('get', EXPECTED_URL, 200)) mock.MagicMock(return_value=FakeResponse('get', EXPECTED_URL, 200))
) )
def test_get_request_options_with_profile_enabled(self): def test_get_request_options_with_profile_enabled(self):
osprofiler.profiler.clean()
osprofiler.profiler.init(PROFILER_HMAC_KEY) osprofiler.profiler.init(PROFILER_HMAC_KEY)
data = {'base_id': PROFILER_TRACE_ID, 'parent_id': PROFILER_TRACE_ID} data = {'base_id': PROFILER_TRACE_ID, 'parent_id': PROFILER_TRACE_ID}
signed_data = osprofiler_utils.signed_pack(data, PROFILER_HMAC_KEY) signed_data = osprofiler_utils.signed_pack(data, PROFILER_HMAC_KEY)
headers = { headers = {
'X-Trace-Info': signed_data[0], 'X-Trace-Info': signed_data[0],
'X-Trace-HMAC': signed_data[1] 'X-Trace-HMAC': signed_data[1]
} }
self.client.get(API_URL) self.client.get(API_URL)
expected_options = copy.deepcopy(EXPECTED_REQ_OPTIONS) expected_options = copy.deepcopy(EXPECTED_REQ_OPTIONS)

View File

@ -33,7 +33,7 @@ class TestShell(base.BaseShellTests):
) )
self.assertTrue(mock.called) self.assertTrue(mock.called)
dcmanager_version = mock.call_args 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') @mock.patch('dcmanagerclient.api.client.determine_client_version')
def test_default_dcmanager_version(self, mock): def test_default_dcmanager_version(self, mock):
@ -89,7 +89,7 @@ class TestShell(base.BaseShellTests):
@mock.patch('dcmanagerclient.api.client.client') @mock.patch('dcmanagerclient.api.client.client')
def test_kb_endpoint_type(self, mock): 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) self.assertTrue(mock.called)
params = mock.call_args params = mock.call_args
self.assertEqual('adminURL', params[1]['endpoint_type']) self.assertEqual('adminURL', params[1]['endpoint_type'])
@ -123,11 +123,11 @@ class TestShell(base.BaseShellTests):
@mock.patch('dcmanagerclient.api.client.client') @mock.patch('dcmanagerclient.api.client.client')
def test_command_with_dcmanager_url(self, mock): def test_command_with_dcmanager_url(self, mock):
self.shell( self.shell(
'--os-dcmanager-url=http://localhost:8118/v1 quota-defaults' '--dcmanager-url=http://localhost:8118/v1.0 quota-defaults'
) )
self.assertTrue(mock.called) self.assertTrue(mock.called)
params = mock.call_args params = mock.call_args
self.assertEqual('http://localhost:8118/v1', self.assertEqual('http://localhost:8118/v1.0',
params[1]['dcmanager_url']) params[1]['dcmanager_url'])
@mock.patch('dcmanagerclient.api.client.client') @mock.patch('dcmanagerclient.api.client.client')

19
tox.ini
View File

@ -3,6 +3,9 @@ minversion = 2.3
envlist = py27,pep8 envlist = py27,pep8
skipsdist = True skipsdist = True
[dcclient]
client_base_dir = .
[testenv] [testenv]
basepython = python3 basepython = python3
install_command = pip install -c{env:UPPER_CONSTRAINTS_FILE:https://git.openstack.org/cgit/openstack/requirements/plain/upper-constraints.txt} {opts} {packages} 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 # DISCOVER_DIRECTORY=dcmanagerclient/tests
deps = -r{toxinidir}/test-requirements.txt deps = -r{toxinidir}/test-requirements.txt
#deps = -r{toxinidir}/requirements.txt -r{toxinidir}/requirements.txt
# -r{toxinidir}/test-requirements.txt whitelist_externals =
#commands = python setup.py testr --slowest --testr-args='{posargs}' 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] [testenv:pep8]
commands = flake8 {posargs} commands = flake8 {posargs}
@ -33,7 +44,7 @@ commands = oslo_debug_helper {posargs}
[flake8] [flake8]
# E123, E125 skipped as they are invalid PEP-8. # E123, E125 skipped as they are invalid PEP-8.
show-source = True show-source = True
ignore = E123,E125 ignore = E123,E125,H102
builtins = _ builtins = _
exclude=.venv,.git,.tox,dist,doc,*lib/python*,*openstack/common*,*egg,build exclude=.venv,.git,.tox,dist,doc,*lib/python*,*openstack/common*,*egg,build