From 6d45d9f3c8f6d825dfe42e5e1fb42a7b74d16221 Mon Sep 17 00:00:00 2001 From: alhogan <98360253+alhogan@users.noreply.github.com> Date: Fri, 13 Sep 2024 15:21:04 -0500 Subject: [PATCH 1/6] fixed file copy issues --- pyntc/devices/eos_device.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pyntc/devices/eos_device.py b/pyntc/devices/eos_device.py index 24646a9e..1fbd4613 100644 --- a/pyntc/devices/eos_device.py +++ b/pyntc/devices/eos_device.py @@ -73,11 +73,11 @@ 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"): if dest is None: dest = os.path.basename(src) - file_copy = FileTransfer(self.native_ssh, src, dest, file_system=file_system) + file_copy = FileTransfer(self.native_ssh, src, dest, file_system="/mnt/flash") log.debug("Host %s: File copy instance %s.", self.host, file_copy) return file_copy @@ -175,7 +175,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} @@ -375,7 +375,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) From 85cd8f8c9aa857493c0184489eb3274a44e470ce Mon Sep 17 00:00:00 2001 From: alhogan <98360253+alhogan@users.noreply.github.com> Date: Fri, 13 Sep 2024 15:47:03 -0500 Subject: [PATCH 2/6] linting --- pyntc/devices/eos_device.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pyntc/devices/eos_device.py b/pyntc/devices/eos_device.py index 1fbd4613..7ee87a35 100644 --- a/pyntc/devices/eos_device.py +++ b/pyntc/devices/eos_device.py @@ -74,10 +74,13 @@ def __init__(self, host, username, password, transport="http", port=None, timeou log.init(host=host) 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) - file_copy = FileTransfer(self.native_ssh, src, dest, file_system="/mnt/flash") + file_copy = FileTransfer(self.native_ssh, src, dest, file_system=file_system) log.debug("Host %s: File copy instance %s.", self.host, file_copy) return file_copy From bf74fda72151b5265a869dafe50e33c6a0dad4df Mon Sep 17 00:00:00 2001 From: alhogan <98360253+alhogan@users.noreply.github.com> Date: Fri, 13 Sep 2024 16:07:50 -0500 Subject: [PATCH 3/6] Fixed tests --- tests/unit/test_devices/test_eos_device.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/unit/test_devices/test_eos_device.py b/tests/unit/test_devices/test_eos_device.py index cc0bc78d..02da8788 100644 --- a/tests/unit/test_devices/test_eos_device.py +++ b/tests/unit/test_devices/test_eos_device.py @@ -237,7 +237,7 @@ 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.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() @@ -255,7 +255,7 @@ 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.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() @@ -286,7 +286,7 @@ def test_boot_options(self): def test_set_boot_options(self): results = [ - [{"result": {"output": "flash:"}}], + [{"result": {"output": "/mnt/flash"}}], [{"result": {"output": "new_image.swi"}}], [{"result": {}}], [{"result": {"softwareImage": "flash:new_image.swi"}}], From 247454a7af3e9011cb797bc13d78fcae503c9d70 Mon Sep 17 00:00:00 2001 From: alhogan <98360253+alhogan@users.noreply.github.com> Date: Fri, 13 Sep 2024 16:10:43 -0500 Subject: [PATCH 4/6] fixed black --- tests/unit/test_devices/test_eos_device.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/unit/test_devices/test_eos_device.py b/tests/unit/test_devices/test_eos_device.py index 02da8788..e7902aef 100644 --- a/tests/unit/test_devices/test_eos_device.py +++ b/tests/unit/test_devices/test_eos_device.py @@ -237,7 +237,9 @@ 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="/mnt/flash") + 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() From 95690fb3ff84c3289733d4d72a20d6cfbe364785 Mon Sep 17 00:00:00 2001 From: alhogan <98360253+alhogan@users.noreply.github.com> Date: Fri, 13 Sep 2024 16:16:13 -0500 Subject: [PATCH 5/6] Disable enable_scp in tests --- tests/unit/test_devices/test_eos_device.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/unit/test_devices/test_eos_device.py b/tests/unit/test_devices/test_eos_device.py index e7902aef..181c3ff0 100644 --- a/tests/unit/test_devices/test_eos_device.py +++ b/tests/unit/test_devices/test_eos_device.py @@ -240,7 +240,7 @@ def test_file_copy(self, mock_open, mock_close, mock_ssh, mock_ft): 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.enable_scp.assert_any_call() mock_ft_instance.establish_scp_conn.assert_any_call() mock_ft_instance.transfer_file.assert_any_call() @@ -258,7 +258,7 @@ def test_file_copy_different_dest(self, mock_open, mock_close, mock_ssh, mock_ft self.device.file_copy("source_file", "dest_file") 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.enable_scp.assert_any_call() mock_ft_instance.establish_scp_conn.assert_any_call() mock_ft_instance.transfer_file.assert_any_call() From 510fbffbc23d573720ce805f5e49e6eb9a183382 Mon Sep 17 00:00:00 2001 From: alhogan <98360253+alhogan@users.noreply.github.com> Date: Fri, 13 Sep 2024 16:48:06 -0500 Subject: [PATCH 6/6] Fixed tests --- .../device_mocks/eos/enable_json/show_boot-config | 2 +- tests/unit/test_devices/test_eos_device.py | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/unit/test_devices/device_mocks/eos/enable_json/show_boot-config b/tests/unit/test_devices/device_mocks/eos/enable_json/show_boot-config index 3ea642bb..03f27d2b 100644 --- a/tests/unit/test_devices/device_mocks/eos/enable_json/show_boot-config +++ b/tests/unit/test_devices/device_mocks/eos/enable_json/show_boot-config @@ -2,7 +2,7 @@ "command": "show boot-config", "result": { "memTestIterations": 0, - "softwareImage": "flash:EOS.swi", + "softwareImage": "EOS.swi", "abootPassword": "(not set)" }, "encoding": "json" diff --git a/tests/unit/test_devices/test_eos_device.py b/tests/unit/test_devices/test_eos_device.py index 181c3ff0..2d6bcdc2 100644 --- a/tests/unit/test_devices/test_eos_device.py +++ b/tests/unit/test_devices/test_eos_device.py @@ -240,7 +240,7 @@ def test_file_copy(self, mock_open, mock_close, mock_ssh, mock_ft): 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.enable_scp.assert_any_call() mock_ft_instance.establish_scp_conn.assert_any_call() mock_ft_instance.transfer_file.assert_any_call() @@ -258,7 +258,7 @@ def test_file_copy_different_dest(self, mock_open, mock_close, mock_ssh, mock_ft self.device.file_copy("source_file", "dest_file") 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.enable_scp.assert_any_call() mock_ft_instance.establish_scp_conn.assert_any_call() mock_ft_instance.transfer_file.assert_any_call() @@ -288,10 +288,10 @@ def test_boot_options(self): def test_set_boot_options(self): results = [ - [{"result": {"output": "/mnt/flash"}}], + [{"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"),