Esempio n. 1
0
 def update_auth_section(self):
     """Update auth section in tempest.conf"""
     rconfig = configparser.RawConfigParser()
     rconfig.read(self.conf_file)
     if not rconfig.has_section("auth"):
         rconfig.add_section("auth")
     if env.get("NEW_USER_ROLE").lower() != "member":
         tempest_roles = []
         if rconfig.has_option("auth", "tempest_roles"):
             tempest_roles = functest_utils.convert_ini_to_list(
                 rconfig.get("auth", "tempest_roles"))
         rconfig.set(
             'auth', 'tempest_roles',
             functest_utils.convert_list_to_ini(
                 [env.get("NEW_USER_ROLE")] + tempest_roles))
     if not json.loads(env.get("USE_DYNAMIC_CREDENTIALS").lower()):
         rconfig.set('auth', 'use_dynamic_credentials', False)
         account_file = os.path.join(
             getattr(config.CONF, 'dir_functest_data'), 'accounts.yaml')
         assert os.path.exists(
             account_file), "{} doesn't exist".format(account_file)
         rconfig.set('auth', 'test_accounts_file', account_file)
     if env.get('NO_TENANT_NETWORK').lower() == 'true':
         rconfig.set('auth', 'create_isolated_networks', False)
     with open(self.conf_file, 'w') as config_file:
         rconfig.write(config_file)
Esempio n. 2
0
 def update_scenario_section(self):
     """Update scenario section in tempest.conf"""
     rconfig = configparser.RawConfigParser()
     rconfig.read(self.conf_file)
     filename = getattr(config.CONF, '{}_image'.format(self.case_name),
                        self.filename)
     if not rconfig.has_section('scenario'):
         rconfig.add_section('scenario')
     rconfig.set('scenario', 'img_file', os.path.basename(filename))
     rconfig.set('scenario', 'img_dir', os.path.dirname(filename))
     rconfig.set(
         'scenario', 'img_disk_format',
         getattr(config.CONF, '{}_image_format'.format(self.case_name),
                 self.image_format))
     extra_properties = self.extra_properties.copy()
     if env.get('IMAGE_PROPERTIES'):
         extra_properties.update(
             functest_utils.convert_ini_to_dict(
                 env.get('IMAGE_PROPERTIES')))
     extra_properties.update(
         getattr(config.CONF, '{}_extra_properties'.format(self.case_name),
                 {}))
     rconfig.set('scenario', 'img_properties',
                 functest_utils.convert_dict_to_ini(extra_properties))
     with open(self.conf_file, 'wb') as config_file:
         rconfig.write(config_file)
Esempio n. 3
0
    def create_flavor_alt(self, name=None):
        """Create flavor

        It allows creating multiple alt flavors for the child testcases. It
        forces the same configuration for all subtestcases.

        Returns: flavor

        Raises: expection on error
        """
        assert self.orig_cloud
        flavor = self.orig_cloud.create_flavor(
            name if name else '{}-flavor_alt_{}'.format(
                self.case_name, self.guid),
            getattr(config.CONF, '{}_flavor_alt_ram'.format(self.case_name),
                    self.flavor_alt_ram),
            getattr(config.CONF, '{}_flavor_alt_vcpus'.format(self.case_name),
                    self.flavor_alt_vcpus),
            getattr(config.CONF, '{}_flavor_alt_disk'.format(self.case_name),
                    self.flavor_alt_disk))
        self.__logger.debug("flavor: %s", flavor)
        flavor_alt_extra_specs = self.flavor_alt_extra_specs.copy()
        if env.get('FLAVOR_EXTRA_SPECS'):
            flavor_alt_extra_specs.update(
                functest_utils.convert_ini_to_dict(
                    env.get('FLAVOR_EXTRA_SPECS')))
        flavor_alt_extra_specs.update(
            getattr(config.CONF,
                    '{}_flavor_alt_extra_specs'.format(self.case_name), {}))
        self.orig_cloud.set_flavor_specs(
            flavor.id, flavor_alt_extra_specs)
        return flavor
Esempio n. 4
0
    def publish_image(self, name=None):
        """Publish image

        It allows publishing multiple images for the child testcases. It forces
        the same configuration for all subtestcases.

        Returns: image

        Raises: expection on error
        """
        assert self.cloud
        extra_properties = self.extra_properties.copy()
        if env.get('IMAGE_PROPERTIES'):
            extra_properties.update(
                functest_utils.convert_ini_to_dict(
                    env.get('IMAGE_PROPERTIES')))
        extra_properties.update(
            getattr(config.CONF, '{}_extra_properties'.format(
                self.case_name), {}))
        image = self.cloud.create_image(
            name if name else '{}-img_{}'.format(self.case_name, self.guid),
            filename=getattr(
                config.CONF, '{}_image'.format(self.case_name),
                self.filename),
            meta=extra_properties,
            disk_format=getattr(
                config.CONF, '{}_image_format'.format(self.case_name),
                self.image_format),
            visibility=getattr(
                config.CONF, '{}_visibility'.format(self.case_name),
                self.visibility),
            wait=True)
        self.__logger.debug("image: %s", image)
        return image
Esempio n. 5
0
    def _run(self, args):  # pylint: disable=no-self-use
        """ The built_in function to run a test case """

        case_name = args.get('testcase')
        self._update_logging_ini(args.get('task_id'))

        try:
            cmd = "run_tests -t {}".format(case_name)
            runner = ft_utils.execute_command(cmd)
        except Exception:  # pylint: disable=broad-except
            result = 'FAIL'
            LOGGER.exception("Running test case %s failed!", case_name)
        if runner == os.EX_OK:
            result = 'PASS'
        else:
            result = 'FAIL'

        env_info = {
            'installer': env.get('INSTALLER_TYPE'),
            'scenario': env.get('DEPLOY_SCENARIO'),
            'build_tag': env.get('BUILD_TAG'),
            'ci_loop': env.get('CI_LOOP')
        }
        result = {
            'task_id': args.get('task_id'),
            'testcase': case_name,
            'env_info': env_info,
            'result': result
        }

        return {'result': result}
Esempio n. 6
0
def get_external_net(neutron_client):
    if (env.get('EXTERNAL_NETWORK')):
        return env.get('EXTERNAL_NETWORK')
    for network in neutron_client.list_networks()['networks']:
        if network['router:external']:
            return network['name']
    return None
Esempio n. 7
0
def get_external_net_id(neutron_client):
    if (env.get('EXTERNAL_NETWORK')):
        networks = neutron_client.list_networks(
            name=env.get('EXTERNAL_NETWORK'))
        net_id = networks['networks'][0]['id']
        return net_id
    for network in neutron_client.list_networks()['networks']:
        if network['router:external']:
            return network['id']
    return None
Esempio n. 8
0
 def update_keystone_default_role(rally_conf='/etc/rally/rally.conf'):
     """Set keystone_default_role in rally.conf"""
     if env.get("NEW_USER_ROLE").lower() != "member":
         rconfig = configparser.RawConfigParser()
         rconfig.read(rally_conf)
         if not rconfig.has_section('openstack'):
             rconfig.add_section('openstack')
         rconfig.set('openstack', 'keystone_default_role',
                     env.get("NEW_USER_ROLE"))
         with open(rally_conf, 'wb') as config_file:
             rconfig.write(config_file)
Esempio n. 9
0
    def run(self, **kwargs):
        """Run suites in OPNFV environment

        It basically checks env vars to call main() with the keywords
        required.

        Args:
            kwargs: Arbitrary keyword arguments.

        Returns:
            EX_OK if all suites ran well.
            EX_RUN_ERROR otherwise.
        """
        try:
            suites = self.default_suites
            try:
                suites = kwargs["suites"]
            except KeyError:
                pass
            cloud = os_client_config.make_shade()
            neutron_id = cloud.search_services('neutron')[0].id
            endpoint = cloud.search_endpoints(
                filters={
                    'interface':
                    os.environ.get('OS_INTERFACE', 'public').replace(
                        'URL', ''),
                    'service_id':
                    neutron_id
                })[0].url
            kwargs = {'neutronurl': endpoint}
            kwargs['odlip'] = env.get('SDN_CONTROLLER_IP')
            kwargs['odlwebport'] = env.get('SDN_CONTROLLER_WEBPORT')
            kwargs['odlrestconfport'] = env.get('SDN_CONTROLLER_RESTCONFPORT')
            kwargs['odlusername'] = env.get('SDN_CONTROLLER_USER')
            kwargs['odlpassword'] = env.get('SDN_CONTROLLER_PASSWORD')
            kwargs['osusername'] = os.environ['OS_USERNAME']
            kwargs['osuserdomainname'] = os.environ.get(
                'OS_USER_DOMAIN_NAME', 'Default')
            kwargs['osprojectname'] = os.environ['OS_PROJECT_NAME']
            kwargs['osprojectdomainname'] = os.environ.get(
                'OS_PROJECT_DOMAIN_NAME', 'Default')
            kwargs['osauthurl'] = os.environ['OS_AUTH_URL']
            kwargs['ospassword'] = os.environ['OS_PASSWORD']
            assert kwargs['odlip']
        except KeyError as ex:
            self.__logger.error(
                "Cannot run ODL testcases. Please check env var: %s", str(ex))
            return self.EX_RUN_ERROR
        except Exception:  # pylint: disable=broad-except
            self.__logger.exception("Cannot run ODL testcases.")
            return self.EX_RUN_ERROR

        return self.run_suites(suites, **kwargs)
Esempio n. 10
0
 def update_dashboard_section(self):
     """Update dashboard section in tempest.conf"""
     rconfig = configparser.RawConfigParser()
     rconfig.read(self.conf_file)
     if env.get('DASHBOARD_URL'):
         if not rconfig.has_section('dashboard'):
             rconfig.add_section('dashboard')
         rconfig.set('dashboard', 'dashboard_url', env.get('DASHBOARD_URL'))
     else:
         rconfig.set('service_available', 'horizon', False)
     with open(self.conf_file, 'w') as config_file:
         rconfig.write(config_file)
Esempio n. 11
0
    def deploy_vnf(self):
        """Deploy Clearwater IMS."""
        start_time = time.time()

        self.image_alt = self.publish_image_alt()
        self.flavor_alt = self.create_flavor_alt()
        # KeyPair + Image + Flavor OK

        descriptor = self.vnf['descriptor']
        parameters = self.vnf['parameters']

        parameters['public_mgmt_net_id'] = self.ext_net.id
        parameters['public_sig_net_id'] = self.ext_net.id
        parameters['flavor'] = self.flavor_alt.name
        parameters['image'] = self.image_alt.name
        parameters['key_name'] = self.keypair.name
        parameters['external_mgmt_dns_ip'] = env.get('NAMESERVER')
        parameters['external_sig_dns_ip'] = env.get('NAMESERVER')

        self.__logger.info("Create Heat Stack")
        self.stack = self.cloud.create_stack(
            name=descriptor.get('name'),
            template_file=descriptor.get('file_name'),
            wait=True,
            **parameters)
        self.__logger.debug("stack: %s", self.stack)

        servers = self.cloud.list_servers(detailed=True)
        self.__logger.debug("servers: %s", servers)
        for server in servers:
            if not self.check_regex_in_console(
                    server.name, regex='Cloud-init .* finished at ', loop=60):
                return False
            if 'ellis' in server.name:
                self.__logger.debug("server: %s", server)
                ellis_ip = server.public_v4

        assert ellis_ip
        self.clearwater = clearwater.ClearwaterTesting(self.case_name,
                                                       ellis_ip)
        # This call can take time and many retry because Heat is
        # an infrastructure orchestrator so when Heat say "stack created"
        # it means that all OpenStack ressources are created but not that
        # Clearwater are up and ready (Cloud-Init script still running)
        self.clearwater.availability_check_by_creating_numbers()

        duration = time.time() - start_time

        self.details['vnf'].update(status='PASS', duration=duration)
        self.result += 1 / 3 * 100

        return True
Esempio n. 12
0
 def get_external_network(cloud):
     """
     Return the configured external network name or
     the first retrieved external network name
     """
     assert cloud
     if env.get("EXTERNAL_NETWORK"):
         network = cloud.get_network(env.get("EXTERNAL_NETWORK"),
                                     {"router:external": True})
         if network:
             return network
     networks = cloud.list_networks({"router:external": True})
     if networks:
         return networks[0]
     return None
Esempio n. 13
0
def get_ext_net_name(os_creds):
    """
    Returns the configured external network name or
    the first retrieved external network name
    :param: os_creds: an instance of snaps OSCreds object
    :return:
    """
    neutron = neutron_utils.neutron_client(os_creds)
    ext_nets = neutron_utils.get_external_networks(neutron)
    if env.get('EXTERNAL_NETWORK'):
        extnet_config = env.get('EXTERNAL_NETWORK')
        for ext_net in ext_nets:
            if ext_net.name == extnet_config:
                return extnet_config
    return ext_nets[0].name if ext_nets else ""
Esempio n. 14
0
    def create_network_resources(self):
        """Create all tenant network resources

        It creates a router which gateway is the external network detected.
        The new subnet is attached to that router.

        Raises: expection on error
        """
        assert self.cloud
        if env.get('NO_TENANT_NETWORK').lower() != 'true':
            assert self.ext_net
        provider = {}
        if hasattr(config.CONF, '{}_network_type'.format(self.case_name)):
            provider["network_type"] = getattr(
                config.CONF, '{}_network_type'.format(self.case_name))
        if hasattr(config.CONF, '{}_physical_network'.format(self.case_name)):
            provider["physical_network"] = getattr(
                config.CONF, '{}_physical_network'.format(self.case_name))
        if hasattr(config.CONF, '{}_segmentation_id'.format(self.case_name)):
            provider["segmentation_id"] = getattr(
                config.CONF, '{}_segmentation_id'.format(self.case_name))
        domain = self.orig_cloud.get_domain(
            name_or_id=self.orig_cloud.auth.get("project_domain_name",
                                                "Default"))
        project = self.orig_cloud.get_project(self.cloud.auth['project_name'],
                                              domain_id=domain.id)
        self.network = self.orig_cloud.create_network(
            '{}-net_{}'.format(self.case_name, self.guid),
            provider=provider,
            project_id=project.id,
            shared=self.shared_network)
        self.__logger.debug("network: %s", self.network)

        self.subnet = self.cloud.create_subnet(
            self.network.id,
            subnet_name='{}-subnet_{}'.format(self.case_name, self.guid),
            cidr=getattr(config.CONF,
                         '{}_private_subnet_cidr'.format(self.case_name),
                         self.cidr),
            enable_dhcp=True,
            dns_nameservers=[env.get('NAMESERVER')])
        self.__logger.debug("subnet: %s", self.subnet)

        self.router = self.cloud.create_router(
            name='{}-router_{}'.format(self.case_name, self.guid),
            ext_gateway_net_id=self.ext_net.id if self.ext_net else None)
        self.__logger.debug("router: %s", self.router)
        self.cloud.add_router_interface(self.router, subnet_id=self.subnet.id)
Esempio n. 15
0
 def configure(self, **kwargs):
     assert self.user2
     super(TempestHeat, self).configure(**kwargs)
     rconfig = configparser.RawConfigParser()
     rconfig.read(self.conf_file)
     if not rconfig.has_section('heat_plugin'):
         rconfig.add_section('heat_plugin')
     # It fails if region and domain ids are unset
     rconfig.set(
         'heat_plugin', 'region',
         os.environ.get('OS_REGION_NAME', 'RegionOne'))
     rconfig.set('heat_plugin', 'auth_url', os.environ["OS_AUTH_URL"])
     rconfig.set('heat_plugin', 'project_domain_id', self.project.domain.id)
     rconfig.set('heat_plugin', 'user_domain_id', self.project.domain.id)
     rconfig.set(
         'heat_plugin', 'project_domain_name', self.project.domain.name)
     rconfig.set(
         'heat_plugin', 'user_domain_name', self.project.domain.name)
     rconfig.set('heat_plugin', 'username', self.user2.name)
     rconfig.set('heat_plugin', 'password', self.project.password)
     rconfig.set('heat_plugin', 'project_name', self.project.project.name)
     rconfig.set('heat_plugin', 'admin_username', self.project.user.name)
     rconfig.set('heat_plugin', 'admin_password', self.project.password)
     rconfig.set(
         'heat_plugin', 'admin_project_name', self.project.project.name)
     rconfig.set('heat_plugin', 'image_ref', self.image_alt.id)
     rconfig.set('heat_plugin', 'instance_type', self.flavor_alt.id)
     rconfig.set('heat_plugin', 'minimal_image_ref', self.image.id)
     rconfig.set('heat_plugin', 'minimal_instance_type', self.flavor.id)
     if self.ext_net:
         rconfig.set(
             'heat_plugin', 'floating_network_name', self.ext_net.name)
     if self.network:
         rconfig.set('heat_plugin', 'fixed_network_name', self.network.name)
         rconfig.set('heat_plugin', 'fixed_subnet_name', self.subnet.name)
         rconfig.set('heat_plugin', 'network_for_ssh', self.network.name)
     else:
         LOGGER.warning(
             'No tenant network created. '
             'Trying EXTERNAL_NETWORK as a fallback')
         rconfig.set(
             'heat_plugin', 'fixed_network_name',
             env.get("EXTERNAL_NETWORK"))
         rconfig.set(
             'heat_plugin', 'network_for_ssh', env.get("EXTERNAL_NETWORK"))
     with open(self.conf_file, 'w') as config_file:
         rconfig.write(config_file)
     self.backup_tempest_config(self.conf_file, self.res_dir)
Esempio n. 16
0
    def apply_tempest_blacklist(self):
        """Exclude blacklisted test cases."""
        LOGGER.debug("Applying tempest blacklist...")
        if os.path.exists(self.raw_list):
            os.remove(self.raw_list)
        os.rename(self.list, self.raw_list)
        cases_file = self.read_file(self.raw_list)
        result_file = open(self.list, 'w')
        black_tests = []
        try:
            deploy_scenario = env.get('DEPLOY_SCENARIO')
            if bool(deploy_scenario):
                # if DEPLOY_SCENARIO is set we read the file
                black_list_file = open(self.TEMPEST_BLACKLIST)
                black_list_yaml = yaml.safe_load(black_list_file)
                black_list_file.close()
                for item in black_list_yaml:
                    scenarios = item['scenarios']
                    if deploy_scenario in scenarios:
                        tests = item['tests']
                        for test in tests:
                            black_tests.append(test)
                        break
        except Exception:  # pylint: disable=broad-except
            black_tests = []
            LOGGER.debug("Tempest blacklist file does not exist.")

        for cases_line in cases_file:
            for black_tests_line in black_tests:
                if black_tests_line in cases_line:
                    break
            else:
                result_file.write(str(cases_line) + '\n')
        result_file.close()
Esempio n. 17
0
    def excl_func(self):
        """Exclude functionalities."""
        black_tests = []
        func_list = []

        try:
            with open(RallyBase.BLACKLIST_FILE, 'r') as black_list_file:
                black_list_yaml = yaml.safe_load(black_list_file)

            if env.get('BLOCK_MIGRATION').lower() == 'true':
                func_list.append("block_migration")
            if not self._migration_supported():
                func_list.append("no_migration")
            if not self._network_trunk_supported():
                func_list.append("no_net_trunk_service")

            if 'functionality' in black_list_yaml.keys():
                for item in black_list_yaml['functionality']:
                    functions = item['functions']
                    for func in func_list:
                        if func in functions:
                            tests = item['tests']
                            black_tests.extend(tests)
        except Exception:  # pylint: disable=broad-except
            LOGGER.debug("Functionality exclusion not applied.")

        return black_tests
Esempio n. 18
0
    def build_task_args(self, test_name):
        """Build arguments for the Rally task."""
        task_args = {'service_list': [test_name]}
        task_args['image_name'] = str(self.image.name)
        task_args['flavor_name'] = str(self.flavor.name)
        task_args['flavor_alt_name'] = str(self.flavor_alt.name)
        task_args['glance_image_location'] = str(self.filename)
        task_args['glance_image_format'] = str(self.image_format)
        task_args['tmpl_dir'] = str(self.TEMPLATE_DIR)
        task_args['sup_dir'] = str(self.SUPPORT_DIR)
        task_args['users_amount'] = self.USERS_AMOUNT
        task_args['tenants_amount'] = self.TENANTS_AMOUNT
        task_args['use_existing_users'] = False
        task_args['iterations'] = self.ITERATIONS_AMOUNT
        task_args['concurrency'] = self.CONCURRENCY
        task_args['smoke'] = self.smoke
        task_args['volume_version'] = self.VOLUME_VERSION
        task_args['volume_service_type'] = self.VOLUME_SERVICE_TYPE
        task_args['block_migration'] = env.get("BLOCK_MIGRATION").lower()

        if self.ext_net:
            task_args['floating_network'] = str(self.ext_net.name)
        else:
            task_args['floating_network'] = ''

        if self.network:
            task_args['netid'] = str(self.network.id)
        else:
            task_args['netid'] = ''

        return task_args
Esempio n. 19
0
    def _create_network(self):
        """Create network for tests."""
        tempest_net_name = getattr(config.CONF,
                                   'tempest_private_net_name') + self.guid
        provider = {}
        if hasattr(config.CONF, 'tempest_network_type'):
            provider["network_type"] = getattr(config.CONF,
                                               'tempest_network_type')
        if hasattr(config.CONF, 'tempest_physical_network'):
            provider["physical_network"] = getattr(config.CONF,
                                                   'tempest_physical_network')
        if hasattr(config.CONF, 'tempest_segmentation_id'):
            provider["segmentation_id"] = getattr(config.CONF,
                                                  'tempest_segmentation_id')
        LOGGER.info("Creating network with name: '%s'", tempest_net_name)
        self.network = self.cloud.create_network(tempest_net_name,
                                                 provider=provider)
        LOGGER.debug("network: %s", self.network)

        self.subnet = self.cloud.create_subnet(
            self.network.id,
            subnet_name=getattr(config.CONF, 'tempest_private_subnet_name') +
            self.guid,
            cidr=getattr(config.CONF, 'tempest_private_subnet_cidr'),
            enable_dhcp=True,
            dns_nameservers=[env.get('NAMESERVER')])
        LOGGER.debug("subnet: %s", self.subnet)
Esempio n. 20
0
    def build_task_args(self, test_name):
        """Build arguments for the Rally task."""
        task_args = {'service_list': [test_name]}
        task_args['image_name'] = str(self.image.name)
        task_args['flavor_name'] = str(self.flavor.name)
        task_args['flavor_alt_name'] = str(self.flavor_alt.name)
        task_args['glance_image_location'] = str(self.filename)
        task_args['glance_image_format'] = str(self.image_format)
        task_args['tmpl_dir'] = str(self.template_dir)
        task_args['sup_dir'] = str(self.support_dir)
        task_args['users_amount'] = self.users_amount
        task_args['tenants_amount'] = self.tenants_amount
        task_args['use_existing_users'] = False
        task_args['iterations'] = self.iterations_amount
        task_args['concurrency'] = self.concurrency
        task_args['smoke'] = self.smoke
        task_args['volume_version'] = self.volume_version
        task_args['volume_service_type'] = self.volume_service_type
        task_args['block_migration'] = env.get("BLOCK_MIGRATION").lower()

        if self.ext_net:
            task_args['floating_network'] = str(self.ext_net.name)
        else:
            task_args['floating_network'] = ''

        if self.network:
            task_args['netid'] = str(self.network.id)
        else:
            task_args['netid'] = ''

        return task_args
Esempio n. 21
0
 def run(self, **kwargs):
     self.start_time = time.time()
     try:
         assert super(TempestCommon, self).run(
             **kwargs) == testcase.TestCase.EX_OK
         if not os.path.exists(self.res_dir):
             os.makedirs(self.res_dir)
         self.update_rally_regex()
         self.update_default_role()
         rally.RallyBase.update_rally_logs(self.res_dir)
         shutil.copy("/etc/rally/rally.conf", self.res_dir)
         self.configure(**kwargs)
         self.generate_test_list(**kwargs)
         self.apply_tempest_blacklist(TempestCommon.tempest_blacklist)
         if env.get('PUBLIC_ENDPOINT_ONLY').lower() == 'true':
             self.apply_tempest_blacklist(
                 TempestCommon.tempest_public_blacklist)
         self.run_verifier_tests(**kwargs)
         self.parse_verifier_result()
         rally.RallyBase.verify_report(
             os.path.join(self.res_dir, "tempest-report.html"),
             self.verification_id)
         rally.RallyBase.verify_report(
             os.path.join(self.res_dir, "tempest-report.xml"),
             self.verification_id, "junit-xml")
         res = testcase.TestCase.EX_OK
     except Exception:  # pylint: disable=broad-except
         LOGGER.exception('Error with run')
         self.result = 0
         res = testcase.TestCase.EX_RUN_ERROR
     self.stop_time = time.time()
     return res
Esempio n. 22
0
 def __init__(self, **kwargs):
     if "case_name" not in kwargs:
         kwargs["case_name"] = 'tenantnetwork1'
     super(TenantNetwork1, self).__init__(**kwargs)
     self.dir_results = os.path.join(getattr(config.CONF, 'dir_results'))
     self.res_dir = os.path.join(self.dir_results, self.case_name)
     self.output_log_name = 'functest.log'
     self.output_debug_log_name = 'functest.debug.log'
     self.ext_net = None
     try:
         cloud_config = os_client_config.get_config()
         self.cloud = self.orig_cloud = shade.OpenStackCloud(
             cloud_config=cloud_config)
     except Exception:  # pylint: disable=broad-except
         self.cloud = self.orig_cloud = None
         self.__logger.exception("Cannot connect to Cloud")
     if env.get('NO_TENANT_NETWORK').lower() != 'true':
         try:
             self.ext_net = self.get_external_network(self.cloud)
         except Exception:  # pylint: disable=broad-except
             self.__logger.exception("Cannot get the external network")
     self.guid = str(uuid.uuid4())
     self.network = None
     self.subnet = None
     self.router = None
Esempio n. 23
0
    def apply_tempest_blacklist(self, black_list):
        """Exclude blacklisted test cases."""
        LOGGER.debug("Applying tempest blacklist...")
        if os.path.exists(self.raw_list):
            os.remove(self.raw_list)
        os.rename(self.list, self.raw_list)
        cases_file = self.read_file(self.raw_list)
        result_file = open(self.list, 'w')
        black_tests = []
        try:
            deploy_scenario = env.get('DEPLOY_SCENARIO')
            if bool(deploy_scenario):
                # if DEPLOY_SCENARIO is set we read the file
                black_list_file = open(black_list)
                black_list_yaml = yaml.safe_load(black_list_file)
                black_list_file.close()
                for item in black_list_yaml:
                    scenarios = item['scenarios']
                    in_it = rally.RallyBase.in_iterable_re
                    if in_it(deploy_scenario, scenarios):
                        tests = item['tests']
                        black_tests.extend(tests)
        except Exception:  # pylint: disable=broad-except
            black_tests = []
            LOGGER.debug("Tempest blacklist file does not exist.")

        for cases_line in cases_file:
            for black_tests_line in black_tests:
                if re.search(black_tests_line, cases_line):
                    break
            else:
                result_file.write(str(cases_line) + '\n')
        result_file.close()
Esempio n. 24
0
    def write_config(self):
        """Write vmtp.conf

        Raises: Exception on error
        """
        assert self.cloud
        if not os.path.exists(self.res_dir):
            os.makedirs(self.res_dir)
        cmd = ['vmtp', '-sc']
        output = subprocess.check_output(cmd)
        self.__logger.info("%s\n%s", " ".join(cmd), output)
        with open(self.config, "w+") as conf:
            vmtp_conf = yaml.load(output)
            vmtp_conf["private_key_file"] = self.privkey_filename
            vmtp_conf["public_key_file"] = self.pubkey_filename
            vmtp_conf["image_name"] = str(self.image.name)
            vmtp_conf["router_name"] = str(self.router.name)
            vmtp_conf["flavor_type"] = str(self.flavor.name)
            vmtp_conf["internal_network_name"] = [
                "pns-internal-net_{}".format(self.guid),
                "pns-internal-net2_{}".format(self.guid)
            ]
            vmtp_conf["vm_name_client"] = "TestClient_{}".format(self.guid)
            vmtp_conf["vm_name_server"] = "TestServer_{}".format(self.guid)
            vmtp_conf["security_group_name"] = "pns-security{}".format(
                self.guid)
            vmtp_conf["dns_nameservers"] = [env.get('NAMESERVER')]
            vmtp_conf["generic_retry_count"] = self.create_server_timeout // 2
            conf.write(yaml.dump(vmtp_conf))
Esempio n. 25
0
 def run(self, **kwargs):
     # pylint: disable=protected-access
     """Run all read operations to check connections"""
     status = testcase.TestCase.EX_RUN_ERROR
     try:
         assert self.cloud
         self.start_time = time.time()
         self.__logger.debug("list_services: %s",
                             functest_utils.list_services(self.cloud))
         if env.get('NO_TENANT_NETWORK').lower() == 'true':
             self.func_list.remove("list_floating_ip_pools")
             self.func_list.remove("list_floating_ips")
             self.func_list.remove("list_routers")
         for func in self.func_list:
             self.__logger.debug("%s: %s", func,
                                 getattr(self.cloud, func)())
         data = self.cloud._network_client.get("/service-providers.json")
         self.__logger.debug(
             "list_service_providers: %s",
             self.cloud._get_and_munchify('service_providers', data))
         functest_utils.get_openstack_version(self.cloud)
         self.result = 100
         status = testcase.TestCase.EX_OK
     except Exception:  # pylint: disable=broad-except
         self.__logger.exception('Cannot run %s', self.case_name)
     finally:
         self.stop_time = time.time()
     return status
Esempio n. 26
0
 def _read_data(self):
     assert self.cloud
     # Attach volume to VM 2
     self.logger.info("Attach volume to VM 2")
     self.cloud.attach_volume(self.vm2,
                              self.volume,
                              timeout=self.volume_timeout)
     # Check volume data
     read_data_script = pkg_resources.resource_filename(
         'functest.opnfv_tests.openstack.cinder', 'read_data.sh')
     try:
         scp = SCPClient(self.ssh2.get_transport())
         scp.put(read_data_script, remote_path="~/")
     except Exception:  # pylint: disable=broad-except
         self.logger.error("File not transfered!")
         return testcase.TestCase.EX_RUN_ERROR
     self.logger.debug("ssh: %s", self.ssh2)
     (_, stdout, stderr) = self.ssh2.exec_command(
         "sh ~/read_data.sh {}".format(env.get('VOLUME_DEVICE_NAME')))
     self.logger.debug("read volume stdout: %s",
                       stdout.read().decode("utf-8"))
     self.logger.debug("read volume stderr: %s",
                       stderr.read().decode("utf-8"))
     self.logger.info("Detach volume from VM 2")
     self.cloud.detach_volume(self.vm2,
                              self.volume,
                              timeout=self.volume_timeout)
     return stdout.channel.recv_exit_status()
Esempio n. 27
0
    def create_network_infrastructure(self, net_name, subnet_name, subnet_cidr,
                                      router_name):
        logger.info("Creating networks...")
        # Network and subnet
        subnet_settings = SubnetConfig(name=subnet_name, cidr=subnet_cidr)
        network_settings = NetworkConfig(name=net_name,
                                         subnet_settings=[subnet_settings])
        network_creator = OpenStackNetwork(self.os_creds, network_settings)
        network = network_creator.create()

        self.creators.append(network_creator)

        # Router
        logger.info("Creating the router...")
        ext_network_name = env.get('EXTERNAL_NETWORK')

        router_settings = RouterConfig(name=router_name,
                                       external_gateway=ext_network_name,
                                       internal_subnets=[subnet_name])

        router_creator = OpenStackRouter(self.os_creds, router_settings)
        router = router_creator.create()

        self.creators.append(router_creator)

        return network, router
Esempio n. 28
0
def configure_tempest_update_params(tempest_conf_file,
                                    network_name=None,
                                    image_id=None,
                                    flavor_id=None,
                                    compute_cnt=1,
                                    image_alt_id=None,
                                    flavor_alt_id=None):
    # pylint: disable=too-many-branches, too-many-arguments
    """
    Add/update needed parameters into tempest.conf file
    """
    LOGGER.debug("Updating selected tempest.conf parameters...")
    rconfig = ConfigParser.RawConfigParser()
    rconfig.read(tempest_conf_file)
    rconfig.set('compute', 'fixed_network_name', network_name)
    rconfig.set('compute', 'volume_device_name', env.get('VOLUME_DEVICE_NAME'))
    if image_id is not None:
        rconfig.set('compute', 'image_ref', image_id)
    if image_alt_id is not None:
        rconfig.set('compute', 'image_ref_alt', image_alt_id)
    if flavor_id is not None:
        rconfig.set('compute', 'flavor_ref', flavor_id)
    if flavor_alt_id is not None:
        rconfig.set('compute', 'flavor_ref_alt', flavor_alt_id)
    if compute_cnt > 1:
        # enable multinode tests
        rconfig.set('compute', 'min_compute_nodes', compute_cnt)
        rconfig.set('compute-feature-enabled', 'live_migration', True)

    rconfig.set('identity', 'region', os.environ.get('OS_REGION_NAME'))
    identity_api_version = os.environ.get("OS_IDENTITY_API_VERSION", '3')
    if identity_api_version == '3':
        auth_version = 'v3'
        rconfig.set('identity-feature-enabled', 'api_v2', False)
    else:
        auth_version = 'v2'
    rconfig.set('identity', 'auth_version', auth_version)
    rconfig.set('validation', 'ssh_timeout',
                getattr(config.CONF, 'tempest_validation_ssh_timeout'))
    rconfig.set('object-storage', 'operator_role',
                getattr(config.CONF, 'tempest_object_storage_operator_role'))

    rconfig.set('identity', 'v3_endpoint_type',
                os.environ.get('OS_INTERFACE', 'public'))

    sections = rconfig.sections()
    services_list = [
        'compute', 'volume', 'image', 'network', 'data-processing',
        'object-storage', 'orchestration'
    ]
    for service in services_list:
        if service not in sections:
            rconfig.add_section(service)
        rconfig.set(service, 'endpoint_type',
                    os.environ.get('OS_INTERFACE', 'public'))

    LOGGER.debug('Add/Update required params defined in tempest_conf.yaml '
                 'into tempest.conf file')
    update_tempest_conf_file(tempest_conf_file, rconfig)
Esempio n. 29
0
    def patch_file(self, patch_file_path):
        with open(patch_file_path) as yfile:
            patch_file = yaml.safe_load(yfile)

        for key in patch_file:
            if key in env.get('DEPLOY_SCENARIO'):
                self.functest_yaml = dict(
                    Config._merge_dicts(self.functest_yaml, patch_file[key]))
Esempio n. 30
0
    def show():
        install_type = env.get('INSTALLER_TYPE')
        scenario = env.get('DEPLOY_SCENARIO')
        node = env.get('NODE_NAME')
        build_tag = env.get('BUILD_TAG')
        if build_tag:
            build_tag = build_tag.lstrip("jenkins-").lstrip("functest").lstrip(
                "-")

        env_info = {
            'INSTALLER': install_type,
            'SCENARIO': scenario,
            'POD': node,
            'BUILD_TAG': build_tag
        }

        return env_info