Skip to content

Commit d96981a

Browse files
Distro CLI: Add integration tests and test topology
- Add device_integration_test.py with end-to-end update tests - Add test topology infrastructure with start.sh script - Add integration test data (manifest, build scripts, dummy artifacts) - Update update_service.sh to resolve symlinks for systemd RootDirectory This completes the device update feature with integration testing.
1 parent 9584e6e commit d96981a

File tree

9 files changed

+720
-4
lines changed

9 files changed

+720
-4
lines changed

cmake/FbossImageDistroCliTests.cmake

Lines changed: 76 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,16 @@ list(FILTER DISTRO_CLI_TEST_SOURCES EXCLUDE REGEX "image_builder_test\\.py$")
2929
list(FILTER DISTRO_CLI_TEST_SOURCES EXCLUDE REGEX "kernel_build_test\\.py$")
3030
list(FILTER DISTRO_CLI_TEST_SOURCES EXCLUDE REGEX "sai_build_test\\.py$")
3131

32-
# Exclude: Docker not available
32+
# Exclude: Docker not available in standard builds
3333
list(FILTER DISTRO_CLI_TEST_SOURCES EXCLUDE REGEX "build_entrypoint_test\\.py$")
3434
list(FILTER DISTRO_CLI_TEST_SOURCES EXCLUDE REGEX "build_test\\.py$")
3535
list(FILTER DISTRO_CLI_TEST_SOURCES EXCLUDE REGEX "docker_test\\.py$")
3636

37+
# Separate integration tests (require Docker) from unit tests
38+
file(GLOB DISTRO_CLI_INTEGRATION_TEST_SOURCES
39+
"fboss-image/distro_cli/tests/device_integration_test.py"
40+
)
41+
3742
file(GLOB DISTRO_CLI_TEST_HELPERS
3843
"fboss-image/distro_cli/tests/test_helpers.py"
3944
)
@@ -45,7 +50,7 @@ file(GLOB_RECURSE DISTRO_CLI_LIB_SOURCES
4550
"fboss-image/distro_cli/tools/*.py"
4651
)
4752

48-
# Create Python unittest executable with test data files
53+
# Create Python unittest executable for unit tests
4954
# Use TYPE "dir" to create a directory-based executable instead of zipapp.
5055
# This allows tests to access data files via Path(__file__).parent, which
5156
# doesn't work inside zip archives.
@@ -64,6 +69,8 @@ add_fb_python_unittest(
6469
${DISTRO_CLI_LIB_SOURCES}
6570
ENV
6671
"PYTHONPATH=${CMAKE_CURRENT_SOURCE_DIR}/fboss-image"
72+
PROPERTIES
73+
LABELS "unit"
6774
)
6875

6976
# Copy test data files AFTER the build generates the directory structure
@@ -100,6 +107,73 @@ add_custom_command(
100107

101108
install_fb_python_executable(distro_cli_tests)
102109

110+
# Create Python unittest executable for integration tests (require Docker)
111+
# These tests are labeled "integration" and "docker" so they can be run separately
112+
# Run with: ctest -L integration
113+
if(DISTRO_CLI_INTEGRATION_TEST_SOURCES)
114+
add_fb_python_unittest(
115+
distro_cli_integration_tests
116+
BASE_DIR "fboss-image"
117+
TYPE "dir"
118+
SOURCES
119+
${DISTRO_CLI_INTEGRATION_TEST_SOURCES}
120+
${DISTRO_CLI_TEST_HELPERS}
121+
${DISTRO_CLI_LIB_SOURCES}
122+
ENV
123+
"PYTHONPATH=${CMAKE_CURRENT_SOURCE_DIR}/fboss-image"
124+
PROPERTIES
125+
LABELS "integration;docker"
126+
)
127+
128+
# Copy test data files for integration tests
129+
set(INTEGRATION_DATA_DEST_DIR "${CMAKE_CURRENT_BINARY_DIR}/distro_cli_integration_tests/distro_cli/tests")
130+
add_custom_command(
131+
TARGET distro_cli_integration_tests.GEN_PY_EXE
132+
POST_BUILD
133+
COMMAND ${CMAKE_COMMAND} -E copy_directory
134+
"${DATA_SOURCE_DIR}"
135+
"${INTEGRATION_DATA_DEST_DIR}/data"
136+
COMMENT "Copying test data files for distro_cli_integration_tests"
137+
)
138+
139+
# Copy scripts directory for integration tests
140+
set(INTEGRATION_SCRIPTS_DEST_DIR "${CMAKE_CURRENT_BINARY_DIR}/distro_cli_integration_tests/distro_cli/scripts")
141+
add_custom_command(
142+
TARGET distro_cli_integration_tests.GEN_PY_EXE
143+
POST_BUILD
144+
COMMAND ${CMAKE_COMMAND} -E copy_directory
145+
"${SCRIPTS_SOURCE_DIR}"
146+
"${INTEGRATION_SCRIPTS_DEST_DIR}"
147+
COMMENT "Copying scripts for distro_cli_integration_tests"
148+
)
149+
150+
# Copy proxy_device directory for integration tests
151+
set(PROXY_DEVICE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/fboss-image/distro_cli/tests/proxy_device")
152+
set(PROXY_DEVICE_DEST_DIR "${CMAKE_CURRENT_BINARY_DIR}/distro_cli_integration_tests/distro_cli/tests/proxy_device")
153+
add_custom_command(
154+
TARGET distro_cli_integration_tests.GEN_PY_EXE
155+
POST_BUILD
156+
COMMAND ${CMAKE_COMMAND} -E copy_directory
157+
"${PROXY_DEVICE_SOURCE_DIR}"
158+
"${PROXY_DEVICE_DEST_DIR}"
159+
COMMENT "Copying proxy_device for distro_cli_integration_tests"
160+
)
161+
162+
# Copy test_topology directory for integration tests
163+
set(TEST_TOPOLOGY_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/fboss-image/distro_cli/tests/test_topology")
164+
set(TEST_TOPOLOGY_DEST_DIR "${CMAKE_CURRENT_BINARY_DIR}/distro_cli_integration_tests/distro_cli/tests/test_topology")
165+
add_custom_command(
166+
TARGET distro_cli_integration_tests.GEN_PY_EXE
167+
POST_BUILD
168+
COMMAND ${CMAKE_COMMAND} -E copy_directory
169+
"${TEST_TOPOLOGY_SOURCE_DIR}"
170+
"${TEST_TOPOLOGY_DEST_DIR}"
171+
COMMENT "Copying test_topology for distro_cli_integration_tests"
172+
)
173+
174+
install_fb_python_executable(distro_cli_integration_tests)
175+
endif()
176+
103177
# Restore the original Python3_EXECUTABLE if it was set
104178
if(DEFINED SAVED_Python3_EXECUTABLE)
105179
set(Python3_EXECUTABLE "${SAVED_Python3_EXECUTABLE}")

fboss-image/distro_cli/scripts/update_service.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ SERVICES="$*"
2222

2323
SCRIPT_DIR=$(dirname "$(readlink -f "$0")")
2424
TIMESTAMP=$(date +%s)
25-
BASE_SNAPSHOT="/distro-base"
26-
UPDATES_DIR="/updates"
25+
# Resolve symlinks to real paths (needed for systemd RootDirectory which doesn't follow symlinks)
26+
BASE_SNAPSHOT="$(readlink -f /distro-base)"
27+
UPDATES_DIR="$(readlink -f /updates)"
2728

2829
echo "Updating component: ${COMPONENT}"
2930
echo "Services to restart: ${SERVICES}"

0 commit comments

Comments
 (0)