From d46516c46d24f8fea6ea71fdbe2f3fa2d296eb4d Mon Sep 17 00:00:00 2001 From: albailey Date: Wed, 13 May 2020 14:00:12 -0500 Subject: [PATCH] Enable python3 unit tests as part of zuul The existing py27 unit tests were not all passing in py36, however now they are and so the zuul check and gate for py36 have been added. Change-Id: Ie293ec69a04e6fd657f960aa9a135c428138b4b4 Story: 2004515 Task: 39768 Signed-off-by: albailey --- .zuul.yaml | 15 +++++++++++++++ .../v1/controllers/test_subcloud_deploy.py | 9 ++++++--- .../unit/api/v1/controllers/test_subclouds.py | 11 +++++++---- .../unit/manager/test_subcloud_manager.py | 14 +++++++++----- distributedcloud/tox.ini | 19 +++++++++++++++++++ 5 files changed, 56 insertions(+), 12 deletions(-) diff --git a/.zuul.yaml b/.zuul.yaml index ee2a636a0..767c891b8 100644 --- a/.zuul.yaml +++ b/.zuul.yaml @@ -9,12 +9,14 @@ - openstack-tox-linters - stx-distcloud-tox-pep8 - stx-distcloud-tox-py27 + - stx-distcloud-tox-py36 - stx-distcloud-tox-pylint gate: jobs: - openstack-tox-linters - stx-distcloud-tox-pep8 - stx-distcloud-tox-py27 + - stx-distcloud-tox-py36 - stx-distcloud-tox-pylint post: jobs: @@ -33,6 +35,19 @@ tox_envlist: py27 tox_extra_args: -c distributedcloud/tox.ini +- job: + name: stx-distcloud-tox-py36 + parent: tox + description: Run py36 for distcloud + required-projects: + - starlingx/fault + - starlingx/nfv + - starlingx/update + - starlingx/config + vars: + tox_envlist: py36 + tox_extra_args: -c distributedcloud/tox.ini + - job: name: stx-distcloud-tox-pylint parent: tox diff --git a/distributedcloud/dcmanager/tests/unit/api/v1/controllers/test_subcloud_deploy.py b/distributedcloud/dcmanager/tests/unit/api/v1/controllers/test_subcloud_deploy.py index 73b713d03..e6500269e 100644 --- a/distributedcloud/dcmanager/tests/unit/api/v1/controllers/test_subcloud_deploy.py +++ b/distributedcloud/dcmanager/tests/unit/api/v1/controllers/test_subcloud_deploy.py @@ -45,7 +45,8 @@ class TestSubcloudDeploy(testroot.DCManagerApiTest): fields = list() for opt in consts.DEPLOY_COMMON_FILE_OPTIONS: fake_name = opt + "_fake" - fields.append((opt, fake_name, "fake content")) + fake_content = "fake content".encode('utf-8') + fields.append((opt, fake_name, fake_content)) mock_upload_files.return_value = True response = self.app.post(FAKE_URL, headers=FAKE_HEADERS, @@ -59,7 +60,8 @@ class TestSubcloudDeploy(testroot.DCManagerApiTest): fields = list() for opt in opts: fake_name = opt + "_fake" - fields.append((opt, fake_name, "fake content")) + fake_content = "fake content".encode('utf-8') + fields.append((opt, fake_name, fake_content)) mock_upload_files.return_value = True response = self.app.post(FAKE_URL, headers=FAKE_HEADERS, @@ -72,7 +74,8 @@ class TestSubcloudDeploy(testroot.DCManagerApiTest): def test_post_subcloud_deploy_missing_file_name(self, mock_upload_files): fields = list() for opt in consts.DEPLOY_COMMON_FILE_OPTIONS: - fields.append((opt, "", "fake content")) + fake_content = "fake content".encode('utf-8') + fields.append((opt, "", fake_content)) mock_upload_files.return_value = True response = self.app.post(FAKE_URL, headers=FAKE_HEADERS, diff --git a/distributedcloud/dcmanager/tests/unit/api/v1/controllers/test_subclouds.py b/distributedcloud/dcmanager/tests/unit/api/v1/controllers/test_subclouds.py index bde347d99..6263968cc 100644 --- a/distributedcloud/dcmanager/tests/unit/api/v1/controllers/test_subclouds.py +++ b/distributedcloud/dcmanager/tests/unit/api/v1/controllers/test_subclouds.py @@ -131,7 +131,8 @@ class TestSubclouds(testroot.DCManagerApiTest): fields = list() for f in subclouds.SUBCLOUD_ADD_MANDATORY_FILE: fake_name = f + "_fake" - fields.append((f, fake_name, "fake content")) + fake_content = "fake content".encode('utf-8') + fields.append((f, fake_name, fake_content)) data = copy.copy(FAKE_SUBCLOUD_DATA) data.update(FAKE_BOOTSTRAP_VALUE) mock_get_request_data.return_value = data @@ -174,10 +175,12 @@ class TestSubclouds(testroot.DCManagerApiTest): fields = list() for f in subclouds.SUBCLOUD_ADD_GET_FILE_CONTENTS: fake_name = f + "_fake" - fields.append((f, fake_name, "fake content")) + fake_content = "fake content".encode('utf-8') + fields.append((f, fake_name, fake_content)) params = copy.copy(FAKE_BOOTSTRAP_VALUE) - params.update({'bmc_password': - base64.b64encode('bmc_password'.encode("utf-8"))}) + params.update( + {'bmc_password': + base64.b64encode('bmc_password'.encode("utf-8")).decode('utf-8')}) data.update(params) mock_get_request_data.return_value = data mock_upload_deploy_config_file.return_value = True diff --git a/distributedcloud/dcmanager/tests/unit/manager/test_subcloud_manager.py b/distributedcloud/dcmanager/tests/unit/manager/test_subcloud_manager.py index f3c61fa4c..a2e8e04f0 100644 --- a/distributedcloud/dcmanager/tests/unit/manager/test_subcloud_manager.py +++ b/distributedcloud/dcmanager/tests/unit/manager/test_subcloud_manager.py @@ -163,9 +163,6 @@ class TestSubcloudManager(base.DCManagerTestCase): self.assertEqual('localhost', sm.host) self.assertEqual(self.ctx, sm.context) - def exception_dcorch_rpc(self): - raise FakeException - @mock.patch.object(subcloud_manager.SubcloudManager, '_create_intermediate_ca_cert') @mock.patch.object(subcloud_manager.SubcloudManager, @@ -194,6 +191,10 @@ class TestSubcloudManager(base.DCManagerTestCase): controllers = FAKE_CONTROLLERS services = FAKE_SERVICES + # dcmanager add_subcloud queries the data from the db + fake_subcloud = Subcloud(values, False) + mock_db_api.subcloud_get_by_name.return_value = fake_subcloud + mock_sysinv_client().get_controller_hosts.return_value = controllers mock_keystone_client().services_list = services mock_keyring.get_password.return_value = "testpassword" @@ -221,8 +222,11 @@ class TestSubcloudManager(base.DCManagerTestCase): controllers = FAKE_CONTROLLERS services = FAKE_SERVICES - self.fake_dcorch_api.add_subcloud.\ - side_effect = self.exception_dcorch_rpc + # dcmanager add_subcloud queries the data from the db + fake_subcloud = Subcloud(values, False) + mock_db_api.subcloud_get_by_name.return_value = fake_subcloud + + self.fake_dcorch_api.add_subcloud.side_effect = FakeException('boom') mock_sysinv_client().get_controller_hosts.return_value = controllers mock_keystone_client().services_list = services diff --git a/distributedcloud/tox.ini b/distributedcloud/tox.ini index 56c3824f5..6f7c3a8f2 100644 --- a/distributedcloud/tox.ini +++ b/distributedcloud/tox.ini @@ -55,6 +55,25 @@ commands = find {toxinidir} -not -path '{toxinidir}/.tox/*' -name '*.py[c|o]' -delete python setup.py testr --slowest --testr-args='{posargs}' +[testenv:py36] +basepython = python3.6 +deps = -r{toxinidir}/test-requirements.txt + -r{toxinidir}/requirements.txt + keyring + -e{[dc]nfv_client_src_dir} + -e{[dc]sysinv_src_dir} + -e{[dc]tsconfig_src_dir} + -e{[dc]fmclient_src_dir} + -e{[dc]fm_api_src_dir} + -e{[dc]cgtsclient_src_dir} +setenv = + CURRENT_CFG_FILE={toxinidir}/.current.cfg + SINGLE_REPO=True + OSLO_LOCK_PATH={toxinidir} +commands = + find {toxinidir} -not -path '{toxinidir}/.tox/*' -name '*.py[c|o]' -delete + python setup.py testr --slowest --testr-args='{posargs}' + [testenv:debug-py27] basepython = python2.7 commands = oslo_debug_helper {posargs}