-
Notifications
You must be signed in to change notification settings - Fork 6
NFV-18043: add cluster fields to existing device API #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b922062
NFV-18156: add cluster struct in ne-go repository
rling-equinix 1d48925
Update README.md
yvikrant f992fcf
NFV-18156: add new device state and license state for cluster
rling-equinix b292e70
NFV-18192: add unit test cases for cluster and clean up go module
rling-equinix 8a48ed9
NFV-18157, NFV-18192: modify cluster struct and fix unit test cases
rling-equinix File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -127,6 +127,76 @@ func TestCreateRedundantDevice(t *testing.T) { | |
| verifyRedundantDeviceRequest(t, primary, secondary, req) | ||
| } | ||
|
|
||
| func TestCreateClusterDevice(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{ | ||
| Name: String("PANW-cluster"), | ||
| MetroCode: String("SV"), | ||
| TypeCode: String("PA-VM"), | ||
| IsSelfManaged: Bool(true), | ||
| IsBYOL: Bool(true), | ||
| PackageCode: String("VM100"), | ||
| Notifications: []string{"[email protected]", "[email protected]"}, | ||
| HostName: String("panwHostName"), | ||
| TermLength: Int(24), | ||
| AccountNumber: String("177643"), | ||
| Version: String("10.1.3"), | ||
| InterfaceCount: Int(10), | ||
| CoreCount: Int(2), | ||
| ACLTemplateUUID: String("4972e8d2-417f-4821-91a8-f4a61a6dcdc3"), | ||
| MgmtAclTemplateUuid: String("4972e8d2-417f-4821-91a8-f4a61a6dcdc3"), | ||
| UserPublicKey: &DeviceUserPublicKey{ | ||
| Username: String("testUserName"), | ||
| KeyName: String("testKey"), | ||
| }, | ||
| ClusterDetails: &ClusterDetails{ | ||
| ClusterName: String("clusterName"), | ||
| ClusterNodeDetails: map[string]*ClusterNodeDetail{ | ||
| "node0": { | ||
| VendorConfiguration: map[string]string{ | ||
| "hostName": "panw-host0", | ||
| }, | ||
| LicenseFileId: String("8d180057-8309-4c59-b645-f630f010ad43"), | ||
| LicenseToken: String("licenseToken"), | ||
| }, | ||
| "node1": { | ||
| VendorConfiguration: map[string]string{ | ||
| "hostName": "panw-host1", | ||
| }, | ||
| LicenseFileId: String("8d180057-8309-4c59-b645-f630f010ad43"), | ||
| LicenseToken: String("licenseToken"), | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
| 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") | ||
| verifyClusterDeviceRequest(t, device, req) | ||
| } | ||
|
|
||
| func TestGetDevice(t *testing.T) { | ||
| //given | ||
| resp := api.Device{} | ||
|
|
@@ -413,6 +483,37 @@ func verifyRedundantDeviceRequest(t *testing.T, primary, secondary Device, req a | |
| verifyDeviceUserPublicKeyRequest(t, *secondary.UserPublicKey, *req.Secondary.UserPublicKey) | ||
| } | ||
|
|
||
| func verifyClusterDeviceRequest(t *testing.T, device Device, req api.DeviceRequest) { | ||
| assert.Equal(t, device.Name, req.VirtualDeviceName, "Name matches") | ||
| assert.Equal(t, device.MetroCode, req.MetroCode, "MetroCode matches") | ||
| assert.Equal(t, device.TypeCode, req.DeviceTypeCode, "TypeCode matches") | ||
| if *device.IsSelfManaged { | ||
| assert.Equal(t, DeviceManagementTypeSelf, StringValue(req.DeviceManagementType), "DeviceManagementType matches") | ||
| } else { | ||
| assert.Equal(t, DeviceManagementTypeEquinix, StringValue(req.DeviceManagementType), "DeviceManagementType matches") | ||
| } | ||
| if *device.IsBYOL { | ||
| assert.Equal(t, DeviceLicenseModeBYOL, StringValue(req.LicenseMode), "LicenseMode matches") | ||
| } else { | ||
| assert.Equal(t, DeviceLicenseModeSubscription, StringValue(req.LicenseMode), "LicenseMode matches") | ||
| } | ||
| assert.Equal(t, device.PackageCode, req.PackageCode, "PackageCode matches") | ||
| assert.ElementsMatch(t, device.Notifications, req.Notifications, "Notifications matches") | ||
| assert.Equal(t, device.HostName, req.HostNamePrefix, "HostName matches") | ||
| termLengthStr := strconv.Itoa(*device.TermLength) | ||
| assert.Equal(t, &termLengthStr, req.TermLength, "TermLength matches") | ||
| assert.Equal(t, device.AccountNumber, req.AccountNumber, "AccountNumber matches") | ||
| assert.Equal(t, device.Version, req.Version, "Version matches") | ||
| assert.Equal(t, device.InterfaceCount, req.InterfaceCount, "InterfaceCount matches") | ||
| assert.Equal(t, device.CoreCount, req.Core, "Core matches") | ||
| assert.Equal(t, device.ACLTemplateUUID, req.ACLTemplateUUID, "ACLTemplateUUID matches") | ||
| assert.Equal(t, device.MgmtAclTemplateUuid, req.MgmtAclTemplateUuid, "MgmtAclTemplateUuid matches") | ||
| assert.NotNil(t, req.UserPublicKey, "UserPublicKey is not nil") | ||
| verifyDeviceUserPublicKeyRequest(t, *device.UserPublicKey, *req.UserPublicKey) | ||
| assert.NotNil(t, req.ClusterDetails, "ClusterDetails are not nil") | ||
| verifyClusterDetailsRequest(t, *device.ClusterDetails, *req.ClusterDetails) | ||
| } | ||
|
|
||
| func verifyDeviceUserPublicKey(t *testing.T, userKey DeviceUserPublicKey, apiUserKey api.DeviceUserPublicKey) { | ||
| assert.Equal(t, apiUserKey.Username, userKey.Username, "Username matches") | ||
| assert.Equal(t, apiUserKey.KeyName, userKey.KeyName, "KeyName matches") | ||
|
|
@@ -422,3 +523,19 @@ func verifyDeviceUserPublicKeyRequest(t *testing.T, userKey DeviceUserPublicKey, | |
| assert.Equal(t, apiUserKeyReq.Username, userKey.Username, "Username matches") | ||
| assert.Equal(t, apiUserKeyReq.KeyName, userKey.KeyName, "KeyName matches") | ||
| } | ||
|
|
||
| func verifyClusterDetailsRequest(t *testing.T, clusterDetails ClusterDetails, apiClusterDetailsReq api.ClusterDetailsRequest) { | ||
| assert.Equal(t, clusterDetails.ClusterName, apiClusterDetailsReq.ClusterName, "ClusterName matches") | ||
| apiClusterNodeDetailReqMap := apiClusterDetailsReq.ClusterNodeDetails | ||
| assert.NotNil(t, apiClusterNodeDetailReqMap, "ClusterNodeDetails are not nil") | ||
| for k, v := range clusterDetails.ClusterNodeDetails { | ||
| verifyClusterNodeDetailRequest(t, v, apiClusterNodeDetailReqMap[k]) | ||
| } | ||
| } | ||
|
|
||
| func verifyClusterNodeDetailRequest(t *testing.T, clusterNodeDetail *ClusterNodeDetail, apiClusterNodeDetailReq api.ClusterNodeDetailRequest) { | ||
| assert.NotNil(t, apiClusterNodeDetailReq, "ClusterNodeDetailRequest is not nil") | ||
| assert.Equal(t, clusterNodeDetail.VendorConfiguration, apiClusterNodeDetailReq.VendorConfiguration, "VendorConfigurations match") | ||
| assert.Equal(t, clusterNodeDetail.LicenseFileId, apiClusterNodeDetailReq.LicenseFileId, "LicenseFileId matches") | ||
| assert.Equal(t, clusterNodeDetail.LicenseToken, apiClusterNodeDetailReq.LicenseToken, "LicenseToken matches") | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| { | ||
| "uuid": "877a3aa2-c49a-4af1-98a6-007424e737ae", | ||
| "secondaryUUID": "b22c289a-162a-4e51-879d-b3e779805fb7" | ||
| "secondaryUuid": "b22c289a-162a-4e51-879d-b3e779805fb7" | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.