fix: narrow virsh domain absence classification

go-agent
admin 1 month ago
parent 0599909d28
commit a592b69f83

@ -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)
}
}
}

@ -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

Loading…
Cancel
Save