From 4ce7734743ef526cfd30d24d43c82b665a2daf3a Mon Sep 17 00:00:00 2001 From: BoYuan Chang Date: Wed, 20 Jul 2022 12:00:38 -0400 Subject: [PATCH] Minor Code Change Based on Py39 Pylint Feedback Pylint is currently running python3.0 syntax and we are updating the pylint to python3.9. As a result we received a few warnings that have not been previously identified with python3.0 syntax. This code change will address those warnings raised by latest pylint check. The following alarms are addressed: 1. W0237 - Parameter '.' has been renamed to '.' in overridden method 2. E1101 - Instance of '.' has no '.' member (no-member) 3. W0127 - Assigning the same variable to itself 4. E4702 - Iterated dict is being modified inside for loop body 5. W0602 - Using global for '.' but no assignment is done 6. E1123 - Unexpected keyword argument '.'. in method call 7. W0238 - Unused private memeber '.' 8. E1121 - Too many positional arguments for methods call The following alarms are still remain suppressed: 1. W1514 - Using open with specifying encoding (python2 does not support this change) 2. W0707 - Consider explicitly re-raising using raise '.' from '.' (same as above) Test Plan : 1. Perform DC Regression Test and compare before and after code change 2. Ensure Tox can pass on both Debain and CentOS build server 3. Ensure pylint3 and pylint3.9 can pass without warning 4. Ensure ISO can be properly booted on both Debian and CentOS Story: 2008943 Task: 45832 Signed-off-by: BoYuan Chang Change-Id: I6f3a25fd788a3bdc021067c624123132a716e5c8 --- .../dcdbsync/api/controllers/restcomm.py | 6 ++-- distributedcloud/dcdbsync/common/context.py | 3 +- .../dcdbsync/db/identity/sqlalchemy/api.py | 4 --- .../dcdbsync/db/identity/utils.py | 8 +++-- .../dcmanager/api/controllers/restcomm.py | 6 ++-- distributedcloud/dcmanager/common/context.py | 1 + .../dcmanager/common/serializer.py | 26 +++++++-------- distributedcloud/dcmanager/db/utils.py | 8 +++-- .../firmware/test_applying_vim_strategy.py | 4 +-- .../firmware/test_creating_vim_strategy.py | 4 +-- .../firmware/test_finishing_vim_strategy.py | 4 +-- .../firmware/test_importing_firmware.py | 4 +-- .../states/kube/test_pre_check.py | 4 +-- .../states/kube_rootca/test_pre_check.py | 4 +-- .../states/kube_rootca/test_start_update.py | 4 +-- .../states/kube_rootca/test_upload_cert.py | 4 +-- .../states/prestage/test_states.py | 8 ++--- .../states/test_applying_vim_strategy.py | 4 +-- .../states/test_creating_vim_strategy.py | 4 +-- .../states/upgrade/test_activating_upgrade.py | 4 +-- .../states/upgrade/test_completing_upgrade.py | 4 +-- .../states/upgrade/test_deleting_load.py | 4 +-- .../upgrade/test_finishing_patch_strategy.py | 4 +-- .../states/upgrade/test_importing_load.py | 4 +-- .../states/upgrade/test_installing_license.py | 4 +-- .../states/upgrade/test_lock_controller.py | 4 +-- .../states/upgrade/test_migrating_data.py | 4 +-- .../states/upgrade/test_pre_check.py | 2 +- .../states/upgrade/test_starting_upgrade.py | 4 +-- .../states/upgrade/test_swact_controller.py | 4 +-- .../states/upgrade/test_unlock_controller.py | 4 +-- .../states/upgrade/test_updating_patches.py | 4 +-- .../states/upgrade/test_upgrading_duplex.py | 4 +-- .../states/upgrade/test_upgrading_simplex.py | 4 +-- .../tests/unit/orchestrator/test_base.py | 6 ++-- .../unit/orchestrator/test_fw_orch_thread.py | 6 ++-- .../dcorch/api/controllers/restcomm.py | 5 +-- distributedcloud/dcorch/common/context.py | 2 ++ distributedcloud/dcorch/common/serializer.py | 26 +++++++-------- distributedcloud/dcorch/common/utils.py | 5 +-- distributedcloud/dcorch/db/utils.py | 7 +++- distributedcloud/dcorch/drivers/base.py | 1 + .../dcorch/drivers/openstack/nova_v2.py | 6 +++- .../dcorch/engine/generic_sync_manager.py | 6 +--- .../dcorch/engine/sync_services/compute.py | 33 ++++++++++--------- .../dcorch/engine/sync_services/identity.py | 2 ++ .../dcorch/engine/sync_services/network.py | 12 ++++--- distributedcloud/dcorch/engine/sync_thread.py | 5 +-- distributedcloud/dcorch/objects/service.py | 9 ++++- .../tests/unit/db/test_orch_request_db_api.py | 3 -- 50 files changed, 164 insertions(+), 138 deletions(-) diff --git a/distributedcloud/dcdbsync/api/controllers/restcomm.py b/distributedcloud/dcdbsync/api/controllers/restcomm.py index e509163cf..06900c7d8 100644 --- a/distributedcloud/dcdbsync/api/controllers/restcomm.py +++ b/distributedcloud/dcdbsync/api/controllers/restcomm.py @@ -13,7 +13,7 @@ # License for the specific language governing permissions and limitations # under the License. # -# Copyright (c) 2019 Wind River Systems, Inc. +# Copyright (c) 2019, 2022 Wind River Systems, Inc. # # SPDX-License-Identifier: Apache-2.0 # @@ -38,8 +38,8 @@ def extract_context_from_environ(): environ = request.environ - for key in context_paras: - context_paras[key] = environ.get(context_paras[key]) + for key, val in context_paras.items(): + context_paras[key] = environ.get(val) role = environ.get('HTTP_X_ROLE') context_paras['is_admin'] = 'admin' in role.split(',') diff --git a/distributedcloud/dcdbsync/common/context.py b/distributedcloud/dcdbsync/common/context.py index 51114c6d0..0c7bc2a7c 100644 --- a/distributedcloud/dcdbsync/common/context.py +++ b/distributedcloud/dcdbsync/common/context.py @@ -10,7 +10,7 @@ # License for the specific language governing permissions and limitations # under the License. # -# Copyright (c) 2019 Wind River Systems, Inc. +# Copyright (c) 2019, 2022 Wind River Systems, Inc. # # SPDX-License-Identifier: Apache-2.0 # @@ -45,6 +45,7 @@ class RequestContext(base_context.RequestContext): # Initializer of request context. # We still have 'tenant' param because oslo_context still use it. + # pylint: disable=E1123 super(RequestContext, self).__init__( auth_token=auth_token, user=user, tenant=project, domain=domain, user_domain=user_domain, diff --git a/distributedcloud/dcdbsync/db/identity/sqlalchemy/api.py b/distributedcloud/dcdbsync/db/identity/sqlalchemy/api.py index 445da4139..7033c6ad2 100644 --- a/distributedcloud/dcdbsync/db/identity/sqlalchemy/api.py +++ b/distributedcloud/dcdbsync/db/identity/sqlalchemy/api.py @@ -106,7 +106,6 @@ def index2column(r_table, index_name): def query(connection, table, index_name=None, index_value=None): - global registry r_table = registry.get(connection, table) if index_name and index_value: @@ -126,7 +125,6 @@ def query(connection, table, index_name=None, index_value=None): def insert(connection, table, data): - global registry r_table = registry.get(connection, table) stmt = r_table.insert() @@ -134,7 +132,6 @@ def insert(connection, table, data): def delete(connection, table, index_name, index_value): - global registry r_table = registry.get(connection, table) c = index2column(r_table, index_name) @@ -143,7 +140,6 @@ def delete(connection, table, index_name, index_value): def update(connection, table, index_name, index_value, data): - global registry r_table = registry.get(connection, table) c = index2column(r_table, index_name) diff --git a/distributedcloud/dcdbsync/db/identity/utils.py b/distributedcloud/dcdbsync/db/identity/utils.py index e437a90d9..f32f1b80e 100644 --- a/distributedcloud/dcdbsync/db/identity/utils.py +++ b/distributedcloud/dcdbsync/db/identity/utils.py @@ -13,11 +13,15 @@ # License for the specific language governing permissions and limitations # under the License. # -# Copyright (c) 2019 Wind River Systems, Inc. +# Copyright (c) 2019, 2022 Wind River Systems, Inc. # # SPDX-License-Identifier: Apache-2.0 # +from oslo_config import cfg + +CONF = cfg.CONF + class LazyPluggable(object): """A pluggable backend loaded lazily based on some value.""" @@ -29,7 +33,7 @@ class LazyPluggable(object): def __get_backend(self): if not self.__backend: - backend_name = 'sqlalchemy' + backend_name = CONF[self.__pivot] backend = self.__backends[backend_name] if isinstance(backend, tuple): name = backend[0] diff --git a/distributedcloud/dcmanager/api/controllers/restcomm.py b/distributedcloud/dcmanager/api/controllers/restcomm.py index f2861922b..336754f7e 100644 --- a/distributedcloud/dcmanager/api/controllers/restcomm.py +++ b/distributedcloud/dcmanager/api/controllers/restcomm.py @@ -1,5 +1,5 @@ # Copyright (c) 2015 Huawei Tech. Co., Ltd. -# Copyright (c) 2017, 2019, 2021 Wind River Systems, Inc. +# Copyright (c) 2017, 2019, 2021, 2022 Wind River Systems, Inc. # All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may @@ -35,8 +35,8 @@ def extract_context_from_environ(): environ = request.environ - for key in context_paras: - context_paras[key] = environ.get(context_paras[key]) + for key, val in context_paras.items(): + context_paras[key] = environ.get(val) role = environ.get('HTTP_X_ROLE') context_paras['is_admin'] = 'admin' in role.split(',') diff --git a/distributedcloud/dcmanager/common/context.py b/distributedcloud/dcmanager/common/context.py index f0c644caa..fddb16ef5 100644 --- a/distributedcloud/dcmanager/common/context.py +++ b/distributedcloud/dcmanager/common/context.py @@ -54,6 +54,7 @@ class RequestContext(base_context.RequestContext): """Initializer of request context.""" # We still have 'tenant' param because oslo_context still use it. + # pylint: disable=E1123 super(RequestContext, self).__init__( auth_token=auth_token, user=user, tenant=project, domain=domain, user_domain=user_domain, diff --git a/distributedcloud/dcmanager/common/serializer.py b/distributedcloud/dcmanager/common/serializer.py index 71f3dfe84..9c58b94fd 100644 --- a/distributedcloud/dcmanager/common/serializer.py +++ b/distributedcloud/dcmanager/common/serializer.py @@ -1,5 +1,5 @@ # Copyright 2015 Huawei Technologies Co., Ltd. -# Copyright (c) 2017, 2019, 2021 Wind River Systems, Inc. +# Copyright (c) 2017, 2019, 2021, 2022 Wind River Systems, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -37,48 +37,48 @@ class DCManagerSerializer(oslo_messaging.Serializer): super(DCManagerSerializer, self).__init__() self._base = base - def serialize_entity(self, context, entity): + def serialize_entity(self, ctxt, entity): if isinstance(entity, dict): for key, value in entity.items(): - entity[key] = self.serialize_entity(context, value) + entity[key] = self.serialize_entity(ctxt, value) elif isinstance(entity, list): for i, item in enumerate(entity): - entity[i] = self.serialize_entity(context, item) + entity[i] = self.serialize_entity(ctxt, item) elif entity in _SINGLETON_MAPPING.direct_mapping: entity = _SINGLETON_MAPPING.direct_mapping[entity] if self._base is not None: - entity = self._base.serialize_entity(context, entity) + entity = self._base.serialize_entity(ctxt, entity) return entity - def deserialize_entity(self, context, entity): + def deserialize_entity(self, ctxt, entity): if isinstance(entity, dict): for key, value in entity.items(): - entity[key] = self.deserialize_entity(context, value) + entity[key] = self.deserialize_entity(ctxt, value) elif isinstance(entity, list): for i, item in enumerate(entity): - entity[i] = self.deserialize_entity(context, item) + entity[i] = self.deserialize_entity(ctxt, item) elif entity in _SINGLETON_MAPPING.reverse_mapping: entity = _SINGLETON_MAPPING.reverse_mapping[entity] if self._base is not None: - entity = self._base.deserialize_entity(context, entity) + entity = self._base.deserialize_entity(ctxt, entity) return entity - def serialize_context(self, context): + def serialize_context(self, ctxt): if self._base is not None: - context = self._base.serialize_context(context) + context = self._base.serialize_context(ctxt) return context - def deserialize_context(self, context): + def deserialize_context(self, ctxt): if self._base is not None: - context = self._base.deserialize_context(context) + context = self._base.deserialize_context(ctxt) return context diff --git a/distributedcloud/dcmanager/db/utils.py b/distributedcloud/dcmanager/db/utils.py index 73aa5fcc1..e2223033c 100644 --- a/distributedcloud/dcmanager/db/utils.py +++ b/distributedcloud/dcmanager/db/utils.py @@ -1,5 +1,5 @@ # Copyright (c) 2015 Ericsson AB. -# Copyright (c) 2017, 2019, 2021 Wind River Systems, Inc. +# Copyright (c) 2017, 2019, 2021, 2022 Wind River Systems, Inc. # All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may @@ -15,6 +15,10 @@ # under the License. # +from oslo_config import cfg + +CONF = cfg.CONF + class LazyPluggable(object): """A pluggable backend loaded lazily based on some value.""" @@ -26,7 +30,7 @@ class LazyPluggable(object): def __get_backend(self): if not self.__backend: - backend_name = 'sqlalchemy' + backend_name = CONF[self.__pivot] backend = self.__backends[backend_name] if isinstance(backend, tuple): name = backend[0] diff --git a/distributedcloud/dcmanager/tests/unit/orchestrator/states/firmware/test_applying_vim_strategy.py b/distributedcloud/dcmanager/tests/unit/orchestrator/states/firmware/test_applying_vim_strategy.py index d5da85d88..ac6aa0239 100644 --- a/distributedcloud/dcmanager/tests/unit/orchestrator/states/firmware/test_applying_vim_strategy.py +++ b/distributedcloud/dcmanager/tests/unit/orchestrator/states/firmware/test_applying_vim_strategy.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2020 Wind River Systems, Inc. +# Copyright (c) 2020, 2022 Wind River Systems, Inc. # # SPDX-License-Identifier: Apache-2.0 # @@ -40,7 +40,7 @@ class TestFwUpdateApplyingVIMStrategyStage(TestFwUpdateState): # Add the strategy_step state being processed by this unit test self.strategy_step = self.setup_strategy_step( - consts.STRATEGY_STATE_APPLYING_FW_UPDATE_STRATEGY) + self.subcloud.id, consts.STRATEGY_STATE_APPLYING_FW_UPDATE_STRATEGY) # Add mock API endpoints for client calls invcked by this state self.vim_client.get_strategy = mock.MagicMock() diff --git a/distributedcloud/dcmanager/tests/unit/orchestrator/states/firmware/test_creating_vim_strategy.py b/distributedcloud/dcmanager/tests/unit/orchestrator/states/firmware/test_creating_vim_strategy.py index 1f188846b..a03176eea 100644 --- a/distributedcloud/dcmanager/tests/unit/orchestrator/states/firmware/test_creating_vim_strategy.py +++ b/distributedcloud/dcmanager/tests/unit/orchestrator/states/firmware/test_creating_vim_strategy.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2020 Wind River Systems, Inc. +# Copyright (c) 2020, 2022 Wind River Systems, Inc. # # SPDX-License-Identifier: Apache-2.0 # @@ -38,7 +38,7 @@ class TestFwUpdateCreatingVIMStrategyStage(TestFwUpdateState): # Add the strategy_step state being processed by this unit test self.strategy_step = self.setup_strategy_step( - consts.STRATEGY_STATE_CREATING_FW_UPDATE_STRATEGY) + self.subcloud.id, consts.STRATEGY_STATE_CREATING_FW_UPDATE_STRATEGY) # Add mock API endpoints for sysinv client calls invcked by this state self.vim_client.create_strategy = mock.MagicMock() diff --git a/distributedcloud/dcmanager/tests/unit/orchestrator/states/firmware/test_finishing_vim_strategy.py b/distributedcloud/dcmanager/tests/unit/orchestrator/states/firmware/test_finishing_vim_strategy.py index 15b9f0ded..0e9727acb 100644 --- a/distributedcloud/dcmanager/tests/unit/orchestrator/states/firmware/test_finishing_vim_strategy.py +++ b/distributedcloud/dcmanager/tests/unit/orchestrator/states/firmware/test_finishing_vim_strategy.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2020-2021 Wind River Systems, Inc. +# Copyright (c) 2020-2022 Wind River Systems, Inc. # # SPDX-License-Identifier: Apache-2.0 # @@ -32,7 +32,7 @@ class TestFwUpdateFinishingFwUpdateStage(TestFwUpdateState): # Add the strategy_step state being processed by this unit test self.strategy_step = self.setup_strategy_step( - consts.STRATEGY_STATE_FINISHING_FW_UPDATE) + self.subcloud.id, consts.STRATEGY_STATE_FINISHING_FW_UPDATE) # Add mock API endpoints for sysinv client calls invcked by this state self.vim_client.get_strategy = mock.MagicMock() diff --git a/distributedcloud/dcmanager/tests/unit/orchestrator/states/firmware/test_importing_firmware.py b/distributedcloud/dcmanager/tests/unit/orchestrator/states/firmware/test_importing_firmware.py index b3e32165a..92d9e0cce 100644 --- a/distributedcloud/dcmanager/tests/unit/orchestrator/states/firmware/test_importing_firmware.py +++ b/distributedcloud/dcmanager/tests/unit/orchestrator/states/firmware/test_importing_firmware.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2020 Wind River Systems, Inc. +# Copyright (c) 2020, 2022 Wind River Systems, Inc. # # SPDX-License-Identifier: Apache-2.0 # @@ -63,7 +63,7 @@ class TestFwUpdateImportingFirmwareStage(TestFwUpdateState): # Add the strategy_step state being processed by this unit test self.strategy_step = \ - self.setup_strategy_step(consts.STRATEGY_STATE_IMPORTING_FIRMWARE) + self.setup_strategy_step(self.subcloud.id, consts.STRATEGY_STATE_IMPORTING_FIRMWARE) # Add mock API endpoints for sysinv client calls invcked by this state self.sysinv_client.get_device_images = mock.MagicMock() diff --git a/distributedcloud/dcmanager/tests/unit/orchestrator/states/kube/test_pre_check.py b/distributedcloud/dcmanager/tests/unit/orchestrator/states/kube/test_pre_check.py index f9a6d227c..f6a92ce24 100644 --- a/distributedcloud/dcmanager/tests/unit/orchestrator/states/kube/test_pre_check.py +++ b/distributedcloud/dcmanager/tests/unit/orchestrator/states/kube/test_pre_check.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2020 Wind River Systems, Inc. +# Copyright (c) 2020, 2022 Wind River Systems, Inc. # # SPDX-License-Identifier: Apache-2.0 # @@ -35,7 +35,7 @@ class TestKubeUpgradePreCheckStage(TestKubeUpgradeState): # Add the strategy_step state being processed by this unit test self.strategy_step = \ - self.setup_strategy_step(STRATEGY_STATE_KUBE_UPGRADE_PRE_CHECK) + self.setup_strategy_step(self.subcloud.id, STRATEGY_STATE_KUBE_UPGRADE_PRE_CHECK) # mock there not being a kube upgrade in progress self.sysinv_client.get_kube_upgrades = mock.MagicMock() diff --git a/distributedcloud/dcmanager/tests/unit/orchestrator/states/kube_rootca/test_pre_check.py b/distributedcloud/dcmanager/tests/unit/orchestrator/states/kube_rootca/test_pre_check.py index 12cbeccaf..05da74262 100644 --- a/distributedcloud/dcmanager/tests/unit/orchestrator/states/kube_rootca/test_pre_check.py +++ b/distributedcloud/dcmanager/tests/unit/orchestrator/states/kube_rootca/test_pre_check.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2021 Wind River Systems, Inc. +# Copyright (c) 2021-2022 Wind River Systems, Inc. # # SPDX-License-Identifier: Apache-2.0 # @@ -23,7 +23,7 @@ class TestPreCheckStage(TestKubeRootCaUpgradeState): # Add the strategy_step state being processed by this unit test self.strategy_step = self.setup_strategy_step( - STRATEGY_STATE_KUBE_ROOTCA_UPDATE_PRE_CHECK) + self.subcloud.id, STRATEGY_STATE_KUBE_ROOTCA_UPDATE_PRE_CHECK) def test_pre_check_no_extra_args(self): """Test pre check step where there are no extra args diff --git a/distributedcloud/dcmanager/tests/unit/orchestrator/states/kube_rootca/test_start_update.py b/distributedcloud/dcmanager/tests/unit/orchestrator/states/kube_rootca/test_start_update.py index 12286ca51..15850a760 100644 --- a/distributedcloud/dcmanager/tests/unit/orchestrator/states/kube_rootca/test_start_update.py +++ b/distributedcloud/dcmanager/tests/unit/orchestrator/states/kube_rootca/test_start_update.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2021 Wind River Systems, Inc. +# Copyright (c) 2021-2022 Wind River Systems, Inc. # # SPDX-License-Identifier: Apache-2.0 # @@ -31,7 +31,7 @@ class TestStartUpdateStage(TestKubeRootCaUpgradeState): # Add the strategy_step state being processed by this unit test self.strategy_step = self.setup_strategy_step( - STRATEGY_STATE_KUBE_ROOTCA_UPDATE_START) + self.subcloud.id, STRATEGY_STATE_KUBE_ROOTCA_UPDATE_START) self.sysinv_client.kube_rootca_update_start = mock.MagicMock() self.sysinv_client.get_kube_rootca_updates = mock.MagicMock() diff --git a/distributedcloud/dcmanager/tests/unit/orchestrator/states/kube_rootca/test_upload_cert.py b/distributedcloud/dcmanager/tests/unit/orchestrator/states/kube_rootca/test_upload_cert.py index deac795e2..eb631e0dc 100644 --- a/distributedcloud/dcmanager/tests/unit/orchestrator/states/kube_rootca/test_upload_cert.py +++ b/distributedcloud/dcmanager/tests/unit/orchestrator/states/kube_rootca/test_upload_cert.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2021 Wind River Systems, Inc. +# Copyright (c) 2021-2022 Wind River Systems, Inc. # # SPDX-License-Identifier: Apache-2.0 # @@ -32,7 +32,7 @@ class TestUploadCertStage(TestKubeRootCaUpgradeState): # Add the strategy_step state being processed by this unit test self.strategy_step = self.setup_strategy_step( - STRATEGY_STATE_KUBE_ROOTCA_UPDATE_UPLOAD_CERT) + self.subcloud.id, STRATEGY_STATE_KUBE_ROOTCA_UPDATE_UPLOAD_CERT) self.sysinv_client.kube_rootca_update_upload_cert = mock.MagicMock() diff --git a/distributedcloud/dcmanager/tests/unit/orchestrator/states/prestage/test_states.py b/distributedcloud/dcmanager/tests/unit/orchestrator/states/prestage/test_states.py index b287ea19d..e46d21336 100644 --- a/distributedcloud/dcmanager/tests/unit/orchestrator/states/prestage/test_states.py +++ b/distributedcloud/dcmanager/tests/unit/orchestrator/states/prestage/test_states.py @@ -56,7 +56,7 @@ class TestPrestagePreCheckState(TestPrestage): # Add the strategy_step state being processed by this unit test self.strategy_step = \ - self.setup_strategy_step(STRATEGY_STATE_PRESTAGE_PRE_CHECK) + self.setup_strategy_step(self.subcloud.id, STRATEGY_STATE_PRESTAGE_PRE_CHECK) def test_prestage_prepare(self): next_state = STRATEGY_STATE_PRESTAGE_PREPARE @@ -169,7 +169,7 @@ class TestPrestagePrepareState(TestPrestage): # Add the strategy_step state being processed by this unit test self.strategy_step = \ - self.setup_strategy_step(STRATEGY_STATE_PRESTAGE_PREPARE) + self.setup_strategy_step(self.subcloud.id, STRATEGY_STATE_PRESTAGE_PREPARE) def test_prestage_prestage_prepare(self): @@ -236,7 +236,7 @@ class TestPrestagePackageState(TestPrestage): # Add the strategy_step state being processed by this unit test self.strategy_step = \ - self.setup_strategy_step(STRATEGY_STATE_PRESTAGE_PACKAGES) + self.setup_strategy_step(self.subcloud.id, STRATEGY_STATE_PRESTAGE_PACKAGES) def test_prestage_prestage_package(self): @@ -279,7 +279,7 @@ class TestPrestageImagesState(TestPrestage): # Add the strategy_step state being processed by this unit test self.strategy_step = \ - self.setup_strategy_step(STRATEGY_STATE_PRESTAGE_IMAGES) + self.setup_strategy_step(self.subcloud.id, STRATEGY_STATE_PRESTAGE_IMAGES) def test_prestage_prestage_images(self): diff --git a/distributedcloud/dcmanager/tests/unit/orchestrator/states/test_applying_vim_strategy.py b/distributedcloud/dcmanager/tests/unit/orchestrator/states/test_applying_vim_strategy.py index 4a664c5b6..01ec02f6b 100644 --- a/distributedcloud/dcmanager/tests/unit/orchestrator/states/test_applying_vim_strategy.py +++ b/distributedcloud/dcmanager/tests/unit/orchestrator/states/test_applying_vim_strategy.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2020-2021 Wind River Systems, Inc. +# Copyright (c) 2020-2022 Wind River Systems, Inc. # # SPDX-License-Identifier: Apache-2.0 # @@ -36,7 +36,7 @@ class ApplyingVIMStrategyMixin(object): self.subcloud = self.setup_subcloud() # Add the strategy_step state being processed by this unit test - self.strategy_step = self.setup_strategy_step(self.state) + self.strategy_step = self.setup_strategy_step(self.subcloud.id, self.state) # Add mock API endpoints for client calls invcked by this state self.vim_client.get_strategy = mock.MagicMock() diff --git a/distributedcloud/dcmanager/tests/unit/orchestrator/states/test_creating_vim_strategy.py b/distributedcloud/dcmanager/tests/unit/orchestrator/states/test_creating_vim_strategy.py index 364e8985b..43321b6e6 100644 --- a/distributedcloud/dcmanager/tests/unit/orchestrator/states/test_creating_vim_strategy.py +++ b/distributedcloud/dcmanager/tests/unit/orchestrator/states/test_creating_vim_strategy.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2020-2021 Wind River Systems, Inc. +# Copyright (c) 2020-2022 Wind River Systems, Inc. # # SPDX-License-Identifier: Apache-2.0 # @@ -34,7 +34,7 @@ class CreatingVIMStrategyStageMixin(object): self.subcloud = self.setup_subcloud() # Add the strategy_step state being processed by this unit test - self.strategy_step = self.setup_strategy_step(self.state) + self.strategy_step = self.setup_strategy_step(self.subcloud.id, self.state) # Add mock API endpoints for sysinv client calls invcked by this state self.vim_client.create_strategy = mock.MagicMock() diff --git a/distributedcloud/dcmanager/tests/unit/orchestrator/states/upgrade/test_activating_upgrade.py b/distributedcloud/dcmanager/tests/unit/orchestrator/states/upgrade/test_activating_upgrade.py index 25edf7e8e..39d49c592 100644 --- a/distributedcloud/dcmanager/tests/unit/orchestrator/states/upgrade/test_activating_upgrade.py +++ b/distributedcloud/dcmanager/tests/unit/orchestrator/states/upgrade/test_activating_upgrade.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2020 Wind River Systems, Inc. +# Copyright (c) 2020, 2022 Wind River Systems, Inc. # # SPDX-License-Identifier: Apache-2.0 # @@ -38,7 +38,7 @@ class TestSwUpgradeActivatingStage(TestSwUpgradeState): # Add the strategy_step state being processed by this unit test self.strategy_step = \ - self.setup_strategy_step(consts.STRATEGY_STATE_ACTIVATING_UPGRADE) + self.setup_strategy_step(self.subcloud.id, consts.STRATEGY_STATE_ACTIVATING_UPGRADE) # Add mock API endpoints for sysinv client calls invoked by this state self.sysinv_client.upgrade_activate = mock.MagicMock() diff --git a/distributedcloud/dcmanager/tests/unit/orchestrator/states/upgrade/test_completing_upgrade.py b/distributedcloud/dcmanager/tests/unit/orchestrator/states/upgrade/test_completing_upgrade.py index a0d2f3ceb..a5bf0a8d4 100644 --- a/distributedcloud/dcmanager/tests/unit/orchestrator/states/upgrade/test_completing_upgrade.py +++ b/distributedcloud/dcmanager/tests/unit/orchestrator/states/upgrade/test_completing_upgrade.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2020 Wind River Systems, Inc. +# Copyright (c) 2020, 2022 Wind River Systems, Inc. # # SPDX-License-Identifier: Apache-2.0 # @@ -36,7 +36,7 @@ class TestSwUpgradeCompletingStage(TestSwUpgradeState): # Add the strategy_step state being processed by this unit test self.strategy_step = \ - self.setup_strategy_step(consts.STRATEGY_STATE_COMPLETING_UPGRADE) + self.setup_strategy_step(self.subcloud.id, consts.STRATEGY_STATE_COMPLETING_UPGRADE) # Add mock API endpoints for sysinv client calls invoked by this state self.sysinv_client.upgrade_complete = mock.MagicMock() diff --git a/distributedcloud/dcmanager/tests/unit/orchestrator/states/upgrade/test_deleting_load.py b/distributedcloud/dcmanager/tests/unit/orchestrator/states/upgrade/test_deleting_load.py index fb6cff2be..8fa325a70 100644 --- a/distributedcloud/dcmanager/tests/unit/orchestrator/states/upgrade/test_deleting_load.py +++ b/distributedcloud/dcmanager/tests/unit/orchestrator/states/upgrade/test_deleting_load.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2020 Wind River Systems, Inc. +# Copyright (c) 2020, 2022 Wind River Systems, Inc. # # SPDX-License-Identifier: Apache-2.0 # @@ -53,7 +53,7 @@ class TestSwUpgradeDeletingLoadStage(TestSwUpgradeState): # Add the strategy_step state being processed by this unit test self.strategy_step = \ - self.setup_strategy_step(consts.STRATEGY_STATE_DELETING_LOAD) + self.setup_strategy_step(self.subcloud.id, consts.STRATEGY_STATE_DELETING_LOAD) # Add mock API endpoints for sysinv client calls invoked by this state self.sysinv_client.get_loads = mock.MagicMock() diff --git a/distributedcloud/dcmanager/tests/unit/orchestrator/states/upgrade/test_finishing_patch_strategy.py b/distributedcloud/dcmanager/tests/unit/orchestrator/states/upgrade/test_finishing_patch_strategy.py index 5df15eff7..de727895b 100644 --- a/distributedcloud/dcmanager/tests/unit/orchestrator/states/upgrade/test_finishing_patch_strategy.py +++ b/distributedcloud/dcmanager/tests/unit/orchestrator/states/upgrade/test_finishing_patch_strategy.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2020 Wind River Systems, Inc. +# Copyright (c) 2020, 2022 Wind River Systems, Inc. # # SPDX-License-Identifier: Apache-2.0 # @@ -63,7 +63,7 @@ class TestSwUpgradeFinishingPatchStrategyStage(TestSwUpgradeState): # Add the strategy_step state being processed by this unit test self.strategy_step = \ - self.setup_strategy_step(consts.STRATEGY_STATE_FINISHING_PATCH_STRATEGY) + self.setup_strategy_step(self.subcloud.id, consts.STRATEGY_STATE_FINISHING_PATCH_STRATEGY) # Add mock API endpoints for patching client calls invoked by this state self.patching_client.query = mock.MagicMock() diff --git a/distributedcloud/dcmanager/tests/unit/orchestrator/states/upgrade/test_importing_load.py b/distributedcloud/dcmanager/tests/unit/orchestrator/states/upgrade/test_importing_load.py index 86b5a457a..7587f66c0 100644 --- a/distributedcloud/dcmanager/tests/unit/orchestrator/states/upgrade/test_importing_load.py +++ b/distributedcloud/dcmanager/tests/unit/orchestrator/states/upgrade/test_importing_load.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2020-2021 Wind River Systems, Inc. +# Copyright (c) 2020-2022 Wind River Systems, Inc. # # SPDX-License-Identifier: Apache-2.0 # @@ -110,7 +110,7 @@ class TestSwUpgradeImportingLoadStage(TestSwUpgradeState): # Add the strategy_step state being processed by this unit test self.strategy_step = \ - self.setup_strategy_step(consts.STRATEGY_STATE_IMPORTING_LOAD) + self.setup_strategy_step(self.subcloud.id, consts.STRATEGY_STATE_IMPORTING_LOAD) # Mock the get_vault_load_files utility method p = mock.patch( diff --git a/distributedcloud/dcmanager/tests/unit/orchestrator/states/upgrade/test_installing_license.py b/distributedcloud/dcmanager/tests/unit/orchestrator/states/upgrade/test_installing_license.py index c1aec811e..ff6cf1104 100644 --- a/distributedcloud/dcmanager/tests/unit/orchestrator/states/upgrade/test_installing_license.py +++ b/distributedcloud/dcmanager/tests/unit/orchestrator/states/upgrade/test_installing_license.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2020 Wind River Systems, Inc. +# Copyright (c) 2020, 2022 Wind River Systems, Inc. # # SPDX-License-Identifier: Apache-2.0 # @@ -39,7 +39,7 @@ class TestSwUpgradeInstallingLicenseStage(TestSwUpgradeState): # Add the strategy_step state being processed by this unit test self.strategy_step = \ - self.setup_strategy_step(consts.STRATEGY_STATE_INSTALLING_LICENSE) + self.setup_strategy_step(self.subcloud.id, consts.STRATEGY_STATE_INSTALLING_LICENSE) # Add mock API endpoints for sysinv client calls invoked by this state self.sysinv_client.get_license = mock.MagicMock() diff --git a/distributedcloud/dcmanager/tests/unit/orchestrator/states/upgrade/test_lock_controller.py b/distributedcloud/dcmanager/tests/unit/orchestrator/states/upgrade/test_lock_controller.py index 4c305230f..8f6e710de 100644 --- a/distributedcloud/dcmanager/tests/unit/orchestrator/states/upgrade/test_lock_controller.py +++ b/distributedcloud/dcmanager/tests/unit/orchestrator/states/upgrade/test_lock_controller.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2020 Wind River Systems, Inc. +# Copyright (c) 2020, 2022 Wind River Systems, Inc. # # SPDX-License-Identifier: Apache-2.0 # @@ -30,7 +30,7 @@ class TestSwUpgradeLockSimplexStage(TestSwUpgradeState): self.subcloud = self.setup_subcloud() # Add the strategy_step state being processed by this unit test - self.strategy_step = self.setup_strategy_step(self.state) + self.strategy_step = self.setup_strategy_step(self.subcloud.id, self.state) # Add mock API endpoints for sysinv client calls invoked by this state self.sysinv_client.get_host = mock.MagicMock() diff --git a/distributedcloud/dcmanager/tests/unit/orchestrator/states/upgrade/test_migrating_data.py b/distributedcloud/dcmanager/tests/unit/orchestrator/states/upgrade/test_migrating_data.py index 320ba2bf1..6919a097d 100644 --- a/distributedcloud/dcmanager/tests/unit/orchestrator/states/upgrade/test_migrating_data.py +++ b/distributedcloud/dcmanager/tests/unit/orchestrator/states/upgrade/test_migrating_data.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2020 Wind River Systems, Inc. +# Copyright (c) 2020, 2022 Wind River Systems, Inc. # # SPDX-License-Identifier: Apache-2.0 # @@ -45,7 +45,7 @@ class TestSwUpgradeMigratingDataStage(TestSwUpgradeState): # Add the strategy_step state being processed by this unit test self.strategy_step = \ - self.setup_strategy_step(consts.STRATEGY_STATE_MIGRATING_DATA) + self.setup_strategy_step(self.subcloud.id, consts.STRATEGY_STATE_MIGRATING_DATA) # Add mock API endpoints for sysinv client calls invoked by this state self.sysinv_client.get_host = mock.MagicMock() diff --git a/distributedcloud/dcmanager/tests/unit/orchestrator/states/upgrade/test_pre_check.py b/distributedcloud/dcmanager/tests/unit/orchestrator/states/upgrade/test_pre_check.py index fe4446bc3..3651f1aaf 100644 --- a/distributedcloud/dcmanager/tests/unit/orchestrator/states/upgrade/test_pre_check.py +++ b/distributedcloud/dcmanager/tests/unit/orchestrator/states/upgrade/test_pre_check.py @@ -133,7 +133,7 @@ class TestSwUpgradePreCheckStage(TestSwUpgradeState): # Add the strategy_step state being processed by this unit test self.strategy_step = \ - self.setup_strategy_step(consts.STRATEGY_STATE_PRE_CHECK) + self.setup_strategy_step(self.subcloud.id, consts.STRATEGY_STATE_PRE_CHECK) self.sysinv_client.get_host = mock.MagicMock() self.sysinv_client.get_host_filesystem = mock.MagicMock() diff --git a/distributedcloud/dcmanager/tests/unit/orchestrator/states/upgrade/test_starting_upgrade.py b/distributedcloud/dcmanager/tests/unit/orchestrator/states/upgrade/test_starting_upgrade.py index e73620d36..3689ad587 100644 --- a/distributedcloud/dcmanager/tests/unit/orchestrator/states/upgrade/test_starting_upgrade.py +++ b/distributedcloud/dcmanager/tests/unit/orchestrator/states/upgrade/test_starting_upgrade.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2020 Wind River Systems, Inc. +# Copyright (c) 2020, 2022 Wind River Systems, Inc. # # SPDX-License-Identifier: Apache-2.0 # @@ -38,7 +38,7 @@ class TestSwUpgradeSimplexStartingUpgradeStage(TestSwUpgradeState): # Add the strategy_step state being processed by this unit test self.strategy_step = \ - self.setup_strategy_step(consts.STRATEGY_STATE_STARTING_UPGRADE) + self.setup_strategy_step(self.subcloud.id, consts.STRATEGY_STATE_STARTING_UPGRADE) # Add mock API endpoints for sysinv client calls invoked by this state self.sysinv_client.upgrade_start = mock.MagicMock() diff --git a/distributedcloud/dcmanager/tests/unit/orchestrator/states/upgrade/test_swact_controller.py b/distributedcloud/dcmanager/tests/unit/orchestrator/states/upgrade/test_swact_controller.py index 71204d5f7..6cb3d417f 100644 --- a/distributedcloud/dcmanager/tests/unit/orchestrator/states/upgrade/test_swact_controller.py +++ b/distributedcloud/dcmanager/tests/unit/orchestrator/states/upgrade/test_swact_controller.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2021 Wind River Systems, Inc. +# Copyright (c) 2021-2022 Wind River Systems, Inc. # # SPDX-License-Identifier: Apache-2.0 # @@ -32,7 +32,7 @@ class TestSwUpgradeSwactToController0Stage(TestSwUpgradeState): # Add the strategy_step state being processed by this unit test self.strategy_step = \ - self.setup_strategy_step(self.state) + self.setup_strategy_step(self.subcloud.id, self.state) # Add mock API endpoints for sysinv client calls invoked by this state self.sysinv_client.get_host = mock.MagicMock() diff --git a/distributedcloud/dcmanager/tests/unit/orchestrator/states/upgrade/test_unlock_controller.py b/distributedcloud/dcmanager/tests/unit/orchestrator/states/upgrade/test_unlock_controller.py index d5522f11a..4addc3cd2 100644 --- a/distributedcloud/dcmanager/tests/unit/orchestrator/states/upgrade/test_unlock_controller.py +++ b/distributedcloud/dcmanager/tests/unit/orchestrator/states/upgrade/test_unlock_controller.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2020 Wind River Systems, Inc. +# Copyright (c) 2020, 2022 Wind River Systems, Inc. # # SPDX-License-Identifier: Apache-2.0 # @@ -40,7 +40,7 @@ class TestSwUpgradeUnlockSimplexStage(TestSwUpgradeState): self.subcloud = self.setup_subcloud() # Add the strategy_step state being processed by this unit test - self.strategy_step = self.setup_strategy_step(self.state) + self.strategy_step = self.setup_strategy_step(self.subcloud.id, self.state) self.setup_fake_controllers('controller-0') diff --git a/distributedcloud/dcmanager/tests/unit/orchestrator/states/upgrade/test_updating_patches.py b/distributedcloud/dcmanager/tests/unit/orchestrator/states/upgrade/test_updating_patches.py index 350acbbc1..9f2d84e5b 100644 --- a/distributedcloud/dcmanager/tests/unit/orchestrator/states/upgrade/test_updating_patches.py +++ b/distributedcloud/dcmanager/tests/unit/orchestrator/states/upgrade/test_updating_patches.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2020 Wind River Systems, Inc. +# Copyright (c) 2020, 2022 Wind River Systems, Inc. # # SPDX-License-Identifier: Apache-2.0 # @@ -103,7 +103,7 @@ class TestSwUpgradeUpdatingPatchesStage(TestSwUpgradeState): # Add the strategy_step state being processed by this unit test self.strategy_step = \ - self.setup_strategy_step(consts.STRATEGY_STATE_UPDATING_PATCHES) + self.setup_strategy_step(self.subcloud.id, consts.STRATEGY_STATE_UPDATING_PATCHES) # Add mock API endpoints for patching and sysinv client calls invoked by this state self.patching_client.query = mock.MagicMock() diff --git a/distributedcloud/dcmanager/tests/unit/orchestrator/states/upgrade/test_upgrading_duplex.py b/distributedcloud/dcmanager/tests/unit/orchestrator/states/upgrade/test_upgrading_duplex.py index 83be2e085..28beec5e7 100644 --- a/distributedcloud/dcmanager/tests/unit/orchestrator/states/upgrade/test_upgrading_duplex.py +++ b/distributedcloud/dcmanager/tests/unit/orchestrator/states/upgrade/test_upgrading_duplex.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2020 Wind River Systems, Inc. +# Copyright (c) 2020, 2022 Wind River Systems, Inc. # # SPDX-License-Identifier: Apache-2.0 # @@ -36,7 +36,7 @@ class TestSwUpgradeUpgradingDuplexStage(TestSwUpgradeState): # Add the strategy_step state being processed by this unit test self.strategy_step = \ - self.setup_strategy_step(consts.STRATEGY_STATE_UPGRADING_DUPLEX) + self.setup_strategy_step(self.subcloud.id, consts.STRATEGY_STATE_UPGRADING_DUPLEX) # Add mock API endpoints for sysinv client calls invoked by this state self.sysinv_client.get_host = mock.MagicMock() diff --git a/distributedcloud/dcmanager/tests/unit/orchestrator/states/upgrade/test_upgrading_simplex.py b/distributedcloud/dcmanager/tests/unit/orchestrator/states/upgrade/test_upgrading_simplex.py index ae605f2fd..31dfbac8a 100644 --- a/distributedcloud/dcmanager/tests/unit/orchestrator/states/upgrade/test_upgrading_simplex.py +++ b/distributedcloud/dcmanager/tests/unit/orchestrator/states/upgrade/test_upgrading_simplex.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2020 Wind River Systems, Inc. +# Copyright (c) 2020, 2022 Wind River Systems, Inc. # # SPDX-License-Identifier: Apache-2.0 # @@ -39,7 +39,7 @@ class TestSwUpgradeUpgradingSimplexStage(TestSwUpgradeState): # Add the strategy_step state being processed by this unit test self.strategy_step = \ - self.setup_strategy_step(consts.STRATEGY_STATE_UPGRADING_SIMPLEX) + self.setup_strategy_step(self.subcloud.id, consts.STRATEGY_STATE_UPGRADING_SIMPLEX) # simulate get_vault_load_files finding the iso and sig in the vault p = mock.patch('dcmanager.common.utils.get_vault_load_files') diff --git a/distributedcloud/dcmanager/tests/unit/orchestrator/test_base.py b/distributedcloud/dcmanager/tests/unit/orchestrator/test_base.py index cc3e52242..caafe264d 100644 --- a/distributedcloud/dcmanager/tests/unit/orchestrator/test_base.py +++ b/distributedcloud/dcmanager/tests/unit/orchestrator/test_base.py @@ -192,12 +192,12 @@ class TestSwUpdate(base.DCManagerTestCase): management_state=dccommon_consts.MANAGEMENT_MANAGED, availability_status=dccommon_consts.AVAILABILITY_ONLINE) - def setup_strategy_step(self, strategy_state): + def setup_strategy_step(self, subcloud_id, strategy_state): fake_strategy.create_fake_strategy_step( self.ctx, - subcloud_id=self.subcloud.id, + subcloud_id=subcloud_id, state=strategy_state) - return db_api.strategy_step_get(self.ctx, self.subcloud.id) + return db_api.strategy_step_get(self.ctx, subcloud_id) def assert_step_updated(self, subcloud_id, update_state): step = db_api.strategy_step_get(self.ctx, subcloud_id) diff --git a/distributedcloud/dcmanager/tests/unit/orchestrator/test_fw_orch_thread.py b/distributedcloud/dcmanager/tests/unit/orchestrator/test_fw_orch_thread.py index 554160344..4b1f2a446 100644 --- a/distributedcloud/dcmanager/tests/unit/orchestrator/test_fw_orch_thread.py +++ b/distributedcloud/dcmanager/tests/unit/orchestrator/test_fw_orch_thread.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2020-2021 Wind River Systems, Inc. +# Copyright (c) 2020-2022 Wind River Systems, Inc. # # SPDX-License-Identifier: Apache-2.0 # @@ -74,7 +74,7 @@ class TestFwOrchThread(TestSwUpdate): self.subcloud = self.setup_subcloud() self.setup_strategy_step( - consts.STRATEGY_STATE_CREATING_FW_UPDATE_STRATEGY) + self.subcloud.id, consts.STRATEGY_STATE_CREATING_FW_UPDATE_STRATEGY) # If the subcloud does not have a vim strategy, it raises an exception self.vim_client.get_strategy.side_effect = Exception @@ -108,7 +108,7 @@ class TestFwOrchThread(TestSwUpdate): self.subcloud = self.setup_subcloud() self.setup_strategy_step( - consts.STRATEGY_STATE_CREATING_FW_UPDATE_STRATEGY) + self.subcloud.id, consts.STRATEGY_STATE_CREATING_FW_UPDATE_STRATEGY) # the subcloud returns a vim strategy vim_strategy = FakeVimStrategy(state=vim.STATE_APPLIED) diff --git a/distributedcloud/dcorch/api/controllers/restcomm.py b/distributedcloud/dcorch/api/controllers/restcomm.py index 52d5d34c9..722079c50 100644 --- a/distributedcloud/dcorch/api/controllers/restcomm.py +++ b/distributedcloud/dcorch/api/controllers/restcomm.py @@ -1,4 +1,5 @@ # Copyright (c) 2015 Huawei Tech. Co., Ltd. +# Copyright (c) 2020-2022 Wind River Systems, Inc. # All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may @@ -33,8 +34,8 @@ def extract_context_from_environ(): environ = request.environ - for key in context_paras: - context_paras[key] = environ.get(context_paras[key]) + for key, val in context_paras.items(): + context_paras[key] = environ.get(val) role = environ.get('HTTP_X_ROLE') # context_paras['is_admin'] = role == 'admin' diff --git a/distributedcloud/dcorch/common/context.py b/distributedcloud/dcorch/common/context.py index 67d50c2d6..f05036092 100644 --- a/distributedcloud/dcorch/common/context.py +++ b/distributedcloud/dcorch/common/context.py @@ -1,3 +1,4 @@ +# Copyright (c) 2020-2022 Wind River Systems, Inc. # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at @@ -40,6 +41,7 @@ class RequestContext(base_context.RequestContext): """Initializer of request context.""" # We still have 'tenant' param because oslo_context still use it. + # pylint: disable=E1123 super(RequestContext, self).__init__( auth_token=auth_token, user=user, tenant=project, domain=domain, user_domain=user_domain, diff --git a/distributedcloud/dcorch/common/serializer.py b/distributedcloud/dcorch/common/serializer.py index f13d92594..5e5d58ca8 100644 --- a/distributedcloud/dcorch/common/serializer.py +++ b/distributedcloud/dcorch/common/serializer.py @@ -1,5 +1,5 @@ # Copyright 2015 Huawei Technologies Co., Ltd. -# +# Copyright (c) 2020-2022 Wind River Systems, Inc. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -35,48 +35,48 @@ class DCOrchSerializer(oslo_messaging.Serializer): super(DCOrchSerializer, self).__init__() self._base = base - def serialize_entity(self, context, entity): + def serialize_entity(self, ctxt, entity): if isinstance(entity, dict): for key, value in entity.items(): - entity[key] = self.serialize_entity(context, value) + entity[key] = self.serialize_entity(ctxt, value) elif isinstance(entity, list): for i, item in enumerate(entity): - entity[i] = self.serialize_entity(context, item) + entity[i] = self.serialize_entity(ctxt, item) elif entity in _SINGLETON_MAPPING.direct_mapping: entity = _SINGLETON_MAPPING.direct_mapping[entity] if self._base is not None: - entity = self._base.serialize_entity(context, entity) + entity = self._base.serialize_entity(ctxt, entity) return entity - def deserialize_entity(self, context, entity): + def deserialize_entity(self, ctxt, entity): if isinstance(entity, dict): for key, value in entity.items(): - entity[key] = self.deserialize_entity(context, value) + entity[key] = self.deserialize_entity(ctxt, value) elif isinstance(entity, list): for i, item in enumerate(entity): - entity[i] = self.deserialize_entity(context, item) + entity[i] = self.deserialize_entity(ctxt, item) elif entity in _SINGLETON_MAPPING.reverse_mapping: entity = _SINGLETON_MAPPING.reverse_mapping[entity] if self._base is not None: - entity = self._base.deserialize_entity(context, entity) + entity = self._base.deserialize_entity(ctxt, entity) return entity - def serialize_context(self, context): + def serialize_context(self, ctxt): if self._base is not None: - context = self._base.serialize_context(context) + context = self._base.serialize_context(ctxt) return context - def deserialize_context(self, context): + def deserialize_context(self, ctxt): if self._base is not None: - context = self._base.deserialize_context(context) + context = self._base.deserialize_context(ctxt) return context diff --git a/distributedcloud/dcorch/common/utils.py b/distributedcloud/dcorch/common/utils.py index 96afc4e77..6965c88d6 100644 --- a/distributedcloud/dcorch/common/utils.py +++ b/distributedcloud/dcorch/common/utils.py @@ -150,7 +150,7 @@ def enqueue_work(context, endpoint_type, rsrc = resource.Resource.get_by_type_and_master_id( context, resource_type, source_resource_id) LOG.info("Resource already in DB {}/{}/{}/{}".format( - rsrc.id, resource_type, source_resource_id, operation_type)) + rsrc.id, resource_type, source_resource_id, operation_type)) # pylint: disable=E1101 except Exception as e: LOG.exception(e) return @@ -168,6 +168,7 @@ def enqueue_work(context, endpoint_type, rsrc.create() # todo: user_id and project_id are not used, to be removed from model + # pylint: disable=E1101 orch_job = orchjob.OrchJob( context=context, user_id='', project_id='', endpoint_type=endpoint_type, source_resource_id=source_resource_id, @@ -185,4 +186,4 @@ def enqueue_work(context, endpoint_type, orch_job_id=orch_job.id) # pylint: disable=E1101 orch_req.create() LOG.info("Work order created for {}:{}/{}/{}/{}".format( - subcloud, rsrc.id, resource_type, source_resource_id, operation_type)) + subcloud, rsrc.id, resource_type, source_resource_id, operation_type)) # pylint: disable=E1101 diff --git a/distributedcloud/dcorch/db/utils.py b/distributedcloud/dcorch/db/utils.py index e8a9bed6f..40c7e0cc2 100644 --- a/distributedcloud/dcorch/db/utils.py +++ b/distributedcloud/dcorch/db/utils.py @@ -1,4 +1,5 @@ # Copyright (c) 2015 Ericsson AB. +# Copyright (c) 2020-2022 Wind River Systems, Inc. # All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may @@ -13,6 +14,10 @@ # License for the specific language governing permissions and limitations # under the License. +from oslo_config import cfg + +CONF = cfg.CONF + class LazyPluggable(object): """A pluggable backend loaded lazily based on some value.""" @@ -24,7 +29,7 @@ class LazyPluggable(object): def __get_backend(self): if not self.__backend: - backend_name = 'sqlalchemy' + backend_name = CONF[self.__pivot] backend = self.__backends[backend_name] if isinstance(backend, tuple): name = backend[0] diff --git a/distributedcloud/dcorch/drivers/base.py b/distributedcloud/dcorch/drivers/base.py index a91962f56..6548f9f3d 100644 --- a/distributedcloud/dcorch/drivers/base.py +++ b/distributedcloud/dcorch/drivers/base.py @@ -1,3 +1,4 @@ +# Copyright (c) 2020-2022 Wind River Systems, Inc. # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at diff --git a/distributedcloud/dcorch/drivers/openstack/nova_v2.py b/distributedcloud/dcorch/drivers/openstack/nova_v2.py index a353fc426..027c92cdd 100644 --- a/distributedcloud/dcorch/drivers/openstack/nova_v2.py +++ b/distributedcloud/dcorch/drivers/openstack/nova_v2.py @@ -88,7 +88,11 @@ class NovaClient(base.DriverBase): except exceptions.InternalError: raise - def update_quota_limits(self, project_id, user_id, **new_quota): + # Since additional parameter variables are added on top of abc class previously defined + # Pylint will raise a warning (W0237) saying parameter got renamed. Added suppress to ignore + # Since alarm W0237 was not introduced until pylint 2.1x, the CentOS pylint (running 2.3) will + # raise an alarm (E0012) on W0237 suggesting it is invalid, Another suppress is added for E0012 + def update_quota_limits(self, project_id, user_id, **new_quota): # pylint: disable=E0012,W0237 """Update quota limits for a given project. :params: project_id, dictionary with the quota limits to update diff --git a/distributedcloud/dcorch/engine/generic_sync_manager.py b/distributedcloud/dcorch/engine/generic_sync_manager.py index d1a89716f..da280f7d8 100644 --- a/distributedcloud/dcorch/engine/generic_sync_manager.py +++ b/distributedcloud/dcorch/engine/generic_sync_manager.py @@ -159,10 +159,6 @@ class GenericSyncManager(object): LOG.debug('Engine id:(%s): All subcloud syncs have completed.' % engine_id) - def _get_endpoint_sync_request(self, subcloud_name, endpoint_type): - sc = subcloud.Subcloud.get_by_name(self.context, subcloud_name) - return sc.sync_request.get(endpoint_type) - @subcloud_lock.sync_subcloud def mutex_start_thread(self, context, engine_id, subcloud_name, endpoint_type, action): @@ -413,7 +409,7 @@ class GenericSyncManager(object): # create the subcloud_sync !!! db_api.subcloud_sync_create( context, subcloud_name, endpoint_type, - values={'subcloud_id': sc.id}) + values={'subcloud_id': sc.id}) # pylint: disable=E1101 if self.is_subcloud_ready(subcloud_name): sync_obj.enable() diff --git a/distributedcloud/dcorch/engine/sync_services/compute.py b/distributedcloud/dcorch/engine/sync_services/compute.py index dbeded466..af26af8d3 100644 --- a/distributedcloud/dcorch/engine/sync_services/compute.py +++ b/distributedcloud/dcorch/engine/sync_services/compute.py @@ -1,5 +1,5 @@ -# Copyright 2017-2018 Wind River -# +# Copyright 2017-2018, 2022 Wind River + # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -399,37 +399,37 @@ class ComputeSyncThread(SyncThread): f1.is_public == f2.is_public and f1.ephemeral == f2.ephemeral) - def audit_dependants(self, resource_type, m_flavor, sc_flavor): + def audit_dependants(self, resource_type, m_resource, sc_resource): num_of_audit_jobs = 0 if not self.is_subcloud_enabled() or self.should_exit(): return num_of_audit_jobs if resource_type == consts.RESOURCE_TYPE_COMPUTE_FLAVOR: num_of_audit_jobs += self.audit_flavor_access( - resource_type, m_flavor, sc_flavor) + resource_type, m_resource, sc_resource) num_of_audit_jobs += self.audit_extra_specs( - resource_type, m_flavor, sc_flavor) + resource_type, m_resource, sc_resource) return num_of_audit_jobs - def audit_flavor_access(self, resource_type, m_flavor, sc_flavor): + def audit_flavor_access(self, resource_type, m_resource, sc_resource): num_of_audit_jobs = 0 sc_fa_attachment = [] # Subcloud flavor-access attachment - if sc_flavor: - sc_fa_attachment = sc_flavor.attach_fa + if sc_resource: + sc_fa_attachment = sc_resource.attach_fa # Flavor-access needs to be audited. flavor-access details are # filled in m_resources and sc_resources during query. - for m_fa in m_flavor.attach_fa: + for m_fa in m_resource.attach_fa: found = False for sc_fa in sc_fa_attachment: if m_fa.tenant_id == sc_fa.tenant_id: found = True - sc_flavor.attach_fa.remove(sc_fa) + sc_resource.attach_fa.remove(sc_fa) break if not found: action_dict = { consts.ACTION_ADDTENANTACCESS: {"tenant": m_fa.tenant_id}} self.schedule_work( - self.endpoint_type, resource_type, m_flavor.id, + self.endpoint_type, resource_type, m_resource.id, consts.OPERATION_TYPE_ACTION, jsonutils.dumps(action_dict)) num_of_audit_jobs += 1 @@ -438,19 +438,19 @@ class ComputeSyncThread(SyncThread): action_dict = { consts.ACTION_REMOVETENANTACCESS: {"tenant": sc_fa.tenant_id}} self.schedule_work( - self.endpoint_type, resource_type, m_flavor.id, + self.endpoint_type, resource_type, m_resource.id, consts.OPERATION_TYPE_ACTION, jsonutils.dumps(action_dict)) num_of_audit_jobs += 1 return num_of_audit_jobs - def audit_extra_specs(self, resource_type, m_flavor, sc_flavor): + def audit_extra_specs(self, resource_type, m_flavor, sc_resource): num_of_audit_jobs = 0 sc_es_attachment = {} # Subcloud extra-spec attachment - if sc_flavor: - # sc_flavor could be None. - sc_es_attachment = sc_flavor.attach_es + if sc_resource: + # sc_resource could be None. + sc_es_attachment = sc_resource.attach_es # Extra-spec needs to be audited. Extra-spec details are # filled in m_resources and sc_resources during query. @@ -550,6 +550,7 @@ class ComputeSyncThread(SyncThread): subcloud_rsrc.delete() # Master Resource can be deleted only when all subcloud resources # are deleted along with corresponding orch_job and orch_requests. + # pylint: disable=E1101 LOG.info("Keypair {}:{} [{}] deleted".format(rsrc.id, subcloud_rsrc.id, log_str), extra=self.log_extra) diff --git a/distributedcloud/dcorch/engine/sync_services/identity.py b/distributedcloud/dcorch/engine/sync_services/identity.py index 4061606e4..02077a6de 100644 --- a/distributedcloud/dcorch/engine/sync_services/identity.py +++ b/distributedcloud/dcorch/engine/sync_services/identity.py @@ -1377,6 +1377,7 @@ class IdentitySyncThread(SyncThread): # Master Resource can be deleted only when all subcloud resources # are deleted along with corresponding orch_job and orch_requests. + # pylint: disable=E1101 LOG.info("Keystone token revocation event {}:{} [{}] deleted" .format(rsrc.id, revoke_event_subcloud_rsrc.id, revoke_event_subcloud_rsrc.subcloud_resource_id), @@ -1451,6 +1452,7 @@ class IdentitySyncThread(SyncThread): # Master Resource can be deleted only when all subcloud resources # are deleted along with corresponding orch_job and orch_requests. + # pylint: disable=E1101 LOG.info("Keystone token revocation event {}:{} [{}] deleted" .format(rsrc.id, revoke_event_subcloud_rsrc.id, revoke_event_subcloud_rsrc.subcloud_resource_id), diff --git a/distributedcloud/dcorch/engine/sync_services/network.py b/distributedcloud/dcorch/engine/sync_services/network.py index 3ad5c4a97..1bf0a74d4 100644 --- a/distributedcloud/dcorch/engine/sync_services/network.py +++ b/distributedcloud/dcorch/engine/sync_services/network.py @@ -1,4 +1,4 @@ -# Copyright 2017-2018 Wind River +# Copyright 2017-2018, 2022 Wind River # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -208,6 +208,7 @@ class NetworkSyncThread(SyncThread): subcloud_rsrc.delete() # Master Resource can be deleted only when all subcloud resources # are deleted along with corresponding orch_job and orch_requests. + # pylint: disable=E1101 LOG.info("Security group {}:{} [{}] deleted" .format(rsrc.id, subcloud_rsrc.id, subcloud_rsrc.subcloud_resource_id), @@ -265,6 +266,7 @@ class NetworkSyncThread(SyncThread): subcloud_rsrc.delete() # Master Resource can be deleted only when all subcloud resources # are deleted along with corresponding orch_job and orch_requests. + # pylint: disable=E1101 LOG.info("Security group rule {}:{} [{}] deleted" .format(rsrc.id, subcloud_rsrc.id, subcloud_rsrc.subcloud_resource_id), @@ -391,7 +393,7 @@ class NetworkSyncThread(SyncThread): self.ctxt, consts.RESOURCE_TYPE_NETWORK_SECURITY_GROUP, master_sec_group_id) sec_group_subcloud_rsrc = self.get_db_subcloud_resource( - sec_group_rsrc.id) + sec_group_rsrc.id) # pylint: disable=E1101 if sec_group_subcloud_rsrc: m_r['security_group_id'] = \ sec_group_subcloud_rsrc.subcloud_resource_id @@ -401,7 +403,7 @@ class NetworkSyncThread(SyncThread): "cannot find equivalent security group in subcloud." .format(m_r), extra=self.log_extra) raise exceptions.SubcloudResourceNotFound( - resource=sec_group_rsrc.id) + resource=sec_group_rsrc.id) # pylint: disable=E1101 if m_r.get('remote_group_id') is not None: # If the remote group id is in the dict then it is for the @@ -413,7 +415,7 @@ class NetworkSyncThread(SyncThread): self.ctxt, consts.RESOURCE_TYPE_NETWORK_SECURITY_GROUP, master_remote_group_id) remote_group_subcloud_rsrc = self.get_db_subcloud_resource( - remote_group_rsrc.id) + remote_group_rsrc.id) # pylint: disable=E1101 if remote_group_subcloud_rsrc: m_r['remote_group_id'] = \ remote_group_subcloud_rsrc.subcloud_resource_id @@ -423,7 +425,7 @@ class NetworkSyncThread(SyncThread): "cannot find equivalent remote group in subcloud." .format(m_r), extra=self.log_extra) raise exceptions.SubcloudResourceNotFound( - resource=sec_group_rsrc.id) + resource=sec_group_rsrc.id) # pylint: disable=E1101 return m_r # This will only be called by the audit code. diff --git a/distributedcloud/dcorch/engine/sync_thread.py b/distributedcloud/dcorch/engine/sync_thread.py index a02a112dc..0f7847957 100644 --- a/distributedcloud/dcorch/engine/sync_thread.py +++ b/distributedcloud/dcorch/engine/sync_thread.py @@ -206,7 +206,7 @@ class SyncThread(object): subcloud_rsrc = \ subcloud_resource.SubcloudResource. \ get_by_resource_and_subcloud( - self.ctxt, rsrc_id, subcloud.id) + self.ctxt, rsrc_id, subcloud.id) # pylint: disable=E1101 return subcloud_rsrc except exceptions.SubcloudResourceNotFound: LOG.info("{} not found in subcloud {} resource table".format( @@ -228,7 +228,7 @@ class SyncThread(object): subcloud_rsrc = subcloud_resource.SubcloudResource( self.ctxt, subcloud_resource_id=subcloud_rsrc_id, resource_id=db_rsrc_id, - subcloud_id=subcloud.id) + subcloud_id=subcloud.id) # pylint: disable=E1101 # There is no race condition for creation of # subcloud_resource as it is always done from the same thread. subcloud_rsrc.create() @@ -250,6 +250,7 @@ class SyncThread(object): def sync_resource(self, sync_request): rsrc = resource.Resource.get_by_id(self.ctxt, sync_request.orch_job.resource_id) + # pylint: disable=E1101 handler = self.sync_handler_map[rsrc.resource_type] LOG.info("{} Invoking {} for {} [{}]".format( self.engine_id, handler.__name__, rsrc.resource_type, diff --git a/distributedcloud/dcorch/objects/service.py b/distributedcloud/dcorch/objects/service.py index aea99dfb1..0297cc5b3 100644 --- a/distributedcloud/dcorch/objects/service.py +++ b/distributedcloud/dcorch/objects/service.py @@ -1,4 +1,5 @@ # Copyright (c) 2015 Ericsson AB. +# Copyright (c) 2020-2022 Wind River Systems, Inc. # All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may @@ -53,8 +54,14 @@ class Service(base.OrchestratorObject, base.VersionedObjectDictCompat): objs = db_api.service_get_all(context) return [cls._from_db_object(context, cls(), obj) for obj in objs] + # A function named update has been defined inside the base class (oslo_versionedobjects) + # which was defined with different parameters and served a different purpose + # Pylint was not able to distinguish the two thus raised an warning (W0237) suggesting + # undesired parameter name change. Added suppress to ignore this check + # Since alarm W0237 was not introduced until pylint 2.1x, the CentOS pylint (running 2.3) will + # raise an alarm (E0012) on W0237 suggesting it is invalid, Another suppress is added for E0012 @classmethod - def update(cls, context, obj_id, values=None): + def update(cls, context, obj_id, values=None): # pylint: disable=E0012,W0237 obj = db_api.service_update(context, obj_id, values=values) return cls._from_db_object(context, cls(), obj) diff --git a/distributedcloud/dcorch/tests/unit/db/test_orch_request_db_api.py b/distributedcloud/dcorch/tests/unit/db/test_orch_request_db_api.py index c2c6293db..e5e30523a 100644 --- a/distributedcloud/dcorch/tests/unit/db/test_orch_request_db_api.py +++ b/distributedcloud/dcorch/tests/unit/db/test_orch_request_db_api.py @@ -87,9 +87,6 @@ class DBAPIOrchRequestTest(base.OrchestratorTestCase): operation_type, values=None): if values is None: values = {} - endpoint_type = endpoint_type - operation_type = operation_type - values = values orch_job = db_api.orch_job_create(ctxt, resource_id, endpoint_type,