#!/usr/bin/env python # # jose.lausuch@ericsson.com # valentin.boucher@orange.com # 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 logging import os.path import re import sys import time from keystoneauth1 import loading from keystoneauth1 import session from cinderclient import client as cinderclient from glanceclient import client as glanceclient from heatclient import client as heatclient from novaclient import client as novaclient from keystoneclient import client as keystoneclient from neutronclient.neutron import client as neutronclient from functest.utils.constants import CONST import functest.utils.functest_utils as ft_utils logger = logging.getLogger(__name__) DEFAULT_API_VERSION = '2' DEFAULT_HEAT_API_VERSION = '1' # ********************************************* # CREDENTIALS # ********************************************* class MissingEnvVar(Exception): def __init__(self, var): self.var = var def __str__(self): return str.format("Please set the mandatory env var: {}", self.var) def is_keystone_v3(): keystone_api_version = os.getenv('OS_IDENTITY_API_VERSION') if (keystone_api_version is None or keystone_api_version == '2'): return False else: return True def get_rc_env_vars(): env_vars = ['OS_AUTH_URL', 'OS_USERNAME', 'OS_PASSWORD'] if is_keystone_v3(): env_vars.extend(['OS_PROJECT_NAME', 'OS_USER_DOMAIN_NAME', 'OS_PROJECT_DOMAIN_NAME']) else: env_vars.extend(['OS_TENANT_NAME']) return env_vars def check_credentials(): """ Check if the OpenStack credentials (openrc) are sourced """ env_vars = get_rc_env_vars() return all(map(lambda v: v in os.environ and os.environ[v], env_vars)) def get_env_cred_dict(): env_cred_dict = { 'OS_USERNAME': 'username', 'OS_PASSWORD': 'password', 'OS_AUTH_URL': 'auth_url', 'OS_TENANT_NAME': 'tenant_name', 'OS_USER_DOMAIN_NAME': 'user_domain_name', 'OS_PROJECT_DOMAIN_NAME': 'project_domain_name', 'OS_PROJECT_NAME': 'project_name', 'OS_ENDPOINT_TYPE': 'endpoint_type', 'OS_REGION_NAME': 'region_name', 'OS_CACERT': 'https_cacert', 'OS_INSECURE': 'https_insecure' } return env_cred_dict def get_credentials(other_creds={}): """Returns a creds dictionary filled with parsed from env """ creds = {} env_vars = get_rc_env_vars() env_cred_dict = get_env_cred_dict() for envvar in env_vars: if os.getenv(envvar) is None: raise MissingEnvVar(envvar) else: creds_key = env_cred_dict.get(envvar) creds.update({creds_key: os.getenv(envvar)}) if 'tenant' in other_creds.keys(): if is_keystone_v3(): tenant = 'project_name' else: tenant = 'tenant_name' other_creds[tenant] = other_creds.pop('tenant') creds.update(other_creds) return creds def source_credentials(rc_file): with open(rc_file, "r") as f: for line in f: var = (line.rstrip('"\n').replace('export ', '').split("=") if re.search(r'(.*)=(.*)', line) else None) # The two next lines should be modified as soon as rc_file # conforms with common rules. Be aware that it could induce # issues if value starts with ' if var: key = re.sub(r'^["\' ]*|[ \'"]*$', '', var[0]) value = re.sub(r'^["\' ]*|[ \'"]*$', '', "".join(var[1:])) os.environ[key] = value def get_credentials_for_rally(): creds = get_credentials() env_cred_dict = get_env_cred_dict() rally_conf = {"admin": {}} for key in creds: if key == 'auth_url': rally_conf[key] = creds[key] else: rally_conf['admin'][key] = creds[key] endpoint_types = [('internalURL', 'internal'), ('publicURL', 'public'), ('adminURL', 'admin')] endpoint_type = get_endpoint_type_from_env() if endpoint_type is not None: cred_key = env_cred_dict.get('OS_ENDPOINT_TYPE') for k, v in endpoint_types: if endpoint_type == v: rally_conf[cred_key] = v region_name = os.getenv('OS_REGION_NAME') if region_name is not None: cred_key = env_cred_dict.get('OS_REGION_NAME') rally_conf[cred_key] = region_name cred_key = env_cred_dict.get('OS_CACERT') rally_conf[cred_key] = os.getenv('OS_CACERT', '') insecure_key = env_cred_dict.get('OS_INSECURE') rally_conf[insecure_key] = os.getenv('OS_INSECURE', '').lower() == 'true' rally_conf = {"openstack": rally_conf} return rally_conf def get_endpoint_type_from_env(): endpoint_type = os.environ.get("OS_ENDPOINT_TYPE", os.environ.get("OS_INTERFACE")) if endpoint_type and "URL" in endpoint_type: endpoint_type = endpoint_type.replace("URL", "") return endpoint_type def get_session_auth(other_creds={}): loader = loading.get_plugin_loader('password') creds = get_credentials(other_creds) auth = loader.load_from_options(**creds) return auth def get_endpoint(service_type, interface='public'): auth = get_session_auth() return get_session().get_endpoint(auth=auth, service_type=service_type, interface=interface) def get_session(other_creds={}): auth = get_session_auth(other_creds) https_cacert = os.getenv('OS_CACERT', '') https_insecure = os.getenv('OS_INSECURE', '').lower() == 'true' return session.Session(auth=auth, verify=(https_cacert or not https_insecure)) # ********************************************* # CLIENTS # ********************************************* def get_keystone_client_version(): api_version = os.getenv('OS_IDENTITY_API_VERSION') if api_version is not None: logger.info("OS_IDENTITY_API_VERSION is set in env as '%s'", api_version) return api_version return DEFAULT_API_VERSION def get_keystone_client(other_creds={}): sess = get_session(other_creds) return keystoneclient.Client(get_keystone_client_version(), session=sess, interface=os.getenv('OS_INTERFACE', 'admin')) def get_nova_client_version(): api_version = os.getenv('OS_COMPUTE_API_VERSION') if api_version is not None: logger.info("OS_COMPUTE_API_VERSION is set in env as '%s'", api_version) return api_version return DEFAULT_API_VERSION def get_nova_client(other_creds={}): sess = get_session(other_creds) return novaclient.Client(get_nova_client_version(), session=sess) def get_cinder_client_version(): api_version = os.getenv('OS_VOLUME_API_VERSION') if api_version is not None: logger.info("OS_VOLUME_API_VERSION is set in env as '%s'", api_version) return api_version return DEFAULT_API_VERSION def get_cinder_client(other_creds={}): sess = get_session(other_creds) return cinderclient.Client(get_cinder_client_version(), session=sess) def get_neutron_client_version(): api_version = os.getenv('OS_NETWORK_API_VERSION') if api_version is not None: logger.info("OS_NETWORK_API_VERSION is set in env as '%s'", api_version) return api_version return DEFAULT_API_VERSION def get_neutron_client(other_creds={}): sess = get_session(other_creds) return neutronclient.Client(get_neutron_client_version(), session=sess) def get_glance_client_version(): api_version = os.getenv('OS_IMAGE_API_VERSION') if api_version is not None: logger.info("OS_IMAGE_API_VERSION is set in env as '%s'", api_version) return api_version return DEFAULT_API_VERSION def get_glance_client(other_creds={}): sess = get_session(other_creds) return glanceclient.Client(get_glance_client_version(), session=sess) def get_heat_client_version(): api_versi
# Copyright (c) 2016-2018 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
{% set vports = vports or 2 %}
{% set mem = mem or 20480 %}
{% set vcpus = vcpus or 10 %}
{% set disk = disk or 6 %}
{% set timeout = timeout or 300 %}
---
schema: "yardstick:task:0.1"
scenarios:
-
type: NSPerf
traffic_profile: ../../traffic_profiles/prox_binsearch.yaml
extra_args:
vports: {{ vports }}
topology: prox-tg-topology-scale-up.yaml
nodes:
tg__0: tg_0.yardstick
vnf__0: vnf_0.yardstick
options:
vnf__0:
prox_path: /opt/nsb_bin/prox
prox_config: "configs/handle_l2fwd-{{ vports }}.cfg"
prox_args:
"-t": ""
tg__0:
prox_path: /opt/nsb_bin/prox
prox_config: "configs/gen_l2fwd-{{ vports }}.cfg"
prox_args:
"-e": ""
"-t": ""
runner:
type: Search
# we kill after duration, independent of test duration, so set this high
interval: 5
timeout: {{ timeout }}
-
type: NSPerf
traffic_profile: ../../traffic_profiles/prox_binsearch.yaml
extra_args:
vports: {{ vports }}
topology: prox-tg-topology-scale-up.yaml
nodes:
tg__0: tg_0.yardstick
vnf__0: vnf_0.yardstick
options:
vnf__0:
prox_path: /opt/nsb_bin/prox
prox_config: "configs/handle_l3fwd-{{ vports }}.cfg"
prox_args:
"-t": ""
prox_files:
"configs/ipv4.lua" : ""
tg__0:
prox_path: /opt/nsb_bin/prox
prox_config: "configs/gen_l3fwd-{{ vports }}.cfg"
prox_args:
"-e": ""
"-t": ""
runner:
type: Search
# we kill after duration, independent of test duration, so set this high
interval: 5
timeout: {{ timeout }}
context:
name: yardstick
image: yardstick-samplevnfs
user: ubuntu
flavor:
vcpus: {{ vcpus }}
ram: {{ mem }}
disk: {{ disk }}
extra_specs:
hw:cpu_sockets: 1
hw:cpu_cores: {{ vcpus }}
hw:cpu_threads: 1
placement_groups:
pgrp1:
policy: "availability"
servers:
vnf_0:
floating_ip: true
placement: "pgrp1"
tg_0:
floating_ip: true
placement: "pgrp1"
networks:
mgmt:
cidr: '10.0.1.0/24'
{% for vport in range(1,vports,2|int) %}
uplink_{{ loop.index0 }}:
cidr: '10.0.{{ vport+1 }}.0/24'
gateway_ip: 'null'
port_security_enabled: False
enable_dhcp: 'false'
downlink_{{ loop.index0 }}:
cidr: '10.0.{{ vport+2 }}.0/24'
gateway_ip: 'null'
port_security_enabled: False
enable_dhcp: 'false'
{% endfor %}