Merge lp:~javier.collado/utah/static_analysis_6 into lp:utah

Proposed by Javier Collado
Status: Merged
Approved by: Javier Collado
Approved revision: 695
Merged at revision: 692
Proposed branch: lp:~javier.collado/utah/static_analysis_6
Merge into: lp:utah
Diff against target: 190 lines (+32/-22)
7 files modified
client.py (+2/-1)
utah/client/common.py (+6/-3)
utah/client/phoenix.py (+10/-10)
utah/client/tests/test_phoenix.py (+4/-3)
utah/client/tests/test_runner.py (+5/-2)
utah/client/tests/test_state_agent.py (+2/-1)
utah/provisioning/baremetal/cobbler.py (+3/-2)
To merge this branch: bzr merge lp:~javier.collado/utah/static_analysis_6
Reviewer Review Type Date Requested Status
Joe Talbott (community) Approve
Review via email: mp+127682@code.launchpad.net

Description of the change

Static analysis changes. As usual every commit fixes a different problem/warning.

To post a comment you must log in.
Revision history for this message
Joe Talbott (joetalbott) wrote :

Looks good. Can you give some details on the tool you're using so we can check our code before submitting?

Merge away.

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

@Joe

What I use is flake8 (pyflakes + pep8 together):
http://pypi.python.org/pypi/flake8/.

It isn't packaged in ubuntu so you have to install it with:
pip install flake8

In the branch directory I run a command like this:
find . -name '*.py' | xargs flake8

Lately pep8 (http://pypi.python.org/pypi/pep8) has been updated with additional warning/error codes, so sometimes I also run pep8 since latest changes aren't included in flake8 yet. Anyway, I'm not convinced about the usefulness of some of the new warnings/errors, so I'm not being strict with them.

Another interesting tool is autopep8 (http://pypi.python.org/pypi/autopep8/0.8.1) which applies changes to source files needed to meet pep8. For now, I'm just running some experiments with it.

Anyway, the most important thing is to integrate static analysis with your editor, so that any time something is wrong you get immediate feedback and fix it because otherwise all the highlighting becomes annoying. In my case, I'm using vim and syntastic (http://www.vim.org/scripts/script.php?script_id=2736) configured to use flake8. If you use another editor, is quite likely that some kind of integration is already available for it.

For the future, another tool I'd like to use is pep257 (http://pypi.python.org/pypi/pep257/) to make sure that docstrings have a common format across the whole project. However, it currently returns around 1300 errors, so that's something I won't be attempting any time soon.

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 2012-09-14 11:11:38 +0000
3+++ client.py 2012-10-03 09:37:24 +0000
4@@ -41,7 +41,8 @@
5 parser.add_argument('-i', '--install-type',
6 choices=['desktop', 'server', 'mini', 'alternate'],
7 default='desktop',
8- help='Installation Variant (i.e. server, desktop, etc.)')
9+ help=('Installation Variant '
10+ '(i.e. server, desktop, etc.)'))
11 parser.add_argument('-r', '--runlist', type=url_argument,
12 # Having a default here means that if a resume happens
13 # post-reboot without a runlist specified, it will
14
15=== modified file 'utah/client/common.py'
16--- utah/client/common.py 2012-09-27 13:55:41 +0000
17+++ utah/client/common.py 2012-10-03 09:37:24 +0000
18@@ -68,7 +68,9 @@
19 cmd_prefix = "sudo -n -u {} ".format(run_as)
20 else:
21 cmd_prefix = ""
22- run_as = getpass.getuser() # just a guess, but we're only displaying it
23+
24+ # just a guess, but we're only displaying it
25+ run_as = getpass.getuser()
26
27 if command is None:
28 return
29@@ -80,8 +82,9 @@
30 raise TimeoutAlarm
31
32 start_time = datetime.datetime.now()
33- p = subprocess.Popen("{} {}".format(cmd_prefix, command), shell=True, cwd=cwd, stdout=subprocess.PIPE,
34- stderr=subprocess.PIPE)
35+ p = subprocess.Popen("{} {}".format(cmd_prefix, command),
36+ shell=True, cwd=cwd,
37+ stdout=subprocess.PIPE, stderr=subprocess.PIPE)
38
39 if timeout != 0:
40 signal.signal(signal.SIGALRM, alarm_handler)
41
42=== modified file 'utah/client/phoenix.py'
43--- utah/client/phoenix.py 2012-09-26 15:23:11 +0000
44+++ utah/client/phoenix.py 2012-10-03 09:37:24 +0000
45@@ -3,17 +3,16 @@
46
47 import argparse
48 import os
49-import sys
50-
51-TC_CONTROL_NAME='tc_control'
52-TS_CONTROL_NAME='ts_control'
53-TSLIST_NAME='tslist.run'
54-MASTER_NAME='master.run'
55-CHANGEME="CHANGE_ME"
56+
57+TC_CONTROL_NAME = 'tc_control'
58+TS_CONTROL_NAME = 'ts_control'
59+TSLIST_NAME = 'tslist.run'
60+MASTER_NAME = 'master.run'
61+CHANGEME = "CHANGE_ME"
62+
63
64 class Phoenix(object):
65
66-
67 def __init__(self, testsuite, directory='.', testcases=['testcase1']):
68 self.testsuite = testsuite
69 self.directory = directory
70@@ -60,7 +59,8 @@
71 self.FILE_CONTENT[TSLIST_NAME] += "- test: {name}\n".format(name=d)
72
73 self.FILE_CONTENT[MASTER_NAME] += " - name: {}\n".format(testsuite)
74- self.FILE_CONTENT[MASTER_NAME] += " fetch_cmd: {}\n".format(CHANGEME)
75+ self.FILE_CONTENT[MASTER_NAME] += \
76+ " fetch_cmd: {}\n".format(CHANGEME)
77
78 self.debug()
79
80@@ -119,7 +119,7 @@
81 help='names of testcases to create')
82 parser.add_argument('--directory', '-D', dest='directory', default='.',
83 help='where to create the testsuite')
84-
85+
86 args = parser.parse_args()
87
88 phoenix = Phoenix(args.testsuite[0],
89
90=== modified file 'utah/client/tests/test_phoenix.py'
91--- utah/client/tests/test_phoenix.py 2012-09-25 19:21:16 +0000
92+++ utah/client/tests/test_phoenix.py 2012-10-03 09:37:24 +0000
93@@ -6,14 +6,17 @@
94
95 directory_name = "/tmp/phoenix"
96
97+
98 def setUp():
99 if os.path.exists(directory_name):
100 raise Exception("directory '{}' already exists".format(directory_name))
101
102+
103 def tearDown():
104 if os.path.exists(directory_name):
105 shutil.rmtree(directory_name)
106
107+
108 class TestPhoenix(unittest.TestCase):
109 testsuite_name = "testsuite_name"
110 testcases = ['test_one', 'test_two']
111@@ -35,7 +38,6 @@
112 Phoenix,
113 )
114
115-
116 def test_providing_required_args(self):
117 """
118 Test that __init__ succeeds with the required arguments.
119@@ -43,7 +45,6 @@
120
121 self.assertTrue(self.phoenix is not None)
122
123-
124 def test_suite_name(self):
125 """
126 Test that the testsuite name is correctly set.
127@@ -78,7 +79,7 @@
128 """
129 Test that the default testcase is correctly set.
130 """
131-
132+
133 phoenix = Phoenix(self.testsuite_name)
134 # there should be only one default testcase.
135 self.assertEqual(len(phoenix.testcases), 1)
136
137=== modified file 'utah/client/tests/test_runner.py'
138--- utah/client/tests/test_runner.py 2012-08-29 18:22:44 +0000
139+++ utah/client/tests/test_runner.py 2012-10-03 09:37:24 +0000
140@@ -20,7 +20,8 @@
141 self.result_class = ResultYAML
142 self.state_file = '/tmp/state.yaml'
143 self.state_agent = StateAgentYAML(state_file=self.state_file)
144- self.runner = Runner(install_type='desktop', result_class=self.result_class,
145+ self.runner = Runner(install_type='desktop',
146+ result_class=self.result_class,
147 state_agent=self.state_agent)
148 self.bad_dir = "/tmp/does_not_exist"
149
150@@ -123,7 +124,9 @@
151 fp.write(master_runlist_content)
152 fp.close()
153
154- runner = Runner(install_type='desktop', result_class=self.result_class, runlist=runlist)
155+ runner = Runner(install_type='desktop',
156+ result_class=self.result_class,
157+ runlist=runlist)
158 runner.save_state()
159
160 print("tests: {}".format(runner.count_tests()))
161
162=== modified file 'utah/client/tests/test_state_agent.py'
163--- utah/client/tests/test_state_agent.py 2012-09-06 15:44:36 +0000
164+++ utah/client/tests/test_state_agent.py 2012-10-03 09:37:24 +0000
165@@ -159,7 +159,8 @@
166 shutil.copytree(test_src, test_dir)
167
168 state_agent = StateAgentYAML(state_file=self.state_file)
169- runner = Runner(install_type="desktop", state_agent=state_agent, resume=True)
170+ runner = Runner(install_type="desktop", state_agent=state_agent,
171+ resume=True)
172 runner.load_state()
173
174 self.assertEqual(runner.status, 'RUN')
175
176=== modified file 'utah/provisioning/baremetal/cobbler.py'
177--- utah/provisioning/baremetal/cobbler.py 2012-09-19 19:03:03 +0000
178+++ utah/provisioning/baremetal/cobbler.py 2012-10-03 09:37:24 +0000
179@@ -173,8 +173,9 @@
180 users, remote login, not sudo, etc.
181 """
182 if self._runargs(['sudo', 'cobbler'] + cmd) != 0:
183- self.logger.error('Cobbler command failed: ' + ' '.join(cmd))
184- raise UTAHBMProvisioningException('Cobbler command failed: ' + ' '.join(cmd))
185+ error_msg = 'Cobbler command failed: ' + ' '.join(cmd)
186+ self.logger.error(error_msg)
187+ raise UTAHBMProvisioningException(error_msg)
188
189 def _start(self):
190 """

Subscribers

People subscribed via source and target branches