diff options
Diffstat (limited to 'utils/env_prepare')
-rw-r--r-- | utils/env_prepare/moon_prepare.bash | 35 | ||||
-rw-r--r-- | utils/env_prepare/moon_prepare.py | 25 | ||||
-rw-r--r-- | utils/env_prepare/quota_prepare.py | 31 | ||||
-rw-r--r-- | utils/env_prepare/stack_prepare.py | 47 |
4 files changed, 124 insertions, 14 deletions
diff --git a/utils/env_prepare/moon_prepare.bash b/utils/env_prepare/moon_prepare.bash new file mode 100644 index 00000000..7625418c --- /dev/null +++ b/utils/env_prepare/moon_prepare.bash @@ -0,0 +1,35 @@ +#!/bin/bash +############################################################################## +# 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 +############################################################################## +if grep -q "cadvisor" /etc/systemd/system/kubelet.service.d/10-kubeadm.conf +then + sed -e "/cadvisor-port=0/d" -i /etc/systemd/system/kubelet.service.d/10-kubeadm.conf + systemctl daemon-reload + systemctl restart kubelet + +fi +if kubectl get po -n monitoring |grep prometheus-k8s |grep -q Running +then + echo "monitoring k8s deployment has been done" +else + git clone https://github.com/coreos/prometheus-operator.git + cd prometheus-operator + kubectl apply -n kube-system -f bundle.yaml + cd contrib/kube-prometheus + sleep 10 + hack/cluster-monitoring/deploy +fi + +while ! $(kubectl get po -n monitoring |grep prometheus-k8s |grep -q Running);do + echo "waiting for monitoring deployment finish!" + sleep 10 +done + +echo "waiting for monitoring tool works" +sleep 60 diff --git a/utils/env_prepare/moon_prepare.py b/utils/env_prepare/moon_prepare.py new file mode 100644 index 00000000..41739454 --- /dev/null +++ b/utils/env_prepare/moon_prepare.py @@ -0,0 +1,25 @@ +#!/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 utils.infra_setup.passwordless_SSH.ssh as localssh + + +def moon_envprepare(host_info): + if ("password") in host_info: + client = localssh.SSH(user=host_info["user"], + host=host_info["ip"], + password=host_info["password"]) + else: + client = localssh.SSH(user=host_info["user"], + host=host_info["ip"], + key_filename=host_info["keyfile"]) + with open("/home/opnfv/bottlenecks/utils/env_prepare/moon_prepare.bash", + "rb") as stdin_file: + client.run("cat > ~/bottlenecks_envprepare.bash", stdin=stdin_file) + client.execute("sudo bash ~/bottlenecks_envprepare.bash") diff --git a/utils/env_prepare/quota_prepare.py b/utils/env_prepare/quota_prepare.py index 24015954..8dcdf3d6 100644 --- a/utils/env_prepare/quota_prepare.py +++ b/utils/env_prepare/quota_prepare.py @@ -22,7 +22,9 @@ neutron_quota = {"subnet": -1, "subnetpool": -1, "router": -1, "port": -1, - "security_group": -1} + "security_group": -1, + "security_group_rule": -1, + "rbac_policy": -1} nova_quota = {"ram": -1, "cores": -1, @@ -40,14 +42,37 @@ nova_quota = {"ram": -1, "injected_file_path_bytes": -1} +def check_https_enabled(): + LOG.debug("Check if https is enabled in OpenStack") + os_auth_url = os.getenv('OS_AUTH_URL') + if os_auth_url.startswith('https'): + LOG.debug("https is enabled") + return True + LOG.debug("https is not enabled") + return False + + def quota_env_prepare(): + https_enabled = check_https_enabled() + insecure_option = '' + insecure = os.getenv('OS_INSECURE',) + if https_enabled: + LOG.info("https is enabled") + if insecure: + if insecure.lower() == "true": + insecure_option = ' --insecure ' + else: + LOG.warn("Env variable OS_INSECURE is {}: if https + no " + "credential used, it should be set as True." + .format(insecure)) + tenant_name = os.getenv("OS_TENANT_NAME") - cmd = ("openstack project list | grep " + + cmd = ("openstack {} project list | grep ".format(insecure_option) + tenant_name + " | awk '{print $2}'") result = commands.getstatusoutput(cmd) - if result[0] == 0: + if result[0] == 0 and 'exception' not in result[1]: LOG.info("Get %s project id is %s" % (tenant_name, result[1])) else: LOG.error("can't get openstack project id") diff --git a/utils/env_prepare/stack_prepare.py b/utils/env_prepare/stack_prepare.py index 5de6218f..6b9bc510 100644 --- a/utils/env_prepare/stack_prepare.py +++ b/utils/env_prepare/stack_prepare.py @@ -14,6 +14,7 @@ from utils.logger import Logger from utils.parser import Parser as config import utils.infra_setup.heat.manager as utils import utils.infra_setup.runner.docker_env as docker_env +import utils.infra_setup.heat.manager as client_manager LOG = Logger(__name__).getLogger() @@ -37,16 +38,6 @@ def _prepare_env_daemon(test_yardstick): config.bottlenecks_config["yardstick_rc_dir"]) docker_env.docker_exec_cmd(yardstick_contain, cmd) - file_orig = ("/home/opnfv/repos/yardstick/etc" - "/yardstick/yardstick.conf.sample") - file_after = "/etc/yardstick/yardstick.conf" - cmd = "cp %s %s" % (file_orig, - file_after) - docker_env.docker_exec_cmd(yardstick_contain, - cmd) - cmd = "sed -i '13s/http/file/g' /etc/yardstick/yardstick.conf" - docker_env.docker_exec_cmd(yardstick_contain, - cmd) # update the external_network _source_file(rc_file) @@ -83,7 +74,14 @@ def _source_file(rc_file): p = subprocess.Popen(". %s; env" % rc_file, stdout=subprocess.PIPE, shell=True) output = p.communicate()[0] - env = dict((line.split('=', 1) for line in output.splitlines())) + output_lines = output.splitlines() + env = list() + for line in output_lines: + if '=' in line: + env.append(tuple(line.split('=', 1))) + + env = dict(env) +# env = dict((line.split('=', 1) for line in output_lines)) os.environ.update(env) return env @@ -103,3 +101,30 @@ def _append_external_network(rc_file): except OSError as e: if e.errno != errno.EEXIST: raise + + +def prepare_image(image_name, image_dir): + glance_client = client_manager._get_glance_client() + if not os.path.isfile(image_dir): + LOG.error("Error: file %s does not exist.", image_dir) + return None + try: + images = glance_client.images.list() + image_id = next((i.id for i in images if i.name == image_name), None) + if image_id is not None: + LOG.info("Image %s already exists.", image_name) + else: + LOG.info("Creating image '%s' from '%s'...", image_name, image_dir) + + image = glance_client.images.create( + name=image_name, visibility="public", disk_format="qcow2", + container_format="bare") + image_id = image.id + with open(image_dir) as image_data: + glance_client.images.upload(image_id, image_data) + return image_id + except Exception: # pylint: disable=broad-except + LOG.error( + "Error [create_glance_image(glance_client, '%s', '%s')]", + image_name, image_dir) + return None |