rename attributes to slice_attribute_types
[plcapi.git] / Test.py
1 #!/usr/bin/env ./Shell.py
2 #
3 # Test script example
4 #
5 # Mark Huang <mlhuang@cs.princeton.edu>
6 # Copyright (C) 2006 The Trustees of Princeton University
7 #
8 # $Id: Test.py,v 1.9 2006/10/11 15:46:09 mlhuang Exp $
9 #
10
11 from pprint import pprint
12 from string import letters, digits, punctuation
13 import re
14 import socket
15 import struct
16
17 from random import Random
18 random = Random()
19
20 def randfloat(min = 0.0, max = 1.0):
21     return float(min) + (random.random() * (float(max) - float(min)))
22
23 def randint(min = 0, max = 1):
24     return int(randfloat(min, max + 1))
25
26 # See "2.2 Characters" in the XML specification:
27 #
28 # #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD]
29 # avoiding
30 # [#x7F-#x84], [#x86-#x9F], [#xFDD0-#xFDDF]
31
32 low_xml_chars  = map(unichr, [0x9, 0xA, 0xD])
33 low_xml_chars += map(unichr, xrange(0x20, 0x7F - 1))
34 low_xml_chars += map(unichr, xrange(0x84 + 1, 0x86 - 1))
35 low_xml_chars += map(unichr, xrange(0x9F + 1, 0xFF))
36 valid_xml_chars  = list(low_xml_chars)
37 valid_xml_chars += map(unichr, xrange(0xFF + 1, 0xD7FF))
38 valid_xml_chars += map(unichr, xrange(0xE000, 0xFDD0 - 1))
39 valid_xml_chars += map(unichr, xrange(0xFDDF + 1, 0xFFFD))
40
41 def randstr(length, pool = valid_xml_chars, encoding = "utf-8"):
42     sample = random.sample(pool, min(length, len(pool)))
43     while True:
44         s = u''.join(sample)
45         bytes = len(s.encode(encoding))
46         if bytes > length:
47             sample.pop()
48         elif bytes < length:
49             sample += random.sample(pool, min(length - bytes, len(pool)))
50             random.shuffle(sample)
51         else:
52             break
53     return s
54
55 def randhostname():
56     # 1. Each part begins and ends with a letter or number.
57     # 2. Each part except the last can contain letters, numbers, or hyphens.
58     # 3. Each part is between 1 and 64 characters, including the trailing dot.
59     # 4. At least two parts.
60     # 5. Last part can only contain between 2 and 6 letters.
61     hostname = 'a' + randstr(61, letters + digits + '-') + '1.' + \
62                'b' + randstr(61, letters + digits + '-') + '2.' + \
63                'c' + randstr(5, letters)
64     return hostname
65
66 def unicmp(a, b, encoding = "utf-8"):
67     """
68     When connected directly to the DB, values are returned as raw
69     8-bit strings that may need to be decoded (as UTF-8 by default) in
70     order to compare them against expected Python Unicode strings.
71     """
72     
73     is8bit = re.compile("[\x80-\xff]").search
74     if isinstance(a, str) and is8bit(a):
75         a = unicode(a, encoding)
76     if isinstance(b, str) and is8bit(b):
77         b = unicode(b, encoding)
78     return a == b
79
80 admin = {'AuthMethod': "capability",
81          'Username': config.PLC_API_MAINTENANCE_USER,
82          'AuthString': config.PLC_API_MAINTENANCE_PASSWORD,
83          'Role': "admin"}
84
85 user = {'AuthMethod': "password",
86         'Role': "user"}
87
88 pi = {'AuthMethod': "password",
89       'Role': "pi"}
90
91 tech = {'AuthMethod': "password",
92         'Role': "tech"}
93
94 # Add sites
95 site_ids = []
96 for i in range(3):
97     name = randstr(254)
98     abbreviated_name = randstr(50)
99     login_base = randstr(20, letters).lower()
100     latitude = int(randfloat(-90.0, 90.0) * 1000) / 1000.0
101     longitude = int(randfloat(-180.0, 180.0) * 1000) / 1000.0
102
103     # Add site
104     print "AdmAddSite(%s)" % login_base,
105     site_id = AdmAddSite(admin, name, abbreviated_name, login_base,
106                          {'latitude': latitude, 'longitude': longitude})
107
108     # Should return a unique site_id
109     assert site_id not in site_ids
110     site_ids.append(site_id)
111     print "=>", site_id
112
113     # Check site
114     print "AdmGetSites(%d)" % site_id,
115     site = AdmGetSites(admin, [site_id])[0]
116     for key in 'name', 'abbreviated_name', 'login_base', 'latitude', 'longitude', 'site_id':
117         assert unicmp(site[key], locals()[key])
118     print "=> OK"
119
120     # Update site
121     name = randstr(254)
122     abbreviated_name = randstr(50)
123     latitude = int(randfloat(-90.0, 90.0) * 1000) / 1000.0
124     longitude = int(randfloat(-180.0, 180.0) * 1000) / 1000.0
125     max_slices = 10
126     print "AdmUpdateSite(%s)" % login_base,
127     AdmUpdateSite(admin, site_id, {'name': name, 'abbreviated_name': abbreviated_name,
128                                    'latitude': latitude, 'longitude': longitude,
129                                    'max_slices': max_slices})
130     site = AdmGetSites(admin, [site_id])[0]
131     for key in 'name', 'abbreviated_name', 'latitude', 'longitude', 'max_slices':
132         assert unicmp(site[key], locals()[key])
133     print "=> OK"
134
135 print "AdmGetSites",
136 sites = AdmGetSites(admin, site_ids)
137 assert set(site_ids) == set([site['site_id'] for site in sites])
138 print "=>", site_ids
139
140 print "AdmGetAllRoles",
141 role_ids = AdmGetAllRoles(admin)
142 roles = dict(zip(role_ids.values(), map(int, role_ids.keys())))
143 print "=>", role_ids
144
145 # Add users
146 person_ids = []
147 for auth in user, pi, tech:
148     first_name = randstr(128)
149     last_name = randstr(128)
150     # 119 + 1 + 64 + 64 + 6 = 254
151     email = (randstr(119, letters + digits) + "@" + randhostname()).lower()
152     bio = randstr(254)
153     # Accounts are disabled by default
154     enabled = False
155
156     auth['Username'] = email
157     auth['AuthString'] = randstr(254)
158
159     print "AdmAddPerson(%s)" % email,
160     person_id = AdmAddPerson(admin, first_name, last_name,
161                              {'email': email, 'bio': bio,
162                               'password': auth['AuthString']})
163
164     # Should return a unique person_id
165     assert person_id not in person_ids
166     person_ids.append(person_id)
167     print "=>", person_id
168
169     # Check account
170     print "AdmGetPersons(%d)" % person_id,
171     person = AdmGetPersons(admin, [person_id])[0]
172     for key in 'first_name', 'last_name', 'email', 'bio', 'person_id', 'enabled':
173         assert unicmp(person[key], locals()[key])
174     print "=> OK"
175
176     # Update account
177     first_name = randstr(128)
178     last_name = randstr(128)
179     bio = randstr(254)
180     print "AdmUpdatePerson(%d)" % person_id,
181     AdmUpdatePerson(admin, person_id, {'first_name': first_name,
182                                        'last_name': last_name,
183                                        'bio': bio})
184     person = AdmGetPersons(admin, [person_id])[0]
185     for key in 'first_name', 'last_name', 'email', 'bio':
186         assert unicmp(person[key], locals()[key])
187     print "=> OK"
188
189     # Enable account
190     print "AdmSetPersonEnabled(%d, True)" % person_id,
191     AdmSetPersonEnabled(admin, person_id, True)
192     person = AdmGetPersons(admin, [person_id])[0]
193     assert person['enabled']
194     print "=> OK"
195
196     # Add role
197     role_id = roles[auth['Role']]
198     print "AdmGrantRoleToPerson(%d, %d)" % (person_id, role_id),
199     AdmGrantRoleToPerson(admin, person_id, role_id)
200     print "=> OK"
201
202     print "AdmGetPersonRoles(%d)" % person_id,
203     person_roles = AdmGetPersonRoles(admin, person_id)
204     person_role_ids = map(int, person_roles.keys())
205     assert [role_id] == person_role_ids
206     person = AdmGetPersons(admin, [person_id])[0]
207     assert [role_id] == person['role_ids']
208     print "=>", person_role_ids
209
210     # Associate account with each site
211     for site_id in site_ids:
212         print "AdmAddPersonToSite(%d, %d)" % (person_id, site_id),
213         AdmAddPersonToSite(admin, person_id, site_id)
214         print "=> OK"
215
216         print "AdmGetSitePersons(%d)" % site_id,
217         site_person_ids = AdmGetSitePersons(admin, site_id)
218         assert person_id in site_person_ids
219         print "=>", site_person_ids
220
221     # Make sure it really did it
222     print "AdmGetPersonSites(%d)" % person_id,
223     person_site_ids = AdmGetPersonSites(auth, person_id)
224     assert set(site_ids) == set(person_site_ids)
225     person = AdmGetPersons(admin, [person_id])[0]
226     assert set(site_ids) == set(person['site_ids'])
227     print "=>", person_site_ids
228
229     # First site should be the primary site
230     print "AdmSetPersonPrimarySite(%d, %d)" % (person_id, person_site_ids[1]),
231     AdmSetPersonPrimarySite(auth, person_id, person_site_ids[1])
232     assert AdmGetPersonSites(auth, person_id)[0] == person_site_ids[1]
233     person = AdmGetPersons(admin, [person_id])[0]
234     assert person['site_ids'][0] == person_site_ids[1]
235     print "=> OK"
236
237     # Check authentication
238     print "AdmAuthCheck(%s)" % auth['Username'],
239     assert AdmAuthCheck(auth)
240     print "=> OK"
241
242 print "AdmGetPersons",
243 persons = AdmGetPersons(admin, person_ids)
244 assert set(person_ids) == set([person['person_id'] for person in persons])
245 print "=>", person_ids
246
247 # Verify PI role
248 for person in persons:
249     if 'pi' in person['roles']:
250         assert AdmIsPersonInRole(admin, pi['Username'], roles['pi'])
251
252 # Add node groups
253 nodegroup_ids = []
254 for i in range(3):
255     name = randstr(50)
256     description = randstr(200)
257     print "AdmAddNodeGroup",
258     nodegroup_id = AdmAddNodeGroup(admin, name, description)
259
260     # Should return a unique nodegroup_id
261     assert nodegroup_id not in nodegroup_ids
262     nodegroup_ids.append(nodegroup_id)
263     print "=>", nodegroup_id
264
265     # Check nodegroup
266     print "AdmGetNodeGroups(%d)" % nodegroup_id,
267     nodegroup = AdmGetNodeGroups(admin, [nodegroup_id])[0]
268     for key in 'name', 'description', 'nodegroup_id':
269         assert unicmp(nodegroup[key], locals()[key])
270     print "=> OK"
271
272     # Update node group
273     name = randstr(50)
274     description = randstr(200)
275     print "AdmUpdateNodeGroup",
276     AdmUpdateNodeGroup(admin, nodegroup_id, name, description)
277     nodegroup = AdmGetNodeGroups(admin, [nodegroup_id])[0]
278     for key in 'name', 'description', 'nodegroup_id':
279         assert unicmp(nodegroup[key], locals()[key])
280     print "=> OK"
281
282 print "AdmGetNodeGroups",
283 nodegroups = AdmGetNodeGroups(admin, nodegroup_ids)
284 assert set(nodegroup_ids) == set([nodegroup['nodegroup_id'] for nodegroup in nodegroups])
285 print "=>", nodegroup_ids
286
287 # Add nodes
288 node_ids = []
289 for site_id in site_ids:
290     for i in range(3):
291         hostname = randhostname()
292         boot_state = 'inst'
293         model = randstr(255)
294
295         # Add node
296         print "AdmAddNode(%s)" % hostname,
297         node_id = AdmAddNode(admin, site_id, hostname, boot_state,
298                              {'model': model})
299
300         # Should return a unique node_id
301         assert node_id not in node_ids
302         node_ids.append(node_id)
303         print "=>", node_id
304
305         # Check node
306         print "AdmGetNodes(%d)" % node_id,
307         node = AdmGetNodes(admin, [node_id])[0]
308         for key in 'hostname', 'boot_state', 'model', 'node_id':
309             assert unicmp(node[key], locals()[key])
310         print "=> OK"
311
312         # Update node
313         hostname = randhostname()
314         model = randstr(255)
315         print "AdmUpdateNode(%s)" % hostname,
316         AdmUpdateNode(admin, node_id, {'hostname': hostname, 'model': model})
317         node = AdmGetNodes(admin, [node_id])[0]
318         for key in 'hostname', 'boot_state', 'model', 'node_id':
319             assert unicmp(node[key], locals()[key])
320         print "=> OK"
321
322         # Add to node groups
323         for nodegroup_id in nodegroup_ids:
324             print "AdmAddNodeToNodeGroup(%d, %d)" % (nodegroup_id, node_id),
325             AdmAddNodeToNodeGroup(admin, nodegroup_id, node_id)
326             print "=> OK"
327
328 print "AdmGetNodes",
329 nodes = AdmGetNodes(admin, node_ids)
330 assert set(node_ids) == set([node['node_id'] for node in nodes])
331 print "=>", node_ids
332
333 print "AdmGetSiteNodes" % site_ids,
334 site_node_ids = AdmGetSiteNodes(admin, site_ids)
335 assert set(node_ids) == set(reduce(lambda a, b: a + b, site_node_ids.values()))
336 print "=>", site_node_ids
337
338 for nodegroup_id in nodegroup_ids:
339     print "AdmGetNodeGroupNodes(%d)" % nodegroup_id,
340     nodegroup_node_ids = AdmGetNodeGroupNodes(admin, nodegroup_id)
341     assert set(nodegroup_node_ids) == set(node_ids)
342     print "=>", nodegroup_node_ids
343
344 # Add node networks
345 nodenetwork_ids = []
346 for node_id in node_ids:
347     ip = randint(0, 0xffffffff)
348     netmask = (0xffffffff << randint(2, 31)) & 0xffffffff
349     network = ip & netmask
350     broadcast = ((ip & netmask) | ~netmask) & 0xffffffff
351     gateway = randint(network + 1, broadcast - 1)
352     dns1 = randint(0, 0xffffffff)
353
354     for method in 'static', 'dhcp':
355         optional = {}
356         if method == 'static':
357             for key in 'ip', 'netmask', 'network', 'broadcast', 'gateway', 'dns1':
358                 optional[key] = socket.inet_ntoa(struct.pack('>L', locals()[key]))
359
360         print "AdmAddNodeNetwork(%s)" % method,
361         nodenetwork_id = AdmAddNodeNetwork(admin, node_id, method, 'ipv4', optional)
362
363         # Should return a unique nodenetwork_id
364         assert nodenetwork_id not in nodenetwork_ids
365         nodenetwork_ids.append(nodenetwork_id)
366         print "=>", nodenetwork_id
367
368     # Check node networks
369     print "AdmGetAllNodeNetworks(%d)" % node_id,
370     nodenetworks = AdmGetAllNodeNetworks(admin, node_id)
371     for nodenetwork in nodenetworks:
372         if nodenetwork['method'] == 'static':
373             for key in 'ip', 'netmask', 'network', 'broadcast', 'gateway', 'dns1':
374                 address = struct.unpack('>L', socket.inet_aton(nodenetwork[key]))[0]
375                 assert address == locals()[key]
376     print "=>", [nodenetwork['nodenetwork_id'] for nodenetwork in nodenetworks]
377
378 # Update node networks
379 for node_id in node_ids:
380     ip = randint(0, 0xffffffff)
381     netmask = (0xffffffff << randint(2, 31)) & 0xffffffff
382     network = ip & netmask
383     broadcast = ((ip & netmask) | ~netmask) & 0xffffffff
384     gateway = randint(network + 1, broadcast - 1)
385     dns1 = randint(0, 0xffffffff)
386
387     nodenetworks = AdmGetAllNodeNetworks(admin, node_id)
388     for nodenetwork in nodenetworks:
389         # Update node network
390         optional = {}
391         if nodenetwork['method'] == 'static':
392             for key in 'ip', 'netmask', 'network', 'broadcast', 'gateway', 'dns1':
393                 optional[key] = socket.inet_ntoa(struct.pack('>L', locals()[key]))
394
395         print "AdmUpdateNodeNetwork(%s)" % nodenetwork['method'],
396         AdmUpdateNodeNetwork(admin, nodenetwork['nodenetwork_id'], optional)
397         print "=> OK"
398
399     # Check node network again
400     print "AdmGetAllNodeNetworks(%d)" % node_id,
401     nodenetworks = AdmGetAllNodeNetworks(admin, node_id)
402     for nodenetwork in nodenetworks:
403         if nodenetwork['method'] == 'static':
404             for key in 'ip', 'netmask', 'network', 'broadcast', 'gateway', 'dns1':
405                 address = struct.unpack('>L', socket.inet_aton(nodenetwork[key]))[0]
406                 assert address == locals()[key]
407     print "=>", [nodenetwork['nodenetwork_id'] for nodenetwork in nodenetworks]
408
409 # Add node attribute types
410 attribute_type_ids = []
411 for i in range(3):
412     name = randstr(100)
413     description = randstr(254)
414     min_role_id = random.sample(roles.values(), 1)[0]
415
416     # Add slice attribute type
417     print "AddSliceAttributeType",
418     attribute_type_id = AddSliceAttributeType(admin, name,
419                                          {'description': description,
420                                           'min_role_id': min_role_id})
421
422     # Should return a unique attribute_type_id
423     assert attribute_type_id not in attribute_type_ids
424     attribute_type_ids.append(attribute_type_id)
425     print "=>", attribute_type_id
426
427     # Check slice attribute type
428     print "GetSliceAttributeTypes(%d)" % attribute_type_id,
429     attribute_type = GetSliceAttributeTypes(admin, [attribute_type_id])[0]
430     for key in 'min_role_id', 'description':
431         assert unicmp(attribute_type[key], locals()[key])
432     print "=> OK"
433
434     # Update slice attribute type
435     description = randstr(254)
436     min_role_id = random.sample(roles.values(), 1)[0]
437     print "UpdateSliceAttributeType(%d)" % attribute_type_id,
438     UpdateSliceAttributeType(admin, attribute_type_id,
439                              {'description': description,
440                               'min_role_id': min_role_id})
441     attribute_type = GetSliceAttributeTypes(admin, [attribute_type_id])[0]
442     for key in 'min_role_id', 'description':
443         assert unicmp(attribute_type[key], locals()[key])
444     print "=> OK"
445
446 # Add slices and slice attributes
447 slice_ids = []
448 slice_attribute_ids = []
449 sites = AdmGetSites(admin, site_ids)
450 for site in sites:
451     for i in range(10):
452         name = site['login_base'] + "_" + randstr(11, letters).lower()
453         url = "http://" + randhostname() + "/"
454         description = randstr(2048)
455
456         # Add slice
457         print "AddSlice(%s)" % name,
458         slice_id = AddSlice(admin, name, {'url': url, 'description': description})
459
460         # Should return a unique slice_id
461         assert slice_id not in slice_ids
462         slice_ids.append(slice_id)
463         print "=>", slice_id
464
465         # Check slice
466         print "GetSlices(%d)" % slice_id,
467         slice = GetSlices(admin, [slice_id])[0]
468         for key in 'name', 'url', 'description', 'slice_id':
469             assert unicmp(slice[key], locals()[key])
470         print "=> OK"
471
472         # Update slice
473         url = "http://" + randhostname() + "/"
474         description = randstr(2048)
475         print "UpdateSlice(%s)" % name,
476         UpdateSlice(admin, slice_id, {'url': url, 'description': description})
477         slice = GetSlices(admin, [slice_id])[0]
478         for key in 'name', 'url', 'description', 'slice_id':
479             assert unicmp(slice[key], locals()[key])
480         print "=> OK"
481
482         # XXX Add nodes to slice
483
484         # XXX Add people to slice
485         
486         # Set slice/sliver attributes
487         for attribute_type_id in attribute_type_ids:
488             value = randstr(254)
489             # Make it a sliver attribute with 50% probability
490             # node_id = random.sample(node_ids + [None] * len(node_ids), 1)[0]
491             node_id = None
492
493             # Add slice attribute
494             print "AddSliceAttribute(%s, %d)" % (name, attribute_type_id),
495             if node_id is None:
496                 slice_attribute_id = AddSliceAttribute(admin, slice_id, attribute_type_id, value)
497             else:
498                 slice_attribute_id = AddSliceAttribute(admin, slice_id, attribute_type_id, value, node_id)
499
500             # Should return a unique slice_attribute_id
501             assert slice_attribute_id not in slice_attribute_ids
502             slice_attribute_ids.append(slice_attribute_id)
503             print "=>", slice_attribute_id
504
505             # Check slice attribute
506             print "GetSliceAttributes(%d)" % slice_attribute_id,
507             slice_attribute = GetSliceAttributes(admin, [slice_attribute_id])[0]
508             for key in 'attribute_type_id', 'slice_id', 'node_id', 'slice_attribute_id', 'value':
509                 assert unicmp(slice_attribute[key], locals()[key])
510             print "=> OK"
511
512             # Update slice attribute
513             url = "http://" + randhostname() + "/"
514             description = randstr(2048)
515             print "UpdateSliceAttribute(%s)" % name,
516             UpdateSliceAttribute(admin, slice_attribute_id, value)
517             slice_attribute = GetSliceAttributes(admin, [slice_attribute_id])[0]
518             for key in 'attribute_type_id', 'slice_id', 'node_id', 'slice_attribute_id', 'value':
519                 assert unicmp(slice_attribute[key], locals()[key])
520             print "=> OK"
521
522 # Delete slices
523 for slice_id in slice_ids:
524     # Delete slice attributes
525     slice = GetSlices(admin, [slice_id])[0]
526     for slice_attribute_id in slice['slice_attribute_ids']:
527         print "DeleteSliceAttribute(%s, %d)" % (slice['name'], slice_attribute_id),
528         DeleteSliceAttribute(admin, slice_attribute_id)
529         print "=> OK"
530     slice = GetSlices(admin, [slice_id])[0]
531     assert not slice['slice_attribute_ids']
532
533     # Delete slice
534     print "DeleteSlice(%d)" % slice_id,
535     DeleteSlice(admin, slice_id)
536     assert not GetSlices(admin, [slice_id])
537
538     # Make sure it really deleted it
539     slices = GetSlices(admin, slice_ids)
540     assert slice_id not in [slice['slice_id'] for slice in slices]
541     print "=> OK"
542
543 print "GetSlices",
544 assert not GetSlices(admin, slice_ids)
545 print "=> []"
546
547 # Delete slice attribute types
548 for attribute_type_id in attribute_type_ids:
549     # Delete attribute
550     print "DeleteAttribute(%d)" % attribute_type_id,
551     DeleteSliceAttributeType(admin, attribute_type_id)
552     assert not GetSliceAttributeTypes(admin, [attribute_type_id])
553
554     # Make sure it really deleted it
555     attribute_types = GetSliceAttributeTypes(admin, attribute_type_ids)
556     assert attribute_type_id not in [attribute_type['attribute_type_id'] for attribute_type in attribute_types]
557     print "=> OK"
558
559 print "GetAttributes",
560 assert not GetSliceAttributeTypes(admin, attribute_type_ids)
561 print "=> []"
562
563 # Delete node networks
564 for node_id in node_ids:
565     nodenetworks = AdmGetAllNodeNetworks(admin, node_id)
566     for nodenetwork in nodenetworks:
567         # Delete node network
568         print "AdmDeleteNodeNetwork(%d, %d)" % (node_id, nodenetwork['nodenetwork_id']),
569         AdmDeleteNodeNetwork(admin, node_id, nodenetwork['nodenetwork_id'])
570         print "=>", "OK"
571     assert not AdmGetAllNodeNetworks(admin, node_id)
572
573 # Delete nodes
574 for node_id in node_ids:
575     # Remove from node groups
576     for nodegroup_id in nodegroup_ids:
577         print "AdmRemoveNodeFromNodeGroup(%d, %d)" % (nodegroup_id, node_id),
578         AdmRemoveNodeFromNodeGroup(admin, nodegroup_id, node_id)
579         # Make sure it really deleted it
580         assert node_id not in AdmGetNodeGroupNodes(nodegroup_id)
581         print "=> OK"
582
583     # Delete node
584     print "AdmDeleteNode(%d)" % node_id,
585     AdmDeleteNode(admin, node_id)
586     assert not AdmGetNodes(admin, [node_id])
587
588     # Make sure it really deleted it
589     nodes = AdmGetNodes(admin, node_ids)
590     assert node_id not in [node['node_id'] for node in nodes]
591     print "=> OK"
592
593 print "AdmGetNodes",
594 assert not AdmGetNodes(admin, node_ids)
595 print "=> []"
596
597 for nodegroup_id in nodegroup_ids:
598     print "AdmGetNodeGroupNodes(%d)" % nodegroup_id,
599     assert not AdmGetNodeGroupNodes(nodegroup_id)
600     print "=> []"
601
602 # Delete users
603 for person_id in person_ids:
604     # Remove from each site
605     for site_id in site_ids:
606         print "AdmRemovePersonFromSite(%d, %d)" % (person_id, site_id),
607         AdmRemovePersonFromSite(admin, person_id, site_id)
608         assert site_id not in AdmGetPersonSites(admin, person_id)
609         person = AdmGetPersons(admin, [person_id])[0]
610         assert site_id not in person['site_ids']
611         print "=> OK"
612
613     assert not AdmGetPersonSites(admin, person_id)
614
615     # Revoke role
616     person_roles = AdmGetPersonRoles(admin, person_id)
617     role_id = int(person_roles.keys()[0])
618     print "AdmRevokeRoleFromPerson(%d, %d)" % (person_id, role_id),
619     AdmRevokeRoleFromPerson(admin, person_id, role_id)
620     assert not AdmGetPersonRoles(admin, person_id)
621     person = AdmGetPersons(admin, [person_id])[0]
622     assert not person['role_ids']
623     print "=> OK"
624
625     # Disable account
626     print "AdmSetPersonEnabled(%d, False)" % person_id,
627     AdmSetPersonEnabled(admin, person_id, False)
628     person = AdmGetPersons(admin, [person_id])[0]
629     assert not person['enabled']
630     print "=> OK"
631
632     # Delete account
633     print "AdmDeletePerson(%d)" % person_id,
634     AdmDeletePerson(admin, person_id)
635     assert not AdmGetPersons(admin, [person_id])                         
636     print "=> OK"
637
638 print "AdmGetPersons",
639 assert not AdmGetPersons(admin, person_ids)
640 print "=> []"
641
642 # Delete node groups
643 for nodegroup_id in nodegroup_ids:
644     print "AdmDeleteNodeGroup(%d)" % nodegroup_id,
645     AdmDeleteNodeGroup(admin, nodegroup_id)
646     assert not AdmGetNodeGroups(admin, [nodegroup_id])
647     print "=> OK"
648
649 print "AdmGetNodeGroups",
650 assert not AdmGetNodeGroups(admin, nodegroup_ids)
651 print "=> []"
652
653 # Delete sites
654 for site_id in site_ids:
655     print "AdmDeleteSite(%d)" % site_id,
656     AdmDeleteSite(admin, site_id)
657     assert not AdmGetSites(admin, [site_id])
658     print "=> OK"
659
660 print "AdmGetSites",
661 assert not AdmGetSites(admin, site_ids)
662 print "=> []"