From 77a31d31b226e081b6dc9a1681f61aeb22a0926f Mon Sep 17 00:00:00 2001 From: Steven Dake Date: Mon, 17 Sep 2012 17:49:32 -0700 Subject: [PATCH] Implement test_AutoScalingMultiAZSample.py Fixes issue #200 Change-Id: Iaea2d01a9659c703986d009fb9c0605ba6d0279f Signed-off-by: Steven Dake --- .../test_AutoScalingMultiAZSample.py | 81 +++++++++++++++++++ heat/tests/functional/util.py | 7 ++ 2 files changed, 88 insertions(+) create mode 100644 heat/tests/functional/test_AutoScalingMultiAZSample.py diff --git a/heat/tests/functional/test_AutoScalingMultiAZSample.py b/heat/tests/functional/test_AutoScalingMultiAZSample.py new file mode 100644 index 0000000000..2bb644b6b3 --- /dev/null +++ b/heat/tests/functional/test_AutoScalingMultiAZSample.py @@ -0,0 +1,81 @@ +# 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 +from time import sleep + + +@attr(speed='slow') +@attr(tag=['func', 'autoscaling', 'AutoScalingMultiAZSample.template']) +class AutoScalingMultiAZSampleFunctionalTest(unittest.TestCase): + def setUp(self): + template = 'AutoScalingMultiAZSample.template' + + stack_paramstr = ';'.join(['InstanceType=m1.small', + 'DBUsername=dbuser', + 'DBPassword=' + os.environ['OS_PASSWORD']]) + + self.stack = util.Stack(template, 'F17', 'x86_64', 'cfntools', + stack_paramstr) + self.WebServerGroup0 = util.Instance('WebServerGroup-0') + + def tearDown(self): + pass + self.stack.cleanup() + + def test_instance(self): + self.stack.create() + self.WebServerGroup0.wait_for_boot() + self.WebServerGroup0.check_cfntools() + self.WebServerGroup0.wait_for_provisioning() + + # TODO: verify the code below tests the template properly + +# TODO(sdake) use a util exists function for nonexistent instances (needs dev) + # Trigger the load balancer by taking up memory + self.WebServerGroup0.exec_command('memhog -r100000 1500m') + + # Give the load balancer 2 minutes to react + sleep(2 * 60) + + self.WebServerGroup1 = util.Instance('WebServerGroup-1') + # Verify the second instance gets launched + self.assertTrue(self.WebServerGroup1.exists()) + self.WebServerGroup1.wait_for_boot() + self.WebServerGroup1.check_cfntools() + self.WebServerGroup1.wait_for_provisioning() + + # ensure wordpress was installed by checking for expected + # configuration file over ssh + self.assertTrue(self.WebServerGroup0.file_present + ('/etc/wordpress/wp-config.php')) + print "Wordpress installation detected on WSG0" + + # ensure wordpress was installed by checking for expected + # configuration file over ssh + self.assertTrue(self.WebServerGroup1.file_present + ('/etc/wordpress/wp-config.php')) + print "Wordpress installation detected on WSG1" + + # Verify the output URL parses as expected, ie check that + # the wordpress installation is operational + stack_url = self.stack.get_stack_output("URL") + print "Got stack output WebsiteURL=%s, verifying" % stack_url + ver = verify.VerifyStack() + self.assertTrue(ver.verify_wordpress(stack_url)) diff --git a/heat/tests/functional/util.py b/heat/tests/functional/util.py index e104c1bd96..1dd22728b4 100644 --- a/heat/tests/functional/util.py +++ b/heat/tests/functional/util.py @@ -154,6 +154,13 @@ class Instance(object): def exec_command(self, cmd): return self.ssh.exec_command(cmd) + def exists(self): + servers = self.novaclient.servers.list() + for server in servers: + if server.name == self.name: + return True + return False + def file_present(self, path): print "Verifying file '%s' exists" % path stdin, stdout, sterr = self.ssh.exec_command('ls "%s"' % path)