def test_topology_scontrol(): """Topology: Compare scontrol values to PySlurm values.""" test_topology = pyslurm.topology().get() scontrol = subprocess.Popen( ["scontrol", "-ddo", "show", "topology", "s2"], stdout=subprocess.PIPE, stderr=subprocess.PIPE ).communicate() scontrol_stdout = scontrol[0].strip().decode("UTF-8") scontrol_stderr = scontrol[1].strip().decode("UTF-8") if "No topology information" in scontrol_stderr: pass else: # Convert scontrol show topology into a dictionary of key value pairs. sctl = {} for item in scontrol_stdout.split(): kv = item.split("=", 1) if kv[1] in ["None", "(null)"]: sctl.update({kv[0]: None}) elif kv[1].isdigit(): sctl.update({kv[0]: int(kv[1])}) else: sctl.update({kv[0]: kv[1]}) s2 = test_topology["s2"] assert_equals(s2.get("name"), sctl.get("SwitchName")) assert_equals(s2.get("level"), sctl.get("Level")) assert_equals(s2.get("link_speed"), sctl.get("LinkSpeed")) assert_equals(s2.get("nodes"), sctl.get("Nodes")) assert_equals(s2.get("switches"), sctl.get("Switches"))
def test_topology_scontrol(): """Topology: Compare scontrol values to PySlurm values.""" test_topology = pyslurm.topology().get() scontrol = subprocess.Popen( ["scontrol", "-ddo", "show", "topology", "s2"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, ).communicate() scontrol_stdout = scontrol[0].strip().decode("UTF-8") scontrol_stderr = scontrol[1].strip().decode("UTF-8") if "No topology information" in scontrol_stderr: pass else: # Convert scontrol show topology into a dictionary of key value pairs. sctl = {} for item in scontrol_stdout.split(): kv = item.split("=", 1) if kv[1] in ["None", "(null)"]: sctl.update({kv[0]: None}) elif kv[1].isdigit(): sctl.update({kv[0]: int(kv[1])}) else: sctl.update({kv[0]: kv[1]}) s2 = test_topology["s2"] assert s2.get("name") == sctl.get("SwitchName") assert s2.get("level") == sctl.get("Level") assert s2.get("link_speed") == sctl.get("LinkSpeed") assert s2.get("nodes") == sctl.get("Nodes") assert s2.get("switches") == sctl.get("Switches")
def get_topology(): try: topology = pyslurm.topology().get() except Exception as e: topology = {'error': str(e)} return topology
def get_topology(): if mocking: return mock('topology.json') try: topology = pyslurm.topology().get() except Exception as e: topology = {'error': str(e)} return topology
def get_topology(): try: topology = get_from_cache(pyslurm.topology().get, 'get_topology') # As of pyslurm 15.08.0~git20160229-2, switches and nodes dict members # are strings (or None eventually) representing the hostlist of devices # connected to the switch. These hostlist are expanded in lists using # Clustershell Nodeset() into new corresponding *list members. for switch in topology.itervalues(): if switch['switches'] is not None: switch['switchlist'] = list(NodeSet(switch['switches'])) if switch['nodes'] is not None: switch['nodelist'] = list(NodeSet(switch['nodes'])) except Exception as e: topology = {'error': str(e)} return topology
def get_topology(): try: topology = pyslurm.topology().get() # As of pyslurm 15.08.0~git20160229-2, switches and nodes dict members # are strings (or None eventually) representing the hostlist of devices # connected to the switch. These hostlist are expanded in lists using # Clustershell Nodeset() into new corresponding *list members. for switch in topology.itervalues(): if switch['switches'] is not None: switch['switchlist'] = list(NodeSet(switch['switches'])) if switch['nodes'] is not None: switch['nodelist'] = list(NodeSet(switch['nodes'])) except Exception as e: topology = {'error': str(e)} return topology
#!/usr/bin/env python import pyslurm from time import gmtime, strftime try: a = pyslurm.topology() b = a.get() except ValueError as e: print 'Topology error - %s' % (e) else: if not b: print "No toplogy found" else: print b
#!/usr/bin/env python from __future__ import print_function import pyslurm from time import gmtime, strftime try: a = pyslurm.topology() b = a.get() except ValueError as e: print("Topology error - {0}".format(e.args[0])) else: if not b: print("No toplogy found") else: print(b)
def test_get_topology(): """Topology: Test get_topology() return type""" test_topology = pyslurm.topology().get() assert_true(isinstance(test_topology, dict))
def test_get_topology(): """Topology: Test get_topology() return type""" test_topology = pyslurm.topology().get() assert isinstance(test_topology, dict)