Skip to content

Commit

Permalink
radius server unit testing code added (#210)
Browse files Browse the repository at this point in the history
  • Loading branch information
kannankvs authored Apr 3, 2023
1 parent 374316a commit 8e197b1
Show file tree
Hide file tree
Showing 2 changed files with 276 additions and 0 deletions.
207 changes: 207 additions & 0 deletions tests/unit/modules/network/sonic/fixtures/sonic_radius_server.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,207 @@
---
merged_01:
module_args:
config:
auth_type: chap
key: chap
nas_ip: 1.2.3.4
statistics: true
timeout: 10
retransmit: 3
servers:
host:
- name: localhost
auth_type: mschapv2
key: local
priority: 2
port: 52
retransmit: 2
timeout: 20
source_interface: Eth1/2
vrf: mgmt
existing_radius_server_config:
- path: "data/openconfig-interfaces:interfaces"
response:
code: 200
value:
openconfig-interfaces:interfaces:
interface:
- name: 'Eth1/1'
config:
mtu: 2000
- path: "data/openconfig-system:system/aaa/server-groups/server-group=RADIUS/config"
response:
code: 200
- path: "data/openconfig-system:system/aaa/server-groups/server-group=RADIUS/openconfig-aaa-radius-ext:radius/config"
response:
code: 200
- path: "data/openconfig-system:system/aaa/server-groups/server-group=RADIUS/servers"
response:
code: 200
expected_config_requests:
- path: "data/openconfig-system:system/aaa/server-groups/server-group=RADIUS/config"
method: "patch"
data:
openconfig-system:config:
auth-type: 'chap'
secret-key: 'chap'
timeout: 10
- path: "data/openconfig-system:system/aaa/server-groups/server-group=RADIUS/openconfig-aaa-radius-ext:radius/config"
method: "patch"
data:
openconfig-aaa-radius-ext:config:
nas-ip-address: 1.2.3.4
retransmit-attempts: 3
statistics: True
- path: "data/openconfig-system:system/aaa/server-groups/server-group=RADIUS/servers"
method: "patch"
data:
openconfig-system:servers:
server:
- address: localhost
config:
address: localhost
auth-type: mschapv2
priority: 2
vrf: mgmt
timeout: 20
radius:
config:
auth-port: 52
secret-key: local
retransmit-attempts: 2
openconfig-aaa-radius-ext:source-interface: Eth1/2

deleted_01:
module_args:
state: deleted
existing_radius_server_config:
- path: "data/openconfig-system:system/aaa/server-groups/server-group=RADIUS/config"
response:
code: 200
value:
openconfig-system:config:
auth-type: 'chap'
secret-key: 'chap'
- path: "data/openconfig-system:system/aaa/server-groups/server-group=RADIUS/openconfig-aaa-radius-ext:radius/config"
response:
code: 200
value:
openconfig-aaa-radius-ext:config:
nas-ip-address: 1.2.3.4
retransmit-attempts: 3
statistics: True
- path: "data/openconfig-system:system/aaa/server-groups/server-group=RADIUS/servers"
response:
code: 200
value:
openconfig-system:servers:
server:
- address: localhost
config:
address: localhost
auth-type: mschapv2
priority: 2
vrf: mgmt
timeout: 20
radius:
config:
auth-port: 52
secret-key: local
retransmit-attempts: 2
openconfig-aaa-radius-ext:source-interface: Eth1/2
expected_config_requests:
- path: "data/openconfig-system:system/aaa/server-groups/server-group=RADIUS/config/auth-type"
method: "delete"
data:
- path: "data/openconfig-system:system/aaa/server-groups/server-group=RADIUS/config/secret-key"
method: "delete"
data:
- path: "data/openconfig-system:system/aaa/server-groups/server-group=RADIUS/openconfig-aaa-radius-ext:radius/config/nas-ip-address"
method: "delete"
data:
- path: "data/openconfig-system:system/aaa/server-groups/server-group=RADIUS/openconfig-aaa-radius-ext:radius/config/retransmit-attempts"
method: "delete"
data:
- path: "data/openconfig-system:system/aaa/server-groups/server-group=RADIUS/openconfig-aaa-radius-ext:radius/config/statistics"
method: "delete"
data:
- path: "data/openconfig-system:system/aaa/server-groups/server-group=RADIUS/servers/server=localhost"
method: "delete"
data:

deleted_02:
module_args:
state: deleted
config:
auth_type: chap
key: chap
nas_ip: 1.2.3.4
statistics: true
timeout: 10
retransmit: 3
servers:
host:
- name: localhost
auth_type: mschapv2
key: local
priority: 2
port: 52
retransmit: 2
timeout: 20
source_interface: Eth1/2
vrf: mgmt
existing_radius_server_config:
- path: "data/openconfig-system:system/aaa/server-groups/server-group=RADIUS/config"
response:
code: 200
value:
openconfig-system:config:
auth-type: 'chap'
secret-key: 'chap'
- path: "data/openconfig-system:system/aaa/server-groups/server-group=RADIUS/openconfig-aaa-radius-ext:radius/config"
response:
code: 200
value:
openconfig-aaa-radius-ext:config:
nas-ip-address: 1.2.3.4
retransmit-attempts: 3
statistics: True
- path: "data/openconfig-system:system/aaa/server-groups/server-group=RADIUS/servers"
response:
code: 200
value:
openconfig-system:servers:
server:
- address: localhost
config:
address: localhost
auth-type: mschapv2
priority: 2
vrf: mgmt
timeout: 20
radius:
config:
auth-port: 52
secret-key: local
retransmit-attempts: 2
openconfig-aaa-radius-ext:source-interface: Eth1/2
expected_config_requests:
- path: "data/openconfig-system:system/aaa/server-groups/server-group=RADIUS/config/auth-type"
method: "delete"
data:
- path: "data/openconfig-system:system/aaa/server-groups/server-group=RADIUS/config/secret-key"
method: "delete"
data:
- path: "data/openconfig-system:system/aaa/server-groups/server-group=RADIUS/openconfig-aaa-radius-ext:radius/config/nas-ip-address"
method: "delete"
data:
- path: "data/openconfig-system:system/aaa/server-groups/server-group=RADIUS/openconfig-aaa-radius-ext:radius/config/retransmit-attempts"
method: "delete"
data:
- path: "data/openconfig-system:system/aaa/server-groups/server-group=RADIUS/openconfig-aaa-radius-ext:radius/config/statistics"
method: "delete"
data:
- path: "data/openconfig-system:system/aaa/server-groups/server-group=RADIUS/servers/server=localhost"
method: "delete"
data:
69 changes: 69 additions & 0 deletions tests/unit/modules/network/sonic/test_sonic_radius_server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
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_radius_server,
)
from ansible_collections.dellemc.enterprise_sonic.tests.unit.modules.utils import (
set_module_args,
)
from .sonic_module import TestSonicModule


class TestSonicInterfacesModule(TestSonicModule):
module = sonic_radius_server

@classmethod
def setUpClass(cls):
cls.mock_facts_edit_config = patch(
"ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.facts.radius_server.radius_server.edit_config"
)
cls.mock_config_edit_config = patch(
"ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.config.radius_server.radius_server.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_radius_server.yaml')

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

self.facts_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_config_edit_config.stop()
self.mock_get_interface_naming_mode.stop()

def test_sonic_radius_server_merged_01(self):
set_module_args(self.fixture_data['merged_01']['module_args'])
self.initialize_facts_get_requests(self.fixture_data['merged_01']['existing_radius_server_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_radius_server_deleted_01(self):
set_module_args(self.fixture_data['deleted_01']['module_args'])
self.initialize_facts_get_requests(self.fixture_data['deleted_01']['existing_radius_server_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_radius_server_deleted_02(self):
set_module_args(self.fixture_data['deleted_02']['module_args'])
self.initialize_facts_get_requests(self.fixture_data['deleted_02']['existing_radius_server_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 8e197b1

Please sign in to comment.