Example #1
0
 def test_create(self):
     name = "mnubo.com-sa-{0}".format(str(uuid.uuid4().hex[:5]))
     acct = utils.create_service_account(name=name)
     if utils.is_reachable(acct.config.api_host):
         acct.create()
         from_get = acct.get()
         self.assertEqual(acct, from_get)
Example #2
0
 def test_list(self):
     name = "mnubo.com-sa-{0}".format(str(uuid.uuid4().hex[:5]))
     acct = utils.create_service_account(name=name)
     if utils.is_reachable(acct.config.api_host):
         acct.create()
         _list = acct.list()
         for x in _list:
             self.assertIsInstance(x, K8sServiceAccount)
Example #3
0
 def test_init_with_name(self):
     name = "yoname"
     secret = utils.create_service_account(name=name)
     self.assertIsNotNone(secret)
     self.assertIsInstance(secret, K8sServiceAccount)
     self.assertEqual(secret.name, name)
     self.assertEqual('default', secret.config.namespace)
     self.assertEqual('ServiceAccount', secret.obj_type)
Example #4
0
 def test_add_api_token(self):
     name = "mnubo.com-sa-{0}".format(str(uuid.uuid4().hex[:5]))
     acct = utils.create_service_account(name=name)
     if utils.is_reachable(acct.config.api_host):
         acct.create()
         acct.add_api_token()
         secrets = K8sSecret.api_tokens_for_service_account(
             config=acct.config, name=acct.name)
         self.assertEqual(2, len(secrets))
Example #5
0
 def test_create_service_account_api_token(self):
     sa = utils.create_service_account(name='build-robot')
     if utils.is_reachable(sa.config.api_host):
         sa.create()
         secret = K8sSecret.create_service_account_api_token(
             config=sa.config, name=sa.name)
         self.assertIsInstance(secret, K8sSecret)
         secrets = K8sSecret.api_tokens_for_service_account(
             config=sa.config, name=sa.name)
         self.assertEqual(2, len(secrets))
Example #6
0
 def test_init_with_name_and_config(self):
     name = "yoname"
     nspace = "yomama"
     config = K8sConfig(kubeconfig=utils.kubeconfig_fallback,
                        namespace=nspace)
     secret = utils.create_service_account(config=config, name=name)
     self.assertIsNotNone(secret)
     self.assertIsInstance(secret, K8sServiceAccount)
     self.assertEqual(secret.name, name)
     self.assertEqual(secret.config.namespace, nspace)
     self.assertEqual('ServiceAccount', secret.obj_type)
Example #7
0
 def test_add_image_pull_secret(self):
     name = "mnubo.com-sa-{0}".format(str(uuid.uuid4().hex[:5]))
     acct = utils.create_service_account(name=name)
     data = {
         "auths": {
             "repo:port": {
                 "auth": "authstring",
                 "email": "*****@*****.**"
             }
         }
     }
     if utils.is_reachable(acct.config.api_host):
         acct.create()
         secret = K8sSecret.create_image_pull_secret(config=acct.config,
                                                     name=acct.name,
                                                     data=data)
         acct.add_image_pull_secret(secret)
         secrets = K8sSecret.list_image_pull_secrets()
         self.assertEqual(1, len(secrets))
Example #8
0
 def test_init_with_invalid_name(self):
     name = object()
     with self.assertRaises(SyntaxError):
         utils.create_service_account(name=name)