Skip to content

Commit b7d6f4d

Browse files
author
Uwe Schwaeke
committed
fix(nova): always emit server image field, "" for boot-from-volume
The single-server GET only set response["image"] when image_id was non-NULL, so a boot-from-volume server omitted the key entirely. Horizon's instance-detail view reads server.image unconditionally, so novaclient raised "AttributeError: image" and the page 500'd. /detail already emitted "" for that case, so the two handlers had drifted. Extract serverImageField(), shared by both handlers: an {id} object for an image-booted server, "" for a boot-from-volume one — present either way, matching upstream Nova. Assisted-by: Claude:claude-opus-4-8 Signed-off-by: Uwe Schwaeke <uwe.schwaeke@sap.com>
1 parent 0b7122f commit b7d6f4d

2 files changed

Lines changed: 37 additions & 8 deletions

File tree

‎internal/nova/handlers.go‎

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1619,11 +1619,7 @@ func (svc *Service) ListServersDetail(c *gin.Context) {
16191619
} else {
16201620
entry["key_name"] = nil
16211621
}
1622-
if imageID.Valid {
1623-
entry["image"] = gin.H{"id": imageID.String}
1624-
} else {
1625-
entry["image"] = ""
1626-
}
1622+
entry["image"] = serverImageField(imageID)
16271623
if launchedAt.Valid {
16281624
entry["OS-SRV-USG:launched_at"] = launchedAt.Time.Format(time.RFC3339)
16291625
} else {
@@ -1867,6 +1863,18 @@ func addressEntry(addr, kind string) gin.H {
18671863
}
18681864

18691865
// GetServer returns details for a single server
1866+
// serverImageField renders a server response's "image" member: an {id} object for an
1867+
// image-booted server, and "" for a boot-from-volume server (image_id NULL), matching
1868+
// upstream Nova. The key must ALWAYS be present — Horizon reads server.image
1869+
// unconditionally (instance detail view), and a missing key makes novaclient raise
1870+
// AttributeError. Shared by the list and single-server handlers so they cannot drift.
1871+
func serverImageField(imageID sql.NullString) any {
1872+
if imageID.Valid {
1873+
return gin.H{"id": imageID.String}
1874+
}
1875+
return ""
1876+
}
1877+
18701878
func (svc *Service) GetServer(c *gin.Context) {
18711879
// Owner-or-administrator: an administrator may show any project's server
18721880
// (SPEC-023 FR-004). The lookup below is then keyed on the resolved id and
@@ -1929,9 +1937,7 @@ func (svc *Service) GetServer(c *gin.Context) {
19291937
if flavorID.Valid {
19301938
response["flavor"] = gin.H{"id": flavorID.String}
19311939
}
1932-
if imageID.Valid {
1933-
response["image"] = gin.H{"id": imageID.String}
1934-
}
1940+
response["image"] = serverImageField(imageID)
19351941

19361942
// key_name: always present; null when the instance has no keypair (FR-001).
19371943
if keyName.Valid {
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package nova
2+
3+
import (
4+
"database/sql"
5+
"testing"
6+
7+
"github.com/gin-gonic/gin"
8+
)
9+
10+
// A server response must always carry an "image" member: an {id} object for an
11+
// image-booted server, and "" for a boot-from-volume server. Horizon's instance detail
12+
// view reads server.image unconditionally, so omitting it (the old single-server bug)
13+
// made novaclient raise "AttributeError: image".
14+
func TestServerImageField(t *testing.T) {
15+
img := serverImageField(sql.NullString{String: "img-1", Valid: true})
16+
m, ok := img.(gin.H)
17+
if !ok || m["id"] != "img-1" {
18+
t.Errorf("image-boot: serverImageField = %#v, want gin.H{id: img-1}", img)
19+
}
20+
if got := serverImageField(sql.NullString{}); got != "" {
21+
t.Errorf("boot-from-volume: serverImageField = %#v, want \"\" (present, empty)", got)
22+
}
23+
}

0 commit comments

Comments
 (0)