3 # Copyright (c) 2015 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
15 import opnfv.utils.constants as releng_constants
17 import functest.utils.functest_utils as ft_utils
18 import functest.utils.openstack_utils as os_utils
19 from functest.utils.constants import CONST
23 REPO_PATH = CONST.dir_repo_functest
24 GLANCE_IMAGE_PATH = os.path.join(CONST.dir_functest_data,
25 CONST.openstack_image_file_name)
26 TEMPEST_TEST_LIST_DIR = CONST.dir_tempest_cases
27 TEMPEST_RESULTS_DIR = os.path.join(CONST.dir_results,
29 TEMPEST_CUSTOM = os.path.join(REPO_PATH, TEMPEST_TEST_LIST_DIR,
31 TEMPEST_BLACKLIST = os.path.join(REPO_PATH, TEMPEST_TEST_LIST_DIR,
33 TEMPEST_DEFCORE = os.path.join(REPO_PATH, TEMPEST_TEST_LIST_DIR,
35 TEMPEST_RAW_LIST = os.path.join(TEMPEST_RESULTS_DIR, 'test_raw_list.txt')
36 TEMPEST_LIST = os.path.join(TEMPEST_RESULTS_DIR, 'test_list.txt')
38 CI_INSTALLER_TYPE = CONST.INSTALLER_TYPE
39 CI_INSTALLER_IP = CONST.INSTALLER_IP
42 def configure_tempest(logger, deployment_dir, IMAGE_ID=None, FLAVOR_ID=None):
44 Add/update needed parameters into tempest.conf file generated by Rally
46 tempest_conf_file = deployment_dir + "/tempest.conf"
47 if os.path.isfile(tempest_conf_file):
48 logger.debug("Deleting old tempest.conf file...")
49 os.remove(tempest_conf_file)
51 logger.debug("Generating new tempest.conf file...")
52 cmd = "rally verify genconfig"
53 ft_utils.execute_command(cmd)
55 logger.debug("Finding tempest.conf file...")
56 if not os.path.isfile(tempest_conf_file):
57 logger.error("Tempest configuration file %s NOT found."
59 return releng_constants.EXIT_RUN_ERROR
61 logger.debug("Updating selected tempest.conf parameters...")
62 config = ConfigParser.RawConfigParser()
63 config.read(tempest_conf_file)
67 CONST.tempest_private_net_name)
68 if CONST.tempest_use_custom_images:
69 if IMAGE_ID is not None:
70 config.set('compute', 'image_ref', IMAGE_ID)
71 if IMAGE_ID_ALT is not None:
72 config.set('compute', 'image_ref_alt', IMAGE_ID_ALT)
73 if CONST.tempest_use_custom_flavors:
74 if FLAVOR_ID is not None:
75 config.set('compute', 'flavor_ref', FLAVOR_ID)
76 if FLAVOR_ID_ALT is not None:
77 config.set('compute', 'flavor_ref_alt', FLAVOR_ID_ALT)
78 config.set('identity', 'tenant_name', CONST.tempest_identity_tenant_name)
79 config.set('identity', 'username', CONST.tempest_identity_user_name)
80 config.set('identity', 'password', CONST.tempest_identity_user_password)
82 'validation', 'ssh_timeout', CONST.tempest_validation_ssh_timeout)
84 if CONST.OS_ENDPOINT_TYPE is not None:
85 services_list = ['compute',
92 sections = config.sections()
93 for service in services_list:
94 if service not in sections:
95 config.add_section(service)
96 config.set(service, 'endpoint_type',
97 CONST.OS_ENDPOINT_TYPE)
99 with open(tempest_conf_file, 'wb') as config_file:
100 config.write(config_file)
102 # Copy tempest.conf to /home/opnfv/functest/results/tempest/
104 tempest_conf_file, TEMPEST_RESULTS_DIR + '/tempest.conf')
106 return releng_constants.EXIT_OK
109 def configure_tempest_multisite(logger, deployment_dir):
111 Add/update needed parameters into tempest.conf file generated by Rally
113 logger.debug("configure the tempest")
114 configure_tempest(logger, deployment_dir)
116 logger.debug("Finding tempest.conf file...")
117 tempest_conf_old = os.path.join(deployment_dir, '/tempest.conf')
118 if not os.path.isfile(tempest_conf_old):
119 logger.error("Tempest configuration file %s NOT found."
121 return releng_constants.EXIT_RUN_ERROR
123 # Copy tempest.conf to /home/opnfv/functest/results/tempest/
124 cur_path = os.path.split(os.path.realpath(__file__))[0]
125 tempest_conf_file = os.path.join(cur_path, '/tempest_multisite.conf')
126 shutil.copyfile(tempest_conf_old, tempest_conf_file)
128 logger.debug("Updating selected tempest.conf parameters...")
129 config = ConfigParser.RawConfigParser()
130 config.read(tempest_conf_file)
132 config.set('service_available', 'kingbird', 'true')
133 # cmd = ("openstack endpoint show kingbird | grep publicurl |"
134 # "awk '{print $4}' | awk -F '/' '{print $4}'")
135 # kingbird_api_version = os.popen(cmd).read()
136 kingbird_api_version = os_utils.get_endpoint(service_type='kingbird')
138 if CI_INSTALLER_TYPE == 'fuel':
139 # For MOS based setup, the service is accessible
141 kingbird_conf_path = "/etc/kingbird/kingbird.conf"
142 installer_type = CI_INSTALLER_TYPE
143 installer_ip = CI_INSTALLER_IP
144 installer_username = CONST.__getattribute__(
145 'multisite_{}_installer_username'.format(installer_type))
146 installer_password = CONST.__getattribute__(
147 'multisite_{}_installer_password'.format(installer_type))
149 ssh_options = ("-o UserKnownHostsFile=/dev/null -o "
150 "StrictHostKeyChecking=no")
152 # Get the controller IP from the fuel node
153 cmd = 'sshpass -p %s ssh 2>/dev/null %s %s@%s \
154 \'fuel node --env 1| grep controller | grep "True\| 1" \
155 | awk -F\| "{print \$5}"\'' % (installer_password,
159 multisite_controller_ip = "".join(os.popen(cmd).read().split())
161 # Login to controller and get bind host details
162 cmd = 'sshpass -p %s ssh 2>/dev/null %s %s@%s "ssh %s \\" \
163 grep -e "^bind_" %s \\""' % (installer_password,
167 multisite_controller_ip,
169 bind_details = os.popen(cmd).read()
170 bind_details = "".join(bind_details.split())
171 # Extract port number from the bind details
172 bind_port = re.findall(r"\D(\d{4})", bind_details)[0]
173 # Extract ip address from the bind details
174 bind_host = re.findall(r"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}",
176 kingbird_endpoint_url = "http://%s:%s/" % (bind_host, bind_port)
178 # cmd = "openstack endpoint show kingbird | grep publicurl |\
179 # awk '{print $4}' | awk -F '/' '{print $3}'"
180 # kingbird_endpoint_url = os.popen(cmd).read()
181 kingbird_endpoint_url = os_utils.get_endpoint(service_type='kingbird')
184 config.add_section("kingbird")
186 logger.info('kingbird section exist')
187 config.set('kingbird', 'endpoint_type', 'publicURL')
188 config.set('kingbird', 'TIME_TO_SYNC', '20')
189 config.set('kingbird', 'endpoint_url', kingbird_endpoint_url)
190 config.set('kingbird', 'api_version', kingbird_api_version)
191 with open(tempest_conf_file, 'wb') as config_file:
192 config.write(config_file)
194 return releng_constants.EXIT_OK