Hacking: check for deprecated os.popen()
Add hacking check for deprecated library function os.popen(). This hacking prevents new os.popen() in the code. Closes-Bug: 1529836 Change-Id: I09ad101861b790d2f9bec45757b8c921e68b696e
This commit is contained in:
parent
11019fab7a
commit
b4a3193c20
@ -58,6 +58,7 @@ Nova Specific Commandments
|
||||
- [N345] Python 3: do not use dict.iterkeys.
|
||||
- [N346] Python 3: do not use dict.itervalues.
|
||||
- [N347] Provide enough help text for config options
|
||||
- [N348] Deprecated library function os.popen()
|
||||
|
||||
Creating Unit Tests
|
||||
-------------------
|
||||
|
@ -683,6 +683,20 @@ def cfg_help_with_enough_text(logical_line, tokens):
|
||||
yield(0, msg)
|
||||
|
||||
|
||||
def no_os_popen(logical_line):
|
||||
"""Disallow 'os.popen('
|
||||
|
||||
Deprecated library function os.popen() Replace it using subprocess
|
||||
https://bugs.launchpad.net/tempest/+bug/1529836
|
||||
|
||||
N348
|
||||
"""
|
||||
|
||||
if 'os.popen(' in logical_line:
|
||||
yield(0, 'N348 Deprecated library function os.popen(). '
|
||||
'Replace it using subprocess module. ')
|
||||
|
||||
|
||||
def factory(register):
|
||||
register(import_no_db_in_virt)
|
||||
register(no_db_session_in_public_api)
|
||||
@ -717,3 +731,4 @@ def factory(register):
|
||||
register(check_python3_no_iterkeys)
|
||||
register(check_python3_no_itervalues)
|
||||
register(cfg_help_with_enough_text)
|
||||
register(no_os_popen)
|
||||
|
@ -732,3 +732,21 @@ class HackingTestCase(test.NoDBTestCase):
|
||||
\"\"\")
|
||||
"""
|
||||
self._assert_has_no_errors(code9, checks.cfg_help_with_enough_text)
|
||||
|
||||
def test_no_os_popen(self):
|
||||
code = """
|
||||
import os
|
||||
|
||||
foobar_cmd = "foobar -get -beer"
|
||||
answer = os.popen(foobar_cmd).read()
|
||||
|
||||
if answer == nok":
|
||||
try:
|
||||
os.popen(os.popen('foobar -beer -please')).read()
|
||||
|
||||
except ValueError:
|
||||
go_home()
|
||||
"""
|
||||
errors = [(4, 0, 'N348'), (8, 8, 'N348')]
|
||||
self._assert_has_errors(code, checks.no_os_popen,
|
||||
expected_errors=errors)
|
||||
|
Loading…
Reference in New Issue
Block a user