Skip to content

Commit

Permalink
Merge pull request #445 from powerapi-ng/refactor/libvirt-cleanup
Browse files Browse the repository at this point in the history
refactor: Cleanup libvirt pre-processor
  • Loading branch information
gfieni authored Oct 17, 2024
2 parents 30a9c22 + 95b43dc commit 42f7048
Show file tree
Hide file tree
Showing 20 changed files with 1 addition and 749 deletions.
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ opentsdb = ["opentsdb-py >= 0.6.0"]
prometheus = ["prometheus-client >= 0.9.0"]

# Plaforms:
libvirt = ["libvirt-python >= 6.1.0"] # requires libvirt lib/headers, do not include by default.
kubernetes = ["kubernetes >= 27.0.2"]

# Aliases:
Expand Down
22 changes: 0 additions & 22 deletions src/powerapi/cli/common_cli_parsing_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,28 +354,6 @@ def __init__(self):
subgroup_parser=subparser_influx2_output
)

subparser_libvirt_pre_processor = SubgroupConfigParsingManager("libvirt")
subparser_libvirt_pre_processor.add_argument(
"u", "uri", help_text="libvirt daemon uri", default_value=""
)
subparser_libvirt_pre_processor.add_argument(
"d",
"domain-regexp",
help_text="regexp used to extract domain from cgroup string",
)

subparser_libvirt_pre_processor.add_argument(
"p",
"puller",
help_text="target puller for the pre-processor",
)

subparser_libvirt_pre_processor.add_argument("n", "name", help_text="")
self.add_subgroup_parser(
subgroup_name="pre-processor",
subgroup_parser=subparser_libvirt_pre_processor
)

subparser_k8s_pre_processor = SubgroupConfigParsingManager("k8s")
subparser_k8s_pre_processor.add_argument(
"a",
Expand Down
16 changes: 0 additions & 16 deletions src/powerapi/cli/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
DatabaseNameAlreadyUsed, ProcessorTypeDoesNotExist, ProcessorTypeAlreadyUsed
from powerapi.filter import Filter
from powerapi.processor.pre.k8s import K8sPreProcessorActor
from powerapi.processor.pre.libvirt.libvirt_pre_processor_actor import LibvirtPreProcessorActor
from powerapi.processor.processor_actor import ProcessorActor
from powerapi.puller import PullerActor
from powerapi.pusher import PusherActor
Expand Down Expand Up @@ -331,20 +330,6 @@ class PreProcessorGenerator(ProcessorGenerator):
def __init__(self):
super().__init__('pre-processor', self._get_default_processor_factories())

@staticmethod
def _libvirt_pre_processor_factory(processor_config: dict) -> LibvirtPreProcessorActor:
"""
Libvirt pre-processor actor factory.
:param processor_config: Pre-Processor configuration
:return: Configured Libvirt pre-processor actor
"""
name = processor_config[ACTOR_NAME_KEY]
uri = processor_config[COMPONENT_URI_KEY]
regexp = processor_config[REGEXP_KEY]
target_actors_name = [processor_config[PULLER_NAME_KEY]]
level_logger = logging.DEBUG if processor_config[GENERAL_CONF_VERBOSE_KEY] else logging.INFO
return LibvirtPreProcessorActor(name, uri, regexp, [], target_actors_name, level_logger)

@staticmethod
def _k8s_pre_processor_factory(processor_config: Dict) -> K8sPreProcessorActor:
"""
Expand All @@ -365,7 +350,6 @@ def _get_default_processor_factories(self) -> Dict[str, Callable[[Dict], Process
Return the default pre-processors factory.
"""
return {
'libvirt': self._libvirt_pre_processor_factory,
'k8s': self._k8s_pre_processor_factory,
}

Expand Down
9 changes: 0 additions & 9 deletions src/powerapi/exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,15 +280,6 @@ def __init__(self, existing_prefix: str, new_prefix: str):
+ self.existing_prefix


class LibvirtException(PowerAPIException):
"""
Exception raised when there are issues regarding the import of LibvirtException
"""

def __init__(self, _):
PowerAPIException.__init__(self)


class ProcessorTypeDoesNotExist(PowerAPIException):
"""
Exception raised when attempting to remove to a ProcessorActorGenerator a processor factory with a type that is not
Expand Down
28 changes: 0 additions & 28 deletions src/powerapi/processor/pre/libvirt/__init__.py

This file was deleted.

79 changes: 0 additions & 79 deletions src/powerapi/processor/pre/libvirt/libvirt_pre_processor_actor.py

This file was deleted.

This file was deleted.

27 changes: 1 addition & 26 deletions tests/unit/cli/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,23 +188,6 @@ def several_inputs_outputs_stream_filedb_without_some_arguments_config(several_i
return several_inputs_outputs_stream_config


@pytest.fixture
def several_libvirt_pre_processors_config():
"""
Configuration with several libvirt processors
"""
return load_configuration_from_json_file(file_name='several_libvirt_pre_processors_configuration.json')


@pytest.fixture
def several_libvirt_processors_without_some_arguments_config():
"""
Configuration with several libvirt processors
"""
return load_configuration_from_json_file(
file_name='several_libvirt_processors_without_some_arguments_configuration.json')


@pytest.fixture
def several_k8s_pre_processors_config():
"""
Expand Down Expand Up @@ -283,14 +266,6 @@ def config_without_output(csv_io_postmortem_config):
return csv_io_postmortem_config


@pytest.fixture
def libvirt_pre_processor_config():
"""
Configuration with libvirt as pre-processor
"""
return load_configuration_from_json_file(file_name='libvirt_pre_processor_configuration.json')


@pytest.fixture
def k8s_pre_processor_config():
"""
Expand Down Expand Up @@ -669,7 +644,7 @@ def dispatcher_actor_in_dictionary():
@pytest.fixture
def pre_processor_binding_manager(pre_processor_pullers_and_processors_dictionaries):
"""
Return a ProcessorBindingManager with a libvirt/K8s Processor
Return a ProcessorBindingManager with a Processor
"""
pullers = pre_processor_pullers_and_processors_dictionaries[0]
processors = pre_processor_pullers_and_processors_dictionaries[1]
Expand Down
51 changes: 0 additions & 51 deletions tests/unit/cli/test_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
from powerapi.database import MongoDB, CsvDB, SocketDB, PrometheusDB, InfluxDB2
from powerapi.exception import PowerAPIException
from powerapi.processor.pre.k8s import K8sPreProcessorActor
from powerapi.processor.pre.libvirt.libvirt_pre_processor_actor import LibvirtPreProcessorActor
from powerapi.puller import PullerActor
from powerapi.pusher import PusherActor

Expand Down Expand Up @@ -392,56 +391,6 @@ def test_generate_pre_processor_from_empty_config_dict_raise_an_exception():
generator.generate(conf)


@pytest.mark.skip(reason='libvirt is disable by default')
def test_generate_pre_processor_from_libvirt_config(libvirt_pre_processor_config):
"""
Test that generation for libvirt pre-processor from a config works correctly
"""
generator = PreProcessorGenerator()

processors = generator.generate(libvirt_pre_processor_config)

assert len(processors) == len(libvirt_pre_processor_config['pre-processor'])
assert 'my_processor' in processors
processor = processors['my_processor']

assert isinstance(processor, LibvirtPreProcessorActor)

assert processor.state.daemon_uri is None
assert isinstance(processor.state.regexp, Pattern)


@pytest.mark.skip(reason='libvirt is disable by default')
def test_generate_several_libvirt_pre_processors_from_config(several_libvirt_pre_processors_config):
"""
Test that several libvirt pre-processors are correctly generated
"""
generator = PreProcessorGenerator()

processors = generator.generate(several_libvirt_pre_processors_config)

assert len(processors) == len(several_libvirt_pre_processors_config['pre-processor'])

for processor_name, current_processor_infos in several_libvirt_pre_processors_config['pre-processor'].items():
assert processor_name in processors
assert isinstance(processors[processor_name], LibvirtPreProcessorActor)

assert processors[processor_name].state.daemon_uri is None
assert isinstance(processors[processor_name].state.regexp, Pattern)


@pytest.mark.skip(reason='libvirt is disable by default')
def test_generate_libvirt_pre_processor_raise_exception_when_missing_arguments(
several_libvirt_processors_without_some_arguments_config):
"""
Test that PreProcessorGenerator raises a PowerAPIException when some arguments are missing for libvirt processor
"""
generator = PreProcessorGenerator()

with pytest.raises(PowerAPIException):
generator.generate(several_libvirt_processors_without_some_arguments_config)


def check_k8s_pre_processor_infos(pre_processor: K8sPreProcessorActor, expected_pre_processor_info: dict):
"""
Check that the infos related to a K8sMonitorAgentActor are correct regarding its related K8SProcessorActor
Expand Down
Loading

0 comments on commit 42f7048

Please sign in to comment.