Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
df9a7c1
the MS stack management methods (create a stack, apply a stack) added
sdi38 Aug 1, 2025
ab40f4b
update path. test file created
sdi38 Aug 1, 2025
f809385
test file added
sdi38 Aug 1, 2025
d73ddf3
Update msa_sdk/order.py
sdi38 Aug 4, 2025
5ee4302
Update tests/test_command_stack.py
sdi38 Aug 4, 2025
67fa32b
Update msa_sdk/order.py
sdi38 Aug 4, 2025
3e741fe
OPSLAB-89: suppression of apply_stack methode
sdi38 Aug 4, 2025
8e63b11
the MS stack management methods (create a stack, apply a stack) added
sdi38 Aug 1, 2025
385504f
update path. test file created
sdi38 Aug 1, 2025
e552241
test file added
sdi38 Aug 1, 2025
7920370
Update msa_sdk/order.py
sdi38 Aug 4, 2025
715bbc5
Update tests/test_command_stack.py
sdi38 Aug 4, 2025
b842d98
Update msa_sdk/order.py
sdi38 Aug 4, 2025
ac50d30
OPSLAB-89: suppression of apply_stack methode
sdi38 Aug 4, 2025
2a3ed04
OPSLAB-89: Merge remote-tracking branch 'origin/sdi_stack_management'
sdi38 Aug 4, 2025
14f3f7f
OPSLAB-69: suppression comments
sdi38 Aug 4, 2025
abe6ee7
opslab 69: order_stack.py create, method stack added
sdi38 Aug 5, 2025
d7c01f3
opslab 69: classname changed
sdi38 Aug 5, 2025
17182f4
opslab 69: orderstack_fixture added
sdi38 Aug 5, 2025
6287da5
opslab 69: test_add_command_in_stack created
sdi38 Aug 5, 2025
0b141a6
opslab 69: method init updated
sdi38 Aug 5, 2025
8dda68a
opslab 69: params of apply_command_stacked updated
sdi38 Aug 5, 2025
1c22935
opslab 69: test_apply_command_stacked updated to match apply method p…
sdi38 Aug 5, 2025
fe52f9e
opslab 69: test_command_stack.py deleted
sdi38 Aug 5, 2025
a801207
opslab 69: cleaning code
sdi38 Aug 5, 2025
1024f29
opslab 69: cleaning code
sdi38 Aug 5, 2025
fd8e1fd
Delete msa_sdk/order.py
sdi38 Aug 5, 2025
b4efc8f
Update order_stack.py
sdi38 Aug 5, 2025
b15c868
opslab 69: order.py restored
sdi38 Aug 5, 2025
8a48654
opslab 69: order.py restored
sdi38 Aug 5, 2025
43a3aae
opslab 69: order.py restored
sdi38 Aug 5, 2025
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
76 changes: 76 additions & 0 deletions msa_sdk/order_stack.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
"""Module Orderstack."""

import json

from msa_sdk.device import Device


class OrderStack(Device):
"""Class OrderStack."""

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,
timeout=300) -> None:
"""

To push 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_command_stacked(self, timeout=300) -> None:
"""
Execute all the commands stacked for the device.

Parameters
-----------
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 for the device'
self.path = '{}/execute/{}'.format(self.api_path, self.device_id)

self._call_post(timeout=timeout)
42 changes: 42 additions & 0 deletions tests/test_order_stack.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
"""
Test Order Stack
"""
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 Add command in the 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)


@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)
16 changes: 16 additions & 0 deletions tests/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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."""
Expand Down