1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00
community.general/test/units/modules/network/onyx/test_onyx_ptp.py
anasbadaha dea9e9b4c8 Adding new module for supporting PTP Global Protocol (#47501)
Signed-off-by: Anas Badaha <anasb@mellanox.com>
2018-11-01 14:16:30 +05:30

138 lines
5.1 KiB
Python

#
# (c) 2016 Red Hat Inc.
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
# 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_ptp_global
from units.modules.utils import set_module_args
from .onyx_module import TestOnyxModule, load_fixture
class TestOnyxPtpModule(TestOnyxModule):
module = onyx_ptp_global
def setUp(self):
self._ptp_enabled = True
self._ntp_enabled = True
super(TestOnyxPtpModule, self).setUp()
self.mock_get_ptp_config = patch.object(onyx_ptp_global.OnyxPtpGlobalModule, "_show_ptp_config")
self.get_ptp_config = self.mock_get_ptp_config.start()
self.mock_get_ntp_config = patch.object(onyx_ptp_global.OnyxPtpGlobalModule, "_show_ntp_config")
self.get_ntp_config = self.mock_get_ntp_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(TestOnyxPtpModule, self).tearDown()
self.mock_get_ptp_config.stop()
self.mock_get_ntp_config.stop()
self.mock_load_config.stop()
def load_fixtures(self, commands=None, transport='cli'):
if self._ptp_enabled:
config_file = 'onyx_show_ptp_clock.cfg'
self.get_ptp_config.return_value = load_fixture(config_file)
else:
self.get_ptp_config.return_value = None
config_file = 'onyx_show_ntp_configured.cfg'
ret_val = load_fixture(config_file)
if self._ntp_enabled:
ret_val[0]['NTP enabled'] = 'yes'
self.get_ntp_config.return_value = ret_val
self.load_config.return_value = None
def test_ptp_enabled_no_change(self):
set_module_args(dict(ptp_state='enabled'))
self.execute_module(changed=False)
def test_ptp_enabled_with_change(self):
self._ptp_enabled = False
set_module_args(dict(ptp_state='enabled'))
commands = ['protocol ptp']
self.execute_module(changed=True, commands=commands)
def test_ptp_disabled_no_change(self):
self._ptp_enabled = False
set_module_args(dict(ptp_state='disabled'))
self.execute_module(changed=False)
def test_ptp_disabled_with_change(self):
set_module_args(dict(ptp_state='disabled'))
commands = ['no protocol ptp']
self.execute_module(changed=True, commands=commands)
def test_ntp_enabled_no_change(self):
self._ptp_enabled = False
set_module_args(dict(ntp_state='enabled',
ptp_state='disabled'))
self.execute_module(changed=False)
def test_ntp_enabled_with_change(self):
self._ptp_enabled = False
self._ntp_enabled = False
set_module_args(dict(ntp_state='enabled',
ptp_state='disabled'))
commands = ['ntp enable']
self.execute_module(changed=True, commands=commands)
def test_ntp_disabled_no_change(self):
self._ntp_enabled = False
set_module_args(dict(ntp_state='disabled'))
self.execute_module(changed=False)
def test_ntp_disabled_with_change(self):
set_module_args(dict(ntp_state='disabled'))
commands = ['no ntp enable']
self.execute_module(changed=True, commands=commands)
def test_set_domain_no_change(self):
self._ntp_enabled = False
set_module_args(dict(ntp_state='disabled',
domain=127))
self.execute_module(changed=False)
def test_set_domain_with_change(self):
set_module_args(dict(domain=100))
commands = ['ptp domain 100']
self.execute_module(changed=True, commands=commands)
def test_set_primary_priority_no_change(self):
set_module_args(dict(primary_priority=128))
self.execute_module(changed=False)
def test_set_primary_priority_with_change(self):
set_module_args(dict(primary_priority=250))
commands = ['ptp priority1 250']
self.execute_module(changed=True, commands=commands)
def test_set_secondary_priority_no_change(self):
set_module_args(dict(secondary_priority=128))
self.execute_module(changed=False)
def test_set_secondary_priority_with_change(self):
set_module_args(dict(secondary_priority=190))
commands = ['ptp priority2 190']
self.execute_module(changed=True, commands=commands)