From 0d3e9ace323660381350a884b08ed92aa2290dbd Mon Sep 17 00:00:00 2001 From: Huang Haibin Date: Tue, 10 Jul 2018 19:22:34 +0800 Subject: Add Openstack Pike plugin framework Add Pike framework and one function extension Add Vagrant for test Change-Id: I045ac1f1a920b509a69d7a72f8e60fb108102839 Issue-ID: MULTICLOUD-276 Signed-off-by: Huang Haibin --- pike/vagrant/test/Dockerfile | 25 ++++++ pike/vagrant/test/extsys.py | 145 +++++++++++++++++++++++++++++++++++ pike/vagrant/test/test-extensions.sh | 6 ++ pike/vagrant/test/test_multicloud.sh | 29 +++++++ pike/vagrant/test/tests | 1 + 5 files changed, 206 insertions(+) create mode 100644 pike/vagrant/test/Dockerfile create mode 100644 pike/vagrant/test/extsys.py create mode 100644 pike/vagrant/test/test-extensions.sh create mode 100644 pike/vagrant/test/test_multicloud.sh create mode 100644 pike/vagrant/test/tests (limited to 'pike/vagrant/test') diff --git a/pike/vagrant/test/Dockerfile b/pike/vagrant/test/Dockerfile new file mode 100644 index 00000000..00f8250c --- /dev/null +++ b/pike/vagrant/test/Dockerfile @@ -0,0 +1,25 @@ +FROM python:2 + +ENV MSB_ADDR "127.0.0.1" +ENV MSB_PORT "80" +ENV AAI_ADDR "aai.api.simpledemo.openecomp.org" +ENV AAI_PORT "8443" +ENV AAI_SCHEMA_VERSION "v13" +ENV AAI_USERNAME "AAI" +ENV AAI_PASSWORD "AAI" + +EXPOSE 9007 + +COPY multicloud-openstack-pike.zip /opt +RUN apt-get update && \ + apt-get install -y vim memcached unzip && \ + cd /opt/ && \ + unzip -q -o -B multicloud-openstack-pike.zip && \ + chmod +x /opt/pike/*.sh && \ + rm -f multicloud-openstack-pike.zip && \ + pip install -r /opt/pike/requirements.txt + +ADD extsys.py /opt/pike/lib/share/common/msapi/extsys.py + +WORKDIR /opt/pike +CMD /bin/sh -c /opt/pike/run.sh diff --git a/pike/vagrant/test/extsys.py b/pike/vagrant/test/extsys.py new file mode 100644 index 00000000..78b41387 --- /dev/null +++ b/pike/vagrant/test/extsys.py @@ -0,0 +1,145 @@ +# Copyright (c) 2017-2018 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. +# See the License for the specific language governing permissions and +# limitations under the License. + +import json +import logging +import re + +from rest_framework import status +from common.exceptions import VimDriverNewtonException +from common.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.1.10:5000/v3", + "userName": "admin", + "vendor": "OpenStack", + "version": "pike", + "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/pike/vagrant/test/test-extensions.sh b/pike/vagrant/test/test-extensions.sh new file mode 100644 index 00000000..82c254a8 --- /dev/null +++ b/pike/vagrant/test/test-extensions.sh @@ -0,0 +1,6 @@ +#!/bin/bash +set -ex + +MULTICLOUD_PLUGIN_ENDPOINT=http://172.16.77.40:9007/api/multicloud-pike/v0/openstack-hudson-dc_RegionOne +curl -v -s -H "Content-Type: application/json" -X GET $MULTICLOUD_PLUGIN_ENDPOINT/extensions +curl -v -s -H "Content-Type: application/json" -X GET $MULTICLOUD_PLUGIN_ENDPOINT/extensions/epa-caps diff --git a/pike/vagrant/test/test_multicloud.sh b/pike/vagrant/test/test_multicloud.sh new file mode 100644 index 00000000..efc934ce --- /dev/null +++ b/pike/vagrant/test/test_multicloud.sh @@ -0,0 +1,29 @@ +#!/bin/bash +set -ex + +sudo apt-get update -y +sudo apt-get install -y docker.io maven npm virtualenv python-dev + +git clone http://gerrit.onap.org/r/oparent +mkdir $HOME/.m2 +cp oparent/settings.xml $HOME/.m2 + +git clone /openstack +cd openstack +mvn clean install +cp pike/target/multicloud-openstack-pike*.zip pike/vagrant/test/multicloud-openstack-pike.zip + +cd pike/vagrant/test +sudo docker build -t multicloud-pike-test:latest . +sudo docker network create --subnet=172.16.77.0/24 onap +sudo docker run -d -t --name pike-test --network onap --ip 172.16.77.40 -e MSB_ADDR=172.16.77.40 -e MSB_PORT=9007 multicloud-pike-test + +while true; do + sleep 10 + curl http://172.16.77.40:9007/api/multicloud-pike/v0/swagger.json && break +done + +for i in `cat tests` +do + bash ./$i +done diff --git a/pike/vagrant/test/tests b/pike/vagrant/test/tests new file mode 100644 index 00000000..018c7a48 --- /dev/null +++ b/pike/vagrant/test/tests @@ -0,0 +1 @@ +test-extensions.sh -- cgit 1.2.3-korg