Beispiel #1
0
def main():
    logger.info("Generating OpenStack snapshot...")

    nova_client = os_utils.get_nova_client()
    neutron_client = os_utils.get_neutron_client()
    keystone_client = os_utils.get_keystone_client()
    cinder_client = os_utils.get_cinder_client()

    if not os_utils.check_credentials():
        logger.error("Please source the openrc credentials and run the" +
                     "script again.")
        exit(-1)

    snapshot = {}
    snapshot.update(get_instances(nova_client))
    snapshot.update(get_images(nova_client))
    snapshot.update(get_volumes(cinder_client))
    snapshot.update(get_networks(neutron_client))
    snapshot.update(get_routers(neutron_client))
    snapshot.update(get_security_groups(neutron_client))
    snapshot.update(get_floatinips(nova_client))
    snapshot.update(get_users(keystone_client))
    snapshot.update(get_tenants(keystone_client))

    with open(OS_SNAPSHOT_FILE, 'w+') as yaml_file:
        yaml_file.write(yaml.safe_dump(snapshot, default_flow_style=False))
        yaml_file.seek(0)
        logger.debug("Openstack Snapshot found in the deployment:\n%s" %
                     yaml_file.read())
        logger.debug("NOTE: These objects will NOT be deleted after " +
                     "running the test.")
Beispiel #2
0
 def __init__(self, case_name=''):
     super(RallyBase, self).__init__(case_name)
     self.mode = ''
     self.summary = []
     self.scenario_dir = ''
     self.nova_client = os_utils.get_nova_client()
     self.neutron_client = os_utils.get_neutron_client()
     self.cinder_client = os_utils.get_cinder_client()
     self.network_dict = {}
     self.volume_type = None
     self.smoke = None
Beispiel #3
0
def main():
    logging.basicConfig()
    logger.info("Cleaning OpenStack resources...")

    nova_client = os_utils.get_nova_client()
    neutron_client = os_utils.get_neutron_client()
    keystone_client = os_utils.get_keystone_client()
    cinder_client = os_utils.get_cinder_client()
    glance_client = os_utils.get_glance_client()

    try:
        with open(OS_SNAPSHOT_FILE) as f:
            snapshot_yaml = yaml.safe_load(f)
    except Exception:
        logger.info("The file %s does not exist. The OpenStack snapshot must"
                    " be created first. Aborting cleanup." % OS_SNAPSHOT_FILE)
        return 0

    default_images = snapshot_yaml.get('images')
    default_instances = snapshot_yaml.get('instances')
    default_volumes = snapshot_yaml.get('volumes')
    default_networks = snapshot_yaml.get('networks')
    default_routers = snapshot_yaml.get('routers')
    default_security_groups = snapshot_yaml.get('secgroups')
    default_floatingips = snapshot_yaml.get('floatingips')
    default_users = snapshot_yaml.get('users')
    default_tenants = snapshot_yaml.get('tenants')

    if not os_utils.check_credentials():
        logger.error("Please source the openrc credentials and run "
                     "the script again.")
        return -1

    remove_instances(nova_client, default_instances)
    separator()
    remove_images(glance_client, default_images)
    separator()
    remove_volumes(cinder_client, default_volumes)
    separator()
    remove_floatingips(neutron_client, default_floatingips)
    separator()
    remove_networks(neutron_client, default_networks, default_routers)
    separator()
    remove_security_groups(neutron_client, default_security_groups)
    separator()
    remove_users(keystone_client, default_users)
    separator()
    remove_tenants(keystone_client, default_tenants)
    separator()
    return 0
Beispiel #4
0
 def __init__(self, **kwargs):
     """Initialize RallyBase object."""
     super(RallyBase, self).__init__(**kwargs)
     self.mode = ''
     self.summary = []
     self.scenario_dir = ''
     self.nova_client = os_utils.get_nova_client()
     self.neutron_client = os_utils.get_neutron_client()
     self.cinder_client = os_utils.get_cinder_client()
     self.network_dict = {}
     self.volume_type = None
     self.smoke = None
     self.test_name = None
     self.image_exists = None
     self.image_id = None
     self.start_time = None
     self.result = None
     self.details = None
Beispiel #5
0
def main():
    logger.info("Cleaning OpenStack resources...")

    nova_client = os_utils.get_nova_client()
    neutron_client = os_utils.get_neutron_client()
    keystone_client = os_utils.get_keystone_client()
    cinder_client = os_utils.get_cinder_client()
    tacker_client = os_tacker.get_tacker_client()

    try:
        with open(OS_SNAPSHOT_FILE) as f:
            snapshot_yaml = yaml.safe_load(f)
    except Exception:
        logger.info("The file %s does not exist. The OpenStack snapshot must"
                    " be created first. Aborting cleanup." % OS_SNAPSHOT_FILE)
        exit(0)

    default_images = snapshot_yaml.get('images')
    default_instances = snapshot_yaml.get('instances')
    default_volumes = snapshot_yaml.get('volumes')
    default_networks = snapshot_yaml.get('networks')
    default_routers = snapshot_yaml.get('routers')
    default_security_groups = snapshot_yaml.get('secgroups')
    default_floatingips = snapshot_yaml.get('floatingips')
    default_users = snapshot_yaml.get('users')
    default_tenants = snapshot_yaml.get('tenants')
    default_vnfds = snapshot_yaml.get('vnfds')
    default_vnfs = snapshot_yaml.get('vnfs')
    default_sfcs = snapshot_yaml.get('sfcs')
    default_sfc_classifiers = snapshot_yaml.get('sfc_classifiers')

    if not os_utils.check_credentials():
        logger.error("Please source the openrc credentials and run "
                     "the script again.")
        exit(-1)

    remove_instances(nova_client, default_instances)
    separator()
    remove_images(nova_client, default_images)
    separator()
    remove_volumes(cinder_client, default_volumes)
    separator()
    remove_floatingips(nova_client, default_floatingips)
    separator()
    remove_networks(neutron_client, default_networks, default_routers)
    separator()
    remove_security_groups(neutron_client, default_security_groups)
    separator()
    remove_users(keystone_client, default_users)
    separator()
    remove_tenants(keystone_client, default_tenants)
    separator()
    # Note: Delete in this order
    # 1. Classifiers, 2. SFCs, 3. VNFs, 4. VNFDs
    remove_tacker_sfc_classifiers(tacker_client, default_sfc_classifiers)
    separator()
    remove_tacker_sfcs(tacker_client, default_sfcs)
    separator()
    remove_tacker_vnfs(tacker_client, default_vnfs)
    separator()
    remove_tacker_vnfds(tacker_client, default_vnfds)
    separator()
Beispiel #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)