Skip to content

Commit

Permalink
[tests] Do not trim from PATH if we did not append to it; Clean up/fi…
Browse files Browse the repository at this point in the history
…x shebangs in scripts (#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
  • Loading branch information
jleveque authored Nov 13, 2020
1 parent 929ff7c commit 71aa221
Show file tree
Hide file tree
Showing 35 changed files with 33 additions and 51 deletions.
2 changes: 0 additions & 2 deletions clear/main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#! /usr/bin/python -u

import click
import os
import subprocess
Expand Down
3 changes: 0 additions & 3 deletions config/kube.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#!/usr/bin/python -u
# -*- coding: utf-8 -*-

import fcntl
import os
import shutil
Expand Down
2 changes: 0 additions & 2 deletions connect/main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#! /usr/bin/python -u

import click
import os
import pexpect
Expand Down
2 changes: 0 additions & 2 deletions counterpoll/main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#! /usr/bin/python -u

import click
import json
import swsssdk
Expand Down
3 changes: 0 additions & 3 deletions debug/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#! /usr/bin/python -u
# date: 07/12/17

import click
import subprocess

Expand Down
2 changes: 0 additions & 2 deletions pfcwd/main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#! /usr/bin/python -u

import os
import sys

Expand Down
3 changes: 2 additions & 1 deletion scripts/aclshow
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/python
#!/usr/bin/env python

"""
using aclshow to display SONiC switch acl rules and counters
Expand Down
2 changes: 1 addition & 1 deletion scripts/dump_nat_entries.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/env python

""""
Description: dump_nat_entries.py -- dump conntrack nat entries from kernel into a file
Expand Down
3 changes: 2 additions & 1 deletion scripts/ecnconfig
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/python
#!/usr/bin/env python

"""
ecnconfig is the utility to
Expand Down
3 changes: 2 additions & 1 deletion scripts/fanshow
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/python
#!/usr/bin/env python

"""
Script to show fan status.
"""
Expand Down
3 changes: 2 additions & 1 deletion scripts/fdbclear
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/python
#!/usr/bin/env python

"""
Script to clear MAC/FDB entries learnt in Hardware
Expand Down
3 changes: 2 additions & 1 deletion scripts/fdbshow
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/python
#!/usr/bin/env python

"""
Script to show MAC/FDB entries learnt in Hardware
Expand Down
2 changes: 1 addition & 1 deletion scripts/gearboxutil
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! /usr/bin/python
#!/usr/bin/env python

import swsssdk
import sys
Expand Down
2 changes: 1 addition & 1 deletion scripts/intfutil
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! /usr/bin/python
#!/usr/bin/env python

import argparse
import os
Expand Down
3 changes: 2 additions & 1 deletion scripts/mmuconfig
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/python
#!/usr/bin/env python

"""
mmuconfig is the utility to show and change mmu configuration
Expand Down
3 changes: 2 additions & 1 deletion scripts/natclear
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/python
#!/usr/bin/env python

"""
Script to clear nat dynamic entries from Hardware and also to clear the nat statistics
Expand Down
2 changes: 1 addition & 1 deletion scripts/natconfig
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/env python

"""
Script to show nat configuration
Expand Down
2 changes: 1 addition & 1 deletion scripts/natshow
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/env python

"""
Script to show nat entries and nat statistics in a summary view
Expand Down
3 changes: 2 additions & 1 deletion scripts/nbrshow
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/python
#!/usr/bin/env python

"""
Script to show Ipv4/Ipv6 neighbor entries
Expand Down
3 changes: 2 additions & 1 deletion scripts/portconfig
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/python
#!/usr/bin/env python

"""
portconfig is the utility to show and change ECN configuration
Expand Down
2 changes: 1 addition & 1 deletion scripts/psushow
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! /usr/bin/python
#!/usr/bin/env python

import argparse
import sys
Expand Down
3 changes: 2 additions & 1 deletion scripts/sfpshow
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/python
#!/usr/bin/env python

"""
Script to show sfp eeprom and presence status.
Not like sfputil this scripts get the sfp data from DB directly.
Expand Down
3 changes: 2 additions & 1 deletion scripts/sonic-kdump-config
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/python
#!/usr/bin/env python

'''
Copyright 2019 Broadcom. The term "Broadcom" refers to Broadcom Inc.
and/or its subsidiaries.
Expand Down
3 changes: 2 additions & 1 deletion scripts/sonic_sku_create.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/python
#!/usr/bin/env python

"""
usage: sonic_sku_create.py [-h] [-v] [-f FILE] [-m [MINIGRAPH_FILE]] [-b BASE]
[-r] [-k HWSKU]
Expand Down
3 changes: 2 additions & 1 deletion scripts/tempershow
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/python
#!/usr/bin/env python

"""
Script to show fan status.
"""
Expand Down
2 changes: 1 addition & 1 deletion scripts/watermarkstat
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/env python

#####################################################################
#
Expand Down
3 changes: 0 additions & 3 deletions show/kube.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#!/usr/bin/python -u
# -*- coding: utf-8 -*-

import os

import click
Expand Down
2 changes: 0 additions & 2 deletions show/main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#! /usr/bin/python -u

import json
import netaddr
import os
Expand Down
2 changes: 0 additions & 2 deletions sonic_installer/main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#! /usr/bin/python -u

try:
import ConfigParser as configparser
except ImportError:
Expand Down
2 changes: 0 additions & 2 deletions tests/crm_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -999,7 +999,6 @@ def test_crm_show_resources_nexthop(self):
@classmethod
def teardown_class(cls):
print("TEARDOWN")
os.environ["PATH"] = os.pathsep.join(os.environ["PATH"].split(os.pathsep)[:-1])
os.environ["UTILITIES_UNIT_TESTING"] = "0"

class TestCrmMultiAsic(object):
Expand Down Expand Up @@ -1295,7 +1294,6 @@ def test_crm_multi_asic_show_resources_nexthop(self):
@classmethod
def teardown_class(cls):
print("TEARDOWN")
os.environ["PATH"] = os.pathsep.join(os.environ["PATH"].split(os.pathsep)[:-1])
os.environ["UTILITIES_UNIT_TESTING"] = "0"
os.environ["UTILITIES_UNIT_TESTING_TOPOLOGY"] = ""
import mock_tables.mock_single_asic
1 change: 0 additions & 1 deletion tests/sflow_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,5 +267,4 @@ def test_config_sflow_intf_sample_rate(self):
@classmethod
def teardown_class(cls):
print("TEARDOWN")
os.environ["PATH"] = os.pathsep.join(os.environ["PATH"].split(os.pathsep)[:-1])
os.environ["UTILITIES_UNIT_TESTING"] = "0"
1 change: 0 additions & 1 deletion tests/show_breakout_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,4 @@ def test_single_intf_current_mode(self):
@classmethod
def teardown_class(cls):
print("TEARDOWN")
os.environ["PATH"] = os.pathsep.join(os.environ["PATH"].split(os.pathsep)[:-1])
os.environ["UTILITIES_UNIT_TESTING"] = "0"
1 change: 0 additions & 1 deletion tests/show_platform_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,4 @@ def test_summary(self):
@classmethod
def teardown_class(cls):
print("TEARDOWN")
os.environ["PATH"] = os.pathsep.join(os.environ["PATH"].split(os.pathsep)[:-1])
os.environ["UTILITIES_UNIT_TESTING"] = "0"
2 changes: 0 additions & 2 deletions tests/system_health_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#! /usr/bin/python -u

import sys
import os

Expand Down
3 changes: 0 additions & 3 deletions undebug/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#! /usr/bin/python -u
# date: 07/12/17

import click
import subprocess

Expand Down

0 comments on commit 71aa221

Please sign in to comment.