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

Commit

Permalink
CORTX-33151 Codacy fixes related to style and security (#2157)
Browse files Browse the repository at this point in the history
Solution:
a) Fix all pep257 issues.
b) False positive and conflicting Codacy rules are disabled in codacy flake8.
c) Fix medium priority and security issues.
d) Fix 13 test cases in classes TestDeliveryHeraldAny &  TestDeliveryHeraldAll.

Signed-off-by: Sarang Sawant <sarang.sawant@seagate.com>
  • Loading branch information
seagate-sarang-sawant authored Aug 30, 2022
1 parent bd943b6 commit 1879e27
Show file tree
Hide file tree
Showing 28 changed files with 169 additions and 125 deletions.
2 changes: 1 addition & 1 deletion cfgen/cfgen
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ def validate_cdf_schema(cdf: str, cdf_path: str, schema_path: str) -> None:
input=cdf)
except CliException as e:
die(
f'{cdf_path}: Invalid cluster description\n' + e.stderr +
f"{cdf_path}: Invalid cluster description\n" + e.stderr +
f"\n\nTo learn more, run '{sys.argv[0]} --help-schema'.")


Expand Down
1 change: 1 addition & 0 deletions ha-simulator/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ COPY ./patches/ /app/patches/
RUN python3 -m venv --system-site-packages .py-venv/ \
&& source ./.py-venv/bin/activate \
&& pip install -r ./requirements.txt
# shellcheck disable=SC2046
RUN pip3 install -r https://raw.githubusercontent.com/Seagate/cortx-utils/main/py-utils/python_requirements.txt \
&& pip3 install -r https://raw.githubusercontent.com/Seagate/cortx-utils/main/py-utils/python_requirements.ext.txt \
&& yum install -y http://cortx-storage.colo.seagate.com/releases/cortx/github/main/centos-7.9.2009/last_successful/$(curl --silent http://cortx-storage.colo.seagate.com/releases/cortx/github/main/centos-7.9.2009/last_successful/ | grep py-utils | sed 's/.*href="\([^"]*\)".*/\1/g')
Expand Down
10 changes: 4 additions & 6 deletions hax/hax/common/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
# For any questions about this software or licensing,
# please email opensource@seagate.com or cortx-questions@seagate.com.
#
"""Hax commons package symbols."""
import inject


class HaxGlobalState:

"""
Global state of whole HaX application.
"""
"""Global state of whole Hax application."""
def __init__(self):
"""Initialize current state to non-stopping state."""
self.stopping: bool = False

def is_stopping(self) -> bool:
Expand All @@ -36,7 +36,5 @@ def set_stopping(self):


def di_configuration(binder: inject.Binder):
"""
Configures Dependency Injection (DI) engine.
"""
"""Configures Dependency Injection (DI) engine."""
binder.bind(HaxGlobalState, HaxGlobalState())
3 changes: 2 additions & 1 deletion hax/hax/ha/message_type/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@
# please email opensource@seagate.com or cortx-questions@seagate.com.
#

# empty
"""Module provides Message type interface and Health Message implementation to
send health events to message bus topic `cortx_health_events`. """
1 change: 1 addition & 0 deletions hax/hax/ha/message_type/message_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

class MessageType():
def __init__(self):
"""Message base class with abstract send method."""
logging.debug('Inside MessageType')

def send(self, event, util: ConsulUtil):
Expand Down
2 changes: 1 addition & 1 deletion hax/hax/ha/resource/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
# please email opensource@seagate.com or cortx-questions@seagate.com.
#

# empty
"""Modue provides Resource Type interface to send resource status events."""
20 changes: 10 additions & 10 deletions hax/hax/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ def _restart_notify(self, req: FirstEntrypointRequest,
self.consul.set_proc_restart_count(req.process_fid,
restart_count + 1)

def _do_work(self, planner: WorkPlanner, motr: Motr):
def _do_work(self, planner: WorkPlanner, motr: Motr): # noqa: MC0001
LOG.info('Handler thread has started')

try:
Expand All @@ -340,14 +340,14 @@ def _do_work(self, planner: WorkPlanner, motr: Motr):
if isinstance(item, FirstEntrypointRequest):
self._restart_notify(item, motr)
motr.send_entrypoint_request_reply(
EntrypointRequest(
reply_context=item.reply_context,
req_id=item.req_id,
remote_rpc_endpoint=item.remote_rpc_endpoint,
process_fid=item.process_fid,
git_rev=item.git_rev,
pid=item.pid,
is_first_request=item.is_first_request))
EntrypointRequest(
reply_context=item.reply_context,
req_id=item.req_id,
remote_rpc_endpoint=item.remote_rpc_endpoint,
process_fid=item.process_fid,
git_rev=item.git_rev,
pid=item.pid,
is_first_request=item.is_first_request))
elif isinstance(item, EntrypointRequest):
# While replying any Exception is catched. In such a
# case, the motr process will receive EAGAIN and
Expand All @@ -368,7 +368,7 @@ def _do_work(self, planner: WorkPlanner, motr: Motr):
motr.broadcast_ha_states(item.states,
update_kv=False)
status = self.consul.objHealthToProcessEvent(
item.states[0].status)
item.states[0].status)
# Account for received process status.
self.consul.update_process_status_local(
ConfHaProcess(chp_event=status,
Expand Down
1 change: 1 addition & 0 deletions hax/hax/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class HaNvecGetEvent(BaseMessage):
nvec: List[HaNote]

def __repr__(self):
"""Machine readable string representation of HaNvecGetEvent."""
return f'HaNvecGetEvent(<{len(self.nvec)} items>)'


Expand Down
1 change: 1 addition & 0 deletions hax/hax/motr/rconfc.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class RconfcStarter(StoppableThread):
can happen when Motr is initialized in hax).
"""
def __init__(self, motr: Motr, consul_util: ConsulUtil):
"""Rconfc starter's thread constructor."""
super().__init__(target=self._execute,
name='rconfc-starter',
args=(motr, ))
Expand Down
10 changes: 10 additions & 0 deletions hax/hax/queue/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""Broadcast Queue Consumer implementation."""
import json
import logging
from queue import Queue
Expand Down Expand Up @@ -27,6 +28,15 @@ class BQProcessor:
"""
def __init__(self, planner: WorkPlanner, delivery_herald: DeliveryHerald,
motr: Motr, conf_obj_util: ConfObjUtil):
"""Initialize pre requisites for Broadcast Queue Processor.
Args:
planner: work planner for Motr-aware threads (see ConsumerThread).
delivery_herald: Thread synchronizing block that ensures
delivery is confirmed.
motr: hax side foreign fucntion interface wrapper.
conf_obj_util: references KV(consul) adapter.
"""
self.planner = planner
self.confobjutil = conf_obj_util
self.herald = delivery_herald
Expand Down
5 changes: 3 additions & 2 deletions hax/hax/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ def hctl_stat(request):
# request a parameter. The respective result is obtained by executing
# corresponding `hctl-fetch-fids` script.
def hctl_fetch_fids(request):
"""calls the hare-fetch-fids to provide info about services configured.
"""
calls the hare-fetch-fids to provide info about services configured.
This function calls the hare-fetch-fids script from the hax-server in
order to provide details about services configured by Hare e.g. Hax,
Expand All @@ -124,7 +125,7 @@ def hctl_fetch_fids(request):

def to_ha_states(data: Any, consul_util: ConsulUtil) -> List[HAState]:
"""
converts dictionary into list of HA states
converts dictionary into list of HA states.
Converts a dictionary, obtained from JSON data, into a list of
HA states.
Expand Down
17 changes: 15 additions & 2 deletions hax/helper/configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ def _setup_logging(opts: AppCtx):
@click.pass_context
def parse_opts(ctx, cdf: str, conf_dir: str, transport: str, log_dir: str,
consul_server: bool, uuid: str, log_file: str):
"""Generate Hare configuration according to the given CDF file.
"""
Generate Hare configuration according to the given CDF file.
CDF Full path to the Cluster Description File (CDF).
"""
ctx.ensure_object(dict)
Expand All @@ -119,7 +119,20 @@ def parse_opts(ctx, cdf: str, conf_dir: str, transport: str, log_dir: str,


class ConfGenerator:

"""Generates confd.dhall from CDF file and uses m0confgen to generate motr
specific confd.xc.
confd.dhall is a pre-configuration file for Motr using dhall configuration
language which is an input to dhall utility that generates a list of motr
configuration objects corresponding to motr configuration obt structures
in a human readable format. This output is then passed as an input to
m0confgen to generate motr specific `confd.xc` that follows
motr xcode grammar.
"""

def __init__(self, context: AppCtx):
"""Construct ConfGenerator with necessary context."""
self.cdf_path = context.cdf_path
self.conf_dir = context.conf_dir
self.transport = context.transport
Expand Down
7 changes: 7 additions & 0 deletions hax/helper/exec.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ class Program:
to be executed by Executor class.
"""
def __init__(self, cmd: List[str], stdin: Optional['Program'] = None):
"""Holds a command or chain of commands.
Args:
cmd: a single command.
stdin: input to the command.
"""
self.cmd = cmd
self.stdin = stdin

Expand All @@ -38,6 +44,7 @@ def __or__(self, other):
return other

def __repr__(self):
"""Machine readable repr of the command"""
return f'Program({self.cmd}, stdin={self.stdin})'


Expand Down
2 changes: 2 additions & 0 deletions hax/helper/generate_sysconf.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class KVFile:
"""Helper to fetch data from Hare-Motr configuration key values file."""

def __init__(self, kv_file: str, node: str) -> None:
"""Loads Hare-Motr configuration in memory to generate sysconfig."""
self.kv_file = kv_file
self.kv_data = self._read_file()
self.node = node
Expand Down Expand Up @@ -127,6 +128,7 @@ class ConsulKV:
"""

def __init__(self, node: str) -> None:
"""Initializes the Consul KV adapter."""
self.kv = KVAdapter()
self.node = node

Expand Down
2 changes: 2 additions & 0 deletions hax/test/integration/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,11 @@ def __init__(self, pattern: List[HAState]):
self.pattern = pattern

def __repr__(self):
"""Machine readable representation of list of HA states"""
return str(self.pattern)

def __eq__(self, value):
"""Equality support for BroadcastHAStates."""
if not isinstance(value, BroadcastHAStates):
return False
return self.pattern == value.states
Expand Down
1 change: 1 addition & 0 deletions hax/test/integration/testutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ def fn(trace: Invocation) -> bool:
return fn


# pylint: disable=E0202
class FakeFFI(HaxFFI):
def __init__(self):
self.traces: List[Invocation] = []
Expand Down
Loading

0 comments on commit 1879e27

Please sign in to comment.