Ejemplo n.º 1
0
    def test_k8s_client_configuration_missing_token(self):
        evaluator = PriorityEvaluator(
            {
                KEY_K8S_MASTER_URI: VALUE_CLI,
                KEY_K8S_CA_BASE64: VALUE_CLI,
            }, {}, {})

        with self.assertRaises(RuntimeError):
            evaluator.k8s_client_configuration()
Ejemplo n.º 2
0
    def test_k8s_client_configuration_success(self):
        evaluator = PriorityEvaluator(
            {
                KEY_K8S_MASTER_URI: VALUE_CLI,
                KEY_K8S_CA_BASE64: VALUE_CA,
                KEY_K8S_TOKEN: VALUE_TOKEN,
            }, {}, {})
        configuration = evaluator.k8s_client_configuration()
        self.assertEqual(configuration.host, VALUE_CLI)
        self.assertEqual(configuration.api_key,
                         {'authorization': 'Bearer token'})
        self.assertEqual(configuration.host, VALUE_CLI)
        self.assertFalse(configuration.debug)

        with open(configuration.ssl_ca_cert) as f:
            self.assertEqual(f.read(), 'CA\n')

        evaluator = PriorityEvaluator(
            {
                KEY_K8S_MASTER_URI: VALUE_CLI,
                KEY_K8S_CA_BASE64: VALUE_CA,
                KEY_K8S_TOKEN: VALUE_TOKEN,
            }, {KEY_K8S_HANDLE_DEBUG: 'true'}, {})
        configuration = evaluator.k8s_client_configuration()
        self.assertTrue(configuration.debug)
Ejemplo n.º 3
0
    def test_k8s_namespace_default(self):
        context = {KEY_K8S_NAMESPACE: VALUE_CONTEXT}
        env = {KEY_K8S_NAMESPACE_ENV: VALUE_ENV}
        evaluator = PriorityEvaluator({}, context, env)

        self.assertEqual(evaluator.k8s_namespace_default(), VALUE_CONTEXT)
        self.assertEqual(evaluator.k8s_namespace_default(KUBECONFIG_NAMESPACE),
                         VALUE_CONTEXT)

        context.pop(KEY_K8S_NAMESPACE)
        self.assertEqual(evaluator.k8s_namespace_default(), VALUE_ENV)
        self.assertEqual(evaluator.k8s_namespace_default(KUBECONFIG_NAMESPACE),
                         KUBECONFIG_NAMESPACE)
Ejemplo n.º 4
0
 def test_environment_deprecated(self):
     evaluator = PriorityEvaluator(
         {}, {},
         {KEY_K8S_CA_BASE64_URI_ENV_DEPRECATED: VALUE_ENV_DEPRECATED})
     self.assertTrue(evaluator.environment_deprecated())
     evaluator = PriorityEvaluator(
         {}, {}, {KEY_K8S_MASTER_URI_ENV_DEPRECATED: VALUE_ENV_DEPRECATED})
     self.assertTrue(evaluator.environment_deprecated())
     evaluator = PriorityEvaluator(
         {}, {}, {KEY_K8S_CA_BASE64_URI_ENV_DEPRECATED: ''})
     self.assertFalse(evaluator.environment_deprecated())
     evaluator = PriorityEvaluator({}, {},
                                   {KEY_K8S_MASTER_URI_ENV_DEPRECATED: ''})
     self.assertFalse(evaluator.environment_deprecated())
Ejemplo n.º 5
0
 def test_first_priority(self):
     self.assertEqual(PriorityEvaluator._first(VALUE_CLI, VALUE_ENV),
                      VALUE_CLI)
     self.assertEqual(PriorityEvaluator._first("", VALUE_ENV), VALUE_ENV)
Ejemplo n.º 6
0
 def test_first_none_argument(self):
     self.assertIsNone(PriorityEvaluator._first())
     self.assertIsNone(PriorityEvaluator._first(None))
     self.assertIsNone(PriorityEvaluator._first(None, False, 0, "", {}, []))