-
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.
Remove updates on created and updated timestamps from the Moab adapter
- Loading branch information
Showing
2 changed files
with
46 additions
and
121 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
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 |
---|---|---|
|
@@ -225,28 +225,16 @@ def test_start_up_command_deprecation_warning(self): | |
|
||
@mock_executor_run_command(TEST_DEPLOY_RESOURCE_RESPONSE) | ||
def test_deploy_resource(self): | ||
expected_resource_attributes = self.resource_attributes | ||
expected_resource_attributes.update( | ||
created=datetime.now(), updated=datetime.now() | ||
) | ||
return_resource_attributes = run_async( | ||
self.moab_adapter.deploy_resource, | ||
resource_attributes=self.resource_attributes, | ||
) | ||
if ( | ||
return_resource_attributes.created - expected_resource_attributes.created | ||
> timedelta(seconds=1) | ||
or return_resource_attributes.updated - expected_resource_attributes.updated | ||
> timedelta(seconds=1) | ||
): | ||
raise Exception("Creation time or update time wrong!") | ||
del ( | ||
expected_resource_attributes.created, | ||
expected_resource_attributes.updated, | ||
return_resource_attributes.created, | ||
return_resource_attributes.updated, | ||
self.assertDictEqual( | ||
AttributeDict( | ||
remote_resource_uuid=4761849, resource_status=ResourceStatus.Booting | ||
), | ||
run_async( | ||
self.moab_adapter.deploy_resource, | ||
resource_attributes=self.resource_attributes, | ||
), | ||
) | ||
self.assertEqual(return_resource_attributes, expected_resource_attributes) | ||
|
||
self.mock_executor.return_value.run_command.assert_called_with( | ||
"msub -j oe -m p -l walltime=02:00:00:00,mem=120gb,nodes=1:ppn=20 -v TardisDroneCores=128,TardisDroneMemory=120,TardisDroneDisk=100,TardisDroneUuid=testsite-abcdef startVM.py" # noqa: B950 | ||
) | ||
|
@@ -260,12 +248,11 @@ def test_deploy_resource_w_submit_options(self): | |
) | ||
) | ||
|
||
moab_adapter = MoabAdapter(machine_type="test2large", site_name="TestSite") | ||
|
||
run_async( | ||
moab_adapter.deploy_resource, | ||
self.moab_adapter.deploy_resource, | ||
resource_attributes=self.resource_attributes, | ||
) | ||
|
||
self.mock_executor.return_value.run_command.assert_called_with( | ||
"msub -M [email protected] -j oe -m p -l walltime=02:00:00:00,mem=120gb,nodes=1:ppn=20 -v TardisDroneCores=128,TardisDroneMemory=120,TardisDroneDisk=100,TardisDroneUuid=testsite-abcdef --timeout=60 startVM.py" # noqa: B950 | ||
) | ||
|
@@ -283,19 +270,15 @@ def test_site_name(self): | |
|
||
@mock_executor_run_command(TEST_RESOURCE_STATUS_RESPONSE) | ||
def test_resource_status(self): | ||
expected_resource_attributes = self.resource_attributes | ||
expected_resource_attributes.update(updated=datetime.now()) | ||
return_resource_attributes = run_async( | ||
self.moab_adapter.resource_status, | ||
resource_attributes=self.resource_attributes, | ||
self.assertDictEqual( | ||
AttributeDict( | ||
remote_resource_uuid=4761849, resource_status=ResourceStatus.Booting | ||
), | ||
run_async( | ||
self.moab_adapter.resource_status, | ||
resource_attributes=self.resource_attributes, | ||
), | ||
) | ||
if ( | ||
return_resource_attributes.updated - expected_resource_attributes.updated | ||
> timedelta(seconds=1) | ||
): | ||
raise Exception("Update time wrong!") | ||
del expected_resource_attributes.updated, return_resource_attributes.updated | ||
self.assertEqual(return_resource_attributes, expected_resource_attributes) | ||
|
||
@mock_executor_run_command(TEST_RESOURCE_STATE_TRANSLATION_RESPONSE) | ||
def test_resource_state_translation(self): | ||
|
@@ -316,49 +299,36 @@ def test_resource_status_update(self): | |
self.assertEqual( | ||
self.resource_attributes["resource_status"], ResourceStatus.Booting | ||
) | ||
return_resource_attributes = run_async( | ||
self.moab_adapter.resource_status, | ||
resource_attributes=self.resource_attributes, | ||
) | ||
self.assertEqual( | ||
return_resource_attributes["resource_status"], ResourceStatus.Running | ||
|
||
self.assertDictEqual( | ||
AttributeDict( | ||
remote_resource_uuid=4761849, resource_status=ResourceStatus.Running | ||
), | ||
run_async( | ||
self.moab_adapter.resource_status, | ||
resource_attributes=self.resource_attributes, | ||
), | ||
) | ||
|
||
@mock_executor_run_command(TEST_TERMINATE_RESOURCE_RESPONSE) | ||
def test_stop_resource(self): | ||
expected_resource_attributes = self.resource_attributes | ||
expected_resource_attributes.update( | ||
updated=datetime.now(), resource_status=ResourceStatus.Stopped | ||
) | ||
return_resource_attributes = run_async( | ||
run_async( | ||
self.moab_adapter.stop_resource, | ||
resource_attributes=self.resource_attributes, | ||
) | ||
if ( | ||
return_resource_attributes.updated - expected_resource_attributes.updated | ||
> timedelta(seconds=1) | ||
): | ||
raise Exception("Update time wrong!") | ||
del expected_resource_attributes.updated, return_resource_attributes.updated | ||
self.assertEqual(return_resource_attributes, expected_resource_attributes) | ||
self.mock_executor.return_value.run_command.assert_called_with( | ||
"canceljob 4761849" | ||
) | ||
|
||
@mock_executor_run_command(TEST_TERMINATE_RESOURCE_RESPONSE) | ||
def test_terminate_resource(self): | ||
expected_resource_attributes = self.resource_attributes | ||
expected_resource_attributes.update( | ||
updated=datetime.now(), resource_status=ResourceStatus.Stopped | ||
) | ||
return_resource_attributes = run_async( | ||
run_async( | ||
self.moab_adapter.terminate_resource, | ||
resource_attributes=self.resource_attributes, | ||
) | ||
if ( | ||
return_resource_attributes.updated - expected_resource_attributes.updated | ||
> timedelta(seconds=1) | ||
): | ||
raise Exception("Update time wrong!") | ||
del expected_resource_attributes.updated, return_resource_attributes.updated | ||
self.assertEqual(return_resource_attributes, expected_resource_attributes) | ||
self.mock_executor.return_value.run_command.assert_called_with( | ||
"canceljob 4761849" | ||
) | ||
|
||
@mock_executor_run_command( | ||
"", | ||
|
@@ -372,18 +342,11 @@ def test_terminate_resource(self): | |
), | ||
) | ||
def test_terminate_dead_resource(self): | ||
expected_resource_attributes = self.resource_attributes | ||
expected_resource_attributes.update( | ||
updated=datetime.now(), resource_status=ResourceStatus.Stopped | ||
) | ||
with self.assertLogs(level=logging.WARNING): | ||
return_resource_attributes = run_async( | ||
run_async( | ||
self.moab_adapter.terminate_resource, | ||
resource_attributes=self.resource_attributes, | ||
) | ||
self.assertEqual( | ||
return_resource_attributes["resource_status"], ResourceStatus.Stopped | ||
) | ||
|
||
@mock_executor_run_command( | ||
"", | ||
|
@@ -461,9 +424,3 @@ def test_exception_handling(to_raise, to_catch): | |
|
||
for to_raise, to_catch in matrix: | ||
test_exception_handling(to_raise, to_catch) | ||
|
||
def test_check_remote_resource_uuid(self): | ||
with self.assertRaises(TardisError): | ||
self.moab_adapter.check_remote_resource_uuid( | ||
AttributeDict(remote_resource_uuid=1), regex=r"^(\d)$", response="2" | ||
) |