Artem Panchenko | 0594cd7 | 2017-06-12 13:25:26 +0300 | [diff] [blame] | 1 | # 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 Jigulin | 4ad52a8 | 2018-08-12 05:51:30 +0400 | [diff] [blame] | 15 | from kubernetes import client |
| 16 | |
| 17 | from devops.helpers import helpers |
| 18 | |
Artem Panchenko | 0594cd7 | 2017-06-12 13:25:26 +0300 | [diff] [blame] | 19 | from tcp_tests.managers.k8s.base import K8sBaseResource |
| 20 | from tcp_tests.managers.k8s.base import K8sBaseManager |
| 21 | |
| 22 | |
| 23 | class K8sDeployment(K8sBaseResource): |
Vladimir Jigulin | 4ad52a8 | 2018-08-12 05:51:30 +0400 | [diff] [blame] | 24 | resource_type = 'deployment' |
Artem Panchenko | 0594cd7 | 2017-06-12 13:25:26 +0300 | [diff] [blame] | 25 | |
Vladimir Jigulin | 4ad52a8 | 2018-08-12 05:51:30 +0400 | [diff] [blame] | 26 | def _read(self, **kwargs): |
| 27 | return self._manager.api.read_namespaced_deployment( |
| 28 | self.name, self.namespace, **kwargs) |
Artem Panchenko | 0594cd7 | 2017-06-12 13:25:26 +0300 | [diff] [blame] | 29 | |
Vladimir Jigulin | 4ad52a8 | 2018-08-12 05:51:30 +0400 | [diff] [blame] | 30 | def _create(self, body, **kwargs): |
| 31 | return self._manager.api.create_namespaced_deployment( |
| 32 | self.namespace, body, **kwargs) |
Artem Panchenko | 0594cd7 | 2017-06-12 13:25:26 +0300 | [diff] [blame] | 33 | |
Vladimir Jigulin | 4ad52a8 | 2018-08-12 05:51:30 +0400 | [diff] [blame] | 34 | def _patch(self, body, **kwargs): |
| 35 | return self._manager.api.patch_namespaced_deployment( |
| 36 | self.name, self.namespace, body, **kwargs) |
| 37 | |
| 38 | def _replace(self, body, **kwargs): |
| 39 | return self._manager.api.replace_namespaced_deployment( |
| 40 | self.name, self.namespace, body, **kwargs) |
| 41 | |
| 42 | def _delete(self, **kwargs): |
| 43 | self._manager.api.delete_namespaced_deployment( |
| 44 | self.name, self.namespace, client.V1DeleteOptions(), **kwargs) |
| 45 | |
| 46 | def is_ready(self): |
| 47 | dep = self.read() |
| 48 | return dep.status.available_replicas == dep.status.replicas |
| 49 | |
| 50 | def wait_ready(self, timeout=120, interval=5): |
| 51 | helpers.wait(lambda: self.is_ready(), |
| 52 | timeout=timeout, interval=interval) |
| 53 | return self |
Artem Panchenko | 501e67e | 2017-06-14 14:59:18 +0300 | [diff] [blame] | 54 | |
Artem Panchenko | 0594cd7 | 2017-06-12 13:25:26 +0300 | [diff] [blame] | 55 | |
| 56 | class K8sDeploymentManager(K8sBaseManager): |
Artem Panchenko | 0594cd7 | 2017-06-12 13:25:26 +0300 | [diff] [blame] | 57 | resource_class = K8sDeployment |
| 58 | |
Vladimir Jigulin | 4ad52a8 | 2018-08-12 05:51:30 +0400 | [diff] [blame] | 59 | @property |
| 60 | def api(self): |
| 61 | return self._cluster.api_apps |
Artem Panchenko | 0594cd7 | 2017-06-12 13:25:26 +0300 | [diff] [blame] | 62 | |
Vladimir Jigulin | 4ad52a8 | 2018-08-12 05:51:30 +0400 | [diff] [blame] | 63 | def _list(self, namespace, **kwargs): |
| 64 | return self.api.list_namespaced_deployment(namespace, **kwargs) |
Artem Panchenko | 0594cd7 | 2017-06-12 13:25:26 +0300 | [diff] [blame] | 65 | |
Vladimir Jigulin | 4ad52a8 | 2018-08-12 05:51:30 +0400 | [diff] [blame] | 66 | def _list_all(self, **kwargs): |
| 67 | return self.api.list_deployment_for_all_namespaces(**kwargs) |