Skip to content

Commit

Permalink
refactor: Improve code quality
Browse files Browse the repository at this point in the history
  • Loading branch information
roda82 committed Nov 9, 2023
1 parent 9d672c9 commit f4a7765
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 14 deletions.
16 changes: 7 additions & 9 deletions powerapi/processor/pre/k8s/k8s_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@

# pylint: disable=W0603,W0718

import logging
import multiprocessing
from logging import Logger
from multiprocessing import Process
from logging import Formatter, getLogger, Logger, StreamHandler, WARNING
from multiprocessing import Manager, Process

from kubernetes import client, config, watch
from kubernetes.client.configuration import Configuration
Expand Down Expand Up @@ -144,7 +142,7 @@ class K8sMonitorAgent(Process):
when pod are created, removed or modified.
"""

def __init__(self, name: str, concerned_actor_state: K8sPreProcessorState, level_logger: int = logging.WARNING):
def __init__(self, name: str, concerned_actor_state: K8sPreProcessorState, level_logger: int = WARNING):
"""
:param str name: The actor name
:param K8sPreProcessorState concerned_actor_state: state of the actor that will use the monitored information
Expand All @@ -153,17 +151,17 @@ def __init__(self, name: str, concerned_actor_state: K8sPreProcessorState, level
Process.__init__(self, name=name)

#: (logging.Logger): Logger
self.logger = logging.getLogger(name)
self.logger = getLogger(name)
self.logger.setLevel(level_logger)
formatter = logging.Formatter('%(asctime)s || %(levelname)s || ' + '%(process)d %(processName)s || %(message)s')
handler = logging.StreamHandler()
formatter = Formatter('%(asctime)s || %(levelname)s || ' + '%(process)d %(processName)s || %(message)s')
handler = StreamHandler()
handler.setFormatter(formatter)

# Concerned Actor state
self.concerned_actor_state = concerned_actor_state

# Multiprocessing Manager
self.manager = multiprocessing.Manager()
self.manager = Manager()

# Shared cache
self.concerned_actor_state.metadata_cache_manager = K8sMetadataCacheManager(process_manager=self.manager,
Expand Down
7 changes: 3 additions & 4 deletions tests/unit/cli/test_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,11 @@
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

import os
import re
from re import Pattern
from re import compile, Pattern

import pytest

from powerapi.cli.generator import PullerGenerator, DBActorGenerator, PusherGenerator, ProcessorGenerator, \
from powerapi.cli.generator import PullerGenerator, DBActorGenerator, PusherGenerator, \
MonitorGenerator, MONITOR_NAME_SUFFIX, LISTENER_ACTOR_KEY, PreProcessorGenerator
from powerapi.cli.generator import ModelNameDoesNotExist
from powerapi.processor.pre.k8s.k8s_monitor import K8sMonitorAgent
Expand Down Expand Up @@ -292,7 +291,7 @@ def test_generate_several_pushers_from_config(several_inputs_outputs_stream_conf
assert db.metric_name == current_pusher_infos['metric_name']

elif pusher_type == 'virtiofs':
assert db.vm_name_regexp == re.compile(current_pusher_infos['vm_name_regexp'])
assert db.vm_name_regexp == compile(current_pusher_infos['vm_name_regexp'])
assert db.root_directory_name == current_pusher_infos['root_directory_name']
assert db.vm_directory_name_prefix == current_pusher_infos['vm_directory_name_prefix']
assert db.vm_directory_name_suffix == current_pusher_infos['vm_directory_name_suffix']
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/processor/pre/k8s/test_k8s_monitor.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Copyright (c) 2023, INRIA
# Copyright (c) 2023, University of Lille
# All rights reserved.
from time import sleep
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:

Expand Down Expand Up @@ -29,6 +28,7 @@

# pylint: disable=R6301,W0613,W0221

from time import sleep
from unittest.mock import patch, Mock

import pytest
Expand Down

0 comments on commit f4a7765

Please sign in to comment.