summaryrefslogtreecommitdiff
path: root/test/units/modules/network/onyx/test_onyx_lldp_interface.py
blob: 4cbf9f4bbc6ab66e984aabf20560950e7e892914 (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
#
# 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 ansible.compat.tests.mock import patch
from ansible.modules.network.onyx import onyx_lldp_interface
from units.modules.utils import set_module_args
from .onyx_module import TestOnyxModule, load_fixture


class TestOnyxLldpInterfaceModule(TestOnyxModule):

    module = onyx_lldp_interface

    def setUp(self):
        super(TestOnyxLldpInterfaceModule, self).setUp()
        self.mock_get_config = patch.object(
            onyx_lldp_interface.OnyxLldpInterfaceModule,
            "_get_lldp_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(TestOnyxLldpInterfaceModule, self).tearDown()
        self.mock_get_config.stop()
        self.mock_load_config.stop()

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

    def test_lldp_no_change(self):
        set_module_args(dict(name='Eth1/1', state='present'))
        self.execute_module(changed=False)

    def test_no_lldp_no_change(self):
        set_module_args(dict(name='Eth1/2', state='absent'))
        self.execute_module(changed=False)

    def test_no_lldp_change(self):
        set_module_args(dict(name='Eth1/2', state='present'))
        commands = ['interface ethernet 1/2 lldp receive',
                    'interface ethernet 1/2 lldp transmit']
        self.execute_module(changed=True, commands=commands)

    def test_lldp_change(self):
        set_module_args(dict(name='Eth1/1', state='absent'))
        commands = ['interface ethernet 1/1 no lldp receive',
                    'interface ethernet 1/1 no lldp transmit']
        self.execute_module(changed=True, commands=commands)

    def test_lldp_aggregate(self):
        aggregate = [dict(name='Eth1/1'), dict(name='Eth1/2')]
        set_module_args(dict(aggregate=aggregate, state='present'))
        commands = ['interface ethernet 1/2 lldp receive',
                    'interface ethernet 1/2 lldp transmit']
        self.execute_module(changed=True, commands=commands)

    def test_lldp_aggregate_purge(self):
        aggregate = [dict(name='Eth1/3'), dict(name='Eth1/2')]
        set_module_args(dict(aggregate=aggregate, state='present', purge=True))
        commands = ['interface ethernet 1/2 lldp receive',
                    'interface ethernet 1/2 lldp transmit',
                    'interface ethernet 1/3 lldp receive',
                    'interface ethernet 1/3 lldp transmit',
                    'interface ethernet 1/1 no lldp receive',
                    'interface ethernet 1/1 no lldp transmit']
        self.execute_module(changed=True, commands=commands)