diff --git a/.github/workflows/build-push.yaml b/.github/workflows/build-push.yaml index a6b9bb4..54a7dcc 100644 --- a/.github/workflows/build-push.yaml +++ b/.github/workflows/build-push.yaml @@ -33,7 +33,7 @@ jobs: with: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} + password: ${{ secrets.GITHUB_TOKEN }} - name: Extract metadata (tags, labels) for Docker id: meta diff --git a/main.go b/main.go index 84b3a41..8ee203e 100644 --- a/main.go +++ b/main.go @@ -27,12 +27,15 @@ func main() { } type Glob struct { - Url url.URL - Username string - Password string - Stream string - Client HTTPClient - Mode string + Url url.URL + Username string + Password string + Stream string + Client HTTPClient + Mode string + PanoramaBaseAddress string + PanoramaAdminUsername string + PanoramaAdminPassword string } var NewGlob = func() Glob { @@ -43,11 +46,19 @@ var NewGlob = func() Glob { var stream string var mode string + var panoramaAddress string + var panoramaAdminUsername string + var panoramaAdminPassword string + flag.StringVar(&targetUrl, "url", "http://localhost:8000", "Specify url. Default is root") flag.StringVar(&username, "user", "admin", "Specify username. Default is admin") flag.StringVar(&password, "pass", "admin", "Specify pass. Default is admin") flag.StringVar(&stream, "stream", "app", "Specify stream. Default is app") flag.StringVar(&mode, "mode", "smoke", "Specify mode. Default is smoke") + flag.StringVar(&panoramaAddress, "panorama-address", "http://localhost:5000", "Specify panorama address. Default is http://localhost:5000") + + flag.StringVar(&panoramaAdminUsername, "panorama-admin-username", "pano_admin", "Specify module connection username. Default is pano_admin") + flag.StringVar(&panoramaAdminPassword, "panorama-admin-password", "pano_admin", "Specify Module connection password. Default is pano_admin") flag.Parse() @@ -59,11 +70,14 @@ var NewGlob = func() Glob { client := DefaultClient(*parsedTargetUrl, username, password) return Glob{ - Url: *parsedTargetUrl, - Username: username, - Password: password, - Stream: stream, - Client: client, - Mode: mode, + Url: *parsedTargetUrl, + Username: username, + Password: password, + Stream: stream, + Client: client, + Mode: mode, + PanoramaBaseAddress: panoramaAddress, + PanoramaAdminUsername: panoramaAdminUsername, + PanoramaAdminPassword: panoramaAdminPassword, } }() diff --git a/main.sh b/main.sh index ff6b673..9351471 100755 --- a/main.sh +++ b/main.sh @@ -20,17 +20,21 @@ mode=$1 endpoint=$2 username=$3 password=$4 -schema_count=$5 -: "${schema_count:=20}" -vus=$6 -: "${vus:=10}" -duration=$7 -: "${duration:="5m"}" + +schema_count="${5:-20}" +vus="${6:-10}" +duration="${7:-5m}" + +# todo: accept all these as named argument instead: eg: -pan_user admin +panorama_address="${8:-http:0.0.0.0:5000}" +panorama_admin_username="${9:-pano_admin}" +panorama_admin_password="${10:-pano_admin}" stream_name=$(head /dev/urandom | tr -dc a-z | head -c10) run () { - ./quest.test -test.v -mode="$mode" -url="$endpoint" -stream="$stream_name" -user="$username" -pass="$password" + ./quest.test -test.v -mode="$mode" -url="$endpoint" -stream="$stream_name" -user="$username" -pass="$password" \ + -panorama-address="$panorama_address" -panorama-admin-username="$panorama_admin_username" -panorama-admin-password="$panorama_admin_password" return $? } diff --git a/modules_test_utils.go b/modules_test_utils.go new file mode 100644 index 0000000..6b150aa --- /dev/null +++ b/modules_test_utils.go @@ -0,0 +1,91 @@ +// Copyright (c) 2023 Cloudnatively Services Pvt Ltd +// +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package main + +import ( + "bytes" + "testing" + + "github.com/stretchr/testify/require" +) + +const sample_module_config_per_stream = ` +[{ + "mode": "col", + "algorithm": "z-score", + "start_time": "2023-10-12T08:38:47.069Z", + "end_time": "2023-10-12T08:40:47.069Z", + "interval_window": "5s", + "column_to_watch": "api_timeToResponseInNS" +}] +` + +func test_module_registration_flow(t *testing.T) error { + + module_name := "panorama" + stream_name := NewGlob.Stream + sample_proxy_route_body := ` +{ + "stream_name": "` + stream_name + `" +} +` + println("Module Registration flow for: " + module_name) + + println("Getting list of modules:") + req, _ := NewGlob.Client.NewRequest("GET", "modules", bytes.NewBufferString("{}")) + response, err := NewGlob.Client.Do(req) + require.NoErrorf(t, err, "Request failed: %s", err) + require.Equalf(t, 200, response.StatusCode, "Server returned http code: %s resp %s", response.Status, readAsString(response.Body)) + + println("Updating config for stream: ", stream_name) + req, _ = NewGlob.Client.NewRequest("PUT", "modules/"+module_name+"/config/"+stream_name, bytes.NewBufferString(sample_module_config_per_stream)) + response, err = NewGlob.Client.Do(req) + require.NoErrorf(t, err, "Request failed: %s", err) + require.Equalf(t, 200, response.StatusCode, "Server returned http code: %s resp %s", response.Status, readAsString(response.Body)) + + println("Receiving config") + req, _ = NewGlob.Client.NewRequest("GET", "modules/"+module_name+"/config/"+stream_name, bytes.NewBufferString("{}")) + response, err = NewGlob.Client.Do(req) + require.NoErrorf(t, err, "Request failed: %s", err) + require.Equalf(t, 200, response.StatusCode, "Server returned http code: %s resp %s", response.Status, readAsString(response.Body)) + + println("Testing Proxy Route") + req, _ = NewGlob.Client.NewRequest("GET", "modules/"+module_name+"/anomaly", bytes.NewBufferString(sample_proxy_route_body)) + response, err = NewGlob.Client.Do(req) + require.NoErrorf(t, err, "Request failed: %s", err) + require.Equalf(t, 200, response.StatusCode, "Server returned http code: %s resp %s", response.Status, readAsString(response.Body)) + + println("Stop anomaly watching by putting config as empty") + req, _ = NewGlob.Client.NewRequest("PUT", "modules/"+module_name+"/config/"+stream_name, bytes.NewBufferString("{}")) + response, err = NewGlob.Client.Do(req) + require.NoErrorf(t, err, "Request failed: %s", err) + require.Equalf(t, 200, response.StatusCode, "Server returned http code: %s resp %s", response.Status, readAsString(response.Body)) + + println("Testing DeRegistering Module") + req, _ = NewGlob.Client.NewRequest("DELETE", "modules/"+module_name, bytes.NewBufferString("{}")) + response, err = NewGlob.Client.Do(req) + require.NoErrorf(t, err, "Request failed: %s", err) + require.Equalf(t, 200, response.StatusCode, "Server returned http code: %s resp %s", response.Status, readAsString(response.Body)) + + println("Testing Duplicate DeRegister ") + req, _ = NewGlob.Client.NewRequest("DELETE", "modules/"+module_name, bytes.NewBufferString("{}")) + response, err = NewGlob.Client.Do(req) + require.NoErrorf(t, err, "Request failed: %s", err) + require.Equalf(t, 400, response.StatusCode, "Server returned http code: %s resp %s", response.Status, readAsString(response.Body)) + + return nil +} diff --git a/quest_test.go b/quest_test.go index a244677..a5488a6 100644 --- a/quest_test.go +++ b/quest_test.go @@ -81,6 +81,12 @@ func TestSmokeIngestEventsToStream(t *testing.T) { Sleep() } +func TestSmokeModulesAPI(t *testing.T) { + CreateStream(t, NewGlob.Client, NewGlob.Stream) + test_module_registration_flow(t) + DeleteStream(t, NewGlob.Client, NewGlob.Stream) +} + func TestSmokeLoadWithK6Stream(t *testing.T) { CreateStream(t, NewGlob.Client, NewGlob.Stream) cmd := exec.Command("k6",