当前位置: 首页>>代码示例>>Python>>正文


Python utils.random_gen函数代码示例

本文整理汇总了Python中marvin.lib.utils.random_gen函数的典型用法代码示例。如果您正苦于以下问题:Python random_gen函数的具体用法?Python random_gen怎么用?Python random_gen使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了random_gen函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: createLogs

    def createLogs(self,
                   test_module_name=None,
                   log_cfg=None,
                   user_provided_logpath=None):
        '''
        @Name : createLogs
        @Desc : Gets the Logger with file paths initialized and created
        @Inputs :test_module_name: Test Module Name to use for logs while
                 creating log folder path
                 log_cfg: Log Configuration provided inside of
                 Configuration
                 user_provided_logpath:LogPath provided by user
                                       If user provided log path
                                       is available, then one in cfg
                                       will  not be picked up.
        @Output : SUCCESS\FAILED
        '''
        try:
            temp_ts = time.strftime("%b_%d_%Y_%H_%M_%S",
                                    time.localtime())
            if test_module_name is None:
                temp_path = temp_ts + "_" + random_gen()
            else:
                temp_path = str(test_module_name) + \
                    "__" + str(temp_ts) + "_" + random_gen()

            if user_provided_logpath:
                temp_dir = user_provided_logpath
            elif ((log_cfg is not None) and
                    ('LogFolderPath' in log_cfg.__dict__.keys()) and
                    (log_cfg.__dict__.get('LogFolderPath') is not None)):
                temp_dir = \
                    log_cfg.__dict__.get('LogFolderPath') + "/MarvinLogs"

            self.__logFolderDir = temp_dir + "//" + temp_path
            print "\n==== Log Folder Path: %s. " \
                  "All logs will be available here ====" \
                  % str(self.__logFolderDir)
            os.makedirs(self.__logFolderDir)

            '''
            Log File Paths
            1. FailedExceptionLog
            2. RunLog contains the complete Run Information for Test Run
            3. ResultFile contains the TC result information for Test Run
            '''
            tc_failed_exception_log = \
                self.__logFolderDir + "/failed_plus_exceptions.txt"
            tc_run_log = self.__logFolderDir + "/runinfo.txt"
            if self.__setLogHandler(tc_run_log,
                                    log_level=logging.DEBUG) != FAILED:
                self.__setLogHandler(tc_failed_exception_log,
                                     log_level=logging.FATAL)
                return SUCCESS
            return FAILED
        except Exception as e:
            print "\n Exception Occurred Under createLogs :%s" % \
                  GetDetailExceptionInfo(e)
            return FAILED
开发者ID:MANIKANDANVEN,项目名称:cloudstack,代码行数:59,代码来源:marvinLog.py

示例2: test_02_edit_iso

    def test_02_edit_iso(self):
        """Test Edit ISO
        """

        # Validate the following:
        # 1. UI should show the edited values for ISO
        # 2. database (vm_template table) should have updated values

        # Generate random values for updating ISO name and Display text
        new_displayText = random_gen()
        new_name = random_gen()

        self.debug("Updating ISO permissions for ISO: %s" % self.iso_1.id)

        cmd = updateIso.updateIsoCmd()
        # Assign new values to attributes
        cmd.id = self.iso_1.id
        cmd.displaytext = new_displayText
        cmd.name = new_name
        cmd.bootable = self.services["bootable"]
        cmd.passwordenabled = self.services["passwordenabled"]

        self.apiclient.updateIso(cmd)

        # Check whether attributes are updated in ISO using listIsos
        list_iso_response = list_isos(
            self.apiclient,
            id=self.iso_1.id
        )
        self.assertEqual(
            isinstance(list_iso_response, list),
            True,
            "Check list response returns a valid list"
        )
        self.assertNotEqual(
            len(list_iso_response),
            0,
            "Check template available in List ISOs"
        )

        iso_response = list_iso_response[0]
        self.assertEqual(
            iso_response.displaytext,
            new_displayText,
            "Check display text of updated ISO"
        )
        self.assertEqual(
            iso_response.bootable,
            self.services["bootable"],
            "Check if image is bootable of updated ISO"
        )

        self.assertEqual(
            iso_response.ostypeid,
            self.services["ostypeid"],
            "Check OSTypeID of updated ISO"
        )
        return
开发者ID:K0zka,项目名称:cloudstack,代码行数:58,代码来源:test_iso.py

示例3: test_instance_name_with_hyphens

    def test_instance_name_with_hyphens(self):
        """ Test the instance  name with hyphens
        """

        # Validate the following
        # 1. Set the vm.instancename.flag to true.
        # 2. Add the virtual machine with display name with hyphens

        # Reading display name property
        if not is_config_suitable(
                apiclient=self.apiclient,
                name='vm.instancename.flag',
                value='true'):
            self.skipTest('vm.instancename.flag should be true. skipping')

        self.services["virtual_machine"]["displayname"] = random_gen(
            chars=string.ascii_uppercase) + "-" + random_gen(
            chars=string.ascii_uppercase)

        self.debug("Deploying an instance in account: %s" %
                   self.account.name)

        virtual_machine = VirtualMachine.create(
            self.apiclient,
            self.services["virtual_machine"],
            accountid=self.account.name,
            domainid=self.account.domainid,
            serviceofferingid=self.service_offering.id,
        )
        self.debug(
            "Checking if the virtual machine is created properly or not?")
        vms = VirtualMachine.list(
            self.apiclient,
            id=virtual_machine.id,
            listall=True
        )

        self.assertEqual(
            isinstance(vms, list),
            True,
            "List vms should retuen a valid name"
        )
        vm = vms[0]
        self.assertEqual(
            vm.state,
            "Running",
            "Vm state should be running after deployment"
        )
        self.debug("Display name: %s" % vm.displayname)
        return
开发者ID:miguelaferreira,项目名称:cosmic-core,代码行数:50,代码来源:test_custom_hostname.py

示例4: test_02_edit_service_offering

    def test_02_edit_service_offering(self):
        """Test to update existing service offering"""

        # Validate the following:
        # 1. updateServiceOffering should return
        #    a valid information for newly created offering

        # Generate new name & displaytext from random data
        random_displaytext = random_gen()
        random_name = random_gen()

        self.debug("Updating service offering with ID: %s" %
                   self.service_offering_1.id)

        cmd = updateServiceOffering.updateServiceOfferingCmd()
        # Add parameters for API call
        cmd.id = self.service_offering_1.id
        cmd.displaytext = random_displaytext
        cmd.name = random_name
        self.apiclient.updateServiceOffering(cmd)

        list_service_response = list_service_offering(
            self.apiclient,
            id=self.service_offering_1.id
        )
        self.assertEqual(
            isinstance(list_service_response, list),
            True,
            "Check list response returns a valid list"
        )

        self.assertNotEqual(
            len(list_service_response),
            0,
            "Check Service offering is updated"
        )

        self.assertEqual(
            list_service_response[0].displaytext,
            random_displaytext,
            "Check server displaytext in updateServiceOffering"
        )
        self.assertEqual(
            list_service_response[0].name,
            random_name,
            "Check server name in updateServiceOffering"
        )

        return
开发者ID:Accelerite,项目名称:cloudstack,代码行数:49,代码来源:test_service_offerings.py

示例5: createZone

 def createZone(self, zone, rec=0):
     try:
         zoneresponse = self.__apiClient.createZone(zone)
         if zoneresponse.id:
             self.__addToCleanUp("Zone", zoneresponse.id)
             self.__tcRunLogger.\
                 debug("Zone Name : %s Id : %s Created Successfully" %
                       (str(zone.name), str(zoneresponse.id)))
             return zoneresponse.id
         else:
             self.__tcRunLogger.\
                 exception("====Zone : %s Creation Failed=====" %
                           str(zone.name))
             print "\n====Zone : %s Creation Failed=====" % str(zone.name)
             if not rec:
                 zone.name = zone.name + "_" + random_gen()
                 self.__tcRunLogger.\
                     debug("====Recreating Zone With New Name : "
                           "%s" % zone.name)
                 print "\n====Recreating Zone With New Name ====", \
                     str(zone.name)
                 return self.createZone(zone, 1)
     except Exception as e:
         print "\nException Occurred under createZone : %s" % \
               GetDetailExceptionInfo(e)
         self.__tcRunLogger.exception("====Create Zone Failed ===")
         return FAILED
开发者ID:MountHuang,项目名称:cloudstack,代码行数:27,代码来源:deployDataCenter.py

示例6: test_05_unsupported_chars_in_display_name

    def test_05_unsupported_chars_in_display_name(self):
        """ Test Unsupported chars in the display name
            (eg: Spaces,Exclamation,yet to get unsupported chars from the dev)
        """

        # Validate the following
        # 1) Set the Global Setting vm.instancename.flag to true
        # 2) While creating VM give a Display name which has unsupported chars
        #    Gives an error message "Instance name can not be longer than 63
        #    characters. Only ASCII letters a~z, A~Z, digits 0~9, hyphen are
        #    allowed. Must start with a letter and end with a letter or digit

        self.debug("Creating VM with unsupported chars in display name")
        display_names = ["!hkzs566", "asdh asd", "!dsf d"]

        for display_name in display_names:
            self.debug("Display name: %s" % display_name)
            self.services["virtual_machine"]["displayname"] = display_name
            self.services["virtual_machine"]["name"] = random_gen(
                chars=string.ascii_uppercase)

            with self.assertRaises(Exception):
                # Spawn an instance in that network
                VirtualMachine.create(
                    self.apiclient,
                    self.services["virtual_machine"],
                    accountid=self.account.name,
                    domainid=self.account.domainid,
                    serviceofferingid=self.service_offering.id,
                )
        return
开发者ID:Skotha,项目名称:cloudstack,代码行数:31,代码来源:test_custom_hostname.py

示例7: setUp

    def setUp(self):
        self.apiclient = self.testClient.getApiClient()
        self.dbclient = self.testClient.getDbConnection()

        self.services["virtual_machine"]["name"] =\
            random_gen(chars=string.ascii_uppercase)
        self.cleanup = []
        return
开发者ID:miguelaferreira,项目名称:cosmic-core,代码行数:8,代码来源:test_custom_hostname.py

示例8: setUpClass

    def setUpClass(cls):
        testClient = super(TestVmSnapshot, cls).getClsTestClient()

        hypervisor = testClient.getHypervisorInfo()
        if hypervisor.lower() in (KVM.lower(), "hyperv", "lxc"):
            raise unittest.SkipTest(
                "VM snapshot feature is not supported on KVM, Hyper-V or LXC")

        cls.apiclient = testClient.getApiClient()
        cls.services = testClient.getParsedTestDataConfig()
        # Get Zone, Domain and templates
        cls.domain = get_domain(cls.apiclient)
        cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests())

        template = get_template(
            cls.apiclient,
            cls.zone.id,
            cls.services["ostype"]
        )
        if template == FAILED:
            assert False, "get_template() failed to return template\
                    with description %s" % cls.services["ostype"]

        cls.services["domainid"] = cls.domain.id
        cls.services["server"]["zoneid"] = cls.zone.id
        cls.services["templates"]["ostypeid"] = template.ostypeid
        cls.services["zoneid"] = cls.zone.id

        # Create VMs, NAT Rules etc
        cls.account = Account.create(
            cls.apiclient,
            cls.services["account"],
            domainid=cls.domain.id
        )

        cls.service_offering = ServiceOffering.create(
            cls.apiclient,
            cls.services["service_offerings"]
        )
        cls.virtual_machine = VirtualMachine.create(
            cls.apiclient,
            cls.services["server"],
            templateid=template.id,
            accountid=cls.account.name,
            domainid=cls.account.domainid,
            serviceofferingid=cls.service_offering.id,
            mode=cls.zone.networktype
        )
        cls.random_data_0 = random_gen(size=100)
        cls.test_dir = "/tmp"
        cls.random_data = "random.data"
        cls._cleanup = [
            cls.service_offering,
            cls.account,
        ]
        return
开发者ID:K0zka,项目名称:cloudstack,代码行数:56,代码来源:test_vm_snapshots.py

示例9: configure_Stickiness_Policy

 def configure_Stickiness_Policy(self, lb_rule, method, paramDict=None):
     """Configure the stickiness policy on lb rule"""
     try:
         result = lb_rule.createSticky(
             self.apiclient, methodname=method, name="-".join([method, random_gen()]), param=paramDict
         )
         self.debug("Response: %s" % result)
         return result
     except Exception as e:
         self.fail("Configure sticky policy failed with exception: %s" % e)
开发者ID:ktenzer,项目名称:cloudstack,代码行数:10,代码来源:test_haproxy.py

示例10: create_aff_grp

    def create_aff_grp(self, aff_grp=None,
                  acc=None, domainid=None):

        aff_grp["name"] = "aff_grp_" + random_gen(size=6)

        try:
            aff_grp = AffinityGroup.create(self.apiclient,
                                           aff_grp, acc, domainid)
            return aff_grp
        except Exception as e:
            raise Exception("Error: Creation of Affinity Group failed : %s" %e)
开发者ID:Accelerite,项目名称:cloudstack,代码行数:11,代码来源:test_vmware_drs.py

示例11: finalize

 def finalize(self, result):
     try:
         if not self.__userLogPath:
             src = self.__logFolderPath
             log_cfg = self.__parsedConfig.logger
             tmp = log_cfg.__dict__.get('LogFolderPath') + "/MarvinLogs"
             dst = tmp + "//" + random_gen()
             mod_name = "test_suite"
             if self.__testModName:
                 mod_name = self.__testModName.split(".")
                 if len(mod_name) > 2:
                     mod_name = mod_name[-2]
             if mod_name:
                 dst = tmp + "/" + mod_name + "_" + random_gen()
             cmd = "mv " + src + " " + dst
             os.system(cmd)
             print "===final results are now copied to: %s===" % str(dst)
     except Exception, e:
         print "=== Exception occurred under finalize :%s ===" % \
               str(GetDetailExceptionInfo(e))
开发者ID:MANIKANDANVEN,项目名称:cloudstack,代码行数:20,代码来源:marvinPlugin.py

示例12: create_aff_grp

    def create_aff_grp(self, api_client=None, aff_grp=None, aff_grp_name=None, projectid=None):

       if not api_client:
          api_client = self.api_client
       if aff_grp is None:
          aff_grp = self.services["host_anti_affinity"]
       if aff_grp_name is None:
          aff_grp["name"] = "aff_grp_" + random_gen(size=6)
       else:
          aff_grp["name"] = aff_grp_name
       if projectid is None:
          projectid = self.project.id
       try:
          return AffinityGroup.create(api_client, aff_grp, None, None, projectid)
       except Exception as e:
          raise Exception("Error: Creation of Affinity Group failed : %s" % e)
开发者ID:CIETstudents,项目名称:cloudstack,代码行数:16,代码来源:test_affinity_groups_projects.py

示例13: create_Volume_from_Snapshot

    def create_Volume_from_Snapshot(self, snapshot):
        try:
            self.debug("Creating volume from snapshot: %s" % snapshot.name)

            cmd = createVolume.createVolumeCmd()
            cmd.name = "-".join([
                                self.services["volume"]["diskname"],
                                random_gen()])
            cmd.snapshotid = snapshot.id
            cmd.zoneid = self.zone.id
            cmd.size = self.services["volume"]["size"]
            cmd.account = self.account.name
            cmd.domainid = self.account.domainid
            return cmd
        except Exception as e:
            self.fail("Failed to create volume from snapshot: %s - %s" %
                                                        (snapshot.name, e))
开发者ID:K0zka,项目名称:cloudstack,代码行数:17,代码来源:test_snapshots_improvement.py

示例14: test_vm_instance_name_duplicate_different_accounts

    def test_vm_instance_name_duplicate_different_accounts(self):
        """
        @Desc: Test whether cloudstack allows duplicate vm instance
               names in the diff networks
        @Steps:
        Step1: Set the vm.instancename.flag to true.
        Step2: Deploy a VM with name say webserver01 from account1
               Internal name should be i-<userid>-<vmid>-webserver01
        Step3: Now deploy VM with the same name "webserver01" from account2.
        Step4: Deployment of VM with same name should fail
        """

        if not is_config_suitable(
                apiclient=self.apiclient,
                name='vm.instancename.flag',
                value='true'):
            self.skipTest('vm.instancename.flag should be true. skipping')
        # Step2: Deploy a VM with name say webserver01 from account1
        self.debug("Deploying VM in account: %s" % self.account.name)
        self.services["virtual_machine2"][
            "displayname"] = random_gen(chars=string.ascii_uppercase)
        self.services["virtual_machine2"]["zoneid"] = self.zone.id
        self.services["virtual_machine2"]["template"] = self.template.id
        vm1 = VirtualMachine.create(
            self.apiclient,
            self.services["virtual_machine2"],
            accountid=self.account.name,
            domainid=self.account.domainid,
            serviceofferingid=self.service_offering.id,
        )
        self.cleanup.append(vm1)

        # Step3: Now deploy VM with the same name "webserver01" from account2.
        self.debug("Deploying VM in account: %s" % self.account_2.name)
        with self.assertRaises(Exception):
            vm2 = VirtualMachine.create(
                self.apiclient,
                self.services["virtual_machine2"],
                accountid=self.account_2.name,
                domainid=self.account_2.domainid,
                serviceofferingid=self.service_offering.id,
            )
            self.cleanup.append(vm2)
        # Step4: Deployment of VM with same name should fail
        return
开发者ID:miguelaferreira,项目名称:cosmic-core,代码行数:45,代码来源:test_custom_hostname.py

示例15: deploy_domain

    def deploy_domain(self, domain_data):
        if domain_data['name'] == 'ROOT':
            domain_list = Domain.list(
                api_client=self.api_client,
                name=domain_data['name']
            )
            domain = domain_list[0]
        else:
            self.logger.debug('>>>  DOMAIN  =>  Creating "%s"...', domain_data['name'])
            domain = Domain.create(
                api_client=self.api_client,
                name=domain_data['name'] + ('-' + random_gen() if self.randomizeNames else '')
            )

        self.logger.debug('>>>  DOMAIN  =>  ID: %s  =>  Name: %s  =>  Path: %s  =>  State: %s', domain.id, domain.name,
                          domain.path, domain.state)

        self.deploy_accounts(domain_data['accounts'], domain)
开发者ID:MissionCriticalCloud,项目名称:cosmic,代码行数:18,代码来源:testScenarioManager.py


注:本文中的marvin.lib.utils.random_gen函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。