How to use rand_name method in tempest

Best Python code snippet using tempest_python

datagen.py

Source:datagen.py Github

copy

Full Screen

...73 :param image_id: image id or name74 :returns: BayModelEntity with generated data75 """76 data = {77 "name": data_utils.rand_name('bay'),78 "coe": "kubernetes",79 "tls_disabled": False,80 "network_driver": None,81 "volume_driver": None,82 "labels": {},83 "public": False,84 "dns_nameserver": "8.8.8.8",85 "flavor_id": data_utils.rand_name('bay'),86 "master_flavor_id": data_utils.rand_name('bay'),87 "external_network_id": config.Config.nic_id,88 "keypair_id": data_utils.rand_name('bay'),89 "image_id": data_utils.rand_name('bay')90 }91 data.update(kwargs)92 model = baymodel_model.BayModelEntity.from_dict(data)93 return model94def baymodel_replace_patch_data(path, value=data_utils.rand_name('bay')):95 """Generates random baymodel patch data96 :param path: path to replace97 :param value: value to replace in patch98 :returns: BayModelPatchCollection with generated data99 """100 data = [{101 "path": path,102 "value": value,103 "op": "replace"104 }]105 return baymodelpatch_model.BayModelPatchCollection.from_dict(data)106def baymodel_remove_patch_data(path):107 """Generates baymodel patch data by removing value108 :param path: path to remove109 :returns: BayModelPatchCollection with generated data110 """111 data = [{112 "path": path,113 "op": "remove"114 }]115 return baymodelpatch_model.BayModelPatchCollection.from_dict(data)116def baymodel_data_with_valid_keypair_image_flavor():117 """Generates random baymodel data with valid keypair,image and flavor118 :returns: BayModelEntity with generated data119 """120 return baymodel_data(keypair_id=config.Config.keypair_name,121 image_id=config.Config.image_id,122 flavor_id=config.Config.flavor_id,123 master_flavor_id=config.Config.master_flavor_id)124def baymodel_data_with_missing_image():125 """Generates random baymodel data with missing image126 :returns: BayModelEntity with generated data127 """128 return baymodel_data(keypair_id=config.Config.keypair_name,129 flavor_id=config.Config.flavor_id,130 master_flavor_id=config.Config.master_flavor_id)131def baymodel_data_with_missing_flavor():132 """Generates random baymodel data with missing flavor133 :returns: BayModelEntity with generated data134 """135 return baymodel_data(keypair_id=config.Config.keypair_name,136 image_id=config.Config.image_id)137def baymodel_data_with_missing_keypair():138 """Generates random baymodel data with missing keypair139 :returns: BayModelEntity with generated data140 """141 return baymodel_data(image_id=config.Config.image_id,142 flavor_id=config.Config.flavor_id,143 master_flavor_id=config.Config.master_flavor_id)144def baymodel_valid_data_with_specific_coe(coe):145 """Generates random baymodel data with valid keypair and image146 :param coe: coe147 :returns: BayModelEntity with generated data148 """149 return baymodel_data(keypair_id=config.Config.keypair_name,150 image_id=config.Config.image_id, coe=coe)151def valid_kubernetes_baymodel(is_public=False):152 """Generates a valid kubernetes baymodel with valid data153 :returns: BayModelEntity with generated data154 """155 return baymodel_data(image_id=config.Config.image_id,156 flavor_id=config.Config.flavor_id, public=is_public,157 dns_nameserver=config.Config.dns_nameserver,158 master_flavor_id=config.Config.master_flavor_id,159 keypair_id=config.Config.keypair_name,160 coe="kubernetes",161 cluster_distro=None,162 external_network_id=config.Config.nic_id,163 http_proxy=None, https_proxy=None, no_proxy=None,164 network_driver=None, volume_driver=None, labels={},165 tls_disabled=False)166def bay_data(name=data_utils.rand_name('bay'),167 baymodel_id=data_utils.rand_uuid(),168 node_count=random_int(1, 5), discovery_url=gen_random_ip(),169 bay_create_timeout=random_int(1, 30),170 master_count=random_int(1, 5)):171 """Generates random bay data172 BayModel_id cannot be random for the bay to be valid due to173 validations for the presence of baymodel prior to baymodel174 creation.175 :param name: bay name (must be unique)176 :param baymodel_id: baymodel unique id (must already exist)177 :param node_count: number of agents for bay178 :param discovery_url: url provided for node discovery179 :param bay_create_timeout: timeout in minutes for bay create180 :param master_count: number of master nodes for the bay181 :returns: BayEntity with generated data182 """183 data = {184 "name": name,185 "baymodel_id": baymodel_id,186 "node_count": node_count,187 "discovery_url": None,188 "bay_create_timeout": bay_create_timeout,189 "master_count": master_count190 }191 model = bay_model.BayEntity.from_dict(data)192 return model193def valid_bay_data(baymodel_id, name=data_utils.rand_name('bay'), node_count=1,194 master_count=1, bay_create_timeout=None):195 """Generates random bay data with valid196 :param baymodel_id: baymodel unique id that already exists197 :param name: bay name (must be unique)198 :param node_count: number of agents for bay199 :returns: BayEntity with generated data200 """201 return bay_data(baymodel_id=baymodel_id, name=name,202 master_count=master_count, node_count=node_count,203 bay_create_timeout=bay_create_timeout)204def bay_name_patch_data(name=data_utils.rand_name('bay')):205 """Generates random baymodel patch data206 :param name: name to replace in patch207 :returns: BayPatchCollection with generated data208 """209 data = [{210 "path": "/name",211 "value": name,212 "op": "replace"213 }]214 return baypatch_model.BayPatchCollection.from_dict(data)215def bay_api_addy_patch_data(address='0.0.0.0'):216 """Generates random bay patch data217 :param name: name to replace in patch218 :returns: BayPatchCollection with generated data219 """220 data = [{221 "path": "/api_address",222 "value": address,223 "op": "replace"224 }]225 return baypatch_model.BayPatchCollection.from_dict(data)226def bay_node_count_patch_data(node_count=2):227 """Generates random bay patch data228 :param name: name to replace in patch229 :returns: BayPatchCollection with generated data230 """231 data = [{232 "path": "/node_count",233 "value": node_count,234 "op": "replace"235 }]236 return baypatch_model.BayPatchCollection.from_dict(data)237def cert_data(cluster_uuid, csr_data):238 data = {239 "cluster_uuid": cluster_uuid,240 "csr": csr_data}241 model = cert_model.CertEntity.from_dict(data)242 return model243def cluster_template_data(**kwargs):244 """Generates random cluster_template data245 Keypair and image id cannot be random for the cluster_template to be valid246 due to validations for the presence of keypair and image id prior to247 cluster_template creation.248 :param keypair_id: keypair name249 :param image_id: image id or name250 :returns: ClusterTemplateEntity with generated data251 """252 data = {253 "name": data_utils.rand_name('cluster'),254 "coe": "kubernetes",255 "tls_disabled": False,256 "network_driver": None,257 "volume_driver": None,258 "labels": {},259 "public": False,260 "dns_nameserver": "8.8.8.8",261 "flavor_id": data_utils.rand_name('cluster'),262 "master_flavor_id": data_utils.rand_name('cluster'),263 "external_network_id": config.Config.nic_id,264 "keypair_id": data_utils.rand_name('cluster'),265 "image_id": data_utils.rand_name('cluster')266 }267 data.update(kwargs)268 model = cluster_template_model.ClusterTemplateEntity.from_dict(data)269 return model270def cluster_template_replace_patch_data(path,271 value=data_utils.rand_name('cluster')):272 """Generates random ClusterTemplate patch data273 :param path: path to replace274 :param value: value to replace in patch275 :returns: ClusterTemplatePatchCollection with generated data276 """277 data = [{278 "path": path,279 "value": value,280 "op": "replace"281 }]282 collection = cluster_templatepatch_model.ClusterTemplatePatchCollection283 return collection.from_dict(data)284def cluster_template_remove_patch_data(path):285 """Generates ClusterTemplate patch data by removing value286 :param path: path to remove287 :returns: ClusterTemplatePatchCollection with generated data288 """289 data = [{290 "path": path,291 "op": "remove"292 }]293 collection = cluster_templatepatch_model.ClusterTemplatePatchCollection294 return collection.from_dict(data)295def cluster_template_name_patch_data(name=data_utils.rand_name('cluster')):296 """Generates random cluster_template patch data297 :param name: name to replace in patch298 :returns: ClusterTemplatePatchCollection with generated data299 """300 data = [{301 "path": "/name",302 "value": name,303 "op": "replace"304 }]305 collection = cluster_templatepatch_model.ClusterTemplatePatchCollection306 return collection.from_dict(data)307def cluster_template_flavor_patch_data(flavor=data_utils.rand_name('cluster')):308 """Generates random cluster_template patch data309 :param flavor: flavor to replace in patch310 :returns: ClusterTemplatePatchCollection with generated data311 """312 data = [{313 "path": "/flavor_id",314 "value": flavor,315 "op": "replace"316 }]317 collection = cluster_templatepatch_model.ClusterTemplatePatchCollection318 return collection.from_dict(data)319def cluster_template_data_with_valid_keypair_image_flavor():320 """Generates random clustertemplate data with valid data321 :returns: ClusterTemplateEntity with generated data322 """323 master_flavor = config.Config.master_flavor_id324 return cluster_template_data(keypair_id=config.Config.keypair_name,325 image_id=config.Config.image_id,326 flavor_id=config.Config.flavor_id,327 master_flavor_id=master_flavor)328def cluster_template_data_with_missing_image():329 """Generates random cluster_template data with missing image330 :returns: ClusterTemplateEntity with generated data331 """332 return cluster_template_data(333 keypair_id=config.Config.keypair_name,334 flavor_id=config.Config.flavor_id,335 master_flavor_id=config.Config.master_flavor_id)336def cluster_template_data_with_missing_flavor():337 """Generates random cluster_template data with missing flavor338 :returns: ClusterTemplateEntity with generated data339 """340 return cluster_template_data(keypair_id=config.Config.keypair_name,341 image_id=config.Config.image_id)342def cluster_template_data_with_missing_keypair():343 """Generates random cluster_template data with missing keypair344 :returns: ClusterTemplateEntity with generated data345 """346 return cluster_template_data(347 image_id=config.Config.image_id,348 flavor_id=config.Config.flavor_id,349 master_flavor_id=config.Config.master_flavor_id)350def cluster_template_valid_data_with_specific_coe(coe):351 """Generates random cluster_template data with valid keypair and image352 :param coe: coe353 :returns: ClusterTemplateEntity with generated data354 """355 return cluster_template_data(keypair_id=config.Config.keypair_name,356 image_id=config.Config.image_id, coe=coe)357def valid_cluster_template(is_public=False):358 """Generates a valid swarm-mode cluster_template with valid data359 :returns: ClusterTemplateEntity with generated data360 """361 master_flavor_id = config.Config.master_flavor_id362 return cluster_template_data(363 image_id=config.Config.image_id,364 flavor_id=config.Config.flavor_id,365 public=is_public,366 dns_nameserver=config.Config.dns_nameserver,367 master_flavor_id=master_flavor_id,368 coe=config.Config.coe,369 cluster_distro=None,370 external_network_id=config.Config.nic_id,371 http_proxy=None, https_proxy=None,372 no_proxy=None, network_driver=config.Config.network_driver,373 volume_driver=None, labels={},374 docker_storage_driver=config.Config.docker_storage_driver,375 tls_disabled=False)376def cluster_data(name=data_utils.rand_name('cluster'),377 cluster_template_id=data_utils.rand_uuid(),378 node_count=random_int(1, 5), discovery_url=gen_random_ip(),379 create_timeout=None,380 master_count=random_int(1, 5)):381 """Generates random cluster data382 cluster_template_id cannot be random for the cluster to be valid due to383 validations for the presence of clustertemplate prior to clustertemplate384 creation.385 :param name: cluster name (must be unique)386 :param cluster_template_id: clustertemplate unique id (must already exist)387 :param node_count: number of agents for cluster388 :param discovery_url: url provided for node discovery389 :param create_timeout: timeout in minutes for cluster create390 :param master_count: number of master nodes for the cluster391 :returns: ClusterEntity with generated data392 """393 timeout = create_timeout or config.Config.cluster_creation_timeout394 data = {395 "name": name,396 "cluster_template_id": cluster_template_id,397 "keypair": config.Config.keypair_name,398 "node_count": node_count,399 "discovery_url": None,400 "create_timeout": timeout,401 "master_count": master_count402 }403 model = cluster_model.ClusterEntity.from_dict(data)404 return model405def valid_cluster_data(cluster_template_id,406 name=data_utils.rand_name('cluster'),407 node_count=1, master_count=1, create_timeout=None):408 """Generates random cluster data with valid409 :param cluster_template_id: clustertemplate unique id that already exists410 :param name: cluster name (must be unique)411 :param node_count: number of agents for cluster412 :returns: ClusterEntity with generated data413 """414 return cluster_data(cluster_template_id=cluster_template_id, name=name,415 master_count=master_count, node_count=node_count,416 create_timeout=create_timeout)417def cluster_name_patch_data(name=data_utils.rand_name('cluster')):418 """Generates random clustertemplate patch data419 :param name: name to replace in patch420 :returns: ClusterPatchCollection with generated data421 """422 data = [{423 "path": "/name",424 "value": name,425 "op": "replace"426 }]427 return clusterpatch_model.ClusterPatchCollection.from_dict(data)428def cluster_api_addy_patch_data(address='0.0.0.0'):429 """Generates random cluster patch data430 :param name: name to replace in patch431 :returns: ClusterPatchCollection with generated data...

Full Screen

Full Screen

ccbr_get_consensus_peaks.py

Source:ccbr_get_consensus_peaks.py Github

copy

Full Screen

1import os2import argparse3import uuid4import pandas5parser = argparse.ArgumentParser(description="""6Get consensus peaks from multiple narrowPeak files7This is similar to the consensus MAX peaks from https://dx.doi.org/10.5936%2Fcsbj.2014010028On Biowulf the following modules need to be pre-loaded9module load bedops10module load bedtools11module load ucsc12""",formatter_class=argparse.RawTextHelpFormatter)13parser.add_argument('--peakfiles', required = True, nargs = '+', help = 'space separated list of peakfiles')14parser.add_argument('--outbed', required = True, dest = 'outbed', help = 'consensus output bed file')15parser.add_argument('--nofilter', action = 'store_true', default = 'store_false',required = False,dest = 'nofilter',help = ' do not filter keep all peaks with score')16deleteFiles=[]17args = parser.parse_args()18print(args)19out=open(args.outbed,'w')20filter=0.521rand_name=str(uuid.uuid4())22# concat23cmd="cat"24for p in args.peakfiles:25 cmd+=" "+p26cmd+=" | cut -f1-3 > "+rand_name+".concat.bed"27deleteFiles.append(rand_name+".concat.bed")28print(cmd)29os.system(cmd)30# sort and merge31cmd="bedSort "+rand_name+".concat.bed "+rand_name+".concat.bed && bedtools merge -i "+rand_name+".concat.bed > "+rand_name+".merged.bed"32deleteFiles.append(rand_name+".merged.bed")33print(cmd)34os.system(cmd)35# check merged count36npeaks=len(open(rand_name+".merged.bed").readlines())37if (npeaks==0):38 out.close()39 exit("Number of merged peaks = 0")40count=041for p in args.peakfiles:42 count+=143 sortedfile=p + ".sorted." + rand_name44 countfile=p + ".counts." + rand_name45 cmd = "cut -f1-3 " + p + " > " + sortedfile + " && bedSort " + sortedfile + " " + sortedfile46 print(cmd)47 os.system(cmd)48 cmd = "bedmap --delim '\t' --echo-ref-name --count " + rand_name + ".merged.bed " + sortedfile + "|awk -F'\t\' -v OFS='\t' '{if ($2>1){$2=1}{print}}' > " + countfile49 print(cmd)50 os.system(cmd)51 deleteFiles.append(countfile)52 deleteFiles.append(sortedfile)53 if count==1:54 df=pandas.read_csv(countfile,delimiter="\t")55 df.columns=["peakid",countfile]56 else:57 dfx=pandas.read_csv(countfile,delimiter="\t")58 dfx.columns=["peakid",countfile]59 df=df.merge(dfx,on="peakid")60df=df.set_index("peakid")61df=df.sum(axis=1)/len(df.columns)62df=pandas.DataFrame({'peakid':df.index,'score':df.values})63for index, row in df.iterrows():64 chrom,coords=row["peakid"].split(":")65 start,end=coords.split("-")66 if args.nofilter==True:67 out.write("%s\t%s\t%s\t%s\t%.3f\t.\n"%(chrom,start,end,row["peakid"],float(row["score"])))68 elif float(row["score"])>filter:69 out.write("%s\t%s\t%s\t%s\t%.3f\t.\n"%(chrom,start,end,row["peakid"],float(row["score"])))70out.close()71for f in deleteFiles:72 os.remove(f)...

Full Screen

Full Screen

utils.py

Source:utils.py Github

copy

Full Screen

1import os2import uuid3from functools import wraps4from django.conf import settings5from django.contrib.sites.models import Site6from django.core.urlresolvers import reverse7def absolute_url_reverse(url_name=None, **kwargs):8 domain = Site.objects.get_current().domain9 path = '/'10 if url_name:11 path = reverse(url_name, **kwargs)12 full_url = "{}://{}{}".format(settings.DEFAULT_HTTP_PROTOCOL,13 domain, path)14 return full_url15def generate_upload_path(instance, filename, dirname=None):16 """17 Generate path with random file name for FileField.18 """19 ext = os.path.splitext(filename)[1].lstrip('.')20 rand_name = "{}.{}".format(uuid.uuid4().hex, ext)21 if dirname:22 rand_name = "{}/{}".format(dirname, rand_name)23 return rand_name24def disable_for_loaddata(signal_handler):25 """26 Decorator that turns off signal handlers when loading fixture data.27 """28 @wraps(signal_handler)29 def wrapper(*args, **kwargs):30 if kwargs.get('raw'):31 return32 signal_handler(*args, **kwargs)...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run tempest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful