1 #!/usr/bin/env /usr/share/plc_api/plcsh
5 # Copyright (C) 2006 The Trustees of Princeton University
9 from pprint import pprint
10 from string import letters, digits, punctuation
12 from traceback import print_exc
22 from qa.Config import Config
23 from qa.logger import Logfile, log, logfile
24 from random import Random
32 try: boot_states = api.GetBootStates(auth)
33 except: boot_states = [u'boot', u'dbg', u'inst', u'new', u'rcnf', u'rins']
35 try: roles = [role['role_id'] for role in api.GetRoles(auth)]
36 except: roles = [10,20,30,40]
38 try: methods = api.GetNetworkMethods(auth)
39 except: methods = [u'static', u'dhcp', u'proxy', u'tap', u'ipmi', u'unknown']
41 try: key_types = api.GetKeyTypes(auth)
42 except: key_types = [u'ssh']
44 try:types = api.GetNetworkTypes(auth)
45 except: types = [u'ipv4']
48 attribute_types = [a['attribute_type_id'] for a in api.GetSliceAttributeTypes(auth)]
49 attribute_types = filter(lambda x: x['name'] != 'initscript', attribute_types)
52 attribute_types = range(6,20)
55 sites = api.GetSites(auth, None, ['login_base'])
56 login_bases = [site['login_base'] for site in sites]
61 def randfloat(min = 0.0, max = 1.0):
62 return float(min) + (random.random() * (float(max) - float(min)))
64 def randint(min = 0, max = 1):
65 return int(randfloat(min, max + 1))
68 return random.sample([True, False], 1)[0]
69 # See "2.2 Characters" in the XML specification:
71 # #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD]
73 # [#x7F-#x84], [#x86-#x9F], [#xFDD0-#xFDDF]
75 ascii_xml_chars = map(unichr, [0x9, 0xA, 0xD])
76 ascii_xml_chars += map(unichr, xrange(0x20, 0x7F - 1))
77 low_xml_chars = list(ascii_xml_chars)
78 low_xml_chars += map(unichr, xrange(0x84 + 1, 0x86 - 1))
79 low_xml_chars += map(unichr, xrange(0x9F + 1, 0xFF))
80 valid_xml_chars = list(low_xml_chars)
81 valid_xml_chars += map(unichr, xrange(0xFF + 1, 0xD7FF))
82 valid_xml_chars += map(unichr, xrange(0xE000, 0xFDD0 - 1))
83 valid_xml_chars += map(unichr, xrange(0xFDDF + 1, 0xFFFD))
85 def randstr(length, pool = valid_xml_chars, encoding = "utf-8"):
86 sample = random.sample(pool, min(length, len(pool)))
89 bytes = len(s.encode(encoding))
93 sample += random.sample(pool, min(length - bytes, len(pool)))
94 random.shuffle(sample)
100 # 1. Each part begins and ends with a letter or number.
101 # 2. Each part except the last can contain letters, numbers, or hyphens.
102 # 3. Each part is between 1 and 64 characters, including the trailing dot.
103 # 4. At least two parts.
104 # 5. Last part can only contain between 2 and 6 letters.
105 hostname = 'a' + randstr(61, letters + digits + '-') + '1.' + \
106 'b' + randstr(61, letters + digits + '-') + '2.' + \
107 'c' + randstr(5, letters)
110 def randpath(length):
112 for i in range(randint(1, 10)):
113 parts.append(randstr(randint(1, 30), ascii_xml_chars))
114 return os.sep.join(parts)[0:length]
117 return (randstr(100, letters + digits) + "@" + randhostname()).lower()
119 def randkey(bits = 2048):
120 key_types = ["ssh-dss", "ssh-rsa"]
121 key_type = random.sample(key_types, 1)[0]
122 return ' '.join([key_type,
123 base64.b64encode(''.join(randstr(bits / 8).encode("utf-8"))),
128 'name': randstr(254),
129 'abbreviated_name': randstr(50),
130 'login_base': randstr(20, letters).lower(),
131 'latitude': int(randfloat(-90.0, 90.0) * 1000) / 1000.0,
132 'longitude': int(randfloat(-180.0, 180.0) * 1000) / 1000.0,
139 'peername': randstr(254),
140 'peer_url': "https://" + randhostname() + "/",
141 'key': base64.b64encode(''.join(randstr(bits / 8).encode("utf-8"))),
142 'cacert': base64.b64encode(''.join(randstr(bits / 8).encode("utf-8")))
144 def random_address_type():
147 'description': randstr(254),
150 def random_address():
152 'line1': randstr(254),
153 'line2': randstr(254),
154 'line3': randstr(254),
155 'city': randstr(254),
156 'state': randstr(254),
157 'postalcode': randstr(64),
158 'country': randstr(128),
163 'first_name': randstr(128),
164 'last_name': randstr(128),
165 'email': randemail(),
167 # Accounts are disabled by default
169 'password': randstr(254),
174 'key_type': random.sample(key_types, 1)[0],
180 'name': random.sample(login_bases, 1)[0] + "_" + randstr(11, letters).lower(),
181 'url': "http://" + randhostname() + "/",
182 'description': randstr(2048),
185 def random_nodegroup():
188 'description': randstr(200),
193 'hostname': randhostname(),
194 'boot_state': random.sample(boot_states, 1)[0],
195 'model': randstr(255),
196 'version': randstr(64),
199 def random_nodenetwork():
200 nodenetwork_fields = {
201 'method': random.sample(methods, 1)[0],
202 'type': random.sample(types, 1)[0],
203 'bwlimit': randint(500000, 10000000),
206 if nodenetwork_fields['method'] != 'dhcp':
207 ip = randint(0, 0xffffffff)
208 netmask = (0xffffffff << randint(2, 31)) & 0xffffffff
209 network = ip & netmask
210 broadcast = ((ip & netmask) | ~netmask) & 0xffffffff
211 gateway = randint(network + 1, broadcast - 1)
212 dns1 = randint(0, 0xffffffff)
214 for field in 'ip', 'netmask', 'network', 'broadcast', 'gateway', 'dns1':
215 nodenetwork_fields[field] = socket.inet_ntoa(struct.pack('>L', locals()[field]))
217 return nodenetwork_fields
219 def random_nodenetwork_setting():
224 def random_nodenetwork_setting_type():
227 'description': randstr(50),
228 'category': randstr(20),
229 'min_role_id': random.sample(roles, 1)[0]
234 'hostname': randhostname(),
235 'ip': socket.inet_ntoa(struct.pack('>L', randint(0, 0xffffffff))),
236 'protocol': randstr(16),
237 'username': randstr(254),
238 'password': randstr(254),
239 'notes': randstr(254),
240 'model': randstr(32),
243 def random_conf_file():
245 'enabled': bool(randint()),
246 'source': randpath(255),
247 'dest': randpath(255),
248 'file_permissions': "%#o" % randint(0, 512),
249 'file_owner': randstr(32, letters + '_' + digits),
250 'file_group': randstr(32, letters + '_' + digits),
251 'preinstall_cmd': randpath(100),
252 'postinstall_cmd': randpath(100),
253 'error_cmd': randpath(100),
254 'ignore_cmd_errors': bool(randint()),
255 'always_update': bool(randint()),
258 def random_attribute_type():
260 'name': randstr(100),
261 'description': randstr(254),
262 'min_role_id': int(random.sample(roles, 1)[0]),
265 def random_pcu_type():
267 'model': randstr(254),
268 'name': randstr(254),
271 def random_pcu_protocol_type():
273 'port': randint(0, 65535),
274 'protocol': randstr(254),
275 'supported': randbool()
278 def random_slice_instantiation():
280 'instantiation': randstr(10)
282 def random_slice_attribute():
284 'attribute_type_id': random.sample(attribute_types, 1)[0],
289 def random_initscript():
292 'enabled': randbool(),
293 'script': randstr(200)
298 'role_id': randint(1000),
302 class api_unit_test(Test):
304 logfile = Logfile("api-unittest-summary.log")
313 pcu_protocol_types = 2,
321 nodenetwork_setting_types = 2,
322 nodenetwork_settings = 2,
323 slice_attribute_types = 2,
324 slice_instantiations = 2,
326 slice_attributes = 4,
334 # Filter out deprecated (Adm) and boot Methods
335 current_methods = lambda method: not method.startswith('Adm') and \
336 not method.startswith('Slice') and \
337 not method.startswith('Boot') and \
338 not method.startswith('Anon') and \
339 not method.startswith('system')
340 self.all_methods = set(filter(current_methods, api.system.listMethods()))
341 self.methods_tested = set()
342 self.methods_failed = set()
344 # Begin testing methods
347 if hasattr(self, 'BootStates'): self.boot_states = self.BootStates(boot_states)
348 if hasattr(self, 'Sites'): self.site_ids = self.Sites(sites)
349 if hasattr(self, 'Peers'): self.peer_ids = self.Peers(peers)
350 if hasattr(self, 'AddressTypes'): self.address_type_ids = self.AddressTypes(address_types)
351 if hasattr(self, 'Addresses'): self.address_ids = self.Addresses(addresses)
352 if hasattr(self, 'PCUTypes'): self.pcu_type_ids = self.PCUTypes(pcu_types)
353 if hasattr(self, 'PCUProtocolTypes'): self.pcu_protocol_type_ids = self.PCUProtocolTypes(pcu_protocol_types)
354 if hasattr(self, 'PCUs'): self.pcu_ids = self.PCUs(pcus)
355 if hasattr(self, 'NetworkMethods'): self.network_methods = self.NetworkMethods()
356 if hasattr(self, 'NetworkTypes'): self.network_types = self.NetworkTypes()
357 if hasattr(self, 'NodeGroups'): self.nodegroup_ids = self.NodeGroups()
358 if hasattr(self, 'Nodes'): self.node_ids = self.Nodes(nodes)
359 if hasattr(self, 'ConfFiles'): self.conf_file_ids = self.ConfFiles(conf_files)
360 if hasattr(self, 'NodeNetworks'): self.nodenetwork_ids = self.NodeNetworks(nodenetworks)
361 if hasattr(self, 'NodeNetworkSettingTypes'): self.nodenetwork_setting_type_ids = self.NodeNetworkSettingTypes(nodenetwork_setting_types)
362 if hasattr(self, 'NodeNetworkSettings'): self.nodenetwork_setting_ids = self.NodeNetworkSettings(nodenetwork_settings)
363 if hasattr(self, 'SliceAttributeTypes'): self.slice_attribute_type_ids = self.SliceAttributeTypes(slice_attribute_types)
364 if hasattr(self, 'SliceInstantiations'): self.slice_instantiations = self.SliceInstantiations(slice_instantiations)
365 if hasattr(self, 'Slices'): self.slice_ids = self.Slices(slices)
366 if hasattr(self, 'SliceAttributes'): self.slice_attribute_ids = self.SliceAttributes(slice_attributes)
367 if hasattr(self, 'InitScripts'): self.initscript_ids = self.InitScripts(initscripts)
368 if hasattr(self, 'Roles'): self.role_ids = self.Roles(roles)
369 if hasattr(self, 'Persons'): self.person_ids = self.Persons(persons)
370 if hasattr(self, 'KeyTypes'): self.key_types = self.KeyTypes(key_types)
371 if hasattr(self, 'Keys'): self.key_ids = self.Keys(keys)
372 if hasattr(self, 'Messages'): self.message_ids = self.Messages(messages)
373 if hasattr(self, 'Sessions'): self.Sessions()
375 # Test misc Get calls
376 if hasattr(self, 'GenerateNodeConfFile'): self.GenerateNodeConfFile()
377 if hasattr(self, 'GetBootMedium'): self.GetBootMedium()
378 if hasattr(self, 'GetEventObjects'): self.event_object_ids = self.GetEventObjects()
379 if hasattr(self, 'GetEvents'): self.event_ids = self.GetEvents()
380 if hasattr(self, 'GetPeerData'): self.GetPeerData()
381 if hasattr(self, 'GetPeerName'): self.GetPeerName()
382 if hasattr(self, 'GetPlcRelease'): self.GetPlcRelease()
383 if hasattr(self, 'GetSliceKeys'): self.GetSliceKeys()
384 if hasattr(self, 'GetSliceTicket'): self.GetSliceTicket()
385 if hasattr(self, 'GetSlicesMD5'): self.GetSlicesMD5()
386 if hasattr(self, 'GetSlivers'): self.GetSlivers()
387 if hasattr(self, 'GetWhitelist'): self.GetWhitelist()
389 # Test various administrative methods
390 if hasattr(self, 'NotifyPersons'): self.NotifyPersons()
391 if hasattr(self, 'NotifySupport'): self.NotifySupport()
392 if hasattr(self, 'RebootNode'): self.RebootNode()
393 if hasattr(self, 'RefrestPeer'): self.RefreshPeer()
394 if hasattr(self, 'ResetPassword'): self.ResetPassword()
395 if hasattr(self, 'SetPersonPrimarySite'): self.SetPersonPrimarySite()
396 if hasattr(self, 'VerifyPerson'): self.VerifyPerson()
407 utils.header("writing api-unittest-summary.log")
408 methods_ok = list(self.methods_tested.difference(self.methods_failed))
409 methods_failed = list(self.methods_failed)
410 methods_untested = list(self.all_methods.difference(self.methods_tested))
412 methods_failed.sort()
413 methods_untested.sort()
414 print >> self.logfile, "\n".join([m+": [OK]" for m in methods_ok])
415 print >> self.logfile, "\n".join([m+": [FAILED]" for m in methods_failed])
416 print >> self.logfile, "\n".join([m+": [Not Tested]" for m in methods_untested])
418 def isequal(self, object_fields, expected_fields, method_name):
420 for field in expected_fields:
421 assert field in object_fields
422 assert object_fields[field] == expected_fields[field]
424 self.methods_failed.update([method_name])
428 def islistequal(self, list1, list2, method_name):
429 try: assert set(list1) == set(list2)
431 self.methods_failed.update([method_name])
435 def isunique(self, id, id_list, method_name):
436 try: assert id not in id_list
438 self.methods_failed.update([method_name])
442 def isinlist(self, item, item_list, method_name):
443 try: assert item in item_list
445 self.methods_failed.update([method_name])
448 def debug(self, method, method_name=None):
449 if method_name is None:
450 method_name = method.name
452 self.methods_tested.update([method_name])
453 def wrapper(*args, **kwds):
455 return method(*args, **kwds)
457 self.methods_failed.update([method_name])
458 print >> logfile, "%s%s: %s\n" % (method_name, tuple(args[1:]), traceback.format_exc())
464 if hasattr(self, 'key_types'): self.DeleteKeyTypes()
465 if hasattr(self, 'key_ids'): self.DeleteKeys()
466 if hasattr(self, 'person_ids'): self.DeletePersons()
467 if hasattr(self, 'role_ids'): self.DeleteRoles()
468 if hasattr(self, 'initscript_ids'): self.DeleteInitScripts()
469 if hasattr(self, 'slice_attribute_ids'): self.DeleteSliceAttributes()
470 if hasattr(self, 'slice_ids'): self.DeleteSlices()
471 if hasattr(self, 'slice_instantiations'): self.DeleteSliceInstantiations()
472 if hasattr(self, 'slice_attribute_type_ids'): self.DeleteSliceAttributeTypes()
473 if hasattr(self, 'nodenetwork_setting_ids'): self.DeleteNodeNetworkSettings()
474 if hasattr(self, 'nodenetwork_setting_type_ids'): self.DeleteNodeNetworkSettingTypes()
475 if hasattr(self, 'nodenetwork_ids'): self.DeleteNodeNetworks()
476 if hasattr(self, 'conf_file_ids'): self.DeleteConfFiles()
477 if hasattr(self, 'node_ids'): self.DeleteNodes()
478 if hasattr(self, 'nodegroup_ids'): self.DeleteNodeGroups()
479 if hasattr(self, 'network_types'): self.DeleteNetworkTypes()
480 if hasattr(self, 'network_methods'): self.DeleteNetworkMethods()
481 if hasattr(self, 'pcu_ids'): self.DeletePCUs()
482 if hasattr(self, 'pcu_protocol_type_ids'): self.DeletePCUProtocolTypes()
483 if hasattr(self, 'pcu_type_ids'): self.DeletePCUTypes()
484 if hasattr(self, 'address_ids'): self.DeleteAddresses()
485 if hasattr(self, 'address_type_ids'): self.DeleteAddressTypes()
486 if hasattr(self, 'peer_ids'): self.DeletePeers()
487 if hasattr(self, 'site_ids'): self.DeleteSites()
488 if hasattr(self, 'boot_states'): self.DeleteBootStates()
491 def Sites(self, n=4):
495 site_fields = random_site()
496 AddSite = self.debug(api.AddSite)
497 site_id = AddSite(auth, site_fields)
498 if site_id is None: continue
500 # Should return a unique id
501 self.isunique(site_id, site_ids, 'AddSite - isunique')
502 site_ids.append(site_id)
503 GetSites = self.debug(api.GetSites)
504 sites = GetSites(auth, [site_id])
505 if sites is None: continue
507 self.isequal(site, site_fields, 'AddSite - isequal')
510 site_fields = random_site()
511 UpdateSite = self.debug(api.UpdateSite)
512 result = UpdateSite(auth, site_id, site_fields)
515 sites = GetSites(auth, [site_id])
516 if sites is None: continue
518 self.isequal(site, site_fields, 'UpdateSite - isequal')
520 sites = GetSites(auth, site_ids)
521 if sites is not None:
522 self.islistequal(site_ids, [site['site_id'] for site in sites], 'GetSites - isequal')
524 if self.config.verbose:
525 utils.header("Added sites: %s" % site_ids)
530 def DeleteSites(self):
532 DeleteSite = self.debug(api.DeleteSite)
533 for site_id in self.site_ids:
534 result = DeleteSite(auth, site_id)
536 # Check if sites are deleted
537 GetSites = self.debug(api.GetSites)
538 sites = GetSites(auth, self.site_ids)
539 self.islistequal(sites, [], 'DeleteSite - check')
541 if self.config.verbose:
542 utils.header("Deleted sites: %s" % self.site_ids)
546 def NetworkMethods(self, n=2):
548 AddNetworkMethod = self.debug(api.AddNetworkMethod)
549 GetNetworkMethods = self.debug(api.GetNetworkMethods)
553 net_method = randstr(10)
554 AddNetworkMethod(auth, net_method)
555 if net_method is None: continue
557 # Should return a unique id
558 self.isunique(net_method, methods, 'AddNetworkMethod - isunique')
559 methods.append(net_method)
560 net_methods = GetNetworkMethods(auth)
561 if net_methods is None: continue
562 net_methods = filter(lambda x: x in [net_method], net_methods)
563 method = net_methods[0]
564 self.isequal(method, net_method, 'AddNetworkMethod - isequal')
567 net_methods = GetNetworkMethods(auth)
568 if net_methods is not None:
569 net_methods = filter(lambda x: x in methods, net_methods)
570 self.islistequal(methods, net_methods, 'GetNetworkMethods - isequal')
572 if self.config.verbose:
573 utils.header("Added network methods: %s" % methods)
577 def DeleteNetworkMethods(self):
578 DeleteNetworkMethod = self.debug(api.DeleteNetworkMethod)
579 GetNetworkMethods = self.debug(api.GetNetworkMethods)
580 for method in self.network_methods:
581 DeleteNetworkMethod(auth, method)
584 network_methods = GetNetworkMethods(auth)
585 network_methods = filter(lambda x: x in self.network_methods, network_methods)
586 self.islistequal(network_methods, [], 'DeleteNetworkMethods - check')
588 if self.config.verbose:
589 utils.header("Deleted network methods: %s" % self.network_methods)
590 self.network_methods = []
592 def NetworkTypes(self, n=2):
594 AddNetworkType = self.debug(api.AddNetworkType)
595 GetNetworkTypes = self.debug(api.GetNetworkTypes)
600 AddNetworkType(auth, type)
602 # Should return a unique id
603 self.isunique(type, net_types, 'AddNetworkType - isunique')
604 net_types.append(type)
605 types = GetNetworkTypes(auth)
606 if types is None: continue
607 types = filter(lambda x: x in [type], types)
608 if types is None: continue
610 self.isequal(net_type, type, 'AddNetworkType - isequal')
612 types = GetNetworkTypes(auth)
613 if types is not None:
614 types = filter(lambda x: x in net_types, types)
615 self.islistequal(types, net_types, 'GetNetworkTypes - isequal')
617 if self.config.verbose:
618 utils.header("Added network types: %s" % net_types)
622 def DeleteNetworkTypes(self):
623 DeleteNetworkType = self.debug(api.DeleteNetworkType)
624 GetNetworkTypes = self.debug(api.GetNetworkTypes)
625 for type in self.network_types:
626 DeleteNetworkType(auth, type)
629 network_types = GetNetworkTypes(auth)
630 network_types = filter(lambda x: x in self.network_types, network_types)
631 self.islistequal(network_types, [], 'DeleteNetworkTypes - check')
633 if self.config.verbose:
634 utils.header("Deleted network types: %s" % self.network_types)
635 self.network_types = []
638 def NodeGroups(self, n = 4):
640 AddNodeGroup = self.debug(api.AddNodeGroup)
641 UpdateNodeGroup = self.debug(api.UpdateNodeGroup)
642 GetNodeGroups = self.debug(api.GetNodeGroups)
646 nodegroup_fields = random_nodegroup()
647 nodegroup_id = AddNodeGroup(auth, nodegroup_fields)
648 if nodegroup_id is None: continue
650 # Should return a unique id
651 self.isunique(nodegroup_id, nodegroup_ids, 'AddNodeGroup - isunique')
652 nodegroup_ids.append(nodegroup_id)
653 nodegroups = GetNodeGroups(auth, [nodegroup_id])
654 if nodegroups is None: continue
655 nodegroup = nodegroups[0]
656 self.isequal(nodegroup, nodegroup_fields, 'AddNodeGroup - isequal')
659 nodegroup_fields = random_nodegroup()
660 UpdateNodeGroup(auth, nodegroup_id, nodegroup_fields)
663 nodegroups = GetNodeGroups(auth, [nodegroup_id])
664 if nodegroups is None: continue
665 nodegroup = nodegroups[0]
666 self.isequal(nodegroup, nodegroup_fields, 'UpdateNodeGroup - isequal')
668 nodegroups = GetNodeGroups(auth, nodegroup_ids)
669 if nodegroups is not None:
670 self.islistequal(nodegroup_ids, [n['nodegroup_id'] for n in nodegroups], 'GetNodeGroups - isequal')
671 if self.config.verbose:
672 utils.header("Added nodegroups: %s" % nodegroup_ids)
676 def DeleteNodeGroups(self):
677 # Delete all NodeGroups
678 GetNodeGroups = self.debug(api.GetNodeGroups)
679 DeleteNodeGroup = self.debug(api.DeleteNodeGroup)
681 for nodegroup_id in self.nodegroup_ids:
682 result = DeleteNodeGroup(auth, nodegroup_id)
684 # Check is nodegroups are deleted
685 nodegroups = GetNodeGroups(auth, self.nodegroup_ids)
686 self.islistequal(nodegroups, [], 'DeleteNodeGroup - check')
688 if self.config.verbose:
689 utils.header("Deleted nodegroups: %s" % self.nodegroup_ids)
691 self.nodegroup_ids = []
693 def PCUTypes(self, n=2):
695 AddPCUType = self.debug(api.AddPCUType)
696 UpdatePCUType = self.debug(api.UpdatePCUType)
697 GetPCUTypes = self.debug(api.GetPCUTypes)
701 pcu_type_fields = random_pcu_type()
702 pcu_type_id = AddPCUType(auth, pcu_type_fields)
703 if pcu_type_id is None: continue
704 # Should return a unique id
705 self.isunique(pcu_type_id, pcu_type_ids, 'AddPCUType - isunique')
706 pcu_type_ids.append(pcu_type_id)
709 pcu_types = GetPCUTypes(auth, [pcu_type_id])
710 if pcu_types is None: continue
711 pcu_type = pcu_types[0]
712 self.isequal(pcu_type, pcu_type_fields, 'AddPCUType - isequal')
715 pcu_type_fields = random_pcu_type()
716 UpdatePCUType(auth, pcu_type_id, pcu_type_fields)
719 pcu_types = GetPCUTypes(auth, [pcu_type_id])
720 if pcu_types is None: continue
721 pcu_type = pcu_types[0]
722 self.isequal(pcu_type, pcu_type_fields, 'UpdatePCUType - isequal')
724 pcu_types = GetPCUTypes(auth, pcu_type_ids)
725 if pcu_types is not None:
726 self.islistequal(pcu_type_ids, [p['pcu_type_id'] for p in pcu_types], 'GetPCUTypes - check')
728 if self.config.verbose:
729 utils.header("Added pcu_types: %s " % pcu_type_ids)
732 def DeletePCUTypes(self):
733 GetPCUTypes = self.debug(api.GetPCUTypes)
734 DeletePCUType = self.debug(api.DeletePCUType)
736 for pcu_type_id in self.pcu_type_ids:
737 DeletePCUType(auth, pcu_type_id)
739 pcu_types = GetPCUTypes(auth, self.pcu_type_ids)
740 self.islistequal(pcu_types, [], 'DeletePCUType - check')
742 def PCUProtocolTypes(self, n=2):
743 protocol_type_ids = []
744 AddPCUProtocolType = self.debug(api.AddPCUProtocolType)
745 UpdatePCUProtocolType = self.debug(api.UpdatePCUProtocolType)
746 GetPCUProtocolTypes = self.debug(api.GetPCUProtocolTypes)
749 # Add PCUProtocolType
750 protocol_type_fields = random_pcu_protocol_type()
751 pcu_type_id = random.sample(self.pcu_type_ids, 1)[0]
752 protocol_type_id = AddPCUProtocolType(auth, pcu_type_id, protocol_type_fields)
753 if protocol_type_id is None: continue
755 # Should return a unique id
756 self.isunique(protocol_type_id, protocol_type_ids, 'AddPCUProtocolType - isunique')
757 protocol_type_ids.append(protocol_type_id)
759 # Check protocol type
760 protocol_types = GetPCUProtocolTypes(auth, [protocol_type_id])
761 if protocol_types is None: continue
762 protocol_type = protocol_types[0]
763 self.isequal(protocol_type, protocol_type_fields, 'AddPCUProtocolType - isequal')
765 # Update protocol type
766 protocol_type_fields = random_pcu_protocol_type()
767 UpdatePCUProtocolType(auth, protocol_type_id, protocol_type_fields)
770 protocol_types = GetPCUProtocolTypes(auth, [protocol_type_id])
771 if protocol_types is None: continue
772 protocol_type = protocol_types[0]
773 self.isequal(protocol_type, protocol_type_fields, 'UpdatePCUProtocolType - isequal')
775 protocol_types = GetPCUProtocolTypes(auth, protocol_type_ids)
776 if protocol_types is not None:
777 pt_ids = [p['pcu_protocol_type_id'] for p in protocol_types]
778 self.islistequal(protocol_type_ids, pt_ids, 'GetPCUProtocolTypes - isequal')
780 if self.config.verbose:
781 utils.header('Added pcu_protocol_types: %s' % protocol_type_ids)
783 return protocol_type_ids
785 def DeletePCUProtocolTypes(self):
786 GetPCUProtocolTypes = self.debug(api.GetPCUProtocolTypes)
787 DeletePCUProtocolType = self.debug(api.DeletePCUProtocolType)
789 for protocol_type_id in self.pcu_protocol_type_ids:
790 DeletePCUProtocolType(auth, protocol_type_id)
793 protocol_types = GetPCUProtocolTypes(auth, self.pcu_protocol_type_ids)
794 self.islistequal(protocol_types, [], 'DeletePCUProtocolType - check')
796 if self.config.verbose:
797 utils.header("Deleted pcu_protocol_types: %s" % self.pcu_protocol_type_ids)
798 self.pcu_protocol_type_ids = []
800 def PCUs(self, n = 4):
802 AddPCU = self.debug(api.AddPCU)
803 UpdatePCU = self.debug(api.UpdatePCU)
804 GetPCUs = self.debug(api.GetPCUs)
806 for site_id in self.site_ids:
808 pcu_fields = random_pcu()
809 pcu_id = AddPCU(auth, site_id, pcu_fields)
810 if pcu_id is None: continue
812 # Should return a unique id
813 self.isunique(pcu_id, pcu_ids, 'AddPCU - isunique')
814 pcu_ids.append(pcu_id)
817 pcus = GetPCUs(auth, [pcu_id])
818 if pcus is None: continue
820 self.isequal(pcu, pcu_fields, 'AddPCU - isequal')
823 pcu_fields = random_pcu()
824 UpdatePCU(auth, pcu_id, pcu_fields)
827 pcus = GetPCUs(auth, [pcu_id])
828 if pcus is None: continue
830 self.isequal(pcu, pcu_fields, 'UpdatePCU - isequal')
832 pcus = GetPCUs(auth, pcu_ids)
834 self.islistequal(pcu_ids, [p['pcu_id'] for p in pcus], 'GetPCUs - isequal')
836 if self.config.verbose:
837 utils.header('Added pcus: %s' % pcu_ids)
841 def DeletePCUs(self):
842 GetPCUs = self.debug(api.GetPCUs)
843 DeletePCU = self.debug(api.DeletePCU)
845 for pcu_id in self.pcu_ids:
846 DeletePCU(auth, pcu_id)
849 pcus = GetPCUs(auth, self.pcu_ids)
850 self.islistequal(pcus, [], 'DeletePCU - check')
852 if self.config.verbose:
853 utils.header("Deleted pcus: %s " % self.pcu_ids)
856 def Nodes(self, n=4):
858 AddNode = self.debug(api.AddNode)
859 GetNodes = self.debug(api.GetNodes)
860 UpdateNode = self.debug(api.UpdateNode)
863 node_fields = random_node()
864 site_id = random.sample(self.site_ids, 1)[0]
865 node_id = AddNode(auth, site_id, node_fields)
866 if node_id is None: continue
868 # Should return a unique id
869 self.isunique(node_id, node_ids, 'AddNode - isunique')
870 node_ids.append(node_id)
873 nodes = GetNodes(auth, [node_id])
874 if nodes is None: continue
876 self.isequal(node, node_fields, 'AddNode - isequal')
879 node_fields = random_node()
880 result = UpdateNode(auth, node_id, node_fields)
883 nodes = GetNodes(auth, [node_id])
884 if nodes is None: continue
886 self.isequal(node, node_fields, 'UpdateNode - isequal')
888 # Add node to nodegroup
889 nodegroup_id = random.sample(self.nodegroup_ids, 1)[0]
890 AddNodeToNodeGroup = self.debug(api.AddNodeToNodeGroup)
891 AddNodeToNodeGroup(auth, node_id, nodegroup_id)
894 sites = api.GetSites(auth, [node['site_id']], ['pcu_ids'])
895 if not sites: continue
897 pcu_id = random.sample(site['pcu_ids'], 1)[0]
898 port = random.sample(range(65535), 1)[0]
899 AddNodeToPCU = self.debug(api.AddNodeToPCU)
900 AddNodeToPCU(auth, node_id, pcu_id, port)
902 # check nodegroup, pcu
903 nodes = GetNodes(auth, [node_id], ['nodegroup_ids', 'pcu_ids'])
904 if nodes is None or not nodes: continue
906 self.islistequal([nodegroup_id], node['nodegroup_ids'], 'AddNodeToNodeGroup - check')
907 self.islistequal([pcu_id], node['pcu_ids'], 'AddNodeToPCU - check')
909 nodes = GetNodes(auth, node_ids)
910 if nodes is not None:
911 self.islistequal(node_ids, [node['node_id'] for node in nodes], 'GetNodes - isequal')
913 if self.config.verbose:
914 utils.header("Added nodes: %s" % node_ids)
918 def DeleteNodes(self):
920 # Delete attributes manually for first node
921 GetNodes = self.debug(api.GetNodes)
922 nodes = GetNodes(auth, self.node_ids)
923 if nodes is None or not nodes: return 0
926 if node['nodegroup_ids']:
928 nodegroup_id = random.sample(node['nodegroup_ids'], 1)[0]
929 DeleteNodeFromNodeGroup = self.debug(api.DeleteNodeFromNodeGroup)
930 DeleteNodeFromNodeGroup(auth, node['node_id'], nodegroup_id)
934 pcu_id = random.sample(node['pcu_ids'], 1)[0]
935 DeleteNodeFromPCU = self.debug(api.DeleteNodeFromPCU)
936 DeleteNodeFromPCU(auth, node['node_id'], pcu_id)
938 # check nodegroup, pcu
939 nodes = GetNodes(auth, [node['node_id']])
940 if nodes is None or not nodes: return 0
941 self.islistequal([], node['nodegroup_ids'], 'DeleteNodeGromNodeGroup - check')
942 self.islistequal([], node['pcu_ids'], 'DeleteNodeFromPCU - check')
944 # Delete rest of nodes
945 DeleteNode = self.debug(api.DeleteNode)
946 for node_id in self.node_ids:
947 result = DeleteNode(auth, node_id)
949 # Check if nodes are deleted
950 GetNodes = self.debug(api.GetNodes)
951 nodes = GetNodes(auth, self.node_ids)
952 self.islistequal(nodes, [], 'DeleteNode Check')
954 if self.config.verbose:
955 utils.header("Deleted nodes: %s" % self.node_ids)
959 def AddressTypes(self, n = 3):
960 address_type_ids = []
962 address_type_fields = random_address_type()
963 AddAddressType = self.debug(api.AddAddressType)
964 address_type_id = AddAddressType(auth, address_type_fields)
965 if address_type_id is None: continue
967 # Should return a unique address_type_id
968 self.isunique(address_type_id, address_type_ids, 'AddAddressType - isunique')
969 address_type_ids.append(address_type_id)
972 GetAddressTypes = self.debug(api.GetAddressTypes)
973 address_types = GetAddressTypes(auth, [address_type_id])
974 if address_types is None: continue
975 address_type = address_types[0]
976 self.isequal(address_type, address_type_fields, 'AddAddressType - isequal')
978 # Update address type
979 address_type_fields = random_address_type()
980 UpdateAddressType = self.debug(api.UpdateAddressType)
981 result = UpdateAddressType(auth, address_type_id, address_type_fields)
982 if result is None: continue
984 # Check address type again
985 address_types = GetAddressTypes(auth, [address_type_id])
986 if address_types is None: continue
987 address_type = address_types[0]
988 self.isequal(address_type, address_type_fields, 'UpdateAddressType - isequal')
990 # Check get all address types
991 address_types = GetAddressTypes(auth, address_type_ids)
992 if address_types is not None:
993 self.islistequal(address_type_ids, [address_type['address_type_id'] for address_type in address_types], 'GetAddressTypes - isequal')
995 if self.config.verbose:
996 utils.header("Added address types: %s " % address_type_ids)
998 return address_type_ids
1000 def DeleteAddressTypes(self):
1002 DeleteAddressType = self.debug(api.DeleteAddressType)
1003 for address_type_id in self.address_type_ids:
1004 DeleteAddressType(auth, address_type_id)
1006 GetAddressTypes = self.debug(api.GetAddressTypes)
1007 address_types = GetAddressTypes(auth, self.address_type_ids)
1008 self.islistequal(address_types, [], 'DeleteAddressType - check')
1010 if self.config.verbose:
1011 utils.header("Deleted address types: %s" % self.address_type_ids)
1013 self.address_type_ids = []
1015 def Addresses(self, n = 3):
1017 AddSiteAddress = self.debug(api.AddSiteAddress)
1018 GetAddresses = self.debug(api.GetAddresses)
1019 UpdateAddress = self.debug(api.UpdateAddress)
1020 AddAddressTypeToAddress = self.debug(api.AddAddressTypeToAddress)
1022 address_fields = random_address()
1023 site_id = random.sample(self.site_ids, 1)[0]
1024 address_id = AddSiteAddress(auth, site_id, address_fields)
1025 if address_id is None: continue
1027 # Should return a unique address_id
1028 self.isunique(address_id, address_ids, 'AddSiteAddress - isunique')
1029 address_ids.append(address_id)
1032 addresses = GetAddresses(auth, [address_id])
1033 if addresses is None: continue
1034 address = addresses[0]
1035 self.isequal(address, address_fields, 'AddSiteAddress - isequal')
1038 address_fields = random_address()
1039 result = UpdateAddress(auth, address_id, address_fields)
1042 addresses = GetAddresses(auth, [address_id])
1043 if addresses is None: continue
1044 address = addresses[0]
1045 self.isequal(address, address_fields, 'UpdateAddress - isequal')
1048 address_type_id = random.sample(self.address_type_ids, 1)[0]
1049 AddAddressTypeToAddress(auth, address_type_id, address_id)
1052 addresses = GetAddresses(auth, [address_id], ['address_type_ids'])
1053 if addresses is None or not addresses: continue
1054 address = addresses[0]
1055 self.islistequal([address_type_id], address['address_type_ids'], 'AddAddressTypeToAddress - check')
1057 addresses = GetAddresses(auth, address_ids)
1058 if addresses is not None:
1059 self.islistequal(address_ids, [ad['address_id'] for ad in addresses], 'GetAddresses - isequal')
1061 if self.config.verbose:
1062 utils.header("Added addresses: %s" % address_ids)
1066 def DeleteAddresses(self):
1068 DeleteAddress = self.debug(api.DeleteAddress)
1069 DeleteAddressTypeFromAddress = self.debug(api.DeleteAddressTypeFromAddress)
1070 GetAddresses = self.debug(api.GetAddresses)
1072 # Delete attributes mananually first
1073 addresses = GetAddresses(auth, self.address_ids, ['address_id', 'address_type_ids'])
1074 if addresses is None or not addresses: return 0
1075 address = addresses[0]
1077 if address['address_type_ids']:
1078 address_type_id = random.sample(address['address_type_ids'], 1)[0]
1079 DeleteAddressTypeFromAddress(auth, address_type_id, address['address_id'])
1081 # check address_type_ids
1082 addresses = GetAddresses(auth, [address['address_id']], ['address_type_ids'])
1083 if addresses is None or not addresses: return 0
1084 address = addresses[0]
1085 self.islistequal([], address['address_type_ids'], 'DeleteAddressTypeFromAddress - check')
1087 # Delete site addresses
1088 for address_id in self.address_ids:
1089 result = DeleteAddress(auth, address_id)
1092 addresses = GetAddresses(auth, self.address_ids)
1093 self.islistequal(addresses, [], 'DeleteAddress - check')
1094 if self.config.verbose:
1095 utils.header("Deleted addresses: %s" % self.address_ids)
1097 self.address_ids = []
1099 def SliceAttributeTypes(self, n = 2):
1100 attribute_type_ids = []
1101 AddSliceAttributeType = self.debug(api.AddSliceAttributeType)
1102 GetSliceAttributeTypes = self.debug(api.GetSliceAttributeTypes)
1103 UpdateSliceAttributeType = self.debug(api.UpdateSliceAttributeType)
1106 attribute_type_fields = random_attribute_type()
1107 attribute_type_id = AddSliceAttributeType(auth, attribute_type_fields)
1108 if attribute_type_id is None: continue
1110 # Should return a unique slice_attribute_type_id
1111 self.isunique(attribute_type_id, attribute_type_ids, 'AddSliceAttributeType - isunique')
1112 attribute_type_ids.append(attribute_type_id)
1114 # Check slice_attribute_type
1115 attribute_types = GetSliceAttributeTypes(auth, [attribute_type_id])
1116 if attribute_types is None: continue
1117 attribute_type = attribute_types[0]
1118 self.isequal(attribute_type, attribute_type_fields, 'AddSliceAttributeType - isequal')
1120 # Update slice_attribute_type
1121 attribute_type_fields = random_attribute_type()
1122 result = UpdateSliceAttributeType(auth, attribute_type_id, attribute_type_fields)
1125 attribute_types = GetSliceAttributeTypes(auth, [attribute_type_id])
1126 if attribute_types is None: continue
1127 attribute_type = attribute_types[0]
1128 self.isequal(attribute_type, attribute_type_fields, 'UpdateSliceAttributeType - isequal')
1130 attribute_types = GetSliceAttributeTypes(auth, attribute_type_ids)
1131 if attribute_types is not None:
1132 at_ids = [at['attribute_type_id'] for at in attribute_types]
1133 self.islistequal(attribute_type_ids, at_ids, 'GetSliceAttributeTypes - isequal')
1135 if self.config.verbose:
1136 utils.header("Added slice_attribute_types: %s" % attribute_type_ids)
1138 return attribute_type_ids
1140 def DeleteSliceAttributeTypes(self):
1141 DeleteSliceAttributeType = self.debug(api.DeleteSliceAttributeType)
1142 GetSliceAttributeTypes = self.debug(api.GetSliceAttributeTypes)
1144 # Delete slice_attribute_type
1145 for slice_attribute_type_id in self.slice_attribute_type_ids:
1146 result = DeleteSliceAttributeType(auth, slice_attribute_type_id)
1149 slice_attribute_types = GetSliceAttributeTypes(auth, self.slice_attribute_type_ids)
1150 self.islistequal(slice_attribute_types, [], 'DeleteSliceAttributeTypes - check')
1151 if self.config.verbose:
1152 utils.header("Deleted slice_attributes: %s" % self.slice_attribute_type_ids)
1154 self.slice_attribute_type_ids = []
1156 def SliceInstantiations(self, n = 2):
1158 AddSliceInstantiation= self.debug(api.AddSliceInstantiation)
1159 GetSliceInstantiations = self.debug(api.GetSliceInstantiations)
1163 result = AddSliceInstantiation(auth, inst)
1164 if result is None: continue
1167 # Check slice instantiaton
1168 instantiations = GetSliceInstantiations(auth)
1169 if instantiations is None: continue
1170 instantiations = filter(lambda x: x in [inst], instantiations)
1171 instantiation = instantiations[0]
1172 self.isequal(instantiation, inst, 'AddSliceInstantiation - isequal')
1175 instantiations = GetSliceInstantiations(auth)
1176 if instantiations is not None:
1177 instantiations = filter(lambda x: x in insts, instantiations)
1178 self.islistequal(insts, instantiations, 'GetSliceInstantiations - isequal')
1180 if self.config.verbose:
1181 utils.header("Added slice instantiations: %s" % insts)
1185 def DeleteSliceInstantiations(self):
1186 DeleteSliceInstantiation = self.debug(api.DeleteSliceInstantiation)
1187 GetSliceInstantiations = self.debug(api.GetSliceInstantiations)
1188 # Delete slice instantiation
1189 for instantiation in self.slice_instantiations:
1190 result = DeleteSliceInstantiation(auth, instantiation)
1193 instantiations = GetSliceInstantiations(auth)
1194 instantiations = filter(lambda x: x in self.slice_instantiations, instantiations)
1195 self.islistequal(instantiations, [], 'DeleteSliceInstantiation - check')
1196 if self.config.verbose:
1197 utils.header("Deleted slice instantiations: %s" % self.slice_instantiations)
1199 self.slice_instantiations = []
1201 def Slices(self, n = 3):
1203 AddSlice = self.debug(api.AddSlice)
1204 GetSlices = self.debug(api.GetSlices)
1205 UpdateSlice = self.debug(api.UpdateSlice)
1206 AddSliceToNodes = self.debug(api.AddSliceToNodes)
1209 slice_fields = random_slice()
1210 slice_id = AddSlice(auth, slice_fields)
1211 if slice_id is None: continue
1213 # Should return a unique id
1214 self.isunique(slice_id, slice_ids, 'AddSlicel - isunique')
1215 slice_ids.append(slice_id)
1216 slices = GetSlices(auth, [slice_id])
1217 if slices is None: continue
1219 self.isequal(slice, slice_fields, 'AddSlice - isequal')
1222 slice_fields = random_slice()
1223 result = UpdateSlice(auth, slice_id, slice_fields)
1226 slices = GetSlices(auth, [slice_id])
1227 if slices is None: continue
1229 self.isequal(slice, slice_fields, 'UpdateSlice - isequal')
1232 node_id = random.sample(self.node_ids, 1)[0]
1233 AddSliceToNodes(auth, slice_id, [node_id])
1236 slices = GetSlices(auth, [slice_id], ['node_ids'])
1237 if slices is None or not slices: continue
1239 self.islistequal([node_id], slice['node_ids'], 'AddSliceToNode - check')
1241 slices = GetSlices(auth, slice_ids)
1242 if slices is not None:
1243 self.islistequal(slice_ids, [slice['slice_id'] for slice in slices], 'GetSlices - isequal')
1245 if self.config.verbose:
1246 utils.header("Added slices: %s" % slice_ids)
1250 def DeleteSlices(self):
1252 GetSlices = self.debug(api.GetSlices)
1253 DeleteSlice = self.debug(api.DeleteSlice)
1254 DeleteSliceFromNodes = self.debug(api.DeleteSliceFromNodes)
1256 # manually delete attributes for first slice
1257 slices = GetSlices(auth, self.slice_ids, ['slice_id', 'node_ids'])
1258 if slices is None or not slices: return 0
1261 if slice['node_ids']:
1262 # Delete node from slice
1263 node_id = random.sample(slice['node_ids'], 1)[0]
1264 DeleteSliceFromNodes(slice['slice_id'], [node_id])
1267 slices = GetSlices(auth, [slice['slice_id']], ['node_ids'])
1268 if slices is None or not slices: return 0
1270 self.islistequal([], slice['node_ids'], 'DeleteSliceFromNode - check')
1272 # Have DeleteSlice automatically delete attriubtes for the rest
1273 for slice_id in self.slice_ids:
1275 DeleteSlice(auth, slice_id)
1277 # Check if slices are deleted
1278 GetSlices = self.debug(api.GetSlices)
1279 slices = GetSlices(auth, self.slice_ids)
1280 self.islistequal(slices, [], 'DeleteSlice - check')
1282 if self.config.verbose:
1283 utils.header("Deleted slices: %s" % self.slice_ids)
1287 def SliceAttributes(self, n = 4):
1289 AddSliceAttribute = self.debug(api.AddSliceAttribute)
1290 GetSliceAttributes = self.debug(api.GetSliceAttributes)
1291 UpdateSliceAttribute = self.debug(api.UpdateSliceAttribute)
1294 # Add slice attribute
1295 attribute_fields = random_slice_attribute()
1296 slice_id = random.sample(self.slice_ids, 1)[0]
1297 type = attribute_fields['attribute_type_id']
1298 value = attribute_fields['value']
1299 attribute_id = AddSliceAttribute(auth, slice_id, type, value)
1300 if attribute_id is None: continue
1302 # Should return a unique id
1303 self.isunique(attribute_id, attribute_ids, 'AddSliceAttribute - isunique')
1304 attribute_ids.append(attribute_id)
1307 attributes = GetSliceAttributes(auth, [attribute_id])
1308 if attributes is None: continue
1309 attribute = attributes[0]
1310 self.isequal(attribute, attribute_fields, 'AddSliceAttribute - isequal')
1313 attribute_fields = random_slice_attribute()
1314 type = attribute_fields['attribute_type_id']
1315 value = attribute_fields['value']
1316 result = UpdateSliceAttribute(auth, attribute_id, value)
1319 attributes = GetSliceAttributes(auth, [attribute_id])
1320 if attributes is None: continue
1321 attribute = attributes[0]
1322 self.isequal(attribute, attribute_fields, 'UpdateSliceAttribute - isequal')
1324 attributes = GetSliceAttributes(auth, attribute_ids)
1325 if attributes is not None:
1326 attr_ids = [a['slice_attribute_id'] for a in attributes]
1327 self.islistequal(attribute_ids, attr_ids, 'GetSliceAttributes - isequal')
1328 if self.config.verbose:
1329 utils.header("Added slice attributes: %s" % attribute_ids)
1331 return attribute_ids
1333 def DeleteSliceAttributes(self):
1334 DeleteSliceAttribute = self.debug(api.DeleteSliceAttribute)
1335 GetSliceAttributes = self.debug(api.GetSliceAttributes)
1337 for attribute_id in self.slice_attribute_ids:
1338 DeleteSliceAttribute(auth, attribute_id)
1340 attributes = GetSliceAttributes(auth, self.slice_attribute_ids)
1341 self.islistequal(attributes, [], 'DeleteSliceAttribute - check')
1343 if self.config.verbose:
1344 utils.header("Deleted slice attributes: %s" % self.slice_attribute_ids)
1346 self.slice_attribute_ids = []
1348 def InitScripts(self, n = 2):
1350 AddInitScript = self.debug(api.AddInitScript)
1351 GetInitScripts = self.debug(api.GetInitScripts)
1352 UpdateInitScript = self.debug(api.UpdateInitScript)
1355 initscript_fields = random_initscript()
1356 initscript_id = AddInitScript(auth, initscript_fields)
1358 # Should return a unique id
1359 self.isunique(initscript_id, initscript_ids, 'AddInitScript - isunique')
1360 initscript_ids.append(initscript_id)
1361 initscripts = GetInitScripts(auth, [initscript_id])
1362 if initscripts is None: continue
1363 initscript = initscripts[0]
1364 self.isequal(initscript, initscript_fields, 'AddInitScript - isequal')
1367 initscript_fields = random_initscript()
1368 result = UpdateInitScript(auth, initscript_id, initscript_fields)
1371 initscripts = GetInitScripts(auth, [initscript_id])
1372 if initscripts is None: continue
1373 initscript = initscripts[0]
1374 self.isequal(initscript, initscript_fields, 'UpdateInitScript - isequal')
1376 initscripts = GetInitScripts(auth, initscript_ids)
1377 if initscripts is not None:
1378 self.islistequal(initscript_ids, [i['initscript_id'] for i in initscripts], 'GetInitScripts -isequal')
1380 if self.config.verbose:
1381 utils.header("Added initscripts: %s" % initscript_ids)
1383 return initscript_ids
1385 def DeleteInitScripts(self):
1386 # Delete all initscripts
1387 DeleteInitScript = self.debug(api.DeleteInitScript)
1388 GetInitScripts = self.debug(api.GetInitScripts)
1389 for initscript_id in self.initscript_ids:
1390 result = DeleteInitScript(auth, initscript_id)
1392 # Check if peers are deleted
1393 initscripts = GetInitScripts(auth, self.initscript_ids)
1394 self.islistequal(initscripts, [], 'DeletInitScript - check')
1396 if self.config.verbose:
1397 utils.header("Deleted initscripts: %s" % self.initscript_ids)
1398 self.initscript_ids =[]
1400 def Roles(self, n = 2):
1402 AddRole = self.debug(api.AddRole)
1403 GetRoles = self.debug(api.GetRoles)
1406 role_fields = random_role()
1407 role_id = role_fields['role_id']
1408 name = role_fields['name']
1409 AddRole(auth, role_id, name)
1411 # Should return a unique id
1412 self.isunique(role_id, role_ids, 'AddRole - isunique')
1413 role_ids.append(role_id)
1414 roles = GetRoles(auth)
1415 if roles is None: continue
1416 roles = filter(lambda x: x['role_id'] in [role_id], roles)
1418 self.isequal(role, role_fields, 'AddRole - isequal')
1420 roles = GetRoles(auth)
1421 if roles is not None:
1422 roles = filter(lambda x: x['role_id'] in role_ids, roles)
1423 self.islistequal(role_ids, [r['role_id'] for r in roles], 'GetRoles - isequal')
1425 if self.config.verbose:
1426 utils.header("Added roles: %s" % role_ids)
1430 def DeleteRoles(self):
1432 DeleteRole = self.debug(api.DeleteRole)
1433 GetRoles = self.debug(api.GetRoles)
1434 for role_id in self.role_ids:
1435 result = DeleteRole(auth, role_id)
1437 # Check if peers are deleted
1438 roles = GetRoles(auth)
1439 roles = filter(lambda x: x['role_id'] in self.role_ids, roles)
1440 self.islistequal(roles, [], 'DeleteRole - check' % self.role_ids)
1442 if self.config.verbose:
1443 utils.header("Deleted roles: %s" % self.role_ids)
1446 def Persons(self, n = 3):
1452 person_fields = random_person()
1453 AddPerson = self.debug(api.AddPerson)
1454 person_id = AddPerson(auth, person_fields)
1455 if person_id is None: continue
1457 # Should return a unique person_id
1458 self.isunique(person_id, person_ids, 'AddPerson - isunique')
1459 person_ids.append(person_id)
1460 GetPersons = self.debug(api.GetPersons)
1461 persons = GetPersons(auth, [person_id])
1462 if persons is None: continue
1464 self.isequal(person, person_fields, 'AddPerson - isequal')
1467 person_fields = random_person()
1468 person_fields['enabled'] = True
1469 UpdatePerson = self.debug(api.UpdatePerson)
1470 result = UpdatePerson(auth, person_id, person_fields)
1473 AddRoleToPerson = self.debug(api.AddRoleToPerson)
1474 role = random.sample(roles, 1)[0]
1475 result = AddRoleToPerson(auth, role, person_id)
1479 key_id = AddPersonKey = self.debug(api.AddPersonKey)
1480 AddPersonKey(auth, person_id, key)
1482 # Add person to site
1483 site_id = random.sample(self.site_ids, 1)[0]
1484 AddPersonToSite = self.debug(api.AddPersonToSite)
1485 AddPersonToSite(auth, person_id, site_id)
1487 # Add person to slice
1488 slice_id = random.sample(self.slice_ids, 1)[0]
1489 AddPersonToSlice = self.debug(api.AddPersonToSlice)
1490 AddPersonToSlice(auth, person_id, slice_id)
1492 # check role, key, site, slice
1493 persons = GetPersons(auth, [person_id], ['roles', 'key_ids', 'site_ids', 'slice_ids'])
1494 if persons is None or not persons: continue
1496 self.islistequal([role], person['roles'], 'AddRoleToPerson - check')
1497 self.islistequal([key_id], person['key_ids'], 'AddPersonKey - check')
1498 self.islistequal([site_id], person['site_ids'], 'AddPersonToSite - check')
1499 self.islistequal([slice_id], person['slice_ids'], 'AddPersonToSlice - check')
1501 persons = GetPersons(auth, person_ids)
1502 if persons is not None:
1503 self.islistequal(person_ids, [p['person_id'] for p in persons], 'GetPersons - isequal')
1505 if self.config.verbose:
1506 utils.header("Added users: %s" % person_ids)
1510 def DeletePersons(self):
1512 # Delete attributes manually for first person
1513 GetPersons = self.debug(api.GetPersons)
1514 persons = GetPersons(auth, self.person_ids, ['person_id' , 'key_ids', 'site_ids', 'slice_ids', 'roles'])
1515 if persons is None or not persons: return 0
1520 role = random.sample(person['roles'], 1)[0]
1521 DeleteRoleFromPerson = self.debug(api.DeleteRoleFromPerson)
1522 DeleteRoleFromPerson(auth, role, person['person_id'])
1524 if person['key_ids']:
1526 key_id = random.sample(person['key_ids'], 1)[0]
1527 DeleteKey = self.debug(api.DeleteKey)
1528 DeleteKey(auth, key_id)
1530 if person['site_ids']:
1531 # Remove person from site
1532 site_id = random.sample(person['site_ids'], 1)[0]
1533 DeletePersonFromSite = self.debug(api.DeletePersonFromSite)
1534 DeletePersonFromSite(auth, person['person_id'], site_id)
1536 if person['slice_ids']:
1537 # Remove person from slice
1538 slice_id = random.sample(person['slice_ids'], 1)[0]
1539 DeletePersonFromSlice = self.debug(api.DeletePersonFromSlice)
1540 DeletePersonFromSlice(auth, person['person_id'], slice_id)
1542 # check role, key, site, slice
1543 persons = GetPersons(auth, [person['person_id']], ['roles', 'key_ids', 'site_ids', 'slice_ids'])
1544 if persons is None or not persons: return 0
1546 self.islistequal([], person['roles'], 'DeleteRoleFromPerson - check')
1547 self.islistequal([], person['key_ids'], 'DeleteKey - check')
1548 self.islistequal([], person['site_ids'], 'DeletePersonFromSite - check')
1549 self.islistequal([], person['slice_ids'], 'DeletePersonFromSlice - check')
1551 DeletePerson = self.debug(api.DeletePerson)
1552 # Have DeletePeson automatically delete attriubtes for all other persons
1553 for person_id in self.person_ids:
1555 DeletePerson(auth, person_id)
1557 # Check if persons are deleted
1558 GetPersons = self.debug(api.GetPersons)
1559 persons = GetPersons(auth, self.person_ids)
1560 self.islistequal(persons, [], 'DeletePerson - check')
1562 if self.config.verbose:
1563 utils.header("Deleted users: %s" % self.person_ids)
1565 self.person_ids = []
1567 def KeyTypes(self, n = 2):
1569 AddKeyType = self.debug(api.AddKeyType)
1570 GetKeyTypes = self.debug(api.GetKeyTypes)
1573 keytype = randstr(10)
1574 result = AddKeyType(auth, keytype)
1575 if result is None: continue
1578 key_types.append(keytype)
1579 keytypes = GetKeyTypes(auth)
1580 if not keytypes: continue
1581 keytypes = filter(lambda x: x in [keytype], keytypes)
1582 if not keytypes: continue
1583 self.isequal(keytype, keytypes[0], 'AddKeyType - isequal')
1586 keytypes = GetKeyTypes(auth)
1587 if keytypes is not None:
1588 keytypes = filter(lambda x: x in key_types, keytypes)
1589 self.islistequal(key_types, keytypes, 'GetKeyTypes - isequal')
1591 if self.config.verbose:
1592 utils.header("Added key types: %s" % key_types)
1596 def DeleteKeyTypes(self):
1597 DeleteKeyType = self.debug(api.DeleteKeyType)
1598 GetKeyTypes = self.debug(api.GetKeyTypes)
1599 for key_type in self.key_types:
1600 result = DeleteKeyType(auth, key_type)
1602 # Check if key types are deleted
1603 key_types = GetKeyTypes(auth)
1604 key_types = filter(lambda x: x in self.key_types, key_types)
1605 self.islistequal(key_types, [], 'DeleteKeyType - check')
1607 if self.config.verbose:
1608 utils.header("Deleted key types %s" % self.key_types)
1612 def Keys(self, n = 3):
1615 # Add a key to an account
1616 key_fields = random_key()
1617 person_id = random.sample(self.person_ids, 1)[0]
1618 AddPersonKey = self.debug(api.AddPersonKey)
1619 key_id = AddPersonKey(auth, person_id, key_fields)
1620 if key_id is None: continue
1622 # Should return a unique key_id
1623 self.isunique(key_id, key_ids, 'AddPersonKey - isunique')
1624 key_ids.append(key_id)
1625 GetKeys = self.debug(api.GetKeys)
1626 keys = GetKeys(auth, [key_id])
1627 if keys is None: continue
1629 self.isequal(key, key_fields, 'AddPersonKey - isequal')
1632 key_fields = random_key()
1633 UpdateKey = self.debug(api.UpdateKey)
1634 result = UpdateKey(auth, key_id, key_fields)
1636 keys = GetKeys(auth, [key_id])
1637 if keys is None or not keys: continue
1639 self.isequal(key, key_fields, 'UpdatePersonKey - isequal')
1641 keys = GetKeys(auth, key_ids)
1642 if keys is not None:
1643 self.islistequal(key_ids, [key['key_id'] for key in keys], 'GetKeys - isequal')
1645 if self.config.verbose:
1646 utils.header("Added keys: %s" % key_ids)
1650 def DeleteKeys(self):
1652 # Blacklist first key, Delete rest
1653 GetKeys = self.debug(api.GetKeys)
1654 DeleteKey = self.debug(api.DeleteKey)
1655 BlacklistKey = self.debug(api.BlacklistKey)
1657 key_id = self.key_ids.pop()
1658 BlacklistKey(auth, key_id)
1659 keys = GetKeys(auth, [key_id])
1660 self.islistequal(keys, [], 'BlacklistKey - check')
1662 if self.config.verbose:
1663 utils.header("Blacklisted key: %s" % key_id)
1665 for key_id in self.key_ids:
1666 DeleteKey(auth, key_id)
1668 keys = GetKeys(auth, self.key_ids)
1669 self.islistequal(keys, [], 'DeleteKey - check')
1671 if self.config.verbose:
1672 utils.header("Deleted keys: %s" % self.key_ids)
1676 def BootStates(self, n = 3):
1678 AddBootState = self.debug(api.AddBootState)
1679 GetBootStates = self.debug(api.GetBootStates)
1682 bootstate_fields = randstr(10)
1683 result = AddBootState(auth, bootstate_fields)
1684 if result is None: continue
1687 boot_states.append(bootstate_fields)
1688 bootstates = GetBootStates(auth)
1689 if not bootstates: continue
1690 bootstates = filter(lambda x: x in [bootstate_fields], bootstates)
1691 if not bootstates: continue
1692 bootstate = bootstates[0]
1693 self.isequal(bootstate, bootstate_fields, 'AddBootState - isequal')
1696 bs = GetBootStates(auth)
1698 bs = filter(lambda x: x in [boot_states], bs)
1699 self.islistequal(boot_states, bs, 'GetBootStates - isequal')
1701 if self.config.verbose:
1702 utils.header("Added boot_states: %s" % boot_states)
1706 def DeleteBootStates(self):
1707 DeleteBootState = self.debug(api.DeleteBootState)
1708 GetBootStates = self.debug(api.GetBootStates)
1709 for boot_state in self.boot_states:
1710 result = DeleteBootState(auth, boot_state)
1712 # Check if bootsates are deleted
1713 boot_states = GetBootStates(auth)
1714 boot_states = filter(lambda x: x in self.boot_states, boot_states)
1715 self.islistequal(boot_states, [], 'DeleteBootState check')
1717 if self.config.verbose:
1718 utils.header("Deleted boot_states: %s" % self.boot_states)
1720 self.boot_states = []
1723 def Peers(self, n = 2):
1725 AddPeer = self.debug(api.AddPeer)
1726 GetPeers = self.debug(api.GetPeers)
1727 UpdatePeer = self.debug(api.UpdatePeer)
1730 peer_fields = random_peer()
1731 peer_id = AddPeer(auth, peer_fields)
1733 # Should return a unique id
1734 self.isunique(peer_id, peer_ids, 'AddPeer - isunique')
1735 peer_ids.append(peer_id)
1736 peers = GetPeers(auth, [peer_id])
1737 if peers is None: continue
1739 self.isequal(peer, peer_fields, 'AddPeer - isequal')
1742 peer_fields = random_peer()
1743 result = UpdatePeer(auth, peer_id, peer_fields)
1746 peers = GetPeers(auth, [peer_id])
1747 if peers is None: continue
1749 self.isequal(peer, peer_fields, 'UpdatePeer - isequal')
1751 peers = GetPeers(auth, peer_ids)
1752 if peers is not None:
1753 self.islistequal(peer_ids, [peer['peer_id'] for peer in peers], 'GetPeers -isequal')
1755 if self.config.verbose:
1756 utils.header("Added peers: %s" % peer_ids)
1761 def DeletePeers(self):
1763 DeletePeer = self.debug(api.DeletePeer)
1764 GetPeers = self.debug(api.GetPeers)
1765 for peer_id in self.peer_ids:
1766 result = DeletePeer(auth, peer_id)
1768 # Check if peers are deleted
1769 peers = GetPeers(auth, self.peer_ids)
1770 self.islistequal(peers, [], 'DeletePeer - check' % self.peer_ids)
1772 if self.config.verbose:
1773 utils.header("Deleted peers: %s" % self.peer_ids)
1776 def ConfFiles(self, n = 2):
1780 conf_file_fields = random_conf_file()
1781 AddConfFile = self.debug(api.AddConfFile)
1782 conf_file_id = AddConfFile(auth, conf_file_fields)
1783 if conf_file_id is None: continue
1785 # Should return a unique id
1786 self.isunique(conf_file_id, conf_file_ids, 'AddConfFile - isunique')
1787 conf_file_ids.append(conf_file_id)
1790 GetConfFiles = self.debug(api.GetConfFiles)
1791 conf_files = GetConfFiles(auth, [conf_file_id])
1792 if conf_files is None: continue
1793 conf_file = conf_files[0]
1794 self.isequal(conf_file, conf_file_fields, 'AddConfFile - isunique')
1797 conf_file_fields = random_conf_file()
1798 UpdateConfFile = self.debug(api.UpdateConfFile)
1799 result = UpdateConfFile(auth, conf_file_id, conf_file_fields)
1802 conf_files = GetConfFiles(auth, [conf_file_id])
1803 if conf_files is None: continue
1804 conf_file = conf_files[0]
1805 self.isequal(conf_file, conf_file_fields, 'UpdateConfFile - isunique')
1808 # Add this conf file to a random node
1809 node_id = random.sample(self.node_ids, 1)[0]
1810 AddConfFileToNode = self.debug(api.AddConfFileToNode)
1811 AddConfFileToNode(auth, conf_file_id, node_id)
1813 # Add this conf file to a random node group
1814 nodegroup_id = random.sample(self.nodegroup_ids, 1)[0]
1815 AddConfFileToNodeGroup = self.debug(api.AddConfFileToNodeGroup)
1816 AddConfFileToNodeGroup(auth, conf_file_id, nodegroup_id)
1818 # Check node, nodegroup
1819 conf_files = GetConfFiles(auth, [conf_file_id], ['node_ids', 'nodegroup_ids'])
1820 if conf_files is None or not conf_files: continue
1821 conf_file = conf_files[0]
1822 self.islistequal([node_id], conf_file['node_ids'], 'AddConfFileToNode - check')
1823 self.islistequal([nodegroup_id], conf_file['nodegroup_ids'], 'AddConfFileToNodeGroup - check')
1827 conf_files = GetConfFiles(auth, conf_file_ids)
1828 if conf_files is not None:
1829 self.islistequal(conf_file_ids, [c['conf_file_id'] for c in conf_files], 'GetConfFiles - isequal')
1830 if self.config.verbose:
1831 utils.header("Added conf_files: %s" % conf_file_ids)
1833 return conf_file_ids
1835 def DeleteConfFiles(self):
1837 GetConfFiles = self.debug(api.GetConfFiles)
1838 DeleteConfFile = self.debug(api.DeleteConfFile)
1839 DeleteConfFileFromNode = self.debug(api.DeleteConfFileFromNode)
1840 DeleteConfFileFromNodeGroup = self.debug(api.DeleteConfFileFromNodeGroup)
1842 conf_files = GetConfFiles(auth, self.conf_file_ids)
1843 if conf_files is None or not conf_files: return 0
1844 conf_file = conf_files[0]
1845 if conf_file['node_ids']:
1846 node_id = random.sample(conf_file['node_ids'], 1)[0]
1847 DeleteConfFileFromNode(auth, conf_file['conf_file_id'], node_id)
1848 if conf_file['nodegroup_ids']:
1849 nodegroup_id = random.sample(conf_file['nodegroup_ids'], 1)[0]
1850 DeleteConfFileFromNodeGroup(auth, conf_file['conf_file_id'], nodegroup_id)
1853 conf_files = GetConfFiles(auth, [conf_file['conf_file_id']], ['node_ids', 'nodegroup_ids'])
1854 if conf_files is None or not conf_files: return 0
1855 conf_file = conf_files[0]
1856 self.islistequal([], conf_file['node_ids'], 'AddConfFileToNode - check')
1857 self.islistequal([], conf_file['nodegroup_ids'], 'AddConfFileToNodeGroup - check')
1859 for conf_file_id in self.conf_file_ids:
1860 DeleteConfFile(auth, conf_file_id)
1863 conf_files = GetConfFiles(auth, self.conf_file_ids)
1864 self.islistequal(conf_files, [], 'DeleteConfFile - check')
1866 if self.config.verbose:
1867 utils.header("Deleted conf_files: %s" % self.conf_file_ids)
1869 self.conf_file_ids = []
1871 def NodeNetworks(self, n = 4):
1872 nodenetwork_ids = []
1873 AddNodeNetwork = self.debug(api.AddNodeNetwork)
1874 UpdateNodeNetwork = self.debug(api.UpdateNodeNetwork)
1875 GetNodeNetworks = self.debug(api.GetNodeNetworks)
1879 nodenetwork_fields = random_nodenetwork()
1880 node_id = random.sample(self.node_ids, 1)[0]
1881 nodenetwork_id = AddNodeNetwork(auth, node_id, nodenetwork_fields)
1882 if nodenetwork_id is None: continue
1884 # Should return a unique id
1885 self.isunique(nodenetwork_ids, nodenetwork_ids, 'AddNodeNetwork - isunique')
1886 nodenetwork_ids.append(nodenetwork_id)
1888 # check Node Network
1889 nodenetworks = GetNodeNetworks(auth, [nodenetwork_id])
1890 if nodenetworks is None: continue
1891 nodenetwork = nodenetworks[0]
1892 self.isequal(nodenetwork, nodenetwork_fields, 'AddNodeNetwork - isequal')
1894 # Update NodeNetwork
1895 nodenetwork_fields = random_nodenetwork()
1896 UpdateNodeNetwork(auth, nodenetwork_id, nodenetwork_fields)
1899 nodenetworks = GetNodeNetworks(auth, [nodenetwork_id])
1900 if nodenetworks is None: continue
1901 nodenetwork = nodenetworks[0]
1902 self.isequal(nodenetwork, nodenetwork_fields, 'UpdateNodeNetwork - isequal')
1904 nodenetworks = GetNodeNetworks(auth, nodenetwork_ids)
1905 if nodenetworks is not None:
1906 self.islistequal(nodenetwork_ids, [n['nodenetwork_id'] for n in nodenetworks], 'GetNodeNetworks - isequal')
1908 if self.config.verbose:
1909 utils.header('Added nodenetworks: %s' % nodenetwork_ids)
1911 return nodenetwork_ids
1913 def DeleteNodeNetworks(self):
1914 GetNodeNetworks = self.debug(api.GetNodeNetworks)
1915 DeleteNodeNetwork = self.debug(api.DeleteNodeNetwork)
1917 for nodenetwork_id in self.nodenetwork_ids:
1918 DeleteNodeNetwork(auth, nodenetwork_id)
1921 nodenetworks = GetNodeNetworks(auth, self.nodenetwork_ids)
1922 self.islistequal(nodenetworks, [], 'DeleteNodeNetwork - check')
1924 if self.config.verbose:
1925 utils.header("Deleted nodenetworks: %s " % self.nodenetwork_ids)
1926 self.nodenetwork_ids = []
1928 def NodeNetworkSettings(self, n=2):
1929 nodenetwork_setting_ids = []
1930 AddNodeNetworkSetting = self.debug(api.AddNodeNetworkSetting)
1931 UpdateNodeNetworkSetting = self.debug(api.UpdateNodeNetworkSetting)
1932 GetNodeNetworkSettings = self.debug(api.GetNodeNetworkSettings)
1934 for nodenetwork_id in self.nodenetwork_ids:
1936 nodenetwork_setting_fields = random_nodenetwork_setting()
1937 #nodenetwork_id = random.sample(self.nodenetwork_ids, 1)[0]
1938 nodenetwork_setting_type_id = random.sample(self.nodenetwork_setting_type_ids, 1)[0]
1939 value = nodenetwork_setting_fields['value']
1940 nodenetwork_setting_id = AddNodeNetworkSetting(auth, nodenetwork_id, nodenetwork_setting_type_id, value)
1941 if nodenetwork_setting_id is None: continue
1943 # Should return a unique id
1944 self.isunique(nodenetwork_setting_ids, nodenetwork_setting_ids, 'AddNodeNetworkSetting - isunique')
1945 nodenetwork_setting_ids.append(nodenetwork_setting_id)
1947 # check Node Network
1948 nodenetwork_settings = GetNodeNetworkSettings(auth, [nodenetwork_setting_id])
1949 if nodenetwork_settings is None: continue
1950 nodenetwork_setting = nodenetwork_settings[0]
1951 self.isequal(nodenetwork_setting, nodenetwork_setting_fields, 'AddNodeNetworkSetting - isequal')
1953 # Update NodeNetworkSetting
1954 nodenetwork_setting_fields = random_nodenetwork_setting()
1955 value = nodenetwork_setting_fields['value']
1956 UpdateNodeNetworkSetting(auth, nodenetwork_setting_id, value)
1959 nodenetwork_settings = GetNodeNetworkSettings(auth, [nodenetwork_setting_id])
1960 if nodenetwork_settings is None: continue
1961 nodenetwork_setting = nodenetwork_settings[0]
1962 self.isequal(nodenetwork_setting, nodenetwork_setting_fields, 'UpdateNodeNetworkSetting - isequal')
1964 nodenetwork_settings = GetNodeNetworkSettings(auth, nodenetwork_setting_ids)
1965 if nodenetwork_settings is not None:
1966 self.islistequal(nodenetwork_setting_ids, [n['nodenetwork_setting_id'] for n in nodenetwork_settings], 'GetNodeNetworkSettings - isequal')
1968 if self.config.verbose:
1969 utils.header('Added nodenetwork_settings: %s' % nodenetwork_setting_ids)
1971 return nodenetwork_setting_ids
1973 def DeleteNodeNetworkSettings(self):
1974 GetNodeNetworkSettings = self.debug(api.GetNodeNetworkSettings)
1975 DeleteNodeNetworkSetting = self.debug(api.DeleteNodeNetworkSetting)
1977 for nodenetwork_setting_id in self.nodenetwork_setting_ids:
1978 DeleteNodeNetworkSetting(auth, nodenetwork_setting_id)
1981 nodenetwork_settings = GetNodeNetworkSettings(auth, self.nodenetwork_setting_ids)
1982 self.islistequal(nodenetwork_settings, [], 'DeleteNodeNetworkSetting - check')
1984 if self.config.verbose:
1985 utils.header("Deleted nodenetwork settings: %s " % self.nodenetwork_setting_ids)
1986 self.nodenetwork_setting_ids = []
1988 def NodeNetworkSettingTypes(self, n = 2):
1989 nodenetwork_setting_type_ids = []
1990 AddNodeNetworkSettingType = self.debug(api.AddNodeNetworkSettingType)
1991 UpdateNodeNetworkSettingType = self.debug(api.UpdateNodeNetworkSettingType)
1992 GetNodeNetworkSettingTypes = self.debug(api.GetNodeNetworkSettingTypes)
1995 # Add Node Network Settings Type
1996 nodenetwork_setting_type_fields = random_nodenetwork_setting_type()
1997 nodenetwork_setting_type_id = AddNodeNetworkSettingType(auth, nodenetwork_setting_type_fields)
1998 if nodenetwork_setting_type_id is None: continue
2000 # Should return a unique id
2001 self.isunique(nodenetwork_setting_type_ids, nodenetwork_setting_type_ids, 'AddNodeNetworkSettingType - isunique')
2002 nodenetwork_setting_type_ids.append(nodenetwork_setting_type_id)
2004 # check Node Network Settings Type
2005 nodenetwork_setting_types = GetNodeNetworkSettingTypes(auth, [nodenetwork_setting_type_id])
2006 if nodenetwork_setting_types is None: continue
2007 nodenetwork_setting_type = nodenetwork_setting_types[0]
2008 self.isequal(nodenetwork_setting_type, nodenetwork_setting_type_fields, 'AddNodeNetworkSettingType - isequal')
2010 # Update NodeNetworkSetting
2011 nodenetwork_setting_type_fields = random_nodenetwork_setting_type()
2012 UpdateNodeNetworkSettingType(auth, nodenetwork_setting_type_id, nodenetwork_setting_type_fields)
2015 nodenetwork_setting_types = GetNodeNetworkSettingTypes(auth, [nodenetwork_setting_type_id])
2016 if nodenetwork_setting_types is None: continue
2017 nodenetwork_setting_type = nodenetwork_setting_types[0]
2018 self.isequal(nodenetwork_setting_type, nodenetwork_setting_type_fields, 'UpdateNodeNetworkSettingType - isequal')
2020 nodenetwork_setting_types = GetNodeNetworkSettingTypes(auth, nodenetwork_setting_type_ids)
2021 if nodenetwork_setting_types is not None:
2022 self.islistequal(nodenetwork_setting_type_ids, [n['nodenetwork_setting_type_id'] for n in nodenetwork_setting_types], 'GetNodeNetworkSettingTypes - isequal')
2024 if self.config.verbose:
2025 utils.header('Added nodenetwork_setting_types: %s' % nodenetwork_setting_type_ids)
2027 return nodenetwork_setting_type_ids
2029 def DeleteNodeNetworkSettingTypes(self):
2030 GetNodeNetworkSettingTypes = self.debug(api.GetNodeNetworkSettingTypes)
2031 DeleteNodeNetworkSettingType = self.debug(api.DeleteNodeNetworkSettingType)
2033 for nodenetwork_setting_type_id in self.nodenetwork_setting_type_ids:
2034 DeleteNodeNetworkSettingType(auth, nodenetwork_setting_type_id)
2037 nodenetwork_setting_types = GetNodeNetworkSettingTypes(auth, self.nodenetwork_setting_type_ids)
2038 self.islistequal(nodenetwork_setting_types, [], 'DeleteNodeNetworkSettingType - check')
2040 if self.config.verbose:
2041 utils.header("Deleted nodenetwork setting types: %s " % self.nodenetwork_setting_type_ids)
2042 self.nodenetwork_setting_type_ids = []
2044 if __name__ == '__main__':
2045 args = tuple(sys.argv[1:])
2046 api_unit_test()(*args)