Skip to content

Commit bad36a5

Browse files
authored
Merge pull request #152 from powerapi-ng/fix/issue151/csv_input_only_postmortem
Fix/issue151/csv input only postmortem
2 parents d577f15 + ef221c1 commit bad36a5

34 files changed

+303
-119
lines changed

powerapi/actor/actor.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838

3939
from powerapi.exception import PowerAPIExceptionWithMessage
4040
from powerapi.message import PoisonPillMessage
41-
from powerapi.message import UnknowMessageTypeException
41+
from powerapi.message import UnknownMessageTypeException
4242
from powerapi.handler import HandlerException
4343

4444
from .socket_interface import SocketInterface
@@ -228,7 +228,7 @@ def _initial_behaviour(self):
228228
try:
229229
handler = self.state.get_corresponding_handler(msg)
230230
handler.handle_message(msg)
231-
except UnknowMessageTypeException:
231+
except UnknownMessageTypeException:
232232
self.logger.warning("UnknowMessageTypeException: " + str(msg))
233233
except HandlerException:
234234
self.logger.warning("HandlerException")

powerapi/actor/state.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2828
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2929

30-
from powerapi.message import UnknowMessageTypeException
30+
from powerapi.message import UnknownMessageTypeException
3131
from powerapi.actor.supervisor import Supervisor
3232

3333

@@ -74,7 +74,7 @@ def get_corresponding_handler(self, msg):
7474
for (msg_type, handler) in self.handlers:
7575
if isinstance(msg, msg_type):
7676
return handler
77-
raise UnknowMessageTypeException()
77+
raise UnknownMessageTypeException()
7878

7979
def add_handler(self, message_type, handler):
8080
"""

powerapi/cli/config_validator.py

+4
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ def validate(config: Dict):
6868
logging.error("no files parameter found for csv input")
6969
return False
7070

71+
if input_config['type'] == 'csv' and config['stream']:
72+
logging.error("stream mode cannot be used for csv input")
73+
return False
74+
7175
if 'model' not in input_config:
7276
input_config['model'] = 'PowerReport'
7377
if 'name' not in input_config:

powerapi/dispatcher/dispatcher_actor.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -150,12 +150,11 @@ class DispatcherActor(Actor):
150150
"""
151151

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

168167
# (powerapi.DispatcherState): Actor state
169168
self.state = DispatcherState(self, self._create_factory(pushers), route_table)
170-
self.device_id = device_id
171169

172170
def setup(self):
173171
"""

powerapi/dispatcher/simple/simple_dispatcher_handlers.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2929
from powerapi.actor import State
3030
from powerapi.handler import StartHandler, PoisonPillMessageHandler, Handler
31-
from powerapi.message import StartMessage, UnknowMessageTypeException
31+
from powerapi.message import StartMessage, UnknownMessageTypeException
3232
from powerapi.report import Report
3333

3434

@@ -75,4 +75,4 @@ def handle(self, msg: Report):
7575
self.state.actor.logger.debug('send ' + str(msg) + ' to ' + self.state.formula_name)
7676
self.state.formula.send_data(msg)
7777
else:
78-
raise UnknowMessageTypeException()
78+
raise UnknownMessageTypeException()

powerapi/formula/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,5 @@
3030
from powerapi.formula.handlers import FormulaPoisonPillMessageHandler
3131
from powerapi.formula.abstract_cpu_dram_formula import AbstractCpuDramFormula
3232
from powerapi.formula.dummy.dummy_formula_actor import DummyFormulaActor
33-
from powerapi.formula.formula_actor import FormulaActor, FormulaState, DomainValues
33+
from powerapi.formula.formula_actor import FormulaActor, FormulaState
3434
from powerapi.formula.simple.simple_formula_actor import SimpleFormulaActor

powerapi/formula/formula_actor.py

+1-11
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
import logging
3131
import re
3232

33-
from typing import Dict, Tuple
33+
from typing import Dict
3434

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

5252

53-
class DomainValues:
54-
"""
55-
values that describe the device that the formula compute the power consumption for
56-
"""
57-
58-
def __init__(self, device_id: str, formula_id: Tuple):
59-
self.device_id = device_id
60-
self.sensor = formula_id[0]
61-
62-
6353
class FormulaActor(Actor):
6454
"""
6555
Abstract actor class used to implement formula actor that compute power consumption of a device from Reports

powerapi/handler/handler.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2929

3030
from powerapi.exception import PowerAPIException
31-
from powerapi.message import Message, UnknowMessageTypeException
31+
from powerapi.message import Message, UnknownMessageTypeException
3232

3333

3434
class HandlerException(PowerAPIException):
@@ -83,7 +83,7 @@ def delegate_message_handling(self, msg: Message):
8383
try:
8484
handler = self.state.get_corresponding_handler(msg)
8585
handler.handle_message(msg)
86-
except UnknowMessageTypeException:
86+
except UnknownMessageTypeException:
8787
self.state.actor.logger.warning("UnknowMessageTypeException: " + str(msg))
8888
except HandlerException:
8989
self.state.actor.logger.warning("HandlerException")

powerapi/handler/poison_pill_message_handler.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2828
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2929

30-
from powerapi.message import UnknowMessageTypeException, PoisonPillMessage
30+
from powerapi.message import UnknownMessageTypeException, PoisonPillMessage
3131
from .handler import Handler
3232

3333

@@ -68,7 +68,7 @@ def handle(self, msg):
6868
:param Object msg: the message received by the actor
6969
"""
7070
if not isinstance(msg, PoisonPillMessage):
71-
raise UnknowMessageTypeException(type(msg))
71+
raise UnknownMessageTypeException(type(msg))
7272

7373
if msg.is_soft:
7474
self._empty_mail_box()

powerapi/message.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
from powerapi.database import BaseDB
3737
from powerapi.filter import Filter
3838
from powerapi.dispatcher import RouteTable
39-
from powerapi.formula import FormulaActor, FormulaState, DomainValues
39+
from powerapi.formula import FormulaActor, FormulaState
4040
from powerapi.report_modifier import ReportModifier
4141

4242

@@ -172,7 +172,7 @@ def __eq__(self, other):
172172
return False
173173

174174

175-
class UnknowMessageTypeException(PowerAPIException):
175+
class UnknownMessageTypeException(PowerAPIException):
176176
"""
177177
Exception happen when we don't know the message type
178178
"""

powerapi/puller/simple/simple_puller_handlers.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
from powerapi.actor import State
3131
from powerapi.handler import Handler, StartHandler
32-
from powerapi.message import Message, SimplePullerSendReportsMessage, UnknowMessageTypeException
32+
from powerapi.message import Message, SimplePullerSendReportsMessage, UnknownMessageTypeException
3333
from powerapi.puller.handlers import PullerInitializationException
3434

3535

@@ -72,4 +72,4 @@ def handle(self, msg: Message):
7272
sent += 1
7373
self.state.actor.logger.debug('sent reports: ' + str(sent))
7474
else:
75-
raise UnknowMessageTypeException()
75+
raise UnknownMessageTypeException()

tests/__init__.py

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Copyright (c) 2023, INRIA
2+
# Copyright (c) 2023, University of Lille
3+
# All rights reserved.
4+
#
5+
# Redistribution and use in source and binary forms, with or without
6+
# modification, are permitted provided that the following conditions are met:
7+
#
8+
# * Redistributions of source code must retain the above copyright notice, this
9+
# list of conditions and the following disclaimer.
10+
#
11+
# * Redistributions in binary form must reproduce the above copyright notice,
12+
# this list of conditions and the following disclaimer in the documentation
13+
# and/or other materials provided with the distribution.
14+
#
15+
# * Neither the name of the copyright holder nor the names of its
16+
# contributors may be used to endorse or promote products derived from
17+
# this software without specific prior written permission.
18+
#
19+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22+
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23+
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24+
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25+
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26+
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27+
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28+
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

tests/acceptation/conftest.py

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Copyright (c) 2023, INRIA
2+
# Copyright (c) 2023, University of Lille
3+
# All rights reserved.
4+
5+
# Redistribution and use in source and binary forms, with or without
6+
# modification, are permitted provided that the following conditions are met:
7+
8+
# * Redistributions of source code must retain the above copyright notice, this
9+
# list of conditions and the following disclaimer.
10+
11+
# * Redistributions in binary form must reproduce the above copyright notice,
12+
# this list of conditions and the following disclaimer in the documentation
13+
# and/or other materials provided with the distribution.
14+
15+
# * Neither the name of the copyright holder nor the names of its
16+
# contributors may be used to endorse or promote products derived from
17+
# this software without specific prior written permission.
18+
19+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22+
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23+
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24+
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25+
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26+
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27+
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28+
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29+
from multiprocessing import active_children
30+
31+
import pytest
32+
33+
from tests.utils.db.mongo import MONGO_URI, MONGO_DATABASE_NAME, MONGO_OUTPUT_COLLECTION_NAME
34+
35+
36+
@pytest.fixture
37+
def shutdown_system():
38+
"""
39+
Shutdown the actor system, i.e., all actors are killed
40+
"""
41+
yield None
42+
active = active_children()
43+
for child in active:
44+
child.kill()
45+
46+
47+
@pytest.fixture()
48+
def socket_info_config():
49+
"""
50+
Return a configuration with socket as input and mongo as output
51+
"""
52+
return {'verbose': True,
53+
'stream': False,
54+
'input': {'test_puller': {'type': 'socket',
55+
'port': 0,
56+
'model': 'HWPCReport'}},
57+
'output': {'test_pusher': {'type': 'mongodb',
58+
'uri': MONGO_URI,
59+
'db': MONGO_DATABASE_NAME,
60+
'model': 'PowerReport',
61+
'max_buffer_size': 0,
62+
'collection': MONGO_OUTPUT_COLLECTION_NAME}},
63+
}

tests/acceptation/test_simple_architecture.py

+2-8
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,7 @@
4747
- each HWPCReport in the intput database was converted in one PowerReport per
4848
socket in the output database
4949
"""
50-
# pylint: disable=redefined-outer-name
51-
# pylint: disable=unused-argument
52-
# pylint: disable=unused-import
50+
# pylint: disable=redefined-outer-name,unused-argument,unused-import
5351
import time
5452
from datetime import datetime
5553

@@ -59,8 +57,7 @@
5957
from powerapi.actor import Supervisor
6058
from powerapi.formula.dummy import DummyFormulaActor
6159

62-
# noinspection PyUnresolvedReferences
63-
from tests.utils.acceptation import launch_simple_architecture, socket_info_config, BASIC_CONFIG, SOCKET_DEPTH_LEVEL, \
60+
from tests.utils.acceptation import launch_simple_architecture, BASIC_CONFIG, SOCKET_DEPTH_LEVEL, \
6461
INFLUX_OUTPUT_CONFIG, CSV_INPUT_OUTPUT_CONFIG
6562
from tests.utils.report.hwpc import extract_rapl_reports_with_2_sockets
6663
# noinspection PyUnresolvedReferences
@@ -72,9 +69,6 @@
7269
from tests.utils.db.csv import ROOT_PATH, OUTPUT_PATH, files
7370
from tests.utils.db.socket import ClientThread, ClientThreadDelay
7471

75-
# noinspection PyUnresolvedReferences
76-
from tests.utils.unit import shutdown_system
77-
7872

7973
##################
8074
# MONGO to MONGO #

tests/acceptation/test_simple_architecture_with_libvirt_mapper.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,7 @@
4848
socket in the output database
4949
- only target name LIBVIRT_TARGET_NAME1 was converted into UUID_1
5050
"""
51-
# pylint: disable=redefined-outer-name
52-
# pylint: disable=unused-argument
53-
# pylint: disable=unused-import
51+
# pylint: disable=redefined-outer-name,disable=unused-argument,disable=unused-import
5452
import time
5553
from datetime import datetime
5654
from mock import patch
@@ -66,8 +64,6 @@
6664
MONGO_DATABASE_NAME, mongo_database
6765
from tests.utils.report.hwpc import extract_all_events_reports_with_vm_name
6866
from tests.utils.libvirt import MockedLibvirt, LIBVIRT_TARGET_NAME1, UUID_1
69-
# noinspection PyUnresolvedReferences
70-
from tests.utils.unit import shutdown_system
7167

7268

7369
@pytest.fixture

tests/integration/cli/test_generate_pusher.py

-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@
3636
from powerapi.utils import timestamp_to_datetime
3737
# noinspection PyUnresolvedReferences
3838
from tests.utils.db.influx import INFLUX_URI, INFLUX_PORT, INFLUX_DBNAME, influx_database
39-
# noinspection PyUnresolvedReferences
40-
from tests.utils.unit import shutdown_system
4139

4240
SENSOR_NAME = 'sensor_test'
4341
TARGET_NAME = 'system'

tests/utils/unit.py renamed to tests/integration/conftest.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
# Copyright (c) 2022, INRIA
2-
# Copyright (c) 2022, University of Lille
1+
# Copyright (c) 2023, INRIA
2+
# Copyright (c) 2023, University of Lille
33
# All rights reserved.
4-
#
4+
55
# Redistribution and use in source and binary forms, with or without
66
# modification, are permitted provided that the following conditions are met:
7-
#
7+
88
# * Redistributions of source code must retain the above copyright notice, this
99
# list of conditions and the following disclaimer.
10-
#
10+
1111
# * Redistributions in binary form must reproduce the above copyright notice,
1212
# this list of conditions and the following disclaimer in the documentation
1313
# and/or other materials provided with the distribution.
14-
#
14+
1515
# * Neither the name of the copyright holder nor the names of its
1616
# contributors may be used to endorse or promote products derived from
1717
# this software without specific prior written permission.
18-
#
18+
1919
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
2020
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2121
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
@@ -26,10 +26,10 @@
2626
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
2727
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2828
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29-
from multiprocessing import active_children
30-
3129
import pytest
3230

31+
from multiprocessing import active_children
32+
3333

3434
@pytest.fixture
3535
def shutdown_system():

tests/integration/test_dispatcher.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@
3838
from tests.utils.dummy_actor import DummyActor
3939
from tests.utils.report.hwpc import gen_HWPCReports
4040
from tests.unit.actor.abstract_test_actor import recv_from_pipe
41-
# noinspection PyUnresolvedReferences
42-
from tests.utils.unit import shutdown_system
4341

4442
PUSHER_NAME_POWER_REPORT = 'fake_pusher_power'
4543
REPORT_TYPE_TO_BE_SENT = PowerReport
@@ -92,8 +90,7 @@ def started_dispatcher(started_fake_pusher_power_report, route_table):
9290
pushers=pushers, socket=0,
9391
core=0),
9492
route_table=route_table,
95-
pushers={PUSHER_NAME_POWER_REPORT: started_fake_pusher_power_report},
96-
device_id='test_device')
93+
pushers={PUSHER_NAME_POWER_REPORT: started_fake_pusher_power_report})
9794
actor.start()
9895
actor.connect_data()
9996
actor.connect_control()

0 commit comments

Comments
 (0)