fix slice attribute functions
[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.8 2006/10/03 19:33:16 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 print "AdmGetAllNodeNetworkBandwidthLimits",
345 bwlimits = AdmGetAllNodeNetworkBandwidthLimits(admin)
346 print "=>", bwlimits
347
348 # Add node networks
349 nodenetwork_ids = []
350 for node_id in node_ids:
351     ip = randint(0, 0xffffffff)
352     netmask = (0xffffffff << randint(2, 31)) & 0xffffffff
353     network = ip & netmask
354     broadcast = ((ip & netmask) | ~netmask) & 0xffffffff
355     gateway = randint(network + 1, broadcast - 1)
356     dns1 = randint(0, 0xffffffff)
357
358     for method in 'static', 'dhcp':
359         optional = {}
360         if method == 'static':
361             for key in 'ip', 'netmask', 'network', 'broadcast', 'gateway', 'dns1':
362                 optional[key] = socket.inet_ntoa(struct.pack('>L', locals()[key]))
363
364         print "AdmAddNodeNetwork(%s)" % method,
365         nodenetwork_id = AdmAddNodeNetwork(admin, node_id, method, 'ipv4', optional)
366
367         # Should return a unique nodenetwork_id
368         assert nodenetwork_id not in nodenetwork_ids
369         nodenetwork_ids.append(nodenetwork_id)
370         print "=>", nodenetwork_id
371
372     # Check node networks
373     print "AdmGetAllNodeNetworks(%d)" % node_id,
374     nodenetworks = AdmGetAllNodeNetworks(admin, node_id)
375     for nodenetwork in nodenetworks:
376         if nodenetwork['method'] == 'static':
377             for key in 'ip', 'netmask', 'network', 'broadcast', 'gateway', 'dns1':
378                 address = struct.unpack('>L', socket.inet_aton(nodenetwork[key]))[0]
379                 assert address == locals()[key]
380     print "=>", [nodenetwork['nodenetwork_id'] for nodenetwork in nodenetworks]
381
382 # Update node networks
383 for node_id in node_ids:
384     ip = randint(0, 0xffffffff)
385     netmask = (0xffffffff << randint(2, 31)) & 0xffffffff
386     network = ip & netmask
387     broadcast = ((ip & netmask) | ~netmask) & 0xffffffff
388     gateway = randint(network + 1, broadcast - 1)
389     dns1 = randint(0, 0xffffffff)
390
391     nodenetworks = AdmGetAllNodeNetworks(admin, node_id)
392     for nodenetwork in nodenetworks:
393         # Update node network
394         optional = {}
395         if nodenetwork['method'] == 'static':
396             for key in 'ip', 'netmask', 'network', 'broadcast', 'gateway', 'dns1':
397                 optional[key] = socket.inet_ntoa(struct.pack('>L', locals()[key]))
398
399         print "AdmUpdateNodeNetwork(%s)" % nodenetwork['method'],
400         AdmUpdateNodeNetwork(admin, nodenetwork['nodenetwork_id'], optional)
401         print "=> OK"
402
403     # Check node network again
404     print "AdmGetAllNodeNetworks(%d)" % node_id,
405     nodenetworks = AdmGetAllNodeNetworks(admin, node_id)
406     for nodenetwork in nodenetworks:
407         if nodenetwork['method'] == 'static':
408             for key in 'ip', 'netmask', 'network', 'broadcast', 'gateway', 'dns1':
409                 address = struct.unpack('>L', socket.inet_aton(nodenetwork[key]))[0]
410                 assert address == locals()[key]
411     print "=>", [nodenetwork['nodenetwork_id'] for nodenetwork in nodenetworks]
412
413 # Add attribute types
414 attribute_ids = []
415 for i in range(3):
416     name = randstr(100)
417     description = randstr(254)
418     min_role_id = random.sample(roles.values(), 1)[0]
419
420     # Add attribute
421     print "AddAttribute",
422     attribute_id = AddAttribute(admin, name,
423                                 {'description': description,
424                                  'min_role_id': min_role_id})
425
426     # Should return a unique attribute_id
427     assert attribute_id not in attribute_ids
428     attribute_ids.append(attribute_id)
429     print "=>", attribute_id
430
431     # Check attribute
432     print "GetAttributes(%d)" % attribute_id,
433     attribute = GetAttributes(admin, [attribute_id])[0]
434     for key in 'min_role_id', 'description':
435         assert unicmp(attribute[key], locals()[key])
436     print "=> OK"
437
438     # Update attribute
439     description = randstr(254)
440     min_role_id = random.sample(roles.values(), 1)[0]
441     print "UpdateAttribute(%d)" % attribute_id,
442     UpdateAttribute(admin, attribute_id,
443                     {'description': description,
444                      'min_role_id': min_role_id})
445     attribute = GetAttributes(admin, [attribute_id])[0]
446     for key in 'min_role_id', 'description':
447         assert unicmp(attribute[key], locals()[key])
448     print "=> OK"
449
450 # Add slices and slice attributes
451 slice_ids = []
452 slice_attribute_ids = []
453 sites = AdmGetSites(admin, site_ids)
454 for site in sites:
455     for i in range(10):
456         name = site['login_base'] + "_" + randstr(11, letters).lower()
457         url = "http://" + randhostname() + "/"
458         description = randstr(2048)
459
460         # Add slice
461         print "AddSlice(%s)" % name,
462         slice_id = AddSlice(admin, name, {'url': url, 'description': description})
463
464         # Should return a unique slice_id
465         assert slice_id not in slice_ids
466         slice_ids.append(slice_id)
467         print "=>", slice_id
468
469         # Check slice
470         print "GetSlices(%d)" % slice_id,
471         slice = GetSlices(admin, [slice_id])[0]
472         for key in 'name', 'url', 'description', 'slice_id':
473             assert unicmp(slice[key], locals()[key])
474         print "=> OK"
475
476         # Update slice
477         url = "http://" + randhostname() + "/"
478         description = randstr(2048)
479         print "UpdateSlice(%s)" % name,
480         UpdateSlice(admin, slice_id, {'url': url, 'description': description})
481         slice = GetSlices(admin, [slice_id])[0]
482         for key in 'name', 'url', 'description', 'slice_id':
483             assert unicmp(slice[key], locals()[key])
484         print "=> OK"
485
486         # XXX Add nodes to slice
487
488         # XXX Add people to slice
489         
490         # Set slice/sliver attributes
491         for attribute_id in attribute_ids:
492             value = randstr(254)
493             # Make it a sliver attribute with 50% probability
494             # node_id = random.sample(node_ids + [None] * len(node_ids), 1)[0]
495             node_id = None
496
497             # Add slice attribute
498             print "AddSliceAttribute(%s, %d)" % (name, attribute_id),
499             if node_id is None:
500                 slice_attribute_id = AddSliceAttribute(admin, slice_id, attribute_id, value)
501             else:
502                 slice_attribute_id = AddSliceAttribute(admin, slice_id, attribute_id, value, node_id)
503
504             # Should return a unique slice_attribute_id
505             assert slice_attribute_id not in slice_attribute_ids
506             slice_attribute_ids.append(slice_attribute_id)
507             print "=>", slice_attribute_id
508
509             # Check slice attribute
510             print "GetSliceAttributes(%d)" % slice_attribute_id,
511             slice_attribute = GetSliceAttributes(admin, slice_id, [slice_attribute_id])[0]
512             for key in 'attribute_id', 'slice_id', 'node_id', 'slice_attribute_id', 'value':
513                 assert unicmp(slice_attribute[key], locals()[key])
514             print "=> OK"
515
516             # Update slice attribute
517             url = "http://" + randhostname() + "/"
518             description = randstr(2048)
519             print "UpdateSliceAttribute(%s)" % name,
520             UpdateSliceAttribute(admin, slice_attribute_id, value)
521             slice_attribute = GetSliceAttributes(admin, slice_id, [slice_attribute_id])[0]
522             for key in 'attribute_id', 'slice_id', 'node_id', 'slice_attribute_id', 'value':
523                 assert unicmp(slice_attribute[key], locals()[key])
524             print "=> OK"
525
526 # Delete slices
527 for slice_id in slice_ids:
528     # Delete slice attributes
529     slice = GetSlices(admin, [slice_id])[0]
530     for slice_attribute_id in slice['slice_attribute_ids']:
531         print "DeleteSliceAttribute(%s, %d)" % (slice['name'], slice_attribute_id),
532         DeleteSliceAttribute(admin, slice_attribute_id)
533         print "=> OK"
534     slice = GetSlices(admin, [slice_id])[0]
535     assert not slice['slice_attribute_ids']
536
537     # Delete slice
538     print "DeleteSlice(%d)" % slice_id,
539     DeleteSlice(admin, slice_id)
540     assert not GetSlices(admin, [slice_id])
541
542     # Make sure it really deleted it
543     slices = GetSlices(admin, slice_ids)
544     assert slice_id not in [slice['slice_id'] for slice in slices]
545     print "=> OK"
546
547 print "GetSlices",
548 assert not GetSlices(admin, slice_ids)
549 print "=> []"
550
551 # Delete attributes
552 for attribute_id in attribute_ids:
553     # Delete attribute
554     print "DeleteAttribute(%d)" % attribute_id,
555     DeleteAttribute(admin, attribute_id)
556     assert not GetAttributes(admin, [attribute_id])
557
558     # Make sure it really deleted it
559     attributes = GetAttributes(admin, attribute_ids)
560     assert attribute_id not in [attribute['attribute_id'] for attribute in attributes]
561     print "=> OK"
562
563 print "GetAttributes",
564 assert not GetAttributes(admin, attribute_ids)
565 print "=> []"
566
567 # Delete node networks
568 for node_id in node_ids:
569     nodenetworks = AdmGetAllNodeNetworks(admin, node_id)
570     for nodenetwork in nodenetworks:
571         # Delete node network
572         print "AdmDeleteNodeNetwork(%d, %d)" % (node_id, nodenetwork['nodenetwork_id']),
573         AdmDeleteNodeNetwork(admin, node_id, nodenetwork['nodenetwork_id'])
574         print "=>", "OK"
575     assert not AdmGetAllNodeNetworks(admin, node_id)
576
577 # Delete nodes
578 for node_id in node_ids:
579     # Remove from node groups
580     for nodegroup_id in nodegroup_ids:
581         print "AdmRemoveNodeFromNodeGroup(%d, %d)" % (nodegroup_id, node_id),
582         AdmRemoveNodeFromNodeGroup(admin, nodegroup_id, node_id)
583         # Make sure it really deleted it
584         assert node_id not in AdmGetNodeGroupNodes(nodegroup_id)
585         print "=> OK"
586
587     # Delete node
588     print "AdmDeleteNode(%d)" % node_id,
589     AdmDeleteNode(admin, node_id)
590     assert not AdmGetNodes(admin, [node_id])
591
592     # Make sure it really deleted it
593     nodes = AdmGetNodes(admin, node_ids)
594     assert node_id not in [node['node_id'] for node in nodes]
595     print "=> OK"
596
597 print "AdmGetNodes",
598 assert not AdmGetNodes(admin, node_ids)
599 print "=> []"
600
601 for nodegroup_id in nodegroup_ids:
602     print "AdmGetNodeGroupNodes(%d)" % nodegroup_id,
603     assert not AdmGetNodeGroupNodes(nodegroup_id)
604     print "=> []"
605
606 # Delete users
607 for person_id in person_ids:
608     # Remove from each site
609     for site_id in site_ids:
610         print "AdmRemovePersonFromSite(%d, %d)" % (person_id, site_id),
611         AdmRemovePersonFromSite(admin, person_id, site_id)
612         assert site_id not in AdmGetPersonSites(admin, person_id)
613         person = AdmGetPersons(admin, [person_id])[0]
614         assert site_id not in person['site_ids']
615         print "=> OK"
616
617     assert not AdmGetPersonSites(admin, person_id)
618
619     # Revoke role
620     person_roles = AdmGetPersonRoles(admin, person_id)
621     role_id = int(person_roles.keys()[0])
622     print "AdmRevokeRoleFromPerson(%d, %d)" % (person_id, role_id),
623     AdmRevokeRoleFromPerson(admin, person_id, role_id)
624     assert not AdmGetPersonRoles(admin, person_id)
625     person = AdmGetPersons(admin, [person_id])[0]
626     assert not person['role_ids']
627     print "=> OK"
628
629     # Disable account
630     print "AdmSetPersonEnabled(%d, False)" % person_id,
631     AdmSetPersonEnabled(admin, person_id, False)
632     person = AdmGetPersons(admin, [person_id])[0]
633     assert not person['enabled']
634     print "=> OK"
635
636     # Delete account
637     print "AdmDeletePerson(%d)" % person_id,
638     AdmDeletePerson(admin, person_id)
639     assert not AdmGetPersons(admin, [person_id])                         
640     print "=> OK"
641
642 print "AdmGetPersons",
643 assert not AdmGetPersons(admin, person_ids)
644 print "=> []"
645
646 # Delete node groups
647 for nodegroup_id in nodegroup_ids:
648     print "AdmDeleteNodeGroup(%d)" % nodegroup_id,
649     AdmDeleteNodeGroup(admin, nodegroup_id)
650     assert not AdmGetNodeGroups(admin, [nodegroup_id])
651     print "=> OK"
652
653 print "AdmGetNodeGroups",
654 assert not AdmGetNodeGroups(admin, nodegroup_ids)
655 print "=> []"
656
657 # Delete sites
658 for site_id in site_ids:
659     print "AdmDeleteSite(%d)" % site_id,
660     AdmDeleteSite(admin, site_id)
661     assert not AdmGetSites(admin, [site_id])
662     print "=> OK"
663
664 print "AdmGetSites",
665 assert not AdmGetSites(admin, site_ids)
666 print "=> []"