Add new OpenShift test

New utility functions added to add/remove host file entries.

Closes #204

Change-Id: I182b451a25e22a558d1b4073e981cdc826ab836d
Signed-off-by: Jeff Peeler <jpeeler@redhat.com>
This commit is contained in:
Jeff Peeler 2012-09-14 01:44:37 -04:00
parent e5ce50eaf3
commit 1650f849fb
2 changed files with 89 additions and 0 deletions

View File

@ -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)

View 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()