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 functest.utils.functest_constants as ft_constants
16 import functest.utils.functest_utils as ft_utils
17 import opnfv.utils.constants as releng_constants
22 REPO_PATH = ft_constants.FUNCTEST_REPO_DIR
23 GLANCE_IMAGE_PATH = os.path.join(ft_constants.FUNCTEST_DATA_DIR,
24 ft_constants.GLANCE_IMAGE_FILENAME)
25 TEMPEST_TEST_LIST_DIR = ft_constants.TEMPEST_TEST_LIST_DIR
26 TEMPEST_RESULTS_DIR = os.path.join(ft_constants.FUNCTEST_RESULTS_DIR,
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 = ft_constants.CI_INSTALLER_TYPE
38 CI_INSTALLER_IP = ft_constants.CI_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 ft_constants.TEMPEST_PRIVATE_NET_NAME)
67 if ft_constants.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 ft_constants.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', ft_constants.TEMPEST_TENANT_NAME)
78 config.set('identity', 'username', ft_constants.TEMPEST_USER_NAME)
79 config.set('identity', 'password', ft_constants.TEMPEST_USER_PASSWORD)
81 'validation', 'ssh_timeout', ft_constants.TEMPEST_SSH_TIMEOUT)
83 if ft_constants.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 ft_constants.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 = ft_utils.get_functest_config(
142 "multisite." + installer_type +
143 "_environment.installer_username")
144 installer_password = ft_utils.get_functest_config(
145 "multisite." + installer_type +
146 "_environment.installer_password")
148 ssh_options = ("-o UserKnownHostsFile=/dev/null -o "
149 "StrictHostKeyChecking=no")
151 # Get the controller IP from the fuel node
152 cmd = 'sshpass -p %s ssh 2>/dev/null %s %s@%s \
153 \'fuel node --env 1| grep controller | grep "True\| 1" \
154 | awk -F\| "{print \$5}"\'' % (installer_password,
158 multisite_controller_ip = "".join(os.popen(cmd).read().split())
160 # Login to controller and get bind host details
161 cmd = 'sshpass -p %s ssh 2>/dev/null %s %s@%s "ssh %s \\" \
162 grep -e "^bind_" %s \\""' % (installer_password,
166 multisite_controller_ip,
168 bind_details = os.popen(cmd).read()
169 bind_details = "".join(bind_details.split())
170 # Extract port number from the bind details
171 bind_port = re.findall(r"\D(\d{4})", bind_details)[0]
172 # Extract ip address from the bind details
173 bind_host = re.findall(r"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}",
175 kingbird_endpoint_url = "http://%s:%s/" % (bind_host, bind_port)
177 cmd = "openstack endpoint show kingbird | grep publicurl |\
178 awk '{print $4}' | awk -F '/' '{print $3}'"
179 kingbird_endpoint_url = os.popen(cmd).read()
182 config.add_section("kingbird")
184 logger.info('kingbird section exist')
185 config.set('kingbird', 'endpoint_type', 'publicURL')
186 config.set('kingbird', 'TIME_TO_SYNC', '20')
187 config.set('kingbird', 'endpoint_url', kingbird_endpoint_url)
188 config.set('kingbird', 'api_version', kingbird_api_version)
189 with open(tempest_conf_file, 'wb') as config_file:
190 config.write(config_file)
192 return releng_constants.EXIT_OK