| Pablo Montes Moreno | eebea06 | 2017-02-27 12:33:10 +0100 | [diff] [blame] | 1 | #!/usr/bin/env python2 |
| 2 | # -*- coding: utf-8 -*- |
| 3 | |
| 4 | ## |
| tierno | ec66e9a | 2017-05-17 15:28:10 +0200 | [diff] [blame] | 5 | # Copyright 2017 |
| Pablo Montes Moreno | eebea06 | 2017-02-27 12:33:10 +0100 | [diff] [blame] | 6 | # 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 Moreno | eebea06 | 2017-02-27 12:33:10 +0100 | [diff] [blame] | 21 | ## |
| 22 | |
| jamartinezv | 14a823d | 2019-08-01 11:45:15 +0200 | [diff] [blame^] | 23 | # DEBUG WITH PDB |
| 24 | import os |
| 25 | if os.getenv('OSMRO_PDB_DEBUG'): |
| 26 | import sys |
| 27 | print(sys.path) |
| 28 | import pdb |
| 29 | pdb.set_trace() |
| 30 | |
| 31 | |
| tierno | ed85457 | 2017-10-03 16:18:09 +0200 | [diff] [blame] | 32 | """ |
| Pablo Montes Moreno | eebea06 | 2017-02-27 12:33:10 +0100 | [diff] [blame] | 33 | Module for testing openmano functionality. It uses openmanoclient.py for invoking openmano |
| tierno | ed85457 | 2017-10-03 16:18:09 +0200 | [diff] [blame] | 34 | """ |
| Pablo Montes Moreno | eebea06 | 2017-02-27 12:33:10 +0100 | [diff] [blame] | 35 | |
| 36 | import logging |
| Pablo Montes Moreno | eebea06 | 2017-02-27 12:33:10 +0100 | [diff] [blame] | 37 | import os |
| tierno | ec66e9a | 2017-05-17 15:28:10 +0200 | [diff] [blame] | 38 | import argcomplete |
| Pablo Montes Moreno | eebea06 | 2017-02-27 12:33:10 +0100 | [diff] [blame] | 39 | import unittest |
| 40 | import string |
| 41 | import inspect |
| 42 | import random |
| tierno | ed85457 | 2017-10-03 16:18:09 +0200 | [diff] [blame] | 43 | # import traceback |
| Pablo Montes Moreno | eebea06 | 2017-02-27 12:33:10 +0100 | [diff] [blame] | 44 | import glob |
| 45 | import yaml |
| 46 | import sys |
| 47 | import time |
| kasar | bd11fd8 | 2017-06-01 23:44:03 -0700 | [diff] [blame] | 48 | import uuid |
| tierno | ed85457 | 2017-10-03 16:18:09 +0200 | [diff] [blame] | 49 | from argparse import ArgumentParser |
| Pablo Montes Moreno | eebea06 | 2017-02-27 12:33:10 +0100 | [diff] [blame] | 50 | |
| tierno | ed85457 | 2017-10-03 16:18:09 +0200 | [diff] [blame] | 51 | __author__ = "Pablo Montes, Alfonso Tierno" |
| 52 | __date__ = "$16-Feb-2017 17:08:16$" |
| 53 | __version__ = "0.1.0" |
| 54 | version_date = "Oct 2017" |
| 55 | |
| 56 | test_config = {} # used for global variables with the test configuration |
| 57 | |
| tierno | ec66e9a | 2017-05-17 15:28:10 +0200 | [diff] [blame] | 58 | |
| tierno | f050835 | 2017-06-19 13:37:44 +0200 | [diff] [blame] | 59 | class 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 Moreno | eebea06 | 2017-02-27 12:33:10 +0100 | [diff] [blame] | 79 | |
| Pablo Montes Moreno | 2fe24fa | 2017-03-27 12:56:13 +0200 | [diff] [blame] | 80 | def check_instance_scenario_active(uuid): |
| tierno | ec66e9a | 2017-05-17 15:28:10 +0200 | [diff] [blame] | 81 | instance = test_config["client"].get_instance(uuid=uuid) |
| Pablo Montes Moreno | 2fe24fa | 2017-03-27 12:56:13 +0200 | [diff] [blame] | 82 | |
| 83 | for net in instance['nets']: |
| 84 | status = net['status'] |
| Pablo Montes Moreno | b12711f | 2017-04-06 11:54:34 +0200 | [diff] [blame] | 85 | if status != 'ACTIVE': |
| Pablo Montes Moreno | 2fe24fa | 2017-03-27 12:56:13 +0200 | [diff] [blame] | 86 | 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 | |
| tierno | ec66e9a | 2017-05-17 15:28:10 +0200 | [diff] [blame] | 96 | |
| Pablo Montes Moreno | eebea06 | 2017-02-27 12:33:10 +0100 | [diff] [blame] | 97 | ''' |
| 98 | IMPORTANT NOTE |
| 99 | All unittest classes for code based tests must have prefix 'test_' in order to be taken into account for tests |
| 100 | ''' |
| tierno | f050835 | 2017-06-19 13:37:44 +0200 | [diff] [blame] | 101 | class test_VIM_datacenter_tenant_operations(test_base): |
| Pablo Montes Moreno | eebea06 | 2017-02-27 12:33:10 +0100 | [diff] [blame] | 102 | tenant_name = None |
| Pablo Montes Moreno | eebea06 | 2017-02-27 12:33:10 +0100 | [diff] [blame] | 103 | |
| 104 | def test_000_create_RO_tenant(self): |
| 105 | self.__class__.tenant_name = _get_random_string(20) |
| tierno | ec66e9a | 2017-05-17 15:28:10 +0200 | [diff] [blame] | 106 | self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"], self.__class__.test_index, |
| Pablo Montes Moreno | eebea06 | 2017-02-27 12:33:10 +0100 | [diff] [blame] | 107 | inspect.currentframe().f_code.co_name) |
| 108 | self.__class__.test_index += 1 |
| tierno | ec66e9a | 2017-05-17 15:28:10 +0200 | [diff] [blame] | 109 | tenant = test_config["client"].create_tenant(name=self.__class__.tenant_name, |
| 110 | description=self.__class__.tenant_name) |
| Pablo Montes Moreno | eebea06 | 2017-02-27 12:33:10 +0100 | [diff] [blame] | 111 | 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): |
| tierno | ec66e9a | 2017-05-17 15:28:10 +0200 | [diff] [blame] | 115 | self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"], self.__class__.test_index, |
| Pablo Montes Moreno | eebea06 | 2017-02-27 12:33:10 +0100 | [diff] [blame] | 116 | inspect.currentframe().f_code.co_name) |
| 117 | self.__class__.test_index += 1 |
| tierno | ec66e9a | 2017-05-17 15:28:10 +0200 | [diff] [blame] | 118 | tenant = test_config["client"].get_tenant(name=self.__class__.tenant_name) |
| Pablo Montes Moreno | eebea06 | 2017-02-27 12:33:10 +0100 | [diff] [blame] | 119 | 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): |
| tierno | ec66e9a | 2017-05-17 15:28:10 +0200 | [diff] [blame] | 123 | self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"], self.__class__.test_index, |
| Pablo Montes Moreno | eebea06 | 2017-02-27 12:33:10 +0100 | [diff] [blame] | 124 | inspect.currentframe().f_code.co_name) |
| 125 | self.__class__.test_index += 1 |
| tierno | ec66e9a | 2017-05-17 15:28:10 +0200 | [diff] [blame] | 126 | tenant = test_config["client"].delete_tenant(name=self.__class__.tenant_name) |
| Pablo Montes Moreno | eebea06 | 2017-02-27 12:33:10 +0100 | [diff] [blame] | 127 | logger.debug("{}".format(tenant)) |
| 128 | assert('deleted' in tenant.get('result',"")) |
| 129 | |
| tierno | ec66e9a | 2017-05-17 15:28:10 +0200 | [diff] [blame] | 130 | |
| tierno | f050835 | 2017-06-19 13:37:44 +0200 | [diff] [blame] | 131 | class test_VIM_datacenter_operations(test_base): |
| Pablo Montes Moreno | eebea06 | 2017-02-27 12:33:10 +0100 | [diff] [blame] | 132 | datacenter_name = None |
| Pablo Montes Moreno | eebea06 | 2017-02-27 12:33:10 +0100 | [diff] [blame] | 133 | |
| 134 | def test_000_create_datacenter(self): |
| tierno | ec66e9a | 2017-05-17 15:28:10 +0200 | [diff] [blame] | 135 | self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"], self.__class__.test_index, |
| Pablo Montes Moreno | eebea06 | 2017-02-27 12:33:10 +0100 | [diff] [blame] | 136 | inspect.currentframe().f_code.co_name) |
| 137 | self.__class__.datacenter_name = _get_random_string(20) |
| 138 | self.__class__.test_index += 1 |
| tierno | ec66e9a | 2017-05-17 15:28:10 +0200 | [diff] [blame] | 139 | self.datacenter = test_config["client"].create_datacenter(name=self.__class__.datacenter_name, |
| 140 | vim_url="http://fakeurl/fake") |
| Pablo Montes Moreno | eebea06 | 2017-02-27 12:33:10 +0100 | [diff] [blame] | 141 | 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): |
| tierno | ec66e9a | 2017-05-17 15:28:10 +0200 | [diff] [blame] | 145 | self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"], self.__class__.test_index, |
| Pablo Montes Moreno | eebea06 | 2017-02-27 12:33:10 +0100 | [diff] [blame] | 146 | inspect.currentframe().f_code.co_name) |
| 147 | |
| 148 | self.__class__.test_index += 1 |
| tierno | ec66e9a | 2017-05-17 15:28:10 +0200 | [diff] [blame] | 149 | self.datacenter = test_config["client"].get_datacenter(all_tenants=True, name=self.__class__.datacenter_name) |
| Pablo Montes Moreno | eebea06 | 2017-02-27 12:33:10 +0100 | [diff] [blame] | 150 | 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): |
| tierno | ec66e9a | 2017-05-17 15:28:10 +0200 | [diff] [blame] | 154 | self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"], self.__class__.test_index, |
| Pablo Montes Moreno | eebea06 | 2017-02-27 12:33:10 +0100 | [diff] [blame] | 155 | inspect.currentframe().f_code.co_name) |
| 156 | |
| 157 | self.__class__.test_index += 1 |
| tierno | ec66e9a | 2017-05-17 15:28:10 +0200 | [diff] [blame] | 158 | self.datacenter = test_config["client"].attach_datacenter(name=self.__class__.datacenter_name, |
| 159 | vim_tenant_name='fake') |
| Pablo Montes Moreno | eebea06 | 2017-02-27 12:33:10 +0100 | [diff] [blame] | 160 | logger.debug("{}".format(self.datacenter)) |
| tierno | d3750b3 | 2018-07-20 15:33:08 +0200 | [diff] [blame] | 161 | assert ('uuid' in self.datacenter.get('datacenter', {})) |
| Pablo Montes Moreno | eebea06 | 2017-02-27 12:33:10 +0100 | [diff] [blame] | 162 | |
| 163 | def test_030_list_attached_datacenter(self): |
| tierno | ec66e9a | 2017-05-17 15:28:10 +0200 | [diff] [blame] | 164 | self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"], self.__class__.test_index, |
| Pablo Montes Moreno | eebea06 | 2017-02-27 12:33:10 +0100 | [diff] [blame] | 165 | inspect.currentframe().f_code.co_name) |
| 166 | |
| 167 | self.__class__.test_index += 1 |
| tierno | ec66e9a | 2017-05-17 15:28:10 +0200 | [diff] [blame] | 168 | self.datacenter = test_config["client"].get_datacenter(all_tenants=False, name=self.__class__.datacenter_name) |
| Pablo Montes Moreno | eebea06 | 2017-02-27 12:33:10 +0100 | [diff] [blame] | 169 | 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): |
| tierno | ec66e9a | 2017-05-17 15:28:10 +0200 | [diff] [blame] | 173 | self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"], self.__class__.test_index, |
| Pablo Montes Moreno | eebea06 | 2017-02-27 12:33:10 +0100 | [diff] [blame] | 174 | inspect.currentframe().f_code.co_name) |
| 175 | |
| 176 | self.__class__.test_index += 1 |
| tierno | ec66e9a | 2017-05-17 15:28:10 +0200 | [diff] [blame] | 177 | self.datacenter = test_config["client"].detach_datacenter(name=self.__class__.datacenter_name) |
| Pablo Montes Moreno | eebea06 | 2017-02-27 12:33:10 +0100 | [diff] [blame] | 178 | logger.debug("{}".format(self.datacenter)) |
| 179 | assert ('detached' in self.datacenter.get('result', "")) |
| 180 | |
| 181 | def test_050_delete_datacenter(self): |
| tierno | ec66e9a | 2017-05-17 15:28:10 +0200 | [diff] [blame] | 182 | self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"], self.__class__.test_index, |
| Pablo Montes Moreno | eebea06 | 2017-02-27 12:33:10 +0100 | [diff] [blame] | 183 | inspect.currentframe().f_code.co_name) |
| 184 | |
| 185 | self.__class__.test_index += 1 |
| tierno | ec66e9a | 2017-05-17 15:28:10 +0200 | [diff] [blame] | 186 | self.datacenter = test_config["client"].delete_datacenter(name=self.__class__.datacenter_name) |
| Pablo Montes Moreno | eebea06 | 2017-02-27 12:33:10 +0100 | [diff] [blame] | 187 | logger.debug("{}".format(self.datacenter)) |
| 188 | assert('deleted' in self.datacenter.get('result',"")) |
| 189 | |
| tierno | ec66e9a | 2017-05-17 15:28:10 +0200 | [diff] [blame] | 190 | |
| tierno | f050835 | 2017-06-19 13:37:44 +0200 | [diff] [blame] | 191 | class test_VIM_network_operations(test_base): |
| Pablo Montes Moreno | eebea06 | 2017-02-27 12:33:10 +0100 | [diff] [blame] | 192 | vim_network_name = None |
| Pablo Montes Moreno | eebea06 | 2017-02-27 12:33:10 +0100 | [diff] [blame] | 193 | vim_network_uuid = None |
| 194 | |
| Pablo Montes Moreno | eebea06 | 2017-02-27 12:33:10 +0100 | [diff] [blame] | 195 | def test_000_create_VIM_network(self): |
| tierno | ec66e9a | 2017-05-17 15:28:10 +0200 | [diff] [blame] | 196 | self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"], self.__class__.test_index, |
| Pablo Montes Moreno | eebea06 | 2017-02-27 12:33:10 +0100 | [diff] [blame] | 197 | inspect.currentframe().f_code.co_name) |
| 198 | self.__class__.vim_network_name = _get_random_string(20) |
| 199 | self.__class__.test_index += 1 |
| tierno | ec66e9a | 2017-05-17 15:28:10 +0200 | [diff] [blame] | 200 | network = test_config["client"].vim_action("create", "networks", name=self.__class__.vim_network_name) |
| Pablo Montes Moreno | eebea06 | 2017-02-27 12:33:10 +0100 | [diff] [blame] | 201 | 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): |
| tierno | ec66e9a | 2017-05-17 15:28:10 +0200 | [diff] [blame] | 206 | self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"], self.__class__.test_index, |
| Pablo Montes Moreno | eebea06 | 2017-02-27 12:33:10 +0100 | [diff] [blame] | 207 | inspect.currentframe().f_code.co_name) |
| 208 | self.__class__.test_index += 1 |
| tierno | ec66e9a | 2017-05-17 15:28:10 +0200 | [diff] [blame] | 209 | networks = test_config["client"].vim_action("list", "networks") |
| Pablo Montes Moreno | eebea06 | 2017-02-27 12:33:10 +0100 | [diff] [blame] | 210 | logger.debug("{}".format(networks)) |
| 211 | |
| 212 | def test_020_get_VIM_network_by_uuid(self): |
| tierno | ec66e9a | 2017-05-17 15:28:10 +0200 | [diff] [blame] | 213 | self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"], self.__class__.test_index, |
| Pablo Montes Moreno | eebea06 | 2017-02-27 12:33:10 +0100 | [diff] [blame] | 214 | inspect.currentframe().f_code.co_name) |
| 215 | |
| 216 | self.__class__.test_index += 1 |
| tierno | ec66e9a | 2017-05-17 15:28:10 +0200 | [diff] [blame] | 217 | network = test_config["client"].vim_action("show", "networks", uuid=self.__class__.vim_network_uuid) |
| Pablo Montes Moreno | eebea06 | 2017-02-27 12:33:10 +0100 | [diff] [blame] | 218 | 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): |
| tierno | ec66e9a | 2017-05-17 15:28:10 +0200 | [diff] [blame] | 222 | self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"], self.__class__.test_index, |
| Pablo Montes Moreno | eebea06 | 2017-02-27 12:33:10 +0100 | [diff] [blame] | 223 | inspect.currentframe().f_code.co_name) |
| 224 | |
| 225 | self.__class__.test_index += 1 |
| tierno | ec66e9a | 2017-05-17 15:28:10 +0200 | [diff] [blame] | 226 | network = test_config["client"].vim_action("delete", "networks", uuid=self.__class__.vim_network_uuid) |
| Pablo Montes Moreno | eebea06 | 2017-02-27 12:33:10 +0100 | [diff] [blame] | 227 | logger.debug("{}".format(network)) |
| 228 | assert ('deleted' in network.get('result', "")) |
| 229 | |
| tierno | ec66e9a | 2017-05-17 15:28:10 +0200 | [diff] [blame] | 230 | |
| tierno | f050835 | 2017-06-19 13:37:44 +0200 | [diff] [blame] | 231 | class test_VIM_image_operations(test_base): |
| Pablo Montes Moreno | eebea06 | 2017-02-27 12:33:10 +0100 | [diff] [blame] | 232 | |
| 233 | def test_000_list_VIM_images(self): |
| tierno | ec66e9a | 2017-05-17 15:28:10 +0200 | [diff] [blame] | 234 | self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"], self.__class__.test_index, |
| Pablo Montes Moreno | eebea06 | 2017-02-27 12:33:10 +0100 | [diff] [blame] | 235 | inspect.currentframe().f_code.co_name) |
| 236 | self.__class__.test_index += 1 |
| tierno | ec66e9a | 2017-05-17 15:28:10 +0200 | [diff] [blame] | 237 | images = test_config["client"].vim_action("list", "images") |
| Pablo Montes Moreno | eebea06 | 2017-02-27 12:33:10 +0100 | [diff] [blame] | 238 | logger.debug("{}".format(images)) |
| 239 | |
| 240 | ''' |
| 241 | The following is a non critical test that will fail most of the times. |
| 242 | In case of OpenStack datacenter these tests will only success if RO has access to the admin endpoint |
| 243 | This test will only be executed in case it is specifically requested by the user |
| 244 | ''' |
| tierno | f050835 | 2017-06-19 13:37:44 +0200 | [diff] [blame] | 245 | class test_VIM_tenant_operations(test_base): |
| Pablo Montes Moreno | eebea06 | 2017-02-27 12:33:10 +0100 | [diff] [blame] | 246 | vim_tenant_name = None |
| Pablo Montes Moreno | eebea06 | 2017-02-27 12:33:10 +0100 | [diff] [blame] | 247 | vim_tenant_uuid = None |
| 248 | |
| 249 | @classmethod |
| 250 | def setUpClass(cls): |
| tierno | f050835 | 2017-06-19 13:37:44 +0200 | [diff] [blame] | 251 | test_base.setUpClass(cls) |
| Pablo Montes Moreno | eebea06 | 2017-02-27 12:33:10 +0100 | [diff] [blame] | 252 | logger.warning("In case of OpenStack datacenter these tests will only success " |
| 253 | "if RO has access to the admin endpoint") |
| 254 | |
| Pablo Montes Moreno | eebea06 | 2017-02-27 12:33:10 +0100 | [diff] [blame] | 255 | def test_000_create_VIM_tenant(self): |
| tierno | ec66e9a | 2017-05-17 15:28:10 +0200 | [diff] [blame] | 256 | self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"], self.__class__.test_index, |
| Pablo Montes Moreno | eebea06 | 2017-02-27 12:33:10 +0100 | [diff] [blame] | 257 | inspect.currentframe().f_code.co_name) |
| 258 | self.__class__.vim_tenant_name = _get_random_string(20) |
| 259 | self.__class__.test_index += 1 |
| tierno | ec66e9a | 2017-05-17 15:28:10 +0200 | [diff] [blame] | 260 | tenant = test_config["client"].vim_action("create", "tenants", name=self.__class__.vim_tenant_name) |
| Pablo Montes Moreno | eebea06 | 2017-02-27 12:33:10 +0100 | [diff] [blame] | 261 | 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): |
| tierno | ec66e9a | 2017-05-17 15:28:10 +0200 | [diff] [blame] | 266 | self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"], self.__class__.test_index, |
| Pablo Montes Moreno | eebea06 | 2017-02-27 12:33:10 +0100 | [diff] [blame] | 267 | inspect.currentframe().f_code.co_name) |
| 268 | self.__class__.test_index += 1 |
| tierno | ec66e9a | 2017-05-17 15:28:10 +0200 | [diff] [blame] | 269 | tenants = test_config["client"].vim_action("list", "tenants") |
| Pablo Montes Moreno | eebea06 | 2017-02-27 12:33:10 +0100 | [diff] [blame] | 270 | logger.debug("{}".format(tenants)) |
| 271 | |
| 272 | def test_020_get_VIM_tenant_by_uuid(self): |
| tierno | ec66e9a | 2017-05-17 15:28:10 +0200 | [diff] [blame] | 273 | self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"], self.__class__.test_index, |
| Pablo Montes Moreno | eebea06 | 2017-02-27 12:33:10 +0100 | [diff] [blame] | 274 | inspect.currentframe().f_code.co_name) |
| 275 | |
| 276 | self.__class__.test_index += 1 |
| tierno | ec66e9a | 2017-05-17 15:28:10 +0200 | [diff] [blame] | 277 | tenant = test_config["client"].vim_action("show", "tenants", uuid=self.__class__.vim_tenant_uuid) |
| Pablo Montes Moreno | eebea06 | 2017-02-27 12:33:10 +0100 | [diff] [blame] | 278 | 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): |
| tierno | ec66e9a | 2017-05-17 15:28:10 +0200 | [diff] [blame] | 282 | self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"], self.__class__.test_index, |
| Pablo Montes Moreno | eebea06 | 2017-02-27 12:33:10 +0100 | [diff] [blame] | 283 | inspect.currentframe().f_code.co_name) |
| 284 | |
| 285 | self.__class__.test_index += 1 |
| tierno | ec66e9a | 2017-05-17 15:28:10 +0200 | [diff] [blame] | 286 | tenant = test_config["client"].vim_action("delete", "tenants", uuid=self.__class__.vim_tenant_uuid) |
| Pablo Montes Moreno | eebea06 | 2017-02-27 12:33:10 +0100 | [diff] [blame] | 287 | logger.debug("{}".format(tenant)) |
| 288 | assert ('deleted' in tenant.get('result', "")) |
| 289 | |
| tierno | ed85457 | 2017-10-03 16:18:09 +0200 | [diff] [blame] | 290 | |
| tierno | f050835 | 2017-06-19 13:37:44 +0200 | [diff] [blame] | 291 | class test_vimconn_connect(test_base): |
| kasar | 70532ae | 2017-05-26 03:53:52 -0700 | [diff] [blame] | 292 | |
| 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)) |
| kasar | c5bf293 | 2018-03-09 04:15:22 -0800 | [diff] [blame] | 302 | self.assertIsNotNone(vca_object) |
| jamartinezv | 14a823d | 2019-08-01 11:45:15 +0200 | [diff] [blame^] | 303 | elif test_config['vimtype'] in ('openstack', 'azure'): |
| anwars | c76a3ee | 2018-10-04 14:05:32 +0530 | [diff] [blame] | 304 | 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) |
| kasar | 70532ae | 2017-05-26 03:53:52 -0700 | [diff] [blame] | 308 | |
| tierno | f050835 | 2017-06-19 13:37:44 +0200 | [diff] [blame] | 309 | class test_vimconn_new_network(test_base): |
| kasar | 70532ae | 2017-05-26 03:53:52 -0700 | [diff] [blame] | 310 | network_name = None |
| kasar | 70532ae | 2017-05-26 03:53:52 -0700 | [diff] [blame] | 311 | |
| 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 | |
| jamartinezv | 14a823d | 2019-08-01 11:45:15 +0200 | [diff] [blame^] | 320 | network, _ = test_config["vim_conn"].new_network(net_name=self.__class__.network_name, |
| kasar | 70532ae | 2017-05-26 03:53:52 -0700 | [diff] [blame] | 321 | net_type=network_type) |
| 322 | self.__class__.network_id = network |
| 323 | logger.debug("{}".format(network)) |
| 324 | |
| kasar | f358ad5 | 2017-07-24 01:28:44 -0700 | [diff] [blame] | 325 | network_list = test_config["vim_conn"].get_network_list() |
| kasar | 70532ae | 2017-05-26 03:53:52 -0700 | [diff] [blame] | 326 | 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) |
| jamartinezv | 14a823d | 2019-08-01 11:45:15 +0200 | [diff] [blame^] | 347 | network_id, _ = test_config["vim_conn"].new_network(net_name=self.__class__.network_name, |
| kasar | 70532ae | 2017-05-26 03:53:52 -0700 | [diff] [blame] | 348 | net_type=net_type) |
| 349 | |
| 350 | delete_net_ids.append(network_id) |
| 351 | logger.debug("{}".format(network_id)) |
| 352 | |
| kasar | f358ad5 | 2017-07-24 01:28:44 -0700 | [diff] [blame] | 353 | network_list = test_config["vim_conn"].get_network_list() |
| kasar | 70532ae | 2017-05-26 03:53:52 -0700 | [diff] [blame] | 354 | 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'] |
| anwars | c76a3ee | 2018-10-04 14:05:32 +0530 | [diff] [blame] | 389 | dhcp_start_address = item['ip-profile']['dhcp']['start-address'] |
| 390 | subnet_address = item['ip-profile']['subnet-address'] |
| 391 | |
| kasar | 70532ae | 2017-05-26 03:53:52 -0700 | [diff] [blame] | 392 | |
| 393 | self.__class__.network_name = _get_random_string(20) |
| 394 | ip_profile = {'dhcp_count': dhcp_count, |
| 395 | 'dhcp_enabled': dhcp_enabled, |
| anwars | c76a3ee | 2018-10-04 14:05:32 +0530 | [diff] [blame] | 396 | 'dhcp_start_address': dhcp_start_address, |
| 397 | 'ip_version': version, |
| 398 | 'subnet_address': subnet_address |
| kasar | 70532ae | 2017-05-26 03:53:52 -0700 | [diff] [blame] | 399 | } |
| 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 |
| jamartinezv | 14a823d | 2019-08-01 11:45:15 +0200 | [diff] [blame^] | 404 | network, _ = test_config["vim_conn"].new_network(net_name=self.__class__.network_name, |
| kasar | 70532ae | 2017-05-26 03:53:52 -0700 | [diff] [blame] | 405 | net_type='mgmt', |
| 406 | ip_profile=ip_profile) |
| 407 | self.__class__.network_id = network |
| 408 | logger.debug("{}".format(network)) |
| 409 | |
| kasar | f358ad5 | 2017-07-24 01:28:44 -0700 | [diff] [blame] | 410 | network_list = test_config["vim_conn"].get_network_list() |
| kasar | 70532ae | 2017-05-26 03:53:52 -0700 | [diff] [blame] | 411 | 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 |
| jamartinezv | 14a823d | 2019-08-01 11:45:15 +0200 | [diff] [blame^] | 429 | network, _ = test_config["vim_conn"].new_network(net_name=self.__class__.network_name, |
| kasar | 70532ae | 2017-05-26 03:53:52 -0700 | [diff] [blame] | 430 | net_type='bridge', |
| 431 | shared=shared) |
| 432 | self.__class__.network_id = network |
| 433 | logger.debug("{}".format(network)) |
| 434 | |
| kasar | f358ad5 | 2017-07-24 01:28:44 -0700 | [diff] [blame] | 435 | network_list = test_config["vim_conn"].get_network_list() |
| kasar | 70532ae | 2017-05-26 03:53:52 -0700 | [diff] [blame] | 436 | 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 |
| jamartinezv | 14a823d | 2019-08-01 11:45:15 +0200 | [diff] [blame^] | 454 | network, _ = test_config["vim_conn"].new_network(net_name=self.__class__.network_name, |
| kasar | 70532ae | 2017-05-26 03:53:52 -0700 | [diff] [blame] | 455 | net_type='unknowntype') |
| 456 | self.__class__.network_id = network |
| 457 | logger.debug("{}".format(network)) |
| kasar | f358ad5 | 2017-07-24 01:28:44 -0700 | [diff] [blame] | 458 | network_list = test_config["vim_conn"].get_network_list() |
| kasar | 70532ae | 2017-05-26 03:53:52 -0700 | [diff] [blame] | 459 | 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 | |
| kasar | 114050e | 2017-07-06 02:04:59 -0700 | [diff] [blame] | 470 | 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' |
| jamartinezv | 14a823d | 2019-08-01 11:45:15 +0200 | [diff] [blame^] | 478 | network_id, _ = test_config["vim_conn"].new_network(net_name=network_name, |
| kasar | 114050e | 2017-07-06 02:04:59 -0700 | [diff] [blame] | 479 | 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]) |
| jamartinezv | 14a823d | 2019-08-01 11:45:15 +0200 | [diff] [blame^] | 502 | if test_config['vimtype'] in ('openstack', 'azure'): |
| anwars | c76a3ee | 2018-10-04 14:05:32 +0530 | [diff] [blame] | 503 | 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, {}) |
| kasar | 114050e | 2017-07-06 02:04:59 -0700 | [diff] [blame] | 507 | |
| tierno | f050835 | 2017-06-19 13:37:44 +0200 | [diff] [blame] | 508 | class test_vimconn_get_network_list(test_base): |
| kasar | 70532ae | 2017-05-26 03:53:52 -0700 | [diff] [blame] | 509 | network_name = None |
| kasar | 70532ae | 2017-05-26 03:53:52 -0700 | [diff] [blame] | 510 | |
| kasar | 70532ae | 2017-05-26 03:53:52 -0700 | [diff] [blame] | 511 | def setUp(self): |
| 512 | # creating new network |
| 513 | self.__class__.network_name = _get_random_string(20) |
| 514 | self.__class__.net_type = 'bridge' |
| jamartinezv | 14a823d | 2019-08-01 11:45:15 +0200 | [diff] [blame^] | 515 | network, _ = test_config["vim_conn"].new_network(net_name=self.__class__.network_name, |
| kasar | 70532ae | 2017-05-26 03:53:52 -0700 | [diff] [blame] | 516 | net_type=self.__class__.net_type) |
| 517 | self.__class__.network_id = network |
| 518 | logger.debug("{}".format(network)) |
| 519 | |
| 520 | def tearDown(self): |
| tierno | f050835 | 2017-06-19 13:37:44 +0200 | [diff] [blame] | 521 | test_base.tearDown(self) |
| kasar | 70532ae | 2017-05-26 03:53:52 -0700 | [diff] [blame] | 522 | |
| 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') |
| jamartinezv | 14a823d | 2019-08-01 11:45:15 +0200 | [diff] [blame^] | 542 | if test_config['vimtype'] != 'azure': |
| 543 | self.assertEqual(net.get('shared'), False) |
| kasar | 70532ae | 2017-05-26 03:53:52 -0700 | [diff] [blame] | 544 | |
| 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 | |
| jamartinezv | 14a823d | 2019-08-01 11:45:15 +0200 | [diff] [blame^] | 551 | if test_config['vimtype'] in ('openstack', 'azure'): |
| anwars | c76a3ee | 2018-10-04 14:05:32 +0530 | [diff] [blame] | 552 | 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) |
| kasar | 70532ae | 2017-05-26 03:53:52 -0700 | [diff] [blame] | 555 | |
| 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 | |
| jamartinezv | 14a823d | 2019-08-01 11:45:15 +0200 | [diff] [blame^] | 585 | if test_config['vimtype'] in ('openstack', 'azure'): |
| anwars | c76a3ee | 2018-10-04 14:05:32 +0530 | [diff] [blame] | 586 | 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) |
| kasar | 70532ae | 2017-05-26 03:53:52 -0700 | [diff] [blame] | 589 | # 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() |
| jamartinezv | 14a823d | 2019-08-01 11:45:15 +0200 | [diff] [blame^] | 605 | if test_config['vimtype'] in ('openstack', 'azure'): |
| anwars | c76a3ee | 2018-10-04 14:05:32 +0530 | [diff] [blame] | 606 | 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) |
| kasar | 70532ae | 2017-05-26 03:53:52 -0700 | [diff] [blame] | 609 | |
| 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 | |
| jamartinezv | 14a823d | 2019-08-01 11:45:15 +0200 | [diff] [blame^] | 629 | if test_config['vimtype'] in ('openstack', 'azure'): |
| anwars | c76a3ee | 2018-10-04 14:05:32 +0530 | [diff] [blame] | 630 | 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) |
| kasar | 70532ae | 2017-05-26 03:53:52 -0700 | [diff] [blame] | 633 | |
| 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 | |
| tierno | f050835 | 2017-06-19 13:37:44 +0200 | [diff] [blame] | 651 | class test_vimconn_get_network(test_base): |
| kasar | bd11fd8 | 2017-06-01 23:44:03 -0700 | [diff] [blame] | 652 | network_name = None |
| kasar | bd11fd8 | 2017-06-01 23:44:03 -0700 | [diff] [blame] | 653 | |
| 654 | def setUp(self): |
| 655 | # creating new network |
| 656 | self.__class__.network_name = _get_random_string(20) |
| 657 | self.__class__.net_type = 'bridge' |
| jamartinezv | 14a823d | 2019-08-01 11:45:15 +0200 | [diff] [blame^] | 658 | network, _ = test_config["vim_conn"].new_network(net_name=self.__class__.network_name, |
| kasar | bd11fd8 | 2017-06-01 23:44:03 -0700 | [diff] [blame] | 659 | net_type=self.__class__.net_type) |
| 660 | self.__class__.network_id = network |
| 661 | logger.debug("{}".format(network)) |
| 662 | |
| 663 | def tearDown(self): |
| tierno | f050835 | 2017-06-19 13:37:44 +0200 | [diff] [blame] | 664 | test_base.tearDown(self) |
| kasar | bd11fd8 | 2017-06-01 23:44:03 -0700 | [diff] [blame] | 665 | |
| 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 |
| kasar | c5bf293 | 2018-03-09 04:15:22 -0800 | [diff] [blame] | 691 | with self.assertRaises(Exception) as context: |
| 692 | test_config["vim_conn"].get_network(Non_exist_id) |
| kasar | bd11fd8 | 2017-06-01 23:44:03 -0700 | [diff] [blame] | 693 | |
| kasar | c5bf293 | 2018-03-09 04:15:22 -0800 | [diff] [blame] | 694 | self.assertEqual((context.exception).http_code, 404) |
| kasar | bd11fd8 | 2017-06-01 23:44:03 -0700 | [diff] [blame] | 695 | |
| tierno | f050835 | 2017-06-19 13:37:44 +0200 | [diff] [blame] | 696 | class test_vimconn_delete_network(test_base): |
| kasar | bd11fd8 | 2017-06-01 23:44:03 -0700 | [diff] [blame] | 697 | network_name = None |
| kasar | bd11fd8 | 2017-06-01 23:44:03 -0700 | [diff] [blame] | 698 | |
| 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' |
| jamartinezv | 14a823d | 2019-08-01 11:45:15 +0200 | [diff] [blame^] | 703 | network, _ = test_config["vim_conn"].new_network(net_name=self.__class__.network_name, |
| kasar | bd11fd8 | 2017-06-01 23:44:03 -0700 | [diff] [blame] | 704 | 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 | |
| tierno | 12a0c3b | 2018-10-15 15:10:36 +0200 | [diff] [blame] | 734 | self.assertEqual((context.exception).http_code, 404) |
| kasar | bd11fd8 | 2017-06-01 23:44:03 -0700 | [diff] [blame] | 735 | |
| tierno | f050835 | 2017-06-19 13:37:44 +0200 | [diff] [blame] | 736 | class test_vimconn_get_flavor(test_base): |
| kasar | bd11fd8 | 2017-06-01 23:44:03 -0700 | [diff] [blame] | 737 | |
| 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 | |
| anwars | c76a3ee | 2018-10-04 14:05:32 +0530 | [diff] [blame] | 758 | flavor_data = { |
| 759 | 'name' : _get_random_string(20), |
| 760 | 'ram': ram, |
| kasar | bd11fd8 | 2017-06-01 23:44:03 -0700 | [diff] [blame] | 761 | 'vcpus': vcpus, |
| 762 | 'disk': disk |
| anwars | c76a3ee | 2018-10-04 14:05:32 +0530 | [diff] [blame] | 763 | } |
| kasar | bd11fd8 | 2017-06-01 23:44:03 -0700 | [diff] [blame] | 764 | |
| 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) |
| jamartinezv | 14a823d | 2019-08-01 11:45:15 +0200 | [diff] [blame^] | 773 | |
| 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']) |
| kasar | bd11fd8 | 2017-06-01 23:44:03 -0700 | [diff] [blame] | 782 | |
| 783 | # delete flavor |
| jamartinezv | 14a823d | 2019-08-01 11:45:15 +0200 | [diff] [blame^] | 784 | 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)) |
| kasar | bd11fd8 | 2017-06-01 23:44:03 -0700 | [diff] [blame] | 790 | |
| 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 | |
| kasar | feaaa05 | 2017-06-08 03:46:18 -0700 | [diff] [blame] | 804 | class test_vimconn_new_flavor(test_base): |
| 805 | flavor_id = None |
| 806 | |
| 807 | def test_000_new_flavor(self): |
| jamartinezv | 14a823d | 2019-08-01 11:45:15 +0200 | [diff] [blame^] | 808 | flavor_data = {'name': _get_random_string(20), 'ram': 1024, 'vcpus': 1, 'disk': 10} |
| kasar | feaaa05 | 2017-06-08 03:46:18 -0700 | [diff] [blame] | 809 | |
| 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 |
| kasar | 114050e | 2017-07-06 02:04:59 -0700 | [diff] [blame] | 816 | self.__class__.flavor_id = test_config["vim_conn"].new_flavor(flavor_data) |
| anwars | c76a3ee | 2018-10-04 14:05:32 +0530 | [diff] [blame] | 817 | self.assertIsInstance(self.__class__.flavor_id, (str, unicode)) |
| 818 | self.assertIsInstance(uuid.UUID(self.__class__.flavor_id), uuid.UUID) |
| kasar | feaaa05 | 2017-06-08 03:46:18 -0700 | [diff] [blame] | 819 | |
| 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 |
| jamartinezv | 14a823d | 2019-08-01 11:45:15 +0200 | [diff] [blame^] | 827 | 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) |
| kasar | feaaa05 | 2017-06-08 03:46:18 -0700 | [diff] [blame] | 832 | else: |
| jamartinezv | 14a823d | 2019-08-01 11:45:15 +0200 | [diff] [blame^] | 833 | 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") |
| kasar | feaaa05 | 2017-06-08 03:46:18 -0700 | [diff] [blame] | 839 | |
| 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 | |
| jamartinezv | 14a823d | 2019-08-01 11:45:15 +0200 | [diff] [blame^] | 851 | if test_config['vimtype'] == 'azure': |
| 852 | self.assertEqual((context.exception).http_code, 404) |
| 853 | else: |
| 854 | self.assertEqual((context.exception).http_code, 400) |
| kasar | feaaa05 | 2017-06-08 03:46:18 -0700 | [diff] [blame] | 855 | |
| 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 | |
| jamartinezv | 14a823d | 2019-08-01 11:45:15 +0200 | [diff] [blame^] | 867 | if test_config['vimtype'] == 'azure': |
| 868 | self.assertEqual((context.exception).http_code, 401) |
| 869 | else: |
| 870 | self.assertEqual((context.exception).http_code, 404) |
| kasar | feaaa05 | 2017-06-08 03:46:18 -0700 | [diff] [blame] | 871 | |
| 872 | class 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: |
| jamartinezv | 14a823d | 2019-08-01 11:45:15 +0200 | [diff] [blame^] | 882 | self.__class__.image_id = test_config["vim_conn"].new_image({ 'name': 'TestImage', 'location' : image_path, |
| 883 | 'metadata': {'upload_location':None} }) |
| kasar | c705303 | 2017-08-03 03:29:23 -0700 | [diff] [blame] | 884 | time.sleep(20) |
| shashankjain | 3c83a21 | 2018-10-04 13:05:46 +0530 | [diff] [blame] | 885 | |
| 886 | self.assertIsInstance(self.__class__.image_id, (str, unicode)) |
| 887 | self.assertIsInstance(uuid.UUID(self.__class__.image_id), uuid.UUID) |
| kasar | feaaa05 | 2017-06-08 03:46:18 -0700 | [diff] [blame] | 888 | 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: |
| shashankjain | 3c83a21 | 2018-10-04 13:05:46 +0530 | [diff] [blame] | 900 | test_config["vim_conn"].new_image({ 'name': 'TestImage', 'location' : Non_exist_image_path}) |
| kasar | feaaa05 | 2017-06-08 03:46:18 -0700 | [diff] [blame] | 901 | |
| 902 | self.assertEqual((context.exception).http_code, 400) |
| kasar | 70532ae | 2017-05-26 03:53:52 -0700 | [diff] [blame] | 903 | |
| kasar | c705303 | 2017-08-03 03:29:23 -0700 | [diff] [blame] | 904 | 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) |
| shashankjain | 3c83a21 | 2018-10-04 13:05:46 +0530 | [diff] [blame] | 911 | |
| 912 | self.assertIsInstance(image_id, (str, unicode)) |
| kasar | c705303 | 2017-08-03 03:29:23 -0700 | [diff] [blame] | 913 | |
| 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 | |
| kasar | ffdaf29 | 2017-06-23 04:06:52 -0700 | [diff] [blame] | 927 | class 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 | |
| 955 | class 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 |
| jamartinezv | 14a823d | 2019-08-01 11:45:15 +0200 | [diff] [blame^] | 964 | |
| 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() |
| kasar | ffdaf29 | 2017-06-23 04:06:52 -0700 | [diff] [blame] | 969 | |
| 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'] |
| shashankjain | 3c83a21 | 2018-10-04 13:05:46 +0530 | [diff] [blame] | 974 | self.assertIsInstance(self.__class__.image_name, (str, unicode)) |
| 975 | self.assertIsInstance(self.__class__.image_id, (str, unicode)) |
| kasar | ffdaf29 | 2017-06-23 04:06:52 -0700 | [diff] [blame] | 976 | |
| 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: |
| shashankjain | 3c83a21 | 2018-10-04 13:05:46 +0530 | [diff] [blame] | 986 | self.assertIsInstance(item['id'], (str, unicode)) |
| 987 | self.assertIsInstance(item['name'], (str, unicode)) |
| kasar | ffdaf29 | 2017-06-23 04:06:52 -0700 | [diff] [blame] | 988 | self.assertEqual(item['id'], self.__class__.image_id) |
| kasar | ffdaf29 | 2017-06-23 04:06:52 -0700 | [diff] [blame] | 989 | 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: |
| shashankjain | 3c83a21 | 2018-10-04 13:05:46 +0530 | [diff] [blame] | 1000 | 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) |
| kasar | ffdaf29 | 2017-06-23 04:06:52 -0700 | [diff] [blame] | 1004 | |
| 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 | |
| 1016 | class test_vimconn_new_vminstance(test_base): |
| 1017 | network_name = None |
| 1018 | net_type = None |
| 1019 | network_id = None |
| 1020 | image_id = None |
| kasar | 114050e | 2017-07-06 02:04:59 -0700 | [diff] [blame] | 1021 | instance_id = None |
| kasar | ffdaf29 | 2017-06-23 04:06:52 -0700 | [diff] [blame] | 1022 | |
| 1023 | def setUp(self): |
| 1024 | # create network |
| 1025 | self.__class__.network_name = _get_random_string(20) |
| 1026 | self.__class__.net_type = 'bridge' |
| 1027 | |
| jamartinezv | 14a823d | 2019-08-01 11:45:15 +0200 | [diff] [blame^] | 1028 | self.__class__.network_id, _ = test_config["vim_conn"].new_network(net_name=self.__class__.network_name, |
| kasar | ffdaf29 | 2017-06-23 04:06:52 -0700 | [diff] [blame] | 1029 | net_type=self.__class__.net_type) |
| kasar | ffdaf29 | 2017-06-23 04:06:52 -0700 | [diff] [blame] | 1030 | # 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 | |
| kasar | ffdaf29 | 2017-06-23 04:06:52 -0700 | [diff] [blame] | 1044 | 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 | |
| kokardekar | 430e62f | 2018-10-04 14:27:09 +0530 | [diff] [blame] | 1057 | flavor_data = {'name': _get_random_string(20), 'ram': 1024, 'vcpus': 1, 'disk': 10} |
| kasar | ffdaf29 | 2017-06-23 04:06:52 -0700 | [diff] [blame] | 1058 | |
| 1059 | # create new flavor |
| 1060 | flavor_id = test_config["vim_conn"].new_flavor(flavor_data) |
| 1061 | |
| kasar | ffdaf29 | 2017-06-23 04:06:52 -0700 | [diff] [blame] | 1062 | |
| 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 | |
| jamartinezv | 14a823d | 2019-08-01 11:45:15 +0200 | [diff] [blame^] | 1068 | 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}] |
| kasar | ffdaf29 | 2017-06-23 04:06:52 -0700 | [diff] [blame] | 1070 | |
| jamartinezv | 14a823d | 2019-08-01 11:45:15 +0200 | [diff] [blame^] | 1071 | 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) |
| kasar | ffdaf29 | 2017-06-23 04:06:52 -0700 | [diff] [blame] | 1075 | |
| kokardekar | 430e62f | 2018-10-04 14:27:09 +0530 | [diff] [blame] | 1076 | self.assertIsInstance(self.__class__.instance_id, (str, unicode)) |
| kasar | ffdaf29 | 2017-06-23 04:06:52 -0700 | [diff] [blame] | 1077 | |
| 1078 | def test_010_new_vminstance_by_model(self): |
| kokardekar | 430e62f | 2018-10-04 14:27:09 +0530 | [diff] [blame] | 1079 | flavor_data = {'name': _get_random_string(20),'ram': 1024, 'vcpus': 2, 'disk': 10} |
| kasar | ffdaf29 | 2017-06-23 04:06:52 -0700 | [diff] [blame] | 1080 | 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 | |
| jamartinezv | 14a823d | 2019-08-01 11:45:15 +0200 | [diff] [blame^] | 1091 | 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}] |
| kasar | ffdaf29 | 2017-06-23 04:06:52 -0700 | [diff] [blame] | 1093 | |
| jamartinezv | 14a823d | 2019-08-01 11:45:15 +0200 | [diff] [blame^] | 1094 | 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) |
| kokardekar | 430e62f | 2018-10-04 14:27:09 +0530 | [diff] [blame] | 1097 | |
| 1098 | self.assertIsInstance(instance_id, (str, unicode)) |
| 1099 | |
| kasar | ffdaf29 | 2017-06-23 04:06:52 -0700 | [diff] [blame] | 1100 | # 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): |
| kokardekar | 430e62f | 2018-10-04 14:27:09 +0530 | [diff] [blame] | 1106 | flavor_data = {'name': _get_random_string(20),'ram': 1024, 'vcpus': 2, 'disk': 10} |
| kasar | ffdaf29 | 2017-06-23 04:06:52 -0700 | [diff] [blame] | 1107 | 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 | |
| jamartinezv | 14a823d | 2019-08-01 11:45:15 +0200 | [diff] [blame^] | 1118 | net_list = [{'use': net_use, 'name': name, 'floating_ip': False, 'port_security': True, 'type': 'virtual', |
| 1119 | 'net_id': self.__class__.network_id}] |
| kasar | ffdaf29 | 2017-06-23 04:06:52 -0700 | [diff] [blame] | 1120 | |
| jamartinezv | 14a823d | 2019-08-01 11:45:15 +0200 | [diff] [blame^] | 1121 | 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) |
| kokardekar | 430e62f | 2018-10-04 14:27:09 +0530 | [diff] [blame] | 1124 | self.assertIsInstance(instance_id, (str, unicode)) |
| 1125 | |
| kasar | ffdaf29 | 2017-06-23 04:06:52 -0700 | [diff] [blame] | 1126 | # 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): |
| kokardekar | 430e62f | 2018-10-04 14:27:09 +0530 | [diff] [blame] | 1132 | flavor_data = {'name':_get_random_string(20),'ram': 1024, 'vcpus': 2, 'disk': 10} |
| kasar | ffdaf29 | 2017-06-23 04:06:52 -0700 | [diff] [blame] | 1133 | _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 | |
| kokardekar | 430e62f | 2018-10-04 14:27:09 +0530 | [diff] [blame] | 1144 | 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}] |
| kasar | ffdaf29 | 2017-06-23 04:06:52 -0700 | [diff] [blame] | 1147 | |
| kokardekar | 430e62f | 2018-10-04 14:27:09 +0530 | [diff] [blame] | 1148 | 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 | |
| jamartinezv | 14a823d | 2019-08-01 11:45:15 +0200 | [diff] [blame^] | 1153 | if test_config['vimtype'] in ('openstack', 'azure'): |
| kokardekar | 430e62f | 2018-10-04 14:27:09 +0530 | [diff] [blame] | 1154 | # create network of type data |
| 1155 | network_name = _get_random_string(20) |
| 1156 | net_type = 'data' |
| 1157 | |
| jamartinezv | 14a823d | 2019-08-01 11:45:15 +0200 | [diff] [blame^] | 1158 | network_id, _ = test_config["vim_conn"].new_network(net_name=network_name, |
| kokardekar | 430e62f | 2018-10-04 14:27:09 +0530 | [diff] [blame] | 1159 | 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, |
| jamartinezv | 14a823d | 2019-08-01 11:45:15 +0200 | [diff] [blame^] | 1164 | image_id=self.__class__.image_id, disk_list=None, |
| 1165 | flavor_id=flavor_id, |
| 1166 | net_list=net_list) |
| kokardekar | 430e62f | 2018-10-04 14:27:09 +0530 | [diff] [blame] | 1167 | |
| 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 | |
| kasar | ffdaf29 | 2017-06-23 04:06:52 -0700 | [diff] [blame] | 1177 | # 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): |
| kokardekar | 430e62f | 2018-10-04 14:27:09 +0530 | [diff] [blame] | 1183 | flavor_data = {'name': _get_random_string(20),'ram': 1024, 'vcpus': 2, 'disk': 10} |
| kasar | ffdaf29 | 2017-06-23 04:06:52 -0700 | [diff] [blame] | 1184 | name = 'eth0' |
| 1185 | user_name = 'test_user' |
| 1186 | |
| jamartinezv | 14a823d | 2019-08-01 11:45:15 +0200 | [diff] [blame^] | 1187 | key_pairs = ['ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDtAjl5R+GSKP3gFrdFxgizKEUzhXKQbyjaxJH9thsK 0/fDiYlaNEjvijgPgiVZkfwvqgWeLprPcpzL2j4jvmmSJ3+7C8ihCwObWP0VUiuewmbIINBPAR0RqusjMRyPsa+q0asFBPOoZLx3Cv3vzmC1AA3mKuCNeT EuA0rlWhDIOVwMcU5sP1grnmuexQB8HcR7BdKcA9y08pTwnCQR8vmtW77SRkaxEGXm4Gnw5qw8Z27mHdk2wWS2SnbVH7aFwWvDXc6jjf5TpEWypdr/EAPC +eJipeS2Oa4FsntEqAu3Fz6gp/9ub8uNqgCgHfMzs6FhYpZpipwS0hXYyF6eVsSx osm@osm'] |
| kasar | ffdaf29 | 2017-06-23 04:06:52 -0700 | [diff] [blame] | 1188 | |
| jamartinezv | 14a823d | 2019-08-01 11:45:15 +0200 | [diff] [blame^] | 1189 | users_data = [{'key-pairs': ['ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDtAjl5R+GSKP3gFrdFxgizKEUzhXKQbyjaxJH9thsK0/fDiYlaNEjvijgPgiVZkfwvqgWeLprPcpzL2j4jvmmSJ3+7C8ihCwObWP0VUiuewmbIINBPAR0RqusjMRyPsa+q0asFBPOoZLx3Cv3vzmC1AA3mKuCNeTEuA0rlWhDIOVwMcU5sP1grnmuexQB8HcR7BdKcA9y08pTwnCQR8vmtW77SRkaxEGXm4Gnw5qw8Z27mHdk2wWS2SnbVH7aFwWvDXc6jjf5TpEWypdr/EAPC+eJipeS2Oa4FsntEqAu3Fz6gp/9ub8uNqgCgHfMzs6FhYpZpipwS0hXYyF6eVsSx osm@osm'], 'name': 'cloudinit'}] |
| kasar | ffdaf29 | 2017-06-23 04:06:52 -0700 | [diff] [blame] | 1190 | |
| 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 } |
| jamartinezv | 14a823d | 2019-08-01 11:45:15 +0200 | [diff] [blame^] | 1192 | #cloud_data = {'users': users_data } |
| kasar | ffdaf29 | 2017-06-23 04:06:52 -0700 | [diff] [blame] | 1193 | |
| 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 | |
| jamartinezv | 14a823d | 2019-08-01 11:45:15 +0200 | [diff] [blame^] | 1202 | net_list = [{'use': self.__class__.net_type, 'name': name, 'floating_ip': False, 'port_security': True, |
| 1203 | 'type': 'virtual', 'net_id': self.__class__.network_id}] |
| kasar | ffdaf29 | 2017-06-23 04:06:52 -0700 | [diff] [blame] | 1204 | |
| kokardekar | 430e62f | 2018-10-04 14:27:09 +0530 | [diff] [blame] | 1205 | instance_id, _ = test_config["vim_conn"].new_vminstance(name='Cloud_vm', description='', start=False, |
| jamartinezv | 14a823d | 2019-08-01 11:45:15 +0200 | [diff] [blame^] | 1206 | image_id=self.__class__.image_id, |
| 1207 | flavor_id=flavor_id,net_list=net_list, |
| 1208 | cloud_config=cloud_data) |
| kokardekar | 430e62f | 2018-10-04 14:27:09 +0530 | [diff] [blame] | 1209 | |
| 1210 | self.assertIsInstance(instance_id, (str, unicode)) |
| 1211 | |
| kasar | ffdaf29 | 2017-06-23 04:06:52 -0700 | [diff] [blame] | 1212 | # 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): |
| kokardekar | 430e62f | 2018-10-04 14:27:09 +0530 | [diff] [blame] | 1218 | flavor_data = {'name':_get_random_string(20),'ram': 1024, 'vcpus': 2, 'disk': 10} |
| kasar | ffdaf29 | 2017-06-23 04:06:52 -0700 | [diff] [blame] | 1219 | name = 'eth0' |
| 1220 | |
| kokardekar | 430e62f | 2018-10-04 14:27:09 +0530 | [diff] [blame] | 1221 | device_data = [{'image_id': self.__class__.image_id, 'size': '10'}] |
| kasar | ffdaf29 | 2017-06-23 04:06:52 -0700 | [diff] [blame] | 1222 | |
| 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 | |
| jamartinezv | 14a823d | 2019-08-01 11:45:15 +0200 | [diff] [blame^] | 1231 | net_list = [{'use': self.__class__.net_type, 'name': name, 'floating_ip': False, 'port_security': True, |
| 1232 | 'type': 'virtual', 'net_id': self.__class__.network_id}] |
| kasar | ffdaf29 | 2017-06-23 04:06:52 -0700 | [diff] [blame] | 1233 | |
| jamartinezv | 14a823d | 2019-08-01 11:45:15 +0200 | [diff] [blame^] | 1234 | 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) |
| kokardekar | 430e62f | 2018-10-04 14:27:09 +0530 | [diff] [blame] | 1238 | |
| 1239 | self.assertIsInstance(instance_id, (str, unicode)) |
| kasar | ffdaf29 | 2017-06-23 04:06:52 -0700 | [diff] [blame] | 1240 | # 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 | |
| jamartinezv | 14a823d | 2019-08-01 11:45:15 +0200 | [diff] [blame^] | 1255 | net_list = [{'use': self.__class__.net_type, 'name': name, 'floating_ip': False, 'port_security': True, |
| 1256 | 'type': 'virtual', 'net_id': self.__class__.network_id}] |
| kasar | ffdaf29 | 2017-06-23 04:06:52 -0700 | [diff] [blame] | 1257 | |
| 1258 | with self.assertRaises(Exception) as context: |
| jamartinezv | 14a823d | 2019-08-01 11:45:15 +0200 | [diff] [blame^] | 1259 | 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) |
| kokardekar | 430e62f | 2018-10-04 14:27:09 +0530 | [diff] [blame] | 1263 | |
| 1264 | self.assertIn((context.exception).http_code, (400, 404)) |
| 1265 | |
| kasar | ffdaf29 | 2017-06-23 04:06:52 -0700 | [diff] [blame] | 1266 | |
| kasar | 114050e | 2017-07-06 02:04:59 -0700 | [diff] [blame] | 1267 | 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 |
| kasar | 114050e | 2017-07-06 02:04:59 -0700 | [diff] [blame] | 1306 | |
| kokardekar | 430e62f | 2018-10-04 14:27:09 +0530 | [diff] [blame] | 1307 | 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 | |
| jamartinezv | 14a823d | 2019-08-01 11:45:15 +0200 | [diff] [blame^] | 1319 | if test_config['vimtype'] in ('openstack', 'azure'): |
| kokardekar | 430e62f | 2018-10-04 14:27:09 +0530 | [diff] [blame] | 1320 | 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 |
| jamartinezv | 14a823d | 2019-08-01 11:45:15 +0200 | [diff] [blame^] | 1328 | 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}] |
| kokardekar | 430e62f | 2018-10-04 14:27:09 +0530 | [diff] [blame] | 1330 | |
| jamartinezv | 14a823d | 2019-08-01 11:45:15 +0200 | [diff] [blame^] | 1331 | 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) |
| kokardekar | 430e62f | 2018-10-04 14:27:09 +0530 | [diff] [blame] | 1334 | |
| 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 | |
| kasar | 114050e | 2017-07-06 02:04:59 -0700 | [diff] [blame] | 1352 | |
| 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]) |
| kokardekar | 430e62f | 2018-10-04 14:27:09 +0530 | [diff] [blame] | 1362 | |
| 1363 | if test_config['vimtype'] == 'vmware': |
| 1364 | self.assertEqual(vm_dict,{}) |
| 1365 | |
| jamartinezv | 14a823d | 2019-08-01 11:45:15 +0200 | [diff] [blame^] | 1366 | if test_config['vimtype'] in ('openstack', 'azure'): |
| kokardekar | 430e62f | 2018-10-04 14:27:09 +0530 | [diff] [blame] | 1367 | self.assertEqual(vm_dict[unknown_id]['status'], 'DELETED') |
| kasar | 114050e | 2017-07-06 02:04:59 -0700 | [diff] [blame] | 1368 | |
| 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 | |
| kokardekar | 430e62f | 2018-10-04 14:27:09 +0530 | [diff] [blame] | 1375 | 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 | |
| jamartinezv | 14a823d | 2019-08-01 11:45:15 +0200 | [diff] [blame^] | 1383 | if test_config['vimtype'] in ('openstack', 'azure'): |
| kokardekar | 430e62f | 2018-10-04 14:27:09 +0530 | [diff] [blame] | 1384 | # 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 | |
| jamartinezv | 14a823d | 2019-08-01 11:45:15 +0200 | [diff] [blame^] | 1393 | 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}] |
| kokardekar | 430e62f | 2018-10-04 14:27:09 +0530 | [diff] [blame] | 1395 | |
| jamartinezv | 14a823d | 2019-08-01 11:45:15 +0200 | [diff] [blame^] | 1396 | 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) |
| kokardekar | 430e62f | 2018-10-04 14:27:09 +0530 | [diff] [blame] | 1399 | |
| jamartinezv | 14a823d | 2019-08-01 11:45:15 +0200 | [diff] [blame^] | 1400 | 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'] |
| kokardekar | 430e62f | 2018-10-04 14:27:09 +0530 | [diff] [blame] | 1404 | |
| 1405 | # various action on vminstace |
| 1406 | for action in action_list: |
| 1407 | # sleep for sometime till status is changed |
| 1408 | time.sleep(25) |
| jamartinezv | 14a823d | 2019-08-01 11:45:15 +0200 | [diff] [blame^] | 1409 | instance_id = test_config["vim_conn"].action_vminstance(new_instance_id, {action: None}) |
| kokardekar | 430e62f | 2018-10-04 14:27:09 +0530 | [diff] [blame] | 1410 | |
| 1411 | self.assertTrue(instance_id is None) |
| 1412 | |
| jamartinezv | 14a823d | 2019-08-01 11:45:15 +0200 | [diff] [blame^] | 1413 | #Deleting created vm instance |
| kokardekar | 430e62f | 2018-10-04 14:27:09 +0530 | [diff] [blame] | 1414 | logger.info("Deleting created vm intance") |
| 1415 | test_config["vim_conn"].delete_vminstance(new_instance_id) |
| 1416 | time.sleep(10) |
| kasar | 114050e | 2017-07-06 02:04:59 -0700 | [diff] [blame] | 1417 | |
| 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 | |
| kokardekar | 430e62f | 2018-10-04 14:27:09 +0530 | [diff] [blame] | 1429 | self.assertEqual((context.exception).http_code, 404) |
| 1430 | |
| kasar | 114050e | 2017-07-06 02:04:59 -0700 | [diff] [blame] | 1431 | |
| 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 Chamarty | 59d2436 | 2018-11-22 01:22:16 +0000 | [diff] [blame] | 1443 | 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 | |
| jamartinezv | 14a823d | 2019-08-01 11:45:15 +0200 | [diff] [blame^] | 1462 | net_list = [{'use': 'data', 'name': name, 'floating_ip': False, 'port_security': True, 'type': 'VF', |
| 1463 | 'net_id': self.__class__.sriov_network_id}] |
| Ravi Chamarty | 59d2436 | 2018-11-22 01:22:16 +0000 | [diff] [blame] | 1464 | |
| jamartinezv | 14a823d | 2019-08-01 11:45:15 +0200 | [diff] [blame^] | 1465 | 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 Chamarty | 59d2436 | 2018-11-22 01:22:16 +0000 | [diff] [blame] | 1468 | |
| 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 | |
| kasar | f358ad5 | 2017-07-24 01:28:44 -0700 | [diff] [blame] | 1478 | class 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'] |
| shashankjain | 3c83a21 | 2018-10-04 13:05:46 +0530 | [diff] [blame] | 1493 | self.assertIsInstance(item['name'], (str, unicode)) |
| 1494 | self.assertIsInstance(item['id'], (str, unicode)) |
| kasar | f358ad5 | 2017-07-24 01:28:44 -0700 | [diff] [blame] | 1495 | |
| 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: |
| shashankjain | 3c83a21 | 2018-10-04 13:05:46 +0530 | [diff] [blame] | 1506 | self.assertIsInstance(item['id'], (str, unicode)) |
| kasar | f358ad5 | 2017-07-24 01:28:44 -0700 | [diff] [blame] | 1507 | 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: |
| shashankjain | 3c83a21 | 2018-10-04 13:05:46 +0530 | [diff] [blame] | 1519 | self.assertIsInstance(item['name'], (str, unicode)) |
| kasar | f358ad5 | 2017-07-24 01:28:44 -0700 | [diff] [blame] | 1520 | 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: |
| shashankjain | 3c83a21 | 2018-10-04 13:05:46 +0530 | [diff] [blame] | 1533 | self.assertIsInstance(item['name'], (str, unicode)) |
| 1534 | self.assertIsInstance(item['id'], (str, unicode)) |
| kasar | f358ad5 | 2017-07-24 01:28:44 -0700 | [diff] [blame] | 1535 | 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 | |
| shashankjain | 3c83a21 | 2018-10-04 13:05:46 +0530 | [diff] [blame] | 1551 | |
| kasar | 55f7085 | 2017-07-31 01:25:55 -0700 | [diff] [blame] | 1552 | class 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 | |
| jamartinezv | 14a823d | 2019-08-01 11:45:15 +0200 | [diff] [blame^] | 1562 | if test_config['vimtype'] != 'azure': |
| 1563 | self.__class__.tenant_id = test_config["vim_conn"].new_tenant(tenant_name, "") |
| 1564 | time.sleep(15) |
| kasar | 55f7085 | 2017-07-31 01:25:55 -0700 | [diff] [blame] | 1565 | |
| jamartinezv | 14a823d | 2019-08-01 11:45:15 +0200 | [diff] [blame^] | 1566 | 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) |
| shashankjain | 3c83a21 | 2018-10-04 13:05:46 +0530 | [diff] [blame] | 1571 | |
| kasar | 55f7085 | 2017-07-31 01:25:55 -0700 | [diff] [blame] | 1572 | |
| 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: |
| shashankjain | 3c83a21 | 2018-10-04 13:05:46 +0530 | [diff] [blame] | 1581 | test_config["vim_conn"].new_tenant(Invalid_tenant_name, "") |
| kasar | 55f7085 | 2017-07-31 01:25:55 -0700 | [diff] [blame] | 1582 | |
| jamartinezv | 14a823d | 2019-08-01 11:45:15 +0200 | [diff] [blame^] | 1583 | if test_config['vimtype'] != 'azure': |
| 1584 | self.assertEqual((context.exception).http_code, 400) |
| 1585 | else: |
| 1586 | self.assertEqual((context.exception).http_code, 401) |
| kasar | 55f7085 | 2017-07-31 01:25:55 -0700 | [diff] [blame] | 1587 | |
| shashankjain | 3c83a21 | 2018-10-04 13:05:46 +0530 | [diff] [blame] | 1588 | |
| kasar | 55f7085 | 2017-07-31 01:25:55 -0700 | [diff] [blame] | 1589 | 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 | |
| jamartinezv | 14a823d | 2019-08-01 11:45:15 +0200 | [diff] [blame^] | 1595 | 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) |
| kasar | 55f7085 | 2017-07-31 01:25:55 -0700 | [diff] [blame] | 1602 | |
| 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 | |
| jamartinezv | 14a823d | 2019-08-01 11:45:15 +0200 | [diff] [blame^] | 1613 | if test_config['vimtype'] != 'azure': |
| 1614 | self.assertEqual((context.exception).http_code, 404) |
| 1615 | else: |
| 1616 | self.assertEqual((context.exception).http_code, 401) |
| kasar | f358ad5 | 2017-07-24 01:28:44 -0700 | [diff] [blame] | 1617 | |
| tierno | ed85457 | 2017-10-03 16:18:09 +0200 | [diff] [blame] | 1618 | |
| kasar | 532f8c2 | 2018-10-12 02:25:31 -0700 | [diff] [blame] | 1619 | def 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 | |
| 1635 | class 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 | |
| jamartinezv | 14a823d | 2019-08-01 11:45:15 +0200 | [diff] [blame^] | 1643 | self.network_id, _ = test_config["vim_conn"].new_network(net_name=self.network_name, |
| kasar | 532f8c2 | 2018-10-12 02:25:31 -0700 | [diff] [blame] | 1644 | 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 | |
| 1769 | class 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) |
| jamartinezv | 14a823d | 2019-08-01 11:45:15 +0200 | [diff] [blame^] | 1778 | network_id, _ = test_config["vim_conn"].new_network(net_name=self.network_name, |
| kasar | 532f8c2 | 2018-10-12 02:25:31 -0700 | [diff] [blame] | 1779 | 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 | |
| jamartinezv | 14a823d | 2019-08-01 11:45:15 +0200 | [diff] [blame^] | 1814 | 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) |
| kasar | 532f8c2 | 2018-10-12 02:25:31 -0700 | [diff] [blame] | 1816 | |
| 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 | |
| 1823 | class 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) |
| jamartinezv | 14a823d | 2019-08-01 11:45:15 +0200 | [diff] [blame^] | 1830 | self.network_id, _ = test_config["vim_conn"].new_network(net_name=self.network_name, |
| kasar | 532f8c2 | 2018-10-12 02:25:31 -0700 | [diff] [blame] | 1831 | 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 | |
| jamartinezv | 14a823d | 2019-08-01 11:45:15 +0200 | [diff] [blame^] | 1867 | instance_id, _ = test_config["vim_conn"].new_vminstance(name='Test1_vm', description='', start=False, |
| 1868 | image_id=image_id, |
| kasar | 532f8c2 | 2018-10-12 02:25:31 -0700 | [diff] [blame] | 1869 | 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 | |
| jamartinezv | 14a823d | 2019-08-01 11:45:15 +0200 | [diff] [blame^] | 1895 | instance_id, _ = test_config["vim_conn"].new_vminstance(name='Test1_vm', description='', start=False, |
| 1896 | image_id=image_id, |
| kasar | 532f8c2 | 2018-10-12 02:25:31 -0700 | [diff] [blame] | 1897 | 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 | |
| jamartinezv | 14a823d | 2019-08-01 11:45:15 +0200 | [diff] [blame^] | 1927 | instance_id, _ = test_config["vim_conn"].new_vminstance(name='Test1_vm', description='', start=False, |
| 1928 | image_id=image_id, |
| kasar | 532f8c2 | 2018-10-12 02:25:31 -0700 | [diff] [blame] | 1929 | 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 | |
| 1937 | class 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) |
| jamartinezv | 14a823d | 2019-08-01 11:45:15 +0200 | [diff] [blame^] | 1944 | self.network_id, _ = test_config["vim_conn"].new_network(net_name=self.network_name, |
| kasar | 532f8c2 | 2018-10-12 02:25:31 -0700 | [diff] [blame] | 1945 | 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 | |
| jamartinezv | 14a823d | 2019-08-01 11:45:15 +0200 | [diff] [blame^] | 1978 | instance_id, _ = test_config["vim_conn"].new_vminstance(name='Test1_vm', description='', start=False, |
| 1979 | image_id=image_id, |
| kasar | 532f8c2 | 2018-10-12 02:25:31 -0700 | [diff] [blame] | 1980 | 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 | |
| 1988 | class 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) |
| jamartinezv | 14a823d | 2019-08-01 11:45:15 +0200 | [diff] [blame^] | 1995 | self.network_id, _ = test_config["vim_conn"].new_network(net_name=self.network_name, |
| kasar | 532f8c2 | 2018-10-12 02:25:31 -0700 | [diff] [blame] | 1996 | 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']], |
| jamartinezv | 14a823d | 2019-08-01 11:45:15 +0200 | [diff] [blame^] | 2009 | ' paired-threads': 2, 'memory': 1}]}, |
| 2010 | 'ram': 1024, 'vcpus': 1, 'disk': 10} |
| kasar | 532f8c2 | 2018-10-12 02:25:31 -0700 | [diff] [blame] | 2011 | 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 | |
| jamartinezv | 14a823d | 2019-08-01 11:45:15 +0200 | [diff] [blame^] | 2027 | instance_id, _ = test_config["vim_conn"].new_vminstance(name='Test1_vm', description='', start=False, |
| 2028 | image_id=image_id, |
| kasar | 532f8c2 | 2018-10-12 02:25:31 -0700 | [diff] [blame] | 2029 | 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 Moreno | eebea06 | 2017-02-27 12:33:10 +0100 | [diff] [blame] | 2037 | ''' |
| 2038 | IMPORTANT NOTE |
| 2039 | The following unittest class does not have the 'test_' on purpose. This test is the one used for the |
| 2040 | scenario based tests. |
| 2041 | ''' |
| tierno | f050835 | 2017-06-19 13:37:44 +0200 | [diff] [blame] | 2042 | class descriptor_based_scenario_test(test_base): |
| Pablo Montes Moreno | eebea06 | 2017-02-27 12:33:10 +0100 | [diff] [blame] | 2043 | test_index = 0 |
| Pablo Montes Moreno | eebea06 | 2017-02-27 12:33:10 +0100 | [diff] [blame] | 2044 | scenario_test_path = None |
| Pablo Montes Moreno | eebea06 | 2017-02-27 12:33:10 +0100 | [diff] [blame] | 2045 | |
| 2046 | @classmethod |
| 2047 | def setUpClass(cls): |
| 2048 | cls.test_index = 1 |
| 2049 | cls.to_delete_list = [] |
| tierno | ed85457 | 2017-10-03 16:18:09 +0200 | [diff] [blame] | 2050 | cls.scenario_uuids = [] |
| 2051 | cls.instance_scenario_uuids = [] |
| tierno | ec66e9a | 2017-05-17 15:28:10 +0200 | [diff] [blame] | 2052 | 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 Moreno | eebea06 | 2017-02-27 12:33:10 +0100 | [diff] [blame] | 2054 | |
| 2055 | @classmethod |
| 2056 | def tearDownClass(cls): |
| tierno | ec66e9a | 2017-05-17 15:28:10 +0200 | [diff] [blame] | 2057 | test_config["test_number"] += 1 |
| Pablo Montes Moreno | eebea06 | 2017-02-27 12:33:10 +0100 | [diff] [blame] | 2058 | |
| Pablo Montes Moreno | eebea06 | 2017-02-27 12:33:10 +0100 | [diff] [blame] | 2059 | def test_000_load_scenario(self): |
| tierno | ec66e9a | 2017-05-17 15:28:10 +0200 | [diff] [blame] | 2060 | self.__class__.test_text = "{}.{}. TEST {} {}".format(test_config["test_number"], self.__class__.test_index, |
| Pablo Montes Moreno | eebea06 | 2017-02-27 12:33:10 +0100 | [diff] [blame] | 2061 | inspect.currentframe().f_code.co_name, |
| tierno | ec66e9a | 2017-05-17 15:28:10 +0200 | [diff] [blame] | 2062 | test_config["test_folder"]) |
| Pablo Montes Moreno | eebea06 | 2017-02-27 12:33:10 +0100 | [diff] [blame] | 2063 | self.__class__.test_index += 1 |
| tierno | ed85457 | 2017-10-03 16:18:09 +0200 | [diff] [blame] | 2064 | # 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 Moreno | eebea06 | 2017-02-27 12:33:10 +0100 | [diff] [blame] | 2076 | scenario_file = glob.glob(self.__class__.scenario_test_path + '/scenario_*.yaml') |
| tierno | ed85457 | 2017-10-03 16:18:09 +0200 | [diff] [blame] | 2077 | if not vnf_descriptors or not scenario_descriptors or len(scenario_descriptors) > 1: |
| tierno | ec66e9a | 2017-05-17 15:28:10 +0200 | [diff] [blame] | 2078 | 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 Moreno | eebea06 | 2017-02-27 12:33:10 +0100 | [diff] [blame] | 2080 | |
| tierno | ed85457 | 2017-10-03 16:18:09 +0200 | [diff] [blame] | 2081 | # load all vnfd |
| 2082 | for vnf_descriptor in vnf_descriptors: |
| Pablo Montes Moreno | eebea06 | 2017-02-27 12:33:10 +0100 | [diff] [blame] | 2083 | logger.debug("VNF descriptor: {}".format(vnf_descriptor)) |
| tierno | ed85457 | 2017-10-03 16:18:09 +0200 | [diff] [blame] | 2084 | vnf = test_config["client"].create_vnf(descriptor=vnf_descriptor, image_name=test_config["image_name"]) |
| Pablo Montes Moreno | eebea06 | 2017-02-27 12:33:10 +0100 | [diff] [blame] | 2085 | logger.debug(vnf) |
| tierno | ed85457 | 2017-10-03 16:18:09 +0200 | [diff] [blame] | 2086 | if 'vnf' in vnf: |
| 2087 | vnf_uuid = vnf['vnf']['uuid'] |
| 2088 | else: |
| 2089 | vnf_uuid = vnf['vnfd'][0]['uuid'] |
| tierno | ec66e9a | 2017-05-17 15:28:10 +0200 | [diff] [blame] | 2090 | self.__class__.to_delete_list.insert(0, {"item": "vnf", "function": test_config["client"].delete_vnf, |
| tierno | ed85457 | 2017-10-03 16:18:09 +0200 | [diff] [blame] | 2091 | "params": {"uuid": vnf_uuid}}) |
| Pablo Montes Moreno | eebea06 | 2017-02-27 12:33:10 +0100 | [diff] [blame] | 2092 | |
| tierno | ed85457 | 2017-10-03 16:18:09 +0200 | [diff] [blame] | 2093 | # 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 Moreno | eebea06 | 2017-02-27 12:33:10 +0100 | [diff] [blame] | 2108 | |
| 2109 | def test_010_instantiate_scenario(self): |
| tierno | ec66e9a | 2017-05-17 15:28:10 +0200 | [diff] [blame] | 2110 | self.__class__.test_text = "{}.{}. TEST {} {}".format(test_config["test_number"], self.__class__.test_index, |
| Pablo Montes Moreno | eebea06 | 2017-02-27 12:33:10 +0100 | [diff] [blame] | 2111 | inspect.currentframe().f_code.co_name, |
| tierno | ec66e9a | 2017-05-17 15:28:10 +0200 | [diff] [blame] | 2112 | test_config["test_folder"]) |
| Pablo Montes Moreno | eebea06 | 2017-02-27 12:33:10 +0100 | [diff] [blame] | 2113 | self.__class__.test_index += 1 |
| tierno | ed85457 | 2017-10-03 16:18:09 +0200 | [diff] [blame] | 2114 | 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 Moreno | eebea06 | 2017-02-27 12:33:10 +0100 | [diff] [blame] | 2130 | |
| Pablo Montes Moreno | 2fe24fa | 2017-03-27 12:56:13 +0200 | [diff] [blame] | 2131 | def test_020_check_deployent(self): |
| tierno | ec66e9a | 2017-05-17 15:28:10 +0200 | [diff] [blame] | 2132 | self.__class__.test_text = "{}.{}. TEST {} {}".format(test_config["test_number"], self.__class__.test_index, |
| Pablo Montes Moreno | 2fe24fa | 2017-03-27 12:56:13 +0200 | [diff] [blame] | 2133 | inspect.currentframe().f_code.co_name, |
| tierno | ec66e9a | 2017-05-17 15:28:10 +0200 | [diff] [blame] | 2134 | test_config["test_folder"]) |
| Pablo Montes Moreno | 2fe24fa | 2017-03-27 12:56:13 +0200 | [diff] [blame] | 2135 | self.__class__.test_index += 1 |
| 2136 | |
| tierno | ec66e9a | 2017-05-17 15:28:10 +0200 | [diff] [blame] | 2137 | if test_config["manual"]: |
| Pablo Montes Moreno | 3be0b2a | 2017-03-30 13:22:15 +0200 | [diff] [blame] | 2138 | raw_input('Scenario has been deployed. Perform manual check and press any key to resume') |
| 2139 | return |
| 2140 | |
| tierno | ec66e9a | 2017-05-17 15:28:10 +0200 | [diff] [blame] | 2141 | keep_waiting = test_config["timeout"] |
| tierno | ed85457 | 2017-10-03 16:18:09 +0200 | [diff] [blame] | 2142 | 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 Moreno | 2fe24fa | 2017-03-27 12:56:13 +0200 | [diff] [blame] | 2155 | |
| tierno | 0e6fcaa | 2017-05-05 15:54:07 +0200 | [diff] [blame] | 2156 | 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 Moreno | 2fe24fa | 2017-03-27 12:56:13 +0200 | [diff] [blame] | 2166 | |
| 2167 | def test_030_clean_deployment(self): |
| tierno | ec66e9a | 2017-05-17 15:28:10 +0200 | [diff] [blame] | 2168 | self.__class__.test_text = "{}.{}. TEST {} {}".format(test_config["test_number"], self.__class__.test_index, |
| Pablo Montes Moreno | eebea06 | 2017-02-27 12:33:10 +0100 | [diff] [blame] | 2169 | inspect.currentframe().f_code.co_name, |
| tierno | ec66e9a | 2017-05-17 15:28:10 +0200 | [diff] [blame] | 2170 | test_config["test_folder"]) |
| Pablo Montes Moreno | eebea06 | 2017-02-27 12:33:10 +0100 | [diff] [blame] | 2171 | 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 | |
| tierno | ec66e9a | 2017-05-17 15:28:10 +0200 | [diff] [blame] | 2179 | |
| Pablo Montes Moreno | eebea06 | 2017-02-27 12:33:10 +0100 | [diff] [blame] | 2180 | def _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 | |
| tierno | ec66e9a | 2017-05-17 15:28:10 +0200 | [diff] [blame] | 2192 | |
| 2193 | def test_vimconnector(args): |
| 2194 | global test_config |
| tierno | 0e6fcaa | 2017-05-05 15:54:07 +0200 | [diff] [blame] | 2195 | sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + "/osm_ro") |
| kasar | 70532ae | 2017-05-26 03:53:52 -0700 | [diff] [blame] | 2196 | test_config['vimtype'] = args.vimtype |
| tierno | ec66e9a | 2017-05-17 15:28:10 +0200 | [diff] [blame] | 2197 | if args.vimtype == "vmware": |
| 2198 | import vimconn_vmware as vim |
| kasar | 70532ae | 2017-05-26 03:53:52 -0700 | [diff] [blame] | 2199 | |
| 2200 | test_config["test_directory"] = os.path.dirname(__file__) + "/RO_tests" |
| 2201 | |
| 2202 | tenant_name = args.tenant_name |
| 2203 | test_config['tenant'] = tenant_name |
| tierno | 12a0c3b | 2018-10-15 15:10:36 +0200 | [diff] [blame] | 2204 | config_params = yaml.load(args.config_param) |
| kasar | 70532ae | 2017-05-26 03:53:52 -0700 | [diff] [blame] | 2205 | 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 |
| kasar | feaaa05 | 2017-06-08 03:46:18 -0700 | [diff] [blame] | 2209 | test_config['image_path'] = args.image_path |
| kasar | ffdaf29 | 2017-06-23 04:06:52 -0700 | [diff] [blame] | 2210 | test_config['image_name'] = args.image_name |
| Ravi Chamarty | 59d2436 | 2018-11-22 01:22:16 +0000 | [diff] [blame] | 2211 | test_config['sriov_net_name'] = args.sriov_net_name |
| kasar | 70532ae | 2017-05-26 03:53:52 -0700 | [diff] [blame] | 2212 | |
| 2213 | # vmware connector obj |
| jamartinezv | 14a823d | 2019-08-01 11:45:15 +0200 | [diff] [blame^] | 2214 | 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) |
| kasar | 70532ae | 2017-05-26 03:53:52 -0700 | [diff] [blame] | 2216 | |
| tierno | ec66e9a | 2017-05-17 15:28:10 +0200 | [diff] [blame] | 2217 | elif args.vimtype == "aws": |
| 2218 | import vimconn_aws as vim |
| 2219 | elif args.vimtype == "openstack": |
| 2220 | import vimconn_openstack as vim |
| shashankjain | 3cd4971 | 2018-09-28 11:59:03 +0530 | [diff] [blame] | 2221 | |
| 2222 | test_config["test_directory"] = os.path.dirname(__file__) + "/RO_tests" |
| 2223 | |
| 2224 | tenant_name = args.tenant_name |
| 2225 | test_config['tenant'] = tenant_name |
| tierno | 12a0c3b | 2018-10-15 15:10:36 +0200 | [diff] [blame] | 2226 | config_params = yaml.load(args.config_param) |
| shashankjain | 3cd4971 | 2018-09-28 11:59:03 +0530 | [diff] [blame] | 2227 | 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 Chamarty | 59d2436 | 2018-11-22 01:22:16 +0000 | [diff] [blame] | 2232 | test_config['sriov_net_name'] = args.sriov_net_name |
| shashankjain | 3cd4971 | 2018-09-28 11:59:03 +0530 | [diff] [blame] | 2233 | |
| 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 | |
| tierno | ec66e9a | 2017-05-17 15:28:10 +0200 | [diff] [blame] | 2245 | elif args.vimtype == "openvim": |
| 2246 | import vimconn_openvim as vim |
| jamartinezv | 14a823d | 2019-08-01 11:45:15 +0200 | [diff] [blame^] | 2247 | 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 | |
| tierno | ec66e9a | 2017-05-17 15:28:10 +0200 | [diff] [blame] | 2273 | else: |
| 2274 | logger.critical("vimtype '{}' not supported".format(args.vimtype)) |
| 2275 | sys.exit(1) |
| 2276 | executed = 0 |
| 2277 | failed = 0 |
| Pablo Montes Moreno | eebea06 | 2017-02-27 12:33:10 +0100 | [diff] [blame] | 2278 | clsmembers = inspect.getmembers(sys.modules[__name__], inspect.isclass) |
| Pablo Montes Moreno | eebea06 | 2017-02-27 12:33:10 +0100 | [diff] [blame] | 2279 | # If only want to obtain a tests list print it and exit |
| tierno | ec66e9a | 2017-05-17 15:28:10 +0200 | [diff] [blame] | 2280 | if args.list_tests: |
| Pablo Montes Moreno | eebea06 | 2017-02-27 12:33:10 +0100 | [diff] [blame] | 2281 | tests_names = [] |
| 2282 | for cls in clsmembers: |
| shashankjain | 3cd4971 | 2018-09-28 11:59:03 +0530 | [diff] [blame] | 2283 | if cls[0].startswith('test_vimconn'): |
| Pablo Montes Moreno | eebea06 | 2017-02-27 12:33:10 +0100 | [diff] [blame] | 2284 | tests_names.append(cls[0]) |
| 2285 | |
| tierno | ec66e9a | 2017-05-17 15:28:10 +0200 | [diff] [blame] | 2286 | msg = "The 'vim' set tests are:\n\t" + ', '.join(sorted(tests_names)) |
| 2287 | print(msg) |
| Pablo Montes Moreno | eebea06 | 2017-02-27 12:33:10 +0100 | [diff] [blame] | 2288 | logger.info(msg) |
| 2289 | sys.exit(0) |
| 2290 | |
| tierno | 0e6fcaa | 2017-05-05 15:54:07 +0200 | [diff] [blame] | 2291 | # Create the list of tests to be run |
| Pablo Montes Moreno | eebea06 | 2017-02-27 12:33:10 +0100 | [diff] [blame] | 2292 | code_based_tests = [] |
| tierno | ec66e9a | 2017-05-17 15:28:10 +0200 | [diff] [blame] | 2293 | 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: |
| tierno | 0e6fcaa | 2017-05-05 15:54:07 +0200 | [diff] [blame] | 2303 | # include all tests |
| Pablo Montes Moreno | eebea06 | 2017-02-27 12:33:10 +0100 | [diff] [blame] | 2304 | for cls in clsmembers: |
| tierno | 0e6fcaa | 2017-05-05 15:54:07 +0200 | [diff] [blame] | 2305 | # We exclude 'test_VIM_tenant_operations' unless it is specifically requested by the user |
| tierno | 12a0c3b | 2018-10-15 15:10:36 +0200 | [diff] [blame] | 2306 | if cls[0].startswith('test_vimconn'): |
| Pablo Montes Moreno | eebea06 | 2017-02-27 12:33:10 +0100 | [diff] [blame] | 2307 | code_based_tests.append(cls[1]) |
| 2308 | |
| tierno | ec66e9a | 2017-05-17 15:28:10 +0200 | [diff] [blame] | 2309 | logger.debug("tests to be executed: {}".format(code_based_tests)) |
| Pablo Montes Moreno | eebea06 | 2017-02-27 12:33:10 +0100 | [diff] [blame] | 2310 | |
| 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 Moreno | eebea06 | 2017-02-27 12:33:10 +0100 | [diff] [blame] | 2314 | |
| tierno | 0e6fcaa | 2017-05-05 15:54:07 +0200 | [diff] [blame] | 2315 | # Run code based tests |
| Pablo Montes Moreno | eebea06 | 2017-02-27 12:33:10 +0100 | [diff] [blame] | 2316 | basic_tests_suite = unittest.TestSuite() |
| 2317 | for test in code_based_tests: |
| 2318 | basic_tests_suite.addTest(unittest.makeSuite(test)) |
| tierno | 0e6fcaa | 2017-05-05 15:54:07 +0200 | [diff] [blame] | 2319 | result = unittest.TextTestRunner(stream=stream, failfast=failfast).run(basic_tests_suite) |
| Pablo Montes Moreno | eebea06 | 2017-02-27 12:33:10 +0100 | [diff] [blame] | 2320 | executed += result.testsRun |
| 2321 | failed += len(result.failures) + len(result.errors) |
| tierno | 0e6fcaa | 2017-05-05 15:54:07 +0200 | [diff] [blame] | 2322 | if failfast and failed: |
| 2323 | sys.exit(1) |
| Pablo Montes Moreno | eebea06 | 2017-02-27 12:33:10 +0100 | [diff] [blame] | 2324 | 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)) |
| tierno | ec66e9a | 2017-05-17 15:28:10 +0200 | [diff] [blame] | 2328 | return executed, failed |
| Pablo Montes Moreno | eebea06 | 2017-02-27 12:33:10 +0100 | [diff] [blame] | 2329 | |
| tierno | ec66e9a | 2017-05-17 15:28:10 +0200 | [diff] [blame] | 2330 | |
| 2331 | def 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 Bravalheri | 0446cd5 | 2018-08-17 15:26:19 +0100 | [diff] [blame] | 2397 | def 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 | |
| tierno | ec66e9a | 2017-05-17 15:28:10 +0200 | [diff] [blame] | 2463 | def 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: |
| tierno | f050835 | 2017-06-19 13:37:44 +0200 | [diff] [blame] | 2476 | msg = "the 'deploy' set tests are:\n\t" + ', '.join(sorted(test_directory_content)) |
| tierno | ec66e9a | 2017-05-17 15:28:10 +0200 | [diff] [blame] | 2477 | print(msg) |
| tierno | f050835 | 2017-06-19 13:37:44 +0200 | [diff] [blame] | 2478 | # logger.info(msg) |
| tierno | ec66e9a | 2017-05-17 15:28:10 +0200 | [diff] [blame] | 2479 | 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 Moreno | eebea06 | 2017-02-27 12:33:10 +0100 | [diff] [blame] | 2508 | # This scenario based tests are defined as directories inside the directory defined in 'test_directory' |
| 2509 | for test in descriptor_based_tests: |
| tierno | ec66e9a | 2017-05-17 15:28:10 +0200 | [diff] [blame] | 2510 | test_config["test_folder"] = test |
| Pablo Montes Moreno | eebea06 | 2017-02-27 12:33:10 +0100 | [diff] [blame] | 2511 | test_suite = unittest.TestSuite() |
| 2512 | test_suite.addTest(unittest.makeSuite(descriptor_based_scenario_test)) |
| tierno | 0e6fcaa | 2017-05-05 15:54:07 +0200 | [diff] [blame] | 2513 | result = unittest.TextTestRunner(stream=stream, failfast=False).run(test_suite) |
| Pablo Montes Moreno | eebea06 | 2017-02-27 12:33:10 +0100 | [diff] [blame] | 2514 | executed += result.testsRun |
| 2515 | failed += len(result.failures) + len(result.errors) |
| tierno | 0e6fcaa | 2017-05-05 15:54:07 +0200 | [diff] [blame] | 2516 | if failfast and failed: |
| 2517 | sys.exit(1) |
| Pablo Montes Moreno | eebea06 | 2017-02-27 12:33:10 +0100 | [diff] [blame] | 2518 | 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 | |
| tierno | ec66e9a | 2017-05-17 15:28:10 +0200 | [diff] [blame] | 2523 | return executed, failed |
| 2524 | |
| 2525 | if __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') |
| jamartinezv | 14a823d | 2019-08-01 11:45:15 +0200 | [diff] [blame^] | 2578 | mandatory_arguments.add_argument('--vimtype', choices=['vmware', 'aws', 'openstack', 'openvim','azure'], required=True, |
| tierno | ec66e9a | 2017-05-17 15:28:10 +0200 | [diff] [blame] | 2579 | help='Set the vimconnector type to test') |
| kasar | 70532ae | 2017-05-26 03:53:52 -0700 | [diff] [blame] | 2580 | 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") |
| tierno | ec66e9a | 2017-05-17 15:28:10 +0200 | [diff] [blame] | 2583 | # Optional arguments |
| kasar | feaaa05 | 2017-06-08 03:46:18 -0700 | [diff] [blame] | 2584 | vimconn_parser.add_argument('-i', '--image-path', dest='image_path', help="Provide image path present at RO container") |
| kasar | ffdaf29 | 2017-06-23 04:06:52 -0700 | [diff] [blame] | 2585 | vimconn_parser.add_argument('-n', '--image-name', dest='image_name', help="Provide image name for test") |
| tierno | ec66e9a | 2017-05-17 15:28:10 +0200 | [diff] [blame] | 2586 | # TODO add optional arguments for vimconn tests |
| 2587 | # vimconn_parser.add_argument("-i", '--image-name', dest='image_name', help='<HELP>')) |
| Ravi Chamarty | 59d2436 | 2018-11-22 01:22:16 +0000 | [diff] [blame] | 2588 | vimconn_parser.add_argument('-s', '--sriov-net-name', dest='sriov_net_name', help="Provide SRIOV network name for test") |
| tierno | ec66e9a | 2017-05-17 15:28:10 +0200 | [diff] [blame] | 2589 | |
| 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 Bravalheri | 0446cd5 | 2018-08-17 15:26:19 +0100 | [diff] [blame] | 2603 | # 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 | |
| tierno | ec66e9a | 2017-05-17 15:28:10 +0200 | [diff] [blame] | 2616 | 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 | |
| tierno | 0e6fcaa | 2017-05-05 15:54:07 +0200 | [diff] [blame] | 2654 | # Log summary |
| Pablo Montes Moreno | eebea06 | 2017-02-27 12:33:10 +0100 | [diff] [blame] | 2655 | logger.warning("Total number of tests: {}; Total number of failures/errors: {}".format(executed, failed)) |
| tierno | 0e6fcaa | 2017-05-05 15:54:07 +0200 | [diff] [blame] | 2656 | sys.exit(1 if failed else 0) |