Skip to content

Commit

Permalink
NFV-25313: updated ZNPD logic to support new changes
Browse files Browse the repository at this point in the history
  • Loading branch information
schadalawada committed Aug 17, 2023
1 parent fed2e48 commit 3f59012
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 25 deletions.
18 changes: 3 additions & 15 deletions rest_device.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,6 @@ const (
//DeviceLicenseModeBYOL indicates device software license mode where
//customer provides his own, externally procured device license
DeviceLicenseModeBYOL = "BYOL"
//Connectivity type ZNPD indicates device with no internet
ConnectivityZnpd = "ZNPD"
//ZNPD indicates device with no internet
Znpd = "PRIVATE"
//DeviceManagementTypeSelfZnpd indicates device management mode where customer
//fully manages the device and device is created with no internet access
DeviceManagementTypeSelfZnpd = "SELF-CONFIGURED-ZNPD"
)

type restDeviceUpdateRequest struct {
Expand Down Expand Up @@ -246,14 +239,12 @@ func mapDeviceAPIToDomain(apiDevice api.Device) *Device {
}
if apiDevice.DeviceManagementType != nil {
if *apiDevice.DeviceManagementType == DeviceManagementTypeSelf {
if apiDevice.Connectivity != nil && strings.EqualFold(*apiDevice.Connectivity, ConnectivityZnpd) {
device.Connectivity = String(Znpd)
}
device.IsSelfManaged = Bool(true)
} else {
device.IsSelfManaged = Bool(false)
}
}
device.Connectivity = apiDevice.Connectivity
device.Interfaces = mapDeviceInterfacesAPIToDomain(apiDevice.Interfaces)
device.VendorConfiguration = apiDevice.VendorConfig
device.UserPublicKey = mapDeviceUserPublicKeyAPIToDomain(apiDevice.UserPublicKey)
Expand Down Expand Up @@ -386,15 +377,12 @@ func createDeviceRequest(device Device) api.DeviceRequest {
req.InterfaceCount = device.InterfaceCount
if device.IsSelfManaged != nil {
if *device.IsSelfManaged {
if device.Connectivity != nil && strings.EqualFold(*device.Connectivity, Znpd) {
req.DeviceManagementType = String(DeviceManagementTypeSelfZnpd)
} else {
req.DeviceManagementType = String(DeviceManagementTypeSelf)
}
req.DeviceManagementType = String(DeviceManagementTypeSelf)
} else {
req.DeviceManagementType = String(DeviceManagementTypeEquinix)
}
}
req.Connectivity = device.Connectivity
req.Core = device.CoreCount
req.AdditionalBandwidth = device.AdditionalBandwidth
req.SshInterfaceId = device.WanInterfaceId
Expand Down
17 changes: 7 additions & 10 deletions rest_device_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ func TestCreateDevice(t *testing.T) {
//then
assert.Nil(t, err, "Error is not returned")
assert.Equal(t, uuid, resp.UUID, "UUID matches")
verifyDeviceRequest(t, device, req, false)
verifyDeviceRequest(t, device, req)
}

func TestCreateZnpdDevice(t *testing.T) {
func TestCreateDeviceWithConnectivityTypeAsPrivate(t *testing.T) {
//given
resp := api.DeviceRequestResponse{}
if err := readJSONData("./test-fixtures/ne_device_create_resp.json", &resp); err != nil {
Expand Down Expand Up @@ -138,7 +138,7 @@ func TestCreateZnpdDevice(t *testing.T) {
//then
assert.Nil(t, err, "Error is not returned")
assert.Equal(t, uuid, resp.UUID, "UUID matches")
verifyDeviceRequest(t, device, req, true)
verifyDeviceRequest(t, device, req)
}

func TestCreateRedundantDevice(t *testing.T) {
Expand Down Expand Up @@ -494,7 +494,7 @@ func verifyDeviceInterface(t *testing.T, inf DeviceInterface, apiInf api.DeviceI
assert.Equal(t, apiInf.Type, inf.Type, "Type matches")
}

func verifyDeviceRequest(t *testing.T, device Device, req api.DeviceRequest, isZnpd bool) {
func verifyDeviceRequest(t *testing.T, device Device, req api.DeviceRequest) {
assert.Equal(t, device.Throughput, req.Throughput, "Throughput matches")
assert.Equal(t, device.ThroughputUnit, req.ThroughputUnit, "ThroughputUnit matches")
assert.Equal(t, device.MetroCode, req.MetroCode, "MetroCode matches")
Expand All @@ -519,11 +519,8 @@ func verifyDeviceRequest(t *testing.T, device Device, req api.DeviceRequest, isZ
assert.Equal(t, device.Version, req.Version, "Version matches")
assert.Equal(t, device.InterfaceCount, req.InterfaceCount, "InterfaceCount matches")
if *device.IsSelfManaged {
if isZnpd {
assert.Equal(t, DeviceManagementTypeSelfZnpd, StringValue(req.DeviceManagementType), "DeviceManagementType matches")
} else {
assert.Equal(t, DeviceManagementTypeSelf, StringValue(req.DeviceManagementType), "DeviceManagementType matches")
}

assert.Equal(t, DeviceManagementTypeSelf, StringValue(req.DeviceManagementType), "DeviceManagementType matches")
} else {
assert.Equal(t, DeviceManagementTypeEquinix, StringValue(req.DeviceManagementType), "DeviceManagementType matches")
}
Expand All @@ -536,7 +533,7 @@ func verifyDeviceRequest(t *testing.T, device Device, req api.DeviceRequest, isZ
}

func verifyRedundantDeviceRequest(t *testing.T, primary, secondary Device, req api.DeviceRequest) {
verifyDeviceRequest(t, primary, req, false)
verifyDeviceRequest(t, primary, req)
assert.Equal(t, secondary.MetroCode, req.Secondary.MetroCode, "Secondary MetroCode matches")
assert.Equal(t, secondary.LicenseToken, req.Secondary.LicenseToken, "LicenseFileID matches")
assert.Equal(t, secondary.LicenseFileID, req.Secondary.LicenseFileID, "LicenseFileID matches")
Expand Down

0 comments on commit 3f59012

Please sign in to comment.