diff options
Diffstat (limited to 'utils')
-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 | ||||
-rw-r--r-- | utils/infra_setup/heat/manager.py | 2 | ||||
-rw-r--r-- | utils/infra_setup/runner/docker_env.py | 4 | ||||
-rw-r--r-- | utils/infra_setup/runner/storperf_usage.py | 171 | ||||
-rw-r--r-- | utils/infra_setup/runner/yardstick.py | 15 | ||||
-rw-r--r-- | utils/parser.py | 5 |
9 files changed, 318 insertions, 17 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 diff --git a/utils/infra_setup/heat/manager.py b/utils/infra_setup/heat/manager.py index 5c181ae6..1a360b78 100644 --- a/utils/infra_setup/heat/manager.py +++ b/utils/infra_setup/heat/manager.py @@ -35,7 +35,7 @@ def _get_neutron_client(): return neutron_client -def stack_create_images( +def create_images( imagefile=None, image_name="bottlenecks_image"): print "========== Create image in OS ==========" diff --git a/utils/infra_setup/runner/docker_env.py b/utils/infra_setup/runner/docker_env.py index 64d049ba..438d3d19 100644 --- a/utils/infra_setup/runner/docker_env.py +++ b/utils/infra_setup/runner/docker_env.py @@ -45,13 +45,13 @@ def env_yardstick(docker_name): volume = get_self_volume() yardstick_tag = os.getenv("Yardstick_TAG") if yardstick_tag is None: - yardstick_tag = "danube.3.1" + yardstick_tag = "latest" env_docker = client.containers.run(image="opnfv/yardstick:%s" % yardstick_tag, privileged=True, tty=True, detach=True, - ports={'5000': '8888'}, + # ports={'5000': '8888'}, volumes=volume, name=docker_name) yardstick_info["container"] = env_docker diff --git a/utils/infra_setup/runner/storperf_usage.py b/utils/infra_setup/runner/storperf_usage.py new file mode 100644 index 00000000..69f0a29c --- /dev/null +++ b/utils/infra_setup/runner/storperf_usage.py @@ -0,0 +1,171 @@ +#!/usr/bin/env python +############################################################################## +# Copyright (c) 2017 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 +############################################################################## +'''This file contain all functions about storperf API. +At present, This file contain the following function: +1. Ask storperf to configure the environment. +2. Ask Storperf to run testcase and get the job id. +3. Use Job id to ask storperf for status, metrics and metadata. +4. Query information about current jobs, environment and view logs.''' + +import time +import requests +import json +import os +import utils.logger as logger + +headers = { + "Content-Type": "application/json", + "Accept": "application/json" + } +LOG = logger.Logger(__name__).getLogger() + + +def storperf_env_prepare(con_dic, storperf_count, storperf_image, + storperf_flavor, volume_size): + base_url = ("http://%s/api/v1.0/configurations" + % (con_dic['storperf_test_ip'])) + test_dict = { + "agent_count": storperf_count, + "agent_image": storperf_image, + "agent_flavor": storperf_flavor, + "public_network": os.environ.get("EXTERNAL_NETWORK"), + "volume_size": volume_size + } + LOG.info("waiting for storperf environment to prepare") + reponse = requests.post( + base_url, data=json.dumps(test_dict), headers=headers) + ask_data = json.loads(reponse.text) + stack_id = ask_data["stack_id"] + LOG.info("Done, storperf environment prepare complete!") + time.sleep(30) + return stack_id + + +def warmup(con_dic): + base_url = ("http://%s/api/v1.0/jobs" + % (con_dic['storperf_test_ip'])) + test_dict = { + "workload": "_warm_up" + } + LOG.info("filling the cinder volume with random data") + reponse = requests.post( + base_url, data=json.dumps(test_dict), headers=headers) + ask_data = json.loads(reponse.text) + job_id = ask_data["job_id"] + LOG.info("Done, filled the cinder volume with random data!") + time.sleep(600) + return job_id + + +def job(con_dic): + base_url = ("http://%s/api/v1.0/jobs" + % (con_dic['storperf_test_ip'])) + test_dict = { + "block_sizes": con_dic['block_sizes'], + "deadline": con_dic['deadline'], + "steady_state_samples": con_dic['steady_state_samples'], + "queue_depths": con_dic['queue_depths'], + "workload": con_dic['workload'] + } + deadline = con_dic['deadline'] + LOG.info("running the storage performance testcase") + reponse = requests.post( + base_url, data=json.dumps(test_dict), headers=headers) + ask_data = json.loads(reponse.text) + job_id = ask_data["job_id"] + LOG.info("Done, testcase still executing for specified deadline") + time.sleep(deadline) + return job_id + + +def current_jobs(con_dic): + base_url = ("http://%s/api/v1.0/jobs" + % (con_dic['storperf_test_ip'])) + reply_response = requests.get( + base_url, headers=headers) + reply_data = json.loads(reply_response.text) + LOG.info("current storperf jobs are %s" % (reply_data)) + return reply_data + + +def job_status(con_dic, job_id): + base_url = ("http://%s/api/v1.0/jobs?id=%s&type=status" + % (con_dic['storperf_test_ip'], job_id)) + reply_response = requests.get( + base_url, headers=headers) + reply_data = json.loads(reply_response.text) + LOG.info("job status is %s" % (reply_data)) + return reply_data + + +def job_metrics(con_dic, job_id): + base_url = ("http://%s/api/v1.0/jobs?id=%s&type=metrics" + % (con_dic['storperf_test_ip'], job_id)) + reply_response = requests.get( + base_url, headers=headers) + reply_data = json.loads(reply_response.text) + LOG.info("job metrics is %s" % (reply_data)) + return reply_data + + +def job_metadata(con_dic, job_id): + base_url = ("http://%s/api/v1.0/jobs?id=%s&type=metadata" + % (con_dic['storperf_test_ip'], job_id)) + reply_response = requests.get( + base_url, headers=headers) + reply_data = json.loads(reply_response.text) + LOG.info("job metadata is %s" % (reply_data)) + return reply_data + + +def get_logs(con_dic): + base_url = ("http://%s/api/v1.0/logs?lines=all" + % (con_dic['storperf_test_ip'])) + reply_response = requests.get( + base_url, headers=headers) + reply_data = json.loads(reply_response.text) + LOG.info("All storperf logs: %s" % (reply_data)) + return reply_data + + +def get_quotas(con_dic): + base_url = ("http://%s/api/v1.0/quotas" + % (con_dic['storperf_test_ip'])) + reply_response = requests.get( + base_url, headers=headers) + reply_data = json.loads(reply_response.text) + LOG.info("current quotas is %s" % (reply_data)) + return reply_data + + +def get_configurations(con_dic): + base_url = ("http://%s/api/v1.0/configurations" + % (con_dic['storperf_test_ip'])) + reply_response = requests.get( + base_url, headers=headers) + reply_data = json.loads(reply_response.text) + LOG.info("current configurations is %s" % (reply_data)) + return reply_data + + +def delete_configurations(con_dic): + base_url = ("http://%s/api/v1.0/configurations" + % (con_dic['storperf_test_ip'])) + requests.delete( + base_url, headers=headers) + LOG.info("delete the storperf environment") + + +def delete_jobs(con_dic): + base_url = ("http://%s/api/v1.0/jobs" + % (con_dic['storperf_test_ip'])) + requests.delete( + base_url, headers=headers) + LOG.info("delete current storperf jobs") diff --git a/utils/infra_setup/runner/yardstick.py b/utils/infra_setup/runner/yardstick.py index 559b9c10..3eeeee6b 100644 --- a/utils/infra_setup/runner/yardstick.py +++ b/utils/infra_setup/runner/yardstick.py @@ -15,15 +15,27 @@ At present, This file contain the following function: 4.how the process of task.''' import sys +import os import time import requests import json +import urllib import utils.logger as logger +from utils.parser import Parser as config +import utils.env_prepare.stack_prepare as env headers = {"Content-Type": "application/json"} LOG = logger.Logger(__name__).getLogger() +def yardstick_image_prepare(): + if not os.path.exists(config.bottlenecks_config["yardstick_image_dir"]): + urllib.urlretrieve(config.bottlenecks_config["image_url"], + config.bottlenecks_config["yardstick_image_dir"]) + env.prepare_image(config.bottlenecks_config["yardstick_image_name"], + config.bottlenecks_config["yardstick_image_dir"]) + + def yardstick_command_parser(debug, cidr, outfile, parameter): cmd = "yardstick" if debug: @@ -31,6 +43,9 @@ def yardstick_command_parser(debug, cidr, outfile, parameter): cmd += " task start " cmd += str(cidr) cmd += " --output-file " + outfile + image_name = config.bottlenecks_config["yardstick_image_name"] + parameter["image_name"] = image_name + LOG.info(parameter) if parameter is not None: cmd += " --task-args " + '"' + str(parameter) + '"' return cmd diff --git a/utils/parser.py b/utils/parser.py index b46a3b91..c0c10721 100644 --- a/utils/parser.py +++ b/utils/parser.py @@ -45,6 +45,11 @@ class Parser(): cls.bottlenecks_config["pod_info"] = common_config['pod_info'] cls.bottlenecks_config["yardstick_rc_dir"] = \ common_config['yardstick_rc_dir'] + cls.bottlenecks_config["yardstick_image_dir"] = \ + common_config['yardstick_image_dir'] + cls.bottlenecks_config["image_url"] = common_config['image_url'] + cls.bottlenecks_config["yardstick_image_name"] = \ + common_config['yardstick_image_name'] cls.config_dir_check(cls.bottlenecks_config["log_dir"]) @classmethod |