Merge lp:~pwlars/lava-test/results into lp:lava-test/0.0

Proposed by Paul Larson
Status: Merged
Merged at revision: 25
Proposed branch: lp:~pwlars/lava-test/results
Merge into: lp:lava-test/0.0
Diff against target: 536 lines (+278/-55)
10 files modified
abrek/builtins.py (+10/-15)
abrek/command.py (+5/-2)
abrek/config.py (+1/-0)
abrek/main.py (+1/-0)
abrek/results.py (+111/-0)
abrek/testdef.py (+4/-0)
tests/__init__.py (+2/-1)
tests/faketests.py (+47/-0)
tests/test_builtins.py (+2/-37)
tests/test_results.py (+95/-0)
To merge this branch: bzr merge lp:~pwlars/lava-test/results
Reviewer Review Type Date Requested Status
Paul Larson (community) Needs Resubmitting
James Westby (community) Needs Fixing
Review via email: mp+33593@code.launchpad.net

Description of the change

  Make a new 'results' module for abrek that contains the subcommands:
   * list
   * rm
   * rename
   * show

  This changes a single command (list-results to results list) and extends
  functionality to further operate on locally stored results

To post a comment you must log in.
Revision history for this message
James Westby (james-w) wrote :

17 - test = abrek.testdef.testloader(testdata['testname'])
18 + test = abrek.testdef.testloader(testdata['test_id'])

This looks unrelated to the other changes in the branch.

Is there a test for it?

57 + from abrek import (builtins, results)

No need for brackets there.

Two lines between classes in the new files please.

Has the set_config to fake the config, or the stdout capturing been
done in other tests?

I would also appreciate tests for failure modes in the non-rename
cases.

Thanks,

James

review: Needs Fixing
lp:~pwlars/lava-test/results updated
27. By Paul Larson

remove unneeded parens

28. By Paul Larson

style change, add extra blank line between classes

29. By Paul Larson

Handle calling results show for a result that doesn't exist

30. By Paul Larson

Change error message for consistency

31. By Paul Larson

* Split out the FakeConfigTests and FakeOutputTests
* Add several more tests to cover failure cases for results command

Revision history for this message
Paul Larson (pwlars) wrote :

On Wed, 2010-08-25 at 14:13 +0000, James Westby wrote:
> Review: Needs Fixing
> 17 - test = abrek.testdef.testloader(testdata['testname'])
> 18 + test = abrek.testdef.testloader(testdata['test_id'])
>
> This looks unrelated to the other changes in the branch.
Yep, I forgot to check it in separately. It's in that parse command
that I use for testing output. The format changed a while back, and
it's one place I missed the change. I plan on removing it eventually,
though I've thought about perhaps keeping it in some form. I'm thinking
when I get through some of the important things I need to add, I may
come back and add a --json or something like that to the results output,
that would spit out the bundle in json as it would be submitted to the
dashboard. I'll add tests for it when that happens. For now, this is
not something that would typically be used when running abrek under
normal conditions.

> 57 + from abrek import (builtins, results)
>
> No need for brackets there.
Fixed

> Two lines between classes in the new files please.
Fixed, and I went ahead and did it for other files as well (sorry if it
increased the diff size, but those should just show up as blank lines in
the patch, so easy to skip past I'm thinking)

> Has the set_config to fake the config, or the stdout capturing been
> done in other tests?
I split off FakeConfigTests and FakeOutputTests into a separate file for
both of those tests to import, since it's used in more than one place
now.

> I would also appreciate tests for failure modes in the non-rename
> cases.
Done

Revision history for this message
Paul Larson (pwlars) :
review: Needs Resubmitting

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'abrek/builtins.py'
2--- abrek/builtins.py 2010-08-18 15:33:32 +0000
3+++ abrek/builtins.py 2010-08-26 20:53:40 +0000
4@@ -20,6 +20,8 @@
5
6 import abrek.command
7 import abrek.testdef
8+from abrek.config import get_config
9+from abrek.utils import read_file
10
11
12 class cmd_version(abrek.command.AbrekCmd):
13@@ -30,6 +32,7 @@
14 import abrek
15 print abrek.__version__
16
17+
18 class cmd_help(abrek.command.AbrekCmd):
19 """ Get help on abrek commands
20
21@@ -52,6 +55,7 @@
22 else:
23 print "No command found for '%s'" % self.args[0]
24
25+
26 class cmd_install(abrek.command.AbrekCmd):
27 """
28 Install a test
29@@ -69,6 +73,7 @@
30 print "Test installation error: %s" % strerror
31 sys.exit(1)
32
33+
34 class cmd_run(abrek.command.AbrekCmd):
35 """
36 Run tests
37@@ -86,6 +91,7 @@
38 print "Test execution error: %s" % strerror
39 sys.exit(1)
40
41+
42 class cmd_parse(abrek.command.AbrekCmd):
43 def run(self):
44 if len(self.args) != 1:
45@@ -95,7 +101,7 @@
46 resultsdir = os.path.join(config.resultsdir,self.args[0])
47 testdatafile = os.path.join(resultsdir,"testdata.json")
48 testdata = json.loads(file(testdatafile,'r').read())
49- test = abrek.testdef.testloader(testdata['testname'])
50+ test = abrek.testdef.testloader(testdata['test_id'])
51 try:
52 test.parse(self.args[0])
53 except Exception as strerror:
54@@ -103,6 +109,7 @@
55 sys.exit(1)
56 print test.parser.results
57
58+
59 class cmd_uninstall(abrek.command.AbrekCmd):
60 """
61 Uninstall a test
62@@ -120,12 +127,12 @@
63 print "Test uninstall error: %s" % strerror
64 sys.exit(1)
65
66+
67 class cmd_list_installed(abrek.command.AbrekCmd):
68 """
69 List tests that are currently installed
70 """
71 def run(self):
72- from abrek.config import get_config
73 config = get_config()
74 print "Installed tests:"
75 try:
76@@ -134,6 +141,7 @@
77 except OSError:
78 print "No tests installed"
79
80+
81 class cmd_list_tests(abrek.command.AbrekCmd):
82 """
83 List all known tests
84@@ -145,16 +153,3 @@
85 for importer, mod, ispkg in walk_packages(test_definitions.__path__):
86 print mod
87
88-class cmd_list_results(abrek.command.AbrekCmd):
89- """
90- List results of previous runs
91- """
92- def run(self):
93- from abrek.config import get_config
94- config = get_config()
95- print "Saved results:"
96- try:
97- for dir in os.listdir(config.resultsdir):
98- print dir
99- except OSError:
100- print "No results found"
101
102=== modified file 'abrek/command.py'
103--- abrek/command.py 2010-08-18 15:33:32 +0000
104+++ abrek/command.py 2010-08-26 20:53:40 +0000
105@@ -15,6 +15,7 @@
106
107 from optparse import OptionParser
108
109+
110 class _AbrekOptionParser(OptionParser):
111 """
112 This is just to override the epilog formatter to allow newlines
113@@ -22,6 +23,7 @@
114 def format_epilog(self, formatter):
115 return self.epilog
116
117+
118 class AbrekCmd(object):
119 """ Base class for commands that can be passed to Abrek.
120
121@@ -115,8 +117,9 @@
122 return cmds
123
124 def get_all_cmds():
125- import abrek.builtins
126- cmds = _find_commands(abrek.builtins)
127+ from abrek import builtins, results
128+ cmds = _find_commands(builtins)
129+ cmds.update(_find_commands(results))
130 return cmds
131
132 def get_command(cmd_name):
133
134=== modified file 'abrek/config.py'
135--- abrek/config.py 2010-08-18 15:33:32 +0000
136+++ abrek/config.py 2010-08-26 20:53:40 +0000
137@@ -15,6 +15,7 @@
138
139 import os
140
141+
142 class AbrekConfig(object):
143 def __init__(self):
144 home = os.environ.get('HOME', '/')
145
146=== modified file 'abrek/main.py'
147--- abrek/main.py 2010-08-18 15:33:32 +0000
148+++ abrek/main.py 2010-08-26 20:53:40 +0000
149@@ -16,6 +16,7 @@
150 import sys
151 import abrek.command
152
153+
154 def main(argv=None):
155 if argv is None:
156 argv = sys.argv[1:]
157
158=== added file 'abrek/results.py'
159--- abrek/results.py 1970-01-01 00:00:00 +0000
160+++ abrek/results.py 2010-08-26 20:53:40 +0000
161@@ -0,0 +1,111 @@
162+# Copyright (c) 2010 Linaro
163+#
164+# This program is free software: you can redistribute it and/or modify
165+# it under the terms of the GNU General Public License as published by
166+# the Free Software Foundation, either version 3 of the License, or
167+# (at your option) any later version.
168+#
169+# This program is distributed in the hope that it will be useful,
170+# but WITHOUT ANY WARRANTY; without even the implied warranty of
171+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
172+# GNU General Public License for more details.
173+#
174+# You should have received a copy of the GNU General Public License
175+# along with this program. If not, see <http://www.gnu.org/licenses/>.
176+
177+import os
178+import shutil
179+import sys
180+from optparse import make_option
181+
182+from abrek.command import AbrekCmd
183+from abrek.config import get_config
184+from abrek.utils import read_file
185+
186+
187+class subcmd_results_list(AbrekCmd):
188+ """
189+ List results of previous runs
190+ """
191+ def run(self):
192+ config = get_config()
193+ print "Saved results:"
194+ try:
195+ for dir in os.listdir(config.resultsdir):
196+ print dir
197+ except OSError:
198+ print "No results found"
199+
200+
201+class subcmd_results_show(AbrekCmd):
202+ """
203+ Display the output from a previous test run
204+ """
205+ arglist = ['*result']
206+ def run(self):
207+ if len(self.args) != 1:
208+ print "please specify the name of the result dir"
209+ sys.exit(1)
210+ config = get_config()
211+ resultsdir = os.path.join(config.resultsdir,self.args[0])
212+ testoutput = os.path.join(resultsdir,"testoutput.log")
213+ if not os.path.exists(testoutput):
214+ print "No result found for '%s'" % self.args[0]
215+ sys.exit(1)
216+ print(read_file(testoutput))
217+
218+
219+class subcmd_results_remove(AbrekCmd):
220+ """
221+ Remove the results of a previous test run
222+ """
223+ arglist = ['*result']
224+ options = [make_option('-f', '--force', action='store_true',
225+ dest='force')]
226+ def run(self):
227+ if len(self.args) != 1:
228+ print "please specify the name of the result dir"
229+ sys.exit(1)
230+ config = get_config()
231+ resultsdir = os.path.join(config.resultsdir,self.args[0])
232+ if not os.path.exists(resultsdir):
233+ print "No result found for '%s'" % self.args[0]
234+ sys.exit(1)
235+ if not self.opts.force:
236+ print "Delete result '%s' for good? [Y/N]" % self.args[0],
237+ response = raw_input()
238+ if response[0].upper() != 'Y':
239+ sys.exit(0)
240+ shutil.rmtree(resultsdir)
241+
242+
243+class subcmd_results_rename(AbrekCmd):
244+ """
245+ Rename the results from a previous test run
246+ """
247+ arglist = ['*source', '*destination']
248+
249+ def run(self):
250+ if len(self.args) != 2:
251+ print "please specify the name of the result, and the new name"
252+ sys.exit(1)
253+ config = get_config()
254+ srcdir = os.path.join(config.resultsdir,self.args[0])
255+ destdir = os.path.join(config.resultsdir,self.args[1])
256+ if not os.path.exists(srcdir):
257+ print "Result directory not found"
258+ sys.exit(1)
259+ if os.path.exists(destdir):
260+ print "Destination result name already exists"
261+ sys.exit(1)
262+ shutil.move(srcdir, destdir)
263+
264+
265+class cmd_results(AbrekCmd):
266+ """
267+ Operate on results of previous test runs stored locally
268+ """
269+ subcmds = {'list':subcmd_results_list(),
270+ 'rm':subcmd_results_remove(),
271+ 'rename':subcmd_results_rename(),
272+ 'show':subcmd_results_show()}
273
274=== modified file 'abrek/testdef.py'
275--- abrek/testdef.py 2010-08-18 15:33:32 +0000
276+++ abrek/testdef.py 2010-08-26 20:53:40 +0000
277@@ -29,6 +29,7 @@
278 from abrek import hwprofile
279 from abrek import swprofile
280
281+
282 class AbrekTest(object):
283 """Base class for defining tests.
284
285@@ -124,6 +125,7 @@
286 os.chdir(self.resultsdir)
287 self.parser.parse()
288
289+
290 class AbrekTestInstaller(object):
291 """Base class for defining an installer object.
292
293@@ -182,6 +184,7 @@
294 self._download()
295 self._runsteps()
296
297+
298 class AbrekTestRunner(object):
299 """Base class for defining an test runner object.
300
301@@ -209,6 +212,7 @@
302 self._runsteps(resultsdir)
303 self.endtime = datetime.utcnow()
304
305+
306 class AbrekTestParser(object):
307 """Base class for defining a test parser
308
309
310=== modified file 'tests/__init__.py'
311--- tests/__init__.py 2010-08-18 15:33:32 +0000
312+++ tests/__init__.py 2010-08-26 20:53:40 +0000
313@@ -22,7 +22,8 @@
314 'tests.test_abrektestrunner',
315 'tests.test_abrektestparser',
316 'tests.test_swprofile',
317- 'tests.test_hwprofile']
318+ 'tests.test_hwprofile',
319+ 'tests.test_results']
320 loader = unittest.TestLoader()
321 suite = loader.loadTestsFromNames(module_names)
322 return suite
323
324=== added file 'tests/faketests.py'
325--- tests/faketests.py 1970-01-01 00:00:00 +0000
326+++ tests/faketests.py 2010-08-26 20:53:40 +0000
327@@ -0,0 +1,47 @@
328+# Copyright (c) 2010 Linaro
329+#
330+# This program is free software: you can redistribute it and/or modify
331+# it under the terms of the GNU General Public License as published by
332+# the Free Software Foundation, either version 3 of the License, or
333+# (at your option) any later version.
334+#
335+# This program is distributed in the hope that it will be useful,
336+# but WITHOUT ANY WARRANTY; without even the implied warranty of
337+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
338+# GNU General Public License for more details.
339+#
340+# You should have received a copy of the GNU General Public License
341+# along with this program. If not, see <http://www.gnu.org/licenses/>.
342+
343+import os
344+import shutil
345+import sys
346+import tempfile
347+import unittest
348+import StringIO
349+
350+from abrek.config import set_config
351+
352+class FakeOutputTests(unittest.TestCase):
353+ def setUp(self):
354+ self.origstdout = sys.stdout
355+ sys.stdout = self.fakestdout = StringIO.StringIO()
356+
357+ def tearDown(self):
358+ sys.stdout = self.origstdout
359+
360+class FakeConfigTests(FakeOutputTests):
361+ def setUp(self):
362+ super(FakeConfigTests, self).setUp()
363+ class fakeconfig:
364+ def __init__(self, basedir):
365+ self.configdir = os.path.join(basedir, "config")
366+ self.installdir = os.path.join(basedir, "install")
367+ self.resultsdir = os.path.join(basedir, "results")
368+ self.tmpdir = tempfile.mkdtemp()
369+ self.config = fakeconfig(self.tmpdir)
370+ set_config(self.config)
371+
372+ def tearDown(self):
373+ super(FakeConfigTests, self).tearDown()
374+ shutil.rmtree(self.tmpdir)
375
376=== modified file 'tests/test_builtins.py'
377--- tests/test_builtins.py 2010-08-18 15:33:32 +0000
378+++ tests/test_builtins.py 2010-08-26 20:53:40 +0000
379@@ -14,22 +14,9 @@
380 # along with this program. If not, see <http://www.gnu.org/licenses/>.
381
382 import os
383-import shutil
384-import sys
385-import tempfile
386-import unittest
387-import StringIO
388
389 import abrek.builtins
390-from abrek.config import set_config
391-
392-class FakeOutputTests(unittest.TestCase):
393- def setUp(self):
394- self.origstdout = sys.stdout
395- sys.stdout = self.fakestdout = StringIO.StringIO()
396-
397- def tearDown(self):
398- sys.stdout = self.origstdout
399+from faketests import FakeConfigTests, FakeOutputTests
400
401 class ListKnown(FakeOutputTests):
402 def test_list_tests(self):
403@@ -37,32 +24,10 @@
404 cmd.run()
405 self.assertTrue("stream" in self.fakestdout.getvalue())
406
407-class FakeConfigTests(FakeOutputTests):
408- def setUp(self):
409- super(FakeConfigTests, self).setUp()
410- class fakeconfig:
411- def __init__(self, basedir):
412- self.configdir = os.path.join(basedir, "config")
413- self.installdir = os.path.join(basedir, "install")
414- self.resultsdir = os.path.join(basedir, "results")
415- self.tmpdir = tempfile.mkdtemp()
416- self.config = fakeconfig(self.tmpdir)
417- set_config(self.config)
418-
419- def tearDown(self):
420- super(FakeConfigTests, self).tearDown()
421- shutil.rmtree(self.tmpdir)
422-
423+class ListInstalled(FakeConfigTests):
424 def test_list_installed(self):
425 test_name="test_list_installed000"
426 os.makedirs(os.path.join(self.config.installdir, test_name))
427 cmd = abrek.builtins.cmd_list_installed()
428 cmd.run()
429 self.assertTrue(test_name in self.fakestdout.getvalue())
430-
431- def test_list_results(self):
432- result_name = "test_list_results000"
433- os.makedirs(os.path.join(self.config.resultsdir, result_name))
434- cmd = abrek.builtins.cmd_list_results()
435- cmd.run()
436- self.assertTrue(result_name in self.fakestdout.getvalue())
437
438=== added file 'tests/test_results.py'
439--- tests/test_results.py 1970-01-01 00:00:00 +0000
440+++ tests/test_results.py 2010-08-26 20:53:40 +0000
441@@ -0,0 +1,95 @@
442+import os
443+
444+import abrek.results
445+from abrek.utils import write_file
446+from faketests import FakeConfigTests
447+
448+class ResultsTests(FakeConfigTests):
449+ def test_results_list(self):
450+ result_name = "test_results_list000"
451+ os.makedirs(os.path.join(self.config.resultsdir, result_name))
452+ cmd = abrek.results.subcmd_results_list()
453+ cmd.run()
454+ self.assertTrue(result_name in self.fakestdout.getvalue())
455+
456+ def test_results_list_nodir(self):
457+ errmsg = "No results found"
458+ cmd = abrek.results.subcmd_results_list()
459+ cmd.run()
460+ self.assertTrue(errmsg in self.fakestdout.getvalue())
461+
462+ def test_results_show(self):
463+ result_name = "test_results_show000"
464+ result_output = "test result output"
465+ result_dir = os.path.join(self.config.resultsdir, result_name)
466+ os.makedirs(result_dir)
467+ outputfile = os.path.join(result_dir, 'testoutput.log')
468+ write_file(result_output, outputfile)
469+ cmd = abrek.results.subcmd_results_show()
470+ cmd.main(argv=[result_name])
471+ self.assertEqual(result_output, self.fakestdout.getvalue().strip())
472+
473+ def test_results_show_noarg(self):
474+ errmsg = "please specify the name of the result dir"
475+ cmd = abrek.results.subcmd_results_show()
476+ self.assertRaises(SystemExit, cmd.main, argv=[])
477+ self.assertEqual(errmsg, self.fakestdout.getvalue().strip())
478+
479+ def test_results_show_nodir(self):
480+ testname = "foo"
481+ errmsg = "No result found for '%s'" % testname
482+ cmd = abrek.results.subcmd_results_show()
483+ self.assertRaises(SystemExit, cmd.main, argv=[testname])
484+ self.assertEqual(errmsg, self.fakestdout.getvalue().strip())
485+
486+ def test_results_remove(self):
487+ result_name = "test_results_remove000"
488+ result_dir = os.path.join(self.config.resultsdir, result_name)
489+ os.makedirs(result_dir)
490+ cmd = abrek.results.subcmd_results_remove()
491+ cmd.main(argv=[result_name, '-f'])
492+ self.assertFalse(os.path.exists(result_dir))
493+
494+ def test_results_remove_noarg(self):
495+ errmsg = "please specify the name of the result dir"
496+ cmd = abrek.results.subcmd_results_remove()
497+ self.assertRaises(SystemExit, cmd.main, argv=[])
498+ self.assertEqual(errmsg, self.fakestdout.getvalue().strip())
499+
500+ def test_results_remove_nodir(self):
501+ testname = "foo"
502+ errmsg = "No result found for '%s'" % testname
503+ cmd = abrek.results.subcmd_results_remove()
504+ self.assertRaises(SystemExit, cmd.main, argv=[testname])
505+ self.assertEqual(errmsg, self.fakestdout.getvalue().strip())
506+
507+ def test_results_rename(self):
508+ result_src = "test_results_old"
509+ result_dest = "test_results_new"
510+ result_srcdir = os.path.join(self.config.resultsdir, result_src)
511+ result_destdir = os.path.join(self.config.resultsdir, result_dest)
512+ os.makedirs(result_srcdir)
513+ cmd = abrek.results.subcmd_results_rename()
514+ cmd.main(argv=[result_src, result_dest])
515+ self.assertFalse(os.path.exists(result_srcdir))
516+ self.assertTrue(os.path.exists(result_destdir))
517+
518+ def test_results_rename_badsrc(self):
519+ errmsg = "Result directory not found"
520+ result_src = "test_results_old"
521+ result_dest = "test_results_new"
522+ cmd = abrek.results.subcmd_results_rename()
523+ self.assertRaises(SystemExit, cmd.main, argv=[result_src, result_dest])
524+ self.assertEqual(errmsg, self.fakestdout.getvalue().strip())
525+
526+ def test_results_rename_baddest(self):
527+ errmsg = "Destination result name already exists"
528+ result_src = "test_results_old"
529+ result_dest = "test_results_new"
530+ result_srcdir = os.path.join(self.config.resultsdir, result_src)
531+ result_destdir = os.path.join(self.config.resultsdir, result_dest)
532+ os.makedirs(result_srcdir)
533+ os.makedirs(result_destdir)
534+ cmd = abrek.results.subcmd_results_rename()
535+ self.assertRaises(SystemExit, cmd.main, argv=[result_src, result_dest])
536+ self.assertEqual(errmsg, self.fakestdout.getvalue().strip())

Subscribers

People subscribed via source and target branches