From 08f042835a504f0bafe1cb83fc8f5008502ade78 Mon Sep 17 00:00:00 2001 From: Mike Marchetti Date: Thu, 4 May 2017 16:43:09 -0400 Subject: [PATCH] initial delivery of system test framework - add initial pytest framework with fixtures for vim, openstack, osm - test cirros and ping_pong ns available from repo Change-Id: Iae1fa4bcbf55fb8bc6986e798fd662a0bd452470 Signed-off-by: Mike Marchetti --- .gitignore | 2 + systest/.gitignore | 5 + systest/Makefile | 134 ++++++++++++++++++++++++++ systest/conftest.py | 24 +++++ systest/lib/__init__.py | 0 systest/lib/openstack/__init__.py | 15 +++ systest/lib/openstack/fixtures.py | 38 ++++++++ systest/lib/openstack/openstack.py | 23 +++++ systest/lib/osm/__init__.py | 15 +++ systest/lib/osm/fixtures.py | 51 ++++++++++ systest/lib/osm/osm.py | 32 ++++++ systest/lib/vim/__init__.py | 15 +++ systest/lib/vim/fixtures.py | 27 ++++++ systest/lib/vim/vim.py | 26 +++++ systest/testcases/conftest.py | 19 ++++ systest/testcases/smoke/test_smoke.py | 35 +++++++ systest/testcases/vim/test_vim.py | 50 ++++++++++ systest/testcases/vnfs/test_vnfs.py | 106 ++++++++++++++++++++ 18 files changed, 617 insertions(+) create mode 100644 .gitignore create mode 100644 systest/.gitignore create mode 100644 systest/Makefile create mode 100644 systest/conftest.py create mode 100644 systest/lib/__init__.py create mode 100644 systest/lib/openstack/__init__.py create mode 100644 systest/lib/openstack/fixtures.py create mode 100644 systest/lib/openstack/openstack.py create mode 100644 systest/lib/osm/__init__.py create mode 100644 systest/lib/osm/fixtures.py create mode 100644 systest/lib/osm/osm.py create mode 100644 systest/lib/vim/__init__.py create mode 100644 systest/lib/vim/fixtures.py create mode 100644 systest/lib/vim/vim.py create mode 100644 systest/testcases/conftest.py create mode 100644 systest/testcases/smoke/test_smoke.py create mode 100644 systest/testcases/vim/test_vim.py create mode 100644 systest/testcases/vnfs/test_vnfs.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..d9a34988 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.pyc +.cache diff --git a/systest/.gitignore b/systest/.gitignore new file mode 100644 index 00000000..97f7edd0 --- /dev/null +++ b/systest/.gitignore @@ -0,0 +1,5 @@ +pytest-output.xml +*.pyc +.cache +descriptor-packages/ +*.xml diff --git a/systest/Makefile b/systest/Makefile new file mode 100644 index 00000000..fb296cca --- /dev/null +++ b/systest/Makefile @@ -0,0 +1,134 @@ +# Copyright 2017 Sandvine +# All Rights Reserved. +# +# 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. + +# +# These variables need to be defined in environment or passed in +# the make invocation. +# eg. +# export OSM_HOSTNAME=1.2.3.4:8008 +# export OS_URL=https://:5000/v2.0 +# export OS_USERNAME=admin +# export OS_PASSWORD=admin +# export OS_PROJECT_NAME=admin +OSM_HOSTNAME ?= +OS_URL ?= +OS_USERNAME ?= +OS_PASSWORD_NAME ?= +OS_PROJECT_NAME ?= + +ifdef OS_URL + OPTION_OS_URL=--os-url $(OS_URL) +endif +ifdef OS_USERNAME + OPTION_OS_USERNAME=--os-username $(OS_USERNAME) +endif +ifdef OS_PASSWORD + OPTION_OS_PASSWORD=--os-password $(OS_PASSWORD) +endif +ifdef OS_PROJECT_NAME + OPTION_OS_PROJECT_NAME=--os-project-name $(OS_PROJECT_NAME) +endif + +ifdef TEST_VNFD_DESCRIPTORS + OPTION_TEST_VNFD_DESCRIPTORS=--osm-vnfd-descriptor-packages $(TEST_VNFD_DESCRIPTORS) +endif +ifdef TEST_NSD_DESCRIPTORS + OPTION_TEST_NSD_DESCRIPTORS=--osm-nsd-descriptor-packages $(TEST_NSD_DESCRIPTORS) +endif + +DESCRIPTOR_REPO_NAME=descriptor-packages +DESCRIPTOR_BUILD_DIR := $(shell pwd)/$(DESCRIPTOR_REPO_NAME)/build +OPTION_DESCRIPTOR_BUILD_DIR=--osm-descriptor-packages $(DESCRIPTOR_BUILD_DIR) + +TEST_OSM_NS_NAME_PREFIX=pytest-$(shell date +%D-%T)- +OPTION_TEST_OSM_NS_NAME_PREFIX=--osm-ns-name-prefix $(TEST_OSM_NS_NAME_PREFIX) + +JUNITXML_DIR = reports + +JUNITXML ?= pytest-output.xml + +PYTEST_OPTIONS= +Q=@ + +DESCRIPTOR_REPO ?= https://osm.etsi.org/gerrit/osm/$(DESCRIPTOR_REPO_NAME) + + +TEST_VNFD_DESCRIPTORS ?= None +TEST_NSD_DESCRIPTORS ?= None + +.NOTPARALLEL: +all: smoke cirros ping_pong + +define check_env_var + $(Q)if [ -z "$($(1))" ]; then echo "error: $(1) not set"; exit 1; fi +endef + +check_OSM_HOSTNAME: + $(call check_env_var,OSM_HOSTNAME) + +check_openstack_env: + $(call check_env_var,OS_URL) + $(call check_env_var,OS_USERNAME) + $(call check_env_var,OS_PASSWORD) + $(call check_env_var,OS_PROJECT_NAME) + +.PHONY: check_openstack_env check_OSM_HOSTNAME + +$(DESCRIPTOR_REPO_NAME): + @test -e $(DESCRIPTOR_REPO_NAME) || git clone $(DESCRIPTOR_REPO) + make -C $(DESCRIPTOR_REPO_NAME) + +report_dir: + @mkdir -p reports + +_run_test: $(DESCRIPTOR_REPO_NAME) report_dir + $(Q)py.test \ + --osmhost $(OSM_HOSTNAME) \ + $(OPTION_OS_URL) \ + $(OPTION_OS_USERNAME) \ + $(OPTION_OS_PASSWORD) \ + $(OPTION_OS_PROJECT_NAME) \ + $(OPTION_TEST_VNFD_DESCRIPTORS) \ + $(OPTION_TEST_NSD_DESCRIPTORS) \ + $(OPTION_DESCRIPTOR_BUILD_DIR) \ + $(OPTION_TEST_OSM_NS_NAME_PREFIX) \ + --junitxml $(JUNITXML_DIR)/$(JUNITXML) \ + $(PYTEST_OPTIONS) + +cirros: check_OSM_HOSTNAME check_openstack_env + $(Q)$(MAKE) \ + TEST_VNFD_DESCRIPTORS=$(DESCRIPTOR_BUILD_DIR)/vnfd_pkgs/cirros_vnf.tar.gz \ + TEST_NSD_DESCRIPTORS=$(DESCRIPTOR_BUILD_DIR)/nsd_pkgs/cirros_ns.tar.gz \ + JUNITXML=pytest-$@.xml \ + PYTEST_OPTIONS="$(PYTEST_OPTIONS) -m vnf" _run_test + +smoke: check_OSM_HOSTNAME + $(Q)$(MAKE) \ + JUNITXML=pytest-$@.xml \ + PYTEST_OPTIONS="$(PYTEST_OPTIONS) -m smoke" _run_test + +vim: check_OSM_HOSTNAME check_openstack_env + $(Q)$(MAKE) \ + JUNITXML=pytest-$@.xml \ + PYTEST_OPTIONS="$(PYTEST_OPTIONS) -m vim" _run_test + +ping_pong: check_OSM_HOSTNAME check_openstack_env + $(Q)$(MAKE) \ + TEST_VNFD_DESCRIPTORS="$(DESCRIPTOR_BUILD_DIR)/vnfd_pkgs/ping_vnf.tar.gz,$(DESCRIPTOR_BUILD_DIR)/vnfd_pkgs/pong_vnf.tar.gz" \ + TEST_NSD_DESCRIPTORS="$(DESCRIPTOR_BUILD_DIR)/nsd_pkgs/ping_pong_ns.tar.gz" \ + JUNITXML=pytest-$@.xml \ + PYTEST_OPTIONS="$(PYTEST_OPTIONS) -m vnf" _run_test + +.PHONY: report_dir cirros vim smoke ping_pong diff --git a/systest/conftest.py b/systest/conftest.py new file mode 100644 index 00000000..2032002d --- /dev/null +++ b/systest/conftest.py @@ -0,0 +1,24 @@ +# Copyright 2017 Sandvine +# +# All Rights Reserved. +# +# 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. + +from lib.osm.fixtures import osm_add_options +from lib.openstack.fixtures import openstack_add_options +from lib.vim.fixtures import vim_add_options + +def pytest_addoption(parser): + osm_add_options(parser) + openstack_add_options(parser) + vim_add_options(parser) diff --git a/systest/lib/__init__.py b/systest/lib/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/systest/lib/openstack/__init__.py b/systest/lib/openstack/__init__.py new file mode 100644 index 00000000..2bf7fedd --- /dev/null +++ b/systest/lib/openstack/__init__.py @@ -0,0 +1,15 @@ +# Copyright 2017 Sandvine +# +# All Rights Reserved. +# +# 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. diff --git a/systest/lib/openstack/fixtures.py b/systest/lib/openstack/fixtures.py new file mode 100644 index 00000000..7c1ec7f5 --- /dev/null +++ b/systest/lib/openstack/fixtures.py @@ -0,0 +1,38 @@ +# Copyright 2017 Sandvine +# +# All Rights Reserved. +# +# 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 pytest +import json + + +def openstack_add_options(parser): + parser.addoption("--os-url", default="", help="openstack identity url") + parser.addoption("--os-username", default="", help="openstack username") + parser.addoption("--os-password", default="", help="openstack password") + parser.addoption("--os-project-name", default="", help="openstack project name") + +@pytest.fixture +def openstack(request): + from lib.openstack import openstack + access = {} + access['os-url'] = request.config.getoption("--os-url") + access['os-username'] = request.config.getoption("--os-username") + access['os-password'] = request.config.getoption("--os-password") + access['os-project-name'] = request.config.getoption("--os-project-name") + access['vim-type'] = 'openstack' + access['description'] = 'pytest system test' + + return openstack.Openstack(access) diff --git a/systest/lib/openstack/openstack.py b/systest/lib/openstack/openstack.py new file mode 100644 index 00000000..9f5c3043 --- /dev/null +++ b/systest/lib/openstack/openstack.py @@ -0,0 +1,23 @@ +# Copyright 2017 Sandvine +# +# All Rights Reserved. +# +# 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. + + +class Openstack(): + def __init__(self,access): + self._os_access = access + + def get_access(self): + return self._os_access diff --git a/systest/lib/osm/__init__.py b/systest/lib/osm/__init__.py new file mode 100644 index 00000000..2bf7fedd --- /dev/null +++ b/systest/lib/osm/__init__.py @@ -0,0 +1,15 @@ +# Copyright 2017 Sandvine +# +# All Rights Reserved. +# +# 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. diff --git a/systest/lib/osm/fixtures.py b/systest/lib/osm/fixtures.py new file mode 100644 index 00000000..edfc0760 --- /dev/null +++ b/systest/lib/osm/fixtures.py @@ -0,0 +1,51 @@ +# Copyright 2017 Sandvine +# +# All Rights Reserved. +# +# 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 pytest +import json + + +def osm_add_options(parser): + parser.addoption("--osmhost", default="", help="osm hostname") + parser.addoption("--osm-descriptor-packages", default="", help="location of descriptor packages") + parser.addoption("--osm-vnfd-descriptor-packages", default="", help="vnfd packages to test") + parser.addoption("--osm-nsd-descriptor-packages", default="", help="nsd package to test") + parser.addoption("--osmfile", action="store", default="", help="osm json data file") + parser.addoption("--osm-ns-name-prefix", action="store", default="", help="ns name prefix to apply") + +''' +@pytest.fixture +def osm(request): + from osmclient.common import OsmAPI + with open(request.config.getoption("--osm")) as json_data: + osmdict=json.load(json_data) + return OsmAPI.OsmAPI(osmdict['ip']) + +''' + +@pytest.fixture +def osm(request): + from lib.osm import osm + osmhost=request.config.getoption("--osmhost") + descriptors_dir=request.config.getoption("--osm-descriptor-packages") + vnfd_descriptors_list=request.config.getoption("--osm-vnfd-descriptor-packages").split(',') + nsd_descriptors_list=request.config.getoption("--osm-nsd-descriptor-packages").split(',') + ns_name_prefix=request.config.getoption("--osm-ns-name-prefix") + return osm.Osm(osmhost, + descriptors_dir=descriptors_dir, + vnfd_descriptors_list=vnfd_descriptors_list, + nsd_descriptors_list=nsd_descriptors_list, + ns_name_prefix=ns_name_prefix) diff --git a/systest/lib/osm/osm.py b/systest/lib/osm/osm.py new file mode 100644 index 00000000..8798be89 --- /dev/null +++ b/systest/lib/osm/osm.py @@ -0,0 +1,32 @@ +# Copyright 2017 Sandvine +# +# All Rights Reserved. +# +# 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. + + +from osmclient.client import client + +class Osm(): + def __init__(self,osmhost,descriptors_dir=None,vnfd_descriptors_list=None,nsd_descriptors_list=None,ns_name_prefix=None): + self._OsmApi=client.Client(host=osmhost) + self._descriptors_dir = descriptors_dir + self.vnfd_descriptors_list = vnfd_descriptors_list + self.nsd_descriptors_list = nsd_descriptors_list + self.ns_name_prefix = ns_name_prefix + + def get_api(self): + return self._OsmApi + + def get_descriptors_dir(self): + return self._descriptors_dir diff --git a/systest/lib/vim/__init__.py b/systest/lib/vim/__init__.py new file mode 100644 index 00000000..2bf7fedd --- /dev/null +++ b/systest/lib/vim/__init__.py @@ -0,0 +1,15 @@ +# Copyright 2017 Sandvine +# +# All Rights Reserved. +# +# 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. diff --git a/systest/lib/vim/fixtures.py b/systest/lib/vim/fixtures.py new file mode 100644 index 00000000..e552bbc8 --- /dev/null +++ b/systest/lib/vim/fixtures.py @@ -0,0 +1,27 @@ +# Copyright 2017 Sandvine +# +# All Rights Reserved. +# +# 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 pytest +import json + + +def vim_add_options(parser): + pass + +@pytest.fixture +def vim(request,osm,openstack): + from lib.vim import vim + return vim.Vim(osm,openstack) diff --git a/systest/lib/vim/vim.py b/systest/lib/vim/vim.py new file mode 100644 index 00000000..98bda387 --- /dev/null +++ b/systest/lib/vim/vim.py @@ -0,0 +1,26 @@ +# Copyright 2017 Sandvine +# +# All Rights Reserved. +# +# 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. + +from osmclient.common.exceptions import ClientException + + +class Vim(): + def __init__(self,osm,openstack): + self.vim_name='pytest' + try: + osm.get_api().vim.get(self.vim_name) + except ClientException: + osm.get_api().vim.create(self.vim_name,openstack.get_access()) diff --git a/systest/testcases/conftest.py b/systest/testcases/conftest.py new file mode 100644 index 00000000..9f8be17c --- /dev/null +++ b/systest/testcases/conftest.py @@ -0,0 +1,19 @@ +# Copyright 2017 Sandvine +# +# All Rights Reserved. +# +# 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. + +from lib.osm.fixtures import osm +from lib.openstack.fixtures import openstack +from lib.vim.fixtures import vim diff --git a/systest/testcases/smoke/test_smoke.py b/systest/testcases/smoke/test_smoke.py new file mode 100644 index 00000000..e915e23f --- /dev/null +++ b/systest/testcases/smoke/test_smoke.py @@ -0,0 +1,35 @@ +# Copyright 2017 Sandvine +# +# All Rights Reserved. +# +# 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 pytest +import pprint +import time + + +@pytest.mark.smoke +class TestClass(object): + + def test_empty_vnf(self,osm): + assert not osm.get_api().vnf.list() + + def test_empty_vnf_catalog(self,osm): + assert not osm.get_api().vnfd.list() + + def test_empty_ns(self,osm): + assert not osm.get_api().ns.list() + + def test_empty_ns_catalog(self,osm): + assert not osm.get_api().nsd.list() diff --git a/systest/testcases/vim/test_vim.py b/systest/testcases/vim/test_vim.py new file mode 100644 index 00000000..5ea7077e --- /dev/null +++ b/systest/testcases/vim/test_vim.py @@ -0,0 +1,50 @@ +# Copyright 2017 Sandvine +# +# All Rights Reserved. +# +# 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 pytest +import time + + +@pytest.mark.vim +@pytest.mark.openstack +class TestClass(object): + + def test_empty_vim(self,osm): + assert not osm.get_api().vim.list() + + @pytest.fixture(scope='function') + def cleanup_test_add_vim_account(self,osm,request): + def teardown(): + try: + osm.get_api().vim.delete('pytest') + except: + pass + request.addfinalizer(teardown) + + @pytest.mark.openstack + def test_add_vim_account(self,osm,openstack,cleanup_test_add_vim_account): + os_access=openstack.get_access() + assert not osm.get_api().vim.create('pytest',os_access) + + resp=osm.get_api().vim.get('pytest') + assert resp['name'] == 'pytest' + assert resp['type'] == 'openstack' + assert resp['vim_url'] == os_access['os-url'] + assert resp['vim_url_admin'] == os_access['os-url'] + assert resp['vim_tenants'][0]['user'] == os_access['os-username'] + assert resp['vim_tenants'][0]['vim_tenant_name'] == os_access['os-project-name'] + + assert not osm.get_api().vim.delete('pytest') diff --git a/systest/testcases/vnfs/test_vnfs.py b/systest/testcases/vnfs/test_vnfs.py new file mode 100644 index 00000000..618f3e30 --- /dev/null +++ b/systest/testcases/vnfs/test_vnfs.py @@ -0,0 +1,106 @@ +# Copyright 2017 Sandvine +# +# All Rights Reserved. +# +# 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 pytest +import pprint +import time +from osmclient.common import utils + + +class TestClass(object): + + @pytest.fixture(scope='function') + def cleanup_test_vnf(self,osm,request): + vnfd_file_list = osm.vnfd_descriptors_list + nsd_file_list = osm.nsd_descriptors_list + + # cleanup all ns/packages that might have been left around + def teardown(): + + # first delete all nsd's + for file in nsd_file_list: + try: + desc = osm.get_api().package.get_descriptor_type_from_pkg(file) + ns_name=osm.ns_name_prefix+nsd_desc['name'] + osm.get_api().ns.delete(ns_name) + except: + pass + + # delete all nsd packages + for file in nsd_file_list: + try: + desc = osm.get_api().package.get_descriptor_type_from_pkg(file) + osm.get_api().nsd.delete(desc['name']) + except: + pass + + # delete all vnfd packages + for file in vnfd_file_list: + try: + desc = osm.get_api().package.get_descriptor_type_from_pkg(file) + osm.get_api().vnfd.delete(desc['name']) + except: + pass + + request.addfinalizer(teardown) + + def vnf_test(self,osm, openstack, vim, vnfd_file_list, nsd_file_list): + vnfd_descriptors=[] + for file in vnfd_file_list: + assert not osm.get_api().package.upload(file) + assert not osm.get_api().package.wait_for_upload(file) + desc = osm.get_api().package.get_descriptor_type_from_pkg(file) + assert desc + vnfd_descriptors.append(desc) + + nsd_descriptors=[] + for file in nsd_file_list: + assert not osm.get_api().package.upload(file) + assert not osm.get_api().package.wait_for_upload(file) + desc = osm.get_api().package.get_descriptor_type_from_pkg(file) + assert desc + nsd_descriptors.append(desc) + + # TODO/HACK: need to figure out why this is necessary. + # vnfd/nsd is there (seen on ping_pong), but the ns fails that nsd is not there, + # another way to check if the nsd is really ready via API? + time.sleep(10) + + for nsd_desc in nsd_descriptors: + ns_name=osm.ns_name_prefix+nsd_desc['name'] + + assert not osm.get_api().ns.create(nsd_desc['name'],ns_name,vim.vim_name) + + assert utils.wait_for_value(lambda: osm.get_api().ns.get_field(ns_name,'operational-status'),result='init') + + # make sure ns is running + assert utils.wait_for_value(lambda: osm.get_api().ns.get_field(ns_name,'operational-status'),result='running',wait_time=120) + + assert not osm.get_api().ns.delete(ns_name) + + assert not osm.get_api().nsd.delete(nsd_desc['name']) + + for vnfd_desc in vnfd_descriptors: + + assert not osm.get_api().vnfd.delete(vnfd_desc['name']) + + @pytest.mark.openstack + @pytest.mark.vnf + def test_vnf(self,osm, vim, openstack, cleanup_test_vnf): + vnfd_file_list = osm.vnfd_descriptors_list + nsd_file_list = osm.nsd_descriptors_list + + self.vnf_test(osm,openstack, vim, vnfd_file_list, nsd_file_list) -- 2.25.1