fix flake8 warnings
This commit is contained in:
parent
30e7445c80
commit
25fea48f8a
|
|
@ -1,22 +1,23 @@
|
||||||
|
|
||||||
import unittest, yaml, time
|
import unittest
|
||||||
from kubernetes import client, config, utils
|
import time
|
||||||
from pprint import pprint
|
|
||||||
import timeout_decorator
|
import timeout_decorator
|
||||||
import subprocess
|
import subprocess
|
||||||
import git
|
import git
|
||||||
|
|
||||||
|
from kubernetes import client, config, utils
|
||||||
|
|
||||||
|
|
||||||
class K8sApi:
|
class K8sApi:
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.config = config.load_kube_config()
|
self.config = config.load_kube_config()
|
||||||
self.k8s_client = client.ApiClient()
|
self.k8s_client = client.ApiClient()
|
||||||
self.core_v1 = client.CoreV1Api()
|
self.core_v1 = client.CoreV1Api()
|
||||||
self.crd_api = client.CustomObjectsApi()
|
self.crd = client.CustomObjectsApi()
|
||||||
self.apps_v1 = client.AppsV1Api()
|
self.apps_v1 = client.AppsV1Api()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class SmokeTestCase(unittest.TestCase):
|
class SmokeTestCase(unittest.TestCase):
|
||||||
'''
|
'''
|
||||||
Test the most basic e2e functionality of the operator.
|
Test the most basic e2e functionality of the operator.
|
||||||
|
|
@ -34,7 +35,8 @@ class SmokeTestCase(unittest.TestCase):
|
||||||
'''
|
'''
|
||||||
|
|
||||||
# HACK
|
# HACK
|
||||||
# 1. creating RBAC entites with a separate client fails with "AttributeError: object has no attribute 'select_header_accept'"
|
# 1. creating RBAC entites with a separate client fails
|
||||||
|
# with "AttributeError: object has no attribute 'select_header_accept'"
|
||||||
# 2. utils.create_from_yaml cannot create multiple entites from a single file
|
# 2. utils.create_from_yaml cannot create multiple entites from a single file
|
||||||
subprocess.run(["kubectl", "create", "-f", "manifests/operator-service-account-rbac.yaml"])
|
subprocess.run(["kubectl", "create", "-f", "manifests/operator-service-account-rbac.yaml"])
|
||||||
|
|
||||||
|
|
@ -54,7 +56,7 @@ class SmokeTestCase(unittest.TestCase):
|
||||||
"spec": {
|
"spec": {
|
||||||
"containers": [
|
"containers": [
|
||||||
{
|
{
|
||||||
"name" : "postgres-operator",
|
"name": "postgres-operator",
|
||||||
"image": "registry.opensource.zalan.do/acid/postgres-operator:" + version
|
"image": "registry.opensource.zalan.do/acid/postgres-operator:" + version
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
@ -91,8 +93,9 @@ class SmokeTestCase(unittest.TestCase):
|
||||||
Check that there is a single pod in the k8s cluster with the label "spilo-role=master".
|
Check that there is a single pod in the k8s cluster with the label "spilo-role=master".
|
||||||
"""
|
"""
|
||||||
k8s = K8sApi()
|
k8s = K8sApi()
|
||||||
master_pods = k8s.core_v1.list_namespaced_pod('default', label_selector='spilo-role=master,version=acid-minimal-cluster').items
|
labels = 'spilo-role=master,version=acid-minimal-cluster'
|
||||||
self.assertEqual(len(master_pods), 1, "Expected 1 master pod,found " + str(len(master_pods)))
|
master_pods = k8s.core_v1.list_namespaced_pod('default', label_selector=labels).items
|
||||||
|
self.assertEqual(len(master_pods), 1, "Expected 1 master pod, found " + str(len(master_pods)))
|
||||||
|
|
||||||
@timeout_decorator.timeout(240)
|
@timeout_decorator.timeout(240)
|
||||||
def test_scaling(self):
|
def test_scaling(self):
|
||||||
|
|
@ -106,12 +109,14 @@ class SmokeTestCase(unittest.TestCase):
|
||||||
"numberOfInstances": 3
|
"numberOfInstances": 3
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ = k8s.crd_api.patch_namespaced_custom_object("acid.zalan.do", "v1", "default", "postgresqls", "acid-minimal-cluster", body)
|
_ = k8s.crd.patch_namespaced_custom_object("acid.zalan.do",
|
||||||
|
"v1", "default", "postgresqls", "acid-minimal-cluster", body)
|
||||||
|
|
||||||
while len(k8s.core_v1.list_namespaced_pod('default', label_selector='version=acid-minimal-cluster').items) != 3:
|
labels = 'version=acid-minimal-cluster'
|
||||||
|
while len(k8s.core_v1.list_namespaced_pod('default', label_selector=labels).items) != 3:
|
||||||
print("Waiting for the cluster to scale up to 3 pods.")
|
print("Waiting for the cluster to scale up to 3 pods.")
|
||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
self.assertEqual(3, len(k8s.core_v1.list_namespaced_pod('default', label_selector='version=acid-minimal-cluster').items))
|
self.assertEqual(3, len(k8s.core_v1.list_namespaced_pod('default', label_selector=labels).items))
|
||||||
|
|
||||||
body = {
|
body = {
|
||||||
"spec": {
|
"spec": {
|
||||||
|
|
@ -119,12 +124,14 @@ class SmokeTestCase(unittest.TestCase):
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_ = k8s.crd_api.patch_namespaced_custom_object("acid.zalan.do", "v1", "default", "postgresqls", "acid-minimal-cluster", body)
|
_ = k8s.crd.patch_namespaced_custom_object("acid.zalan.do",
|
||||||
|
"v1", "default", "postgresqls", "acid-minimal-cluster", body)
|
||||||
|
|
||||||
while len(k8s.core_v1.list_namespaced_pod('default', label_selector='version=acid-minimal-cluster').items) != 2:
|
while len(k8s.core_v1.list_namespaced_pod('default', label_selector=labels).items) != 2:
|
||||||
print("Waiting for the cluster to scale down to 2 pods.")
|
print("Waiting for the cluster to scale down to 2 pods.")
|
||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
self.assertEqual(2, len(k8s.core_v1.list_namespaced_pod('default', label_selector='version=acid-minimal-cluster').items))
|
self.assertEqual(2, len(k8s.core_v1.list_namespaced_pod('default', label_selector=labels).items))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
Loading…
Reference in New Issue