]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
Add new OpenShift test
authorJeff Peeler <jpeeler@redhat.com>
Fri, 14 Sep 2012 05:44:37 +0000 (01:44 -0400)
committerJeff Peeler <jpeeler@redhat.com>
Fri, 14 Sep 2012 15:02:32 +0000 (11:02 -0400)
New utility functions added to add/remove host file entries.

Closes #204

Change-Id: I182b451a25e22a558d1b4073e981cdc826ab836d
Signed-off-by: Jeff Peeler <jpeeler@redhat.com>
heat/tests/functional/test_OpenShift_Prebuilt_JEOS.py [new file with mode: 0644]
heat/tests/functional/util.py

diff --git a/heat/tests/functional/test_OpenShift_Prebuilt_JEOS.py b/heat/tests/functional/test_OpenShift_Prebuilt_JEOS.py
new file mode 100644 (file)
index 0000000..bf06fb8
--- /dev/null
@@ -0,0 +1,66 @@
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
+#
+#    Licensed under the Apache License, Version 2.0 (the "License"); you may
+#    not use this file except in compliance with the License. You may obtain
+#    a copy of the License at
+#
+#         http://www.apache.org/licenses/LICENSE-2.0
+#
+#    Unless required by applicable law or agreed to in writing, software
+#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+#    License for the specific language governing permissions and limitations
+#
+
+import util
+import verify
+import nose
+from nose.plugins.attrib import attr
+import unittest
+import os
+
+
+@attr(speed='slow')
+@attr(tag=['func', 'openshift', 'OpenShift_Prebuilt_JEOS.template'])
+class OpenShiftFunctionalTest(unittest.TestCase):
+
+    def tearDown(self):
+        self.stack.cleanup()
+
+    def setUp(self):
+        template = 'OpenShift_Prebuilt_JEOS.template'
+        stack_paramstr = ';'.join(['InstanceType=m1.xlarge'])
+
+        self.stack = util.Stack(template, 'F16', 'x86_64',
+                'cfntools-openshift', stack_paramstr)
+
+        self.Node = util.Instance('OpenShiftNodeServer')
+        self.Broker = util.Instance('OpenShiftBrokerServer')
+
+    def test_instance(self):
+        self.stack.create()
+        self.Broker.wait_for_boot()
+        self.Node.wait_for_boot()
+        self.Node.check_cfntools()
+        self.Broker.check_cfntools()
+        self.Node.wait_for_provisioning()
+        self.Broker.wait_for_provisioning()
+
+        # ensure wordpress was installed by checking for expected
+        # configuration file over ssh
+        self.assertTrue(self.Broker.file_present
+                        ('/etc/sysconfig/stickshift-broker'))
+        print 'OpenShift installation detected'
+
+        # must change ip lookup so apache rewrite works properly
+        openshift_host = 'hello-admin.example.com'
+        util.add_host(self.Broker.ip, openshift_host)
+
+        # Verify the output URL parses as expected, ie check that
+        # the openshift installation is operational with the deployed hello app
+        stack_url = 'https://' + openshift_host
+        print 'Verifying URL=%s' % stack_url
+        ver = verify.VerifyStack()
+        self.assertTrue(ver.verify_openshift(stack_url))
+
+        util.remove_host(self.Broker.ip, openshift_host)
index ed1f656deb679092225278d12471cd2f301cf466..6a92c664264e34b0ede74d32025316b8cbd6910c 100644 (file)
@@ -24,6 +24,8 @@ import json
 import time  # for sleep
 import nose
 import errno
+import tempfile
+import stat
 from pkg_resources import resource_string
 from lxml import etree
 
@@ -568,6 +570,27 @@ class StackBoto(Stack):
                 return o.value
 
 
+def add_host(ip, hostname):
+    with open('/etc/hosts', 'a') as hostfile:
+        hostfile.write(ip + '\t' + hostname)
+
+
+def remove_host(ip, hostname):
+    data = None
+    with open('/etc/hosts', 'r') as hostfile:
+        data = hostfile.readlines()
+
+    perms = stat.S_IMODE(os.stat('/etc/hosts').st_mode)
+
+    with tempfile.NamedTemporaryFile('w', dir='/etc', delete=False) as tmp:
+        for line in data:
+            if line.rstrip() == ip + '\t' + hostname:
+                continue
+            tmp.write(line)
+        os.chmod(tmp.name, perms)
+        os.rename(tmp.name, '/etc/hosts')
+
+
 if __name__ == '__main__':
     sys.argv.append(__file__)
     nose.main()