From fed2e4857510c44beb7db2b186af89ed03261234 Mon Sep 17 00:00:00 2001 From: schadalawada Date: Wed, 26 Jul 2023 11:32:19 -0700 Subject: [PATCH] NFV-25313: Add new field connectivity to support ZNPD --- client.go | 3 ++ internal/api/device.go | 2 ++ rest_device.go | 16 ++++++++- rest_device_test.go | 75 +++++++++++++++++++++++++++++++++++++++--- 4 files changed, 91 insertions(+), 5 deletions(-) diff --git a/client.go b/client.go index 1e041c7..dbfe122 100644 --- a/client.go +++ b/client.go @@ -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 @@ -264,6 +266,7 @@ type Device struct { InterfaceCount *int CoreCount *int IsSelfManaged *bool + Connectivity *string WanInterfaceId *string Interfaces []DeviceInterface VendorConfiguration map[string]string diff --git a/internal/api/device.go b/internal/api/device.go index d9f9362..3b80e02 100644 --- a/internal/api/device.go +++ b/internal/api/device.go @@ -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 @@ -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 diff --git a/rest_device.go b/rest_device.go index 5174f9e..495f8a2 100644 --- a/rest_device.go +++ b/rest_device.go @@ -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 { @@ -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) @@ -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) } diff --git a/rest_device_test.go b/rest_device_test.go index 7875fb1..bcc05e7 100644 --- a/rest_device_test.go +++ b/rest_device_test.go @@ -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{"test1@example.com", "test2@example.com"}, + 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) { @@ -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") @@ -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") } @@ -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")