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
=== modified file 'client.py'
--- client.py 2012-09-14 11:11:38 +0000
+++ client.py 2012-10-03 09:37:24 +0000
@@ -41,7 +41,8 @@
41 parser.add_argument('-i', '--install-type',41 parser.add_argument('-i', '--install-type',
42 choices=['desktop', 'server', 'mini', 'alternate'],42 choices=['desktop', 'server', 'mini', 'alternate'],
43 default='desktop',43 default='desktop',
44 help='Installation Variant (i.e. server, desktop, etc.)')44 help=('Installation Variant '
45 '(i.e. server, desktop, etc.)'))
45 parser.add_argument('-r', '--runlist', type=url_argument,46 parser.add_argument('-r', '--runlist', type=url_argument,
46 # Having a default here means that if a resume happens47 # Having a default here means that if a resume happens
47 # post-reboot without a runlist specified, it will48 # post-reboot without a runlist specified, it will
4849
=== modified file 'utah/client/common.py'
--- utah/client/common.py 2012-09-27 13:55:41 +0000
+++ utah/client/common.py 2012-10-03 09:37:24 +0000
@@ -68,7 +68,9 @@
68 cmd_prefix = "sudo -n -u {} ".format(run_as)68 cmd_prefix = "sudo -n -u {} ".format(run_as)
69 else:69 else:
70 cmd_prefix = ""70 cmd_prefix = ""
71 run_as = getpass.getuser() # just a guess, but we're only displaying it71
72 # just a guess, but we're only displaying it
73 run_as = getpass.getuser()
7274
73 if command is None:75 if command is None:
74 return76 return
@@ -80,8 +82,9 @@
80 raise TimeoutAlarm82 raise TimeoutAlarm
8183
82 start_time = datetime.datetime.now()84 start_time = datetime.datetime.now()
83 p = subprocess.Popen("{} {}".format(cmd_prefix, command), shell=True, cwd=cwd, stdout=subprocess.PIPE,85 p = subprocess.Popen("{} {}".format(cmd_prefix, command),
84 stderr=subprocess.PIPE)86 shell=True, cwd=cwd,
87 stdout=subprocess.PIPE, stderr=subprocess.PIPE)
8588
86 if timeout != 0:89 if timeout != 0:
87 signal.signal(signal.SIGALRM, alarm_handler)90 signal.signal(signal.SIGALRM, alarm_handler)
8891
=== modified file 'utah/client/phoenix.py'
--- utah/client/phoenix.py 2012-09-26 15:23:11 +0000
+++ utah/client/phoenix.py 2012-10-03 09:37:24 +0000
@@ -3,17 +3,16 @@
33
4import argparse4import argparse
5import os5import os
6import sys6
77TC_CONTROL_NAME = 'tc_control'
8TC_CONTROL_NAME='tc_control'8TS_CONTROL_NAME = 'ts_control'
9TS_CONTROL_NAME='ts_control'9TSLIST_NAME = 'tslist.run'
10TSLIST_NAME='tslist.run'10MASTER_NAME = 'master.run'
11MASTER_NAME='master.run'11CHANGEME = "CHANGE_ME"
12CHANGEME="CHANGE_ME"12
1313
14class Phoenix(object):14class Phoenix(object):
1515
16
17 def __init__(self, testsuite, directory='.', testcases=['testcase1']):16 def __init__(self, testsuite, directory='.', testcases=['testcase1']):
18 self.testsuite = testsuite17 self.testsuite = testsuite
19 self.directory = directory18 self.directory = directory
@@ -60,7 +59,8 @@
60 self.FILE_CONTENT[TSLIST_NAME] += "- test: {name}\n".format(name=d)59 self.FILE_CONTENT[TSLIST_NAME] += "- test: {name}\n".format(name=d)
6160
62 self.FILE_CONTENT[MASTER_NAME] += " - name: {}\n".format(testsuite)61 self.FILE_CONTENT[MASTER_NAME] += " - name: {}\n".format(testsuite)
63 self.FILE_CONTENT[MASTER_NAME] += " fetch_cmd: {}\n".format(CHANGEME)62 self.FILE_CONTENT[MASTER_NAME] += \
63 " fetch_cmd: {}\n".format(CHANGEME)
6464
65 self.debug()65 self.debug()
6666
@@ -119,7 +119,7 @@
119 help='names of testcases to create')119 help='names of testcases to create')
120 parser.add_argument('--directory', '-D', dest='directory', default='.',120 parser.add_argument('--directory', '-D', dest='directory', default='.',
121 help='where to create the testsuite')121 help='where to create the testsuite')
122 122
123 args = parser.parse_args()123 args = parser.parse_args()
124124
125 phoenix = Phoenix(args.testsuite[0],125 phoenix = Phoenix(args.testsuite[0],
126126
=== modified file 'utah/client/tests/test_phoenix.py'
--- utah/client/tests/test_phoenix.py 2012-09-25 19:21:16 +0000
+++ utah/client/tests/test_phoenix.py 2012-10-03 09:37:24 +0000
@@ -6,14 +6,17 @@
66
7directory_name = "/tmp/phoenix"7directory_name = "/tmp/phoenix"
88
9
9def setUp():10def setUp():
10 if os.path.exists(directory_name):11 if os.path.exists(directory_name):
11 raise Exception("directory '{}' already exists".format(directory_name))12 raise Exception("directory '{}' already exists".format(directory_name))
1213
14
13def tearDown():15def tearDown():
14 if os.path.exists(directory_name):16 if os.path.exists(directory_name):
15 shutil.rmtree(directory_name)17 shutil.rmtree(directory_name)
1618
19
17class TestPhoenix(unittest.TestCase):20class TestPhoenix(unittest.TestCase):
18 testsuite_name = "testsuite_name"21 testsuite_name = "testsuite_name"
19 testcases = ['test_one', 'test_two']22 testcases = ['test_one', 'test_two']
@@ -35,7 +38,6 @@
35 Phoenix,38 Phoenix,
36 )39 )
3740
38
39 def test_providing_required_args(self):41 def test_providing_required_args(self):
40 """42 """
41 Test that __init__ succeeds with the required arguments.43 Test that __init__ succeeds with the required arguments.
@@ -43,7 +45,6 @@
4345
44 self.assertTrue(self.phoenix is not None)46 self.assertTrue(self.phoenix is not None)
4547
46
47 def test_suite_name(self):48 def test_suite_name(self):
48 """49 """
49 Test that the testsuite name is correctly set.50 Test that the testsuite name is correctly set.
@@ -78,7 +79,7 @@
78 """79 """
79 Test that the default testcase is correctly set.80 Test that the default testcase is correctly set.
80 """81 """
81 82
82 phoenix = Phoenix(self.testsuite_name)83 phoenix = Phoenix(self.testsuite_name)
83 # there should be only one default testcase.84 # there should be only one default testcase.
84 self.assertEqual(len(phoenix.testcases), 1)85 self.assertEqual(len(phoenix.testcases), 1)
8586
=== modified file 'utah/client/tests/test_runner.py'
--- utah/client/tests/test_runner.py 2012-08-29 18:22:44 +0000
+++ utah/client/tests/test_runner.py 2012-10-03 09:37:24 +0000
@@ -20,7 +20,8 @@
20 self.result_class = ResultYAML20 self.result_class = ResultYAML
21 self.state_file = '/tmp/state.yaml'21 self.state_file = '/tmp/state.yaml'
22 self.state_agent = StateAgentYAML(state_file=self.state_file)22 self.state_agent = StateAgentYAML(state_file=self.state_file)
23 self.runner = Runner(install_type='desktop', result_class=self.result_class,23 self.runner = Runner(install_type='desktop',
24 result_class=self.result_class,
24 state_agent=self.state_agent)25 state_agent=self.state_agent)
25 self.bad_dir = "/tmp/does_not_exist"26 self.bad_dir = "/tmp/does_not_exist"
2627
@@ -123,7 +124,9 @@
123 fp.write(master_runlist_content)124 fp.write(master_runlist_content)
124 fp.close()125 fp.close()
125126
126 runner = Runner(install_type='desktop', result_class=self.result_class, runlist=runlist)127 runner = Runner(install_type='desktop',
128 result_class=self.result_class,
129 runlist=runlist)
127 runner.save_state()130 runner.save_state()
128131
129 print("tests: {}".format(runner.count_tests()))132 print("tests: {}".format(runner.count_tests()))
130133
=== modified file 'utah/client/tests/test_state_agent.py'
--- utah/client/tests/test_state_agent.py 2012-09-06 15:44:36 +0000
+++ utah/client/tests/test_state_agent.py 2012-10-03 09:37:24 +0000
@@ -159,7 +159,8 @@
159 shutil.copytree(test_src, test_dir)159 shutil.copytree(test_src, test_dir)
160160
161 state_agent = StateAgentYAML(state_file=self.state_file)161 state_agent = StateAgentYAML(state_file=self.state_file)
162 runner = Runner(install_type="desktop", state_agent=state_agent, resume=True)162 runner = Runner(install_type="desktop", state_agent=state_agent,
163 resume=True)
163 runner.load_state()164 runner.load_state()
164165
165 self.assertEqual(runner.status, 'RUN')166 self.assertEqual(runner.status, 'RUN')
166167
=== modified file 'utah/provisioning/baremetal/cobbler.py'
--- utah/provisioning/baremetal/cobbler.py 2012-09-19 19:03:03 +0000
+++ utah/provisioning/baremetal/cobbler.py 2012-10-03 09:37:24 +0000
@@ -173,8 +173,9 @@
173 users, remote login, not sudo, etc.173 users, remote login, not sudo, etc.
174 """174 """
175 if self._runargs(['sudo', 'cobbler'] + cmd) != 0:175 if self._runargs(['sudo', 'cobbler'] + cmd) != 0:
176 self.logger.error('Cobbler command failed: ' + ' '.join(cmd))176 error_msg = 'Cobbler command failed: ' + ' '.join(cmd)
177 raise UTAHBMProvisioningException('Cobbler command failed: ' + ' '.join(cmd))177 self.logger.error(error_msg)
178 raise UTAHBMProvisioningException(error_msg)
178179
179 def _start(self):180 def _start(self):
180 """181 """

Subscribers

People subscribed via source and target branches