@@ -121,3 +121,143 @@ patch: && version
121121run cmd * args :
122122 @ echo " Running: {{ cmd}} {{ args}} (run gen manually if needed)"
123123 @ go run {{ go_base_flags}} ./ cmd/ {{ cmd}} {{ args}}
124+
125+ # =============================================================================
126+ # Integration Tests
127+ # =============================================================================
128+
129+ agent_gnmi_test_dir := " test/integration/agent-gnmi"
130+ agent_gnmi_images_dir := agent_gnmi_test_dir + " /images"
131+
132+ # Build agent binary for integration tests
133+ build-agent :
134+ @ echo " Building agent binary for integration tests..."
135+ {{ go_linux_build}} -o ./ bin/ agent ./ cmd/ agent
136+ @ echo " Agent binary built: ./bin/agent"
137+
138+ # Prepare SONiC VS image
139+ sonic-vs-prep :
140+ @ echo " Preparing SONiC VS images..."
141+ @ mkdir -p {{ agent_gnmi_images_dir}}
142+ @ echo " "
143+ @ echo " TODO: Download SONiC VS image"
144+ @ echo " For now, you need to manually place the following files in {{ agent_gnmi_images_dir}} :"
145+ @ echo " - sonic-vs.qcow2 (SONiC VS disk image)"
146+ @ echo " - efi_code.fd (EFI code firmware)"
147+ @ echo " - efi_vars.fd (EFI vars firmware)"
148+
149+ # Internal helper to run agent-gnmi integration tests with custom parameters
150+ _ test-agent-gnmi extra_args = " ": build-agent
151+ cd {{ agent_gnmi_test_dir}} && \
152+ go test -v -timeout 30 m \
153+ - target=vs \
154+ - agent-binary=../ ../ ../ bin/ agent \
155+ - cache-dir=./ images \
156+ {{ extra_args}} \
157+ ./ ...
158+
159+ # Run agent-gnmi integration tests (Virtual Switch)
160+ test-agent-gnmi-vs : (_test-agent-gnmi " " )
161+
162+ # Run agent-gnmi integration tests with verbose output
163+ test-agent-gnmi-verbose : (_test-agent-gnmi " -test.v" )
164+
165+ # Run agent-gnmi integration tests and keep VM on failure for debugging
166+ test-agent-gnmi-debug : (_test-agent-gnmi " -keep-on-failure=true" )
167+
168+ # Build agent control utility
169+ build-agent-utils :
170+ @ echo " Building agent control utility..."
171+ cd {{ agent_gnmi_test_dir}} && \
172+ go build -o bin/ agent-ctl ./ cmd/ agent-ctl
173+ @ echo " Utility built: {{ agent_gnmi_test_dir}} /bin/agent-ctl"
174+
175+ # Start SONiC VS manually for development/debugging
176+ sonic-vs-up :
177+ @ echo " Starting SONiC VS..."
178+ @ if [ ! -f {{ agent_gnmi_images_dir}} / sonic-vs.qcow2 ]; then \
179+ echo " ERROR: SONiC VS image not found at {{ agent_gnmi_images_dir}} /sonic-vs.qcow2" ; \
180+ echo " Run 'just sonic-vs-prep' for instructions" ; \
181+ exit 1 ; \
182+ fi
183+ @ echo " "
184+ @ echo " VM will start with:"
185+ @ echo " - SSH: localhost:2222"
186+ @ echo " - gNMI: localhost:8080"
187+ @ echo " - Serial console: ./test/integration/agent-gnmi/images/serial.log"
188+ @ echo " "
189+ @ echo " To stop: just sonic-vs-down"
190+ @ echo " To connect: ssh -i {{ agent_gnmi_test_dir}} /sshkey admin@localhost -p 2222"
191+ @ echo " "
192+ @ cd {{ agent_gnmi_images_dir}} && \
193+ qemu-system-x86 _64 \
194+ - name sonic-vs-debug \
195+ - m 4096 M \
196+ - machine q35 ,accel=kvm,smm=on \
197+ - cpu host \
198+ - smp 4 \
199+ - drive if =none,file=sonic-vs.qcow2,id=disk1 \
200+ - device virtio-blk-pci,drive=disk1,bootindex=1 \
201+ - drive if =pflash,file=efi_code.fd,format=raw,readonly=on \
202+ - drive if =pflash,file=efi_vars.fd,format=raw \
203+ - netdev user,id=mgmt,hostfwd=tcp::2222 -:22 ,hostfwd=tcp::8080 -:8080 \
204+ - device e1000,netdev=mgmt \
205+ - nographic \
206+ - serial mon:stdio
207+
208+ # Stop SONiC VS (graceful shutdown)
209+ sonic-vs-down :
210+ @ echo " Stopping SONiC VS..."
211+ @ if ! pgrep -f " qemu-system-x86_64.*sonic-vs" > / dev/ null; then \
212+ echo " SONiC VS is not running" ; \
213+ exit 0; \
214+ fi
215+ @ ssh -i {{ agent_gnmi_test_dir}} / sshkey \
216+ - o StrictHostKeyChecking=no \
217+ - o UserKnownHostsFile=/ dev/ null \
218+ - o ConnectTimeout=5 \
219+ - p 2222 admin@localhost ' sudo poweroff' 2 >/ dev/ null || \
220+ (echo " Could not connect via SSH, sending SIGTERM to QEMU..." && \
221+ pkill -TERM -f " qemu-system-x86_64.*sonic-vs" )
222+ @ echo " SONiC VS shutdown initiated"
223+
224+ # Check if SONiC VS is running
225+ sonic-vs-status :
226+ @ echo " SONiC VS status:"
227+ @ if pgrep -f " qemu-system-x86_64.*sonic-vs" > / dev/ null; then \
228+ echo " VM: Running (PID: $$(pgrep -f 'qemu-system-x86_64.*sonic-vs'))" ; \
229+ if nc -z localhost 2222 2 >/ dev/ null; then \
230+ echo " SSH: Accessible on localhost:2222" ; \
231+ else \
232+ echo " SSH: Not accessible (VM may still be booting)" ; \
233+ fi; \
234+ if nc -z localhost 8080 2 >/ dev/ null; then \
235+ echo " gNMI: Accessible on localhost:8080" ; \
236+ else \
237+ echo " gNMI: Not accessible" ; \
238+ fi; \
239+ else \
240+ echo " VM: Not running" ; \
241+ fi
242+
243+ # Connect to SONiC VS via SSH
244+ sonic-vs-ssh :
245+ @ ssh -i {{ agent_gnmi_test_dir}} / sshkey \
246+ - o StrictHostKeyChecking=no \
247+ - o UserKnownHostsFile=/ dev/ null \
248+ admin@localhost -p 2222
249+
250+ # Install agent on running SONiC VS
251+ sonic-vs-agent-install : build-agent build-agent-utils
252+ @ cd {{ agent_gnmi_test_dir}} && \
253+ ./ bin/ agent-ctl -v install
254+
255+ # Uninstall agent from running SONiC VS
256+ sonic-vs-agent-uninstall : build-agent-utils
257+ @ cd {{ agent_gnmi_test_dir}} && \
258+ ./ bin/ agent-ctl -v uninstall
259+
260+ # Check agent status on running SONiC VS
261+ sonic-vs-agent-status : build-agent-utils
262+ @ cd {{ agent_gnmi_test_dir}} && \
263+ ./ bin/ agent-ctl status
0 commit comments