Remove multisite support
[functest-xtesting.git] / functest / opnfv_tests / openstack / tempest / conf_utils.py
index 15365cc..975f2bd 100644 (file)
 import ConfigParser
 import logging
 import os
-import re
+import pkg_resources
 import shutil
 import subprocess
 
+import yaml
+
 from functest.utils.constants import CONST
 import functest.utils.functest_utils as ft_utils
 import functest.utils.openstack_utils as os_utils
@@ -21,23 +23,24 @@ import functest.utils.openstack_utils as os_utils
 
 IMAGE_ID_ALT = None
 FLAVOR_ID_ALT = None
-REPO_PATH = CONST.__getattribute__('dir_repo_functest')
 GLANCE_IMAGE_PATH = os.path.join(
     CONST.__getattribute__('dir_functest_images'),
     CONST.__getattribute__('openstack_image_file_name'))
-TEMPEST_TEST_LIST_DIR = CONST.__getattribute__('dir_tempest_cases')
 TEMPEST_RESULTS_DIR = os.path.join(CONST.__getattribute__('dir_results'),
                                    'tempest')
-TEMPEST_CUSTOM = os.path.join(REPO_PATH, TEMPEST_TEST_LIST_DIR,
-                              'test_list.txt')
-TEMPEST_BLACKLIST = os.path.join(REPO_PATH, TEMPEST_TEST_LIST_DIR,
-                                 'blacklist.txt')
-TEMPEST_DEFCORE = os.path.join(REPO_PATH, TEMPEST_TEST_LIST_DIR,
-                               'defcore_req.txt')
+TEMPEST_CUSTOM = pkg_resources.resource_filename(
+    'functest', 'opnfv_tests/openstack/tempest/custom_tests/test_list.txt')
+TEMPEST_BLACKLIST = pkg_resources.resource_filename(
+    'functest', 'opnfv_tests/openstack/tempest/custom_tests/blacklist.txt')
+TEMPEST_DEFCORE = pkg_resources.resource_filename(
+    'functest',
+    'opnfv_tests/openstack/tempest/custom_tests/defcore_req.txt')
 TEMPEST_RAW_LIST = os.path.join(TEMPEST_RESULTS_DIR, 'test_raw_list.txt')
 TEMPEST_LIST = os.path.join(TEMPEST_RESULTS_DIR, 'test_list.txt')
 REFSTACK_RESULTS_DIR = os.path.join(CONST.__getattribute__('dir_results'),
                                     'refstack')
+TEMPEST_CONF_YAML = pkg_resources.resource_filename(
+    'functest', 'opnfv_tests/openstack/tempest/custom_tests/tempest_conf.yaml')
 
 CI_INSTALLER_TYPE = CONST.__getattribute__('INSTALLER_TYPE')
 CI_INSTALLER_IP = CONST.__getattribute__('INSTALLER_IP')
@@ -227,8 +230,6 @@ def configure_tempest(deployment_dir, IMAGE_ID=None, FLAVOR_ID=None,
     conf_file = configure_verifier(deployment_dir)
     configure_tempest_update_params(conf_file,
                                     IMAGE_ID, FLAVOR_ID)
-    if MODE == 'feature_multisite':
-        configure_tempest_multisite_params(conf_file)
 
 
 def configure_tempest_defcore(deployment_dir, img_flavor_dict):
@@ -243,6 +244,11 @@ def configure_tempest_defcore(deployment_dir, img_flavor_dict):
     logger.debug("Updating selected tempest.conf parameters for defcore...")
     config = ConfigParser.RawConfigParser()
     config.read(conf_file)
+    config.set('DEFAULT', 'log_file', '{}/tempest.log'.format(deployment_dir))
+    config.set('oslo_concurrency', 'lock_path',
+               '{}/lock_files'.format(deployment_dir))
+    config.set('scenario', 'img_dir', '{}'.format(deployment_dir))
+    config.set('scenario', 'img_file', 'tempest-image')
     config.set('compute', 'image_ref', img_flavor_dict.get("image_id"))
     config.set('compute', 'image_ref_alt',
                img_flavor_dict['image_id_alt'])
@@ -253,9 +259,9 @@ def configure_tempest_defcore(deployment_dir, img_flavor_dict):
     with open(conf_file, 'wb') as config_file:
         config.write(config_file)
 
-    confpath = os.path.join(
-        CONST.__getattribute__('dir_functest_test'),
-        CONST.__getattribute__('refstack_tempest_conf_path'))
+    confpath = pkg_resources.resource_filename(
+        'functest',
+        'opnfv_tests/openstack/refstack_client/refstack_tempest.conf')
     shutil.copyfile(conf_file, confpath)
 
 
@@ -290,6 +296,11 @@ def configure_tempest_update_params(tempest_conf_file,
     config.set('identity', 'password',
                CONST.__getattribute__('tempest_identity_user_password'))
     config.set('identity', 'region', 'RegionOne')
+    if os_utils.is_keystone_v3():
+        auth_version = 'v3'
+    else:
+        auth_version = 'v2'
+    config.set('identity', 'auth_version', auth_version)
     config.set(
         'validation', 'ssh_timeout',
         CONST.__getattribute__('tempest_validation_ssh_timeout'))
@@ -318,6 +329,19 @@ def configure_tempest_update_params(tempest_conf_file,
             config.set(service, 'endpoint_type',
                        CONST.__getattribute__('OS_ENDPOINT_TYPE'))
 
+    logger.debug('Add/Update required params defined in tempest_conf.yaml '
+                 'into tempest.conf file')
+    with open(TEMPEST_CONF_YAML) as f:
+        conf_yaml = yaml.safe_load(f)
+    if conf_yaml:
+        sections = config.sections()
+        for section in conf_yaml:
+            if section not in sections:
+                config.add_section(section)
+            sub_conf = conf_yaml.get(section)
+            for key, value in sub_conf.items():
+                config.set(section, key, value)
+
     with open(tempest_conf_file, 'wb') as config_file:
         config.write(config_file)
 
@@ -346,93 +370,3 @@ def configure_verifier(deployment_dir):
                         % tempest_conf_file)
     else:
         return tempest_conf_file
-
-
-def configure_tempest_multisite_params(tempest_conf_file):
-    """
-    Add/update multisite parameters into tempest.conf file generated by Rally
-    """
-    logger.debug("Updating multisite tempest.conf parameters...")
-    config = ConfigParser.RawConfigParser()
-    config.read(tempest_conf_file)
-
-    config.set('service_available', 'kingbird', 'true')
-    # cmd = ("openstack endpoint show kingbird | grep publicurl |"
-    #       "awk '{print $4}' | awk -F '/' '{print $4}'")
-    # kingbird_api_version = os.popen(cmd).read()
-    # kingbird_api_version = os_utils.get_endpoint(service_type='multisite')
-
-    if CI_INSTALLER_TYPE == 'fuel':
-        # For MOS based setup, the service is accessible
-        # via bind host
-        kingbird_conf_path = "/etc/kingbird/kingbird.conf"
-        installer_type = CI_INSTALLER_TYPE
-        installer_ip = CI_INSTALLER_IP
-        installer_username = CONST.__getattribute__(
-            'multisite_{}_installer_username'.format(installer_type))
-        installer_password = CONST.__getattribute__(
-            'multisite_{}_installer_password'.format(installer_type))
-
-        ssh_options = ("-o UserKnownHostsFile=/dev/null -o "
-                       "StrictHostKeyChecking=no")
-
-        # Get the controller IP from the fuel node
-        cmd = ('sshpass -p %s ssh 2>/dev/null %s %s@%s '
-               '\'fuel node --env 1| grep controller | grep "True\|  1" '
-               '| awk -F\| "{print \$5}"\'' % (installer_password,
-                                               ssh_options,
-                                               installer_username,
-                                               installer_ip))
-        multisite_controller_ip = "".join(os.popen(cmd).read().split())
-
-        # Login to controller and get bind host details
-        cmd = ('sshpass -p %s ssh 2>/dev/null  %s %s@%s "ssh %s \\" '
-               'grep -e "^bind_" %s  \\""' % (installer_password,
-                                              ssh_options,
-                                              installer_username,
-                                              installer_ip,
-                                              multisite_controller_ip,
-                                              kingbird_conf_path))
-        bind_details = os.popen(cmd).read()
-        bind_details = "".join(bind_details.split())
-        # Extract port number from the bind details
-        bind_port = re.findall(r"\D(\d{4})", bind_details)[0]
-        # Extract ip address from the bind details
-        bind_host = re.findall(r"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}",
-                               bind_details)[0]
-        kingbird_endpoint_url = "http://%s:%s/" % (bind_host, bind_port)
-    else:
-        # cmd = "openstack endpoint show kingbird | grep publicurl |\
-        #       awk '{print $4}' | awk -F '/' '{print $3}'"
-        # kingbird_endpoint_url = os.popen(cmd).read()
-        kingbird_endpoint_url = os_utils.get_endpoint(service_type='kingbird')
-
-    try:
-        config.add_section("kingbird")
-    except Exception:
-        logger.info('kingbird section exist')
-
-    # set the domain id
-    config.set('auth', 'admin_domain_name', 'default')
-
-    config.set('kingbird', 'endpoint_type', 'publicURL')
-    config.set('kingbird', 'TIME_TO_SYNC', '120')
-    config.set('kingbird', 'endpoint_url', kingbird_endpoint_url)
-    config.set('kingbird', 'api_version', 'v1.0')
-    with open(tempest_conf_file, 'wb') as config_file:
-        config.write(config_file)
-
-    backup_tempest_config(tempest_conf_file)
-
-
-def install_verifier_ext(path):
-    """
-    Install extension to active verifier
-    """
-    logger.info("Installing verifier from existing repo...")
-    tag = get_repo_tag(path)
-    cmd = ("rally verify add-verifier-ext --source {0} "
-           "--version {1}"
-           .format(path, tag))
-    error_msg = ("Problem while adding verifier extension from %s" % path)
-    ft_utils.execute_command_raise(cmd, error_msg=error_msg)