mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Pluribus Networks point feature cpu mgmt class module with UT's (#51427)
This commit is contained in:
parent
52cab33e4e
commit
5fa2d29c9a
2 changed files with 191 additions and 0 deletions
142
lib/ansible/modules/network/netvisor/pn_cpu_mgmt_class.py
Normal file
142
lib/ansible/modules/network/netvisor/pn_cpu_mgmt_class.py
Normal file
|
@ -0,0 +1,142 @@
|
|||
#!/usr/bin/python
|
||||
# Copyright: (c) 2018, Pluribus Networks
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
from __future__ import absolute_import, division, print_function
|
||||
__metaclass__ = type
|
||||
|
||||
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
||||
'status': ['preview'],
|
||||
'supported_by': 'community'}
|
||||
|
||||
|
||||
DOCUMENTATION = """
|
||||
---
|
||||
module: pn_cpu_mgmt_class
|
||||
author: "Pluribus Networks (@rajaspachipulusu17)"
|
||||
version_added: 2.8
|
||||
short_description: CLI command to modify cpu-mgmt-class
|
||||
description:
|
||||
- This module can we used to update mgmt port ingress policers.
|
||||
options:
|
||||
pn_cliswitch:
|
||||
description:
|
||||
- Target switch to run the CLI on.
|
||||
type: str
|
||||
required: false
|
||||
state:
|
||||
description:
|
||||
- State the action to perform. Use C(update) to modify cpu-mgmt-class.
|
||||
type: str
|
||||
required: true
|
||||
choices: ['update']
|
||||
pn_burst_size:
|
||||
description:
|
||||
- ingress traffic burst size (bytes) or default.
|
||||
required: false
|
||||
type: str
|
||||
pn_name:
|
||||
description:
|
||||
- mgmt port ingress traffic class.
|
||||
type: str
|
||||
required: false
|
||||
choices: ['arp', 'icmp', 'ssh', 'snmp', 'fabric', 'bcast', 'nfs',
|
||||
'web', 'web-ssl', 'net-api']
|
||||
pn_rate_limit:
|
||||
description:
|
||||
- ingress rate limit on mgmt port(bps) or unlimited.
|
||||
type: str
|
||||
required: false
|
||||
"""
|
||||
|
||||
EXAMPLES = """
|
||||
- name: cpu mgmt class modify ingress policers
|
||||
pn_cpu_mgmt_class:
|
||||
pn_cliswitch: "sw01"
|
||||
state: "update"
|
||||
pn_name: "icmp"
|
||||
pn_rate_limit: "10000"
|
||||
pn_burst_size: "14000"
|
||||
|
||||
- name: cpu mgmt class modify ingress policers
|
||||
pn_cpu_mgmt_class:
|
||||
pn_cliswitch: "sw01"
|
||||
state: "update"
|
||||
pn_name: "snmp"
|
||||
pn_burst_size: "8000"
|
||||
pn_rate_limit: "100000"
|
||||
|
||||
- name: cpu mgmt class modify ingress policers
|
||||
pn_cpu_mgmt_class:
|
||||
pn_cliswitch: "sw01"
|
||||
state: "update"
|
||||
pn_name: "web"
|
||||
pn_rate_limit: "10000"
|
||||
pn_burst_size: "1000"
|
||||
"""
|
||||
|
||||
RETURN = """
|
||||
command:
|
||||
description: the CLI command run on the target node.
|
||||
returned: always
|
||||
type: str
|
||||
stdout:
|
||||
description: set of responses from the cpu-mgmt-class command.
|
||||
returned: always
|
||||
type: list
|
||||
stderr:
|
||||
description: set of error responses from the cpu-mgmt-class command.
|
||||
returned: on error
|
||||
type: list
|
||||
changed:
|
||||
description: indicates whether the CLI caused changes on the target.
|
||||
returned: always
|
||||
type: bool
|
||||
"""
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.network.netvisor.pn_nvos import pn_cli, run_cli
|
||||
|
||||
|
||||
def main():
|
||||
""" This section is for arguments parsing """
|
||||
|
||||
state_map = dict(
|
||||
update='cpu-mgmt-class-modify'
|
||||
)
|
||||
|
||||
module = AnsibleModule(
|
||||
argument_spec=dict(
|
||||
pn_cliswitch=dict(required=False, type='str'),
|
||||
state=dict(required=True, type='str', choices=state_map.keys()),
|
||||
pn_burst_size=dict(required=False, type='str'),
|
||||
pn_name=dict(required=False, type='str',
|
||||
choices=['arp', 'icmp', 'ssh', 'snmp',
|
||||
'fabric', 'bcast', 'nfs', 'web',
|
||||
'web-ssl', 'net-api']),
|
||||
pn_rate_limit=dict(required=False, type='str'),
|
||||
),
|
||||
required_if=([['state', 'update', ['pn_name', 'pn_burst_size', 'pn_rate_limit']]]),
|
||||
)
|
||||
|
||||
# Accessing the arguments
|
||||
cliswitch = module.params['pn_cliswitch']
|
||||
state = module.params['state']
|
||||
burst_size = module.params['pn_burst_size']
|
||||
name = module.params['pn_name']
|
||||
rate_limit = module.params['pn_rate_limit']
|
||||
|
||||
command = state_map[state]
|
||||
|
||||
# Building the CLI command string
|
||||
cli = pn_cli(module, cliswitch)
|
||||
|
||||
if command == 'cpu-mgmt-class-modify':
|
||||
cli += ' %s name %s ' % (command, name)
|
||||
cli += ' burst-size %s rate-limit %s' % (burst_size, rate_limit)
|
||||
|
||||
run_cli(module, cli, state_map)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
|
@ -0,0 +1,49 @@
|
|||
# Copyright: (c) 2018, Pluribus Networks
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import json
|
||||
|
||||
from units.compat.mock import patch
|
||||
from ansible.modules.network.netvisor import pn_cpu_mgmt_class
|
||||
from units.modules.utils import set_module_args
|
||||
from .nvos_module import TestNvosModule, load_fixture
|
||||
|
||||
|
||||
class TestCpuMgmtClassModule(TestNvosModule):
|
||||
|
||||
module = pn_cpu_mgmt_class
|
||||
|
||||
def setUp(self):
|
||||
self.mock_run_nvos_commands = patch('ansible.modules.network.netvisor.pn_cpu_mgmt_class.run_cli')
|
||||
self.run_nvos_commands = self.mock_run_nvos_commands.start()
|
||||
|
||||
def tearDown(self):
|
||||
self.mock_run_nvos_commands.stop()
|
||||
|
||||
def run_cli_patch(self, module, cli, state_map):
|
||||
if state_map['update'] == 'cpu-mgmt-class-modify':
|
||||
results = dict(
|
||||
changed=True,
|
||||
cli_cmd=cli
|
||||
)
|
||||
module.exit_json(**results)
|
||||
|
||||
def load_fixtures(self, commands=None, state=None, transport='cli'):
|
||||
self.run_nvos_commands.side_effect = self.run_cli_patch
|
||||
|
||||
def test_cpu_mgmt_class_modify_t1(self):
|
||||
set_module_args({'pn_cliswitch': 'sw01', 'pn_name': 'icmp',
|
||||
'pn_rate_limit': '10000', 'pn_burst_size': '14000', 'state': 'update'})
|
||||
result = self.execute_module(changed=True, state='update')
|
||||
expected_cmd = '/usr/bin/cli --quiet -e --no-login-prompt switch sw01 cpu-mgmt-class-modify name icmp burst-size 14000 rate-limit 10000'
|
||||
self.assertEqual(result['cli_cmd'], expected_cmd)
|
||||
|
||||
def test_cpu_mgmt_class_modify_t2(self):
|
||||
set_module_args({'pn_cliswitch': 'sw01', 'pn_name': 'ssh',
|
||||
'pn_rate_limit': '10000', 'pn_burst_size': '100000', 'state': 'update'})
|
||||
result = self.execute_module(changed=True, state='update')
|
||||
expected_cmd = '/usr/bin/cli --quiet -e --no-login-prompt switch sw01 cpu-mgmt-class-modify name ssh burst-size 100000 rate-limit 10000'
|
||||
self.assertEqual(result['cli_cmd'], expected_cmd)
|
Loading…
Reference in a new issue