def test_create_two_report_without_metadata_metadata_are_different(): """ When using a default parameter, its value is evaluated at the instantiation of the class So if not used carefully, all object have the same value as attribute """ a = Report(0, 'toto', 'all') a.metadata["test"] = "value" b = Report(0, 'toto', 'all') assert a.metadata != b.metadata
def __init__(self, timestamp: datetime, sensor: str, target: str, metadata: Dict[str, Any]): """ Initialize a Power report using the given parameters. :param timestamp: Report timestamp :param sensor: Sensor name :param target: Target name :param metadata: Metadata values, can be anything that add useful information """ Report.__init__(self, timestamp, sensor, target) self.metadata = metadata
def __init__(self, timestamp: datetime, sensor: str, target: str, action: str, parameters: List): """ Initialize a Control Event report using the given parameters. :param timestamp: Report timestamp :param sensor: Sensor name :param target: Target name :param action: Action name :param parameters: Parameter values """ Report.__init__(self, timestamp, sensor, target) self.action = action self.parameters = parameters
def __init__(self, timestamp: datetime, sensor: str, target: str, socket: int, power: float, metadata: Dict[str, Any]): """ Initialize a Power report using the given parameters. :param datetime timestamp: Report timestamp :param str sensor: Sensor name :param str target: Target name :param float power: Power value :param dict metadata: Metadata values, can be anything that add useful information """ Report.__init__(self, timestamp, sensor, target) self.metadata = metadata self.power = power self.socket = socket
def test_send_Report_to_dummy_formula_make_formula_send_power_report_to_logger_with_42_as_power_value_after_1_second(self, system, started_actor, dummy_pipe_out): report1 = Report(1, 2, 3) system.tell(started_actor, report1) _, msg = recv_from_pipe(dummy_pipe_out, 2) assert isinstance(msg, PowerReport) assert msg.power == 42
def save(self, report: Report, report_model: ReportModel): """ Override from BaseDB :param report: Report to save :param report_model: ReportModel """ self.collection.insert_one(report_model.to_mongodb(report.serialize()))
def save(self, report: Report, report_model: ReportModel): json = report.serialize() with self.lock: for i in range(0, len(self.clients)): if (self.clients[i].is_closing()): self.clients = self.clients[:i] + self.clients[i + 1:] else: self.clients[i].write(str(json).encode())
def save(self, report: Report, report_model: ReportModel): """ Override from BaseDB :param report: Report to save :param report_model: ReportModel """ data = report_model.to_influxdb(report.serialize()) self.client.write_points([data])
def save(self, report: Report, report_model: ReportModel): """ Override from BaseDB :param report: Report to save :param report_model: ReportModel """ value = report_model.to_prometheus(report.serialize()) key = ''.join([value['tags'][tag] for tag in self.report_model.get_tags()]) self.buffer.append(value, key) self._expose_data(key)
def save(self, report: Report, report_model: ReportModel): """ Allow to save a serialized_report in the db :param report: Report :param report_model: ReportModel """ serialized_report = report.serialize() csv_header, data = report_model.to_csvdb(serialized_report) # If the repository doesn't exist, create it rep_path = self.current_path + serialized_report[ 'sensor'] + "-" + serialized_report['target'] try: os.makedirs(rep_path) except FileExistsError: pass for filename, values in data.items(): rep_path_with_file = rep_path + '/' + filename + '.csv' # Get the header and check if it's ok # TODO: inefficient for value in values: header = csv_header + sorted( list( set([event_key for event_key, _ in value.items()]) - set(csv_header))) header_exist = False try: with open(rep_path_with_file) as csvfile: reader = csv.DictReader(csvfile) if reader.fieldnames: header_exist = True if header != reader.fieldnames: raise HeaderAreNotTheSameError( "Header are not the same in " + rep_path_with_file) csvfile.close() except FileNotFoundError: pass # Write with open(rep_path_with_file, 'a') as csvfile: writer = csv.DictWriter(csvfile, header) if not header_exist: writer.writeheader() writer.writerow(value) csvfile.close()
def message_a(): msg = Report(0, 'A', 'A') msg.dispatcher_report_id = 1 return msg
import pytest from mock import Mock from thespian.actors import ActorExitRequest from powerapi.puller import PullerActor from powerapi.message import PullerStartMessage, ErrorMessage, StartMessage, EndMessage from powerapi.filter import Filter, RouterWithoutRuleException from powerapi.report import Report from powerapi.test_utils.abstract_test import AbstractTestActor, AbstractTestActorWithDB, define_database_content, recv_from_pipe from powerapi.test_utils.db import FakeDB from powerapi.test_utils.dummy_actor import DummyActor, DummyStartMessage from powerapi.test_utils.actor import is_actor_alive, system REPORT1 = Report(1, 2, 3) REPORT2 = Report(3, 4, 5) def define_filter(filt): """ Decorator to set the _filt attribute for individual tests. """ def wrap(func): setattr(func, '_filter', filt) return func return wrap
def message_c(): msg = Report(2, 'C', 'C') msg.dispatcher_report_id = 3 return msg
def message_d(): msg = Report(3, 'D', 'D') msg.dispatcher_report_id = 4 return msg
def message_e(): msg = Report(4, 'E', 'E') msg.dispatcher_report_id = 5 return msg
def test_creating_report_with_metadata(): report = Report(('1970-09-01T09:09:10.543'), 'toto', 'all', {"tag": 1}) assert report.metadata["tag"] == 1
def message_f(): msg = Report(5, 'F', 'F') msg.dispatcher_report_id = 6 return msg
def message_g(): msg = Report(6, 'G', 'G') msg.dispatcher_report_id = 7 return msg
def test_modify_report_that_match_regexp_but_with_wrong_domain_name_musnt_modify_report( libvirt_mapper): report = Report(0, 'sensor', LIBVIRT_TARGET_NAME2) new_report = libvirt_mapper.modify_report(report) assert new_report.metadata == {}
def test_modify_report_that_match_regexp_must_modify_report(libvirt_mapper): report = Report(0, 'sensor', LIBVIRT_TARGET_NAME1) new_report = libvirt_mapper.modify_report(report) assert new_report.metadata["domain_id"] == UUID_1
def test_modify_report_that_not_match_regexp_musnt_modify_report( libvirt_mapper): report = Report(0, 'sensor', BAD_TARGET) new_report = libvirt_mapper.modify_report(report) assert new_report.target == BAD_TARGET assert new_report.metadata == {}
def message_b(): msg = Report(1, 'B', 'B') msg.dispatcher_report_id = 2 return msg
def __init__(self): Report.__init__(self, None, None, None) self.value = None