ce_file_copy : update ce_file_copy to fix a bug. (#59071)
* update ce_file_copy to fix a bug. * Update ce_file_copy.py * Update ce_file_copy.py
This commit is contained in:
parent
a6d32eda84
commit
7a0a21ea7a
1 changed files with 47 additions and 26 deletions
|
@ -113,6 +113,21 @@ try:
|
||||||
except ImportError:
|
except ImportError:
|
||||||
HAS_SCP = False
|
HAS_SCP = False
|
||||||
|
|
||||||
|
CE_NC_GET_DISK_INFO = """
|
||||||
|
<filter type="subtree">
|
||||||
|
<vfm xmlns="http://www.huawei.com/netconf/vrp" content-version="1.0" format-version="1.0">
|
||||||
|
<dfs>
|
||||||
|
<df>
|
||||||
|
<fileSys></fileSys>
|
||||||
|
<inputPath></inputPath>
|
||||||
|
<totalSize></totalSize>
|
||||||
|
<freeSize></freeSize>
|
||||||
|
</df>
|
||||||
|
</dfs>
|
||||||
|
</vfm>
|
||||||
|
</filter>
|
||||||
|
"""
|
||||||
|
|
||||||
CE_NC_GET_FILE_INFO = """
|
CE_NC_GET_FILE_INFO = """
|
||||||
<filter type="subtree">
|
<filter type="subtree">
|
||||||
<vfm xmlns="http://www.huawei.com/netconf/vrp" content-version="1.0" format-version="1.0">
|
<vfm xmlns="http://www.huawei.com/netconf/vrp" content-version="1.0" format-version="1.0">
|
||||||
|
@ -130,11 +145,12 @@ CE_NC_GET_FILE_INFO = """
|
||||||
CE_NC_GET_SCP_ENABLE = """
|
CE_NC_GET_SCP_ENABLE = """
|
||||||
<filter type="subtree">
|
<filter type="subtree">
|
||||||
<sshs xmlns="http://www.huawei.com/netconf/vrp" content-version="1.0" format-version="1.0">
|
<sshs xmlns="http://www.huawei.com/netconf/vrp" content-version="1.0" format-version="1.0">
|
||||||
<sshServer>
|
<sshServerEnable>
|
||||||
<scpEnable></scpEnable>
|
<scpIpv4Enable></scpIpv4Enable>
|
||||||
</sshServer>
|
<scpIpv6Enable></scpIpv6Enable>
|
||||||
|
</sshServerEnable>
|
||||||
</sshs>
|
</sshs>
|
||||||
</filter>
|
</filter>
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
@ -215,7 +231,7 @@ class FileCopy(object):
|
||||||
|
|
||||||
# get file info
|
# get file info
|
||||||
root = ElementTree.fromstring(xml_str)
|
root = ElementTree.fromstring(xml_str)
|
||||||
topo = root.find("data/vfm/dirs/dir")
|
topo = root.find("vfm/dirs/dir")
|
||||||
if topo is None:
|
if topo is None:
|
||||||
return False, 0
|
return False, 0
|
||||||
|
|
||||||
|
@ -233,16 +249,19 @@ class FileCopy(object):
|
||||||
def enough_space(self):
|
def enough_space(self):
|
||||||
"""Whether device has enough space"""
|
"""Whether device has enough space"""
|
||||||
|
|
||||||
commands = list()
|
xml_str = CE_NC_GET_DISK_INFO
|
||||||
cmd = 'dir %s' % self.file_system
|
ret_xml = get_nc_config(self.module, xml_str)
|
||||||
commands.append(cmd)
|
if "<data/>" in ret_xml:
|
||||||
output = run_commands(self.module, commands)
|
return
|
||||||
if not output:
|
|
||||||
return True
|
xml_str = ret_xml.replace('\r', '').replace('\n', '').\
|
||||||
|
replace('xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"', "").\
|
||||||
|
replace('xmlns="http://www.huawei.com/netconf/vrp"', "")
|
||||||
|
|
||||||
|
root = ElementTree.fromstring(xml_str)
|
||||||
|
topo = root.find("vfm/dfs/df/freeSize")
|
||||||
|
kbytes_free = topo.text
|
||||||
|
|
||||||
match = re.search(r'\((.*) KB free\)', output[0])
|
|
||||||
kbytes_free = match.group(1)
|
|
||||||
kbytes_free = kbytes_free.replace(',', '')
|
|
||||||
file_size = os.path.getsize(self.local_file)
|
file_size = os.path.getsize(self.local_file)
|
||||||
if int(kbytes_free) * 1024 > file_size:
|
if int(kbytes_free) * 1024 > file_size:
|
||||||
return True
|
return True
|
||||||
|
@ -284,7 +303,6 @@ class FileCopy(object):
|
||||||
self.module.fail_json(msg='Could not transfer file. There was an error '
|
self.module.fail_json(msg='Could not transfer file. There was an error '
|
||||||
'during transfer. Please make sure the format of '
|
'during transfer. Please make sure the format of '
|
||||||
'input parameters is right.')
|
'input parameters is right.')
|
||||||
|
|
||||||
scp.close()
|
scp.close()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@ -292,9 +310,10 @@ class FileCopy(object):
|
||||||
"""Get scp enable state"""
|
"""Get scp enable state"""
|
||||||
|
|
||||||
xml_str = CE_NC_GET_SCP_ENABLE
|
xml_str = CE_NC_GET_SCP_ENABLE
|
||||||
|
scp_enable = dict()
|
||||||
ret_xml = get_nc_config(self.module, xml_str)
|
ret_xml = get_nc_config(self.module, xml_str)
|
||||||
if "<data/>" in ret_xml:
|
if "<data/>" in ret_xml:
|
||||||
return False
|
return scp_enable
|
||||||
|
|
||||||
xml_str = ret_xml.replace('\r', '').replace('\n', '').\
|
xml_str = ret_xml.replace('\r', '').replace('\n', '').\
|
||||||
replace('xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"', "").\
|
replace('xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"', "").\
|
||||||
|
@ -302,15 +321,14 @@ class FileCopy(object):
|
||||||
|
|
||||||
# get file info
|
# get file info
|
||||||
root = ElementTree.fromstring(xml_str)
|
root = ElementTree.fromstring(xml_str)
|
||||||
topo = root.find("data/sshs/sshServer")
|
topo = root.find("sshs/sshServerEnable")
|
||||||
if topo is None:
|
if topo is None:
|
||||||
return False
|
return scp_enable
|
||||||
|
|
||||||
for eles in topo:
|
for eles in topo:
|
||||||
if eles.tag in ["scpEnable"]:
|
scp_enable[eles.tag] = eles.text
|
||||||
return True, eles.text
|
|
||||||
|
|
||||||
return False
|
return scp_enable
|
||||||
|
|
||||||
def work(self):
|
def work(self):
|
||||||
"""Excute task """
|
"""Excute task """
|
||||||
|
@ -331,10 +349,13 @@ class FileCopy(object):
|
||||||
self.module.fail_json(
|
self.module.fail_json(
|
||||||
msg="'Error: The maximum length of remote_file is 4096.'")
|
msg="'Error: The maximum length of remote_file is 4096.'")
|
||||||
|
|
||||||
retcode, cur_state = self.get_scp_enable()
|
cur_state = self.get_scp_enable()
|
||||||
if retcode and cur_state == 'Disable':
|
if len(cur_state) > 0 and (cur_state.get('scpIpv4Enable').lower() == 'disable' or cur_state.get('scpIpv6Enable').lower() == 'disable'):
|
||||||
self.module.fail_json(
|
self.module.fail_json(
|
||||||
msg="'Error: Please ensure SCP server is enabled.'")
|
msg="'Error: Please ensure ipv4 and ipv6 SCP server are enabled.'")
|
||||||
|
elif len(cur_state) == 0:
|
||||||
|
self.module.fail_json(
|
||||||
|
msg="'Error: Please ensure ipv4 and ipv6 SCP server are enabled.'")
|
||||||
|
|
||||||
if not os.path.isfile(self.local_file):
|
if not os.path.isfile(self.local_file):
|
||||||
self.module.fail_json(
|
self.module.fail_json(
|
||||||
|
|
Loading…
Reference in a new issue