Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 38 additions & 33 deletions spytest/bin/lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -122,20 +122,21 @@ IGNORE3="$IGNORE3 --disable=R1729" #use-a-generator

IGNORE3="$IGNORE3 --disable=C3001" #unnecessary-lambda-assignment

exclude="apis/gnmi/openconfig apis/gnmi unused/"
exclude="$exclude apis/yang/autogen/bindings"
exclude="$exclude apis/yang/codegen/bindings"
exclude="$exclude apis/yang/codegen/test.py"
exclude="$exclude apis/yang/codegen/gnoi_bindings"
exclude="$exclude spytest/ddm/third-party"
exclude="$exclude tests/dell/infra/bgpcfgd_test.py"
EXCLUDE="$EXCLUDE apis/gnmi/openconfig"
EXCLUDE="$EXCLUDE apis/gnmi unused/"
EXCLUDE="$EXCLUDE apis/yang/autogen/bindings"
EXCLUDE="$EXCLUDE apis/yang/codegen/bindings"
EXCLUDE="$EXCLUDE apis/yang/codegen/test.py"
EXCLUDE="$EXCLUDE apis/yang/codegen/gnoi_bindings"
EXCLUDE="$EXCLUDE spytest/ddm/third-party"
EXCLUDE="$EXCLUDE tests/dell/infra/bgpcfgd_test.py"

if [ "$LINT_EXCLUDE_KNOWN_FAILS" == "1" ]; then
exclude="$exclude apis/yang/codegen"
exclude="$exclude tests/dell"
exclude="$exclude tests/ut/acl_fbs"
exclude="$exclude tests/infra_ut/data_driven"
exclude="$exclude tests/systb"
EXCLUDE="$EXCLUDE apis/yang/codegen"
EXCLUDE="$EXCLUDE tests/dell"
EXCLUDE="$EXCLUDE tests/ut/acl_fbs"
EXCLUDE="$EXCLUDE tests/infra_ut/data_driven"
EXCLUDE="$EXCLUDE tests/systb"
fi

LINT_PYVER=${LINT_PYVER:=3}
Expand All @@ -150,8 +151,8 @@ if [ "$LINT_MODIFIED" == "1" ]; then
DBG_FILE=modified_lint_debug.log
ERR_FILE=modified_lint_errors.log
REP_FILE=modified_lint_report.log
#exclude=""
exclude="$exclude __init__.py"
#EXCLUDE=""
EXCLUDE="$EXCLUDE __init__.py"
fi

#IGNORE1="$IGNORE1 --disable=W0612" #unused-variable
Expand All @@ -173,7 +174,7 @@ RUFF_OPTS="$RUFF_OPTS --ignore E501" #line-too-long
RUFF_OPTS="$RUFF_OPTS --ignore E701" #multiple-statements
RUFF_OPTS="$RUFF_OPTS --ignore E702" #multiple-statements-on-one-line-semicolon
RUFF_OPTS="$RUFF_OPTS --ignore E703" #useless-semicolon
RUFF_OPTS="$RUFF_OPTS --ignore E713" #not-in-test
#RUFF_OPTS="$RUFF_OPTS --ignore E713" #not-in-test
RUFF_OPTS="$RUFF_OPTS --ignore E722" #bare-except
RUFF_OPTS="$RUFF_OPTS --ignore E731" #lambda-assignment
RUFF_OPTS="$RUFF_OPTS --ignore E741" #ambiguous-variable-name
Expand All @@ -186,6 +187,7 @@ RUFF_OPTS="$RUFF_OPTS --ignore W293" #Blank line contains whitespace
RUFF_OPTS="$RUFF_OPTS --ignore PLW2901"
RUFF_OPTS="$RUFF_OPTS --ignore PLW0603"
RUFF_OPTS="$RUFF_OPTS --ignore PLC1901"
RUFF_OPTS="$RUFF_OPTS --ignore PLE1300" #PLE1300 Unsupported format character '}'

LINT_TOOL="${LINT_TOOL:-ruff}"
if [ "$LINT_TOOL" = "pylint" ]; then
Expand Down Expand Up @@ -216,37 +218,40 @@ if [ "$LINT_TOOL" != "pyflakes" ]; then
fi

if [ $# -eq 0 ]; then
files1=$(find $ddir/spytest/ -name "*.py")
files1=$(find $ddir/spytest/ -name "*.py" | xargs)
if [ -d $ddir/scheduler ]; then
files2=$(find $ddir/scheduler/ -name "*.py")
files2=$(find $ddir/scheduler/ -name "*.py" | xargs)
fi
files3=$(find $ddir/apis/ -name "*.py")
files4=$(find $ddir/utilities/ -name "*.py")
files5=$(find $ddir/tests/ -name "*.py")
files3=$(find $ddir/apis/ -name "*.py" | xargs)
files4=$(find $ddir/utilities/ -name "*.py" | xargs)
files5=$(find $ddir/tests/ -name "*.py" | xargs)
files="$files1 $files2 $files3 $files4 $files5"
else
files=""
for arg in $*; do
if [ -f $arg ]; then
files="$files $arg"
elif [ -d $arg ]; then
files="$files $(find $arg -name '*.py')"
files="$files $(find $arg -name '*.py' | xargs)"
fi
done
fi

cmd="grep -q"
for ex in $exclude; do
cmd="$cmd -e $ex"
done
files2=""
for f in $files;do
if [ -z "$exclude" ]; then
files2="$files2 $f"
elif ! $cmd <<< $f; then
files2="$files2 $f"
fi
done
function exclude_files() {
python - <<END
retval = []
for f in "$1".split():
skip = False
for e in "$2".split():
if e in f:
skip = True
break
if not skip:
retval.append(f)
print(" ".join(retval))
END
}
files2=$(exclude_files "$files" "$EXCLUDE")

rm -f $DBG_FILE $ERR_FILE $REP_FILE $ERR_TEMP $REP_FILE.err
line="\--------------------------------------------------------------------"
Expand Down
2 changes: 1 addition & 1 deletion spytest/bin/tools_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ dir=$(dirname $0)
dir=$(cd $dir;pwd -P)
scid=$(cd $dir/..;pwd -P)

# sourde environment
# source environment
. $dir/env

if [ -f $dir/.tools_env ]; then
Expand Down
1 change: 1 addition & 0 deletions spytest/bin/upgrade_requirements.sh
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ if [ $is_v3 -ne 0 ]; then
else
$SPYTEST_PYTHON -m pip install --upgrade git+https://github.com/ramakristipatibrcm/pytest-xdist.git@spytest#egg=pytest-xdist
fi
$SPYTEST_PYTHON -m pip --no-cache-dir install $INSTALL_OPTS pre-commit autopep8 flake8===6.0.0
fi

read -rs -n1 -t30 -p "Press any key or wait to continue ..."
Expand Down
2 changes: 1 addition & 1 deletion spytest/spytest/gnmi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def configure(self, ip=None, port=8080, targetName=None, username='admin',
return self

def reinit(self, ip, port=8080):
self.ip = ip.decode('utf-8') if type(ip) == bytes else str(ip)
self.ip = ip.decode('utf-8') if isinstance(ip, bytes) else str(ip)
self.port = int(port)
self.target_addr = "{}:{}".format(self.ip, self.port)
return self
Expand Down
4 changes: 2 additions & 2 deletions spytest/spytest/remote/spytest-helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,9 +435,9 @@ def apply_file(filepath, method):

def parse_and_apply_files(names, method):
ensure_mac_address(config_file)
if type(names) is str:
if isinstance(names, str):
apply_file(names, method)
elif type(names) is list:
elif isinstance(names, list):
for filename in names:
parse_and_apply_files(filename, method)

Expand Down
4 changes: 2 additions & 2 deletions spytest/spytest/tgen/tg.py
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ def trgen_pre_proc(self, fname, **kwargs):
tgen_wait(10)
self.tg_topology_test_control(action='apply_on_the_fly_changes', skip_wait=True)
logger.info('start the host.')
temp = ret_ds['handle'] if type(ret_ds['handle']) != list else ret_ds['handle'][0]
temp = ret_ds['handle'] if not isinstance(ret_ds['handle'], list) else ret_ds['handle'][0]
self.tg_topology_test_control(handle=temp, stack='deviceGroup', action='start_protocol')
self.manage_interface_config_handles(kwargs.get('mode'), kwargs_port_handle, ret_ds['handle'])
elif kwargs.get('mode') == 'modify':
Expand Down Expand Up @@ -1190,7 +1190,7 @@ def tg_interface_handle(self, ret_ds):
temp = ret_ds['handles_pylist']
elif "handles" in ret_ds:
temp = ret_ds['handles']
if type(temp) == list:
if isinstance(temp, list):
temp = temp[0] if len(temp) == 1 else temp
ret_ds['handle'] = temp
return ret_ds
Expand Down
2 changes: 1 addition & 1 deletion spytest/spytest/tgen/tgen_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ def _verify_analyzer_filter_stats(tr_details, **kwargs):
tx_ph = txObj.get_port_handle(txPort)
i = 1
j = str(i)
if type(stream) == str:
if isinstance(stream, str):
st.log('only one stream is configured, form a list')
stream = [stream]
fparam = [fparam]
Expand Down