Esempio n. 1
0
    def _prepare_env(self):
        logger.debug('Validating the test name...')
        if not (self.test_name in self.TESTS):
            raise Exception("Test name '%s' is invalid" % self.test_name)

        volume_types = os_utils.list_volume_types(self.cinder_client,
                                                  private=False)
        if volume_types:
            logger.debug("Using existing volume type(s)...")
        else:
            logger.debug('Creating volume type...')
            self.volume_type = os_utils.create_volume_type(
                self.cinder_client, self.CINDER_VOLUME_TYPE_NAME)
            if self.volume_type is None:
                raise Exception("Failed to create volume type '%s'" %
                                self.CINDER_VOLUME_TYPE_NAME)
            logger.debug("Volume type '%s' is created succesfully." %
                         self.CINDER_VOLUME_TYPE_NAME)

        logger.debug('Getting or creating image...')
        self.image_exists, self.image_id = os_utils.get_or_create_image(
            self.GLANCE_IMAGE_NAME, self.GLANCE_IMAGE_PATH,
            self.GLANCE_IMAGE_FORMAT)
        if self.image_id is None:
            raise Exception("Failed to get or create image '%s'" %
                            self.GLANCE_IMAGE_NAME)

        logger.debug("Creating network '%s'..." % self.RALLY_PRIVATE_NET_NAME)
        self.network_dict = os_utils.create_shared_network_full(
            self.RALLY_PRIVATE_NET_NAME, self.RALLY_PRIVATE_SUBNET_NAME,
            self.RALLY_ROUTER_NAME, self.RALLY_PRIVATE_SUBNET_CIDR)
        if self.network_dict is None:
            raise Exception("Failed to create shared network '%s'" %
                            self.RALLY_PRIVATE_NET_NAME)
Esempio n. 2
0
    def create_image(self):
        _, image_id = os_utils.get_or_create_image(self.image_name,
                                                   self.image_path,
                                                   self.image_format)
        if not image_id:
            return None

        return image_id
Esempio n. 3
0
    def create_tempest_resources(self):
        keystone_client = os_utils.get_keystone_client()

        logger.debug("Creating tenant and user for Tempest suite")
        tenant_id = os_utils.create_tenant(
            keystone_client,
            CONST.tempest_identity_tenant_name,
            CONST.tempest_identity_tenant_description)
        if not tenant_id:
            logger.error("Failed to create %s tenant"
                         % CONST.tempest_identity_tenant_name)

        user_id = os_utils.create_user(keystone_client,
                                       CONST.tempest_identity_user_name,
                                       CONST.tempest_identity_user_password,
                                       None, tenant_id)
        if not user_id:
            logger.error("Failed to create %s user" %
                         CONST.tempest_identity_user_name)

        logger.debug("Creating private network for Tempest suite")
        network_dic = os_utils.create_shared_network_full(
            CONST.tempest_private_net_name,
            CONST.tempest_private_subnet_name,
            CONST.tempest_router_name,
            CONST.tempest_private_subnet_cidr)
        if network_dic is None:
            raise Exception('Failed to create private network')

        if CONST.tempest_use_custom_images:
            # adding alternative image should be trivial should we need it
            logger.debug("Creating image for Tempest suite")
            _, self.IMAGE_ID = os_utils.get_or_create_image(
                CONST.openstack_image_name, conf_utils.GLANCE_IMAGE_PATH,
                CONST.openstack_image_disk_format)
            if self.IMAGE_ID is None:
                raise Exception('Failed to create image')

        if CONST.tempest_use_custom_flavors:
            # adding alternative flavor should be trivial should we need it
            logger.debug("Creating flavor for Tempest suite")
            _, self.FLAVOR_ID = os_utils.get_or_create_flavor(
                CONST.openstack_flavor_name,
                CONST.openstack_flavor_ram,
                CONST.openstack_flavor_disk,
                CONST.openstack_flavor_vcpus)
            if self.FLAVOR_ID is None:
                raise Exception('Failed to create flavor')
Esempio n. 4
0
def create_tempest_resources():
    keystone_client = os_utils.get_keystone_client()

    logger.debug("Creating tenant and user for Tempest suite")
    tenant_id = os_utils.create_tenant(keystone_client, TEMPEST_TENANT_NAME,
                                       TEMPEST_TENANT_DESCRIPTION)
    if not tenant_id:
        logger.error("Error : Failed to create %s tenant" %
                     TEMPEST_TENANT_NAME)

    user_id = os_utils.create_user(keystone_client, TEMPEST_USER_NAME,
                                   TEMPEST_USER_PASSWORD, None, tenant_id)
    if not user_id:
        logger.error("Error : Failed to create %s user" % TEMPEST_USER_NAME)

    logger.debug("Creating private network for Tempest suite")
    network_dic = \
        os_utils.create_shared_network_full(TEMPEST_PRIVATE_NET_NAME,
                                            TEMPEST_PRIVATE_SUBNET_NAME,
                                            TEMPEST_ROUTER_NAME,
                                            TEMPEST_PRIVATE_SUBNET_CIDR)
    if not network_dic:
        exit(1)

    if TEMPEST_USE_CUSTOM_IMAGES:
        # adding alternative image should be trivial should we need it
        logger.debug("Creating image for Tempest suite")
        _, GlobalVariables.IMAGE_ID = os_utils.get_or_create_image(
            GLANCE_IMAGE_NAME, GLANCE_IMAGE_PATH, GLANCE_IMAGE_FORMAT)
        if not GlobalVariables.IMAGE_ID:
            exit(-1)

    if TEMPEST_USE_CUSTOM_FLAVORS:
        # adding alternative flavor should be trivial should we need it
        logger.debug("Creating flavor for Tempest suite")
        _, GlobalVariables.FLAVOR_ID = os_utils.get_or_create_flavor(
            FLAVOR_NAME, FLAVOR_RAM, FLAVOR_DISK, FLAVOR_VCPUS)
        if not GlobalVariables.FLAVOR_ID:
            exit(-1)
Esempio n. 5
0
def create_tempest_resources(use_custom_images=False,
                             use_custom_flavors=False):
    keystone_client = os_utils.get_keystone_client()

    logger.debug("Creating tenant and user for Tempest suite")
    tenant_id = os_utils.create_tenant(
        keystone_client,
        CONST.__getattribute__('tempest_identity_tenant_name'),
        CONST.__getattribute__('tempest_identity_tenant_description'))
    if not tenant_id:
        logger.error("Failed to create %s tenant"
                     % CONST.__getattribute__('tempest_identity_tenant_name'))

    user_id = os_utils.create_user(
        keystone_client,
        CONST.__getattribute__('tempest_identity_user_name'),
        CONST.__getattribute__('tempest_identity_user_password'),
        None, tenant_id)
    if not user_id:
        logger.error("Failed to create %s user" %
                     CONST.__getattribute__('tempest_identity_user_name'))

    logger.debug("Creating private network for Tempest suite")
    network_dic = os_utils.create_shared_network_full(
        CONST.__getattribute__('tempest_private_net_name'),
        CONST.__getattribute__('tempest_private_subnet_name'),
        CONST.__getattribute__('tempest_router_name'),
        CONST.__getattribute__('tempest_private_subnet_cidr'))
    if network_dic is None:
        raise Exception('Failed to create private network')

    image_id = ""
    image_id_alt = ""
    flavor_id = ""
    flavor_id_alt = ""

    if (CONST.__getattribute__('tempest_use_custom_images') or
       use_custom_images):
        # adding alternative image should be trivial should we need it
        logger.debug("Creating image for Tempest suite")
        _, image_id = os_utils.get_or_create_image(
            CONST.__getattribute__('openstack_image_name'),
            GLANCE_IMAGE_PATH,
            CONST.__getattribute__('openstack_image_disk_format'))
        if image_id is None:
            raise Exception('Failed to create image')

    if use_custom_images:
        logger.debug("Creating 2nd image for Tempest suite")
        _, image_id_alt = os_utils.get_or_create_image(
            CONST.__getattribute__('openstack_image_name_alt'),
            GLANCE_IMAGE_PATH,
            CONST.__getattribute__('openstack_image_disk_format'))
        if image_id_alt is None:
            raise Exception('Failed to create image')

    if (CONST.__getattribute__('tempest_use_custom_flavors') or
       use_custom_flavors):
        # adding alternative flavor should be trivial should we need it
        logger.debug("Creating flavor for Tempest suite")
        _, flavor_id = os_utils.get_or_create_flavor(
            CONST.__getattribute__('openstack_flavor_name'),
            CONST.__getattribute__('openstack_flavor_ram'),
            CONST.__getattribute__('openstack_flavor_disk'),
            CONST.__getattribute__('openstack_flavor_vcpus'))
        if flavor_id is None:
            raise Exception('Failed to create flavor')

    if use_custom_flavors:
        logger.debug("Creating 2nd flavor for tempest_defcore")
        _, flavor_id_alt = os_utils.get_or_create_flavor(
            CONST.__getattribute__('openstack_flavor_name_alt'),
            CONST.__getattribute__('openstack_flavor_ram'),
            CONST.__getattribute__('openstack_flavor_disk'),
            CONST.__getattribute__('openstack_flavor_vcpus'))
        if flavor_id_alt is None:
            raise Exception('Failed to create flavor')

    img_flavor_dict = {}
    img_flavor_dict['image_id'] = image_id
    img_flavor_dict['image_id_alt'] = image_id_alt
    img_flavor_dict['flavor_id'] = flavor_id
    img_flavor_dict['flavor_id_alt'] = flavor_id_alt

    return img_flavor_dict
Esempio n. 6
0
def main():

    GlobalVariables.nova_client = os_utils.get_nova_client()
    GlobalVariables.neutron_client = os_utils.get_neutron_client()
    cinder_client = os_utils.get_cinder_client()

    start_time = time.time()

    # configure script
    if not (args.test_name in tests):
        logger.error('argument not valid')
        exit(-1)

    GlobalVariables.SUMMARY = []

    volume_types = os_utils.list_volume_types(cinder_client, private=False)
    if not volume_types:
        volume_type = os_utils.create_volume_type(cinder_client,
                                                  CINDER_VOLUME_TYPE_NAME)
        if not volume_type:
            logger.error("Failed to create volume type...")
            exit(-1)
        else:
            logger.debug("Volume type '%s' created succesfully..." %
                         CINDER_VOLUME_TYPE_NAME)
    else:
        logger.debug("Using existing volume type(s)...")

    image_exists, image_id = os_utils.get_or_create_image(
        GLANCE_IMAGE_NAME, GLANCE_IMAGE_PATH, GLANCE_IMAGE_FORMAT)
    if not image_id:
        exit(-1)

    logger.debug("Creating network '%s'..." % RALLY_PRIVATE_NET_NAME)
    GlobalVariables.network_dict = \
        os_utils.create_shared_network_full(RALLY_PRIVATE_NET_NAME,
                                            RALLY_PRIVATE_SUBNET_NAME,
                                            RALLY_ROUTER_NAME,
                                            RALLY_PRIVATE_SUBNET_CIDR)
    if not GlobalVariables.network_dict:
        exit(1)

    if args.test_name == "all":
        for test_name in tests:
            if not (test_name == 'all' or test_name == 'vm'):
                run_task(test_name)
    else:
        logger.debug("Test name: " + args.test_name)
        run_task(args.test_name)

    report = ("\n"
              "                                                              "
              "\n"
              "                     Rally Summary Report\n"
              "\n"
              "+===================+============+===============+===========+"
              "\n"
              "| Module            | Duration   | nb. Test Run  | Success   |"
              "\n"
              "+===================+============+===============+===========+"
              "\n")
    payload = []
    stop_time = time.time()

    # for each scenario we draw a row for the table
    total_duration = 0.0
    total_nb_tests = 0
    total_success = 0.0
    for s in GlobalVariables.SUMMARY:
        name = "{0:<17}".format(s['test_name'])
        duration = float(s['overall_duration'])
        total_duration += duration
        duration = time.strftime("%M:%S", time.gmtime(duration))
        duration = "{0:<10}".format(duration)
        nb_tests = "{0:<13}".format(s['nb_tests'])
        total_nb_tests += int(s['nb_tests'])
        success = "{0:<10}".format(str(s['success']) + '%')
        total_success += float(s['success'])
        report += ("" + "| " + name + " | " + duration + " | " + nb_tests +
                   " | " + success + "|\n" +
                   "+-------------------+------------"
                   "+---------------+-----------+\n")
        payload.append({
            'module': name,
            'details': {
                'duration': s['overall_duration'],
                'nb tests': s['nb_tests'],
                'success': s['success']
            }
        })

    total_duration_str = time.strftime("%H:%M:%S", time.gmtime(total_duration))
    total_duration_str2 = "{0:<10}".format(total_duration_str)
    total_nb_tests_str = "{0:<13}".format(total_nb_tests)

    if len(GlobalVariables.SUMMARY):
        success_rate = total_success / len(GlobalVariables.SUMMARY)
    else:
        success_rate = 100
    success_rate = "{:0.2f}".format(success_rate)
    success_rate_str = "{0:<10}".format(str(success_rate) + '%')
    report += "+===================+============+===============+===========+"
    report += "\n"
    report += ("| TOTAL:            | " + total_duration_str2 + " | " +
               total_nb_tests_str + " | " + success_rate_str + "|\n")
    report += "+===================+============+===============+===========+"
    report += "\n"

    logger.info("\n" + report)
    payload.append({
        'summary': {
            'duration': total_duration,
            'nb tests': total_nb_tests,
            'nb success': success_rate
        }
    })

    if args.sanity:
        case_name = "rally_sanity"
    else:
        case_name = "rally_full"

    # Evaluation of the success criteria
    status = ft_utils.check_success_rate(case_name, success_rate)

    exit_code = -1
    if status == "PASS":
        exit_code = 0

    if args.report:
        logger.debug("Pushing Rally summary into DB...")
        ft_utils.push_results_to_db("functest", case_name, start_time,
                                    stop_time, status, payload)
    if args.noclean:
        exit(exit_code)

    if not image_exists:
        logger.debug("Deleting image '%s' with ID '%s'..." %
                     (GLANCE_IMAGE_NAME, image_id))
        if not os_utils.delete_glance_image(GlobalVariables.nova_client,
                                            image_id):
            logger.error("Error deleting the glance image")

    if not volume_types:
        logger.debug("Deleting volume type '%s'..." % CINDER_VOLUME_TYPE_NAME)
        if not os_utils.delete_volume_type(cinder_client, volume_type):
            logger.error("Error in deleting volume type...")

    exit(exit_code)