Skip to content

Fixed swallowing python client exceptions in e2e tests #94

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion docker/mongodb-kubernetes-tests/kubetester/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@ def create_or_update_secret(
api_client: Optional[client.ApiClient] = None,
) -> str:
try:
create_secret(namespace, name, data, type, api_client)
create_secret(namespace, name, data, type, api_client, )
except kubernetes.client.ApiException as e:
if e.status == 409:
update_secret(namespace, name, data, api_client)
else:
raise e

return name

Expand Down Expand Up @@ -161,6 +163,8 @@ def create_or_update_service(
update_service(
namespace, service_name, cluster_ip=cluster_ip, ports=ports, selector=selector, service=service
)
else:
raise e
return service_name


Expand Down Expand Up @@ -269,6 +273,8 @@ def create_or_update_namespace(
except kubernetes.client.ApiException as e:
if e.status == 409:
client.CoreV1Api(api_client=api_client).patch_namespace(namespace, namespace_resource)
else:
raise e


def delete_namespace(name: str):
Expand Down
8 changes: 4 additions & 4 deletions docker/mongodb-kubernetes-tests/kubetester/certs.py
Original file line number Diff line number Diff line change
Expand Up @@ -804,16 +804,16 @@ def create_x509_agent_tls_certs(issuer: str, namespace: str, name: str, secret_b

def approve_certificate(name: str) -> None:
"""Approves the CertificateSigningRequest with the provided name"""
body = client.CertificatesV1beta1Api().read_certificate_signing_request_status(name)
conditions = client.V1beta1CertificateSigningRequestCondition(
body = client.CertificatesV1Api().read_certificate_signing_request_status(name)
conditions = client.V1CertificateSigningRequestCondition(
last_update_time=datetime.now(timezone.utc).astimezone(),
message="This certificate was approved by E2E testing framework",
reason="E2ETestingFramework",
type="Approved",
)

body.status.conditions = [conditions]
client.CertificatesV1beta1Api().replace_certificate_signing_request_approval(name, body)
client.CertificatesV1Api().replace_certificate_signing_request_approval(name, body)


def create_x509_user_cert(issuer: str, namespace: str, path: str):
Expand Down Expand Up @@ -876,7 +876,7 @@ def yield_existing_csrs(csr_names: List[str], timeout: int = 300) -> Generator[s
while len(csr_names) > 0 and time.time() < stop_time:
csr = random.choice(csr_names)
try:
client.CertificatesV1beta1Api().read_certificate_signing_request_status(csr)
client.CertificatesV1Api().read_certificate_signing_request_status(csr)
except ApiException:
time.sleep(3)
continue
Expand Down
2 changes: 1 addition & 1 deletion docker/mongodb-kubernetes-tests/kubetester/crypto.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def generate_csr(namespace: str, host: str, servicename: str):


def get_pem_certificate(name: str) -> Optional[str]:
body = client.CertificatesV1beta1Api().read_certificate_signing_request_status(name)
body = client.CertificatesV1Api().read_certificate_signing_request_status(name)
if body.status.certificate is None:
return None
return base64.b64decode(body.status.certificate)
Expand Down
16 changes: 9 additions & 7 deletions docker/mongodb-kubernetes-tests/kubetester/kubetester.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,8 @@ def create_or_update_pvc(
cls.clients("corev1", api_client=api_client).patch_namespaced_persistent_volume_claim(
body=body, name=body["metadata"]["name"], namespace=namespace
)
else:
raise e

@classmethod
def delete_pvc(cls, namespace: str, name: str):
Expand All @@ -325,7 +327,7 @@ def clients(name, api_client: Optional[client.ApiClient] = None):
"appsv1": client.AppsV1Api(api_client=api_client),
"storagev1": client.StorageV1Api(api_client=api_client),
"customv1": client.CustomObjectsApi(api_client=api_client),
"certificates": client.CertificatesV1beta1Api(api_client=api_client),
"certificates": client.CertificatesV1Api(api_client=api_client),
"namespace": KubernetesTester.get_namespace(),
}[name]

Expand Down Expand Up @@ -807,7 +809,7 @@ def setup_method(self):
self.client = client
self.corev1 = client.CoreV1Api()
self.appsv1 = client.AppsV1Api()
self.certificates = client.CertificatesV1beta1Api()
self.certificates = client.CertificatesV1Api()
self.customv1 = client.CustomObjectsApi()
self.namespace = KubernetesTester.get_namespace()
self.name = None
Expand Down Expand Up @@ -1224,19 +1226,19 @@ def generate_certfile(
if namespace is None:
namespace = self.namespace

csr_body = client.V1beta1CertificateSigningRequest(
csr_body = client.V1CertificateSigningRequest(
metadata=client.V1ObjectMeta(name=csr_name, namespace=namespace),
spec=client.V1beta1CertificateSigningRequestSpec(
spec=client.V1CertificateSigningRequestSpec(
groups=["system:authenticated"],
usages=["digital signature", "key encipherment", "client auth"],
request=encoded_request,
),
)

client.CertificatesV1beta1Api().create_certificate_signing_request(csr_body)
client.CertificatesV1Api().create_certificate_signing_request(csr_body)
self.approve_certificate(csr_name)
wait_for_certs_to_be_issued([csr_name])
csr = client.CertificatesV1beta1Api().read_certificate_signing_request(csr_name)
csr = client.CertificatesV1Api().read_certificate_signing_request(csr_name)
certificate = b64decode(csr.status.certificate)

tmp = tempfile.NamedTemporaryFile()
Expand Down Expand Up @@ -1383,7 +1385,7 @@ def get_csr_sans(csr_name: str) -> List[str]:
Return all of the subject alternative names for a given Kubernetes
certificate signing request.
"""
csr = client.CertificatesV1beta1Api().read_certificate_signing_request_status(csr_name)
csr = client.CertificatesV1Api().read_certificate_signing_request_status(csr_name)
base64_csr_request = csr.spec.request
csr_pem_string = b64decode(base64_csr_request)
csr = x509.load_pem_x509_csr(csr_pem_string, default_backend())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -379,8 +379,8 @@ def update_subscription() -> bool:
except kubernetes.client.ApiException as e:
if e.status == 409:
return False
else:
raise e
else:
raise e

run_periodically(update_subscription, timeout=100, msg="Subscription to be updated")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,8 +363,8 @@ def update_subscription() -> bool:
except kubernetes.client.ApiException as e:
if e.status == 409:
return False
else:
raise e
else:
raise e

run_periodically(update_subscription, timeout=100, msg="Subscription to be updated")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ def test_om_container_override(self, ops_manager: MongoDBOpsManager):
"initial_delay_seconds": 5,
"_exec": None,
"tcp_socket": None,
"grpc": None,
"termination_grace_period_seconds": None,
},
"startup_probe": {
"http_get": {
Expand All @@ -168,6 +170,8 @@ def test_om_container_override(self, ops_manager: MongoDBOpsManager):
"initial_delay_seconds": 1,
"_exec": None,
"tcp_socket": None,
"grpc": None,
"termination_grace_period_seconds": None,
},
"volume_mounts": [
{
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ MarkupSafe==2.0.1
semver==2.13.0
chardet==3.0.4
jsonpatch==1.33
kubernetes==17.17.0
kubernetes==30.1.0
pymongo==4.6.3
pytest==7.4.3
pytest-asyncio==0.14.0
Expand Down