Merge lp:~mhall119/awstrial/fix-873023 into lp:awstrial

Proposed by Michael Hall
Status: Merged
Approved by: Matthew Nuzum
Approved revision: 262
Merged at revision: 260
Proposed branch: lp:~mhall119/awstrial/fix-873023
Merge into: lp:awstrial
Diff against target: 262 lines (+115/-11)
8 files modified
awstrial/templates/cloud-init/info-callback (+8/-0)
awstrial/templates/cloud-init/password-enable (+8/-3)
awstrial/templates/instance.html (+7/-0)
awstrial/trial/ec2_helper.py (+8/-8)
awstrial/trial/info_callback.py (+3/-0)
awstrial/trial/models.py (+9/-0)
awstrial/trial/tests.py (+71/-0)
awstrial/trial/views.py (+1/-0)
To merge this branch: bzr merge lp:~mhall119/awstrial/fix-873023
Reviewer Review Type Date Requested Status
Matthew Nuzum (community) Approve
Review via email: mp+79729@code.launchpad.net

Commit message

Adds instance-side test data collection framework, checks password expiration time when using password-auth

Description of the change

Adds instance-side test data collection framework, checks password expiration time when using password-auth.

http://awesomescreenshot.com/0e2mhjoe8

To post a comment you must log in.
Revision history for this message
Matthew Nuzum (newz) wrote :

Looks OK

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'awstrial/templates/cloud-init/info-callback'
--- awstrial/templates/cloud-init/info-callback 2011-02-11 02:31:50 +0000
+++ awstrial/templates/cloud-init/info-callback 2011-10-18 18:30:29 +0000
@@ -22,7 +22,15 @@
22 process = Popen(['/bin/bash', '-c', dumpk, "dumpkey", iid], stdout=PIPE)22 process = Popen(['/bin/bash', '-c', dumpk, "dumpkey", iid], stdout=PIPE)
23 (pubkeys,err) = process.communicate()23 (pubkeys,err) = process.communicate()
24 if process.wait() != 0: raise Exception("dumpkey exit nonzero")24 if process.wait() != 0: raise Exception("dumpkey exit nonzero")
25 {% if debug %}
26 try:
27 tdata = open('/var/log/instance-testing').read()
28 pdata=urlencode({ 'instance-id' : iid, 'pubkeys' : pubkeys, 'testdata' : tdata })
29 except IOError:
30 pdata=urlencode({ 'instance-id' : iid, 'pubkeys' : pubkeys })
31 {% else %}
25 pdata=urlencode({ 'instance-id' : iid, 'pubkeys' : pubkeys })32 pdata=urlencode({ 'instance-id' : iid, 'pubkeys' : pubkeys })
33 {% endif %}
26 resp = urlopen(purl,pdata).read()34 resp = urlopen(purl,pdata).read()
27 print "posted keys to %s. got: %s" % (purl,resp)35 print "posted keys to %s. got: %s" % (purl,resp)
28 exit(0)36 exit(0)
2937
=== modified file 'awstrial/templates/cloud-init/password-enable'
--- awstrial/templates/cloud-init/password-enable 2010-10-08 20:02:24 +0000
+++ awstrial/templates/cloud-init/password-enable 2011-10-18 18:30:29 +0000
@@ -30,16 +30,21 @@
30 exit 030 exit 0
31fi31fi
3232
33fail() { echo "$@" 1>&2; exit 1; }33fail() { echo "$@" 1>&2; echo "$@" >> /var/log/instance-testing; exit 1; }
3434
35pa_s="\(PasswordAuthentication[[:space:]]\+\)"35pa_s="\(PasswordAuthentication[[:space:]]\+\)"
3636
37echo "${user}:${pass}" | chpasswd ||37echo "${user}:${pass}" | chpasswd ||
38 fail "failed to chpasswd for ${user}"38 fail "failed to chpasswd for ${user}"
39passwd --expire "${user}" ||
40 fail "failed to expire password for ${user}"
41sed -i "s,${pa_s}no,\1yes," /etc/ssh/sshd_config ||39sed -i "s,${pa_s}no,\1yes," /etc/ssh/sshd_config ||
42 fail "failed to switch chpasswd for ${user}"40 fail "failed to switch chpasswd for ${user}"
43restart ssh ||41restart ssh ||
44 fail "failed to restart ssh"42 fail "failed to restart ssh"
43
44{% if debug %}
45# instance testing
46expires=$(passwd --status ubuntu |awk '{print $5}')
47echo "Password expires in $expires days" >> /var/log/instance-testing
48{% endif %}
49
45exit 050exit 0
4651
=== modified file 'awstrial/templates/instance.html'
--- awstrial/templates/instance.html 2011-10-12 14:10:24 +0000
+++ awstrial/templates/instance.html 2011-10-18 18:30:29 +0000
@@ -89,6 +89,13 @@
89<p>The instance's SSH key fingerprint is</p>89<p>The instance's SSH key fingerprint is</p>
90<pre>90<pre>
91{{instance.pubkeys}}</pre>91{{instance.pubkeys}}</pre>
92
93 {% if debug %}
94 {% if instance.testdata %}
95<p>Test Data:</p>
96<pre>{{instance.testdata}}</pre>
97 {% endif %}
98 {% endif %}
92 {% endif %}99 {% endif %}
93 {% endif %}100 {% endif %}
94{% endif %}101{% endif %}
95102
=== modified file 'awstrial/trial/ec2_helper.py'
--- awstrial/trial/ec2_helper.py 2011-09-29 13:56:47 +0000
+++ awstrial/trial/ec2_helper.py 2011-10-18 18:30:29 +0000
@@ -80,43 +80,43 @@
80 parts.append(80 parts.append(
81 util.partItem(81 util.partItem(
82 render_to_string("import-launchpad-ssh-keys",82 render_to_string("import-launchpad-ssh-keys",
83 { 'launchpad_id' : lpid, 'password' : password } ),83 { 'debug' : settings.DEBUG, 'launchpad_id' : lpid, 'password' : password } ),
84 part_type=util.CI_SCRIPT, filename="10-launchpad-ssh-keys"))84 part_type=util.CI_SCRIPT, filename="10-launchpad-ssh-keys"))
85 85
86 callback_url = "%s/info_callback/%s" % (settings.BASE_URL, sec_key)86 callback_url = "%s/info_callback/%s" % (settings.BASE_URL, sec_key)
87 parts.append(87 parts.append(
88 util.partItem(88 util.partItem(
89 render_to_string("info-callback",89 render_to_string("info-callback",
90 { 'callback_url' : "%s/initial/" % callback_url } ),90 { 'debug' : settings.DEBUG, 'callback_url' : "%s/initial/" % callback_url } ),
91 part_type=util.CI_SCRIPT, filename="99-info-callback"))91 part_type=util.CI_SCRIPT, filename="99-info-callback"))
9292
93 parts.append(93 parts.append(
94 util.partItem(94 util.partItem(
95 render_to_string("schedule-warnings",95 render_to_string("schedule-warnings",
96 { 'launch_time' : util.dtnow().strftime("%H:%M %Y-%m-%d UTC") } ),96 { 'debug' : settings.DEBUG, 'launch_time' : util.dtnow().strftime("%H:%M %Y-%m-%d UTC") } ),
97 part_type=util.CI_SCRIPT, filename="50-schedule-warnings"))97 part_type=util.CI_SCRIPT, filename="50-schedule-warnings"))
9898
99 parts.append(99 parts.append(
100 util.partItem(100 util.partItem(
101 render_to_string("log-login",101 render_to_string("log-login",
102 { 'callback_url' : "%s/login/" % callback_url }),102 { 'debug' : settings.DEBUG, 'callback_url' : "%s/login/" % callback_url }),
103 part_type=util.CI_BOOTHOOK, filename="50-log-login"))103 part_type=util.CI_BOOTHOOK, filename="50-log-login"))
104104
105 parts.append(105 parts.append(
106 util.partItem(106 util.partItem(
107 render_to_string("personal-hello", { 'launchpad_id' : lpid }),107 render_to_string("personal-hello", { 'debug' : settings.DEBUG, 'launchpad_id' : lpid }),
108 part_type=util.CI_SCRIPT, filename="50-personal-hello"))108 part_type=util.CI_SCRIPT, filename="50-personal-hello"))
109109
110 parts.append(110 parts.append(
111 util.partItem(111 util.partItem(
112 render_to_string("password-enable",112 render_to_string("password-enable",
113 { 'user': 'ubuntu', 'password' : password }),113 { 'debug' : settings.DEBUG, 'user': 'ubuntu', 'password' : password }),
114 part_type=util.CI_SCRIPT, filename="55-password-enable"))114 part_type=util.CI_SCRIPT, filename="55-password-enable"))
115115
116 if str(byobu).lower() == "true":116 if str(byobu).lower() == "true":
117 parts.append(117 parts.append(
118 util.partItem(118 util.partItem(
119 render_to_string("byobu-enable", { }),119 render_to_string("byobu-enable", { 'debug' : settings.DEBUG, }),
120 part_type=util.CI_BOOTHOOK, filename="byobu-enable"))120 part_type=util.CI_BOOTHOOK, filename="byobu-enable"))
121 cust['byobu']=True121 cust['byobu']=True
122122
@@ -132,7 +132,7 @@
132 if instcfg['template']:132 if instcfg['template']:
133 parts.append(133 parts.append(
134 util.partItem(134 util.partItem(
135 render_to_string(instcfg['template'], { }),135 render_to_string(instcfg['template'], { 'debug' : settings.DEBUG, }),
136 part_type=util.CI_CLOUDCONFIG, filename=instcfg['template']))136 part_type=util.CI_CLOUDCONFIG, filename=instcfg['template']))
137137
138 # Create the instance record in the database before creating it in ec2138 # Create the instance record in the database before creating it in ec2
139139
=== modified file 'awstrial/trial/info_callback.py'
--- awstrial/trial/info_callback.py 2011-09-13 20:15:42 +0000
+++ awstrial/trial/info_callback.py 2011-10-18 18:30:29 +0000
@@ -59,6 +59,9 @@
5959
60 inst.pubkeys = pubkeys60 inst.pubkeys = pubkeys
61 inst.ph_time = util.dtnow()61 inst.ph_time = util.dtnow()
62
63 if settings.DEBUG and 'testdata' in request.POST:
64 inst.testdata = request.POST.get('testdata', '')
62 inst.save()65 inst.save()
63 return(HttpResponse("registered keys %s\n" % inst.instance_id))66 return(HttpResponse("registered keys %s\n" % inst.instance_id))
6467
6568
=== modified file 'awstrial/trial/models.py'
--- awstrial/trial/models.py 2011-09-29 13:56:47 +0000
+++ awstrial/trial/models.py 2011-10-18 18:30:29 +0000
@@ -158,6 +158,15 @@
158 def remote_ips(self,val):158 def remote_ips(self,val):
159 self._cfgval_set("remote_ips",val)159 self._cfgval_set("remote_ips",val)
160160
161 @property
162 def testdata(self):
163 return(self._cfgval_get("testdata",None))
164
165 @testdata.setter
166 def testdata(self,val):
167 self._cfgval_set("testdata",val)
168
169
161class Feedback(models.Model):170class Feedback(models.Model):
162 user = models.ForeignKey(User)171 user = models.ForeignKey(User)
163 comment = models.TextField(verbose_name=_('Comments'))172 comment = models.TextField(verbose_name=_('Comments'))
164173
=== modified file 'awstrial/trial/tests.py'
--- awstrial/trial/tests.py 2011-09-29 13:50:26 +0000
+++ awstrial/trial/tests.py 2011-10-18 18:30:29 +0000
@@ -20,6 +20,7 @@
20# along with this program. If not, see <http://www.gnu.org/licenses/>.20# along with this program. If not, see <http://www.gnu.org/licenses/>.
2121
2222
23import datetime
23from unittest import TestCase as UnitTestCase24from unittest import TestCase as UnitTestCase
24from django.test import TestCase as DjangoTestCase25from django.test import TestCase as DjangoTestCase
25from django.conf import settings26from django.conf import settings
@@ -158,3 +159,73 @@
158 159
159 response = call_run_instance()160 response = call_run_instance()
160 self.assertEquals(1, Instances.objects.all().count())161 self.assertEquals(1, Instances.objects.all().count())
162
163
164class TestDataTestCase(DjangoTestCase):
165 """
166 Tests the calls to functions in the ec2_helper module
167 """
168 def setUp(self):
169 settings.DEBUG = True
170 self.campaign = Campaign.objects.create(
171 name='test-campaign',
172 verbose_name='Test Campaign',
173 max_instances=5,
174 active=True,
175 )
176
177 self.user = User.objects.create_user('testuser', 'test@example.com', 'testpasswd')
178 self.client.login(username='testuser', password='testpasswd')
179
180 def tearDown(self):
181 settings.DEBUG = False
182
183 def test_info_callback(self):
184 """
185 Checks that testdata passed to the info callback will be stored
186 """
187 instance = Instances.objects.create(
188 instance_id='i-00000001',
189 campaign=self.campaign,
190 owner=self.user,
191 reservation_time=datetime.datetime.now(),
192 running_time=datetime.datetime.now(),
193 hostname='testing.localhost',
194 ip='127.0.0.1',
195 secret='12345678',
196 )
197 pdata = {
198 'instance-id': 'i-00000001',
199 'pubkeys': 'TSA: 12345678',
200 'testdata': 'Sample Test Data\n',
201 }
202 response = self.client.post('/info_callback/12345678/initial/', pdata)
203 self.assertContains(response, 'registered keys')
204
205 instance = Instances.objects.get(instance_id='i-00000001')
206 self.assertEquals('Sample Test Data\n', instance.testdata)
207
208 def test_display_in_instance_info(self):
209 """
210 Checks that an Instance's testdata is displayed on /instance_info/
211 """
212
213 instance = Instances.objects.create(
214 instance_id='i-00000001',
215 campaign=self.campaign,
216 owner=self.user,
217 reservation_time=datetime.datetime.now(),
218 running_time=datetime.datetime.now(),
219 ph_time=datetime.datetime.now(),
220 hostname='testing.localhost',
221 ip='127.0.0.1',
222 pubkeys='TSA: 1234567890',
223 secret='12345678',
224 )
225 instance.testdata = "Sample Test Data\n"
226 instance.save()
227
228 response = self.client.get('/test-campaign/instance_info/')
229 self.assertContains(response, '<p>Test Data:</p>')
230 self.assertContains(response, '<pre>Sample Test Data\n</pre>')
231
161232
=== modified file 'awstrial/trial/views.py'
--- awstrial/trial/views.py 2011-09-13 20:47:35 +0000
+++ awstrial/trial/views.py 2011-10-18 18:30:29 +0000
@@ -132,6 +132,7 @@
132 context = {132 context = {
133 'instance': instance,133 'instance': instance,
134 'config': instcfg,134 'config': instcfg,
135 'debug': settings.DEBUG,
135 }136 }
136 context['cloudconfig']=None137 context['cloudconfig']=None
137 if instcfg and instcfg['template']:138 if instcfg and instcfg['template']:

Subscribers

People subscribed via source and target branches