summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Kraft <george.kraft@calxeda.com>2013-12-17 13:48:11 -0600
committerGeorge Kraft <george.kraft@calxeda.com>2013-12-17 13:48:11 -0600
commitf2b9396d3b06c7d10f9223f015b8f8e41a8dedb5 (patch)
treea460ab32ad8b96a21cc69fd1b0f8b59bd0f700aa
parenta33148ed61ef8d4865674206404a9f9798526bc5 (diff)
downloadcxmanage-f2b9396d3b06c7d10f9223f015b8f8e41a8dedb5.tar.gz
CXMAN-223: Make Node.run_fabric_tftp_command return file contents
Instead of returning a filename, just return the contents of the file. We never use the filename for anything else.
-rw-r--r--cxmanage_api/fabric.py13
-rw-r--r--cxmanage_api/node.py32
2 files changed, 21 insertions, 24 deletions
diff --git a/cxmanage_api/fabric.py b/cxmanage_api/fabric.py
index 4184dd1..ff4b241 100644
--- a/cxmanage_api/fabric.py
+++ b/cxmanage_api/fabric.py
@@ -334,18 +334,17 @@ class Fabric(object):
"""
results = {}
- filename = self.primary_node.run_fabric_tftp_command(
+ contents = self.primary_node.run_fabric_tftp_command(
'fabric_config_get_networks'
)
regex = re.compile(r'\d+ Network (\w+), private=(\d)')
- contents = open(filename, 'r').readlines()
- for line in contents:
+ for line in contents.splitlines():
try:
name, private = regex.findall(line)[0]
results[name] = (int(private) != 0)
except IndexError:
- raise CommandFailedError(
- 'Unable to parse networks: %s' % '\n'.join(contents)
+ raise ParseError(
+ 'Unable to parse networks\n%s' % contents
)
return results
@@ -451,11 +450,11 @@ class Fabric(object):
"""
results = {}
- filename = self.primary_node.run_fabric_tftp_command(
+ contents = self.primary_node.run_fabric_tftp_command(
'fabric_config_get_uplinks'
)
current_uplink = None
- for line in open(filename, 'r').readlines():
+ for line in contents.splitlines():
if('Uplink' in line):
current_uplink = int(line.split('Uplink ')[1].replace(':', ''))
results[current_uplink] = []
diff --git a/cxmanage_api/node.py b/cxmanage_api/node.py
index f276594..0a8a83a 100644
--- a/cxmanage_api/node.py
+++ b/cxmanage_api/node.py
@@ -1193,10 +1193,9 @@ communication.
:raises ParseError: If we fail to parse IP info
"""
- filename = self.run_fabric_tftp_command(
+ contents = self.run_fabric_tftp_command(
function_name='fabric_config_get_ip_info'
)
- contents = open(filename).read()
results = {}
for line in contents.splitlines():
@@ -1258,10 +1257,9 @@ communication.
:raises ParseError: If we fail to parse macaddrs output
"""
- filename = self.run_fabric_tftp_command(
+ contents = self.run_fabric_tftp_command(
function_name='fabric_config_get_mac_addresses'
)
- contents = open(filename).read()
results = {}
for line in contents.splitlines():
@@ -1310,13 +1308,13 @@ communication.
:raises TftpException: If the TFTP transfer fails.
"""
- filename = self.run_fabric_tftp_command(
+ contents = self.run_fabric_tftp_command(
function_name='fabric_config_get_uplink_info'
)
# Parse addresses from ipinfo file
results = {}
- for line in open(filename):
+ for line in contents.splitlines():
node_id = int(line.replace('Node ', '')[0])
ul_info = line.replace('Node %s:' % node_id, '').strip().split(',')
node_data = {}
@@ -1360,12 +1358,12 @@ communication.
:raises IpmiError: If the IPMI command fails.
"""
- filename = self.run_fabric_tftp_command(
+ contents = self.run_fabric_tftp_command(
function_name='fabric_get_linkstats',
link=link
)
results = {}
- for line in open(filename):
+ for line in contents.splitlines():
if ('=' in line):
reg_value = line.strip().split('=')
if (len(reg_value) < 2):
@@ -1394,12 +1392,12 @@ communication.
:raises TftpException: If the TFTP transfer fails.
"""
- filename = self.run_fabric_tftp_command(
+ contents = self.run_fabric_tftp_command(
function_name='fabric_info_get_link_map',
)
results = {}
- for line in open(filename):
+ for line in contents.splitlines():
if (line.startswith("Link")):
elements = line.strip().split()
link_id = int(elements[1].rstrip(':'))
@@ -1421,12 +1419,12 @@ communication.
:raises TftpException: If the TFTP transfer fails.
"""
- filename = self.run_fabric_tftp_command(
+ contents = self.run_fabric_tftp_command(
function_name='fabric_info_get_routing_table',
)
results = {}
- for line in open(filename):
+ for line in contents.splitlines():
if (line.startswith("Node")):
elements = line.strip().split()
node_id = int(elements[1].rstrip(':'))
@@ -1454,12 +1452,12 @@ communication.
:raises TftpException: If the TFTP transfer fails.
"""
- filename = self.run_fabric_tftp_command(
+ contents = self.run_fabric_tftp_command(
function_name='fabric_info_get_depth_chart',
)
results = {}
- for line in open(filename):
+ for line in contents.splitlines():
if (line.startswith("Node")):
elements = line.strip().split()
target = int(elements[1].rstrip(':'))
@@ -1627,12 +1625,12 @@ obtained.
return(hexfile.read(bytes_to_read))
def run_fabric_tftp_command(self, function_name, **kwargs):
- """Run a fabric TFTP command, returning the filename.
+ """Run a fabric TFTP command and return the contents of the file.
:param function_name: BMC fabric function name
:type function_name: string
- :return: Downloaded filename
+ :return: Contents of downloaded file
:rtype: string
"""
@@ -1662,7 +1660,7 @@ obtained.
if os.path.getsize(filename) == 0:
raise TftpException("Node failed to reach TFTP server")
- return filename
+ return open(filename, "rb").read()
@staticmethod
def _get_partition(fwinfo, image_type, partition_arg):