From 52a4a6c4c89846045988ef7869c3db5cbea3cd1f Mon Sep 17 00:00:00 2001 From: Muhamad Awad Date: Thu, 1 Feb 2024 09:30:24 +0100 Subject: [PATCH] add compatibility to still support ygg_ip for old workloads (#2193) --- pkg/gridtypes/zos/zmachine.go | 24 ++++++++++++++++++++++++ pkg/gridtypes/zos/zmachine_test.go | 22 ++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/pkg/gridtypes/zos/zmachine.go b/pkg/gridtypes/zos/zmachine.go index f3c38b8a8..a544ede2d 100644 --- a/pkg/gridtypes/zos/zmachine.go +++ b/pkg/gridtypes/zos/zmachine.go @@ -350,3 +350,27 @@ type ZMachineResult struct { PlanetaryIP string `json:"planetary_ip"` ConsoleURL string `json:"console_url"` } + +func (r *ZMachineResult) UnmarshalJSON(data []byte) error { + var deprecated struct { + ID string `json:"id"` + IP string `json:"ip"` + YggIP string `json:"ygg_ip"` + PlanetaryIP string `json:"planetary_ip"` + ConsoleURL string `json:"console_url"` + } + + if err := json.Unmarshal(data, &deprecated); err != nil { + return err + } + + r.ID = deprecated.ID + r.IP = deprecated.IP + r.PlanetaryIP = deprecated.PlanetaryIP + if deprecated.YggIP != "" { + r.PlanetaryIP = deprecated.YggIP + } + r.ConsoleURL = deprecated.ConsoleURL + + return nil +} diff --git a/pkg/gridtypes/zos/zmachine_test.go b/pkg/gridtypes/zos/zmachine_test.go index 888728e86..9737bef1e 100644 --- a/pkg/gridtypes/zos/zmachine_test.go +++ b/pkg/gridtypes/zos/zmachine_test.go @@ -1,6 +1,7 @@ package zos import ( + "encoding/json" "testing" "github.com/stretchr/testify/require" @@ -94,3 +95,24 @@ func TestZMachineSRU(t *testing.T) { }) } } + +func TestResultDeprecated(t *testing.T) { + raw := ` { + "id": "192-74881-testing2", + "ip": "10.20.2.2", + "ygg_ip": "32b:8310:9b03:5529:ff0f:37cd:de80:b322", + "console_url": "10.20.2.0:20002" + }` + + var result ZMachineResult + + err := json.Unmarshal([]byte(raw), &result) + require.NoError(t, err) + + require.EqualValues(t, ZMachineResult{ + ID: "192-74881-testing2", + IP: "10.20.2.2", + PlanetaryIP: "32b:8310:9b03:5529:ff0f:37cd:de80:b322", + ConsoleURL: "10.20.2.0:20002", + }, result) +}