Skip to content

Commit

Permalink
Merge pull request #152 from powerapi-ng/fix/issue151/csv_input_only_…
Browse files Browse the repository at this point in the history
…postmortem

Fix/issue151/csv input only postmortem
  • Loading branch information
gfieni committed Mar 31, 2023
2 parents d577f15 + ef221c1 commit bad36a5
Show file tree
Hide file tree
Showing 34 changed files with 303 additions and 119 deletions.
4 changes: 2 additions & 2 deletions powerapi/actor/actor.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

from powerapi.exception import PowerAPIExceptionWithMessage
from powerapi.message import PoisonPillMessage
from powerapi.message import UnknowMessageTypeException
from powerapi.message import UnknownMessageTypeException
from powerapi.handler import HandlerException

from .socket_interface import SocketInterface
Expand Down Expand Up @@ -228,7 +228,7 @@ def _initial_behaviour(self):
try:
handler = self.state.get_corresponding_handler(msg)
handler.handle_message(msg)
except UnknowMessageTypeException:
except UnknownMessageTypeException:
self.logger.warning("UnknowMessageTypeException: " + str(msg))
except HandlerException:
self.logger.warning("HandlerException")
Expand Down
4 changes: 2 additions & 2 deletions powerapi/actor/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

from powerapi.message import UnknowMessageTypeException
from powerapi.message import UnknownMessageTypeException
from powerapi.actor.supervisor import Supervisor


Expand Down Expand Up @@ -74,7 +74,7 @@ def get_corresponding_handler(self, msg):
for (msg_type, handler) in self.handlers:
if isinstance(msg, msg_type):
return handler
raise UnknowMessageTypeException()
raise UnknownMessageTypeException()

def add_handler(self, message_type, handler):
"""
Expand Down
4 changes: 4 additions & 0 deletions powerapi/cli/config_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ def validate(config: Dict):
logging.error("no files parameter found for csv input")
return False

if input_config['type'] == 'csv' and config['stream']:
logging.error("stream mode cannot be used for csv input")
return False

if 'model' not in input_config:
input_config['model'] = 'PowerReport'
if 'name' not in input_config:
Expand Down
4 changes: 1 addition & 3 deletions powerapi/dispatcher/dispatcher_actor.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,11 @@ class DispatcherActor(Actor):
"""

def __init__(self, name: str, formula_init_function: Callable, pushers: [], route_table: RouteTable,
device_id: str, level_logger: Literal = logging.WARNING, timeout=None):
level_logger: Literal = logging.WARNING, timeout=None):
"""
:param str name: Actor name
:param func formula_init_function: Function for creating Formula
:param route_table: initialized route table of the DispatcherActor
:param device_id: name of the device the dispatcher handle
:param int level_logger: Define the level of the logger
:param bool timeout: Define the time in millisecond to wait for a
message before run timeout_handler
Expand All @@ -167,7 +166,6 @@ def __init__(self, name: str, formula_init_function: Callable, pushers: [], rout

# (powerapi.DispatcherState): Actor state
self.state = DispatcherState(self, self._create_factory(pushers), route_table)
self.device_id = device_id

def setup(self):
"""
Expand Down
4 changes: 2 additions & 2 deletions powerapi/dispatcher/simple/simple_dispatcher_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
from powerapi.actor import State
from powerapi.handler import StartHandler, PoisonPillMessageHandler, Handler
from powerapi.message import StartMessage, UnknowMessageTypeException
from powerapi.message import StartMessage, UnknownMessageTypeException
from powerapi.report import Report


Expand Down Expand Up @@ -75,4 +75,4 @@ def handle(self, msg: Report):
self.state.actor.logger.debug('send ' + str(msg) + ' to ' + self.state.formula_name)
self.state.formula.send_data(msg)
else:
raise UnknowMessageTypeException()
raise UnknownMessageTypeException()
2 changes: 1 addition & 1 deletion powerapi/formula/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@
from powerapi.formula.handlers import FormulaPoisonPillMessageHandler
from powerapi.formula.abstract_cpu_dram_formula import AbstractCpuDramFormula
from powerapi.formula.dummy.dummy_formula_actor import DummyFormulaActor
from powerapi.formula.formula_actor import FormulaActor, FormulaState, DomainValues
from powerapi.formula.formula_actor import FormulaActor, FormulaState
from powerapi.formula.simple.simple_formula_actor import SimpleFormulaActor
12 changes: 1 addition & 11 deletions powerapi/formula/formula_actor.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import logging
import re

from typing import Dict, Tuple
from typing import Dict

from powerapi.actor import Actor, State
from powerapi.pusher import PusherActor
Expand All @@ -50,16 +50,6 @@ def __init__(self, actor, pushers, metadata):
self.metadata = metadata


class DomainValues:
"""
values that describe the device that the formula compute the power consumption for
"""

def __init__(self, device_id: str, formula_id: Tuple):
self.device_id = device_id
self.sensor = formula_id[0]


class FormulaActor(Actor):
"""
Abstract actor class used to implement formula actor that compute power consumption of a device from Reports
Expand Down
4 changes: 2 additions & 2 deletions powerapi/handler/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

from powerapi.exception import PowerAPIException
from powerapi.message import Message, UnknowMessageTypeException
from powerapi.message import Message, UnknownMessageTypeException


class HandlerException(PowerAPIException):
Expand Down Expand Up @@ -83,7 +83,7 @@ def delegate_message_handling(self, msg: Message):
try:
handler = self.state.get_corresponding_handler(msg)
handler.handle_message(msg)
except UnknowMessageTypeException:
except UnknownMessageTypeException:
self.state.actor.logger.warning("UnknowMessageTypeException: " + str(msg))
except HandlerException:
self.state.actor.logger.warning("HandlerException")
Expand Down
4 changes: 2 additions & 2 deletions powerapi/handler/poison_pill_message_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

from powerapi.message import UnknowMessageTypeException, PoisonPillMessage
from powerapi.message import UnknownMessageTypeException, PoisonPillMessage
from .handler import Handler


Expand Down Expand Up @@ -68,7 +68,7 @@ def handle(self, msg):
:param Object msg: the message received by the actor
"""
if not isinstance(msg, PoisonPillMessage):
raise UnknowMessageTypeException(type(msg))
raise UnknownMessageTypeException(type(msg))

if msg.is_soft:
self._empty_mail_box()
Expand Down
4 changes: 2 additions & 2 deletions powerapi/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
from powerapi.database import BaseDB
from powerapi.filter import Filter
from powerapi.dispatcher import RouteTable
from powerapi.formula import FormulaActor, FormulaState, DomainValues
from powerapi.formula import FormulaActor, FormulaState
from powerapi.report_modifier import ReportModifier


Expand Down Expand Up @@ -172,7 +172,7 @@ def __eq__(self, other):
return False


class UnknowMessageTypeException(PowerAPIException):
class UnknownMessageTypeException(PowerAPIException):
"""
Exception happen when we don't know the message type
"""
4 changes: 2 additions & 2 deletions powerapi/puller/simple/simple_puller_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

from powerapi.actor import State
from powerapi.handler import Handler, StartHandler
from powerapi.message import Message, SimplePullerSendReportsMessage, UnknowMessageTypeException
from powerapi.message import Message, SimplePullerSendReportsMessage, UnknownMessageTypeException
from powerapi.puller.handlers import PullerInitializationException


Expand Down Expand Up @@ -72,4 +72,4 @@ def handle(self, msg: Message):
sent += 1
self.state.actor.logger.debug('sent reports: ' + str(sent))
else:
raise UnknowMessageTypeException()
raise UnknownMessageTypeException()
28 changes: 28 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright (c) 2023, INRIA
# Copyright (c) 2023, University of Lille
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# * Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
63 changes: 63 additions & 0 deletions tests/acceptation/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Copyright (c) 2023, INRIA
# Copyright (c) 2023, University of Lille
# All rights reserved.

# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:

# * Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.

# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.

# * Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.

# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
from multiprocessing import active_children

import pytest

from tests.utils.db.mongo import MONGO_URI, MONGO_DATABASE_NAME, MONGO_OUTPUT_COLLECTION_NAME


@pytest.fixture
def shutdown_system():
"""
Shutdown the actor system, i.e., all actors are killed
"""
yield None
active = active_children()
for child in active:
child.kill()


@pytest.fixture()
def socket_info_config():
"""
Return a configuration with socket as input and mongo as output
"""
return {'verbose': True,
'stream': False,
'input': {'test_puller': {'type': 'socket',
'port': 0,
'model': 'HWPCReport'}},
'output': {'test_pusher': {'type': 'mongodb',
'uri': MONGO_URI,
'db': MONGO_DATABASE_NAME,
'model': 'PowerReport',
'max_buffer_size': 0,
'collection': MONGO_OUTPUT_COLLECTION_NAME}},
}
10 changes: 2 additions & 8 deletions tests/acceptation/test_simple_architecture.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@
- each HWPCReport in the intput database was converted in one PowerReport per
socket in the output database
"""
# pylint: disable=redefined-outer-name
# pylint: disable=unused-argument
# pylint: disable=unused-import
# pylint: disable=redefined-outer-name,unused-argument,unused-import
import time
from datetime import datetime

Expand All @@ -59,8 +57,7 @@
from powerapi.actor import Supervisor
from powerapi.formula.dummy import DummyFormulaActor

# noinspection PyUnresolvedReferences
from tests.utils.acceptation import launch_simple_architecture, socket_info_config, BASIC_CONFIG, SOCKET_DEPTH_LEVEL, \
from tests.utils.acceptation import launch_simple_architecture, BASIC_CONFIG, SOCKET_DEPTH_LEVEL, \
INFLUX_OUTPUT_CONFIG, CSV_INPUT_OUTPUT_CONFIG
from tests.utils.report.hwpc import extract_rapl_reports_with_2_sockets
# noinspection PyUnresolvedReferences
Expand All @@ -72,9 +69,6 @@
from tests.utils.db.csv import ROOT_PATH, OUTPUT_PATH, files
from tests.utils.db.socket import ClientThread, ClientThreadDelay

# noinspection PyUnresolvedReferences
from tests.utils.unit import shutdown_system


##################
# MONGO to MONGO #
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@
socket in the output database
- only target name LIBVIRT_TARGET_NAME1 was converted into UUID_1
"""
# pylint: disable=redefined-outer-name
# pylint: disable=unused-argument
# pylint: disable=unused-import
# pylint: disable=redefined-outer-name,disable=unused-argument,disable=unused-import
import time
from datetime import datetime
from mock import patch
Expand All @@ -66,8 +64,6 @@
MONGO_DATABASE_NAME, mongo_database
from tests.utils.report.hwpc import extract_all_events_reports_with_vm_name
from tests.utils.libvirt import MockedLibvirt, LIBVIRT_TARGET_NAME1, UUID_1
# noinspection PyUnresolvedReferences
from tests.utils.unit import shutdown_system


@pytest.fixture
Expand Down
2 changes: 0 additions & 2 deletions tests/integration/cli/test_generate_pusher.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@
from powerapi.utils import timestamp_to_datetime
# noinspection PyUnresolvedReferences
from tests.utils.db.influx import INFLUX_URI, INFLUX_PORT, INFLUX_DBNAME, influx_database
# noinspection PyUnresolvedReferences
from tests.utils.unit import shutdown_system

SENSOR_NAME = 'sensor_test'
TARGET_NAME = 'system'
Expand Down
18 changes: 9 additions & 9 deletions tests/utils/unit.py → tests/integration/conftest.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
# Copyright (c) 2022, INRIA
# Copyright (c) 2022, University of Lille
# Copyright (c) 2023, INRIA
# Copyright (c) 2023, University of Lille
# All rights reserved.
#

# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#

# * Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#

# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#

# * Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#

# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Expand All @@ -26,10 +26,10 @@
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
from multiprocessing import active_children

import pytest

from multiprocessing import active_children


@pytest.fixture
def shutdown_system():
Expand Down
5 changes: 1 addition & 4 deletions tests/integration/test_dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@
from tests.utils.dummy_actor import DummyActor
from tests.utils.report.hwpc import gen_HWPCReports
from tests.unit.actor.abstract_test_actor import recv_from_pipe
# noinspection PyUnresolvedReferences
from tests.utils.unit import shutdown_system

PUSHER_NAME_POWER_REPORT = 'fake_pusher_power'
REPORT_TYPE_TO_BE_SENT = PowerReport
Expand Down Expand Up @@ -92,8 +90,7 @@ def started_dispatcher(started_fake_pusher_power_report, route_table):
pushers=pushers, socket=0,
core=0),
route_table=route_table,
pushers={PUSHER_NAME_POWER_REPORT: started_fake_pusher_power_report},
device_id='test_device')
pushers={PUSHER_NAME_POWER_REPORT: started_fake_pusher_power_report})
actor.start()
actor.connect_data()
actor.connect_control()
Expand Down

0 comments on commit bad36a5

Please sign in to comment.