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 from functest.utils.constants import CONST
22 REPO_PATH = CONST.dir_repo_functest
23 GLANCE_IMAGE_PATH = os.path.join(CONST.dir_functest_data,
24 CONST.openstack_image_file_name)
25 TEMPEST_TEST_LIST_DIR = CONST.dir_tempest_cases
26 TEMPEST_RESULTS_DIR = os.path.join(CONST.dir_results,
28 TEMPEST_CUSTOM = os.path.join(REPO_PATH, TEMPEST_TEST_LIST_DIR,
30 TEMPEST_BLACKLIST = os.path.join(REPO_PATH, TEMPEST_TEST_LIST_DIR,
32 TEMPEST_DEFCORE = os.path.join(REPO_PATH, TEMPEST_TEST_LIST_DIR,
34 TEMPEST_RAW_LIST = os.path.join(TEMPEST_RESULTS_DIR, 'test_raw_list.txt')
35 TEMPEST_LIST = os.path.join(TEMPEST_RESULTS_DIR, 'test_list.txt')
37 CI_INSTALLER_TYPE = CONST.INSTALLER_TYPE
38 CI_INSTALLER_IP = CONST.INSTALLER_IP
41 def configure_tempest(logger, deployment_dir, IMAGE_ID=None, FLAVOR_ID=None):
43 Add/update needed parameters into tempest.conf file generated by Rally
45 tempest_conf_file = deployment_dir + "/tempest.conf"
46 if os.path.isfile(tempest_conf_file):
47 logger.debug("Deleting old tempest.conf file...")
48 os.remove(tempest_conf_file)
50 logger.debug("Generating new tempest.conf file...")
51 cmd = "rally verify genconfig"
52 ft_utils.execute_command(cmd)
54 logger.debug("Finding tempest.conf file...")
55 if not os.path.isfile(tempest_conf_file):
56 logger.error("Tempest configuration file %s NOT found."
58 return releng_constants.EXIT_RUN_ERROR
60 logger.debug("Updating selected tempest.conf parameters...")
61 config = ConfigParser.RawConfigParser()
62 config.read(tempest_conf_file)
66 CONST.tempest_private_net_name)
67 if CONST.tempest_use_custom_images:
68 if IMAGE_ID is not None:
69 config.set('compute', 'image_ref', IMAGE_ID)
70 if IMAGE_ID_ALT is not None:
71 config.set('compute', 'image_ref_alt', IMAGE_ID_ALT)
72 if CONST.tempest_use_custom_flavors:
73 if FLAVOR_ID is not None:
74 config.set('compute', 'flavor_ref', FLAVOR_ID)
75 if FLAVOR_ID_ALT is not None:
76 config.set('compute', 'flavor_ref_alt', FLAVOR_ID_ALT)
77 config.set('identity', 'tenant_name', CONST.tempest_identity_tenant_name)
78 config.set('identity', 'username', CONST.tempest_identity_user_name)
79 config.set('identity', 'password', CONST.tempest_identity_user_password)
81 'validation', 'ssh_timeout', CONST.tempest_validation_ssh_timeout)
83 if CONST.OS_ENDPOINT_TYPE is not None:
84 services_list = ['compute',
91 sections = config.sections()
92 for service in services_list:
93 if service not in sections:
94 config.add_section(service)
95 config.set(service, 'endpoint_type',
96 CONST.OS_ENDPOINT_TYPE)
98 with open(tempest_conf_file, 'wb') as config_file:
99 config.write(config_file)
101 # Copy tempest.conf to /home/opnfv/functest/results/tempest/
103 tempest_conf_file, TEMPEST_RESULTS_DIR + '/tempest.conf')
105 return releng_constants.EXIT_OK
108 def configure_tempest_multisite(logger, deployment_dir):
110 Add/update needed parameters into tempest.conf file generated by Rally
112 logger.debug("configure the tempest")
113 configure_tempest(logger, deployment_dir)
115 logger.debug("Finding tempest.conf file...")
116 tempest_conf_old = os.path.join(deployment_dir, '/tempest.conf')
117 if not os.path.isfile(tempest_conf_old):
118 logger.error("Tempest configuration file %s NOT found."
120 return releng_constants.EXIT_RUN_ERROR
122 # Copy tempest.conf to /home/opnfv/functest/results/tempest/
123 cur_path = os.path.split(os.path.realpath(__file__))[0]
124 tempest_conf_file = os.path.join(cur_path, '/tempest_multisite.conf')
125 shutil.copyfile(tempest_conf_old, tempest_conf_file)
127 logger.debug("Updating selected tempest.conf parameters...")
128 config = ConfigParser.RawConfigParser()
129 config.read(tempest_conf_file)
131 config.set('service_available', 'kingbird', 'true')
132 cmd = ("openstack endpoint show kingbird | grep publicurl |"
133 "awk '{print $4}' | awk -F '/' '{print $4}'")
134 kingbird_api_version = os.popen(cmd).read()
135 if CI_INSTALLER_TYPE == 'fuel':
136 # For MOS based setup, the service is accessible
138 kingbird_conf_path = "/etc/kingbird/kingbird.conf"
139 installer_type = CI_INSTALLER_TYPE
140 installer_ip = CI_INSTALLER_IP
141 installer_username = CONST.__getattribute__(
142 'multisite_{}_installer_username'.format(installer_type))
143 installer_password = CONST.__getattribute__(
144 'multisite_{}_installer_password'.format(installer_type))
146 ssh_options = ("-o UserKnownHostsFile=/dev/null -o "
147 "StrictHostKeyChecking=no")
149 # Get the controller IP from the fuel node
150 cmd = 'sshpass -p %s ssh 2>/dev/null %s %s@%s \
151 \'fuel node --env 1| grep controller | grep "True\| 1" \
152 | awk -F\| "{print \$5}"\'' % (installer_password,
156 multisite_controller_ip = "".join(os.popen(cmd).read().split())
158 # Login to controller and get bind host details
159 cmd = 'sshpass -p %s ssh 2>/dev/null %s %s@%s "ssh %s \\" \
160 grep -e "^bind_" %s \\""' % (installer_password,
164 multisite_controller_ip,
166 bind_details = os.popen(cmd).read()
167 bind_details = "".join(bind_details.split())
168 # Extract port number from the bind details
169 bind_port = re.findall(r"\D(\d{4})", bind_details)[0]
170 # Extract ip address from the bind details
171 bind_host = re.findall(r"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}",
173 kingbird_endpoint_url = "http://%s:%s/" % (bind_host, bind_port)
175 cmd = "openstack endpoint show kingbird | grep publicurl |\
176 awk '{print $4}' | awk -F '/' '{print $3}'"
177 kingbird_endpoint_url = os.popen(cmd).read()
180 config.add_section("kingbird")
182 logger.info('kingbird section exist')
183 config.set('kingbird', 'endpoint_type', 'publicURL')
184 config.set('kingbird', 'TIME_TO_SYNC', '20')
185 config.set('kingbird', 'endpoint_url', kingbird_endpoint_url)
186 config.set('kingbird', 'api_version', kingbird_api_version)
187 with open(tempest_conf_file, 'wb') as config_file:
188 config.write(config_file)
190 return releng_constants.EXIT_OK