Skip to content

Commit

Permalink
Unit Testing for port_breakout module added (#229)
Browse files Browse the repository at this point in the history
  • Loading branch information
kannankvs authored Apr 12, 2023
1 parent 0938d39 commit 0f33f77
Show file tree
Hide file tree
Showing 2 changed files with 181 additions and 0 deletions.
106 changes: 106 additions & 0 deletions tests/unit/modules/network/sonic/fixtures/sonic_port_breakout.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
---
merged_01:
module_args:
config:
- name: BreakoutForEth1/10
mode: 1x100G
existing_port_breakout_config:
- path: "data/sonic-port-breakout:sonic-port-breakout/BREAKOUT_CFG/BREAKOUT_CFG_LIST"
response:
code: 200
expected_config_requests:
- path: "data/openconfig-platform:components"
method: "patch"
data:
openconfig-platform:components:
component:
- name: BreakoutForEth1/10
port:
openconfig-platform-port:breakout-mode:
groups:
group:
- index: 1
config:
index: 1
num-breakouts: 1
breakout-speed: SPEED_100GB
deleted_01:
module_args:
state: deleted
existing_port_breakout_config:
- path: "data/sonic-port-breakout:sonic-port-breakout/BREAKOUT_CFG/BREAKOUT_CFG_LIST"
response:
code: 200
value:
sonic-port-breakout:BREAKOUT_CFG_LIST:
- port: 1/10
brkout_mode: 1x100G
- path: "openconfig-platform:components"
response:
code: 200
value:
component:
- name: Eth1/1
- name: Eth1/10
- name: Eth1/20
- path: "data/openconfig-platform:components/component=1%2f10"
response:
code: 200
value:
openconfig-platform:component:
- name: Eth1/10
port:
openconfig-platform-port:breakout-mode:
groups:
group:
- index: 1
config:
index: 1
breakout-speed: openconfig-if-ethernet:SPEED_100GB
num-breakouts: 1
expected_config_requests:
- path: "data/openconfig-platform:components/component=1%2f10/port/openconfig-platform-port:breakout-mode"
method: "delete"
data:

deleted_02:
module_args:
state: deleted
config:
- name: 1/10
mode: 1x100G
existing_port_breakout_config:
- path: "data/sonic-port-breakout:sonic-port-breakout/BREAKOUT_CFG/BREAKOUT_CFG_LIST"
response:
code: 200
value:
sonic-port-breakout:BREAKOUT_CFG_LIST:
- port: 1/10
brkout_mode: 1x100G
- path: "openconfig-platform:components"
response:
code: 200
value:
component:
- name: Eth1/1
- name: Eth1/10
- name: Eth1/20
- path: "data/openconfig-platform:components/component=1%2f10"
response:
code: 200
value:
openconfig-platform:component:
- name: Eth1/10
port:
openconfig-platform-port:breakout-mode:
groups:
group:
- index: 1
config:
index: 1
breakout-speed: openconfig-if-ethernet:SPEED_100GB
num-breakouts: 1
expected_config_requests:
- path: "data/openconfig-platform:components/component=1%2f10/port/openconfig-platform-port:breakout-mode"
method: "delete"
data:
75 changes: 75 additions & 0 deletions tests/unit/modules/network/sonic/test_sonic_port_breakout.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
from __future__ import absolute_import, division, print_function

__metaclass__ = type

from ansible_collections.dellemc.enterprise_sonic.tests.unit.compat.mock import (
patch,
)
from ansible_collections.dellemc.enterprise_sonic.plugins.modules import (
sonic_port_breakout,
)
from ansible_collections.dellemc.enterprise_sonic.tests.unit.modules.utils import (
set_module_args,
)
from .sonic_module import TestSonicModule


class TestSonicInterfacesModule(TestSonicModule):
module = sonic_port_breakout

@classmethod
def setUpClass(cls):
cls.mock_facts_edit_config = patch(
"ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.facts.port_breakout.port_breakout.edit_config"
)
cls.mock_utils_edit_config = patch(
"ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.utils.utils.edit_config"
)
cls.mock_config_edit_config = patch(
"ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.config.port_breakout.port_breakout.edit_config"
)
cls.mock_get_interface_naming_mode = patch(
"ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.utils.utils.get_device_interface_naming_mode"
)
cls.fixture_data = cls.load_fixtures('sonic_port_breakout.yaml')

def setUp(self):
super(TestSonicInterfacesModule, self).setUp()
self.facts_edit_config = self.mock_facts_edit_config.start()
self.utils_edit_config = self.mock_utils_edit_config.start()
self.config_edit_config = self.mock_config_edit_config.start()

self.facts_edit_config.side_effect = self.facts_side_effect
self.utils_edit_config.side_effect = self.facts_side_effect
self.config_edit_config.side_effect = self.config_side_effect

self.get_interface_naming_mode = self.mock_get_interface_naming_mode.start()
self.get_interface_naming_mode.return_value = 'standard'

def tearDown(self):
super(TestSonicInterfacesModule, self).tearDown()
self.mock_facts_edit_config.stop()
self.mock_utils_edit_config.stop()
self.mock_config_edit_config.stop()
self.mock_get_interface_naming_mode.stop()

def test_sonic_port_breakout_merged_01(self):
set_module_args(self.fixture_data['merged_01']['module_args'])
self.initialize_facts_get_requests(self.fixture_data['merged_01']['existing_port_breakout_config'])
self.initialize_config_requests(self.fixture_data['merged_01']['expected_config_requests'])
result = self.execute_module(changed=True)
self.validate_config_requests()

def test_sonic_port_breakout_deleted_01(self):
set_module_args(self.fixture_data['deleted_01']['module_args'])
self.initialize_facts_get_requests(self.fixture_data['deleted_01']['existing_port_breakout_config'])
self.initialize_config_requests(self.fixture_data['deleted_01']['expected_config_requests'])
result = self.execute_module(changed=True)
self.validate_config_requests()

def test_sonic_port_breakout_deleted_02(self):
set_module_args(self.fixture_data['deleted_02']['module_args'])
self.initialize_facts_get_requests(self.fixture_data['deleted_02']['existing_port_breakout_config'])
self.initialize_config_requests(self.fixture_data['deleted_02']['expected_config_requests'])
result = self.execute_module(changed=True)
self.validate_config_requests()

0 comments on commit 0f33f77

Please sign in to comment.