How to use smart_get_bulk method in autotest

Best Python code snippet using autotest_python

reservations.py

Source:reservations.py Github

copy

Full Screen

...49 :param username: login of the user reserving hosts50 :type username: str51 :raises: AclAccessViolation if user cannot reserve all specified hosts52 """53 hosts = models.Host.smart_get_bulk(hosts_to_reserve)54 if not hosts:55 raise Exception("At least one host must be specified")56 # check if this user can access specified hosts57 user = get_user(username)58 models.AclGroup.check_for_acl_violation_hosts(hosts, user.login)59 user_acl, created = models.AclGroup.objects.get_or_create(name=user.login)60 if created:61 user_acl.users = [user]62 user_acl.save()63 for host in hosts:64 host.aclgroup_set.add(user_acl)65 # and add to reservation acl66 user_acl.hosts.add(*hosts)67 user_acl.on_host_membership_change()68def release(hosts_to_release, username=None):69 """70 Release a collection of hosts from user71 It's OK if user does not own these systems, in which case this does nothing72 :param hosts_to_release: strings or idents for hosts to release73 :type hosts_to_release: list74 :param username: login of the user reserving hosts75 :type username: str76 """77 hosts = models.Host.smart_get_bulk(hosts_to_release)78 if not hosts:79 raise Exception("At least one host must be specified")80 user = get_user(username)81 acls = models.AclGroup.objects.filter(name=user.login)82 if acls:83 user_acl = acls[0]84 user_acl.hosts.remove(*hosts)85 user_acl.on_host_membership_change()86def force_release(hosts_to_release, username=None):87 """88 Force release a collection of hosts from user89 This will remove all ACLs from the hosts90 :param hosts_to_release: strings or idents for hosts to release91 :type hosts_to_release: list92 :param username: login of the user reserving hosts93 :type username: str94 """95 hosts = models.Host.smart_get_bulk(hosts_to_release)96 if not hosts:97 raise Exception("At least one host must be specified")98 user = get_user(username)99 if not user.is_superuser():100 raise Exception("Must be super user to force release")101 acls = models.AclGroup.objects.all()102 for user_acl in acls:103 user_acl.hosts.remove(*hosts)...

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 autotest 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