diff options
Diffstat (limited to 'utils')
-rw-r--r-- | utils/env_prepare/config_prepare.sh | 5 | ||||
-rwxr-xr-x | utils/infra_setup/heat/common.py | 16 | ||||
-rw-r--r-- | utils/k8s_setup/__init__.py (renamed from utils/kube_setup/__init__.py) | 0 | ||||
-rw-r--r-- | utils/k8s_setup/golang_install.sh (renamed from utils/kube_setup/install_golang.sh) | 0 | ||||
-rw-r--r-- | utils/k8s_setup/k8s_config_pre.sh | 80 | ||||
-rw-r--r-- | utils/k8s_setup/k8s_env.sh (renamed from utils/kube_setup/kube_env.sh) | 0 | ||||
-rw-r--r-- | utils/k8s_setup/k8s_utils.py | 95 | ||||
-rw-r--r-- | utils/k8s_setup/kubectl_install.sh (renamed from utils/kube_setup/install_kubectl.sh) | 2 | ||||
-rw-r--r-- | utils/tools/dos2unix.sh | 5 |
9 files changed, 193 insertions, 10 deletions
diff --git a/utils/env_prepare/config_prepare.sh b/utils/env_prepare/config_prepare.sh index b13b5a02..23923198 100644 --- a/utils/env_prepare/config_prepare.sh +++ b/utils/env_prepare/config_prepare.sh @@ -97,6 +97,7 @@ if [[ ${INSTALLER_TYPE} != "" ]]; then ${RELENG_REPO}/utils/fetch_os_creds.sh -d ${OPENRC} -i ${INSTALLER_TYPE} -a ${INSTALLER_IP} >${redirect} fi elif [[ $INSTALLER_TYPE == 'apex' ]]; then + export BRANCH="stable/fraser" INSTALLER_IP=$(sudo virsh domifaddr undercloud | grep -Eo '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}') ${RELENG_REPO}/utils/fetch_os_creds.sh -d ${OPENRC} -i ${INSTALLER_TYPE} -a ${INSTALLER_IP} -o ${OS_CACERT} >${redirect} echo ${cmd} @@ -155,7 +156,7 @@ if [[ ${INSTALLER_TYPE} != "" ]]; then echo "export OS_CACERT=${OS_CACERT}" >> ${OPENRC} cat ${OPENRC} else - error "Couldn't find openstack cacert file: ${OS_CACERT}, please check if the it's been properly provided." + info "Couldn't find openstack cacert file: ${OS_CACERT}, please check if the it's been properly provided." fi else error "Couldn't find openstack rc file: ${OPENRC}, please check if the it's been properly provided." @@ -166,6 +167,6 @@ if [[ ${INSTALLER_TYPE} != "" ]]; then if [[ -f "/tmp/id_rsa" ]]; then info "Path of ssh key file for openstack nodes is /tmp/id_rsa" else - error "Couldn't find the ssh key file for openstack nodes. If you are using user/pwd in pod.yaml, please ignore." + info "Couldn't find the ssh key file for openstack nodes. If you are using user/pwd in pod.yaml, please ignore." fi fi diff --git a/utils/infra_setup/heat/common.py b/utils/infra_setup/heat/common.py index a0d6d83c..f0512b0f 100755 --- a/utils/infra_setup/heat/common.py +++ b/utils/infra_setup/heat/common.py @@ -66,14 +66,16 @@ def get_session_auth(): def get_session(): auth = get_session_auth() - try: - cacert = os.environ['OS_CACERT'] - except KeyError: - return session.Session(auth=auth) - else: - insecure = os.getenv('OS_INSECURE', '').lower() == 'true' - cacert = False if insecure else cacert + if os.getenv('OS_INSECURE', '').lower() == 'true': + cacert = False return session.Session(auth=auth, verify=cacert) + else: + try: + cacert = os.environ['OS_CACERT'] + except KeyError: + return session.Session(auth=auth) + else: + return session.Session(auth=auth, verify=cacert) def get_endpoint(service_type, endpoint_type='publicURL'): diff --git a/utils/kube_setup/__init__.py b/utils/k8s_setup/__init__.py index e69de29b..e69de29b 100644 --- a/utils/kube_setup/__init__.py +++ b/utils/k8s_setup/__init__.py diff --git a/utils/kube_setup/install_golang.sh b/utils/k8s_setup/golang_install.sh index 06c54cee..06c54cee 100644 --- a/utils/kube_setup/install_golang.sh +++ b/utils/k8s_setup/golang_install.sh diff --git a/utils/k8s_setup/k8s_config_pre.sh b/utils/k8s_setup/k8s_config_pre.sh new file mode 100644 index 00000000..38e71d23 --- /dev/null +++ b/utils/k8s_setup/k8s_config_pre.sh @@ -0,0 +1,80 @@ +#!/bin/bash +############################################################################## +# Copyright (c) 2018 Huawei Tech and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## +K8S_CONFIG="/tmp/k8s_config" + +usage="Script to prepare kubenetes test configurations. + +usage: + bash $(basename "$0") [-h|--help] [-i|--installer <installer typer>] [-c|--config <k8s config>] + +where: + -h|--help show the help text + -i|--installer specify the installer for the system to be monitored + <installer type> + one of the following: + (compass) +examples: + $(basename "$0") -i compass" + + +info () { + logger -s -t "BOTTLENECKS INFO" "$*" +} + +error () { + logger -s -t "BOTTLENECKS ERROR" "$*" + exit 1 +} + +# Process input variables +while [[ $# > 0 ]] + do + key="$1" + case $key in + -h|--help) + echo "$usage" + exit 0 + shift + ;; + -i|--installer) + INSTALLER_TYPE="$2" + shift + ;; + -c|--config) + K8S_CONFIG="$2" + shift + ;; + *) + error "unkown input options $1 $2" + exit 1 + ;; + esac + shift +done + +if [[ ${INSTALLER_TYPE} == 'compass' ]]; then + sshpass -p root scp -o StrictHostKeyChecking=no root@192.16.1.222:~/.kube/config ${K8S_CONFIG} +else + echo "BOTTLENECKS EROOR: unrecognized installer" +fi + +if [[ -f ${K8S_CONFIG} ]]; then + if [[ -d ~/.kube ]]; then + cp ${K8S_CONFIG} ~/.kube/config + echo "BOTTLENECKS INFO: copying k8s config to ~./kube" + else + mkdir ~/.kube + cp ${K8S_CONFIG} ~/.kube/config + echo "BOTTLENECKS INFO: copying k8s config to ~./kube" + fi +else + echo "BOTTLENECKS ERROR: k8s config file does no exit (${K8S_CONFIG})" + exit 1 +fi diff --git a/utils/kube_setup/kube_env.sh b/utils/k8s_setup/k8s_env.sh index 855dea2f..855dea2f 100644 --- a/utils/kube_setup/kube_env.sh +++ b/utils/k8s_setup/k8s_env.sh diff --git a/utils/k8s_setup/k8s_utils.py b/utils/k8s_setup/k8s_utils.py new file mode 100644 index 00000000..a89889f3 --- /dev/null +++ b/utils/k8s_setup/k8s_utils.py @@ -0,0 +1,95 @@ +#!/usr/bin/env python +############################################################################## +# Copyright (c) 2018 Huawei Technologies Co.,Ltd and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## + +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, K8S_CONFIG_PATH="/tmp/k8s_config"): + if INSTALLER_TYPE: + CMD = "bash " + K8S_UTILS + "/k8s_config_pre.sh -i " \ + + INSTALLER_TYPE + \ + " -c " + K8S_CONFIG_PATH + LOG.info("Executing command: " + CMD) + os.popen(CMD) + else: + if not os.path.exists(K8S_CONFIG_PATH): + raise Exception("Must at least specify the path \ +of k8s config!") + return K8S_CONFIG_PATH + + +def get_core_api(version='v1'): + if version.lower() == 'v1': + API = client.CoreV1Api() + LOG.info(API) + else: + 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)) + LOG.info("Watch stream generated: {}".format( + w.stream(namespace, _request_timeout=request_timeout))) + for event in w.stream(namespace, _request_timeout=request_timeout): + LOG.info("Event: %s %s" % + (event['type'], event['object'].metadata.name)) + if event['object'].metadata.name == stop: + LOG.info("Namesapce successfully added.\n") + w.stop() + count -= 1 + 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") diff --git a/utils/kube_setup/install_kubectl.sh b/utils/k8s_setup/kubectl_install.sh index 14f97f2b..22c6197b 100644 --- a/utils/kube_setup/install_kubectl.sh +++ b/utils/k8s_setup/kubectl_install.sh @@ -9,7 +9,7 @@ ############################################################################## OS_TYPE=$(uname -a) -OS_UBUNTU=$(echo $OS_TYPE | grep ubuntu) +OS_UBUNTU=$(echo $OS_TYPE | grep Ubuntu) if [[ $OS_UBUNTU ]]; then apt-get update && apt-get install -y apt-transport-https diff --git a/utils/tools/dos2unix.sh b/utils/tools/dos2unix.sh new file mode 100644 index 00000000..6bfc8f9c --- /dev/null +++ b/utils/tools/dos2unix.sh @@ -0,0 +1,5 @@ +#!/bin/bash +for file in `find ./` +do +vi +':w ++ff=unix' +':q' ${file} +done |