diff options
Diffstat (limited to 'resources/libraries/bash/entry')
15 files changed, 330 insertions, 178 deletions
diff --git a/resources/libraries/bash/entry/bisect.sh b/resources/libraries/bash/entry/bisect.sh new file mode 100644 index 0000000000..d5cb1d51ba --- /dev/null +++ b/resources/libraries/bash/entry/bisect.sh @@ -0,0 +1,188 @@ +#!/usr/bin/env bash + +# Copyright (c) 2023 Cisco and/or its affiliates. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at: +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set -exuo pipefail + +# This entry script does not change which CSIT branch is used, +# use "with_oper_for_vpp.sh" wrapper for that. +# +# This script is to be used for locating performance regressions +# (or breakages, or progressions, or fixes). +# It uses "git bisect" commands on the VPP repository, +# between the triggered VPP patch and a commit specified in the first argument +# of the gerrit comment text. +# The other arguments are used as tag expressions for selecting tests as usual. +# Many different result types are supported. +# +# Logs are present in the archive directory, but usually the main output +# is the offending commit as identified by "git bisect", visible in console. +# +# While selecting just one testcase is the intended use, +# this script should be able to deal with multiple testcases as well, +# grouping all the values together. This usually inflates +# the standard deviation, but it is not clear how that affects the bisection. +# +# For the bisection decision, jumpavg library is used, +# deciding whether shorter description is achieved by forcefully grouping +# the middle results with the old, or with the new ones. +# If the shortest description is achieved with 3 separate groups, +# bisect interval focuses on biggest relative change +# (with respect to pairwise maximum). +# +# If a test fails, an artificial result is used to distinguish +# from normal results. Currently, the value 1.0, with the multiplicity of 4. +# +# Note that if there was a VPP API change that affects tests in the interval, +# there frequently is no good way for single CSIT commit to work there. +# You can try manually reverting the CSIT changes to make tests pass, +# possibly needing to search over multiple subintervals. +# Using and older CSIT commit (possibly cherry-picking the bisect Change +# if it was not present in CSIT compatible with old enough VPP builds) +# is the fastest solution; but beware of CSIT-induced performance effects +# (e.g. TRex settings). +# +# If a regression happens during a subinterval where the test fails +# due to a bug in VPP, you may try to create a new commit chain +# with the fix cherry-picked to the start of the interval. +# Do not do that as a chain in Gerrit, it would be long and Gerrit will refuse +# edits of already merged Changes. +# Instead, add a block of bash code to do the manipulation +# on local git history between checkout and bisect. +# +# At the start, the script executes first bisect iteration in an attempt +# to avoid work if the search interval has only one commit (or is invalid). +# Only when the work is needed, earliest and latest commits are built +# and tested. Branches "earliest", "middle" and "latest" are temporarily created +# as a way to remember which commits to check out. +# +# Test results are parsed from json files, +# symlinks are used to tell python script which results to compare. +# +# Assumptions: +# + There is a directory holding VPP repo with patch under test checked out. +# + It contains csit subdirectory with CSIT code to use (this script is there). +# + Everything needed to build VPP is already installed locally. +# Consequences: +# + Working directory is switched to the VPP repo root. +# + At the end, VPP repo has checked out and built some commit, +# as chosen by "git bisect". +# + Directories build_root, build and csit are reset during the run. +# + The following directories (relative to VPP repo) are (re)created: +# ++ csit_{earliest,middle,latest}, build_{earliest,latest}, +# ++ archive, csit/archive, csit/download_dir. +# + Symlinks csit_{early,late,mid} are also created. +# Arguments: +# - ${1} - If present, override JOB_NAME to simplify manual usage. + +# "set -eu" handles failures from the following two lines. +BASH_ENTRY_DIR="$(dirname $(readlink -e "${BASH_SOURCE[0]}"))" +BASH_FUNCTION_DIR="$(readlink -e "${BASH_ENTRY_DIR}/../function")" +source "${BASH_FUNCTION_DIR}/common.sh" || { + echo "Source failed." >&2 + exit 1 +} +source "${BASH_FUNCTION_DIR}/per_patch.sh" || die "Source failed." +# Cleanup needs ansible. +source "${BASH_FUNCTION_DIR}/ansible.sh" || die "Source failed." +common_dirs || die +check_prerequisites || die +set_perpatch_vpp_dir || die +get_test_code "${1-}" || die +get_test_tag_string || die +# Unfortunately, git bisect only works at the top of the repo. +cd "${VPP_DIR}" || die + +# Save the current commit. +git checkout -b "latest" +# Save the lower bound commit. +git checkout -b "earliest" +git reset --hard "${GIT_BISECT_FROM}" + +# This is the place for custom code manipulating local git history. + +#git checkout -b "alter" +#... +#git checkout "latest" +#git rebase "alter" || git rebase --skip +#git branch -D "alter" + +git bisect start || die +# TODO: Can we add a trap for "git bisect reset" or even "deactivate", +# without affecting the inner trap for unreserve and cleanup? +git checkout "latest" +git status || die +git describe || die +git bisect new || die +# Performing first iteration early to avoid testing or even building. +git checkout "earliest" || die "Failed to checkout earliest commit." +git status || die +git describe || die +# The first iteration. +git bisect old | tee "git.log" || die "Invalid bisect interval?" +git checkout -b "middle" || die "Failed to create branch: middle" +git status || die +git describe || die +if head -n 1 "git.log" | cut -b -11 | fgrep -q "Bisecting:"; then + echo "Building and testing initial bounds." +else + echo "Single commit, no work needed." + exit 0 +fi +# Building latest first, good for avoiding DPDK rebuilds. +git checkout "latest" || die "Failed to checkout latest commit." +build_vpp_ubuntu "LATEST" || die +set_aside_build_artifacts "latest" || die +git checkout "earliest" || die "Failed to checkout earliest commit." +git status || die +git describe || die +build_vpp_ubuntu "EARLIEST" || die +set_aside_build_artifacts "earliest" || die +git checkout "middle" || die "Failed to checkout middle commit." +git branch -D "earliest" "latest" || die "Failed to remove branches." +# Done with repo manipulation for now, testing commences. +initialize_csit_dirs "earliest" "middle" "latest" || die +set_perpatch_dut || die +select_topology || die +select_arch_os || die +activate_virtualenv "${VPP_DIR}" || die +generate_tests || die +archive_tests || die + +# TODO: Does it matter which build is tested first? + +select_build "build_earliest" || die +check_download_dir || die +reserve_and_cleanup_testbed || die +run_robot || die +move_test_results "csit_earliest" || die +ln -s -T "csit_earliest" "csit_early" || die + +# Explicit cleanup, in case the previous test left the testbed in a bad shape. +ansible_playbook "cleanup" + +select_build "build_latest" || die +check_download_dir || die +run_robot || die +move_test_results "csit_latest" || die +ln -s -T "csit_latest" "csit_late" || die +untrap_and_unreserve_testbed || die + +# See function documentation for the logic in the loop. +main_bisect_loop || die +# In worst case, the middle branch is still checked out. +# TODO: Is there a way to ensure "middle" branch is always deleted? +git branch -D "middle" || true +# Delete symlinks to prevent duplicate archiving. +rm -vrf "csit_early" "csit_late" "csit_mid" diff --git a/resources/libraries/bash/entry/bootstrap_aws_eb_version_create_release.sh b/resources/libraries/bash/entry/bootstrap_aws_eb_version_create_release.sh new file mode 100755 index 0000000000..0bbf3b83ff --- /dev/null +++ b/resources/libraries/bash/entry/bootstrap_aws_eb_version_create_release.sh @@ -0,0 +1,32 @@ +# Copyright (c) 2024 Cisco and/or its affiliates. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at: +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set -exuo pipefail + +# Assumptions: +# + There is a directory holding CSIT code to use (this script is there). +# Consequences (and specific assumptions) are multiple, +# examine tree of functions for current description. + +# "set -eu" handles failures from the following two lines. +BASH_ENTRY_DIR="$(dirname $(readlink -e "${BASH_SOURCE[0]}"))" +BASH_FUNCTION_DIR="$(readlink -e "${BASH_ENTRY_DIR}/../function")" +source "${BASH_FUNCTION_DIR}/common.sh" || { + echo "Source failed." >&2 + exit 1 +} +source "${BASH_FUNCTION_DIR}/eb_version.sh" || die "Source failed." +source "${BASH_FUNCTION_DIR}/hugo.sh" || die "Source failed." +source "${BASH_FUNCTION_DIR}/terraform.sh" || die "Source failed." +common_dirs || die +eb_version_create_release || die diff --git a/resources/libraries/bash/entry/bootstrap_docs.sh b/resources/libraries/bash/entry/bootstrap_aws_eb_version_deploy.sh index 9d2519ebf3..15d6dae405 100755 --- a/resources/libraries/bash/entry/bootstrap_docs.sh +++ b/resources/libraries/bash/entry/bootstrap_aws_eb_version_deploy.sh @@ -1,4 +1,4 @@ -# Copyright (c) 2021 Cisco and/or its affiliates. +# Copyright (c) 2023 Cisco and/or its affiliates. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at: @@ -25,8 +25,8 @@ source "${BASH_FUNCTION_DIR}/common.sh" || { echo "Source failed." >&2 exit 1 } -source "${BASH_FUNCTION_DIR}/docs.sh" || die "Source failed." +source "${BASH_FUNCTION_DIR}/eb_version.sh" || die "Source failed." +source "${BASH_FUNCTION_DIR}/hugo.sh" || die "Source failed." +source "${BASH_FUNCTION_DIR}/terraform.sh" || die "Source failed." common_dirs || die -activate_virtualenv || die -generate_docs || die -die_on_docs_error || die +eb_version_deploy || die diff --git a/resources/libraries/bash/entry/bootstrap_trending.sh b/resources/libraries/bash/entry/bootstrap_aws_eb_version_verify.sh index b172a81be5..362a2f78af 100755 --- a/resources/libraries/bash/entry/bootstrap_trending.sh +++ b/resources/libraries/bash/entry/bootstrap_aws_eb_version_verify.sh @@ -1,4 +1,4 @@ -# Copyright (c) 2021 Cisco and/or its affiliates. +# Copyright (c) 2023 Cisco and/or its affiliates. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at: @@ -25,8 +25,8 @@ source "${BASH_FUNCTION_DIR}/common.sh" || { echo "Source failed." >&2 exit 1 } -source "${BASH_FUNCTION_DIR}/docs.sh" || die "Source failed." +source "${BASH_FUNCTION_DIR}/eb_version.sh" || die "Source failed." +source "${BASH_FUNCTION_DIR}/hugo.sh" || die "Source failed." +source "${BASH_FUNCTION_DIR}/terraform.sh" || die "Source failed." common_dirs || die -activate_virtualenv || die -generate_trending || die -die_on_docs_error || die +eb_version_build_verify || die diff --git a/resources/libraries/bash/entry/bootstrap_report.sh b/resources/libraries/bash/entry/bootstrap_report.sh index 191f910171..47a9d2e3d4 100755 --- a/resources/libraries/bash/entry/bootstrap_report.sh +++ b/resources/libraries/bash/entry/bootstrap_report.sh @@ -1,4 +1,4 @@ -# Copyright (c) 2021 Cisco and/or its affiliates. +# Copyright (c) 2023 Cisco and/or its affiliates. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at: @@ -25,8 +25,8 @@ source "${BASH_FUNCTION_DIR}/common.sh" || { echo "Source failed." >&2 exit 1 } -source "${BASH_FUNCTION_DIR}/docs.sh" || die "Source failed." +source "${BASH_FUNCTION_DIR}/eb_version.sh" || die "Source failed." common_dirs || die activate_virtualenv || die generate_report || die -die_on_docs_error || die +die_on_error || die diff --git a/resources/libraries/bash/entry/bootstrap_verify_perf.sh b/resources/libraries/bash/entry/bootstrap_verify_perf.sh index 99813573ea..18dfd08c39 100755 --- a/resources/libraries/bash/entry/bootstrap_verify_perf.sh +++ b/resources/libraries/bash/entry/bootstrap_verify_perf.sh @@ -1,4 +1,4 @@ -# Copyright (c) 2021 Cisco and/or its affiliates. +# Copyright (c) 2023 Cisco and/or its affiliates. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at: @@ -46,10 +46,7 @@ archive_tests || die prepare_topology || die select_topology || die reserve_and_cleanup_testbed || die -select_tags || die -compose_pybot_arguments || die -set_environment_variables || die -run_pybot || die -untrap_and_unreserve_testbed || die +run_robot || die move_archives || die -die_on_pybot_error || die +untrap_and_unreserve_testbed || die +die_on_robot_error || die diff --git a/resources/libraries/bash/entry/bootstrap_vpp_device.sh b/resources/libraries/bash/entry/bootstrap_vpp_device.sh index ae4c26a1ba..fd6279f8c7 100755 --- a/resources/libraries/bash/entry/bootstrap_vpp_device.sh +++ b/resources/libraries/bash/entry/bootstrap_vpp_device.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -# Copyright (c) 2021 Cisco and/or its affiliates. +# Copyright (c) 2023 Cisco and/or its affiliates. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at: @@ -44,9 +44,6 @@ archive_tests || die prepare_topology || die select_topology || die activate_docker_topology || die -select_tags || die -compose_pybot_arguments || die -set_environment_variables || die -run_pybot || die +run_robot || die move_archives || die -die_on_pybot_error || die +die_on_robot_error || die diff --git a/resources/libraries/bash/entry/patch_l3fwd_flip_routes b/resources/libraries/bash/entry/patch_l3fwd_flip_routes index 23a6675145..c5eff5d3ca 100755 --- a/resources/libraries/bash/entry/patch_l3fwd_flip_routes +++ b/resources/libraries/bash/entry/patch_l3fwd_flip_routes @@ -1,7 +1,7 @@ #!/bin/sh patch --ignore-whitespace --forward main.c <<"_EOF" -185,186c185,186 +204,205c204,205 < {RTE_IPV4(198, 18, 0, 0), 24, 0}, < {RTE_IPV4(198, 18, 1, 0), 24, 1}, --- diff --git a/resources/libraries/bash/entry/per_patch_device.sh b/resources/libraries/bash/entry/per_patch_device.sh index db977b6e96..88d7f13494 100644 --- a/resources/libraries/bash/entry/per_patch_device.sh +++ b/resources/libraries/bash/entry/per_patch_device.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -# Copyright (c) 2021 Cisco and/or its affiliates. +# Copyright (c) 2023 Cisco and/or its affiliates. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at: @@ -39,14 +39,15 @@ source "${BASH_FUNCTION_DIR}/per_patch.sh" || die "Source failed." common_dirs || die check_prerequisites || die set_perpatch_vpp_dir || die -build_vpp_ubuntu_amd64 "CURRENT" || die -set_aside_commit_build_artifacts || die -initialize_csit_dirs || die +git status || die +git describe || die +build_vpp_ubuntu "CURRENT" || die +initialize_csit_dirs "current" || die get_test_code "${1-}" || die get_test_tag_string || die set_perpatch_dut || die select_arch_os || die -select_build "build_current" || die +select_build "build-root" || die check_download_dir || die activate_virtualenv "${VPP_DIR}" || die generate_tests || die @@ -54,8 +55,6 @@ archive_tests || die prepare_topology || die select_topology || die activate_docker_topology || die -select_tags || die -compose_pybot_arguments || die -run_pybot || die +run_robot || die move_archives || die -die_on_pybot_error || die +die_on_robot_error || die diff --git a/resources/libraries/bash/entry/per_patch_perf.sh b/resources/libraries/bash/entry/per_patch_perf.sh index 565a566eb0..9a825a007e 100644 --- a/resources/libraries/bash/entry/per_patch_perf.sh +++ b/resources/libraries/bash/entry/per_patch_perf.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -# Copyright (c) 2021 Cisco and/or its affiliates. +# Copyright (c) 2023 Cisco and/or its affiliates. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at: @@ -44,11 +44,16 @@ source "${BASH_FUNCTION_DIR}/ansible.sh" || die "Source failed." common_dirs || die check_prerequisites || die set_perpatch_vpp_dir || die -build_vpp_ubuntu_amd64 "CURRENT" || die -set_aside_commit_build_artifacts || die -build_vpp_ubuntu_amd64 "PARENT" || die -set_aside_parent_build_artifacts || die -initialize_csit_dirs || die +git status || die +git describe || die +build_vpp_ubuntu "CURRENT" || die +set_aside_build_artifacts "current" || die +git checkout "HEAD~" || die "Failed to checkout parent commit." +git status || die +git describe || die +build_vpp_ubuntu "PARENT" || die +set_aside_build_artifacts "parent" || die +initialize_csit_dirs "parent" "current" || die get_test_code "${1-}" || die get_test_tag_string || die set_perpatch_dut || die @@ -58,8 +63,6 @@ activate_virtualenv "${VPP_DIR}" || die generate_tests || die archive_tests || die reserve_and_cleanup_testbed || die -select_tags || die -compose_pybot_arguments || die # Support for interleaved measurements is kept for future. iterations=1 # 8 for ((iter=0; iter<iterations; iter++)); do @@ -71,16 +74,14 @@ for ((iter=0; iter<iterations; iter++)); do # Testing current first. Good for early failures or for API changes. select_build "build_current" || die check_download_dir || die - run_pybot || die - archive_parse_test_results "csit_current/${iter}" || die - die_on_pybot_error || die + run_robot || die + move_test_results "csit_current/${iter}" || die # TODO: Use less heavy way to avoid apt remove failures. ansible_playbook "cleanup" || die select_build "build_parent" || die check_download_dir || die - run_pybot || die - archive_parse_test_results "csit_parent/${iter}" || die - die_on_pybot_error || die + run_robot || die + move_test_results "csit_parent/${iter}" || die done untrap_and_unreserve_testbed || die compare_test_results # The error code becomes this script's error code. diff --git a/resources/libraries/bash/entry/tox/README.txt b/resources/libraries/bash/entry/tox/README.txt index e13b60209e..9ce21e93d0 100644 --- a/resources/libraries/bash/entry/tox/README.txt +++ b/resources/libraries/bash/entry/tox/README.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2022 Cisco and/or its affiliates. +# Copyright (c) 2024 Cisco and/or its affiliates. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at: @@ -14,6 +14,13 @@ This directory contains tox scripts and other files they need. Generally, a tox script is either a checker (suitable for automated verify) or a fixer (manually started, risky as uncommitted edits can be lost). + +In the tox verify job we want to avoid running fixers, +as they can affect what other checkers see +(e.g. autogen fixer could add more too long lines). +That is why we keep fixers separate from checkers in principle, +even for fairly safe tasks (e.g. bumping copyright years). + Each tox script is assumed to be run from tox, when working directory is set to ${CSIT_DIR}. @@ -26,14 +33,9 @@ Each checker script should: + Only the output suitable for automated processing by an external caller should be written to stdout. ++ The level of "less verbose" depends on check and state of codebase. -+ TODO: Should we carefully document which files are - whitelisted/blacklisted for a particulat check? Each fixer script should: + Perform edits on current filesystem + Not assume git is clean (there may be uncommitted edits). + Use "git diff HEAD~" to get both comitted and uncomitted edits to analyze. + Output whatever it wants (possibly nothing). - -TODO: Should checkers be named differently than fixers? - E.g. both scripts and tox environments start with fix_? diff --git a/resources/libraries/bash/entry/tox/copyright_year.sh b/resources/libraries/bash/entry/tox/copyright_year.sh index 9ed9fcb653..272763100e 100644 --- a/resources/libraries/bash/entry/tox/copyright_year.sh +++ b/resources/libraries/bash/entry/tox/copyright_year.sh @@ -1,4 +1,4 @@ -# Copyright (c) 2022 Cisco and/or its affiliates. +# Copyright (c) 2024 Cisco and/or its affiliates. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at: @@ -24,10 +24,7 @@ set -exuo pipefail # but not the current year (in the same line). # The offending lines are stored to copyright_year.log (overwriting). # -# 3 lines were chosen, because first two lines could be shebang and empty line, -# and more than 3 lines would start failing on files with multiple copyright -# holders. There, only the last updating entity needs to bump its year, -# and put other copyright lines below. +# 3 lines were chosen, because first two lines could be shebang and empty line. # "set -eu" handles failures from the following two lines. BASH_CHECKS_DIR="$(dirname $(readlink -e "${BASH_SOURCE[0]}"))" @@ -42,7 +39,7 @@ IFS=$'\n' files=($(git diff --name-only HEAD~ || true)) unset IFS truncate -s 0 "copyright_year.log" || die -# A change can have thousands of files, supress console output in the cycle. +# A change can have thousands of files, supress console output for the cycle. set +x for fil in "${files[@]}"; do # Greps do "fail" on 0 line output, we need to ignore that diff --git a/resources/libraries/bash/entry/tox/doc_verify.sh b/resources/libraries/bash/entry/tox/doc_verify.sh deleted file mode 100644 index 7eec4b69e4..0000000000 --- a/resources/libraries/bash/entry/tox/doc_verify.sh +++ /dev/null @@ -1,51 +0,0 @@ -# Copyright (c) 2022 Cisco and/or its affiliates. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at: -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -set -xeuo pipefail - -# This file should be executed from tox, as the assumend working directory -# is different from where this file is located. -# This file does not have executable flag nor shebang, -# to dissuade non-tox callers. - -# "set -eu" handles failures from the following two lines. -BASH_CHECKS_DIR="$(dirname $(readlink -e "${BASH_SOURCE[0]}"))" -BASH_FUNCTION_DIR="$(readlink -e "${BASH_CHECKS_DIR}/../../function")" -source "${BASH_FUNCTION_DIR}/common.sh" || { - echo "Source failed." >&2 - exit 1 -} -source "${BASH_FUNCTION_DIR}/docs.sh" || die "Source failed." -common_dirs || die -activate_virtualenv || die - -# Documentation generation. -# Here we do store only stderr to file while stdout (inlcuding Xtrace) is -# printed to console. This way we can track increased errors in future. -# We do not need to do trap as the env will be closed after tox finished the -# task. -exec 3>&1 || die -export BASH_XTRACEFD="3" || die -log_file="$(pwd)/doc_verify.log" || die - -generate_docs 2> ${log_file} || die - -if [[ "${DOCS_EXIT_STATUS}" != 0 ]]; then - # Failed to generate report. - warn - warn "Doc verify checker: FAIL" - exit 1 -fi - -warn -warn "Doc verify checker: PASS" diff --git a/resources/libraries/bash/entry/tox/fix_copyright_year.sh b/resources/libraries/bash/entry/tox/fix_copyright_year.sh new file mode 100644 index 0000000000..d822f272af --- /dev/null +++ b/resources/libraries/bash/entry/tox/fix_copyright_year.sh @@ -0,0 +1,55 @@ +# Copyright (c) 2024 Cisco and/or its affiliates. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at: +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set -exuo pipefail + +# This file should be executed from tox, as the assumed working directory +# is different from where this file is located. +# This file does not have executable flag nor shebang, +# to dissuade non-tox callers. + +# This is a fixer script, so be careful before starting it. +# It is recommended to always commit your recent edits before running this, +# and use "git diff" after running this to confirm the edits are correct. +# Otherwise you can lose your edits and introduce bad edits. + +# This script runs a variant of "git diff" command +# to get the list of edited files, and few sed commands to edit the year +# if "20.." pattern matches in first 3 lines. +# No detection of "copyright", so edits can apply at surprising places. + +# 3 lines were chosen, because first two lines could be shebang and empty line. + +# "set -eu" handles failures from the following two lines. +BASH_CHECKS_DIR="$(dirname $(readlink -e "${BASH_SOURCE[0]}"))" +BASH_FUNCTION_DIR="$(readlink -e "${BASH_CHECKS_DIR}/../../function")" +source "${BASH_FUNCTION_DIR}/common.sh" || { + echo "Source failed." >&2 + exit 1 +} + +year=$(date +'%Y') +IFS=$'\n' +files=($(git diff --name-only HEAD~ || true)) +unset IFS +# A change can have thousands of files, supress console output for the cycle. +set +x +for fil in "${files[@]}"; do + if [[ -f "${fil}" ]]; then + sed -i "1 s/20../${year}/g" "${fil}" + sed -i "2 s/20../${year}/g" "${fil}" + sed -i "3 s/20../${year}/g" "${fil}" + # Else the file was actually deleted and sed would fail. + fi +done +set -x diff --git a/resources/libraries/bash/entry/tox/model_version.sh b/resources/libraries/bash/entry/tox/model_version.sh deleted file mode 100644 index 2bcc628bfb..0000000000 --- a/resources/libraries/bash/entry/tox/model_version.sh +++ /dev/null @@ -1,65 +0,0 @@ -# Copyright (c) 2022 Cisco and/or its affiliates. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at: -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -set -exuo pipefail - -# This file should be executed from tox, as the assumed working directory -# is different from where this file is located. -# This file does not have executable flag nor shebang, -# to dissuade non-tox callers. - -# This script runs a two grep commands as "if" conditions, -# using log files to store the data (generated by git commands) to grep, -# failing when model implementation edits do not come with model version edit. -# The contents of the log files may be useful when fail cause is not obvious. - -# "set -eu" handles failures from the following two lines. -BASH_CHECKS_DIR="$(dirname $(readlink -e "${BASH_SOURCE[0]}"))" -BASH_FUNCTION_DIR="$(readlink -e "${BASH_CHECKS_DIR}/../../function")" -source "${BASH_FUNCTION_DIR}/common.sh" || { - echo "Source failed." >&2 - exit 1 -} - -impl_log="edited_files.log" -git diff --name-only HEAD~ > "${impl_log}" -if ! grep -q '^docs/model/current/schema/test_case*' "${impl_log}"; then - # Failing grep means no model edits. - warn "No model implementation edits detected." - warn - warn "CSIT model version checker: PASS" - exit 0 -fi -const_log="constants_edits.log" -git diff -U0 HEAD~ -- "resources/libraries/python/Constants.py" > "${const_log}" -if ! grep -q '^\+ MODEL_VERSION = ' "${const_log}"; then - warn "Model implementation edits without version edit detected!" - warn "See ${impl_log} and ${const_log} for what was detected." - warn - warn "CSIT model version checker: FAIL" - exit 1 -fi -doc_log="docs_edits.log" -git diff -U0 HEAD~ -- "docs/model/current/top.rst" > "${doc_log}" -if ! grep -q '^\+This document is valid for CSIT model' "${doc_log}"; then - warn "Model implementation edits without documentation update detected!" - warn "See ${impl_log}, ${const_log} and ${doc_log} for what was detected." - warn - warn "CSIT model version checker: FAIL" - exit 1 -fi -# TODO: Check constants and docs are specifying the same version. -warn "Model version and doc are edited, model implementation edits are allowed." -warn -warn "CSIT model version checker: PASS" -exit 0 |