blob: bc0db301323d6b4f26af8bf28f16af734ec0ef74 [file] [log] [blame]
Artem Panchenko0594cd72017-06-12 13:25:26 +03001# Copyright 2017 Mirantis, Inc.
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may
4# not use this file except in compliance with the License. You may obtain
5# a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations
13
14
Vladimir Jigulin4ad52a82018-08-12 05:51:30 +040015from kubernetes import client
16
Vladimir Jigulin57ecae92018-09-10 22:51:15 +040017from devops.helpers import helpers
18
Artem Panchenko0594cd72017-06-12 13:25:26 +030019from tcp_tests.managers.k8s.base import K8sBaseResource
20from tcp_tests.managers.k8s.base import K8sBaseManager
21
22
23class K8sServiceAccount(K8sBaseResource):
Vladimir Jigulin4ad52a82018-08-12 05:51:30 +040024 resource_type = 'serviceaccount'
Artem Panchenko0594cd72017-06-12 13:25:26 +030025
Vladimir Jigulin4ad52a82018-08-12 05:51:30 +040026 def _read(self, **kwargs):
27 return self._manager.api.read_namespaced_service_account(
28 self.name, self.namespace, **kwargs)
Artem Panchenko0594cd72017-06-12 13:25:26 +030029
Vladimir Jigulin4ad52a82018-08-12 05:51:30 +040030 def _create(self, body, **kwargs):
31 return self._manager.api.create_namespaced_service_account(
32 self.namespace, body, **kwargs)
33
34 def _patch(self, body, **kwargs):
35 return self._manager.api.patch_namespaced_service_account(
36 self.name, self.namespace, body, **kwargs)
37
38 def _replace(self, body, **kwargs):
39 return self._manager.api.replace_namespaced_service_account(
40 self.name, self.namespace, body, **kwargs)
41
42 def _delete(self, **kwargs):
43 self._manager.api.delete_namespaced_service_account(
44 self.name, self.namespace, client.V1DeleteOptions(), **kwargs)
Artem Panchenko0594cd72017-06-12 13:25:26 +030045
Vladimir Jigulin57ecae92018-09-10 22:51:15 +040046 def wait_secret_generation(self, timeout=90, interval=2):
47 def is_secret_generated():
48 secrets = self.read().secrets
49 return secrets is not None and len(secrets) > 0
50 helpers.wait(lambda: is_secret_generated(),
51 timeout=timeout, interval=interval)
52
Artem Panchenko0594cd72017-06-12 13:25:26 +030053
54class K8sServiceAccountManager(K8sBaseManager):
Artem Panchenko0594cd72017-06-12 13:25:26 +030055 resource_class = K8sServiceAccount
56
Vladimir Jigulin4ad52a82018-08-12 05:51:30 +040057 @property
58 def api(self):
59 return self._cluster.api_core
Artem Panchenko0594cd72017-06-12 13:25:26 +030060
Vladimir Jigulin4ad52a82018-08-12 05:51:30 +040061 def _list(self, namespace, **kwargs):
62 return self.api.list_namespaced_service_account(namespace, **kwargs)
Artem Panchenko0594cd72017-06-12 13:25:26 +030063
Vladimir Jigulin4ad52a82018-08-12 05:51:30 +040064 def _list_all(self, **kwargs):
65 return self.api.list_service_account_for_all_namespaces(**kwargs)