From df9a7c1861e1666d8f1fde6b72079cdd86b6c3e9 Mon Sep 17 00:00:00 2001 From: Saliou DIOP Date: Fri, 1 Aug 2025 09:49:27 +0200 Subject: [PATCH 01/30] the MS stack management methods (create a stack, apply a stack) added --- msa_sdk/order.py | 67 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 66 insertions(+), 1 deletion(-) diff --git a/msa_sdk/order.py b/msa_sdk/order.py index dd16555d..5559be3a 100644 --- a/msa_sdk/order.py +++ b/msa_sdk/order.py @@ -42,12 +42,53 @@ def command_execute(self, command: str, params: dict, timeout=300) -> None: None """ - self.action = 'Command execute' + self.action = 'Commands stack execute' self.path = '{}/execute/{}/{}'.format(self.api_path, self.device_id, command) self._call_post(params, timeout) + def apply_command_stack(self, command: str, params: dict, timeout=300) -> None: + """ + + Apply all commands stack of a device. + + Parameters + ----------- + command: String + Apply command + Available values : CREATE, UPDATE, IMPORT, LIST, READ, DELETE + + params: dict + Parameters in a dict format: + + { + "simple_firewall": { + "1": { + "object_id": "1", + "src_ip": "3.4.5.7", + "dst_port": "44" + }, + "2": { + "object_id": "2", + "src_ip": "3.4.5.6", + "dst_port": "42" + } + } + timeout: int timeout in sec (300 secondes by default) + + Returns + ------- + None + + """ + self.action = 'Command execute' + self.api_path = '/orderstack' + self.path = '{}/command/{}/{}'.format(self.api_path, self.device_id, + command) + + self._call_post(params, timeout) + def command_generate_configuration(self, command: str, params: dict) -> None: """ @@ -184,6 +225,30 @@ def command_call(self, command: str, mode: int, params, mode) self._call_post(params, timeout) + + def command_stack(self, command: str, params, + timeout=300) -> None: + """ + + Stack Command. + + Parameters + ----------- + command: String + CRUID method in microservice to add to the stack. + Returns + -------- + None + + """ + self.action = 'Call command' + self.api_path = '/orderstack' + self.path = '{}/command/{}/{}'.format(self.api_path, + self.device_id, + command) + self._call_post(params, timeout) + + def command_objects_all(self) -> None: """ From ab40f4bf9553010b477ebe474b974480779e9ccc Mon Sep 17 00:00:00 2001 From: Saliou DIOP Date: Fri, 1 Aug 2025 11:34:54 +0200 Subject: [PATCH 02/30] update path. test file created --- msa_sdk/order.py | 51 +++++++++++++++-------------- tests/test_order_command_execute.py | 19 +++++++++++ 2 files changed, 45 insertions(+), 25 deletions(-) diff --git a/msa_sdk/order.py b/msa_sdk/order.py index 5559be3a..c285d20f 100644 --- a/msa_sdk/order.py +++ b/msa_sdk/order.py @@ -48,34 +48,15 @@ def command_execute(self, command: str, params: dict, timeout=300) -> None: self._call_post(params, timeout) - def apply_command_stack(self, command: str, params: dict, timeout=300) -> None: + def apply_command_stack(self, timeout=300) -> None: """ Apply all commands stack of a device. Parameters ----------- - command: String - Apply command - Available values : CREATE, UPDATE, IMPORT, LIST, READ, DELETE - - params: dict - Parameters in a dict format: - - { - "simple_firewall": { - "1": { - "object_id": "1", - "src_ip": "3.4.5.7", - "dst_port": "44" - }, - "2": { - "object_id": "2", - "src_ip": "3.4.5.6", - "dst_port": "42" - } - } - timeout: int timeout in sec (300 secondes by default) + timeout: Integer + Connection timeout (300 seconds by default) Returns ------- @@ -84,10 +65,10 @@ def apply_command_stack(self, command: str, params: dict, timeout=300) -> None: """ self.action = 'Command execute' self.api_path = '/orderstack' - self.path = '{}/command/{}/{}'.format(self.api_path, self.device_id, - command) + self.path = '{}/execute/{}'.format(self.api_path, self.device_id) - self._call_post(params, timeout) + self._call_post(timeout=timeout) + self.api_path = '/ordercommand' def command_generate_configuration(self, command: str, params: dict) -> None: @@ -236,6 +217,25 @@ def command_stack(self, command: str, params, ----------- command: String CRUID method in microservice to add to the stack. + + params: dict + Parameters in a dict format: + + { + "simple_firewall": { + "1": { + "object_id": "1", + "src_ip": "3.4.5.7", + "dst_port": "44" + }, + "2": { + "object_id": "2", + "src_ip": "3.4.5.6", + "dst_port": "42" + } + } + timeout: int timeout in sec (300 secondes by default) + Returns -------- None @@ -247,6 +247,7 @@ def command_stack(self, command: str, params, self.device_id, command) self._call_post(params, timeout) + self.api_path = '/ordercommand' def command_objects_all(self) -> None: diff --git a/tests/test_order_command_execute.py b/tests/test_order_command_execute.py index 808a4f78..010f7435 100644 --- a/tests/test_order_command_execute.py +++ b/tests/test_order_command_execute.py @@ -25,6 +25,25 @@ def test_command_execute(_, order_fixture): mock_call_post.assert_called_once_with({"subnet": "mySubnet"}, 50) +# @patch('msa_sdk.device.Device.read') +# def test_apply_command_stack(_, order_fixture): +# """ +# Test Command apply command stack +# """ + +# local_path_command_stack = '/orderstack/command/21594/UPDATE' +# local_path_apply = '/orderstack/execute/21594' + +# with patch('msa_sdk.msa_api.MSA_API._call_post') as mock_call_post: +# order = order_fixture +# order.command_stack('UPDATE', {"1": {"subnet": "mySubnet1"}, "2": {"subnet": "mySubnet2"}}, 50) +# assert order.path == local_path_command_stack +# mock_call_post.assert_called_with({"1": {"subnet": "mySubnet1"}, "2": {"subnet": "mySubnet2"}}, 50) +# order.apply_command_stack() +# assert order.path == local_path_apply + + + def test_command_execute_fail(order_fixture): """ Test Command execute fail parameters type From f809385cfdfaeea0d352d1f1078bc03ef92f59a6 Mon Sep 17 00:00:00 2001 From: Saliou DIOP Date: Fri, 1 Aug 2025 11:35:24 +0200 Subject: [PATCH 03/30] test file added --- tests/test_command_stack.py | 47 +++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 tests/test_command_stack.py diff --git a/tests/test_command_stack.py b/tests/test_command_stack.py new file mode 100644 index 00000000..3e713dfd --- /dev/null +++ b/tests/test_command_stack.py @@ -0,0 +1,47 @@ +""" +Test Order Command +""" +import json +from unittest.mock import patch + +import pytest +from util import order_fixture # pylint: disable=unused-import + + +@patch('msa_sdk.device.Device.read') +def test_command_execute(_, order_fixture): + """ + Test Command execute + """ + + local_path = '/ordercommand/execute/21594/UPDATE' + + with patch('msa_sdk.msa_api.MSA_API._call_post') as mock_call_post: + order = order_fixture + order.command_execute('UPDATE', {"subnet": "mySubnet"}, 50) + + assert order.path == local_path + + mock_call_post.assert_called_once_with({"subnet": "mySubnet"}, 50) + + +@patch('msa_sdk.device.Device.read') +def test_apply_command_stack(_, order_fixture): + """ + Test Command apply command stack + """ + + local_path_command_stack = '/orderstack/command/21594/UPDATE' + local_path_apply = '/orderstack/execute/21594' + + with patch('msa_sdk.msa_api.MSA_API._call_post') as mock_call_post: + order = order_fixture + order.command_stack('UPDATE', {"1": {"subnet": "mySubnet1"}, "2": {"subnet": "mySubnet2"}}, 50) + assert order.path == local_path_command_stack + mock_call_post.assert_called_with({"1": {"subnet": "mySubnet1"}, "2": {"subnet": "mySubnet2"}}, 50) + order.apply_command_stack() + assert order.path == local_path_apply + + + + From d73ddf3c0992354d7fd751f0f4bf5baeb93acd21 Mon Sep 17 00:00:00 2001 From: sdi38 Date: Mon, 4 Aug 2025 09:29:14 +0200 Subject: [PATCH 04/30] Update msa_sdk/order.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- msa_sdk/order.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/msa_sdk/order.py b/msa_sdk/order.py index c285d20f..20f7bb5d 100644 --- a/msa_sdk/order.py +++ b/msa_sdk/order.py @@ -42,7 +42,7 @@ def command_execute(self, command: str, params: dict, timeout=300) -> None: None """ - self.action = 'Commands stack execute' + self.action = 'Command execute' self.path = '{}/execute/{}/{}'.format(self.api_path, self.device_id, command) From 5ee4302dcd9c1bd65da8cd1f7741901fc0a79abd Mon Sep 17 00:00:00 2001 From: sdi38 Date: Mon, 4 Aug 2025 09:30:00 +0200 Subject: [PATCH 05/30] Update tests/test_command_stack.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- tests/test_command_stack.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_command_stack.py b/tests/test_command_stack.py index 3e713dfd..ca54de99 100644 --- a/tests/test_command_stack.py +++ b/tests/test_command_stack.py @@ -1,5 +1,5 @@ """ -Test Order Command +Test Order Command Stack """ import json from unittest.mock import patch From 67fa32bb835f437f21c3485a316ec9992152583a Mon Sep 17 00:00:00 2001 From: sdi38 Date: Mon, 4 Aug 2025 09:30:33 +0200 Subject: [PATCH 06/30] Update msa_sdk/order.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- msa_sdk/order.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/msa_sdk/order.py b/msa_sdk/order.py index 20f7bb5d..c4f6d0c4 100644 --- a/msa_sdk/order.py +++ b/msa_sdk/order.py @@ -67,7 +67,7 @@ def apply_command_stack(self, timeout=300) -> None: self.api_path = '/orderstack' self.path = '{}/execute/{}'.format(self.api_path, self.device_id) - self._call_post(timeout=timeout) + self._call_post({}, timeout) self.api_path = '/ordercommand' def command_generate_configuration(self, command: str, From 3e741fe10aee5cc2834c52e3e11506ab45d6393f Mon Sep 17 00:00:00 2001 From: Saliou DIOP Date: Mon, 4 Aug 2025 10:15:33 +0200 Subject: [PATCH 07/30] OPSLAB-89: suppression of apply_stack methode --- msa_sdk/order.py | 23 +---------------------- tests/test_command_stack.py | 28 +++++----------------------- 2 files changed, 6 insertions(+), 45 deletions(-) diff --git a/msa_sdk/order.py b/msa_sdk/order.py index c4f6d0c4..92ded9b2 100644 --- a/msa_sdk/order.py +++ b/msa_sdk/order.py @@ -48,27 +48,6 @@ def command_execute(self, command: str, params: dict, timeout=300) -> None: self._call_post(params, timeout) - def apply_command_stack(self, timeout=300) -> None: - """ - - Apply all commands stack of a device. - - Parameters - ----------- - timeout: Integer - Connection timeout (300 seconds by default) - - Returns - ------- - None - - """ - self.action = 'Command execute' - self.api_path = '/orderstack' - self.path = '{}/execute/{}'.format(self.api_path, self.device_id) - - self._call_post({}, timeout) - self.api_path = '/ordercommand' def command_generate_configuration(self, command: str, params: dict) -> None: @@ -211,7 +190,7 @@ def command_stack(self, command: str, params, timeout=300) -> None: """ - Stack Command. + To queue multiple commands in a stack. Parameters ----------- diff --git a/tests/test_command_stack.py b/tests/test_command_stack.py index ca54de99..48a6d598 100644 --- a/tests/test_command_stack.py +++ b/tests/test_command_stack.py @@ -1,5 +1,5 @@ """ -Test Order Command Stack +Test Order Command """ import json from unittest.mock import patch @@ -9,39 +9,21 @@ @patch('msa_sdk.device.Device.read') -def test_command_execute(_, order_fixture): - """ - Test Command execute - """ - - local_path = '/ordercommand/execute/21594/UPDATE' - - with patch('msa_sdk.msa_api.MSA_API._call_post') as mock_call_post: - order = order_fixture - order.command_execute('UPDATE', {"subnet": "mySubnet"}, 50) - - assert order.path == local_path - - mock_call_post.assert_called_once_with({"subnet": "mySubnet"}, 50) - - -@patch('msa_sdk.device.Device.read') -def test_apply_command_stack(_, order_fixture): +def test_command_stack(_, order_fixture): """ Test Command apply command stack """ local_path_command_stack = '/orderstack/command/21594/UPDATE' - local_path_apply = '/orderstack/execute/21594' with patch('msa_sdk.msa_api.MSA_API._call_post') as mock_call_post: order = order_fixture order.command_stack('UPDATE', {"1": {"subnet": "mySubnet1"}, "2": {"subnet": "mySubnet2"}}, 50) + assert order.path == local_path_command_stack - mock_call_post.assert_called_with({"1": {"subnet": "mySubnet1"}, "2": {"subnet": "mySubnet2"}}, 50) - order.apply_command_stack() - assert order.path == local_path_apply + print(json.loads(order.content)) + mock_call_post.assert_called_with({"1": {"subnet": "mySubnet1"}, "2": {"subnet": "mySubnet2"}}, 50) From 8e63b11f26542ecdc99e7c7f7f6cd3677a055abe Mon Sep 17 00:00:00 2001 From: Saliou DIOP Date: Fri, 1 Aug 2025 09:49:27 +0200 Subject: [PATCH 08/30] the MS stack management methods (create a stack, apply a stack) added --- msa_sdk/order.py | 67 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 66 insertions(+), 1 deletion(-) diff --git a/msa_sdk/order.py b/msa_sdk/order.py index dd16555d..5559be3a 100644 --- a/msa_sdk/order.py +++ b/msa_sdk/order.py @@ -42,12 +42,53 @@ def command_execute(self, command: str, params: dict, timeout=300) -> None: None """ - self.action = 'Command execute' + self.action = 'Commands stack execute' self.path = '{}/execute/{}/{}'.format(self.api_path, self.device_id, command) self._call_post(params, timeout) + def apply_command_stack(self, command: str, params: dict, timeout=300) -> None: + """ + + Apply all commands stack of a device. + + Parameters + ----------- + command: String + Apply command + Available values : CREATE, UPDATE, IMPORT, LIST, READ, DELETE + + params: dict + Parameters in a dict format: + + { + "simple_firewall": { + "1": { + "object_id": "1", + "src_ip": "3.4.5.7", + "dst_port": "44" + }, + "2": { + "object_id": "2", + "src_ip": "3.4.5.6", + "dst_port": "42" + } + } + timeout: int timeout in sec (300 secondes by default) + + Returns + ------- + None + + """ + self.action = 'Command execute' + self.api_path = '/orderstack' + self.path = '{}/command/{}/{}'.format(self.api_path, self.device_id, + command) + + self._call_post(params, timeout) + def command_generate_configuration(self, command: str, params: dict) -> None: """ @@ -184,6 +225,30 @@ def command_call(self, command: str, mode: int, params, mode) self._call_post(params, timeout) + + def command_stack(self, command: str, params, + timeout=300) -> None: + """ + + Stack Command. + + Parameters + ----------- + command: String + CRUID method in microservice to add to the stack. + Returns + -------- + None + + """ + self.action = 'Call command' + self.api_path = '/orderstack' + self.path = '{}/command/{}/{}'.format(self.api_path, + self.device_id, + command) + self._call_post(params, timeout) + + def command_objects_all(self) -> None: """ From 385504f42dc12e7d2743411ce354b868addb130c Mon Sep 17 00:00:00 2001 From: Saliou DIOP Date: Fri, 1 Aug 2025 11:34:54 +0200 Subject: [PATCH 09/30] update path. test file created --- msa_sdk/order.py | 51 +++++++++++++++-------------- tests/test_order_command_execute.py | 19 +++++++++++ 2 files changed, 45 insertions(+), 25 deletions(-) diff --git a/msa_sdk/order.py b/msa_sdk/order.py index 5559be3a..c285d20f 100644 --- a/msa_sdk/order.py +++ b/msa_sdk/order.py @@ -48,34 +48,15 @@ def command_execute(self, command: str, params: dict, timeout=300) -> None: self._call_post(params, timeout) - def apply_command_stack(self, command: str, params: dict, timeout=300) -> None: + def apply_command_stack(self, timeout=300) -> None: """ Apply all commands stack of a device. Parameters ----------- - command: String - Apply command - Available values : CREATE, UPDATE, IMPORT, LIST, READ, DELETE - - params: dict - Parameters in a dict format: - - { - "simple_firewall": { - "1": { - "object_id": "1", - "src_ip": "3.4.5.7", - "dst_port": "44" - }, - "2": { - "object_id": "2", - "src_ip": "3.4.5.6", - "dst_port": "42" - } - } - timeout: int timeout in sec (300 secondes by default) + timeout: Integer + Connection timeout (300 seconds by default) Returns ------- @@ -84,10 +65,10 @@ def apply_command_stack(self, command: str, params: dict, timeout=300) -> None: """ self.action = 'Command execute' self.api_path = '/orderstack' - self.path = '{}/command/{}/{}'.format(self.api_path, self.device_id, - command) + self.path = '{}/execute/{}'.format(self.api_path, self.device_id) - self._call_post(params, timeout) + self._call_post(timeout=timeout) + self.api_path = '/ordercommand' def command_generate_configuration(self, command: str, params: dict) -> None: @@ -236,6 +217,25 @@ def command_stack(self, command: str, params, ----------- command: String CRUID method in microservice to add to the stack. + + params: dict + Parameters in a dict format: + + { + "simple_firewall": { + "1": { + "object_id": "1", + "src_ip": "3.4.5.7", + "dst_port": "44" + }, + "2": { + "object_id": "2", + "src_ip": "3.4.5.6", + "dst_port": "42" + } + } + timeout: int timeout in sec (300 secondes by default) + Returns -------- None @@ -247,6 +247,7 @@ def command_stack(self, command: str, params, self.device_id, command) self._call_post(params, timeout) + self.api_path = '/ordercommand' def command_objects_all(self) -> None: diff --git a/tests/test_order_command_execute.py b/tests/test_order_command_execute.py index 808a4f78..010f7435 100644 --- a/tests/test_order_command_execute.py +++ b/tests/test_order_command_execute.py @@ -25,6 +25,25 @@ def test_command_execute(_, order_fixture): mock_call_post.assert_called_once_with({"subnet": "mySubnet"}, 50) +# @patch('msa_sdk.device.Device.read') +# def test_apply_command_stack(_, order_fixture): +# """ +# Test Command apply command stack +# """ + +# local_path_command_stack = '/orderstack/command/21594/UPDATE' +# local_path_apply = '/orderstack/execute/21594' + +# with patch('msa_sdk.msa_api.MSA_API._call_post') as mock_call_post: +# order = order_fixture +# order.command_stack('UPDATE', {"1": {"subnet": "mySubnet1"}, "2": {"subnet": "mySubnet2"}}, 50) +# assert order.path == local_path_command_stack +# mock_call_post.assert_called_with({"1": {"subnet": "mySubnet1"}, "2": {"subnet": "mySubnet2"}}, 50) +# order.apply_command_stack() +# assert order.path == local_path_apply + + + def test_command_execute_fail(order_fixture): """ Test Command execute fail parameters type From e552241733e260e3ce4b9cfe2296aa0bc09caec7 Mon Sep 17 00:00:00 2001 From: Saliou DIOP Date: Fri, 1 Aug 2025 11:35:24 +0200 Subject: [PATCH 10/30] test file added --- tests/test_command_stack.py | 47 +++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 tests/test_command_stack.py diff --git a/tests/test_command_stack.py b/tests/test_command_stack.py new file mode 100644 index 00000000..3e713dfd --- /dev/null +++ b/tests/test_command_stack.py @@ -0,0 +1,47 @@ +""" +Test Order Command +""" +import json +from unittest.mock import patch + +import pytest +from util import order_fixture # pylint: disable=unused-import + + +@patch('msa_sdk.device.Device.read') +def test_command_execute(_, order_fixture): + """ + Test Command execute + """ + + local_path = '/ordercommand/execute/21594/UPDATE' + + with patch('msa_sdk.msa_api.MSA_API._call_post') as mock_call_post: + order = order_fixture + order.command_execute('UPDATE', {"subnet": "mySubnet"}, 50) + + assert order.path == local_path + + mock_call_post.assert_called_once_with({"subnet": "mySubnet"}, 50) + + +@patch('msa_sdk.device.Device.read') +def test_apply_command_stack(_, order_fixture): + """ + Test Command apply command stack + """ + + local_path_command_stack = '/orderstack/command/21594/UPDATE' + local_path_apply = '/orderstack/execute/21594' + + with patch('msa_sdk.msa_api.MSA_API._call_post') as mock_call_post: + order = order_fixture + order.command_stack('UPDATE', {"1": {"subnet": "mySubnet1"}, "2": {"subnet": "mySubnet2"}}, 50) + assert order.path == local_path_command_stack + mock_call_post.assert_called_with({"1": {"subnet": "mySubnet1"}, "2": {"subnet": "mySubnet2"}}, 50) + order.apply_command_stack() + assert order.path == local_path_apply + + + + From 792037059a35501f05249e907284c93e68516aab Mon Sep 17 00:00:00 2001 From: sdi38 Date: Mon, 4 Aug 2025 09:29:14 +0200 Subject: [PATCH 11/30] Update msa_sdk/order.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- msa_sdk/order.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/msa_sdk/order.py b/msa_sdk/order.py index c285d20f..20f7bb5d 100644 --- a/msa_sdk/order.py +++ b/msa_sdk/order.py @@ -42,7 +42,7 @@ def command_execute(self, command: str, params: dict, timeout=300) -> None: None """ - self.action = 'Commands stack execute' + self.action = 'Command execute' self.path = '{}/execute/{}/{}'.format(self.api_path, self.device_id, command) From 715bbc5b1804fd5d7b4dd66b272e9c29c3c983d6 Mon Sep 17 00:00:00 2001 From: sdi38 Date: Mon, 4 Aug 2025 09:30:00 +0200 Subject: [PATCH 12/30] Update tests/test_command_stack.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- tests/test_command_stack.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_command_stack.py b/tests/test_command_stack.py index 3e713dfd..ca54de99 100644 --- a/tests/test_command_stack.py +++ b/tests/test_command_stack.py @@ -1,5 +1,5 @@ """ -Test Order Command +Test Order Command Stack """ import json from unittest.mock import patch From b842d983c838f073ca7ccaa1b4facd98016de9ee Mon Sep 17 00:00:00 2001 From: sdi38 Date: Mon, 4 Aug 2025 09:30:33 +0200 Subject: [PATCH 13/30] Update msa_sdk/order.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- msa_sdk/order.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/msa_sdk/order.py b/msa_sdk/order.py index 20f7bb5d..c4f6d0c4 100644 --- a/msa_sdk/order.py +++ b/msa_sdk/order.py @@ -67,7 +67,7 @@ def apply_command_stack(self, timeout=300) -> None: self.api_path = '/orderstack' self.path = '{}/execute/{}'.format(self.api_path, self.device_id) - self._call_post(timeout=timeout) + self._call_post({}, timeout) self.api_path = '/ordercommand' def command_generate_configuration(self, command: str, From ac50d308c714332df302429ecd72689fa991046d Mon Sep 17 00:00:00 2001 From: Saliou DIOP Date: Mon, 4 Aug 2025 10:15:33 +0200 Subject: [PATCH 14/30] OPSLAB-89: suppression of apply_stack methode --- msa_sdk/order.py | 23 +---------------------- tests/test_command_stack.py | 28 +++++----------------------- 2 files changed, 6 insertions(+), 45 deletions(-) diff --git a/msa_sdk/order.py b/msa_sdk/order.py index c4f6d0c4..92ded9b2 100644 --- a/msa_sdk/order.py +++ b/msa_sdk/order.py @@ -48,27 +48,6 @@ def command_execute(self, command: str, params: dict, timeout=300) -> None: self._call_post(params, timeout) - def apply_command_stack(self, timeout=300) -> None: - """ - - Apply all commands stack of a device. - - Parameters - ----------- - timeout: Integer - Connection timeout (300 seconds by default) - - Returns - ------- - None - - """ - self.action = 'Command execute' - self.api_path = '/orderstack' - self.path = '{}/execute/{}'.format(self.api_path, self.device_id) - - self._call_post({}, timeout) - self.api_path = '/ordercommand' def command_generate_configuration(self, command: str, params: dict) -> None: @@ -211,7 +190,7 @@ def command_stack(self, command: str, params, timeout=300) -> None: """ - Stack Command. + To queue multiple commands in a stack. Parameters ----------- diff --git a/tests/test_command_stack.py b/tests/test_command_stack.py index ca54de99..48a6d598 100644 --- a/tests/test_command_stack.py +++ b/tests/test_command_stack.py @@ -1,5 +1,5 @@ """ -Test Order Command Stack +Test Order Command """ import json from unittest.mock import patch @@ -9,39 +9,21 @@ @patch('msa_sdk.device.Device.read') -def test_command_execute(_, order_fixture): - """ - Test Command execute - """ - - local_path = '/ordercommand/execute/21594/UPDATE' - - with patch('msa_sdk.msa_api.MSA_API._call_post') as mock_call_post: - order = order_fixture - order.command_execute('UPDATE', {"subnet": "mySubnet"}, 50) - - assert order.path == local_path - - mock_call_post.assert_called_once_with({"subnet": "mySubnet"}, 50) - - -@patch('msa_sdk.device.Device.read') -def test_apply_command_stack(_, order_fixture): +def test_command_stack(_, order_fixture): """ Test Command apply command stack """ local_path_command_stack = '/orderstack/command/21594/UPDATE' - local_path_apply = '/orderstack/execute/21594' with patch('msa_sdk.msa_api.MSA_API._call_post') as mock_call_post: order = order_fixture order.command_stack('UPDATE', {"1": {"subnet": "mySubnet1"}, "2": {"subnet": "mySubnet2"}}, 50) + assert order.path == local_path_command_stack - mock_call_post.assert_called_with({"1": {"subnet": "mySubnet1"}, "2": {"subnet": "mySubnet2"}}, 50) - order.apply_command_stack() - assert order.path == local_path_apply + print(json.loads(order.content)) + mock_call_post.assert_called_with({"1": {"subnet": "mySubnet1"}, "2": {"subnet": "mySubnet2"}}, 50) From 14f3f7fb70b55a28c37a244bb006bc7db185c333 Mon Sep 17 00:00:00 2001 From: Saliou DIOP Date: Mon, 4 Aug 2025 10:29:31 +0200 Subject: [PATCH 15/30] OPSLAB-69: suppression comments --- tests/test_order_command_execute.py | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/tests/test_order_command_execute.py b/tests/test_order_command_execute.py index 010f7435..e44de8fe 100644 --- a/tests/test_order_command_execute.py +++ b/tests/test_order_command_execute.py @@ -24,26 +24,6 @@ def test_command_execute(_, order_fixture): mock_call_post.assert_called_once_with({"subnet": "mySubnet"}, 50) - -# @patch('msa_sdk.device.Device.read') -# def test_apply_command_stack(_, order_fixture): -# """ -# Test Command apply command stack -# """ - -# local_path_command_stack = '/orderstack/command/21594/UPDATE' -# local_path_apply = '/orderstack/execute/21594' - -# with patch('msa_sdk.msa_api.MSA_API._call_post') as mock_call_post: -# order = order_fixture -# order.command_stack('UPDATE', {"1": {"subnet": "mySubnet1"}, "2": {"subnet": "mySubnet2"}}, 50) -# assert order.path == local_path_command_stack -# mock_call_post.assert_called_with({"1": {"subnet": "mySubnet1"}, "2": {"subnet": "mySubnet2"}}, 50) -# order.apply_command_stack() -# assert order.path == local_path_apply - - - def test_command_execute_fail(order_fixture): """ Test Command execute fail parameters type From abe6ee7cc07c856c59b886a30c11d395ded6095c Mon Sep 17 00:00:00 2001 From: Saliou DIOP Date: Tue, 5 Aug 2025 12:09:06 +0200 Subject: [PATCH 16/30] opslab 69: order_stack.py create, method stack added --- msa_sdk/order_stack.py | 96 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 msa_sdk/order_stack.py diff --git a/msa_sdk/order_stack.py b/msa_sdk/order_stack.py new file mode 100644 index 00000000..87309ffa --- /dev/null +++ b/msa_sdk/order_stack.py @@ -0,0 +1,96 @@ +"""Module Order.""" + +import json + +from msa_sdk.device import Device + + +class Order(Device): + """Class Order.""" + + def __init__(self, device_id): + """Initialize.""" + Device.__init__(self, device_id=device_id) + self.api_path = '/orderstack' + + + self._call_get() + return json.loads(self.content) + + + def add_command_in_stack(self, command: str, params, + timeout=300) -> None: + """ + + To queue multiple commands in a stack. + + Parameters + ----------- + command: String + CRUID method in microservice to add to the stack. + + params: dict + Parameters in a dict format: + + { + "simple_firewall": { + "1": { + "object_id": "1", + "src_ip": "3.4.5.7", + "dst_port": "44" + }, + "2": { + "object_id": "2", + "src_ip": "3.4.5.6", + "dst_port": "42" + } + } + timeout: int timeout in sec (300 secondes by default) + + Returns + -------- + None + + """ + self.action = 'Adds a command in the stack' + self.path = '{}/command/{}/{}'.format(self.api_path, + self.device_id, + command) + self._call_put(params, timeout) + + + def apply_commands_stacked(self, command: str, params: dict, timeout=300) -> None: + """ + Apply all commands stack of a device. + Parameters + ----------- + command: String + Apply command + Available values : CREATE, UPDATE, IMPORT, LIST, READ, DELETE + params: dict + Parameters in a dict format: + { + "simple_firewall": { + "1": { + "object_id": "1", + "src_ip": "3.4.5.7", + "dst_port": "44" + }, + "2": { + "object_id": "2", + "src_ip": "3.4.5.6", + "dst_port": "42" + } + } + timeout: int timeout in sec (300 secondes by default) + Returns + ------- + None + """ + self.action = 'Execute all the commands stacked' + self.path = '{}/command/{}/{}'.format(self.api_path, self.device_id, + command) + + self._call_post(params, timeout) + + From d7c01f36d975f7149d854940180dc664307e69e7 Mon Sep 17 00:00:00 2001 From: Saliou DIOP Date: Tue, 5 Aug 2025 12:12:13 +0200 Subject: [PATCH 17/30] opslab 69: classname changed --- msa_sdk/order_stack.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/msa_sdk/order_stack.py b/msa_sdk/order_stack.py index 87309ffa..b305c7dc 100644 --- a/msa_sdk/order_stack.py +++ b/msa_sdk/order_stack.py @@ -5,8 +5,8 @@ from msa_sdk.device import Device -class Order(Device): - """Class Order.""" +class OrderStack(Device): + """Class OrderStack.""" def __init__(self, device_id): """Initialize.""" From 17182f408ac4e88e15006de5f471b6edd404e3c1 Mon Sep 17 00:00:00 2001 From: Saliou DIOP Date: Tue, 5 Aug 2025 12:21:42 +0200 Subject: [PATCH 18/30] opslab 69: orderstack_fixture added --- tests/util.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/util.py b/tests/util.py index 18cf8e77..e24e3341 100644 --- a/tests/util.py +++ b/tests/util.py @@ -11,6 +11,7 @@ from msa_sdk.device import Device from msa_sdk.orchestration import Orchestration from msa_sdk.order import Order +from msa_sdk.order_stack import OrderStack from msa_sdk.profile import Profile from msa_sdk.repository import Repository @@ -224,6 +225,21 @@ def order_fixture(): return order +@pytest.fixture +def orderstack_fixture(): + """OrderStack fixture.""" + with patch('requests.post') as mock_post: + mock_post.return_value.json.return_value = {'token': '12345qwert'} + + with patch('requests.get') as mock_call_get: + mock_call_get.return_value.text = device_info() + + with patch('msa_sdk.msa_api.host_port') as mock_host_port: + mock_host_port.return_value = ('api_hostname', '8080') + orderstack = OrderStack(1234) + return orderstack + + @pytest.fixture def customer_fixture(): """Create Customer fixture.""" From 6287da5ff52e5ce8f2f08e0afdf4a284565af09e Mon Sep 17 00:00:00 2001 From: Saliou DIOP Date: Tue, 5 Aug 2025 12:26:07 +0200 Subject: [PATCH 19/30] opslab 69: test_add_command_in_stack created --- tests/test_order_stack.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 tests/test_order_stack.py diff --git a/tests/test_order_stack.py b/tests/test_order_stack.py new file mode 100644 index 00000000..5fdc6e5b --- /dev/null +++ b/tests/test_order_stack.py @@ -0,0 +1,28 @@ +""" +Test Order Command +""" +import json +from unittest.mock import patch + +import pytest +from util import orderstack_fixture # pylint: disable=unused-import + + +@patch('msa_sdk.device.Device.read') +def test_add_command_in_stack(_, orderstack_fixture): + """ + Test Command apply command stack + """ + + local_path_command_stack = '/orderstack/command/21594/UPDATE' + + with patch('msa_sdk.msa_api.MSA_API._call_put') as mock_call_put: + orderstack = orderstack_fixture + orderstack.add_command_in_stack('UPDATE', {"1": {"subnet": "mySubnet1"}, "2": {"subnet": "mySubnet2"}}, 50) + + assert orderstack.path == local_path_command_stack + + mock_call_put.assert_called_once_with({"1": {"subnet": "mySubnet1"}, "2": {"subnet": "mySubnet2"}}, 50) + + + From 0b141a6680b818eb3d69e866240999e40c7c6fdb Mon Sep 17 00:00:00 2001 From: Saliou DIOP Date: Tue, 5 Aug 2025 12:35:44 +0200 Subject: [PATCH 20/30] opslab 69: method init updated --- msa_sdk/order_stack.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/msa_sdk/order_stack.py b/msa_sdk/order_stack.py index b305c7dc..b5ca88da 100644 --- a/msa_sdk/order_stack.py +++ b/msa_sdk/order_stack.py @@ -13,9 +13,6 @@ def __init__(self, device_id): Device.__init__(self, device_id=device_id) self.api_path = '/orderstack' - - self._call_get() - return json.loads(self.content) def add_command_in_stack(self, command: str, params, From 8dda68aae74e2e48c3950c5441b22bbda8ef4fa4 Mon Sep 17 00:00:00 2001 From: Saliou DIOP Date: Tue, 5 Aug 2025 12:59:54 +0200 Subject: [PATCH 21/30] opslab 69: params of apply_command_stacked updated --- msa_sdk/order_stack.py | 33 ++++++++------------------------- 1 file changed, 8 insertions(+), 25 deletions(-) diff --git a/msa_sdk/order_stack.py b/msa_sdk/order_stack.py index b5ca88da..d835a112 100644 --- a/msa_sdk/order_stack.py +++ b/msa_sdk/order_stack.py @@ -12,7 +12,6 @@ def __init__(self, device_id): """Initialize.""" Device.__init__(self, device_id=device_id) self.api_path = '/orderstack' - def add_command_in_stack(self, command: str, params, @@ -56,38 +55,22 @@ def add_command_in_stack(self, command: str, params, self._call_put(params, timeout) - def apply_commands_stacked(self, command: str, params: dict, timeout=300) -> None: + def apply_command_stacked(self, timeout=300) -> None: """ Apply all commands stack of a device. Parameters ----------- - command: String - Apply command - Available values : CREATE, UPDATE, IMPORT, LIST, READ, DELETE - params: dict - Parameters in a dict format: - { - "simple_firewall": { - "1": { - "object_id": "1", - "src_ip": "3.4.5.7", - "dst_port": "44" - }, - "2": { - "object_id": "2", - "src_ip": "3.4.5.6", - "dst_port": "42" - } - } - timeout: int timeout in sec (300 secondes by default) + device_id: int + Id of the device. + timeout: int + Timeout in seconds (300 seconds by default) Returns ------- None """ - self.action = 'Execute all the commands stacked' - self.path = '{}/command/{}/{}'.format(self.api_path, self.device_id, - command) + self.action = 'Apply all commands stack of a device' + self.path = '{}/execute/{}'.format(self.api_path, self.device_id) - self._call_post(params, timeout) + self._call_post(timeout=timeout) From 1c22935e74bbc6808455e1e2dae25c06acac2678 Mon Sep 17 00:00:00 2001 From: Saliou DIOP Date: Tue, 5 Aug 2025 13:01:08 +0200 Subject: [PATCH 22/30] opslab 69: test_apply_command_stacked updated to match apply method params --- tests/test_order_stack.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/tests/test_order_stack.py b/tests/test_order_stack.py index 5fdc6e5b..8b6a0d92 100644 --- a/tests/test_order_stack.py +++ b/tests/test_order_stack.py @@ -11,7 +11,7 @@ @patch('msa_sdk.device.Device.read') def test_add_command_in_stack(_, orderstack_fixture): """ - Test Command apply command stack + Test Add command in the stack """ local_path_command_stack = '/orderstack/command/21594/UPDATE' @@ -25,4 +25,18 @@ def test_add_command_in_stack(_, orderstack_fixture): mock_call_put.assert_called_once_with({"1": {"subnet": "mySubnet1"}, "2": {"subnet": "mySubnet2"}}, 50) +@patch('msa_sdk.device.Device.read') +def test_apply_command_stacked(_, orderstack_fixture): + """ + Test Apply command in the stack + """ + + local_path_apply = '/orderstack/execute/21594' + + with patch('msa_sdk.msa_api.MSA_API._call_post') as mock_call_post: + orderstack = orderstack_fixture + orderstack.apply_command_stacked(timeout=50) + + assert orderstack.path == local_path_apply + mock_call_post.assert_called_once_with(timeout=50) From fe52f9e04e52ee32f2f97c172d6b18bb382d0dbd Mon Sep 17 00:00:00 2001 From: Saliou DIOP Date: Tue, 5 Aug 2025 13:08:02 +0200 Subject: [PATCH 23/30] opslab 69: test_command_stack.py deleted --- tests/test_command_stack.py | 29 ----------------------------- 1 file changed, 29 deletions(-) delete mode 100644 tests/test_command_stack.py diff --git a/tests/test_command_stack.py b/tests/test_command_stack.py deleted file mode 100644 index 48a6d598..00000000 --- a/tests/test_command_stack.py +++ /dev/null @@ -1,29 +0,0 @@ -""" -Test Order Command -""" -import json -from unittest.mock import patch - -import pytest -from util import order_fixture # pylint: disable=unused-import - - -@patch('msa_sdk.device.Device.read') -def test_command_stack(_, order_fixture): - """ - Test Command apply command stack - """ - - local_path_command_stack = '/orderstack/command/21594/UPDATE' - - with patch('msa_sdk.msa_api.MSA_API._call_post') as mock_call_post: - order = order_fixture - order.command_stack('UPDATE', {"1": {"subnet": "mySubnet1"}, "2": {"subnet": "mySubnet2"}}, 50) - - assert order.path == local_path_command_stack - - print(json.loads(order.content)) - mock_call_post.assert_called_with({"1": {"subnet": "mySubnet1"}, "2": {"subnet": "mySubnet2"}}, 50) - - - From a80120760d2e25b09730db941acb2b4ca56fbbf5 Mon Sep 17 00:00:00 2001 From: Saliou DIOP Date: Tue, 5 Aug 2025 15:12:18 +0200 Subject: [PATCH 24/30] opslab 69: cleaning code --- msa_sdk/order.py | 44 ----------------------------- msa_sdk/order_stack.py | 11 ++++---- tests/test_order_command_execute.py | 1 + tests/test_order_stack.py | 2 +- 4 files changed, 7 insertions(+), 51 deletions(-) diff --git a/msa_sdk/order.py b/msa_sdk/order.py index 92ded9b2..cda4cac4 100644 --- a/msa_sdk/order.py +++ b/msa_sdk/order.py @@ -185,50 +185,6 @@ def command_call(self, command: str, mode: int, params, mode) self._call_post(params, timeout) - - def command_stack(self, command: str, params, - timeout=300) -> None: - """ - - To queue multiple commands in a stack. - - Parameters - ----------- - command: String - CRUID method in microservice to add to the stack. - - params: dict - Parameters in a dict format: - - { - "simple_firewall": { - "1": { - "object_id": "1", - "src_ip": "3.4.5.7", - "dst_port": "44" - }, - "2": { - "object_id": "2", - "src_ip": "3.4.5.6", - "dst_port": "42" - } - } - timeout: int timeout in sec (300 secondes by default) - - Returns - -------- - None - - """ - self.action = 'Call command' - self.api_path = '/orderstack' - self.path = '{}/command/{}/{}'.format(self.api_path, - self.device_id, - command) - self._call_post(params, timeout) - self.api_path = '/ordercommand' - - def command_objects_all(self) -> None: """ diff --git a/msa_sdk/order_stack.py b/msa_sdk/order_stack.py index d835a112..eda9bd6f 100644 --- a/msa_sdk/order_stack.py +++ b/msa_sdk/order_stack.py @@ -1,4 +1,4 @@ -"""Module Order.""" +"""Module Orderstack.""" import json @@ -18,7 +18,7 @@ def add_command_in_stack(self, command: str, params, timeout=300) -> None: """ - To queue multiple commands in a stack. + To push multiple commands in a stack. Parameters ----------- @@ -57,7 +57,7 @@ def add_command_in_stack(self, command: str, params, def apply_command_stacked(self, timeout=300) -> None: """ - Apply all commands stack of a device. + Execute all the commands stacked for the device. Parameters ----------- device_id: int @@ -67,10 +67,9 @@ def apply_command_stacked(self, timeout=300) -> None: Returns ------- None + """ - self.action = 'Apply all commands stack of a device' + self.action = 'Execute all the commands stacked for the device' self.path = '{}/execute/{}'.format(self.api_path, self.device_id) self._call_post(timeout=timeout) - - diff --git a/tests/test_order_command_execute.py b/tests/test_order_command_execute.py index e44de8fe..808a4f78 100644 --- a/tests/test_order_command_execute.py +++ b/tests/test_order_command_execute.py @@ -24,6 +24,7 @@ def test_command_execute(_, order_fixture): mock_call_post.assert_called_once_with({"subnet": "mySubnet"}, 50) + def test_command_execute_fail(order_fixture): """ Test Command execute fail parameters type diff --git a/tests/test_order_stack.py b/tests/test_order_stack.py index 8b6a0d92..8663c964 100644 --- a/tests/test_order_stack.py +++ b/tests/test_order_stack.py @@ -1,5 +1,5 @@ """ -Test Order Command +Test Order Stack """ import json from unittest.mock import patch From 1024f290db5dede96bcbd5d88cf6190f87c5c0a3 Mon Sep 17 00:00:00 2001 From: Saliou DIOP Date: Tue, 5 Aug 2025 15:29:43 +0200 Subject: [PATCH 25/30] opslab 69: cleaning code --- msa_sdk/order_stack.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/msa_sdk/order_stack.py b/msa_sdk/order_stack.py index eda9bd6f..c31c8828 100644 --- a/msa_sdk/order_stack.py +++ b/msa_sdk/order_stack.py @@ -57,6 +57,7 @@ def add_command_in_stack(self, command: str, params, def apply_command_stacked(self, timeout=300) -> None: """ + Execute all the commands stacked for the device. Parameters ----------- @@ -67,7 +68,7 @@ def apply_command_stacked(self, timeout=300) -> None: Returns ------- None - + """ self.action = 'Execute all the commands stacked for the device' self.path = '{}/execute/{}'.format(self.api_path, self.device_id) From fd8e1fd74a094f9c903d079750e2e7e19a665617 Mon Sep 17 00:00:00 2001 From: sdi38 Date: Tue, 5 Aug 2025 16:09:31 +0200 Subject: [PATCH 26/30] Delete msa_sdk/order.py --- msa_sdk/order.py | 292 ----------------------------------------------- 1 file changed, 292 deletions(-) delete mode 100644 msa_sdk/order.py diff --git a/msa_sdk/order.py b/msa_sdk/order.py deleted file mode 100644 index cda4cac4..00000000 --- a/msa_sdk/order.py +++ /dev/null @@ -1,292 +0,0 @@ -"""Module Order.""" - -import json - -from msa_sdk.device import Device - - -class Order(Device): - """Class Order.""" - - def __init__(self, device_id): - """Initialize.""" - Device.__init__(self, device_id=device_id) - self.api_path = '/ordercommand' - - def command_execute(self, command: str, params: dict, timeout=300) -> None: - """ - - Command execute. - - Parameters - ----------- - command: String - Order command - Available values : CREATE, UPDATE, IMPORT, LIST, READ, DELETE - - params: dict - Parameters in a dict format: - - { - "simple_firewall": { - "12": { - "object_id": "12", - "src_ip": "3.4.5.6", - "dst_port": "44" - } - } - timeout: int timeout in sec (300 secondes by default) - - Returns - ------- - None - - """ - self.action = 'Command execute' - self.path = '{}/execute/{}/{}'.format(self.api_path, self.device_id, - command) - - self._call_post(params, timeout) - - - def command_generate_configuration(self, command: str, - params: dict) -> None: - """ - - Command generate configuration. - - Parameters - ----------- - command: String - Order command - - params: dict - Parameters - - - Returns - ------- - None - - """ - self.action = 'Command generate configuration' - self.path = '{}/get/configuration/{}/{}'.format(self.api_path, - self.device_id, - command) - - self._call_post(params) - - def command_synchronize(self, timeout: int) -> None: - """ - - Command synchronize. - - Parameters - ----------- - timeout: Integer - Connection timeout - - - Returns - ------- - None - - """ - self.action = 'Command synchronize' - self.path = '{}/synchronize/{}'.format(self.api_path, - self.device_id) - - self._call_post(timeout=timeout) - - def command_synchronize_async(self) -> None: - """ - - Command synchronize Async. - - Returns - ------- - None - - """ - self.action = 'Command synchronize' - self.path = '{}/synchronize/{}?isAsync=true&importWithSameAndUpperRank=true'.format(self.api_path, - self.device_id) - - self._call_post() - - def get_synchronize_status(self): - """ - - Get synchronize Status. - - Returns - -------- - Dict() with synchronize status - - """ - self.action = 'Get synchronize Status' - self.path = '{}/synchronize/status?deviceId={}'.format(self.api_path, - self.device_id) - - self._call_get() - return json.loads(self.content) - - def command_synchronizeOneOrMoreObjectsFromDevice(self, - mservice_uris: list, - timeout: int) -> None: - """ - - Command synchronize objects from a Device. - - Parameters - ----------- - mservice_uris: List - List of microservices - - timeout: Integer - Connection timeout - - Returns - ------- - None - - """ - self.action = 'Command synchronize' - self.path = '{}/microservice/synchronize/{}'.format(self.api_path, - self.device_id) - - params = {"microServiceUris": mservice_uris} - - self._call_post(params, timeout=timeout) - - def command_call(self, command: str, mode: int, params, - timeout=300) -> None: - """ - - Command call. - - Parameters - ----------- - command: String - CRUID method in microservice to call - mode: Integer - 0 - No application - 1 - Apply to base - 2 - Apply to device - Returns - -------- - None - - """ - self.action = 'Call command' - self.path = '{}/call/{}/{}/{}'.format(self.api_path, - self.device_id, - command, - mode) - self._call_post(params, timeout) - - def command_objects_all(self) -> None: - """ - - Get all microservices attached to a device. - - Returns - -------- - None - - """ - self.action = 'Get Microservices' - self.path = f'{self.api_path}/objects/{self.device_id}' - self._call_get() - - def command_objects_instances(self, object_name: str) -> dict: - """ - - Get microservices instance by microservice name. - - Parameters - ----------- - object_name: String - Name of microservice - Returns - -------- - list of object: - List of object IDs per microservice - - """ - self.action = 'Get Microservice Instances' - self.path = '{}/objects/{}/{}'.format(self.api_path, - self.device_id, - object_name) - self._call_get() - - return json.loads(self.content) - - def command_objects_instances_by_id(self, object_name: str, - object_id: str) -> dict: - """ - - Get microservices instance by microservice object ID. - - Parameters - ----------- - object_name: String - Name of microservice - object_id: String - Object ID of microservice instance - Returns - -------- - list of object: - Object of microservice parameters per object ID - - """ - self.action = 'Get Microservice Object Details' - self.path = '{}/objects/{}/{}/{}'.format(self.api_path, - self.device_id, - object_name, - object_id) - self._call_get() - - return json.loads(self.content) - - def command_get_deployment_settings_id(self) -> int: - """ - - Get deployment settings ID for the device. - - Returns - -------- - Integer: - Deployment settings ID - - """ - self.action = 'Get deployment settings ID' - self.path = f'/conf-profile/v1/device/{self.device_id}' - self._call_get() - - config_profile_device = \ - json.loads(self.content)['ConfigProfileByDevice'] - - return int(config_profile_device) - - def command_objects_details_by_name(self, object_name): - """ - Get microservices configuration details by microservice name. - - Parameters - ----------- - object_name: String - Name of the microservice (configuration) - - Returns - -------- - list of object: - Configuration details of the microservice by name - """ - self.action = 'Get Microservice Configuration Details' - self.path = '{}/objects/{}/{}/details'.format(self.api_path, - self.device_id, - object_name) - self._call_get() - - return json.loads(self.content) From b4efc8f1a163683bf6027f97558b6d878e89734c Mon Sep 17 00:00:00 2001 From: sdi38 Date: Tue, 5 Aug 2025 16:10:34 +0200 Subject: [PATCH 27/30] Update order_stack.py --- msa_sdk/order_stack.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/msa_sdk/order_stack.py b/msa_sdk/order_stack.py index c31c8828..c23a5f68 100644 --- a/msa_sdk/order_stack.py +++ b/msa_sdk/order_stack.py @@ -57,8 +57,8 @@ def add_command_in_stack(self, command: str, params, def apply_command_stacked(self, timeout=300) -> None: """ - Execute all the commands stacked for the device. + Parameters ----------- device_id: int From b15c868d00b7275d53308e5f23c5546490127ec7 Mon Sep 17 00:00:00 2001 From: Saliou DIOP Date: Tue, 5 Aug 2025 16:15:39 +0200 Subject: [PATCH 28/30] opslab 69: order.py restored --- msa_sdk/order.py | 291 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 291 insertions(+) create mode 100644 msa_sdk/order.py diff --git a/msa_sdk/order.py b/msa_sdk/order.py new file mode 100644 index 00000000..2bd527c6 --- /dev/null +++ b/msa_sdk/order.py @@ -0,0 +1,291 @@ +"""Module Order.""" + +import json + +from msa_sdk.device import Device + + +class Order(Device): + """Class Order.""" + + def __init__(self, device_id): + """Initialize.""" + Device.__init__(self, device_id=device_id) + self.api_path = '/ordercommand' + + def command_execute(self, command: str, params: dict, timeout=300) -> None: + """ + + Command execute. + + Parameters + ----------- + command: String + Order command + Available values : CREATE, UPDATE, IMPORT, LIST, READ, DELETE + + params: dict + Parameters in a dict format: + + { + "simple_firewall": { + "12": { + "object_id": "12", + "src_ip": "3.4.5.6", + "dst_port": "44" + } + } + timeout: int timeout in sec (300 secondes by default) + + Returns + ------- + None + + """ + self.action = 'Command execute' + self.path = '{}/execute/{}/{}'.format(self.api_path, self.device_id, + command) + + self._call_post(params, timeout) + + def command_generate_configuration(self, command: str, + params: dict) -> None: + """ + + Command generate configuration. + + Parameters + ----------- + command: String + Order command + + params: dict + Parameters + + + Returns + ------- + None + + """ + self.action = 'Command generate configuration' + self.path = '{}/get/configuration/{}/{}'.format(self.api_path, + self.device_id, + command) + + self._call_post(params) + + def command_synchronize(self, timeout: int) -> None: + """ + + Command synchronize. + + Parameters + ----------- + timeout: Integer + Connection timeout + + + Returns + ------- + None + + """ + self.action = 'Command synchronize' + self.path = '{}/synchronize/{}'.format(self.api_path, + self.device_id) + + self._call_post(timeout=timeout) + + def command_synchronize_async(self) -> None: + """ + + Command synchronize Async. + + Returns + ------- + None + + """ + self.action = 'Command synchronize' + self.path = '{}/synchronize/{}?isAsync=true&importWithSameAndUpperRank=true'.format(self.api_path, + self.device_id) + + self._call_post() + + def get_synchronize_status(self): + """ + + Get synchronize Status. + + Returns + -------- + Dict() with synchronize status + + """ + self.action = 'Get synchronize Status' + self.path = '{}/synchronize/status?deviceId={}'.format(self.api_path, + self.device_id) + + self._call_get() + return json.loads(self.content) + + def command_synchronizeOneOrMoreObjectsFromDevice(self, + mservice_uris: list, + timeout: int) -> None: + """ + + Command synchronize objects from a Device. + + Parameters + ----------- + mservice_uris: List + List of microservices + + timeout: Integer + Connection timeout + + Returns + ------- + None + + """ + self.action = 'Command synchronize' + self.path = '{}/microservice/synchronize/{}'.format(self.api_path, + self.device_id) + + params = {"microServiceUris": mservice_uris} + + self._call_post(params, timeout=timeout) + + def command_call(self, command: str, mode: int, params, + timeout=300) -> None: + """ + + Command call. + + Parameters + ----------- + command: String + CRUID method in microservice to call + mode: Integer + 0 - No application + 1 - Apply to base + 2 - Apply to device + Returns + -------- + None + + """ + self.action = 'Call command' + self.path = '{}/call/{}/{}/{}'.format(self.api_path, + self.device_id, + command, + mode) + self._call_post(params, timeout) + + def command_objects_all(self) -> None: + """ + + Get all microservices attached to a device. + + Returns + -------- + None + + """ + self.action = 'Get Microservices' + self.path = f'{self.api_path}/objects/{self.device_id}' + self._call_get() + + def command_objects_instances(self, object_name: str) -> dict: + """ + + Get microservices instance by microservice name. + + Parameters + ----------- + object_name: String + Name of microservice + Returns + -------- + list of object: + List of object IDs per microservice + + """ + self.action = 'Get Microservice Instances' + self.path = '{}/objects/{}/{}'.format(self.api_path, + self.device_id, + object_name) + self._call_get() + + return json.loads(self.content) + + def command_objects_instances_by_id(self, object_name: str, + object_id: str) -> dict: + """ + + Get microservices instance by microservice object ID. + + Parameters + ----------- + object_name: String + Name of microservice + object_id: String + Object ID of microservice instance + Returns + -------- + list of object: + Object of microservice parameters per object ID + + """ + self.action = 'Get Microservice Object Details' + self.path = '{}/objects/{}/{}/{}'.format(self.api_path, + self.device_id, + object_name, + object_id) + self._call_get() + + return json.loads(self.content) + + def command_get_deployment_settings_id(self) -> int: + """ + + Get deployment settings ID for the device. + + Returns + -------- + Integer: + Deployment settings ID + + """ + self.action = 'Get deployment settings ID' + self.path = f'/conf-profile/v1/device/{self.device_id}' + self._call_get() + + config_profile_device = \ + json.loads(self.content)['ConfigProfileByDevice'] + + return int(config_profile_device) + + def command_objects_details_by_name(self, object_name): + """ + Get microservices configuration details by microservice name. + + Parameters + ----------- + object_name: String + Name of the microservice (configuration) + + Returns + -------- + list of object: + Configuration details of the microservice by name + """ + self.action = 'Get Microservice Configuration Details' + self.path = '{}/objects/{}/{}/details'.format(self.api_path, + self.device_id, + object_name) + self._call_get() + + return json.loads(self.content) \ No newline at end of file From 8a48654bddafa7fdb5b5092992ef442bb7c3bf40 Mon Sep 17 00:00:00 2001 From: Saliou DIOP Date: Tue, 5 Aug 2025 16:22:50 +0200 Subject: [PATCH 29/30] opslab 69: order.py restored --- msa_sdk/order.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/msa_sdk/order.py b/msa_sdk/order.py index 2bd527c6..dd16555d 100644 --- a/msa_sdk/order.py +++ b/msa_sdk/order.py @@ -288,4 +288,4 @@ def command_objects_details_by_name(self, object_name): object_name) self._call_get() - return json.loads(self.content) \ No newline at end of file + return json.loads(self.content) From 43a3aae82b9918f8a3ebf63f3bffedbdb53fa9ec Mon Sep 17 00:00:00 2001 From: Saliou DIOP Date: Tue, 5 Aug 2025 16:32:06 +0200 Subject: [PATCH 30/30] opslab 69: order.py restored --- tests/util.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/util.py b/tests/util.py index e24e3341..ff9dd7df 100644 --- a/tests/util.py +++ b/tests/util.py @@ -227,7 +227,7 @@ def order_fixture(): @pytest.fixture def orderstack_fixture(): - """OrderStack fixture.""" + """Orderstack fixture.""" with patch('requests.post') as mock_post: mock_post.return_value.json.return_value = {'token': '12345qwert'}