diff --git a/csm/common/cluster.py b/csm/common/cluster.py index 187770c99..e01116b19 100644 --- a/csm/common/cluster.py +++ b/csm/common/cluster.py @@ -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 @@ -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): @@ -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): diff --git a/csm/common/conf.py b/csm/common/conf.py index cbdf822a4..89f6bfbf4 100644 --- a/csm/common/conf.py +++ b/csm/common/conf.py @@ -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) @@ -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() diff --git a/csm/common/fs_utils.py b/csm/common/fs_utils.py index ef94c9c86..5be9b2537 100644 --- a/csm/common/fs_utils.py +++ b/csm/common/fs_utils.py @@ -135,7 +135,7 @@ 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): @@ -143,13 +143,13 @@ def _make_archive(_base_name, _format, _root_dir, _base_dir): 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) diff --git a/csm/common/timeseries.py b/csm/common/timeseries.py index b5bd74116..44c1563fe 100644 --- a/csm/common/timeseries.py +++ b/csm/common/timeseries.py @@ -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"]) @@ -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) @@ -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): @@ -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) @@ -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: diff --git a/csm/conf/configure.py b/csm/conf/configure.py index 302c3d072..157bec131 100644 --- a/csm/conf/configure.py +++ b/csm/conf/configure.py @@ -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 @@ -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() @@ -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) @@ -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, @@ -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, diff --git a/csm/conf/csm_setup.py b/csm/conf/csm_setup.py index 31f18c65d..0d176dc5b 100755 --- a/csm/conf/csm_setup.py +++ b/csm/conf/csm_setup.py @@ -65,6 +65,8 @@ 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 @@ -72,16 +74,6 @@ def process(self): 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) diff --git a/csm/conf/init.py b/csm/conf/init.py index b3c81424c..a7817e785 100644 --- a/csm/conf/init.py +++ b/csm/conf/init.py @@ -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) diff --git a/csm/conf/post_install.py b/csm/conf/post_install.py index 7917239c0..34f19601e 100644 --- a/csm/conf/post_install.py +++ b/csm/conf/post_install.py @@ -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() diff --git a/csm/conf/prepare.py b/csm/conf/prepare.py index 4a5c4d9da..88b1dcd1d 100644 --- a/csm/conf/prepare.py +++ b/csm/conf/prepare.py @@ -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() diff --git a/csm/core/agent/api.py b/csm/core/agent/api.py index ee6c7dde2..bf47c3c00 100644 --- a/csm/core/agent/api.py +++ b/csm/core/agent/api.py @@ -36,8 +36,6 @@ from cortx.utils.conf_store.conf_store import Conf from csm.common.conf import ConfSection, DebugConf from cortx.utils.log import Log -from cortx.utils.product_features import unsupported_features -from csm.common.payload import Json from csm.core.blogic import const from csm.common.errors import (CsmError, CsmNotFoundError, CsmPermissionDenied, CsmInternalError, InvalidRequest, ResourceExist, @@ -48,7 +46,6 @@ from csm.core.services.file_transfer import DownloadFileEntity from csm.core.controllers.view import CsmView, CsmAuth, CsmHttpException from csm.core.controllers.routes import CsmRoutes -import re from cortx.utils.errors import DataAccessError from marshmallow import ValidationError, fields from csm.core.controllers.validators import ValidateSchema @@ -85,7 +82,7 @@ def process_request(command, request: Request, callback=None): Log.info('command=%s action=%s args=%s' % (command, request.action(), request.args())) - if command not in CsmApi._providers.keys(): + if command not in CsmApi._providers: CsmApi._providers[command] = ProviderFactory.get_provider(command, CsmApi._cluster) provider = CsmApi._providers[command] @@ -390,8 +387,8 @@ async def set_secure_headers(request, handler): async def rest_middleware(request, handler): if CsmRestApi.__is_shutting_down: return CsmRestApi.json_response("CSM agent is shutting down", status=503) + request.request_id = int(time.time()) try: - request_id = int(time.time()) request_body = dict(request.rel_url.query) if request.rel_url.query else {} if not request_body and request.content_length and request.content_length > 0: try: @@ -433,69 +430,80 @@ async def rest_middleware(request, handler): # by client to complete task which are await use atomic except (ConcurrentCancelledError, AsyncioCancelledError): Log.warn(f"Client cancelled call for {request.method} {request.path}") - return CsmRestApi.json_response( - CsmRestApi.error_response( + resp = CsmRestApi.error_response( CsmRequestCancelled(desc="Call cancelled by client"), - request=request, request_id=request_id), - status=499) + request=request, request_id=request.request_id) + return CsmRestApi.json_response(resp, status=499) except CsmHttpException as e: raise e except web.HTTPException as e: Log.error(f'HTTP Exception {e.status}: {e.reason}') - return CsmRestApi.json_response( - CsmRestApi.error_response(e, request=request, request_id=request_id), - status=e.status) + resp = CsmRestApi.error_response(e, request=request, + request_id=request.request_id) + return CsmRestApi.json_response(resp, status=e.status) except DataAccessError as e: Log.error(f"Failed to access the database: {e}") - resp = CsmRestApi.error_response(e, request=request, request_id=request_id) + resp = CsmRestApi.error_response(e, request=request, + request_id=request.request_id) return CsmRestApi.json_response(resp, status=503) except InvalidRequest as e: Log.debug(f"Invalid Request: {e} \n {traceback.format_exc()}") - return CsmRestApi.json_response( - CsmRestApi.error_response(e, request=request, request_id=request_id), status=400) + resp = CsmRestApi.error_response(e, request=request, + request_id=request.request_id) + return CsmRestApi.json_response(resp, status=400) except CsmNotFoundError as e: - return CsmRestApi.json_response( - CsmRestApi.error_response(e, request=request, request_id=request_id), status=404) + resp = CsmRestApi.error_response(e, request=request, + request_id=request.request_id) + return CsmRestApi.json_response(resp, status=404) except CsmPermissionDenied as e: - return CsmRestApi.json_response( - CsmRestApi.error_response(e, request=request, request_id=request_id), status=403) + resp = CsmRestApi.error_response(e, request=request, + request_id=request.request_id) + return CsmRestApi.json_response(resp, status=403) except ResourceExist as e: - return CsmRestApi.json_response( - CsmRestApi.error_response(e, request=request, request_id=request_id), - status=const.STATUS_CONFLICT) + resp = CsmRestApi.error_response(e, request=request, + request_id=request.request_id) + return CsmRestApi.json_response(resp, status=const.STATUS_CONFLICT) except CsmInternalError as e: - return CsmRestApi.json_response( - CsmRestApi.error_response(e, request=request, request_id=request_id), status=500) + resp = CsmRestApi.error_response(e, request=request, + request_id=request.request_id) + return CsmRestApi.json_response(resp, status=500) except CsmNotImplemented as e: - return CsmRestApi.json_response( - CsmRestApi.error_response(e, request=request, request_id=request_id), status=501) + resp = CsmRestApi.error_response(e, request=request, + request_id=request.request_id) + return CsmRestApi.json_response(resp, status=501) except CsmGatewayTimeout as e: - return CsmRestApi.json_response( - CsmRestApi.error_response(e, request=request, request_id=request_id), status=504) + resp = CsmRestApi.error_response(e, request=request, + request_id=request.request_id) + return CsmRestApi.json_response(resp, status=504) except CsmServiceConflict as e: - return CsmRestApi.json_response( - CsmRestApi.error_response(e, request=request, request_id=request_id), status=409) + resp = CsmRestApi.error_response(e, request=request, + request_id=request.request_id) + return CsmRestApi.json_response(resp, status=409) except CsmUnauthorizedError as e: - return CsmRestApi.json_response( - CsmRestApi.error_response(e, request=request, request_id=request_id), status=401) + resp = CsmRestApi.error_response(e, request=request, + request_id=request.request_id) + return CsmRestApi.json_response(resp, status=401) except CsmError as e: - return CsmRestApi.json_response( - CsmRestApi.error_response(e, request=request, request_id=request_id), status=400) + resp = CsmRestApi.error_response(e, request=request, + request_id=request.request_id) + return CsmRestApi.json_response(resp, status=400) except KeyError as e: Log.debug(f"Key Error: {e} \n {traceback.format_exc()}") message = f"Missing Key for {e}" - return CsmRestApi.json_response( - CsmRestApi.error_response(KeyError(message), request=request, - request_id=request_id), - status=422) + resp = CsmRestApi.error_response(KeyError(message), request=request, + request_id=request.request_id) + return CsmRestApi.json_response(resp, status=422) except (ServerDisconnectedError, ClientConnectorError, ClientOSError, ConcurrentTimeoutError) as e: - return CsmRestApi.json_response( - CsmRestApi.error_response(e, request=request, request_id=request_id), status=503) + resp = CsmRestApi.error_response(e, request=request, + request_id=request.request_id) + return CsmRestApi.json_response(resp, status=503) except Exception as e: - Log.critical(f"Unhandled Exception Caught: {e} \n {traceback.format_exc()}") - return CsmRestApi.json_response( - CsmRestApi.error_response(e, request=request, request_id=request_id), status=500) + Log.critical(f"Unhandled Exception Caught: {e} \n" + f"{traceback.format_exc()}") + resp = CsmRestApi.error_response(e, request=request, + request_id=request.request_id) + return CsmRestApi.json_response(resp, status=500) @staticmethod async def _shut_down(loop, site, server=None): @@ -560,17 +568,19 @@ def run(port: int, https_conf: ConfSection, debug_conf: DebugConf): CsmRestApi._run_server( CsmRestApi._app, port=port, ssl_context=ssl_context, access_log=None) - @staticmethod - async def process_request(request): - """Receive a request, processes and sends response back to client.""" - cmd = request.rel_url.query['cmd'] - action = request.rel_url.query['action'] - args = request.rel_url.query['args'] + # Deprecated Method + # TODO: remove this code + # @staticmethod + # async def process_request(request): + # """Receive a request, processes and sends response back to client.""" + # cmd = request.rel_url.query['cmd'] + # action = request.rel_url.query['action'] + # args = request.rel_url.query['args'] - request = Request(action, args) - response = CsmApi.process_request(cmd, request) + # request = Request(action, args) + # response = CsmApi.process_request(cmd, request) - return response + # return response @staticmethod @CsmAuth.public diff --git a/csm/core/agent/csm_agent.py b/csm/core/agent/csm_agent.py index 98267f4df..8bf7e21ef 100755 --- a/csm/core/agent/csm_agent.py +++ b/csm/core/agent/csm_agent.py @@ -254,7 +254,6 @@ def run(): from csm.core.agent.api import CsmRestApi # from csm.common.timeseries import TimelionProvider from csm.common.ha_framework import CortxHAFramework - from cortx.utils.cron import CronJob from cortx.utils.validator.v_consul import ConsulV from cortx.utils.validator.error import VError from csm.core.services.storage_capacity import StorageCapacityService, S3CapacityService diff --git a/csm/core/blogic/email_conf.py b/csm/core/blogic/email_conf.py index c92a70aa8..738877c9d 100644 --- a/csm/core/blogic/email_conf.py +++ b/csm/core/blogic/email_conf.py @@ -47,7 +47,7 @@ def configure(self, args, password = ""): self._email_conf_dict["AuthPass"] = password try: File = open(EmailConfig.SSMTP_CONF, "w") - for key in self._email_conf_dict.keys(): + for key in self._email_conf_dict: conf_line = key+"="+self._email_conf_dict[key]+"\n" File.write(conf_line) File.close() @@ -79,7 +79,7 @@ def unconfigure(self): self._email_conf_dict["AuthPass"] = "" try: File = open(EmailConfig.SSMTP_CONF, "w") - for key in self._email_conf_dict.keys(): + for key in self._email_conf_dict: conf_line = key+"="+self._email_conf_dict[key]+"\n" File.write(conf_line) File.close() @@ -154,7 +154,7 @@ def show(self): if os.path.isfile(EmailConfig.SSMTP_CONF): File = open(EmailConfig.SSMTP_CONF, "r") conf = File.readline() - while (conf != None and conf != ""): + while (conf is not None and conf != ""): if (conf.startswith("AuthUser")): conf.strip("\n") msg = "Sender: "+conf.split("=")[1] diff --git a/csm/core/controllers/users.py b/csm/core/controllers/users.py index 9c286fc39..7bad1cf9f 100644 --- a/csm/core/controllers/users.py +++ b/csm/core/controllers/users.py @@ -21,9 +21,7 @@ from csm.core.controllers.view import CsmView, CsmResponse, CsmAuth from csm.core.controllers.validators import PasswordValidator, UserNameValidator from cortx.utils.log import Log -from csm.common.errors import InvalidRequest, CsmPermissionDenied -from cortx.utils.conf_store.conf_store import Conf - +from csm.common.errors import InvalidRequest class CsmUserCreateSchema(Schema): diff --git a/csm/core/data/models/session.py b/csm/core/data/models/session.py index 23891dd6f..e3d5ac621 100644 --- a/csm/core/data/models/session.py +++ b/csm/core/data/models/session.py @@ -32,7 +32,7 @@ def instantiate_session(session_id: str, expiry_time: datetime, user_id: str, user_role: str, - permissions: {}): + permissions: dict): session = SessionModel() session._session_id = session_id session._expiry_time = expiry_time diff --git a/csm/core/providers/providers.py b/csm/core/providers/providers.py index dd2203ff6..84f7f5494 100644 --- a/csm/core/providers/providers.py +++ b/csm/core/providers/providers.py @@ -28,7 +28,7 @@ class Request(object): def __init__(self, action, args, options=None): self._action = action self._args = args - self.options = options + self._options = options def action(self): return self._action @@ -37,7 +37,7 @@ def args(self): return self._args def options(self): - return self.options + return self._options class Response(object): diff --git a/csm/core/services/permissions.py b/csm/core/services/permissions.py index e821d258d..b11fca3db 100644 --- a/csm/core/services/permissions.py +++ b/csm/core/services/permissions.py @@ -16,12 +16,12 @@ class PermissionSet: """Permission Set stored in a compact way as a dictionary.""" - def __init__(self, items: dict = {}): - self._items = { - resource: set(actions) - for resource, actions in items.items() - if len(actions) > 0 - } + def __init__(self, items:dict = None): + if items: + self._items = { resource: set(actions) + for resource, actions in items.items() if len(actions) > 0 } + else: + self._items = {} def __str__(self) -> str: """String Representation Operator.""" diff --git a/csm/core/services/sessions.py b/csm/core/services/sessions.py index a824362b9..87621fcdc 100644 --- a/csm/core/services/sessions.py +++ b/csm/core/services/sessions.py @@ -351,7 +351,7 @@ async def login(self, user_id, password): if not session: Log.error(f"Failed to create a new session for user: {user_id}") return None, None - + return session.session_id, {"reset_password": user.reset_password} async def logout(self, session_id): diff --git a/csm/core/services/stats.py b/csm/core/services/stats.py index e696551fe..7b97d72cd 100644 --- a/csm/core/services/stats.py +++ b/csm/core/services/stats.py @@ -40,24 +40,26 @@ def __init__(self, stats_provider, metrics_client): self._stats_provider = stats_provider self.metrics_client = metrics_client if self.metrics_client: - self.metrics_client.init(type=const.PRODUCER, - producer_id=Conf.get(const.CSM_GLOBAL_INDEX, - const.MSG_BUS_PERF_STAT_PRODUCER_ID), - message_type=Conf.get(const.CSM_GLOBAL_INDEX, - const.MSG_BUS_PERF_STAT_MSG_TYPE), - method=Conf.get(const.CSM_GLOBAL_INDEX, - const.MSG_BUS_PERF_STAT_METHOD)) - self.metrics_client.init(type=const.CONSUMER, - consumer_id=Conf.get(const.CSM_GLOBAL_INDEX, - const.MSG_BUS_PERF_STAT_CONSUMER_ID), - consumer_group=Conf.get(const.CSM_GLOBAL_INDEX, - const.MSG_BUS_PERF_STAT_CONSUMER_GROUP), - consumer_message_types=[Conf.get(const.CSM_GLOBAL_INDEX, - const.MSG_BUS_MSSG_TYPE)], - auto_ack=Conf.get(const.CSM_GLOBAL_INDEX, - const.MSG_BUS_PERF_STAT_AUTO_ACK), - offset=Conf.get(const.CSM_GLOBAL_INDEX, - const.MSG_BUS_PERF_STAT_OFFSET)) + self.metrics_client.init(type=const.PRODUCER, + producer_id=Conf.get(const.CSM_GLOBAL_INDEX, + const.MSG_BUS_PERF_STAT_PRODUCER_ID), + message_type=Conf.get(const.CSM_GLOBAL_INDEX, + const.MSG_BUS_PERF_STAT_MSG_TYPE), + method=Conf.get(const.CSM_GLOBAL_INDEX, + const.MSG_BUS_PERF_STAT_METHOD) + ) + self.metrics_client.init(type=const.CONSUMER, + consumer_id=Conf.get(const.CSM_GLOBAL_INDEX, + const.MSG_BUS_PERF_STAT_CONSUMER_ID), + consumer_group=Conf.get(const.CSM_GLOBAL_INDEX, + const.MSG_BUS_PERF_STAT_CONSUMER_GROUP), + consumer_message_types=[Conf.get(const.CSM_GLOBAL_INDEX, + const.MSG_BUS_MSSG_TYPE)], + auto_ack=Conf.get(const.CSM_GLOBAL_INDEX, + const.MSG_BUS_PERF_STAT_AUTO_ACK), + offset=Conf.get(const.CSM_GLOBAL_INDEX, + const.MSG_BUS_PERF_STAT_OFFSET) + ) self.convertor_type = const.STATS_CONVERTOR self.convertor = Convertor(self.convertor_type) @@ -159,7 +161,7 @@ async def get_metrics(self, stats_id, metrics_list, from_t, to_t, interval, if stats_id: output["id"]=stats_id data_list = [] - for panel in panels.keys(): + for panel in panels: panel_data = await self._stats_provider.process_request( stats_id = stats_id, panel = panel, diff --git a/csm/core/services/users.py b/csm/core/services/users.py index 4212f53d3..4c71e204c 100644 --- a/csm/core/services/users.py +++ b/csm/core/services/users.py @@ -345,7 +345,6 @@ async def _validate_user_update( password = new_values.get(const.PASS, None) current_password = new_values.get(const.CSM_USER_CURRENT_PASSWORD, None) role = new_values.get('user_role', None) - reset_password = new_values.get('reset_password', None) allowed = CSM_USER_PASSWD_UPDATE_RULES[loggedin_user_role][user_role].apply(self_update) if not allowed: diff --git a/test/service/test_csm_service.py b/test/service/test_csm_service.py index 8ddfac120..45177046b 100644 --- a/test/service/test_csm_service.py +++ b/test/service/test_csm_service.py @@ -44,10 +44,8 @@ def test1(args): port = int(Conf.get(const.CSM_GLOBAL_INDEX, "CSM_SERVICE>CSM_AGENT>port")) url = "http://" if not ssl_check else "https://" url = url + host + ":" + str(port) - resp = process_request(url) - if resp.status_code != 401: - raise - except Exception: + process_request(url) + except requests.exceptions.RequestException: raise TestFailed("csm_agent service is not running. Error: %s" %traceback.format_exc()) def test2(args): @@ -62,10 +60,8 @@ def test2(args): port = Conf.get(const.CSM_GLOBAL_INDEX, "CSM_SERVICE>CSM_WEB>port") url = "http://" if not ssl_check else "https://" url = url + host + ":" + str(port) - resp = process_request(url) - if resp.status_code != 200: - raise - except Exception: + process_request(url) + except requests.exceptions.RequestException: raise TestFailed("csm_web service is not running. Error: %s" %traceback.format_exc()) test_list = [ test1 ] diff --git a/test/user_management/test_api_functional_requirements.py b/test/user_management/test_api_functional_requirements.py index 80c2b94a6..06bac184d 100644 --- a/test/user_management/test_api_functional_requirements.py +++ b/test/user_management/test_api_functional_requirements.py @@ -60,7 +60,7 @@ def __enter__(self): assert self.__authorization_header is not None return self - def __exit__(self, type, value, traceback): + def __exit__(self, exc_type, exc_value, exc_traceback): if self.__username is not None and self.__authorization_header is not None: self.__logout(self.__username)