1 # ============LICENSE_START=======================================================
3 # ================================================================================
4 # Copyright (c) 2018-2019 AT&T Intellectual Property. All rights reserved.
5 # ================================================================================
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
10 # http://www.apache.org/licenses/LICENSE-2.0
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17 # ============LICENSE_END=========================================================
19 # ECOMP is a trademark and service mark of AT&T Intellectual Property.
24 def mockconfig(monkeypatch):
25 from configure import configure
26 """ Override the regular configure() routine that reads a file and calls Consul"""
28 config = configure._set_defaults()
29 config["consul_host"] = config["consul_dns_name"]
31 monkeypatch.setattr(configure, 'configure', altconfig)
34 def mockk8sapi(monkeypatch):
35 import k8sclient.k8sclient
36 from kubernetes import client
38 # We need to patch the kubernetes 'client' module
39 # Awkward because of the way it requires a function call
40 # to get an API object
41 core = client.CoreV1Api()
42 ext = client.ExtensionsV1beta1Api()
44 def pseudo_deploy(namespace, dep):
47 def pseudo_service(namespace, svc):
50 # patched_core returns a CoreV1Api object with the
51 # create_namespaced_service method stubbed out so that there
52 # is no attempt to call the k8s API server
54 monkeypatch.setattr(core, "create_namespaced_service", pseudo_service)
57 # patched_ext returns an ExtensionsV1beta1Api object with the
58 # create_namespaced_deployment method stubbed out so that there
59 # is no attempt to call the k8s API server
61 monkeypatch.setattr(ext,"create_namespaced_deployment", pseudo_deploy)
64 def pseudo_configure(loc):
67 monkeypatch.setattr(k8sclient.k8sclient,"_configure_api", pseudo_configure)
68 monkeypatch.setattr(client, "CoreV1Api", patched_core)
69 monkeypatch.setattr(client,"ExtensionsV1beta1Api", patched_ext)