-
Notifications
You must be signed in to change notification settings - Fork 5
feat: adding nvme subsystem with host tools #89
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
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
d5b84d8
feat: adding nvme subsystem with host tools
Hardikl 1923d9b
feat: adding nvme namespace and subsystem-map tools
Hardikl f3e68f5
Merge remote-tracking branch 'origin/main' into hl_nvme
Hardikl 06c03af
feat: handled copilot comments
Hardikl 1976fd0
feat: add nvme test cases in aff cluster
Hardikl 865e80b
Merge remote-tracking branch 'origin/main' into hl_nvme
Hardikl 1298e19
feat: handled review comments with go mode update
Hardikl 9b2a244
feat: update nvme tools validation
Hardikl 671d4fa
Merge remote-tracking branch 'origin/main' into hl_nvme
Hardikl fe5d478
Merge remote-tracking branch 'origin/main' into hl_nvme
Hardikl 402bc12
feat: handled copilot comment
Hardikl 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 was deleted.
Oops, something went wrong.
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 |
|---|---|---|
| @@ -0,0 +1,199 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "context" | ||
| "crypto/tls" | ||
| "github.com/carlmjohnson/requests" | ||
| "github.com/netapp/ontap-mcp/ontap" | ||
| "log/slog" | ||
| "net/http" | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/netapp/ontap-mcp/config" | ||
| ) | ||
|
|
||
| const NvmeCluster = "aff" | ||
| const NvmeClusterStr = "On the " + NvmeCluster + " cluster, " | ||
|
|
||
| func TestNVMe(t *testing.T) { | ||
| SkipIfMissing(t, CheckTools) | ||
|
|
||
| tests := []struct { | ||
| name string | ||
| input string | ||
| expectedOntapErr string | ||
| verifyAPI ontapVerifier | ||
| }{ | ||
| { | ||
| name: "Clean NVMe subsystem", | ||
| input: NvmeClusterStr + "delete nvme subsystem " + rn("sys2") + " with in marketing svm with allow_delete_while_mapped and allow_delete_with_hosts", | ||
| expectedOntapErr: "because it does not exist", | ||
| verifyAPI: ontapVerifier{api: "api/protocols/nvme/subsystems?svm.name=marketing&name=" + rn("sys2"), validationFunc: deleteObject}, | ||
| }, | ||
| { | ||
| name: "Create NVMe subsystem", | ||
| input: NvmeClusterStr + "create nvme subsystem " + rn("sys2") + " with linux os and with host nqns as nqn.1992-01.example.com:host1, nqn.1992-01.example.com:host2 on the marketing svm", | ||
| expectedOntapErr: "", | ||
| verifyAPI: ontapVerifier{api: "api/protocols/nvme/subsystems?svm.name=marketing&name=" + rn("sys2"), validationFunc: createObject}, | ||
|
Hardikl marked this conversation as resolved.
|
||
| }, | ||
| { | ||
| name: "Update NVMe subsystem", | ||
| input: NvmeClusterStr + "add comment as `comment about the` in " + rn("sys2") + " nvme subsystem on the marketing svm", | ||
| expectedOntapErr: "", | ||
| verifyAPI: ontapVerifier{}, | ||
| }, | ||
| { | ||
| name: "Add host in NVMe subsystem", | ||
| input: NvmeClusterStr + "add host nqn as nqn.1992-01.example.com:host3 in " + rn("sys2") + " nvme subsystem in marketing svm", | ||
| expectedOntapErr: "", | ||
| verifyAPI: ontapVerifier{}, | ||
| }, | ||
| { | ||
| name: "Remove host in NVMe subsystem", | ||
| input: NvmeClusterStr + "remove host nqn as nqn.1992-01.example.com:host3 in " + rn("sys2") + " nvme subsystem in marketing svm", | ||
| expectedOntapErr: "", | ||
| verifyAPI: ontapVerifier{}, | ||
| }, | ||
| { | ||
| name: "Clean NVMe subsystem", | ||
| input: NvmeClusterStr + "delete nvme subsystem " + rn("sys2") + " with in marketing svm with allow_delete_while_mapped and allow_delete_with_hosts", | ||
| expectedOntapErr: "because it does not exist", | ||
|
Hardikl marked this conversation as resolved.
|
||
| verifyAPI: ontapVerifier{api: "api/protocols/nvme/subsystems?svm.name=marketing&name=" + rn("sys2"), validationFunc: deleteObject}, | ||
| }, | ||
| { | ||
| name: "Clean NVMe subsystem", | ||
| input: NvmeClusterStr + "delete nvme subsystem " + rn("sys1") + " with in nvmevs1 svm", | ||
| expectedOntapErr: "because it does not exist", | ||
| verifyAPI: ontapVerifier{api: "api/protocols/nvme/subsystems?svm.name=nvmevs1&name=" + rn("sys1"), validationFunc: deleteObject}, | ||
| }, | ||
| { | ||
| name: "Create NVMe subsystem", | ||
| input: NvmeClusterStr + "create nvme subsystem " + rn("sys1") + " with linux os on the nvmevs1 svm", | ||
| expectedOntapErr: "", | ||
| verifyAPI: ontapVerifier{api: "api/protocols/nvme/subsystems?svm.name=nvmevs1&name=" + rn("sys1"), validationFunc: createObject}, | ||
| }, | ||
| { | ||
| name: "Clean NVMe namespace", | ||
| input: NvmeClusterStr + "delete nvme namespace '" + rn("/vol/docns/ns1") + "' with in nvmevs1 svm", | ||
| expectedOntapErr: "because it does not exist", | ||
| verifyAPI: ontapVerifier{api: "api/storage/namespaces?svm.name=nvmevs1&name=" + rn(`/vol/docns/ns1`), validationFunc: deleteObject}, | ||
| }, | ||
| { | ||
| name: "Create NVMe namespace", | ||
| input: NvmeClusterStr + "create nvme namespace '" + rn("/vol/docns/ns1") + "' with linux os and 20mb size in nvmevs1 svm", | ||
| expectedOntapErr: "", | ||
| verifyAPI: ontapVerifier{api: "api/storage/namespaces?svm.name=nvmevs1&name=" + rn(`/vol/docns/ns1`), validationFunc: createObject}, | ||
| }, | ||
| { | ||
| name: "Update NVMe namespace", | ||
| input: NvmeClusterStr + "update nvme namespace '" + rn("/vol/docns/ns1") + "' with to 40mb size in nvmevs1 svm", | ||
| expectedOntapErr: "", | ||
| verifyAPI: ontapVerifier{}, | ||
| }, | ||
| { | ||
| name: "Create NVMe subsystem map", | ||
| input: NvmeClusterStr + "create subsystem map of " + rn("sys1") + " subsystem and '" + rn("/vol/docns/ns1") + "' namespace in nvmevs1 svm", | ||
| expectedOntapErr: "", | ||
| verifyAPI: ontapVerifier{api: "api/protocols/nvme/subsystem-maps?svm.name=nvmevs1", validationFunc: verifySubsystemMaps(rn("sys1"), rn(`/vol/docns/ns1`), true)}, | ||
| }, | ||
| { | ||
| name: "Clean NVMe subsystem map", | ||
| input: NvmeClusterStr + "delete subsystem map of " + rn("sys1") + " subsystem and namespace '" + rn("/vol/docns/ns1") + "' in nvmevs1 svm", | ||
| expectedOntapErr: "because it does not exist", | ||
|
Hardikl marked this conversation as resolved.
|
||
| verifyAPI: ontapVerifier{api: "api/protocols/nvme/subsystem-maps?svm.name=nvmevs1", validationFunc: verifySubsystemMaps(rn("sys1"), rn(`/vol/docns/ns1`), false)}, | ||
| }, | ||
| { | ||
| name: "Clean NVMe namespace", | ||
| input: NvmeClusterStr + "delete nvme namespace '" + rn("/vol/docns/ns1") + "' with in nvmevs1 svm", | ||
| expectedOntapErr: "because it does not exist", | ||
| verifyAPI: ontapVerifier{api: "api/storage/namespaces?svm.name=nvmevs1&name=" + rn(`/vol/docns/ns1`), validationFunc: deleteObject}, | ||
| }, | ||
| { | ||
| name: "Clean NVMe subsystem", | ||
| input: NvmeClusterStr + "delete nvme subsystem " + rn("sys1") + " with in nvmevs1 svm", | ||
| expectedOntapErr: "because it does not exist", | ||
|
Hardikl marked this conversation as resolved.
|
||
| verifyAPI: ontapVerifier{api: "api/protocols/nvme/subsystems?svm.name=nvmevs1&name=" + rn("sys1"), validationFunc: deleteObject}, | ||
| }, | ||
| } | ||
|
|
||
| cfg, err := config.ReadConfig(ConfigFile) | ||
| if err != nil { | ||
| t.Fatalf("Error parsing the config: %v", err) | ||
| } | ||
|
|
||
| poller := cfg.Pollers[NvmeCluster] | ||
| if poller == nil { | ||
| t.Skipf("Cluster %q not found in %s, skipping NVMe tests", NvmeCluster, ConfigFile) | ||
| } | ||
| transport := &http.Transport{ | ||
| TLSClientConfig: &tls.Config{ | ||
| InsecureSkipVerify: poller.UseInsecureTLS, // #nosec G402 | ||
| }, | ||
| } | ||
| client := &http.Client{Transport: transport, Timeout: 10 * time.Second} | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| slog.Debug("", slog.String("Input", tt.input)) | ||
| ctx, cancel := context.WithTimeout(context.Background(), 3*time.Minute) | ||
| defer cancel() | ||
| if _, err = testAgent.ChatWithResponse(ctx, t, tt.input, tt.expectedOntapErr); err != nil { | ||
| t.Fatalf("Error processing input %q: %v", tt.input, err) | ||
| } | ||
| if tt.verifyAPI.api != "" && !tt.verifyAPI.validationFunc(t, tt.verifyAPI.api, poller, client) { | ||
| t.Errorf("Error while accessing the object via prompt %s", tt.input) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func verifySubsystemMaps(subsystemName, namespaceName string, exist bool) func(t *testing.T, api string, poller *config.Poller, client *http.Client) bool { //nolint:unparam | ||
| return func(t *testing.T, api string, poller *config.Poller, client *http.Client) bool { | ||
| type subsystemMapRecord struct { | ||
| Namespace ontap.NameAndUUID `json:"namespace"` | ||
| Subsystem ontap.NameAndUUID `json:"subsystem"` | ||
| } | ||
| type response struct { | ||
| NumRecords int `json:"num_records"` | ||
| Records []subsystemMapRecord `json:"records"` | ||
| } | ||
|
|
||
| var data response | ||
| err := requests.URL("https://"+poller.Addr+"/"+api). | ||
| BasicAuth(poller.Username, poller.Password). | ||
| Client(client). | ||
| ToJSON(&data). | ||
| Fetch(context.Background()) | ||
| if err != nil { | ||
| t.Errorf("verifySubsystemMaps: request failed: %v", err) | ||
| return false | ||
| } | ||
|
|
||
| if exist { | ||
| for _, record := range data.Records { | ||
| gotSubsystem := record.Subsystem.Name | ||
| gotNamespace := record.Namespace.Name | ||
| if gotSubsystem == subsystemName && gotNamespace == namespaceName { | ||
| return true | ||
| } | ||
| } | ||
| t.Errorf("subsystem map does not exist") | ||
| } else { | ||
| sbsMapRecord := false | ||
| for _, record := range data.Records { | ||
| gotSubsystem := record.Subsystem.Name | ||
| gotNamespace := record.Namespace.Name | ||
| if gotSubsystem == subsystemName && gotNamespace == namespaceName { | ||
| sbsMapRecord = true | ||
| break | ||
| } | ||
| } | ||
| if !sbsMapRecord { | ||
| return true | ||
| } | ||
| t.Errorf("subsystem map exists") | ||
| } | ||
|
Hardikl marked this conversation as resolved.
|
||
| return false | ||
| } | ||
| } | ||
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
Oops, something went wrong.
Oops, something went wrong.
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.