Skip to content

Commit 59589b0

Browse files
authored
Fix Arista EOS file copy issues (#312)
* fixed file copy issues * linting * Fixed tests * fixed black * Disable enable_scp in tests * Fixed tests
1 parent 6cd4e38 commit 59589b0

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

pyntc/devices/eos_device.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,10 @@ def __init__(self, host, username, password, transport="http", port=None, timeou
7373
self._connected = False
7474
log.init(host=host)
7575

76-
def _file_copy_instance(self, src, dest=None, file_system="flash:"):
76+
def _file_copy_instance(self, src, dest=None, file_system="/mnt/flash"):
77+
# "flash:" is only valid locally, "/mnt/flash" is used externally
78+
if file_system == "flash:":
79+
file_system = "/mnt/flash"
7780
if dest is None:
7881
dest = os.path.basename(src)
7982

@@ -175,7 +178,7 @@ def boot_options(self):
175178
dict: Key is ``sys`` with value being the image on the device.
176179
"""
177180
image = self.show("show boot-config")["softwareImage"]
178-
image = image.replace("flash:", "")
181+
image = image.replace("flash:/", "")
179182
log.debug("Host %s: the boot options are %s", self.host, {"sys": image})
180183
return {"sys": image}
181184

@@ -375,7 +378,7 @@ def file_copy(self, src, dest=None, file_system=None):
375378
file_copy = self._file_copy_instance(src, dest, file_system=file_system)
376379

377380
try:
378-
file_copy.enable_scp()
381+
# file_copy.enable_scp()
379382
file_copy.establish_scp_conn()
380383
file_copy.transfer_file()
381384
log.info("Host %s: File %s transferred successfully.", self.host, src)

tests/unit/test_devices/device_mocks/eos/enable_json/show_boot-config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"command": "show boot-config",
33
"result": {
44
"memTestIterations": 0,
5-
"softwareImage": "flash:EOS.swi",
5+
"softwareImage": "EOS.swi",
66
"abootPassword": "(not set)"
77
},
88
"encoding": "json"

tests/unit/test_devices/test_eos_device.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,10 @@ def test_file_copy(self, mock_open, mock_close, mock_ssh, mock_ft):
237237
mock_ft_instance.check_file_exists.side_effect = [False, True]
238238
self.device.file_copy("path/to/source_file")
239239

240-
mock_ft.assert_called_with(self.device.native_ssh, "path/to/source_file", "source_file", file_system="flash:")
241-
mock_ft_instance.enable_scp.assert_any_call()
240+
mock_ft.assert_called_with(
241+
self.device.native_ssh, "path/to/source_file", "source_file", file_system="/mnt/flash"
242+
)
243+
# mock_ft_instance.enable_scp.assert_any_call()
242244
mock_ft_instance.establish_scp_conn.assert_any_call()
243245
mock_ft_instance.transfer_file.assert_any_call()
244246

@@ -255,8 +257,8 @@ def test_file_copy_different_dest(self, mock_open, mock_close, mock_ssh, mock_ft
255257
mock_ft_instance.check_file_exists.side_effect = [False, True]
256258
self.device.file_copy("source_file", "dest_file")
257259

258-
mock_ft.assert_called_with(self.device.native_ssh, "source_file", "dest_file", file_system="flash:")
259-
mock_ft_instance.enable_scp.assert_any_call()
260+
mock_ft.assert_called_with(self.device.native_ssh, "source_file", "dest_file", file_system="/mnt/flash")
261+
# mock_ft_instance.enable_scp.assert_any_call()
260262
mock_ft_instance.establish_scp_conn.assert_any_call()
261263
mock_ft_instance.transfer_file.assert_any_call()
262264

@@ -289,7 +291,7 @@ def test_set_boot_options(self):
289291
[{"result": {"output": "flash:"}}],
290292
[{"result": {"output": "new_image.swi"}}],
291293
[{"result": {}}],
292-
[{"result": {"softwareImage": "flash:new_image.swi"}}],
294+
[{"result": {"softwareImage": "flash:/new_image.swi"}}],
293295
]
294296
calls = [
295297
mock.call(["dir"], encoding="text"),

0 commit comments

Comments
 (0)