summaryrefslogtreecommitdiffstats
path: root/utils
diff options
context:
space:
mode:
authorYang (Gabriel) Yu <Gabriel.yuyang@huawei.com>2018-09-07 03:54:05 +0000
committerGerrit Code Review <gerrit@opnfv.org>2018-09-07 03:54:05 +0000
commit27d82af1145673330eddbe80eb39c47d93322cbe (patch)
tree81c5cf27302f20ab2081f1035bf222da2e63d082 /utils
parente32043f58a2450b6a5986dc2a01f64f8b22c3992 (diff)
parenteacf878ec5372a6db4596c9cbc78ef96bf2453b9 (diff)
Merge "add k8s capacity test case"
Diffstat (limited to 'utils')
-rw-r--r--utils/k8s_setup/k8s_config_pre.sh2
-rw-r--r--utils/k8s_setup/k8s_utils.py53
2 files changed, 47 insertions, 8 deletions
diff --git a/utils/k8s_setup/k8s_config_pre.sh b/utils/k8s_setup/k8s_config_pre.sh
index f41ba78d..05c3f1c3 100644
--- a/utils/k8s_setup/k8s_config_pre.sh
+++ b/utils/k8s_setup/k8s_config_pre.sh
@@ -7,7 +7,7 @@
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
-K8S_CONFIG="/tmp/k8s_conig"
+K8S_CONFIG="/tmp/k8s_config"
usage="Script to prepare kubenetes test configurations.
diff --git a/utils/k8s_setup/k8s_utils.py b/utils/k8s_setup/k8s_utils.py
index 7195bf23..a89889f3 100644
--- a/utils/k8s_setup/k8s_utils.py
+++ b/utils/k8s_setup/k8s_utils.py
@@ -9,25 +9,29 @@
##############################################################################
import os
+import commands
+import json
import utils.logger as log
from kubernetes import client, watch
LOG = log.Logger(__name__).getLogger()
INSTALLER_TYPE = os.getenv("INSTALLER_TYPE")
+K8S_UTILS = "/home/opnfv/bottlenecks/utils/k8s_setup"
-def get_config_path(INSTALLER_TYPE=None, CONFIG_PATH="/tmp/k8s_config"):
+def get_config_path(INSTALLER_TYPE=None, K8S_CONFIG_PATH="/tmp/k8s_config"):
if INSTALLER_TYPE:
- CMD = "bash k8s_config_pre.sh -i " + INSTALLER_TYPE + \
- " -c " + CONFIG_PATH
+ CMD = "bash " + K8S_UTILS + "/k8s_config_pre.sh -i " \
+ + INSTALLER_TYPE + \
+ " -c " + K8S_CONFIG_PATH
LOG.info("Executing command: " + CMD)
- CONFIG_PATH = os.popen(CMD)
+ os.popen(CMD)
else:
- if not os.path.exists(CONFIG_PATH):
+ if not os.path.exists(K8S_CONFIG_PATH):
raise Exception("Must at least specify the path \
of k8s config!")
- return CONFIG_PATH
+ return K8S_CONFIG_PATH
def get_core_api(version='v1'):
@@ -35,10 +39,39 @@ def get_core_api(version='v1'):
API = client.CoreV1Api()
LOG.info(API)
else:
- raise Exception("Must input a validate verison!")
+ raise Exception("Must input a valid verison!")
return API
+def get_apps_api(version='v1'):
+ if version.lower() == 'v1':
+ API = client.AppsV1Api()
+ LOG.info(API)
+ else:
+ raise Exception("Must input a valid verison!")
+ return API
+
+
+def get_namespace_status(namespace):
+ CMD = ("kubectl get ns | grep %s" % namespace)
+ namespace_existed = commands.getstatusoutput(CMD)
+ return namespace_existed
+
+
+def get_deployment_status(name, namespace):
+ CMD = ("kubectl get deployment --namespace={} | grep {}".format(
+ namespace, name))
+ deployment_existed = commands.getstatusoutput(CMD)
+ return deployment_existed
+
+
+def get_available_pods(name, namespace):
+ CMD = ("kubectl get deployment --namespace={} | grep {}".format(
+ namespace, name) + " | awk '{print $5}'")
+ available_pods = commands.getstatusoutput(CMD)
+ return int(available_pods[1])
+
+
def watch_namespace(namespace, count=3, stop=None, request_timeout=0):
w = watch.Watch()
LOG.debug("Watch object generated: {}".format(w))
@@ -54,3 +87,9 @@ def watch_namespace(namespace, count=3, stop=None, request_timeout=0):
if not count:
LOG.info("Ended.\n")
w.stop()
+
+
+def write_json(data, file_name):
+ with open(file_name, "a") as f:
+ f.write(json.dumps(data, f))
+ f.write("\n")