+ def InitScripts(self, n = 2):
+ initscript_ids = []
+ AddInitScript = self.debug(api.AddInitScript)
+ GetInitScripts = self.debug(api.GetInitScripts)
+ UpdateInitScript = self.debug(api.UpdateInitScript)
+ for i in range(n):
+ # Add Peer
+ initscript_fields = random_initscript()
+ initscript_id = AddInitScript(auth, initscript_fields)
+
+ # Should return a unique id
+ self.isunique(initscript_id, initscript_ids, 'AddInitScript - isunique')
+ initscript_ids.append(initscript_id)
+ initscripts = GetInitScripts(auth, [initscript_id])
+ if initscripts is None: continue
+ initscript = initscripts[0]
+ self.isequal(initscript, initscript_fields, 'AddInitScript - isequal')
+
+ # Update Peer
+ initscript_fields = random_initscript()
+ result = UpdateInitScript(auth, initscript_id, initscript_fields)
+
+ # Check again
+ initscripts = GetInitScripts(auth, [initscript_id])
+ if initscripts is None: continue
+ initscript = initscripts[0]
+ self.isequal(initscript, initscript_fields, 'UpdateInitScript - isequal')
+
+ initscripts = GetInitScripts(auth, initscript_ids)
+ if initscripts is not None:
+ self.islistequal(initscript_ids, [i['initscript_id'] for i in initscripts], 'GetInitScripts -isequal')
+
+ if self.config.verbose:
+ utils.header("Added initscripts: %s" % initscript_ids)
+
+ return initscript_ids
+
+ def DeleteInitScripts(self):
+ # Delete all initscripts
+ DeleteInitScript = self.debug(api.DeleteInitScript)
+ GetInitScripts = self.debug(api.GetInitScripts)
+ for initscript_id in self.initscript_ids:
+ result = DeleteInitScript(auth, initscript_id)
+
+ # Check if peers are deleted
+ initscripts = GetInitScripts(auth, self.initscript_ids)
+ self.islistequal(initscripts, [], 'DeletInitScript - check')
+
+ if self.config.verbose:
+ utils.header("Deleted initscripts: %s" % self.initscript_ids)
+ self.initscript_ids =[]
+
+ def Roles(self, n = 2):
+ role_ids = []
+ AddRole = self.debug(api.AddRole)
+ GetRoles = self.debug(api.GetRoles)
+ for i in range(n):
+ # Add Role
+ role_fields = random_role()
+ role_id = role_fields['role_id']
+ name = role_fields['name']
+ AddRole(auth, role_id, name)
+
+ # Should return a unique id
+ self.isunique(role_id, role_ids, 'AddRole - isunique')
+ role_ids.append(role_id)
+ roles = GetRoles(auth)
+ if roles is None: continue
+ roles = filter(lambda x: x['role_id'] in [role_id], roles)
+ role = roles[0]
+ self.isequal(role, role_fields, 'AddRole - isequal')
+
+ roles = GetRoles(auth)
+ if roles is not None:
+ roles = filter(lambda x: x['role_id'] in role_ids, roles)
+ self.islistequal(role_ids, [r['role_id'] for r in roles], 'GetRoles - isequal')
+
+ if self.config.verbose:
+ utils.header("Added roles: %s" % role_ids)
+
+ return role_ids
+
+ def DeleteRoles(self):
+ # Delete all roles
+ DeleteRole = self.debug(api.DeleteRole)
+ GetRoles = self.debug(api.GetRoles)
+ for role_id in self.role_ids:
+ result = DeleteRole(auth, role_id)
+
+ # Check if peers are deleted
+ roles = GetRoles(auth)
+ roles = filter(lambda x: x['role_id'] in self.role_ids, roles)
+ self.islistequal(roles, [], 'DeleteRole - check' % self.role_ids)
+
+ if self.config.verbose:
+ utils.header("Deleted roles: %s" % self.role_ids)
+ self.role_ids =[]
+