Exemple #1
0
def create_tempest_resources():
    ks_creds = os_utils.get_credentials("keystone")
    logger.debug("Creating tenant and user for Tempest suite")
    keystone = ksclient.Client(**ks_creds)
    tenant_id = os_utils.create_tenant(keystone,
                                       TENANT_NAME,
                                       TENANT_DESCRIPTION)
    if tenant_id == '':
        logger.error("Error : Failed to create %s tenant" % TENANT_NAME)

    user_id = os_utils.create_user(keystone, USER_NAME, USER_PASSWORD,
                                   None, tenant_id)
    if user_id == '':
        logger.error("Error : Failed to create %s user" % USER_NAME)

    logger.debug("Creating private network for Tempest suite")
    creds_neutron = os_utils.get_credentials("neutron")
    neutron_client = neutronclient.Client(**creds_neutron)
    network_dic = os_utils.create_network_full(logger,
                                               neutron_client,
                                               PRIVATE_NET_NAME,
                                               PRIVATE_SUBNET_NAME,
                                               ROUTER_NAME,
                                               PRIVATE_SUBNET_CIDR)
    if network_dic:
        if not os_utils.update_neutron_net(neutron_client,
                                           network_dic['net_id'],
                                           shared=True):
            logger.error("Failed to update private network...")
            exit(-1)
        else:
            logger.debug("Network '%s' is available..." % PRIVATE_NET_NAME)
    else:
        logger.error("Private network creation failed")
        exit(-1)

    logger.debug("Creating image for Tempest suite")
    glance_endpoint = keystone.service_catalog.url_for(
        service_type='image', endpoint_type='publicURL')
    glance_client = glanceclient.Client(1, glance_endpoint,
                                        token=keystone.auth_token)
    # Check if the given image exists
    image_id = os_utils.get_image_id(glance_client, GLANCE_IMAGE_NAME)
    if image_id != '':
        logger.info("Using existing image '%s'..." % GLANCE_IMAGE_NAME)
    else:
        logger.info("Creating image '%s' from '%s'..." % (GLANCE_IMAGE_NAME,
                                                          GLANCE_IMAGE_PATH))
        image_id = os_utils.create_glance_image(glance_client,
                                                GLANCE_IMAGE_NAME,
                                                GLANCE_IMAGE_PATH)
        if not image_id:
            logger.error("Failed to create a Glance image...")
            exit(-1)
        logger.debug("Image '%s' with ID=%s created successfully."
                     % (GLANCE_IMAGE_NAME, image_id))
Exemple #2
0
    def prepare(self):
        self.creds = os_utils.get_credentials()
        self.keystone_client = os_utils.get_keystone_client()

        self.logger.info("Prepare OpenStack plateform(create tenant and user)")
        admin_user_id = os_utils.get_user_id(self.keystone_client,
                                             self.creds['username'])
        if admin_user_id == '':
            self.step_failure("Failed to get id of " + self.creds['username'])

        tenant_id = os_utils.create_tenant(self.keystone_client,
                                           self.tenant_name,
                                           self.tenant_description)
        if not tenant_id:
            self.step_failure("Failed to create " + self.tenant_name +
                              " tenant")

        roles_name = ["admin", "Admin"]
        role_id = ''
        for role_name in roles_name:
            if role_id == '':
                role_id = os_utils.get_role_id(self.keystone_client, role_name)

        if role_id == '':
            self.logger.error("Failed to get id for %s role" % role_name)
            self.step_failure("Failed to get role id of " + role_name)

        if not os_utils.add_role_user(self.keystone_client, admin_user_id,
                                      role_id, tenant_id):
            self.logger.error("Failed to add %s on tenant" %
                              self.creds['username'])
            self.step_failure("Failed to add %s on tenant" %
                              self.creds['username'])

        user_id = os_utils.create_user(self.keystone_client, self.tenant_name,
                                       self.tenant_name, None, tenant_id)
        if not user_id:
            self.logger.error("Failed to create %s user" % self.tenant_name)
            self.step_failure("Failed to create user ")

        if not os_utils.add_role_user(self.keystone_client, user_id, role_id,
                                      tenant_id):
            self.logger.error("Failed to add %s on tenant" % self.tenant_name)
            self.step_failure("Failed to add %s on tenant" % self.tenant_name)

        self.logger.info("Update OpenStack creds informations")
        self.admin_creds = self.creds.copy()
        self.admin_creds.update({"tenant": self.tenant_name})
        self.neutron_client = os_utils.get_neutron_client(self.admin_creds)
        self.nova_client = os_utils.get_nova_client(self.admin_creds)
        self.creds.update({
            "tenant": self.tenant_name,
            "username": self.tenant_name,
            "password": self.tenant_name,
        })
Exemple #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')
Exemple #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)
Exemple #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
Exemple #6
0
def main():

    # ############### GENERAL INITIALISATION ################

    if not os.path.exists(vHello_DATA_DIR):
        os.makedirs(vHello_DATA_DIR)

    ks_creds = os_utils.get_credentials("keystone")
    nv_creds = os_utils.get_credentials("nova")
    nt_creds = os_utils.get_credentials("neutron")

    logger.info("Prepare OpenStack plateform (create tenant and user)")
    keystone = ksclient.Client(**ks_creds)

    user_id = os_utils.get_user_id(keystone, ks_creds['username'])
    if user_id == '':
        step_failure("init", "Error : Failed to get id of " +
                     ks_creds['username'])

    tenant_id = os_utils.create_tenant(
        keystone, TENANT_NAME, TENANT_DESCRIPTION)
    if tenant_id == '':
        step_failure("init", "Error : Failed to create " +
                     TENANT_NAME + " tenant")

    roles_name = ["admin", "Admin"]
    role_id = ''
    for role_name in roles_name:
        if role_id == '':
            role_id = os_utils.get_role_id(keystone, role_name)

    if role_id == '':
        logger.error("Error : Failed to get id for %s role" % role_name)

    if not os_utils.add_role_user(keystone, user_id, role_id, tenant_id):
        logger.error("Error : Failed to add %s on tenant" %
                     ks_creds['username'])

    user_id = os_utils.create_user(
        keystone, TENANT_NAME, TENANT_NAME, None, tenant_id)
    if user_id == '':
        logger.error("Error : Failed to create %s user" % TENANT_NAME)

    logger.info("Update OpenStack creds informations")
    ks_creds.update({
        "username": TENANT_NAME,
        "password": TENANT_NAME,
        "tenant_name": TENANT_NAME,
    })

    nt_creds.update({
        "tenant_name": TENANT_NAME,
    })

    nv_creds.update({
        "project_id": TENANT_NAME,
    })

    logger.info("Upload some OS images if it doesn't exist")
    glance_endpoint = keystone.service_catalog.url_for(
        service_type='image', endpoint_type='publicURL')
    glance = glclient.Client(1, glance_endpoint, token=keystone.auth_token)

    for img in IMAGES.keys():
        image_name = IMAGES[img]['image_name']
        image_url = IMAGES[img]['image_url']

        image_id = os_utils.get_image_id(glance, image_name)

        if image_id == '':
            logger.info("""%s image doesn't exist on glance repository. Try
            downloading this image and upload on glance !""" % image_name)
            image_id = download_and_add_image_on_glance(
                glance, image_name, image_url)

        if image_id == '':
            step_failure(
                "init",
                "Error : Failed to find or upload required OS "
                "image for this deployment")

    nova = nvclient.Client("2", **nv_creds)

    logger.info("Update security group quota for this tenant")
    neutron = ntclient.Client(**nt_creds)
    if not os_utils.update_sg_quota(neutron, tenant_id, 50, 100):
        step_failure(
            "init",
            "Failed to update security group quota for tenant " + TENANT_NAME)

    logger.info("Update cinder quota for this tenant")
    from cinderclient import client as cinderclient

    creds_cinder = os_utils.get_credentials("cinder")
    cinder_client = cinderclient.Client('1', creds_cinder['username'],
                                        creds_cinder['api_key'],
                                        creds_cinder['project_id'],
                                        creds_cinder['auth_url'],
                                        service_type="volume")
    if not os_utils.update_cinder_quota(cinder_client, tenant_id, 20, 10, 150):
        step_failure(
            "init", "Failed to update cinder quota for tenant " + TENANT_NAME)

    # ############### CLOUDIFY INITIALISATION ################

    cfy = orchestrator(vHello_DATA_DIR, CFY_INPUTS, logger)

    cfy.set_credentials(username=ks_creds['username'], password=ks_creds[
                        'password'], tenant_name=ks_creds['tenant_name'],
                        auth_url=ks_creds['auth_url'])

    logger.info("Collect flavor id for cloudify manager server")
    nova = nvclient.Client("2", **nv_creds)

    flavor_name = "m1.medium"
    flavor_id = os_utils.get_flavor_id(nova, flavor_name)
    for requirement in CFY_MANAGER_REQUIERMENTS:
        if requirement == 'ram_min':
            flavor_id = os_utils.get_flavor_id_by_ram_range(
                nova, CFY_MANAGER_REQUIERMENTS['ram_min'], 8196)

    if flavor_id == '':
        logger.error(
            "Failed to find %s flavor. "
            "Try with ram range default requirement !" % flavor_name)
        flavor_id = os_utils.get_flavor_id_by_ram_range(nova, 4000, 8196)

    if flavor_id == '':
        step_failure("orchestrator",
                     "Failed to find required flavor for this deployment")

    cfy.set_flavor_id(flavor_id)

    image_name = "centos_7"
    image_id = os_utils.get_image_id(glance, image_name)
    for requirement in CFY_MANAGER_REQUIERMENTS:
        if requirement == 'os_image':
            image_id = os_utils.get_image_id(
                glance, CFY_MANAGER_REQUIERMENTS['os_image'])

    if image_id == '':
        step_failure(
            "orchestrator",
            "Error : Failed to find required OS image for cloudify manager")

    cfy.set_image_id(image_id)

    ext_net = os_utils.get_external_net(neutron)
    if not ext_net:
        step_failure("orchestrator", "Failed to get external network")

    cfy.set_external_network_name(ext_net)

    ns = functest_utils.get_resolvconf_ns()
    if ns:
        cfy.set_nameservers(ns)

    logger.info("Prepare virtualenv for cloudify-cli")
    cmd = "chmod +x " + vHello_DIR + "create_venv.sh"
    functest_utils.execute_command(cmd, logger)
    time.sleep(3)
    cmd = vHello_DIR + "create_venv.sh " + vHello_DATA_DIR
    functest_utils.execute_command(cmd, logger)

    cfy.download_manager_blueprint(
        CFY_MANAGER_BLUEPRINT['url'], CFY_MANAGER_BLUEPRINT['branch'])

    # ############### CLOUDIFY DEPLOYMENT ################
    start_time_ts = time.time()
    end_time_ts = start_time_ts
    logger.info("Cloudify deployment Start Time:'%s'" % (
        datetime.datetime.fromtimestamp(start_time_ts).strftime(
            '%Y-%m-%d %H:%M:%S')))

    error = cfy.deploy_manager()
    if error:
        step_failure("orchestrator", error)

    end_time_ts = time.time()
    duration = round(end_time_ts - start_time_ts, 1)
    logger.info("Cloudify deployment duration:'%s'" % duration)
    set_result("orchestrator", duration, "")

    # ############### helloworld INITIALISATION ################

    cw = helloworld(CW_INPUTS, cfy, logger)

    logger.info("Collect flavor id for all helloworld vm")
    nova = nvclient.Client("2", **nv_creds)

    flavor_name = "m1.small"
    flavor_id = os_utils.get_flavor_id(nova, flavor_name)
    for requirement in CW_REQUIERMENTS:
        if requirement == 'ram_min':
            flavor_id = os_utils.get_flavor_id_by_ram_range(
                nova, CW_REQUIERMENTS['ram_min'], 8196)

    if flavor_id == '':
        logger.error(
            "Failed to find %s flavor. Try with ram range "
            "default requirement !" % flavor_name)
        flavor_id = os_utils.get_flavor_id_by_ram_range(nova, 4000, 8196)

    if flavor_id == '':
        step_failure(
            "vHello", "Failed to find required flavor for this deployment")

    cw.set_flavor_id(flavor_id)

    image_name = "ubuntu_14.04"
    image_id = os_utils.get_image_id(glance, image_name)
    for requirement in CW_REQUIERMENTS:
        if requirement == 'os_image':
            image_id = os_utils.get_image_id(
                glance, CW_REQUIERMENTS['os_image'])

    if image_id == '':
        step_failure(
            "vHello",
            "Error : Failed to find required OS image for cloudify manager")

    cw.set_image_id(image_id)

    ext_net = os_utils.get_external_net(neutron)
    if not ext_net:
        step_failure("vHello", "Failed to get external network")

    cw.set_external_network_name(ext_net)

    # ############### helloworld DEPLOYMENT ################

    start_time_ts = time.time()
    end_time_ts = start_time_ts
    logger.info("vHello VNF deployment Start Time:'%s'" % (
        datetime.datetime.fromtimestamp(start_time_ts).strftime(
            '%Y-%m-%d %H:%M:%S')))

    error = cw.deploy_vnf(CW_BLUEPRINT)
    if error:
        step_failure("vHello", error)

    end_time_ts = time.time()
    duration = round(end_time_ts - start_time_ts, 1)
    logger.info("vHello VNF deployment duration:'%s'" % duration)
    set_result("vHello", duration, "")
    def init(self):

        start_time_ts = time.time()

        self.util = utilvnf(self.logger)

        self.ks_cresds = os_utils.get_credentials()

        self.logger.info("Prepare OpenStack plateform(create tenant and user)")
        keystone = os_utils.get_keystone_client()

        user_id = os_utils.get_user_id(keystone, self.ks_cresds['username'])

        if user_id == '':
            return self.step_failure(
                "init",
                "Error : Failed to get id of " + self.ks_cresds['username'])

        tenant_id = os_utils.create_tenant(keystone, TENANT_NAME,
                                           TENANT_DESCRIPTION)

        if tenant_id == '':
            return self.step_failure(
                "init", "Error : Failed to create " + TENANT_NAME + " tenant")
        roles_name = ["admin", "Admin"]
        role_id = ''
        for role_name in roles_name:
            if role_id == '':
                role_id = os_utils.get_role_id(keystone, role_name)

        if role_id == '':
            self.logger.error("Error : Failed to get id for %s role" %
                              role_name)

        if not os_utils.add_role_user(keystone, user_id, role_id, tenant_id):

            self.logger.error("Error : Failed to add %s on tenant" %
                              self.ks_cresds['username'])

        user_id = os_utils.create_user(keystone, TENANT_NAME, TENANT_NAME,
                                       None, tenant_id)
        if user_id == '':
            self.logger.error("Error : Failed to create %s user" % TENANT_NAME)

        if not os_utils.add_role_user(keystone, user_id, role_id, tenant_id):

            self.logger.error("Failed to add %s on tenant" % TENANT_NAME)

        self.logger.info("Update OpenStack creds informations")

        self.ks_cresds.update({
            "tenant_name": TENANT_NAME,
        })

        self.neutron = os_utils.get_neutron_client(self.ks_cresds)
        nova = os_utils.get_nova_client()
        self.glance = os_utils.get_glance_client(self.ks_cresds)

        self.ks_cresds.update({
            "username": TENANT_NAME,
            "password": TENANT_NAME,
        })

        self.load_test_env_config()

        self.logger.info("Upload some OS images if it doesn't exist")
        images = {}
        images.update(IMAGES)
        images.update(self.VNF_TEST_IMAGES)
        for img in images.keys():
            image_name = images[img]['image_name']
            self.logger.info("image name = " + image_name)
            image_url = images[img]['image_url']

            image_id = os_utils.get_image_id(self.glance, image_name)

            if image_id == '':
                self.logger.info(
                    """%s image doesn't exist on glance repository. Try
                downloading this image and upload on glance !""" % image_name)
                image_id = self.download_and_add_image_on_glance(
                    self.glance, image_name, image_url)

            if image_id == '':
                return self.step_failure(
                    "init", "Error : Failed to find or upload required OS "
                    "image for this deployment")

        self.logger.info("Update security group quota for this tenant")

        result = os_utils.update_sg_quota(self.neutron, tenant_id, 50, 100)

        if not result:
            return self.step_failure(
                "init", "Failed to update security group quota for tenant " +
                TENANT_NAME)

        self.credentials = {
            "username": TENANT_NAME,
            "password": TENANT_NAME,
            "auth_url": os_utils.get_endpoint('identity'),
            "tenant_name": TENANT_NAME,
            "region_name": os.environ['OS_REGION_NAME']
        }

        self.util.set_credentials(self.credentials["username"],
                                  self.credentials["password"],
                                  self.credentials["auth_url"],
                                  self.credentials["tenant_name"],
                                  self.credentials["region_name"])

        test_scenario_file = open(self.util.TEST_SCENATIO_YAML_FILE, 'r')
        self.test_scenario_yaml = yaml.safe_load(test_scenario_file)
        test_scenario_file.close()

        res = self.util.test_scenario_validation_check(self.test_scenario_yaml)
        if res["status"] is False:
            self.logger.error(res["message"])
            return self.step_failure("init",
                                     "Error : Faild to test execution.")

        self.logger.info("Test scenario yaml validation check : " +
                         res["message"])

        end_time_ts = time.time()
        duration = round(end_time_ts - start_time_ts, 1)

        self.set_result("init", duration, "OK")

        return self.set_resultdata(self.testcase_start_time, "", "",
                                   self.results)
Exemple #8
0
def main():
    exit_code = -1
    start_time = time.time()
    ks_creds = openstack_utils.get_credentials("keystone")
    nv_creds = openstack_utils.get_credentials("nova")
    nt_creds = openstack_utils.get_credentials("neutron")

    keystone = ksclient.Client(**ks_creds)

    user_id = openstack_utils.get_user_id(keystone, ks_creds['username'])
    if user_id == '':
        logger.error("Error : Failed to get id of %s user" %
                     ks_creds['username'])
        exit(-1)

    logger.info("Creating tenant '%s'..." % PROMISE_TENANT_NAME)
    tenant_id = openstack_utils.create_tenant(keystone, PROMISE_TENANT_NAME,
                                              TENANT_DESCRIPTION)
    if not tenant_id:
        logger.error("Error : Failed to create %s tenant" %
                     PROMISE_TENANT_NAME)
        exit(-1)
    logger.debug("Tenant '%s' created successfully." % PROMISE_TENANT_NAME)

    roles_name = ["admin", "Admin"]
    role_id = ''
    for role_name in roles_name:
        if role_id == '':
            role_id = openstack_utils.get_role_id(keystone, role_name)

    if role_id == '':
        logger.error("Error : Failed to get id for %s role" % role_name)
        exit(-1)

    logger.info("Adding role '%s' to tenant '%s'..." %
                (role_id, PROMISE_TENANT_NAME))
    if not openstack_utils.add_role_user(keystone, user_id, role_id,
                                         tenant_id):
        logger.error("Error : Failed to add %s on tenant %s" %
                     (ks_creds['username'], PROMISE_TENANT_NAME))
        exit(-1)
    logger.debug("Role added successfully.")

    logger.info("Creating user '%s'..." % PROMISE_USER_NAME)
    user_id = openstack_utils.create_user(keystone, PROMISE_USER_NAME,
                                          PROMISE_USER_PWD, None, tenant_id)

    if not user_id:
        logger.error("Error : Failed to create %s user" % PROMISE_USER_NAME)
        exit(-1)
    logger.debug("User '%s' created successfully." % PROMISE_USER_NAME)

    logger.info("Updating OpenStack credentials...")
    ks_creds.update({
        "username": PROMISE_TENANT_NAME,
        "password": PROMISE_TENANT_NAME,
        "tenant_name": PROMISE_TENANT_NAME,
    })

    nt_creds.update({
        "tenant_name": PROMISE_TENANT_NAME,
    })

    nv_creds.update({
        "project_id": PROMISE_TENANT_NAME,
    })

    glance = openstack_utils.get_glance_client()
    nova = nvclient.Client("2", **nv_creds)

    logger.info("Creating image '%s' from '%s'..." %
                (PROMISE_IMAGE_NAME, GLANCE_IMAGE_PATH))
    image_id = openstack_utils.create_glance_image(glance, PROMISE_IMAGE_NAME,
                                                   GLANCE_IMAGE_PATH)
    if not image_id:
        logger.error("Failed to create the Glance image...")
        exit(-1)
    logger.debug("Image '%s' with ID '%s' created successfully." %
                 (PROMISE_IMAGE_NAME, image_id))
    flavor_id = openstack_utils.get_flavor_id(nova, PROMISE_FLAVOR_NAME)
    if flavor_id == '':
        logger.info("Creating flavor '%s'..." % PROMISE_FLAVOR_NAME)
        flavor_id = openstack_utils.create_flavor(nova, PROMISE_FLAVOR_NAME,
                                                  PROMISE_FLAVOR_RAM,
                                                  PROMISE_FLAVOR_DISK,
                                                  PROMISE_FLAVOR_VCPUS)
        if not flavor_id:
            logger.error("Failed to create the Flavor...")
            exit(-1)
        logger.debug("Flavor '%s' with ID '%s' created successfully." %
                     (PROMISE_FLAVOR_NAME, flavor_id))
    else:
        logger.debug("Using existing flavor '%s' with ID '%s'..." %
                     (PROMISE_FLAVOR_NAME, flavor_id))

    neutron = ntclient.Client(**nt_creds)

    network_dic = openstack_utils.create_network_full(neutron,
                                                      PROMISE_NET_NAME,
                                                      PROMISE_SUBNET_NAME,
                                                      PROMISE_ROUTER_NAME,
                                                      PROMISE_SUBNET_CIDR)
    if not network_dic:
        logger.error("Failed to create the private network...")
        exit(-1)

    logger.info("Exporting environment variables...")
    os.environ["NODE_ENV"] = "functest"
    os.environ["OS_PASSWORD"] = PROMISE_USER_PWD
    os.environ["OS_TEST_IMAGE"] = image_id
    os.environ["OS_TEST_FLAVOR"] = flavor_id
    os.environ["OS_TEST_NETWORK"] = network_dic["net_id"]
    os.environ["OS_TENANT_NAME"] = PROMISE_TENANT_NAME
    os.environ["OS_USERNAME"] = PROMISE_USER_NAME

    os.chdir(PROMISE_REPO_DIR + '/source/')
    results_file_name = os.path.join(RESULTS_DIR, 'promise-results.json')
    results_file = open(results_file_name, 'w+')
    cmd = 'npm run -s test -- --reporter json'

    logger.info("Running command: %s" % cmd)
    ret = subprocess.call(cmd,
                          shell=True,
                          stdout=results_file,
                          stderr=subprocess.STDOUT)
    results_file.close()

    if ret == 0:
        logger.info("The test succeeded.")
        # test_status = 'OK'
    else:
        logger.info("The command '%s' failed." % cmd)
        # test_status = "Failed"

    # Print output of file
    with open(results_file_name, 'r') as results_file:
        data = results_file.read()
        logger.debug("\n%s" % data)
        json_data = json.loads(data)

        suites = json_data["stats"]["suites"]
        tests = json_data["stats"]["tests"]
        passes = json_data["stats"]["passes"]
        pending = json_data["stats"]["pending"]
        failures = json_data["stats"]["failures"]
        start_time_json = json_data["stats"]["start"]
        end_time = json_data["stats"]["end"]
        duration = float(json_data["stats"]["duration"]) / float(1000)

    logger.info("\n"
                "****************************************\n"
                "          Promise test report\n\n"
                "****************************************\n"
                " Suites:  \t%s\n"
                " Tests:   \t%s\n"
                " Passes:  \t%s\n"
                " Pending: \t%s\n"
                " Failures:\t%s\n"
                " Start:   \t%s\n"
                " End:     \t%s\n"
                " Duration:\t%s\n"
                "****************************************\n\n" %
                (suites, tests, passes, pending, failures, start_time_json,
                 end_time, duration))

    if args.report:
        stop_time = time.time()
        json_results = {
            "timestart": start_time,
            "duration": duration,
            "tests": int(tests),
            "failures": int(failures)
        }
        logger.debug("Promise Results json: " + str(json_results))

        # criteria for Promise in Release B was 100% of tests OK
        status = "FAIL"
        if int(tests) > 32 and int(failures) < 1:
            status = "PASS"
            exit_code = 0

        ft_utils.push_results_to_db("promise", "promise", start_time,
                                    stop_time, status, json_results)

    exit(exit_code)
Exemple #9
0
def main():
    start_time = time.time()
    ks_creds = openstack_utils.get_credentials("keystone")
    nv_creds = openstack_utils.get_credentials("nova")
    nt_creds = openstack_utils.get_credentials("neutron")

    keystone = ksclient.Client(**ks_creds)

    user_id = openstack_utils.get_user_id(keystone, ks_creds['username'])
    if user_id == '':
        logger.error("Error : Failed to get id of %s user" %
                     ks_creds['username'])
        exit(-1)

    logger.info("Creating tenant '%s'..." % TENANT_NAME)
    tenant_id = openstack_utils.create_tenant(
        keystone, TENANT_NAME, TENANT_DESCRIPTION)
    if tenant_id == '':
        logger.error("Error : Failed to create %s tenant" % TENANT_NAME)
        exit(-1)
    logger.debug("Tenant '%s' created successfully." % TENANT_NAME)

    roles_name = ["admin", "Admin"]
    role_id = ''
    for role_name in roles_name:
        if role_id == '':
            role_id = openstack_utils.get_role_id(keystone, role_name)

    if role_id == '':
        logger.error("Error : Failed to get id for %s role" % role_name)
        exit(-1)

    logger.info("Adding role '%s' to tenant '%s'..." % (role_id, TENANT_NAME))
    if not openstack_utils.add_role_user(keystone, user_id,
                                         role_id, tenant_id):
        logger.error("Error : Failed to add %s on tenant %s" %
                     (ks_creds['username'], TENANT_NAME))
        exit(-1)
    logger.debug("Role added successfully.")

    logger.info("Creating user '%s'..." % USER_NAME)
    user_id = openstack_utils.create_user(
        keystone, USER_NAME, USER_PWD, None, tenant_id)

    if user_id == '':
        logger.error("Error : Failed to create %s user" % USER_NAME)
        exit(-1)
    logger.debug("User '%s' created successfully." % USER_NAME)

    logger.info("Updating OpenStack credentials...")
    ks_creds.update({
        "username": TENANT_NAME,
        "password": TENANT_NAME,
        "tenant_name": TENANT_NAME,
    })

    nt_creds.update({
        "tenant_name": TENANT_NAME,
    })

    nv_creds.update({
        "project_id": TENANT_NAME,
    })

    glance_endpoint = keystone.service_catalog.url_for(
        service_type='image', endpoint_type='publicURL')
    glance = glclient.Client(1, glance_endpoint, token=keystone.auth_token)
    nova = nvclient.Client("2", **nv_creds)

    logger.info("Creating image '%s' from '%s'..." % (IMAGE_NAME,
                                                      GLANCE_IMAGE_PATH))
    image_id = openstack_utils.create_glance_image(glance,
                                                   IMAGE_NAME,
                                                   GLANCE_IMAGE_PATH)
    if not image_id:
        logger.error("Failed to create the Glance image...")
        exit(-1)
    logger.debug("Image '%s' with ID '%s' created successfully." % (IMAGE_NAME,
                                                                    image_id))
    flavor_id = openstack_utils.get_flavor_id(nova, FLAVOR_NAME)
    if flavor_id == '':
        logger.info("Creating flavor '%s'..." % FLAVOR_NAME)
        flavor_id = openstack_utils.create_flavor(nova,
                                                  FLAVOR_NAME,
                                                  FLAVOR_RAM,
                                                  FLAVOR_DISK,
                                                  FLAVOR_VCPUS)
        if not flavor_id:
            logger.error("Failed to create the Flavor...")
            exit(-1)
        logger.debug("Flavor '%s' with ID '%s' created successfully." %
                     (FLAVOR_NAME, flavor_id))
    else:
        logger.debug("Using existing flavor '%s' with ID '%s'..."
                     % (FLAVOR_NAME, flavor_id))

    neutron = ntclient.Client(**nt_creds)

    network_dic = openstack_utils.create_network_full(logger,
                                                      neutron,
                                                      NET_NAME,
                                                      SUBNET_NAME,
                                                      ROUTER_NAME,
                                                      SUBNET_CIDR)
    if network_dic is False:
        logger.error("Failed to create the private network...")
        exit(-1)

    logger.info("Exporting environment variables...")
    os.environ["NODE_ENV"] = "functest"
    os.environ["OS_TENANT_NAME"] = TENANT_NAME
    os.environ["OS_USERNAME"] = USER_NAME
    os.environ["OS_PASSWORD"] = USER_PWD
    os.environ["OS_TEST_IMAGE"] = image_id
    os.environ["OS_TEST_FLAVOR"] = flavor_id
    os.environ["OS_TEST_NETWORK"] = network_dic["net_id"]

    os.chdir(PROMISE_REPO)
    results_file_name = 'promise-results.json'
    results_file = open(results_file_name, 'w+')
    cmd = 'npm run -s test -- --reporter json'

    logger.info("Running command: %s" % cmd)
    ret = subprocess.call(cmd, shell=True, stdout=results_file,
                          stderr=subprocess.STDOUT)
    results_file.close()

    if ret == 0:
        logger.info("The test succeeded.")
        # test_status = 'OK'
    else:
        logger.info("The command '%s' failed." % cmd)
        # test_status = "Failed"

    # Print output of file
    with open(results_file_name, 'r') as results_file:
        data = results_file.read()
        logger.debug("\n%s" % data)
        json_data = json.loads(data)

        suites = json_data["stats"]["suites"]
        tests = json_data["stats"]["tests"]
        passes = json_data["stats"]["passes"]
        pending = json_data["stats"]["pending"]
        failures = json_data["stats"]["failures"]
        start_time_json = json_data["stats"]["start"]
        end_time = json_data["stats"]["end"]
        duration = float(json_data["stats"]["duration"]) / float(1000)

    logger.info("\n"
                "****************************************\n"
                "          Promise test report\n\n"
                "****************************************\n"
                " Suites:  \t%s\n"
                " Tests:   \t%s\n"
                " Passes:  \t%s\n"
                " Pending: \t%s\n"
                " Failures:\t%s\n"
                " Start:   \t%s\n"
                " End:     \t%s\n"
                " Duration:\t%s\n"
                "****************************************\n\n"
                % (suites, tests, passes, pending, failures,
                   start_time_json, end_time, duration))

    if args.report:
        stop_time = time.time()
        json_results = {"timestart": start_time, "duration": duration,
                        "tests": int(tests), "failures": int(failures)}
        logger.debug("Promise Results json: " + str(json_results))

        # criteria for Promise in Release B was 100% of tests OK
        status = "FAIL"
        if int(tests) > 32 and int(failures) < 1:
            status = "PASS"

        functest_utils.push_results_to_db("promise",
                                          "promise",
                                          logger,
                                          start_time,
                                          stop_time,
                                          status,
                                          json_results)
Exemple #10
0
def main():

    # ############### GENERAL INITIALISATION ################

    if not os.path.exists(VIMS_DATA_DIR):
        os.makedirs(VIMS_DATA_DIR)

    ks_creds = os_utils.get_credentials("keystone")
    nv_creds = os_utils.get_credentials("nova")
    nt_creds = os_utils.get_credentials("neutron")

    logger.info("Prepare OpenStack plateform (create tenant and user)")
    keystone = ksclient.Client(**ks_creds)

    user_id = os_utils.get_user_id(keystone, ks_creds['username'])
    if user_id == '':
        step_failure("init", "Error : Failed to get id of " +
                     ks_creds['username'])

    tenant_id = os_utils.create_tenant(
        keystone, TENANT_NAME, TENANT_DESCRIPTION)
    if tenant_id == '':
        step_failure("init", "Error : Failed to create " +
                     TENANT_NAME + " tenant")

    roles_name = ["admin", "Admin"]
    role_id = ''
    for role_name in roles_name:
        if role_id == '':
            role_id = os_utils.get_role_id(keystone, role_name)

    if role_id == '':
        logger.error("Error : Failed to get id for %s role" % role_name)

    if not os_utils.add_role_user(keystone, user_id, role_id, tenant_id):
        logger.error("Error : Failed to add %s on tenant" %
                     ks_creds['username'])

    user_id = os_utils.create_user(
        keystone, TENANT_NAME, TENANT_NAME, None, tenant_id)
    if user_id == '':
        logger.error("Error : Failed to create %s user" % TENANT_NAME)

    logger.info("Update OpenStack creds informations")
    ks_creds.update({
        "username": TENANT_NAME,
        "password": TENANT_NAME,
        "tenant_name": TENANT_NAME,
    })

    nt_creds.update({
        "tenant_name": TENANT_NAME,
    })

    nv_creds.update({
        "project_id": TENANT_NAME,
    })

    logger.info("Upload some OS images if it doesn't exist")
    glance_endpoint = keystone.service_catalog.url_for(
        service_type='image', endpoint_type='publicURL')
    glance = glclient.Client(1, glance_endpoint, token=keystone.auth_token)

    for img in IMAGES.keys():
        image_name = IMAGES[img]['image_name']
        image_url = IMAGES[img]['image_url']

        image_id = os_utils.get_image_id(glance, image_name)

        if image_id == '':
            logger.info("""%s image doesn't exist on glance repository. Try
            downloading this image and upload on glance !""" % image_name)
            image_id = download_and_add_image_on_glance(
                glance, image_name, image_url)

        if image_id == '':
            step_failure(
                "init",
                "Error : Failed to find or upload required OS "
                "image for this deployment")

    nova = nvclient.Client("2", **nv_creds)

    logger.info("Update security group quota for this tenant")
    neutron = ntclient.Client(**nt_creds)
    if not os_utils.update_sg_quota(neutron, tenant_id, 50, 100):
        step_failure(
            "init",
            "Failed to update security group quota for tenant " + TENANT_NAME)

    logger.info("Update cinder quota for this tenant")
    from cinderclient import client as cinderclient

    creds_cinder = os_utils.get_credentials("cinder")
    cinder_client = cinderclient.Client('1', creds_cinder['username'],
                                        creds_cinder['api_key'],
                                        creds_cinder['project_id'],
                                        creds_cinder['auth_url'],
                                        service_type="volume")
    if not os_utils.update_cinder_quota(cinder_client, tenant_id, 20, 10, 150):
        step_failure(
            "init", "Failed to update cinder quota for tenant " + TENANT_NAME)

    # ############### CLOUDIFY INITIALISATION ################

    cfy = orchestrator(VIMS_DATA_DIR, CFY_INPUTS, logger)

    cfy.set_credentials(username=ks_creds['username'], password=ks_creds[
                        'password'], tenant_name=ks_creds['tenant_name'],
                        auth_url=ks_creds['auth_url'])

    logger.info("Collect flavor id for cloudify manager server")
    nova = nvclient.Client("2", **nv_creds)

    flavor_name = "m1.medium"
    flavor_id = os_utils.get_flavor_id(nova, flavor_name)
    for requirement in CFY_MANAGER_REQUIERMENTS:
        if requirement == 'ram_min':
            flavor_id = os_utils.get_flavor_id_by_ram_range(
                nova, CFY_MANAGER_REQUIERMENTS['ram_min'], 8196)

    if flavor_id == '':
        logger.error(
            "Failed to find %s flavor. "
            "Try with ram range default requirement !" % flavor_name)
        flavor_id = os_utils.get_flavor_id_by_ram_range(nova, 4000, 8196)

    if flavor_id == '':
        step_failure("orchestrator",
                     "Failed to find required flavor for this deployment")

    cfy.set_flavor_id(flavor_id)

    image_name = "centos_7"
    image_id = os_utils.get_image_id(glance, image_name)
    for requirement in CFY_MANAGER_REQUIERMENTS:
        if requirement == 'os_image':
            image_id = os_utils.get_image_id(
                glance, CFY_MANAGER_REQUIERMENTS['os_image'])

    if image_id == '':
        step_failure(
            "orchestrator",
            "Error : Failed to find required OS image for cloudify manager")

    cfy.set_image_id(image_id)

    ext_net = os_utils.get_external_net(neutron)
    if not ext_net:
        step_failure("orchestrator", "Failed to get external network")

    cfy.set_external_network_name(ext_net)

    ns = functest_utils.get_resolvconf_ns()
    if ns:
        cfy.set_nameservers(ns)

    logger.info("Prepare virtualenv for cloudify-cli")
    cmd = "chmod +x " + VIMS_DIR + "create_venv.sh"
    functest_utils.execute_command(cmd, logger)
    time.sleep(3)
    cmd = VIMS_DIR + "create_venv.sh " + VIMS_DATA_DIR
    functest_utils.execute_command(cmd, logger)

    cfy.download_manager_blueprint(
        CFY_MANAGER_BLUEPRINT['url'], CFY_MANAGER_BLUEPRINT['branch'])

    # ############### CLOUDIFY DEPLOYMENT ################
    start_time_ts = time.time()
    end_time_ts = start_time_ts
    logger.info("Cloudify deployment Start Time:'%s'" % (
        datetime.datetime.fromtimestamp(start_time_ts).strftime(
            '%Y-%m-%d %H:%M:%S')))

    error = cfy.deploy_manager()
    if error:
        step_failure("orchestrator", error)

    end_time_ts = time.time()
    duration = round(end_time_ts - start_time_ts, 1)
    logger.info("Cloudify deployment duration:'%s'" % duration)
    set_result("orchestrator", duration, "")

    # ############### CLEARWATER INITIALISATION ################

    cw = clearwater(CW_INPUTS, cfy, logger)

    logger.info("Collect flavor id for all clearwater vm")
    nova = nvclient.Client("2", **nv_creds)

    flavor_name = "m1.small"
    flavor_id = os_utils.get_flavor_id(nova, flavor_name)
    for requirement in CW_REQUIERMENTS:
        if requirement == 'ram_min':
            flavor_id = os_utils.get_flavor_id_by_ram_range(
                nova, CW_REQUIERMENTS['ram_min'], 8196)

    if flavor_id == '':
        logger.error(
            "Failed to find %s flavor. Try with ram range "
            "default requirement !" % flavor_name)
        flavor_id = os_utils.get_flavor_id_by_ram_range(nova, 4000, 8196)

    if flavor_id == '':
        step_failure(
            "vIMS", "Failed to find required flavor for this deployment")

    cw.set_flavor_id(flavor_id)

    image_name = "ubuntu_14.04"
    image_id = os_utils.get_image_id(glance, image_name)
    for requirement in CW_REQUIERMENTS:
        if requirement == 'os_image':
            image_id = os_utils.get_image_id(
                glance, CW_REQUIERMENTS['os_image'])

    if image_id == '':
        step_failure(
            "vIMS",
            "Error : Failed to find required OS image for cloudify manager")

    cw.set_image_id(image_id)

    ext_net = os_utils.get_external_net(neutron)
    if not ext_net:
        step_failure("vIMS", "Failed to get external network")

    cw.set_external_network_name(ext_net)

    # ############### CLEARWATER DEPLOYMENT ################

    start_time_ts = time.time()
    end_time_ts = start_time_ts
    logger.info("vIMS VNF deployment Start Time:'%s'" % (
        datetime.datetime.fromtimestamp(start_time_ts).strftime(
            '%Y-%m-%d %H:%M:%S')))

    error = cw.deploy_vnf(CW_BLUEPRINT)
    if error:
        step_failure("vIMS", error)

    end_time_ts = time.time()
    duration = round(end_time_ts - start_time_ts, 1)
    logger.info("vIMS VNF deployment duration:'%s'" % duration)
    set_result("vIMS", duration, "")

    # ############### CLEARWATER TEST ################

    test_clearwater()

    # ########## CLEARWATER UNDEPLOYMENT ############

    cw.undeploy_vnf()

    # ########### CLOUDIFY UNDEPLOYMENT #############

    cfy.undeploy_manager()

    # ############## GENERAL CLEANUP ################
    if args.noclean:
        exit(0)

    ks_creds = os_utils.get_credentials("keystone")

    keystone = ksclient.Client(**ks_creds)

    logger.info("Removing %s tenant .." % CFY_INPUTS['keystone_tenant_name'])
    tenant_id = os_utils.get_tenant_id(
        keystone, CFY_INPUTS['keystone_tenant_name'])
    if tenant_id == '':
        logger.error("Error : Failed to get id of %s tenant" %
                     CFY_INPUTS['keystone_tenant_name'])
    else:
        if not os_utils.delete_tenant(keystone, tenant_id):
            logger.error("Error : Failed to remove %s tenant" %
                         CFY_INPUTS['keystone_tenant_name'])

    logger.info("Removing %s user .." % CFY_INPUTS['keystone_username'])
    user_id = os_utils.get_user_id(
        keystone, CFY_INPUTS['keystone_username'])
    if user_id == '':
        logger.error("Error : Failed to get id of %s user" %
                     CFY_INPUTS['keystone_username'])
    else:
        if not os_utils.delete_user(keystone, user_id):
            logger.error("Error : Failed to remove %s user" %
                         CFY_INPUTS['keystone_username'])