Merge lp:~abentley/charmworld/restore-questions into lp:~juju-jitsu/charmworld/trunk

Proposed by Aaron Bentley
Status: Merged
Approved by: Aaron Bentley
Approved revision: 335
Merged at revision: 335
Proposed branch: lp:~abentley/charmworld/restore-questions
Merge into: lp:~juju-jitsu/charmworld/trunk
Diff against target: 281 lines (+187/-13)
6 files modified
Makefile (+3/-3)
charmworld/migrations/migrate.py (+5/-2)
charmworld/migrations/versions/011_ensure_category_questions.py (+15/-0)
charmworld/migrations/versions/tests/test_migrations.py (+18/-7)
charmworld/qa_questions.py (+145/-0)
setup.py (+1/-1)
To merge this branch: bzr merge lp:~abentley/charmworld/restore-questions
Reviewer Review Type Date Requested Status
Brad Crittenden (community) Approve
Review via email: mp+178753@code.launchpad.net

Commit message

Restore QA questions to migrations.

Description of the change

This branch restores the QA questions to the migrations. I had deleted them because they were old migrations. Most migrations describe a change to apply, so they can be deleted once no databases exist that lack the change. But the QA questions are a desired state, and so they must be applied to all databases, even new ones.

To post a comment you must log in.
Revision history for this message
Brad Crittenden (bac) wrote :

Hi Aaron, the code and tests look good to me. I found two typos, one legacy. Thanks.

typo: mirgrations
typo: comfigure

review: Approve
335. By Aaron Bentley

Fix typos.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Makefile'
2--- Makefile 2013-07-18 21:33:26 +0000
3+++ Makefile 2013-08-06 13:54:26 +0000
4@@ -91,17 +91,17 @@
5 # ###################
6
7 test: test.ini $(INI) bin/nosetests
8- $(NOSE) charmworld migrations
9+ $(NOSE) charmworld
10
11 testid: test.ini bin/nosetests
12 # Run specific nose id tests.
13 # To set up the index you must run `make testid` once to completion to
14 # setup the index. Then you can run a group of tests like:
15 # Call with `ID="3 5" make testid`
16- $(NOSE) -v -s -x --with-id $(ID) charmworld migrations
17+ $(NOSE) -v -s -x --with-id $(ID) charmworld
18
19 testdebug: test.ini bin/nosetests
20- $(NOSE) --with-id --pdb --pdb-failures charmworld migrations
21+ $(NOSE) --with-id --pdb --pdb-failures charmworld
22
23 check: clear_ini clean sysdeps install testid
24
25
26=== renamed directory 'migrations' => 'charmworld/migrations'
27=== modified file 'charmworld/migrations/migrate.py'
28--- migrations/migrate.py 2013-07-15 21:31:05 +0000
29+++ charmworld/migrations/migrate.py 2013-08-06 13:54:26 +0000
30@@ -389,6 +389,10 @@
31 print "Updated the datastore to version: {0}".format(new_version)
32
33
34+def get_migration_path():
35+ return join(abspath(dirname(__file__)), 'versions')
36+
37+
38 def main():
39 """Target for the console entry point."""
40 configure_logging()
41@@ -396,8 +400,7 @@
42 ini = get_ini()
43
44 # Add the migration path to the ini.
45- migration_path = join(abspath(dirname(__file__)), 'versions')
46- ini['migrations'] = migration_path
47+ ini['migrations'] = get_migration_path()
48
49 args.func(ini, args)
50
51
52=== added file 'charmworld/migrations/versions/011_ensure_category_questions.py'
53--- charmworld/migrations/versions/011_ensure_category_questions.py 1970-01-01 00:00:00 +0000
54+++ charmworld/migrations/versions/011_ensure_category_questions.py 2013-08-06 13:54:26 +0000
55@@ -0,0 +1,15 @@
56+# Copyright 2013 Canonical Ltd. This software is licensed under the
57+# GNU Affero General Public License version 3 (see the file LICENSE).
58+
59+from charmworld.qa_questions import iter_categories
60+
61+
62+def upgrade(db, index_client):
63+ """Update each category of questions from new_category_data.
64+
65+ This update elaborates on the 001_* migration. Subsequent qa form
66+ migrations can replace new_category_data and run this same method.
67+ """
68+ db.qa.drop()
69+ for category_dict in iter_categories():
70+ db.qa.insert(category_dict)
71
72=== modified file 'charmworld/migrations/versions/tests/test_migrations.py'
73--- migrations/versions/tests/test_migrations.py 2013-07-22 19:18:21 +0000
74+++ charmworld/migrations/versions/tests/test_migrations.py 2013-08-06 13:54:26 +0000
75@@ -6,8 +6,8 @@
76 )
77 from charmworld.models import CharmSource
78 from charmworld.testing import MongoTestBase
79-import migrations.migrate
80-from migrations.migrate import Versions
81+from charmworld.migrations import migrate
82+from charmworld.migrations.migrate import Versions
83
84
85 def fake():
86@@ -18,12 +18,12 @@
87
88 def setUp(self):
89 super(MigrationTestBase, self).setUp()
90- self.versions = Versions('migrations/versions/')
91- true_configure_logging = migrations.migrate.configure_logging
92- migrations.migrate.configure_logging = fake
93+ self.versions = Versions(migrate.get_migration_path())
94+ true_configure_logging = migrate.configure_logging
95+ migrate.configure_logging = fake
96 self.addCleanup(
97- setattr, migrations.migrate,
98- 'comfigure_logging', true_configure_logging)
99+ setattr, migrate,
100+ 'configure_logging', true_configure_logging)
101
102
103 class TestMigration010(MigrationTestBase):
104@@ -78,3 +78,14 @@
105 self.index_client.get('e')
106 self.assertEqual({'_id': 'e', 'config': ['a']},
107 self.db.charms.find_one({'_id': 'e'}))
108+
109+
110+class TestMigration011(MigrationTestBase):
111+
112+ def test_migration(self):
113+ self.use_index_client()
114+ source = CharmSource.from_request(self)
115+ self.assertItemsEqual([], self.db.qa.find())
116+ self.versions.run_migration(self.db, self.index_client,
117+ '011_ensure_category_questions.py')
118+ self.assertIn('reliable', [cat['name'] for cat in self.db.qa.find()])
119
120=== added file 'charmworld/qa_questions.py'
121--- charmworld/qa_questions.py 1970-01-01 00:00:00 +0000
122+++ charmworld/qa_questions.py 2013-08-06 13:54:26 +0000
123@@ -0,0 +1,145 @@
124+# Copyright 2012, 2013 Canonical Ltd. This software is licensed under the
125+# GNU Affero General Public License version 3 (see the file LICENSE).
126+
127+# -*- coding: utf-8 -*-
128+"""
129+Load qa questions into the collection for populating the scoring parts of
130+the quality assessment form.
131+
132+"""
133+
134+
135+def iter_categories():
136+ """Complete this function with work to be done for the migration/update.
137+
138+ db is the pymongo db instance for our datastore. Charms are in db.charms
139+ for instance.
140+ """
141+
142+ initial = [
143+ (
144+ u'reliable',
145+ u'Reliable',
146+ [
147+ (u'Check for integrity from upstream source', 1, u''),
148+ (u'Fail gracefully if upstream source goes missing', 1, u''),
149+ (u'Contain a suite of tests with the charm that pass', 1, u''),
150+ (u'Passes tests from Jenkins on jujucharms.com', 1, u''),
151+ ]
152+ ),
153+
154+ (
155+ u'secure',
156+ u'Secure',
157+ [
158+ (u'Contain a well tested AppArmor profile', 1, ''),
159+ (u'Conform to security policies of the charm store', 1,
160+ 'Tight access control'),
161+ (u"Doesn't run as root", 1, ''),
162+ (u'Per instance or service access control', 1, ''),
163+ ]
164+ ),
165+
166+ (
167+ u'flexible',
168+ u'Flexible',
169+ [
170+ (
171+ u'Contain opinionated tuning options', 1,
172+ u'Examples (depends on the service): "safe", "default",'
173+ ' "fast", "real fast, not so safe". Don\'t expose every'
174+ ' configuration, pick those that reflect real world usage.'
175+ ' Make it so I don\'t have to read the book.'
176+ ),
177+ (u'Use existing interfaces with other charms', 1,
178+ u'Highly relatable'),
179+ ]
180+ ),
181+
182+ (
183+ u'data_handling',
184+ u'Data Handling',
185+ [
186+ (u'Integrate data storage best practices', 1,
187+ u'Backups based on service usage'),
188+ (u"Handle the service's user data", 1, u'Version control'),
189+ (u"Handle the service's user data", 1,
190+ u'Automated snapshots and backup.'),
191+ ]
192+ ),
193+
194+ (
195+ u'scalable',
196+ u'Scaleable',
197+ [
198+ (u"Responds to add-unit based on the service's needs", 1,
199+ u'Configuration should not require additional steps to scale'
200+ ' horizontally'),
201+ (u'Be tested with a real workload, not just a synthetic'
202+ ' benchmark', 1, ''),
203+ (u'From upstream and existing devops practices for that'
204+ ' service', 1, ''),
205+ (u'Community peer reviewed', 1, ''),
206+ (u'Have a configure option for most performant configuration'
207+ ' if not the default', 1, ''),
208+ ]
209+ ),
210+
211+ (
212+ u'easy_deploy',
213+ u'Easy to Deploy',
214+ [
215+ (u'README with examples of use for a typical workload', 1, ''),
216+ (u'README with examples of use for workloads at scale', 1, ''),
217+ (u'README with examples of use recommend best-practice'
218+ ' relationships', 1, ''),
219+ (u'Allow installation from pure upstream source', 1, ''),
220+ (u'Allow installation from your local source', 1, ''),
221+ (u'Allow installation from PPA (if available)', 1, ''),
222+ (u'Allow installation from the Ubuntu repository', 1, ''),
223+ ]
224+ ),
225+
226+ (
227+ u'responsive',
228+ u'Responsive to DevOps Needs',
229+ [
230+ (u'Allow for easy upgrade via juju upgrade-charm', 1, ''),
231+ (u'Allow upgrading the service itself.', 1, ''),
232+ (u'Responsive to user bug reports and concerns', 1, ''),
233+ (u'Maintainable, easy to read and modify', 1, ''),
234+ ]
235+ ),
236+
237+ (
238+ u'upstream',
239+ u'Upstream Friendly',
240+ [
241+ (u'Follow upstream best practices', 1,
242+ u'Provide an option for a barebones "pure upstream"'
243+ ' configuration'),
244+ (u'Should go lock-step with deployment recommendations', 1,
245+ u'Provide tip-of-trunk testing if feasible'),
246+ (u'Fresh charm on release day!', 1, ''),
247+ (
248+ u"Endeavour to be upstream's recommended way to deploy"
249+ ' that service in the cloud (website mention or'
250+ ' something)', 1, ''
251+ ),
252+ ]
253+ ),
254+ ]
255+
256+ """Add the sample data into the db."""
257+ for cat in initial:
258+ category_dict = {
259+ 'name': cat[0],
260+ 'description': cat[1],
261+ 'questions': [{
262+ 'id': '{0}_{1}'.format(cat[0].lower(), i),
263+ 'description': q[0],
264+ 'points': q[1],
265+ 'extended_description': q[2]
266+ } for i, q in enumerate(cat[2])]
267+ }
268+ yield category_dict
269
270=== modified file 'setup.py'
271--- setup.py 2013-06-28 20:56:31 +0000
272+++ setup.py 2013-08-06 13:54:26 +0000
273@@ -36,7 +36,7 @@
274 enqueue = charmworld.jobs.lp:main
275 dequeue = charmworld.jobs.lp:dequeue
276 ingest-queued = charmworld.jobs.worker:main
277- migrations = migrations.migrate:main
278+ migrations = charmworld.migrations.migrate:main
279 es-update = charmworld.search:update_main
280 sync-index = charmworld.models:sync_index
281 [beaker.backends]

Subscribers

People subscribed via source and target branches