Ejemplo n.º 1
0
def test_get_config_announces():
    for good_config in (MESOS_CONFIG_WITH_ANNOUNCE_1, MESOS_CONFIG_WITH_ANNOUNCE_2, MESOS_CONFIG_WITHOUT_ANNOUNCE):
        with temporary_file() as fp:
            fp.write(good_config)
            fp.flush()

            fp.seek(0)
            config.get_config("hello_world", fp)
Ejemplo n.º 2
0
def test_get_config_announces():
    for good_config in (MESOS_CONFIG_WITH_ANNOUNCE_1,
                        MESOS_CONFIG_WITH_ANNOUNCE_2,
                        MESOS_CONFIG_WITHOUT_ANNOUNCE):
        with temporary_file() as fp:
            fp.write(good_config)
            fp.flush()

            fp.seek(0)
            config.get_config('hello_world', fp)
Ejemplo n.º 3
0
def test_get_config_select():
    with temporary_file() as fp:
        fp.write(MESOS_CONFIG_BASE % "")
        fp.flush()

        fp.seek(0)
        config.get_config("hello_world", fp, select_env="test", select_role="john_doe", select_cluster="test-cluster")

        fp.seek(0)
        with pytest.raises(ValueError) as cm:
            config.get_config(
                "hello_world", fp, select_env="staging42", select_role="moua", select_cluster="test-cluster"
            )
        assert "test-cluster/john_doe/test/hello_world" in str(cm.value.message)
Ejemplo n.º 4
0
def get_job_config(job_spec, config_file, options):
  try:
    job_key = AuroraJobKey.from_path(job_spec)
    select_cluster = job_key.cluster
    select_env = job_key.env
    select_role = job_key.role
    jobname = job_key.name
  except AuroraJobKey.Error:
    deprecation_warning('Please refer to your job in CLUSTER/ROLE/ENV/NAME format.')
    select_cluster = options.cluster if options.cluster else None
    select_env = options.env
    select_role = None
    jobname = job_spec
  try:
    json_option = options.json
  except AttributeError:
    json_option = False
  try:
    bindings = options.bindings
  except AttributeError:
    bindings = ()
  return get_config(
      jobname,
      config_file,
      json_option,
      bindings,
      select_cluster=select_cluster,
      select_role=select_role,
      select_env=select_env)
Ejemplo n.º 5
0
def test_get_config_select():
  with temporary_file() as fp:
    fp.write(MESOS_CONFIG_BASE % '')
    fp.flush()

    fp.seek(0)
    config.get_config(
        'hello_world', fp, select_env='test',
        select_role='john_doe', select_cluster='test-cluster')

    fp.seek(0)
    with pytest.raises(ValueError) as cm:
      config.get_config(
          'hello_world', fp, select_env='staging42',
          select_role='moua', select_cluster='test-cluster')
    assert 'test-cluster/john_doe/test/hello_world' in str(cm.value.message)
Ejemplo n.º 6
0
 def get_job_config(self, jobkey, config_file):
   """Loads a job configuration from a config file."""
   jobname = jobkey.name
   try:
     # TODO(mchucarroll): pull request to pystachio, to make it possible to log the loaded
     # file without double-reading.
     with open(config_file, "r") as fp:
       self.print_log(TRANSCRIPT, "Config: %s" % fp.readlines())
     bindings = bindings_to_list(self.options.bindings) if self.options.bindings else None
     result = get_config(
       jobname,
       config_file,
       self.options.read_json,
       bindings,
       select_cluster=jobkey.cluster,
       select_role=jobkey.role,
       select_env=jobkey.env)
     check_result = result.raw().check()
     if not check_result.ok():
       self.print_err(str(check_result))
       raise self.CommandError(EXIT_INVALID_CONFIGURATION,
           "Error in configuration")
     return result
   except Exception as e:
     raise self.CommandError(EXIT_INVALID_CONFIGURATION, 'Error loading configuration: %s' % e)
Ejemplo n.º 7
0
def get_job_config(job_spec, config_file, options):
    try:
        job_key = AuroraJobKey.from_path(job_spec)
        select_cluster = job_key.cluster
        select_env = job_key.env
        select_role = job_key.role
        jobname = job_key.name
    except AuroraJobKey.Error:
        deprecation_warning(
            'Please refer to your job in CLUSTER/ROLE/ENV/NAME format.')
        select_cluster = options.cluster if options.cluster else None
        select_env = options.env
        select_role = None
        jobname = job_spec
    try:
        json_option = options.json
    except AttributeError:
        json_option = False
    try:
        bindings = options.bindings
    except AttributeError:
        bindings = ()
    return get_config(jobname,
                      config_file,
                      json_option,
                      bindings,
                      select_cluster=select_cluster,
                      select_role=select_role,
                      select_env=select_env)
Ejemplo n.º 8
0
 def get_job_config(self, jobkey, config_file, use_memoized_env=False):
     """Loads a job configuration from a config file."""
     jobname = jobkey.name
     try:
         # TODO(mchucarroll): pull request to pystachio, to make it possible to log the loaded
         # file without double-reading.
         with open(config_file, "r") as fp:
             logging.debug("Config: %s" % fp.readlines())
         result = get_config(jobname,
                             config_file,
                             self.options.read_json,
                             self.options.bindings,
                             select_cluster=jobkey.cluster,
                             select_role=jobkey.role,
                             select_env=jobkey.env,
                             use_memoized_env=use_memoized_env)
         check_result = result.raw().check()
         if not check_result.ok():
             raise self.CommandError(EXIT_INVALID_CONFIGURATION,
                                     check_result)
         return self._get_config_with_production_and_tier(
             jobkey.cluster, result)
     except Exception as e:
         raise self.CommandError(EXIT_INVALID_CONFIGURATION,
                                 'Error loading configuration: %s' % e)
Ejemplo n.º 9
0
def test_include():
    with temporary_dir() as dir:
        hello_mesos_fname = "hello_world.mesos"
        hello_mesos_path = os.path.join(dir, hello_mesos_fname)
        with open(os.path.join(dir, hello_mesos_path), "wb") as hello_world_mesos:
            hello_world_mesos.write(MESOS_CONFIG_WITHOUT_ANNOUNCE)
            hello_world_mesos.flush()

            hello_include_fname_path = os.path.join(dir, "hello_include_fname.mesos")
            with open(hello_include_fname_path, "wb+") as hello_include_fname_fp:
                hello_include_fname_fp.write(MESOS_CONFIG_WITH_INCLUDE % ("", """'%s'""" % hello_mesos_fname))
                hello_include_fname_fp.flush()

                config.get_config("hello_world", hello_include_fname_path)

                hello_include_fname_fp.seek(0)
                with pytest.raises(AuroraConfigLoader.InvalidConfigError):
                    config.get_config("hello_world", hello_include_fname_fp)
Ejemplo n.º 10
0
 def get_job_config(self, job_key, config_file):
   """Loads a job configuration from a config file"""
   jobname = job_key.name
   return get_config(
     jobname,
     config_file,
     self.options.json,
     self.options.bindings,
     select_cluster=job_key.cluster,
     select_role=job_key.role,
     select_env=job_key.env)
Ejemplo n.º 11
0
def test_get_config_select():
    with temporary_file() as fp:
        fp.write(MESOS_CONFIG_BASE % '')
        fp.flush()

        fp.seek(0)
        config.get_config('hello_world',
                          fp,
                          select_env='test',
                          select_role='john_doe',
                          select_cluster='test-cluster')

        fp.seek(0)
        with pytest.raises(ValueError) as cm:
            config.get_config('hello_world',
                              fp,
                              select_env='staging42',
                              select_role='moua',
                              select_cluster='test-cluster')
        assert 'test-cluster/john_doe/test/hello_world' in str(
            cm.value.message)
Ejemplo n.º 12
0
def test_include():
    with temporary_dir() as dir:
        hello_mesos_fname = "hello_world.mesos"
        hello_mesos_path = os.path.join(dir, hello_mesos_fname)
        with open(os.path.join(dir, hello_mesos_path),
                  "wb") as hello_world_mesos:
            hello_world_mesos.write(MESOS_CONFIG_WITHOUT_ANNOUNCE)
            hello_world_mesos.flush()

            hello_include_fname_path = os.path.join(
                dir, "hello_include_fname.mesos")
            with open(hello_include_fname_path,
                      "wb+") as hello_include_fname_fp:
                hello_include_fname_fp.write(
                    MESOS_CONFIG_WITH_INCLUDE %
                    ("", """'%s'""" % hello_mesos_fname))
                hello_include_fname_fp.flush()

                config.get_config('hello_world', hello_include_fname_path)

                hello_include_fname_fp.seek(0)
                with pytest.raises(AuroraConfigLoader.InvalidConfigError):
                    config.get_config('hello_world', hello_include_fname_fp)
Ejemplo n.º 13
0
 def get_job_config(self, jobkey, config_file):
   """Loads a job configuration from a config file."""
   jobname = jobkey.name
   try:
     return get_config(
       jobname,
       config_file,
       self.options.read_json,
       self.options.bindings,
       select_cluster=jobkey.cluster,
       select_role=jobkey.role,
       select_env=jobkey.env)
   except Exception as e:
     raise self.CommandError(EXIT_INVALID_CONFIGURATION, 'Error loading configuration: %s' % e)
Ejemplo n.º 14
0
 def get_job_config(self, jobkey, config_file):
     """Loads a job configuration from a config file."""
     jobname = jobkey.name
     try:
         # TODO(mchucarroll): pull request to pystachio, to make it possible to log the loaded
         # file without double-reading.
         with open(config_file, "r") as fp:
             self.print_log(TRANSCRIPT, "Config: %s" % fp.readlines())
         return get_config(
             jobname,
             config_file,
             self.options.read_json,
             self.options.bindings,
             select_cluster=jobkey.cluster,
             select_role=jobkey.role,
             select_env=jobkey.env,
         )
     except Exception as e:
         raise self.CommandError(EXIT_INVALID_CONFIGURATION, "Error loading configuration: %s" % e)
Ejemplo n.º 15
0
 def get_job_config(self, jobkey, config_file):
     """Loads a job configuration from a config file."""
     jobname = jobkey.name
     try:
         # TODO(mchucarroll): pull request to pystachio, to make it possible to log the loaded
         # file without double-reading.
         with open(config_file, "r") as fp:
             self.print_log(TRANSCRIPT, "Config: %s" % fp.readlines())
         bindings = bindings_to_list(
             self.options.bindings) if self.options.bindings else None
         return get_config(jobname,
                           config_file,
                           self.options.read_json,
                           bindings,
                           select_cluster=jobkey.cluster,
                           select_role=jobkey.role,
                           select_env=jobkey.env)
     except Exception as e:
         raise self.CommandError(EXIT_INVALID_CONFIGURATION,
                                 'Error loading configuration: %s' % e)
Ejemplo n.º 16
0
 def get_job_config(self, jobkey, config_file):
   """Loads a job configuration from a config file."""
   jobname = jobkey.name
   try:
     # TODO(mchucarroll): pull request to pystachio, to make it possible to log the loaded
     # file without double-reading.
     with open(config_file, "r") as fp:
       logging.debug("Config: %s" % fp.readlines())
     result = get_config(
         jobname,
         config_file,
         self.options.read_json,
         self.options.bindings,
         select_cluster=jobkey.cluster,
         select_role=jobkey.role,
         select_env=jobkey.env)
     check_result = result.raw().check()
     if not check_result.ok():
       raise self.CommandError(EXIT_INVALID_CONFIGURATION, check_result)
     return self._get_config_with_production_and_tier(jobkey.cluster, result)
   except Exception as e:
     raise self.CommandError(EXIT_INVALID_CONFIGURATION, 'Error loading configuration: %s' % e)