- ip = randint(0, 0xffffffff)
- netmask = (0xffffffff << randint(2, 31)) & 0xffffffff
- network = ip & netmask
- broadcast = ((ip & netmask) | ~netmask) & 0xffffffff
- gateway = randint(network + 1, broadcast - 1)
- dns1 = randint(0, 0xffffffff)
-
- for method in 'static', 'dhcp':
- optional = {}
- if method == 'static':
- for key in 'ip', 'netmask', 'network', 'broadcast', 'gateway', 'dns1':
- optional[key] = socket.inet_ntoa(struct.pack('>L', locals()[key]))
-
- print "AdmAddNodeNetwork(%s)" % method,
- nodenetwork_id = AdmAddNodeNetwork(admin, node_id, method, 'ipv4', optional)
-
- # Should return a unique nodenetwork_id
- assert nodenetwork_id not in nodenetwork_ids
- nodenetwork_ids.append(nodenetwork_id)
- print "=>", nodenetwork_id
-
- # Check node networks
- print "AdmGetAllNodeNetworks(%d)" % node_id,
- nodenetworks = AdmGetAllNodeNetworks(admin, node_id)
- for nodenetwork in nodenetworks:
- if nodenetwork['method'] == 'static':
- for key in 'ip', 'netmask', 'network', 'broadcast', 'gateway', 'dns1':
- address = struct.unpack('>L', socket.inet_aton(nodenetwork[key]))[0]
- assert address == locals()[key]
- print "=>", [nodenetwork['nodenetwork_id'] for nodenetwork in nodenetworks]
-
-# Update node networks
-for node_id in node_ids:
- ip = randint(0, 0xffffffff)
- netmask = (0xffffffff << randint(2, 31)) & 0xffffffff
- network = ip & netmask
- broadcast = ((ip & netmask) | ~netmask) & 0xffffffff
- gateway = randint(network + 1, broadcast - 1)
- dns1 = randint(0, 0xffffffff)
-
- nodenetworks = AdmGetAllNodeNetworks(admin, node_id)
- for nodenetwork in nodenetworks:
- # Update node network
- optional = {}
- if nodenetwork['method'] == 'static':
- for key in 'ip', 'netmask', 'network', 'broadcast', 'gateway', 'dns1':
- optional[key] = socket.inet_ntoa(struct.pack('>L', locals()[key]))
-
- print "AdmUpdateNodeNetwork(%s)" % nodenetwork['method'],
- AdmUpdateNodeNetwork(admin, nodenetwork['nodenetwork_id'], optional)
+ def random_nodenetwork(method, type):
+ nodenetwork_fields = {
+ 'method': method,
+ 'type': type,
+ 'bwlimit': randint(500000, 10000000),
+ }
+
+ if method != 'dhcp':
+ ip = randint(0, 0xffffffff)
+ netmask = (0xffffffff << randint(2, 31)) & 0xffffffff
+ network = ip & netmask
+ broadcast = ((ip & netmask) | ~netmask) & 0xffffffff
+ gateway = randint(network + 1, broadcast - 1)
+ dns1 = randint(0, 0xffffffff)
+
+ for field in 'ip', 'netmask', 'network', 'broadcast', 'gateway', 'dns1':
+ nodenetwork_fields[field] = socket.inet_ntoa(struct.pack('>L', locals()[field]))
+
+ return nodenetwork_fields
+
+ for method in network_methods:
+ for type in network_types:
+ # Add node network
+ print "AddNodeNetwork",
+ nodenetwork_fields = random_nodenetwork(method, type)
+ nodenetwork_id = AddNodeNetwork(admin, node_id, nodenetwork_fields)
+
+ # Should return a unique nodenetwork_id
+ assert nodenetwork_id not in nodenetwork_ids
+ nodenetwork_ids.append(nodenetwork_id)
+ print "=>", nodenetwork_id
+
+ # Check node network
+ print "GetNodeNetworks(%d)" % nodenetwork_id,
+ nodenetwork = GetNodeNetworks(admin, [nodenetwork_id])[0]
+ for field in nodenetwork_fields:
+ assert nodenetwork[field] == nodenetwork_fields[field]
+ print "=> OK"
+
+ # Update node network
+ nodenetwork_fields = random_nodenetwork(method, type)
+ print "UpdateNodeNetwork(%d)" % nodenetwork_id,
+ UpdateNodeNetwork(admin, nodenetwork_id, nodenetwork_fields)
+ print "=> OK"
+
+ # Check node network again
+ nodenetwork = GetNodeNetworks(admin, [nodenetwork_id])[0]
+ for field in nodenetwork_fields:
+ assert nodenetwork[field] == nodenetwork_fields[field]
+
+print "GetNodeNetworks",
+nodenetworks = GetNodeNetworks(admin, nodenetwork_ids)
+assert set(nodenetwork_ids) == set([nodenetwork['nodenetwork_id'] for nodenetwork in nodenetworks])
+print "=>", nodenetwork_ids
+
+# Add PCUs
+pcu_ids = []
+for site_id in site_ids:
+ def random_pcu():
+ return {
+ 'hostname': randhostname(),
+ 'ip': socket.inet_ntoa(struct.pack('>L', randint(0, 0xffffffff))),
+ 'protocol': randstr(16),
+ 'username': randstr(254),
+ 'password': randstr(254),
+ 'notes': randstr(254),
+ 'model': randstr(32),
+ }
+
+ # Add PCU
+ pcu_fields = random_pcu()
+ print "AddPCU",
+ pcu_id = AddPCU(admin, site_id, pcu_fields)
+
+ # Should return a unique pcu_id
+ assert pcu_id not in pcu_ids
+ pcu_ids.append(pcu_id)
+ print "=>", pcu_id
+
+ # Check PCU
+ print "GetPCUs(%d)" % pcu_id,
+ pcu = GetPCUs(admin, [pcu_id])[0]
+ for field in pcu_fields:
+ assert pcu[field] == pcu_fields[field]
+ print "=> OK"
+
+ # Update PCU
+ pcu_fields = random_pcu()
+ print "UpdatePCU(%d)" % pcu_id,
+ UpdatePCU(admin, pcu_id, pcu_fields)
+ print "=> OK"
+
+ # Check PCU again
+ pcu = GetPCUs(admin, [pcu_id])[0]
+ for field in pcu_fields:
+ assert pcu[field] == pcu_fields[field]
+
+ # Add each node at this site to a different port on this PCU
+ site = GetSites(admin, [site_id])[0]
+ port = randint(1, 10)
+ for node_id in site['node_ids']:
+ print "AddNodeToPCU(%d, %d, %d)" % (node_id, pcu_id, port),
+ AddNodeToPCU(admin, node_id, pcu_id, port)
+ print "=> OK"
+ port += 1
+
+print "GetPCUs",
+pcus = GetPCUs(admin, pcu_ids)
+assert set(pcu_ids) == set([pcu['pcu_id'] for pcu in pcus])
+print "=>", pcu_ids
+
+# Add configuration files
+conf_file_ids = []
+for nodegroup_id in nodegroup_ids:
+ def random_conf_file():
+ return {
+ 'enabled': bool(randint()),
+ 'source': randpath(255),
+ 'dest': randpath(255),
+ 'file_permissions': "%#o" % randint(0, 512),
+ 'file_owner': randstr(32, letters + '_' + digits),
+ 'file_group': randstr(32, letters + '_' + digits),
+ 'preinstall_cmd': randpath(100),
+ 'postinstall_cmd': randpath(100),
+ 'error_cmd': randpath(100),
+ 'ignore_cmd_errors': bool(randint()),
+ 'always_update': bool(randint()),
+ }
+
+ # Add configuration file
+ conf_file_fields = random_conf_file()
+ print "AddConfFile",
+ conf_file_id = AddConfFile(admin, conf_file_fields)
+
+ # Should return a unique conf_file_id
+ assert conf_file_id not in conf_file_ids
+ conf_file_ids.append(conf_file_id)
+ print "=>", conf_file_id
+
+ # Check configuration file
+ print "GetConfFiles(%d)" % conf_file_id,
+ conf_file = GetConfFiles(admin, [conf_file_id])[0]
+ for field in conf_file_fields:
+ assert conf_file[field] == conf_file_fields[field]
+ print "=> OK"
+
+ # Update configuration file
+ conf_file_fields = random_conf_file()
+ print "UpdateConfFile(%d)" % conf_file_id,
+ UpdateConfFile(admin, conf_file_id, conf_file_fields)
+ print "=> OK"
+
+ # Check configuration file
+ conf_file = GetConfFiles(admin, [conf_file_id])[0]
+ for field in conf_file_fields:
+ assert conf_file[field] == conf_file_fields[field]
+
+ # Add to all node groups
+ for nodegroup_id in nodegroup_ids:
+ print "AddConfFileToNodeGroup(%d, %d)" % (conf_file_id, nodegroup_id),
+ AddConfFileToNodeGroup(admin, conf_file_id, nodegroup_id)
+ print "=> OK"
+
+ # Add to all nodes
+ for node_id in node_ids:
+ print "AddConfFileToNode(%d, %d)" % (conf_file_id, node_id),
+ AddConfFileToNode(admin, conf_file_id, node_id)