summaryrefslogtreecommitdiff
path: root/test/units/modules/network/onyx/test_onyx_magp.py
blob: 8a5146b6b8652e5b677621bab7c5ae3da182bc19 (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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#
# Copyright: Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

# Make coding more python3-ish
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type

from units.compat.mock import patch
from ansible.modules.network.onyx import onyx_magp
from units.modules.utils import set_module_args
from .onyx_module import TestOnyxModule, load_fixture


class TestOnyxMagpModule(TestOnyxModule):

    module = onyx_magp

    def setUp(self):
        super(TestOnyxMagpModule, self).setUp()
        self.mock_get_config = patch.object(
            onyx_magp.OnyxMagpModule,
            "_get_magp_config")
        self.get_config = self.mock_get_config.start()

        self.mock_load_config = patch(
            'ansible.module_utils.network.onyx.onyx.load_config')
        self.load_config = self.mock_load_config.start()

    def tearDown(self):
        super(TestOnyxMagpModule, self).tearDown()
        self.mock_get_config.stop()
        self.mock_load_config.stop()

    def load_fixtures(self, commands=None, transport='cli'):
        config_file = 'onyx_magp_show.cfg'
        self.get_config.return_value = load_fixture(config_file)
        self.load_config.return_value = None

    def test_magp_absent_no_change(self):
        set_module_args(dict(interface='Vlan 1002', magp_id=110,
                             state='absent'))
        self.execute_module(changed=False)

    def test_magp_no_change(self):
        set_module_args(dict(interface='Vlan 1200', magp_id=103,
                             state='disabled'))
        self.execute_module(changed=False)

    def test_magp_present_no_change(self):
        set_module_args(dict(interface='Vlan 1200', magp_id=103))
        self.execute_module(changed=False)

    def test_magp_enable(self):
        set_module_args(dict(interface='Vlan 1200', magp_id=103,
                             state='enabled'))
        commands = ['interface vlan 1200 magp 103 no shutdown']
        self.execute_module(changed=True, commands=commands)

    def test_magp_disable(self):
        set_module_args(dict(interface='Vlan 1243', magp_id=102,
                             state='disabled', router_ip='10.0.0.43',
                             router_mac='01:02:03:04:05:06'))
        commands = ['interface vlan 1243 magp 102 shutdown']
        self.execute_module(changed=True, commands=commands)

    def test_magp_change_address(self):
        set_module_args(dict(interface='Vlan 1243', magp_id=102,
                             router_ip='10.0.0.44',
                             router_mac='01:02:03:04:05:07'))
        commands = [
            'interface vlan 1243 magp 102 ip virtual-router address 10.0.0.44',
            'interface vlan 1243 magp 102 ip virtual-router mac-address 01:02:03:04:05:07']
        self.execute_module(changed=True, commands=commands)

    def test_magp_remove_address(self):
        set_module_args(dict(interface='Vlan 1243', magp_id=102))
        commands = [
            'interface vlan 1243 magp 102 no ip virtual-router address',
            'interface vlan 1243 magp 102 no ip virtual-router mac-address']
        self.execute_module(changed=True, commands=commands)

    def test_magp_add(self):
        set_module_args(dict(interface='Vlan 1244', magp_id=104,
                             router_ip='10.0.0.44',
                             router_mac='01:02:03:04:05:07'))
        commands = [
            'interface vlan 1244 magp 104',
            'exit',
            'interface vlan 1244 magp 104 ip virtual-router address 10.0.0.44',
            'interface vlan 1244 magp 104 ip virtual-router mac-address 01:02:03:04:05:07']
        self.execute_module(changed=True, commands=commands, sort=False)

    def test_magp_change_vlan(self):
        set_module_args(dict(interface='Vlan 1244', magp_id=102,
                             router_ip='10.0.0.43',
                             router_mac='01:02:03:04:05:06'))
        commands = [
            'interface vlan 1243 no magp 102',
            'interface vlan 1244 magp 102',
            'exit',
            'interface vlan 1244 magp 102 ip virtual-router address 10.0.0.43',
            'interface vlan 1244 magp 102 ip virtual-router mac-address 01:02:03:04:05:06']
        self.execute_module(changed=True, commands=commands)