diff --git a/cmapi/cmapi_server/helpers.py b/cmapi/cmapi_server/helpers.py index a899e3ee6..e022d3503 100644 --- a/cmapi/cmapi_server/helpers.py +++ b/cmapi/cmapi_server/helpers.py @@ -11,7 +11,6 @@ import os import socket import time from collections import namedtuple -from functools import partial from random import random from shutil import copyfile from typing import Tuple, Optional @@ -603,11 +602,6 @@ def get_dbroots(node, config=DEFAULT_MCS_CONF_PATH): smc_node.find(f"./ModuleDBRootID{i}-{j}-3").text ) - if dbroots and nc.is_read_only(): - logger = logging.getLogger('dbroots') - logger.warning(f'Config contains dbroots {dbroots} for this read-only node, ignoring') - return [] - return dbroots diff --git a/cmapi/cmapi_server/node_manipulation.py b/cmapi/cmapi_server/node_manipulation.py index 0a3f4c4c7..4c2e2ff1d 100644 --- a/cmapi/cmapi_server/node_manipulation.py +++ b/cmapi/cmapi_server/node_manipulation.py @@ -398,7 +398,7 @@ def _remove_node(root, node): for n in (root.find("./DesiredNodes"), root.find("./InactiveNodes"), root.find("./ActiveNodes")): __remove_helper(n, node) - read_only_nodes = root.find("./ReadOnlyNodes") + read_only_nodes = root.find('./ReadOnlyNodes') if read_only_nodes is not None: __remove_helper(read_only_nodes, node) @@ -1015,11 +1015,11 @@ def _add_WES(root, pm_num, node): etree.SubElement(wes_node, "Port").text = "8630" -def _add_read_only_node(root, node) -> None: - """Add node name to ReadOnlyNodes if it's not already there""" - read_only_nodes = root.find("./ReadOnlyNodes") +def _add_read_only_node(root: etree.Element, node: str) -> None: + '''Add node name to ReadOnlyNodes if it is not already there''' + read_only_nodes = root.find('./ReadOnlyNodes') if read_only_nodes is None: - read_only_nodes = etree.SubElement(root, "ReadOnlyNodes") + read_only_nodes = etree.SubElement(root, 'ReadOnlyNodes') else: for n in read_only_nodes.findall("./Node"): if n.text == node: diff --git a/cmapi/cmapi_server/test/test_node_manip.py b/cmapi/cmapi_server/test/test_node_manip.py index d52953ed5..195c28649 100644 --- a/cmapi/cmapi_server/test/test_node_manip.py +++ b/cmapi/cmapi_server/test/test_node_manip.py @@ -1,7 +1,7 @@ import logging import socket import unittest -from unittest.mock import patch +from unittest.mock import patch, ANY from lxml import etree from cmapi_server import node_manipulation @@ -97,7 +97,7 @@ class NodeManipTester(BaseNodeManipTestCase): mock_rebalance_dbroots.assert_not_called() mock_move_primary_node.assert_not_called() - mock_add_dbroots_of_other_nodes.assert_called_once_with(root, 2) + mock_add_dbroots_of_other_nodes.assert_called_once_with(ANY, 2) # Test read-only node removal node_manipulation.remove_node( @@ -111,7 +111,7 @@ class NodeManipTester(BaseNodeManipTestCase): mock_rebalance_dbroots.assert_not_called() mock_move_primary_node.assert_not_called() - mock_remove_dbroots_of_node.assert_called_once_with(root, 2) + mock_remove_dbroots_of_node.assert_called_once_with(ANY, 2) def test_add_dbroots_nodes_rebalance(self): diff --git a/cmapi/mcs_node_control/models/node_config.py b/cmapi/mcs_node_control/models/node_config.py index 2943d4c98..c71e39703 100644 --- a/cmapi/mcs_node_control/models/node_config.py +++ b/cmapi/mcs_node_control/models/node_config.py @@ -567,11 +567,6 @@ has dbroot {subel.text}') for j in range(1, int(smc_node.find(f"./ModuleDBRootCount{i}-3").text) + 1): dbroots.append(smc_node.find(f"./ModuleDBRootID{i}-{j}-3").text) - # TODO not sure about it - if dbroots and self.is_read_only(root): - module_logger.warning("Config contains dbroots %s for this read-only node, ignoring", dbroots) - return [] - return dbroots def is_read_only(self, root=None) -> bool: diff --git a/cmapi/pyproject.toml b/cmapi/pyproject.toml new file mode 100644 index 000000000..c81c64faa --- /dev/null +++ b/cmapi/pyproject.toml @@ -0,0 +1,22 @@ +[tool.ruff] +line-length = 80 +target-version = "py39" +# Enable common rule sets +select = [ + "E", # pycodestyle errors + "F", # pyflakes: undefined names, unused imports, etc. + "I", # isort: import sorting + "B", # flake8-bugbear: common bugs and anti-patterns + "UP", # pyupgrade: use modern Python syntax + "N", # pep8-naming: naming conventions +] + +ignore = [] + +# Exclude cache and temporary directories +exclude = [ + "__pycache__", +] + +[tool.ruff.format] +quote-style = "single"