kvm2: apply the milestone review
Shorter start wait with immediate verdicts for dead or paused domains, ListByTag without state or address RPCs, Timeout for an expired check round, no adoption of unmarked domains, reference-counted keyed locks, dead options removed, HEAD fallback on any non-2xx. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
@@ -72,8 +72,43 @@ func TestListByTag_acrossHostsInConfigOrder(t *testing.T) {
|
||||
if got := listIDs(list); strings.Join(got, ",") != strings.Join(want, ",") {
|
||||
t.Errorf("ListByTag = %v, want %v (config order, then name order)", got, want)
|
||||
}
|
||||
if list[0].State != provider.StateStopped || list[1].State != provider.StateProvisioning {
|
||||
t.Errorf("states = %s, %s, want Stopped, Provisioning", list[0].State, list[1].State)
|
||||
if list[0].UID != "uid-a" || list[1].UID != "uid-z" || list[2].UID != "uid-b" {
|
||||
t.Errorf("uids = %s, %s, %s, want uid-a, uid-z, uid-b", list[0].UID, list[1].UID, list[2].UID)
|
||||
}
|
||||
}
|
||||
|
||||
func TestListByTag_doesNotReadStateOrAddresses(t *testing.T) {
|
||||
t.Parallel()
|
||||
fx := newFixture(t, 2)
|
||||
id := fx.create(testName)
|
||||
fx.setAddrs(testName, libvirt.DomainInterfaceAddressesSrcAgent, "10.0.0.5")
|
||||
fx.fake.addDomain("proxy-off", libvirt.DomainShutoff, managedMetadata("uid-off", time.Now()))
|
||||
before := len(fx.fake.callLog())
|
||||
|
||||
list, err := fx.p.ListByTag(fx.ctx)
|
||||
if err != nil {
|
||||
t.Fatalf("ListByTag() error = %v", err)
|
||||
}
|
||||
if len(list) != 2 || list[0].ID != id || list[1].ID != formatProviderID(testHost, "proxy-off") {
|
||||
t.Fatalf("ListByTag = %v, want the two managed domains", listIDs(list))
|
||||
}
|
||||
for _, inst := range list {
|
||||
if inst.State != "" || inst.IP != "" {
|
||||
t.Errorf("listed %s = state %q ip %q, want both empty: GC does not use them", inst.ID, inst.State, inst.IP)
|
||||
}
|
||||
if inst.UID == "" || inst.CreatedAt.IsZero() {
|
||||
t.Errorf("listed %s lacks uid or createdAt: %+v", inst.ID, inst)
|
||||
}
|
||||
}
|
||||
for _, rpc := range fx.fake.callLog()[before:] {
|
||||
switch rpc {
|
||||
case "ConnectListAllDomains", "DomainGetMetadata":
|
||||
default:
|
||||
t.Errorf("ListByTag made %s; want only the listing and one metadata read per domain", rpc)
|
||||
}
|
||||
}
|
||||
if got := fx.logs.matching("kvm2 listed instance"); len(got) != 2 || strings.Contains(got[0], `"state"=`) {
|
||||
t.Errorf("listed instance lines = %v, want two without a state", got)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,12 +161,12 @@ func TestListByTag_unreadableDomainSkipped(t *testing.T) {
|
||||
line: "skipping domain with unreadable metadata",
|
||||
},
|
||||
{
|
||||
name: "state rpc fails for the first domain only",
|
||||
name: "domain gone between listing and metadata read",
|
||||
setup: func(fx *fixture) {
|
||||
fx.fake.addDomain("proxy-bad", libvirt.DomainRunning, managedMetadata("uid-bad", time.Now()))
|
||||
var calls int
|
||||
fx.fake.mu.Lock()
|
||||
fx.fake.hooks["DomainGetState"] = func() error {
|
||||
fx.fake.hooks["DomainGetMetadata"] = func() error {
|
||||
calls++
|
||||
if calls == 1 {
|
||||
return fakeErr(libvirt.ErrNoDomain, "Domain not found")
|
||||
@@ -140,7 +175,7 @@ func TestListByTag_unreadableDomainSkipped(t *testing.T) {
|
||||
}
|
||||
fx.fake.mu.Unlock()
|
||||
},
|
||||
line: "skipping domain that could not be inspected",
|
||||
line: "skipping domain with unreadable metadata",
|
||||
},
|
||||
}
|
||||
for _, tc := range tests {
|
||||
@@ -172,7 +207,7 @@ func TestListByTag_includesInactiveDomains(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("ListByTag() error = %v", err)
|
||||
}
|
||||
if len(list) != 1 || list[0].ID != id || list[0].State != provider.StateStopped {
|
||||
t.Errorf("ListByTag = %+v, want the shut-off domain as Stopped", list)
|
||||
if len(list) != 1 || list[0].ID != id || list[0].UID != testUID {
|
||||
t.Errorf("ListByTag = %+v, want the shut-off domain listed with its uid", list)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user