Skip to content
This repository has been archived by the owner on Feb 8, 2024. It is now read-only.

CORTX-33159: Codacy Fix #882

Merged
merged 4 commits into from
Aug 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions csm/common/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def __init__(self, inventory_file, ha_framework):
sw_components = self._inventory[node_type][const.KEY_COMPONENTS]
admin_user = self._inventory[node_type][const.ADMIN_USER]
for node_id in self._inventory[node_type][const.KEY_NODES]:
if node_id not in self._node_list.keys():
if node_id not in self._node_list:
node = Node(node_id, node_type, sw_components, admin_user)
self._node_list[node_id] = node

Expand All @@ -131,15 +131,15 @@ def init(self, force_flag):
def node_list(self, node_type=None):
"""Get nodes of specified type."""
if node_type is None:
return [self._node_list[x] for x in self._node_list.keys()]
return [self._node_list[x] for x in self._node_list.keys()
return [self._node_list[x] for x in self._node_list]
return [self._node_list[x] for x in self._node_list
if self._node_list[x].node_type() == node_type]

def host_list(self, node_type=None):
"""Get the list of all SSUs in the cluster."""
if node_type is None:
return [self._node_list[x].host_name() for x in self._node_list.keys()]
return [self._node_list[x].host_name() for x in self._node_list.keys()
return [self._node_list[x].host_name() for x in self._node_list]
return [self._node_list[x].host_name() for x in self._node_list
if self._node_list[x].node_type() == node_type]

def sw_components(self, node_type):
Expand All @@ -149,7 +149,7 @@ def sw_components(self, node_type):
def active_node_list(self):
"""Get all the active nodes in the cluster."""
# TODO - Scan the list and identify reachable nodes
return [self._node_list[x] for x in self._node_list.keys()
return [self._node_list[x] for x in self._node_list
if self._node_list[x].is_active()]

def state(self):
Expand Down
4 changes: 2 additions & 2 deletions csm/common/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def init():
def load(index, doc, force=False):
if not os.path.isfile(doc):
raise CsmError(-1, f'File {doc} does not exist')
if index in Conf._payloads.keys():
if index in Conf._payloads:
if not force:
raise Exception(f'index {index} is already loaded')
Conf.save(index)
Expand Down Expand Up @@ -67,7 +67,7 @@ def delete(index, key):

@staticmethod
def save(index=None):
indexes = [x for x in Conf._payloads.keys()] if index is None else [index]
indexes = [x for x in Conf._payloads] if index is None else [index]
for index in indexes:
Conf._payloads[index].dump()

Expand Down
8 changes: 4 additions & 4 deletions csm/common/fs_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,21 +135,21 @@ def __init__(self, thread_pool_exec: ThreadPoolExecutor = None,
if thread_pool_exec is None else thread_pool_exec)
self._loop = asyncio.get_event_loop() if loop is None else loop

async def make_archive(self, base_name, format=ArchiveFormats.GZTAR.value,
async def make_archive(self, base_name, _format=ArchiveFormats.GZTAR.value,
root_dir=None, base_dir=None):

def _make_archive(_base_name, _format, _root_dir, _base_dir):
# imported function validates correctness/existence of archive and directories itself
make_archive(base_name=_base_name, format=_format,
root_dir=_root_dir, base_dir=_base_dir)
await self._loop.run_in_executor(self._pool, _make_archive,
base_name, format, root_dir, base_dir)
base_name, _format, root_dir, base_dir)

async def unpack_archive(self, filename, extract_dir=None, format=None):
async def unpack_archive(self, filename, extract_dir=None, _format=None):

def _unpack_archive(_filename, _extract_dir, _format):
# imported function validates correctness/existence of archive and directories itself
unpack_archive(filename=_filename, extract_dir=_extract_dir, format=_format)

await self._loop.run_in_executor(self._pool, _unpack_archive,
filename, extract_dir, format)
filename, extract_dir, _format)
12 changes: 6 additions & 6 deletions csm/common/timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,10 @@ def init(self):
def _parse(self, nodes, panel, output):
for node in nodes:
if isinstance(node["val"], str):
if node["val"] in self._metric_set.keys():
if node["val"] in self._metric_set:
output = self._parse(node["node"], panel, output)
output = "(" + output + ")." + self._metric_set[node["val"]]
elif node["val"] in self._config_list.keys():
elif node["val"] in self._config_list:
cv = self._config_list[node["val"]]
if cv is None:
raise CsmInternalError('Can not load config parameter "%s"' % node["val"])
Expand Down Expand Up @@ -221,7 +221,7 @@ async def get_all_units(self):
if st not in mu:
mu.append(st)
if panel == "throughput":
for sz in self._SIZE_DIV.keys():
for sz in self._SIZE_DIV:
st = (str(panel) + '.' + str(metric.get('name')) + '.' + str(sz))
if st not in mu:
mu.append(st)
Expand All @@ -239,7 +239,7 @@ async def _get_metric_list(self, panel, metric_list, unit):
unit_li = unit
if len(metric_list) == 0:
metric_list = list(await self.get_labels(panel))
for i in range(0, len(metric_list)):
for i, _ in enumerate(metric_list):
if metric_list[i] not in aggr_panel:
raise CsmInternalError("Invalid label %s for %s" % (metric_list[i], panel))
if isinstance(unit, list):
Expand Down Expand Up @@ -367,7 +367,7 @@ async def _convert_payload(self, res, stats_id, panel, output_format, units):
res_payload['stats'] = panel
if "sheet" in timelion_payload:
data_list = timelion_payload["sheet"][0]["list"]
for i in range(0, len(data_list)):
for i, _ in enumerate(data_list):
datapoint = await self._modify_panel_val(data_list[i]["data"], panel, units[i])
if output_format == "gui":
datapoint = await self._get_list(datapoint)
Expand Down Expand Up @@ -398,7 +398,7 @@ async def _modify_throughput(self, datapoint, unit):
Modify throughput with unit
"""
li = []
if unit not in self._SIZE_DIV.keys():
if unit not in self._SIZE_DIV:
raise CsmInternalError("Invalid unit for stats %s" % unit)
unit_val = self._SIZE_DIV[unit]
for point in datapoint:
Expand Down
9 changes: 4 additions & 5 deletions csm/conf/configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import os
# from cortx.utils.product_features import unsupported_features
from marshmallow.exceptions import ValidationError
from csm.common.payload import Json
from csm.common.service_urls import ServiceUrls
from cortx.utils.log import Log
from cortx.utils.conf_store.conf_store import Conf
Expand Down Expand Up @@ -68,7 +67,7 @@ async def execute(self, command):
services = ["agent"]
else:
services=[services]
if not "agent" in services:
if "agent" not in services:
return Response(output=const.CSM_SETUP_PASS, rc=CSM_OPERATION_SUCESSFUL)
self._prepare_and_validate_confstore_keys()

Expand Down Expand Up @@ -142,7 +141,7 @@ def create(self):
def _set_csm_endpoint():
Log.info("Config: Setting CSM endpoint in configuration.")
csm_endpoint = Conf.get(const.CONSUMER_INDEX, const.CSM_AGENT_ENDPOINTS_KEY)
csm_protocol, csm_host, csm_port = ServiceUrls.parse_url(csm_endpoint)
csm_protocol, _, csm_port = ServiceUrls.parse_url(csm_endpoint)
Conf.set(const.CSM_GLOBAL_INDEX, const.AGENT_ENDPOINTS, csm_endpoint)
# Not considering Hostname. Bydefault 0.0.0.0 used
# Conf.set(const.CSM_GLOBAL_INDEX, const.AGENT_HOST, csm_host)
Expand Down Expand Up @@ -275,7 +274,7 @@ def _create_perf_stat_topic(mb_admin):
partitions = int(Conf.get(const.CSM_GLOBAL_INDEX,const.MSG_BUS_PERF_STAT_PARTITIONS))
retention_size = int(Conf.get(const.CSM_GLOBAL_INDEX,const.MSG_BUS_PERF_STAT_RETENTION_SIZE))
retention_period = int(Conf.get(const.CSM_GLOBAL_INDEX,const.MSG_BUS_PERF_STAT_RETENTION_PERIOD))
if not message_type in mb_admin.list_message_types():
if message_type not in mb_admin.list_message_types():
Log.info(f"Config: Registering message_type:{message_type}")
mb_admin.register_message_type(message_types=[message_type], partitions=partitions)
mb_admin.set_message_type_expire(message_type,
Expand All @@ -291,7 +290,7 @@ def _create_cluster_stop_topic(mb_admin):
partitions = int(Conf.get(const.CSM_GLOBAL_INDEX,const.MSG_BUS_CLUSTER_STOP_PARTITIONS))
retention_size = int(Conf.get(const.CSM_GLOBAL_INDEX,const.MSG_BUS_CLUSTER_STOP_RETENTION_SIZE))
retention_period = int(Conf.get(const.CSM_GLOBAL_INDEX,const.MSG_BUS_CLUSTER_STOP_RETENTION_PERIOD))
if not message_type in mb_admin.list_message_types():
if message_type not in mb_admin.list_message_types():
Log.info(f"Config: Registering message_type:{message_type}")
mb_admin.register_message_type(message_types=[message_type], partitions=partitions)
mb_admin.set_message_type_expire(message_type,
Expand Down
12 changes: 2 additions & 10 deletions csm/conf/csm_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,23 +65,15 @@ def process(self):
response=response)

if __name__ == '__main__':


sys.path.append(os.path.join(os.path.dirname(pathlib.Path(__file__)), '..', '..'))
sys.path.append(os.path.join(os.path.dirname(pathlib.Path(os.path.realpath(__file__))), '..', '..'))
from cortx.utils.conf_store.conf_store import Conf
from csm.common.payload import Json
from cortx.utils.cli_framework.parser import CommandParser
from csm.core.blogic import const
from cortx.utils.cli_framework.client import CliClient
from csm.conf.post_install import PostInstall
from csm.conf.prepare import Prepare
from csm.conf.configure import Configure
from csm.conf.init import Init
from csm.conf.reset import Reset
from csm.conf.test import Test
from csm.conf.upgrade import Upgrade
from csm.conf.pre_upgrade import PreUpgrade
from csm.conf.post_upgrade import PostUpgrade
from csm.conf.cleanup import Cleanup

try:
csm_setup = CsmSetupCommand(sys.argv)
Expand Down
2 changes: 1 addition & 1 deletion csm/conf/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ async def execute(self, command):
services = ["agent"]
else:
services=[services]
if not "agent" in services:
if "agent" not in services:
return Response(output=const.CSM_SETUP_PASS, rc=CSM_OPERATION_SUCESSFUL)
Log.info("Init: Successfully passed Init phase.")
return Response(output=const.CSM_SETUP_PASS, rc=CSM_OPERATION_SUCESSFUL)
2 changes: 1 addition & 1 deletion csm/conf/post_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ async def execute(self, command):
services = ["agent"]
else:
services=[services]
if not "agent" in services:
if "agent" not in services:
return Response(output=const.CSM_SETUP_PASS, rc=CSM_OPERATION_SUCESSFUL)

self._prepare_and_validate_confstore_keys()
Expand Down
2 changes: 1 addition & 1 deletion csm/conf/prepare.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ async def execute(self, command):
services = ["agent"]
else:
services=[services]
if not "agent" in services:
if "agent" not in services:
return Response(output=const.CSM_SETUP_PASS, rc=CSM_OPERATION_SUCESSFUL)

self._prepare_and_validate_confstore_keys()
Expand Down
Loading