From 1f0070db6cbc0bde8c187ddc50f91d4d4e6bc146 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Rados=C5=82aw=20Piliszek?= <radoslaw.piliszek@gmail.com>
Date: Sun, 23 Feb 2020 18:29:16 +0100
Subject: [PATCH] CI: Test floating ip allocation and connectivity to the
 instance

Inspired by pending work of mnasiadka [1] and mgoddard [2].

[1] https://review.opendev.org/708250
[2] https://review.opendev.org/707604

Depends-on: https://review.opendev.org/709362
Depends-on: https://review.opendev.org/709671
Depends-on: https://review.opendev.org/709830
Change-Id: Ifd7bde60881a4b644fc3f18dd9fcb7f8b02d3a00
---
 tests/pre.yml                | 24 ++++++++++++++++++++++++
 tests/test-core-openstack.sh | 25 +++++++++++++++++++++++++
 2 files changed, 49 insertions(+)

diff --git a/tests/pre.yml b/tests/pre.yml
index 47bc3b32d6..6d06605e07 100644
--- a/tests/pre.yml
+++ b/tests/pre.yml
@@ -38,6 +38,30 @@
         - "kolla"
         - "ansible"
 
+    # NOTE(yoctozepto): let's observe forwarding behavior
+    - name: iptables - LOG FORWARD
+      become: true
+      iptables:
+        state: present
+        action: append
+        chain: FORWARD
+        jump: LOG
+        log_prefix: 'iptables FORWARD: '
+
+    # NOTE(yoctozepto): This is to undo Docker's default policy of DROP which
+    # breaks l3 forwarding and also linuxbridge deploys due to bridge-nf-call-iptables.
+    # FIXME(yoctozepto): really handle this for users - somehow my local multinode
+    # deploy fixed it for itself by setting it to ACCEPT on network nodes without
+    # my intervention but so far we have no idea what did that. It certainly does
+    # not happen in CI where all nodes are aio.
+    - name: iptables - ACCEPT FORWARD
+      become: True
+      iptables:
+        state: present
+        action: append
+        chain: FORWARD
+        jump: ACCEPT
+
     - name: set new hostname based on ansible inventory file
       hostname:
         name: "{{ inventory_hostname }}"
diff --git a/tests/test-core-openstack.sh b/tests/test-core-openstack.sh
index 29334b58eb..d767edfec1 100755
--- a/tests/test-core-openstack.sh
+++ b/tests/test-core-openstack.sh
@@ -70,6 +70,31 @@ function test_instance_boot {
         echo "SUCCESS: Cinder volume attachment"
     fi
 
+    echo "TESTING: Floating ip allocation"
+    fip_addr=$(openstack floating ip create public1 -f value -c floating_ip_address)
+    openstack server add floating ip kolla_boot_test ${fip_addr}
+    echo "SUCCESS: Floating ip allocation"
+
+    echo "TESTING: PING&SSH to floating ip"
+    attempts=6
+    for i in $(seq 1 ${attempts}); do
+        if ping -c1 -W1 ${fip_addr} && ssh -v -o BatchMode=yes -o StrictHostKeyChecking=no cirros@${fip_addr} hostname; then
+            break
+        elif [[ $i -eq ${attempts} ]]; then
+            echo "Failed to access server via SSH after ${attempts} attempts"
+            return 1
+        else
+            echo "Cannot access server - retrying"
+        fi
+        sleep 10
+    done
+    echo "SUCCESS: PING&SSH to floating ip"
+
+    echo "TESTING: Floating ip deallocation"
+    openstack server remove floating ip kolla_boot_test ${fip_addr}
+    openstack floating ip delete ${fip_addr}
+    echo "SUCCESS: Floating ip deallocation"
+
     echo "TESTING: Server deletion"
     openstack server delete --wait kolla_boot_test
     echo "SUCCESS: Server deletion"