1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
3
# Licensed under the Apache License, Version 2.0 (the "License"); you may
4
# not use this file except in compliance with the License. You may obtain
5
# a copy of the License at
7
# http://www.apache.org/licenses/LICENSE-2.0
9
# Unless required by applicable law or agreed to in writing, software
10
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12
# License for the specific language governing permissions and limitations
18
from nose.plugins.attrib import attr
24
@attr(tag=['func', 'wordpress', 'HA', 'F17',
25
'WordPress_Single_Instance_With_IHA.template'])
26
class WordPressIHAFunctionalTest(unittest.TestCase):
28
template = 'WordPress_Single_Instance_With_IHA.template'
29
stack_paramstr = ';'.join(['InstanceType=m1.xlarge',
31
'DBPassword=' + os.environ['OS_PASSWORD']])
33
self.stack = util.Stack(self, template, 'F17', 'x86_64', 'cfntools',
35
self.WikiDatabase = util.Instance(self, 'WikiDatabase')
40
def test_instance(self):
42
self.WikiDatabase.wait_for_boot()
43
self.WikiDatabase.check_cfntools()
44
self.WikiDatabase.wait_for_provisioning()
46
# ensure wordpress was installed by checking for expected
47
# configuration file over ssh
48
wp_file = '/usr/share/wordpress/wp-config.php'
49
self.assertTrue(self.WikiDatabase.file_present(wp_file))
50
print "Wordpress installation detected"
52
# Verify the output URL parses as expected, ie check that
53
# the wordpress installation is operational
54
stack_url = self.stack.get_stack_output("WebsiteURL")
55
print "Got stack output WebsiteURL=%s, verifying" % stack_url
56
ver = verify.VerifyStack()
57
self.assertTrue(ver.verify_wordpress(stack_url))
59
# Save the instance physical resource ID
60
phys_res_ids = self.stack.instance_phys_ids()
61
self.assertEqual(len(phys_res_ids), 1)
62
print "Shutting down instance ID = %s" % phys_res_ids[0]
64
# Now shut down the instance via SSH, and wait for HA to reprovision
65
# note it may not come back on the same IP
66
stdin, stdout, stderr =\
67
self.WikiDatabase.exec_sudo_command('/sbin/halt')
69
# Now poll the stack events, as the current WikiDatabase instance
70
# should be replaced with a new one
71
# we can then prove the physical resource ID is different, and that
72
# wordpress is accessible on the new WikiDatabase instance
75
pollids = self.stack.instance_phys_ids()
76
print "Waiting for Instance to be replaced %s/%s %s" %\
78
if (len(pollids) == 2):
79
self.assertTrue(pollids[1] != phys_res_ids[0])
80
print "Instance replaced, new ID = %s" % pollids[1]
85
# Check we didn't timeout
86
self.assertTrue(tries < 500)
88
# Create a new Instance object and wait for boot
89
# It seems to be necessary to close the old WikiDatabase
90
# instance SSH transport, or paramiko throws an exception
91
# when the SSH daemon starts on the new instance if it comes
92
# up on the same IP address, suspect paramiko bug, TBC
93
self.WikiDatabase.close_ssh_client()
94
self.WikiDatabaseNew = util.Instance(self, 'WikiDatabase')
95
self.WikiDatabaseNew.wait_for_boot()
96
self.WikiDatabaseNew.check_cfntools()
97
self.WikiDatabaseNew.wait_for_provisioning()
99
# Re-check wordpress installation as for the first instance
100
self.assertTrue(self.WikiDatabaseNew.file_present(wp_file))
101
print "Wordpress installation detected on new instance"
103
# Verify the output URL parses as expected, ie check that
104
# the wordpress installation is operational
105
stack_url = self.stack.get_stack_output("WebsiteURL")
106
print "Got stack output WebsiteURL=%s, verifying" % stack_url
107
self.assertTrue(ver.verify_wordpress(stack_url))