Skip to content

Commit

Permalink
Fix Arista EOS file copy issues (#312)
Browse files Browse the repository at this point in the history
* fixed file copy issues

* linting

* Fixed tests

* fixed black

* Disable enable_scp in tests

* Fixed tests
  • Loading branch information
alhogan authored Sep 13, 2024
1 parent 6cd4e38 commit 59589b0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
9 changes: 6 additions & 3 deletions pyntc/devices/eos_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ def __init__(self, host, username, password, transport="http", port=None, timeou
self._connected = False
log.init(host=host)

def _file_copy_instance(self, src, dest=None, file_system="flash:"):
def _file_copy_instance(self, src, dest=None, file_system="/mnt/flash"):
# "flash:" is only valid locally, "/mnt/flash" is used externally
if file_system == "flash:":
file_system = "/mnt/flash"
if dest is None:
dest = os.path.basename(src)

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

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

try:
file_copy.enable_scp()
# file_copy.enable_scp()
file_copy.establish_scp_conn()
file_copy.transfer_file()
log.info("Host %s: File %s transferred successfully.", self.host, src)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"command": "show boot-config",
"result": {
"memTestIterations": 0,
"softwareImage": "flash:EOS.swi",
"softwareImage": "EOS.swi",
"abootPassword": "(not set)"
},
"encoding": "json"
Expand Down
12 changes: 7 additions & 5 deletions tests/unit/test_devices/test_eos_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,10 @@ def test_file_copy(self, mock_open, mock_close, mock_ssh, mock_ft):
mock_ft_instance.check_file_exists.side_effect = [False, True]
self.device.file_copy("path/to/source_file")

mock_ft.assert_called_with(self.device.native_ssh, "path/to/source_file", "source_file", file_system="flash:")
mock_ft_instance.enable_scp.assert_any_call()
mock_ft.assert_called_with(
self.device.native_ssh, "path/to/source_file", "source_file", file_system="/mnt/flash"
)
# mock_ft_instance.enable_scp.assert_any_call()
mock_ft_instance.establish_scp_conn.assert_any_call()
mock_ft_instance.transfer_file.assert_any_call()

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

mock_ft.assert_called_with(self.device.native_ssh, "source_file", "dest_file", file_system="flash:")
mock_ft_instance.enable_scp.assert_any_call()
mock_ft.assert_called_with(self.device.native_ssh, "source_file", "dest_file", file_system="/mnt/flash")
# mock_ft_instance.enable_scp.assert_any_call()
mock_ft_instance.establish_scp_conn.assert_any_call()
mock_ft_instance.transfer_file.assert_any_call()

Expand Down Expand Up @@ -289,7 +291,7 @@ def test_set_boot_options(self):
[{"result": {"output": "flash:"}}],
[{"result": {"output": "new_image.swi"}}],
[{"result": {}}],
[{"result": {"softwareImage": "flash:new_image.swi"}}],
[{"result": {"softwareImage": "flash:/new_image.swi"}}],
]
calls = [
mock.call(["dir"], encoding="text"),
Expand Down

0 comments on commit 59589b0

Please sign in to comment.