Merge lp:~nuclearbob/utah/bug1155615 into lp:utah

Proposed by Max Brustkern
Status: Merged
Approved by: Javier Collado
Approved revision: 881
Merged at revision: 880
Proposed branch: lp:~nuclearbob/utah/bug1155615
Merge into: lp:utah
Diff against target: 98 lines (+21/-6)
4 files modified
client.py (+1/-1)
debian/changelog (+2/-1)
utah/client/runner.py (+6/-3)
utah/client/tests/test_runner.py (+12/-1)
To merge this branch: bzr merge lp:~nuclearbob/utah/bug1155615
Reviewer Review Type Date Requested Status
Javier Collado (community) Approve
Max Brustkern (community) Needs Resubmitting
Review via email: mp+161205@code.launchpad.net

Description of the change

This branch sets rc.local to use the file specified in -o if one exists.

To post a comment you must log in.
Revision history for this message
Andy Doan (doanac) wrote :

On 04/26/2013 01:01 PM, Max Brustkern wrote:

> https://code.launchpad.net/~nuclearbob/utah/bug1155615/+merge/161205

> === modified file 'utah/client/runner.py'

> def __init__(self, install_type, runlist=None, result_class=Result,
> testdir=UTAH_DIR, state_agent=None,
> - resume=False, old_results=None):
> + resume=False, old_results=None, output=None):
>
> # Runlist URL passed through the command line
> self.testdir = testdir
> self.revision = "Unknown"
> + self.output = (output or
> + os.path.join('/', 'var', 'lib', 'utah', 'utah.out'))

does os.path.join really gain anything here? ie wouldn't it be more
concise to just do "/var/lib/utah/utah.out"? might even default it in
the parameters to the function so you don't have to check for None here.

> with open(rc_local, 'w') as fp:
> - fp.write(self.rc_local_content.format(runlist=runlist))
> + fp.write(self.rc_local_content.format(runlist=runlist,
> + output=self.output))

I think you forgot to update rc_local_content at the top of the file to
take in this new parameter. ie:

rc_local_content = """#!/bin/sh

/usr/bin/utah --resume -o {outout} -r {runlist}
"""

Also - would it be possible to add a test case to ensure we do write to
non-standard output directory?

Revision history for this message
Max Brustkern (nuclearbob) wrote :

I did forget to add that. Whoops. I can add a test case as well.

The reason I'm not doing the parameter default (although I suppose I could) is the old reason we didn't use parameter defaults in Machine: args is going to overwrite them with None if nothing gets passed.

As far as os.path.join is concerned, I don't think we actually need it in the vast majority of cases we're currently using it, but it always seems like a good idea? If we want to use that less, I'd like to be clearer on when we do and don't want to use it.

lp:~nuclearbob/utah/bug1155615 updated
879. By Max Brustkern

Actually set output in rc_local_content

Revision history for this message
Andy Doan (doanac) wrote :

On 04/26/2013 02:18 PM, Max Brustkern wrote:
> As far as os.path.join is concerned, I don't think we actually need it in the vast majority of cases we're currently using it, but it always seems like a good idea? If we want to use that less, I'd like to be clearer on when we do and don't want to use it.

yeah - this isn't the only place. I guess I see it as useful when you
are joining variables like "basedir" and "fname". ie
  os.path.join(basedir, fname)

but maybe that's beyond the scope of this.

Revision history for this message
Javier Collado (javier.collado) wrote :

There's a problem in `client.py` because `args.output` is passed as a positional argument after a keyword argument and that's disallowed.

I already talked to Max about this and he's working on it.

review: Needs Fixing
lp:~nuclearbob/utah/bug1155615 updated
880. By Max Brustkern

Specified keyword argument for output

Revision history for this message
Javier Collado (javier.collado) wrote :

Looks good to me.

Could you add a test case to verify that the contents of the `rc.local` file is correct? There's already a test to verify that the file is written, so it shouldn't be hard to verify its contents.

lp:~nuclearbob/utah/bug1155615 updated
881. By Max Brustkern

Added testcase for contents of rc.local

Revision history for this message
Max Brustkern (nuclearbob) wrote :

Let me know how that looks.

review: Needs Resubmitting
Revision history for this message
Javier Collado (javier.collado) wrote :

Looks good. Thanks for the update.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'client.py'
2--- client.py 2013-04-19 19:04:15 +0000
3+++ client.py 2013-05-01 16:53:26 +0000
4@@ -159,7 +159,7 @@
5 runner = Runner(install_type=install_type, state_agent=state_agent,
6 result_class=result_class, runlist=runlist,
7 resume=resume, old_results=old_results,
8- testdir=testdir)
9+ testdir=testdir, output=args.output)
10 if resume:
11 runner.load_state()
12
13
14=== modified file 'debian/changelog'
15--- debian/changelog 2013-04-26 15:08:17 +0000
16+++ debian/changelog 2013-05-01 16:53:26 +0000
17@@ -14,8 +14,9 @@
18 * Make rsyslog timeout error message clearer (LP: #1169846)
19 * Write to log UTAH version as soon as possible (LP: #1152216)
20 * Fixed help output to use just one runlist (LP: #1112597)
21+ * Setup rc.local to use output passed via command line (LP: #1155615)
22
23- -- Max Brustkern <max@canonical.com> Wed, 24 Apr 2013 17:04:27 -0400
24+ -- Max Brustkern <max@canonical.com> Fri, 26 Apr 2013 13:58:25 -0400
25
26 utah (0.10ubuntu1) UNRELEASED; urgency=low
27
28
29=== modified file 'utah/client/runner.py'
30--- utah/client/runner.py 2013-04-26 13:40:06 +0000
31+++ utah/client/runner.py 2013-05-01 16:53:26 +0000
32@@ -58,7 +58,7 @@
33 # run.
34 rc_local_content = """#!/bin/sh
35
36-/usr/bin/utah --resume -o /var/lib/utah/utah.out -r {runlist}
37+/usr/bin/utah --resume -o {output} -r {runlist}
38 """
39
40
41@@ -140,11 +140,13 @@
42
43 def __init__(self, install_type, runlist=None, result_class=Result,
44 testdir=UTAH_DIR, state_agent=None,
45- resume=False, old_results=None):
46+ resume=False, old_results=None, output=None):
47
48 # Runlist URL passed through the command line
49 self.testdir = testdir
50 self.revision = "Unknown"
51+ self.output = (output or
52+ os.path.join('/', 'var', 'lib', 'utah', 'utah.out'))
53
54 self.testsuitedir = os.path.join(testdir, 'testsuites')
55
56@@ -239,7 +241,8 @@
57
58 try:
59 with open(rc_local, 'w') as fp:
60- fp.write(self.rc_local_content.format(runlist=runlist))
61+ fp.write(self.rc_local_content.format(runlist=runlist,
62+ output=self.output))
63 os.fchmod(fp.fileno(),
64 stat.S_IRWXU | stat.S_IROTH | stat.S_IRGRP)
65 except (IOError, OSError) as err:
66
67=== modified file 'utah/client/tests/test_runner.py'
68--- utah/client/tests/test_runner.py 2013-04-29 18:55:25 +0000
69+++ utah/client/tests/test_runner.py 2013-05-01 16:53:26 +0000
70@@ -49,9 +49,11 @@
71 self.result_class = ResultYAML
72 self.state_file = '/tmp/state.yaml'
73 self.state_agent = StateAgentYAML(state_file=self.state_file)
74+ self.output_file='/tmp/utah.out'
75 self.runner = Runner(install_type='desktop',
76 result_class=self.result_class,
77- state_agent=self.state_agent)
78+ state_agent=self.state_agent,
79+ output=self.output_file)
80 self.bad_dir = "/tmp/does_not_exist"
81
82 self.assertFalse(os.path.exists(self.bad_dir),
83@@ -98,6 +100,15 @@
84
85 self.assertTrue(os.path.exists(tmp_rc_local))
86
87+ def test_rc_local_contents(self):
88+ """Test rc.local output setting."""
89+ tmp_rc_local = '/tmp/rc.local'
90+ self.runner.setup_rc_local(tmp_rc_local)
91+
92+ with open(tmp_rc_local) as rc_local:
93+ self.assertIn(self.output_file, rc_local.read(),
94+ 'Output directory not written to rc.local')
95+
96 def test_run(self):
97 """Test running all test suites."""
98 retcode = self.runner.run()

Subscribers

People subscribed via source and target branches