Merge "Minor Code Change Based on Py39 Pylint Feedback"

This commit is contained in:
Zuul 2022-08-10 20:52:16 +00:00 committed by Gerrit Code Review
commit 9e57f0fe25
50 changed files with 164 additions and 138 deletions

View File

@ -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(',')

View File

@ -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,

View File

@ -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)

View File

@ -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]

View File

@ -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(',')

View File

@ -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,

View File

@ -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

View File

@ -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]

View File

@ -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()

View File

@ -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()

View File

@ -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()

View File

@ -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()

View File

@ -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()

View File

@ -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

View File

@ -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()

View File

@ -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()

View File

@ -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):

View File

@ -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()

View File

@ -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()

View File

@ -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()

View File

@ -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()

View File

@ -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()

View File

@ -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()

View File

@ -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(

View File

@ -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()

View File

@ -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()

View File

@ -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()

View File

@ -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()

View File

@ -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()

View File

@ -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()

View File

@ -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')

View File

@ -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()

View File

@ -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()

View File

@ -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')

View File

@ -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)

View File

@ -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)

View File

@ -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'

View File

@ -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,

View File

@ -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

View File

@ -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

View File

@ -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]

View File

@ -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

View File

@ -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

View File

@ -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()

View File

@ -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)

View File

@ -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),

View File

@ -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.

View File

@ -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,

View File

@ -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)

View File

@ -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,