Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Arista EOS file copy issues #312

Merged
merged 6 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading