Skip to content

Commit

Permalink
Add lancium deploy resource test
Browse files Browse the repository at this point in the history
  • Loading branch information
giffels committed Nov 17, 2022
1 parent d950709 commit 04313ab
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 3 deletions.
4 changes: 2 additions & 2 deletions docs/source/changelog.rst
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
.. Created by changelog.py at 2022-11-11, command
.. Created by changelog.py at 2022-11-17, command
'/Users/giffler/.cache/pre-commit/repor6pnmwlm/py_env-python3.10/bin/changelog docs/source/changes compile --output=docs/source/changelog.rst'
based on the format of 'https://keepachangelog.com/'
#########
CHANGELOG
#########

[Unreleased] - 2022-11-11
[Unreleased] - 2022-11-17
=========================

Added
Expand Down
94 changes: 93 additions & 1 deletion tests/adapters_t/sites_t/test_lancium.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
from tardis.adapters.sites.lancium import LanciumAdapter
from tardis.interfaces.siteadapter import ResourceStatus
from tardis.utilities.attributedict import AttributeDict

from ...utilities.utilities import run_async, set_awaitable_return_value

from unittest import TestCase
from unittest.mock import patch
Expand All @@ -15,12 +19,100 @@ def setUpClass(cls) -> None:
cls.mock_lancium_api_patcher = patch(
"tardis.adapters.sites.lancium.LanciumClient"
)
cls.mock_openstack_api = cls.mock_lancium_api_patcher.start()
cls.mock_lancium_api = cls.mock_lancium_api_patcher.start()

@classmethod
def tearDownClass(cls):
cls.mock_config_patcher.stop()
cls.mock_lancium_api_patcher.stop()

def setUp(self) -> None:
self.mock_configuration()
self.mock_lancium_adapter()
self.adapter = LanciumAdapter(machine_type="test2large", site_name="TestSite")

def mock_configuration(self):
config = self.mock_config.return_value
test_site_config = config.TestSite
test_site_config.api_url = "https://test.site.api"
test_site_config.api_key = "top_secret_test"
test_site_config.max_age = 1
test_site_config.MachineTypeConfiguration = AttributeDict(
test2large=AttributeDict(
qos="high",
image="lancium/ubuntu",
command_line="sleep 500",
max_run_time=600,
)
)
test_site_config.MachineMetaData = AttributeDict(
test2large=AttributeDict(Cores=8, Memory=20, Disk=20)
)

def mock_lancium_adapter(self):
self.mocked_lancium_api = self.mock_lancium_api.return_value
set_awaitable_return_value(
self.mocked_lancium_api.jobs.create_job,
{"job": {"id": 123, "status": "created", "name": "testsite-089123"}},
)
set_awaitable_return_value(self.mocked_lancium_api.jobs.submit_job, {})

def test_deploy_resource(self):
self.assertEqual(
AttributeDict(
drone_uuid="testsite-089123",
remote_resource_uuid=123,
resource_status=ResourceStatus.Booting,
),
run_async(
self.adapter.deploy_resource,
resource_attributes=AttributeDict(
drone_uuid="testsite-089123",
obs_machine_meta_data_translation_mapping=AttributeDict(
Cores=1,
Memory=1,
Disk=1,
),
),
),
)

self.assertDictEqual(
{
"name": "testsite-089123",
"qos": "high",
"image": "lancium/ubuntu",
"command_line": "sleep 500",
"max_run_time": 600,
"resources": {"core_count": 8, "memory": 20, "scratch": 20},
"environment": [
{"variable": "TardisDroneCores", "value": "8"},
{"variable": "TardisDroneMemory", "value": "20"},
{"variable": "TardisDroneDisk", "value": "20"},
{"variable": "TardisDroneUuid", "value": "testsite-089123"},
],
},
self.mocked_lancium_api.jobs.create_job.call_args.kwargs["job"],
)
self.mocked_lancium_api.jobs.submit_job.assert_called_with(id=123)

def test_machine_meta_data(self):
...

def test_machine_type(self):
...

def test_site_name(self):
...

def test_resource_status(self):
...

def test_stop_resource(self):
...

def test_terminate_resource(self):
...

def test_exception_handling(self):
...

0 comments on commit 04313ab

Please sign in to comment.