blob: be711c86580bd7ec23a56aab283ca563a0233329 [file] [log] [blame]
Pablo Montes Morenoeebea062017-02-27 12:33:10 +01001#!/usr/bin/env python2
2# -*- coding: utf-8 -*-
3
4##
tiernoec66e9a2017-05-17 15:28:10 +02005# Copyright 2017
Pablo Montes Morenoeebea062017-02-27 12:33:10 +01006# This file is part of openmano
7# All Rights Reserved.
8#
9# Licensed under the Apache License, Version 2.0 (the "License"); you may
10# not use this file except in compliance with the License. You may obtain
11# a copy of the License at
12#
13# http://www.apache.org/licenses/LICENSE-2.0
14#
15# Unless required by applicable law or agreed to in writing, software
16# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
18# License for the specific language governing permissions and limitations
19# under the License.
20#
Pablo Montes Morenoeebea062017-02-27 12:33:10 +010021##
22
jamartinezv14a823d2019-08-01 11:45:15 +020023# DEBUG WITH PDB
24import os
25if os.getenv('OSMRO_PDB_DEBUG'):
26 import sys
27 print(sys.path)
28 import pdb
29 pdb.set_trace()
30
31
tiernoed854572017-10-03 16:18:09 +020032"""
Pablo Montes Morenoeebea062017-02-27 12:33:10 +010033Module for testing openmano functionality. It uses openmanoclient.py for invoking openmano
tiernoed854572017-10-03 16:18:09 +020034"""
Pablo Montes Morenoeebea062017-02-27 12:33:10 +010035
36import logging
Pablo Montes Morenoeebea062017-02-27 12:33:10 +010037import os
tiernoec66e9a2017-05-17 15:28:10 +020038import argcomplete
Pablo Montes Morenoeebea062017-02-27 12:33:10 +010039import unittest
40import string
41import inspect
42import random
tiernoed854572017-10-03 16:18:09 +020043# import traceback
Pablo Montes Morenoeebea062017-02-27 12:33:10 +010044import glob
45import yaml
46import sys
47import time
kasarbd11fd82017-06-01 23:44:03 -070048import uuid
tiernoed854572017-10-03 16:18:09 +020049from argparse import ArgumentParser
Pablo Montes Morenoeebea062017-02-27 12:33:10 +010050
tiernoed854572017-10-03 16:18:09 +020051__author__ = "Pablo Montes, Alfonso Tierno"
52__date__ = "$16-Feb-2017 17:08:16$"
53__version__ = "0.1.0"
54version_date = "Oct 2017"
55
56test_config = {} # used for global variables with the test configuration
57
tiernoec66e9a2017-05-17 15:28:10 +020058
tiernof0508352017-06-19 13:37:44 +020059class test_base(unittest.TestCase):
60 test_index = 1
61 test_text = None
62
63 @classmethod
64 def setUpClass(cls):
65 logger.info("{}. {}".format(test_config["test_number"], cls.__name__))
66
67 @classmethod
68 def tearDownClass(cls):
69 test_config["test_number"] += 1
70
71 def tearDown(self):
72 exec_info = sys.exc_info()
73 if exec_info == (None, None, None):
74 logger.info(self.__class__.test_text+" -> TEST OK")
75 else:
76 logger.warning(self.__class__.test_text+" -> TEST NOK")
77 logger.critical("Traceback error",exc_info=True)
78
Pablo Montes Morenoeebea062017-02-27 12:33:10 +010079
Pablo Montes Moreno2fe24fa2017-03-27 12:56:13 +020080def check_instance_scenario_active(uuid):
tiernoec66e9a2017-05-17 15:28:10 +020081 instance = test_config["client"].get_instance(uuid=uuid)
Pablo Montes Moreno2fe24fa2017-03-27 12:56:13 +020082
83 for net in instance['nets']:
84 status = net['status']
Pablo Montes Morenob12711f2017-04-06 11:54:34 +020085 if status != 'ACTIVE':
Pablo Montes Moreno2fe24fa2017-03-27 12:56:13 +020086 return (False, status)
87
88 for vnf in instance['vnfs']:
89 for vm in vnf['vms']:
90 status = vm['status']
91 if status != 'ACTIVE':
92 return (False, status)
93
94 return (True, None)
95
tiernoec66e9a2017-05-17 15:28:10 +020096
Pablo Montes Morenoeebea062017-02-27 12:33:10 +010097'''
98IMPORTANT NOTE
99All unittest classes for code based tests must have prefix 'test_' in order to be taken into account for tests
100'''
tiernof0508352017-06-19 13:37:44 +0200101class test_VIM_datacenter_tenant_operations(test_base):
Pablo Montes Morenoeebea062017-02-27 12:33:10 +0100102 tenant_name = None
Pablo Montes Morenoeebea062017-02-27 12:33:10 +0100103
104 def test_000_create_RO_tenant(self):
105 self.__class__.tenant_name = _get_random_string(20)
tiernoec66e9a2017-05-17 15:28:10 +0200106 self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"], self.__class__.test_index,
Pablo Montes Morenoeebea062017-02-27 12:33:10 +0100107 inspect.currentframe().f_code.co_name)
108 self.__class__.test_index += 1
tiernoec66e9a2017-05-17 15:28:10 +0200109 tenant = test_config["client"].create_tenant(name=self.__class__.tenant_name,
110 description=self.__class__.tenant_name)
Pablo Montes Morenoeebea062017-02-27 12:33:10 +0100111 logger.debug("{}".format(tenant))
112 self.assertEqual(tenant.get('tenant', {}).get('name', ''), self.__class__.tenant_name)
113
114 def test_010_list_RO_tenant(self):
tiernoec66e9a2017-05-17 15:28:10 +0200115 self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"], self.__class__.test_index,
Pablo Montes Morenoeebea062017-02-27 12:33:10 +0100116 inspect.currentframe().f_code.co_name)
117 self.__class__.test_index += 1
tiernoec66e9a2017-05-17 15:28:10 +0200118 tenant = test_config["client"].get_tenant(name=self.__class__.tenant_name)
Pablo Montes Morenoeebea062017-02-27 12:33:10 +0100119 logger.debug("{}".format(tenant))
120 self.assertEqual(tenant.get('tenant', {}).get('name', ''), self.__class__.tenant_name)
121
122 def test_020_delete_RO_tenant(self):
tiernoec66e9a2017-05-17 15:28:10 +0200123 self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"], self.__class__.test_index,
Pablo Montes Morenoeebea062017-02-27 12:33:10 +0100124 inspect.currentframe().f_code.co_name)
125 self.__class__.test_index += 1
tiernoec66e9a2017-05-17 15:28:10 +0200126 tenant = test_config["client"].delete_tenant(name=self.__class__.tenant_name)
Pablo Montes Morenoeebea062017-02-27 12:33:10 +0100127 logger.debug("{}".format(tenant))
128 assert('deleted' in tenant.get('result',""))
129
tiernoec66e9a2017-05-17 15:28:10 +0200130
tiernof0508352017-06-19 13:37:44 +0200131class test_VIM_datacenter_operations(test_base):
Pablo Montes Morenoeebea062017-02-27 12:33:10 +0100132 datacenter_name = None
Pablo Montes Morenoeebea062017-02-27 12:33:10 +0100133
134 def test_000_create_datacenter(self):
tiernoec66e9a2017-05-17 15:28:10 +0200135 self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"], self.__class__.test_index,
Pablo Montes Morenoeebea062017-02-27 12:33:10 +0100136 inspect.currentframe().f_code.co_name)
137 self.__class__.datacenter_name = _get_random_string(20)
138 self.__class__.test_index += 1
tiernoec66e9a2017-05-17 15:28:10 +0200139 self.datacenter = test_config["client"].create_datacenter(name=self.__class__.datacenter_name,
140 vim_url="http://fakeurl/fake")
Pablo Montes Morenoeebea062017-02-27 12:33:10 +0100141 logger.debug("{}".format(self.datacenter))
142 self.assertEqual (self.datacenter.get('datacenter', {}).get('name',''), self.__class__.datacenter_name)
143
144 def test_010_list_datacenter(self):
tiernoec66e9a2017-05-17 15:28:10 +0200145 self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"], self.__class__.test_index,
Pablo Montes Morenoeebea062017-02-27 12:33:10 +0100146 inspect.currentframe().f_code.co_name)
147
148 self.__class__.test_index += 1
tiernoec66e9a2017-05-17 15:28:10 +0200149 self.datacenter = test_config["client"].get_datacenter(all_tenants=True, name=self.__class__.datacenter_name)
Pablo Montes Morenoeebea062017-02-27 12:33:10 +0100150 logger.debug("{}".format(self.datacenter))
151 self.assertEqual (self.datacenter.get('datacenter', {}).get('name', ''), self.__class__.datacenter_name)
152
153 def test_020_attach_datacenter(self):
tiernoec66e9a2017-05-17 15:28:10 +0200154 self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"], self.__class__.test_index,
Pablo Montes Morenoeebea062017-02-27 12:33:10 +0100155 inspect.currentframe().f_code.co_name)
156
157 self.__class__.test_index += 1
tiernoec66e9a2017-05-17 15:28:10 +0200158 self.datacenter = test_config["client"].attach_datacenter(name=self.__class__.datacenter_name,
159 vim_tenant_name='fake')
Pablo Montes Morenoeebea062017-02-27 12:33:10 +0100160 logger.debug("{}".format(self.datacenter))
tiernod3750b32018-07-20 15:33:08 +0200161 assert ('uuid' in self.datacenter.get('datacenter', {}))
Pablo Montes Morenoeebea062017-02-27 12:33:10 +0100162
163 def test_030_list_attached_datacenter(self):
tiernoec66e9a2017-05-17 15:28:10 +0200164 self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"], self.__class__.test_index,
Pablo Montes Morenoeebea062017-02-27 12:33:10 +0100165 inspect.currentframe().f_code.co_name)
166
167 self.__class__.test_index += 1
tiernoec66e9a2017-05-17 15:28:10 +0200168 self.datacenter = test_config["client"].get_datacenter(all_tenants=False, name=self.__class__.datacenter_name)
Pablo Montes Morenoeebea062017-02-27 12:33:10 +0100169 logger.debug("{}".format(self.datacenter))
170 self.assertEqual (self.datacenter.get('datacenter', {}).get('name', ''), self.__class__.datacenter_name)
171
172 def test_040_detach_datacenter(self):
tiernoec66e9a2017-05-17 15:28:10 +0200173 self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"], self.__class__.test_index,
Pablo Montes Morenoeebea062017-02-27 12:33:10 +0100174 inspect.currentframe().f_code.co_name)
175
176 self.__class__.test_index += 1
tiernoec66e9a2017-05-17 15:28:10 +0200177 self.datacenter = test_config["client"].detach_datacenter(name=self.__class__.datacenter_name)
Pablo Montes Morenoeebea062017-02-27 12:33:10 +0100178 logger.debug("{}".format(self.datacenter))
179 assert ('detached' in self.datacenter.get('result', ""))
180
181 def test_050_delete_datacenter(self):
tiernoec66e9a2017-05-17 15:28:10 +0200182 self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"], self.__class__.test_index,
Pablo Montes Morenoeebea062017-02-27 12:33:10 +0100183 inspect.currentframe().f_code.co_name)
184
185 self.__class__.test_index += 1
tiernoec66e9a2017-05-17 15:28:10 +0200186 self.datacenter = test_config["client"].delete_datacenter(name=self.__class__.datacenter_name)
Pablo Montes Morenoeebea062017-02-27 12:33:10 +0100187 logger.debug("{}".format(self.datacenter))
188 assert('deleted' in self.datacenter.get('result',""))
189
tiernoec66e9a2017-05-17 15:28:10 +0200190
tiernof0508352017-06-19 13:37:44 +0200191class test_VIM_network_operations(test_base):
Pablo Montes Morenoeebea062017-02-27 12:33:10 +0100192 vim_network_name = None
Pablo Montes Morenoeebea062017-02-27 12:33:10 +0100193 vim_network_uuid = None
194
Pablo Montes Morenoeebea062017-02-27 12:33:10 +0100195 def test_000_create_VIM_network(self):
tiernoec66e9a2017-05-17 15:28:10 +0200196 self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"], self.__class__.test_index,
Pablo Montes Morenoeebea062017-02-27 12:33:10 +0100197 inspect.currentframe().f_code.co_name)
198 self.__class__.vim_network_name = _get_random_string(20)
199 self.__class__.test_index += 1
tiernoec66e9a2017-05-17 15:28:10 +0200200 network = test_config["client"].vim_action("create", "networks", name=self.__class__.vim_network_name)
Pablo Montes Morenoeebea062017-02-27 12:33:10 +0100201 logger.debug("{}".format(network))
202 self.__class__.vim_network_uuid = network["network"]["id"]
203 self.assertEqual(network.get('network', {}).get('name', ''), self.__class__.vim_network_name)
204
205 def test_010_list_VIM_networks(self):
tiernoec66e9a2017-05-17 15:28:10 +0200206 self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"], self.__class__.test_index,
Pablo Montes Morenoeebea062017-02-27 12:33:10 +0100207 inspect.currentframe().f_code.co_name)
208 self.__class__.test_index += 1
tiernoec66e9a2017-05-17 15:28:10 +0200209 networks = test_config["client"].vim_action("list", "networks")
Pablo Montes Morenoeebea062017-02-27 12:33:10 +0100210 logger.debug("{}".format(networks))
211
212 def test_020_get_VIM_network_by_uuid(self):
tiernoec66e9a2017-05-17 15:28:10 +0200213 self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"], self.__class__.test_index,
Pablo Montes Morenoeebea062017-02-27 12:33:10 +0100214 inspect.currentframe().f_code.co_name)
215
216 self.__class__.test_index += 1
tiernoec66e9a2017-05-17 15:28:10 +0200217 network = test_config["client"].vim_action("show", "networks", uuid=self.__class__.vim_network_uuid)
Pablo Montes Morenoeebea062017-02-27 12:33:10 +0100218 logger.debug("{}".format(network))
219 self.assertEqual(network.get('network', {}).get('name', ''), self.__class__.vim_network_name)
220
221 def test_030_delete_VIM_network_by_uuid(self):
tiernoec66e9a2017-05-17 15:28:10 +0200222 self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"], self.__class__.test_index,
Pablo Montes Morenoeebea062017-02-27 12:33:10 +0100223 inspect.currentframe().f_code.co_name)
224
225 self.__class__.test_index += 1
tiernoec66e9a2017-05-17 15:28:10 +0200226 network = test_config["client"].vim_action("delete", "networks", uuid=self.__class__.vim_network_uuid)
Pablo Montes Morenoeebea062017-02-27 12:33:10 +0100227 logger.debug("{}".format(network))
228 assert ('deleted' in network.get('result', ""))
229
tiernoec66e9a2017-05-17 15:28:10 +0200230
tiernof0508352017-06-19 13:37:44 +0200231class test_VIM_image_operations(test_base):
Pablo Montes Morenoeebea062017-02-27 12:33:10 +0100232
233 def test_000_list_VIM_images(self):
tiernoec66e9a2017-05-17 15:28:10 +0200234 self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"], self.__class__.test_index,
Pablo Montes Morenoeebea062017-02-27 12:33:10 +0100235 inspect.currentframe().f_code.co_name)
236 self.__class__.test_index += 1
tiernoec66e9a2017-05-17 15:28:10 +0200237 images = test_config["client"].vim_action("list", "images")
Pablo Montes Morenoeebea062017-02-27 12:33:10 +0100238 logger.debug("{}".format(images))
239
240'''
241The following is a non critical test that will fail most of the times.
242In case of OpenStack datacenter these tests will only success if RO has access to the admin endpoint
243This test will only be executed in case it is specifically requested by the user
244'''
tiernof0508352017-06-19 13:37:44 +0200245class test_VIM_tenant_operations(test_base):
Pablo Montes Morenoeebea062017-02-27 12:33:10 +0100246 vim_tenant_name = None
Pablo Montes Morenoeebea062017-02-27 12:33:10 +0100247 vim_tenant_uuid = None
248
249 @classmethod
250 def setUpClass(cls):
tiernof0508352017-06-19 13:37:44 +0200251 test_base.setUpClass(cls)
Pablo Montes Morenoeebea062017-02-27 12:33:10 +0100252 logger.warning("In case of OpenStack datacenter these tests will only success "
253 "if RO has access to the admin endpoint")
254
Pablo Montes Morenoeebea062017-02-27 12:33:10 +0100255 def test_000_create_VIM_tenant(self):
tiernoec66e9a2017-05-17 15:28:10 +0200256 self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"], self.__class__.test_index,
Pablo Montes Morenoeebea062017-02-27 12:33:10 +0100257 inspect.currentframe().f_code.co_name)
258 self.__class__.vim_tenant_name = _get_random_string(20)
259 self.__class__.test_index += 1
tiernoec66e9a2017-05-17 15:28:10 +0200260 tenant = test_config["client"].vim_action("create", "tenants", name=self.__class__.vim_tenant_name)
Pablo Montes Morenoeebea062017-02-27 12:33:10 +0100261 logger.debug("{}".format(tenant))
262 self.__class__.vim_tenant_uuid = tenant["tenant"]["id"]
263 self.assertEqual(tenant.get('tenant', {}).get('name', ''), self.__class__.vim_tenant_name)
264
265 def test_010_list_VIM_tenants(self):
tiernoec66e9a2017-05-17 15:28:10 +0200266 self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"], self.__class__.test_index,
Pablo Montes Morenoeebea062017-02-27 12:33:10 +0100267 inspect.currentframe().f_code.co_name)
268 self.__class__.test_index += 1
tiernoec66e9a2017-05-17 15:28:10 +0200269 tenants = test_config["client"].vim_action("list", "tenants")
Pablo Montes Morenoeebea062017-02-27 12:33:10 +0100270 logger.debug("{}".format(tenants))
271
272 def test_020_get_VIM_tenant_by_uuid(self):
tiernoec66e9a2017-05-17 15:28:10 +0200273 self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"], self.__class__.test_index,
Pablo Montes Morenoeebea062017-02-27 12:33:10 +0100274 inspect.currentframe().f_code.co_name)
275
276 self.__class__.test_index += 1
tiernoec66e9a2017-05-17 15:28:10 +0200277 tenant = test_config["client"].vim_action("show", "tenants", uuid=self.__class__.vim_tenant_uuid)
Pablo Montes Morenoeebea062017-02-27 12:33:10 +0100278 logger.debug("{}".format(tenant))
279 self.assertEqual(tenant.get('tenant', {}).get('name', ''), self.__class__.vim_tenant_name)
280
281 def test_030_delete_VIM_tenant_by_uuid(self):
tiernoec66e9a2017-05-17 15:28:10 +0200282 self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"], self.__class__.test_index,
Pablo Montes Morenoeebea062017-02-27 12:33:10 +0100283 inspect.currentframe().f_code.co_name)
284
285 self.__class__.test_index += 1
tiernoec66e9a2017-05-17 15:28:10 +0200286 tenant = test_config["client"].vim_action("delete", "tenants", uuid=self.__class__.vim_tenant_uuid)
Pablo Montes Morenoeebea062017-02-27 12:33:10 +0100287 logger.debug("{}".format(tenant))
288 assert ('deleted' in tenant.get('result', ""))
289
tiernoed854572017-10-03 16:18:09 +0200290
tiernof0508352017-06-19 13:37:44 +0200291class test_vimconn_connect(test_base):
kasar70532ae2017-05-26 03:53:52 -0700292
293 def test_000_connect(self):
294 self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"],
295 self.__class__.test_index,
296 inspect.currentframe().f_code.co_name)
297
298 self.__class__.test_index += 1
299 if test_config['vimtype'] == 'vmware':
300 vca_object = test_config["vim_conn"].connect()
301 logger.debug("{}".format(vca_object))
kasarc5bf2932018-03-09 04:15:22 -0800302 self.assertIsNotNone(vca_object)
jamartinezv14a823d2019-08-01 11:45:15 +0200303 elif test_config['vimtype'] in ('openstack', 'azure'):
anwarsc76a3ee2018-10-04 14:05:32 +0530304 test_config["vim_conn"]._reload_connection()
305 network_list = test_config["vim_conn"].get_network_list()
306 logger.debug("{}".format(network_list))
307 self.assertIsNotNone(network_list)
kasar70532ae2017-05-26 03:53:52 -0700308
tiernof0508352017-06-19 13:37:44 +0200309class test_vimconn_new_network(test_base):
kasar70532ae2017-05-26 03:53:52 -0700310 network_name = None
kasar70532ae2017-05-26 03:53:52 -0700311
312 def test_000_new_network(self):
313 self.__class__.network_name = _get_random_string(20)
314 network_type = 'bridge'
315
316 self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"],
317 self.__class__.test_index, inspect.currentframe().f_code.co_name)
318 self.__class__.test_index += 1
319
jamartinezv14a823d2019-08-01 11:45:15 +0200320 network, _ = test_config["vim_conn"].new_network(net_name=self.__class__.network_name,
kasar70532ae2017-05-26 03:53:52 -0700321 net_type=network_type)
322 self.__class__.network_id = network
323 logger.debug("{}".format(network))
324
kasarf358ad52017-07-24 01:28:44 -0700325 network_list = test_config["vim_conn"].get_network_list()
kasar70532ae2017-05-26 03:53:52 -0700326 for net in network_list:
327 if self.__class__.network_name in net.get('name'):
328 self.assertIn(self.__class__.network_name, net.get('name'))
329 self.assertEqual(net.get('type'), network_type)
330
331 # Deleting created network
332 result = test_config["vim_conn"].delete_network(self.__class__.network_id)
333 if result:
334 logger.info("Network id {} sucessfully deleted".format(self.__class__.network_id))
335 else:
336 logger.info("Failed to delete network id {}".format(self.__class__.network_id))
337
338 def test_010_new_network_by_types(self):
339 delete_net_ids = []
340 network_types = ['data','bridge','mgmt']
341 self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"],
342 self.__class__.test_index,
343 inspect.currentframe().f_code.co_name)
344 self.__class__.test_index += 1
345 for net_type in network_types:
346 self.__class__.network_name = _get_random_string(20)
jamartinezv14a823d2019-08-01 11:45:15 +0200347 network_id, _ = test_config["vim_conn"].new_network(net_name=self.__class__.network_name,
kasar70532ae2017-05-26 03:53:52 -0700348 net_type=net_type)
349
350 delete_net_ids.append(network_id)
351 logger.debug("{}".format(network_id))
352
kasarf358ad52017-07-24 01:28:44 -0700353 network_list = test_config["vim_conn"].get_network_list()
kasar70532ae2017-05-26 03:53:52 -0700354 for net in network_list:
355 if self.__class__.network_name in net.get('name'):
356 self.assertIn(self.__class__.network_name, net.get('name'))
357 if net_type in net.get('type'):
358 self.assertEqual(net.get('type'), net_type)
359 else:
360 self.assertNotEqual(net.get('type'), net_type)
361
362 # Deleting created network
363 for net_id in delete_net_ids:
364 result = test_config["vim_conn"].delete_network(net_id)
365 if result:
366 logger.info("Network id {} sucessfully deleted".format(net_id))
367 else:
368 logger.info("Failed to delete network id {}".format(net_id))
369
370 def test_020_new_network_by_ipprofile(self):
371 test_directory_content = os.listdir(test_config["test_directory"])
372
373 for dir_name in test_directory_content:
374 if dir_name == 'simple_multi_vnfc':
375 self.__class__.scenario_test_path = test_config["test_directory"] + '/'+ dir_name
376 vnfd_files = glob.glob(self.__class__.scenario_test_path+'/vnfd_*.yaml')
377 break
378
379 for vnfd in vnfd_files:
380 with open(vnfd, 'r') as stream:
381 vnf_descriptor = yaml.load(stream)
382
383 internal_connections_list = vnf_descriptor['vnf']['internal-connections']
384 for item in internal_connections_list:
385 if 'ip-profile' in item:
386 version = item['ip-profile']['ip-version']
387 dhcp_count = item['ip-profile']['dhcp']['count']
388 dhcp_enabled = item['ip-profile']['dhcp']['enabled']
anwarsc76a3ee2018-10-04 14:05:32 +0530389 dhcp_start_address = item['ip-profile']['dhcp']['start-address']
390 subnet_address = item['ip-profile']['subnet-address']
391
kasar70532ae2017-05-26 03:53:52 -0700392
393 self.__class__.network_name = _get_random_string(20)
394 ip_profile = {'dhcp_count': dhcp_count,
395 'dhcp_enabled': dhcp_enabled,
anwarsc76a3ee2018-10-04 14:05:32 +0530396 'dhcp_start_address': dhcp_start_address,
397 'ip_version': version,
398 'subnet_address': subnet_address
kasar70532ae2017-05-26 03:53:52 -0700399 }
400 self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"],
401 self.__class__.test_index,
402 inspect.currentframe().f_code.co_name)
403 self.__class__.test_index += 1
jamartinezv14a823d2019-08-01 11:45:15 +0200404 network, _ = test_config["vim_conn"].new_network(net_name=self.__class__.network_name,
kasar70532ae2017-05-26 03:53:52 -0700405 net_type='mgmt',
406 ip_profile=ip_profile)
407 self.__class__.network_id = network
408 logger.debug("{}".format(network))
409
kasarf358ad52017-07-24 01:28:44 -0700410 network_list = test_config["vim_conn"].get_network_list()
kasar70532ae2017-05-26 03:53:52 -0700411 for net in network_list:
412 if self.__class__.network_name in net.get('name'):
413 self.assertIn(self.__class__.network_name, net.get('name'))
414
415 # Deleting created network
416 result = test_config["vim_conn"].delete_network(self.__class__.network_id)
417 if result:
418 logger.info("Network id {} sucessfully deleted".format(self.__class__.network_id))
419 else:
420 logger.info("Failed to delete network id {}".format(self.__class__.network_id))
421
422 def test_030_new_network_by_isshared(self):
423 self.__class__.network_name = _get_random_string(20)
424 shared = True
425 self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"],
426 self.__class__.test_index,
427 inspect.currentframe().f_code.co_name)
428 self.__class__.test_index += 1
jamartinezv14a823d2019-08-01 11:45:15 +0200429 network, _ = test_config["vim_conn"].new_network(net_name=self.__class__.network_name,
kasar70532ae2017-05-26 03:53:52 -0700430 net_type='bridge',
431 shared=shared)
432 self.__class__.network_id = network
433 logger.debug("{}".format(network))
434
kasarf358ad52017-07-24 01:28:44 -0700435 network_list = test_config["vim_conn"].get_network_list()
kasar70532ae2017-05-26 03:53:52 -0700436 for net in network_list:
437 if self.__class__.network_name in net.get('name'):
438 self.assertIn(self.__class__.network_name, net.get('name'))
439 self.assertEqual(net.get('shared'), shared)
440
441 # Deleting created network
442 result = test_config["vim_conn"].delete_network(self.__class__.network_id)
443 if result:
444 logger.info("Network id {} sucessfully deleted".format(self.__class__.network_id))
445 else:
446 logger.info("Failed to delete network id {}".format(self.__class__.network_id))
447
448 def test_040_new_network_by_negative(self):
449 self.__class__.network_name = _get_random_string(20)
450 self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"],
451 self.__class__.test_index,
452 inspect.currentframe().f_code.co_name)
453 self.__class__.test_index += 1
jamartinezv14a823d2019-08-01 11:45:15 +0200454 network, _ = test_config["vim_conn"].new_network(net_name=self.__class__.network_name,
kasar70532ae2017-05-26 03:53:52 -0700455 net_type='unknowntype')
456 self.__class__.network_id = network
457 logger.debug("{}".format(network))
kasarf358ad52017-07-24 01:28:44 -0700458 network_list = test_config["vim_conn"].get_network_list()
kasar70532ae2017-05-26 03:53:52 -0700459 for net in network_list:
460 if self.__class__.network_name in net.get('name'):
461 self.assertIn(self.__class__.network_name, net.get('name'))
462
463 # Deleting created network
464 result = test_config["vim_conn"].delete_network(self.__class__.network_id)
465 if result:
466 logger.info("Network id {} sucessfully deleted".format(self.__class__.network_id))
467 else:
468 logger.info("Failed to delete network id {}".format(self.__class__.network_id))
469
kasar114050e2017-07-06 02:04:59 -0700470 def test_050_refresh_nets_status(self):
471 self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"],
472 self.__class__.test_index,
473 inspect.currentframe().f_code.co_name)
474 self.__class__.test_index += 1
475 # creating new network
476 network_name = _get_random_string(20)
477 net_type = 'bridge'
jamartinezv14a823d2019-08-01 11:45:15 +0200478 network_id, _ = test_config["vim_conn"].new_network(net_name=network_name,
kasar114050e2017-07-06 02:04:59 -0700479 net_type=net_type)
480 # refresh net status
481 net_dict = test_config["vim_conn"].refresh_nets_status([network_id])
482 for attr in net_dict[network_id]:
483 if attr == 'status':
484 self.assertEqual(net_dict[network_id][attr], 'ACTIVE')
485
486 # Deleting created network
487 result = test_config["vim_conn"].delete_network(network_id)
488 if result:
489 logger.info("Network id {} sucessfully deleted".format(network_id))
490 else:
491 logger.info("Failed to delete network id {}".format(network_id))
492
493 def test_060_refresh_nets_status_negative(self):
494 unknown_net_id = str(uuid.uuid4())
495 self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"],
496 self.__class__.test_index,
497 inspect.currentframe().f_code.co_name)
498 self.__class__.test_index += 1
499
500 # refresh net status
501 net_dict = test_config["vim_conn"].refresh_nets_status([unknown_net_id])
jamartinezv14a823d2019-08-01 11:45:15 +0200502 if test_config['vimtype'] in ('openstack', 'azure'):
anwarsc76a3ee2018-10-04 14:05:32 +0530503 self.assertEqual(net_dict[unknown_net_id]['status'], 'DELETED')
504 else:
505 # TODO : Fix vmware connector to return status DELETED as per vimconn.py
506 self.assertEqual(net_dict, {})
kasar114050e2017-07-06 02:04:59 -0700507
tiernof0508352017-06-19 13:37:44 +0200508class test_vimconn_get_network_list(test_base):
kasar70532ae2017-05-26 03:53:52 -0700509 network_name = None
kasar70532ae2017-05-26 03:53:52 -0700510
kasar70532ae2017-05-26 03:53:52 -0700511 def setUp(self):
512 # creating new network
513 self.__class__.network_name = _get_random_string(20)
514 self.__class__.net_type = 'bridge'
jamartinezv14a823d2019-08-01 11:45:15 +0200515 network, _ = test_config["vim_conn"].new_network(net_name=self.__class__.network_name,
kasar70532ae2017-05-26 03:53:52 -0700516 net_type=self.__class__.net_type)
517 self.__class__.network_id = network
518 logger.debug("{}".format(network))
519
520 def tearDown(self):
tiernof0508352017-06-19 13:37:44 +0200521 test_base.tearDown(self)
kasar70532ae2017-05-26 03:53:52 -0700522
523 # Deleting created network
524 result = test_config["vim_conn"].delete_network(self.__class__.network_id)
525 if result:
526 logger.info("Network id {} sucessfully deleted".format(self.__class__.network_id))
527 else:
528 logger.info("Failed to delete network id {}".format(self.__class__.network_id))
529
530 def test_000_get_network_list(self):
531 self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"],
532 self.__class__.test_index,
533 inspect.currentframe().f_code.co_name)
534 self.__class__.test_index += 1
535
536 network_list = test_config["vim_conn"].get_network_list()
537 for net in network_list:
538 if self.__class__.network_name in net.get('name'):
539 self.assertIn(self.__class__.network_name, net.get('name'))
540 self.assertEqual(net.get('type'), self.__class__.net_type)
541 self.assertEqual(net.get('status'), 'ACTIVE')
jamartinezv14a823d2019-08-01 11:45:15 +0200542 if test_config['vimtype'] != 'azure':
543 self.assertEqual(net.get('shared'), False)
kasar70532ae2017-05-26 03:53:52 -0700544
545 def test_010_get_network_list_by_name(self):
546 self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"],
547 self.__class__.test_index,
548 inspect.currentframe().f_code.co_name)
549 self.__class__.test_index += 1
550
jamartinezv14a823d2019-08-01 11:45:15 +0200551 if test_config['vimtype'] in ('openstack', 'azure'):
anwarsc76a3ee2018-10-04 14:05:32 +0530552 network_name = test_config['vim_conn'].get_network(self.__class__.network_id)['name']
553 else:
554 network_name = test_config['vim_conn'].get_network_name_by_id(self.__class__.network_id)
kasar70532ae2017-05-26 03:53:52 -0700555
556 # find network from list by it's name
557 new_network_list = test_config["vim_conn"].get_network_list({'name': network_name})
558 for list_item in new_network_list:
559 if self.__class__.network_name in list_item.get('name'):
560 self.assertEqual(network_name, list_item.get('name'))
561 self.assertEqual(list_item.get('type'), self.__class__.net_type)
562 self.assertEqual(list_item.get('status'), 'ACTIVE')
563
564 def test_020_get_network_list_by_id(self):
565 self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"],
566 self.__class__.test_index,
567 inspect.currentframe().f_code.co_name)
568 self.__class__.test_index += 1
569
570 # find network from list by it's id
571 new_network_list = test_config["vim_conn"].get_network_list({'id':self.__class__.network_id})
572 for list_item in new_network_list:
573 if self.__class__.network_id in list_item.get('id'):
574 self.assertEqual(self.__class__.network_id, list_item.get('id'))
575 self.assertEqual(list_item.get('type'), self.__class__.net_type)
576 self.assertEqual(list_item.get('status'), 'ACTIVE')
577
578 def test_030_get_network_list_by_shared(self):
579 Shared = False
580 self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"],
581 self.__class__.test_index,
582 inspect.currentframe().f_code.co_name)
583 self.__class__.test_index += 1
584
jamartinezv14a823d2019-08-01 11:45:15 +0200585 if test_config['vimtype'] in ('openstack', 'azure'):
anwarsc76a3ee2018-10-04 14:05:32 +0530586 network_name = test_config['vim_conn'].get_network(self.__class__.network_id)['name']
587 else:
588 network_name = test_config['vim_conn'].get_network_name_by_id(self.__class__.network_id)
kasar70532ae2017-05-26 03:53:52 -0700589 # find network from list by it's shared value
590 new_network_list = test_config["vim_conn"].get_network_list({'shared':Shared,
591 'name':network_name})
592 for list_item in new_network_list:
593 if list_item.get('shared') == Shared:
594 self.assertEqual(list_item.get('shared'), Shared)
595 self.assertEqual(list_item.get('type'), self.__class__.net_type)
596 self.assertEqual(network_name, list_item.get('name'))
597
598 def test_040_get_network_list_by_tenant_id(self):
599 self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"],
600 self.__class__.test_index,
601 inspect.currentframe().f_code.co_name)
602 self.__class__.test_index += 1
603
604 tenant_list = test_config["vim_conn"].get_tenant_list()
jamartinezv14a823d2019-08-01 11:45:15 +0200605 if test_config['vimtype'] in ('openstack', 'azure'):
anwarsc76a3ee2018-10-04 14:05:32 +0530606 network_name = test_config['vim_conn'].get_network(self.__class__.network_id)['name']
607 else:
608 network_name = test_config['vim_conn'].get_network_name_by_id(self.__class__.network_id)
kasar70532ae2017-05-26 03:53:52 -0700609
610 for tenant_item in tenant_list:
611 if test_config['tenant'] == tenant_item.get('name'):
612 # find network from list by it's tenant id
613 tenant_id = tenant_item.get('id')
614 new_network_list = test_config["vim_conn"].get_network_list({'tenant_id':tenant_id,
615 'name':network_name})
616 for list_item in new_network_list:
617 self.assertEqual(tenant_id, list_item.get('tenant_id'))
618 self.assertEqual(network_name, list_item.get('name'))
619 self.assertEqual(list_item.get('type'), self.__class__.net_type)
620 self.assertEqual(list_item.get('status'), 'ACTIVE')
621
622 def test_050_get_network_list_by_status(self):
623 self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"],
624 self.__class__.test_index,
625 inspect.currentframe().f_code.co_name)
626 self.__class__.test_index += 1
627 status = 'ACTIVE'
628
jamartinezv14a823d2019-08-01 11:45:15 +0200629 if test_config['vimtype'] in ('openstack', 'azure'):
anwarsc76a3ee2018-10-04 14:05:32 +0530630 network_name = test_config['vim_conn'].get_network(self.__class__.network_id)['name']
631 else:
632 network_name = test_config['vim_conn'].get_network_name_by_id(self.__class__.network_id)
kasar70532ae2017-05-26 03:53:52 -0700633
634 # find network from list by it's status
635 new_network_list = test_config["vim_conn"].get_network_list({'status':status,
636 'name': network_name})
637 for list_item in new_network_list:
638 self.assertIn(self.__class__.network_name, list_item.get('name'))
639 self.assertEqual(list_item.get('type'), self.__class__.net_type)
640 self.assertEqual(list_item.get('status'), status)
641
642 def test_060_get_network_list_by_negative(self):
643 self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"],
644 self.__class__.test_index,
645 inspect.currentframe().f_code.co_name)
646 self.__class__.test_index += 1
647
648 network_list = test_config["vim_conn"].get_network_list({'name': 'unknown_name'})
649 self.assertEqual(network_list, [])
650
tiernof0508352017-06-19 13:37:44 +0200651class test_vimconn_get_network(test_base):
kasarbd11fd82017-06-01 23:44:03 -0700652 network_name = None
kasarbd11fd82017-06-01 23:44:03 -0700653
654 def setUp(self):
655 # creating new network
656 self.__class__.network_name = _get_random_string(20)
657 self.__class__.net_type = 'bridge'
jamartinezv14a823d2019-08-01 11:45:15 +0200658 network, _ = test_config["vim_conn"].new_network(net_name=self.__class__.network_name,
kasarbd11fd82017-06-01 23:44:03 -0700659 net_type=self.__class__.net_type)
660 self.__class__.network_id = network
661 logger.debug("{}".format(network))
662
663 def tearDown(self):
tiernof0508352017-06-19 13:37:44 +0200664 test_base.tearDown(self)
kasarbd11fd82017-06-01 23:44:03 -0700665
666 # Deleting created network
667 result = test_config["vim_conn"].delete_network(self.__class__.network_id)
668 if result:
669 logger.info("Network id {} sucessfully deleted".format(self.__class__.network_id))
670 else:
671 logger.info("Failed to delete network id {}".format(self.__class__.network_id))
672
673 def test_000_get_network(self):
674 self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"],
675 self.__class__.test_index,
676 inspect.currentframe().f_code.co_name)
677 self.__class__.test_index += 1
678
679 network_info = test_config["vim_conn"].get_network(self.__class__.network_id)
680 self.assertEqual(network_info.get('status'), 'ACTIVE')
681 self.assertIn(self.__class__.network_name, network_info.get('name'))
682 self.assertEqual(network_info.get('type'), self.__class__.net_type)
683 self.assertEqual(network_info.get('id'), self.__class__.network_id)
684
685 def test_010_get_network_negative(self):
686 Non_exist_id = str(uuid.uuid4())
687 self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"],
688 self.__class__.test_index,
689 inspect.currentframe().f_code.co_name)
690 self.__class__.test_index += 1
kasarc5bf2932018-03-09 04:15:22 -0800691 with self.assertRaises(Exception) as context:
692 test_config["vim_conn"].get_network(Non_exist_id)
kasarbd11fd82017-06-01 23:44:03 -0700693
kasarc5bf2932018-03-09 04:15:22 -0800694 self.assertEqual((context.exception).http_code, 404)
kasarbd11fd82017-06-01 23:44:03 -0700695
tiernof0508352017-06-19 13:37:44 +0200696class test_vimconn_delete_network(test_base):
kasarbd11fd82017-06-01 23:44:03 -0700697 network_name = None
kasarbd11fd82017-06-01 23:44:03 -0700698
699 def test_000_delete_network(self):
700 # Creating network
701 self.__class__.network_name = _get_random_string(20)
702 self.__class__.net_type = 'bridge'
jamartinezv14a823d2019-08-01 11:45:15 +0200703 network, _ = test_config["vim_conn"].new_network(net_name=self.__class__.network_name,
kasarbd11fd82017-06-01 23:44:03 -0700704 net_type=self.__class__.net_type)
705 self.__class__.network_id = network
706 logger.debug("{}".format(network))
707
708 self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"],
709 self.__class__.test_index,
710 inspect.currentframe().f_code.co_name)
711 self.__class__.test_index += 1
712
713 result = test_config["vim_conn"].delete_network(self.__class__.network_id)
714 if result:
715 logger.info("Network id {} sucessfully deleted".format(self.__class__.network_id))
716 else:
717 logger.info("Failed to delete network id {}".format(self.__class__.network_id))
718 time.sleep(5)
719 # after deleting network we check in network list
720 network_list = test_config["vim_conn"].get_network_list({ 'id':self.__class__.network_id })
721 self.assertEqual(network_list, [])
722
723 def test_010_delete_network_negative(self):
724 Non_exist_id = str(uuid.uuid4())
725
726 self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"],
727 self.__class__.test_index,
728 inspect.currentframe().f_code.co_name)
729 self.__class__.test_index += 1
730
731 with self.assertRaises(Exception) as context:
732 test_config["vim_conn"].delete_network(Non_exist_id)
733
tierno12a0c3b2018-10-15 15:10:36 +0200734 self.assertEqual((context.exception).http_code, 404)
kasarbd11fd82017-06-01 23:44:03 -0700735
tiernof0508352017-06-19 13:37:44 +0200736class test_vimconn_get_flavor(test_base):
kasarbd11fd82017-06-01 23:44:03 -0700737
738 def test_000_get_flavor(self):
739 test_directory_content = os.listdir(test_config["test_directory"])
740
741 for dir_name in test_directory_content:
742 if dir_name == 'simple_linux':
743 self.__class__.scenario_test_path = test_config["test_directory"] + '/'+ dir_name
744 vnfd_files = glob.glob(self.__class__.scenario_test_path+'/vnfd_*.yaml')
745 break
746
747 for vnfd in vnfd_files:
748 with open(vnfd, 'r') as stream:
749 vnf_descriptor = yaml.load(stream)
750
751 vnfc_list = vnf_descriptor['vnf']['VNFC']
752 for item in vnfc_list:
753 if 'ram' in item and 'vcpus' in item and 'disk' in item:
754 ram = item['ram']
755 vcpus = item['vcpus']
756 disk = item['disk']
757
anwarsc76a3ee2018-10-04 14:05:32 +0530758 flavor_data = {
759 'name' : _get_random_string(20),
760 'ram': ram,
kasarbd11fd82017-06-01 23:44:03 -0700761 'vcpus': vcpus,
762 'disk': disk
anwarsc76a3ee2018-10-04 14:05:32 +0530763 }
kasarbd11fd82017-06-01 23:44:03 -0700764
765 self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"],
766 self.__class__.test_index,
767 inspect.currentframe().f_code.co_name)
768 self.__class__.test_index += 1
769 # create new flavor
770 flavor_id = test_config["vim_conn"].new_flavor(flavor_data)
771 # get flavor by id
772 result = test_config["vim_conn"].get_flavor(flavor_id)
jamartinezv14a823d2019-08-01 11:45:15 +0200773
774 if test_config['vimtype'] != 'azure':
775 self.assertEqual(ram, result['ram'])
776 self.assertEqual(vcpus, result['vcpus'])
777 self.assertEqual(disk, result['disk'])
778 else:
779 self.assertTrue(ram <= result['ram'])
780 self.assertTrue(vcpus <= result['vcpus'])
781 self.assertTrue(disk <= result['disk'])
kasarbd11fd82017-06-01 23:44:03 -0700782
783 # delete flavor
jamartinezv14a823d2019-08-01 11:45:15 +0200784 if test_config['vimtype'] != 'azure':
785 result = test_config["vim_conn"].delete_flavor(flavor_id)
786 if result:
787 logger.info("Flavor id {} sucessfully deleted".format(result))
788 else:
789 logger.info("Failed to delete flavor id {}".format(result))
kasarbd11fd82017-06-01 23:44:03 -0700790
791 def test_010_get_flavor_negative(self):
792 Non_exist_flavor_id = str(uuid.uuid4())
793
794 self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"],
795 self.__class__.test_index,
796 inspect.currentframe().f_code.co_name)
797 self.__class__.test_index += 1
798
799 with self.assertRaises(Exception) as context:
800 test_config["vim_conn"].get_flavor(Non_exist_flavor_id)
801
802 self.assertEqual((context.exception).http_code, 404)
803
kasarfeaaa052017-06-08 03:46:18 -0700804class test_vimconn_new_flavor(test_base):
805 flavor_id = None
806
807 def test_000_new_flavor(self):
jamartinezv14a823d2019-08-01 11:45:15 +0200808 flavor_data = {'name': _get_random_string(20), 'ram': 1024, 'vcpus': 1, 'disk': 10}
kasarfeaaa052017-06-08 03:46:18 -0700809
810 self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"],
811 self.__class__.test_index,
812 inspect.currentframe().f_code.co_name)
813 self.__class__.test_index += 1
814
815 # create new flavor
kasar114050e2017-07-06 02:04:59 -0700816 self.__class__.flavor_id = test_config["vim_conn"].new_flavor(flavor_data)
anwarsc76a3ee2018-10-04 14:05:32 +0530817 self.assertIsInstance(self.__class__.flavor_id, (str, unicode))
818 self.assertIsInstance(uuid.UUID(self.__class__.flavor_id), uuid.UUID)
kasarfeaaa052017-06-08 03:46:18 -0700819
820 def test_010_delete_flavor(self):
821 self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"],
822 self.__class__.test_index,
823 inspect.currentframe().f_code.co_name)
824 self.__class__.test_index += 1
825
826 # delete flavor
jamartinezv14a823d2019-08-01 11:45:15 +0200827 if test_config['vimtype'] == 'azure':
828 with self.assertRaises(Exception) as context:
829 test_config["vim_conn"].delete_flavor(self.__class__.flavor_id)
830
831 self.assertEqual((context.exception).http_code, 401)
kasarfeaaa052017-06-08 03:46:18 -0700832 else:
jamartinezv14a823d2019-08-01 11:45:15 +0200833 result = test_config["vim_conn"].delete_flavor(self.__class__.flavor_id)
834 if result:
835 logger.info("Flavor id {} sucessfully deleted".format(result))
836 else:
837 logger.error("Failed to delete flavor id {}".format(result))
838 raise Exception ("Failed to delete created flavor")
kasarfeaaa052017-06-08 03:46:18 -0700839
840 def test_020_new_flavor_negative(self):
841 Invalid_flavor_data = {'ram': '1024', 'vcpus': 2.0, 'disk': 2.0}
842
843 self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"],
844 self.__class__.test_index,
845 inspect.currentframe().f_code.co_name)
846 self.__class__.test_index += 1
847
848 with self.assertRaises(Exception) as context:
849 test_config["vim_conn"].new_flavor(Invalid_flavor_data)
850
jamartinezv14a823d2019-08-01 11:45:15 +0200851 if test_config['vimtype'] == 'azure':
852 self.assertEqual((context.exception).http_code, 404)
853 else:
854 self.assertEqual((context.exception).http_code, 400)
kasarfeaaa052017-06-08 03:46:18 -0700855
856 def test_030_delete_flavor_negative(self):
857 Non_exist_flavor_id = str(uuid.uuid4())
858
859 self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"],
860 self.__class__.test_index,
861 inspect.currentframe().f_code.co_name)
862 self.__class__.test_index += 1
863
864 with self.assertRaises(Exception) as context:
865 test_config["vim_conn"].delete_flavor(Non_exist_flavor_id)
866
jamartinezv14a823d2019-08-01 11:45:15 +0200867 if test_config['vimtype'] == 'azure':
868 self.assertEqual((context.exception).http_code, 401)
869 else:
870 self.assertEqual((context.exception).http_code, 404)
kasarfeaaa052017-06-08 03:46:18 -0700871
872class test_vimconn_new_image(test_base):
873
874 def test_000_new_image(self):
875 self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"],
876 self.__class__.test_index,
877 inspect.currentframe().f_code.co_name)
878 self.__class__.test_index += 1
879
880 image_path = test_config['image_path']
881 if image_path:
jamartinezv14a823d2019-08-01 11:45:15 +0200882 self.__class__.image_id = test_config["vim_conn"].new_image({ 'name': 'TestImage', 'location' : image_path,
883 'metadata': {'upload_location':None} })
kasarc7053032017-08-03 03:29:23 -0700884 time.sleep(20)
shashankjain3c83a212018-10-04 13:05:46 +0530885
886 self.assertIsInstance(self.__class__.image_id, (str, unicode))
887 self.assertIsInstance(uuid.UUID(self.__class__.image_id), uuid.UUID)
kasarfeaaa052017-06-08 03:46:18 -0700888 else:
889 self.skipTest("Skipping test as image file not present at RO container")
890
891 def test_010_new_image_negative(self):
892 Non_exist_image_path = '/temp1/cirros.ovf'
893
894 self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"],
895 self.__class__.test_index,
896 inspect.currentframe().f_code.co_name)
897 self.__class__.test_index += 1
898
899 with self.assertRaises(Exception) as context:
shashankjain3c83a212018-10-04 13:05:46 +0530900 test_config["vim_conn"].new_image({ 'name': 'TestImage', 'location' : Non_exist_image_path})
kasarfeaaa052017-06-08 03:46:18 -0700901
902 self.assertEqual((context.exception).http_code, 400)
kasar70532ae2017-05-26 03:53:52 -0700903
kasarc7053032017-08-03 03:29:23 -0700904 def test_020_delete_image(self):
905 self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"],
906 self.__class__.test_index,
907 inspect.currentframe().f_code.co_name)
908 self.__class__.test_index += 1
909
910 image_id = test_config["vim_conn"].delete_image(self.__class__.image_id)
shashankjain3c83a212018-10-04 13:05:46 +0530911
912 self.assertIsInstance(image_id, (str, unicode))
kasarc7053032017-08-03 03:29:23 -0700913
914 def test_030_delete_image_negative(self):
915 Non_exist_image_id = str(uuid.uuid4())
916
917 self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"],
918 self.__class__.test_index,
919 inspect.currentframe().f_code.co_name)
920 self.__class__.test_index += 1
921
922 with self.assertRaises(Exception) as context:
923 test_config["vim_conn"].delete_image(Non_exist_image_id)
924
925 self.assertEqual((context.exception).http_code, 404)
926
kasarffdaf292017-06-23 04:06:52 -0700927class test_vimconn_get_image_id_from_path(test_base):
928
929 def test_000_get_image_id_from_path(self):
930 self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"],
931 self.__class__.test_index,
932 inspect.currentframe().f_code.co_name)
933 self.__class__.test_index += 1
934
935 image_path = test_config['image_path']
936 if image_path:
937 image_id = test_config["vim_conn"].get_image_id_from_path( image_path )
938 self.assertEqual(type(image_id),str)
939 else:
940 self.skipTest("Skipping test as image file not present at RO container")
941
942 def test_010_get_image_id_from_path_negative(self):
943 Non_exist_image_path = '/temp1/cirros.ovf'
944
945 self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"],
946 self.__class__.test_index,
947 inspect.currentframe().f_code.co_name)
948 self.__class__.test_index += 1
949
950 with self.assertRaises(Exception) as context:
951 test_config["vim_conn"].new_image({ 'name': 'TestImage', 'location' : Non_exist_image_path })
952
953 self.assertEqual((context.exception).http_code, 400)
954
955class test_vimconn_get_image_list(test_base):
956 image_name = None
957 image_id = None
958
959 def test_000_get_image_list(self):
960 self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"],
961 self.__class__.test_index,
962 inspect.currentframe().f_code.co_name)
963 self.__class__.test_index += 1
jamartinezv14a823d2019-08-01 11:45:15 +0200964
965 if test_config['image_name']:
966 image_list = test_config['vim_conn'].get_image_list({'name': test_config['image_name']})
967 else:
968 image_list = test_config["vim_conn"].get_image_list()
kasarffdaf292017-06-23 04:06:52 -0700969
970 for item in image_list:
971 if 'name' in item:
972 self.__class__.image_name = item['name']
973 self.__class__.image_id = item['id']
shashankjain3c83a212018-10-04 13:05:46 +0530974 self.assertIsInstance(self.__class__.image_name, (str, unicode))
975 self.assertIsInstance(self.__class__.image_id, (str, unicode))
kasarffdaf292017-06-23 04:06:52 -0700976
977 def test_010_get_image_list_by_name(self):
978 self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"],
979 self.__class__.test_index,
980 inspect.currentframe().f_code.co_name)
981 self.__class__.test_index += 1
982
983 image_list = test_config["vim_conn"].get_image_list({'name': self.__class__.image_name})
984
985 for item in image_list:
shashankjain3c83a212018-10-04 13:05:46 +0530986 self.assertIsInstance(item['id'], (str, unicode))
987 self.assertIsInstance(item['name'], (str, unicode))
kasarffdaf292017-06-23 04:06:52 -0700988 self.assertEqual(item['id'], self.__class__.image_id)
kasarffdaf292017-06-23 04:06:52 -0700989 self.assertEqual(item['name'], self.__class__.image_name)
990
991 def test_020_get_image_list_by_id(self):
992 self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"],
993 self.__class__.test_index,
994 inspect.currentframe().f_code.co_name)
995 self.__class__.test_index += 1
996
997 filter_image_list = test_config["vim_conn"].get_image_list({'id': self.__class__.image_id})
998
999 for item1 in filter_image_list:
shashankjain3c83a212018-10-04 13:05:46 +05301000 self.assertIsInstance(item1['id'], (str, unicode))
1001 self.assertIsInstance(item1['name'], (str, unicode))
1002 self.assertEqual(item1['id'], self.__class__.image_id)
1003 self.assertEqual(item1['name'], self.__class__.image_name)
kasarffdaf292017-06-23 04:06:52 -07001004
1005 def test_030_get_image_list_negative(self):
1006 Non_exist_image_id = uuid.uuid4()
1007 self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"],
1008 self.__class__.test_index,
1009 inspect.currentframe().f_code.co_name)
1010 self.__class__.test_index += 1
1011 image_list = test_config["vim_conn"].get_image_list({'name': 'Unknown_name', 'id': Non_exist_image_id})
1012
1013 self.assertIsNotNone(image_list, None)
1014 self.assertEqual(image_list, [])
1015
1016class test_vimconn_new_vminstance(test_base):
1017 network_name = None
1018 net_type = None
1019 network_id = None
1020 image_id = None
kasar114050e2017-07-06 02:04:59 -07001021 instance_id = None
kasarffdaf292017-06-23 04:06:52 -07001022
1023 def setUp(self):
1024 # create network
1025 self.__class__.network_name = _get_random_string(20)
1026 self.__class__.net_type = 'bridge'
1027
jamartinezv14a823d2019-08-01 11:45:15 +02001028 self.__class__.network_id, _ = test_config["vim_conn"].new_network(net_name=self.__class__.network_name,
kasarffdaf292017-06-23 04:06:52 -07001029 net_type=self.__class__.net_type)
kasarffdaf292017-06-23 04:06:52 -07001030 # find image name and image id
1031 if test_config['image_name']:
1032 image_list = test_config['vim_conn'].get_image_list({'name': test_config['image_name']})
1033 if len(image_list) == 0:
1034 raise Exception("Image {} is not found at VIM".format(test_config['image_name']))
1035 else:
1036 self.__class__.image_id = image_list[0]['id']
1037 else:
1038 image_list = test_config['vim_conn'].get_image_list()
1039 if len(image_list) == 0:
1040 raise Exception("Not found any image at VIM")
1041 else:
1042 self.__class__.image_id = image_list[0]['id']
1043
kasarffdaf292017-06-23 04:06:52 -07001044 def tearDown(self):
1045 test_base.tearDown(self)
1046 # Deleting created network
1047 result = test_config["vim_conn"].delete_network(self.__class__.network_id)
1048 if result:
1049 logger.info("Network id {} sucessfully deleted".format(self.__class__.network_id))
1050 else:
1051 logger.info("Failed to delete network id {}".format(self.__class__.network_id))
1052
1053 def test_000_new_vminstance(self):
1054 vpci = "0000:00:11.0"
1055 name = "eth0"
1056
kokardekar430e62f2018-10-04 14:27:09 +05301057 flavor_data = {'name': _get_random_string(20), 'ram': 1024, 'vcpus': 1, 'disk': 10}
kasarffdaf292017-06-23 04:06:52 -07001058
1059 # create new flavor
1060 flavor_id = test_config["vim_conn"].new_flavor(flavor_data)
1061
kasarffdaf292017-06-23 04:06:52 -07001062
1063 self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"],
1064 self.__class__.test_index,
1065 inspect.currentframe().f_code.co_name)
1066 self.__class__.test_index += 1
1067
jamartinezv14a823d2019-08-01 11:45:15 +02001068 net_list = [{'use': self.__class__.net_type, 'name': name, 'floating_ip': False, 'vpci': vpci,
1069 'port_security': True, 'type': 'virtual', 'net_id': self.__class__.network_id}]
kasarffdaf292017-06-23 04:06:52 -07001070
jamartinezv14a823d2019-08-01 11:45:15 +02001071 self.__class__.instance_id, _ = test_config["vim_conn"].new_vminstance(name='Test1_vm', description='',
1072 start=False,
1073 image_id=self.__class__.image_id,
1074 flavor_id=flavor_id, net_list=net_list)
kasarffdaf292017-06-23 04:06:52 -07001075
kokardekar430e62f2018-10-04 14:27:09 +05301076 self.assertIsInstance(self.__class__.instance_id, (str, unicode))
kasarffdaf292017-06-23 04:06:52 -07001077
1078 def test_010_new_vminstance_by_model(self):
kokardekar430e62f2018-10-04 14:27:09 +05301079 flavor_data = {'name': _get_random_string(20),'ram': 1024, 'vcpus': 2, 'disk': 10}
kasarffdaf292017-06-23 04:06:52 -07001080 model_name = 'e1000'
1081 name = 'eth0'
1082
1083 # create new flavor
1084 flavor_id = test_config["vim_conn"].new_flavor(flavor_data)
1085
1086 self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"],
1087 self.__class__.test_index,
1088 inspect.currentframe().f_code.co_name)
1089 self.__class__.test_index += 1
1090
jamartinezv14a823d2019-08-01 11:45:15 +02001091 net_list = [{'use': self.__class__.net_type, 'name': name, 'floating_ip': False, 'port_security': True,
1092 'model': model_name, 'type': 'virtual', 'net_id': self.__class__.network_id}]
kasarffdaf292017-06-23 04:06:52 -07001093
jamartinezv14a823d2019-08-01 11:45:15 +02001094 instance_id, _ = test_config["vim_conn"].new_vminstance(name='Test1_vm', description='', start=False,
1095 image_id=self.__class__.image_id,
1096 flavor_id=flavor_id,net_list=net_list)
kokardekar430e62f2018-10-04 14:27:09 +05301097
1098 self.assertIsInstance(instance_id, (str, unicode))
1099
kasarffdaf292017-06-23 04:06:52 -07001100 # Deleting created vm instance
1101 logger.info("Deleting created vm intance")
1102 test_config["vim_conn"].delete_vminstance(instance_id)
1103 time.sleep(10)
1104
1105 def test_020_new_vminstance_by_net_use(self):
kokardekar430e62f2018-10-04 14:27:09 +05301106 flavor_data = {'name': _get_random_string(20),'ram': 1024, 'vcpus': 2, 'disk': 10}
kasarffdaf292017-06-23 04:06:52 -07001107 net_use = 'data'
1108 name = 'eth0'
1109
1110 # create new flavor
1111 flavor_id = test_config["vim_conn"].new_flavor(flavor_data)
1112
1113 self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"],
1114 self.__class__.test_index,
1115 inspect.currentframe().f_code.co_name)
1116 self.__class__.test_index += 1
1117
jamartinezv14a823d2019-08-01 11:45:15 +02001118 net_list = [{'use': net_use, 'name': name, 'floating_ip': False, 'port_security': True, 'type': 'virtual',
1119 'net_id': self.__class__.network_id}]
kasarffdaf292017-06-23 04:06:52 -07001120
jamartinezv14a823d2019-08-01 11:45:15 +02001121 instance_id, _ = test_config["vim_conn"].new_vminstance(name='Test1_vm', description='', start=False,
1122 image_id=self.__class__.image_id,disk_list=None,
1123 flavor_id=flavor_id, net_list=net_list)
kokardekar430e62f2018-10-04 14:27:09 +05301124 self.assertIsInstance(instance_id, (str, unicode))
1125
kasarffdaf292017-06-23 04:06:52 -07001126 # Deleting created vm instance
1127 logger.info("Deleting created vm intance")
1128 test_config["vim_conn"].delete_vminstance(instance_id)
1129 time.sleep(10)
1130
1131 def test_030_new_vminstance_by_net_type(self):
kokardekar430e62f2018-10-04 14:27:09 +05301132 flavor_data = {'name':_get_random_string(20),'ram': 1024, 'vcpus': 2, 'disk': 10}
kasarffdaf292017-06-23 04:06:52 -07001133 _type = 'VF'
1134 name = 'eth0'
1135
1136 # create new flavor
1137 flavor_id = test_config["vim_conn"].new_flavor(flavor_data)
1138
1139 self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"],
1140 self.__class__.test_index,
1141 inspect.currentframe().f_code.co_name)
1142 self.__class__.test_index += 1
1143
kokardekar430e62f2018-10-04 14:27:09 +05301144 if test_config['vimtype'] == 'vmware':
1145 net_list = [{'use': self.__class__.net_type, 'name': name, 'floating_ip': False, 'port_security': True,
1146 'type': _type, 'net_id': self.__class__.network_id}]
kasarffdaf292017-06-23 04:06:52 -07001147
kokardekar430e62f2018-10-04 14:27:09 +05301148 instance_id, _ = test_config["vim_conn"].new_vminstance(name='Test1_vm', image_id=self.__class__.image_id,
1149 flavor_id=flavor_id,
1150 net_list=net_list)
1151 self.assertEqual(type(instance_id),str)
1152
jamartinezv14a823d2019-08-01 11:45:15 +02001153 if test_config['vimtype'] in ('openstack', 'azure'):
kokardekar430e62f2018-10-04 14:27:09 +05301154 # create network of type data
1155 network_name = _get_random_string(20)
1156 net_type = 'data'
1157
jamartinezv14a823d2019-08-01 11:45:15 +02001158 network_id, _ = test_config["vim_conn"].new_network(net_name=network_name,
kokardekar430e62f2018-10-04 14:27:09 +05301159 net_type=net_type)
1160 net_list = [{'use': net_type, 'name': name, 'floating_ip': False, 'port_security': True,
1161 'type': _type, 'net_id': network_id}]
1162
1163 instance_id, _ = test_config["vim_conn"].new_vminstance(name='Test1_vm', description='', start=False,
jamartinezv14a823d2019-08-01 11:45:15 +02001164 image_id=self.__class__.image_id, disk_list=None,
1165 flavor_id=flavor_id,
1166 net_list=net_list)
kokardekar430e62f2018-10-04 14:27:09 +05301167
1168 self.assertEqual(type(instance_id), unicode)
1169
1170 # delete created network
1171 result = test_config["vim_conn"].delete_network(network_id)
1172 if result:
1173 logger.info("Network id {} sucessfully deleted".format(network_id))
1174 else:
1175 logger.info("Failed to delete network id {}".format(network_id))
1176
kasarffdaf292017-06-23 04:06:52 -07001177 # Deleting created vm instance
1178 logger.info("Deleting created vm intance")
1179 test_config["vim_conn"].delete_vminstance(instance_id)
1180 time.sleep(10)
1181
1182 def test_040_new_vminstance_by_cloud_config(self):
kokardekar430e62f2018-10-04 14:27:09 +05301183 flavor_data = {'name': _get_random_string(20),'ram': 1024, 'vcpus': 2, 'disk': 10}
kasarffdaf292017-06-23 04:06:52 -07001184 name = 'eth0'
1185 user_name = 'test_user'
1186
jamartinezv14a823d2019-08-01 11:45:15 +02001187 key_pairs = ['ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDtAjl5R+GSKP3gFrdFxgizKEUzhXKQbyjaxJH9thsK 0/fDiYlaNEjvijgPgiVZkfwvqgWeLprPcpzL2j4jvmmSJ3+7C8ihCwObWP0VUiuewmbIINBPAR0RqusjMRyPsa+q0asFBPOoZLx3Cv3vzmC1AA3mKuCNeT EuA0rlWhDIOVwMcU5sP1grnmuexQB8HcR7BdKcA9y08pTwnCQR8vmtW77SRkaxEGXm4Gnw5qw8Z27mHdk2wWS2SnbVH7aFwWvDXc6jjf5TpEWypdr/EAPC +eJipeS2Oa4FsntEqAu3Fz6gp/9ub8uNqgCgHfMzs6FhYpZpipwS0hXYyF6eVsSx osm@osm']
kasarffdaf292017-06-23 04:06:52 -07001188
jamartinezv14a823d2019-08-01 11:45:15 +02001189 users_data = [{'key-pairs': ['ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDtAjl5R+GSKP3gFrdFxgizKEUzhXKQbyjaxJH9thsK0/fDiYlaNEjvijgPgiVZkfwvqgWeLprPcpzL2j4jvmmSJ3+7C8ihCwObWP0VUiuewmbIINBPAR0RqusjMRyPsa+q0asFBPOoZLx3Cv3vzmC1AA3mKuCNeTEuA0rlWhDIOVwMcU5sP1grnmuexQB8HcR7BdKcA9y08pTwnCQR8vmtW77SRkaxEGXm4Gnw5qw8Z27mHdk2wWS2SnbVH7aFwWvDXc6jjf5TpEWypdr/EAPC+eJipeS2Oa4FsntEqAu3Fz6gp/9ub8uNqgCgHfMzs6FhYpZpipwS0hXYyF6eVsSx osm@osm'], 'name': 'cloudinit'}]
kasarffdaf292017-06-23 04:06:52 -07001190
1191 cloud_data = {'config-files': [{'content': 'auto enp0s3\niface enp0s3 inet dhcp\n', 'dest': '/etc/network/interfaces.d/enp0s3.cfg', 'owner': 'root:root', 'permissions': '0644'}, {'content': '#! /bin/bash\nls -al >> /var/log/osm.log\n', 'dest': '/etc/rc.local', 'permissions': '0755'}, {'content': 'file content', 'dest': '/etc/test_delete'}], 'boot-data-drive': True, 'key-pairs': key_pairs, 'users': users_data }
jamartinezv14a823d2019-08-01 11:45:15 +02001192 #cloud_data = {'users': users_data }
kasarffdaf292017-06-23 04:06:52 -07001193
1194 # create new flavor
1195 flavor_id = test_config["vim_conn"].new_flavor(flavor_data)
1196
1197 self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"],
1198 self.__class__.test_index,
1199 inspect.currentframe().f_code.co_name)
1200 self.__class__.test_index += 1
1201
jamartinezv14a823d2019-08-01 11:45:15 +02001202 net_list = [{'use': self.__class__.net_type, 'name': name, 'floating_ip': False, 'port_security': True,
1203 'type': 'virtual', 'net_id': self.__class__.network_id}]
kasarffdaf292017-06-23 04:06:52 -07001204
kokardekar430e62f2018-10-04 14:27:09 +05301205 instance_id, _ = test_config["vim_conn"].new_vminstance(name='Cloud_vm', description='', start=False,
jamartinezv14a823d2019-08-01 11:45:15 +02001206 image_id=self.__class__.image_id,
1207 flavor_id=flavor_id,net_list=net_list,
1208 cloud_config=cloud_data)
kokardekar430e62f2018-10-04 14:27:09 +05301209
1210 self.assertIsInstance(instance_id, (str, unicode))
1211
kasarffdaf292017-06-23 04:06:52 -07001212 # Deleting created vm instance
1213 logger.info("Deleting created vm intance")
1214 test_config["vim_conn"].delete_vminstance(instance_id)
1215 time.sleep(10)
1216
1217 def test_050_new_vminstance_by_disk_list(self):
kokardekar430e62f2018-10-04 14:27:09 +05301218 flavor_data = {'name':_get_random_string(20),'ram': 1024, 'vcpus': 2, 'disk': 10}
kasarffdaf292017-06-23 04:06:52 -07001219 name = 'eth0'
1220
kokardekar430e62f2018-10-04 14:27:09 +05301221 device_data = [{'image_id': self.__class__.image_id, 'size': '10'}]
kasarffdaf292017-06-23 04:06:52 -07001222
1223 # create new flavor
1224 flavor_id = test_config["vim_conn"].new_flavor(flavor_data)
1225
1226 self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"],
1227 self.__class__.test_index,
1228 inspect.currentframe().f_code.co_name)
1229 self.__class__.test_index += 1
1230
jamartinezv14a823d2019-08-01 11:45:15 +02001231 net_list = [{'use': self.__class__.net_type, 'name': name, 'floating_ip': False, 'port_security': True,
1232 'type': 'virtual', 'net_id': self.__class__.network_id}]
kasarffdaf292017-06-23 04:06:52 -07001233
jamartinezv14a823d2019-08-01 11:45:15 +02001234 instance_id, _ = test_config["vim_conn"].new_vminstance(name='VM_test1', description='', start=False,
1235 image_id=self.__class__.image_id,
1236 flavor_id=flavor_id, net_list=net_list,
1237 disk_list=device_data)
kokardekar430e62f2018-10-04 14:27:09 +05301238
1239 self.assertIsInstance(instance_id, (str, unicode))
kasarffdaf292017-06-23 04:06:52 -07001240 # Deleting created vm instance
1241 logger.info("Deleting created vm intance")
1242 test_config["vim_conn"].delete_vminstance(instance_id)
1243 time.sleep(10)
1244
1245 def test_060_new_vminstance_negative(self):
1246 unknown_flavor_id = str(uuid.uuid4())
1247 unknown_image_id = str(uuid.uuid4())
1248 name = 'eth2'
1249
1250 self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"],
1251 self.__class__.test_index,
1252 inspect.currentframe().f_code.co_name)
1253 self.__class__.test_index += 1
1254
jamartinezv14a823d2019-08-01 11:45:15 +02001255 net_list = [{'use': self.__class__.net_type, 'name': name, 'floating_ip': False, 'port_security': True,
1256 'type': 'virtual', 'net_id': self.__class__.network_id}]
kasarffdaf292017-06-23 04:06:52 -07001257
1258 with self.assertRaises(Exception) as context:
jamartinezv14a823d2019-08-01 11:45:15 +02001259 test_config["vim_conn"].new_vminstance(name='Test1_vm', description='', start=False,
1260 image_id=unknown_image_id,
1261 flavor_id=unknown_flavor_id,
1262 net_list=net_list)
kokardekar430e62f2018-10-04 14:27:09 +05301263
1264 self.assertIn((context.exception).http_code, (400, 404))
1265
kasarffdaf292017-06-23 04:06:52 -07001266
kasar114050e2017-07-06 02:04:59 -07001267 def test_070_get_vminstance(self):
1268 self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"],
1269 self.__class__.test_index,
1270 inspect.currentframe().f_code.co_name)
1271 self.__class__.test_index += 1
1272
1273 # Get instance by its id
1274 vm_info = test_config["vim_conn"].get_vminstance(self.__class__.instance_id)
1275
1276 if test_config['vimtype'] == 'vmware':
1277 for attr in vm_info:
1278 if attr == 'status':
1279 self.assertEqual(vm_info[attr], 'ACTIVE')
1280 if attr == 'hostId':
1281 self.assertEqual(type(vm_info[attr]), str)
1282 if attr == 'interfaces':
1283 self.assertEqual(type(vm_info[attr]), list)
1284 self.assertEqual(vm_info[attr][0]['IsConnected'], 'true')
1285 if attr == 'IsEnabled':
1286 self.assertEqual(vm_info[attr], 'true')
1287
1288 def test_080_get_vminstance_negative(self):
1289 unknown_instance_id = str(uuid.uuid4())
1290
1291 self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"],
1292 self.__class__.test_index,
1293 inspect.currentframe().f_code.co_name)
1294 self.__class__.test_index += 1
1295
1296 with self.assertRaises(Exception) as context:
1297 test_config["vim_conn"].get_vminstance(unknown_instance_id)
1298
1299 self.assertEqual((context.exception).http_code, 404)
1300
1301 def test_090_refresh_vms_status(self):
1302 self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"],
1303 self.__class__.test_index,
1304 inspect.currentframe().f_code.co_name)
1305 self.__class__.test_index += 1
kasar114050e2017-07-06 02:04:59 -07001306
kokardekar430e62f2018-10-04 14:27:09 +05301307 if test_config['vimtype'] == 'vmware':
1308 vm_list = []
1309 vm_list.append(self.__class__.instance_id)
1310
1311 # refresh vm status
1312 vm_info = test_config["vim_conn"].refresh_vms_status(vm_list)
1313 for attr in vm_info[self.__class__.instance_id]:
1314 if attr == 'status':
1315 self.assertEqual(vm_info[self.__class__.instance_id][attr], 'ACTIVE')
1316 if attr == 'interfaces':
1317 self.assertEqual(type(vm_info[self.__class__.instance_id][attr]), list)
1318
jamartinezv14a823d2019-08-01 11:45:15 +02001319 if test_config['vimtype'] in ('openstack', 'azure'):
kokardekar430e62f2018-10-04 14:27:09 +05301320 vpci = "0000:00:11.0"
1321 name = "eth0"
1322
1323 flavor_data = {'name': _get_random_string(20), 'ram': 1024, 'vcpus': 1, 'disk': 10}
1324
1325 # create new flavor
1326 flavor_id = test_config["vim_conn"].new_flavor(flavor_data)
1327 # create new vm instance
jamartinezv14a823d2019-08-01 11:45:15 +02001328 net_list = [{'use': self.__class__.net_type, 'name': name, 'floating_ip': False, 'vpci': vpci,
1329 'port_security': True, 'type': 'virtual', 'net_id': self.__class__.network_id}]
kokardekar430e62f2018-10-04 14:27:09 +05301330
jamartinezv14a823d2019-08-01 11:45:15 +02001331 instance_id, _ = test_config["vim_conn"].new_vminstance(name='Test1_vm', description='', start=False,
1332 image_id=self.__class__.image_id,
1333 flavor_id=flavor_id, net_list=net_list)
kokardekar430e62f2018-10-04 14:27:09 +05301334
1335 time.sleep(30)
1336 vm_list = []
1337 vm_list.append(instance_id)
1338
1339 # refresh vm status
1340 vm_info = test_config["vim_conn"].refresh_vms_status(vm_list)
1341 for attr in vm_info[instance_id]:
1342 if attr == 'status':
1343 self.assertEqual(vm_info[instance_id][attr], 'ACTIVE')
1344 if attr == 'interfaces':
1345 self.assertEqual(type(vm_info[instance_id][attr]), list)
1346
1347 #Deleting created vm instance
1348 logger.info("Deleting created vm intance")
1349 test_config["vim_conn"].delete_vminstance(instance_id)
1350 time.sleep(10)
1351
kasar114050e2017-07-06 02:04:59 -07001352
1353 def test_100_refresh_vms_status_negative(self):
1354 unknown_id = str(uuid.uuid4())
1355
1356 self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"],
1357 self.__class__.test_index,
1358 inspect.currentframe().f_code.co_name)
1359 self.__class__.test_index += 1
1360
1361 vm_dict = test_config["vim_conn"].refresh_vms_status([unknown_id])
kokardekar430e62f2018-10-04 14:27:09 +05301362
1363 if test_config['vimtype'] == 'vmware':
1364 self.assertEqual(vm_dict,{})
1365
jamartinezv14a823d2019-08-01 11:45:15 +02001366 if test_config['vimtype'] in ('openstack', 'azure'):
kokardekar430e62f2018-10-04 14:27:09 +05301367 self.assertEqual(vm_dict[unknown_id]['status'], 'DELETED')
kasar114050e2017-07-06 02:04:59 -07001368
1369 def test_110_action_vminstance(self):
1370 self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"],
1371 self.__class__.test_index,
1372 inspect.currentframe().f_code.co_name)
1373 self.__class__.test_index += 1
1374
kokardekar430e62f2018-10-04 14:27:09 +05301375 if test_config['vimtype'] == 'vmware':
1376 action_list = ['shutdown', 'start', 'shutoff', 'rebuild', 'pause', 'resume']
1377 # various action on vminstace
1378 for action in action_list:
1379 instance_id = test_config["vim_conn"].action_vminstance(self.__class__.instance_id,
1380 {action: None})
1381 self.assertEqual(instance_id, self.__class__.instance_id)
1382
jamartinezv14a823d2019-08-01 11:45:15 +02001383 if test_config['vimtype'] in ('openstack', 'azure'):
kokardekar430e62f2018-10-04 14:27:09 +05301384 # create new vm instance
1385 vpci = "0000:00:11.0"
1386 name = "eth0"
1387
1388 flavor_data = {'name': _get_random_string(20), 'ram': 1024, 'vcpus': 1, 'disk': 10}
1389
1390 # create new flavor
1391 flavor_id = test_config["vim_conn"].new_flavor(flavor_data)
1392
jamartinezv14a823d2019-08-01 11:45:15 +02001393 net_list = [{'use': self.__class__.net_type, 'name': name, 'floating_ip': False, 'vpci': vpci,
1394 'port_security': True, 'type': 'virtual', 'net_id': self.__class__.network_id}]
kokardekar430e62f2018-10-04 14:27:09 +05301395
jamartinezv14a823d2019-08-01 11:45:15 +02001396 new_instance_id, _ = test_config["vim_conn"].new_vminstance(name='Test1_vm', description='',
1397 start=False, image_id=self.__class__.image_id,
1398 flavor_id=flavor_id, net_list=net_list)
kokardekar430e62f2018-10-04 14:27:09 +05301399
jamartinezv14a823d2019-08-01 11:45:15 +02001400 if test_config['vimtype'] == 'openstack':
1401 action_list = ['shutdown','start','shutoff','rebuild','start','pause','start']
1402 else:
1403 action_list = ['shutdown','start','stop','start','shutoff','start','reboot']
kokardekar430e62f2018-10-04 14:27:09 +05301404
1405 # various action on vminstace
1406 for action in action_list:
1407 # sleep for sometime till status is changed
1408 time.sleep(25)
jamartinezv14a823d2019-08-01 11:45:15 +02001409 instance_id = test_config["vim_conn"].action_vminstance(new_instance_id, {action: None})
kokardekar430e62f2018-10-04 14:27:09 +05301410
1411 self.assertTrue(instance_id is None)
1412
jamartinezv14a823d2019-08-01 11:45:15 +02001413 #Deleting created vm instance
kokardekar430e62f2018-10-04 14:27:09 +05301414 logger.info("Deleting created vm intance")
1415 test_config["vim_conn"].delete_vminstance(new_instance_id)
1416 time.sleep(10)
kasar114050e2017-07-06 02:04:59 -07001417
1418 def test_120_action_vminstance_negative(self):
1419 non_exist_id = str(uuid.uuid4())
1420 self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"],
1421 self.__class__.test_index,
1422 inspect.currentframe().f_code.co_name)
1423 self.__class__.test_index += 1
1424
1425 action = 'start'
1426 with self.assertRaises(Exception) as context:
1427 test_config["vim_conn"].action_vminstance(non_exist_id, { action: None})
1428
kokardekar430e62f2018-10-04 14:27:09 +05301429 self.assertEqual((context.exception).http_code, 404)
1430
kasar114050e2017-07-06 02:04:59 -07001431
1432 def test_130_delete_vminstance(self):
1433 self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"],
1434 self.__class__.test_index,
1435 inspect.currentframe().f_code.co_name)
1436 self.__class__.test_index += 1
1437
1438 # Deleting created vm instance
1439 logger.info("Deleting created vm instance")
1440 test_config["vim_conn"].delete_vminstance(self.__class__.instance_id)
1441 time.sleep(10)
1442
Ravi Chamarty59d24362018-11-22 01:22:16 +00001443 def test_140_new_vminstance_sriov(self):
1444 logger.info("Testing creation of sriov vm instance using {}".format(test_config['sriov_net_name']))
1445 flavor_data = {'name': _get_random_string(20),'ram': 1024, 'vcpus': 2, 'disk': 10}
1446 name = 'eth0'
1447
1448 # create new flavor
1449 flavor_id = test_config["vim_conn"].new_flavor(flavor_data)
1450
1451 self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"],
1452 self.__class__.test_index,
1453 inspect.currentframe().f_code.co_name)
1454 self.__class__.test_index += 1
1455
1456 sriov_net_name = test_config['sriov_net_name']
1457 new_network_list = test_config["vim_conn"].get_network_list({'name': sriov_net_name})
1458 for list_item in new_network_list:
1459 self.assertEqual(sriov_net_name, list_item.get('name'))
1460 self.__class__.sriov_network_id = list_item.get('id')
1461
jamartinezv14a823d2019-08-01 11:45:15 +02001462 net_list = [{'use': 'data', 'name': name, 'floating_ip': False, 'port_security': True, 'type': 'VF',
1463 'net_id': self.__class__.sriov_network_id}]
Ravi Chamarty59d24362018-11-22 01:22:16 +00001464
jamartinezv14a823d2019-08-01 11:45:15 +02001465 instance_id, _ = test_config["vim_conn"].new_vminstance(name='Test1_sriov_vm', description='', start=False,
1466 image_id=self.__class__.image_id, flavor_id=flavor_id,
1467 net_list=net_list)
Ravi Chamarty59d24362018-11-22 01:22:16 +00001468
1469 self.assertIsInstance(instance_id, (str, unicode))
1470
1471 logger.info("Waiting for created sriov-vm intance")
1472 time.sleep(10)
1473 # Deleting created vm instance
1474 logger.info("Deleting created sriov-vm intance")
1475 test_config["vim_conn"].delete_vminstance(instance_id)
1476 time.sleep(10)
1477
kasarf358ad52017-07-24 01:28:44 -07001478class test_vimconn_get_tenant_list(test_base):
1479 tenant_id = None
1480
1481 def test_000_get_tenant_list(self):
1482 self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"],
1483 self.__class__.test_index,
1484 inspect.currentframe().f_code.co_name)
1485 self.__class__.test_index += 1
1486
1487 # Getting tenant list
1488 tenant_list = test_config["vim_conn"].get_tenant_list()
1489
1490 for item in tenant_list:
1491 if test_config['tenant'] == item['name']:
1492 self.__class__.tenant_id = item['id']
shashankjain3c83a212018-10-04 13:05:46 +05301493 self.assertIsInstance(item['name'], (str, unicode))
1494 self.assertIsInstance(item['id'], (str, unicode))
kasarf358ad52017-07-24 01:28:44 -07001495
1496 def test_010_get_tenant_list_by_id(self):
1497 self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"],
1498 self.__class__.test_index,
1499 inspect.currentframe().f_code.co_name)
1500 self.__class__.test_index += 1
1501
1502 # Getting filter tenant list by its id
1503 filter_tenant_list = test_config["vim_conn"].get_tenant_list({'id': self.__class__.tenant_id})
1504
1505 for item in filter_tenant_list:
shashankjain3c83a212018-10-04 13:05:46 +05301506 self.assertIsInstance(item['id'], (str, unicode))
kasarf358ad52017-07-24 01:28:44 -07001507 self.assertEqual(item['id'], self.__class__.tenant_id)
1508
1509 def test_020_get_tenant_list_by_name(self):
1510 self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"],
1511 self.__class__.test_index,
1512 inspect.currentframe().f_code.co_name)
1513 self.__class__.test_index += 1
1514
1515 # Getting filter tenant list by its name
1516 filter_tenant_list = test_config["vim_conn"].get_tenant_list({'name': test_config['tenant']})
1517
1518 for item in filter_tenant_list:
shashankjain3c83a212018-10-04 13:05:46 +05301519 self.assertIsInstance(item['name'], (str, unicode))
kasarf358ad52017-07-24 01:28:44 -07001520 self.assertEqual(item['name'], test_config['tenant'])
1521
1522 def test_030_get_tenant_list_by_name_and_id(self):
1523 self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"],
1524 self.__class__.test_index,
1525 inspect.currentframe().f_code.co_name)
1526 self.__class__.test_index += 1
1527
1528 # Getting filter tenant list by its name and id
1529 filter_tenant_list = test_config["vim_conn"].get_tenant_list({'name': test_config['tenant'],
1530 'id': self.__class__.tenant_id})
1531
1532 for item in filter_tenant_list:
shashankjain3c83a212018-10-04 13:05:46 +05301533 self.assertIsInstance(item['name'], (str, unicode))
1534 self.assertIsInstance(item['id'], (str, unicode))
kasarf358ad52017-07-24 01:28:44 -07001535 self.assertEqual(item['name'], test_config['tenant'])
1536 self.assertEqual(item['id'], self.__class__.tenant_id)
1537
1538 def test_040_get_tenant_list_negative(self):
1539 non_exist_tenant_name = "Tenant_123"
1540 non_exist_tenant_id = "kjhgrt456-45345kjhdfgnbdk-34dsfjdfg"
1541 self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"],
1542 self.__class__.test_index,
1543 inspect.currentframe().f_code.co_name)
1544 self.__class__.test_index += 1
1545
1546 filter_tenant_list = test_config["vim_conn"].get_tenant_list({'name': non_exist_tenant_name,
1547 'id': non_exist_tenant_id})
1548
1549 self.assertEqual(filter_tenant_list, [])
1550
shashankjain3c83a212018-10-04 13:05:46 +05301551
kasar55f70852017-07-31 01:25:55 -07001552class test_vimconn_new_tenant(test_base):
1553 tenant_id = None
1554
1555 def test_000_new_tenant(self):
1556 tenant_name = _get_random_string(20)
1557 self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"],
1558 self.__class__.test_index,
1559 inspect.currentframe().f_code.co_name)
1560 self.__class__.test_index += 1
1561
jamartinezv14a823d2019-08-01 11:45:15 +02001562 if test_config['vimtype'] != 'azure':
1563 self.__class__.tenant_id = test_config["vim_conn"].new_tenant(tenant_name, "")
1564 time.sleep(15)
kasar55f70852017-07-31 01:25:55 -07001565
jamartinezv14a823d2019-08-01 11:45:15 +02001566 self.assertIsInstance(self.__class__.tenant_id, (str, unicode))
1567 else:
1568 with self.assertRaises(Exception) as context:
1569 test_config["vim_conn"].new_tenant(self.__class__.tenant_id)
1570 self.assertEqual((context.exception).http_code, 401)
shashankjain3c83a212018-10-04 13:05:46 +05301571
kasar55f70852017-07-31 01:25:55 -07001572
1573 def test_010_new_tenant_negative(self):
1574 Invalid_tenant_name = 10121
1575 self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"],
1576 self.__class__.test_index,
1577 inspect.currentframe().f_code.co_name)
1578 self.__class__.test_index += 1
1579
1580 with self.assertRaises(Exception) as context:
shashankjain3c83a212018-10-04 13:05:46 +05301581 test_config["vim_conn"].new_tenant(Invalid_tenant_name, "")
kasar55f70852017-07-31 01:25:55 -07001582
jamartinezv14a823d2019-08-01 11:45:15 +02001583 if test_config['vimtype'] != 'azure':
1584 self.assertEqual((context.exception).http_code, 400)
1585 else:
1586 self.assertEqual((context.exception).http_code, 401)
kasar55f70852017-07-31 01:25:55 -07001587
shashankjain3c83a212018-10-04 13:05:46 +05301588
kasar55f70852017-07-31 01:25:55 -07001589 def test_020_delete_tenant(self):
1590 self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"],
1591 self.__class__.test_index,
1592 inspect.currentframe().f_code.co_name)
1593 self.__class__.test_index += 1
1594
jamartinezv14a823d2019-08-01 11:45:15 +02001595 if test_config['vimtype'] != 'azure':
1596 tenant_id = test_config["vim_conn"].delete_tenant(self.__class__.tenant_id)
1597 self.assertIsInstance(tenant_id, (str, unicode))
1598 else:
1599 with self.assertRaises(Exception) as context:
1600 test_config["vim_conn"].delete_tenant(self.__class__.tenant_id)
1601 self.assertEqual((context.exception).http_code, 401)
kasar55f70852017-07-31 01:25:55 -07001602
1603 def test_030_delete_tenant_negative(self):
1604 Non_exist_tenant_name = 'Test_30_tenant'
1605 self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"],
1606 self.__class__.test_index,
1607 inspect.currentframe().f_code.co_name)
1608 self.__class__.test_index += 1
1609
1610 with self.assertRaises(Exception) as context:
1611 test_config["vim_conn"].delete_tenant(Non_exist_tenant_name)
1612
jamartinezv14a823d2019-08-01 11:45:15 +02001613 if test_config['vimtype'] != 'azure':
1614 self.assertEqual((context.exception).http_code, 404)
1615 else:
1616 self.assertEqual((context.exception).http_code, 401)
kasarf358ad52017-07-24 01:28:44 -07001617
tiernoed854572017-10-03 16:18:09 +02001618
kasar532f8c22018-10-12 02:25:31 -07001619def get_image_id():
1620 if test_config['image_name']:
1621 image_list = test_config['vim_conn'].get_image_list({'name': test_config['image_name']})
1622 if len(image_list) == 0:
1623 raise Exception("Image {} is not found at VIM".format(test_config['image_name']))
1624 else:
1625 image_id = image_list[0]['id']
1626 else:
1627 image_list = test_config['vim_conn'].get_image_list()
1628 if len(image_list) == 0:
1629 raise Exception("Not found any image at VIM")
1630 else:
1631 image_id = image_list[0]['id']
1632 return image_id
1633
1634
1635class test_vimconn_vminstance_by_ip_address(test_base):
1636 network_name = None
1637 network_id = None
1638
1639 def setUp(self):
1640 # create network
1641 self.network_name = _get_random_string(20)
1642
jamartinezv14a823d2019-08-01 11:45:15 +02001643 self.network_id, _ = test_config["vim_conn"].new_network(net_name=self.network_name,
kasar532f8c22018-10-12 02:25:31 -07001644 net_type='bridge')
1645
1646 def tearDown(self):
1647 test_base.tearDown(self)
1648 # Deleting created network
1649 result = test_config["vim_conn"].delete_network(self.network_id)
1650 if result:
1651 logger.info("Network id {} sucessfully deleted".format(self.network_id))
1652 else:
1653 logger.info("Failed to delete network id {}".format(self.network_id))
1654
1655
1656 def test_000_vminstance_by_ip_address(self):
1657 """
1658 This test case will deploy VM with provided IP address
1659 Pre-requesite: provided IP address should be from IP pool range which has used for network creation
1660 """
1661 name = "eth0"
1662 # provide ip address
1663 ip_address = ''
1664
1665 flavor_data = {'ram': 1024, 'vcpus': 1, 'disk': 10}
1666
1667 # create new flavor
1668 flavor_id = test_config["vim_conn"].new_flavor(flavor_data)
1669
1670 # find image id
1671 image_id = get_image_id()
1672
1673 self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"],
1674 self.__class__.test_index,
1675 inspect.currentframe().f_code.co_name)
1676 self.__class__.test_index += 1
1677
1678 net_list = [{'use': 'bridge', 'name': name, 'floating_ip': False, 'port_security': True, 'type': 'virtual',
1679 'net_id': self.network_id, 'ip_address': ip_address}]
1680
1681 instance_id, _ = test_config["vim_conn"].new_vminstance(name='Test1_vm', image_id=image_id,
1682 flavor_id=flavor_id, net_list=net_list)
1683
1684 self.assertEqual(type(instance_id),str)
1685 logger.info("Deleting created vm instance")
1686 test_config["vim_conn"].delete_vminstance(instance_id)
1687 time.sleep(10)
1688
1689 def test_010_vminstance_by_ip_address_negative(self):
1690 name = "eth1"
1691 # IP address not from subnet range
1692 invalid_ip_address = '10.10.12.1'
1693
1694 flavor_data = {'ram': 1024, 'vcpus': 1, 'disk': 10}
1695
1696 # create new flavor
1697 flavor_id = test_config["vim_conn"].new_flavor(flavor_data)
1698
1699 # find image name and image id
1700 image_id = get_image_id()
1701
1702 self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"],
1703 self.__class__.test_index,
1704 inspect.currentframe().f_code.co_name)
1705 self.__class__.test_index += 1
1706
1707 net_list = [{'use': 'bridge', 'name': name, 'floating_ip': False, 'port_security': True, 'type': 'virtual',
1708 'net_id': self.network_id, 'ip_address': invalid_ip_address}]
1709
1710 with self.assertRaises(Exception) as context:
1711 test_config["vim_conn"].new_vminstance(name='Test1_vm', image_id=image_id,
1712 flavor_id=flavor_id,
1713 net_list=net_list)
1714 self.assertEqual((context.exception).http_code, 400)
1715
1716 def test_020_vminstance_by_floating_ip(self):
1717 name = "eth1"
1718 flavor_data = {'ram': 1024, 'vcpus': 1, 'disk': 10}
1719
1720 # create new flavor
1721 flavor_id = test_config["vim_conn"].new_flavor(flavor_data)
1722
1723 # find image name and image id
1724 image_id = get_image_id()
1725
1726 self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"],
1727 self.__class__.test_index,
1728 inspect.currentframe().f_code.co_name)
1729 self.__class__.test_index += 1
1730
1731 net_list = [{'use': 'bridge', 'name': name, 'floating_ip': True, 'port_security': True, 'type': 'virtual',
1732 'net_id': self.network_id}]
1733
1734 instance_id, _ = test_config["vim_conn"].new_vminstance(name='Test1_vm', image_id=image_id,
1735 flavor_id=flavor_id, net_list=net_list)
1736
1737 self.assertEqual(type(instance_id),str)
1738 logger.info("Deleting created vm instance")
1739 test_config["vim_conn"].delete_vminstance(instance_id)
1740 time.sleep(10)
1741
1742 def test_030_vminstance_by_mac_address(self):
1743 name = "eth1"
1744 mac_address = "74:54:2f:21:da:8c"
1745 flavor_data = {'ram': 1024, 'vcpus': 1, 'disk': 10}
1746
1747 # create new flavor
1748 flavor_id = test_config["vim_conn"].new_flavor(flavor_data)
1749
1750 # find image name and image id
1751 image_id = get_image_id()
1752
1753 self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"],
1754 self.__class__.test_index,
1755 inspect.currentframe().f_code.co_name)
1756 self.__class__.test_index += 1
1757
1758 net_list = [{'use': 'bridge', 'name': name, 'floating_ip': False, 'port_security': True, 'type': 'virtual',
1759 'net_id': self.network_id,'mac_address': mac_address}]
1760
1761 instance_id, _ = test_config["vim_conn"].new_vminstance(name='Test1_vm', image_id=image_id,
1762 flavor_id=flavor_id, net_list=net_list)
1763
1764 self.assertEqual(type(instance_id),str)
1765 logger.info("Deleting created vm instance")
1766 test_config["vim_conn"].delete_vminstance(instance_id)
1767 time.sleep(10)
1768
1769class test_vimconn_vminstance_by_adding_10_nics(test_base):
1770 network_name = None
1771 net_ids = []
1772
1773 def setUp(self):
1774 # create network
1775 i = 0
1776 for i in range(10):
1777 self.network_name = _get_random_string(20)
jamartinezv14a823d2019-08-01 11:45:15 +02001778 network_id, _ = test_config["vim_conn"].new_network(net_name=self.network_name,
kasar532f8c22018-10-12 02:25:31 -07001779 net_type='bridge')
1780 self.net_ids.append(network_id)
1781
1782 def tearDown(self):
1783 test_base.tearDown(self)
1784 # Deleting created network
1785 for net_id in self.net_ids:
1786 result = test_config["vim_conn"].delete_network(net_id)
1787 if result:
1788 logger.info("Network id {} sucessfully deleted".format(net_id))
1789 else:
1790 logger.info("Failed to delete network id {}".format(net_id))
1791
1792 def test_000_vminstance_by_adding_10_nics(self):
1793 flavor_data = {'ram': 1024, 'vcpus': 1, 'disk': 10}
1794
1795 # create new flavor
1796 flavor_id = test_config["vim_conn"].new_flavor(flavor_data)
1797
1798 # find image name and image id
1799 image_id = get_image_id()
1800
1801 self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"],
1802 self.__class__.test_index,
1803 inspect.currentframe().f_code.co_name)
1804 self.__class__.test_index += 1
1805
1806 net_list = []
1807 c = 1
1808 for net_id in self.net_ids:
1809 name = "eth{}".format(c)
1810 net_list.append({'use': 'bridge', 'name': name, 'floating_ip': False,
1811 'port_security': True, 'type': 'virtual', 'net_id': net_id})
1812 c = c+1
1813
jamartinezv14a823d2019-08-01 11:45:15 +02001814 instance_id, _ = test_config["vim_conn"].new_vminstance(name='Test1_vm', description='', start=False,
1815 image_id=image_id, flavor_id=flavor_id, net_list=net_list)
kasar532f8c22018-10-12 02:25:31 -07001816
1817 self.assertEqual(type(instance_id),str)
1818 logger.info("Deleting created vm instance")
1819 test_config["vim_conn"].delete_vminstance(instance_id)
1820 time.sleep(10)
1821
1822
1823class test_vimconn_vminstance_by_existing_disk(test_base):
1824 network_name = None
1825 network_id = None
1826
1827 def setUp(self):
1828 # create network
1829 self.network_name = _get_random_string(20)
jamartinezv14a823d2019-08-01 11:45:15 +02001830 self.network_id, _ = test_config["vim_conn"].new_network(net_name=self.network_name,
kasar532f8c22018-10-12 02:25:31 -07001831 net_type='bridge')
1832
1833 def tearDown(self):
1834 test_base.tearDown(self)
1835 # Deleting created network
1836 result = test_config["vim_conn"].delete_network(self.network_id)
1837 if result:
1838 logger.info("Network id {} sucessfully deleted".format(self.network_id))
1839 else:
1840 logger.info("Failed to delete network id {}".format(self.network_id))
1841
1842
1843 def test_000_vminstance_by_existing_disk(self):
1844 """ This testcase will add existing disk only if given catalog/image is free
1845 means not used by any other VM
1846 """
1847
1848 flavor_data = {'ram': 1024, 'vcpus': 1, 'disk': 10}
1849 name = "eth10"
1850
1851 # create new flavor
1852 flavor_id = test_config["vim_conn"].new_flavor(flavor_data)
1853
1854 # find image name and image id
1855 image_id = get_image_id()
1856 cirros_image = test_config["vim_conn"].get_image_list({'name': 'cirros'})
1857 disk_list = [{'image_id': cirros_image[0]['id'],'size': 5}]
1858
1859 self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"],
1860 self.__class__.test_index,
1861 inspect.currentframe().f_code.co_name)
1862 self.__class__.test_index += 1
1863
1864 net_list = [{'use': 'bridge', 'name': name, 'floating_ip': False, 'port_security': True,
1865 'type': 'virtual', 'net_id': self.network_id}]
1866
jamartinezv14a823d2019-08-01 11:45:15 +02001867 instance_id, _ = test_config["vim_conn"].new_vminstance(name='Test1_vm', description='', start=False,
1868 image_id=image_id,
kasar532f8c22018-10-12 02:25:31 -07001869 flavor_id=flavor_id, net_list=net_list,disk_list=disk_list)
1870
1871 self.assertEqual(type(instance_id),str)
1872 logger.info("Deleting created vm instance")
1873 test_config["vim_conn"].delete_vminstance(instance_id)
1874 time.sleep(10)
1875
1876 def test_010_vminstance_by_new_disk(self):
1877 flavor_data = {'ram': 1024, 'vcpus': 1, 'disk': 10}
1878 name = "eth10"
1879
1880 # create new flavor
1881 flavor_id = test_config["vim_conn"].new_flavor(flavor_data)
1882
1883 # find image name and image id
1884 image_id = get_image_id()
1885 disk_list = [{'size': '5'}]
1886
1887 self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"],
1888 self.__class__.test_index,
1889 inspect.currentframe().f_code.co_name)
1890 self.__class__.test_index += 1
1891
1892 net_list = [{'use': 'bridge', 'name': name, 'floating_ip': False, 'port_security': True,
1893 'type': 'virtual', 'net_id': self.network_id}]
1894
jamartinezv14a823d2019-08-01 11:45:15 +02001895 instance_id, _ = test_config["vim_conn"].new_vminstance(name='Test1_vm', description='', start=False,
1896 image_id=image_id,
kasar532f8c22018-10-12 02:25:31 -07001897 flavor_id=flavor_id, net_list=net_list,disk_list=disk_list)
1898
1899 self.assertEqual(type(instance_id),str)
1900 logger.info("Deleting created vm instance")
1901 test_config["vim_conn"].delete_vminstance(instance_id)
1902 time.sleep(10)
1903
1904 def test_020_vminstance_by_CDROM(self):
1905 """ This testcase will insert media file only if provided catalog
1906 has pre-created ISO media file into vCD
1907 """
1908 flavor_data ={'ram': 1024, 'vcpus': 1, 'disk': 10}
1909 name = "eth10"
1910 image_list = test_config["vim_conn"].get_image_list({'name':'Ubuntu'})
1911 disk_list = [{'image_id':image_list[0]['id'],'device_type':'cdrom'}]
1912
1913 # create new flavor
1914 flavor_id = test_config["vim_conn"].new_flavor(flavor_data)
1915
1916 # find image name and image id
1917 image_id = get_image_id()
1918
1919 self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"],
1920 self.__class__.test_index,
1921 inspect.currentframe().f_code.co_name)
1922 self.__class__.test_index += 1
1923
1924 net_list = [{'use': 'bridge', 'name': name, 'floating_ip': False, 'port_security': True,
1925 'type': 'virtual', 'net_id': self.network_id}]
1926
jamartinezv14a823d2019-08-01 11:45:15 +02001927 instance_id, _ = test_config["vim_conn"].new_vminstance(name='Test1_vm', description='', start=False,
1928 image_id=image_id,
kasar532f8c22018-10-12 02:25:31 -07001929 flavor_id=flavor_id, net_list=net_list,disk_list=disk_list )
1930
1931 self.assertEqual(type(instance_id),str)
1932 logger.info("Deleting created vm instance")
1933 test_config["vim_conn"].delete_vminstance(instance_id)
1934 time.sleep(10)
1935
1936
1937class test_vimconn_vminstance_by_affinity_anti_affinity(test_base):
1938 network_name = None
1939 network_id = None
1940
1941 def setUp(self):
1942 # create network
1943 self.network_name = _get_random_string(20)
jamartinezv14a823d2019-08-01 11:45:15 +02001944 self.network_id, _ = test_config["vim_conn"].new_network(net_name=self.network_name,
kasar532f8c22018-10-12 02:25:31 -07001945 net_type='bridge')
1946
1947 def tearDown(self):
1948 test_base.tearDown(self)
1949 # Deleting created network
1950 result = test_config["vim_conn"].delete_network(self.network_id)
1951 if result:
1952 logger.info("Network id {} sucessfully deleted".format(self.network_id))
1953 else:
1954 logger.info("Failed to delete network id {}".format(self.network_id))
1955
1956 def test_000_vminstance_by_affinity_anti_affinity(self):
1957 """ This testcase will deploy VM into provided HOSTGROUP in VIM config
1958 Pre-requisites: User has created Hosh Groups in vCenter with respective Hosts to be used
1959 While creating VIM account user has to pass the Host Group names in availability_zone list
1960 """
1961 flavor_data = {'ram': 1024, 'vcpus': 1, 'disk': 10}
1962 name = "eth10"
1963
1964 # create new flavor
1965 flavor_id = test_config["vim_conn"].new_flavor(flavor_data)
1966
1967 # find image name and image id
1968 image_id = get_image_id()
1969
1970 self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"],
1971 self.__class__.test_index,
1972 inspect.currentframe().f_code.co_name)
1973 self.__class__.test_index += 1
1974
1975 net_list = [{'use': 'bridge', 'name': name, 'floating_ip': False, 'port_security': True,
1976 'type': 'virtual', 'net_id': self.network_id}]
1977
jamartinezv14a823d2019-08-01 11:45:15 +02001978 instance_id, _ = test_config["vim_conn"].new_vminstance(name='Test1_vm', description='', start=False,
1979 image_id=image_id,
kasar532f8c22018-10-12 02:25:31 -07001980 flavor_id=flavor_id, net_list=net_list,availability_zone_index=1,
1981 availability_zone_list=['HG_174','HG_175'])
1982
1983 self.assertEqual(type(instance_id),str)
1984 time.sleep(10)
1985 logger.info("Deleting created vm instance")
1986 test_config["vim_conn"].delete_vminstance(instance_id)
1987
1988class test_vimconn_vminstance_by_numa_affinity(test_base):
1989 network_name = None
1990 network_id = None
1991
1992 def setUp(self):
1993 # create network
1994 self.network_name = _get_random_string(20)
jamartinezv14a823d2019-08-01 11:45:15 +02001995 self.network_id, _ = test_config["vim_conn"].new_network(net_name=self.network_name,
kasar532f8c22018-10-12 02:25:31 -07001996 net_type='bridge')
1997
1998 def tearDown(self):
1999 test_base.tearDown(self)
2000 # Deleting created network
2001 result = test_config["vim_conn"].delete_network(self.network_id)
2002 if result:
2003 logger.info("Network id {} sucessfully deleted".format(self.network_id))
2004 else:
2005 logger.info("Failed to delete network id {}".format(self.network_id))
2006
2007 def test_000_vminstance_by_numa_affinity(self):
2008 flavor_data = {'extended': {'numas': [{'paired-threads-id': [['1', '3'], ['2', '4']],
jamartinezv14a823d2019-08-01 11:45:15 +02002009 ' paired-threads': 2, 'memory': 1}]},
2010 'ram': 1024, 'vcpus': 1, 'disk': 10}
kasar532f8c22018-10-12 02:25:31 -07002011 name = "eth10"
2012
2013 # create new flavor
2014 flavor_id = test_config["vim_conn"].new_flavor(flavor_data)
2015
2016 # find image name and image id
2017 image_id = get_image_id()
2018
2019 self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"],
2020 self.__class__.test_index,
2021 inspect.currentframe().f_code.co_name)
2022 self.__class__.test_index += 1
2023
2024 net_list = [{'use': 'bridge', 'name': name, 'floating_ip': False, 'port_security': True,
2025 'type': 'virtual', 'net_id': self.network_id}]
2026
jamartinezv14a823d2019-08-01 11:45:15 +02002027 instance_id, _ = test_config["vim_conn"].new_vminstance(name='Test1_vm', description='', start=False,
2028 image_id=image_id,
kasar532f8c22018-10-12 02:25:31 -07002029 flavor_id=flavor_id, net_list=net_list)
2030
2031 self.assertEqual(type(instance_id),str)
2032 logger.info("Deleting created vm instance")
2033 test_config["vim_conn"].delete_vminstance(instance_id)
2034 time.sleep(10)
2035
2036
Pablo Montes Morenoeebea062017-02-27 12:33:10 +01002037'''
2038IMPORTANT NOTE
2039The following unittest class does not have the 'test_' on purpose. This test is the one used for the
2040scenario based tests.
2041'''
tiernof0508352017-06-19 13:37:44 +02002042class descriptor_based_scenario_test(test_base):
Pablo Montes Morenoeebea062017-02-27 12:33:10 +01002043 test_index = 0
Pablo Montes Morenoeebea062017-02-27 12:33:10 +01002044 scenario_test_path = None
Pablo Montes Morenoeebea062017-02-27 12:33:10 +01002045
2046 @classmethod
2047 def setUpClass(cls):
2048 cls.test_index = 1
2049 cls.to_delete_list = []
tiernoed854572017-10-03 16:18:09 +02002050 cls.scenario_uuids = []
2051 cls.instance_scenario_uuids = []
tiernoec66e9a2017-05-17 15:28:10 +02002052 cls.scenario_test_path = test_config["test_directory"] + '/' + test_config["test_folder"]
2053 logger.info("{}. {} {}".format(test_config["test_number"], cls.__name__, test_config["test_folder"]))
Pablo Montes Morenoeebea062017-02-27 12:33:10 +01002054
2055 @classmethod
2056 def tearDownClass(cls):
tiernoec66e9a2017-05-17 15:28:10 +02002057 test_config["test_number"] += 1
Pablo Montes Morenoeebea062017-02-27 12:33:10 +01002058
Pablo Montes Morenoeebea062017-02-27 12:33:10 +01002059 def test_000_load_scenario(self):
tiernoec66e9a2017-05-17 15:28:10 +02002060 self.__class__.test_text = "{}.{}. TEST {} {}".format(test_config["test_number"], self.__class__.test_index,
Pablo Montes Morenoeebea062017-02-27 12:33:10 +01002061 inspect.currentframe().f_code.co_name,
tiernoec66e9a2017-05-17 15:28:10 +02002062 test_config["test_folder"])
Pablo Montes Morenoeebea062017-02-27 12:33:10 +01002063 self.__class__.test_index += 1
tiernoed854572017-10-03 16:18:09 +02002064 # load VNFD and NSD
2065 descriptor_files = glob.glob(self.__class__.scenario_test_path+'/*.yaml')
2066 vnf_descriptors = []
2067 scenario_descriptors = []
2068 for descriptor_file in descriptor_files:
2069 with open(descriptor_file, 'r') as stream:
2070 descriptor = yaml.load(stream)
2071 if "vnf" in descriptor or "vnfd:vnfd-catalog" in descriptor or "vnfd-catalog" in descriptor:
2072 vnf_descriptors.append(descriptor)
2073 else:
2074 scenario_descriptors.append(descriptor)
2075
Pablo Montes Morenoeebea062017-02-27 12:33:10 +01002076 scenario_file = glob.glob(self.__class__.scenario_test_path + '/scenario_*.yaml')
tiernoed854572017-10-03 16:18:09 +02002077 if not vnf_descriptors or not scenario_descriptors or len(scenario_descriptors) > 1:
tiernoec66e9a2017-05-17 15:28:10 +02002078 raise Exception("Test '{}' not valid. It must contain an scenario file and at least one vnfd file'".format(
2079 test_config["test_folder"]))
Pablo Montes Morenoeebea062017-02-27 12:33:10 +01002080
tiernoed854572017-10-03 16:18:09 +02002081 # load all vnfd
2082 for vnf_descriptor in vnf_descriptors:
Pablo Montes Morenoeebea062017-02-27 12:33:10 +01002083 logger.debug("VNF descriptor: {}".format(vnf_descriptor))
tiernoed854572017-10-03 16:18:09 +02002084 vnf = test_config["client"].create_vnf(descriptor=vnf_descriptor, image_name=test_config["image_name"])
Pablo Montes Morenoeebea062017-02-27 12:33:10 +01002085 logger.debug(vnf)
tiernoed854572017-10-03 16:18:09 +02002086 if 'vnf' in vnf:
2087 vnf_uuid = vnf['vnf']['uuid']
2088 else:
2089 vnf_uuid = vnf['vnfd'][0]['uuid']
tiernoec66e9a2017-05-17 15:28:10 +02002090 self.__class__.to_delete_list.insert(0, {"item": "vnf", "function": test_config["client"].delete_vnf,
tiernoed854572017-10-03 16:18:09 +02002091 "params": {"uuid": vnf_uuid}})
Pablo Montes Morenoeebea062017-02-27 12:33:10 +01002092
tiernoed854572017-10-03 16:18:09 +02002093 # load the scenario definition
2094 for scenario_descriptor in scenario_descriptors:
2095 # networks = scenario_descriptor['scenario']['networks']
2096 # networks[test_config["mgmt_net"]] = networks.pop('mgmt')
2097 logger.debug("Scenario descriptor: {}".format(scenario_descriptor))
2098 scenario = test_config["client"].create_scenario(descriptor=scenario_descriptor)
2099 logger.debug(scenario)
2100 if 'scenario' in scenario:
2101 scenario_uuid = scenario['scenario']['uuid']
2102 else:
2103 scenario_uuid = scenario['nsd'][0]['uuid']
2104 self.__class__.to_delete_list.insert(0, {"item": "scenario",
2105 "function": test_config["client"].delete_scenario,
2106 "params": {"uuid": scenario_uuid}})
2107 self.__class__.scenario_uuids.append(scenario_uuid)
Pablo Montes Morenoeebea062017-02-27 12:33:10 +01002108
2109 def test_010_instantiate_scenario(self):
tiernoec66e9a2017-05-17 15:28:10 +02002110 self.__class__.test_text = "{}.{}. TEST {} {}".format(test_config["test_number"], self.__class__.test_index,
Pablo Montes Morenoeebea062017-02-27 12:33:10 +01002111 inspect.currentframe().f_code.co_name,
tiernoec66e9a2017-05-17 15:28:10 +02002112 test_config["test_folder"])
Pablo Montes Morenoeebea062017-02-27 12:33:10 +01002113 self.__class__.test_index += 1
tiernoed854572017-10-03 16:18:09 +02002114 for scenario_uuid in self.__class__.scenario_uuids:
2115 instance_descriptor = {
2116 "instance":{
2117 "name": self.__class__.test_text,
2118 "scenario": scenario_uuid,
2119 "networks":{
2120 "mgmt": {"sites": [ { "netmap-use": test_config["mgmt_net"]} ]}
2121 }
2122 }
2123 }
2124 instance = test_config["client"].create_instance(instance_descriptor)
2125 self.__class__.instance_scenario_uuids.append(instance['uuid'])
2126 logger.debug(instance)
2127 self.__class__.to_delete_list.insert(0, {"item": "instance",
2128 "function": test_config["client"].delete_instance,
2129 "params": {"uuid": instance['uuid']}})
Pablo Montes Morenoeebea062017-02-27 12:33:10 +01002130
Pablo Montes Moreno2fe24fa2017-03-27 12:56:13 +02002131 def test_020_check_deployent(self):
tiernoec66e9a2017-05-17 15:28:10 +02002132 self.__class__.test_text = "{}.{}. TEST {} {}".format(test_config["test_number"], self.__class__.test_index,
Pablo Montes Moreno2fe24fa2017-03-27 12:56:13 +02002133 inspect.currentframe().f_code.co_name,
tiernoec66e9a2017-05-17 15:28:10 +02002134 test_config["test_folder"])
Pablo Montes Moreno2fe24fa2017-03-27 12:56:13 +02002135 self.__class__.test_index += 1
2136
tiernoec66e9a2017-05-17 15:28:10 +02002137 if test_config["manual"]:
Pablo Montes Moreno3be0b2a2017-03-30 13:22:15 +02002138 raw_input('Scenario has been deployed. Perform manual check and press any key to resume')
2139 return
2140
tiernoec66e9a2017-05-17 15:28:10 +02002141 keep_waiting = test_config["timeout"]
tiernoed854572017-10-03 16:18:09 +02002142 pending_instance_scenario_uuids = list(self.__class__.instance_scenario_uuids) # make a copy
2143 while pending_instance_scenario_uuids:
2144 index = 0
2145 while index < len(pending_instance_scenario_uuids):
2146 result = check_instance_scenario_active(pending_instance_scenario_uuids[index])
2147 if result[0]:
2148 del pending_instance_scenario_uuids[index]
2149 break
2150 elif 'ERROR' in result[1]:
2151 msg = 'Got error while waiting for the instance to get active: '+result[1]
2152 logging.error(msg)
2153 raise Exception(msg)
2154 index += 1
Pablo Montes Moreno2fe24fa2017-03-27 12:56:13 +02002155
tierno0e6fcaa2017-05-05 15:54:07 +02002156 if keep_waiting >= 5:
2157 time.sleep(5)
2158 keep_waiting -= 5
2159 elif keep_waiting > 0:
2160 time.sleep(keep_waiting)
2161 keep_waiting = 0
2162 else:
2163 msg = 'Timeout reached while waiting instance scenario to get active'
2164 logging.error(msg)
2165 raise Exception(msg)
Pablo Montes Moreno2fe24fa2017-03-27 12:56:13 +02002166
2167 def test_030_clean_deployment(self):
tiernoec66e9a2017-05-17 15:28:10 +02002168 self.__class__.test_text = "{}.{}. TEST {} {}".format(test_config["test_number"], self.__class__.test_index,
Pablo Montes Morenoeebea062017-02-27 12:33:10 +01002169 inspect.currentframe().f_code.co_name,
tiernoec66e9a2017-05-17 15:28:10 +02002170 test_config["test_folder"])
Pablo Montes Morenoeebea062017-02-27 12:33:10 +01002171 self.__class__.test_index += 1
2172 #At the moment if you delete an scenario right after creating it, in openstack datacenters
2173 #sometimes scenario ports get orphaned. This sleep is just a dirty workaround
2174 time.sleep(5)
2175 for item in self.__class__.to_delete_list:
2176 response = item["function"](**item["params"])
2177 logger.debug(response)
2178
tiernoec66e9a2017-05-17 15:28:10 +02002179
Pablo Montes Morenoeebea062017-02-27 12:33:10 +01002180def _get_random_string(maxLength):
2181 '''generates a string with random characters string.letters and string.digits
2182 with a random length up to maxLength characters. If maxLength is <15 it will be changed automatically to 15
2183 '''
2184 prefix = 'testing_'
2185 min_string = 15
2186 minLength = min_string - len(prefix)
2187 if maxLength < min_string: maxLength = min_string
2188 maxLength -= len(prefix)
2189 length = random.randint(minLength,maxLength)
2190 return 'testing_'+"".join([random.choice(string.letters+string.digits) for i in xrange(length)])
2191
tiernoec66e9a2017-05-17 15:28:10 +02002192
2193def test_vimconnector(args):
2194 global test_config
tierno0e6fcaa2017-05-05 15:54:07 +02002195 sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + "/osm_ro")
kasar70532ae2017-05-26 03:53:52 -07002196 test_config['vimtype'] = args.vimtype
tiernoec66e9a2017-05-17 15:28:10 +02002197 if args.vimtype == "vmware":
2198 import vimconn_vmware as vim
kasar70532ae2017-05-26 03:53:52 -07002199
2200 test_config["test_directory"] = os.path.dirname(__file__) + "/RO_tests"
2201
2202 tenant_name = args.tenant_name
2203 test_config['tenant'] = tenant_name
tierno12a0c3b2018-10-15 15:10:36 +02002204 config_params = yaml.load(args.config_param)
kasar70532ae2017-05-26 03:53:52 -07002205 org_name = config_params.get('orgname')
2206 org_user = config_params.get('user')
2207 org_passwd = config_params.get('passwd')
2208 vim_url = args.endpoint_url
kasarfeaaa052017-06-08 03:46:18 -07002209 test_config['image_path'] = args.image_path
kasarffdaf292017-06-23 04:06:52 -07002210 test_config['image_name'] = args.image_name
Ravi Chamarty59d24362018-11-22 01:22:16 +00002211 test_config['sriov_net_name'] = args.sriov_net_name
kasar70532ae2017-05-26 03:53:52 -07002212
2213 # vmware connector obj
jamartinezv14a823d2019-08-01 11:45:15 +02002214 test_config['vim_conn'] = vim.vimconnector(name=org_name, tenant_name=tenant_name, user=org_user,
2215 passwd=org_passwd, url=vim_url, config=config_params)
kasar70532ae2017-05-26 03:53:52 -07002216
tiernoec66e9a2017-05-17 15:28:10 +02002217 elif args.vimtype == "aws":
2218 import vimconn_aws as vim
2219 elif args.vimtype == "openstack":
2220 import vimconn_openstack as vim
shashankjain3cd49712018-09-28 11:59:03 +05302221
2222 test_config["test_directory"] = os.path.dirname(__file__) + "/RO_tests"
2223
2224 tenant_name = args.tenant_name
2225 test_config['tenant'] = tenant_name
tierno12a0c3b2018-10-15 15:10:36 +02002226 config_params = yaml.load(args.config_param)
shashankjain3cd49712018-09-28 11:59:03 +05302227 os_user = config_params.get('user')
2228 os_passwd = config_params.get('passwd')
2229 vim_url = args.endpoint_url
2230 test_config['image_path'] = args.image_path
2231 test_config['image_name'] = args.image_name
Ravi Chamarty59d24362018-11-22 01:22:16 +00002232 test_config['sriov_net_name'] = args.sriov_net_name
shashankjain3cd49712018-09-28 11:59:03 +05302233
2234 # openstack connector obj
2235 vim_persistent_info = {}
2236 test_config['vim_conn'] = vim.vimconnector(
2237 uuid="test-uuid-1", name="VIO-openstack",
2238 tenant_id=None, tenant_name=tenant_name,
2239 url=vim_url, url_admin=None,
2240 user=os_user, passwd=os_passwd,
2241 config=config_params, persistent_info=vim_persistent_info
2242 )
2243 test_config['vim_conn'].debug = "true"
2244
tiernoec66e9a2017-05-17 15:28:10 +02002245 elif args.vimtype == "openvim":
2246 import vimconn_openvim as vim
jamartinezv14a823d2019-08-01 11:45:15 +02002247 elif args.vimtype == "azure":
2248 import vimconn_azure as vim
2249
2250 test_config["test_directory"] = os.path.dirname(__file__) + "/RO_tests"
2251
2252 tenant_name = args.tenant_name
2253 test_config['tenant'] = tenant_name
2254 config_params = yaml.load(args.config_param)
2255 os_user = config_params.get('user')
2256 os_passwd = config_params.get('passwd')
2257 vim_url = args.endpoint_url
2258 test_config['image_path'] = args.image_path
2259 test_config['image_name'] = args.image_name
2260 #test_config['sriov_net_name'] = args.sriov_net_name
2261
2262 # azure connector obj
2263 vim_persistent_info = {}
2264 test_config['vim_conn'] = vim.vimconnector(
2265 uuid="test-uuid-1", name="VIO-azure",
2266 tenant_id=None, tenant_name=tenant_name,
2267 url=vim_url, url_admin=None,
2268 user=os_user, passwd=os_passwd,
2269 config=config_params, persistent_info=vim_persistent_info
2270 )
2271 test_config['vim_conn'].debug = "true"
2272
tiernoec66e9a2017-05-17 15:28:10 +02002273 else:
2274 logger.critical("vimtype '{}' not supported".format(args.vimtype))
2275 sys.exit(1)
2276 executed = 0
2277 failed = 0
Pablo Montes Morenoeebea062017-02-27 12:33:10 +01002278 clsmembers = inspect.getmembers(sys.modules[__name__], inspect.isclass)
Pablo Montes Morenoeebea062017-02-27 12:33:10 +01002279 # If only want to obtain a tests list print it and exit
tiernoec66e9a2017-05-17 15:28:10 +02002280 if args.list_tests:
Pablo Montes Morenoeebea062017-02-27 12:33:10 +01002281 tests_names = []
2282 for cls in clsmembers:
shashankjain3cd49712018-09-28 11:59:03 +05302283 if cls[0].startswith('test_vimconn'):
Pablo Montes Morenoeebea062017-02-27 12:33:10 +01002284 tests_names.append(cls[0])
2285
tiernoec66e9a2017-05-17 15:28:10 +02002286 msg = "The 'vim' set tests are:\n\t" + ', '.join(sorted(tests_names))
2287 print(msg)
Pablo Montes Morenoeebea062017-02-27 12:33:10 +01002288 logger.info(msg)
2289 sys.exit(0)
2290
tierno0e6fcaa2017-05-05 15:54:07 +02002291 # Create the list of tests to be run
Pablo Montes Morenoeebea062017-02-27 12:33:10 +01002292 code_based_tests = []
tiernoec66e9a2017-05-17 15:28:10 +02002293 if args.tests:
2294 for test in args.tests:
2295 for t in test.split(','):
2296 matches_code_based_tests = [item for item in clsmembers if item[0] == t]
2297 if len(matches_code_based_tests) > 0:
2298 code_based_tests.append(matches_code_based_tests[0][1])
2299 else:
2300 logger.critical("Test '{}' is not among the possible ones".format(t))
2301 sys.exit(1)
2302 if not code_based_tests:
tierno0e6fcaa2017-05-05 15:54:07 +02002303 # include all tests
Pablo Montes Morenoeebea062017-02-27 12:33:10 +01002304 for cls in clsmembers:
tierno0e6fcaa2017-05-05 15:54:07 +02002305 # We exclude 'test_VIM_tenant_operations' unless it is specifically requested by the user
tierno12a0c3b2018-10-15 15:10:36 +02002306 if cls[0].startswith('test_vimconn'):
Pablo Montes Morenoeebea062017-02-27 12:33:10 +01002307 code_based_tests.append(cls[1])
2308
tiernoec66e9a2017-05-17 15:28:10 +02002309 logger.debug("tests to be executed: {}".format(code_based_tests))
Pablo Montes Morenoeebea062017-02-27 12:33:10 +01002310
2311 # TextTestRunner stream is set to /dev/null in order to avoid the method to directly print the result of tests.
2312 # This is handled in the tests using logging.
2313 stream = open('/dev/null', 'w')
Pablo Montes Morenoeebea062017-02-27 12:33:10 +01002314
tierno0e6fcaa2017-05-05 15:54:07 +02002315 # Run code based tests
Pablo Montes Morenoeebea062017-02-27 12:33:10 +01002316 basic_tests_suite = unittest.TestSuite()
2317 for test in code_based_tests:
2318 basic_tests_suite.addTest(unittest.makeSuite(test))
tierno0e6fcaa2017-05-05 15:54:07 +02002319 result = unittest.TextTestRunner(stream=stream, failfast=failfast).run(basic_tests_suite)
Pablo Montes Morenoeebea062017-02-27 12:33:10 +01002320 executed += result.testsRun
2321 failed += len(result.failures) + len(result.errors)
tierno0e6fcaa2017-05-05 15:54:07 +02002322 if failfast and failed:
2323 sys.exit(1)
Pablo Montes Morenoeebea062017-02-27 12:33:10 +01002324 if len(result.failures) > 0:
2325 logger.debug("failures : {}".format(result.failures))
2326 if len(result.errors) > 0:
2327 logger.debug("errors : {}".format(result.errors))
tiernoec66e9a2017-05-17 15:28:10 +02002328 return executed, failed
Pablo Montes Morenoeebea062017-02-27 12:33:10 +01002329
tiernoec66e9a2017-05-17 15:28:10 +02002330
2331def test_vim(args):
2332 global test_config
2333 sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + "/osm_ro")
2334 import openmanoclient
2335 executed = 0
2336 failed = 0
2337 test_config["client"] = openmanoclient.openmanoclient(
2338 endpoint_url=args.endpoint_url,
2339 tenant_name=args.tenant_name,
2340 datacenter_name=args.datacenter,
2341 debug=args.debug, logger=test_config["logger_name"])
2342 clsmembers = inspect.getmembers(sys.modules[__name__], inspect.isclass)
2343 # If only want to obtain a tests list print it and exit
2344 if args.list_tests:
2345 tests_names = []
2346 for cls in clsmembers:
2347 if cls[0].startswith('test_VIM'):
2348 tests_names.append(cls[0])
2349
2350 msg = "The 'vim' set tests are:\n\t" + ', '.join(sorted(tests_names)) +\
2351 "\nNOTE: The test test_VIM_tenant_operations will fail in case the used datacenter is type OpenStack " \
2352 "unless RO has access to the admin endpoint. Therefore this test is excluded by default"
2353 print(msg)
2354 logger.info(msg)
2355 sys.exit(0)
2356
2357 # Create the list of tests to be run
2358 code_based_tests = []
2359 if args.tests:
2360 for test in args.tests:
2361 for t in test.split(','):
2362 matches_code_based_tests = [item for item in clsmembers if item[0] == t]
2363 if len(matches_code_based_tests) > 0:
2364 code_based_tests.append(matches_code_based_tests[0][1])
2365 else:
2366 logger.critical("Test '{}' is not among the possible ones".format(t))
2367 sys.exit(1)
2368 if not code_based_tests:
2369 # include all tests
2370 for cls in clsmembers:
2371 # We exclude 'test_VIM_tenant_operations' unless it is specifically requested by the user
2372 if cls[0].startswith('test_VIM') and cls[0] != 'test_VIM_tenant_operations':
2373 code_based_tests.append(cls[1])
2374
2375 logger.debug("tests to be executed: {}".format(code_based_tests))
2376
2377 # TextTestRunner stream is set to /dev/null in order to avoid the method to directly print the result of tests.
2378 # This is handled in the tests using logging.
2379 stream = open('/dev/null', 'w')
2380
2381 # Run code based tests
2382 basic_tests_suite = unittest.TestSuite()
2383 for test in code_based_tests:
2384 basic_tests_suite.addTest(unittest.makeSuite(test))
2385 result = unittest.TextTestRunner(stream=stream, failfast=failfast).run(basic_tests_suite)
2386 executed += result.testsRun
2387 failed += len(result.failures) + len(result.errors)
2388 if failfast and failed:
2389 sys.exit(1)
2390 if len(result.failures) > 0:
2391 logger.debug("failures : {}".format(result.failures))
2392 if len(result.errors) > 0:
2393 logger.debug("errors : {}".format(result.errors))
2394 return executed, failed
2395
2396
Anderson Bravalheri0446cd52018-08-17 15:26:19 +01002397def test_wim(args):
2398 global test_config
2399 sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + "/osm_ro")
2400 import openmanoclient
2401 executed = 0
2402 failed = 0
2403 test_config["client"] = openmanoclient.openmanoclient(
2404 endpoint_url=args.endpoint_url,
2405 tenant_name=args.tenant_name,
2406 datacenter_name=args.datacenter,
2407 debug=args.debug, logger=test_config["logger_name"])
2408 clsmembers = inspect.getmembers(sys.modules[__name__], inspect.isclass)
2409 # If only want to obtain a tests list print it and exit
2410 if args.list_tests:
2411 tests_names = []
2412 for cls in clsmembers:
2413 if cls[0].startswith('test_WIM'):
2414 tests_names.append(cls[0])
2415
2416 msg = "The 'wim' set tests are:\n\t" + ', '.join(sorted(tests_names)) +\
2417 "\nNOTE: The test test_VIM_tenant_operations will fail in case the used datacenter is type OpenStack " \
2418 "unless RO has access to the admin endpoint. Therefore this test is excluded by default"
2419 print(msg)
2420 logger.info(msg)
2421 sys.exit(0)
2422
2423 # Create the list of tests to be run
2424 code_based_tests = []
2425 if args.tests:
2426 for test in args.tests:
2427 for t in test.split(','):
2428 matches_code_based_tests = [item for item in clsmembers if item[0] == t]
2429 if len(matches_code_based_tests) > 0:
2430 code_based_tests.append(matches_code_based_tests[0][1])
2431 else:
2432 logger.critical("Test '{}' is not among the possible ones".format(t))
2433 sys.exit(1)
2434 if not code_based_tests:
2435 # include all tests
2436 for cls in clsmembers:
2437 # We exclude 'test_VIM_tenant_operations' unless it is specifically requested by the user
2438 if cls[0].startswith('test_VIM') and cls[0] != 'test_VIM_tenant_operations':
2439 code_based_tests.append(cls[1])
2440
2441 logger.debug("tests to be executed: {}".format(code_based_tests))
2442
2443 # TextTestRunner stream is set to /dev/null in order to avoid the method to directly print the result of tests.
2444 # This is handled in the tests using logging.
2445 stream = open('/dev/null', 'w')
2446
2447 # Run code based tests
2448 basic_tests_suite = unittest.TestSuite()
2449 for test in code_based_tests:
2450 basic_tests_suite.addTest(unittest.makeSuite(test))
2451 result = unittest.TextTestRunner(stream=stream, failfast=failfast).run(basic_tests_suite)
2452 executed += result.testsRun
2453 failed += len(result.failures) + len(result.errors)
2454 if failfast and failed:
2455 sys.exit(1)
2456 if len(result.failures) > 0:
2457 logger.debug("failures : {}".format(result.failures))
2458 if len(result.errors) > 0:
2459 logger.debug("errors : {}".format(result.errors))
2460 return executed, failed
2461
2462
tiernoec66e9a2017-05-17 15:28:10 +02002463def test_deploy(args):
2464 global test_config
2465 sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + "/osm_ro")
2466 import openmanoclient
2467 executed = 0
2468 failed = 0
2469 test_config["test_directory"] = os.path.dirname(__file__) + "/RO_tests"
2470 test_config["image_name"] = args.image_name
2471 test_config["mgmt_net"] = args.mgmt_net
2472 test_config["manual"] = args.manual
2473 test_directory_content = os.listdir(test_config["test_directory"])
2474 # If only want to obtain a tests list print it and exit
2475 if args.list_tests:
tiernof0508352017-06-19 13:37:44 +02002476 msg = "the 'deploy' set tests are:\n\t" + ', '.join(sorted(test_directory_content))
tiernoec66e9a2017-05-17 15:28:10 +02002477 print(msg)
tiernof0508352017-06-19 13:37:44 +02002478 # logger.info(msg)
tiernoec66e9a2017-05-17 15:28:10 +02002479 sys.exit(0)
2480
2481 descriptor_based_tests = []
2482 # Create the list of tests to be run
2483 code_based_tests = []
2484 if args.tests:
2485 for test in args.tests:
2486 for t in test.split(','):
2487 if t in test_directory_content:
2488 descriptor_based_tests.append(t)
2489 else:
2490 logger.critical("Test '{}' is not among the possible ones".format(t))
2491 sys.exit(1)
2492 if not descriptor_based_tests:
2493 # include all tests
2494 descriptor_based_tests = test_directory_content
2495
2496 logger.debug("tests to be executed: {}".format(code_based_tests))
2497
2498 # import openmanoclient from relative path
2499 test_config["client"] = openmanoclient.openmanoclient(
2500 endpoint_url=args.endpoint_url,
2501 tenant_name=args.tenant_name,
2502 datacenter_name=args.datacenter,
2503 debug=args.debug, logger=test_config["logger_name"])
2504
2505 # TextTestRunner stream is set to /dev/null in order to avoid the method to directly print the result of tests.
2506 # This is handled in the tests using logging.
2507 stream = open('/dev/null', 'w')
Pablo Montes Morenoeebea062017-02-27 12:33:10 +01002508 # This scenario based tests are defined as directories inside the directory defined in 'test_directory'
2509 for test in descriptor_based_tests:
tiernoec66e9a2017-05-17 15:28:10 +02002510 test_config["test_folder"] = test
Pablo Montes Morenoeebea062017-02-27 12:33:10 +01002511 test_suite = unittest.TestSuite()
2512 test_suite.addTest(unittest.makeSuite(descriptor_based_scenario_test))
tierno0e6fcaa2017-05-05 15:54:07 +02002513 result = unittest.TextTestRunner(stream=stream, failfast=False).run(test_suite)
Pablo Montes Morenoeebea062017-02-27 12:33:10 +01002514 executed += result.testsRun
2515 failed += len(result.failures) + len(result.errors)
tierno0e6fcaa2017-05-05 15:54:07 +02002516 if failfast and failed:
2517 sys.exit(1)
Pablo Montes Morenoeebea062017-02-27 12:33:10 +01002518 if len(result.failures) > 0:
2519 logger.debug("failures : {}".format(result.failures))
2520 if len(result.errors) > 0:
2521 logger.debug("errors : {}".format(result.errors))
2522
tiernoec66e9a2017-05-17 15:28:10 +02002523 return executed, failed
2524
2525if __name__=="__main__":
2526
2527 parser = ArgumentParser(description='Test RO module')
2528 parser.add_argument('-v','--version', action='version', help="Show current version",
2529 version='%(prog)s version ' + __version__ + ' ' + version_date)
2530
2531 # Common parameters
2532 parent_parser = ArgumentParser(add_help=False)
2533 parent_parser.add_argument('--failfast', help='Stop when a test fails rather than execute all tests',
2534 dest='failfast', action="store_true", default=False)
2535 parent_parser.add_argument('--failed', help='Set logs to show only failed tests. --debug disables this option',
2536 dest='failed', action="store_true", default=False)
2537 default_logger_file = os.path.dirname(__file__)+'/'+os.path.splitext(os.path.basename(__file__))[0]+'.log'
2538 parent_parser.add_argument('--list-tests', help='List all available tests', dest='list_tests', action="store_true",
2539 default=False)
2540 parent_parser.add_argument('--logger_file', dest='logger_file', default=default_logger_file,
2541 help='Set the logger file. By default '+default_logger_file)
2542 parent_parser.add_argument("-t", '--tenant', dest='tenant_name', default="osm",
2543 help="Set the openmano tenant to use for the test. By default 'osm'")
2544 parent_parser.add_argument('--debug', help='Set logs to debug level', dest='debug', action="store_true")
2545 parent_parser.add_argument('--timeout', help='Specify the instantiation timeout in seconds. By default 300',
2546 dest='timeout', type=int, default=300)
2547 parent_parser.add_argument('--test', '--tests', help='Specify the tests to run', dest='tests', action="append")
2548
2549 subparsers = parser.add_subparsers(help='test sets')
2550
2551 # Deployment test set
2552 # -------------------
2553 deploy_parser = subparsers.add_parser('deploy', parents=[parent_parser],
2554 help="test deployment using descriptors at RO_test folder ")
2555 deploy_parser.set_defaults(func=test_deploy)
2556
2557 # Mandatory arguments
2558 mandatory_arguments = deploy_parser.add_argument_group('mandatory arguments')
2559 mandatory_arguments.add_argument('-d', '--datacenter', required=True, help='Set the datacenter to test')
2560 mandatory_arguments.add_argument("-i", '--image-name', required=True, dest="image_name",
2561 help='Image name available at datacenter used for the tests')
2562 mandatory_arguments.add_argument("-n", '--mgmt-net-name', required=True, dest='mgmt_net',
2563 help='Set the vim management network to use for tests')
2564
2565 # Optional arguments
2566 deploy_parser.add_argument('-m', '--manual-check', dest='manual', action="store_true", default=False,
2567 help='Pause execution once deployed to allow manual checking of the '
2568 'deployed instance scenario')
2569 deploy_parser.add_argument('-u', '--url', dest='endpoint_url', default='http://localhost:9090/openmano',
2570 help="Set the openmano server url. By default 'http://localhost:9090/openmano'")
2571
2572 # Vimconn test set
2573 # -------------------
2574 vimconn_parser = subparsers.add_parser('vimconn', parents=[parent_parser], help="test vimconnector plugin")
2575 vimconn_parser.set_defaults(func=test_vimconnector)
2576 # Mandatory arguments
2577 mandatory_arguments = vimconn_parser.add_argument_group('mandatory arguments')
jamartinezv14a823d2019-08-01 11:45:15 +02002578 mandatory_arguments.add_argument('--vimtype', choices=['vmware', 'aws', 'openstack', 'openvim','azure'], required=True,
tiernoec66e9a2017-05-17 15:28:10 +02002579 help='Set the vimconnector type to test')
kasar70532ae2017-05-26 03:53:52 -07002580 mandatory_arguments.add_argument('-c', '--config', dest='config_param', required=True,
2581 help='Set the vimconnector specific config parameters in dictionary format')
2582 mandatory_arguments.add_argument('-u', '--url', dest='endpoint_url',required=True, help="Set the vim connector url or Host IP")
tiernoec66e9a2017-05-17 15:28:10 +02002583 # Optional arguments
kasarfeaaa052017-06-08 03:46:18 -07002584 vimconn_parser.add_argument('-i', '--image-path', dest='image_path', help="Provide image path present at RO container")
kasarffdaf292017-06-23 04:06:52 -07002585 vimconn_parser.add_argument('-n', '--image-name', dest='image_name', help="Provide image name for test")
tiernoec66e9a2017-05-17 15:28:10 +02002586 # TODO add optional arguments for vimconn tests
2587 # vimconn_parser.add_argument("-i", '--image-name', dest='image_name', help='<HELP>'))
Ravi Chamarty59d24362018-11-22 01:22:16 +00002588 vimconn_parser.add_argument('-s', '--sriov-net-name', dest='sriov_net_name', help="Provide SRIOV network name for test")
tiernoec66e9a2017-05-17 15:28:10 +02002589
2590 # Datacenter test set
2591 # -------------------
2592 vimconn_parser = subparsers.add_parser('vim', parents=[parent_parser], help="test vim")
2593 vimconn_parser.set_defaults(func=test_vim)
2594
2595 # Mandatory arguments
2596 mandatory_arguments = vimconn_parser.add_argument_group('mandatory arguments')
2597 mandatory_arguments.add_argument('-d', '--datacenter', required=True, help='Set the datacenter to test')
2598
2599 # Optional arguments
2600 vimconn_parser.add_argument('-u', '--url', dest='endpoint_url', default='http://localhost:9090/openmano',
2601 help="Set the openmano server url. By default 'http://localhost:9090/openmano'")
2602
Anderson Bravalheri0446cd52018-08-17 15:26:19 +01002603 # WIM test set
2604 # -------------------
2605 vimconn_parser = subparsers.add_parser('wim', parents=[parent_parser], help="test wim")
2606 vimconn_parser.set_defaults(func=test_wim)
2607
2608 # Mandatory arguments
2609 mandatory_arguments = vimconn_parser.add_argument_group('mandatory arguments')
2610 mandatory_arguments.add_argument('-d', '--datacenter', required=True, help='Set the datacenter to test')
2611
2612 # Optional arguments
2613 vimconn_parser.add_argument('-u', '--url', dest='endpoint_url', default='http://localhost:9090/openmano',
2614 help="Set the openmano server url. By default 'http://localhost:9090/openmano'")
2615
tiernoec66e9a2017-05-17 15:28:10 +02002616 argcomplete.autocomplete(parser)
2617 args = parser.parse_args()
2618 # print str(args)
2619 test_config = {}
2620
2621 # default logger level is INFO. Options --debug and --failed override this, being --debug prioritary
2622 logger_level = 'INFO'
2623 if args.debug:
2624 logger_level = 'DEBUG'
2625 elif args.failed:
2626 logger_level = 'WARNING'
2627 logger_name = os.path.basename(__file__)
2628 test_config["logger_name"] = logger_name
2629 logger = logging.getLogger(logger_name)
2630 logger.setLevel(logger_level)
2631 failfast = args.failfast
2632
2633 # Configure a logging handler to store in a logging file
2634 if args.logger_file:
2635 fileHandler = logging.FileHandler(args.logger_file)
2636 formatter_fileHandler = logging.Formatter('%(asctime)s %(name)s %(levelname)s: %(message)s')
2637 fileHandler.setFormatter(formatter_fileHandler)
2638 logger.addHandler(fileHandler)
2639
2640 # Configure a handler to print to stdout
2641 consoleHandler = logging.StreamHandler(sys.stdout)
2642 formatter_consoleHandler = logging.Formatter('%(asctime)s %(name)s %(levelname)s: %(message)s')
2643 consoleHandler.setFormatter(formatter_consoleHandler)
2644 logger.addHandler(consoleHandler)
2645
2646 logger.debug('Program started with the following arguments: ' + str(args))
2647
2648 # set test config parameters
2649 test_config["timeout"] = args.timeout
2650 test_config["test_number"] = 1
2651
2652 executed, failed = args.func(args)
2653
tierno0e6fcaa2017-05-05 15:54:07 +02002654 # Log summary
Pablo Montes Morenoeebea062017-02-27 12:33:10 +01002655 logger.warning("Total number of tests: {}; Total number of failures/errors: {}".format(executed, failed))
tierno0e6fcaa2017-05-05 15:54:07 +02002656 sys.exit(1 if failed else 0)