diff --git a/agent/internal/hypervisor/delete_test.go b/agent/internal/hypervisor/delete_test.go index 64f2474b..3fa4079e 100644 --- a/agent/internal/hypervisor/delete_test.go +++ b/agent/internal/hypervisor/delete_test.go @@ -168,3 +168,18 @@ func TestVirshDeleteDomainLeavesUncertainWhenAbsenceReadbackFails(t *testing.T) t.Fatalf("ambiguous delete was reported removed: %+v", result) } } + +func TestVirshMissingDiagnosticClassifierIsNarrow(t *testing.T) { + if !virshReportsMissingDomain([]byte("error: Domain not found: no domain with matching uuid '" + testUUID + "'")) { + t.Fatal("canonical UUID absence diagnostic was not recognized") + } + for _, diagnostic := range []string{ + "error: domain not found while contacting storage", + "error: no domain with matching name 'vm'", + "transport failed: domain not found", + } { + if virshReportsMissingDomain([]byte(diagnostic)) { + t.Fatalf("unrelated diagnostic was classified as UUID absence: %q", diagnostic) + } + } +} diff --git a/agent/internal/hypervisor/virsh.go b/agent/internal/hypervisor/virsh.go index 14698a98..661c0d52 100644 --- a/agent/internal/hypervisor/virsh.go +++ b/agent/internal/hypervisor/virsh.go @@ -122,9 +122,11 @@ func (r ExecRunner) Run(ctx context.Context, args ...string) ([]byte, error) { // opaque transport failure and therefore uncertain. func virshReportsMissingDomain(data []byte) bool { message := strings.ToLower(string(data)) - return strings.Contains(message, "domain not found") || - strings.Contains(message, "no domain with matching uuid") || - strings.Contains(message, "no domain with matching name") + // The UUID-targeted dumpxml form used by this adapter emits the second + // phrase below with LC_ALL=C. Do not match a broad "domain not found" + // substring: unrelated storage/transport diagnostics could contain those + // words and would otherwise turn an ambiguous failure into false absence. + return strings.Contains(message, "no domain with matching uuid") } // VirshBackend is a host-local implementation of Backend. It never changes