Merge lp:~anso/nova/smoketests_fixes into lp:~hudson-openstack/nova/trunk

Proposed by Vish Ishaya
Status: Merged
Approved by: Devin Carlen
Approved revision: 521
Merged at revision: 542
Proposed branch: lp:~anso/nova/smoketests_fixes
Merge into: lp:~hudson-openstack/nova/trunk
Diff against target: 149 lines (+92/-4)
2 files modified
smoketests/admin_smoketests.py (+8/-1)
smoketests/user_smoketests.py (+84/-3)
To merge this branch: bzr merge lp:~anso/nova/smoketests_fixes
Reviewer Review Type Date Requested Status
Devin Carlen (community) Approve
Review via email: mp+45321@code.launchpad.net

Description of the change

A few more changes to the smoeketests. Allows smoketests to find the nova package from the checkout. Adds smoketests for security groups. Also fixes a couple of typos.

To post a comment you must log in.
Revision history for this message
Devin Carlen (devcamcar) wrote :

lgtm

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'smoketests/admin_smoketests.py'
2--- smoketests/admin_smoketests.py 2010-11-04 22:50:23 +0000
3+++ smoketests/admin_smoketests.py 2011-01-06 01:54:58 +0000
4@@ -19,10 +19,17 @@
5 import os
6 import random
7 import sys
8-import time
9 import unittest
10 import zipfile
11
12+# If ../nova/__init__.py exists, add ../ to Python search path, so that
13+# it will override what happens to be installed in /usr/(local/)lib/python...
14+possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]),
15+ os.pardir,
16+ os.pardir))
17+if os.path.exists(os.path.join(possible_topdir, 'nova', '__init__.py')):
18+ sys.path.insert(0, possible_topdir)
19+
20 from nova import adminclient
21 from smoketests import flags
22 from smoketests import base
23
24=== modified file 'smoketests/user_smoketests.py'
25--- smoketests/user_smoketests.py 2010-11-04 22:50:23 +0000
26+++ smoketests/user_smoketests.py 2011-01-06 01:54:58 +0000
27@@ -24,6 +24,14 @@
28 import time
29 import unittest
30
31+# If ../nova/__init__.py exists, add ../ to Python search path, so that
32+# it will override what happens to be installed in /usr/(local/)lib/python...
33+possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]),
34+ os.pardir,
35+ os.pardir))
36+if os.path.exists(os.path.join(possible_topdir, 'nova', '__init__.py')):
37+ sys.path.insert(0, possible_topdir)
38+
39 from smoketests import flags
40 from smoketests import base
41
42@@ -40,6 +48,7 @@
43 TEST_PREFIX = 'test%s' % int (random.random()*1000000)
44 TEST_BUCKET = '%s_bucket' % TEST_PREFIX
45 TEST_KEY = '%s_key' % TEST_PREFIX
46+TEST_GROUP = '%s_group' % TEST_PREFIX
47 TEST_DATA = {}
48
49
50@@ -137,7 +146,7 @@
51 self.data['instance_id'] = reservation.instances[0].id
52
53 def test_003_instance_runs_within_60_seconds(self):
54- reservations = self.conn.get_all_instances([data['instance_id']])
55+ reservations = self.conn.get_all_instances([self.data['instance_id']])
56 instance = reservations[0].instances[0]
57 # allow 60 seconds to exit pending with IP
58 for x in xrange(60):
59@@ -207,7 +216,7 @@
60 def test_999_tearDown(self):
61 self.delete_key_pair(self.conn, TEST_KEY)
62 if self.data.has_key('instance_id'):
63- self.conn.terminate_instances([data['instance_id']])
64+ self.conn.terminate_instances([self.data['instance_id']])
65
66
67 class VolumeTests(UserSmokeTestCase):
68@@ -319,8 +328,80 @@
69 self.conn.delete_key_pair(TEST_KEY)
70
71
72+class SecurityGroupTests(UserSmokeTestCase):
73+
74+ def __public_instance_is_accessible(self):
75+ id_url = "latest/meta-data/instance-id"
76+ options = "-s --max-time 1"
77+ command = "curl %s %s/%s" % (options, self.data['public_ip'], id_url)
78+ instance_id = commands.getoutput(command).strip()
79+ if not instance_id:
80+ return False
81+ if instance_id != self.data['instance_id']:
82+ raise Exception("Wrong instance id")
83+ return True
84+
85+ def test_001_can_create_security_group(self):
86+ self.conn.create_security_group(TEST_GROUP, description='test')
87+
88+ groups = self.conn.get_all_security_groups()
89+ self.assertTrue(TEST_GROUP in [group.name for group in groups])
90+
91+ def test_002_can_launch_instance_in_security_group(self):
92+ self.create_key_pair(self.conn, TEST_KEY)
93+ reservation = self.conn.run_instances(FLAGS.test_image,
94+ key_name=TEST_KEY,
95+ security_groups=[TEST_GROUP],
96+ instance_type='m1.tiny')
97+
98+ self.data['instance_id'] = reservation.instances[0].id
99+
100+ def test_003_can_authorize_security_group_ingress(self):
101+ self.assertTrue(self.conn.authorize_security_group(TEST_GROUP,
102+ ip_protocol='tcp',
103+ from_port=80,
104+ to_port=80))
105+
106+ def test_004_can_access_instance_over_public_ip(self):
107+ result = self.conn.allocate_address()
108+ self.assertTrue(hasattr(result, 'public_ip'))
109+ self.data['public_ip'] = result.public_ip
110+
111+ result = self.conn.associate_address(self.data['instance_id'],
112+ self.data['public_ip'])
113+ start_time = time.time()
114+ while not self.__public_instance_is_accessible():
115+ # 1 minute to launch
116+ if time.time() - start_time > 60:
117+ raise Exception("Timeout")
118+ time.sleep(1)
119+
120+ def test_005_can_revoke_security_group_ingress(self):
121+ self.assertTrue(self.conn.revoke_security_group(TEST_GROUP,
122+ ip_protocol='tcp',
123+ from_port=80,
124+ to_port=80))
125+ start_time = time.time()
126+ while self.__public_instance_is_accessible():
127+ # 1 minute to teardown
128+ if time.time() - start_time > 60:
129+ raise Exception("Timeout")
130+ time.sleep(1)
131+
132+
133+ def test_999_tearDown(self):
134+ self.conn.delete_key_pair(TEST_KEY)
135+ self.conn.delete_security_group(TEST_GROUP)
136+ groups = self.conn.get_all_security_groups()
137+ self.assertFalse(TEST_GROUP in [group.name for group in groups])
138+ self.conn.terminate_instances([self.data['instance_id']])
139+ self.assertTrue(self.conn.release_address(self.data['public_ip']))
140+
141+
142 if __name__ == "__main__":
143 suites = {'image': unittest.makeSuite(ImageTests),
144 'instance': unittest.makeSuite(InstanceTests),
145- 'volume': unittest.makeSuite(VolumeTests)}
146+ 'security_group': unittest.makeSuite(SecurityGroupTests),
147+ 'volume': unittest.makeSuite(VolumeTests)
148+ }
149 sys.exit(base.run_tests(suites))