diff options
author | Tyler Mock <tyler.mock@calxeda.com> | 2013-04-30 18:50:52 -0500 |
---|---|---|
committer | Tyler Mock <tyler.mock@calxeda.com> | 2013-04-30 18:50:52 -0500 |
commit | 4a29d111ac01ab62236e673416c6df0f0776d119 (patch) | |
tree | d4a471b6f25e5951eca25e97e4654a374159d652 | |
parent | 096e8b341a82520e4603d95c806a195089cc709a (diff) | |
download | cxmanage-4a29d111ac01ab62236e673416c6df0f0776d119.tar.gz |
Changed fabric commands to use _run_fabric_command in node.py and
added tests for linkmap, routing_table, and depth_chart
-rw-r--r-- | cxmanage_api/node.py | 93 | ||||
-rw-r--r-- | cxmanage_test/fabric_test.py | 43 | ||||
-rw-r--r-- | cxmanage_test/node_test.py | 119 |
3 files changed, 177 insertions, 78 deletions
diff --git a/cxmanage_api/node.py b/cxmanage_api/node.py index b99cbd6..c1a909e 100644 --- a/cxmanage_api/node.py +++ b/cxmanage_api/node.py @@ -1223,33 +1223,12 @@ class Node(object): :raises TftpException: If the TFTP transfer fails. """ - filename = temp_file() - basename = os.path.basename(filename) - try: - result = self.bmc.fabric_get_linkmap(basename) - if hasattr(result, "error"): - raise IpmiError(result.error) - self.ecme_tftp.get_file(basename, filename) - except (IpmiError, TftpException): - # Fall back and use our tftp server - try: - result = self.bmc.fabric_get_linkmap(basename, - self.tftp_address) - except IpmiError as e: - raise IpmiError(self._parse_ipmierror(e)) - if hasattr(result, "error"): - raise IpmiError(result.error) - - deadline = time.time() + 10 - while time.time() < deadline: - try: - time.sleep(1) - self.tftp.get_file(src=basename, dest=filename) - if (os.path.getsize(filename) > 0): - break - except (TftpException, IOError): - pass + filename = self._run_fabric_command( + function_name='fabric_info_get_link_map', + ) + except IpmiError as e: + raise IpmiError(self._parse_ipmierror(e)) results = {} for line in open(filename): @@ -1275,33 +1254,12 @@ class Node(object): :raises TftpException: If the TFTP transfer fails. """ - filename = temp_file() - basename = os.path.basename(filename) - try: - result = self.bmc.fabric_get_routingtable(basename) - if hasattr(result, "error"): - raise IpmiError(result.error) - self.ecme_tftp.get_file(basename, filename) - except (IpmiError, TftpException): - # Fall back and use our tftp server - try: - result = self.bmc.fabric_get_routingtable(basename, - self.tftp_address) - except IpmiError as e: - raise IpmiError(self._parse_ipmierror(e)) - if hasattr(result, "error"): - raise IpmiError(result.error) - - deadline = time.time() + 10 - while time.time() < deadline: - try: - time.sleep(1) - self.tftp.get_file(src=basename, dest=filename) - if (os.path.getsize(filename) > 0): - break - except (TftpException, IOError): - pass + filename = self._run_fabric_command( + function_name='fabric_info_get_routing_table', + ) + except IpmiError as e: + raise IpmiError(self._parse_ipmierror(e)) results = {} for line in open(filename): @@ -1331,33 +1289,12 @@ class Node(object): :raises TftpException: If the TFTP transfer fails. """ - filename = temp_file() - basename = os.path.basename(filename) - try: - result = self.bmc.fabric_get_depthchart(basename) - if hasattr(result, "error"): - raise IpmiError(result.error) - self.ecme_tftp.get_file(basename, filename) - except (IpmiError, TftpException): - # Fall back and use our tftp server - try: - result = self.bmc.fabric_get_depthchart(basename, - self.tftp_address) - except IpmiError as e: - raise IpmiError(self._parse_ipmierror(e)) - if hasattr(result, "error"): - raise IpmiError(result.error) - - deadline = time.time() + 10 - while time.time() < deadline: - try: - time.sleep(1) - self.tftp.get_file(src=basename, dest=filename) - if (os.path.getsize(filename) > 0): - break - except (TftpException, IOError): - pass + filename = self._run_fabric_command( + function_name='fabric_info_get_depth_chart', + ) + except IpmiError as e: + raise IpmiError(self._parse_ipmierror(e)) results = {} for line in open(filename): diff --git a/cxmanage_test/fabric_test.py b/cxmanage_test/fabric_test.py index 77ec1f4..db6d466 100644 --- a/cxmanage_test/fabric_test.py +++ b/cxmanage_test/fabric_test.py @@ -278,6 +278,24 @@ class FabricTest(unittest.TestCase): for i in range(0, 5): self.assertIn(('get_fabric_link_stats', i), node.executed) + def test_get_linkmap(self): + """Test the get_linkmap method""" + maps = self.fabric.get_linkmap() + for nn, node in self.fabric.nodes.items(): + self.assertIn('get_fabric_linkmap', node.executed) + + def test_get_routing_table(self): + """Test the get_routing_table method""" + maps = self.fabric.get_routing_table() + for nn, node in self.fabric.nodes.items(): + self.assertIn('get_fabric_routing_table', node.executed) + + def test_get_depth_chart(self): + """Test the depth_chart method""" + maps = self.fabric.get_depth_chart() + for nn, node in self.fabric.nodes.items(): + self.assertIn('get_fabric_depth_chart', node.executed) + def test_get_link_users_factor(self): """Test the get_link_users_factor method @@ -462,6 +480,31 @@ class DummyNode(object): 'FS_LC%s_TPKTSCNT' % link: '0x1' } + def get_fabric_linkmap(self): + self.executed.append('get_fabric_linkmap') + results = {} + for n in range(0, NUM_NODES): + results[n] = {n: {1: 2, 3: 1, 4: 3}} + return results + + def get_fabric_routing_table(self): + self.executed.append('get_fabric_routing_table') + results = {} + for n in range(0, NUM_NODES): + results[n] = {n: {1: [0, 0, 0, 3, 0], + 2: [0, 3, 0, 0, 2], + 3: [0, 2, 0, 0, 3]}} + return results + + def get_fabric_depth_chart(self): + self.executed.append('get_fabric_depth_chart') + results = {} + for n in range(0, NUM_NODES): + results[n] = {n: {1: {'shortest': (0, 0)}, + 2: {'hops': [(3, 1)], 'shortest': (0, 0)}, + 3: {'hops': [(2, 1)], 'shortest': (0, 0)}}} + return results + def get_uplink(self, iface): self.executed.append(('get_uplink', iface)) return 0 diff --git a/cxmanage_test/node_test.py b/cxmanage_test/node_test.py index 00ad275..ceeb770 100644 --- a/cxmanage_test/node_test.py +++ b/cxmanage_test/node_test.py @@ -314,6 +314,30 @@ class NodeTest(unittest.TestCase): for x in node.bmc.executed: self.assertEqual(x, "fabric_config_get_uplink_info") + def test_get_fabric_linkmap(self): + """ Test node.get_fabric_linkmap method """ + for node in self.nodes: + result = node.get_fabric_linkmap() + + for x in node.bmc.executed: + self.assertEqual(x, "fabric_info_get_link_map") + + def test_get_fabric_routing_table(self): + """ Test node.get_fabric_routing_table method """ + for node in self.nodes: + result = node.get_fabric_routing_table() + + for x in node.bmc.executed: + self.assertEqual(x, "fabric_info_get_routing_table") + + def test_get_fabric_depth_chart(self): + """ Test node.get_fabric_depth_chart method """ + for node in self.nodes: + result = node.get_fabric_depth_chart() + + for x in node.bmc.executed: + self.assertEqual(x, "fabric_info_get_depth_chart") + def test_get_fabric_link_stats(self): """ Test node.get_fabric_link_stats() """ for node in self.nodes: @@ -498,6 +522,101 @@ class DummyBMC(LanBMC): self.revision = "0" return Result() + def fabric_info_get_link_map(self, filename, tftp_addr=None): + """Upload a link_map file from the node to TFTP""" + self.executed.append('fabric_info_get_link_map') + + if not(tftp_addr): + raise IpmiError('No tftp address!') + + link_map = [] + link_map.append('Link 1: Node 2') + link_map.append('Link 3: Node 1') + link_map.append('Link 4: Node 3') + + work_dir = tempfile.mkdtemp(prefix="cxmanage_test-") + with open('%s/%s' % (work_dir, filename), 'w') as lm_file: + for lmap in link_map: + lm_file.write(lmap + '\n') + lm_file.close() + + # Upload to tftp + address, port = tftp_addr.split(":") + port = int(port) + tftp = ExternalTftp(address, port) + tftp.put_file("%s/%s" % (work_dir, filename), filename) + + shutil.rmtree(work_dir) + + def fabric_info_get_routing_table(self, filename, tftp_addr=None): + """Upload a routing_table file from the node to TFTP""" + self.executed.append('fabric_info_get_routing_table') + + if not(tftp_addr): + raise IpmiError('No tftp address!') + + routing_table = [] + routing_table.append('Node 1: rt - 0.2.0.3.2') + routing_table.append('Node 2: rt - 0.3.0.1.2') + routing_table.append('Node 3: rt - 0.2.0.1.3') + routing_table.append('Node 12: rt - 0.2.0.0.1') + routing_table.append('Node 13: rt - 0.2.0.0.1') + routing_table.append('Node 14: rt - 0.2.0.0.1') + routing_table.append('Node 15: rt - 0.2.0.0.1') + + work_dir = tempfile.mkdtemp(prefix="cxmanage_test-") + with open('%s/%s' % (work_dir, filename), 'w') as rt_file: + for rtable in routing_table: + rt_file.write(rtable + '\n') + rt_file.close() + + # Upload to tftp + address, port = tftp_addr.split(":") + port = int(port) + tftp = ExternalTftp(address, port) + tftp.put_file("%s/%s" % (work_dir, filename), filename) + + shutil.rmtree(work_dir) + + def fabric_info_get_depth_chart(self, filename, tftp_addr=None): + """Upload a depth_chart file from the node to TFTP""" + self.executed.append('fabric_info_get_depth_chart') + + if not(tftp_addr): + raise IpmiError('No tftp address!') + + depth_chart = [] + depth_chart.append('Node 1: Shortest Distance 0 hops via neighbor 0: other hops/neighbors -') + depth_chart.append('Node 2: Shortest Distance 0 hops via neighbor 0: other hops/neighbors - 1/3') + depth_chart.append('Node 3: Shortest Distance 0 hops via neighbor 0: other hops/neighbors - 1/2') + depth_chart.append('Node 4: Shortest Distance 2 hops via neighbor 6: other hops/neighbors - 3/7') + depth_chart.append('Node 5: Shortest Distance 3 hops via neighbor 4: other hops/neighbors -') + depth_chart.append('Node 6: Shortest Distance 1 hops via neighbor 2: other hops/neighbors -') + depth_chart.append('Node 7: Shortest Distance 2 hops via neighbor 6: other hops/neighbors - 3/4') + depth_chart.append('Node 8: Shortest Distance 3 hops via neighbor 10: other hops/neighbors - 4/11') + depth_chart.append('Node 9: Shortest Distance 4 hops via neighbor 8: other hops/neighbors -') + depth_chart.append('Node 10: Shortest Distance 2 hops via neighbor 6: other hops/neighbors -') + depth_chart.append('Node 11: Shortest Distance 3 hops via neighbor 10: other hops/neighbors - 4/8') + depth_chart.append('Node 12: Shortest Distance 4 hops via neighbor 14: other hops/neighbors - 5/15') + depth_chart.append('Node 13: Shortest Distance 5 hops via neighbor 12: other hops/neighbors -') + depth_chart.append('Node 14: Shortest Distance 3 hops via neighbor 10: other hops/neighbors -') + depth_chart.append('Node 15: Shortest Distance 4 hops via neighbor 14: other hops/neighbors - 5/12') + + + work_dir = tempfile.mkdtemp(prefix="cxmanage_test-") + with open('%s/%s' % (work_dir, filename), 'w') as dc_file: + for dchart in depth_chart: + dc_file.write(dchart + '\n') + dc_file.close() + + # Upload to tftp + address, port = tftp_addr.split(":") + port = int(port) + tftp = ExternalTftp(address, port) + tftp.put_file("%s/%s" % (work_dir, filename), filename) + + shutil.rmtree(work_dir) + def fabric_get_link_stats(self, filename, tftp_addr=None, link=None): """Upload a link_stats file from the node to TFTP""" |