2017-05-03 19:06:23 +02:00
|
|
|
# (c) 2017 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
|
|
|
|
|
2018-10-13 05:01:14 +02:00
|
|
|
from units.compat.mock import patch, MagicMock
|
2017-11-17 18:17:07 +01:00
|
|
|
from units.modules.utils import set_module_args
|
|
|
|
from .junos_module import TestJunosModule
|
2017-05-03 19:06:23 +02:00
|
|
|
|
2019-10-24 21:01:05 +02:00
|
|
|
jnpr_mock = MagicMock()
|
2017-05-03 19:06:23 +02:00
|
|
|
modules = {
|
|
|
|
'jnpr': jnpr_mock,
|
|
|
|
'jnpr.junos': jnpr_mock.junos,
|
|
|
|
'jnpr.junos.utils': jnpr_mock.junos.utils,
|
|
|
|
'jnpr.junos.utils.sw': jnpr_mock.junos.utils.sw,
|
|
|
|
}
|
|
|
|
module_patcher = patch.dict('sys.modules', modules)
|
|
|
|
module_patcher.start()
|
|
|
|
|
|
|
|
from ansible.modules.network.junos import junos_package
|
|
|
|
|
|
|
|
|
2019-10-24 21:01:05 +02:00
|
|
|
class TestJunosPackageModule(TestJunosModule):
|
2017-05-03 19:06:23 +02:00
|
|
|
|
|
|
|
module = junos_package
|
|
|
|
|
2019-10-15 21:53:51 +02:00
|
|
|
def setUp(self):
|
2019-10-24 21:01:05 +02:00
|
|
|
super(TestJunosPackageModule, self).setUp()
|
|
|
|
self.mock_get_device = patch('ansible.modules.network.junos.junos_package.get_device')
|
|
|
|
self.get_device = self.mock_get_device.start()
|
2019-10-15 21:53:51 +02:00
|
|
|
|
|
|
|
def tearDown(self):
|
2019-10-24 21:01:05 +02:00
|
|
|
super(TestJunosPackageModule, self).tearDown()
|
|
|
|
self.mock_get_device.stop()
|
2019-10-15 21:53:51 +02:00
|
|
|
|
2017-05-03 19:06:23 +02:00
|
|
|
def test_junos_package_src(self):
|
|
|
|
set_module_args(dict(src='junos-vsrx-12.1X46-D10.2-domestic.tgz'))
|
2019-10-24 21:01:05 +02:00
|
|
|
self.execute_module(changed=True)
|
|
|
|
|
|
|
|
args, _kwargs = jnpr_mock.junos.utils.sw.SW().install.call_args
|
|
|
|
self.assertEqual(args, ('junos-vsrx-12.1X46-D10.2-domestic.tgz',))
|
2017-05-03 19:06:23 +02:00
|
|
|
|
|
|
|
def test_junos_package_src_fail(self):
|
|
|
|
jnpr_mock.junos.utils.sw.SW().install.return_value = 0
|
|
|
|
set_module_args(dict(src='junos-vsrx-12.1X46-D10.2-domestic.tgz'))
|
|
|
|
result = self.execute_module(changed=True, failed=True)
|
2019-10-24 21:01:05 +02:00
|
|
|
|
2017-05-03 19:06:23 +02:00
|
|
|
self.assertEqual(result['msg'], 'Unable to install package on device')
|
|
|
|
|
|
|
|
def test_junos_package_src_no_copy(self):
|
|
|
|
jnpr_mock.junos.utils.sw.SW().install.return_value = 1
|
|
|
|
set_module_args(dict(src='junos-vsrx-12.1X46-D10.2-domestic.tgz', no_copy=True))
|
|
|
|
self.execute_module(changed=True)
|
|
|
|
|
2019-10-24 21:01:05 +02:00
|
|
|
args, kwargs = jnpr_mock.junos.utils.sw.SW().install.call_args
|
|
|
|
self.assertEqual(args, ('junos-vsrx-12.1X46-D10.2-domestic.tgz',))
|
|
|
|
self.assertEqual(kwargs['no_copy'], True)
|