3 # Copyright (c) 2017 All rights reserved
4 # This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
18 from xtesting.core import feature
19 from sdnvpn.lib import config as sdnvpn_config
20 from sdnvpn.lib import openstack_utils as os_utils
21 from sdnvpn.lib.gather_logs import gather_logs
22 from sdnvpn.lib import utils as test_utils
24 COMMON_CONFIG = sdnvpn_config.CommonConfig()
27 class SdnvpnFunctest(feature.Feature):
29 __logger = logging.getLogger(__name__)
33 nova_client = os_utils.get_nova_client()
34 neutron_client = os_utils.get_neutron_client()
36 tenant_id = os_utils.get_tenant_id(os_utils.get_keystone_client(),
37 os.environ['OS_PROJECT_NAME'])
39 neutron_quota = test_utils.get_neutron_quota(neutron_client, tenant_id)
40 (neutron_nw_quota, neutron_subnet_quota, neutron_port_quota,
41 neutron_router_quota) = (
42 neutron_quota['network'], neutron_quota['subnet'],
43 neutron_quota['port'], neutron_quota['router'])
44 instances_quota = test_utils.get_nova_instances_quota(nova_client)
46 self.__logger.info("Setting net/subnet/port/router "
48 test_utils.update_nw_subnet_port_quota(
51 COMMON_CONFIG.neutron_nw_quota,
52 COMMON_CONFIG.neutron_subnet_quota,
53 COMMON_CONFIG.neutron_port_quota,
54 COMMON_CONFIG.neutron_router_quota)
55 test_utils.create_default_flavor()
58 # https://jira.opnfv.org/projects/SDNVPN/issues/SDNVPN-115
59 self.__logger.info("Setting instances quota class to unlimited")
60 test_utils.update_instance_quota_class(
62 COMMON_CONFIG.nova_instances_quota_class)
64 with open(COMMON_CONFIG.config_file) as f:
65 config_yaml = yaml.safe_load(f)
67 testcases = config_yaml.get("testcases")
68 overall_status = "PASS"
70 if testcases[tc]['enabled']:
72 test_descr = testcases[tc]['description']
73 title = ("Running '%s - %s'" %
74 (test_name, test_descr))
75 self.__logger.info(title)
76 self.__logger.info("%s\n" % ("=" * len(title)))
78 self.__logger.info("Importing the testcase %s" % test_name)
79 t = importlib.import_module(test_name, package=None)
80 self.__logger.info("Calling the testcase %s main method"
83 self.__logger.info("Execution is complete for the testcase %s"
85 except Exception as ex:
87 self.__logger.info("Caught Exception in %s: %s Trace: %s"
89 traceback.format_exc()))
92 overall_status = "FAIL"
93 self.__logger.info("Testcase %s failed" % test_name)
95 status = result.get("status")
97 {test_name: {'status': status,
98 'details': result.get("details")}})
99 self.__logger.info("Results of test case '%s - %s':\n%s\n"
100 % (test_name, test_descr, result))
103 overall_status = "FAIL"
105 self.__logger.info("Resetting subnet/net/port quota")
106 test_utils.update_nw_subnet_port_quota(neutron_client,
109 neutron_subnet_quota,
111 neutron_router_quota)
113 self.__logger.info("Resetting instances quota class")
114 test_utils.update_instance_quota_class(nova_client, instances_quota)
117 installer_type = str(os.environ['INSTALLER_TYPE'].lower())
118 if installer_type in ["fuel", "apex"]:
119 gather_logs('overall')
121 self.__logger.info("Skipping log gathering because installer"
122 "type %s is neither fuel nor apex" %
124 except Exception as ex:
125 self.__logger.error(('Something went wrong in the Log gathering.'
127 % (ex, traceback.format_exc()))
129 if overall_status == "PASS":
131 return feature.Feature.EX_OK
133 return feature.Feature.EX_RUN_ERROR
136 if __name__ == '__main__':
137 logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s'
138 '- %(levelname)s - %(message)s')
139 SDNVPN = SdnvpnFunctest()
140 sys.exit(SDNVPN.execute())