Skip to content

Commit

Permalink
Merge pull request #22 from schadalawada/main
Browse files Browse the repository at this point in the history
NFV-25313: Add new field connectivity to support ZNPD
  • Loading branch information
ctreatma authored Jul 28, 2023
2 parents 2d067fd + fed2e48 commit f863c89
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 5 deletions.
3 changes: 3 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ const (
DeviceLicenseStateRegistered = "REGISTERED"
//DeviceLicenseStateApplied license was successfully applied
DeviceLicenseStateApplied = "APPLIED"
//DeviceLicenseStateNA license state not applicable
DeviceLicenseStateNA = "N/A"
//DeviceLicenseStateFailed license registration has failed
DeviceLicenseStateFailed = "REGISTRATION_FAILED"
//DeviceLicenseStateWaitingClusterSetUp license is waiting for cluster setup
Expand Down Expand Up @@ -264,6 +266,7 @@ type Device struct {
InterfaceCount *int
CoreCount *int
IsSelfManaged *bool
Connectivity *string
WanInterfaceId *string
Interfaces []DeviceInterface
VendorConfiguration map[string]string
Expand Down
2 changes: 2 additions & 0 deletions internal/api/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type Device struct {
ASN *int `json:"asn,omitempty"`
ZoneCode *string `json:"zoneCode,omitempty"`
ClusterDetails *ClusterDetails `json:"clusterDetails,omitempty"`
Connectivity *string `json:"connectivity,omitempty"`
}

//DeviceRequest describes network edge device creation request
Expand Down Expand Up @@ -73,6 +74,7 @@ type DeviceRequest struct {
UserPublicKey *DeviceUserPublicKeyRequest `json:"userPublicKey,omitempty"`
Secondary *SecondaryDeviceRequest `json:"secondary,omitempty"`
ClusterDetails *ClusterDetailsRequest `json:"clusterDetails,omitempty"`
Connectivity *string `json:"connectivity,omitempty"`
}

//SecondaryDeviceRequest describes secondary device part of device creation request
Expand Down
16 changes: 15 additions & 1 deletion rest_device.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ 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 @@ -239,6 +246,9 @@ 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)
Expand Down Expand Up @@ -376,7 +386,11 @@ func createDeviceRequest(device Device) api.DeviceRequest {
req.InterfaceCount = device.InterfaceCount
if device.IsSelfManaged != nil {
if *device.IsSelfManaged {
req.DeviceManagementType = String(DeviceManagementTypeSelf)
if device.Connectivity != nil && strings.EqualFold(*device.Connectivity, Znpd) {
req.DeviceManagementType = String(DeviceManagementTypeSelfZnpd)
} else {
req.DeviceManagementType = String(DeviceManagementTypeSelf)
}
} else {
req.DeviceManagementType = String(DeviceManagementTypeEquinix)
}
Expand Down
75 changes: 71 additions & 4 deletions rest_device_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,70 @@ 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)
verifyDeviceRequest(t, device, req, false)
}

func TestCreateZnpdDevice(t *testing.T) {
//given
resp := api.DeviceRequestResponse{}
if err := readJSONData("./test-fixtures/ne_device_create_resp.json", &resp); err != nil {
assert.Fail(t, "Cannot read test response")
}
device := Device{
AdditionalBandwidth: Int(100),
TypeCode: String("PA-VM"),
HostName: String("myhostSRmy"),
IsBYOL: Bool(true),
LicenseToken: String("somelicensetokenaaaaazzzzz"),
LicenseFileID: String("8d180057-8309-4c59-b645-f630f010ad43"),
CloudInitFileID: String("9318885d-4b8c-48a5-9aa4-24387834ebae"),
MetroCode: String("SV"),
Notifications: []string{"[email protected]", "[email protected]"},
PackageCode: String("VM100"),
TermLength: Int(24),
Throughput: Int(1),
ThroughputUnit: String("Gbps"),
Connectivity: String("private"),
Name: String("PaloAltoSRmy"),
ACLTemplateUUID: String("4792d9ab-b8aa-49cc-8fe2-b56ced6c9c2f"),
AccountNumber: String("1777643"),
OrderReference: String("orderRef"),
PurchaseOrderNumber: String("PO123456789"),
InterfaceCount: Int(10),
CoreCount: Int(2),
Version: String("10.09.05"),
IsSelfManaged: Bool(true),
VendorConfiguration: map[string]string{
"serialNumber": "12312312",
"controller1": "1.1.1.1",
},
UserPublicKey: &DeviceUserPublicKey{
Username: String("testUserName"),
KeyName: String("testKey"),
},
}
req := api.DeviceRequest{}
testHc := &http.Client{}
httpmock.ActivateNonDefault(testHc)
httpmock.RegisterResponder("POST", fmt.Sprintf("%s/ne/v1/devices", baseURL),
func(r *http.Request) (*http.Response, error) {
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
return httpmock.NewStringResponse(400, ""), nil
}
resp, _ := httpmock.NewJsonResponse(202, resp)
return resp, nil
},
)
defer httpmock.DeactivateAndReset()

//when
c := NewClient(context.Background(), baseURL, testHc)
uuid, err := c.CreateDevice(device)

//then
assert.Nil(t, err, "Error is not returned")
assert.Equal(t, uuid, resp.UUID, "UUID matches")
verifyDeviceRequest(t, device, req, true)
}

func TestCreateRedundantDevice(t *testing.T) {
Expand Down Expand Up @@ -431,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) {
func verifyDeviceRequest(t *testing.T, device Device, req api.DeviceRequest, isZnpd bool) {
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 @@ -456,7 +519,11 @@ func verifyDeviceRequest(t *testing.T, device Device, req api.DeviceRequest) {
assert.Equal(t, device.Version, req.Version, "Version matches")
assert.Equal(t, device.InterfaceCount, req.InterfaceCount, "InterfaceCount matches")
if *device.IsSelfManaged {
assert.Equal(t, DeviceManagementTypeSelf, StringValue(req.DeviceManagementType), "DeviceManagementType matches")
if isZnpd {
assert.Equal(t, DeviceManagementTypeSelfZnpd, StringValue(req.DeviceManagementType), "DeviceManagementType matches")
} else {
assert.Equal(t, DeviceManagementTypeSelf, StringValue(req.DeviceManagementType), "DeviceManagementType matches")
}
} else {
assert.Equal(t, DeviceManagementTypeEquinix, StringValue(req.DeviceManagementType), "DeviceManagementType matches")
}
Expand All @@ -469,7 +536,7 @@ func verifyDeviceRequest(t *testing.T, device Device, req api.DeviceRequest) {
}

func verifyRedundantDeviceRequest(t *testing.T, primary, secondary Device, req api.DeviceRequest) {
verifyDeviceRequest(t, primary, req)
verifyDeviceRequest(t, primary, req, false)
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 f863c89

Please sign in to comment.