def test_format_tron_job_dict_with_cleanup_action( self, mock_format_action, mock_get_action_config, ): job_dict = { 'name': 'my_job', 'node': 'batch_server', 'schedule': 'daily 12:10:00', 'service': 'my_service', 'deploy_group': 'prod', 'max_runtime': '2h', 'actions': [{ 'name': 'normal', 'command': 'echo first', }], 'cleanup_action': { 'command': 'rm *', }, } job_config = tron_tools.TronJobConfig(job_dict, 'paasta-dev') result = tron_tools.format_tron_job_dict(job_config) assert mock_get_action_config.call_count == 2 assert mock_format_action.call_count == 2 assert result == { 'name': 'my_job', 'node': 'batch_server', 'schedule': 'daily 12:10:00', 'max_runtime': '2h', 'actions': [mock_format_action.return_value], 'cleanup_action': mock_format_action.return_value, }
def test_format_tron_job_dict_with_cleanup_action( self, mock_format_action, mock_get_action_config ): job_dict = { "node": "batch_server", "schedule": "daily 12:10:00", "service": "my_service", "deploy_group": "prod", "max_runtime": "2h", "actions": {"normal": {"command": "echo first"}}, "cleanup_action": {"command": "rm *"}, "monitoring": {"team": "noop"}, } job_config = tron_tools.TronJobConfig("my_job", job_dict, "paasta-dev") result = tron_tools.format_tron_job_dict(job_config) assert mock_get_action_config.call_args_list == [ mock.call(job_config, "normal", job_dict["actions"]["normal"]), mock.call(job_config, "cleanup", job_dict["cleanup_action"]), ] assert mock_format_action.call_count == 2 assert result == { "node": "batch_server", "schedule": "daily 12:10:00", "max_runtime": "2h", "actions": { mock_get_action_config.return_value.get_action_name.return_value: mock_format_action.return_value }, "cleanup_action": mock_format_action.return_value, "monitoring": {"team": "noop"}, }
def test_format_tron_job_dict( self, mock_format_action, mock_get_action_config, action_list, ): action_name = 'normal' action_dict = { 'command': 'echo first', } if action_list: action_dict['name'] = 'normal' actions = [action_dict] else: actions = {action_name: action_dict} job_dict = { 'node': 'batch_server', 'schedule': 'daily 12:10:00', 'service': 'my_service', 'deploy_group': 'prod', 'max_runtime': '2h', 'actions': actions, 'expected_runtime': '1h', 'monitoring': { 'team': 'noop' }, } soa_dir = '/other_dir' cluster = 'paasta-dev' job_config = tron_tools.TronJobConfig('my_job', job_dict, cluster, soa_dir=soa_dir) result = tron_tools.format_tron_job_dict(job_config) mock_get_action_config.assert_called_once_with(job_config, action_name, action_dict) mock_format_action.assert_called_once_with( mock_get_action_config.return_value) assert result == { 'node': 'batch_server', 'schedule': 'daily 12:10:00', 'max_runtime': '2h', 'actions': { mock_get_action_config.return_value.get_action_name.return_value: mock_format_action.return_value, }, 'expected_runtime': '1h', 'monitoring': { 'team': 'noop' }, }
def test_format_tron_job_dict_with_cleanup_action( self, mock_format_action, mock_get_action_config, ): job_dict = { 'node': 'batch_server', 'schedule': 'daily 12:10:00', 'service': 'my_service', 'deploy_group': 'prod', 'max_runtime': '2h', 'actions': { 'normal': { 'command': 'echo first', }, }, 'cleanup_action': { 'command': 'rm *', }, 'monitoring': { 'team': 'noop' }, } job_config = tron_tools.TronJobConfig('my_job', job_dict, 'paasta-dev') result = tron_tools.format_tron_job_dict(job_config) assert mock_get_action_config.call_args_list == [ mock.call(job_config, 'normal', job_dict['actions']['normal']), mock.call(job_config, 'cleanup', job_dict['cleanup_action']), ] assert mock_format_action.call_count == 2 assert result == { 'node': 'batch_server', 'schedule': 'daily 12:10:00', 'max_runtime': '2h', 'actions': { mock_get_action_config.return_value.get_action_name.return_value: mock_format_action.return_value, }, 'cleanup_action': mock_format_action.return_value, 'monitoring': { 'team': 'noop' }, }
def test_format_tron_job_dict(self, mock_format_action, mock_get_action_config): action_name = "normal" action_dict = {"command": "echo first"} actions = {action_name: action_dict} job_dict = { "node": "batch_server", "schedule": "daily 12:10:00", "service": "my_service", "deploy_group": "prod", "max_runtime": "2h", "actions": actions, "expected_runtime": "1h", "monitoring": { "team": "noop" }, } soa_dir = "/other_dir" cluster = "paasta-dev" job_config = tron_tools.TronJobConfig("my_job", job_dict, cluster, soa_dir=soa_dir) result = tron_tools.format_tron_job_dict(job_config) mock_get_action_config.assert_called_once_with(job_config, action_name, action_dict) mock_format_action.assert_called_once_with( mock_get_action_config.return_value) assert result == { "node": "batch_server", "schedule": "daily 12:10:00", "max_runtime": "2h", "actions": { mock_get_action_config.return_value.get_action_name.return_value: mock_format_action.return_value }, "expected_runtime": "1h", "monitoring": { "team": "noop" }, }
def test_format_tron_job_dict( self, mock_format_action, mock_get_action_config, ): action_dict = { 'name': 'normal', 'command': 'echo first', } job_dict = { 'name': 'my_job', 'node': 'batch_server', 'schedule': 'daily 12:10:00', 'service': 'my_service', 'deploy_group': 'prod', 'max_runtime': '2h', 'actions': [action_dict], 'expected_runtime': '1h', } soa_dir = '/other_dir' job_config = tron_tools.TronJobConfig(job_dict, soa_dir=soa_dir) fqdn_format = 'paasta-{cluster:s}' default_cluster = 'paasta-dev' result = tron_tools.format_tron_job_dict(job_config, fqdn_format, default_cluster) mock_get_action_config.assert_called_once_with(job_config, action_dict, default_cluster) mock_format_action.assert_called_once_with( mock_get_action_config.return_value, fqdn_format) assert result == { 'name': 'my_job', 'node': 'batch_server', 'schedule': 'daily 12:10:00', 'max_runtime': '2h', 'actions': [mock_format_action.return_value], 'expected_runtime': '1h', }