def execute(self, context): config = context.get_job_config(context.options.instance_spec.jobkey, context.options.config_file) if context.options.rename_from is not None: cluster = context.options.rename_from.cluster role = context.options.rename_from.role env = context.options.rename_from.environment name = context.options.rename_from.name else: cluster = config.cluster() role = config.role() env = config.environment() name = config.name() api = context.get_api(cluster) resp = api.populate_job_config(config) context.log_response_and_raise(resp, err_code=EXIT_INVALID_CONFIGURATION, err_msg="Error loading configuration") local_task = resp.result.populateJobResult.taskConfig # Deepcopy is important here as tasks will be modified for printing. local_tasks = [deepcopy(local_task) for _ in range(config.instances())] instances = ( None if context.options.instance_spec.instance == ALL_INSTANCES else context.options.instance_spec.instance ) formatter = DiffFormatter(context, config, cluster, role, env, name) if config.raw().has_cron_schedule(): formatter.diff_no_update_details(local_tasks) else: formatter.show_job_update_diff(instances, local_task) return EXIT_OK
def execute(self, context): config = context.get_job_config(context.options.instance_spec.jobkey, context.options.config_file) if context.options.rename_from is not None: cluster = context.options.rename_from.cluster role = context.options.rename_from.role env = context.options.rename_from.environment name = context.options.rename_from.name else: cluster = config.cluster() role = config.role() env = config.environment() name = config.name() api = context.get_api(cluster) resp = api.populate_job_config(config) context.log_response_and_raise(resp, err_code=EXIT_INVALID_CONFIGURATION, err_msg="Error loading configuration") local_task = resp.result.populateJobResult.taskConfig # Deepcopy is important here as tasks will be modified for printing. local_tasks = [deepcopy(local_task) for _ in range(config.instances())] instances = (None if context.options.instance_spec.instance == ALL_INSTANCES else context.options.instance_spec.instance) formatter = DiffFormatter(context, config, cluster, role, env, name) if config.raw().has_cron_schedule(): formatter.diff_no_update_details(local_tasks) else: formatter.show_job_update_diff(instances, local_task) return EXIT_OK
def test_diff_no_update_details_success(self): config = self.get_job_config(is_cron=True) self._fake_context.get_job_config = Mock(return_value=config) formatter = DiffFormatter(self._fake_context, config) self._mock_api.query.return_value = self.create_empty_task_result() query = TaskQuery( jobKeys=[self.TEST_JOBKEY.to_thrift()], statuses=ACTIVE_STATES) self._mock_api.build_query.return_value = query local_tasks = [] formatter.diff_no_update_details(local_tasks)
def test_diff_no_update_details_success(self): config = self.get_job_config(is_cron=True) self._fake_context.get_job_config = Mock(return_value=config) formatter = DiffFormatter(self._fake_context, config) self._mock_api.query.return_value = self.create_empty_task_result() query = TaskQuery( jobKeys=[self.TEST_JOBKEY.to_thrift()], statuses=ACTIVE_STATES) self._mock_api.build_query.return_value = query local_tasks = [] with contextlib.nested( patch('subprocess.call', return_value=0), patch('json.loads', return_value={})) as (subprocess_patch, _): formatter.diff_no_update_details(local_tasks) assert subprocess_patch.call_count == 1 assert subprocess_patch.call_args[0][0].startswith( os.environ.get('DIFF_VIEWER', 'diff') + ' ')
def test_diff_no_update_details_success(self): config = self.get_job_config(is_cron=True) self._fake_context.get_job_config = Mock(return_value=config) formatter = DiffFormatter(self._fake_context, config) self._mock_api.query.return_value = self.create_empty_task_result() query = TaskQuery(jobKeys=[self.TEST_JOBKEY.to_thrift()], statuses=ACTIVE_STATES) self._mock_api.build_query.return_value = query local_tasks = [] with contextlib.nested(patch('subprocess.call', return_value=0), patch('json.loads', return_value={})) as (subprocess_patch, _): formatter.diff_no_update_details(local_tasks) assert subprocess_patch.call_count == 1 assert subprocess_patch.call_args[0][0].startswith( os.environ.get('DIFF_VIEWER', 'diff') + ' ')