def test_get_functest_config_default(self, mock_get_parameter_from_yaml): with mock.patch.dict(os.environ, {'CONFIG_FUNCTEST_YAML': self.config_yaml}): functest_utils.get_functest_config(self.parameter) mock_get_parameter_from_yaml. \ assert_called_once_with(self.parameter, self.config_yaml)
def __init__(self): self.line_length = 30 self.test_db = ft_utils.get_functest_config("results.test_db_url") self.repo_path = CONST.dir_repo_sfc self.sfc_test_dir = os.path.join(self.repo_path, "sfc", "tests", "functest") self.vnfd_dir = os.path.join(self.sfc_test_dir, "vnfd-templates") self.vnfd_default_params_file = os.path.join( self.sfc_test_dir, "vnfd-default-params-file") self.functest_results_dir = os.path.join(CONST.dir_results, "odl-sfc") self.config_file = os.path.join(self.sfc_test_dir, "config.yaml") self.installer_type = ft_utils.get_parameter_from_yaml( "defaults.installer.type", self.config_file) self.installer_ip = ft_utils.get_parameter_from_yaml( "defaults.installer.ip", self.config_file) self.installer_user = ft_utils.get_parameter_from_yaml( "defaults.installer.user", self.config_file) try: self.installer_password = ft_utils.get_parameter_from_yaml( "defaults.installer.password", self.config_file) except: self.installer_password = None try: self.installer_key_file = ft_utils.get_parameter_from_yaml( "defaults.installer.key_file", self.config_file) except: self.installer_key_file = None try: self.installer_cluster = ft_utils.get_parameter_from_yaml( "defaults.installer.cluster", self.config_file) except: self.installer_cluster = None self.flavor = ft_utils.get_parameter_from_yaml("defaults.flavor", self.config_file) self.ram_size_in_mb = ft_utils.get_parameter_from_yaml( "defaults.ram_size_in_mb", self.config_file) self.disk_size_in_gb = ft_utils.get_parameter_from_yaml( "defaults.disk_size_in_gb", self.config_file) self.vcpu_count = ft_utils.get_parameter_from_yaml( "defaults.vcpu_count", self.config_file) self.image_name = ft_utils.get_parameter_from_yaml( "defaults.image_name", self.config_file) self.image_file_name = ft_utils.get_parameter_from_yaml( "defaults.image_file_name", self.config_file) self.image_format = ft_utils.get_parameter_from_yaml( "defaults.image_format", self.config_file) self.url = ft_utils.get_parameter_from_yaml("defaults.url", self.config_file) self.dir_functest_data = ft_utils.get_functest_config( "general.dir.functest_data") self.image_path = os.path.join(self.dir_functest_data, self.image_file_name)
def load_config(): """ Load connectivity settings from yaml. Load connectivity settings to Energy recording API Use functest global config yaml file (see functest_utils.get_functest_config) """ # Singleton pattern for energy_recorder_api static member # Load only if not previouly done if EnergyRecorder.energy_recorder_api is None: environment = CONST.__getattribute__('NODE_NAME') # API URL energy_recorder_uri = ft_utils.get_functest_config( "energy_recorder.api_url") assert energy_recorder_uri assert environment uri_comp = "/recorders/environment/" uri_comp += urllib.quote_plus(environment) EnergyRecorder.logger.debug( "API recorder at: " + energy_recorder_uri + uri_comp) # Creds creds_usr = ft_utils.get_functest_config( "energy_recorder.api_user") creds_pass = ft_utils.get_functest_config( "energy_recorder.api_password") if creds_usr != "" and creds_pass != "": energy_recorder_api_auth = (creds_usr, creds_pass) else: energy_recorder_api_auth = None try: resp = requests.get(energy_recorder_uri + "/monitoring/ping", auth=energy_recorder_api_auth, headers={ 'content-type': 'application/json' }, timeout=EnergyRecorder.CONNECTION_TIMOUT) api_available = json.loads(resp.text)["status"] == "OK" except Exception: # pylint: disable=broad-except EnergyRecorder.logger.error( "Energy recorder API is not available") api_available = False # Final config EnergyRecorder.energy_recorder_api = { "uri": energy_recorder_uri + uri_comp, "auth": energy_recorder_api_auth, "available": api_available } return EnergyRecorder.energy_recorder_api["available"]
def __init__(self): self.repo_path = ft_constants.SDNVPN_REPO_DIR self.config_file = os.path.join(self.repo_path, 'sdnvpn/test/functest/config.yaml') self.keyfile_path = os.path.join(self.repo_path, 'sdnvpn/artifacts/id_rsa') self.test_db = ft_utils.get_functest_config("results.test_db_url") self.line_length = 90 # length for the summary table self.vm_boot_timeout = 180 self.default_flavor = ft_utils.get_parameter_from_yaml( "defaults.flavor", self.config_file) self.image_filename = ft_utils.get_functest_config( "general.openstack.image_file_name") self.image_format = ft_utils.get_functest_config( "general.openstack.image_disk_format") self.image_path = '{0}/{1}'.format( ft_utils.get_functest_config( "general.directories.dir_functest_data"), self.image_filename)
def load_config(): """ Load connectivity settings from yaml. Load connectivity settings to Energy recording API Use functest global config yaml file (see functest_utils.get_functest_config) """ # Singleton pattern for energy_recorder_api static member # Load only if not previouly done if EnergyRecorder.energy_recorder_api is None: environment = ft_utils.get_pod_name() # API URL energy_recorder_uri = ft_utils.get_functest_config( "energy_recorder.api_url") assert energy_recorder_uri assert environment energy_recorder_uri += "/recorders/environment/" energy_recorder_uri += urllib.quote_plus(environment) EnergyRecorder.logger.debug("API recorder at: " + energy_recorder_uri) # Creds user = ft_utils.get_functest_config("energy_recorder.api_user") password = ft_utils.get_functest_config( "energy_recorder.api_password") if user != "" and password != "": energy_recorder_api_auth = (user, password) else: energy_recorder_api_auth = None # Final config EnergyRecorder.energy_recorder_api = { "uri": energy_recorder_uri, "auth": energy_recorder_api_auth }
def get_value(functest_config_key, env_variable): try: constant = ft_utils.get_functest_config(functest_config_key) # logger.debug("%s is defined in config_functest.yaml as [%s]" # % (env_variable, constant)) return constant except ValueError: logger.warning("%s is not defined in config_functest.yaml" % functest_config_key) constant = os.getenv(env_variable) if constant is None: raise ValueError("%s is neither defined in config_functest.yaml" " nor environment variable" % env_variable) else: logger.debug("%s is defined as environment variable as [%s]" % (env_variable, constant)) return constant
def create_flavor(nova_client, flavor_name, ram, disk, vcpus, public=True): try: flavor = nova_client.flavors.create( flavor_name, ram, vcpus, disk, is_public=public) try: extra_specs = ft_utils.get_functest_config( 'general.flavor_extra_specs') flavor.set_keys(extra_specs) except ValueError: # flavor extra specs are not configured, therefore skip the update pass except Exception as e: logger.error("Error [create_flavor(nova_client, '%s', '%s', '%s', " "'%s')]: %s" % (flavor_name, ram, disk, vcpus, e)) return None return flavor.id
def create_glance_image(glance_client, image_name, file_path, disk="qcow2", container="bare", public=True): if not os.path.isfile(file_path): logger.error("Error: file %s does not exist." % file_path) return None try: image_id = get_image_id(glance_client, image_name) if image_id != '': if logger: logger.info("Image %s already exists." % image_name) else: if logger: logger.info("Creating image '%s' from '%s'..." % (image_name, file_path)) try: properties = ft_utils.get_functest_config( 'general.image_properties') except ValueError: # image properties are not configured # therefore don't add any properties properties = {} with open(file_path) as fimage: image = glance_client.images.create(name=image_name, is_public=public, disk_format=disk, container_format=container, properties=properties, data=fimage) image_id = image.id return image_id except Exception, e: logger.error("Error [create_glance_image(glance_client, '%s', '%s', " "'%s')]: %s" % (image_name, file_path, str(public), e)) return None
import sys import time import yaml import functest.utils.functest_logger as ft_logger import functest.utils.functest_utils as ft_utils from sdnvpn.lib import config as sdnvpn_config parser = argparse.ArgumentParser() parser.add_argument("-r", "--report", help="Create json result file", action="store_true") args = parser.parse_args() TEST_DB_URL = ft_utils.get_functest_config('results.test_db_url') logger = ft_logger.Logger("sdnvpn-run-tests").getLogger() COMMON_CONFIG = sdnvpn_config.CommonConfig() def push_results(testname, start_time, end_time, criteria, details): logger.info("Push testcase '%s' results into the DB...\n" % testname) ft_utils.push_results_to_db("sdnvpn", testname, start_time, end_time, criteria, details) def main(): with open(COMMON_CONFIG.config_file) as f: config_yaml = yaml.safe_load(f)
from opnfv.deployment.factory import Factory as DeploymentFactory import sfc.lib.topology_shuffler as topo_shuffler logger = ft_logger.Logger(__name__).getLogger() CLIENT = "client" SERVER = "server" FLAVOR = "custom" RAM_SIZE_IN_MB = "1500" DISK_SIZE_IN_GB = "10" VCPU_COUNT = "1" IMAGE_NAME = "sf_nsh_vnc_sparse" IMAGE_FILE_NAME = "sf_nsh_vnc_sparse.qcow2" IMAGE_FORMAT = "qcow2" IMAGE_URL = "https://www.dropbox.com/s/w3rtdwqm02xkqj6/" DIR_FUNCTEST_DATA = ft_utils.get_functest_config("general.dir.functest_data") IMAGE_PATH = os.path.join(DIR_FUNCTEST_DATA, IMAGE_FILE_NAME) NET_NAME = "example-net" SUBNET_NAME = "example-subnet" ROUTER_NAME = "example-router" SUBNET_CIDR = "11.0.0.0/24" SECGROUP_NAME = "example-sg" SECGROUP_DESCR = "Example Security group" INSTALLER = { "type": "fuel", "ip": "10.20.0.2", "user": "******", "password": "******", "cluster": "1" }
parser.add_argument("-r", "--report", help="Create json result file", action="store_true") args = parser.parse_args() with open(os.environ["CONFIG_FUNCTEST_YAML"]) as f: functest_yaml = yaml.safe_load(f) dirs = functest_yaml.get('general').get('directories') TEST_DB_URL = functest_yaml.get('results').get('test_db_url') logger = ft_logger.Logger("moon").getLogger() RESULTS_DIR = \ functest_utils.get_functest_config('general.directories.dir_results') def __get_endpoint_url(name="keystone"): proc = subprocess.Popen(["openstack", "endpoint", "show", name, "-f", "yaml"], stdout=subprocess.PIPE) y = yaml.load(proc.stdout.read()) url = y['publicurl'] url = url.replace("http://", "") url = url.replace("https://", "") host, port = url.split(":") port = port.split("/")[0] return host, port def test_federation():
def get_conf(parameter): return ft_utils.get_functest_config(parameter)
def configure_tempest_multisite(deployment_dir): """ Add/update needed parameters into tempest.conf file generated by Rally """ logger.debug("configure the tempest") configure_tempest(deployment_dir) logger.debug("Finding tempest.conf file...") tempest_conf_old = os.path.join(deployment_dir, '/tempest.conf') if not os.path.isfile(tempest_conf_old): logger.error("Tempest configuration file %s NOT found." % tempest_conf_old) exit(-1) # Copy tempest.conf to /home/opnfv/functest/results/tempest/ cur_path = os.path.split(os.path.realpath(__file__))[0] tempest_conf_file = os.path.join(cur_path, '/tempest_multisite.conf') shutil.copyfile(tempest_conf_old, tempest_conf_file) logger.debug("Updating selected 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() 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 = ft_utils.get_functest_config( "multisite." + installer_type + "_environment.installer_username") installer_password = ft_utils.get_functest_config( "multisite." + installer_type + "_environment.installer_password") 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() try: config.add_section("kingbird") except Exception: logger.info('kingbird section exist') config.set('kingbird', 'endpoint_type', 'publicURL') config.set('kingbird', 'TIME_TO_SYNC', '20') config.set('kingbird', 'endpoint_url', kingbird_endpoint_url) config.set('kingbird', 'api_version', kingbird_api_version) with open(tempest_conf_file, 'wb') as config_file: config.write(config_file) return True