summaryrefslogtreecommitdiff
path: root/test/units/modules/network/cnos/test_cnos_portchannel.py
blob: eb506b358b65bfff3401f0698f2d7fdec965c37b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type

import json
import os
from units.compat.mock import patch
from ansible.modules.network.cnos import cnos_portchannel
from units.modules.utils import set_module_args
from .cnos_module import TestCnosModule, load_fixture


class TestCnosPortchannelModule(TestCnosModule):

    module = cnos_portchannel

    def setUp(self):
        super(TestCnosPortchannelModule, self).setUp()

        self.mock_run_cnos_commands = patch('ansible.module_utils.network.cnos.cnos.run_cnos_commands')
        self.run_cnos_commands = self.mock_run_cnos_commands.start()

    def tearDown(self):
        super(TestCnosPortchannelModule, self).tearDown()
        self.mock_run_cnos_commands.stop()

    def load_fixtures(self, commands=None, transport='cli'):
        self.run_cnos_commands.return_value = [load_fixture('cnos_portchannel_config.cfg')]

    def test_portchannel_channelgroup(self):
        set_module_args({'username': 'admin', 'password': 'pass',
                         'host': '10.241.107.39', 'deviceType': 'g8272_cnos',
                         'outputfile': self.test_log, 'interfaceRange': '33',
                         'interfaceArg1': 'channel-group', 'interfaceArg2': '33', 'interfaceArg3': 'on'})
        result = self.execute_module(changed=True)
        expected_result = 'Port Channel Configuration is done'
        self.assertEqual(result['msg'], expected_result)

    def test_cnos_portchannel_lacp(self):
        set_module_args({'username': 'admin', 'password': 'pass',
                         'host': '10.241.107.39', 'deviceType': 'g8272_cnos',
                         'outputfile': self.test_log, 'interfaceRange': '33',
                         'interfaceArg1': 'lacp', 'interfaceArg2': 'port-priority', 'interfaceArg3': '33'})
        result = self.execute_module(changed=True)
        expected_result = 'Port Channel Configuration is done'
        self.assertEqual(result['msg'], expected_result)

    def test_cnos_portchannel_duplex(self):
        set_module_args({'username': 'admin', 'password': 'pass',
                         'host': '10.241.107.39', 'deviceType': 'g8272_cnos',
                         'outputfile': self.test_log, 'interfaceRange': '2',
                         'interfaceArg1': 'duplex', 'interfaceArg2': 'auto'})
        result = self.execute_module(changed=True)
        expected_result = 'Port Channel Configuration is done'
        self.assertEqual(result['msg'], expected_result)

    def test_cnos_portchannel_mtu(self):
        set_module_args({'username': 'admin', 'password': 'pass',
                         'host': '10.241.107.39', 'deviceType': 'g8272_cnos',
                         'outputfile': self.test_log, 'interfaceRange': '33',
                         'interfaceArg1': 'mtu', 'interfaceArg2': '1300'})
        result = self.execute_module(changed=True)
        expected_result = 'Port Channel Configuration is done'
        self.assertEqual(result['msg'], expected_result)

    def test_cnos_portchannel_spanningtree(self):
        set_module_args({'username': 'admin', 'password': 'pass',
                         'host': '10.241.107.39', 'deviceType': 'g8272_cnos',
                         'outputfile': self.test_log, 'interfaceRange': '33',
                         'interfaceArg1': 'spanning-tree', 'interfaceArg2': 'mst',
                         'interfaceArg3': '33-35', 'interfaceArg4': 'cost',
                         'interfaceArg5': '33'})
        result = self.execute_module(changed=True)
        expected_result = 'Port Channel Configuration is done'
        self.assertEqual(result['msg'], expected_result)

    def test_cnos_portchannel_ip(self):
        set_module_args({'username': 'admin', 'password': 'pass',
                         'host': '10.241.107.39', 'deviceType': 'g8272_cnos',
                         'outputfile': self.test_log, 'interfaceRange': '33',
                         'interfaceArg1': 'ip', 'interfaceArg2': 'port',
                         'interfaceArg3': 'anil'})
        result = self.execute_module(changed=True)
        expected_result = 'Port Channel Configuration is done'
        self.assertEqual(result['msg'], expected_result)