X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=test%2Ftest_RO.py;h=932853c5037411cb7879dbe78074a3f535545366;hb=0aa0e2fcec7f5c7dcd6d56e2a38f72db327cee50;hp=21af36cdb08dee9cc9fa7716f629696e9d171753;hpb=114050ebb5d734d4e45ee2584a7a48081791dc8e;p=osm%2FRO.git diff --git a/test/test_RO.py b/test/test_RO.py index 21af36cd..932853c5 100755 --- a/test/test_RO.py +++ b/test/test_RO.py @@ -20,33 +20,32 @@ # ## -''' +""" Module for testing openmano functionality. It uses openmanoclient.py for invoking openmano -''' -__author__ = "Pablo Montes, Alfonso Tierno" -__date__ = "$16-Feb-2017 17:08:16$" -__version__ = "0.0.4" -version_date = "Jun 2017" +""" import logging import os -from argparse import ArgumentParser import argcomplete import unittest import string import inspect import random -import traceback +# import traceback import glob import yaml import sys import time -from pyvcloud.vcloudair import VCA import uuid -import json +from argparse import ArgumentParser + +__author__ = "Pablo Montes, Alfonso Tierno" +__date__ = "$16-Feb-2017 17:08:16$" +__version__ = "0.1.0" +version_date = "Oct 2017" + +test_config = {} # used for global variables with the test configuration -global test_config # used for global variables with the test configuration -test_config = {} class test_base(unittest.TestCase): test_index = 1 @@ -150,7 +149,7 @@ class test_VIM_datacenter_operations(test_base): self.datacenter = test_config["client"].attach_datacenter(name=self.__class__.datacenter_name, vim_tenant_name='fake') logger.debug("{}".format(self.datacenter)) - assert ('vim_tenants' in self.datacenter.get('datacenter', {})) + assert ('uuid' in self.datacenter.get('datacenter', {})) def test_030_list_attached_datacenter(self): self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"], self.__class__.test_index, @@ -279,25 +278,8 @@ class test_VIM_tenant_operations(test_base): logger.debug("{}".format(tenant)) assert ('deleted' in tenant.get('result', "")) -class test_vimconn_connect(test_base): - # test_index = 1 - # test_text = None - - # @classmethod - # def setUpClass(cls): - # logger.info("{}. {}".format(test_config["test_number"], cls.__name__)) - # @classmethod - # def tearDownClass(cls): - # test_config["test_number"] += 1 - - # def tearDown(self): - # exec_info = sys.exc_info() - # if exec_info == (None, None, None): - # logger.info(self.__class__.test_text+" -> TEST OK") - # else: - # logger.warning(self.__class__.test_text+" -> TEST NOK") - # logger.critical("Traceback error",exc_info=True) +class test_vimconn_connect(test_base): def test_000_connect(self): self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"], @@ -308,29 +290,15 @@ class test_vimconn_connect(test_base): if test_config['vimtype'] == 'vmware': vca_object = test_config["vim_conn"].connect() logger.debug("{}".format(vca_object)) - self.assertIsInstance(vca_object, VCA) - + self.assertIsNotNone(vca_object) + elif test_config['vimtype'] == 'openstack': + test_config["vim_conn"]._reload_connection() + network_list = test_config["vim_conn"].get_network_list() + logger.debug("{}".format(network_list)) + self.assertIsNotNone(network_list) class test_vimconn_new_network(test_base): - # test_index = 1 network_name = None - # test_text = None - - # @classmethod - # def setUpClass(cls): - # logger.info("{}. {}".format(test_config["test_number"], cls.__name__)) - - # @classmethod - # def tearDownClass(cls): - # test_config["test_number"] += 1 - - # def tearDown(self): - # exec_info = sys.exc_info() - # if exec_info == (None, None, None): - # logger.info(self.__class__.test_text+" -> TEST OK") - # else: - # logger.warning(self.__class__.test_text+" -> TEST NOK") - # logger.critical("Traceback error",exc_info=True) def test_000_new_network(self): self.__class__.network_name = _get_random_string(20) @@ -340,12 +308,12 @@ class test_vimconn_new_network(test_base): self.__class__.test_index, inspect.currentframe().f_code.co_name) self.__class__.test_index += 1 - network = test_config["vim_conn"].new_network(net_name=self.__class__.network_name, + network, _ = test_config["vim_conn"].new_network(net_name=self.__class__.network_name, net_type=network_type) self.__class__.network_id = network logger.debug("{}".format(network)) - network_list = test_config["vim_conn"].get_vcd_network_list() + network_list = test_config["vim_conn"].get_network_list() for net in network_list: if self.__class__.network_name in net.get('name'): self.assertIn(self.__class__.network_name, net.get('name')) @@ -367,13 +335,13 @@ class test_vimconn_new_network(test_base): self.__class__.test_index += 1 for net_type in network_types: self.__class__.network_name = _get_random_string(20) - network_id = test_config["vim_conn"].new_network(net_name=self.__class__.network_name, + network_id, _ = test_config["vim_conn"].new_network(net_name=self.__class__.network_name, net_type=net_type) delete_net_ids.append(network_id) logger.debug("{}".format(network_id)) - network_list = test_config["vim_conn"].get_vcd_network_list() + network_list = test_config["vim_conn"].get_network_list() for net in network_list: if self.__class__.network_name in net.get('name'): self.assertIn(self.__class__.network_name, net.get('name')) @@ -409,23 +377,28 @@ class test_vimconn_new_network(test_base): version = item['ip-profile']['ip-version'] dhcp_count = item['ip-profile']['dhcp']['count'] dhcp_enabled = item['ip-profile']['dhcp']['enabled'] + dhcp_start_address = item['ip-profile']['dhcp']['start-address'] + subnet_address = item['ip-profile']['subnet-address'] + self.__class__.network_name = _get_random_string(20) ip_profile = {'dhcp_count': dhcp_count, 'dhcp_enabled': dhcp_enabled, - 'ip_version': version + 'dhcp_start_address': dhcp_start_address, + 'ip_version': version, + 'subnet_address': subnet_address } self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"], self.__class__.test_index, inspect.currentframe().f_code.co_name) self.__class__.test_index += 1 - network = test_config["vim_conn"].new_network(net_name=self.__class__.network_name, + network, _ = test_config["vim_conn"].new_network(net_name=self.__class__.network_name, net_type='mgmt', ip_profile=ip_profile) self.__class__.network_id = network logger.debug("{}".format(network)) - network_list = test_config["vim_conn"].get_vcd_network_list() + network_list = test_config["vim_conn"].get_network_list() for net in network_list: if self.__class__.network_name in net.get('name'): self.assertIn(self.__class__.network_name, net.get('name')) @@ -444,13 +417,13 @@ class test_vimconn_new_network(test_base): self.__class__.test_index, inspect.currentframe().f_code.co_name) self.__class__.test_index += 1 - network = test_config["vim_conn"].new_network(net_name=self.__class__.network_name, + network, _ = test_config["vim_conn"].new_network(net_name=self.__class__.network_name, net_type='bridge', shared=shared) self.__class__.network_id = network logger.debug("{}".format(network)) - network_list = test_config["vim_conn"].get_vcd_network_list() + network_list = test_config["vim_conn"].get_network_list() for net in network_list: if self.__class__.network_name in net.get('name'): self.assertIn(self.__class__.network_name, net.get('name')) @@ -469,11 +442,11 @@ class test_vimconn_new_network(test_base): self.__class__.test_index, inspect.currentframe().f_code.co_name) self.__class__.test_index += 1 - network = test_config["vim_conn"].new_network(net_name=self.__class__.network_name, + network, _ = test_config["vim_conn"].new_network(net_name=self.__class__.network_name, net_type='unknowntype') self.__class__.network_id = network logger.debug("{}".format(network)) - network_list = test_config["vim_conn"].get_vcd_network_list() + network_list = test_config["vim_conn"].get_network_list() for net in network_list: if self.__class__.network_name in net.get('name'): self.assertIn(self.__class__.network_name, net.get('name')) @@ -493,7 +466,7 @@ class test_vimconn_new_network(test_base): # creating new network network_name = _get_random_string(20) net_type = 'bridge' - network_id = test_config["vim_conn"].new_network(net_name=network_name, + network_id, _ = test_config["vim_conn"].new_network(net_name=network_name, net_type=net_type) # refresh net status net_dict = test_config["vim_conn"].refresh_nets_status([network_id]) @@ -517,38 +490,26 @@ class test_vimconn_new_network(test_base): # refresh net status net_dict = test_config["vim_conn"].refresh_nets_status([unknown_net_id]) - self.assertEqual(net_dict, {}) + if test_config['vimtype'] == 'openstack': + self.assertEqual(net_dict[unknown_net_id]['status'], 'DELETED') + else: + # TODO : Fix vmware connector to return status DELETED as per vimconn.py + self.assertEqual(net_dict, {}) class test_vimconn_get_network_list(test_base): - # test_index = 1 network_name = None - # test_text = None - # @classmethod - # def setUpClass(cls): - # logger.info("{}. {}".format(test_config["test_number"], cls.__name__)) - - # @classmethod - # def tearDownClass(cls): - # test_config["test_number"] += 1 - def setUp(self): # creating new network self.__class__.network_name = _get_random_string(20) self.__class__.net_type = 'bridge' - network = test_config["vim_conn"].new_network(net_name=self.__class__.network_name, + network, _ = test_config["vim_conn"].new_network(net_name=self.__class__.network_name, net_type=self.__class__.net_type) self.__class__.network_id = network logger.debug("{}".format(network)) def tearDown(self): test_base.tearDown(self) - # exec_info = sys.exc_info() - # if exec_info == (None, None, None): - # logger.info(self.__class__.test_text+" -> TEST OK") - # else: - # logger.warning(self.__class__.test_text+" -> TEST NOK") - # logger.critical("Traceback error",exc_info=True) # Deleting created network result = test_config["vim_conn"].delete_network(self.__class__.network_id) @@ -577,7 +538,10 @@ class test_vimconn_get_network_list(test_base): inspect.currentframe().f_code.co_name) self.__class__.test_index += 1 - network_name = test_config['vim_conn'].get_network_name_by_id(self.__class__.network_id) + if test_config['vimtype'] == 'openstack': + network_name = test_config['vim_conn'].get_network(self.__class__.network_id)['name'] + else: + network_name = test_config['vim_conn'].get_network_name_by_id(self.__class__.network_id) # find network from list by it's name new_network_list = test_config["vim_conn"].get_network_list({'name': network_name}) @@ -608,7 +572,10 @@ class test_vimconn_get_network_list(test_base): inspect.currentframe().f_code.co_name) self.__class__.test_index += 1 - network_name = test_config['vim_conn'].get_network_name_by_id(self.__class__.network_id) + if test_config['vimtype'] == 'openstack': + network_name = test_config['vim_conn'].get_network(self.__class__.network_id)['name'] + else: + network_name = test_config['vim_conn'].get_network_name_by_id(self.__class__.network_id) # find network from list by it's shared value new_network_list = test_config["vim_conn"].get_network_list({'shared':Shared, 'name':network_name}) @@ -625,7 +592,10 @@ class test_vimconn_get_network_list(test_base): self.__class__.test_index += 1 tenant_list = test_config["vim_conn"].get_tenant_list() - network_name = test_config['vim_conn'].get_network_name_by_id(self.__class__.network_id) + if test_config['vimtype'] == 'openstack': + network_name = test_config['vim_conn'].get_network(self.__class__.network_id)['name'] + else: + network_name = test_config['vim_conn'].get_network_name_by_id(self.__class__.network_id) for tenant_item in tenant_list: if test_config['tenant'] == tenant_item.get('name'): @@ -646,7 +616,10 @@ class test_vimconn_get_network_list(test_base): self.__class__.test_index += 1 status = 'ACTIVE' - network_name = test_config['vim_conn'].get_network_name_by_id(self.__class__.network_id) + if test_config['vimtype'] == 'openstack': + network_name = test_config['vim_conn'].get_network(self.__class__.network_id)['name'] + else: + network_name = test_config['vim_conn'].get_network_name_by_id(self.__class__.network_id) # find network from list by it's status new_network_list = test_config["vim_conn"].get_network_list({'status':status, @@ -666,35 +639,19 @@ class test_vimconn_get_network_list(test_base): self.assertEqual(network_list, []) class test_vimconn_get_network(test_base): - # test_index = 1 network_name = None - # test_text = None - - # @classmethod - # def setUpClass(cls): - # logger.info("{}. {}".format(test_config["test_number"], cls.__name__)) - - # @classmethod - # def tearDownClass(cls): - # test_config["test_number"] += 1 def setUp(self): # creating new network self.__class__.network_name = _get_random_string(20) self.__class__.net_type = 'bridge' - network = test_config["vim_conn"].new_network(net_name=self.__class__.network_name, + network, _ = test_config["vim_conn"].new_network(net_name=self.__class__.network_name, net_type=self.__class__.net_type) self.__class__.network_id = network logger.debug("{}".format(network)) def tearDown(self): test_base.tearDown(self) - # exec_info = sys.exc_info() - # if exec_info == (None, None, None): - # logger.info(self.__class__.test_text+" -> TEST OK") - # else: - # logger.warning(self.__class__.test_text+" -> TEST NOK") - # logger.critical("Traceback error",exc_info=True) # Deleting created network result = test_config["vim_conn"].delete_network(self.__class__.network_id) @@ -721,36 +678,19 @@ class test_vimconn_get_network(test_base): self.__class__.test_index, inspect.currentframe().f_code.co_name) self.__class__.test_index += 1 + with self.assertRaises(Exception) as context: + test_config["vim_conn"].get_network(Non_exist_id) - network_info = test_config["vim_conn"].get_network(Non_exist_id) - self.assertEqual(network_info, {}) + self.assertEqual((context.exception).http_code, 404) class test_vimconn_delete_network(test_base): - # test_index = 1 network_name = None - # test_text = None - - # @classmethod - # def setUpClass(cls): - # logger.info("{}. {}".format(test_config["test_number"], cls.__name__)) - - # @classmethod - # def tearDownClass(cls): - # test_config["test_number"] += 1 - - # def tearDown(self): - # exec_info = sys.exc_info() - # if exec_info == (None, None, None): - # logger.info(self.__class__.test_text+" -> TEST OK") - # else: - # logger.warning(self.__class__.test_text+" -> TEST NOK") - # logger.critical("Traceback error",exc_info=True) def test_000_delete_network(self): # Creating network self.__class__.network_name = _get_random_string(20) self.__class__.net_type = 'bridge' - network = test_config["vim_conn"].new_network(net_name=self.__class__.network_name, + network, _ = test_config["vim_conn"].new_network(net_name=self.__class__.network_name, net_type=self.__class__.net_type) self.__class__.network_id = network logger.debug("{}".format(network)) @@ -781,27 +721,9 @@ class test_vimconn_delete_network(test_base): with self.assertRaises(Exception) as context: test_config["vim_conn"].delete_network(Non_exist_id) - self.assertEqual((context.exception).http_code, 400) + self.assertEqual((context.exception).http_code, 404) class test_vimconn_get_flavor(test_base): - # test_index = 1 - # test_text = None - - # @classmethod - # def setUpClass(cls): - # logger.info("{}. {}".format(test_config["test_number"], cls.__name__)) - - # @classmethod - # def tearDownClass(cls): - # test_config["test_number"] += 1 - - # def tearDown(self): - # exec_info = sys.exc_info() - # if exec_info == (None, None, None): - # logger.info(self.__class__.test_text+" -> TEST OK") - # else: - # logger.warning(self.__class__.test_text+" -> TEST NOK") - # logger.critical("Traceback error",exc_info=True) def test_000_get_flavor(self): test_directory_content = os.listdir(test_config["test_directory"]) @@ -823,10 +745,12 @@ class test_vimconn_get_flavor(test_base): vcpus = item['vcpus'] disk = item['disk'] - flavor_data = {'ram': ram, + flavor_data = { + 'name' : _get_random_string(20), + 'ram': ram, 'vcpus': vcpus, 'disk': disk - } + } self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"], self.__class__.test_index, @@ -864,7 +788,7 @@ class test_vimconn_new_flavor(test_base): flavor_id = None def test_000_new_flavor(self): - flavor_data = {'ram': 1024, 'vpcus': 1, 'disk': 10} + flavor_data = {'name': _get_random_string(20), 'ram': 1024, 'vpcus': 1, 'disk': 10} self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"], self.__class__.test_index, @@ -873,8 +797,8 @@ class test_vimconn_new_flavor(test_base): # create new flavor self.__class__.flavor_id = test_config["vim_conn"].new_flavor(flavor_data) - self.assertEqual(type(self.__class__.flavor_id),str) - self.assertIsInstance(uuid.UUID(self.__class__.flavor_id),uuid.UUID) + self.assertIsInstance(self.__class__.flavor_id, (str, unicode)) + self.assertIsInstance(uuid.UUID(self.__class__.flavor_id), uuid.UUID) def test_010_delete_flavor(self): self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"], @@ -916,62 +840,87 @@ class test_vimconn_new_flavor(test_base): self.assertEqual((context.exception).http_code, 404) -class test_vimconn_new_image(test_base): - - def test_000_new_image(self): - self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"], - self.__class__.test_index, - inspect.currentframe().f_code.co_name) - self.__class__.test_index += 1 - - image_path = test_config['image_path'] - if image_path: - image_id = test_config["vim_conn"].new_image({ 'name': 'TestImage', 'location' : image_path }) - self.assertEqual(type(image_id),str) - self.assertIsInstance(uuid.UUID(image_id),uuid.UUID) - else: - self.skipTest("Skipping test as image file not present at RO container") - - def test_010_new_image_negative(self): - Non_exist_image_path = '/temp1/cirros.ovf' - - self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"], - self.__class__.test_index, - inspect.currentframe().f_code.co_name) - self.__class__.test_index += 1 - - with self.assertRaises(Exception) as context: - test_config["vim_conn"].new_image({ 'name': 'TestImage', 'location' : Non_exist_image_path }) - - self.assertEqual((context.exception).http_code, 400) - -class test_vimconn_get_image_id_from_path(test_base): - - def test_000_get_image_id_from_path(self): - self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"], - self.__class__.test_index, - inspect.currentframe().f_code.co_name) - self.__class__.test_index += 1 - - image_path = test_config['image_path'] - if image_path: - image_id = test_config["vim_conn"].get_image_id_from_path( image_path ) - self.assertEqual(type(image_id),str) - else: - self.skipTest("Skipping test as image file not present at RO container") - - def test_010_get_image_id_from_path_negative(self): - Non_exist_image_path = '/temp1/cirros.ovf' - - self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"], - self.__class__.test_index, - inspect.currentframe().f_code.co_name) - self.__class__.test_index += 1 - - with self.assertRaises(Exception) as context: - test_config["vim_conn"].new_image({ 'name': 'TestImage', 'location' : Non_exist_image_path }) +# class test_vimconn_new_image(test_base): +# +# def test_000_new_image(self): +# self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"], +# self.__class__.test_index, +# inspect.currentframe().f_code.co_name) +# self.__class__.test_index += 1 +# +# image_path = test_config['image_path'] +# if image_path: +# self.__class__.image_id = test_config["vim_conn"].new_image({ 'name': 'TestImage', 'location' : image_path, 'metadata': {'upload_location':None} }) +# time.sleep(20) +# +# self.assertIsInstance(self.__class__.image_id, (str, unicode)) +# self.assertIsInstance(uuid.UUID(self.__class__.image_id), uuid.UUID) +# else: +# self.skipTest("Skipping test as image file not present at RO container") +# +# def test_010_new_image_negative(self): +# Non_exist_image_path = '/temp1/cirros.ovf' +# +# self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"], +# self.__class__.test_index, +# inspect.currentframe().f_code.co_name) +# self.__class__.test_index += 1 +# +# with self.assertRaises(Exception) as context: +# test_config["vim_conn"].new_image({ 'name': 'TestImage', 'location' : Non_exist_image_path}) +# +# self.assertEqual((context.exception).http_code, 400) +# +# def test_020_delete_image(self): +# self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"], +# self.__class__.test_index, +# inspect.currentframe().f_code.co_name) +# self.__class__.test_index += 1 +# +# image_id = test_config["vim_conn"].delete_image(self.__class__.image_id) +# +# self.assertIsInstance(image_id, (str, unicode)) +# +# def test_030_delete_image_negative(self): +# Non_exist_image_id = str(uuid.uuid4()) +# +# self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"], +# self.__class__.test_index, +# inspect.currentframe().f_code.co_name) +# self.__class__.test_index += 1 +# +# with self.assertRaises(Exception) as context: +# test_config["vim_conn"].delete_image(Non_exist_image_id) +# +# self.assertEqual((context.exception).http_code, 404) - self.assertEqual((context.exception).http_code, 400) +# class test_vimconn_get_image_id_from_path(test_base): +# +# def test_000_get_image_id_from_path(self): +# self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"], +# self.__class__.test_index, +# inspect.currentframe().f_code.co_name) +# self.__class__.test_index += 1 +# +# image_path = test_config['image_path'] +# if image_path: +# image_id = test_config["vim_conn"].get_image_id_from_path( image_path ) +# self.assertEqual(type(image_id),str) +# else: +# self.skipTest("Skipping test as image file not present at RO container") +# +# def test_010_get_image_id_from_path_negative(self): +# Non_exist_image_path = '/temp1/cirros.ovf' +# +# self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"], +# self.__class__.test_index, +# inspect.currentframe().f_code.co_name) +# self.__class__.test_index += 1 +# +# with self.assertRaises(Exception) as context: +# test_config["vim_conn"].new_image({ 'name': 'TestImage', 'location' : Non_exist_image_path }) +# +# self.assertEqual((context.exception).http_code, 400) class test_vimconn_get_image_list(test_base): image_name = None @@ -988,8 +937,8 @@ class test_vimconn_get_image_list(test_base): if 'name' in item: self.__class__.image_name = item['name'] self.__class__.image_id = item['id'] - self.assertEqual(type(self.__class__.image_name),str) - self.assertEqual(type(self.__class__.image_id),str) + self.assertIsInstance(self.__class__.image_name, (str, unicode)) + self.assertIsInstance(self.__class__.image_id, (str, unicode)) def test_010_get_image_list_by_name(self): self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"], @@ -1000,9 +949,9 @@ class test_vimconn_get_image_list(test_base): image_list = test_config["vim_conn"].get_image_list({'name': self.__class__.image_name}) for item in image_list: - self.assertEqual(type(item['id']), str) + self.assertIsInstance(item['id'], (str, unicode)) + self.assertIsInstance(item['name'], (str, unicode)) self.assertEqual(item['id'], self.__class__.image_id) - self.assertEqual(type(item['name']), str) self.assertEqual(item['name'], self.__class__.image_name) def test_020_get_image_list_by_id(self): @@ -1014,10 +963,10 @@ class test_vimconn_get_image_list(test_base): filter_image_list = test_config["vim_conn"].get_image_list({'id': self.__class__.image_id}) for item1 in filter_image_list: - self.assertEqual(type(item1.get('id')), str) - self.assertEqual(item1.get('id'), self.__class__.image_id) - self.assertEqual(type(item1.get('name')), str) - self.assertEqual(item1.get('name'), self.__class__.image_name) + self.assertIsInstance(item1['id'], (str, unicode)) + self.assertIsInstance(item1['name'], (str, unicode)) + self.assertEqual(item1['id'], self.__class__.image_id) + self.assertEqual(item1['name'], self.__class__.image_name) def test_030_get_image_list_negative(self): Non_exist_image_id = uuid.uuid4() @@ -1042,8 +991,21 @@ class test_vimconn_new_vminstance(test_base): self.__class__.network_name = _get_random_string(20) self.__class__.net_type = 'bridge' - self.__class__.network_id = test_config["vim_conn"].new_network(net_name=self.__class__.network_name, + self.__class__.network_id, _ = test_config["vim_conn"].new_network(net_name=self.__class__.network_name, net_type=self.__class__.net_type) + # find image name and image id + if test_config['image_name']: + image_list = test_config['vim_conn'].get_image_list({'name': test_config['image_name']}) + if len(image_list) == 0: + raise Exception("Image {} is not found at VIM".format(test_config['image_name'])) + else: + self.__class__.image_id = image_list[0]['id'] + else: + image_list = test_config['vim_conn'].get_image_list() + if len(image_list) == 0: + raise Exception("Not found any image at VIM") + else: + self.__class__.image_id = image_list[0]['id'] def tearDown(self): test_base.tearDown(self) @@ -1058,24 +1020,11 @@ class test_vimconn_new_vminstance(test_base): vpci = "0000:00:11.0" name = "eth0" - flavor_data = {'ram': 1024, 'vcpus': 1, 'disk': 10} + flavor_data = {'name': _get_random_string(20), 'ram': 1024, 'vcpus': 1, 'disk': 10} # create new flavor flavor_id = test_config["vim_conn"].new_flavor(flavor_data) - # find image name and image id - if test_config['image_name']: - image_list = test_config['vim_conn'].get_image_list({'name': test_config['image_name']}) - if len(image_list) == 0: - raise Exception("Image {} is not found at VIM".format(test_config['image_name'])) - else: - self.__class__.image_id = image_list[0]['id'] - else: - image_list = test_config['vim_conn'].get_image_list() - if len(image_list) == 0: - raise Exception("Not found any image at VIM") - else: - self.__class__.image_id = image_list[0]['id'] self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"], self.__class__.test_index, @@ -1084,12 +1033,12 @@ class test_vimconn_new_vminstance(test_base): net_list = [{'use': self.__class__.net_type, 'name': name, 'floating_ip': False, 'vpci': vpci, 'port_security': True, 'type': 'virtual', 'net_id': self.__class__.network_id}] - self.__class__.instance_id = test_config["vim_conn"].new_vminstance(name='Test1_vm', image_id=self.__class__.image_id, flavor_id=flavor_id, net_list=net_list) + self.__class__.instance_id, _ = test_config["vim_conn"].new_vminstance(name='Test1_vm', description='', start=False, image_id=self.__class__.image_id, flavor_id=flavor_id, net_list=net_list) - self.assertEqual(type(self.__class__.instance_id),str) + self.assertIsInstance(self.__class__.instance_id, (str, unicode)) def test_010_new_vminstance_by_model(self): - flavor_data = {'ram': 1024, 'vcpus': 2, 'disk': 10} + flavor_data = {'name': _get_random_string(20),'ram': 1024, 'vcpus': 2, 'disk': 10} model_name = 'e1000' name = 'eth0' @@ -1103,17 +1052,17 @@ class test_vimconn_new_vminstance(test_base): net_list = [{'use': self.__class__.net_type, 'name': name, 'floating_ip': False, 'port_security': True, 'model': model_name, 'type': 'virtual', 'net_id': self.__class__.network_id}] - instance_id = test_config["vim_conn"].new_vminstance(name='Test1_vm', image_id=self.__class__.image_id, - flavor_id=flavor_id, - net_list=net_list) - self.assertEqual(type(instance_id),str) + instance_id, _ = test_config["vim_conn"].new_vminstance(name='Test1_vm', description='', start=False, image_id=self.__class__.image_id,flavor_id=flavor_id,net_list=net_list) + + self.assertIsInstance(instance_id, (str, unicode)) + # Deleting created vm instance logger.info("Deleting created vm intance") test_config["vim_conn"].delete_vminstance(instance_id) time.sleep(10) def test_020_new_vminstance_by_net_use(self): - flavor_data = {'ram': 1024, 'vcpus': 2, 'disk': 10} + flavor_data = {'name': _get_random_string(20),'ram': 1024, 'vcpus': 2, 'disk': 10} net_use = 'data' name = 'eth0' @@ -1127,17 +1076,18 @@ class test_vimconn_new_vminstance(test_base): net_list = [{'use': net_use, 'name': name, 'floating_ip': False, 'port_security': True, 'type': 'virtual', 'net_id': self.__class__.network_id}] - instance_id = test_config["vim_conn"].new_vminstance(name='Test1_vm', image_id=self.__class__.image_id, + instance_id, _ = test_config["vim_conn"].new_vminstance(name='Test1_vm', description='', start=False, image_id=self.__class__.image_id,disk_list=None, flavor_id=flavor_id, net_list=net_list) - self.assertEqual(type(instance_id),str) + self.assertIsInstance(instance_id, (str, unicode)) + # Deleting created vm instance logger.info("Deleting created vm intance") test_config["vim_conn"].delete_vminstance(instance_id) time.sleep(10) def test_030_new_vminstance_by_net_type(self): - flavor_data = {'ram': 1024, 'vcpus': 2, 'disk': 10} + flavor_data = {'name':_get_random_string(20),'ram': 1024, 'vcpus': 2, 'disk': 10} _type = 'VF' name = 'eth0' @@ -1149,19 +1099,46 @@ class test_vimconn_new_vminstance(test_base): inspect.currentframe().f_code.co_name) self.__class__.test_index += 1 - net_list = [{'use': self.__class__.net_type, 'name': name, 'floating_ip': False, 'port_security': True, 'type': _type, 'net_id': self.__class__.network_id}] + if test_config['vimtype'] == 'vmware': + net_list = [{'use': self.__class__.net_type, 'name': name, 'floating_ip': False, 'port_security': True, + 'type': _type, 'net_id': self.__class__.network_id}] + + instance_id, _ = test_config["vim_conn"].new_vminstance(name='Test1_vm', image_id=self.__class__.image_id, + flavor_id=flavor_id, + net_list=net_list) + self.assertEqual(type(instance_id),str) + + if test_config['vimtype'] == 'openstack': + # create network of type data + network_name = _get_random_string(20) + net_type = 'data' + + network_id, _ = test_config["vim_conn"].new_network(net_name=network_name, + net_type=net_type) + net_list = [{'use': net_type, 'name': name, 'floating_ip': False, 'port_security': True, + 'type': _type, 'net_id': network_id}] + + instance_id, _ = test_config["vim_conn"].new_vminstance(name='Test1_vm', description='', start=False, + image_id=self.__class__.image_id, disk_list=None, + flavor_id=flavor_id, + net_list=net_list) + + self.assertEqual(type(instance_id), unicode) + + # delete created network + result = test_config["vim_conn"].delete_network(network_id) + if result: + logger.info("Network id {} sucessfully deleted".format(network_id)) + else: + logger.info("Failed to delete network id {}".format(network_id)) - instance_id = test_config["vim_conn"].new_vminstance(name='Test1_vm', image_id=self.__class__.image_id, - flavor_id=flavor_id, - net_list=net_list) - self.assertEqual(type(instance_id),str) # Deleting created vm instance logger.info("Deleting created vm intance") test_config["vim_conn"].delete_vminstance(instance_id) time.sleep(10) def test_040_new_vminstance_by_cloud_config(self): - flavor_data = {'ram': 1024, 'vcpus': 2, 'disk': 10} + flavor_data = {'name': _get_random_string(20),'ram': 1024, 'vcpus': 2, 'disk': 10} name = 'eth0' user_name = 'test_user' @@ -1181,21 +1158,21 @@ class test_vimconn_new_vminstance(test_base): net_list = [{'use': self.__class__.net_type, 'name': name, 'floating_ip': False, 'port_security': True, 'type': 'virtual', 'net_id': self.__class__.network_id}] - instance_id = test_config["vim_conn"].new_vminstance(name='Cloud_vm', image_id=self.__class__.image_id, - flavor_id=flavor_id, - net_list=net_list, - cloud_config=cloud_data) - self.assertEqual(type(instance_id),str) + instance_id, _ = test_config["vim_conn"].new_vminstance(name='Cloud_vm', description='', start=False, + image_id=self.__class__.image_id, flavor_id=flavor_id,net_list=net_list,cloud_config=cloud_data) + + self.assertIsInstance(instance_id, (str, unicode)) + # Deleting created vm instance logger.info("Deleting created vm intance") test_config["vim_conn"].delete_vminstance(instance_id) time.sleep(10) def test_050_new_vminstance_by_disk_list(self): - flavor_data = {'ram': 1024, 'vcpus': 2, 'disk': 10} + flavor_data = {'name':_get_random_string(20),'ram': 1024, 'vcpus': 2, 'disk': 10} name = 'eth0' - device_data = [{'image_id': self.__class__.image_id, 'size': '5'}] + device_data = [{'image_id': self.__class__.image_id, 'size': '10'}] # create new flavor flavor_id = test_config["vim_conn"].new_flavor(flavor_data) @@ -1207,11 +1184,12 @@ class test_vimconn_new_vminstance(test_base): net_list = [{'use': self.__class__.net_type, 'name': name, 'floating_ip': False, 'port_security': True, 'type': 'virtual', 'net_id': self.__class__.network_id}] - instance_id = test_config["vim_conn"].new_vminstance(name='VM_test1', image_id=self.__class__.image_id, + instance_id, _ = test_config["vim_conn"].new_vminstance(name='VM_test1', description='', start=False, image_id=self.__class__.image_id, flavor_id=flavor_id, net_list=net_list, disk_list=device_data) - self.assertEqual(type(instance_id),str) + + self.assertIsInstance(instance_id, (str, unicode)) # Deleting created vm instance logger.info("Deleting created vm intance") test_config["vim_conn"].delete_vminstance(instance_id) @@ -1230,10 +1208,12 @@ class test_vimconn_new_vminstance(test_base): net_list = [{'use': self.__class__.net_type, 'name': name, 'floating_ip': False, 'port_security': True, 'type': 'virtual', 'net_id': self.__class__.network_id}] with self.assertRaises(Exception) as context: - test_config["vim_conn"].new_vminstance(name='Test1_vm', image_id=unknown_image_id, + test_config["vim_conn"].new_vminstance(name='Test1_vm', description='', start=False, image_id=unknown_image_id, flavor_id=unknown_flavor_id, net_list=net_list) - self.assertEqual((context.exception).http_code, 404) + + self.assertIn((context.exception).http_code, (400, 404)) + def test_070_get_vminstance(self): self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"], @@ -1274,16 +1254,49 @@ class test_vimconn_new_vminstance(test_base): self.__class__.test_index, inspect.currentframe().f_code.co_name) self.__class__.test_index += 1 - vm_list = [] - vm_list.append(self.__class__.instance_id) - # refresh vm status - vm_info = test_config["vim_conn"].refresh_vms_status(vm_list) - for attr in vm_info[self.__class__.instance_id]: - if attr == 'status': - self.assertEqual(vm_info[self.__class__.instance_id][attr], 'ACTIVE') - if attr == 'interfaces': - self.assertEqual(type(vm_info[self.__class__.instance_id][attr]), list) + if test_config['vimtype'] == 'vmware': + vm_list = [] + vm_list.append(self.__class__.instance_id) + + # refresh vm status + vm_info = test_config["vim_conn"].refresh_vms_status(vm_list) + for attr in vm_info[self.__class__.instance_id]: + if attr == 'status': + self.assertEqual(vm_info[self.__class__.instance_id][attr], 'ACTIVE') + if attr == 'interfaces': + self.assertEqual(type(vm_info[self.__class__.instance_id][attr]), list) + + if test_config['vimtype'] == 'openstack': + vpci = "0000:00:11.0" + name = "eth0" + + flavor_data = {'name': _get_random_string(20), 'ram': 1024, 'vcpus': 1, 'disk': 10} + + # create new flavor + flavor_id = test_config["vim_conn"].new_flavor(flavor_data) + # create new vm instance + net_list = [{'use': self.__class__.net_type, 'name': name, 'floating_ip': False, 'vpci': vpci, 'port_security': True, 'type': 'virtual', 'net_id': self.__class__.network_id}] + + instance_id, _ = test_config["vim_conn"].new_vminstance(name='Test1_vm', description='', start=False, image_id=self.__class__.image_id, flavor_id=flavor_id, net_list=net_list) + + time.sleep(30) + vm_list = [] + vm_list.append(instance_id) + + # refresh vm status + vm_info = test_config["vim_conn"].refresh_vms_status(vm_list) + for attr in vm_info[instance_id]: + if attr == 'status': + self.assertEqual(vm_info[instance_id][attr], 'ACTIVE') + if attr == 'interfaces': + self.assertEqual(type(vm_info[instance_id][attr]), list) + + #Deleting created vm instance + logger.info("Deleting created vm intance") + test_config["vim_conn"].delete_vminstance(instance_id) + time.sleep(10) + def test_100_refresh_vms_status_negative(self): unknown_id = str(uuid.uuid4()) @@ -1294,7 +1307,12 @@ class test_vimconn_new_vminstance(test_base): self.__class__.test_index += 1 vm_dict = test_config["vim_conn"].refresh_vms_status([unknown_id]) - self.assertEqual(vm_dict, {}) + + if test_config['vimtype'] == 'vmware': + self.assertEqual(vm_dict,{}) + + if test_config['vimtype'] == 'openstack': + self.assertEqual(vm_dict[unknown_id]['status'], 'DELETED') def test_110_action_vminstance(self): self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"], @@ -1302,12 +1320,43 @@ class test_vimconn_new_vminstance(test_base): inspect.currentframe().f_code.co_name) self.__class__.test_index += 1 - action_list = ['shutdown','start','shutoff','rebuild','pause','resume'] - # various action on vminstace - for action in action_list: - instance_id = test_config["vim_conn"].action_vminstance(self.__class__.instance_id, - { action: None}) - self.assertEqual(instance_id, self.__class__.instance_id) + if test_config['vimtype'] == 'vmware': + action_list = ['shutdown', 'start', 'shutoff', 'rebuild', 'pause', 'resume'] + # various action on vminstace + for action in action_list: + instance_id = test_config["vim_conn"].action_vminstance(self.__class__.instance_id, + {action: None}) + self.assertEqual(instance_id, self.__class__.instance_id) + + if test_config['vimtype'] == 'openstack': + # create new vm instance + vpci = "0000:00:11.0" + name = "eth0" + + flavor_data = {'name': _get_random_string(20), 'ram': 1024, 'vcpus': 1, 'disk': 10} + + # create new flavor + flavor_id = test_config["vim_conn"].new_flavor(flavor_data) + + net_list = [{'use': self.__class__.net_type, 'name': name, 'floating_ip': False, 'vpci': vpci, 'port_security': True, 'type': 'virtual', 'net_id': self.__class__.network_id}] + + new_instance_id, _ = test_config["vim_conn"].new_vminstance(name='Test1_vm', description='', start=False, image_id=self.__class__.image_id, flavor_id=flavor_id, net_list=net_list) + + action_list = ['shutdown','start','shutoff','rebuild','start','pause','start'] + + # various action on vminstace + for action in action_list: + # sleep for sometime till status is changed + time.sleep(25) + instance_id = test_config["vim_conn"].action_vminstance(new_instance_id, + { action: None}) + + self.assertTrue(instance_id is None) + + # Deleting created vm instance + logger.info("Deleting created vm intance") + test_config["vim_conn"].delete_vminstance(new_instance_id) + time.sleep(10) def test_120_action_vminstance_negative(self): non_exist_id = str(uuid.uuid4()) @@ -1320,7 +1369,8 @@ class test_vimconn_new_vminstance(test_base): with self.assertRaises(Exception) as context: test_config["vim_conn"].action_vminstance(non_exist_id, { action: None}) - self.assertEqual((context.exception).http_code, 400) + self.assertEqual((context.exception).http_code, 404) + def test_130_delete_vminstance(self): self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"], @@ -1333,109 +1383,700 @@ class test_vimconn_new_vminstance(test_base): test_config["vim_conn"].delete_vminstance(self.__class__.instance_id) time.sleep(10) -''' -IMPORTANT NOTE -The following unittest class does not have the 'test_' on purpose. This test is the one used for the -scenario based tests. -''' -class descriptor_based_scenario_test(test_base): - test_index = 0 - scenario_test_path = None - scenario_uuid = None - instance_scenario_uuid = None - to_delete_list = [] - - @classmethod - def setUpClass(cls): - cls.test_index = 1 - cls.to_delete_list = [] - cls.scenario_test_path = test_config["test_directory"] + '/' + test_config["test_folder"] - logger.info("{}. {} {}".format(test_config["test_number"], cls.__name__, test_config["test_folder"])) + def test_140_new_vminstance_sriov(self): + logger.info("Testing creation of sriov vm instance using {}".format(test_config['sriov_net_name'])) + flavor_data = {'name': _get_random_string(20),'ram': 1024, 'vcpus': 2, 'disk': 10} + name = 'eth0' - @classmethod - def tearDownClass(cls): - test_config["test_number"] += 1 + # create new flavor + flavor_id = test_config["vim_conn"].new_flavor(flavor_data) - def test_000_load_scenario(self): - self.__class__.test_text = "{}.{}. TEST {} {}".format(test_config["test_number"], self.__class__.test_index, - inspect.currentframe().f_code.co_name, - test_config["test_folder"]) + self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"], + self.__class__.test_index, + inspect.currentframe().f_code.co_name) self.__class__.test_index += 1 - vnfd_files = glob.glob(self.__class__.scenario_test_path+'/vnfd_*.yaml') - scenario_file = glob.glob(self.__class__.scenario_test_path + '/scenario_*.yaml') - if len(vnfd_files) == 0 or len(scenario_file) > 1: - raise Exception("Test '{}' not valid. It must contain an scenario file and at least one vnfd file'".format( - test_config["test_folder"])) - #load all vnfd - for vnfd in vnfd_files: - with open(vnfd, 'r') as stream: - vnf_descriptor = yaml.load(stream) + sriov_net_name = test_config['sriov_net_name'] + new_network_list = test_config["vim_conn"].get_network_list({'name': sriov_net_name}) + for list_item in new_network_list: + self.assertEqual(sriov_net_name, list_item.get('name')) + self.__class__.sriov_network_id = list_item.get('id') - vnfc_list = vnf_descriptor['vnf']['VNFC'] - for vnfc in vnfc_list: - vnfc['image name'] = test_config["image_name"] - devices = vnfc.get('devices',[]) - for device in devices: - if device['type'] == 'disk' and 'image name' in device: - device['image name'] = test_config["image_name"] + net_list = [{'use': 'data', 'name': name, 'floating_ip': False, 'port_security': True, 'type': 'VF', 'net_id': self.__class__.sriov_network_id}] - logger.debug("VNF descriptor: {}".format(vnf_descriptor)) - vnf = test_config["client"].create_vnf(descriptor=vnf_descriptor) - logger.debug(vnf) - self.__class__.to_delete_list.insert(0, {"item": "vnf", "function": test_config["client"].delete_vnf, - "params": {"uuid": vnf['vnf']['uuid']}}) - - #load the scenario definition - with open(scenario_file[0], 'r') as stream: - scenario_descriptor = yaml.load(stream) - networks = scenario_descriptor['scenario']['networks'] - networks[test_config["mgmt_net"]] = networks.pop('mgmt') - logger.debug("Scenario descriptor: {}".format(scenario_descriptor)) - scenario = test_config["client"].create_scenario(descriptor=scenario_descriptor) - logger.debug(scenario) - self.__class__.to_delete_list.insert(0,{"item": "scenario", "function": test_config["client"].delete_scenario, - "params":{"uuid": scenario['scenario']['uuid']} }) - self.__class__.scenario_uuid = scenario['scenario']['uuid'] + instance_id, _ = test_config["vim_conn"].new_vminstance(name='Test1_sriov_vm', description='', start=False, image_id=self.__class__.image_id, flavor_id=flavor_id, net_list=net_list) - def test_010_instantiate_scenario(self): - self.__class__.test_text = "{}.{}. TEST {} {}".format(test_config["test_number"], self.__class__.test_index, - inspect.currentframe().f_code.co_name, - test_config["test_folder"]) + self.assertIsInstance(instance_id, (str, unicode)) + + logger.info("Waiting for created sriov-vm intance") + time.sleep(10) + # Deleting created vm instance + logger.info("Deleting created sriov-vm intance") + test_config["vim_conn"].delete_vminstance(instance_id) + time.sleep(10) + +class test_vimconn_get_tenant_list(test_base): + tenant_id = None + + def test_000_get_tenant_list(self): + self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"], + self.__class__.test_index, + inspect.currentframe().f_code.co_name) self.__class__.test_index += 1 - instance = test_config["client"].create_instance(scenario_id=self.__class__.scenario_uuid, - name=self.__class__.test_text) - self.__class__.instance_scenario_uuid = instance['uuid'] - logger.debug(instance) - self.__class__.to_delete_list.insert(0, {"item": "instance", "function": test_config["client"].delete_instance, - "params": {"uuid": instance['uuid']}}) + # Getting tenant list + tenant_list = test_config["vim_conn"].get_tenant_list() - def test_020_check_deployent(self): - self.__class__.test_text = "{}.{}. TEST {} {}".format(test_config["test_number"], self.__class__.test_index, - inspect.currentframe().f_code.co_name, - test_config["test_folder"]) + for item in tenant_list: + if test_config['tenant'] == item['name']: + self.__class__.tenant_id = item['id'] + self.assertIsInstance(item['name'], (str, unicode)) + self.assertIsInstance(item['id'], (str, unicode)) + + def test_010_get_tenant_list_by_id(self): + self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"], + self.__class__.test_index, + inspect.currentframe().f_code.co_name) self.__class__.test_index += 1 - if test_config["manual"]: - raw_input('Scenario has been deployed. Perform manual check and press any key to resume') - return + # Getting filter tenant list by its id + filter_tenant_list = test_config["vim_conn"].get_tenant_list({'id': self.__class__.tenant_id}) - keep_waiting = test_config["timeout"] - instance_active = False - while True: - result = check_instance_scenario_active(self.__class__.instance_scenario_uuid) - if result[0]: - break - elif 'ERROR' in result[1]: - msg = 'Got error while waiting for the instance to get active: '+result[1] - logging.error(msg) - raise Exception(msg) + for item in filter_tenant_list: + self.assertIsInstance(item['id'], (str, unicode)) + self.assertEqual(item['id'], self.__class__.tenant_id) - if keep_waiting >= 5: - time.sleep(5) - keep_waiting -= 5 - elif keep_waiting > 0: + def test_020_get_tenant_list_by_name(self): + self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"], + self.__class__.test_index, + inspect.currentframe().f_code.co_name) + self.__class__.test_index += 1 + + # Getting filter tenant list by its name + filter_tenant_list = test_config["vim_conn"].get_tenant_list({'name': test_config['tenant']}) + + for item in filter_tenant_list: + self.assertIsInstance(item['name'], (str, unicode)) + self.assertEqual(item['name'], test_config['tenant']) + + def test_030_get_tenant_list_by_name_and_id(self): + self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"], + self.__class__.test_index, + inspect.currentframe().f_code.co_name) + self.__class__.test_index += 1 + + # Getting filter tenant list by its name and id + filter_tenant_list = test_config["vim_conn"].get_tenant_list({'name': test_config['tenant'], + 'id': self.__class__.tenant_id}) + + for item in filter_tenant_list: + self.assertIsInstance(item['name'], (str, unicode)) + self.assertIsInstance(item['id'], (str, unicode)) + self.assertEqual(item['name'], test_config['tenant']) + self.assertEqual(item['id'], self.__class__.tenant_id) + + def test_040_get_tenant_list_negative(self): + non_exist_tenant_name = "Tenant_123" + non_exist_tenant_id = "kjhgrt456-45345kjhdfgnbdk-34dsfjdfg" + self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"], + self.__class__.test_index, + inspect.currentframe().f_code.co_name) + self.__class__.test_index += 1 + + filter_tenant_list = test_config["vim_conn"].get_tenant_list({'name': non_exist_tenant_name, + 'id': non_exist_tenant_id}) + + self.assertEqual(filter_tenant_list, []) + + +class test_vimconn_new_tenant(test_base): + tenant_id = None + + def test_000_new_tenant(self): + tenant_name = _get_random_string(20) + self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"], + self.__class__.test_index, + inspect.currentframe().f_code.co_name) + self.__class__.test_index += 1 + + self.__class__.tenant_id = test_config["vim_conn"].new_tenant(tenant_name, "") + time.sleep(15) + + self.assertIsInstance(self.__class__.tenant_id, (str, unicode)) + + + def test_010_new_tenant_negative(self): + Invalid_tenant_name = 10121 + self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"], + self.__class__.test_index, + inspect.currentframe().f_code.co_name) + self.__class__.test_index += 1 + + with self.assertRaises(Exception) as context: + test_config["vim_conn"].new_tenant(Invalid_tenant_name, "") + + self.assertEqual((context.exception).http_code, 400) + + + def test_020_delete_tenant(self): + self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"], + self.__class__.test_index, + inspect.currentframe().f_code.co_name) + self.__class__.test_index += 1 + + tenant_id = test_config["vim_conn"].delete_tenant(self.__class__.tenant_id) + + self.assertIsInstance(tenant_id, (str, unicode)) + + def test_030_delete_tenant_negative(self): + Non_exist_tenant_name = 'Test_30_tenant' + self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"], + self.__class__.test_index, + inspect.currentframe().f_code.co_name) + self.__class__.test_index += 1 + + with self.assertRaises(Exception) as context: + test_config["vim_conn"].delete_tenant(Non_exist_tenant_name) + + self.assertEqual((context.exception).http_code, 404) + + +def get_image_id(): + if test_config['image_name']: + image_list = test_config['vim_conn'].get_image_list({'name': test_config['image_name']}) + if len(image_list) == 0: + raise Exception("Image {} is not found at VIM".format(test_config['image_name'])) + else: + image_id = image_list[0]['id'] + else: + image_list = test_config['vim_conn'].get_image_list() + if len(image_list) == 0: + raise Exception("Not found any image at VIM") + else: + image_id = image_list[0]['id'] + return image_id + + +class test_vimconn_vminstance_by_ip_address(test_base): + network_name = None + network_id = None + + def setUp(self): + # create network + self.network_name = _get_random_string(20) + + self.network_id, _ = test_config["vim_conn"].new_network(net_name=self.network_name, + net_type='bridge') + + def tearDown(self): + test_base.tearDown(self) + # Deleting created network + result = test_config["vim_conn"].delete_network(self.network_id) + if result: + logger.info("Network id {} sucessfully deleted".format(self.network_id)) + else: + logger.info("Failed to delete network id {}".format(self.network_id)) + + + def test_000_vminstance_by_ip_address(self): + """ + This test case will deploy VM with provided IP address + Pre-requesite: provided IP address should be from IP pool range which has used for network creation + """ + name = "eth0" + # provide ip address + ip_address = '' + + flavor_data = {'ram': 1024, 'vcpus': 1, 'disk': 10} + + # create new flavor + flavor_id = test_config["vim_conn"].new_flavor(flavor_data) + + # find image id + image_id = get_image_id() + + self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"], + self.__class__.test_index, + inspect.currentframe().f_code.co_name) + self.__class__.test_index += 1 + + net_list = [{'use': 'bridge', 'name': name, 'floating_ip': False, 'port_security': True, 'type': 'virtual', + 'net_id': self.network_id, 'ip_address': ip_address}] + + instance_id, _ = test_config["vim_conn"].new_vminstance(name='Test1_vm', image_id=image_id, + flavor_id=flavor_id, net_list=net_list) + + self.assertEqual(type(instance_id),str) + logger.info("Deleting created vm instance") + test_config["vim_conn"].delete_vminstance(instance_id) + time.sleep(10) + + def test_010_vminstance_by_ip_address_negative(self): + name = "eth1" + # IP address not from subnet range + invalid_ip_address = '10.10.12.1' + + flavor_data = {'ram': 1024, 'vcpus': 1, 'disk': 10} + + # create new flavor + flavor_id = test_config["vim_conn"].new_flavor(flavor_data) + + # find image name and image id + image_id = get_image_id() + + self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"], + self.__class__.test_index, + inspect.currentframe().f_code.co_name) + self.__class__.test_index += 1 + + net_list = [{'use': 'bridge', 'name': name, 'floating_ip': False, 'port_security': True, 'type': 'virtual', + 'net_id': self.network_id, 'ip_address': invalid_ip_address}] + + with self.assertRaises(Exception) as context: + test_config["vim_conn"].new_vminstance(name='Test1_vm', image_id=image_id, + flavor_id=flavor_id, + net_list=net_list) + self.assertEqual((context.exception).http_code, 400) + + def test_020_vminstance_by_floating_ip(self): + name = "eth1" + flavor_data = {'ram': 1024, 'vcpus': 1, 'disk': 10} + + # create new flavor + flavor_id = test_config["vim_conn"].new_flavor(flavor_data) + + # find image name and image id + image_id = get_image_id() + + self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"], + self.__class__.test_index, + inspect.currentframe().f_code.co_name) + self.__class__.test_index += 1 + + net_list = [{'use': 'bridge', 'name': name, 'floating_ip': True, 'port_security': True, 'type': 'virtual', + 'net_id': self.network_id}] + + instance_id, _ = test_config["vim_conn"].new_vminstance(name='Test1_vm', image_id=image_id, + flavor_id=flavor_id, net_list=net_list) + + self.assertEqual(type(instance_id),str) + logger.info("Deleting created vm instance") + test_config["vim_conn"].delete_vminstance(instance_id) + time.sleep(10) + + def test_030_vminstance_by_mac_address(self): + name = "eth1" + mac_address = "74:54:2f:21:da:8c" + flavor_data = {'ram': 1024, 'vcpus': 1, 'disk': 10} + + # create new flavor + flavor_id = test_config["vim_conn"].new_flavor(flavor_data) + + # find image name and image id + image_id = get_image_id() + + self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"], + self.__class__.test_index, + inspect.currentframe().f_code.co_name) + self.__class__.test_index += 1 + + net_list = [{'use': 'bridge', 'name': name, 'floating_ip': False, 'port_security': True, 'type': 'virtual', + 'net_id': self.network_id,'mac_address': mac_address}] + + instance_id, _ = test_config["vim_conn"].new_vminstance(name='Test1_vm', image_id=image_id, + flavor_id=flavor_id, net_list=net_list) + + self.assertEqual(type(instance_id),str) + logger.info("Deleting created vm instance") + test_config["vim_conn"].delete_vminstance(instance_id) + time.sleep(10) + +class test_vimconn_vminstance_by_adding_10_nics(test_base): + network_name = None + net_ids = [] + + def setUp(self): + # create network + i = 0 + for i in range(10): + self.network_name = _get_random_string(20) + network_id, _ = test_config["vim_conn"].new_network(net_name=self.network_name, + net_type='bridge') + self.net_ids.append(network_id) + + def tearDown(self): + test_base.tearDown(self) + # Deleting created network + for net_id in self.net_ids: + result = test_config["vim_conn"].delete_network(net_id) + if result: + logger.info("Network id {} sucessfully deleted".format(net_id)) + else: + logger.info("Failed to delete network id {}".format(net_id)) + + def test_000_vminstance_by_adding_10_nics(self): + flavor_data = {'ram': 1024, 'vcpus': 1, 'disk': 10} + + # create new flavor + flavor_id = test_config["vim_conn"].new_flavor(flavor_data) + + # find image name and image id + image_id = get_image_id() + + self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"], + self.__class__.test_index, + inspect.currentframe().f_code.co_name) + self.__class__.test_index += 1 + + net_list = [] + c = 1 + for net_id in self.net_ids: + name = "eth{}".format(c) + net_list.append({'use': 'bridge', 'name': name, 'floating_ip': False, + 'port_security': True, 'type': 'virtual', 'net_id': net_id}) + c = c+1 + + instance_id, _ = test_config["vim_conn"].new_vminstance(name='Test1_vm', image_id=image_id, + flavor_id=flavor_id, net_list=net_list) + + self.assertEqual(type(instance_id),str) + logger.info("Deleting created vm instance") + test_config["vim_conn"].delete_vminstance(instance_id) + time.sleep(10) + + +class test_vimconn_vminstance_by_existing_disk(test_base): + network_name = None + network_id = None + + def setUp(self): + # create network + self.network_name = _get_random_string(20) + self.network_id, _ = test_config["vim_conn"].new_network(net_name=self.network_name, + net_type='bridge') + + def tearDown(self): + test_base.tearDown(self) + # Deleting created network + result = test_config["vim_conn"].delete_network(self.network_id) + if result: + logger.info("Network id {} sucessfully deleted".format(self.network_id)) + else: + logger.info("Failed to delete network id {}".format(self.network_id)) + + + def test_000_vminstance_by_existing_disk(self): + """ This testcase will add existing disk only if given catalog/image is free + means not used by any other VM + """ + + flavor_data = {'ram': 1024, 'vcpus': 1, 'disk': 10} + name = "eth10" + + # create new flavor + flavor_id = test_config["vim_conn"].new_flavor(flavor_data) + + # find image name and image id + image_id = get_image_id() + cirros_image = test_config["vim_conn"].get_image_list({'name': 'cirros'}) + disk_list = [{'image_id': cirros_image[0]['id'],'size': 5}] + + self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"], + self.__class__.test_index, + inspect.currentframe().f_code.co_name) + self.__class__.test_index += 1 + + net_list = [{'use': 'bridge', 'name': name, 'floating_ip': False, 'port_security': True, + 'type': 'virtual', 'net_id': self.network_id}] + + instance_id, _ = test_config["vim_conn"].new_vminstance(name='Test1_vm', image_id=image_id, + flavor_id=flavor_id, net_list=net_list,disk_list=disk_list) + + self.assertEqual(type(instance_id),str) + logger.info("Deleting created vm instance") + test_config["vim_conn"].delete_vminstance(instance_id) + time.sleep(10) + + def test_010_vminstance_by_new_disk(self): + flavor_data = {'ram': 1024, 'vcpus': 1, 'disk': 10} + name = "eth10" + + # create new flavor + flavor_id = test_config["vim_conn"].new_flavor(flavor_data) + + # find image name and image id + image_id = get_image_id() + disk_list = [{'size': '5'}] + + self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"], + self.__class__.test_index, + inspect.currentframe().f_code.co_name) + self.__class__.test_index += 1 + + net_list = [{'use': 'bridge', 'name': name, 'floating_ip': False, 'port_security': True, + 'type': 'virtual', 'net_id': self.network_id}] + + instance_id, _ = test_config["vim_conn"].new_vminstance(name='Test1_vm', image_id=image_id, + flavor_id=flavor_id, net_list=net_list,disk_list=disk_list) + + self.assertEqual(type(instance_id),str) + logger.info("Deleting created vm instance") + test_config["vim_conn"].delete_vminstance(instance_id) + time.sleep(10) + + def test_020_vminstance_by_CDROM(self): + """ This testcase will insert media file only if provided catalog + has pre-created ISO media file into vCD + """ + flavor_data ={'ram': 1024, 'vcpus': 1, 'disk': 10} + name = "eth10" + image_list = test_config["vim_conn"].get_image_list({'name':'Ubuntu'}) + disk_list = [{'image_id':image_list[0]['id'],'device_type':'cdrom'}] + + # create new flavor + flavor_id = test_config["vim_conn"].new_flavor(flavor_data) + + # find image name and image id + image_id = get_image_id() + + self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"], + self.__class__.test_index, + inspect.currentframe().f_code.co_name) + self.__class__.test_index += 1 + + net_list = [{'use': 'bridge', 'name': name, 'floating_ip': False, 'port_security': True, + 'type': 'virtual', 'net_id': self.network_id}] + + instance_id, _ = test_config["vim_conn"].new_vminstance(name='Test1_vm', image_id=image_id, + flavor_id=flavor_id, net_list=net_list,disk_list=disk_list ) + + self.assertEqual(type(instance_id),str) + logger.info("Deleting created vm instance") + test_config["vim_conn"].delete_vminstance(instance_id) + time.sleep(10) + + +class test_vimconn_vminstance_by_affinity_anti_affinity(test_base): + network_name = None + network_id = None + + def setUp(self): + # create network + self.network_name = _get_random_string(20) + self.network_id, _ = test_config["vim_conn"].new_network(net_name=self.network_name, + net_type='bridge') + + def tearDown(self): + test_base.tearDown(self) + # Deleting created network + result = test_config["vim_conn"].delete_network(self.network_id) + if result: + logger.info("Network id {} sucessfully deleted".format(self.network_id)) + else: + logger.info("Failed to delete network id {}".format(self.network_id)) + + def test_000_vminstance_by_affinity_anti_affinity(self): + """ This testcase will deploy VM into provided HOSTGROUP in VIM config + Pre-requisites: User has created Hosh Groups in vCenter with respective Hosts to be used + While creating VIM account user has to pass the Host Group names in availability_zone list + """ + flavor_data = {'ram': 1024, 'vcpus': 1, 'disk': 10} + name = "eth10" + + # create new flavor + flavor_id = test_config["vim_conn"].new_flavor(flavor_data) + + # find image name and image id + image_id = get_image_id() + + self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"], + self.__class__.test_index, + inspect.currentframe().f_code.co_name) + self.__class__.test_index += 1 + + net_list = [{'use': 'bridge', 'name': name, 'floating_ip': False, 'port_security': True, + 'type': 'virtual', 'net_id': self.network_id}] + + instance_id, _ = test_config["vim_conn"].new_vminstance(name='Test1_vm', image_id=image_id, + flavor_id=flavor_id, net_list=net_list,availability_zone_index=1, + availability_zone_list=['HG_174','HG_175']) + + self.assertEqual(type(instance_id),str) + time.sleep(10) + logger.info("Deleting created vm instance") + test_config["vim_conn"].delete_vminstance(instance_id) + +class test_vimconn_vminstance_by_numa_affinity(test_base): + network_name = None + network_id = None + + def setUp(self): + # create network + self.network_name = _get_random_string(20) + self.network_id, _ = test_config["vim_conn"].new_network(net_name=self.network_name, + net_type='bridge') + + def tearDown(self): + test_base.tearDown(self) + # Deleting created network + result = test_config["vim_conn"].delete_network(self.network_id) + if result: + logger.info("Network id {} sucessfully deleted".format(self.network_id)) + else: + logger.info("Failed to delete network id {}".format(self.network_id)) + + def test_000_vminstance_by_numa_affinity(self): + flavor_data = {'extended': {'numas': [{'paired-threads-id': [['1', '3'], ['2', '4']], + ' paired-threads': 2, 'memory': 1}]}, + 'ram': 1024, 'vcpus': 1, 'disk': 10} + name = "eth10" + + # create new flavor + flavor_id = test_config["vim_conn"].new_flavor(flavor_data) + + # find image name and image id + image_id = get_image_id() + + self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"], + self.__class__.test_index, + inspect.currentframe().f_code.co_name) + self.__class__.test_index += 1 + + net_list = [{'use': 'bridge', 'name': name, 'floating_ip': False, 'port_security': True, + 'type': 'virtual', 'net_id': self.network_id}] + + instance_id, _ = test_config["vim_conn"].new_vminstance(name='Test1_vm', image_id=image_id, + flavor_id=flavor_id, net_list=net_list) + + self.assertEqual(type(instance_id),str) + logger.info("Deleting created vm instance") + test_config["vim_conn"].delete_vminstance(instance_id) + time.sleep(10) + + +''' +IMPORTANT NOTE +The following unittest class does not have the 'test_' on purpose. This test is the one used for the +scenario based tests. +''' +class descriptor_based_scenario_test(test_base): + test_index = 0 + scenario_test_path = None + + @classmethod + def setUpClass(cls): + cls.test_index = 1 + cls.to_delete_list = [] + cls.scenario_uuids = [] + cls.instance_scenario_uuids = [] + cls.scenario_test_path = test_config["test_directory"] + '/' + test_config["test_folder"] + logger.info("{}. {} {}".format(test_config["test_number"], cls.__name__, test_config["test_folder"])) + + @classmethod + def tearDownClass(cls): + test_config["test_number"] += 1 + + def test_000_load_scenario(self): + self.__class__.test_text = "{}.{}. TEST {} {}".format(test_config["test_number"], self.__class__.test_index, + inspect.currentframe().f_code.co_name, + test_config["test_folder"]) + self.__class__.test_index += 1 + # load VNFD and NSD + descriptor_files = glob.glob(self.__class__.scenario_test_path+'/*.yaml') + vnf_descriptors = [] + scenario_descriptors = [] + for descriptor_file in descriptor_files: + with open(descriptor_file, 'r') as stream: + descriptor = yaml.load(stream) + if "vnf" in descriptor or "vnfd:vnfd-catalog" in descriptor or "vnfd-catalog" in descriptor: + vnf_descriptors.append(descriptor) + else: + scenario_descriptors.append(descriptor) + + scenario_file = glob.glob(self.__class__.scenario_test_path + '/scenario_*.yaml') + if not vnf_descriptors or not scenario_descriptors or len(scenario_descriptors) > 1: + raise Exception("Test '{}' not valid. It must contain an scenario file and at least one vnfd file'".format( + test_config["test_folder"])) + + # load all vnfd + for vnf_descriptor in vnf_descriptors: + logger.debug("VNF descriptor: {}".format(vnf_descriptor)) + vnf = test_config["client"].create_vnf(descriptor=vnf_descriptor, image_name=test_config["image_name"]) + logger.debug(vnf) + if 'vnf' in vnf: + vnf_uuid = vnf['vnf']['uuid'] + else: + vnf_uuid = vnf['vnfd'][0]['uuid'] + self.__class__.to_delete_list.insert(0, {"item": "vnf", "function": test_config["client"].delete_vnf, + "params": {"uuid": vnf_uuid}}) + + # load the scenario definition + for scenario_descriptor in scenario_descriptors: + # networks = scenario_descriptor['scenario']['networks'] + # networks[test_config["mgmt_net"]] = networks.pop('mgmt') + logger.debug("Scenario descriptor: {}".format(scenario_descriptor)) + scenario = test_config["client"].create_scenario(descriptor=scenario_descriptor) + logger.debug(scenario) + if 'scenario' in scenario: + scenario_uuid = scenario['scenario']['uuid'] + else: + scenario_uuid = scenario['nsd'][0]['uuid'] + self.__class__.to_delete_list.insert(0, {"item": "scenario", + "function": test_config["client"].delete_scenario, + "params": {"uuid": scenario_uuid}}) + self.__class__.scenario_uuids.append(scenario_uuid) + + def test_010_instantiate_scenario(self): + self.__class__.test_text = "{}.{}. TEST {} {}".format(test_config["test_number"], self.__class__.test_index, + inspect.currentframe().f_code.co_name, + test_config["test_folder"]) + self.__class__.test_index += 1 + for scenario_uuid in self.__class__.scenario_uuids: + instance_descriptor = { + "instance":{ + "name": self.__class__.test_text, + "scenario": scenario_uuid, + "networks":{ + "mgmt": {"sites": [ { "netmap-use": test_config["mgmt_net"]} ]} + } + } + } + instance = test_config["client"].create_instance(instance_descriptor) + self.__class__.instance_scenario_uuids.append(instance['uuid']) + logger.debug(instance) + self.__class__.to_delete_list.insert(0, {"item": "instance", + "function": test_config["client"].delete_instance, + "params": {"uuid": instance['uuid']}}) + + def test_020_check_deployent(self): + self.__class__.test_text = "{}.{}. TEST {} {}".format(test_config["test_number"], self.__class__.test_index, + inspect.currentframe().f_code.co_name, + test_config["test_folder"]) + self.__class__.test_index += 1 + + if test_config["manual"]: + raw_input('Scenario has been deployed. Perform manual check and press any key to resume') + return + + keep_waiting = test_config["timeout"] + pending_instance_scenario_uuids = list(self.__class__.instance_scenario_uuids) # make a copy + while pending_instance_scenario_uuids: + index = 0 + while index < len(pending_instance_scenario_uuids): + result = check_instance_scenario_active(pending_instance_scenario_uuids[index]) + if result[0]: + del pending_instance_scenario_uuids[index] + break + elif 'ERROR' in result[1]: + msg = 'Got error while waiting for the instance to get active: '+result[1] + logging.error(msg) + raise Exception(msg) + index += 1 + + if keep_waiting >= 5: + time.sleep(5) + keep_waiting -= 5 + elif keep_waiting > 0: time.sleep(keep_waiting) keep_waiting = 0 else: @@ -1480,13 +2121,14 @@ def test_vimconnector(args): tenant_name = args.tenant_name test_config['tenant'] = tenant_name - config_params = json.loads(args.config_param) + config_params = yaml.load(args.config_param) org_name = config_params.get('orgname') org_user = config_params.get('user') org_passwd = config_params.get('passwd') vim_url = args.endpoint_url test_config['image_path'] = args.image_path test_config['image_name'] = args.image_name + test_config['sriov_net_name'] = args.sriov_net_name # vmware connector obj test_config['vim_conn'] = vim.vimconnector(name=org_name, tenant_name=tenant_name, user=org_user,passwd=org_passwd, url=vim_url, config=config_params) @@ -1495,6 +2137,30 @@ def test_vimconnector(args): import vimconn_aws as vim elif args.vimtype == "openstack": import vimconn_openstack as vim + + test_config["test_directory"] = os.path.dirname(__file__) + "/RO_tests" + + tenant_name = args.tenant_name + test_config['tenant'] = tenant_name + config_params = yaml.load(args.config_param) + os_user = config_params.get('user') + os_passwd = config_params.get('passwd') + vim_url = args.endpoint_url + test_config['image_path'] = args.image_path + test_config['image_name'] = args.image_name + test_config['sriov_net_name'] = args.sriov_net_name + + # openstack connector obj + vim_persistent_info = {} + test_config['vim_conn'] = vim.vimconnector( + uuid="test-uuid-1", name="VIO-openstack", + tenant_id=None, tenant_name=tenant_name, + url=vim_url, url_admin=None, + user=os_user, passwd=os_passwd, + config=config_params, persistent_info=vim_persistent_info + ) + test_config['vim_conn'].debug = "true" + elif args.vimtype == "openvim": import vimconn_openvim as vim else: @@ -1507,7 +2173,7 @@ def test_vimconnector(args): if args.list_tests: tests_names = [] for cls in clsmembers: - if cls[0].startswith('test_vimconnector'): + if cls[0].startswith('test_vimconn'): tests_names.append(cls[0]) msg = "The 'vim' set tests are:\n\t" + ', '.join(sorted(tests_names)) @@ -1530,7 +2196,7 @@ def test_vimconnector(args): # include all tests for cls in clsmembers: # We exclude 'test_VIM_tenant_operations' unless it is specifically requested by the user - if cls[0].startswith('test_vimconnector'): + if cls[0].startswith('test_vimconn'): code_based_tests.append(cls[1]) logger.debug("tests to be executed: {}".format(code_based_tests)) @@ -1621,6 +2287,72 @@ def test_vim(args): return executed, failed +def test_wim(args): + global test_config + sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + "/osm_ro") + import openmanoclient + executed = 0 + failed = 0 + test_config["client"] = openmanoclient.openmanoclient( + endpoint_url=args.endpoint_url, + tenant_name=args.tenant_name, + datacenter_name=args.datacenter, + debug=args.debug, logger=test_config["logger_name"]) + clsmembers = inspect.getmembers(sys.modules[__name__], inspect.isclass) + # If only want to obtain a tests list print it and exit + if args.list_tests: + tests_names = [] + for cls in clsmembers: + if cls[0].startswith('test_WIM'): + tests_names.append(cls[0]) + + msg = "The 'wim' set tests are:\n\t" + ', '.join(sorted(tests_names)) +\ + "\nNOTE: The test test_VIM_tenant_operations will fail in case the used datacenter is type OpenStack " \ + "unless RO has access to the admin endpoint. Therefore this test is excluded by default" + print(msg) + logger.info(msg) + sys.exit(0) + + # Create the list of tests to be run + code_based_tests = [] + if args.tests: + for test in args.tests: + for t in test.split(','): + matches_code_based_tests = [item for item in clsmembers if item[0] == t] + if len(matches_code_based_tests) > 0: + code_based_tests.append(matches_code_based_tests[0][1]) + else: + logger.critical("Test '{}' is not among the possible ones".format(t)) + sys.exit(1) + if not code_based_tests: + # include all tests + for cls in clsmembers: + # We exclude 'test_VIM_tenant_operations' unless it is specifically requested by the user + if cls[0].startswith('test_VIM') and cls[0] != 'test_VIM_tenant_operations': + code_based_tests.append(cls[1]) + + logger.debug("tests to be executed: {}".format(code_based_tests)) + + # TextTestRunner stream is set to /dev/null in order to avoid the method to directly print the result of tests. + # This is handled in the tests using logging. + stream = open('/dev/null', 'w') + + # Run code based tests + basic_tests_suite = unittest.TestSuite() + for test in code_based_tests: + basic_tests_suite.addTest(unittest.makeSuite(test)) + result = unittest.TextTestRunner(stream=stream, failfast=failfast).run(basic_tests_suite) + executed += result.testsRun + failed += len(result.failures) + len(result.errors) + if failfast and failed: + sys.exit(1) + if len(result.failures) > 0: + logger.debug("failures : {}".format(result.failures)) + if len(result.errors) > 0: + logger.debug("errors : {}".format(result.errors)) + return executed, failed + + def test_deploy(args): global test_config sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + "/osm_ro") @@ -1746,6 +2478,7 @@ if __name__=="__main__": vimconn_parser.add_argument('-n', '--image-name', dest='image_name', help="Provide image name for test") # TODO add optional arguments for vimconn tests # vimconn_parser.add_argument("-i", '--image-name', dest='image_name', help='')) + vimconn_parser.add_argument('-s', '--sriov-net-name', dest='sriov_net_name', help="Provide SRIOV network name for test") # Datacenter test set # ------------------- @@ -1760,6 +2493,19 @@ if __name__=="__main__": vimconn_parser.add_argument('-u', '--url', dest='endpoint_url', default='http://localhost:9090/openmano', help="Set the openmano server url. By default 'http://localhost:9090/openmano'") + # WIM test set + # ------------------- + vimconn_parser = subparsers.add_parser('wim', parents=[parent_parser], help="test wim") + vimconn_parser.set_defaults(func=test_wim) + + # Mandatory arguments + mandatory_arguments = vimconn_parser.add_argument_group('mandatory arguments') + mandatory_arguments.add_argument('-d', '--datacenter', required=True, help='Set the datacenter to test') + + # Optional arguments + vimconn_parser.add_argument('-u', '--url', dest='endpoint_url', default='http://localhost:9090/openmano', + help="Set the openmano server url. By default 'http://localhost:9090/openmano'") + argcomplete.autocomplete(parser) args = parser.parse_args() # print str(args)