-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
113 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
from tardis.plugins.auditor import Auditor | ||
from tardis.utilities.attributedict import AttributeDict | ||
from tardis.interfaces.siteadapter import ResourceStatus | ||
from tardis.resources.dronestates import AvailableState | ||
|
||
from datetime import datetime | ||
from unittest import TestCase | ||
from unittest.mock import patch | ||
|
||
from ..utilities.utilities import run_async | ||
|
||
|
||
class TestAuditor(TestCase): | ||
@classmethod | ||
def setUpClass(cls): | ||
cls.mock_config_patcher = patch("tardis.plugins.auditor.Configuration") | ||
cls.mock_auditor_patcher = patch("tardis.plugins.auditor.Auditor") | ||
|
||
cls.mock_auditor_patcher = patch("tardis.plugins.auditor.AuditorClientBuilder") | ||
cls.mock_config = cls.mock_config_patcher.start() | ||
cls.mock_auditor = cls.mock_auditor_patcher.start() | ||
|
||
@classmethod | ||
def tearDownClass(cls): | ||
cls.mock_config_patcher.stop() | ||
cls.mock_auditor_patcher.stop() | ||
|
||
def setUp(self): | ||
self.address = "127.0.0.1" | ||
self.port = 8000 | ||
self.user = "user-1" | ||
self.group = "group-1" | ||
config = self.mock_config.return_value | ||
config.Plugins.Auditor.address = self.address | ||
config.Plugins.Auditor.port = self.port | ||
config.Plugins.Auditor.user = self.user | ||
config.Plugins.Auditor.group = self.group | ||
config.Plugins.Auditor.components.test_machine_type.Cores = AttributeDict( | ||
HEPSPEC=1.2, BENCHMARK=3.0 | ||
) | ||
config.Plugins.Auditor.components.test_machine_type.Memory = AttributeDict( | ||
BLUBB=1.4 | ||
) | ||
config.Sites.name = ["testsite"] | ||
config.testsite.MachineTypes = ["test_machine_type"] | ||
config.testsite.MachineMetaData.test_machine_type.Cores = 12 | ||
config.testsite.MachineMetaData.test_machine_type.Memory = 100 | ||
|
||
self.plugin = Auditor() | ||
|
||
def test_notify(self): | ||
test_param = AttributeDict( | ||
site_name="testsite", | ||
machine_type="test_machine_type", | ||
created=datetime.now(), | ||
updated=datetime.now(), | ||
resource_status=ResourceStatus.Booting, | ||
drone_uuid="test-drone", | ||
) | ||
|
||
self.mock_auditor.return_value.search.return_value = { | ||
"hits": {"total": {"value": 2}} | ||
} | ||
|
||
run_async( | ||
self.plugin.notify, state=AvailableState(), resource_attributes=test_param | ||
) | ||
|
||
# self.mock_auditor.return_value.search.assert_called_with( | ||
# index=f"{self.plugin._index}*", | ||
# body={"query": {"term": {"drone_uuid.keyword": test_param.drone_uuid}}}, | ||
# ) | ||
# self.mock_auditor.return_value.create.assert_called_with( | ||
# body=test_param_ext, | ||
# id=f"{test_param.drone_uuid}-2", | ||
# index=f"{self.plugin._index}-{self.mock_datetime.now.return_value.strftime.return_value}", # noqa: B950 | ||
# ) | ||
|
||
# def test_notify_resource_status_missing(self): | ||
# test_param = AttributeDict( | ||
# site_name="test-site", | ||
# machine_type="test_machine_type", | ||
# created=datetime.now(), | ||
# updated=datetime.now(), | ||
# drone_uuid="test-drone", | ||
# ) | ||
# | ||
# test_param_ext = { | ||
# **test_param, | ||
# "state": str(CleanupState()), | ||
# "meta": self.plugin._meta, | ||
# "timestamp": int(self.mock_time.return_value * 1000), | ||
# "resource_status": "", | ||
# "revision": 2, | ||
# } | ||
# | ||
# self.mock_auditor.return_value.search.return_value = { | ||
# "hits": {"total": {"value": 2}} | ||
# } | ||
# | ||
# run_async( | ||
# self.plugin.notify, state=CleanupState(), resource_attributes=test_param | ||
# ) | ||
# | ||
# self.mock_auditor.return_value.search.assert_called_with( | ||
# index=f"{self.plugin._index}*", | ||
# body={"query": {"term": {"drone_uuid.keyword": test_param.drone_uuid}}}, | ||
# ) | ||
# self.mock_auditor.return_value.create.assert_called_with( | ||
# body=test_param_ext, | ||
# id=f"{test_param.drone_uuid}-2", | ||
# index=f"{self.plugin._index}-{self.mock_datetime.now.return_value.strftime.return_value}", # noqa: B950 | ||
# ) |