From 9c094d0581c46d3d107facdc55cb2cc7a1d9f765 Mon Sep 17 00:00:00 2001 From: Jack Lucas Date: Tue, 25 Jun 2019 18:52:55 -0400 Subject: Add TLS support for client-only apps Also enhance unit tests to do more robust checking of results. Issue-ID: DCAEGEN2-1550 Change-Id: Icf6e5357d828e19db73bb58b98fd60e9f111d0dc Signed-off-by: Jack Lucas --- k8s/tests/conftest.py | 53 ++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 44 insertions(+), 9 deletions(-) (limited to 'k8s/tests/conftest.py') diff --git a/k8s/tests/conftest.py b/k8s/tests/conftest.py index 572a510..4716b5a 100644 --- a/k8s/tests/conftest.py +++ b/k8s/tests/conftest.py @@ -1,7 +1,7 @@ # ============LICENSE_START======================================================= # org.onap.dcae # ================================================================================ -# Copyright (c) 2018 AT&T Intellectual Property. All rights reserved. +# Copyright (c) 2018-2019 AT&T Intellectual Property. All rights reserved. # ================================================================================ # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -22,13 +22,48 @@ import pytest @pytest.fixture() def mockconfig(monkeypatch): + from configure import configure """ Override the regular configure() routine that reads a file and calls Consul""" def altconfig(): - return { - "consul_host": "consul", - "namespace":"dcae", - "consul_dns_name" : "consul", - "image_pull_secrets" : [] - } - from configure import configure - monkeypatch.setattr(configure, 'configure', altconfig) \ No newline at end of file + config = configure._set_defaults() + config["consul_host"] = config["consul_dns_name"] + return config + monkeypatch.setattr(configure, 'configure', altconfig) + +@pytest.fixture() +def mockk8sapi(monkeypatch): + import k8sclient.k8sclient + from kubernetes import client + + # We need to patch the kubernetes 'client' module + # Awkward because of the way it requires a function call + # to get an API object + core = client.CoreV1Api() + ext = client.ExtensionsV1beta1Api() + + def pseudo_deploy(namespace, dep): + return dep + + def pseudo_service(namespace, svc): + return svc + + # patched_core returns a CoreV1Api object with the + # create_namespaced_service method stubbed out so that there + # is no attempt to call the k8s API server + def patched_core(): + monkeypatch.setattr(core, "create_namespaced_service", pseudo_service) + return core + + # patched_ext returns an ExtensionsV1beta1Api object with the + # create_namespaced_deployment method stubbed out so that there + # is no attempt to call the k8s API server + def patched_ext(): + monkeypatch.setattr(ext,"create_namespaced_deployment", pseudo_deploy) + return ext + + def pseudo_configure(loc): + pass + + monkeypatch.setattr(k8sclient.k8sclient,"_configure_api", pseudo_configure) + monkeypatch.setattr(client, "CoreV1Api", patched_core) + monkeypatch.setattr(client,"ExtensionsV1beta1Api", patched_ext) -- cgit 1.2.3-korg