build: separate Go caches from project tools - #767
Conversation
|
/azp run |
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
There was a problem hiding this comment.
Pull request overview
This PR refactors the build and test workflow to keep Go tool/cache state in the invoking user’s normal Go locations while ensuring repository artifacts (products, pinned tools, and test fixtures) live under build/. It also updates tests and runtime code to make filesystem paths (checkpoints, host roots, DB configs, shared-memory keys) configurable so tests can run without sudo and without writing to system-owned locations.
Changes:
- Move product outputs to
build/binand pin build/test tools underbuild/tools/bin(Makefile +pure.mk). - Rework test fixture/runtime setup to use repo-owned paths and env vars (DB config path, runtime root, checkpoint dir, shared-memory key), removing
sudofrom test runs. - Update documentation and CI to align with the new build/test layout and pinned-tool workflow.
Reviewed changes
Copilot reviewed 25 out of 26 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| tools/test/env.sh | Wrapper now forwards CLI args to the upstream test env script; retains a default mode for local usage. |
| test/utils.py | Removes sudo from gnmi_dump invocation to support non-root test execution. |
| test/test_gnmi_configdb.py | Makes checkpoint location configurable via SONIC_GNMI_CHECKPOINT_DIR. |
| test/test_gnmi_configdb_patch.py | Makes checkpoint location configurable via SONIC_GNMI_CHECKPOINT_DIR. |
| test_utils/test_utils.go | Builds DB fixture files under a configurable runtime root and writes global DB config dynamically. |
| swsscommon/Makefile | Cleans only the SWIG-generated artifacts and copied interface file. |
| sonic_db_config/db_config.go | Uses DB_CONFIG_PATH and derived global config path to initialize DB config via swsscommon. |
| sonic_db_config/db_config_test.go | Updates fatal messages for clearer errors on fixture setup failures. |
| sonic_data_client/mixed_db_client.go | Makes checkpoint base dir configurable for tests/runtime. |
| sonic_data_client/client_test.go | Adds TestMain setup for configurable checkpoint directory. |
| README.md | Updates build instructions and clarifies artifact/tool output locations. |
| pure.mk | Pins test/coverage/security tools under build/tools/bin and uses -mod=readonly for purity targets. |
| proto/gnoi/README.md | Updates proto regeneration guidance to use Make targets + pinned tools. |
| Makefile | Major build/test refactor: pinned tools, repo-owned fixtures, no-sudo Go tests, explicit product binary manifest for packaging. |
| go.sum | Adds checksum entry for golang.org/x/time v0.11.0. |
| go.mod | Bumps github.com/golang/glog and adds explicit golang.org/x/time v0.11.0. |
| gnmi_server/server.go | Makes host log root overridable for tests via an unexported variable. |
| gnmi_server/server_test.go | Uses temp directories for journal/healthz/pathz/checkpoint test artifacts. |
| gnmi_server/gnsi_pathz_test.go | Switches Pathz test file paths to variables (set by TestMain). |
| gnmi_server/gnoi_healthz.go | Makes host root configurable for tests by replacing hard-coded /mnt/host with a variable. |
| gnmi_server/gnoi_healthz_test.go | Updates healthz tests to build container paths using the configurable host root. |
| gnmi_server/db_journal.go | Uses overridable host log root for journal file IO. |
| gnmi_server/db_journal_test.go | Updates journal tests to use overridable host log root. |
| doc/telemetry-dev-env/Dockerfile | Removes GOPATH customization from the dev image; keeps Go on PATH via GOROOT. |
| common_utils/shareMem.go | Allows overriding the SysV shared-memory key via SONIC_GNMI_SHM_KEY for tests. |
| azure-pipelines.yml | Removes GOPATH/bin from PATH setup, aligning with pinned-tool approach. |
Suppressed comments (4)
gnmi_server/gnoi_healthz_test.go:658
filepath.Join(healthzHostRoot, req.GetId())ignoreshealthzHostRootbecause the request ID is absolute (starts with "/"). Trim the leading slash so the test creates the artifact under the configured host root.
realPath := filepath.Join(healthzHostRoot, req.GetId())
gnmi_server/gnoi_healthz_test.go:706
filepath.Join(healthzHostRoot, req.GetId())ignoreshealthzHostRootbecause the request ID is absolute (starts with "/"). Trim the leading slash so the test creates the artifact under the configured host root.
realPath := filepath.Join(healthzHostRoot, req.GetId())
gnmi_server/gnoi_healthz_test.go:744
filepath.Join(healthzHostRoot, req.GetId())ignoreshealthzHostRootbecause the request ID is absolute (starts with "/"). Trim the leading slash so the test creates the artifact under the configured host root.
realPath := filepath.Join(healthzHostRoot, req.GetId())
gnmi_server/gnoi_healthz_test.go:783
filepath.Join(healthzHostRoot, req.GetId())ignoreshealthzHostRootbecause the request ID is absolute (starts with "/"). Trim the leading slash so the test creates the artifact under the configured host root.
realPath := filepath.Join(healthzHostRoot, req.GetId())
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| return nil, status.Errorf(codes.InvalidArgument, "Invalid artifact path") | ||
| } | ||
| file_path := filepath.Join("/mnt/host", cleanPath) | ||
| file_path := filepath.Join(healthzHostRoot, cleanPath) |
| return status.Errorf(codes.InvalidArgument, "Invalid artifact path") | ||
| } | ||
| file_path := filepath.Join("/mnt/host", cleanPath) | ||
| file_path := filepath.Join(healthzHostRoot, cleanPath) |
| req := &healthz.ArtifactRequest{Id: "/tmp/dump/seek_fail.txt"} | ||
|
|
||
| realPath := "/mnt/host/tmp/dump/seek_fail.txt" | ||
| realPath := filepath.Join(healthzHostRoot, req.GetId()) |
| func TestMain(m *testing.M) { | ||
| checkpointDir, err := os.MkdirTemp("", "sonic-checkpoint-") | ||
| if err != nil { | ||
| panic(err) | ||
| } | ||
| testFile = filepath.Join(checkpointDir, "ut.cp.json") | ||
| os.Setenv("SONIC_GNMI_CHECKPOINT_DIR", checkpointDir) | ||
| defer os.RemoveAll(checkpointDir) | ||
| defer test_utils.MemLeakCheck() | ||
| m.Run() | ||
| } |
| . ${TOPDIR}/../sonic-mgmt-common/tools/test/env.sh \ | ||
| --dest=${TOPDIR}/build/test \ | ||
| --dbconfig-in=${TOPDIR}/testdata/database_config.json |
| // Create both host and container path versions | ||
| dummy_hostfile := "/tmp/dump/fake-collect-success" | ||
| dummy_containerfile := "/mnt/host/tmp/dump/fake-collect-success" | ||
| dummy_containerfile := filepath.Join(healthzHostRoot, dummy_hostfile) |
|
/azp run |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
|
/azp run |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
|
/azp run |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
75fafc8 to
445f985
Compare
|
/azp run |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 14 out of 14 changed files in this pull request and generated 4 comments.
Suppressed comments (2)
gnmi_server/server_test.go:6941
- After introducing an exit-code variable in TestMain, capture the return value of m.Run() into it so the deferred os.Exit uses the real test status.
defer test_utils.MemLeakCheck()
m.Run()
}
gnmi_server/server_test.go:6914
- TestMain must call os.Exit with the result of m.Run(); otherwise go test exits with status 0 even when tests fail. Adding a deferred os.Exit wrapper at the top preserves the existing defers (temp dir cleanup + MemLeakCheck) while still returning the correct exit code.
func TestMain(m *testing.M) {
journalDir, err := os.MkdirTemp("", "gnmi-journal-")
if err != nil {
panic(err)
}
|
/azp run |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
006aaa3 to
8107ab5
Compare
|
/azp run |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
Signed-off-by: Dawei Huang <daweihuang@microsoft.com>
8107ab5 to
38cbcad
Compare
|
/azp run |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
Suppressed comments (1)
Makefile:41
- Pinned tool versions diverge from
pure.mk(gotestsum v1.13.0 here vs v1.12.3 inpure.mk; gocov-xml v1.2.0 here vs v1.1.0). Keeping multiple pinned versions for the same tooling can lead to different output/behavior across targets; consider aligning or centralizing versions.
GOTESTSUM := $(abspath $(TOOLS_BIN_DIR)/gotestsum-v1.13.0)
GOCOV := $(abspath $(TOOLS_BIN_DIR)/gocov-v1.1.0)
GOCOV_XML := $(abspath $(TOOLS_BIN_DIR)/gocov-xml-v1.2.0)
Signed-off-by: Dawei Huang <daweihuang@microsoft.com>
|
/azp run |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
Why
GOPATH=/tmp/gomakes privileged and unprivileged Go commands share module and checksum cache state. Root-owned cache files can then block later unprivileged commands after tests pass.Go caches are user state, not repository artifacts. Repository tools also need stable locations that do not depend on ambient
PATHstate.What changes
GOPATH.go listinstead ofGOPATH/pkg/mod.build/tools/binand exact invocation paths.sudorun in an explicit root environment with root default caches.Long-term direction
build/bin.build/tools/bin.sudoand use project-local fixtures.Scope
This PR changes cache and tool ownership only. It does not change product binaries, packaging, fixtures,
sudousage, or cleanup behavior.The
sonic-mgmt-commonpatch helper remains unchanged. It still assumes its default$GOPATH/pkg/modmodule-cache path.Validation
sonic-gnmichecks for commitafb6db7.make -f pure.mk junit-xmlpassed 853 tests and generated Cobertura XML.amd64host executable.Tracking: Azure DevOps Task 39393252.