From 8dc51dfe1c4b8a339e4fba169e508af18af01060 Mon Sep 17 00:00:00 2001
From: Paul Belanger <pabelanger@redhat.com>
Date: Tue, 18 Jun 2019 08:31:05 -0400
Subject: [PATCH] Remove pause logic form junos_netconf tests (#57966)

We can switch to wait_for / meta, as using pause can lead to race
conditions on slower / faster hardware.

Signed-off-by: Paul Belanger <pabelanger@redhat.com>
---
 .../junos_netconf/tests/cli/changeport.yaml   | 35 ++++++++++++-------
 .../junos_netconf/tests/cli/netconf.yaml      | 26 +++++++++-----
 2 files changed, 40 insertions(+), 21 deletions(-)

diff --git a/test/integration/targets/junos_netconf/tests/cli/changeport.yaml b/test/integration/targets/junos_netconf/tests/cli/changeport.yaml
index a6c42ed190c..528380f8d74 100644
--- a/test/integration/targets/junos_netconf/tests/cli/changeport.yaml
+++ b/test/integration/targets/junos_netconf/tests/cli/changeport.yaml
@@ -4,9 +4,9 @@
 - name: Setup
   junos_netconf:
     state: present
-  register: result
 
 ###################################
+
 - name: Change port
   junos_netconf:
     state: present
@@ -27,17 +27,24 @@
     that:
       - "result.changed == false"
 
-- name: wait for netconf server to come up
-  pause:
-    seconds: 10
+- name: wait for netconf port tcp/8022 to be open
+  wait_for:
+    host: "{{ hostvars[item].ansible_host }}"
+    port: 8022
+  with_inventory_hostnames: junos
+
+- name: Reset ansible connections
+  meta: reset_connection
 
 - name: Ensure we can communicate over 8022
   include: "{{ role_path }}/tests/utils/junos_command.yaml ansible_connection=netconf ansible_port=8022 is_ignore_errors=false"
 
-- name: wait for persistent socket to timeout
-  pause:
-    seconds: 120
-
+- name: wait for netconf port tcp/830 to be closed
+  wait_for:
+    host: "{{ hostvars[item].ansible_host }}"
+    port: 830
+    state: stopped
+  with_inventory_hostnames: junos
 
 # This protects against the port override above not being honoured and a bug setting the port
 - name: Ensure we can NOT communicate over default port
@@ -50,11 +57,15 @@
 - name: Set back netconf to default port
   junos_netconf:
     state: present
-  register: result
 
-- name: wait for persistent socket to timeout
-  pause:
-    seconds: 120
+- name: wait for netconf port tcp/830 to be open
+  wait_for:
+    host: "{{ hostvars[item].ansible_host }}"
+    port: 830
+  with_inventory_hostnames: junos
+
+- name: Reset ansible connections
+  meta: reset_connection
 
 - name: Ensure we can communicate over netconf
   include: "{{ role_path }}/tests/utils/junos_command.yaml ansible_connection=netconf ansible_port=830 is_ignore_errors=false"
diff --git a/test/integration/targets/junos_netconf/tests/cli/netconf.yaml b/test/integration/targets/junos_netconf/tests/cli/netconf.yaml
index 9cc69ba356a..2fdf677dea4 100644
--- a/test/integration/targets/junos_netconf/tests/cli/netconf.yaml
+++ b/test/integration/targets/junos_netconf/tests/cli/netconf.yaml
@@ -1,11 +1,9 @@
 ---
 - debug: msg="START netconf/netconf.yaml on connection={{ ansible_connection }}"
 
-
 - name: Ensure netconf is enabled
   junos_netconf:
     state: present
-  register: result
 
 - name: idempotent tests
   junos_netconf:
@@ -18,9 +16,14 @@
 
 ###################################
 
-- name: wait for netconf server to come up
-  pause:
-    seconds: 10
+- name: wait for netconf port tcp/830 to be open
+  wait_for:
+    host: "{{ hostvars[item].ansible_host }}"
+    port: 830
+  with_inventory_hostnames: junos
+
+- name: Reset ansible connections
+  meta: reset_connection
 
 - name: Ensure we can communicate over netconf
   include: "{{ role_path }}/tests/utils/junos_command.yaml ansible_connection=netconf ansible_port=830 is_ignore_errors=false"
@@ -61,9 +64,15 @@
     that:
       - "result.changed == false"
 
-- name: wait for persistent socket to timeout
-  pause:
-    seconds: 120
+- name: wait for netconf port tcp/830 to be closed
+  wait_for:
+    host: "{{ hostvars[item].ansible_host }}"
+    port: 830
+    state: stopped
+  with_inventory_hostnames: junos
+
+- name: Reset ansible connections
+  meta: reset_connection
 
 - name: Ensure we can NOT talk via netconf
   include: "{{ role_path }}/tests/utils/junos_command.yaml ansible_connection=netconf ansible_port=830 is_ignore_errors=true"
@@ -96,6 +105,5 @@
 - name: re-enable netconf
   junos_netconf:
     state: present
-  register: result
 
 - debug: msg="END netconf/netconfg.yaml on connection={{ ansible_connection }}"