How to use _check_acls method in autotest

Best Python code snippet using autotest_python

zookeeper.py

Source:zookeeper.py Github

copy

Full Screen

...26def __virtual__():27 if "zookeeper.create" in __salt__:28 return __virtualname__29 return (False, "zookeeper module could not be loaded")30def _check_acls(left, right):31 first = not bool(set(left) - set(right))32 second = not bool(set(right) - set(left))33 return first and second34def present(35 name,36 value,37 acls=None,38 ephemeral=False,39 sequence=False,40 makepath=False,41 version=-1,42 profile=None,43 hosts=None,44 scheme=None,45 username=None,46 password=None,47 default_acl=None,48):49 """50 Make sure znode is present in the correct state with the correct acls51 name52 path to znode53 value54 value znode should be set to55 acls56 list of acl dictionaries to set on znode (make sure the ones salt is connected with are included)57 Default: None58 ephemeral59 Boolean to indicate if ephemeral znode should be created60 Default: False61 sequence62 Boolean to indicate if znode path is suffixed with a unique index63 Default: False64 makepath65 Boolean to indicate if the parent paths should be created66 Default: False67 version68 For updating, specify the version which should be updated69 Default: -1 (always match)70 profile71 Configured Zookeeper profile to authenticate with (Default: None)72 hosts73 Lists of Zookeeper Hosts (Default: '127.0.0.1:2181)74 scheme75 Scheme to authenticate with (Default: 'digest')76 username77 Username to authenticate (Default: None)78 password79 Password to authenticate (Default: None)80 default_acl81 Default acls to assign if a node is created in this connection (Default: None)82 .. code-block:: yaml83 add znode:84 zookeeper.present:85 - name: /test/name86 - value: gtmanfred87 - makepath: True88 update znode:89 zookeeper.present:90 - name: /test/name91 - value: daniel92 - acls:93 - username: daniel94 password: test95 read: true96 - username: gtmanfred97 password: test98 read: true99 write: true100 create: true101 delete: true102 admin: true103 - makepath: True104 """105 ret = {106 "name": name,107 "result": False,108 "comment": "Failed to setup znode {0}".format(name),109 "changes": {},110 }111 connkwargs = {112 "profile": profile,113 "hosts": hosts,114 "scheme": scheme,115 "username": username,116 "password": password,117 "default_acl": default_acl,118 }119 if acls is None:120 chk_acls = []121 else:122 chk_acls = [__salt__["zookeeper.make_digest_acl"](**acl) for acl in acls]123 if __salt__["zookeeper.exists"](name, **connkwargs):124 cur_value = __salt__["zookeeper.get"](name, **connkwargs)125 cur_acls = __salt__["zookeeper.get_acls"](name, **connkwargs)126 if cur_value == value and _check_acls(cur_acls, chk_acls):127 ret["result"] = True128 ret[129 "comment"130 ] = "Znode {0} is already set to the correct value with the correct acls".format(131 name132 )133 return ret134 elif __opts__["test"] is True:135 ret["result"] = None136 ret["comment"] = "Znode {0} is will be updated".format(name)137 ret["changes"]["old"] = {}138 ret["changes"]["new"] = {}139 if value != cur_value:140 ret["changes"]["old"]["value"] = cur_value141 ret["changes"]["new"]["value"] = value142 if not _check_acls(chk_acls, cur_acls):143 ret["changes"]["old"]["acls"] = cur_acls144 ret["changes"]["new"]["acls"] = chk_acls145 return ret146 else:147 value_result, acl_result = True, True148 changes = {}149 if value != cur_value:150 __salt__["zookeeper.set"](name, value, version, **connkwargs)151 new_value = __salt__["zookeeper.get"](name, **connkwargs)152 value_result = new_value == value153 changes.setdefault("new", {}).setdefault("value", new_value)154 changes.setdefault("old", {}).setdefault("value", cur_value)155 if chk_acls and not _check_acls(chk_acls, cur_acls):156 __salt__["zookeeper.set_acls"](name, acls, version, **connkwargs)157 new_acls = __salt__["zookeeper.get_acls"](name, **connkwargs)158 acl_result = _check_acls(new_acls, chk_acls)159 changes.setdefault("new", {}).setdefault("acls", new_acls)160 changes.setdefault("old", {}).setdefault("value", cur_acls)161 ret["changes"] = changes162 if value_result and acl_result:163 ret["result"] = True164 ret["comment"] = "Znode {0} successfully updated".format(name)165 return ret166 if __opts__["test"] is True:167 ret["result"] = None168 ret["comment"] = "{0} is will be created".format(name)169 ret["changes"]["old"] = {}170 ret["changes"]["new"] = {}171 ret["changes"]["new"]["acls"] = chk_acls172 ret["changes"]["new"]["value"] = value173 return ret174 __salt__["zookeeper.create"](175 name, value, acls, ephemeral, sequence, makepath, **connkwargs176 )177 value_result, acl_result = True, True178 changes = {"old": {}}179 new_value = __salt__["zookeeper.get"](name, **connkwargs)180 value_result = new_value == value181 changes.setdefault("new", {}).setdefault("value", new_value)182 new_acls = __salt__["zookeeper.get_acls"](name, **connkwargs)183 acl_result = acls is None or _check_acls(new_acls, chk_acls)184 changes.setdefault("new", {}).setdefault("acls", new_acls)185 ret["changes"] = changes186 if value_result and acl_result:187 ret["result"] = True188 ret["comment"] = "Znode {0} successfully created".format(name)189 return ret190def absent(191 name,192 version=-1,193 recursive=False,194 profile=None,195 hosts=None,196 scheme=None,197 username=None,198 password=None,199 default_acl=None,200):201 """202 Make sure znode is absent203 name204 path to znode205 version206 Specify the version which should be deleted207 Default: -1 (always match)208 recursive209 Boolean to indicate if children should be recursively deleted210 Default: False211 profile212 Configured Zookeeper profile to authenticate with (Default: None)213 hosts214 Lists of Zookeeper Hosts (Default: '127.0.0.1:2181)215 scheme216 Scheme to authenticate with (Default: 'digest')217 username218 Username to authenticate (Default: None)219 password220 Password to authenticate (Default: None)221 default_acl222 Default acls to assign if a node is created in this connection (Default: None)223 .. code-block:: yaml224 delete znode:225 zookeeper.absent:226 - name: /test227 - recursive: True228 """229 ret = {230 "name": name,231 "result": False,232 "comment": "Failed to delete znode {0}".format(name),233 "changes": {},234 }235 connkwargs = {236 "profile": profile,237 "hosts": hosts,238 "scheme": scheme,239 "username": username,240 "password": password,241 "default_acl": default_acl,242 }243 if __salt__["zookeeper.exists"](name, **connkwargs) is False:244 ret["result"] = True245 ret["comment"] = "Znode {0} does not exist".format(name)246 return ret247 changes = {}248 changes["value"] = __salt__["zookeeper.get"](name, **connkwargs)249 changes["acls"] = __salt__["zookeeper.get_acls"](name, **connkwargs)250 if recursive is True:251 changes["children"] = __salt__["zookeeper.get_children"](name, **connkwargs)252 if __opts__["test"] is True:253 ret["result"] = None254 ret["comment"] = "Znode {0} will be removed".format(name)255 ret["changes"]["old"] = changes256 return ret257 __salt__["zookeeper.delete"](name, version, recursive, **connkwargs)258 if __salt__["zookeeper.exists"](name, **connkwargs) is False:259 ret["result"] = True260 ret["comment"] = "Znode {0} has been removed".format(name)261 ret["changes"]["old"] = changes262 return ret263def acls(264 name,265 acls,266 version=-1,267 profile=None,268 hosts=None,269 scheme=None,270 username=None,271 password=None,272 default_acl=None,273):274 """275 Update acls on a znode276 name277 path to znode278 acls279 list of acl dictionaries to set on znode280 version281 Specify the version which should be deleted282 Default: -1 (always match)283 profile284 Configured Zookeeper profile to authenticate with (Default: None)285 hosts286 Lists of Zookeeper Hosts (Default: '127.0.0.1:2181)287 scheme288 Scheme to authenticate with (Default: 'digest')289 username290 Username to authenticate (Default: None)291 password292 Password to authenticate (Default: None)293 default_acl294 Default acls to assign if a node is created in this connection (Default: None)295 .. code-block:: yaml296 update acls:297 zookeeper.acls:298 - name: /test/name299 - acls:300 - username: daniel301 password: test302 all: True303 - username: gtmanfred304 password: test305 all: True306 """307 ret = {308 "name": name,309 "result": False,310 "comment": "Failed to set acls on znode {0}".format(name),311 "changes": {},312 }313 connkwargs = {314 "profile": profile,315 "hosts": hosts,316 "scheme": scheme,317 "username": username,318 "password": password,319 "default_acl": default_acl,320 }321 if isinstance(acls, dict):322 acls = [acls]323 chk_acls = [__salt__["zookeeper.make_digest_acl"](**acl) for acl in acls]324 if not __salt__["zookeeper.exists"](name, **connkwargs):325 ret["comment"] += ": Znode does not exist"326 return ret327 cur_acls = __salt__["zookeeper.get_acls"](name, **connkwargs)328 if _check_acls(cur_acls, chk_acls):329 ret["result"] = True330 ret["comment"] = "Znode {0} acls already set".format(name)331 return ret332 if __opts__["test"] is True:333 ret["result"] = None334 ret["comment"] = "Znode {0} acls will be updated".format(name)335 ret["changes"]["old"] = cur_acls336 ret["changes"]["new"] = chk_acls337 return ret338 __salt__["zookeeper.set_acls"](name, acls, version, **connkwargs)339 new_acls = __salt__["zookeeper.get_acls"](name, **connkwargs)340 ret["changes"] = {"old": cur_acls, "new": new_acls}341 if _check_acls(new_acls, chk_acls):342 ret["result"] = True343 ret["comment"] = "Znode {0} acls updated".format(name)344 return ret345 ret["comment"] = "Znode {0} acls failed to update".format(name)...

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