diff options
author | Guo Ruijing <ruijing.guo@intel.com> | 2017-09-14 22:54:53 +0800 |
---|---|---|
committer | Guo Ruijing <ruijing.guo@intel.com> | 2017-09-14 22:57:58 +0800 |
commit | f0fd9149506ca92db0dd7f17cf027ccb434bb99a (patch) | |
tree | 5adc853ec41faa0f174d8ebda13e9318394d385b /ocata | |
parent | 51f18c6e84a88eaea53237b3a21d32ad4ab0e8a5 (diff) |
setup function test framework
this patch is to setup function test framwork for multicloud
Change-Id: I372ca4a11878b25fd9b5f4b7ed199e0d8748e11d
Issue-Id: MULTICLOUD-92
Signed-off-by: Guo Ruijing <ruijing.guo@intel.com>
Diffstat (limited to 'ocata')
-rw-r--r-- | ocata/vagrant/Vagrantfile | 42 | ||||
-rw-r--r-- | ocata/vagrant/bootstrap.sh | 16 | ||||
-rw-r--r-- | ocata/vagrant/compute.conf | 20 | ||||
-rw-r--r-- | ocata/vagrant/control.conf | 29 | ||||
-rw-r--r-- | ocata/vagrant/setup_cell.sh | 6 | ||||
-rw-r--r-- | ocata/vagrant/setup_compute.sh | 14 | ||||
-rw-r--r-- | ocata/vagrant/setup_control.sh | 7 | ||||
-rw-r--r-- | ocata/vagrant/test/Dockerfile | 5 | ||||
-rw-r--r-- | ocata/vagrant/test/extsys.py | 142 | ||||
-rw-r--r-- | ocata/vagrant/test/test1.sh | 4 | ||||
-rw-r--r-- | ocata/vagrant/test/test_multicloud.sh | 21 | ||||
-rw-r--r-- | ocata/vagrant/test/tests | 1 |
12 files changed, 307 insertions, 0 deletions
diff --git a/ocata/vagrant/Vagrantfile b/ocata/vagrant/Vagrantfile new file mode 100644 index 00000000..d8b0f955 --- /dev/null +++ b/ocata/vagrant/Vagrantfile @@ -0,0 +1,42 @@ +# Vagrantfile API/syntax version. Don't touch unless you know what you're doing! +$num_compute_nodes = 1 + +Vagrant.configure("2") do |config| + + config.vm.box = "bento/ubuntu-16.04" + + config.vm.provider :virtualbox do |vb| + vb.customize ["modifyvm", :id, "--memory", 9192] + vb.customize ["modifyvm", :id, "--cpus", 4] + vb.customize ["modifyvm", :id, "--nicpromisc3", "allow-all"] + vb.customize "post-boot",["controlvm", :id, "setlinkstate1", "on"] + end + + + config.vm.define "control" do |config| + config.vm.hostname = "control" + config.vm.network "private_network", ip: "192.168.0.10" + config.vm.network :private_network, ip: "192.168.1.10" + config.vm.provision "shell", path: "bootstrap.sh", privileged: false + config.vm.provision "shell", path: "setup_control.sh", privileged: false + end + + (1 .. $num_compute_nodes).each do |n| + config.vm.define vm_name = "compute-#{n}" do |config| + config.vm.hostname = vm_name + config.vm.network "private_network", ip: "192.168.0.#{n+20}" + config.vm.network :private_network, ip: "192.168.1.#{n+20}" + config.vm.provision "shell", path: "bootstrap.sh", privileged: false + config.vm.provision "shell", path: "setup_compute.sh", privileged: false + end + end + + config.vm.define "multicloud" do |config| + config.vm.hostname = "multicloud" + config.vm.network "private_network", ip: "192.168.0.30" + config.vm.network :private_network, ip: "192.168.1.30" + #config.vm.provision "shell", path: "setup_multivm.sh", privileged: false + config.vm.provision "shell", path: "test/test_multicloud.sh", privileged: false + end + +end diff --git a/ocata/vagrant/bootstrap.sh b/ocata/vagrant/bootstrap.sh new file mode 100644 index 00000000..79d31be4 --- /dev/null +++ b/ocata/vagrant/bootstrap.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash + +set -e + +sudo apt-get update -y +sudo apt-get install git -y +git clone https://github.com/openstack-dev/devstack +cd devstack; git checkout stable/ocata +sudo apt-get install openvswitch-switch -y +sudo ovs-vsctl add-br br-ex +ip=$(ip a s enp0s9 | grep inet | grep -v inet6 | sed "s/.*inet//" | cut -f2 -d' ') +sudo ip address flush enp0s9 +sudo ovs-vsctl add-port br-ex enp0s9 +sudo ip a a $ip dev br-ex +sudo ip link set dev br-ex up +sudo ip link set dev enp0s9 up diff --git a/ocata/vagrant/compute.conf b/ocata/vagrant/compute.conf new file mode 100644 index 00000000..f6c19eaa --- /dev/null +++ b/ocata/vagrant/compute.conf @@ -0,0 +1,20 @@ +[[local|localrc]] +SCREEN_LOGDIR=/opt/stack/log +LOGFILE=stack.sh.log +LOG_COLOR=False + +HOST_IP=HOSTIP +HOST_NAME=HOSTNAME +SERVICE_HOST=192.168.0.10 +SERVICE_HOST_NAME=control + +ADMIN_PASSWORD=admin +SERVICE_PASSWORD=admin +DATABASE_PASSWORD=mysql +RABBIT_PASSWORD=rabbit + +ENABLED_SERVICES=rabbit,n-cpu,n-novnc,placement-client,q-agt +LIBVIRT_TYPE=qemu + +OVS_BRIDGE_MAPPINGS=public:br-ex +OVS_PHYSICAL_BRIDGE=br-ex diff --git a/ocata/vagrant/control.conf b/ocata/vagrant/control.conf new file mode 100644 index 00000000..5b551211 --- /dev/null +++ b/ocata/vagrant/control.conf @@ -0,0 +1,29 @@ +[[local|localrc]] +SCREEN_LOGDIR=/opt/stack/log +LOGFILE=stack.sh.log +LOG_COLOR=False + +HOST_IP=192.168.0.10 +HOST_NAME=control +SERVICE_HOST=192.168.0.10 +SERVICE_HOST_NAME=control + +ADMIN_PASSWORD=admin +SERVICE_PASSWORD=admin +DATABASE_PASSWORD=mysql +RABBIT_PASSWORD=rabbit + +enable_plugin heat https://git.openstack.org/openstack/heat stable/ocata +disable_service n-net +disable_service tempest +ENABLED_SERVICES+=,placement-api,q-svc,q-dhcp,q-meta,q-l3 +ENABLED_SERVICES+=,h-eng,h-api,h-api-cfn,h-api-cw + +## Neutron options +FLOATING_RANGE="192.168.1.0/24" +PUBLIC_NETWORK_GATEWAY="192.168.1.1" +FIXED_RANGE="10.0.0.0/24" +Q_FLOATING_ALLOCATION_POOL=start=192.168.1.200,end=192.168.1.250 +Q_USE_SECGROUP=False +Q_L3_ENABLED=True +Q_USE_PROVIDERNET_FOR_PUBLIC=True diff --git a/ocata/vagrant/setup_cell.sh b/ocata/vagrant/setup_cell.sh new file mode 100644 index 00000000..0fa736a6 --- /dev/null +++ b/ocata/vagrant/setup_cell.sh @@ -0,0 +1,6 @@ +#!/bin/bash +set -e + +source ~/devstack/openrc admin admin +nova-manage cell_v2 discover_hosts +nova-manage cell_v2 map_cell_and_hosts diff --git a/ocata/vagrant/setup_compute.sh b/ocata/vagrant/setup_compute.sh new file mode 100644 index 00000000..7b5964e1 --- /dev/null +++ b/ocata/vagrant/setup_compute.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + +set -e + +cd devstack +cp /vagrant/compute.conf local.conf +ip=$(ip a s enp0s8 | grep inet | grep -v inet6 | sed "s/.*inet //" | cut -f1 -d'/') +host=$(hostname) +sed -i -e "s/HOSTIP/$ip/" -e "s/HOSTNAME/$host/" local.conf +./stack.sh + +sudo apt-get update -y +sudo apt-get install -y putty +echo y | plink -ssh -l vagrant -pw vagrant 192.168.0.10 "bash /vagrant/setup_cell.sh" diff --git a/ocata/vagrant/setup_control.sh b/ocata/vagrant/setup_control.sh new file mode 100644 index 00000000..fb7ef8ac --- /dev/null +++ b/ocata/vagrant/setup_control.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +set -e + +cd devstack +cp /vagrant/control.conf local.conf +./stack.sh diff --git a/ocata/vagrant/test/Dockerfile b/ocata/vagrant/test/Dockerfile new file mode 100644 index 00000000..b0789a2a --- /dev/null +++ b/ocata/vagrant/test/Dockerfile @@ -0,0 +1,5 @@ +FROM multicloud-ocata:latest + +RUN apt-get update && \ + apt-get install -y vim +ADD extsys.py /opt/ocata/lib/ocata/ocata/pub/msapi/extsys.py diff --git a/ocata/vagrant/test/extsys.py b/ocata/vagrant/test/extsys.py new file mode 100644 index 00000000..ba988311 --- /dev/null +++ b/ocata/vagrant/test/extsys.py @@ -0,0 +1,142 @@ +# Copyright (c) 2017 Wind River Systems, Inc. +# +# 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. + +import json +import logging +import re + +from rest_framework import status +from newton.pub.exceptions import VimDriverNewtonException +from newton.pub.utils.restcall import req_by_msb,req_to_aai + + +logger = logging.getLogger(__name__) + +tisr4 = { + "createTime": "2017-04-01 02:22:27", + "domain": "Default", + "name": "TiS_R4", + "password": "admin", + "tenant": "admin", + "type": "openstack", + "url": "http://192.168.0.10:5000/v3", + "userName": "admin", + "vendor": "OpenStack", + "version": "ocata", + "vimId": "openstack-hudson-dc_RegionOne", + 'cloud_owner':'openstack-hudson-dc', + 'cloud_region_id':'RegionOne', + 'cloud_extra_info':'', + 'cloud_epa_caps':'{"huge_page":"true","cpu_pinning":"true",\ + "cpu_thread_policy":"true","numa_aware":"true","sriov":"true",\ + "dpdk_vswitch":"true","rdt":"false","numa_locality_pci":"true"}', + 'insecure':'True', +} + +# "vimId": "6e720f68-34b3-44f0-a6a4-755929b20393" + +def mock_get_vim_by_id(method): + def wrapper(vimid): + return tisr4 + return wrapper + +def mock_delete_vim_by_id(method): + def wrapper(vimid): + return status.HTTP_202_ACCEPTED + return wrapper + +#def get_vims(): +# retcode, content, status_code = \ +# req_by_msb("/api/aai-cloudInfrastructure/v1/cloud-infrastructure/cloud-regions", "GET") +# if retcode != 0: +# logger.error("Status code is %s, detail is %s.", status_code, content) +# raise VimDriverNewtonException("Failed to query VIMs from extsys.") +# return json.JSONDecoder().decode(content) + +@mock_get_vim_by_id +def get_vim_by_id(vim_id): + + cloud_owner,cloud_region_id = decode_vim_id(vim_id) + + if cloud_owner and cloud_region_id: + retcode, content, status_code = \ + req_to_aai("/cloud-infrastructure/cloud-regions/cloud-region/%s/%s" + % (cloud_owner,cloud_region_id),"GET") + if retcode != 0: + logger.error("Status code is %s, detail is %s.", status_code, content) + raise VimDriverNewtonException( + "Failed to query VIM with id (%s:%s,%s)." % (vim_id,cloud_owner,cloud_region_id), + status_code, content) + tmp_viminfo = json.JSONDecoder().decode(content) + + #assume esr-system-info-id is composed by {cloud-owner} _ {cloud-region-id} + retcode2,content2,status_code2 = \ + req_to_aai("/cloud-infrastructure/cloud-regions/cloud-region/%s/%s" + + "/esr-system-info-list/esr-system-info/%s_%s" \ + % (cloud_owner,cloud_region_id,cloud_owner,cloud_region_id), + "GET") + if retcode2 != 0: + logger.error("Status code is %s, detail is %s.", status_code, content) + raise VimDriverNewtonException( + "Failed to query ESR system with id (%s:%s,%s)." % (vim_id,cloud_owner,cloud_region_id), + status_code, content) + tmp_authinfo = json.JSONDecoder().decode(content2) + + #convert vim information + + if tmp_viminfo: + viminfo = {} + viminfo['vimId'] = vim_id + viminfo['cloud_owner'] = cloud_owner + viminfo['cloud_region_id'] = cloud_region_id + viminfo['type'] = tmp_viminfo['cloud-type'] + viminfo['name'] = tmp_viminfo['complex-name'] + viminfo['version'] = tmp_viminfo['cloud-region-version'] + viminfo['cloud_extra_info'] = tmp_viminfo['cloud-extra-info'] + viminfo['cloud_epa_caps'] = tmp_viminfo['cloud-epa-caps'] + + if tmp_authinfo: + viminfo['userName'] = tmp_authinfo['user-name'] + viminfo['password'] = tmp_authinfo['password'] + viminfo['domain'] = tmp_authinfo['cloud-domain'] + viminfo['url'] = tmp_authinfo['service-url'] + viminfo['tenant'] = tmp_authinfo['default-tenant'] + viminfo['cacert'] = tmp_authinfo['ssl-cacert'] + viminfo['insecure'] = tmp_authinfo['ssl-insecure'] + else: + return None + + return viminfo + else: + return None + else: + return None + +@mock_delete_vim_by_id +def delete_vim_by_id(vim_id): + cloud_owner, cloud_region_id = decode_vim_id(vim_id) + if cloud_owner and cloud_region_id: + retcode, content, status_code = \ + req_to_aai("/cloud-infrastructure/cloud-regions/cloud-region/%s/%s" + % ( cloud_owner, cloud_region_id), "DELETE") + if retcode != 0: + logger.error("Status code is %s, detail is %s.", status_code, content) + raise VimDriverNewtonException( + "Failed to delete VIM in AAI with id (%s:%s,%s)." % (vim_id,cloud_owner,cloud_region_id), + status_code, content) + return 0 + # return non zero if failed to decode cloud owner and region id + return 1 + +def decode_vim_id(vim_id): + m = re.search(r'^([0-9a-zA-Z-]+)_([0-9a-zA-Z_-]+)$', vim_id) + cloud_owner, cloud_region_id = m.group(1), m.group(2) + return cloud_owner, cloud_region_id diff --git a/ocata/vagrant/test/test1.sh b/ocata/vagrant/test/test1.sh new file mode 100644 index 00000000..5c7b7937 --- /dev/null +++ b/ocata/vagrant/test/test1.sh @@ -0,0 +1,4 @@ +#!/bin/bash +export MULTICLOUD_PLUGIN_ENDPOINT=http://172.16.77.40:9004/api/multicloud-ocata/v0/openstack-hudson-dc_RegionOne +curl -v -s -H "Content-Type: application/json" -H "X-Auth-Token: $TOKEN" -X GET http://172.16.77.40:9004/api/multicloud-ocata/v0/swagger.json +curl -v -s -H "Content-Type: application/json" -X POST -d '{ }' $MULTICLOUD_PLUGIN_ENDPOINT/identity/v3/auth/tokens | grep X-Subject-Token diff --git a/ocata/vagrant/test/test_multicloud.sh b/ocata/vagrant/test/test_multicloud.sh new file mode 100644 index 00000000..d5f56dea --- /dev/null +++ b/ocata/vagrant/test/test_multicloud.sh @@ -0,0 +1,21 @@ +#!/bin/bash +sudo apt-get update -y +sudo apt-get install -y docker.io + +git clone http://gerrit.onap.org/r/multicloud/openstack +cd openstack/ocata/docker +sudo docker build -t multicloud-ocata:latest . +cd /vagrant/test +sudo docker build -t multicloud-ocata-test:latest . +sudo docker network create --subnet=172.16.77.0/24 onap +sudo docker run -d -t --name ocata-test --network onap --ip 172.16.77.40 -e MSB_ADDR=172.16.77.40:9003 multicloud-ocata-test + +while true; do + sleep 10 + curl http://172.16.77.40:9004/api/multicloud-ocata/v0/swagger.json && break +done + +for i in `cat tests` +do + bash ./$i +done diff --git a/ocata/vagrant/test/tests b/ocata/vagrant/test/tests new file mode 100644 index 00000000..9fb87363 --- /dev/null +++ b/ocata/vagrant/test/tests @@ -0,0 +1 @@ +test1.sh |