示例#1
0
文件: user_tests.py 项目: opnfv/snaps
 def test_config_with_name_pass_only(self):
     settings = UserConfig(**{'name': 'foo', 'password': '******'})
     self.assertEqual('foo', settings.name)
     self.assertEqual('bar', settings.password)
     self.assertIsNone(settings.project_name)
     self.assertIsNone(settings.email)
     self.assertTrue(settings.enabled)
示例#2
0
    def test_create_project_sec_grp_one_user(self):
        """
        Tests the creation of an OpenStack object to a project with a new users
        and to create a security group
        """
        self.project_creator = OpenStackProject(self.os_creds,
                                                self.project_settings)
        created_project = self.project_creator.create()
        self.assertIsNotNone(created_project)

        user_creator = OpenStackUser(
            self.os_creds,
            UserConfig(name=self.guid + '-user',
                       password=self.guid,
                       roles={'admin': self.project_settings.name},
                       domain_name=self.os_creds.user_domain_name))
        self.project_creator.assoc_user(user_creator.create())
        self.user_creators.append(user_creator)

        sec_grp_os_creds = user_creator.get_os_creds(
            self.project_creator.get_project().name)
        sec_grp_creator = OpenStackSecurityGroup(
            sec_grp_os_creds,
            SecurityGroupConfig(name=self.guid + '-name',
                                description='hello group'))
        sec_grp = sec_grp_creator.create()
        self.assertIsNotNone(sec_grp)
        self.sec_grp_creators.append(sec_grp_creator)

        self.assertEqual(self.project_creator.get_project().id,
                         sec_grp.project_id)
示例#3
0
    def test_grant_user_role_to_project(self):
        """
        Tests the keystone_utils function grant_user_role_to_project()
        :return:
        """
        user_settings = UserConfig(name=self.username,
                                   password=str(uuid.uuid4()),
                                   domain_name=self.os_creds.user_domain_name)
        self.user = keystone_utils.create_user(self.keystone, user_settings)
        self.assertEqual(self.username, self.user.name)

        project_settings = ProjectConfig(
            name=self.project_name, domain=self.os_creds.project_domain_name)
        self.project = keystone_utils.create_project(self.keystone,
                                                     project_settings)
        self.assertEqual(self.project_name, self.project.name)

        role_name = self.guid + '-role'
        self.role = keystone_utils.create_role(self.keystone, role_name)
        self.assertEqual(role_name, self.role.name)

        keystone_utils.grant_user_role_to_project(self.keystone, self.role,
                                                  self.user, self.project)

        user_roles = keystone_utils.get_roles_by_user(self.keystone, self.user,
                                                      self.project)
        self.assertIsNotNone(user_roles)
        self.assertEqual(1, len(user_roles))
        self.assertEqual(self.role.id, user_roles[0].id)
示例#4
0
文件: user_tests.py 项目: opnfv/snaps
 def test_name_pass_only(self):
     settings = UserConfig(name='foo', password='******')
     self.assertEqual('foo', settings.name)
     self.assertEqual('bar', settings.password)
     self.assertIsNone(settings.project_name)
     self.assertIsNone(settings.email)
     self.assertTrue(settings.enabled)
示例#5
0
 def _bypass_juju_network_discovery_bug(self, name):
     user_creator = OpenStackUser(
         self.snaps_creds,
         UserConfig(
             name=name, password=str(uuid.uuid4()),
             roles={'_member_': self.tenant_name}))
     user_creator.create()
     self.created_object.append(user_creator)
     return user_creator
示例#6
0
文件: user_tests.py 项目: opnfv/snaps
 def test_all(self):
     settings = UserConfig(name='foo',
                           password='******',
                           project_name='proj-foo',
                           email='*****@*****.**',
                           enabled=False)
     self.assertEqual('foo', settings.name)
     self.assertEqual('bar', settings.password)
     self.assertEqual('proj-foo', settings.project_name)
     self.assertEqual('*****@*****.**', settings.email)
     self.assertFalse(settings.enabled)
示例#7
0
    def prepare(self):
        """
        Prepare the environment for VNF testing:

            * Creation of a user,
            * Creation of a tenant,
            * Allocation admin role to the user on this tenant

        Returns base.TestCase.EX_OK if preparation is successfull

        Raise VnfPreparationException in case of problem
        """
        try:
            self.__logger.info("Prepare VNF: %s, description: %s",
                               self.case_name, self.tenant_description)
            snaps_creds = openstack_tests.get_credentials(
                os_env_file=constants.ENV_FILE)

            self.os_project = OpenStackProject(
                snaps_creds,
                ProjectConfig(name=self.tenant_name,
                              description=self.tenant_description,
                              domain=snaps_creds.project_domain_name))
            self.os_project.create()
            self.created_object.append(self.os_project)

            snaps_creds.project_domain_id = \
                self.os_project.get_project().domain_id
            snaps_creds.user_domain_id = \
                self.os_project.get_project().domain_id

            for role in ['admin', 'Admin']:
                if keystone_utils.get_role_by_name(
                        keystone_utils.keystone_client(snaps_creds), role):
                    admin_role = role
                    break

            user_creator = OpenStackUser(
                snaps_creds,
                UserConfig(name=self.user_name,
                           password=str(uuid.uuid4()),
                           project_name=self.tenant_name,
                           domain_name=snaps_creds.user_domain_name,
                           roles={admin_role: self.tenant_name}))
            user_creator.create()
            self.created_object.append(user_creator)
            self.snaps_creds = user_creator.get_os_creds(self.tenant_name)
            self.__logger.debug("snaps creds: %s", self.snaps_creds)

            return vnf.VnfOnBoarding.EX_OK
        except Exception:  # pylint: disable=broad-except
            self.__logger.exception("Exception raised during VNF preparation")
            raise VnfPreparationException
示例#8
0
    def test_create_user_minimal(self):
        """
        Tests the keystone_utils.create_user() function
        """
        user_settings = UserConfig(name=self.username,
                                   password=str(uuid.uuid4()),
                                   domain_name=self.os_creds.user_domain_name)
        self.user = keystone_utils.create_user(self.keystone, user_settings)
        self.assertEqual(self.username, self.user.name)

        user = keystone_utils.get_user(self.keystone, self.username)
        self.assertIsNotNone(user)
        self.assertEqual(self.user, user)
示例#9
0
文件: user_tests.py 项目: opnfv/snaps
 def test_config_all(self):
     settings = UserConfig(
         **{
             'name': 'foo',
             'password': '******',
             'project_name': 'proj-foo',
             'email': '*****@*****.**',
             'enabled': False
         })
     self.assertEqual('foo', settings.name)
     self.assertEqual('bar', settings.password)
     self.assertEqual('proj-foo', settings.project_name)
     self.assertEqual('*****@*****.**', settings.email)
     self.assertFalse(settings.enabled)
示例#10
0
 def _create_user(self):
     """Create user for tests."""
     user_creator = deploy_utils.create_user(
         self.os_creds,
         UserConfig(
             name=CONST.__getattribute__('tempest_identity_user_name') +
             self.guid,
             password=CONST.__getattribute__(
                 'tempest_identity_user_password'),
             project_name=CONST.__getattribute__(
                 'tempest_identity_tenant_name') + self.guid))
     if user_creator is None or user_creator.get_user() is None:
         raise Exception("Failed to create user")
     self.creators.append(user_creator)
     return user_creator.get_user().id
示例#11
0
    def __start__(self):
        """
        Creates a project and user to be leveraged by subclass test methods. If
        implementing class uses this method, it must call __clean__() else you
        will be left with unwanted users and tenants
        """
        self.project_creator = None
        self.user_creator = None
        self.admin_os_creds = self.os_creds
        self.admin_os_session = self.os_session
        self.keystone = keystone_utils.keystone_client(self.admin_os_creds,
                                                       self.admin_os_session)

        if self.use_keystone:
            guid = self.__class__.__name__ + '-' + str(uuid.uuid4())[:-19]
            project_name = guid + '-proj'
            self.project_creator = deploy_utils.create_project(
                self.admin_os_creds,
                ProjectConfig(name=project_name,
                              domain=self.admin_os_creds.project_domain_name))

            # Set by implementing class for setting the user's roles
            roles = dict()
            if self.user_roles and isinstance(self.user_roles, list):
                for user_role in self.user_roles:
                    roles[user_role] = project_name

            self.user_creator = deploy_utils.create_user(
                self.admin_os_creds,
                UserConfig(name=guid + '-user',
                           password=guid,
                           project_name=project_name,
                           roles=roles,
                           domain_name=self.admin_os_creds.user_domain_name))

            self.os_creds = self.user_creator.get_os_creds(
                self.project_creator.project_settings.name)
            self.os_session = keystone_utils.keystone_session(self.os_creds)

            # add user to project
            self.project_creator.assoc_user(self.user_creator.get_user())

            if self.proj_users and isinstance(self.proj_users, list):
                for user_name in self.proj_users:
                    user = keystone_utils.get_user(self.keystone, user_name)
                    if user:
                        self.project_creator.assoc_user(user)
示例#12
0
    def prepare(self):
        """
        Prepare the environment for VNF testing:

            * Creation of a user,
            * Creation of a tenant,
            * Allocation admin role to the user on this tenant

        Returns base.TestCase.EX_OK if preparation is successfull

        Raise VnfPreparationException in case of problem
        """
        try:
            tenant_description = CONST.__getattribute__(
                'vnf_{}_tenant_description'.format(self.case_name))
            self.__logger.info("Prepare VNF: %s, description: %s",
                               self.tenant_name, tenant_description)
            snaps_creds = openstack_tests.get_credentials(
                os_env_file=CONST.__getattribute__('openstack_creds'))

            project_creator = OpenStackProject(
                snaps_creds,
                ProjectConfig(name=self.tenant_name,
                              description=tenant_description))
            project_creator.create()
            self.created_object.append(project_creator)
            self.os_project = project_creator

            user_creator = OpenStackUser(
                snaps_creds,
                UserConfig(name=self.tenant_name,
                           password=self.tenant_name,
                           roles={'admin': self.tenant_name}))

            user_creator.create()
            self.created_object.append(user_creator)

            self.snaps_creds = user_creator.get_os_creds(self.tenant_name)

            return base.TestCase.EX_OK
        except Exception:  # pylint: disable=broad-except
            self.__logger.exception("Exception raised during VNF preparation")
            raise VnfPreparationException
示例#13
0
    def setUp(self):
        """
        Instantiates the CreateImage object that is responsible for downloading
        and creating an OS image file within OpenStack
        """
        guid = str(uuid.uuid4())[:-19]
        guid = self.__class__.__name__ + '-' + guid
        self.user_settings = UserConfig(
            name=guid + '-name',
            password=guid + '-password',
            roles={
                'admin': self.os_creds.project_name,
                'Admin': self.os_creds.project_name
            },
            domain_name=self.os_creds.user_domain_name)

        self.keystone = keystone_utils.keystone_client(self.os_creds,
                                                       self.os_session)

        # Initialize for cleanup
        self.user_creator = None
示例#14
0
文件: user_tests.py 项目: opnfv/snaps
 def test_empty_config(self):
     with self.assertRaises(Exception):
         UserConfig(**dict())
示例#15
0
    def deploy_orchestrator(self):
        # pylint: disable=too-many-locals,too-many-statements
        """
        Deploy Cloudify Manager.

        network, security group, fip, VM creation
        """
        start_time = time.time()

        # orchestrator VM flavor
        self.__logger.info("Get or create flavor for cloudify manager vm ...")
        flavor_settings = FlavorConfig(
            name="{}-{}".format(
                self.orchestrator['requirements']['flavor']['name'],
                self.uuid),
            ram=self.orchestrator['requirements']['flavor']['ram_min'],
            disk=50,
            vcpus=2)
        flavor_creator = OpenStackFlavor(self.snaps_creds, flavor_settings)
        flavor_creator.create()
        self.created_object.append(flavor_creator)

        self.__logger.info("Creating a second user to bypass issues ...")
        user_creator = OpenStackUser(
            self.snaps_creds,
            UserConfig(
                name='cloudify_network_bug-{}'.format(self.uuid),
                password=str(uuid.uuid4()),
                project_name=self.tenant_name,
                domain_name=self.snaps_creds.user_domain_name,
                roles={'_member_': self.tenant_name}))
        user_creator.create()
        self.created_object.append(user_creator)

        snaps_creds = user_creator.get_os_creds(self.snaps_creds.project_name)
        self.__logger.debug("snaps creds: %s", snaps_creds)

        self.__logger.info("Creating keypair ...")
        kp_file = os.path.join(self.data_dir, "cloudify_ims.pem")
        keypair_settings = KeypairConfig(
            name='cloudify_ims_kp-{}'.format(self.uuid),
            private_filepath=kp_file)
        keypair_creator = OpenStackKeypair(snaps_creds, keypair_settings)
        keypair_creator.create()
        self.created_object.append(keypair_creator)

        # needs some images
        self.__logger.info("Upload some OS images if it doesn't exist")
        for image_name, image_file in self.images.iteritems():
            self.__logger.info("image: %s, file: %s", image_name, image_file)
            if image_file and image_name:
                image_creator = OpenStackImage(
                    snaps_creds,
                    ImageConfig(
                        name=image_name, image_user='******',
                        img_format='qcow2', image_file=image_file))
                image_creator.create()
                self.created_object.append(image_creator)

        # network creation
        self.__logger.info("Creating full network ...")
        subnet_settings = SubnetConfig(
            name='cloudify_ims_subnet-{}'.format(self.uuid),
            cidr='10.67.79.0/24',
            dns_nameservers=[env.get('NAMESERVER')])
        network_settings = NetworkConfig(
            name='cloudify_ims_network-{}'.format(self.uuid),
            subnet_settings=[subnet_settings])
        network_creator = OpenStackNetwork(snaps_creds, network_settings)
        network_creator.create()
        self.created_object.append(network_creator)
        ext_net_name = snaps_utils.get_ext_net_name(snaps_creds)
        router_creator = OpenStackRouter(
            snaps_creds,
            RouterConfig(
                name='cloudify_ims_router-{}'.format(self.uuid),
                external_gateway=ext_net_name,
                internal_subnets=[subnet_settings.name]))
        router_creator.create()
        self.created_object.append(router_creator)

        # security group creation
        self.__logger.info("Creating security group for cloudify manager vm")
        sg_rules = list()
        sg_rules.append(
            SecurityGroupRuleConfig(
                sec_grp_name="sg-cloudify-manager-{}".format(self.uuid),
                direction=Direction.ingress, protocol=Protocol.tcp,
                port_range_min=1, port_range_max=65535))
        sg_rules.append(
            SecurityGroupRuleConfig(
                sec_grp_name="sg-cloudify-manager-{}".format(self.uuid),
                direction=Direction.ingress, protocol=Protocol.udp,
                port_range_min=1, port_range_max=65535))
        security_group_creator = OpenStackSecurityGroup(
            snaps_creds,
            SecurityGroupConfig(
                name="sg-cloudify-manager-{}".format(self.uuid),
                rule_settings=sg_rules))
        security_group_creator.create()
        self.created_object.append(security_group_creator)

        image_settings = ImageConfig(
            name=self.orchestrator['requirements']['os_image'],
            image_user='******',
            exists=True)
        port_settings = PortConfig(
            name='cloudify_manager_port-{}'.format(self.uuid),
            network_name=network_settings.name)
        manager_settings = VmInstanceConfig(
            name='cloudify_manager-{}'.format(self.uuid),
            flavor=flavor_settings.name,
            port_settings=[port_settings],
            security_group_names=[
                security_group_creator.sec_grp_settings.name],
            floating_ip_settings=[FloatingIpConfig(
                name='cloudify_manager_fip-{}'.format(self.uuid),
                port_name=port_settings.name,
                router_name=router_creator.router_settings.name)])
        manager_creator = OpenStackVmInstance(
            snaps_creds, manager_settings, image_settings,
            keypair_settings)
        self.__logger.info("Creating cloudify manager VM")
        manager_creator.create()
        self.created_object.append(manager_creator)

        public_auth_url = keystone_utils.get_endpoint(snaps_creds, 'identity')

        cfy_creds = dict(
            keystone_username=snaps_creds.username,
            keystone_password=snaps_creds.password,
            keystone_tenant_name=snaps_creds.project_name,
            keystone_url=public_auth_url,
            region=snaps_creds.region_name,
            user_domain_name=snaps_creds.user_domain_name,
            project_domain_name=snaps_creds.project_domain_name)
        self.__logger.info("Set creds for cloudify manager %s", cfy_creds)

        cfy_client = CloudifyClient(
            host=manager_creator.get_floating_ip().ip,
            username='******', password='******', tenant='default_tenant')

        self.orchestrator['object'] = cfy_client

        self.__logger.info("Attemps running status of the Manager")
        for loop in range(10):
            try:
                self.__logger.debug(
                    "status %s", cfy_client.manager.get_status())
                cfy_status = cfy_client.manager.get_status()['status']
                self.__logger.info(
                    "The current manager status is %s", cfy_status)
                if str(cfy_status) != 'running':
                    raise Exception("Cloudify Manager isn't up and running")
                self.__logger.info("Put OpenStack creds in manager")
                secrets_list = cfy_client.secrets.list()
                for k, val in cfy_creds.iteritems():
                    if not any(d.get('key', None) == k for d in secrets_list):
                        cfy_client.secrets.create(k, val)
                    else:
                        cfy_client.secrets.update(k, val)
                break
            except Exception:  # pylint: disable=broad-except
                self.logger.info(
                    "try %s: Cloudify Manager isn't up and running", loop + 1)
                time.sleep(30)
        else:
            self.logger.error("Cloudify Manager isn't up and running")
            return False

        duration = time.time() - start_time

        if manager_creator.vm_ssh_active(block=True):
            self.__logger.info("Put private keypair in manager")
            ssh = manager_creator.ssh_client()
            scp = SCPClient(ssh.get_transport(), socket_timeout=15.0)
            scp.put(kp_file, '~/')
            cmd = "sudo cp ~/cloudify_ims.pem /etc/cloudify/"
            self.run_blocking_ssh_command(ssh, cmd)
            cmd = "sudo chmod 444 /etc/cloudify/cloudify_ims.pem"
            self.run_blocking_ssh_command(ssh, cmd)
            # cmd2 is badly unpinned by Cloudify
            cmd = "sudo yum install -y gcc python-devel python-cmd2"
            self.run_blocking_ssh_command(
                ssh, cmd, "Unable to install packages on manager")
            self.run_blocking_ssh_command(ssh, 'cfy status')
        else:
            self.__logger.error("Cannot connect to manager")
            return False

        self.details['orchestrator'].update(status='PASS', duration=duration)

        self.vnf['inputs'].update(dict(
            external_network_name=ext_net_name,
            network_name=network_settings.name,
            key_pair_name=keypair_settings.name
        ))
        self.result = 1/3 * 100
        return True
示例#16
0
文件: user_tests.py 项目: opnfv/snaps
 def test_no_params(self):
     with self.assertRaises(Exception):
         UserConfig()
示例#17
0
文件: user_tests.py 项目: opnfv/snaps
 def test_config_with_name_pass_enabled_str(self):
     with self.assertRaises(Exception):
         UserConfig(**{'name': 'foo', 'password': '******', 'enabled': 'true'})
示例#18
0
文件: user_tests.py 项目: opnfv/snaps
 def test_name_pass_enabled_str(self):
     with self.assertRaises(Exception):
         UserConfig(name='foo', password='******', enabled='true')
示例#19
0
文件: user_tests.py 项目: opnfv/snaps
 def test_config_with_name_only(self):
     with self.assertRaises(Exception):
         UserConfig(**{'name': 'foo'})
示例#20
0
    def create(self,
               use_custom_images=False,
               use_custom_flavors=False,
               create_project=False):
        if create_project:
            logger.debug("Creating project (tenant) for Tempest suite")
            project_name = CONST.__getattribute__(
                'tempest_identity_tenant_name') + self.guid
            project_creator = deploy_utils.create_project(
                self.os_creds,
                ProjectConfig(name=project_name,
                              description=CONST.__getattribute__(
                                  'tempest_identity_tenant_description')))
            if (project_creator is None
                    or project_creator.get_project() is None):
                raise Exception("Failed to create tenant")
            project_id = project_creator.get_project().id
            self.creators.append(project_creator)

            logger.debug("Creating user for Tempest suite")
            user_creator = deploy_utils.create_user(
                self.os_creds,
                UserConfig(
                    name=CONST.__getattribute__('tempest_identity_user_name') +
                    self.guid,
                    password=CONST.__getattribute__(
                        'tempest_identity_user_password'),
                    project_name=project_name))
            if user_creator is None or user_creator.get_user() is None:
                raise Exception("Failed to create user")
            user_id = user_creator.get_user().id
            self.creators.append(user_creator)
        else:
            project_name = None
            project_id = None
            user_id = None

        logger.debug("Creating private network for Tempest suite")
        network_creator = deploy_utils.create_network(
            self.os_creds,
            NetworkConfig(
                name=CONST.__getattribute__('tempest_private_net_name') +
                self.guid,
                project_name=project_name,
                subnet_settings=[
                    SubnetConfig(name=CONST.__getattribute__(
                        'tempest_private_subnet_name') + self.guid,
                                 cidr=CONST.__getattribute__(
                                     'tempest_private_subnet_cidr'))
                ]))
        if network_creator is None or network_creator.get_network() is None:
            raise Exception("Failed to create private network")
        self.creators.append(network_creator)

        image_id = None
        image_id_alt = None
        flavor_id = None
        flavor_id_alt = None

        logger.debug("Creating image for Tempest suite")
        image_base_name = CONST.__getattribute__(
            'openstack_image_name') + self.guid
        os_image_settings = openstack_tests.cirros_image_settings(
            image_base_name,
            public=True,
            image_metadata=self.cirros_image_config)
        logger.debug("Creating image for Tempest suite")
        image_creator = deploy_utils.create_image(self.os_creds,
                                                  os_image_settings)
        if image_creator is None:
            raise Exception('Failed to create image')
        self.creators.append(image_creator)
        image_id = image_creator.get_image().id

        if use_custom_images:
            logger.debug("Creating 2nd image for Tempest suite")
            image_base_name_alt = CONST.__getattribute__(
                'openstack_image_name_alt') + self.guid
            os_image_settings_alt = openstack_tests.cirros_image_settings(
                image_base_name_alt,
                public=True,
                image_metadata=self.cirros_image_config)
            logger.debug("Creating 2nd image for Tempest suite")
            image_creator_alt = deploy_utils.create_image(
                self.os_creds, os_image_settings_alt)
            if image_creator_alt is None:
                raise Exception('Failed to create image')
            self.creators.append(image_creator_alt)
            image_id_alt = image_creator_alt.get_image().id

        if (CONST.__getattribute__('tempest_use_custom_flavors') == 'True'
                or use_custom_flavors):
            logger.info("Creating flavor for Tempest suite")
            scenario = CONST.__getattribute__('DEPLOY_SCENARIO')
            flavor_metadata = None
            if 'ovs' in scenario or 'fdio' in scenario:
                flavor_metadata = create_flavor.MEM_PAGE_SIZE_LARGE
            flavor_creator = OpenStackFlavor(
                self.os_creds,
                FlavorConfig(
                    name=CONST.__getattribute__('openstack_flavor_name') +
                    self.guid,
                    ram=CONST.__getattribute__('openstack_flavor_ram'),
                    disk=CONST.__getattribute__('openstack_flavor_disk'),
                    vcpus=CONST.__getattribute__('openstack_flavor_vcpus'),
                    metadata=flavor_metadata))
            flavor = flavor_creator.create()
            if flavor is None:
                raise Exception('Failed to create flavor')
            self.creators.append(flavor_creator)
            flavor_id = flavor.id

        if use_custom_flavors:
            logger.info("Creating 2nd flavor for Tempest suite")
            scenario = CONST.__getattribute__('DEPLOY_SCENARIO')
            flavor_metadata_alt = None
            if 'ovs' in scenario or 'fdio' in scenario:
                flavor_metadata_alt = create_flavor.MEM_PAGE_SIZE_LARGE
                CONST.__setattr__('openstack_flavor_ram', 1024)
            flavor_creator_alt = OpenStackFlavor(
                self.os_creds,
                FlavorConfig(
                    name=CONST.__getattribute__('openstack_flavor_name_alt') +
                    self.guid,
                    ram=CONST.__getattribute__('openstack_flavor_ram'),
                    disk=CONST.__getattribute__('openstack_flavor_disk'),
                    vcpus=CONST.__getattribute__('openstack_flavor_vcpus'),
                    metadata=flavor_metadata_alt))
            flavor_alt = flavor_creator_alt.create()
            if flavor_alt is None:
                raise Exception('Failed to create flavor')
            self.creators.append(flavor_creator_alt)
            flavor_id_alt = flavor_alt.id

        print("RESOURCES CREATE: image_id: %s, image_id_alt: %s, "
              "flavor_id: %s, flavor_id_alt: %s" % (
                  image_id,
                  image_id_alt,
                  flavor_id,
                  flavor_id_alt,
              ))

        result = {
            'image_id': image_id,
            'image_id_alt': image_id_alt,
            'flavor_id': flavor_id,
            'flavor_id_alt': flavor_id_alt
        }

        if create_project:
            result['project_id'] = project_id
            result['tenant_id'] = project_id  # for compatibility
            result['user_id'] = user_id

        return result
示例#21
0
文件: user_tests.py 项目: opnfv/snaps
 def test_name_only(self):
     with self.assertRaises(Exception):
         UserConfig(name='foo')
示例#22
0
    def deploy_vnf(self):
        start_time = time.time()

        self.__logger.info("Upload VNFD")
        cfy_client = self.orchestrator['object']
        descriptor = self.vnf['descriptor']
        self.deployment_name = descriptor.get('name')

        cfy_client.blueprints.upload(descriptor.get('file_name'),
                                     descriptor.get('name'))

        self.__logger.info("Get or create flavor for vrouter")
        flavor_settings = FlavorConfig(
            name=self.vnf['requirements']['flavor']['name'],
            ram=self.vnf['requirements']['flavor']['ram_min'],
            disk=25,
            vcpus=1)
        flavor_creator = OpenStackFlavor(self.snaps_creds, flavor_settings)
        flavor = flavor_creator.create()
        self.created_object.append(flavor_creator)

        # set image name
        glance = glance_utils.glance_client(self.snaps_creds)
        image = glance_utils.get_image(glance, "vyos1.1.7")

        user_creator = OpenStackUser(
            self.snaps_creds,
            UserConfig(name='cloudify_network_bug-{}'.format(self.uuid),
                       password=str(uuid.uuid4()),
                       project_name=self.tenant_name,
                       domain=self.snaps_creds.user_domain_name,
                       roles={'_member_': self.tenant_name}))
        user_creator.create()
        self.created_object.append(user_creator)
        snaps_creds = user_creator.get_os_creds(self.snaps_creds.project_name)
        self.__logger.debug("snaps creds: %s", snaps_creds)

        self.vnf['inputs'].update(dict(target_vnf_image_id=image.id))
        self.vnf['inputs'].update(dict(reference_vnf_image_id=image.id))
        self.vnf['inputs'].update(dict(target_vnf_flavor_id=flavor.id))
        self.vnf['inputs'].update(dict(reference_vnf_flavor_id=flavor.id))
        self.vnf['inputs'].update(dict(keystone_username=snaps_creds.username))
        self.vnf['inputs'].update(dict(keystone_password=snaps_creds.password))
        self.vnf['inputs'].update(
            dict(keystone_tenant_name=snaps_creds.project_name))
        self.vnf['inputs'].update(
            dict(keystone_user_domain_name=snaps_creds.user_domain_name))
        self.vnf['inputs'].update(
            dict(keystone_project_domain_name=snaps_creds.project_domain_name))
        self.vnf['inputs'].update(dict(region=snaps_creds.region_name))
        self.vnf['inputs'].update(
            dict(keystone_url=keystone_utils.get_endpoint(
                snaps_creds, 'identity')))

        self.__logger.info("Create VNF Instance")
        cfy_client.deployments.create(descriptor.get('name'),
                                      descriptor.get('name'),
                                      self.vnf.get('inputs'))

        wait_for_execution(cfy_client,
                           get_execution_id(cfy_client,
                                            descriptor.get('name')),
                           self.__logger,
                           timeout=7200)

        self.__logger.info("Start the VNF Instance deployment")
        execution = cfy_client.executions.start(descriptor.get('name'),
                                                'install')
        # Show execution log
        execution = wait_for_execution(cfy_client, execution, self.__logger)

        duration = time.time() - start_time

        self.__logger.info(execution)
        if execution.status == 'terminated':
            self.details['vnf'].update(status='PASS', duration=duration)
            result = True
        else:
            self.details['vnf'].update(status='FAIL', duration=duration)
            result = False
        return result