示例#1
0
  def _validate_and_populate_local_config(self):
    """Validates local job configuration and populates local task config with default values.

    Returns a TaskConfig populated with default values.
    """
    resp = self._scheduler.populateJobConfig(self._config.job())
    self._check_and_log_response(resp)
    return get_populated_task_config(resp)
示例#2
0
    def _validate_and_populate_local_config(self):
        """Validates local job configuration and populates local task config with default values.

    Returns a TaskConfig populated with default values.
    """
        resp = self._scheduler.populateJobConfig(self._config.job())
        self._check_and_log_response(resp)
        return get_populated_task_config(resp)
示例#3
0
 def execute(self, context):
     config = context.get_job_config(context.options.jobspec,
                                     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.query(
         api.build_query(role, name, env=env, statuses=ACTIVE_STATES))
     context.log_response_and_raise(
         resp,
         err_code=EXIT_INVALID_PARAMETER,
         err_msg="Could not find job to diff against")
     if resp.result.scheduleStatusResult.tasks is None:
         context.print_err("No tasks found for job %s" %
                           context.options.jobspec)
         return EXIT_COMMAND_FAILURE
     else:
         remote_tasks = [
             t.assignedTask.task
             for t in resp.result.scheduleStatusResult.tasks
         ]
     resp = api.populate_job_config(config)
     context.log_response_and_raise(resp,
                                    err_code=EXIT_INVALID_CONFIGURATION,
                                    err_msg="Error loading configuration")
     # Deepcopy is important here as tasks will be modified for printing.
     local_tasks = [
         deepcopy(get_populated_task_config(resp))
         for _ in range(config.instances())
     ]
     diff_program = os.environ.get("DIFF_VIEWER", "diff")
     with NamedTemporaryFile() as local:
         self.dump_tasks(local_tasks, local)
         with NamedTemporaryFile() as remote:
             self.dump_tasks(remote_tasks, remote)
             result = subprocess.call(
                 [diff_program, remote.name, local.name])
             # Unlike most commands, diff doesn't return zero on success; it returns
             # 1 when a successful diff is non-empty.
             if result not in (0, 1):
                 raise context.CommandError(EXIT_COMMAND_FAILURE,
                                            "Error running diff command")
             else:
                 return EXIT_OK
示例#4
0
 def execute(self, context):
   config = context.get_job_config(context.options.jobspec, 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.query(api.build_query(role, name, env=env, statuses=ACTIVE_STATES))
   context.log_response_and_raise(resp, err_code=EXIT_INVALID_PARAMETER,
       err_msg="Could not find job to diff against")
   if resp.result.scheduleStatusResult.tasks is None:
     context.print_err("No tasks found for job %s" % context.options.jobspec)
     return EXIT_COMMAND_FAILURE
   else:
     remote_tasks = [t.assignedTask.task for t in resp.result.scheduleStatusResult.tasks]
   resp = api.populate_job_config(config)
   context.log_response_and_raise(resp, err_code=EXIT_INVALID_CONFIGURATION,
         err_msg="Error loading configuration")
   # Deepcopy is important here as tasks will be modified for printing.
   local_tasks = [deepcopy(get_populated_task_config(resp)) for _ in range(config.instances())]
   diff_program = os.environ.get("DIFF_VIEWER", "diff")
   with NamedTemporaryFile() as local:
     self.dump_tasks(local_tasks, local)
     with NamedTemporaryFile() as remote:
       self.dump_tasks(remote_tasks, remote)
       result = subprocess.call([diff_program, remote.name, local.name])
       # Unlike most commands, diff doesn't return zero on success; it returns
       # 1 when a successful diff is non-empty.
       if result not in (0, 1):
         raise context.CommandError(EXIT_COMMAND_FAILURE, "Error running diff command")
       else:
         return EXIT_OK
 def test_get_populated_task_config_deprecated_set(self):
     config = TaskConfig()
     resp = Response(responseCode=ResponseCode.OK,
                     result=Result(populateJobResult=PopulateJobResult(
                         populatedDEPRECATED=set([config]))))
     assert config == base.get_populated_task_config(resp)
 def test_get_populated_task_config_set(self):
     config = TaskConfig()
     resp = Response(responseCode=ResponseCode.OK,
                     result=Result(populateJobResult=PopulateJobResult(
                         taskConfig=config)))
     assert config == base.get_populated_task_config(resp)
 def test_get_populated_task_config_deprecated_set(self):
   config = TaskConfig()
   resp = Response(responseCode=ResponseCode.OK, result=Result(populateJobResult=PopulateJobResult(
       populatedDEPRECATED=set([config]))))
   assert config == base.get_populated_task_config(resp)
 def test_get_populated_task_config_set(self):
   config = TaskConfig()
   resp = Response(responseCode=ResponseCode.OK, result=Result(populateJobResult=PopulateJobResult(
       taskConfig=config)))
   assert config == base.get_populated_task_config(resp)