Skip to content

Commit 71aa221

Browse files
authored
[tests] Do not trim from PATH if we did not append to it; Clean up/fix shebangs in scripts (sonic-net#1233)
Some tests were trimming the last item from system PATH, but they never appended anything to it, thus these tests were trimming valid entries from the tail of the system path, which in turn caused scripts with shebangs like `#!/usr/bin/env python` to fail, because once `/usr/bin` was removed from PATH, `python` could not be found. **- How I did it** - Remove lines which trimmed the last entry from system PATH in the teardown function if nothing was appended to PATH in the setup method. - Remove shebangs from non-executable Python files - Fix shebangs which had a space in them - Replace `#!/usr/bin/python` shebangs with the preferred, more portable `#!/usr/bin/env python` in executable scripts
1 parent 929ff7c commit 71aa221

35 files changed

+33
-51
lines changed

clear/main.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#! /usr/bin/python -u
2-
31
import click
42
import os
53
import subprocess

config/kube.py

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
#!/usr/bin/python -u
2-
# -*- coding: utf-8 -*-
3-
41
import fcntl
52
import os
63
import shutil

connect/main.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#! /usr/bin/python -u
2-
31
import click
42
import os
53
import pexpect

counterpoll/main.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#! /usr/bin/python -u
2-
31
import click
42
import json
53
import swsssdk

debug/main.py

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
#! /usr/bin/python -u
2-
# date: 07/12/17
3-
41
import click
52
import subprocess
63

pfcwd/main.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#! /usr/bin/python -u
2-
31
import os
42
import sys
53

scripts/aclshow

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#!/usr/bin/python
1+
#!/usr/bin/env python
2+
23
"""
34
using aclshow to display SONiC switch acl rules and counters
45

scripts/dump_nat_entries.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/python
1+
#!/usr/bin/env python
22

33
""""
44
Description: dump_nat_entries.py -- dump conntrack nat entries from kernel into a file

scripts/ecnconfig

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#!/usr/bin/python
1+
#!/usr/bin/env python
2+
23
"""
34
ecnconfig is the utility to
45

scripts/fanshow

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#!/usr/bin/python
1+
#!/usr/bin/env python
2+
23
"""
34
Script to show fan status.
45
"""

scripts/fdbclear

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#!/usr/bin/python
1+
#!/usr/bin/env python
2+
23
"""
34
Script to clear MAC/FDB entries learnt in Hardware
45

scripts/fdbshow

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#!/usr/bin/python
1+
#!/usr/bin/env python
2+
23
"""
34
Script to show MAC/FDB entries learnt in Hardware
45

scripts/gearboxutil

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#! /usr/bin/python
1+
#!/usr/bin/env python
22

33
import swsssdk
44
import sys

scripts/intfutil

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#! /usr/bin/python
1+
#!/usr/bin/env python
22

33
import argparse
44
import os

scripts/mmuconfig

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#!/usr/bin/python
1+
#!/usr/bin/env python
2+
23
"""
34
mmuconfig is the utility to show and change mmu configuration
45

scripts/natclear

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#!/usr/bin/python
1+
#!/usr/bin/env python
2+
23
"""
34
Script to clear nat dynamic entries from Hardware and also to clear the nat statistics
45

scripts/natconfig

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/python
1+
#!/usr/bin/env python
22

33
"""
44
Script to show nat configuration

scripts/natshow

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/python
1+
#!/usr/bin/env python
22

33
"""
44
Script to show nat entries and nat statistics in a summary view

scripts/nbrshow

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#!/usr/bin/python
1+
#!/usr/bin/env python
2+
23
"""
34
Script to show Ipv4/Ipv6 neighbor entries
45

scripts/portconfig

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#!/usr/bin/python
1+
#!/usr/bin/env python
2+
23
"""
34
portconfig is the utility to show and change ECN configuration
45

scripts/psushow

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#! /usr/bin/python
1+
#!/usr/bin/env python
22

33
import argparse
44
import sys

scripts/sfpshow

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#!/usr/bin/python
1+
#!/usr/bin/env python
2+
23
"""
34
Script to show sfp eeprom and presence status.
45
Not like sfputil this scripts get the sfp data from DB directly.

scripts/sonic-kdump-config

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#!/usr/bin/python
1+
#!/usr/bin/env python
2+
23
'''
34
Copyright 2019 Broadcom. The term "Broadcom" refers to Broadcom Inc.
45
and/or its subsidiaries.

scripts/sonic_sku_create.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#!/usr/bin/python
1+
#!/usr/bin/env python
2+
23
"""
34
usage: sonic_sku_create.py [-h] [-v] [-f FILE] [-m [MINIGRAPH_FILE]] [-b BASE]
45
[-r] [-k HWSKU]

scripts/tempershow

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#!/usr/bin/python
1+
#!/usr/bin/env python
2+
23
"""
34
Script to show fan status.
45
"""

scripts/watermarkstat

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/python
1+
#!/usr/bin/env python
22

33
#####################################################################
44
#

show/kube.py

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
#!/usr/bin/python -u
2-
# -*- coding: utf-8 -*-
3-
41
import os
52

63
import click

show/main.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#! /usr/bin/python -u
2-
31
import json
42
import netaddr
53
import os

sonic_installer/main.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#! /usr/bin/python -u
2-
31
try:
42
import ConfigParser as configparser
53
except ImportError:

tests/crm_test.py

-2
Original file line numberDiff line numberDiff line change
@@ -999,7 +999,6 @@ def test_crm_show_resources_nexthop(self):
999999
@classmethod
10001000
def teardown_class(cls):
10011001
print("TEARDOWN")
1002-
os.environ["PATH"] = os.pathsep.join(os.environ["PATH"].split(os.pathsep)[:-1])
10031002
os.environ["UTILITIES_UNIT_TESTING"] = "0"
10041003

10051004
class TestCrmMultiAsic(object):
@@ -1295,7 +1294,6 @@ def test_crm_multi_asic_show_resources_nexthop(self):
12951294
@classmethod
12961295
def teardown_class(cls):
12971296
print("TEARDOWN")
1298-
os.environ["PATH"] = os.pathsep.join(os.environ["PATH"].split(os.pathsep)[:-1])
12991297
os.environ["UTILITIES_UNIT_TESTING"] = "0"
13001298
os.environ["UTILITIES_UNIT_TESTING_TOPOLOGY"] = ""
13011299
import mock_tables.mock_single_asic

tests/sflow_test.py

-1
Original file line numberDiff line numberDiff line change
@@ -267,5 +267,4 @@ def test_config_sflow_intf_sample_rate(self):
267267
@classmethod
268268
def teardown_class(cls):
269269
print("TEARDOWN")
270-
os.environ["PATH"] = os.pathsep.join(os.environ["PATH"].split(os.pathsep)[:-1])
271270
os.environ["UTILITIES_UNIT_TESTING"] = "0"

tests/show_breakout_test.py

-1
Original file line numberDiff line numberDiff line change
@@ -61,5 +61,4 @@ def test_single_intf_current_mode(self):
6161
@classmethod
6262
def teardown_class(cls):
6363
print("TEARDOWN")
64-
os.environ["PATH"] = os.pathsep.join(os.environ["PATH"].split(os.pathsep)[:-1])
6564
os.environ["UTILITIES_UNIT_TESTING"] = "0"

tests/show_platform_test.py

-1
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,4 @@ def test_summary(self):
5454
@classmethod
5555
def teardown_class(cls):
5656
print("TEARDOWN")
57-
os.environ["PATH"] = os.pathsep.join(os.environ["PATH"].split(os.pathsep)[:-1])
5857
os.environ["UTILITIES_UNIT_TESTING"] = "0"

tests/system_health_test.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#! /usr/bin/python -u
2-
31
import sys
42
import os
53

undebug/main.py

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
#! /usr/bin/python -u
2-
# date: 07/12/17
3-
41
import click
52
import subprocess
63

0 commit comments

Comments
 (0)