Skip to content

Commit

Permalink
feat: libvirt mapper recoded using metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
Lauric Desauw committed Nov 16, 2021
1 parent 0e68edf commit eac86ea
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion powerapi/report_modifier/libvirt_mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def modify_report(self, report):
domain_name = result.groups(0)[0]
try:
domain = self.libvirt.lookupByName(domain_name)
report.target = domain.UUIDString()
report.metadata["domain_id"] = domain.UUIDString()
except libvirtError:
pass
return report
5 changes: 3 additions & 2 deletions tests/unit/report_modifier/test_libvirt_mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,16 @@ 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 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.target == UUID_1
assert new_report.metadata["domain_id"] == UUID_1


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.target == LIBVIRT_TARGET_NAME2
assert new_report.metadata["domain_id"] == LIBVIRT_TARGET_NAME2

0 comments on commit eac86ea

Please sign in to comment.