Skip to content

Commit 9281173

Browse files
tests: fixed pylint errors - python 3.6.8
With the new version of python, the linter complains about quite a few things. 1. Subprocess run should check the result of the command. In some cases this is avoided on purpose because we expect the command to fail with a particular status code. In these cases, the subprocess-run-check is disabled. Also, when doing the cleanup, we don't need to check if the cleanup is successful because we need to kill the process no matter what. 2. Unused imports; this seems like a bug, so we just ignore pylint. 3. Unnecessary "else" after "continue" (no-else-continue); re-wrote the if case. 4. Unnecessary "elif" after "break" (no-else-break); re-wrote the if case. Signed-off-by: Andreea Florescu <[email protected]>
1 parent 2abaabf commit 9281173

File tree

7 files changed

+18
-7
lines changed

7 files changed

+18
-7
lines changed

tests/framework/http.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
# SPDX-License-Identifier: Apache-2.0
33
"""Wrapper over an http session with timed requests."""
4-
4+
# pylint: disable=unused-import
55
import requests_unixsocket
66

77
from framework import decorators

tests/framework/jailer.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ def setup(self):
165165

166166
def cleanup(self):
167167
"""Clean up this jailer context."""
168+
# pylint: disable=subprocess-run-check
168169
shutil.rmtree(self.chroot_base_with_id(), ignore_errors=True)
169170

170171
if self.netns:
@@ -218,6 +219,7 @@ def _kill_crgoup_tasks(self, controller):
218219
disappears. The retry function that calls this code makes
219220
sure we do not timeout.
220221
"""
222+
# pylint: disable=subprocess-run-check
221223
tasks_file = '/sys/fs/cgroup/{}/{}/{}/tasks'.format(
222224
controller,
223225
FC_BINARY_NAME,

tests/framework/microvm.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ def __init__(
124124

125125
def kill(self):
126126
"""All clean up associated with this microVM should go here."""
127+
# pylint: disable=subprocess-run-check
127128
if self._jailer.daemonize:
128129
if self.jailer_clone_pid:
129130
run('kill -9 {}'.format(self.jailer_clone_pid), shell=True)
@@ -253,6 +254,7 @@ def setup(self):
253254

254255
def spawn(self):
255256
"""Start a microVM as a daemon or in a screen session."""
257+
# pylint: disable=subprocess-run-check
256258
self._jailer.setup()
257259
self._api_socket = self._jailer.api_socket_path()
258260
self._api_session = Session()

tests/host_tools/network.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ def _init_connection(self):
7676
def _exec(self, cmd):
7777
"""Private function that handles the ssh client invocation."""
7878
def _exec_raw(_cmd):
79+
# pylint: disable=subprocess-run-check
7980
cp = run([
8081
"ssh",
8182
"-q",
@@ -337,6 +338,7 @@ def netns(self):
337338

338339
def __del__(self):
339340
"""Destructor doing tap interface clean up."""
341+
# pylint: disable=subprocess-run-check
340342
_ = run(
341343
'ip netns exec {} ip link set {} down'.format(
342344
self.netns,

tests/integration_tests/functional/test_cpu_features.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,7 @@ def _check_guest_cmd_output(test_microvm, guest_cmd, expected_header,
5555
if expected_header not in (None, ''):
5656
if line.strip() == expected_header:
5757
expected_header = None
58-
continue
59-
else:
60-
continue
58+
continue
6159

6260
# See if any key matches.
6361
# We Use a try-catch block here since line.split() may fail.

tests/integration_tests/functional/test_rate_limiter.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -460,21 +460,24 @@ def _run_iperf_on_guest(test_microvm, iperf_cmd, hostname):
460460

461461
def _start_local_iperf(netns_cmd_prefix):
462462
"""Start iperf in server mode after killing any leftover iperf daemon."""
463+
# pylint: disable=subprocess-run-check
463464
iperf_cmd = 'pkill {}\n'.format(IPERF_BINARY)
464465

466+
# Don't check the result of this command because it can fail if no iperf
467+
# is running.
465468
run(iperf_cmd, shell=True)
466469

467470
iperf_cmd = '{} {} -sD -f KBytes\n'.format(netns_cmd_prefix, IPERF_BINARY)
468471

469-
run(iperf_cmd, shell=True)
472+
run(iperf_cmd, shell=True, check=True)
470473

471474
# Wait for the iperf daemon to start.
472475
time.sleep(2)
473476

474477

475478
def _run_local_iperf(iperf_cmd):
476479
"""Execute a client related iperf command locally."""
477-
process = run(iperf_cmd, shell=True, stdout=PIPE)
480+
process = run(iperf_cmd, shell=True, stdout=PIPE, check=True)
478481
return process.stdout.decode('utf-8')
479482

480483

@@ -505,6 +508,7 @@ def _process_iperf_output(iperf_out):
505508
' '
506509
)[0].strip()
507510
break
508-
elif found_line > 0:
511+
if found_line > 0:
512+
# Skip the first 3 lines after the first line containing `------`
509513
found_line += 1
510514
return float(iperf_out_time), float(iperf_out_bw)

tests/integration_tests/security/test_seccomp.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
def test_seccomp_ls(bin_seccomp_paths):
1111
"""Assert that the seccomp filters deny a blacklisted syscall."""
1212
# pylint: disable=redefined-outer-name
13+
# pylint: disable=subprocess-run-check
1314
# The fixture pattern causes a pylint false positive for that rule.
1415

1516
# Path to the `ls` binary, which attempts to execute the blacklisted
@@ -34,6 +35,7 @@ def test_advanced_seccomp_harmless(bin_seccomp_paths):
3435
Test that the advanced demo jailer allows the harmless demo binary.
3536
"""
3637
# pylint: disable=redefined-outer-name
38+
# pylint: disable=subprocess-run-check
3739
# The fixture pattern causes a pylint false positive for that rule.
3840

3941
demo_advanced_jailer = bin_seccomp_paths['demo_advanced_jailer']
@@ -55,6 +57,7 @@ def test_advanced_seccomp_malicious(bin_seccomp_paths):
5557
Test that the basic demo jailer denies the malicious demo binary.
5658
"""
5759
# pylint: disable=redefined-outer-name
60+
# pylint: disable=subprocess-run-check
5861
# The fixture pattern causes a pylint false positive for that rule.
5962

6063
demo_advanced_jailer = bin_seccomp_paths['demo_advanced_jailer']

0 commit comments

Comments
 (0)