Skip to content

Commit

Permalink
Auditor plugin review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
stefan-k committed Sep 14, 2022
1 parent 445d422 commit bc39f2e
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 16 deletions.
16 changes: 9 additions & 7 deletions tardis/plugins/auditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,18 @@ def __init__(self):
for machine_type in getattr(config, site.name).MachineTypes:
self._resources[site.name][machine_type] = {}
self._components[site.name][machine_type] = {}
for r in getattr(config, site.name).MachineMetaData[machine_type]:
self._resources[site.name][machine_type][r] = getattr(
for resource in getattr(config, site.name).MachineMetaData[
machine_type
]:
self._resources[site.name][machine_type][resource] = getattr(
config, site.name
).MachineMetaData[machine_type][r]
self._components[site.name][machine_type][r] = getattr(
).MachineMetaData[machine_type][resource]
self._components[site.name][machine_type][resource] = getattr(
config_auditor.components, machine_type
).get(r, {})
).get(resource, {})

self._user = config_auditor.user if config_auditor.user else "tardis"
self._group = config_auditor.group if config_auditor.group else "tardis"
self._user = getattr(config_auditor, "user", "tardis")
self._group = getattr(config_auditor, "group", "tardis")
auditor_timeout = getattr(config_auditor, "timeout", 30)
self._local_timezone = get_localzone()
self._client = (
Expand Down
65 changes: 56 additions & 9 deletions tests/plugins_t/test_auditor.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
from tardis.plugins.auditor import Auditor
from tardis.utilities.attributedict import AttributeDict
from tardis.interfaces.siteadapter import ResourceStatus
from tardis.resources.dronestates import AvailableState, DownState
from tardis.resources.dronestates import (
AvailableState,
DownState,
BootingState,
CleanupState,
ShutDownState,
ShuttingDownState,
DrainState,
DrainingState,
IntegrateState,
DisintegrateState,
)

from datetime import datetime
from unittest import TestCase
Expand Down Expand Up @@ -39,14 +50,18 @@ def setUp(self):
self.drone_uuid = "test-drone"
self.machine_type = "test_machine_type"
config = self.mock_config.return_value
config.Plugins.Auditor.host = self.address
config.Plugins.Auditor.port = self.port
config.Plugins.Auditor.timeout = self.timeout
config.Plugins.Auditor.user = self.user
config.Plugins.Auditor.group = self.group
config.Plugins.Auditor.components.test_machine_type = AttributeDict(
Cores=AttributeDict(HEPSPEC=1.2, BENCHMARK=3.0),
Memory=AttributeDict(BLUBB=1.4),
config.Plugins.Auditor = AttributeDict(
host=self.address,
port=self.port,
timeout=self.timeout,
user=self.user,
group=self.group,
components=AttributeDict(
test_machine_type=AttributeDict(
Cores=AttributeDict(HEPSPEC=1.2, BENCHMARK=3.0),
Memory=AttributeDict(BLUBB=1.4),
)
),
)
config.Sites = [AttributeDict(name=self.site)]
config.testsite.MachineTypes = [self.machine_type]
Expand All @@ -70,8 +85,21 @@ def setUp(self):
self.client.add.return_value = async_return()
self.client.update.return_value = async_return()

self.config = config
self.plugin = Auditor()

def test_default_fields(self):
# Potential future race condition ahead.
# Since this is the only test modifying self.config, this is
# fine. However, when adding further tests care must be taken
# when config changes are involved.
del self.config.Plugins.Auditor.user
del self.config.Plugins.Auditor.group
# Needed in order to reload config.
plugin = Auditor()
self.assertEqual(plugin._user, "tardis")
self.assertEqual(plugin._group, "tardis")

def test_notify(self):
self.mock_auditorclientbuilder.return_value.address.assert_called_with(
self.address,
Expand All @@ -96,6 +124,25 @@ def test_notify(self):
self.assertEqual(self.client.add.call_count, 1)
self.assertEqual(self.client.update.call_count, 1)

# test for no-op
for state in [
BootingState(),
IntegrateState(),
CleanupState(),
ShutDownState(),
ShuttingDownState(),
DrainState(),
DrainingState(),
DisintegrateState(),
]:
run_async(
self.plugin.notify,
state=state,
resource_attributes=self.test_param,
)
self.assertEqual(self.client.add.call_count, 1)
self.assertEqual(self.client.update.call_count, 1)

def test_construct_record(self):
record = self.plugin.construct_record(resource_attributes=self.test_param)

Expand Down

0 comments on commit bc39f2e

Please sign in to comment.