Skip to content

Add commit-ready functional tests under tests/junipernetworks.junos #749

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 97 additions & 0 deletions tests/junipernetworks.junos/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
Functional Tests for Juniper Ansible Collection (junipernetworks.junos)

This directory contains a complete suite of functional tests for the modules in the junipernetworks.junos Ansible collection.

These playbooks verify behavior for each supported module using real Junos devices or virtual environments, following official module documentation examples. This ensures compatibility, schema adherence, and correctness across configuration states like merged, replaced, overridden, deleted, rendered, gathered, and parsed.

🔧 Directory Structure

All functional test playbooks are located under:

tests/junipernetworks.junos/

Each playbook corresponds to one Ansible module, for example:

pb.juniper_junos_system.yml

pb.juniper_junos_lag_interfaces.yml

pb.juniper_junos_bgp_global.yml

etc.

Any required configuration files (e.g., parsed_configs/*.cfg) are also included.

🧪 Steps to Execute Functional Test Playbooks

1. Clone the Repository

git clone https://github.com/Juniper/ansible-junos-stdlib.git
cd ansible-junos-stdlib/tests/junipernetworks.junos

2. Ensure ansible.cfg is configured correctly

[defaults]
hash_behaviour = merge
inventory = inventory
host_key_checking = False
log_path = ./ansible.log

[persistent_connection]
command_timeout = 300

3. Inventory Setup (inventory)

The inventory file defines three connection types:

a. NETCONF (default)

[netconf_connection_testcases]
junos_device ansible_host=xx.xx.xx.xx

b. Local connection

[local_connection_testcases]
localhost ansible_connection=local ansible_network_os=none

c. Network CLI

[network_cli_testcases]
junos_netconf_device ansible_host=xx.xx.xx.xx ansible_connection=network_cli ansible_network_os=junipernetworks.junos.junos ansible_user=xx ansible_password=xx

Global variables:

[all:vars]
ansible_python_interpreter=/path/to/venv/bin/python
ansible_connection=netconf
ansible_network_os=junipernetworks.junos.junos
ansible_user=xx
ansible_password=xx


4. Run a Functional Test

ansible-playbook pb.juniper_junos_l3_interfaces.yml

You can use -v or -vvv for verbose output and troubleshooting.

5. Run All Tests Automatically

To run all 38 functional tests in sequence, use the provided script:

./run_all_tests.sh


This script will:

Execute every test playbook under junipernetworks.junos/

Log results to ansible.log

Ensure a complete functional regression pass

Make sure the script is executable:

chmod +x run_all_tests.sh


9 changes: 9 additions & 0 deletions tests/junipernetworks.junos/ansible.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[defaults]
hash_behaviour=merge
inventory = inventory
host_key_checking = False
log_path = ./ansible.log


[persistent_connection]
command_timeout = 300
15 changes: 15 additions & 0 deletions tests/junipernetworks.junos/inventory
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[netconf_connection_testcases]
junos_device ansible_host=xx.xx.xx.xx

[local_connection_testcases]
localhost ansible_connection=local ansible_network_os=none

[network_cli_testcases]
junos_netconf_device ansible_host=xx.xx.xx.xx ansible_connection=network_cli ansible_network_os=junipernetworks.junos.junos ansible_user=xx ansible_password=xx

[all:vars]
ansible_python_interpreter=/path/to/venv/bin/python
ansible_connection=netconf
ansible_network_os=junipernetworks.junos.junos
ansible_user=xx
ansible_password=xx
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<?xml version="1.0" encoding="UTF-8"?>
<rpc-reply>
<configuration>
<protocols>
<bgp>
<family>
<evpn>
<signaling>
<accepted-prefix-limit>
<maximum>20</maximum>
<teardown>
<limit-threshold>98</limit-threshold>
<idle-timeout>
<timeout>2001</timeout>
</idle-timeout>
</teardown>
</accepted-prefix-limit>
<damping/>
<defer-initial-multipath-build>
<maximum-delay>2</maximum-delay>
</defer-initial-multipath-build>
</signaling>
</evpn>
<inet>
<flow>
<legacy-redirect-ip-action>
<send/>
<receive/>
</legacy-redirect-ip-action>
<loops>
<loops>4</loops>
</loops>
<no-install/>
<output-queue-priority>
<expedited/>
</output-queue-priority>
<secondary-independent-resolution/>
</flow>
<unicast>
<local-ipv4-address>9.9.9.9</local-ipv4-address>
<extended-nexthop/>
<extended-nexthop-color/>
</unicast>
<labeled-unicast>
<entropy-label>
<no-next-hop-validation/>
</entropy-label>
<explicit-null>
<connected-only/>
</explicit-null>
<per-prefix-label/>
<per-group-label/>
<prefix-limit>
<maximum>20</maximum>
<teardown>
<limit-threshold>99</limit-threshold>
<idle-timeout>
<forever/>
</idle-timeout>
</teardown>
</prefix-limit>
<resolve-vpn/>
<rib>
<inet.3/>
</rib>
<route-refresh-priority>
<expedited/>
<priority>3</priority>
</route-refresh-priority>
</labeled-unicast>
<any>
<accepted-prefix-limit>
<maximum>20</maximum>
<teardown>
<limit-threshold>99</limit-threshold>
<idle-timeout>
<timeout>2000</timeout>
</idle-timeout>
</teardown>
</accepted-prefix-limit>
<damping/>
<delay-route-advertisements>
<minimum-delay>
<routing-uptime>23000</routing-uptime>
<inbound-convergence>32000</inbound-convergence>
</minimum-delay>
<maximum-delay>
<route-age>20</route-age>
<routing-uptime>32000</routing-uptime>
</maximum-delay>
</delay-route-advertisements>
<defer-initial-multipath-build>
<maximum-delay>2</maximum-delay>
</defer-initial-multipath-build>
<graceful-restart>
<forwarding-state-bit>from-fib</forwarding-state-bit>
</graceful-restart>
</any>
</inet>
</family>
</bgp>
</protocols>
</configuration>
</rpc-reply>
16 changes: 16 additions & 0 deletions tests/junipernetworks.junos/parsed_configs/parsed_bgp_global.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<configuration>
<protocols>
<bgp>
<group>
<name>external-peers</name>
<type>external</type>
<local-address>192.0.2.1</local-address>
<authentication-key-chain>
<name>bgp-keychain</name>
</authentication-key-chain>
<peer-as>65100</peer-as>
</group>
<as-number>65000</as-number>
</bgp>
</protocols>
</configuration>
16 changes: 16 additions & 0 deletions tests/junipernetworks.junos/parsed_configs/parsed_junos_vlans.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<rpc-reply>
<configuration>
<vlans>
<vlan>
<name>vlan1</name>
<vlan-id>1</vlan-id>
</vlan>
<vlan>
<name>vlan2</name>
<vlan-id>2</vlan-id>
<l3-interface>irb.12</l3-interface>
</vlan>
</vlans>
</configuration>
</rpc-reply>
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<rpc-reply xmlns:junos="http://xml.juniper.net/junos/20.1R1/junos" xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="101">
<configuration>
<system>
<syslog>
<file>
<name>messages</name>
<contents>
<name>any</name>
<any/>
</contents>
<contents>
<name>authorization</name>
<info/>
</contents>
</file>
<file>
<name>interactive-commands</name>
<contents>
<name>interactive-commands</name>
<any/>
</contents>
</file>
<user>
<name>*</name>
<contents>
<name>any</name>
<emergency/>
</contents>
</user>
</syslog>
</system>
</configuration>
</rpc-reply>
60 changes: 60 additions & 0 deletions tests/junipernetworks.junos/parsed_configs/parsed_ntp_global.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<configuration>
<system>
<ntp>
<boot-server>78.46.194.186</boot-server>
<broadcast>
<address>172.16.255.255</address>
<key>50</key>
<ttl>200</ttl>
<version>3</version>
<routing-instance-name>rt1</routing-instance-name>
</broadcast>
<broadcast>
<address>192.16.255.255</address>
<key>50</key>
<ttl>200</ttl>
<version>3</version>
<routing-instance-name>rt2</routing-instance-name>
</broadcast>
<broadcast-client/>
<interval-range>2</interval-range>
<multicast-client>224.0.0.1</multicast-client>
<peer>
<name>78.44.194.186</name>
</peer>
<peer>
<name>172.44.194.186</name>
<key-id>10000</key-id>
<prefer/>
<version>3</version>
</peer>
<server>
<name>48.46.194.186</name>
<key-id>34</key-id>
<prefer/>
<version>2</version>
<routing-instance>rt1</routing-instance>
</server>
<server>
<name>48.45.194.186</name>
<key-id>34</key-id>
<prefer/>
<version>2</version>
</server>
<source-address>
<name>172.45.194.186</name>
<routing-instance>rt1</routing-instance>
</source-address>
<source-address>
<name>171.45.194.186</name>
<routing-instance>rt2</routing-instance>
</source-address>
<threshold>
<value>300</value>
<action>accept</action>
</threshold>
<trusted-key>3000</trusted-key>
<trusted-key>2000</trusted-key>
</ntp>
</system>
</configuration>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<configuration>
<protocols>
<ospf>
<area>
<name>0.0.0.0</name>
<interface>
<name>ge-0/0/0.0</name>
<priority>5</priority>
<metric>10</metric>
</interface>
<interface>
<name>ge-0/0/1.0</name>
<passive/>
</interface>
</area>
</ospf>
</protocols>
</configuration>
Loading