Beispiel #1
0
def make_admin_client(cluster):
    if cluster not in CLUSTERS:
        die('Unknown cluster: %s. Known clusters: %s' %
            (cluster, ", ".join(CLUSTERS.keys())))

    verbose = getattr(app.get_options(), 'verbosity', 'normal') == 'verbose'
    return AuroraClientAPI(CLUSTERS[cluster],
                           AURORA_ADMIN_USER_AGENT_NAME,
                           verbose=verbose)
Beispiel #2
0
def make_admin_client(cluster):
  if cluster not in CLUSTERS:
    die('Unknown cluster: %s. Known clusters: %s' % (cluster, ", ".join(CLUSTERS.keys())))

  options = app.get_options()
  verbose = getattr(options, 'verbosity', 'normal') == 'verbose'

  return AuroraClientAPI(
      CLUSTERS[cluster],
      AURORA_ADMIN_USER_AGENT_NAME,
      verbose=verbose,
      bypass_leader_redirect=options.bypass_leader_redirect)
Beispiel #3
0
def test_get_config_with_production_and_tier_is_preemptible():
    context = FakeAuroraCommandContext()
    context.set_options(create_mock_options())
    with CLUSTERS.patch(AuroraClientCommandTest.TEST_CLUSTERS.values()):
        api = context.get_api(TEST_CLUSTER.name)
        api.get_tier_configs.return_value = AuroraClientCommandTest.get_mock_tier_configurations()
        with temporary_file() as fp:
            fp.write(create_test_config())
            fp.flush()
            config = context.get_job_config(AuroraClientCommandTest.TEST_JOBKEY, fp.name)
            assert not config.job().taskConfig.production
            assert config.job().taskConfig.tier == AuroraClientCommandTest.PREEMPTIBLE_TIER.name
Beispiel #4
0
def test_get_api_caches_hook_enabled_apis_separately():
  with CLUSTERS.patch([TEST_CLUSTER]):
    context = AuroraCommandContext()
    hooked_api = context.get_api(TEST_CLUSTER.name)
    unhooked_api = context.get_api(TEST_CLUSTER.name, enable_hooks=False)

    assert hooked_api != unhooked_api

    assert hooked_api in context.apis.values()
    assert hooked_api not in context.unhooked_apis.values()

    assert unhooked_api in context.unhooked_apis.values()
    assert unhooked_api not in context.apis.values()
Beispiel #5
0
def test_get_api_caches_hook_enabled_apis_separately():
    with CLUSTERS.patch([TEST_CLUSTER]):
        context = AuroraCommandContext()
        hooked_api = context.get_api(TEST_CLUSTER.name)
        unhooked_api = context.get_api(TEST_CLUSTER.name, enable_hooks=False)

        assert hooked_api != unhooked_api

        assert hooked_api in context.apis.values()
        assert hooked_api not in context.unhooked_apis.values()

        assert unhooked_api in context.unhooked_apis.values()
        assert unhooked_api not in context.apis.values()
Beispiel #6
0
  def test_docker_binding_throws(self, mock_resolve):
    mock_resolve.side_effect = Exception('mock resolve failure')

    binding_helper.unregister_all()
    BindingHelper.register(DockerBindingHelper())

    with temporary_file() as fp:
      fp.write(DOCKER_BINDING_CONFIG)
      fp.flush()
      with CLUSTERS.patch(TEST_CLUSTERS):
        cfg = AuroraConfig.load(fp.name)
        with pytest.raises(Exception):
          binding_helper.apply_all(cfg)
          assert mock_resolve.mock_calls == [call(TEST_CLUSTER, 'some/name', 'some.tag')]
Beispiel #7
0
def test_get_config_with_production_and_tier_is_preemptible():
    context = FakeAuroraCommandContext()
    context.set_options(create_mock_options())
    with CLUSTERS.patch(AuroraClientCommandTest.TEST_CLUSTERS.values()):
        api = context.get_api(TEST_CLUSTER.name)
        api.get_tier_configs.return_value = AuroraClientCommandTest.get_mock_tier_configurations(
        )
        with temporary_file() as fp:
            fp.write(create_test_config())
            fp.flush()
            config = context.get_job_config(
                AuroraClientCommandTest.TEST_JOBKEY, fp.name)
            assert not config.job().taskConfig.production
            assert config.job(
            ).taskConfig.tier == AuroraClientCommandTest.PREEMPTIBLE_TIER.name
Beispiel #8
0
  def test_docker_binding(self, mock_resolve):
    image_reference = 'registry.example.com/some/repo@some:digest'

    mock_resolve.return_value = image_reference

    binding_helper.unregister_all()
    BindingHelper.register(DockerBindingHelper())

    with temporary_file() as fp:
      fp.write(DOCKER_BINDING_CONFIG)
      fp.flush()
      with CLUSTERS.patch(TEST_CLUSTERS):
        cfg = AuroraConfig.load(fp.name)
        binding_helper.apply_all(cfg)
        assert cfg.job().taskConfig.container.docker.image == image_reference
        assert mock_resolve.mock_calls == [call(TEST_CLUSTER, 'some/name', 'some.tag')]
    def test_docker_binding_throws(self, mock_resolve):
        mock_resolve.side_effect = Exception('mock resolve failure')

        binding_helper.unregister_all()
        BindingHelper.register(DockerBindingHelper())

        with temporary_file() as fp:
            fp.write(DOCKER_BINDING_CONFIG)
            fp.flush()
            with CLUSTERS.patch(TEST_CLUSTERS):
                cfg = AuroraConfig.load(fp.name)
                with pytest.raises(Exception):
                    binding_helper.apply_all(cfg)
                    assert mock_resolve.mock_calls == [
                        call(TEST_CLUSTER, 'some/name', 'some.tag')
                    ]
    def test_docker_binding(self, mock_resolve):
        image_reference = 'registry.example.com/some/repo@some:digest'

        mock_resolve.return_value = image_reference

        binding_helper.unregister_all()
        BindingHelper.register(DockerBindingHelper())

        with temporary_file() as fp:
            fp.write(DOCKER_BINDING_CONFIG)
            fp.flush()
            with CLUSTERS.patch(TEST_CLUSTERS):
                cfg = AuroraConfig.load(fp.name)
                binding_helper.apply_all(cfg)
                assert cfg.job(
                ).taskConfig.container.docker.image == image_reference
                assert mock_resolve.mock_calls == [
                    call(TEST_CLUSTER, 'some/name', 'some.tag')
                ]
Beispiel #11
0
def make_admin_client(cluster, verbose=False, bypass_leader_redirect=False):
  """Creates an API client with the specified options for use in admin commands.

  :param cluster: The cluster to connect with.
  :type cluster: Either a string cluster name or a Cluster object.
  :param verbose: Should the client emit verbose output.
  :type verbose: bool
  :type bypass_leader_redirect: Should the client bypass the scheduler's leader redirect filter.
  :type bypass_leader_redirect: bool
  :rtype: an AuroraClientAPI instance.
  """

  is_cluster_object = isinstance(cluster, Cluster)

  if not is_cluster_object and cluster not in CLUSTERS:
    die('Unknown cluster: %s. Known clusters: %s' % (cluster, ", ".join(CLUSTERS.keys())))

  return AuroraClientAPI(
      cluster if is_cluster_object else CLUSTERS[cluster],
      AURORA_ADMIN_USER_AGENT_NAME,
      verbose=verbose,
      bypass_leader_redirect=bypass_leader_redirect)
Beispiel #12
0
def make_admin_client(cluster, verbose=False, bypass_leader_redirect=False):
    """Creates an API client with the specified options for use in admin commands.

  :param cluster: The cluster to connect with.
  :type cluster: Either a string cluster name or a Cluster object.
  :param verbose: Should the client emit verbose output.
  :type verbose: bool
  :type bypass_leader_redirect: Should the client bypass the scheduler's leader redirect filter.
  :type bypass_leader_redirect: bool
  :rtype: an AuroraClientAPI instance.
  """

    is_cluster_object = isinstance(cluster, Cluster)

    if not is_cluster_object and cluster not in CLUSTERS:
        die('Unknown cluster: %s. Known clusters: %s' %
            (cluster, ", ".join(CLUSTERS.keys())))

    return AuroraClientAPI(cluster if is_cluster_object else CLUSTERS[cluster],
                           AURORA_ADMIN_USER_AGENT_NAME,
                           verbose=verbose,
                           bypass_leader_redirect=bypass_leader_redirect)
Beispiel #13
0
def test_get_api_forwards_hooks_disabled():
    with CLUSTERS.patch([TEST_CLUSTER]):
        api = AuroraCommandContext().get_api(TEST_CLUSTER.name,
                                             enable_hooks=False)
        assert isinstance(api, AuroraClientAPI)
        assert api._cluster == TEST_CLUSTER
Beispiel #14
0
def test_get_api_forwards_hooks_disabled():
  with CLUSTERS.patch([TEST_CLUSTER]):
    api = AuroraCommandContext().get_api(TEST_CLUSTER.name, enable_hooks=False)
    assert isinstance(api, AuroraClientAPI)
    assert api._cluster == TEST_CLUSTER
Beispiel #15
0
def test_get_api_defaults_to_hooks_enabled():
  with CLUSTERS.patch([TEST_CLUSTER]):
    api = AuroraCommandContext().get_api(TEST_CLUSTER.name)
    assert isinstance(api, HookedAuroraClientAPI)
    assert api._cluster == TEST_CLUSTER
Beispiel #16
0
 def run(self, result=None):
     # Since CLUSTERS is a global value that evaluates code on import this is the best way to
     # ensure it does not pollute any tests.
     with CLUSTERS.patch(self.TEST_CLUSTERS._clusters.values()):
         super(AuroraClientCommandTest, self).run(result)
Beispiel #17
0
 def run(self, result=None):
   # Since CLUSTERS is a global value that evaluates code on import this is the best way to
   # ensure it does not pollute any tests.
   with CLUSTERS.patch(self.TEST_CLUSTERS._clusters.values()):
     super(AuroraClientCommandTest, self).run()
Beispiel #18
0
def test_get_api_defaults_to_hooks_enabled():
    with CLUSTERS.patch([TEST_CLUSTER]):
        api = AuroraCommandContext().get_api(TEST_CLUSTER.name)
        assert isinstance(api, HookedAuroraClientAPI)
        assert api._cluster == TEST_CLUSTER