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
1=== modified file 'awstrial/templates/cloud-init/info-callback'
2--- awstrial/templates/cloud-init/info-callback 2011-02-11 02:31:50 +0000
3+++ awstrial/templates/cloud-init/info-callback 2011-10-18 18:30:29 +0000
4@@ -22,7 +22,15 @@
5 process = Popen(['/bin/bash', '-c', dumpk, "dumpkey", iid], stdout=PIPE)
6 (pubkeys,err) = process.communicate()
7 if process.wait() != 0: raise Exception("dumpkey exit nonzero")
8+ {% if debug %}
9+ try:
10+ tdata = open('/var/log/instance-testing').read()
11+ pdata=urlencode({ 'instance-id' : iid, 'pubkeys' : pubkeys, 'testdata' : tdata })
12+ except IOError:
13+ pdata=urlencode({ 'instance-id' : iid, 'pubkeys' : pubkeys })
14+ {% else %}
15 pdata=urlencode({ 'instance-id' : iid, 'pubkeys' : pubkeys })
16+ {% endif %}
17 resp = urlopen(purl,pdata).read()
18 print "posted keys to %s. got: %s" % (purl,resp)
19 exit(0)
20
21=== modified file 'awstrial/templates/cloud-init/password-enable'
22--- awstrial/templates/cloud-init/password-enable 2010-10-08 20:02:24 +0000
23+++ awstrial/templates/cloud-init/password-enable 2011-10-18 18:30:29 +0000
24@@ -30,16 +30,21 @@
25 exit 0
26 fi
27
28-fail() { echo "$@" 1>&2; exit 1; }
29+fail() { echo "$@" 1>&2; echo "$@" >> /var/log/instance-testing; exit 1; }
30
31 pa_s="\(PasswordAuthentication[[:space:]]\+\)"
32
33 echo "${user}:${pass}" | chpasswd ||
34 fail "failed to chpasswd for ${user}"
35-passwd --expire "${user}" ||
36- fail "failed to expire password for ${user}"
37 sed -i "s,${pa_s}no,\1yes," /etc/ssh/sshd_config ||
38 fail "failed to switch chpasswd for ${user}"
39 restart ssh ||
40 fail "failed to restart ssh"
41+
42+{% if debug %}
43+# instance testing
44+expires=$(passwd --status ubuntu |awk '{print $5}')
45+echo "Password expires in $expires days" >> /var/log/instance-testing
46+{% endif %}
47+
48 exit 0
49
50=== modified file 'awstrial/templates/instance.html'
51--- awstrial/templates/instance.html 2011-10-12 14:10:24 +0000
52+++ awstrial/templates/instance.html 2011-10-18 18:30:29 +0000
53@@ -89,6 +89,13 @@
54 <p>The instance's SSH key fingerprint is</p>
55 <pre>
56 {{instance.pubkeys}}</pre>
57+
58+ {% if debug %}
59+ {% if instance.testdata %}
60+<p>Test Data:</p>
61+<pre>{{instance.testdata}}</pre>
62+ {% endif %}
63+ {% endif %}
64 {% endif %}
65 {% endif %}
66 {% endif %}
67
68=== modified file 'awstrial/trial/ec2_helper.py'
69--- awstrial/trial/ec2_helper.py 2011-09-29 13:56:47 +0000
70+++ awstrial/trial/ec2_helper.py 2011-10-18 18:30:29 +0000
71@@ -80,43 +80,43 @@
72 parts.append(
73 util.partItem(
74 render_to_string("import-launchpad-ssh-keys",
75- { 'launchpad_id' : lpid, 'password' : password } ),
76+ { 'debug' : settings.DEBUG, 'launchpad_id' : lpid, 'password' : password } ),
77 part_type=util.CI_SCRIPT, filename="10-launchpad-ssh-keys"))
78
79 callback_url = "%s/info_callback/%s" % (settings.BASE_URL, sec_key)
80 parts.append(
81 util.partItem(
82 render_to_string("info-callback",
83- { 'callback_url' : "%s/initial/" % callback_url } ),
84+ { 'debug' : settings.DEBUG, 'callback_url' : "%s/initial/" % callback_url } ),
85 part_type=util.CI_SCRIPT, filename="99-info-callback"))
86
87 parts.append(
88 util.partItem(
89 render_to_string("schedule-warnings",
90- { 'launch_time' : util.dtnow().strftime("%H:%M %Y-%m-%d UTC") } ),
91+ { 'debug' : settings.DEBUG, 'launch_time' : util.dtnow().strftime("%H:%M %Y-%m-%d UTC") } ),
92 part_type=util.CI_SCRIPT, filename="50-schedule-warnings"))
93
94 parts.append(
95 util.partItem(
96 render_to_string("log-login",
97- { 'callback_url' : "%s/login/" % callback_url }),
98+ { 'debug' : settings.DEBUG, 'callback_url' : "%s/login/" % callback_url }),
99 part_type=util.CI_BOOTHOOK, filename="50-log-login"))
100
101 parts.append(
102 util.partItem(
103- render_to_string("personal-hello", { 'launchpad_id' : lpid }),
104+ render_to_string("personal-hello", { 'debug' : settings.DEBUG, 'launchpad_id' : lpid }),
105 part_type=util.CI_SCRIPT, filename="50-personal-hello"))
106
107 parts.append(
108 util.partItem(
109 render_to_string("password-enable",
110- { 'user': 'ubuntu', 'password' : password }),
111+ { 'debug' : settings.DEBUG, 'user': 'ubuntu', 'password' : password }),
112 part_type=util.CI_SCRIPT, filename="55-password-enable"))
113
114 if str(byobu).lower() == "true":
115 parts.append(
116 util.partItem(
117- render_to_string("byobu-enable", { }),
118+ render_to_string("byobu-enable", { 'debug' : settings.DEBUG, }),
119 part_type=util.CI_BOOTHOOK, filename="byobu-enable"))
120 cust['byobu']=True
121
122@@ -132,7 +132,7 @@
123 if instcfg['template']:
124 parts.append(
125 util.partItem(
126- render_to_string(instcfg['template'], { }),
127+ render_to_string(instcfg['template'], { 'debug' : settings.DEBUG, }),
128 part_type=util.CI_CLOUDCONFIG, filename=instcfg['template']))
129
130 # Create the instance record in the database before creating it in ec2
131
132=== modified file 'awstrial/trial/info_callback.py'
133--- awstrial/trial/info_callback.py 2011-09-13 20:15:42 +0000
134+++ awstrial/trial/info_callback.py 2011-10-18 18:30:29 +0000
135@@ -59,6 +59,9 @@
136
137 inst.pubkeys = pubkeys
138 inst.ph_time = util.dtnow()
139+
140+ if settings.DEBUG and 'testdata' in request.POST:
141+ inst.testdata = request.POST.get('testdata', '')
142 inst.save()
143 return(HttpResponse("registered keys %s\n" % inst.instance_id))
144
145
146=== modified file 'awstrial/trial/models.py'
147--- awstrial/trial/models.py 2011-09-29 13:56:47 +0000
148+++ awstrial/trial/models.py 2011-10-18 18:30:29 +0000
149@@ -158,6 +158,15 @@
150 def remote_ips(self,val):
151 self._cfgval_set("remote_ips",val)
152
153+ @property
154+ def testdata(self):
155+ return(self._cfgval_get("testdata",None))
156+
157+ @testdata.setter
158+ def testdata(self,val):
159+ self._cfgval_set("testdata",val)
160+
161+
162 class Feedback(models.Model):
163 user = models.ForeignKey(User)
164 comment = models.TextField(verbose_name=_('Comments'))
165
166=== modified file 'awstrial/trial/tests.py'
167--- awstrial/trial/tests.py 2011-09-29 13:50:26 +0000
168+++ awstrial/trial/tests.py 2011-10-18 18:30:29 +0000
169@@ -20,6 +20,7 @@
170 # along with this program. If not, see <http://www.gnu.org/licenses/>.
171
172
173+import datetime
174 from unittest import TestCase as UnitTestCase
175 from django.test import TestCase as DjangoTestCase
176 from django.conf import settings
177@@ -158,3 +159,73 @@
178
179 response = call_run_instance()
180 self.assertEquals(1, Instances.objects.all().count())
181+
182+
183+class TestDataTestCase(DjangoTestCase):
184+ """
185+ Tests the calls to functions in the ec2_helper module
186+ """
187+ def setUp(self):
188+ settings.DEBUG = True
189+ self.campaign = Campaign.objects.create(
190+ name='test-campaign',
191+ verbose_name='Test Campaign',
192+ max_instances=5,
193+ active=True,
194+ )
195+
196+ self.user = User.objects.create_user('testuser', 'test@example.com', 'testpasswd')
197+ self.client.login(username='testuser', password='testpasswd')
198+
199+ def tearDown(self):
200+ settings.DEBUG = False
201+
202+ def test_info_callback(self):
203+ """
204+ Checks that testdata passed to the info callback will be stored
205+ """
206+ instance = Instances.objects.create(
207+ instance_id='i-00000001',
208+ campaign=self.campaign,
209+ owner=self.user,
210+ reservation_time=datetime.datetime.now(),
211+ running_time=datetime.datetime.now(),
212+ hostname='testing.localhost',
213+ ip='127.0.0.1',
214+ secret='12345678',
215+ )
216+ pdata = {
217+ 'instance-id': 'i-00000001',
218+ 'pubkeys': 'TSA: 12345678',
219+ 'testdata': 'Sample Test Data\n',
220+ }
221+ response = self.client.post('/info_callback/12345678/initial/', pdata)
222+ self.assertContains(response, 'registered keys')
223+
224+ instance = Instances.objects.get(instance_id='i-00000001')
225+ self.assertEquals('Sample Test Data\n', instance.testdata)
226+
227+ def test_display_in_instance_info(self):
228+ """
229+ Checks that an Instance's testdata is displayed on /instance_info/
230+ """
231+
232+ instance = Instances.objects.create(
233+ instance_id='i-00000001',
234+ campaign=self.campaign,
235+ owner=self.user,
236+ reservation_time=datetime.datetime.now(),
237+ running_time=datetime.datetime.now(),
238+ ph_time=datetime.datetime.now(),
239+ hostname='testing.localhost',
240+ ip='127.0.0.1',
241+ pubkeys='TSA: 1234567890',
242+ secret='12345678',
243+ )
244+ instance.testdata = "Sample Test Data\n"
245+ instance.save()
246+
247+ response = self.client.get('/test-campaign/instance_info/')
248+ self.assertContains(response, '<p>Test Data:</p>')
249+ self.assertContains(response, '<pre>Sample Test Data\n</pre>')
250+
251
252=== modified file 'awstrial/trial/views.py'
253--- awstrial/trial/views.py 2011-09-13 20:47:35 +0000
254+++ awstrial/trial/views.py 2011-10-18 18:30:29 +0000
255@@ -132,6 +132,7 @@
256 context = {
257 'instance': instance,
258 'config': instcfg,
259+ 'debug': settings.DEBUG,
260 }
261 context['cloudconfig']=None
262 if instcfg and instcfg['template']:

Subscribers

People subscribed via source and target branches