diff options
Diffstat (limited to 'test/units')
29 files changed, 0 insertions, 1597 deletions
diff --git a/test/units/modules/network/junos/fixtures/get_configuration_rpc_reply.txt b/test/units/modules/network/junos/fixtures/get_configuration_rpc_reply.txt deleted file mode 100644 index 1d5b239905..0000000000 --- a/test/units/modules/network/junos/fixtures/get_configuration_rpc_reply.txt +++ /dev/null @@ -1,7 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?><rpc-reply message-id="urn:uuid:72c481b8"> - <configuration-set> - set version 15.1X49-D15.4 - set system host-name vsrx01 - set system domain-name ansible.com - </configuration-set> -</rpc-reply>
\ No newline at end of file diff --git a/test/units/modules/network/junos/fixtures/get_configuration_rpc_reply_diff.txt b/test/units/modules/network/junos/fixtures/get_configuration_rpc_reply_diff.txt deleted file mode 100644 index c2b803f828..0000000000 --- a/test/units/modules/network/junos/fixtures/get_configuration_rpc_reply_diff.txt +++ /dev/null @@ -1,12 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?><rpc-reply message-id="urn:uuid:6fcc8e22"> -<configuration-information> -<configuration-output> -[edit interfaces] -+ ae11 { -+ unit 0 { -+ description Test; -+ } -+ } -</configuration-output> -</configuration-information> -</rpc-reply> diff --git a/test/units/modules/network/junos/fixtures/get_configuration_rpc_reply_json.txt b/test/units/modules/network/junos/fixtures/get_configuration_rpc_reply_json.txt deleted file mode 100644 index a1d7345a32..0000000000 --- a/test/units/modules/network/junos/fixtures/get_configuration_rpc_reply_json.txt +++ /dev/null @@ -1,190 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?><rpc-reply message-id="urn:uuid:72c481b8"> -{ - "configuration" : [ - { - "system" : [ - { - "host-name" : [ - { - "data" : "vsrx01" - } - ], - "domain-name" : [ - { - "data" : "junos.com" - } - ], - "name-server" : [ - { - "name" : - { - "data" : "172.26.1.1" - } - }, - { - "name" : - { - "data" : "8.8.8.8" - } - } - ], - "services" : [ - { - "ssh" : [ - { - } - ], - "telnet" : [ - { - } - ], - "netconf" : [ - { - "ssh" : [ - { - "port" : [ - { - "data" : "830" - } - ] - } - ], - "traceoptions" : [ - { - "file" : [ - { - "filename" : [ - { - "data" : "netconf-ops.log" - } - ] - } - ], - "flag" : [ - { - "name" : - { - "data" : "all" - } - } - ] - } - ] - } - ], - "web-management" : [ - { - "http" : [ - { - "interface" : [ - { - "data" : "fxp0.0" - } - ] - } - ] - } - ] - } - ], - "syslog" : [ - { - "user" : [ - { - "name" : - { - "data" : "*" - }, - "contents" : [ - { - "name" : - { - "data" : "any" - }, - "emergency" : [ - { - "data" : null - } - ] - } - ] - } - ], - "file" : [ - { - "name" : - { - "data" : "messages" - }, - "contents" : [ - { - "name" : - { - "data" : "any" - }, - "any" : [ - { - "data" : null - } - ] - }, - { - "name" : - { - "data" : "authorization" - }, - "info" : [ - { - "data" : null - } - ] - } - ] - }, - { - "name" : - { - "data" : "interactive-commands" - }, - "contents" : [ - { - "name" : - { - "data" : "interactive-commands" - }, - "any" : [ - { - "data" : null - } - ] - } - ] - }, - { - "name" : - { - "data" : "test1" - }, - "contents" : [ - { - "name" : - { - "data" : "any" - }, - "any" : [ - { - "data" : null - } - ] - } - ] - } - ] - } - ] - } - ] - } - ] -} -</rpc-reply> diff --git a/test/units/modules/network/junos/fixtures/junos_config.json b/test/units/modules/network/junos/fixtures/junos_config.json deleted file mode 100644 index 46fb623dda..0000000000 --- a/test/units/modules/network/junos/fixtures/junos_config.json +++ /dev/null @@ -1,28 +0,0 @@ - -{ - "interfaces" : [ - { - "interface" : [ - { - "name" : - { - "data" : "ae11" - }, - "unit" : [ - { - "name" : - { - "data" : "0" - }, - "description" : [ - { - "data" : "Test" - } - ] - } - ] - } - ] - } - ] -} diff --git a/test/units/modules/network/junos/fixtures/junos_config.set b/test/units/modules/network/junos/fixtures/junos_config.set deleted file mode 100644 index c822fdb4be..0000000000 --- a/test/units/modules/network/junos/fixtures/junos_config.set +++ /dev/null @@ -1,2 +0,0 @@ -delete interfaces ae11 -set interfaces ae11 unit 0 description Test
\ No newline at end of file diff --git a/test/units/modules/network/junos/fixtures/junos_config.text b/test/units/modules/network/junos/fixtures/junos_config.text deleted file mode 100644 index b3d61b993a..0000000000 --- a/test/units/modules/network/junos/fixtures/junos_config.text +++ /dev/null @@ -1,8 +0,0 @@ - -interfaces { - ae11 { - unit 0 { - description Test - } - } - }
\ No newline at end of file diff --git a/test/units/modules/network/junos/fixtures/junos_config.xml b/test/units/modules/network/junos/fixtures/junos_config.xml deleted file mode 100644 index a0e8fe1b75..0000000000 --- a/test/units/modules/network/junos/fixtures/junos_config.xml +++ /dev/null @@ -1,9 +0,0 @@ -<interfaces> - <interface> - <name>ae11</name> - <unit> - <name>0</name> - <description>Test</description> - </unit> - </interface> -</interfaces> diff --git a/test/units/modules/network/junos/fixtures/junos_ping_ping_10.10.10.10_count_2 b/test/units/modules/network/junos/fixtures/junos_ping_ping_10.10.10.10_count_2 deleted file mode 100644 index 9fcc94a6c3..0000000000 --- a/test/units/modules/network/junos/fixtures/junos_ping_ping_10.10.10.10_count_2 +++ /dev/null @@ -1,7 +0,0 @@ -PING 10.10.10.10 (10.10.10.10): 56 data bytes -64 bytes from 10.10.10.10: icmp_seq=0 ttl=64 time=18.041 ms -64 bytes from 10.10.10.10: icmp_seq=1 ttl=64 time=15.710 ms - ---- 10.10.10.10 ping statistics --- -2 packets transmitted, 2 packets received, 0% packet loss -round-trip min/avg/max/stddev = 15.710/16.876/18.041/1.165 ms diff --git a/test/units/modules/network/junos/fixtures/junos_ping_ping_10.10.10.11_count_5_size_512_interval_2 b/test/units/modules/network/junos/fixtures/junos_ping_ping_10.10.10.11_count_5_size_512_interval_2 deleted file mode 100644 index 68d44d7f57..0000000000 --- a/test/units/modules/network/junos/fixtures/junos_ping_ping_10.10.10.11_count_5_size_512_interval_2 +++ /dev/null @@ -1,11 +0,0 @@ -PING 10.10.10.11 (10.10.10.11): 56 data bytes -64 bytes from 10.10.10.11: icmp_seq=0 ttl=64 time=18.041 ms -64 bytes from 10.10.10.11: icmp_seq=1 ttl=64 time=15.710 ms -64 bytes from 10.10.10.11: icmp_seq=0 ttl=64 time=16.051 ms -64 bytes from 10.10.10.11: icmp_seq=0 ttl=64 time=17.024 ms -64 bytes from 10.10.10.11: icmp_seq=0 ttl=64 time=20.090 ms - - ---- 10.10.10.11 ping statistics --- -5 packets transmitted, 5 packets received, 0% packet loss -round-trip min/avg/max/stddev = 18.710/17.876/20.041/2.165 ms diff --git a/test/units/modules/network/junos/fixtures/junos_ping_ping_10.10.10.20_count_4 b/test/units/modules/network/junos/fixtures/junos_ping_ping_10.10.10.20_count_4 deleted file mode 100644 index 70cff3bc96..0000000000 --- a/test/units/modules/network/junos/fixtures/junos_ping_ping_10.10.10.20_count_4 +++ /dev/null @@ -1,4 +0,0 @@ -PING 10.10.10.20 (10.10.10.20): 56 data bytes - ---- 10.10.10.20 ping statistics --- -4 packets transmitted, 0 packets received, 100% packet loss diff --git a/test/units/modules/network/junos/fixtures/load_configuration_xml.txt b/test/units/modules/network/junos/fixtures/load_configuration_xml.txt deleted file mode 100644 index 72ba03fccf..0000000000 --- a/test/units/modules/network/junos/fixtures/load_configuration_xml.txt +++ /dev/null @@ -1,6 +0,0 @@ -<rpc-reply> - <load-configuration-results> - <load-success/> - <load-error-count>0</load-error-count> - </load-configuration-results> -</rpc-reply> diff --git a/test/units/modules/network/junos/fixtures/show_chassis_hardware_xml.txt b/test/units/modules/network/junos/fixtures/show_chassis_hardware_xml.txt deleted file mode 100644 index a0853b8cfa..0000000000 --- a/test/units/modules/network/junos/fixtures/show_chassis_hardware_xml.txt +++ /dev/null @@ -1,26 +0,0 @@ -<rpc-reply> - <chassis-inventory> - <chassis> - <name>Chassis</name> - <serial-number>adc382ed18b0</serial-number> - <description>VSRX</description> - <chassis-module> - <name>Midplane</name> - </chassis-module> - <chassis-module> - <name>System IO</name> - </chassis-module> - <chassis-module> - <name>Routing Engine</name> - <description>VSRX RE</description> - </chassis-module> - <chassis-module> - <name>FPC 0</name> - <description>Virtual FPC</description> - </chassis-module> - <chassis-module> - <name>Power Supply 0</name> - </chassis-module> - </chassis> - </chassis-inventory> -</rpc-reply> diff --git a/test/units/modules/network/junos/fixtures/show_chassis_routing-engine_xml.txt b/test/units/modules/network/junos/fixtures/show_chassis_routing-engine_xml.txt deleted file mode 100644 index ccdcaca2e5..0000000000 --- a/test/units/modules/network/junos/fixtures/show_chassis_routing-engine_xml.txt +++ /dev/null @@ -1,52 +0,0 @@ -<rpc-reply> - <route-engine-information> - <route-engine> - <slot>0</slot> - <mastership-state>master</mastership-state> - <mastership-priority>master (default)</mastership-priority> - <status>OK</status> - <temperature>30 degrees C / 86 degrees F</temperature> - <cpu-temperature>27 degrees C / 80 degrees F</cpu-temperature> - <memory-dram-size>16349 MB</memory-dram-size> - <memory-installed-size>(16384 MB installed)</memory-installed-size> - <memory-buffer-utilization>16</memory-buffer-utilization> - <cpu-user>3</cpu-user> - <cpu-background>0</cpu-background> - <cpu-system>5</cpu-system> - <cpu-interrupt>1</cpu-interrupt> - <cpu-idle>92</cpu-idle> - <model>RE-S-EX9200-1800X4</model> - <serial-number>0123456789</serial-number> - <start-time>2017-04-27 12:25:03 PDT</start-time> - <up-time>139 days, 3 hours, 12 minutes, 35 seconds</up-time> - <last-reboot-reason>Router rebooted after a normal shutdown.</last-reboot-reason> - <load-average-one>0.03</load-average-one> - <load-average-five>0.06</load-average-five> - <load-average-fifteen>0.02</load-average-fifteen> - </route-engine> - <route-engine> - <slot>1</slot> - <mastership-state>backup</mastership-state> - <mastership-priority>backup (default)</mastership-priority> - <status>OK</status> - <temperature>30 degrees C / 86 degrees F</temperature> - <cpu-temperature>27 degrees C / 80 degrees F</cpu-temperature> - <memory-dram-size>16349 MB</memory-dram-size> - <memory-installed-size>(16384 MB installed)</memory-installed-size> - <memory-buffer-utilization>10</memory-buffer-utilization> - <cpu-user>0</cpu-user> - <cpu-background>0</cpu-background> - <cpu-system>0</cpu-system> - <cpu-interrupt>0</cpu-interrupt> - <cpu-idle>100</cpu-idle> - <model>RE-S-EX9200-1800X4</model> - <serial-number>0123456789</serial-number> - <start-time>2017-09-13 10:24:59 PDT</start-time> - <up-time>5 hours, 12 minutes, 36 seconds</up-time> - <last-reboot-reason>Router rebooted after a normal shutdown.</last-reboot-reason> - <load-average-one>0.00</load-average-one> - <load-average-five>0.00</load-average-five> - <load-average-fifteen>0.00</load-average-fifteen> - </route-engine> - </route-engine-information> -</rpc-reply> diff --git a/test/units/modules/network/junos/fixtures/show_interfaces_details_xml.txt b/test/units/modules/network/junos/fixtures/show_interfaces_details_xml.txt deleted file mode 100644 index 5ba581bfd9..0000000000 --- a/test/units/modules/network/junos/fixtures/show_interfaces_details_xml.txt +++ /dev/null @@ -1,25 +0,0 @@ -<rpc-reply> - <interface-information> - <physical-interface> - <name>em0</name> - <admin-status>up</admin-status> - <oper-status>up</oper-status> - <local-index>8</local-index> - <snmp-index>17</snmp-index> - <generation>1</generation> - <if-type>Ethernet</if-type> - <link-level-type>Ethernet</link-level-type> - <mtu>1514</mtu> - <speed>1000mbps</speed> - <clocking>Unspecified</clocking> - <physical-information>Unspecified</physical-information> - <up-hold-time>0</up-hold-time> - <down-hold-time>0</down-hold-time> - <current-physical-address>52:54:00:8a:af:30</current-physical-address> - <hardware-physical-address>52:54:00:8a:af:30</hardware-physical-address> - <alternate-physical-address>Unspecified</alternate-physical-address> - <interface-flapped>Never</interface-flapped> - <statistics-cleared>Never</statistics-cleared> - </physical-interface> - </interface-information> -</rpc-reply>
\ No newline at end of file diff --git a/test/units/modules/network/junos/fixtures/show_system_memory_xml.txt b/test/units/modules/network/junos/fixtures/show_system_memory_xml.txt deleted file mode 100644 index 541b6614c6..0000000000 --- a/test/units/modules/network/junos/fixtures/show_system_memory_xml.txt +++ /dev/null @@ -1,20 +0,0 @@ -<rpc-reply> - <system-memory-information> - <system-memory-summary-information> - <system-memory-total> 983500</system-memory-total> - <system-memory-total-percent>100%</system-memory-total-percent> - <system-memory-reserved> 17844</system-memory-reserved> - <system-memory-reserved-percent> 1%</system-memory-reserved-percent> - <system-memory-wired> 67284</system-memory-wired> - <system-memory-wired-percent> 6%</system-memory-wired-percent> - <system-memory-active> 148268</system-memory-active> - <system-memory-active-percent> 15%</system-memory-active-percent> - <system-memory-inactive> 288908</system-memory-inactive> - <system-memory-inactive-percent> 29%</system-memory-inactive-percent> - <system-memory-cache> 260500</system-memory-cache> - <system-memory-cache-percent> 26%</system-memory-cache-percent> - <system-memory-free> 200684</system-memory-free> - <system-memory-free-percent> 20%</system-memory-free-percent> - </system-memory-summary-information> - </system-memory-information> -</rpc-reply>
\ No newline at end of file diff --git a/test/units/modules/network/junos/fixtures/show_system_storage_xml.txt b/test/units/modules/network/junos/fixtures/show_system_storage_xml.txt deleted file mode 100644 index ecd29ba1e6..0000000000 --- a/test/units/modules/network/junos/fixtures/show_system_storage_xml.txt +++ /dev/null @@ -1,20 +0,0 @@ -<rpc-reply> - <system-storage-information> - <filesystem> - <filesystem-name>/dev/vtbd0s1a</filesystem-name> - <total-blocks>1025132</total-blocks> - <used-blocks>583460</used-blocks> - <available-blocks>359664</available-blocks> - <used-percent> 62</used-percent> - <mounted-on>/</mounted-on> - </filesystem> - <filesystem> - <filesystem-name>devfs</filesystem-name> - <total-blocks>2</total-blocks> - <used-blocks>2</used-blocks> - <available-blocks>0</available-blocks> - <used-percent>100</used-percent> - <mounted-on>/dev</mounted-on> - </filesystem> - </system-storage-information> -</rpc-reply>
\ No newline at end of file diff --git a/test/units/modules/network/junos/fixtures/show_version_json.txt b/test/units/modules/network/junos/fixtures/show_version_json.txt deleted file mode 100644 index eacfd12d98..0000000000 --- a/test/units/modules/network/junos/fixtures/show_version_json.txt +++ /dev/null @@ -1,42 +0,0 @@ -<rpc-reply message-id="urn:uuid:aefb88cb-c296-4925-b298-ec69a6d61897"> -{ - "software-information" : [ - { - "host-name" : [ - { - "data" : "vsrx01" - } - ], - "product-model" : [ - { - "data" : "vSRX" - } - ], - "product-name" : [ - { - "data" : "vsrx" - } - ], - "junos-version" : [ - { - "data" : "15.1X49-D15.4" - } - ], - "package-information" : [ - { - "name" : [ - { - "data" : "junos" - } - ], - "comment" : [ - { - "data" : "JUNOS Software Release [15.1X49-D15.4]" - } - ] - } - ] - } - ] - } -</rpc-reply>
\ No newline at end of file diff --git a/test/units/modules/network/junos/fixtures/show_version_text.txt b/test/units/modules/network/junos/fixtures/show_version_text.txt deleted file mode 100644 index 81e0f3a8ba..0000000000 --- a/test/units/modules/network/junos/fixtures/show_version_text.txt +++ /dev/null @@ -1,8 +0,0 @@ -<rpc-reply message-id="urn:uuid:0693e4e3-4208-4912-a51e-2e509be7d2d0"> - <output> - Hostname: vsrx01 - Model: vSRX - Junos: 15.1X49-D15.4 - JUNOS Software Release [15.1X49-D15.4] - </output> - </rpc-reply>
\ No newline at end of file diff --git a/test/units/modules/network/junos/fixtures/show_version_xml.txt b/test/units/modules/network/junos/fixtures/show_version_xml.txt deleted file mode 100644 index 996c2a3595..0000000000 --- a/test/units/modules/network/junos/fixtures/show_version_xml.txt +++ /dev/null @@ -1,12 +0,0 @@ -<rpc-reply message-id="urn:uuid:b7ee75e1-e043-4284-a4d5-8e2e8028dbc7"> - <software-information> - <host-name>vsrx01</host-name> - <product-model>vSRX</product-model> - <product-name>vsrx</product-name> - <junos-version>15.1X49-D15.4</junos-version> - <package-information> - <name>junos</name> - <comment>JUNOS Software Release [15.1X49-D15.4]</comment> - </package-information> - </software-information> -</rpc-reply>
\ No newline at end of file diff --git a/test/units/modules/network/junos/junos_module.py b/test/units/modules/network/junos/junos_module.py deleted file mode 100644 index 055b40a4d4..0000000000 --- a/test/units/modules/network/junos/junos_module.py +++ /dev/null @@ -1,91 +0,0 @@ -# (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 - -import os -import json - -try: - from lxml.etree import parse -except ImportError: - from xml.etree.ElementTree import parse - -from units.modules.utils import AnsibleExitJson, AnsibleFailJson, ModuleTestCase - - -fixture_path = os.path.join(os.path.dirname(__file__), 'fixtures') -fixture_data = {} - - -def load_fixture(name, content='xml'): - path = os.path.join(fixture_path, name) - if path in fixture_data: - return fixture_data[path] - - if content == 'str': - with open(path) as f: - data = f.read() - try: - data = json.load(path) - except Exception: - pass - else: - try: - data = parse(path).getroot() - except Exception: - pass - - fixture_data[path] = data - return data - - -class TestJunosModule(ModuleTestCase): - - def execute_module(self, failed=False, changed=False, commands=None, sort=True, defaults=False, format='text'): - - self.load_fixtures(commands, format, changed=changed) - - if failed: - result = self.failed() - self.assertTrue(result['failed'], result) - else: - result = self.changed(changed) - self.assertEqual(result['changed'], changed, result) - - return result - - def failed(self): - with self.assertRaises(AnsibleFailJson) as exc: - self.module.main() - - result = exc.exception.args[0] - self.assertTrue(result['failed'], result) - return result - - def changed(self, changed=False): - with self.assertRaises(AnsibleExitJson) as exc: - self.module.main() - - result = exc.exception.args[0] - self.assertEqual(result['changed'], changed, result) - return result - - def load_fixtures(self, commands=None, format=None, changed=None): - pass diff --git a/test/units/modules/network/junos/test_junos_command.py b/test/units/modules/network/junos/test_junos_command.py deleted file mode 100644 index 3bff372c82..0000000000 --- a/test/units/modules/network/junos/test_junos_command.py +++ /dev/null @@ -1,150 +0,0 @@ -# (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 - -try: - from lxml.etree import fromstring -except ImportError: - from xml.etree.ElementTree import fromstring - -from units.compat.mock import patch -from ansible.modules.network.junos import junos_command -from units.modules.utils import set_module_args -from .junos_module import TestJunosModule, load_fixture - -RPC_CLI_MAP = { - 'get-software-information': 'show version' -} - - -class TestJunosCommandModule(TestJunosModule): - - module = junos_command - - def setUp(self): - super(TestJunosCommandModule, self).setUp() - - self.mock_conn = patch('ansible.module_utils.network.junos.junos.Connection') - self.conn = self.mock_conn.start() - - self.mock_netconf = patch('ansible.module_utils.network.junos.junos.NetconfConnection') - self.netconf_conn = self.mock_netconf.start() - - self.mock_exec_rpc = patch('ansible.modules.network.junos.junos_command.exec_rpc') - self.exec_rpc = self.mock_exec_rpc.start() - - self.mock_netconf_rpc = patch('ansible.module_utils.network.common.netconf.NetconfConnection') - self.netconf_rpc = self.mock_netconf_rpc.start() - - self.mock_get_connection = patch('ansible.modules.network.junos.junos_command.get_connection') - self.get_connection = self.mock_get_connection.start() - - self.mock_get_capabilities = patch('ansible.modules.network.junos.junos_command.get_capabilities') - self.get_capabilities = self.mock_get_capabilities.start() - self.get_capabilities.return_value = {'network_api': 'netconf'} - - def tearDown(self): - super(TestJunosCommandModule, self).tearDown() - self.mock_conn.stop() - self.mock_netconf.stop() - self.mock_get_capabilities.stop() - self.mock_netconf_rpc.stop() - self.mock_exec_rpc.stop() - self.mock_get_connection.stop() - - def load_fixtures(self, commands=None, format='text', changed=False): - def load_from_file(*args, **kwargs): - element = fromstring(args[1]) - if element.text: - path = str(element.text) - else: - path = RPC_CLI_MAP[str(element.tag)] - - filename = path.replace(' ', '_') - filename = '%s_%s.txt' % (filename, format) - return load_fixture(filename) - - self.exec_rpc.side_effect = load_from_file - - def test_junos_command_simple(self): - set_module_args(dict(commands=['show version'])) - result = self.execute_module() - self.assertEqual(len(result['stdout']), 1) - self.assertTrue(result['stdout'][0].startswith('Hostname:')) - - def test_junos_command_multiple(self): - set_module_args(dict(commands=['show version', 'show version'])) - result = self.execute_module() - self.assertEqual(len(result['stdout']), 2) - self.assertTrue(result['stdout'][0].startswith('Hostname:')) - - def test_junos_command_wait_for(self): - wait_for = 'result[0] contains "Junos:"' - set_module_args(dict(commands=['show version'], wait_for=wait_for)) - self.execute_module() - - def test_junos_command_wait_for_fails(self): - wait_for = 'result[0] contains "test string"' - set_module_args(dict(commands=['show version'], wait_for=wait_for)) - self.execute_module(failed=True) - self.assertEqual(self.exec_rpc.call_count, 10) - - def test_junos_command_retries(self): - wait_for = 'result[0] contains "test string"' - set_module_args(dict(commands=['show version'], wait_for=wait_for, retries=2)) - self.execute_module(failed=True) - self.assertEqual(self.exec_rpc.call_count, 2) - - def test_junos_command_match_any(self): - wait_for = ['result[0] contains "Junos:"', - 'result[0] contains "test string"'] - set_module_args(dict(commands=['show version'], wait_for=wait_for, match='any')) - self.execute_module() - - def test_junos_command_match_all(self): - wait_for = ['result[0] contains "Junos:"', - 'result[0] contains "JUNOS Software Release"'] - set_module_args(dict(commands=['show version'], wait_for=wait_for, match='all')) - self.execute_module() - - def test_junos_command_match_all_failure(self): - wait_for = ['result[0] contains "Junos:"', - 'result[0] contains "test string"'] - commands = ['show version', 'show version'] - set_module_args(dict(commands=commands, wait_for=wait_for, match='all')) - self.execute_module(failed=True) - - def test_junos_command_simple_json(self): - set_module_args(dict(commands=['show version'], display='json')) - result = self.execute_module(format='json') - self.assertEqual(len(result['stdout']), 1) - self.assertTrue("software-information" in result['stdout'][0]) - - def test_junos_command_simple_rpc_text(self): - set_module_args(dict(rpcs=['get-software-information'], display='text')) - result = self.execute_module(format='text') - self.assertEqual(len(result['stdout']), 1) - self.assertTrue(result['stdout'][0].startswith('Hostname:')) - - def test_junos_command_simple_rpc_json(self): - set_module_args(dict(rpcs=['get-software-information'], display='json')) - result = self.execute_module(format='json') - self.assertEqual(len(result['stdout']), 1) - self.assertTrue("software-information" in result['stdout'][0]) diff --git a/test/units/modules/network/junos/test_junos_config.py b/test/units/modules/network/junos/test_junos_config.py deleted file mode 100644 index d772284d7b..0000000000 --- a/test/units/modules/network/junos/test_junos_config.py +++ /dev/null @@ -1,189 +0,0 @@ -# -# (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 - -from units.compat.mock import patch -from ansible.modules.network.junos import junos_config -from units.modules.utils import set_module_args -from ansible.module_utils._text import to_text -from .junos_module import TestJunosModule, load_fixture - - -class TestJunosConfigModule(TestJunosModule): - - module = junos_config - - def setUp(self): - super(TestJunosConfigModule, self).setUp() - - self.mock_get_config = patch('ansible.modules.network.junos.junos_config.get_configuration') - self.get_config = self.mock_get_config.start() - - self.mock_load_config = patch('ansible.modules.network.junos.junos_config.load_config') - self.load_config = self.mock_load_config.start() - - self.mock_load_configuration = patch('ansible.modules.network.junos.junos_config.load_configuration') - self.load_configuration = self.mock_load_configuration.start() - - self.mock_lock_configuration = patch('ansible.module_utils.network.junos.junos.lock_configuration') - self.lock_configuration = self.mock_lock_configuration.start() - - self.mock_unlock_configuration = patch('ansible.module_utils.network.junos.junos.unlock_configuration') - self.unlock_configuration = self.mock_unlock_configuration.start() - - self.mock_commit_configuration = patch('ansible.modules.network.junos.junos_config.commit_configuration') - self.commit_configuration = self.mock_commit_configuration.start() - - self.mock_get_diff = patch('ansible.modules.network.junos.junos_config.get_diff') - self.get_diff = self.mock_get_diff.start() - - self.mock_conn = patch('ansible.module_utils.connection.Connection') - self.conn = self.mock_conn.start() - - self.mock_netconf = patch('ansible.module_utils.network.junos.junos.NetconfConnection') - self.netconf_conn = self.mock_netconf.start() - - self.mock_exec_rpc = patch('ansible.modules.network.junos.junos_config.exec_rpc') - self.exec_rpc = self.mock_exec_rpc.start() - - self.mock_netconf_rpc = patch('ansible.module_utils.network.common.netconf.NetconfConnection') - self.netconf_rpc = self.mock_netconf_rpc.start() - - def tearDown(self): - super(TestJunosConfigModule, self).tearDown() - self.mock_get_config.stop() - self.mock_load_config.stop() - self.mock_lock_configuration.stop() - self.mock_unlock_configuration.stop() - self.mock_commit_configuration.stop() - self.mock_get_diff.stop() - self.load_configuration.stop() - self.mock_conn.stop() - self.mock_netconf.stop() - self.mock_exec_rpc.stop() - self.mock_netconf_rpc.stop() - - def load_fixtures(self, commands=None, format='text', changed=False): - self.get_config.return_value = load_fixture('get_configuration_rpc_reply.txt') - if changed: - self.load_config.return_value = load_fixture('get_configuration_rpc_reply_diff.txt') - else: - self.load_config.return_value = None - - def test_junos_config_unchanged(self): - src = load_fixture('junos_config.set', content='str') - set_module_args(dict(src=src)) - self.execute_module() - - def test_junos_config_src_set(self): - src = load_fixture('junos_config.set', content='str') - set_module_args(dict(src=src)) - self.execute_module(changed=True) - args, kwargs = self.load_config.call_args - self.assertEqual(kwargs['action'], 'set') - self.assertEqual(kwargs['format'], 'text') - - def test_junos_config_backup(self): - set_module_args(dict(backup=True)) - result = self.execute_module() - self.assertIn('__backup__', result) - - def test_junos_config_lines(self): - set_module_args(dict(lines=['delete interfaces ae11', 'set interfaces ae11 unit 0 description Test'])) - self.execute_module(changed=True) - args, kwargs = self.load_config.call_args - self.assertEqual(args[1][0], 'set interfaces ae11 unit 0 description Test') - self.assertEqual(kwargs['action'], 'set') - self.assertEqual(kwargs['format'], 'text') - - def test_junos_config_confirm(self): - src = load_fixture('junos_config.set', content='str') - set_module_args(dict(src=src, confirm=40)) - self.execute_module(changed=True) - args, kwargs = self.commit_configuration.call_args - self.assertEqual(kwargs['confirm_timeout'], to_text(40)) - - def test_junos_config_rollback(self): - rollback = 10 - set_module_args(dict(rollback=rollback)) - self.execute_module(changed=True) - self.assertEqual(self.get_diff.call_count, 1) - self.assertEqual(self.load_configuration.call_count, 1) - self.assertEqual(self.commit_configuration.call_count, 1) - load_configuration_args = self.load_configuration.call_args - self.assertEqual(rollback, load_configuration_args[1].get('rollback')) - - def test_junos_config_src_text(self): - src = load_fixture('junos_config.text', content='str') - set_module_args(dict(src=src)) - self.execute_module(changed=True) - args, kwargs = self.load_config.call_args - self.assertEqual(kwargs['action'], 'merge') - self.assertEqual(kwargs['format'], 'text') - - def test_junos_config_src_xml(self): - src = load_fixture('junos_config.xml', content='str') - set_module_args(dict(src=src)) - self.execute_module(changed=True) - args, kwargs = self.load_config.call_args - self.assertEqual(kwargs['action'], 'merge') - self.assertEqual(kwargs['format'], 'xml') - - def test_junos_config_src_json(self): - src = load_fixture('junos_config.json', content='str') - set_module_args(dict(src=src)) - self.execute_module(changed=True) - args, kwargs = self.load_config.call_args - self.assertEqual(kwargs['action'], 'merge') - self.assertEqual(kwargs['format'], 'json') - - def test_junos_config_update_override(self): - src = load_fixture('junos_config.xml', content='str') - set_module_args(dict(src=src, update='override')) - self.execute_module() - args, kwargs = self.load_config.call_args - self.assertEqual(kwargs['action'], 'override') - self.assertEqual(kwargs['format'], 'xml') - - def test_junos_config_update_replace(self): - src = load_fixture('junos_config.json', content='str') - set_module_args(dict(src=src, update='replace')) - self.execute_module() - args, kwargs = self.load_config.call_args - self.assertEqual(kwargs['action'], 'replace') - self.assertEqual(kwargs['format'], 'json') - - def test_junos_config_zeroize(self): - set_module_args(dict(zeroize='yes')) - self.execute_module(changed=True) - self.assertEqual(self.exec_rpc.call_count, 1) - - def test_junos_config_src_format_xml(self): - src = load_fixture('junos_config.json', content='str') - set_module_args(dict(src=src, src_format='xml')) - self.execute_module() - args, kwargs = self.load_config.call_args - self.assertEqual(kwargs['format'], 'xml') - - def test_junos_config_confirm_commit(self): - set_module_args(dict(confirm_commit=True)) - self.execute_module(changed=True) - self.assertEqual(self.commit_configuration.call_count, 1) diff --git a/test/units/modules/network/junos/test_junos_facts.py b/test/units/modules/network/junos/test_junos_facts.py deleted file mode 100644 index a8b8169625..0000000000 --- a/test/units/modules/network/junos/test_junos_facts.py +++ /dev/null @@ -1,150 +0,0 @@ -# (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 - -try: - from lxml.etree import fromstring -except ImportError: - from xml.etree.ElementTree import fromstring - -from units.compat.mock import patch -from ansible.modules.network.junos import junos_facts -from units.modules.utils import set_module_args -from .junos_module import TestJunosModule, load_fixture - -RPC_CLI_MAP = { - 'get-software-information': 'show version', - 'get-interface-information': 'show interfaces details', - 'get-system-memory-information': 'show system memory', - 'get-chassis-inventory': 'show chassis hardware', - 'get-route-engine-information': 'show chassis routing-engine', - 'get-system-storage': 'show system storage' -} - - -class TestJunosCommandModule(TestJunosModule): - - module = junos_facts - - def setUp(self): - super(TestJunosCommandModule, self).setUp() - - self.mock_get_config = patch('ansible.module_utils.network.junos.facts.legacy.base.get_configuration') - self.get_config = self.mock_get_config.start() - - self.mock_netconf = patch('ansible.module_utils.network.junos.junos.NetconfConnection') - self.netconf_conn = self.mock_netconf.start() - - self.mock_exec_rpc = patch('ansible.module_utils.network.junos.facts.legacy.base.exec_rpc') - self.exec_rpc = self.mock_exec_rpc.start() - - self.mock_netconf_rpc = patch('ansible.module_utils.network.common.netconf.NetconfConnection') - self.netconf_rpc = self.mock_netconf_rpc.start() - - self.mock_get_resource_connection = patch('ansible.module_utils.network.common.facts.facts.get_resource_connection') - self.get_resource_connection = self.mock_get_resource_connection.start() - - self.mock_get_capabilities = patch('ansible.module_utils.network.junos.facts.legacy.base.get_capabilities') - self.get_capabilities = self.mock_get_capabilities.start() - - self.get_capabilities.return_value = { - 'device_info': { - 'network_os': 'junos', - 'network_os_hostname': 'vsrx01', - 'network_os_model': 'vsrx', - 'network_os_version': '17.3R1.10' - }, - 'network_api': 'netconf' - } - - def tearDown(self): - super(TestJunosCommandModule, self).tearDown() - self.mock_netconf.stop() - self.mock_exec_rpc.stop() - self.mock_netconf_rpc.stop() - self.mock_get_capabilities.stop() - self.mock_get_resource_connection.stop() - - def load_fixtures(self, commands=None, format='text', changed=False): - def load_from_file(*args, **kwargs): - element = fromstring(args[1]) - - if element.text: - path = str(element.text) - else: - path = RPC_CLI_MAP[str(element.tag)] - - filename = path.replace(' ', '_') - filename = '%s_%s.txt' % (filename, format) - return load_fixture(filename) - - self.exec_rpc.side_effect = load_from_file - - def test_junos_get_facts(self): - set_module_args(dict()) - result = self.execute_module(format='xml') - facts = result['ansible_facts'] - - self.assertEqual(facts['ansible_net_hostname'], 'vsrx01') - self.assertTrue('em0' in facts['ansible_net_interfaces']) - self.assertEqual(facts['ansible_net_interfaces']['em0']['type'], 'Ethernet') - self.assertEqual(facts['ansible_net_memtotal_mb'], 983500) - self.assertEqual(facts['ansible_net_filesystems'][0], '/dev/vtbd0s1a') - self.assertTrue('ansible_net_config' not in facts) - self.assertEqual(facts['ansible_net_routing_engines']["0"]['model'], 'RE-S-EX9200-1800X4') - self.assertEqual(facts['ansible_net_modules'][0]['name'], 'Midplane') - self.assertTrue(facts['ansible_net_has_2RE']) - - def test_junos_get_facts_subset_config_set(self): - self.get_config.return_value = load_fixture('get_configuration_rpc_reply.txt') - set_module_args(dict(gather_subset='config', config_format='set')) - result = self.execute_module(format='xml') - facts = result['ansible_facts'] - - self.assertTrue('ansible_net_config' in facts) - self.assertTrue(facts['ansible_net_config'].startswith('set')) - self.assertEqual(facts['ansible_net_hostname'], 'vsrx01') - self.assertTrue('ansible_net_interfaces' not in facts) - - def test_junos_get_facts_subset_config_json(self): - self.get_config.return_value = load_fixture('get_configuration_rpc_reply_json.txt') - set_module_args(dict(gather_subset='config', config_format='json')) - result = self.execute_module(format='xml') - facts = result['ansible_facts'] - - self.assertTrue('ansible_net_config' in facts) - self.assertTrue('configuration' in facts['ansible_net_config']) - self.assertEqual(facts['ansible_net_hostname'], 'vsrx01') - self.assertTrue('ansible_net_interfaces' not in facts) - - def test_junos_get_facts_subset_list(self): - set_module_args(dict(gather_subset=['hardware', 'interfaces'])) - result = self.execute_module(format='xml') - facts = result['ansible_facts'] - - self.assertTrue('ansible_net_config' not in facts) - self.assertEqual(facts['ansible_net_interfaces']['em0']['oper-status'], 'up') - self.assertEqual(facts['ansible_net_memfree_mb'], 200684) - - def test_junos_get_facts_wrong_subset(self): - set_module_args(dict(gather_subset=['hardware', 'interfaces', 'test'])) - result = self.execute_module(format='xml', failed=True) - - self.assertTrue(result['msg'].startswith('Subset must be one')) diff --git a/test/units/modules/network/junos/test_junos_netconf.py b/test/units/modules/network/junos/test_junos_netconf.py deleted file mode 100644 index 4c71ca09c8..0000000000 --- a/test/units/modules/network/junos/test_junos_netconf.py +++ /dev/null @@ -1,106 +0,0 @@ -# (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 - -from units.compat.mock import patch -from ansible.modules.network.junos import junos_netconf -from units.modules.utils import set_module_args -from .junos_module import TestJunosModule - - -class TestJunosCommandModule(TestJunosModule): - - module = junos_netconf - - def setUp(self): - super(TestJunosCommandModule, self).setUp() - - self.mock_lock_configuration = patch('ansible.module_utils.network.junos.junos.lock_configuration') - self.lock_configuration = self.mock_lock_configuration.start() - - self.mock_unlock_configuration = patch('ansible.module_utils.network.junos.junos.unlock_configuration') - self.unlock_configuration = self.mock_unlock_configuration.start() - - self.mock_conn = patch('ansible.module_utils.connection.Connection') - self.conn = self.mock_conn.start() - - self.mock_netconf = patch('ansible.module_utils.network.junos.junos.NetconfConnection') - self.netconf_conn = self.mock_netconf.start() - - self.mock_netconf_rpc = patch('ansible.module_utils.network.common.netconf.NetconfConnection') - self.netconf_rpc = self.mock_netconf_rpc.start() - - self.mock_get_capabilities = patch('ansible.module_utils.network.junos.junos.get_capabilities') - self.get_capabilities = self.mock_get_capabilities.start() - self.get_capabilities.return_value = {'network_api': 'netconf'} - - def tearDown(self): - super(TestJunosCommandModule, self).tearDown() - self.mock_lock_configuration.stop() - self.mock_unlock_configuration.stop() - self.mock_conn.stop() - self.mock_netconf.stop() - self.mock_netconf_rpc.stop() - self.mock_get_capabilities.stop() - - def test_junos_netconf_enable(self): - self.netconf_conn().get.return_value = '' - set_module_args(dict(state='present')) - result = self.execute_module(changed=True) - self.assertEqual(result['commands'], ['set system services netconf ssh port 830']) - - def test_junos_netconf_disable(self): - out = ''' - ssh { - port 830; - } - ''' - self.netconf_conn().get.return_value = out - set_module_args(dict(state='absent')) - result = self.execute_module(changed=True) - self.assertEqual(result['commands'], ['delete system services netconf']) - - def test_junos_netconf_port_change(self): - out = ''' - ssh { - port 830; - } - ''' - self.netconf_conn().get.return_value = out - set_module_args(dict(state='present', netconf_port=22)) - result = self.execute_module(changed=True) - self.assertEqual(result['commands'], ['set system services netconf ssh port 22']) - - def test_junos_netconf_port_error(self): - out = ''' - ssh { - port 22; - } - ''' - self.netconf_conn().get.return_value = out - set_module_args(dict(state='present', netconf_port=0)) - result = self.execute_module(changed=True, failed=True) - self.assertEqual(result['msg'], 'netconf_port must be between 1 and 65535') - - def test_junos_netconf_config_error(self): - self.netconf_conn().get.return_value = None - set_module_args(dict(state='present')) - result = self.execute_module(failed=True) - self.assertEqual(result['msg'], 'unable to retrieve current config') diff --git a/test/units/modules/network/junos/test_junos_package.py b/test/units/modules/network/junos/test_junos_package.py deleted file mode 100644 index 8ce74e9263..0000000000 --- a/test/units/modules/network/junos/test_junos_package.py +++ /dev/null @@ -1,73 +0,0 @@ -# (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 - -from units.compat.mock import patch, MagicMock -from units.modules.utils import set_module_args -from .junos_module import TestJunosModule - -jnpr_mock = MagicMock() -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 - - -class TestJunosPackageModule(TestJunosModule): - - module = junos_package - - def setUp(self): - 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() - - def tearDown(self): - super(TestJunosPackageModule, self).tearDown() - self.mock_get_device.stop() - - def test_junos_package_src(self): - set_module_args(dict(src='junos-vsrx-12.1X46-D10.2-domestic.tgz')) - 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',)) - - 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) - - 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) - - 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) diff --git a/test/units/modules/network/junos/test_junos_ping.py b/test/units/modules/network/junos/test_junos_ping.py deleted file mode 100644 index b0af7b33e9..0000000000 --- a/test/units/modules/network/junos/test_junos_ping.py +++ /dev/null @@ -1,101 +0,0 @@ -# (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, MagicMock -from ansible.modules.network.junos import junos_ping -from units.modules.utils import set_module_args -from .junos_module import TestJunosModule, load_fixture - - -class TestJunosPingModule(TestJunosModule): - module = junos_ping - - def setUp(self): - super(TestJunosPingModule, self).setUp() - - self.mock_get_connection = patch('ansible.modules.network.junos.junos_ping.get_connection') - self.get_connection = self.mock_get_connection.start() - - self.conn = self.get_connection() - self.conn.get = MagicMock() - - def tearDown(self): - super(TestJunosPingModule, self).tearDown() - self.mock_get_connection.stop() - - def test_junos_ping_expected_success(self): - set_module_args(dict(count=2, dest="10.10.10.10")) - self.conn.get = MagicMock(return_value=load_fixture('junos_ping_ping_10.10.10.10_count_2', content='str')) - result = self.execute_module() - self.assertEqual(result['commands'], 'ping 10.10.10.10 count 2') - - def test_junos_ping_expected_failure(self): - set_module_args(dict(count=4, dest="10.10.10.20", state="absent")) - self.conn.get = MagicMock(return_value=load_fixture('junos_ping_ping_10.10.10.20_count_4', content='str')) - result = self.execute_module() - self.assertEqual(result['commands'], 'ping 10.10.10.20 count 4') - - def test_junos_ping_unexpected_success(self): - ''' Test for successful pings when destination should not be reachable - FAIL. ''' - set_module_args(dict(count=2, dest="10.10.10.10", state="absent")) - self.conn.get = MagicMock(return_value=load_fixture('junos_ping_ping_10.10.10.10_count_2', content='str')) - self.execute_module(failed=True) - - def test_junos_ping_unexpected_failure(self): - ''' Test for unsuccessful pings when destination should be reachable - FAIL. ''' - set_module_args(dict(count=4, dest="10.10.10.20")) - self.conn.get = MagicMock(return_value=load_fixture('junos_ping_ping_10.10.10.20_count_4', content='str')) - self.execute_module(failed=True) - - def test_junos_ping_failure_stats(self): - '''Test for asserting stats when ping fails''' - set_module_args(dict(count=4, dest="10.10.10.20")) - self.conn.get = MagicMock(return_value=load_fixture('junos_ping_ping_10.10.10.20_count_4', content='str')) - result = self.execute_module(failed=True) - self.assertEqual(result['packet_loss'], '100%') - self.assertEqual(result['packets_rx'], 0) - self.assertEqual(result['packets_tx'], 4) - - def test_junos_ping_success_stats(self): - set_module_args(dict(count=2, dest="10.10.10.10")) - self.conn.get = MagicMock(return_value=load_fixture('junos_ping_ping_10.10.10.10_count_2', content='str')) - result = self.execute_module() - self.assertEqual(result['commands'], 'ping 10.10.10.10 count 2') - self.assertEqual(result['packet_loss'], '0%') - self.assertEqual(result['packets_rx'], 2) - self.assertEqual(result['packets_tx'], 2) - self.assertEqual(result['rtt']['min'], 15.71) - self.assertEqual(result['rtt']['avg'], 16.87) - self.assertEqual(result['rtt']['max'], 18.04) - self.assertEqual(result['rtt']['stddev'], 1.165) - - def test_junos_ping_success_stats_with_options(self): - set_module_args(dict(count=5, size=512, interval=2, dest="10.10.10.11")) - self.conn.get = MagicMock(return_value=load_fixture('junos_ping_ping_10.10.10.11_count_5_size_512_interval_2', content='str')) - result = self.execute_module() - self.assertEqual(result['commands'], 'ping 10.10.10.11 count 5 size 512 interval 2') - self.assertEqual(result['packet_loss'], '0%') - self.assertEqual(result['packets_rx'], 5) - self.assertEqual(result['packets_tx'], 5) - self.assertEqual(result['rtt']['min'], 18.71) - self.assertEqual(result['rtt']['avg'], 17.87) - self.assertEqual(result['rtt']['max'], 20.04) - self.assertEqual(result['rtt']['stddev'], 2.165) diff --git a/test/units/modules/network/junos/test_junos_rpc.py b/test/units/modules/network/junos/test_junos_rpc.py deleted file mode 100644 index e3b4db1d20..0000000000 --- a/test/units/modules/network/junos/test_junos_rpc.py +++ /dev/null @@ -1,111 +0,0 @@ -# (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 - -try: - from lxml.etree import fromstring -except ImportError: - from xml.etree.ElementTree import fromstring - -from units.compat.mock import patch -from ansible.modules.network.junos import junos_rpc -from units.modules.utils import set_module_args -from .junos_module import TestJunosModule, load_fixture - - -RPC_CLI_MAP = { - 'get-software-information': 'show version', - 'get-interface-information': 'show interfaces details', - 'get-system-memory-information': 'show system memory', - 'get-chassis-inventory': 'show chassis hardware', - 'get-system-storage': 'show system storage', - 'load-configuration': 'load configuration' -} - - -class TestJunosCommandModule(TestJunosModule): - - module = junos_rpc - - def setUp(self): - super(TestJunosCommandModule, self).setUp() - self.mock_conn = patch('ansible.module_utils.connection.Connection') - self.conn = self.mock_conn.start() - - self.mock_netconf = patch('ansible.module_utils.network.junos.junos.NetconfConnection') - self.netconf_conn = self.mock_netconf.start() - - self.mock_netconf_rpc = patch('ansible.module_utils.network.common.netconf.NetconfConnection') - self.netconf_rpc = self.mock_netconf_rpc.start() - - self.mock_exec_rpc = patch('ansible.modules.network.junos.junos_rpc.exec_rpc') - self.exec_rpc = self.mock_exec_rpc.start() - - def tearDown(self): - super(TestJunosCommandModule, self).tearDown() - self.mock_conn.stop() - self.mock_netconf.stop() - self.mock_netconf_rpc.stop() - self.mock_exec_rpc.stop() - - def load_fixtures(self, commands=None, format='text', changed=False): - def load_from_file(*args, **kwargs): - element = fromstring(args[1]) - if element.text: - path = str(element.text) - else: - tag = str(element.tag) - if tag.startswith('{'): - tag = tag.split('}', 1)[1] - path = RPC_CLI_MAP[tag] - - filename = path.replace(' ', '_') - filename = '%s_%s.txt' % (filename, format) - - return load_fixture(filename) - - self.exec_rpc.side_effect = load_from_file - - def test_junos_rpc_xml(self): - set_module_args(dict(rpc='get-chassis-inventory')) - result = self.execute_module(format='xml') - self.assertTrue(result['xml'].find('<chassis-inventory>\n')) - - def test_junos_rpc_text(self): - set_module_args(dict(rpc='get-software-information', output='text')) - result = self.execute_module(format='text') - self.assertTrue(result['output_lines'][0].startswith('Hostname: vsrx01')) - - def test_junos_rpc_json(self): - set_module_args(dict(rpc='get-software-information', output='json')) - result = self.execute_module(format='json') - self.assertTrue('software-information' in result['output']) - - def test_junos_rpc_args(self): - set_module_args(dict(rpc='get-software-information', args={'interface': 'em0', 'media': True})) - self.execute_module(format='xml') - args, kwargs = self.exec_rpc.call_args - reply = args[1] - self.assertTrue(reply.find('<interface>em0</interface><media /></get-software-information>')) - - def test_junos_rpc_attrs(self): - set_module_args(dict(rpc='load-configuration', output='xml', attrs={'url': '/var/tmp/config.conf'})) - result = self.execute_module(format='xml') - self.assertTrue(result['xml'].find('<load-success/>')) diff --git a/test/units/modules/network/junos/test_junos_scp.py b/test/units/modules/network/junos/test_junos_scp.py deleted file mode 100644 index 59cf926b49..0000000000 --- a/test/units/modules/network/junos/test_junos_scp.py +++ /dev/null @@ -1,82 +0,0 @@ -# (c) 2018 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, MagicMock -from units.modules.utils import set_module_args -from .junos_module import TestJunosModule - -jnpr_mock = MagicMock() -modules = { - 'jnpr': jnpr_mock, - 'jnpr.junos': jnpr_mock.junos, - 'jnpr.junos.utils': jnpr_mock.junos.utils, - 'jnpr.junos.utils.scp': jnpr_mock.junos.utils.scp, -} -module_patcher = patch.dict('sys.modules', modules) -module_patcher.start() - -from ansible.modules.network.junos import junos_scp - - -class TestJunosScpModule(TestJunosModule): - - module = junos_scp - - def setUp(self): - super(TestJunosScpModule, self).setUp() - self.mock_get_device = patch('ansible.modules.network.junos.junos_scp.get_device') - self.get_device = self.mock_get_device.start() - - self.mock_scp = patch('ansible.modules.network.junos.junos_scp.SCP') - self.scp = self.mock_scp.start() - - self.scp_mock = MagicMock() - self.scp().__enter__.return_value = self.scp_mock - - def tearDown(self): - super(TestJunosScpModule, self).tearDown() - self.mock_get_device.stop() - self.mock_scp.stop() - - def test_junos_scp_src(self): - set_module_args(dict(src='test.txt')) - self.execute_module(changed=True) - - self.scp_mock.put.assert_called_once_with('test.txt', remote_path='.', recursive=False) - - def test_junos_scp_src_fail(self): - self.scp_mock.put.side_effect = OSError("[Errno 2] No such file or directory: 'text.txt'") - set_module_args(dict(src='test.txt')) - result = self.execute_module(changed=True, failed=True) - - self.assertEqual(result['msg'], "[Errno 2] No such file or directory: 'text.txt'") - - def test_junos_scp_remote_src(self): - set_module_args(dict(src='test.txt', remote_src=True)) - self.execute_module(changed=True) - - self.scp_mock.get.assert_called_once_with('test.txt', local_path='.', recursive=False) - - def test_junos_scp_all(self): - set_module_args(dict(src='test', remote_src=True, dest="tmp", recursive=True)) - self.execute_module(changed=True) - - self.scp_mock.get.assert_called_once_with('test', local_path='tmp', recursive=True) diff --git a/test/units/plugins/terminal/test_junos.py b/test/units/plugins/terminal/test_junos.py deleted file mode 100644 index b863bb7b03..0000000000 --- a/test/units/plugins/terminal/test_junos.py +++ /dev/null @@ -1,55 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright: (c) 2018, Fran Fitzpatrick <francis.x.fitzpatrick@gmail.com> fxfitz -# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) - -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type - -from mock import call, MagicMock -import pytest - -from ansible.errors import AnsibleConnectionFailure -from ansible.plugins.terminal import junos - - -@pytest.fixture -def junos_terminal(): - mock_connection = MagicMock() - return junos.TerminalModule(mock_connection) - - -def test_on_open_shell_sets_terminal_parameters(junos_terminal): - expected_calls = [ - call(b'set cli timestamp disable'), - call(b'set cli screen-length 0'), - call(b'set cli screen-width 1024'), - ] - junos_terminal._exec_cli_command = MagicMock() - junos_terminal._get_prompt = MagicMock() - - junos_terminal._get_prompt.return_value = b'user@localhost >' - junos_terminal.on_open_shell() - junos_terminal._exec_cli_command.assert_has_calls(expected_calls) - - -def test_on_open_shell_enters_cli_if_root_prompt(junos_terminal): - expected_calls = [ - call(b'cli'), - call(b'set cli timestamp disable'), - call(b'set cli screen-length 0'), - call(b'set cli screen-width 1024'), - ] - junos_terminal._exec_cli_command = MagicMock() - junos_terminal._get_prompt = MagicMock() - - junos_terminal._connection.get_prompt.return_value = b'root@localhost%' - junos_terminal.on_open_shell() - junos_terminal._exec_cli_command.assert_has_calls(expected_calls) - - -def test_on_open_shell_raises_problem_setting_terminal_config(junos_terminal): - junos_terminal._connection.exec_command.side_effect = AnsibleConnectionFailure - with pytest.raises(AnsibleConnectionFailure) as exc: - junos_terminal.on_open_shell() - - assert 'unable to set terminal parameters' in str(exc.value) |