diff --git a/SAS/ResourceAssignment/ResourceAssigner/lib/resource_assigner.py b/SAS/ResourceAssignment/ResourceAssigner/lib/resource_assigner.py index 862491c47751855341fadeda6f4d31f6107d7770..e82cd3dda9625a1140e1b188b27f1e5b4d0e6cf0 100755 --- a/SAS/ResourceAssignment/ResourceAssigner/lib/resource_assigner.py +++ b/SAS/ResourceAssignment/ResourceAssigner/lib/resource_assigner.py @@ -273,6 +273,7 @@ class ResourceAssigner(object): """ main_parset = self._get_main_parset(specification_tree) + task_type = self._get_task_type(specification_tree) cluster_name = self._get_clustername(otdb_id, main_parset, task_type) start_time, end_time = self._get_main_task_start_and_end_times(specification_tree) @@ -608,7 +609,7 @@ class ResourceAssigner(object): try: estimates, rerpc_status = self.rerpc({"specification_tree": specification_tree}, timeout=10) - logger.info('Resource Estimator reply = %s', re_reply) + logger.info('Resource Estimator reply = %s', estimates) if estimates['errors']: for error in estimates['errors']: diff --git a/SAS/ResourceAssignment/ResourceAssigner/test/t_resourceassigner.py b/SAS/ResourceAssignment/ResourceAssigner/test/t_resourceassigner.py index 44f93c2fa7f70d66533484c2411bc23fe4bd7e12..2dfc210ebb5b5b31f988ae2204a4408d09756829 100755 --- a/SAS/ResourceAssignment/ResourceAssigner/test/t_resourceassigner.py +++ b/SAS/ResourceAssignment/ResourceAssigner/test/t_resourceassigner.py @@ -236,7 +236,6 @@ class ResourceAssignerTest(unittest.TestCase): } rerpc_replymessage = { str(otdb_id): { - 'pipeline': { 'errors': [], 'estimates': [{ 'resource_types': {'bandwidth': 2, 'storage': 2}, @@ -247,20 +246,16 @@ class ResourceAssignerTest(unittest.TestCase): }] } }] - } }, str(resources_with_rcus_otdb_id): { - 'observation': { 'errors': [], 'estimates': [{ 'resource_types': {'rcu': '111100010111100101101010' }, 'resource_count': 1, 'root_resource_group': 'CS001' }] - } }, str(resources_with_errors_otdb_id): { - 'pipeline': { 'estimates': [{ 'resource_types': {'bandwidth': 19021319494, 'storage': 713299481024}, 'output_files': { @@ -276,16 +271,11 @@ class ResourceAssignerTest(unittest.TestCase): } }], 'errors': [resource_error1, resource_error2] - } }, str(unknown_resource_type_otdb_id): { - 'pipeline': { - str(unknown_resource_type_name): { - } - } }, - str(maintenance_otdb_id): { - 'reservation': {'errors': [], + str(maintenance_otdb_id): + {'errors': [], 'estimates': [{'resource_count': 1, 'resource_types': {'rcu': '111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111'}, 'root_resource_group': 'CS001'}, @@ -309,15 +299,15 @@ class ResourceAssignerTest(unittest.TestCase): # 'resource_types': {'bandwidth': 3000000000, # 'rsp': 3904}, # 'root_resource_group': 'CS002RSP1'}, - ]}} + ]} , - str(projectreservation_otdb_id): { - 'reservation': {'errors': [], + str(projectreservation_otdb_id): + {'errors': [], 'estimates': [{'resource_count': 1, 'resource_types': {'rcu': '111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111'}, 'root_resource_group': 'CS001'}, - ]}} - } + ]} + } cep4bandwidth_resource_id = 116 cep4storage_resource_id = 117 @@ -1534,10 +1524,15 @@ class ResourceAssignerTest(unittest.TestCase): {'name': 'min_inter_task_delay', 'value': 60}, {'name': 'max_fill_ratio_CEP4_bandwidth', 'value': 0.75} ] + def rerpc_mock(params, timeout=10): + specification_tree = params["specification_tree"] + otdb_id = specification_tree['otdb_id'] + return self.rerpc_replymessage[str(otdb_id)], self.rerpc_status + rerpc_patcher = mock.patch('lofar.messaging.RPC') self.addCleanup(rerpc_patcher.stop) self.rerpc_mock = rerpc_patcher.start() - self.rerpc_mock.return_value = self.rerpc_replymessage, self.rerpc_status + self.rerpc_mock.side_effect = rerpc_mock otdbrpc_patcher = mock.patch('lofar.sas.otdb.otdbrpc') self.addCleanup(otdbrpc_patcher.stop) @@ -1958,16 +1953,6 @@ class ResourceAssignerTest(unittest.TestCase): self.rerpc_mock.assert_any_call({"specification_tree": self.specification_tree}, timeout=10) - def test_do_assignment_logs_when_otdb_id_not_needed_resources(self): - self.specification_tree["otdb_id"] = self.otdb_id + 11 - - self.resource_assigner.do_assignment(self.specification_tree['otdb_id'], self.specification_tree) - - self.logger_mock.error.assert_any_call( - "An exception occurred while obtaining resource estimates. Exception=no otdb_id %s found in estimator results %s" % - (self.otdb_id + 11, self.rerpc_replymessage) - ) - def test_do_assignment_should_not_claim_resouces_when_otdb_id_not_needed_resources(self): self.specification_tree["otdb_id"] = self.otdb_id + 1 @@ -1975,17 +1960,6 @@ class ResourceAssignerTest(unittest.TestCase): self.rarpc_mock.insertResourceClaims.assert_not_called() - def test_do_assignment_logs_when_task_type_not_in_needed_resources(self): - wrong_task_type = "observation" - self.specification_tree["task_type"] = wrong_task_type - - self.resource_assigner.do_assignment(self.specification_tree['otdb_id'], self.specification_tree) - - self.logger_mock.error.assert_any_call( - "An exception occurred while obtaining resource estimates. Exception=no task type %s found in estimator results %s" % - (wrong_task_type, self.rerpc_replymessage[str(self.otdb_id)]) - ) - def test_do_assignment_should_not_claim_resources_when_task_type_not_in_needed_resources(self): wrong_task_type = "observation" self.specification_tree["task_type"] = wrong_task_type @@ -2008,7 +1982,7 @@ class ResourceAssignerTest(unittest.TestCase): self.resource_assigner.do_assignment(self.specification_tree['otdb_id'], self.specification_tree) self.logger_mock.error.assert_any_call( - "An exception occurred while obtaining resource estimates. Exception=Error(s) in estimator for otdb_id=%s radb_id=%s" % + "An exception occurred while obtaining resource estimates. Exception=%s", "Error(s) in estimator for otdb_id=%s radb_id=%s" % (self.resources_with_errors_otdb_id, self.task_id) ) @@ -2036,11 +2010,6 @@ class ResourceAssignerTest(unittest.TestCase): found = True return found - def test_do_assignment_should_log_estimator_reply(self): - self.resource_assigner.do_assignment(self.specification_tree['otdb_id'], self.specification_tree) - - self.logger_mock.info.assert_any_call('Resource Estimator reply = %s', self.rerpc_replymessage) - def test_do_assignment_updates_task_when_it_was_unable_to_claim_some_or_all_resources(self): self.dwell_scheduler_mock().allocate_resources.return_value = False