From a879e2a54e0641b692202d417021f1824032b123 Mon Sep 17 00:00:00 2001
From: Pawel Wieczorek
Date: Mon, 15 Jun 2020 16:29:35 +0200
Subject: Add Ansible roles for OpenStack network
This patch also adds Vagrant provisioners for creating and destroying
OpenStack infrastructure. These are set to never run (unless explicitly
called by the operator) because DevStack instance on a separate machine
might not be ready to provide OpenStack API.
This patch is based on previous work by:
Krzysztof Opasiak
Test harness is based on blog post [1] by:
Chris Morgan
[1] https://chrismorgan.info/blog/make-and-git-diff-test-harness
Issue-ID: INT-1601
Change-Id: I031ca7a5a43cca0258dc0dc9e0339182c431898a
Signed-off-by: Pawel Wieczorek
---
.../noheat/infra-openstack/vagrant/test/Makefile | 12 +++++++++
.../noheat/infra-openstack/vagrant/test/README | 31 ++++++++++++++++++++++
.../noheat/infra-openstack/vagrant/test/README.rst | 1 +
.../vagrant/test/create_network.stderr | 0
.../vagrant/test/create_network.stdout | 1 +
.../vagrant/test/create_network.test | 21 +++++++++++++++
.../vagrant/test/destroy_network.stderr | 0
.../vagrant/test/destroy_network.stdout | 1 +
.../vagrant/test/destroy_network.test | 21 +++++++++++++++
9 files changed, 88 insertions(+)
create mode 100644 deployment/noheat/infra-openstack/vagrant/test/Makefile
create mode 100644 deployment/noheat/infra-openstack/vagrant/test/README
create mode 120000 deployment/noheat/infra-openstack/vagrant/test/README.rst
create mode 100644 deployment/noheat/infra-openstack/vagrant/test/create_network.stderr
create mode 100644 deployment/noheat/infra-openstack/vagrant/test/create_network.stdout
create mode 100755 deployment/noheat/infra-openstack/vagrant/test/create_network.test
create mode 100644 deployment/noheat/infra-openstack/vagrant/test/destroy_network.stderr
create mode 100644 deployment/noheat/infra-openstack/vagrant/test/destroy_network.stdout
create mode 100755 deployment/noheat/infra-openstack/vagrant/test/destroy_network.test
(limited to 'deployment/noheat/infra-openstack/vagrant/test')
diff --git a/deployment/noheat/infra-openstack/vagrant/test/Makefile b/deployment/noheat/infra-openstack/vagrant/test/Makefile
new file mode 100644
index 000000000..403263dfc
--- /dev/null
+++ b/deployment/noheat/infra-openstack/vagrant/test/Makefile
@@ -0,0 +1,12 @@
+rwildcard = $(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2) $(filter $2,$d))
+
+.PHONY: test
+test: $(patsubst %.test,%.stdout,$(call rwildcard,,%.test))
+
+%.stdout: %.test
+ ./$< > $@ 2> $(patsubst %.stdout,%.stderr,$@) \
+ || (touch --date=@0 $@; false)
+ git diff --exit-code --src-prefix=expected/ --dst-prefix=actual/ \
+ $@ $(patsubst %.stdout,%.stderr,$@) \
+ || (touch --date=@0 $@; false)
+
diff --git a/deployment/noheat/infra-openstack/vagrant/test/README b/deployment/noheat/infra-openstack/vagrant/test/README
new file mode 100644
index 000000000..36cf36f38
--- /dev/null
+++ b/deployment/noheat/infra-openstack/vagrant/test/README
@@ -0,0 +1,31 @@
+==============================
+ Vagrant: simple test harness
+==============================
+
+Use ``make`` and ``git diff`` for a simple test harness for Vagrant-based environment.
+
+Prerequisites
+-------------
+
+Dependencies
+~~~~~~~~~~~~
+
+- make
+- git
+
+
+Running
+-------
+
+Command
+~~~~~~~
+
+.. code-block:: shell
+
+ $ make test
+
+
+Credit
+------
+
+This is based on https://chrismorgan.info/blog/make-and-git-diff-test-harness blog post.
diff --git a/deployment/noheat/infra-openstack/vagrant/test/README.rst b/deployment/noheat/infra-openstack/vagrant/test/README.rst
new file mode 120000
index 000000000..100b93820
--- /dev/null
+++ b/deployment/noheat/infra-openstack/vagrant/test/README.rst
@@ -0,0 +1 @@
+README
\ No newline at end of file
diff --git a/deployment/noheat/infra-openstack/vagrant/test/create_network.stderr b/deployment/noheat/infra-openstack/vagrant/test/create_network.stderr
new file mode 100644
index 000000000..e69de29bb
diff --git a/deployment/noheat/infra-openstack/vagrant/test/create_network.stdout b/deployment/noheat/infra-openstack/vagrant/test/create_network.stdout
new file mode 100644
index 000000000..363825389
--- /dev/null
+++ b/deployment/noheat/infra-openstack/vagrant/test/create_network.stdout
@@ -0,0 +1 @@
+"onap_ci_lab"
diff --git a/deployment/noheat/infra-openstack/vagrant/test/create_network.test b/deployment/noheat/infra-openstack/vagrant/test/create_network.test
new file mode 100755
index 000000000..7124f707e
--- /dev/null
+++ b/deployment/noheat/infra-openstack/vagrant/test/create_network.test
@@ -0,0 +1,21 @@
+#!/bin/sh
+
+export NETWORK_NAME='onap_ci_lab'
+
+export VAGRANT_CWD='..'
+
+set_up() {
+ vagrant up --provision-with=run_playbook_destroy
+ vagrant up --provision-with=run_playbook_create
+}
+
+check() {
+ local net="$1"
+ vagrant ssh operator --no-tty -c \
+ "export OS_CLOUD=openstack; openstack network list -fcsv" \
+ | grep "$net" \
+ | cut -d',' -f2
+}
+
+set_up >/dev/null # drop provisioning output
+check "$NETWORK_NAME"
diff --git a/deployment/noheat/infra-openstack/vagrant/test/destroy_network.stderr b/deployment/noheat/infra-openstack/vagrant/test/destroy_network.stderr
new file mode 100644
index 000000000..e69de29bb
diff --git a/deployment/noheat/infra-openstack/vagrant/test/destroy_network.stdout b/deployment/noheat/infra-openstack/vagrant/test/destroy_network.stdout
new file mode 100644
index 000000000..d48081495
--- /dev/null
+++ b/deployment/noheat/infra-openstack/vagrant/test/destroy_network.stdout
@@ -0,0 +1 @@
+Network onap_ci_lab not found.
diff --git a/deployment/noheat/infra-openstack/vagrant/test/destroy_network.test b/deployment/noheat/infra-openstack/vagrant/test/destroy_network.test
new file mode 100755
index 000000000..173b3ecca
--- /dev/null
+++ b/deployment/noheat/infra-openstack/vagrant/test/destroy_network.test
@@ -0,0 +1,21 @@
+#!/bin/sh
+
+export NETWORK_NAME='onap_ci_lab'
+
+export VAGRANT_CWD='..'
+
+set_up() {
+ vagrant up --provision-with=run_playbook_create
+ vagrant up --provision-with=run_playbook_destroy
+}
+
+check() {
+ local net="$1"
+ vagrant ssh operator --no-tty -c \
+ "export OS_CLOUD=openstack; openstack network list -fcsv" \
+ | grep "$net" \
+ || echo "Network ${net} not found."
+}
+
+set_up >/dev/null # drop provisioning output
+check "$NETWORK_NAME"
--
cgit