From 256d91ba9e2d9f696a2d78ab1002c17a63f7cb74 Mon Sep 17 00:00:00 2001
From: Jan Scotka <jscotka@redhat.com>
Date: Apr 05 2017 08:09:30 +0000
Subject: [PATCH 1/6] added some tweaks of haproxy tests


---

diff --git a/examples/haproxy/config.yaml b/examples/haproxy/config.yaml
index e92851c..0a8e318 100644
--- a/examples/haproxy/config.yaml
+++ b/examples/haproxy/config.yaml
@@ -10,22 +10,25 @@ packages:
 testdependecies:
     rpms:
         - nc
+source: https://github.com/container-images/haproxy
 module:
     docker:
+        setup: cp -f my-haproxy.cfg local-haproxy.cfg
         start: "docker run -it -p 8077:80 -v $(pwd)/local-haproxy.cfg:/etc/haproxy/haproxy.cfg:Z"
         labels:
             description: "HAProxy is a TCP/HTTP reverse proxy which is particularly suited for high availability environments."
             io.k8s.description: "HAProxy is a TCP/HTTP reverse proxy which is particularly suited for high availability environments."
-        source: https://github.com/container-images/haproxy
         container: docker.io/modularitycontainers/haproxy
     rpm:
-        start: sed -i 's/bind.*/bind :8077/' $(pwd)/local-haproxy.cfg;
-              cp $(pwd)/local-haproxy.cfg /etc/haproxy/haproxy.cfg;
+        setup: cp -f my-haproxy.cfg local-haproxy.cfg;
+              sed s/127.0.0.1/$(hostname -i | egrep -o '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+')/ -i local-haproxy.cfg;
+              sed -i 's/bind.*/bind :8077/' local-haproxy.cfg;
+              cp local-haproxy.cfg /etc/haproxy/haproxy.cfg;
               semanage port -a -t http_port_t -p tcp 8001;
               semanage port -a -t http_port_t -p tcp 8000;
               semanage port -a -t http_port_t -p tcp 8077;
-              sleep 4;
-              systemctl start haproxy
+              sleep 4
+        start: systemctl start haproxy
         stop: systemctl stop haproxy
         status: systemctl status haproxy
         repos:
diff --git a/examples/haproxy/simpleTest.py b/examples/haproxy/simpleTest.py
index b473c00..44ed28d 100644
--- a/examples/haproxy/simpleTest.py
+++ b/examples/haproxy/simpleTest.py
@@ -34,8 +34,6 @@ class simpleTests(module_framework.AvocadoTest):
         self.runHost('docker pull docker.io/httpd')
         self.runHost('docker run --name http_name_8000 -d -p 8000:80 docker.io/httpd')
         self.runHost('docker run --name http_name_8001 -d -p 8001:80 docker.io/httpd')
-        global myip
-        myip = self.runHost('hostname -i').stdout.strip()
 
     def tearDown(self):
         super(self.__class__, self).tearDown()
@@ -45,7 +43,6 @@ class simpleTests(module_framework.AvocadoTest):
         self.runHost('docker rm http_name_8001')
 
     def testAssertIn(self):
-        self.runHost(('sed s/127.0.0.1/{}/ my-haproxy.cfg > local-haproxy.cfg').format(myip), shell = True)
         self.start()
         self.assertIn('It works!',self.runHost('curl localhost:8077', shell = True).stdout)
 

From f768336e65040cc6cb6df85402ed571fd0d1f291 Mon Sep 17 00:00:00 2001
From: Jan Scotka <jscotka@redhat.com>
Date: Apr 05 2017 08:09:30 +0000
Subject: [PATCH 2/6] added some tweaks of haproxy tests


---

diff --git a/examples/haproxy/config.yaml b/examples/haproxy/config.yaml
index 0a8e318..b49eade 100644
--- a/examples/haproxy/config.yaml
+++ b/examples/haproxy/config.yaml
@@ -13,7 +13,8 @@ testdependecies:
 source: https://github.com/container-images/haproxy
 module:
     docker:
-        setup: cp -f my-haproxy.cfg local-haproxy.cfg
+        setup: cp -f my-haproxy.cfg local-haproxy.cfg;
+              sed s/127.0.0.1/$(hostname -i | egrep -o '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+')/ -i local-haproxy.cfg;
         start: "docker run -it -p 8077:80 -v $(pwd)/local-haproxy.cfg:/etc/haproxy/haproxy.cfg:Z"
         labels:
             description: "HAProxy is a TCP/HTTP reverse proxy which is particularly suited for high availability environments."

From ae552218d2c30b7b8dfc17591d7567eea795c7a4 Mon Sep 17 00:00:00 2001
From: Jan Scotka <jscotka@redhat.com>
Date: Apr 05 2017 08:09:30 +0000
Subject: [PATCH 3/6] more fixes of haproxy to be cleaner


---

diff --git a/examples/haproxy/config.yaml b/examples/haproxy/config.yaml
index b49eade..ed69dd7 100644
--- a/examples/haproxy/config.yaml
+++ b/examples/haproxy/config.yaml
@@ -14,7 +14,9 @@ source: https://github.com/container-images/haproxy
 module:
     docker:
         setup: cp -f my-haproxy.cfg local-haproxy.cfg;
-              sed s/127.0.0.1/$(hostname -i | egrep -o '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+')/ -i local-haproxy.cfg;
+              IPR=`ip r |grep default |cut -d ' ' -f 5`;
+              IPA=`ip a s dev $IPR |egrep -o 'inet [0-9.]+' |egrep -o [0-9.]+`;
+              sed s/127.0.0.1/$IPA/ -i local-haproxy.cfg;
         start: "docker run -it -p 8077:80 -v $(pwd)/local-haproxy.cfg:/etc/haproxy/haproxy.cfg:Z"
         labels:
             description: "HAProxy is a TCP/HTTP reverse proxy which is particularly suited for high availability environments."
@@ -22,7 +24,6 @@ module:
         container: docker.io/modularitycontainers/haproxy
     rpm:
         setup: cp -f my-haproxy.cfg local-haproxy.cfg;
-              sed s/127.0.0.1/$(hostname -i | egrep -o '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+')/ -i local-haproxy.cfg;
               sed -i 's/bind.*/bind :8077/' local-haproxy.cfg;
               cp local-haproxy.cfg /etc/haproxy/haproxy.cfg;
               semanage port -a -t http_port_t -p tcp 8001;

From a01324478b92e75a3f66ce45fea9d960387ff251 Mon Sep 17 00:00:00 2001
From: Jan Scotka <jscotka@redhat.com>
Date: Apr 05 2017 08:09:30 +0000
Subject: [PATCH 4/6] changes of haproxy


---

diff --git a/examples/haproxy/config.yaml b/examples/haproxy/config.yaml
index ed69dd7..048c785 100644
--- a/examples/haproxy/config.yaml
+++ b/examples/haproxy/config.yaml
@@ -10,6 +10,7 @@ packages:
 testdependecies:
     rpms:
         - nc
+        - docker
 source: https://github.com/container-images/haproxy
 module:
     docker:
diff --git a/examples/haproxy/simpleTest.py b/examples/haproxy/simpleTest.py
index 44ed28d..af2aee5 100644
--- a/examples/haproxy/simpleTest.py
+++ b/examples/haproxy/simpleTest.py
@@ -31,6 +31,7 @@ class simpleTests(module_framework.AvocadoTest):
     """
     def setUp(self):
         super(self.__class__, self).setUp()
+        self.runHost('systemctl start docker', ignore_status=True)
         self.runHost('docker pull docker.io/httpd')
         self.runHost('docker run --name http_name_8000 -d -p 8000:80 docker.io/httpd')
         self.runHost('docker run --name http_name_8001 -d -p 8001:80 docker.io/httpd')

From 64ea252132def594a2dc22182f2578f30cd080b1 Mon Sep 17 00:00:00 2001
From: Jan Scotka <jscotka@redhat.com>
Date: Apr 05 2017 08:29:10 +0000
Subject: [PATCH 5/6] changed to 127.0.0.1 instead of localhost


---

diff --git a/examples/haproxy/simpleTest.py b/examples/haproxy/simpleTest.py
index af2aee5..147623d 100644
--- a/examples/haproxy/simpleTest.py
+++ b/examples/haproxy/simpleTest.py
@@ -45,5 +45,5 @@ class simpleTests(module_framework.AvocadoTest):
 
     def testAssertIn(self):
         self.start()
-        self.assertIn('It works!',self.runHost('curl localhost:8077', shell = True).stdout)
+        self.assertIn('It works!',self.runHost('curl 127.0.0.1:8077', shell = True).stdout)
 

From 8d160efa567d8f114f8bd6ba98c62567cc6eafae Mon Sep 17 00:00:00 2001
From: Jan Scotka <jscotka@redhat.com>
Date: Apr 05 2017 10:24:19 +0000
Subject: [PATCH 6/6] added calling avocado service manager instead of starting manually via command


---

diff --git a/examples/haproxy/simpleTest.py b/examples/haproxy/simpleTest.py
index 147623d..2c0a156 100644
--- a/examples/haproxy/simpleTest.py
+++ b/examples/haproxy/simpleTest.py
@@ -23,6 +23,7 @@
 
 from moduleframework import module_framework
 import os
+from avocado.utils import service
 
 
 class simpleTests(module_framework.AvocadoTest):
@@ -31,7 +32,8 @@ class simpleTests(module_framework.AvocadoTest):
     """
     def setUp(self):
         super(self.__class__, self).setUp()
-        self.runHost('systemctl start docker', ignore_status=True)
+        service_manager = service.ServiceManager()
+        service_manager.start('docker')
         self.runHost('docker pull docker.io/httpd')
         self.runHost('docker run --name http_name_8000 -d -p 8000:80 docker.io/httpd')
         self.runHost('docker run --name http_name_8001 -d -p 8001:80 docker.io/httpd')

