|
| 1 | +package main |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "crypto/tls" |
| 6 | + "log/slog" |
| 7 | + "net/http" |
| 8 | + "testing" |
| 9 | + "time" |
| 10 | + |
| 11 | + "github.com/netapp/ontap-mcp/config" |
| 12 | +) |
| 13 | + |
| 14 | +func TestIscsiProtocol(t *testing.T) { |
| 15 | + SkipIfMissing(t, CheckTools) |
| 16 | + |
| 17 | + tests := []struct { |
| 18 | + name string |
| 19 | + input string |
| 20 | + expectedOntapErr string |
| 21 | + verifyAPI ontapVerifier |
| 22 | + }{ |
| 23 | + { |
| 24 | + name: "Clean iSCSI service", |
| 25 | + input: ClusterStr + "delete iscsi service in marketing svm", |
| 26 | + expectedOntapErr: "because it does not exist", |
| 27 | + verifyAPI: ontapVerifier{api: "api/protocols/san/iscsi/services?svm.name=marketing", validationFunc: deleteObject}, |
| 28 | + }, |
| 29 | + { |
| 30 | + name: "Create iSCSI service", |
| 31 | + input: ClusterStr + "create iscsi service target named alias " + rn("tgpath") + " on the marketing svm", |
| 32 | + expectedOntapErr: "", |
| 33 | + verifyAPI: ontapVerifier{api: "api/protocols/san/iscsi/services?svm.name=marketing", validationFunc: createObject}, |
| 34 | + }, |
| 35 | + { |
| 36 | + name: "Clean cluster scope network interface", |
| 37 | + input: ClusterStr + "delete cluster scope network interface named " + rn("cl_mg"), |
| 38 | + expectedOntapErr: "because it does not exist", |
| 39 | + verifyAPI: ontapVerifier{api: "api/network/ip/interfaces?name=" + rn("cl_mg") + "&scope=cluster", validationFunc: deleteObject}, |
| 40 | + }, |
| 41 | + { |
| 42 | + name: "Clean svm scope network interface", |
| 43 | + input: ClusterStr + "delete svm scope network interface named " + rn("svg1") + " in marketing svm", |
| 44 | + expectedOntapErr: "because it does not exist", |
| 45 | + verifyAPI: ontapVerifier{api: "api/network/ip/interfaces?name=" + rn("svg1") + "&scope=svm", validationFunc: deleteObject}, |
| 46 | + }, |
| 47 | + { |
| 48 | + name: "Create cluster scope network interface with IP", |
| 49 | + input: ClusterStr + "create network interface named " + rn("cl_mg") + " with ip address 10.63.41.6 and netmask 18 with Default ipspace on node umeng-aff300-06", |
| 50 | + expectedOntapErr: "", |
| 51 | + verifyAPI: ontapVerifier{api: "api/network/ip/interfaces?name=" + rn("cl_mg") + "&scope=cluster", validationFunc: createObject}, |
| 52 | + }, |
| 53 | + { |
| 54 | + name: "Create svm scope network interface with ip", |
| 55 | + input: ClusterStr + "create network interface named " + rn("svg1") + " in marketing svm with ip address 10.63.41.7 and netmask 18 on node umeng-aff300-06", |
| 56 | + expectedOntapErr: "", |
| 57 | + verifyAPI: ontapVerifier{api: "api/network/ip/interfaces?name=" + rn("svg1") + "&scope=svm", validationFunc: createObject}, |
| 58 | + }, |
| 59 | + { |
| 60 | + name: "Clean cluster scope network interface", |
| 61 | + input: ClusterStr + "delete cluster scope network interface named " + rn("cl_mg"), |
| 62 | + expectedOntapErr: "because it does not exist", |
| 63 | + verifyAPI: ontapVerifier{api: "api/network/ip/interfaces?name=" + rn("cl_mg") + "&scope=cluster", validationFunc: deleteObject}, |
| 64 | + }, |
| 65 | + { |
| 66 | + name: "Clean svm scope network interface", |
| 67 | + input: ClusterStr + "delete svm scope network interface named " + rn("svg1") + " in marketing svm", |
| 68 | + expectedOntapErr: "because it does not exist", |
| 69 | + verifyAPI: ontapVerifier{api: "api/network/ip/interfaces?name=" + rn("svg1") + "&scope=svm", validationFunc: deleteObject}, |
| 70 | + }, |
| 71 | + { |
| 72 | + name: "Create svm scope network interface with broadcast domain", |
| 73 | + input: ClusterStr + "create network interface named " + rn("svg1") + " in marketing svm with ip address 10.63.41.7 and netmask 18 on broadcast domain as Default", |
| 74 | + expectedOntapErr: "", |
| 75 | + verifyAPI: ontapVerifier{api: "api/network/ip/interfaces?name=" + rn("svg1") + "&scope=svm", validationFunc: createObject}, |
| 76 | + }, |
| 77 | + { |
| 78 | + name: "Clean svm scope network interface with broadcast domain", |
| 79 | + input: ClusterStr + "delete svm scope network interface named " + rn("svg1") + " in marketing svm", |
| 80 | + expectedOntapErr: "because it does not exist", |
| 81 | + verifyAPI: ontapVerifier{api: "api/network/ip/interfaces?name=" + rn("svg1") + "&scope=svm", validationFunc: deleteObject}, |
| 82 | + }, |
| 83 | + { |
| 84 | + name: "Update iSCSI service", |
| 85 | + input: ClusterStr + "disabled iscsi service on the marketing svm", |
| 86 | + expectedOntapErr: "", |
| 87 | + verifyAPI: ontapVerifier{}, |
| 88 | + }, |
| 89 | + { |
| 90 | + name: "Clean iSCSI service", |
| 91 | + input: ClusterStr + "delete iscsi service in marketing svm", |
| 92 | + expectedOntapErr: "because it does not exist", |
| 93 | + verifyAPI: ontapVerifier{api: "api/protocols/san/iscsi/services?svm.name=marketing", validationFunc: deleteObject}, |
| 94 | + }, |
| 95 | + } |
| 96 | + |
| 97 | + cfg, err := config.ReadConfig(ConfigFile) |
| 98 | + if err != nil { |
| 99 | + t.Fatalf("Error parsing the config: %v", err) |
| 100 | + } |
| 101 | + |
| 102 | + poller := cfg.Pollers[Cluster] |
| 103 | + transport := &http.Transport{ |
| 104 | + TLSClientConfig: &tls.Config{ |
| 105 | + InsecureSkipVerify: poller.UseInsecureTLS, // #nosec G402 |
| 106 | + }, |
| 107 | + } |
| 108 | + client := &http.Client{Transport: transport, Timeout: 10 * time.Second} |
| 109 | + |
| 110 | + for _, tt := range tests { |
| 111 | + t.Run(tt.name, func(t *testing.T) { |
| 112 | + slog.Debug("", slog.String("Input", tt.input)) |
| 113 | + ctx, cancel := context.WithTimeout(context.Background(), 3*time.Minute) |
| 114 | + defer cancel() |
| 115 | + if _, err = testAgent.ChatWithResponse(ctx, t, tt.input, tt.expectedOntapErr); err != nil { |
| 116 | + slog.Error("Error processing input", slog.Any("error", err)) |
| 117 | + } |
| 118 | + if tt.verifyAPI.api != "" && !tt.verifyAPI.validationFunc(t, tt.verifyAPI.api, poller, client) { |
| 119 | + t.Errorf("Error while accessing the object via prompt %s", tt.input) |
| 120 | + } |
| 121 | + }) |
| 122 | + } |
| 123 | +} |
0 commit comments