From 05075e5ae4f51c0e299d39c938c7b5dd9b30341d Mon Sep 17 00:00:00 2001 From: atighineanu Date: Thu, 27 Feb 2020 18:53:15 +0100 Subject: [PATCH 01/50] added generic functions, plus the ones for cilium --- main_test.go | 99 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 96 insertions(+), 3 deletions(-) diff --git a/main_test.go b/main_test.go index 9193114..0f73719 100644 --- a/main_test.go +++ b/main_test.go @@ -3,10 +3,15 @@ package main import ( "errors" "fmt" + "log" "os" "os/exec" "path" + "strconv" "strings" + "time" + + cilium "github.com/fgerling/bdd-poc/features/cilium" "github.com/cucumber/godog" suse "github.com/fgerling/bdd-poc/internal/suse" @@ -65,10 +70,11 @@ func iRunInDirectory(command, workdir string) error { args := strings.Split(command, " ") cmd := exec.Command(args[0], args[1:]...) cmd.Dir = workdir - Output, err = cmd.CombinedOutput() + Out1, err = cmd.CombinedOutput() if err != nil { return errors.New(string(Output)) } + cilium.Out1 = Out1 return err } @@ -86,7 +92,81 @@ func theOutputContainsAnd(arg1, arg2 string) error { return nil } +func grepFor(arg1 string) error { + var err error + tmp := strings.Split(fmt.Sprintf("%s", string(Out1)), "\n") + for _, elem := range tmp { + if strings.Contains(strings.ToLower(elem), arg1) { + Out1 = []byte(elem) + } + } + return err +} + +var Out1 []byte +var Err error +var VarMap map[string]string + +func ReadStringAsInt(arg1 string) (int, error) { + a, err := strconv.Atoi(arg1) + return a, err +} + +func VARIABLEEquals(arg1, arg2 string) error { + var err error + if VarMap == nil { + VarMap = make(map[string]string) + } + VarMap[arg1] = arg2 + log.Printf("VAR: %s = %s\n", arg1, VarMap[arg1]) + return err +} + +func wait(arg1 string) error { + var err error + temp := strings.Split(arg1, " ") + if len(temp) > 2 || len(temp) == 1 { + log.Println("Sorry... you've mistaken the format of time input (it's <1*EMPTYSPACE>") + return nil + } else { + switch temp[1] { + case "seconds": + a, err := ReadStringAsInt(temp[0]) + if err != nil { + log.Printf("Error: %v\n", err) + } + time.Sleep(time.Duration(a) * time.Second) + case "minutes": + a, err := ReadStringAsInt(temp[0]) + if err != nil { + log.Printf("Error: %v\n", err) + } + time.Sleep(time.Duration(a) * time.Minute) + case "hours": + a, err := ReadStringAsInt(temp[0]) + if err != nil { + log.Printf("Error: %v\n", err) + } + time.Sleep(time.Duration(a) * time.Hour) + } + } + return err +} + +func iRunVAR(arg1 string) error { + if VarMap["command5"] == "" { + return Irun(cilium.VarMap[arg1]) + } else { + return Irun(cilium.VarMap[arg1]) + } +} + +func Irun(command string) error { + return iRunInDirectory(command, ".") +} + func FeatureContext(s *godog.Suite) { + s.Step(`^wait "([^"]*)"$`, wait) s.Step(`^"([^"]*)" exist in gopath$`, existInGopath) s.Step(`^I git clone "([^"]*)" into "([^"]*)"$`, iGitCloneInto) s.Step(`^I have "([^"]*)" in PATH$`, suse.IHaveInPATH) @@ -103,8 +183,21 @@ func FeatureContext(s *godog.Suite) { s.Step(`^the output contains "([^"]*)" and "([^"]*)"$`, theOutputContainsAnd) s.Step(`^there is "([^"]*)" directory$`, theDirectoryExist) s.Step(`^there is no "([^"]*)" directory$`, thereIsNoDirectory) - s.Step(`^I run "([^"]*)"$`, func(command string) error { return iRunInDirectory(command, ".") }) + s.Step(`^I run VAR:"([^"]*)"$`, iRunVAR) + s.Step(`^I run "([^"]*)"$`, Irun) s.Step(`^the output contains "([^"]*)"$`, theOutputContains) s.Step(`^I have the correct go version$`, func() error { return iRunInDirectory("make go-version-check", "skuba") }) - + s.Step(`^grep for "([^"]*)"$`, grepFor) + //--------------------Cilium-specific test functions----------------------------------------------- + s.Step(`^VARIABLE "([^"]*)" equals ContainerFROMOutput "([^"]*)"$`, cilium.VARIABLEEqualsContainerFROMOutput) + s.Step(`^I run "([^"]*)" expecting ERROR$`, cilium.IRunExpectingERROR) + s.Step(`^I run VAR:"([^"]*)" expecting ERROR$`, cilium.IRunVARExpectingERROR) + s.Step(`^I run VAR:"([^"]*)" expecting ERROR in VAR:"([^"]*)" directory$`, cilium.IRunVARExpectingERRORInVARDirectory) + s.Step(`^the error contains "([^"]*)" and "([^"]*)"$`, cilium.TheErrorContainsAnd) + s.Step(`^I run VAR:"([^"]*)" in VAR:"([^"]*)" directory$`, cilium.IRunVARInVARDirectory) + s.Step(`^VARIABLE "([^"]*)" equals "([^"]*)" plus VAR:"([^"]*)"$`, cilium.VARIABLEEqualsPlusVAR) + s.Step(`^VARIABLE "([^"]*)" equals "([^"]*)" plus VAR:"([^"]*)" plus "([^"]*)"$`, cilium.VARIABLEEqualsPlusVARPlus) + s.Step(`^I run "([^"]*)" in VAR:"([^"]*)" directory$`, cilium.IRunInVARDirectory) + s.Step(`^VARIABLE "([^"]*)" equals "([^"]*)"$`, cilium.VARIABLEEquals) + //------------------------------------------------------------------------------------------------- } From 23c5f7287d9a938ba7b601c1a87426f5c4819068 Mon Sep 17 00:00:00 2001 From: atighineanu Date: Thu, 27 Feb 2020 19:00:37 +0100 Subject: [PATCH 02/50] a basic test for cilium --- features/cilium/cilium-01.feature | 91 ++++++++++++++++++++++ features/cilium/cilium.go | 122 ++++++++++++++++++++++++++++++ 2 files changed, 213 insertions(+) create mode 100644 features/cilium/cilium-01.feature create mode 100644 features/cilium/cilium.go diff --git a/features/cilium/cilium-01.feature b/features/cilium/cilium-01.feature new file mode 100644 index 0000000..3a3e0f7 --- /dev/null +++ b/features/cilium/cilium-01.feature @@ -0,0 +1,91 @@ +# doc1: https://gitlab.suse.de/mkravec/scripts/blob/master/tests/cilium.sh +# doc2: http://docs.cilium.io/en/v1.6/gettingstarted/http/ +# doc3: https://github.com/fgerling/bdd-poc + +Feature: cilium-basic + + Scenario: Test-Cilium-Basic on Skuba Cluster + Given there is "imba-cluster" directory + And "skuba" exist in gopath + #And VARIABLE "work-folder" equals "/Users/alexeitighineanu/go/src/github.com/fgerling/bdd-poc/imba-cluster" + When I run "skuba cluster status" + Then the output contains "master" and "worker" + When I run "kubectl get all --namespace=kube-system" + Then the output contains "cilium" and "dex" + + Scenario: Deploy the starwars cilium pods + When I run "kubectl create -f https://raw.githubusercontent.com/cilium/cilium/v1.6/examples/minikube/http-sw-app.yaml" + And wait "10 seconds" + When I run "kubectl get pods --selector=org=empire" + Then the output contains "deathstar" and "tiefighter" + When I run "kubectl get pods --selector=org=alliance" + + Scenario: Check the starwars cilium pods + When I run "kubectl get pods" + And grep for "xwing" + Then the output contains "running" and "running" + And grep for "deathstar" + Then the output contains "running" and "running" + And grep for "tiefighter" + Then the output contains "running" and "running" + + Scenario: Test number1 if empire's ship is allowed into empire space + And I run "kubectl exec tiefighter -- curl -sm10 -XPOST deathstar.default.svc.cluster.local/v1/request-landing" + Then the output contains "Ship" and "landed" + + When I run "kubectl exec xwing -- curl -sm10 -XPOST deathstar.default.svc.cluster.local/v1/request-landing" + Then the output contains "Ship" and "landed" + + Scenario: Test number2 if policies work properly + When I run "kubectl create -f https://raw.githubusercontent.com/cilium/cilium/v1.6/examples/minikube/sw_l3_l4_policy.yaml" + And I run "kubectl exec tiefighter -- curl -sm10 -XPOST deathstar.default.svc.cluster.local/v1/request-landing" + Then the output contains "Ship" and "landed" + + When I run "kubectl exec xwing -- curl -sm10 -XPOST deathstar.default.svc.cluster.local/v1/request-landing" expecting ERROR + And wait "10 seconds" + Then the error contains "exit" and "28" + + Scenario: Inspecting the policies + When I run "kubectl -n kube-system get pods -l k8s-app=cilium" + Then the output contains "cilium-" and "running" + When VARIABLE "cilium-container" equals ContainerFROMOutput "cilium" + And VARIABLE "command5" equals "kubectl -n kube-system exec " plus VAR:"cilium-container" plus " -- cilium endpoint list" + And I run VAR:"command5" + And grep for "class=deathstar" + Then the output contains "enabled" and "disabled" + And I run VAR:"command5" + And grep for "class=xwing" + Then the output contains "disabled" and "disabled" + And I run VAR:"command5" + And grep for "class=tiefighter" + Then the output contains "disabled" and "disabled" + And I run "kubectl get cnp" + When VARIABLE "cilium-rule" equals ContainerFROMOutput "rule" + And VARIABLE "command6" equals "kubectl describe cnp " plus VAR:"cilium-rule" + And grep for "Class:" + Then the output contains "deathstar" and "deathstar" + And grep for "Org:" + Then the output contains "empire" and "empire" + And grep for "Description:" + Then the output contains "policy to restrict" and "empire ships only" + + Scenario: Applying new policy for exhaust port + When I run "kubectl apply -f https://raw.githubusercontent.com/cilium/cilium/v1.6/examples/minikube/sw_l3_l4_l7_policy.yaml" + Then the output contains "ciliumnetworkpolicy" and "configured" + And wait "1 seconds" + #When I run "kubectl exec tiefighter -- curl -s -XPOST deathstar.default.svc.cluster.local/v1/request-landing" + #Then the output contains "Ship" and "landed" + #When I run "kubectl exec tiefighter -- curl -s -XPOST deathstar.default.svc.cluster.local/v1/exhaust-port" + #Then the output contains "Access" and "denied" + + + Scenario: Deleting the policies + When I run "kubectl delete -f https://raw.githubusercontent.com/cilium/cilium/v1.6/examples/minikube/sw_l3_l4_l7_policy.yaml" + Then the output contains "ciliumnetworkpolicy" and "deleted" + + Scenario: Deleting the pods + When VARIABLE "work-folder" equals "/Users/alexeitighineanu/go/src/github.com/fgerling/bdd-poc/imba-cluster" + When I run "kubectl delete -f https://raw.githubusercontent.com/cilium/cilium/v1.6/examples/minikube/http-sw-app.yaml" + Then the output contains "deathstar" and "deleted" + Then the output contains "xwing" and "deleted" + Then the output contains "tiefighter" and "deleted" \ No newline at end of file diff --git a/features/cilium/cilium.go b/features/cilium/cilium.go new file mode 100644 index 0000000..912be31 --- /dev/null +++ b/features/cilium/cilium.go @@ -0,0 +1,122 @@ +package cilium + +import ( + "fmt" + "log" + "os" + "os/exec" + "strings" +) + +var Out1 []byte +var Err error +var VarMap map[string]string + +func iRunInDirectory(arg1, arg2 string) error { + var err error + tmp := strings.Split(arg1, " ") + cmd := exec.Command(tmp[0], tmp[1:]...) + cmd.Dir = arg2 + Out1, err = cmd.CombinedOutput() + if err != nil { + fmt.Fprintf(os.Stdout, "error: %s", err) + return err + } + //fmt.Printf("%s", fmt.Sprintf("%s", string(Out1))) + return err +} + +func IRunVARInVARDirectory(arg1, arg2 string) error { + arg1 = VarMap[arg1] + err := IRunInVARDirectory(arg1, arg2) + return err +} + +func IRunInVARDirectory(arg1, arg2 string) error { + arg2 = VarMap[arg2] + err := iRunInDirectory(arg1, arg2) + return err +} + +func VARIABLEEqualsContainerFROMOutput(arg1, arg2 string) error { + var err error + tmp := strings.Split(fmt.Sprintf("%s", string(Out1)), "\n") + for _, elem := range tmp { + if strings.Contains(elem, arg2) { + tmp2 := strings.Split(elem, " ") + err = VARIABLEEquals(arg1, tmp2[0]) + break + } + } + return err +} + +func VARIABLEEquals(arg1, arg2 string) error { + var err error + if VarMap == nil { + VarMap = make(map[string]string) + } + VarMap[arg1] = arg2 + log.Printf("VAR: %s = %s\n", arg1, VarMap[arg1]) + return err +} + +func VARIABLEEqualsPlusVARPlus(arg1, arg2, arg3, arg4 string) error { + arg3 = VarMap[arg3] + tmp := arg2 + arg3 + arg4 + err := VARIABLEEquals(arg1, tmp) + return err +} + +func VARIABLEEqualsPlusVAR(arg1, arg2, arg3 string) error { + arg3 = VarMap[arg3] + tmp := arg2 + arg3 + err := VARIABLEEquals(arg1, tmp) + return err +} + +func TheErrorContainsAnd(arg1, arg2 string) error { + var err error + if !strings.Contains(fmt.Sprintf("%s", Err), arg1) && strings.Contains(fmt.Sprintf("%s", Err), arg2) { + fmt.Println("ERROR!!!") + } + return err +} + +func IRunExpectingERROR(arg1 string) error { + var err error + tmp := strings.Split(arg1, " ") + cmd := exec.Command(tmp[0], tmp[1:]...) + Out1, err = cmd.CombinedOutput() + if err != nil { + if !strings.Contains(fmt.Sprintf("%s", err), "exit") && strings.Contains(fmt.Sprintf("%s", err), "28") { + fmt.Fprintf(os.Stdout, "error: %s", err) + return err + } + } + Err = err + err = nil + return err +} + +func IRunVARExpectingERROR(arg1 string) error { + IRunExpectingERROR(VarMap[arg1]) + return nil +} + +func IRunVARExpectingERRORInVARDirectory(arg1, arg2 string) error { + var err error + tmp := strings.Split(arg1, " ") + cmd := exec.Command(tmp[0], tmp[1:]...) + cmd.Dir = arg2 + Out1, err = cmd.CombinedOutput() + if err != nil { + if !strings.Contains(fmt.Sprintf("%s", err), "exit code") && strings.Contains(fmt.Sprintf("%s", err), "28") { + fmt.Fprintf(os.Stdout, "error: %s", err) + return err + } + } + Err = err + err = nil + return err +} From 7e6fa25fd4caab89c526b6c13a7933be0590f40a Mon Sep 17 00:00:00 2001 From: atighineanu Date: Mon, 2 Mar 2020 16:32:12 +0100 Subject: [PATCH 03/50] added functions for new cilium test/ improved main_test functions --- features/cilium/cilium-01.feature | 3 +- features/cilium/cilium.go | 51 +++++++++++++++++++++++++++++-- main_test.go | 4 +++ 3 files changed, 54 insertions(+), 4 deletions(-) diff --git a/features/cilium/cilium-01.feature b/features/cilium/cilium-01.feature index 3a3e0f7..c716724 100644 --- a/features/cilium/cilium-01.feature +++ b/features/cilium/cilium-01.feature @@ -5,8 +5,7 @@ Feature: cilium-basic Scenario: Test-Cilium-Basic on Skuba Cluster - Given there is "imba-cluster" directory - And "skuba" exist in gopath + Given "skuba" exist in gopath #And VARIABLE "work-folder" equals "/Users/alexeitighineanu/go/src/github.com/fgerling/bdd-poc/imba-cluster" When I run "skuba cluster status" Then the output contains "master" and "worker" diff --git a/features/cilium/cilium.go b/features/cilium/cilium.go index 912be31..372ea40 100644 --- a/features/cilium/cilium.go +++ b/features/cilium/cilium.go @@ -1,10 +1,11 @@ package cilium import ( + "errors" "fmt" - "log" "os" "os/exec" + "strconv" "strings" ) @@ -38,6 +39,18 @@ func IRunInVARDirectory(arg1, arg2 string) error { return err } +func VARIABLEEqualsContainersFROMOutput(arg1, arg2 string) error { + var err error + tmp := strings.Split(fmt.Sprintf("%s", string(Out1)), "\n") + for index, elem := range tmp { + if strings.Contains(elem, arg2) { + tmp2 := strings.Split(elem, " ") + err = VARIABLEEquals(arg1+strconv.Itoa(index), tmp2[0]) + } + } + return err +} + func VARIABLEEqualsContainerFROMOutput(arg1, arg2 string) error { var err error tmp := strings.Split(fmt.Sprintf("%s", string(Out1)), "\n") @@ -57,7 +70,7 @@ func VARIABLEEquals(arg1, arg2 string) error { VarMap = make(map[string]string) } VarMap[arg1] = arg2 - log.Printf("VAR: %s = %s\n", arg1, VarMap[arg1]) + fmt.Printf(" VAR: %s = %s \n", arg1, VarMap[arg1]) return err } @@ -68,6 +81,21 @@ func VARIABLEEqualsPlusVARPlus(arg1, arg2, arg3, arg4 string) error { return err } +func VARIABLESEqualsPlusVAR(arg1, arg2, arg3 string) error { + var err error + for i := 0; i < 1000; i++ { + if VarMap[arg3+strconv.Itoa(i)] != "" { + tmp := arg2 + VarMap[arg3+strconv.Itoa(i)] + err = VARIABLEEquals(arg1+strconv.Itoa(i), tmp) + if err == nil { + VarMap[arg3+strconv.Itoa(i)] = "" + } + } + + } + return err +} + func VARIABLEEqualsPlusVAR(arg1, arg2, arg3 string) error { arg3 = VarMap[arg3] tmp := arg2 + arg3 @@ -120,3 +148,22 @@ func IRunVARExpectingERRORInVARDirectory(arg1, arg2 string) error { err = nil return err } + +func theOutputContainsAnd(arg1, arg2 string) error { + if !strings.Contains(fmt.Sprintf("%s", string(Out1)), arg1) && strings.Contains(fmt.Sprintf("%s", string(Out1)), arg2) { + return errors.New("Output does not contain expected arguments") + } + return nil +} + +func IRunVARSAndCheckForAnd(arg1, arg2, arg3 string) error { + var err error + for i := 0; i < 1000; i++ { + if VarMap[arg1+strconv.Itoa(i)] != "" { + err = iRunInDirectory(VarMap[arg1+strconv.Itoa(i)], ".") + theOutputContainsAnd(arg2, arg3) + VarMap[arg1+strconv.Itoa(i)] = "" + } + } + return err +} diff --git a/main_test.go b/main_test.go index 0f73719..454d33d 100644 --- a/main_test.go +++ b/main_test.go @@ -70,6 +70,7 @@ func iRunInDirectory(command, workdir string) error { args := strings.Split(command, " ") cmd := exec.Command(args[0], args[1:]...) cmd.Dir = workdir + //cmd.Env = append(os.Environ(), "KUBECONFIG=/Users/alexeitighineanu/go/src/github.com/fgerling/bdd-poc/admin.conf") Out1, err = cmd.CombinedOutput() if err != nil { return errors.New(string(Output)) @@ -189,12 +190,15 @@ func FeatureContext(s *godog.Suite) { s.Step(`^I have the correct go version$`, func() error { return iRunInDirectory("make go-version-check", "skuba") }) s.Step(`^grep for "([^"]*)"$`, grepFor) //--------------------Cilium-specific test functions----------------------------------------------- + s.Step(`^I run VARS:"([^"]*)" and check for "([^"]*)" and "([^"]*)"$`, cilium.IRunVARSAndCheckForAnd) + s.Step(`^VARIABLE "([^"]*)" equals ContainersFROMOutput "([^"]*)"$`, cilium.VARIABLEEqualsContainersFROMOutput) s.Step(`^VARIABLE "([^"]*)" equals ContainerFROMOutput "([^"]*)"$`, cilium.VARIABLEEqualsContainerFROMOutput) s.Step(`^I run "([^"]*)" expecting ERROR$`, cilium.IRunExpectingERROR) s.Step(`^I run VAR:"([^"]*)" expecting ERROR$`, cilium.IRunVARExpectingERROR) s.Step(`^I run VAR:"([^"]*)" expecting ERROR in VAR:"([^"]*)" directory$`, cilium.IRunVARExpectingERRORInVARDirectory) s.Step(`^the error contains "([^"]*)" and "([^"]*)"$`, cilium.TheErrorContainsAnd) s.Step(`^I run VAR:"([^"]*)" in VAR:"([^"]*)" directory$`, cilium.IRunVARInVARDirectory) + s.Step(`^VARIABLES "([^"]*)" equals "([^"]*)" plus VAR:"([^"]*)"$`, cilium.VARIABLESEqualsPlusVAR) s.Step(`^VARIABLE "([^"]*)" equals "([^"]*)" plus VAR:"([^"]*)"$`, cilium.VARIABLEEqualsPlusVAR) s.Step(`^VARIABLE "([^"]*)" equals "([^"]*)" plus VAR:"([^"]*)" plus "([^"]*)"$`, cilium.VARIABLEEqualsPlusVARPlus) s.Step(`^I run "([^"]*)" in VAR:"([^"]*)" directory$`, cilium.IRunInVARDirectory) From bf9bb1530eec17afad19b06ec8e2db83d356cd74 Mon Sep 17 00:00:00 2001 From: atighineanu Date: Mon, 2 Mar 2020 16:33:43 +0100 Subject: [PATCH 04/50] new testcase for corresponding BSC (BUG) --- features/cilium/cilium-bsc#1121353.feature | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 features/cilium/cilium-bsc#1121353.feature diff --git a/features/cilium/cilium-bsc#1121353.feature b/features/cilium/cilium-bsc#1121353.feature new file mode 100644 index 0000000..ec87882 --- /dev/null +++ b/features/cilium/cilium-bsc#1121353.feature @@ -0,0 +1,27 @@ +#TC description: https://github.com/SUSE/caasp-test-cases/pull/22/files#diff-6b705e1a52bb5b33c1c2efee4a329c2f +#BUG: https://bugzilla.suse.com/show_bug.cgi?id=1121353 +#PR: https://github.com/SUSE/skuba/pull/967 + +Feature: bsc#1121353 - Kubernetes – Master node pod configured with Privileged PSP + +Scenario: Checking if Privileged Pods + Given "skuba" exist in gopath + When I run "skuba cluster status" + Then the output contains "master" and "worker" + When I run "kubectl get all --namespace=kube-system" + Then the output contains "cilium" and "dex" + + When I run "kubectl get pods --namespace=kube-system" + When VARIABLE "privileged-pods" equals ContainersFROMOutput "cilium-" + And VARIABLES "commandchecks" equals "kubectl describe pod -n kube-system " plus VAR:"privileged-pods" + And I run VARS:"commandchecks" and check for "psp" and "kubernetes.io/psp: suse.caasp.psp.privileged" + + When I run "kubectl get pods --namespace=kube-system" + When VARIABLE "privileged-pods" equals ContainersFROMOutput "kube-proxy-" + And VARIABLES "commandchecks" equals "kubectl describe pod -n kube-system " plus VAR:"privileged-pods" + And I run VARS:"commandchecks" and check for "psp" and "kubernetes.io/psp: suse.caasp.psp.privileged" + + When I run "kubectl get pods --namespace=kube-system" + When VARIABLE "privileged-pods" equals ContainersFROMOutput "kured-" + And VARIABLES "commandchecks" equals "kubectl describe pod -n kube-system " plus VAR:"privileged-pods" + And I run VARS:"commandchecks" and check for "psp" and "kubernetes.io/psp: suse.caasp.psp.privileged" From 131cc7909ff30b88ad40713dbcece8d817334b5b Mon Sep 17 00:00:00 2001 From: atighineanu Date: Wed, 4 Mar 2020 07:53:20 +0100 Subject: [PATCH 05/50] added kured basic test --- main_test.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/main_test.go b/main_test.go index 454d33d..ee7d413 100644 --- a/main_test.go +++ b/main_test.go @@ -12,6 +12,7 @@ import ( "time" cilium "github.com/fgerling/bdd-poc/features/cilium" + "github.com/fgerling/bdd-poc/features/kured" "github.com/cucumber/godog" suse "github.com/fgerling/bdd-poc/internal/suse" @@ -76,6 +77,7 @@ func iRunInDirectory(command, workdir string) error { return errors.New(string(Output)) } cilium.Out1 = Out1 + kured.Out1 = Out1 return err } @@ -204,4 +206,7 @@ func FeatureContext(s *godog.Suite) { s.Step(`^I run "([^"]*)" in VAR:"([^"]*)" directory$`, cilium.IRunInVARDirectory) s.Step(`^VARIABLE "([^"]*)" equals "([^"]*)"$`, cilium.VARIABLEEquals) //------------------------------------------------------------------------------------------------- + //-------------------Kured-specific test functions------------------------------------------------- + s.Step(`^I run VARS:"([^"]*)" and IPSFromOutput$`, kured.IRunVARSAndIPSFromOutput) + s.Step(`^I run SSHCMD "([^"]*)" on MASTER$`, kured.IRunSSHCMDOnMASTER) } From e612dd2965222f37c7dc23f95e396e1ed986596f Mon Sep 17 00:00:00 2001 From: atighineanu Date: Wed, 4 Mar 2020 07:54:36 +0100 Subject: [PATCH 06/50] functions to test kured --- features/kured/kured.go | 72 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 features/kured/kured.go diff --git a/features/kured/kured.go b/features/kured/kured.go new file mode 100644 index 0000000..4ecdce4 --- /dev/null +++ b/features/kured/kured.go @@ -0,0 +1,72 @@ +package kured + +import ( + "fmt" + "log" + "os" + "os/exec" + "strconv" + "strings" + + "github.com/fgerling/bdd-poc/features/cilium" +) + +var Out1 []byte + +func iRunInDirectory(arg1, arg2 string) error { + var err error + tmp := strings.Split(arg1, " ") + cmd := exec.Command(tmp[0], tmp[1:]...) + cmd.Dir = arg2 + Out1, err = cmd.CombinedOutput() + if err != nil { + fmt.Fprintf(os.Stdout, "error: %s", err) + return err + } + //fmt.Printf("%s", fmt.Sprintf("%s", string(Out1))) + return err +} + +func IRunVARSAndIPSFromOutput(arg1 string) error { + var err error + for i := 0; i < 1000; i++ { + if cilium.VarMap[arg1+strconv.Itoa(i)] != "" { + err = iRunInDirectory(cilium.VarMap[arg1+strconv.Itoa(i)], ".") + tmp1 := strings.Split(fmt.Sprintf("%s", string(Out1)), "\n") + for _, elem := range tmp1 { + if strings.Contains(elem, "Node:") { + tmp2 := strings.Split(strings.Split(strings.Replace(elem, " ", "", 100), ":")[len(strings.Split(strings.Replace(elem, " ", "", 100), ":"))-1], "/") + if len(tmp2) == 2 { + cilium.VARIABLEEquals(tmp2[0], tmp2[1]) + } else { + fmt.Printf("Something's wrong with your kubectl describe...\n Is that even the right row? %s\n", elem) + } + break + } + } + cilium.VarMap[arg1+strconv.Itoa(i)] = "" + } + } + return err +} + +func IRunSSHCMDOnMASTER(arg1 string) error { + var ip string + for key, _ := range cilium.VarMap { + if strings.Contains(key, "master") /*&& strings.Contains(key, "00")*/ { + ip = cilium.VarMap[key] + } + } + arg := append( + []string{"-q", "-o", "StrictHostKeyChecking=no", "-o", "UserKnownHostsFile /dev/null", "-i", "id_shared", + fmt.Sprintf("sles@%s", ip), + }, + arg1, + ) + Out1, err := exec.Command("ssh", arg...).CombinedOutput() + if err != nil { + log.Printf("Error! %s", err) + } + fmt.Printf("%s\n", fmt.Sprintf("%s", string(Out1))) + return err +} From 2afcf21f829cce5161f24209bc7c1f3919c090fa Mon Sep 17 00:00:00 2001 From: atighineanu Date: Wed, 4 Mar 2020 07:54:55 +0100 Subject: [PATCH 07/50] basic BDD test for kured --- features/kured/kured-01.feature | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 features/kured/kured-01.feature diff --git a/features/kured/kured-01.feature b/features/kured/kured-01.feature new file mode 100644 index 0000000..2f839df --- /dev/null +++ b/features/kured/kured-01.feature @@ -0,0 +1,17 @@ +# TC: https://github.com/fgerling/bdd-poc +# This is a basic test for kured (no PR or BSC provided) + +Feature: Check if reboot triggered + +Scenario: Checking if reboot triggered on one node + Given "skuba" exist in gopath + When I run "skuba cluster status" + Then the output contains "master" and "worker" + When I run "kubectl get all --namespace=kube-system" + Then the output contains "cilium" and "dex" + + When I run "kubectl get pods --namespace=kube-system" + When VARIABLE "privileged-pods" equals ContainersFROMOutput "kured-" + And VARIABLES "commandchecks" equals "kubectl describe pod -n kube-system " plus VAR:"privileged-pods" + And I run VARS:"commandchecks" and IPSFromOutput + And I run SSHCMD "sudo touch /var/run/reboot-required" on MASTER \ No newline at end of file From 395e32ae17677e6a2b2cce20db4869ce4b6ae261 Mon Sep 17 00:00:00 2001 From: atighineanu Date: Wed, 4 Mar 2020 07:55:13 +0100 Subject: [PATCH 08/50] grinded the cilium code --- features/cilium/cilium-01.feature | 3 ++- features/cilium/cilium.go | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/features/cilium/cilium-01.feature b/features/cilium/cilium-01.feature index c716724..ac5d6e1 100644 --- a/features/cilium/cilium-01.feature +++ b/features/cilium/cilium-01.feature @@ -1,6 +1,7 @@ # doc1: https://gitlab.suse.de/mkravec/scripts/blob/master/tests/cilium.sh # doc2: http://docs.cilium.io/en/v1.6/gettingstarted/http/ -# doc3: https://github.com/fgerling/bdd-poc +# TC: https://github.com/fgerling/bdd-poc +# This is a basic test for cilium (no PR or BSC provided) Feature: cilium-basic diff --git a/features/cilium/cilium.go b/features/cilium/cilium.go index 372ea40..d4e536d 100644 --- a/features/cilium/cilium.go +++ b/features/cilium/cilium.go @@ -43,7 +43,7 @@ func VARIABLEEqualsContainersFROMOutput(arg1, arg2 string) error { var err error tmp := strings.Split(fmt.Sprintf("%s", string(Out1)), "\n") for index, elem := range tmp { - if strings.Contains(elem, arg2) { + if strings.Contains(elem, arg2) && !strings.Contains(elem, "operator") { //--- "operator" is to exclude cilium-operator tmp2 := strings.Split(elem, " ") err = VARIABLEEquals(arg1+strconv.Itoa(index), tmp2[0]) } From 4f794e85c0c40701e6f114918727aa46b25a8b4f Mon Sep 17 00:00:00 2001 From: atighineanu Date: Thu, 12 Mar 2020 08:44:36 +0100 Subject: [PATCH 09/50] changed the features folder --- features/cilium/cilium.go | 169 -------------------------------- features/kured/kured-01.feature | 5 +- features/kured/kured.go | 72 -------------- main_test.go | 125 ++++++----------------- 4 files changed, 33 insertions(+), 338 deletions(-) delete mode 100644 features/cilium/cilium.go delete mode 100644 features/kured/kured.go diff --git a/features/cilium/cilium.go b/features/cilium/cilium.go deleted file mode 100644 index d4e536d..0000000 --- a/features/cilium/cilium.go +++ /dev/null @@ -1,169 +0,0 @@ -package cilium - -import ( - "errors" - "fmt" - "os" - "os/exec" - "strconv" - "strings" -) - -var Out1 []byte -var Err error -var VarMap map[string]string - -func iRunInDirectory(arg1, arg2 string) error { - var err error - tmp := strings.Split(arg1, " ") - cmd := exec.Command(tmp[0], tmp[1:]...) - cmd.Dir = arg2 - Out1, err = cmd.CombinedOutput() - if err != nil { - fmt.Fprintf(os.Stdout, "error: %s", err) - return err - } - //fmt.Printf("%s", fmt.Sprintf("%s", string(Out1))) - return err -} - -func IRunVARInVARDirectory(arg1, arg2 string) error { - arg1 = VarMap[arg1] - err := IRunInVARDirectory(arg1, arg2) - return err -} - -func IRunInVARDirectory(arg1, arg2 string) error { - arg2 = VarMap[arg2] - err := iRunInDirectory(arg1, arg2) - return err -} - -func VARIABLEEqualsContainersFROMOutput(arg1, arg2 string) error { - var err error - tmp := strings.Split(fmt.Sprintf("%s", string(Out1)), "\n") - for index, elem := range tmp { - if strings.Contains(elem, arg2) && !strings.Contains(elem, "operator") { //--- "operator" is to exclude cilium-operator - tmp2 := strings.Split(elem, " ") - err = VARIABLEEquals(arg1+strconv.Itoa(index), tmp2[0]) - } - } - return err -} - -func VARIABLEEqualsContainerFROMOutput(arg1, arg2 string) error { - var err error - tmp := strings.Split(fmt.Sprintf("%s", string(Out1)), "\n") - for _, elem := range tmp { - if strings.Contains(elem, arg2) { - tmp2 := strings.Split(elem, " ") - err = VARIABLEEquals(arg1, tmp2[0]) - break - } - } - return err -} - -func VARIABLEEquals(arg1, arg2 string) error { - var err error - if VarMap == nil { - VarMap = make(map[string]string) - } - VarMap[arg1] = arg2 - fmt.Printf(" VAR: %s = %s \n", arg1, VarMap[arg1]) - return err -} - -func VARIABLEEqualsPlusVARPlus(arg1, arg2, arg3, arg4 string) error { - arg3 = VarMap[arg3] - tmp := arg2 + arg3 + arg4 - err := VARIABLEEquals(arg1, tmp) - return err -} - -func VARIABLESEqualsPlusVAR(arg1, arg2, arg3 string) error { - var err error - for i := 0; i < 1000; i++ { - if VarMap[arg3+strconv.Itoa(i)] != "" { - tmp := arg2 + VarMap[arg3+strconv.Itoa(i)] - err = VARIABLEEquals(arg1+strconv.Itoa(i), tmp) - if err == nil { - VarMap[arg3+strconv.Itoa(i)] = "" - } - } - - } - return err -} - -func VARIABLEEqualsPlusVAR(arg1, arg2, arg3 string) error { - arg3 = VarMap[arg3] - tmp := arg2 + arg3 - err := VARIABLEEquals(arg1, tmp) - return err -} - -func TheErrorContainsAnd(arg1, arg2 string) error { - var err error - if !strings.Contains(fmt.Sprintf("%s", Err), arg1) && strings.Contains(fmt.Sprintf("%s", Err), arg2) { - fmt.Println("ERROR!!!") - } - return err -} - -func IRunExpectingERROR(arg1 string) error { - var err error - tmp := strings.Split(arg1, " ") - cmd := exec.Command(tmp[0], tmp[1:]...) - Out1, err = cmd.CombinedOutput() - if err != nil { - if !strings.Contains(fmt.Sprintf("%s", err), "exit") && strings.Contains(fmt.Sprintf("%s", err), "28") { - fmt.Fprintf(os.Stdout, "error: %s", err) - return err - } - } - Err = err - err = nil - return err -} - -func IRunVARExpectingERROR(arg1 string) error { - IRunExpectingERROR(VarMap[arg1]) - return nil -} - -func IRunVARExpectingERRORInVARDirectory(arg1, arg2 string) error { - var err error - tmp := strings.Split(arg1, " ") - cmd := exec.Command(tmp[0], tmp[1:]...) - cmd.Dir = arg2 - Out1, err = cmd.CombinedOutput() - if err != nil { - if !strings.Contains(fmt.Sprintf("%s", err), "exit code") && strings.Contains(fmt.Sprintf("%s", err), "28") { - fmt.Fprintf(os.Stdout, "error: %s", err) - return err - } - } - Err = err - err = nil - return err -} - -func theOutputContainsAnd(arg1, arg2 string) error { - if !strings.Contains(fmt.Sprintf("%s", string(Out1)), arg1) && strings.Contains(fmt.Sprintf("%s", string(Out1)), arg2) { - return errors.New("Output does not contain expected arguments") - } - return nil -} - -func IRunVARSAndCheckForAnd(arg1, arg2, arg3 string) error { - var err error - for i := 0; i < 1000; i++ { - if VarMap[arg1+strconv.Itoa(i)] != "" { - err = iRunInDirectory(VarMap[arg1+strconv.Itoa(i)], ".") - theOutputContainsAnd(arg2, arg3) - VarMap[arg1+strconv.Itoa(i)] = "" - } - } - return err -} diff --git a/features/kured/kured-01.feature b/features/kured/kured-01.feature index 2f839df..4b5c6d0 100644 --- a/features/kured/kured-01.feature +++ b/features/kured/kured-01.feature @@ -14,4 +14,7 @@ Scenario: Checking if reboot triggered on one node When VARIABLE "privileged-pods" equals ContainersFROMOutput "kured-" And VARIABLES "commandchecks" equals "kubectl describe pod -n kube-system " plus VAR:"privileged-pods" And I run VARS:"commandchecks" and IPSFromOutput - And I run SSHCMD "sudo touch /var/run/reboot-required" on MASTER \ No newline at end of file + And I run SSHCMD "sudo touch /var/run/reboot-required" on MASTER + And wait "140 seconds" + And I run SSHCMD "sudo crictl ps" on MASTER + Then the output contains "seconds" or "a minute" \ No newline at end of file diff --git a/features/kured/kured.go b/features/kured/kured.go deleted file mode 100644 index 4ecdce4..0000000 --- a/features/kured/kured.go +++ /dev/null @@ -1,72 +0,0 @@ -package kured - -import ( - "fmt" - "log" - "os" - "os/exec" - "strconv" - "strings" - - "github.com/fgerling/bdd-poc/features/cilium" -) - -var Out1 []byte - -func iRunInDirectory(arg1, arg2 string) error { - var err error - tmp := strings.Split(arg1, " ") - cmd := exec.Command(tmp[0], tmp[1:]...) - cmd.Dir = arg2 - Out1, err = cmd.CombinedOutput() - if err != nil { - fmt.Fprintf(os.Stdout, "error: %s", err) - return err - } - //fmt.Printf("%s", fmt.Sprintf("%s", string(Out1))) - return err -} - -func IRunVARSAndIPSFromOutput(arg1 string) error { - var err error - for i := 0; i < 1000; i++ { - if cilium.VarMap[arg1+strconv.Itoa(i)] != "" { - err = iRunInDirectory(cilium.VarMap[arg1+strconv.Itoa(i)], ".") - tmp1 := strings.Split(fmt.Sprintf("%s", string(Out1)), "\n") - for _, elem := range tmp1 { - if strings.Contains(elem, "Node:") { - tmp2 := strings.Split(strings.Split(strings.Replace(elem, " ", "", 100), ":")[len(strings.Split(strings.Replace(elem, " ", "", 100), ":"))-1], "/") - if len(tmp2) == 2 { - cilium.VARIABLEEquals(tmp2[0], tmp2[1]) - } else { - fmt.Printf("Something's wrong with your kubectl describe...\n Is that even the right row? %s\n", elem) - } - break - } - } - cilium.VarMap[arg1+strconv.Itoa(i)] = "" - } - } - return err -} - -func IRunSSHCMDOnMASTER(arg1 string) error { - var ip string - for key, _ := range cilium.VarMap { - if strings.Contains(key, "master") /*&& strings.Contains(key, "00")*/ { - ip = cilium.VarMap[key] - } - } - arg := append( - []string{"-q", "-o", "StrictHostKeyChecking=no", "-o", "UserKnownHostsFile /dev/null", "-i", "id_shared", - fmt.Sprintf("sles@%s", ip), - }, - arg1, - ) - Out1, err := exec.Command("ssh", arg...).CombinedOutput() - if err != nil { - log.Printf("Error! %s", err) - } - fmt.Printf("%s\n", fmt.Sprintf("%s", string(Out1))) - return err -} diff --git a/main_test.go b/main_test.go index ee7d413..06d8c93 100644 --- a/main_test.go +++ b/main_test.go @@ -1,25 +1,22 @@ package main import ( - "errors" "fmt" "log" "os" - "os/exec" "path" "strconv" "strings" "time" - cilium "github.com/fgerling/bdd-poc/features/cilium" - "github.com/fgerling/bdd-poc/features/kured" + . "github.com/fgerling/bdd-poc/features" "github.com/cucumber/godog" suse "github.com/fgerling/bdd-poc/internal/suse" git "gopkg.in/src-d/go-git.v4" ) -var Output []byte +var test TestRun func existInGopath(arg1 string) error { return theFileExist(path.Join(os.Getenv("GOPATH"), "bin")) @@ -66,65 +63,11 @@ func thereIsNoDirectory(target string) error { return os.RemoveAll(target) } -func iRunInDirectory(command, workdir string) error { - var err error - args := strings.Split(command, " ") - cmd := exec.Command(args[0], args[1:]...) - cmd.Dir = workdir - //cmd.Env = append(os.Environ(), "KUBECONFIG=/Users/alexeitighineanu/go/src/github.com/fgerling/bdd-poc/admin.conf") - Out1, err = cmd.CombinedOutput() - if err != nil { - return errors.New(string(Output)) - } - cilium.Out1 = Out1 - kured.Out1 = Out1 - return err -} - -func theOutputContains(arg string) error { - if !strings.Contains(fmt.Sprintf("%s", string(Output)), arg) { - return errors.New("Output does not contain expected argument") - } - return nil -} - -func theOutputContainsAnd(arg1, arg2 string) error { - if !strings.Contains(fmt.Sprintf("%s", string(Output)), arg1) && strings.Contains(fmt.Sprintf("%s", string(Output)), arg2) { - return errors.New("Output does not contain expected arguments") - } - return nil -} - -func grepFor(arg1 string) error { - var err error - tmp := strings.Split(fmt.Sprintf("%s", string(Out1)), "\n") - for _, elem := range tmp { - if strings.Contains(strings.ToLower(elem), arg1) { - Out1 = []byte(elem) - } - } - return err -} - -var Out1 []byte -var Err error -var VarMap map[string]string - func ReadStringAsInt(arg1 string) (int, error) { a, err := strconv.Atoi(arg1) return a, err } -func VARIABLEEquals(arg1, arg2 string) error { - var err error - if VarMap == nil { - VarMap = make(map[string]string) - } - VarMap[arg1] = arg2 - log.Printf("VAR: %s = %s\n", arg1, VarMap[arg1]) - return err -} - func wait(arg1 string) error { var err error temp := strings.Split(arg1, " ") @@ -156,57 +99,47 @@ func wait(arg1 string) error { return err } -func iRunVAR(arg1 string) error { - if VarMap["command5"] == "" { - return Irun(cilium.VarMap[arg1]) - } else { - return Irun(cilium.VarMap[arg1]) - } -} - -func Irun(command string) error { - return iRunInDirectory(command, ".") -} - func FeatureContext(s *godog.Suite) { + s.Step(`^I start test$`, test.IStartTest) s.Step(`^wait "([^"]*)"$`, wait) s.Step(`^"([^"]*)" exist in gopath$`, existInGopath) s.Step(`^I git clone "([^"]*)" into "([^"]*)"$`, iGitCloneInto) s.Step(`^I have "([^"]*)" in PATH$`, suse.IHaveInPATH) - s.Step(`^I install the pattern "([^"]*)"$`, func() error { return iRunInDirectory("zypper -n in -t pattern SUSE-CaaSP-Management", ".") }) + s.Step(`^I install the pattern "([^"]*)"$`, func() error { return test.IRunInDirectory("zypper -n in -t pattern SUSE-CaaSP-Management", ".") }) s.Step(`^I remove "([^"]*)" from gopath$`, iRemoveFromGopath) - s.Step(`^I run "([^"]*)" in "([^"]*)" directory$`, iRunInDirectory) - s.Step(`^I run "([^"]*)" in "([^"]*)"$`, iRunInDirectory) + s.Step(`^I run "([^"]*)" in "([^"]*)" directory$`, test.IRunInDirectory) + s.Step(`^I run "([^"]*)" in "([^"]*)"$`, test.IRunInDirectory) s.Step(`^I set "([^"]*)" to "([^"]*)"$`, iSetTo) - s.Step(`^my workstation fulfill the requirements$`, func() error { return iRunInDirectory("./check_requirement_workstation.sh", "scripts") }) + s.Step(`^my workstation fulfill the requirements$`, func() error { return test.IRunInDirectory("./check_requirement_workstation.sh", "scripts") }) s.Step(`^the "([^"]*)" is set to "([^"]*)"$`, theIsSetTo) s.Step(`^the "([^"]*)" repository exist$`, theRepositoryExist) s.Step(`^the directory "([^"]*)" exist$`, theDirectoryExist) s.Step(`^the file "([^"]*)" exist$`, theFileExist) - s.Step(`^the output contains "([^"]*)" and "([^"]*)"$`, theOutputContainsAnd) + s.Step(`^the output contains "([^"]*)" and "([^"]*)"$`, test.TheOutputContainsAnd) + s.Step(`^the output contains "([^"]*)" or "([^"]*)"$`, test.TheOutputContainsOr) s.Step(`^there is "([^"]*)" directory$`, theDirectoryExist) s.Step(`^there is no "([^"]*)" directory$`, thereIsNoDirectory) - s.Step(`^I run VAR:"([^"]*)"$`, iRunVAR) - s.Step(`^I run "([^"]*)"$`, Irun) - s.Step(`^the output contains "([^"]*)"$`, theOutputContains) - s.Step(`^I have the correct go version$`, func() error { return iRunInDirectory("make go-version-check", "skuba") }) - s.Step(`^grep for "([^"]*)"$`, grepFor) + s.Step(`^I run VAR:"([^"]*)"$`, test.IRunVAR) + s.Step(`^I run "([^"]*)"$`, test.Irun) + s.Step(`^the output contains "([^"]*)"$`, test.TheOutputContains) + s.Step(`^I have the correct go version$`, func() error { return test.IRunInDirectory("make go-version-check", "skuba") }) + s.Step(`^grep for "([^"]*)"$`, test.GrepFor) //--------------------Cilium-specific test functions----------------------------------------------- - s.Step(`^I run VARS:"([^"]*)" and check for "([^"]*)" and "([^"]*)"$`, cilium.IRunVARSAndCheckForAnd) - s.Step(`^VARIABLE "([^"]*)" equals ContainersFROMOutput "([^"]*)"$`, cilium.VARIABLEEqualsContainersFROMOutput) - s.Step(`^VARIABLE "([^"]*)" equals ContainerFROMOutput "([^"]*)"$`, cilium.VARIABLEEqualsContainerFROMOutput) - s.Step(`^I run "([^"]*)" expecting ERROR$`, cilium.IRunExpectingERROR) - s.Step(`^I run VAR:"([^"]*)" expecting ERROR$`, cilium.IRunVARExpectingERROR) - s.Step(`^I run VAR:"([^"]*)" expecting ERROR in VAR:"([^"]*)" directory$`, cilium.IRunVARExpectingERRORInVARDirectory) - s.Step(`^the error contains "([^"]*)" and "([^"]*)"$`, cilium.TheErrorContainsAnd) - s.Step(`^I run VAR:"([^"]*)" in VAR:"([^"]*)" directory$`, cilium.IRunVARInVARDirectory) - s.Step(`^VARIABLES "([^"]*)" equals "([^"]*)" plus VAR:"([^"]*)"$`, cilium.VARIABLESEqualsPlusVAR) - s.Step(`^VARIABLE "([^"]*)" equals "([^"]*)" plus VAR:"([^"]*)"$`, cilium.VARIABLEEqualsPlusVAR) - s.Step(`^VARIABLE "([^"]*)" equals "([^"]*)" plus VAR:"([^"]*)" plus "([^"]*)"$`, cilium.VARIABLEEqualsPlusVARPlus) - s.Step(`^I run "([^"]*)" in VAR:"([^"]*)" directory$`, cilium.IRunInVARDirectory) - s.Step(`^VARIABLE "([^"]*)" equals "([^"]*)"$`, cilium.VARIABLEEquals) + s.Step(`^I run VARS:"([^"]*)" and check for "([^"]*)" and "([^"]*)"$`, test.IRunVARSAndCheckForAnd) + s.Step(`^VARIABLE "([^"]*)" equals ContainersFROMOutput "([^"]*)"$`, test.VARIABLEEqualsContainersFROMOutput) + s.Step(`^VARIABLE "([^"]*)" equals ContainerFROMOutput "([^"]*)"$`, test.VARIABLEEqualsContainerFROMOutput) + s.Step(`^I run "([^"]*)" expecting ERROR$`, test.IRunExpectingERROR) + s.Step(`^I run VAR:"([^"]*)" expecting ERROR$`, test.IRunVARExpectingERROR) + s.Step(`^I run VAR:"([^"]*)" expecting ERROR in VAR:"([^"]*)" directory$`, test.IRunVARExpectingERRORInVARDirectory) + s.Step(`^the error contains "([^"]*)" and "([^"]*)"$`, test.TheErrorContainsAnd) + s.Step(`^I run VAR:"([^"]*)" in VAR:"([^"]*)" directory$`, test.IRunVARInVARDirectory) + s.Step(`^VARIABLES "([^"]*)" equals "([^"]*)" plus VAR:"([^"]*)"$`, test.VARIABLESEqualsPlusVAR) + s.Step(`^VARIABLE "([^"]*)" equals "([^"]*)" plus VAR:"([^"]*)"$`, test.VARIABLEEqualsPlusVAR) + s.Step(`^VARIABLE "([^"]*)" equals "([^"]*)" plus VAR:"([^"]*)" plus "([^"]*)"$`, test.VARIABLEEqualsPlusVARPlus) + s.Step(`^I run "([^"]*)" in VAR:"([^"]*)" directory$`, test.IRunInVARDirectory) + s.Step(`^VARIABLE "([^"]*)" equals "([^"]*)"$`, test.VARIABLEEquals) //------------------------------------------------------------------------------------------------- //-------------------Kured-specific test functions------------------------------------------------- - s.Step(`^I run VARS:"([^"]*)" and IPSFromOutput$`, kured.IRunVARSAndIPSFromOutput) - s.Step(`^I run SSHCMD "([^"]*)" on MASTER$`, kured.IRunSSHCMDOnMASTER) + s.Step(`^I run VARS:"([^"]*)" and IPSFromOutput$`, test.IRunVARSAndIPSFromOutput) + s.Step(`^I run SSHCMD "([^"]*)" on MASTER$`, test.IRunSSHCMDOnMASTER) } From 996a54b2bcb7a86d6eae74b3cd7d7c9c4818d0da Mon Sep 17 00:00:00 2001 From: atighineanu Date: Thu, 12 Mar 2020 08:47:03 +0100 Subject: [PATCH 10/50] moved go files inside a single features package --- features/cilium.go | 153 ++++++++++++++++++++++++++++++++++++++++++ features/data.go | 7 ++ features/kured.go | 80 ++++++++++++++++++++++ features/utilities.go | 58 ++++++++++++++++ 4 files changed, 298 insertions(+) create mode 100644 features/cilium.go create mode 100644 features/data.go create mode 100644 features/kured.go create mode 100644 features/utilities.go diff --git a/features/cilium.go b/features/cilium.go new file mode 100644 index 0000000..ee513f1 --- /dev/null +++ b/features/cilium.go @@ -0,0 +1,153 @@ +package features + +import ( + "errors" + "fmt" + "os" + "os/exec" + "strconv" + "strings" +) + +func (test *TestRun) IRunVARInVARDirectory(arg1, arg2 string) error { + arg1 = test.VarMap[arg1] + err := test.IRunInVARDirectory(arg1, arg2) + return err +} + +func (test *TestRun) IRunInVARDirectory(arg1, arg2 string) error { + arg2 = test.VarMap[arg2] + err := test.IRunInDirectory(arg1, arg2) + return err +} + +func (test *TestRun) VARIABLEEqualsContainersFROMOutput(arg1, arg2 string) error { + var err error + tmp := strings.Split(fmt.Sprintf("%s", string(test.Output)), "\n") + for index, elem := range tmp { + if strings.Contains(elem, arg2) && !strings.Contains(elem, "operator") { //--- "operator" is to exclude cilium-operator + tmp2 := strings.Split(elem, " ") + err = test.VARIABLEEquals(arg1+strconv.Itoa(index), tmp2[0]) + } + } + return err +} + +func (test *TestRun) VARIABLEEqualsContainerFROMOutput(arg1, arg2 string) error { + var err error + tmp := strings.Split(fmt.Sprintf("%s", string(test.Output)), "\n") + for _, elem := range tmp { + if strings.Contains(elem, arg2) { + tmp2 := strings.Split(elem, " ") + err = test.VARIABLEEquals(arg1, tmp2[0]) + break + } + } + return err +} + +func (test *TestRun) VARIABLEEquals(arg1, arg2 string) error { + var err error + if test.VarMap == nil { + test.VarMap = make(map[string]string) + } + test.VarMap[arg1] = arg2 + fmt.Printf(" VAR: %s = %s \n", arg1, test.VarMap[arg1]) + return err +} + +func (test *TestRun) VARIABLEEqualsPlusVARPlus(arg1, arg2, arg3, arg4 string) error { + arg3 = test.VarMap[arg3] + tmp := arg2 + arg3 + arg4 + err := test.VARIABLEEquals(arg1, tmp) + return err +} + +func (test *TestRun) VARIABLESEqualsPlusVAR(arg1, arg2, arg3 string) error { + var err error + for i := 0; i < 1000; i++ { + if test.VarMap[arg3+strconv.Itoa(i)] != "" { + tmp := arg2 + test.VarMap[arg3+strconv.Itoa(i)] + err = test.VARIABLEEquals(arg1+strconv.Itoa(i), tmp) + if err == nil { + test.VarMap[arg3+strconv.Itoa(i)] = "" + } + } + + } + return err +} + +func (test *TestRun) VARIABLEEqualsPlusVAR(arg1, arg2, arg3 string) error { + arg3 = test.VarMap[arg3] + tmp := arg2 + arg3 + err := test.VARIABLEEquals(arg1, tmp) + return err +} + +func (test *TestRun) TheErrorContainsAnd(arg1, arg2 string) error { + var err error + if !strings.Contains(fmt.Sprintf("%s", test.Err), arg1) && strings.Contains(fmt.Sprintf("%s", test.Err), arg2) { + fmt.Println("ERROR!!!") + } + return err +} + +func (test *TestRun) IRunExpectingERROR(arg1 string) error { + var err error + tmp := strings.Split(arg1, " ") + cmd := exec.Command(tmp[0], tmp[1:]...) + output, err := cmd.CombinedOutput() + if err != nil { + if !strings.Contains(fmt.Sprintf("%s", err), "exit") && strings.Contains(fmt.Sprintf("%s", err), "28") { + fmt.Fprintf(os.Stdout, "error: %s", err) + return err + } + } + test.Output = output + test.Err = err + err = nil + return err +} + +func (test *TestRun) IRunVARExpectingERROR(arg1 string) error { + test.IRunExpectingERROR(test.VarMap[arg1]) + return nil +} + +func (test *TestRun) IRunVARExpectingERRORInVARDirectory(arg1, arg2 string) error { + var err error + tmp := strings.Split(arg1, " ") + cmd := exec.Command(tmp[0], tmp[1:]...) + cmd.Dir = arg2 + output, err := cmd.CombinedOutput() + if err != nil { + if !strings.Contains(fmt.Sprintf("%s", err), "exit code") && strings.Contains(fmt.Sprintf("%s", err), "28") { + fmt.Fprintf(os.Stdout, "error: %s", err) + return err + } + } + test.Output = output + test.Err = err + err = nil + return err +} + +func (test *TestRun) theOutputContainsAnd(arg1, arg2 string) error { + if !strings.Contains(fmt.Sprintf("%s", string(test.Output)), arg1) && strings.Contains(fmt.Sprintf("%s", string(test.Output)), arg2) { + return errors.New("Output does not contain expected arguments") + } + return nil +} + +func (test *TestRun) IRunVARSAndCheckForAnd(arg1, arg2, arg3 string) error { + var err error + for i := 0; i < 1000; i++ { + if test.VarMap[arg1+strconv.Itoa(i)] != "" { + err = test.IRunInDirectory(test.VarMap[arg1+strconv.Itoa(i)], ".") + test.theOutputContainsAnd(arg2, arg3) + test.VarMap[arg1+strconv.Itoa(i)] = "" + } + } + return err +} diff --git a/features/data.go b/features/data.go new file mode 100644 index 0000000..a788eb6 --- /dev/null +++ b/features/data.go @@ -0,0 +1,7 @@ +package features + +type TestRun struct { + Output []byte + VarMap map[string]string + Err error +} diff --git a/features/kured.go b/features/kured.go new file mode 100644 index 0000000..42edaa2 --- /dev/null +++ b/features/kured.go @@ -0,0 +1,80 @@ +package features + +import ( + "fmt" + "log" + "os" + "os/exec" + "path/filepath" + "strconv" + "strings" +) + +func (test *TestRun) IRunInDirectory(arg1, arg2 string) error { + var err error + tmp := strings.Split(arg1, " ") + cmd := exec.Command(tmp[0], tmp[1:]...) + cmd.Dir = arg2 + output, err := cmd.CombinedOutput() + if err != nil { + fmt.Fprintf(os.Stdout, "error: %s", err) + return err + } + test.Output = output + test.Err = err + //fmt.Printf("%s", fmt.Sprintf("%s", string(Out1))) + return err +} + +func (test *TestRun) IRunVARSAndIPSFromOutput(arg1 string) error { + var err error + for i := 0; i < 1000; i++ { + if test.VarMap[arg1+strconv.Itoa(i)] != "" { + err = test.IRunInDirectory(test.VarMap[arg1+strconv.Itoa(i)], ".") + tmp1 := strings.Split(fmt.Sprintf("%s", string(test.Output)), "\n") + for _, elem := range tmp1 { + if strings.Contains(elem, "Node:") { + tmp2 := strings.Split(strings.Split(strings.Replace(elem, " ", "", 100), ":")[len(strings.Split(strings.Replace(elem, " ", "", 100), ":"))-1], "/") + if len(tmp2) == 2 { + test.VARIABLEEquals(tmp2[0], tmp2[1]) + } else { + fmt.Printf("Something's wrong with your kubectl describe...\n Is that even the right row? %s\n", elem) + } + break + } + } + test.VarMap[arg1+strconv.Itoa(i)] = "" + } + } + return err +} + +func (test *TestRun) IRunSSHCMDOnMASTER(arg1 string) error { + var ip string + for key, _ := range test.VarMap { + if test.VarMap["master-marked"] == "" { + if strings.Contains(key, "master") /*&& strings.Contains(key, "00")*/ { + ip = test.VarMap[key] + test.VarMap["master-marked"] = ip + } + } else { + ip = test.VarMap["master-marked"] + } + } + dir, _ := os.Getwd() + arg := append( + []string{"-q", "-o", "StrictHostKeyChecking=no", "-o", "UserKnownHostsFile /dev/null", "-i", filepath.Join(dir, "id_shared"), + fmt.Sprintf("sles@%s", ip), + }, + arg1, + ) + cmd := exec.Command("ssh", arg...) + cmd.Env = os.Environ() + output, err := cmd.CombinedOutput() + if err != nil { + log.Printf("Error! %s", err) + } + test.Output = output + //fmt.Printf("%s\n", fmt.Sprintf("%s", string(test.Output))) + return err +} diff --git a/features/utilities.go b/features/utilities.go new file mode 100644 index 0000000..51e8f60 --- /dev/null +++ b/features/utilities.go @@ -0,0 +1,58 @@ +package features + +import ( + "errors" + "fmt" + "strings" +) + +func (test *TestRun) IStartTest() error { + test.Output = []byte{1} + test.VarMap = make(map[string]string) + test.Err = nil + return nil +} + +func (test *TestRun) TheOutputContains(arg string) error { + if !strings.Contains(fmt.Sprintf("%s", string(test.Output)), arg) { + return errors.New("Output does not contain expected argument") + } + return nil +} + +func (test *TestRun) TheOutputContainsAnd(arg1, arg2 string) error { + if !strings.Contains(fmt.Sprintf("%s", string(test.Output)), arg1) && strings.Contains(fmt.Sprintf("%s", string(test.Output)), arg2) { + return errors.New("Output does not contain expected arguments") + } + return nil +} + +func (test *TestRun) TheOutputContainsOr(arg1, arg2 string) error { + if !strings.Contains(fmt.Sprintf("%s", string(test.Output)), arg1) || strings.Contains(fmt.Sprintf("%s", string(test.Output)), arg2) { + return errors.New("Output does not contain expected arguments") + } + return nil +} + +func (test *TestRun) IRunVAR(arg1 string) error { + if test.VarMap["command5"] == "" { + return test.Irun(test.VarMap[arg1]) + } else { + return test.Irun(test.VarMap[arg1]) + } +} + +func (test *TestRun) Irun(command string) error { + return test.IRunInDirectory(command, ".") +} + +func (test *TestRun) GrepFor(arg1 string) error { + var err error + tmp := strings.Split(fmt.Sprintf("%s", string(test.Output)), "\n") + for _, elem := range tmp { + if strings.Contains(strings.ToLower(elem), arg1) { + test.Output = []byte(elem) + } + } + return err +} From 7432b8ed3fac21742726b62b456f7aa9312af784 Mon Sep 17 00:00:00 2001 From: atighineanu Date: Thu, 12 Mar 2020 09:22:29 +0100 Subject: [PATCH 11/50] corrected the xwing check --- features/cilium/cilium-01.feature | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/features/cilium/cilium-01.feature b/features/cilium/cilium-01.feature index ac5d6e1..c38fd09 100644 --- a/features/cilium/cilium-01.feature +++ b/features/cilium/cilium-01.feature @@ -19,15 +19,16 @@ Feature: cilium-basic When I run "kubectl get pods --selector=org=empire" Then the output contains "deathstar" and "tiefighter" When I run "kubectl get pods --selector=org=alliance" + Then the output contains "xwing" Scenario: Check the starwars cilium pods When I run "kubectl get pods" And grep for "xwing" - Then the output contains "running" and "running" + Then the output contains "running" And grep for "deathstar" - Then the output contains "running" and "running" + Then the output contains "running" And grep for "tiefighter" - Then the output contains "running" and "running" + Then the output contains "running" Scenario: Test number1 if empire's ship is allowed into empire space And I run "kubectl exec tiefighter -- curl -sm10 -XPOST deathstar.default.svc.cluster.local/v1/request-landing" From d0ac86d1ae7581a5b4d4dd912fe9c13bea94dfc0 Mon Sep 17 00:00:00 2001 From: atighineanu Date: Thu, 12 Mar 2020 11:21:36 +0100 Subject: [PATCH 12/50] moved .go files inside goscripts folder --- features/{ => goscripts}/cilium.go | 0 features/{ => goscripts}/data.go | 0 features/{ => goscripts}/kured.go | 0 features/{ => goscripts}/utilities.go | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename features/{ => goscripts}/cilium.go (100%) rename features/{ => goscripts}/data.go (100%) rename features/{ => goscripts}/kured.go (100%) rename features/{ => goscripts}/utilities.go (100%) diff --git a/features/cilium.go b/features/goscripts/cilium.go similarity index 100% rename from features/cilium.go rename to features/goscripts/cilium.go diff --git a/features/data.go b/features/goscripts/data.go similarity index 100% rename from features/data.go rename to features/goscripts/data.go diff --git a/features/kured.go b/features/goscripts/kured.go similarity index 100% rename from features/kured.go rename to features/goscripts/kured.go diff --git a/features/utilities.go b/features/goscripts/utilities.go similarity index 100% rename from features/utilities.go rename to features/goscripts/utilities.go From 7825c50be560da9b5b3a2154a7f867e018dd9a11 Mon Sep 17 00:00:00 2001 From: atighineanu Date: Thu, 12 Mar 2020 11:22:31 +0100 Subject: [PATCH 13/50] changed import path for package features --- main_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main_test.go b/main_test.go index 06d8c93..de67034 100644 --- a/main_test.go +++ b/main_test.go @@ -9,7 +9,7 @@ import ( "strings" "time" - . "github.com/fgerling/bdd-poc/features" + . "github.com/fgerling/bdd-poc/features/goscripts" "github.com/cucumber/godog" suse "github.com/fgerling/bdd-poc/internal/suse" From c06e139c5370c848285ada669f1ecf4b14871e97 Mon Sep 17 00:00:00 2001 From: atighineanu Date: Thu, 12 Mar 2020 16:39:49 +0000 Subject: [PATCH 14/50] changed folder of goscripts --- features/goscripts/cilium.go | 153 -------------------------------- features/goscripts/data.go | 7 -- features/goscripts/kured.go | 80 ----------------- features/goscripts/utilities.go | 58 ------------ main_test.go | 4 +- 5 files changed, 3 insertions(+), 299 deletions(-) delete mode 100644 features/goscripts/cilium.go delete mode 100644 features/goscripts/data.go delete mode 100644 features/goscripts/kured.go delete mode 100644 features/goscripts/utilities.go diff --git a/features/goscripts/cilium.go b/features/goscripts/cilium.go deleted file mode 100644 index ee513f1..0000000 --- a/features/goscripts/cilium.go +++ /dev/null @@ -1,153 +0,0 @@ -package features - -import ( - "errors" - "fmt" - "os" - "os/exec" - "strconv" - "strings" -) - -func (test *TestRun) IRunVARInVARDirectory(arg1, arg2 string) error { - arg1 = test.VarMap[arg1] - err := test.IRunInVARDirectory(arg1, arg2) - return err -} - -func (test *TestRun) IRunInVARDirectory(arg1, arg2 string) error { - arg2 = test.VarMap[arg2] - err := test.IRunInDirectory(arg1, arg2) - return err -} - -func (test *TestRun) VARIABLEEqualsContainersFROMOutput(arg1, arg2 string) error { - var err error - tmp := strings.Split(fmt.Sprintf("%s", string(test.Output)), "\n") - for index, elem := range tmp { - if strings.Contains(elem, arg2) && !strings.Contains(elem, "operator") { //--- "operator" is to exclude cilium-operator - tmp2 := strings.Split(elem, " ") - err = test.VARIABLEEquals(arg1+strconv.Itoa(index), tmp2[0]) - } - } - return err -} - -func (test *TestRun) VARIABLEEqualsContainerFROMOutput(arg1, arg2 string) error { - var err error - tmp := strings.Split(fmt.Sprintf("%s", string(test.Output)), "\n") - for _, elem := range tmp { - if strings.Contains(elem, arg2) { - tmp2 := strings.Split(elem, " ") - err = test.VARIABLEEquals(arg1, tmp2[0]) - break - } - } - return err -} - -func (test *TestRun) VARIABLEEquals(arg1, arg2 string) error { - var err error - if test.VarMap == nil { - test.VarMap = make(map[string]string) - } - test.VarMap[arg1] = arg2 - fmt.Printf(" VAR: %s = %s \n", arg1, test.VarMap[arg1]) - return err -} - -func (test *TestRun) VARIABLEEqualsPlusVARPlus(arg1, arg2, arg3, arg4 string) error { - arg3 = test.VarMap[arg3] - tmp := arg2 + arg3 + arg4 - err := test.VARIABLEEquals(arg1, tmp) - return err -} - -func (test *TestRun) VARIABLESEqualsPlusVAR(arg1, arg2, arg3 string) error { - var err error - for i := 0; i < 1000; i++ { - if test.VarMap[arg3+strconv.Itoa(i)] != "" { - tmp := arg2 + test.VarMap[arg3+strconv.Itoa(i)] - err = test.VARIABLEEquals(arg1+strconv.Itoa(i), tmp) - if err == nil { - test.VarMap[arg3+strconv.Itoa(i)] = "" - } - } - - } - return err -} - -func (test *TestRun) VARIABLEEqualsPlusVAR(arg1, arg2, arg3 string) error { - arg3 = test.VarMap[arg3] - tmp := arg2 + arg3 - err := test.VARIABLEEquals(arg1, tmp) - return err -} - -func (test *TestRun) TheErrorContainsAnd(arg1, arg2 string) error { - var err error - if !strings.Contains(fmt.Sprintf("%s", test.Err), arg1) && strings.Contains(fmt.Sprintf("%s", test.Err), arg2) { - fmt.Println("ERROR!!!") - } - return err -} - -func (test *TestRun) IRunExpectingERROR(arg1 string) error { - var err error - tmp := strings.Split(arg1, " ") - cmd := exec.Command(tmp[0], tmp[1:]...) - output, err := cmd.CombinedOutput() - if err != nil { - if !strings.Contains(fmt.Sprintf("%s", err), "exit") && strings.Contains(fmt.Sprintf("%s", err), "28") { - fmt.Fprintf(os.Stdout, "error: %s", err) - return err - } - } - test.Output = output - test.Err = err - err = nil - return err -} - -func (test *TestRun) IRunVARExpectingERROR(arg1 string) error { - test.IRunExpectingERROR(test.VarMap[arg1]) - return nil -} - -func (test *TestRun) IRunVARExpectingERRORInVARDirectory(arg1, arg2 string) error { - var err error - tmp := strings.Split(arg1, " ") - cmd := exec.Command(tmp[0], tmp[1:]...) - cmd.Dir = arg2 - output, err := cmd.CombinedOutput() - if err != nil { - if !strings.Contains(fmt.Sprintf("%s", err), "exit code") && strings.Contains(fmt.Sprintf("%s", err), "28") { - fmt.Fprintf(os.Stdout, "error: %s", err) - return err - } - } - test.Output = output - test.Err = err - err = nil - return err -} - -func (test *TestRun) theOutputContainsAnd(arg1, arg2 string) error { - if !strings.Contains(fmt.Sprintf("%s", string(test.Output)), arg1) && strings.Contains(fmt.Sprintf("%s", string(test.Output)), arg2) { - return errors.New("Output does not contain expected arguments") - } - return nil -} - -func (test *TestRun) IRunVARSAndCheckForAnd(arg1, arg2, arg3 string) error { - var err error - for i := 0; i < 1000; i++ { - if test.VarMap[arg1+strconv.Itoa(i)] != "" { - err = test.IRunInDirectory(test.VarMap[arg1+strconv.Itoa(i)], ".") - test.theOutputContainsAnd(arg2, arg3) - test.VarMap[arg1+strconv.Itoa(i)] = "" - } - } - return err -} diff --git a/features/goscripts/data.go b/features/goscripts/data.go deleted file mode 100644 index a788eb6..0000000 --- a/features/goscripts/data.go +++ /dev/null @@ -1,7 +0,0 @@ -package features - -type TestRun struct { - Output []byte - VarMap map[string]string - Err error -} diff --git a/features/goscripts/kured.go b/features/goscripts/kured.go deleted file mode 100644 index 42edaa2..0000000 --- a/features/goscripts/kured.go +++ /dev/null @@ -1,80 +0,0 @@ -package features - -import ( - "fmt" - "log" - "os" - "os/exec" - "path/filepath" - "strconv" - "strings" -) - -func (test *TestRun) IRunInDirectory(arg1, arg2 string) error { - var err error - tmp := strings.Split(arg1, " ") - cmd := exec.Command(tmp[0], tmp[1:]...) - cmd.Dir = arg2 - output, err := cmd.CombinedOutput() - if err != nil { - fmt.Fprintf(os.Stdout, "error: %s", err) - return err - } - test.Output = output - test.Err = err - //fmt.Printf("%s", fmt.Sprintf("%s", string(Out1))) - return err -} - -func (test *TestRun) IRunVARSAndIPSFromOutput(arg1 string) error { - var err error - for i := 0; i < 1000; i++ { - if test.VarMap[arg1+strconv.Itoa(i)] != "" { - err = test.IRunInDirectory(test.VarMap[arg1+strconv.Itoa(i)], ".") - tmp1 := strings.Split(fmt.Sprintf("%s", string(test.Output)), "\n") - for _, elem := range tmp1 { - if strings.Contains(elem, "Node:") { - tmp2 := strings.Split(strings.Split(strings.Replace(elem, " ", "", 100), ":")[len(strings.Split(strings.Replace(elem, " ", "", 100), ":"))-1], "/") - if len(tmp2) == 2 { - test.VARIABLEEquals(tmp2[0], tmp2[1]) - } else { - fmt.Printf("Something's wrong with your kubectl describe...\n Is that even the right row? %s\n", elem) - } - break - } - } - test.VarMap[arg1+strconv.Itoa(i)] = "" - } - } - return err -} - -func (test *TestRun) IRunSSHCMDOnMASTER(arg1 string) error { - var ip string - for key, _ := range test.VarMap { - if test.VarMap["master-marked"] == "" { - if strings.Contains(key, "master") /*&& strings.Contains(key, "00")*/ { - ip = test.VarMap[key] - test.VarMap["master-marked"] = ip - } - } else { - ip = test.VarMap["master-marked"] - } - } - dir, _ := os.Getwd() - arg := append( - []string{"-q", "-o", "StrictHostKeyChecking=no", "-o", "UserKnownHostsFile /dev/null", "-i", filepath.Join(dir, "id_shared"), - fmt.Sprintf("sles@%s", ip), - }, - arg1, - ) - cmd := exec.Command("ssh", arg...) - cmd.Env = os.Environ() - output, err := cmd.CombinedOutput() - if err != nil { - log.Printf("Error! %s", err) - } - test.Output = output - //fmt.Printf("%s\n", fmt.Sprintf("%s", string(test.Output))) - return err -} diff --git a/features/goscripts/utilities.go b/features/goscripts/utilities.go deleted file mode 100644 index 51e8f60..0000000 --- a/features/goscripts/utilities.go +++ /dev/null @@ -1,58 +0,0 @@ -package features - -import ( - "errors" - "fmt" - "strings" -) - -func (test *TestRun) IStartTest() error { - test.Output = []byte{1} - test.VarMap = make(map[string]string) - test.Err = nil - return nil -} - -func (test *TestRun) TheOutputContains(arg string) error { - if !strings.Contains(fmt.Sprintf("%s", string(test.Output)), arg) { - return errors.New("Output does not contain expected argument") - } - return nil -} - -func (test *TestRun) TheOutputContainsAnd(arg1, arg2 string) error { - if !strings.Contains(fmt.Sprintf("%s", string(test.Output)), arg1) && strings.Contains(fmt.Sprintf("%s", string(test.Output)), arg2) { - return errors.New("Output does not contain expected arguments") - } - return nil -} - -func (test *TestRun) TheOutputContainsOr(arg1, arg2 string) error { - if !strings.Contains(fmt.Sprintf("%s", string(test.Output)), arg1) || strings.Contains(fmt.Sprintf("%s", string(test.Output)), arg2) { - return errors.New("Output does not contain expected arguments") - } - return nil -} - -func (test *TestRun) IRunVAR(arg1 string) error { - if test.VarMap["command5"] == "" { - return test.Irun(test.VarMap[arg1]) - } else { - return test.Irun(test.VarMap[arg1]) - } -} - -func (test *TestRun) Irun(command string) error { - return test.IRunInDirectory(command, ".") -} - -func (test *TestRun) GrepFor(arg1 string) error { - var err error - tmp := strings.Split(fmt.Sprintf("%s", string(test.Output)), "\n") - for _, elem := range tmp { - if strings.Contains(strings.ToLower(elem), arg1) { - test.Output = []byte(elem) - } - } - return err -} diff --git a/main_test.go b/main_test.go index de67034..ee84851 100644 --- a/main_test.go +++ b/main_test.go @@ -9,7 +9,7 @@ import ( "strings" "time" - . "github.com/fgerling/bdd-poc/features/goscripts" + . "github.com/fgerling/bdd-poc/internal" "github.com/cucumber/godog" suse "github.com/fgerling/bdd-poc/internal/suse" @@ -142,4 +142,6 @@ func FeatureContext(s *godog.Suite) { //-------------------Kured-specific test functions------------------------------------------------- s.Step(`^I run VARS:"([^"]*)" and IPSFromOutput$`, test.IRunVARSAndIPSFromOutput) s.Step(`^I run SSHCMD "([^"]*)" on MASTER$`, test.IRunSSHCMDOnMASTER) + //-------------------Skuba Upgrade - specific test fuctions---------------------------------------- + s.Step(`^I run skuba upgrade plan in VAR:"([^"]*)" directory$`, test.IRunSkubaUpgradePlanFirstMasterInVARDirectory) } From aac533940bb1f38bd57a25e29c10e5d296f7bd1f Mon Sep 17 00:00:00 2001 From: atighineanu Date: Thu, 12 Mar 2020 16:40:24 +0000 Subject: [PATCH 15/50] moved all go scripts --- internal/cilium.go | 145 ++++++++++++++++++++++++++++++++++++++ internal/data.go | 8 +++ internal/kured.go | 80 +++++++++++++++++++++ internal/skuba_upgrade.go | 25 +++++++ internal/utilities.go | 58 +++++++++++++++ 5 files changed, 316 insertions(+) create mode 100644 internal/cilium.go create mode 100644 internal/data.go create mode 100644 internal/kured.go create mode 100644 internal/skuba_upgrade.go create mode 100644 internal/utilities.go diff --git a/internal/cilium.go b/internal/cilium.go new file mode 100644 index 0000000..ea3f862 --- /dev/null +++ b/internal/cilium.go @@ -0,0 +1,145 @@ +package features + +import ( + "fmt" + "os" + "os/exec" + "strconv" + "strings" +) + +func (test *TestRun) IRunVARInVARDirectory(arg1, arg2 string) error { + arg1 = test.VarMap[arg1] + err := test.IRunInVARDirectory(arg1, arg2) + return err +} + +func (test *TestRun) IRunInVARDirectory(arg1, arg2 string) error { + arg2 = test.VarMap[arg2] + err := test.IRunInDirectory(arg1, arg2) + return err +} + +func (test *TestRun) VARIABLEEqualsContainersFROMOutput(arg1, arg2 string) error { + var err error + tmp := strings.Split(fmt.Sprintf("%s", string(test.Output)), "\n") + for index, elem := range tmp { + if strings.Contains(elem, arg2) && !strings.Contains(elem, "operator") { //--- "operator" is to exclude cilium-operator + tmp2 := strings.Split(elem, " ") + err = test.VARIABLEEquals(arg1+strconv.Itoa(index), tmp2[0]) + } + } + return err +} + +func (test *TestRun) VARIABLEEqualsContainerFROMOutput(arg1, arg2 string) error { + var err error + tmp := strings.Split(fmt.Sprintf("%s", string(test.Output)), "\n") + for _, elem := range tmp { + if strings.Contains(elem, arg2) { + tmp2 := strings.Split(elem, " ") + err = test.VARIABLEEquals(arg1, tmp2[0]) + break + } + } + return err +} + +func (test *TestRun) VARIABLEEquals(arg1, arg2 string) error { + var err error + if test.VarMap == nil { + test.VarMap = make(map[string]string) + } + test.VarMap[arg1] = arg2 + fmt.Printf(" VAR: %s = %s \n", arg1, test.VarMap[arg1]) + return err +} + +func (test *TestRun) VARIABLEEqualsPlusVARPlus(arg1, arg2, arg3, arg4 string) error { + arg3 = test.VarMap[arg3] + tmp := arg2 + arg3 + arg4 + err := test.VARIABLEEquals(arg1, tmp) + return err +} + +func (test *TestRun) VARIABLESEqualsPlusVAR(arg1, arg2, arg3 string) error { + var err error + for i := 0; i < 1000; i++ { + if test.VarMap[arg3+strconv.Itoa(i)] != "" { + tmp := arg2 + test.VarMap[arg3+strconv.Itoa(i)] + err = test.VARIABLEEquals(arg1+strconv.Itoa(i), tmp) + if err == nil { + test.VarMap[arg3+strconv.Itoa(i)] = "" + } + } + + } + return err +} + +func (test *TestRun) VARIABLEEqualsPlusVAR(arg1, arg2, arg3 string) error { + arg3 = test.VarMap[arg3] + tmp := arg2 + arg3 + err := test.VARIABLEEquals(arg1, tmp) + return err +} + +func (test *TestRun) TheErrorContainsAnd(arg1, arg2 string) error { + var err error + if !strings.Contains(fmt.Sprintf("%s", test.Err), arg1) && strings.Contains(fmt.Sprintf("%s", test.Err), arg2) { + fmt.Println("ERROR!!!") + } + return err +} + +func (test *TestRun) IRunExpectingERROR(arg1 string) error { + var err error + tmp := strings.Split(arg1, " ") + cmd := exec.Command(tmp[0], tmp[1:]...) + output, err := cmd.CombinedOutput() + if err != nil { + if !strings.Contains(fmt.Sprintf("%s", err), "exit") && strings.Contains(fmt.Sprintf("%s", err), "28") { + fmt.Fprintf(os.Stdout, "error: %s", err) + return err + } + } + test.Output = output + test.Err = err + err = nil + return err +} + +func (test *TestRun) IRunVARExpectingERROR(arg1 string) error { + test.IRunExpectingERROR(test.VarMap[arg1]) + return nil +} + +func (test *TestRun) IRunVARExpectingERRORInVARDirectory(arg1, arg2 string) error { + var err error + tmp := strings.Split(arg1, " ") + cmd := exec.Command(tmp[0], tmp[1:]...) + cmd.Dir = arg2 + output, err := cmd.CombinedOutput() + if err != nil { + if !strings.Contains(fmt.Sprintf("%s", err), "exit code") && strings.Contains(fmt.Sprintf("%s", err), "28") { + fmt.Fprintf(os.Stdout, "error: %s", err) + return err + } + } + test.Output = output + test.Err = err + err = nil + return err +} + +func (test *TestRun) IRunVARSAndCheckForAnd(arg1, arg2, arg3 string) error { + var err error + for i := 0; i < 1000; i++ { + if test.VarMap[arg1+strconv.Itoa(i)] != "" { + err = test.IRunInDirectory(test.VarMap[arg1+strconv.Itoa(i)], ".") + test.TheOutputContainsAnd(arg2, arg3) + test.VarMap[arg1+strconv.Itoa(i)] = "" + } + } + return err +} diff --git a/internal/data.go b/internal/data.go new file mode 100644 index 0000000..4df8d5b --- /dev/null +++ b/internal/data.go @@ -0,0 +1,8 @@ +package features + +type TestRun struct { + Output []byte + VarMap map[string]string + UpgradeCheck map[string]bool + Err error +} diff --git a/internal/kured.go b/internal/kured.go new file mode 100644 index 0000000..42edaa2 --- /dev/null +++ b/internal/kured.go @@ -0,0 +1,80 @@ +package features + +import ( + "fmt" + "log" + "os" + "os/exec" + "path/filepath" + "strconv" + "strings" +) + +func (test *TestRun) IRunInDirectory(arg1, arg2 string) error { + var err error + tmp := strings.Split(arg1, " ") + cmd := exec.Command(tmp[0], tmp[1:]...) + cmd.Dir = arg2 + output, err := cmd.CombinedOutput() + if err != nil { + fmt.Fprintf(os.Stdout, "error: %s", err) + return err + } + test.Output = output + test.Err = err + //fmt.Printf("%s", fmt.Sprintf("%s", string(Out1))) + return err +} + +func (test *TestRun) IRunVARSAndIPSFromOutput(arg1 string) error { + var err error + for i := 0; i < 1000; i++ { + if test.VarMap[arg1+strconv.Itoa(i)] != "" { + err = test.IRunInDirectory(test.VarMap[arg1+strconv.Itoa(i)], ".") + tmp1 := strings.Split(fmt.Sprintf("%s", string(test.Output)), "\n") + for _, elem := range tmp1 { + if strings.Contains(elem, "Node:") { + tmp2 := strings.Split(strings.Split(strings.Replace(elem, " ", "", 100), ":")[len(strings.Split(strings.Replace(elem, " ", "", 100), ":"))-1], "/") + if len(tmp2) == 2 { + test.VARIABLEEquals(tmp2[0], tmp2[1]) + } else { + fmt.Printf("Something's wrong with your kubectl describe...\n Is that even the right row? %s\n", elem) + } + break + } + } + test.VarMap[arg1+strconv.Itoa(i)] = "" + } + } + return err +} + +func (test *TestRun) IRunSSHCMDOnMASTER(arg1 string) error { + var ip string + for key, _ := range test.VarMap { + if test.VarMap["master-marked"] == "" { + if strings.Contains(key, "master") /*&& strings.Contains(key, "00")*/ { + ip = test.VarMap[key] + test.VarMap["master-marked"] = ip + } + } else { + ip = test.VarMap["master-marked"] + } + } + dir, _ := os.Getwd() + arg := append( + []string{"-q", "-o", "StrictHostKeyChecking=no", "-o", "UserKnownHostsFile /dev/null", "-i", filepath.Join(dir, "id_shared"), + fmt.Sprintf("sles@%s", ip), + }, + arg1, + ) + cmd := exec.Command("ssh", arg...) + cmd.Env = os.Environ() + output, err := cmd.CombinedOutput() + if err != nil { + log.Printf("Error! %s", err) + } + test.Output = output + //fmt.Printf("%s\n", fmt.Sprintf("%s", string(test.Output))) + return err +} diff --git a/internal/skuba_upgrade.go b/internal/skuba_upgrade.go new file mode 100644 index 0000000..e272d74 --- /dev/null +++ b/internal/skuba_upgrade.go @@ -0,0 +1,25 @@ +package features + +import ( + "fmt" + "os" + "os/exec" + "strings" +) + +func (test *TestRun) IRunSkubaUpgradePlanFirstMasterInVARDirectory(arg1 string) error { + var firstmaster string + for key, _ := range test.VarMap { + if strings.Contains(key, "master") && strings.Contains(key, "00") { + firstmaster = key + } + } + cmd := []string{"skuba", "upgrade", "plan", firstmaster} + output, err := exec.Command(cmd[0], cmd[1:]...).CombinedOutput() + if err != nil { + test.Err = err + fmt.Fprintf(os.Stdout, "error: %v", err) + } + test.Output = output + return nil +} diff --git a/internal/utilities.go b/internal/utilities.go new file mode 100644 index 0000000..c4a20eb --- /dev/null +++ b/internal/utilities.go @@ -0,0 +1,58 @@ +package features + +import ( + "errors" + "fmt" + "strings" +) + +func (test *TestRun) IStartTest() error { + test.Output = []byte{1} + test.VarMap = make(map[string]string) + test.Err = nil + return nil +} + +func (test *TestRun) TheOutputContains(arg string) error { + if !strings.Contains(strings.ToLower(fmt.Sprintf("%s", string(test.Output))), arg) { + return errors.New("Output does not contain expected argument") + } + return nil +} + +func (test *TestRun) TheOutputContainsAnd(arg1, arg2 string) error { + if !strings.Contains(strings.ToLower(fmt.Sprintf("%s", string(test.Output))), arg1) && strings.Contains(strings.ToLower(fmt.Sprintf("%s", string(test.Output))), arg2) { + return errors.New("Output does not contain expected arguments") + } + return nil +} + +func (test *TestRun) TheOutputContainsOr(arg1, arg2 string) error { + if !strings.Contains(strings.ToLower(fmt.Sprintf("%s", string(test.Output))), arg1) || strings.Contains(strings.ToLower(fmt.Sprintf("%s", string(test.Output))), arg2) { + return errors.New("Output does not contain expected arguments") + } + return nil +} + +func (test *TestRun) IRunVAR(arg1 string) error { + if test.VarMap["command5"] == "" { + return test.Irun(test.VarMap[arg1]) + } else { + return test.Irun(test.VarMap[arg1]) + } +} + +func (test *TestRun) Irun(command string) error { + return test.IRunInDirectory(command, ".") +} + +func (test *TestRun) GrepFor(arg1 string) error { + var err error + tmp := strings.Split(fmt.Sprintf("%s", string(test.Output)), "\n") + for _, elem := range tmp { + if strings.Contains(strings.ToLower(elem), arg1) { + test.Output = []byte(elem) + } + } + return err +} From 7cfc2301e279d415895fc6a6b119f35379d324da Mon Sep 17 00:00:00 2001 From: atighineanu Date: Thu, 19 Mar 2020 13:38:01 +0100 Subject: [PATCH 16/50] added skuba upgrade tests --- internal/data.go | 8 +++++- internal/kured.go | 1 + internal/skuba_upgrade.go | 52 ++++++++++++++++++++++++++++++--------- internal/utilities.go | 7 ++++++ main_test.go | 5 +++- 5 files changed, 59 insertions(+), 14 deletions(-) diff --git a/internal/data.go b/internal/data.go index 4df8d5b..8ec57b7 100644 --- a/internal/data.go +++ b/internal/data.go @@ -3,6 +3,12 @@ package features type TestRun struct { Output []byte VarMap map[string]string - UpgradeCheck map[string]bool + UpgradeCheck map[string]NodeCheck Err error } + +type NodeCheck struct { + PlanDone bool + UPDone bool + IP string +} diff --git a/internal/kured.go b/internal/kured.go index 42edaa2..4fc2459 100644 --- a/internal/kured.go +++ b/internal/kured.go @@ -15,6 +15,7 @@ func (test *TestRun) IRunInDirectory(arg1, arg2 string) error { tmp := strings.Split(arg1, " ") cmd := exec.Command(tmp[0], tmp[1:]...) cmd.Dir = arg2 + //fmt.Printf("RUN: %s in %s\n", arg1, arg2) output, err := cmd.CombinedOutput() if err != nil { fmt.Fprintf(os.Stdout, "error: %s", err) diff --git a/internal/skuba_upgrade.go b/internal/skuba_upgrade.go index e272d74..c58cdb9 100644 --- a/internal/skuba_upgrade.go +++ b/internal/skuba_upgrade.go @@ -2,24 +2,52 @@ package features import ( "fmt" - "os" - "os/exec" "strings" ) -func (test *TestRun) IRunSkubaUpgradePlanFirstMasterInVARDirectory(arg1 string) error { - var firstmaster string +func (test *TestRun) VARIABLESEqualsPlusMasterNodes(arg1, arg2 string) error { + var temp1 NodeCheck + if test.UpgradeCheck == nil { + test.UpgradeCheck = make(map[string]NodeCheck) + } + for key, _ := range test.VarMap { + if strings.Contains(key, "master") && !strings.Contains(key, arg1) && test.UpgradeCheck[key].IP == "" { + test.VarMap[arg1+key] = arg2 + key + fmt.Printf("VAR: %s = %s\n", arg1+key, arg2+key) + temp1.IP = test.VarMap[key] + temp1.PlanDone = false + temp1.UPDone = false + test.UpgradeCheck[key] = temp1 + } + } + return nil +} + +func (test *TestRun) VARIABLESEqualsPlusMasterNodeIPS(arg1, arg2 string) error { for key, _ := range test.VarMap { - if strings.Contains(key, "master") && strings.Contains(key, "00") { - firstmaster = key + if strings.Contains(key, "master") && !strings.Contains(test.VarMap[key], "plan") && !strings.Contains(key, arg1) { + test.VarMap[arg1+key] = arg2 + test.UpgradeCheck[key].IP + fmt.Printf("VAR: %s = %s\n", arg1+key, test.VarMap[arg1+key]) } } - cmd := []string{"skuba", "upgrade", "plan", firstmaster} - output, err := exec.Command(cmd[0], cmd[1:]...).CombinedOutput() - if err != nil { - test.Err = err - fmt.Fprintf(os.Stdout, "error: %v", err) + return nil +} + +func (test *TestRun) IRunUPGRADEVARSInVARDirectory(arg1, arg2 string) error { + for key, _ := range test.VarMap { + if strings.Contains(key, arg1) && test.UpgradeCheck[key].PlanDone == false { + //fmt.Printf("Command we run: %s\n", test.VarMap[key]) + test.Output = []byte{1} + test.IRunInDirectory(test.VarMap[key], test.VarMap[arg2]) + temp1 := test.UpgradeCheck[key] + temp1.PlanDone = true + if strings.Contains(test.VarMap[key], "apply") { + temp1.UPDone = true + } + test.UpgradeCheck[key] = temp1 + fmt.Println(fmt.Sprintf("%s", string(test.Output))) + break + } } - test.Output = output return nil } diff --git a/internal/utilities.go b/internal/utilities.go index c4a20eb..c5f6697 100644 --- a/internal/utilities.go +++ b/internal/utilities.go @@ -27,6 +27,13 @@ func (test *TestRun) TheOutputContainsAnd(arg1, arg2 string) error { return nil } +func (test *TestRun) TheOutputContainsAndAnd(arg1, arg2, arg3 string) error { + if !strings.Contains(strings.ToLower(fmt.Sprintf("%s", string(test.Output))), arg1) && strings.Contains(strings.ToLower(fmt.Sprintf("%s", string(test.Output))), arg2) && strings.Contains(strings.ToLower(fmt.Sprintf("%s", string(test.Output))), arg3) { + return errors.New("Output does not contain expected arguments") + } + return nil +} + func (test *TestRun) TheOutputContainsOr(arg1, arg2 string) error { if !strings.Contains(strings.ToLower(fmt.Sprintf("%s", string(test.Output))), arg1) || strings.Contains(strings.ToLower(fmt.Sprintf("%s", string(test.Output))), arg2) { return errors.New("Output does not contain expected arguments") diff --git a/main_test.go b/main_test.go index ee84851..ed9b6c3 100644 --- a/main_test.go +++ b/main_test.go @@ -115,6 +115,7 @@ func FeatureContext(s *godog.Suite) { s.Step(`^the "([^"]*)" repository exist$`, theRepositoryExist) s.Step(`^the directory "([^"]*)" exist$`, theDirectoryExist) s.Step(`^the file "([^"]*)" exist$`, theFileExist) + s.Step(`^the output contains "([^"]*)" and "([^"]*)" and "([^"]*)"$`, test.TheOutputContainsAndAnd) s.Step(`^the output contains "([^"]*)" and "([^"]*)"$`, test.TheOutputContainsAnd) s.Step(`^the output contains "([^"]*)" or "([^"]*)"$`, test.TheOutputContainsOr) s.Step(`^there is "([^"]*)" directory$`, theDirectoryExist) @@ -143,5 +144,7 @@ func FeatureContext(s *godog.Suite) { s.Step(`^I run VARS:"([^"]*)" and IPSFromOutput$`, test.IRunVARSAndIPSFromOutput) s.Step(`^I run SSHCMD "([^"]*)" on MASTER$`, test.IRunSSHCMDOnMASTER) //-------------------Skuba Upgrade - specific test fuctions---------------------------------------- - s.Step(`^I run skuba upgrade plan in VAR:"([^"]*)" directory$`, test.IRunSkubaUpgradePlanFirstMasterInVARDirectory) + s.Step(`^I run UPGRADE VARS:"([^"]*)" in VAR:"([^"]*)" directory$`, test.IRunUPGRADEVARSInVARDirectory) + s.Step(`^VARIABLES "([^"]*)" equals "([^"]*)" plus Master Nodes$`, test.VARIABLESEqualsPlusMasterNodes) + s.Step(`^VARIABLES "([^"]*)" equals "([^"]*)" plus Master Node IPS$`, test.VARIABLESEqualsPlusMasterNodeIPS) } From ee632c925428a08c147c8da61a085c8952ecfee6 Mon Sep 17 00:00:00 2001 From: atighineanu Date: Thu, 19 Mar 2020 13:40:55 +0100 Subject: [PATCH 17/50] skuba upgrade and status features --- .../skuba_upgrade/skuba_upgrade-01.feature | 55 +++++++++++++++++++ features/status.feature | 10 ++++ 2 files changed, 65 insertions(+) create mode 100644 features/skuba_upgrade/skuba_upgrade-01.feature create mode 100644 features/status.feature diff --git a/features/skuba_upgrade/skuba_upgrade-01.feature b/features/skuba_upgrade/skuba_upgrade-01.feature new file mode 100644 index 0000000..6fa344b --- /dev/null +++ b/features/skuba_upgrade/skuba_upgrade-01.feature @@ -0,0 +1,55 @@ +# TC: https://github.com/fgerling/bdd-poc +# PR: https://github.com/SUSE/skuba/pull/911 +# FEATURE: skuba cluster upgrade + +# You are expected to run this test on a cluster bootstrapped with kubernetes-1.15.2 +Feature: Check if cluster upgrade is fine + +Scenario: Checking if cluster exists + Given "skuba" exist in gopath + And VARIABLE "imba-cluster" equals "/root/go/src/github.com/fgerling/bdd-poc/imba-cluster" + When I run "skuba cluster status" in VAR:"imba-cluster" directory + Then the output contains "master" and "worker" + Then the output contains "1.15.2" + When I run "kubectl get all --namespace=kube-system" + Then the output contains "cilium" and "dex" + When I run "skuba version" + Then the output contains "v1.2.6" or "v1.2.7" + + When I run "skuba cluster upgrade plan" in VAR:"imba-cluster" directory + Then the output contains "current kubernetes" and "latest kubernetes" + #Then the output contains "upgrade path to update" + #Then the output contains "addon upgrades from" + + When I run "skuba addon upgrade apply" + Then the output contains "congratulations" + +Scenario: Applying upgrade on nodes + When I run "kubectl get pods --namespace=kube-system" + And VARIABLE "imba-cluster" equals "/root/go/src/github.com/fgerling/bdd-poc/imba-cluster" + When VARIABLE "privileged-pods" equals ContainersFROMOutput "kured-" + And VARIABLES "commandchecks" equals "kubectl describe pod -n kube-system " plus VAR:"privileged-pods" + And I run VARS:"commandchecks" and IPSFromOutput + + #UPGRADING MASTERS FIRST + When VARIABLES "commandupgrades" equals "skuba node upgrade plan " plus Master Nodes + And I run UPGRADE VARS:"commandupgrades" in VAR:"imba-cluster" directory + Then the output contains "apiserver" and "controller-manager" and "scheduler" + And the output contains "etcd" and "kubelet" and "cri-o" + And I run UPGRADE VARS:"commandupgrades" in VAR:"imba-cluster" directory + Then the output contains "apiserver" and "controller-manager" and "scheduler" + And the output contains "etcd" and "kubelet" and "cri-o" + And I run UPGRADE VARS:"commandupgrades" in VAR:"imba-cluster" directory + Then the output contains "apiserver" and "controller-manager" and "scheduler" + And the output contains "etcd" and "kubelet" and "cri-o" + + When VARIABLES "upgradeapply" equals "skuba node upgrade apply --user sles --target " plus Master Node IPS + And I run UPGRADE VARS:"upgradeapply" in VAR:"imba-cluster" directory + Then the output contains "successfully" or "to date" + And I run UPGRADE VARS:"upgradeapply" in VAR:"imba-cluster" directory + Then the output contains "successfully" or "to date" + And I run UPGRADE VARS:"upgradeapply" in VAR:"imba-cluster" directory + Then the output contains "successfully" or "to date" + + + diff --git a/features/status.feature b/features/status.feature new file mode 100644 index 0000000..b34ef3e --- /dev/null +++ b/features/status.feature @@ -0,0 +1,10 @@ +# doc: https://github.com/SUSE/skuba/blob/master/README.md + +Feature: Skuba cluster status + + Scenario: checkout cluster status + Given there is "imba-cluster" directory + And "skuba" exist in gopath + When I run "skuba cluster status" in "imba-cluster" directory + Then the output contains "master" + And the output contains "worker" \ No newline at end of file From 33ece156f07801a70b0f97d288f35c4fbf0d4c3e Mon Sep 17 00:00:00 2001 From: atighineanu Date: Thu, 19 Mar 2020 13:18:21 +0000 Subject: [PATCH 18/50] grinded skuba upgrade (not finished) --- features/skuba_upgrade/skuba_upgrade-01.feature | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/features/skuba_upgrade/skuba_upgrade-01.feature b/features/skuba_upgrade/skuba_upgrade-01.feature index 6fa344b..634a389 100644 --- a/features/skuba_upgrade/skuba_upgrade-01.feature +++ b/features/skuba_upgrade/skuba_upgrade-01.feature @@ -21,7 +21,7 @@ Scenario: Checking if cluster exists #Then the output contains "upgrade path to update" #Then the output contains "addon upgrades from" - When I run "skuba addon upgrade apply" + When I run "skuba addon upgrade apply" in VAR:"imba-cluster" directory Then the output contains "congratulations" Scenario: Applying upgrade on nodes @@ -43,13 +43,18 @@ Scenario: Applying upgrade on nodes Then the output contains "apiserver" and "controller-manager" and "scheduler" And the output contains "etcd" and "kubelet" and "cri-o" - When VARIABLES "upgradeapply" equals "skuba node upgrade apply --user sles --target " plus Master Node IPS + When VARIABLES "upgradeapply" equals "skuba node upgrade apply --user sles --sudo --target " plus Master Node IPS And I run UPGRADE VARS:"upgradeapply" in VAR:"imba-cluster" directory Then the output contains "successfully" or "to date" + And I wait "30 seconds" And I run UPGRADE VARS:"upgradeapply" in VAR:"imba-cluster" directory Then the output contains "successfully" or "to date" + And I wait "30 seconds" And I run UPGRADE VARS:"upgradeapply" in VAR:"imba-cluster" directory Then the output contains "successfully" or "to date" - - - + And I wait "30 seconds" + + When VARIABLES "upgradeapply2" equals "skuba node upgrade apply --user sles --sudo --target " plus Worker Node IPS + And I run UPGRADE VARS:"upgradeapply2" in VAR:"imba-cluster" directory + And I wait "30 seconds" + Then the output contains "successfully" or "to date" From 29e655aeb89722574b64f8dc9f925a9bddecb775 Mon Sep 17 00:00:00 2001 From: atighineanu Date: Thu, 19 Mar 2020 18:08:15 +0100 Subject: [PATCH 19/50] added two skuba upgrade functions --- main_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/main_test.go b/main_test.go index ed9b6c3..9791400 100644 --- a/main_test.go +++ b/main_test.go @@ -146,5 +146,7 @@ func FeatureContext(s *godog.Suite) { //-------------------Skuba Upgrade - specific test fuctions---------------------------------------- s.Step(`^I run UPGRADE VARS:"([^"]*)" in VAR:"([^"]*)" directory$`, test.IRunUPGRADEVARSInVARDirectory) s.Step(`^VARIABLES "([^"]*)" equals "([^"]*)" plus Master Nodes$`, test.VARIABLESEqualsPlusMasterNodes) + s.Step(`^VARIABLES "([^"]*)" equals "([^"]*)" plus Worker Nodes$`, test.VARIABLESEqualsPlusWorkerNodes) s.Step(`^VARIABLES "([^"]*)" equals "([^"]*)" plus Master Node IPS$`, test.VARIABLESEqualsPlusMasterNodeIPS) + s.Step(`^VARIABLES "([^"]*)" equals "([^"]*)" plus Worker Node IPS$`, test.VARIABLESEqualsPlusWorkerNodeIPS) } From 177af80c7ee3adcfdaaa0b0b05028721d10f356d Mon Sep 17 00:00:00 2001 From: atighineanu Date: Thu, 19 Mar 2020 18:08:36 +0100 Subject: [PATCH 20/50] fixe IruninDir --- internal/kured.go | 1 - 1 file changed, 1 deletion(-) diff --git a/internal/kured.go b/internal/kured.go index 4fc2459..5da7147 100644 --- a/internal/kured.go +++ b/internal/kured.go @@ -19,7 +19,6 @@ func (test *TestRun) IRunInDirectory(arg1, arg2 string) error { output, err := cmd.CombinedOutput() if err != nil { fmt.Fprintf(os.Stdout, "error: %s", err) - return err } test.Output = output test.Err = err From 89188b377d9db094664fce69e77c9a1aa0cfe239 Mon Sep 17 00:00:00 2001 From: atighineanu Date: Thu, 19 Mar 2020 18:08:49 +0100 Subject: [PATCH 21/50] added functions to check worker nodes --- internal/skuba_upgrade.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/internal/skuba_upgrade.go b/internal/skuba_upgrade.go index c58cdb9..a7d6ddf 100644 --- a/internal/skuba_upgrade.go +++ b/internal/skuba_upgrade.go @@ -23,6 +23,24 @@ func (test *TestRun) VARIABLESEqualsPlusMasterNodes(arg1, arg2 string) error { return nil } +func (test *TestRun) VARIABLESEqualsPlusWorkerNodes(arg1, arg2 string) error { + var temp1 NodeCheck + if test.UpgradeCheck == nil { + test.UpgradeCheck = make(map[string]NodeCheck) + } + for key, _ := range test.VarMap { + if strings.Contains(key, "worker") && !strings.Contains(key, arg1) && test.UpgradeCheck[key].IP == "" { + test.VarMap[arg1+key] = arg2 + key + fmt.Printf("VAR: %s = %s\n", arg1+key, arg2+key) + temp1.IP = test.VarMap[key] + temp1.PlanDone = false + temp1.UPDone = false + test.UpgradeCheck[key] = temp1 + } + } + return nil +} + func (test *TestRun) VARIABLESEqualsPlusMasterNodeIPS(arg1, arg2 string) error { for key, _ := range test.VarMap { if strings.Contains(key, "master") && !strings.Contains(test.VarMap[key], "plan") && !strings.Contains(key, arg1) { @@ -33,6 +51,16 @@ func (test *TestRun) VARIABLESEqualsPlusMasterNodeIPS(arg1, arg2 string) error { return nil } +func (test *TestRun) VARIABLESEqualsPlusWorkerNodeIPS(arg1, arg2 string) error { + for key, _ := range test.VarMap { + if strings.Contains(key, "worker") && !strings.Contains(test.VarMap[key], "plan") && !strings.Contains(key, arg1) { + test.VarMap[arg1+key] = arg2 + test.UpgradeCheck[key].IP + fmt.Printf("VAR: %s = %s\n", arg1+key, test.VarMap[arg1+key]) + } + } + return nil +} + func (test *TestRun) IRunUPGRADEVARSInVARDirectory(arg1, arg2 string) error { for key, _ := range test.VarMap { if strings.Contains(key, arg1) && test.UpgradeCheck[key].PlanDone == false { From c3d3e1a97a907a68375ec80dbc9a85fcb854952f Mon Sep 17 00:00:00 2001 From: atighineanu Date: Thu, 19 Mar 2020 18:09:08 +0100 Subject: [PATCH 22/50] fixed output contains A or B function --- internal/utilities.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/internal/utilities.go b/internal/utilities.go index c5f6697..82e912b 100644 --- a/internal/utilities.go +++ b/internal/utilities.go @@ -35,7 +35,9 @@ func (test *TestRun) TheOutputContainsAndAnd(arg1, arg2, arg3 string) error { } func (test *TestRun) TheOutputContainsOr(arg1, arg2 string) error { - if !strings.Contains(strings.ToLower(fmt.Sprintf("%s", string(test.Output))), arg1) || strings.Contains(strings.ToLower(fmt.Sprintf("%s", string(test.Output))), arg2) { + //fmt.Printf("text:\n%s\nvars: %s %s\n ", strings.ToLower(fmt.Sprintf("%s", string(test.Output))), arg1, arg2) + if strings.Contains(strings.ToLower(fmt.Sprintf("%s", string(test.Output))), arg1) || strings.Contains(strings.ToLower(fmt.Sprintf("%s", string(test.Output))), arg2) { + } else { return errors.New("Output does not contain expected arguments") } return nil From 069b4bf666abe56bedc6e58d09723e28f5825982 Mon Sep 17 00:00:00 2001 From: atighineanu Date: Thu, 19 Mar 2020 18:10:03 +0100 Subject: [PATCH 23/50] finished implementation for skuba_upgrade --- .../skuba_upgrade/skuba_upgrade-01.feature | 35 ++++++++++++++++--- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/features/skuba_upgrade/skuba_upgrade-01.feature b/features/skuba_upgrade/skuba_upgrade-01.feature index 6fa344b..ee7dd02 100644 --- a/features/skuba_upgrade/skuba_upgrade-01.feature +++ b/features/skuba_upgrade/skuba_upgrade-01.feature @@ -7,7 +7,7 @@ Feature: Check if cluster upgrade is fine Scenario: Checking if cluster exists Given "skuba" exist in gopath - And VARIABLE "imba-cluster" equals "/root/go/src/github.com/fgerling/bdd-poc/imba-cluster" + And VARIABLE "imba-cluster" equals "/Users/alexeitighineanu/go/src/github.com/fgerling/bdd-poc/imba-cluster" When I run "skuba cluster status" in VAR:"imba-cluster" directory Then the output contains "master" and "worker" Then the output contains "1.15.2" @@ -21,12 +21,12 @@ Scenario: Checking if cluster exists #Then the output contains "upgrade path to update" #Then the output contains "addon upgrades from" - When I run "skuba addon upgrade apply" + When I run "skuba addon upgrade apply" in VAR:"imba-cluster" directory Then the output contains "congratulations" Scenario: Applying upgrade on nodes When I run "kubectl get pods --namespace=kube-system" - And VARIABLE "imba-cluster" equals "/root/go/src/github.com/fgerling/bdd-poc/imba-cluster" + And VARIABLE "imba-cluster" equals "/Users/alexeitighineanu/go/src/github.com/fgerling/bdd-poc/imba-cluster" When VARIABLE "privileged-pods" equals ContainersFROMOutput "kured-" And VARIABLES "commandchecks" equals "kubectl describe pod -n kube-system " plus VAR:"privileged-pods" And I run VARS:"commandchecks" and IPSFromOutput @@ -43,13 +43,40 @@ Scenario: Applying upgrade on nodes Then the output contains "apiserver" and "controller-manager" and "scheduler" And the output contains "etcd" and "kubelet" and "cri-o" - When VARIABLES "upgradeapply" equals "skuba node upgrade apply --user sles --target " plus Master Node IPS + When VARIABLES "upgradeapply" equals "skuba node upgrade apply --user sles --sudo --target " plus Master Node IPS And I run UPGRADE VARS:"upgradeapply" in VAR:"imba-cluster" directory Then the output contains "successfully" or "to date" + And wait "30 seconds" And I run UPGRADE VARS:"upgradeapply" in VAR:"imba-cluster" directory Then the output contains "successfully" or "to date" + And wait "30 seconds" And I run UPGRADE VARS:"upgradeapply" in VAR:"imba-cluster" directory Then the output contains "successfully" or "to date" + And wait "30 seconds" + +# UPGRADING THEN WORKERS + When VARIABLES "commandupgrades2" equals "skuba node upgrade plan " plus Worker Nodes + And I run UPGRADE VARS:"commandupgrades2" in VAR:"imba-cluster" directory + Then the output contains "kubelet" and "cri-o" + And I run UPGRADE VARS:"commandupgrades2" in VAR:"imba-cluster" directory + Then the output contains "kubelet" and "cri-o" + + When VARIABLES "upgradeapply2" equals "skuba node upgrade apply --user sles --sudo --target " plus Worker Node IPS + And I run UPGRADE VARS:"upgradeapply2" in VAR:"imba-cluster" directory + Then the output contains "successfully" or "to date" + + When I run "skuba addon upgrade apply" in VAR:"imba-cluster" directory + Then the output contains "not all nodes" + + When VARIABLES "upgradeapply2" equals "skuba node upgrade apply --user sles --sudo --target " plus Worker Node IPS + And I run UPGRADE VARS:"upgradeapply2" in VAR:"imba-cluster" directory + Then the output contains "successfully" or "to date" + + When I run "skuba addon upgrade apply" in VAR:"imba-cluster" directory + Then the output contains "successfully" or "congratulations" + + + From bba92a4e932c8ca182ec5f90678e9a07ac5a45e0 Mon Sep 17 00:00:00 2001 From: atighineanu Date: Thu, 19 Mar 2020 18:17:52 +0100 Subject: [PATCH 24/50] rebased skuba_upgrade-01 --- .../skuba_upgrade/skuba_upgrade-01.feature | 76 +++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 features/skuba_upgrade/skuba_upgrade-01.feature diff --git a/features/skuba_upgrade/skuba_upgrade-01.feature b/features/skuba_upgrade/skuba_upgrade-01.feature new file mode 100644 index 0000000..b3b38d7 --- /dev/null +++ b/features/skuba_upgrade/skuba_upgrade-01.feature @@ -0,0 +1,76 @@ +# TC: https://github.com/fgerling/bdd-poc +# PR: https://github.com/SUSE/skuba/pull/911 +# FEATURE: skuba cluster upgrade + +# You are expected to run this test on a cluster bootstrapped with kubernetes-1.15.2 +Feature: Check if cluster upgrade is fine + +Scenario: Checking if cluster exists + Given "skuba" exist in gopath + And VARIABLE "imba-cluster" equals "/root/go/src/github.com/fgerling/bdd-poc/imba-cluster" + When I run "skuba cluster status" in VAR:"imba-cluster" directory + Then the output contains "master" and "worker" + Then the output contains "1.15.2" + When I run "kubectl get all --namespace=kube-system" + Then the output contains "cilium" and "dex" + When I run "skuba version" + Then the output contains "v1.2.6" or "v1.2.7" + + When I run "skuba cluster upgrade plan" in VAR:"imba-cluster" directory + Then the output contains "current kubernetes" and "latest kubernetes" + #Then the output contains "upgrade path to update" + #Then the output contains "addon upgrades from" + + When I run "skuba addon upgrade apply" in VAR:"imba-cluster" directory + Then the output contains "congratulations" + +Scenario: Applying upgrade on nodes + When I run "kubectl get pods --namespace=kube-system" + And VARIABLE "imba-cluster" equals "/root/go/src/github.com/fgerling/bdd-poc/imba-cluster" + When VARIABLE "privileged-pods" equals ContainersFROMOutput "kured-" + And VARIABLES "commandchecks" equals "kubectl describe pod -n kube-system " plus VAR:"privileged-pods" + And I run VARS:"commandchecks" and IPSFromOutput + + #UPGRADING MASTERS FIRST + When VARIABLES "commandupgrades" equals "skuba node upgrade plan " plus Master Nodes + And I run UPGRADE VARS:"commandupgrades" in VAR:"imba-cluster" directory + Then the output contains "apiserver" and "controller-manager" and "scheduler" + And the output contains "etcd" and "kubelet" and "cri-o" + And I run UPGRADE VARS:"commandupgrades" in VAR:"imba-cluster" directory + Then the output contains "apiserver" and "controller-manager" and "scheduler" + And the output contains "etcd" and "kubelet" and "cri-o" + And I run UPGRADE VARS:"commandupgrades" in VAR:"imba-cluster" directory + Then the output contains "apiserver" and "controller-manager" and "scheduler" + And the output contains "etcd" and "kubelet" and "cri-o" + + When VARIABLES "upgradeapply" equals "skuba node upgrade apply --user sles --sudo --target " plus Master Node IPS + And I run UPGRADE VARS:"upgradeapply" in VAR:"imba-cluster" directory + Then the output contains "successfully" or "to date" + And I wait "30 seconds" + And I run UPGRADE VARS:"upgradeapply" in VAR:"imba-cluster" directory + Then the output contains "successfully" or "to date" + And I wait "30 seconds" + And I run UPGRADE VARS:"upgradeapply" in VAR:"imba-cluster" directory + Then the output contains "successfully" or "to date" + And I wait "30 seconds" + +# UPGRADING THEN WORKERS + When VARIABLES "commandupgrades2" equals "skuba node upgrade plan " plus Worker Nodes + And I run UPGRADE VARS:"commandupgrades2" in VAR:"imba-cluster" directory + Then the output contains "kubelet" and "cri-o" + And I run UPGRADE VARS:"commandupgrades2" in VAR:"imba-cluster" directory + Then the output contains "kubelet" and "cri-o" + + When VARIABLES "upgradeapply2" equals "skuba node upgrade apply --user sles --sudo --target " plus Worker Node IPS + And I run UPGRADE VARS:"upgradeapply2" in VAR:"imba-cluster" directory + Then the output contains "successfully" or "to date" + + When I run "skuba addon upgrade apply" in VAR:"imba-cluster" directory + Then the output contains "not all nodes" + + When VARIABLES "upgradeapply2" equals "skuba node upgrade apply --user sles --sudo --target " plus Worker Node IPS + And I run UPGRADE VARS:"upgradeapply2" in VAR:"imba-cluster" directory + Then the output contains "successfully" or "to date" + + When I run "skuba addon upgrade apply" in VAR:"imba-cluster" directory + Then the output contains "successfully" or "congratulations" From dd1104f6814e5ab3b67454484d01a4ef2d1b78a1 Mon Sep 17 00:00:00 2001 From: atighineanu Date: Thu, 19 Mar 2020 21:32:30 +0100 Subject: [PATCH 25/50] fixed 2nd run --- features/skuba_upgrade/skuba_upgrade-01.feature | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/features/skuba_upgrade/skuba_upgrade-01.feature b/features/skuba_upgrade/skuba_upgrade-01.feature index b3b38d7..b531373 100644 --- a/features/skuba_upgrade/skuba_upgrade-01.feature +++ b/features/skuba_upgrade/skuba_upgrade-01.feature @@ -68,8 +68,8 @@ Scenario: Applying upgrade on nodes When I run "skuba addon upgrade apply" in VAR:"imba-cluster" directory Then the output contains "not all nodes" - When VARIABLES "upgradeapply2" equals "skuba node upgrade apply --user sles --sudo --target " plus Worker Node IPS - And I run UPGRADE VARS:"upgradeapply2" in VAR:"imba-cluster" directory + When VARIABLES "upgradeapply3" equals "skuba node upgrade apply --user sles --sudo --target " plus Worker Node IPS + And I run UPGRADE VARS:"upgradeapply3" in VAR:"imba-cluster" directory Then the output contains "successfully" or "to date" When I run "skuba addon upgrade apply" in VAR:"imba-cluster" directory From 4881efaff536f7580e0e0299b0d9568133bb79d3 Mon Sep 17 00:00:00 2001 From: atighineanu Date: Fri, 20 Mar 2020 10:44:09 +0000 Subject: [PATCH 26/50] improved output reading --- features/skuba_upgrade/skuba_upgrade-01.feature | 16 ++++++++-------- internal/utilities.go | 10 ++++++++++ main_test.go | 1 + 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/features/skuba_upgrade/skuba_upgrade-01.feature b/features/skuba_upgrade/skuba_upgrade-01.feature index b531373..31dcee7 100644 --- a/features/skuba_upgrade/skuba_upgrade-01.feature +++ b/features/skuba_upgrade/skuba_upgrade-01.feature @@ -22,7 +22,7 @@ Scenario: Checking if cluster exists #Then the output contains "addon upgrades from" When I run "skuba addon upgrade apply" in VAR:"imba-cluster" directory - Then the output contains "congratulations" + Then the output contains "congratulations" or "not all" Scenario: Applying upgrade on nodes When I run "kubectl get pods --namespace=kube-system" @@ -45,14 +45,14 @@ Scenario: Applying upgrade on nodes When VARIABLES "upgradeapply" equals "skuba node upgrade apply --user sles --sudo --target " plus Master Node IPS And I run UPGRADE VARS:"upgradeapply" in VAR:"imba-cluster" directory - Then the output contains "successfully" or "to date" - And I wait "30 seconds" + Then the output contains "successfully" or "to date" or "there are addon upgrades available" + And wait "30 seconds" And I run UPGRADE VARS:"upgradeapply" in VAR:"imba-cluster" directory - Then the output contains "successfully" or "to date" - And I wait "30 seconds" + Then the output contains "successfully" or "to date" or "there are addon upgrades available" + And wait "30 seconds" And I run UPGRADE VARS:"upgradeapply" in VAR:"imba-cluster" directory - Then the output contains "successfully" or "to date" - And I wait "30 seconds" + Then the output contains "successfully" or "to date" or "there are addon upgrades available" + And wait "30 seconds" # UPGRADING THEN WORKERS When VARIABLES "commandupgrades2" equals "skuba node upgrade plan " plus Worker Nodes @@ -70,7 +70,7 @@ Scenario: Applying upgrade on nodes When VARIABLES "upgradeapply3" equals "skuba node upgrade apply --user sles --sudo --target " plus Worker Node IPS And I run UPGRADE VARS:"upgradeapply3" in VAR:"imba-cluster" directory - Then the output contains "successfully" or "to date" + Then the output contains "successfully" or "to date" or "there are addon upgrades available" When I run "skuba addon upgrade apply" in VAR:"imba-cluster" directory Then the output contains "successfully" or "congratulations" diff --git a/internal/utilities.go b/internal/utilities.go index 82e912b..8032c81 100644 --- a/internal/utilities.go +++ b/internal/utilities.go @@ -43,6 +43,16 @@ func (test *TestRun) TheOutputContainsOr(arg1, arg2 string) error { return nil } + +func (test *TestRun) TheOutputContainsOrOr(arg1, arg2, arg3 string) error { + //fmt.Printf("text:\n%s\nvars: %s %s\n ", strings.ToLower(fmt.Sprintf("%s", string(test.Output))), arg1, arg2) + if strings.Contains(strings.ToLower(fmt.Sprintf("%s", string(test.Output))), arg1) || strings.Contains(strings.ToLower(fmt.Sprintf("%s", string(test.Output))), arg2) { + } else { + return errors.New("Output does not contain expected arguments") + } + return nil +} + func (test *TestRun) IRunVAR(arg1 string) error { if test.VarMap["command5"] == "" { return test.Irun(test.VarMap[arg1]) diff --git a/main_test.go b/main_test.go index 9791400..525e26c 100644 --- a/main_test.go +++ b/main_test.go @@ -118,6 +118,7 @@ func FeatureContext(s *godog.Suite) { s.Step(`^the output contains "([^"]*)" and "([^"]*)" and "([^"]*)"$`, test.TheOutputContainsAndAnd) s.Step(`^the output contains "([^"]*)" and "([^"]*)"$`, test.TheOutputContainsAnd) s.Step(`^the output contains "([^"]*)" or "([^"]*)"$`, test.TheOutputContainsOr) + s.Step(`^the output contains "([^"]*)" or "([^"]*)" or "([^"]*)"$`, test.TheOutputContainsOrOr) s.Step(`^there is "([^"]*)" directory$`, theDirectoryExist) s.Step(`^there is no "([^"]*)" directory$`, thereIsNoDirectory) s.Step(`^I run VAR:"([^"]*)"$`, test.IRunVAR) From 11245f292083f91b26c49064e88bd82bbab00067 Mon Sep 17 00:00:00 2001 From: atighineanu Date: Fri, 20 Mar 2020 11:45:50 +0100 Subject: [PATCH 27/50] fixed OrOr function --- internal/utilities.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/internal/utilities.go b/internal/utilities.go index 8032c81..37735e5 100644 --- a/internal/utilities.go +++ b/internal/utilities.go @@ -43,10 +43,9 @@ func (test *TestRun) TheOutputContainsOr(arg1, arg2 string) error { return nil } - -func (test *TestRun) TheOutputContainsOrOr(arg1, arg2, arg3 string) error { +func (test *TestRun) TheOutputContainsOrOr(arg1, arg2, arg3 string) error { //fmt.Printf("text:\n%s\nvars: %s %s\n ", strings.ToLower(fmt.Sprintf("%s", string(test.Output))), arg1, arg2) - if strings.Contains(strings.ToLower(fmt.Sprintf("%s", string(test.Output))), arg1) || strings.Contains(strings.ToLower(fmt.Sprintf("%s", string(test.Output))), arg2) { + if strings.Contains(strings.ToLower(fmt.Sprintf("%s", string(test.Output))), arg1) || strings.Contains(strings.ToLower(fmt.Sprintf("%s", string(test.Output))), arg2) || strings.Contains(strings.ToLower(fmt.Sprintf("%s", string(test.Output))), arg3) { } else { return errors.New("Output does not contain expected arguments") } From 50c05dc9648d5ec1a82258cca4f1708bc46f2c99 Mon Sep 17 00:00:00 2001 From: atighineanu Date: Fri, 20 Mar 2020 11:55:09 +0100 Subject: [PATCH 28/50] added scenario --- features/skuba_upgrade/skuba_upgrade-01.feature | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/features/skuba_upgrade/skuba_upgrade-01.feature b/features/skuba_upgrade/skuba_upgrade-01.feature index 31dcee7..1fcf024 100644 --- a/features/skuba_upgrade/skuba_upgrade-01.feature +++ b/features/skuba_upgrade/skuba_upgrade-01.feature @@ -54,7 +54,8 @@ Scenario: Applying upgrade on nodes Then the output contains "successfully" or "to date" or "there are addon upgrades available" And wait "30 seconds" -# UPGRADING THEN WORKERS +# UPGRADING THEN WORKERS + Scenario: Upgrading Workers When VARIABLES "commandupgrades2" equals "skuba node upgrade plan " plus Worker Nodes And I run UPGRADE VARS:"commandupgrades2" in VAR:"imba-cluster" directory Then the output contains "kubelet" and "cri-o" From b711588002405115fcff5b209dded872d7ec5570 Mon Sep 17 00:00:00 2001 From: atighineanu Date: Fri, 20 Mar 2020 11:56:41 +0100 Subject: [PATCH 29/50] fixed output reading --- features/skuba_upgrade/skuba_upgrade-01.feature | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/skuba_upgrade/skuba_upgrade-01.feature b/features/skuba_upgrade/skuba_upgrade-01.feature index 1fcf024..29ad80a 100644 --- a/features/skuba_upgrade/skuba_upgrade-01.feature +++ b/features/skuba_upgrade/skuba_upgrade-01.feature @@ -64,7 +64,7 @@ Scenario: Applying upgrade on nodes When VARIABLES "upgradeapply2" equals "skuba node upgrade apply --user sles --sudo --target " plus Worker Node IPS And I run UPGRADE VARS:"upgradeapply2" in VAR:"imba-cluster" directory - Then the output contains "successfully" or "to date" + Then the output contains "successfully" or "to date" or "there are addon upgrades available"s When I run "skuba addon upgrade apply" in VAR:"imba-cluster" directory Then the output contains "not all nodes" From b6137a792be3fe2c065a5e92043d5690a95816ca Mon Sep 17 00:00:00 2001 From: atighineanu Date: Fri, 20 Mar 2020 11:58:25 +0100 Subject: [PATCH 30/50] fixed folder --- features/skuba_upgrade/skuba_upgrade-01.feature | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/features/skuba_upgrade/skuba_upgrade-01.feature b/features/skuba_upgrade/skuba_upgrade-01.feature index 29ad80a..1cff8a3 100644 --- a/features/skuba_upgrade/skuba_upgrade-01.feature +++ b/features/skuba_upgrade/skuba_upgrade-01.feature @@ -57,6 +57,7 @@ Scenario: Applying upgrade on nodes # UPGRADING THEN WORKERS Scenario: Upgrading Workers When VARIABLES "commandupgrades2" equals "skuba node upgrade plan " plus Worker Nodes + And VARIABLE "imba-cluster" equals "/root/go/src/github.com/fgerling/bdd-poc/imba-cluster" And I run UPGRADE VARS:"commandupgrades2" in VAR:"imba-cluster" directory Then the output contains "kubelet" and "cri-o" And I run UPGRADE VARS:"commandupgrades2" in VAR:"imba-cluster" directory @@ -64,7 +65,7 @@ Scenario: Applying upgrade on nodes When VARIABLES "upgradeapply2" equals "skuba node upgrade apply --user sles --sudo --target " plus Worker Node IPS And I run UPGRADE VARS:"upgradeapply2" in VAR:"imba-cluster" directory - Then the output contains "successfully" or "to date" or "there are addon upgrades available"s + Then the output contains "successfully" or "to date" or "there are addon upgrades available" When I run "skuba addon upgrade apply" in VAR:"imba-cluster" directory Then the output contains "not all nodes" From 14fff0641f1f3348e519f1523d7b876b41c0cb4c Mon Sep 17 00:00:00 2001 From: atighineanu Date: Fri, 20 Mar 2020 11:13:18 +0000 Subject: [PATCH 31/50] fixed output parsing --- features/skuba_upgrade/skuba_upgrade-01.feature | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/features/skuba_upgrade/skuba_upgrade-01.feature b/features/skuba_upgrade/skuba_upgrade-01.feature index 1cff8a3..dd2ecf1 100644 --- a/features/skuba_upgrade/skuba_upgrade-01.feature +++ b/features/skuba_upgrade/skuba_upgrade-01.feature @@ -56,6 +56,12 @@ Scenario: Applying upgrade on nodes # UPGRADING THEN WORKERS Scenario: Upgrading Workers + When I run "kubectl get pods --namespace=kube-system" + And VARIABLE "imba-cluster" equals "/root/go/src/github.com/fgerling/bdd-poc/imba-cluster" + When VARIABLE "privileged-pods" equals ContainersFROMOutput "kured-" + And VARIABLES "commandchecks" equals "kubectl describe pod -n kube-system " plus VAR:"privileged-pods" + And I run VARS:"commandchecks" and IPSFromOutput + When VARIABLES "commandupgrades2" equals "skuba node upgrade plan " plus Worker Nodes And VARIABLE "imba-cluster" equals "/root/go/src/github.com/fgerling/bdd-poc/imba-cluster" And I run UPGRADE VARS:"commandupgrades2" in VAR:"imba-cluster" directory @@ -68,7 +74,7 @@ Scenario: Applying upgrade on nodes Then the output contains "successfully" or "to date" or "there are addon upgrades available" When I run "skuba addon upgrade apply" in VAR:"imba-cluster" directory - Then the output contains "not all nodes" + Then the output contains "not all nodes" or "successfully" or "congratulations" When VARIABLES "upgradeapply3" equals "skuba node upgrade apply --user sles --sudo --target " plus Worker Node IPS And I run UPGRADE VARS:"upgradeapply3" in VAR:"imba-cluster" directory From 54b0d022af109543b8f3e2ae53bb31dd9f99378b Mon Sep 17 00:00:00 2001 From: atighineanu Date: Fri, 20 Mar 2020 12:17:34 +0100 Subject: [PATCH 32/50] fixed outputing --- internal/kured.go | 2 +- internal/utilities.go | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/internal/kured.go b/internal/kured.go index 5da7147..a7b28bf 100644 --- a/internal/kured.go +++ b/internal/kured.go @@ -22,7 +22,7 @@ func (test *TestRun) IRunInDirectory(arg1, arg2 string) error { } test.Output = output test.Err = err - //fmt.Printf("%s", fmt.Sprintf("%s", string(Out1))) + fmt.Printf("%s", fmt.Sprintf("%s", string(test.Output))) return err } diff --git a/internal/utilities.go b/internal/utilities.go index 37735e5..a1eeec3 100644 --- a/internal/utilities.go +++ b/internal/utilities.go @@ -60,6 +60,18 @@ func (test *TestRun) IRunVAR(arg1 string) error { } } +func (test *TestRun) IRunVARInVARDirectory(arg1, arg2 string) error { + arg1 = test.VarMap[arg1] + err := test.IRunInVARDirectory(arg1, arg2) + return err +} + +func (test *TestRun) IRunInVARDirectory(arg1, arg2 string) error { + arg2 = test.VarMap[arg2] + err := test.IRunInDirectory(arg1, arg2) + return err +} + func (test *TestRun) Irun(command string) error { return test.IRunInDirectory(command, ".") } From 9372e90aa80dbce621a386a705d850635a6046ec Mon Sep 17 00:00:00 2001 From: atighineanu Date: Fri, 20 Mar 2020 11:30:24 +0000 Subject: [PATCH 33/50] fixed outputs --- internal/cilium.go | 10 ---------- internal/kured.go | 2 +- internal/utilities.go | 2 ++ 3 files changed, 3 insertions(+), 11 deletions(-) diff --git a/internal/cilium.go b/internal/cilium.go index ea3f862..b9d05d8 100644 --- a/internal/cilium.go +++ b/internal/cilium.go @@ -8,17 +8,7 @@ import ( "strings" ) -func (test *TestRun) IRunVARInVARDirectory(arg1, arg2 string) error { - arg1 = test.VarMap[arg1] - err := test.IRunInVARDirectory(arg1, arg2) - return err -} -func (test *TestRun) IRunInVARDirectory(arg1, arg2 string) error { - arg2 = test.VarMap[arg2] - err := test.IRunInDirectory(arg1, arg2) - return err -} func (test *TestRun) VARIABLEEqualsContainersFROMOutput(arg1, arg2 string) error { var err error diff --git a/internal/kured.go b/internal/kured.go index a7b28bf..a437b13 100644 --- a/internal/kured.go +++ b/internal/kured.go @@ -22,7 +22,7 @@ func (test *TestRun) IRunInDirectory(arg1, arg2 string) error { } test.Output = output test.Err = err - fmt.Printf("%s", fmt.Sprintf("%s", string(test.Output))) + //fmt.Printf("%s", fmt.Sprintf("%s", string(test.Output))) return err } diff --git a/internal/utilities.go b/internal/utilities.go index a1eeec3..e084680 100644 --- a/internal/utilities.go +++ b/internal/utilities.go @@ -63,12 +63,14 @@ func (test *TestRun) IRunVAR(arg1 string) error { func (test *TestRun) IRunVARInVARDirectory(arg1, arg2 string) error { arg1 = test.VarMap[arg1] err := test.IRunInVARDirectory(arg1, arg2) + fmt.Println(fmt.Sprintf("%s", string(test.Output))) return err } func (test *TestRun) IRunInVARDirectory(arg1, arg2 string) error { arg2 = test.VarMap[arg2] err := test.IRunInDirectory(arg1, arg2) + fmt.Println(fmt.Sprintf("%s", string(test.Output))) return err } From ad0eb2b16396c65b7cb5f13b7f6e7187a36d0bd1 Mon Sep 17 00:00:00 2001 From: atighineanu Date: Fri, 20 Mar 2020 11:31:42 +0000 Subject: [PATCH 34/50] removed scenario workers --- features/skuba_upgrade/skuba_upgrade-01.feature | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/features/skuba_upgrade/skuba_upgrade-01.feature b/features/skuba_upgrade/skuba_upgrade-01.feature index dd2ecf1..5b94400 100644 --- a/features/skuba_upgrade/skuba_upgrade-01.feature +++ b/features/skuba_upgrade/skuba_upgrade-01.feature @@ -55,15 +55,9 @@ Scenario: Applying upgrade on nodes And wait "30 seconds" # UPGRADING THEN WORKERS - Scenario: Upgrading Workers - When I run "kubectl get pods --namespace=kube-system" - And VARIABLE "imba-cluster" equals "/root/go/src/github.com/fgerling/bdd-poc/imba-cluster" - When VARIABLE "privileged-pods" equals ContainersFROMOutput "kured-" - And VARIABLES "commandchecks" equals "kubectl describe pod -n kube-system " plus VAR:"privileged-pods" - And I run VARS:"commandchecks" and IPSFromOutput - + #Scenario: Upgrading Workers When VARIABLES "commandupgrades2" equals "skuba node upgrade plan " plus Worker Nodes - And VARIABLE "imba-cluster" equals "/root/go/src/github.com/fgerling/bdd-poc/imba-cluster" + #And VARIABLE "imba-cluster" equals "/root/go/src/github.com/fgerling/bdd-poc/imba-cluster" And I run UPGRADE VARS:"commandupgrades2" in VAR:"imba-cluster" directory Then the output contains "kubelet" and "cri-o" And I run UPGRADE VARS:"commandupgrades2" in VAR:"imba-cluster" directory From 45c0ef07ff4d8edf88faa68f3195f010310aa8e4 Mon Sep 17 00:00:00 2001 From: Alexei Tighineanu Date: Sat, 21 Mar 2020 09:53:03 +0100 Subject: [PATCH 35/50] included real test case from SUSE/caasp-test-cases --- features/skuba_upgrade/skuba_upgrade-01.feature | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/skuba_upgrade/skuba_upgrade-01.feature b/features/skuba_upgrade/skuba_upgrade-01.feature index 5b94400..9d9a35b 100644 --- a/features/skuba_upgrade/skuba_upgrade-01.feature +++ b/features/skuba_upgrade/skuba_upgrade-01.feature @@ -1,4 +1,4 @@ -# TC: https://github.com/fgerling/bdd-poc +# TC: https://github.com/SUSE/caasp-test-cases # PR: https://github.com/SUSE/skuba/pull/911 # FEATURE: skuba cluster upgrade From 09d42c27730a3d446f82e561140823f66becfbf3 Mon Sep 17 00:00:00 2001 From: atighineanu Date: Sun, 22 Mar 2020 00:06:41 +0100 Subject: [PATCH 36/50] added function that changes Cilium Version in output --- main_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/main_test.go b/main_test.go index 525e26c..27ca5aa 100644 --- a/main_test.go +++ b/main_test.go @@ -150,4 +150,5 @@ func FeatureContext(s *godog.Suite) { s.Step(`^VARIABLES "([^"]*)" equals "([^"]*)" plus Worker Nodes$`, test.VARIABLESEqualsPlusWorkerNodes) s.Step(`^VARIABLES "([^"]*)" equals "([^"]*)" plus Master Node IPS$`, test.VARIABLESEqualsPlusMasterNodeIPS) s.Step(`^VARIABLES "([^"]*)" equals "([^"]*)" plus Worker Node IPS$`, test.VARIABLESEqualsPlusWorkerNodeIPS) + s.Step(`^I replace Cilium Version in OUTPUT$`, test.IReplaceCiliumVersionInOUTPUT) } From 4833547e4162c4baf084fabc6d6549e4a76af9a0 Mon Sep 17 00:00:00 2001 From: atighineanu Date: Sun, 22 Mar 2020 00:07:06 +0100 Subject: [PATCH 37/50] implemented strings.Replace for cilium version function --- internal/skuba_upgrade.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/internal/skuba_upgrade.go b/internal/skuba_upgrade.go index a7d6ddf..879dd49 100644 --- a/internal/skuba_upgrade.go +++ b/internal/skuba_upgrade.go @@ -2,6 +2,7 @@ package features import ( "fmt" + "os" "strings" ) @@ -79,3 +80,25 @@ func (test *TestRun) IRunUPGRADEVARSInVARDirectory(arg1, arg2 string) error { } return nil } + +func (test *TestRun) IReplaceCiliumVersionInOUTPUT() error { + template := fmt.Sprintf("%s", string(test.Output)) + for index, row := range strings.Split(template, "\n") { + if strings.Contains(strings.ToLower(row), "cilium") { + version := strings.Split(template, "\n")[index+2] + replace_version := strings.Split(version, ":")[0] + ": 1.5.1" + template = strings.Replace(template, version, replace_version, 1) + break + } + } + f, err := os.Create("skubaconf.yaml") + if err != nil { + fmt.Println(err) + } + _, err = f.WriteString(template) + if err != nil { + fmt.Println(err) + } + f.Close() + return nil +} From 62a9f9d4ffa72b4a8ab396b149cc5033ba4e8ced Mon Sep 17 00:00:00 2001 From: atighineanu Date: Sun, 22 Mar 2020 00:07:48 +0100 Subject: [PATCH 38/50] added test case implementation for corresponding BSC# --- .../skuba_upgrade-bsc#1167320.feature | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 features/skuba_upgrade/skuba_upgrade-bsc#1167320.feature diff --git a/features/skuba_upgrade/skuba_upgrade-bsc#1167320.feature b/features/skuba_upgrade/skuba_upgrade-bsc#1167320.feature new file mode 100644 index 0000000..91f75fe --- /dev/null +++ b/features/skuba_upgrade/skuba_upgrade-bsc#1167320.feature @@ -0,0 +1,26 @@ +# TC: https://github.com/fgerling/bdd-poc +# PR: https://github.com/SUSE/skuba/pull/1018 +# FEATURE: skuba addon upgrade + +# You are expected to run this test on a cluster bootstrapped with kubernetes-1.15.2 +Feature: Check if cluster upgrade is fine + +Scenario: Checking if cluster exists + Given "skuba" exist in gopath + And VARIABLE "imba-cluster" equals "/Users/alexeitighineanu/go/src/github.com/fgerling/bdd-poc/imba-cluster" + When I run "skuba cluster status" in VAR:"imba-cluster" directory + Then the output contains "master" and "worker" + Then the output contains "1.15.2" + When I run "kubectl get all --namespace=kube-system" + Then the output contains "cilium" and "dex" + When I run "skuba version" + Then the output contains "v1.2.6" or "v1.2.7" + + When I run "skuba addon upgrade plan" in VAR:"imba-cluster" directory + Then the output contains "congratulations" or "are already" + + When I run "kubectl get configmaps skuba-config -n kube-system -o yaml" in VAR:"imba-cluster" directory + And I replace Cilium Version in OUTPUT + And I run "kubectl apply -f skubaconf.yaml" + And I run "skuba addon upgrade plan" in VAR:"imba-cluster" directory + Then the output contains "addon upgrades for" or "->" \ No newline at end of file From 241b4227b0b38bcfb2247d62dd48928488c7eb03 Mon Sep 17 00:00:00 2001 From: Alexei Tighineanu Date: Sun, 22 Mar 2020 00:10:27 +0100 Subject: [PATCH 39/50] Update skuba_upgrade-bsc#1167320.feature --- features/skuba_upgrade/skuba_upgrade-bsc#1167320.feature | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/features/skuba_upgrade/skuba_upgrade-bsc#1167320.feature b/features/skuba_upgrade/skuba_upgrade-bsc#1167320.feature index 91f75fe..71ecd33 100644 --- a/features/skuba_upgrade/skuba_upgrade-bsc#1167320.feature +++ b/features/skuba_upgrade/skuba_upgrade-bsc#1167320.feature @@ -1,5 +1,6 @@ -# TC: https://github.com/fgerling/bdd-poc +# TC: https://github.com/SUSE/caasp-test/cases (to be documented) # PR: https://github.com/SUSE/skuba/pull/1018 +# BSC: https://bugzilla.suse.com/show_bug.cgi?id=1167320 # FEATURE: skuba addon upgrade # You are expected to run this test on a cluster bootstrapped with kubernetes-1.15.2 @@ -23,4 +24,4 @@ Scenario: Checking if cluster exists And I replace Cilium Version in OUTPUT And I run "kubectl apply -f skubaconf.yaml" And I run "skuba addon upgrade plan" in VAR:"imba-cluster" directory - Then the output contains "addon upgrades for" or "->" \ No newline at end of file + Then the output contains "addon upgrades for" or "->" From d98b7d777de6fc048660b9c8f54488a411142944 Mon Sep 17 00:00:00 2001 From: atighineanu Date: Sun, 22 Mar 2020 07:47:50 +0100 Subject: [PATCH 40/50] added check for gangway --- features/skuba_upgrade/skuba_upgrade-bsc#1167320.feature | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/features/skuba_upgrade/skuba_upgrade-bsc#1167320.feature b/features/skuba_upgrade/skuba_upgrade-bsc#1167320.feature index 91f75fe..43c1f32 100644 --- a/features/skuba_upgrade/skuba_upgrade-bsc#1167320.feature +++ b/features/skuba_upgrade/skuba_upgrade-bsc#1167320.feature @@ -20,7 +20,12 @@ Scenario: Checking if cluster exists Then the output contains "congratulations" or "are already" When I run "kubectl get configmaps skuba-config -n kube-system -o yaml" in VAR:"imba-cluster" directory - And I replace Cilium Version in OUTPUT + And I replace Cilium Version in OUTPUT and save it into skubaconf.yaml file And I run "kubectl apply -f skubaconf.yaml" And I run "skuba addon upgrade plan" in VAR:"imba-cluster" directory - Then the output contains "addon upgrades for" or "->" \ No newline at end of file + Then the output contains "addon upgrades for" or "->" + + And I replace Gangway Version in OUTPUT and save it into skubaconf.yaml file + And I run "kubectl apply -f skubaconf.yaml" + And I run "skuba addon upgrade plan" in VAR:"imba-cluster" directory + Then the output contains "addon upgrades for" and "gangway" \ No newline at end of file From e1b38a11c19f61156268d65bc44f1e3fb20040a0 Mon Sep 17 00:00:00 2001 From: atighineanu Date: Sun, 22 Mar 2020 08:01:36 +0100 Subject: [PATCH 41/50] fixed --- .../skuba_upgrade-bsc#1167320.feature | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 features/skuba_upgrade/skuba_upgrade-bsc#1167320.feature diff --git a/features/skuba_upgrade/skuba_upgrade-bsc#1167320.feature b/features/skuba_upgrade/skuba_upgrade-bsc#1167320.feature new file mode 100644 index 0000000..c3f8f95 --- /dev/null +++ b/features/skuba_upgrade/skuba_upgrade-bsc#1167320.feature @@ -0,0 +1,31 @@ +# TC: https://github.com/SUSE/caasp-test/cases (to be documented) +# PR: https://github.com/SUSE/skuba/pull/1018 +# BSC: https://bugzilla.suse.com/show_bug.cgi?id=1167320 +# FEATURE: skuba addon upgrade + +# You are expected to run this test on a cluster bootstrapped with kubernetes-1.15.2 +Feature: Check if cluster upgrade is fine + +Scenario: Checking if cluster exists + Given "skuba" exist in gopath + And VARIABLE "imba-cluster" equals "/Users/alexeitighineanu/go/src/github.com/fgerling/bdd-poc/imba-cluster" + When I run "skuba cluster status" in VAR:"imba-cluster" directory + Then the output contains "master" and "worker" + Then the output contains "1.15.2" + When I run "kubectl get all --namespace=kube-system" + Then the output contains "cilium" and "dex" + When I run "skuba version" + Then the output contains "v1.2.6" or "v1.2.7" + + When I run "skuba addon upgrade plan" in VAR:"imba-cluster" directory + Then the output contains "congratulations" or "are already" + + When I run "kubectl get configmaps skuba-config -n kube-system -o yaml" in VAR:"imba-cluster" directory + And I replace Cilium Version in OUTPUT and save it into skubaconf.yaml file + + When I run "cat skubaconf.yaml" + And I replace Gangway Version in OUTPUT and save it into skubaconf.yaml file + And I run "kubectl apply -f skubaconf.yaml" + And I run "skuba addon upgrade plan" in VAR:"imba-cluster" directory + Then the output contains "cilium" and "gangway" + Then the output contains "->" and "1.5.1" and "2.1.0-rev4" From 6ef906f0ca003becd4caad213593869449c4263f Mon Sep 17 00:00:00 2001 From: atighineanu Date: Sun, 22 Mar 2020 09:33:55 +0100 Subject: [PATCH 42/50] modified input of Cluster-Directory (of skuba): from config.json --- features/cilium/cilium-01.feature | 14 ++++++++------ features/cilium/cilium-bsc#1121353.feature | 3 ++- features/cluster/status.feature | 4 ++-- features/kured/kured-01.feature | 8 +++++++- internal/cilium.go | 5 +---- internal/data.go | 5 +++++ internal/kured.go | 20 ++++++++++++++++++++ internal/skuba_upgrade.go | 3 +++ internal/utilities.go | 20 ++++++++++++++++++++ main_test.go | 2 ++ 10 files changed, 70 insertions(+), 14 deletions(-) diff --git a/features/cilium/cilium-01.feature b/features/cilium/cilium-01.feature index c38fd09..1fc58e2 100644 --- a/features/cilium/cilium-01.feature +++ b/features/cilium/cilium-01.feature @@ -7,8 +7,8 @@ Feature: cilium-basic Scenario: Test-Cilium-Basic on Skuba Cluster Given "skuba" exist in gopath - #And VARIABLE "work-folder" equals "/Users/alexeitighineanu/go/src/github.com/fgerling/bdd-poc/imba-cluster" - When I run "skuba cluster status" + And VARIABLE "work-folder" I get from CONFIG + When I run "skuba cluster status" in VAR:"work-folder" directory Then the output contains "master" and "worker" When I run "kubectl get all --namespace=kube-system" Then the output contains "cilium" and "dex" @@ -32,15 +32,17 @@ Feature: cilium-basic Scenario: Test number1 if empire's ship is allowed into empire space And I run "kubectl exec tiefighter -- curl -sm10 -XPOST deathstar.default.svc.cluster.local/v1/request-landing" - Then the output contains "Ship" and "landed" + And wait "5 seconds" + Then the output contains "ship" and "landed" When I run "kubectl exec xwing -- curl -sm10 -XPOST deathstar.default.svc.cluster.local/v1/request-landing" - Then the output contains "Ship" and "landed" + And wait "5 seconds" + Then the output contains "ship" and "landed" Scenario: Test number2 if policies work properly When I run "kubectl create -f https://raw.githubusercontent.com/cilium/cilium/v1.6/examples/minikube/sw_l3_l4_policy.yaml" And I run "kubectl exec tiefighter -- curl -sm10 -XPOST deathstar.default.svc.cluster.local/v1/request-landing" - Then the output contains "Ship" and "landed" + Then the output contains "ship" and "landed" When I run "kubectl exec xwing -- curl -sm10 -XPOST deathstar.default.svc.cluster.local/v1/request-landing" expecting ERROR And wait "10 seconds" @@ -85,7 +87,7 @@ Feature: cilium-basic Then the output contains "ciliumnetworkpolicy" and "deleted" Scenario: Deleting the pods - When VARIABLE "work-folder" equals "/Users/alexeitighineanu/go/src/github.com/fgerling/bdd-poc/imba-cluster" + When VARIABLE "work-folder" I get from CONFIG When I run "kubectl delete -f https://raw.githubusercontent.com/cilium/cilium/v1.6/examples/minikube/http-sw-app.yaml" Then the output contains "deathstar" and "deleted" Then the output contains "xwing" and "deleted" diff --git a/features/cilium/cilium-bsc#1121353.feature b/features/cilium/cilium-bsc#1121353.feature index ec87882..66cee92 100644 --- a/features/cilium/cilium-bsc#1121353.feature +++ b/features/cilium/cilium-bsc#1121353.feature @@ -6,7 +6,8 @@ Feature: bsc#1121353 - Kubernetes – Master node pod configured with Privileged Scenario: Checking if Privileged Pods Given "skuba" exist in gopath - When I run "skuba cluster status" + And VARIABLE "work-folder" I get from CONFIG + When I run "skuba cluster status" in VAR:"work-folder" directory Then the output contains "master" and "worker" When I run "kubectl get all --namespace=kube-system" Then the output contains "cilium" and "dex" diff --git a/features/cluster/status.feature b/features/cluster/status.feature index 1bc6577..beec075 100644 --- a/features/cluster/status.feature +++ b/features/cluster/status.feature @@ -3,8 +3,8 @@ Feature: Skuba cluster status Scenario: checkout cluster status - Given there is "cluster" directory + Given VARIABLE "cluster" I get from CONFIG And "skuba" exist in gopath - When I run "skuba cluster status" in "cluster" directory + When I run "skuba cluster status" in VAR:"cluster" directory Then the output contains "master" And the output contains "worker" diff --git a/features/kured/kured-01.feature b/features/kured/kured-01.feature index 4b5c6d0..af56ab4 100644 --- a/features/kured/kured-01.feature +++ b/features/kured/kured-01.feature @@ -5,11 +5,17 @@ Feature: Check if reboot triggered Scenario: Checking if reboot triggered on one node Given "skuba" exist in gopath - When I run "skuba cluster status" + And VARIABLE "imba-cluster" I get from CONFIG + When I run "skuba cluster status" in VAR:"imba-cluster" directory Then the output contains "master" and "worker" When I run "kubectl get all --namespace=kube-system" Then the output contains "cilium" and "dex" + When I run "kubectl get daemonset kured -o yaml -n kube-system" + And I insert in OUTPUT "- --period=30s" and save it to kurednew.yaml + And I run "kubectl apply -f kurednew.yaml" + Then the output contains "configured" + And wait "30 seconds" When I run "kubectl get pods --namespace=kube-system" When VARIABLE "privileged-pods" equals ContainersFROMOutput "kured-" And VARIABLES "commandchecks" equals "kubectl describe pod -n kube-system " plus VAR:"privileged-pods" diff --git a/internal/cilium.go b/internal/cilium.go index b9d05d8..8ef23a6 100644 --- a/internal/cilium.go +++ b/internal/cilium.go @@ -8,8 +8,6 @@ import ( "strings" ) - - func (test *TestRun) VARIABLEEqualsContainersFROMOutput(arg1, arg2 string) error { var err error tmp := strings.Split(fmt.Sprintf("%s", string(test.Output)), "\n") @@ -36,13 +34,12 @@ func (test *TestRun) VARIABLEEqualsContainerFROMOutput(arg1, arg2 string) error } func (test *TestRun) VARIABLEEquals(arg1, arg2 string) error { - var err error if test.VarMap == nil { test.VarMap = make(map[string]string) } test.VarMap[arg1] = arg2 fmt.Printf(" VAR: %s = %s \n", arg1, test.VarMap[arg1]) - return err + return nil } func (test *TestRun) VARIABLEEqualsPlusVARPlus(arg1, arg2, arg3, arg4 string) error { diff --git a/internal/data.go b/internal/data.go index 8ec57b7..3de7d9e 100644 --- a/internal/data.go +++ b/internal/data.go @@ -5,6 +5,7 @@ type TestRun struct { VarMap map[string]string UpgradeCheck map[string]NodeCheck Err error + Config Config } type NodeCheck struct { @@ -12,3 +13,7 @@ type NodeCheck struct { UPDone bool IP string } + +type Config struct { + ClusterDir string `json:"ClusterDir"` +} diff --git a/internal/kured.go b/internal/kured.go index a437b13..5937d2f 100644 --- a/internal/kured.go +++ b/internal/kured.go @@ -78,3 +78,23 @@ func (test *TestRun) IRunSSHCMDOnMASTER(arg1 string) error { //fmt.Printf("%s\n", fmt.Sprintf("%s", string(test.Output))) return err } + +func (test *TestRun) IInsertInOUTPUTAndSaveItToKurednewyaml(arg1 string) error { + var kurednewouput string + for index, row := range strings.Split(fmt.Sprintf("%s", string(test.Output)), "\n") { + kurednewouput += row + "\n" + if strings.Contains(row, "- /usr/bin/kured") && strings.Contains(strings.Split(fmt.Sprintf("%s", string(test.Output)), "\n")[index-1], "- command:") { + kurednewouput += strings.Replace(row, "- /usr/bin/kured", "- --period=30s\n", 1) + } + } + f, err := os.Create("kurednew.yaml") + if err != nil { + test.TreatErrors(err) + } + _, err = f.WriteString(kurednewouput) + if err != nil { + test.TreatErrors(err) + } + f.Close() + return err +} diff --git a/internal/skuba_upgrade.go b/internal/skuba_upgrade.go index 8f9cadd..dacd40d 100644 --- a/internal/skuba_upgrade.go +++ b/internal/skuba_upgrade.go @@ -69,6 +69,9 @@ func (test *TestRun) IRunUPGRADEVARSInVARDirectory(arg1, arg2 string) error { //fmt.Printf("Command we run: %s\n", test.VarMap[key]) test.Output = []byte{1} err = test.IRunInDirectory(test.VarMap[key], test.VarMap[arg2]) + if err != nil { + test.TreatErrors(err) + } temp1 := test.UpgradeCheck[key] temp1.PlanDone = true if strings.Contains(test.VarMap[key], "apply") { diff --git a/internal/utilities.go b/internal/utilities.go index c40deb4..e9023ff 100644 --- a/internal/utilities.go +++ b/internal/utilities.go @@ -1,6 +1,7 @@ package features import ( + "encoding/json" "errors" "fmt" "os" @@ -95,3 +96,22 @@ func (test *TestRun) TreatErrors(err error) { fmt.Fprintf(os.Stdout, "\nError: %v\n", err) } } + +func (test *TestRun) VARIABLEIGetFromCONFIG(arg1 string) error { + if test.VarMap == nil { + test.IStartTest() + } + var config Config + file, err := os.Open("config.json") + defer file.Close() + if err != nil { + test.TreatErrors(err) + } + if err := json.NewDecoder(file).Decode(&config); err != nil { + test.TreatErrors(err) + } + test.Config = config + test.VarMap[arg1] = config.ClusterDir + fmt.Printf("VAR: %s = %s", arg1, test.VarMap[arg1]) + return nil +} diff --git a/main_test.go b/main_test.go index 14cbffc..6a33659 100644 --- a/main_test.go +++ b/main_test.go @@ -102,6 +102,7 @@ func wait(arg1 string) error { func FeatureContext(s *godog.Suite) { s.Step(`^I start test$`, test.IStartTest) s.Step(`^wait "([^"]*)"$`, wait) + s.Step(`^VARIABLE "([^"]*)" I get from CONFIG$`, test.VARIABLEIGetFromCONFIG) s.Step(`^"([^"]*)" exist in gopath$`, existInGopath) s.Step(`^I git clone "([^"]*)" into "([^"]*)"$`, iGitCloneInto) s.Step(`^I have "([^"]*)" in PATH$`, suse.IHaveInPATH) @@ -144,6 +145,7 @@ func FeatureContext(s *godog.Suite) { //-------------------Kured-specific test functions------------------------------------------------- s.Step(`^I run VARS:"([^"]*)" and IPSFromOutput$`, test.IRunVARSAndIPSFromOutput) s.Step(`^I run SSHCMD "([^"]*)" on MASTER$`, test.IRunSSHCMDOnMASTER) + s.Step(`^I insert in OUTPUT "([^"]*)" and save it to kurednew\.yaml$`, test.IInsertInOUTPUTAndSaveItToKurednewyaml) //-------------------Skuba Upgrade - specific test fuctions---------------------------------------- s.Step(`^I run UPGRADE VARS:"([^"]*)" in VAR:"([^"]*)" directory$`, test.IRunUPGRADEVARSInVARDirectory) s.Step(`^VARIABLES "([^"]*)" equals "([^"]*)" plus Master Nodes$`, test.VARIABLESEqualsPlusMasterNodes) From 58e9aa84bdf049f14bc658c80eaef63a3a4f44fc Mon Sep 17 00:00:00 2001 From: atighineanu Date: Sun, 22 Mar 2020 09:34:45 +0100 Subject: [PATCH 43/50] please, fill in the skuba-cluster directory path... --- config.json | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 config.json diff --git a/config.json b/config.json new file mode 100644 index 0000000..0cb8c39 --- /dev/null +++ b/config.json @@ -0,0 +1,3 @@ +{ +"ClusterDir": "/Users/alexeitighineanu/go/src/github.com/fgerling/bdd-poc/imba-cluster" +} From d778d622312521c348cb640cbb19d911d688eaf9 Mon Sep 17 00:00:00 2001 From: Alexei Tighineanu Date: Sun, 22 Mar 2020 10:22:14 +0100 Subject: [PATCH 44/50] added caasp-test-cases reference --- features/skuba_upgrade/skuba_upgrade-bsc#1167320.feature | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/skuba_upgrade/skuba_upgrade-bsc#1167320.feature b/features/skuba_upgrade/skuba_upgrade-bsc#1167320.feature index c3f8f95..5701546 100644 --- a/features/skuba_upgrade/skuba_upgrade-bsc#1167320.feature +++ b/features/skuba_upgrade/skuba_upgrade-bsc#1167320.feature @@ -1,4 +1,4 @@ -# TC: https://github.com/SUSE/caasp-test/cases (to be documented) +# TC: https://github.com/SUSE/caasp-test/features/skuba_upgrade/skuba_upgrade_bsc#1167320.feature # PR: https://github.com/SUSE/skuba/pull/1018 # BSC: https://bugzilla.suse.com/show_bug.cgi?id=1167320 # FEATURE: skuba addon upgrade From 7f8410244ad0e4427dada3e942160021b0232707 Mon Sep 17 00:00:00 2001 From: Alexei Tighineanu Date: Sun, 22 Mar 2020 14:14:14 +0100 Subject: [PATCH 45/50] added folder "skuba-cluster" do be red from config file --- features/skuba_upgrade/skuba_upgrade-bsc#1167320.feature | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/skuba_upgrade/skuba_upgrade-bsc#1167320.feature b/features/skuba_upgrade/skuba_upgrade-bsc#1167320.feature index 5701546..45be7d6 100644 --- a/features/skuba_upgrade/skuba_upgrade-bsc#1167320.feature +++ b/features/skuba_upgrade/skuba_upgrade-bsc#1167320.feature @@ -8,7 +8,7 @@ Feature: Check if cluster upgrade is fine Scenario: Checking if cluster exists Given "skuba" exist in gopath - And VARIABLE "imba-cluster" equals "/Users/alexeitighineanu/go/src/github.com/fgerling/bdd-poc/imba-cluster" + And VARIABLE "imba-cluster" I get from CONFIG When I run "skuba cluster status" in VAR:"imba-cluster" directory Then the output contains "master" and "worker" Then the output contains "1.15.2" From 110d0500055ec22204b2a6d68e3d7e27459c96af Mon Sep 17 00:00:00 2001 From: Alexei Tighineanu Date: Sun, 22 Mar 2020 14:16:00 +0100 Subject: [PATCH 46/50] changed that folder's "imba-cluster" path it red from confing --- features/skuba_upgrade/skuba_upgrade-01.feature | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/features/skuba_upgrade/skuba_upgrade-01.feature b/features/skuba_upgrade/skuba_upgrade-01.feature index 9d9a35b..d2d130e 100644 --- a/features/skuba_upgrade/skuba_upgrade-01.feature +++ b/features/skuba_upgrade/skuba_upgrade-01.feature @@ -7,7 +7,7 @@ Feature: Check if cluster upgrade is fine Scenario: Checking if cluster exists Given "skuba" exist in gopath - And VARIABLE "imba-cluster" equals "/root/go/src/github.com/fgerling/bdd-poc/imba-cluster" + And VARIABLE "imba-cluster" I get from CONFIG When I run "skuba cluster status" in VAR:"imba-cluster" directory Then the output contains "master" and "worker" Then the output contains "1.15.2" @@ -26,7 +26,7 @@ Scenario: Checking if cluster exists Scenario: Applying upgrade on nodes When I run "kubectl get pods --namespace=kube-system" - And VARIABLE "imba-cluster" equals "/root/go/src/github.com/fgerling/bdd-poc/imba-cluster" + And VARIABLE "imba-cluster" I get from CONFIG When VARIABLE "privileged-pods" equals ContainersFROMOutput "kured-" And VARIABLES "commandchecks" equals "kubectl describe pod -n kube-system " plus VAR:"privileged-pods" And I run VARS:"commandchecks" and IPSFromOutput @@ -57,7 +57,7 @@ Scenario: Applying upgrade on nodes # UPGRADING THEN WORKERS #Scenario: Upgrading Workers When VARIABLES "commandupgrades2" equals "skuba node upgrade plan " plus Worker Nodes - #And VARIABLE "imba-cluster" equals "/root/go/src/github.com/fgerling/bdd-poc/imba-cluster" + And VARIABLE "imba-cluster" I get from CONFIG And I run UPGRADE VARS:"commandupgrades2" in VAR:"imba-cluster" directory Then the output contains "kubelet" and "cri-o" And I run UPGRADE VARS:"commandupgrades2" in VAR:"imba-cluster" directory From 987d38fc8a686f8f4b4add9305de4906c68f70e5 Mon Sep 17 00:00:00 2001 From: atighineanu Date: Fri, 17 Apr 2020 13:18:22 +0000 Subject: [PATCH 47/50] added checker for API health --- .../skuba_upgrade/skuba_upgrade-01.feature | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/features/skuba_upgrade/skuba_upgrade-01.feature b/features/skuba_upgrade/skuba_upgrade-01.feature index d2d130e..1ee97d6 100644 --- a/features/skuba_upgrade/skuba_upgrade-01.feature +++ b/features/skuba_upgrade/skuba_upgrade-01.feature @@ -14,15 +14,23 @@ Scenario: Checking if cluster exists When I run "kubectl get all --namespace=kube-system" Then the output contains "cilium" and "dex" When I run "skuba version" - Then the output contains "v1.2.6" or "v1.2.7" + Then the output contains "v1.0.2" or "v1.1.2" When I run "skuba cluster upgrade plan" in VAR:"imba-cluster" directory Then the output contains "current kubernetes" and "latest kubernetes" #Then the output contains "upgrade path to update" #Then the output contains "addon upgrades from" + When I run "zypper -n in skuba-1.2.1" + Then the output contains "installed" + + When I run "skuba cluster upgrade plan" in VAR:"imba-cluster" directory + Then the output contains "current kubernetes" and "latest kubernetes" + #Then the output contains "upgrade path to update" + #Then the output contains "addon upgrades from" + When I run "skuba addon upgrade apply" in VAR:"imba-cluster" directory - Then the output contains "congratulations" or "not all" + Then the output contains "congratulations" or "ot all" Scenario: Applying upgrade on nodes When I run "kubectl get pods --namespace=kube-system" @@ -46,13 +54,13 @@ Scenario: Applying upgrade on nodes When VARIABLES "upgradeapply" equals "skuba node upgrade apply --user sles --sudo --target " plus Master Node IPS And I run UPGRADE VARS:"upgradeapply" in VAR:"imba-cluster" directory Then the output contains "successfully" or "to date" or "there are addon upgrades available" - And wait "30 seconds" + And wait "120 seconds" And I run UPGRADE VARS:"upgradeapply" in VAR:"imba-cluster" directory Then the output contains "successfully" or "to date" or "there are addon upgrades available" - And wait "30 seconds" + And wait "120 seconds" And I run UPGRADE VARS:"upgradeapply" in VAR:"imba-cluster" directory Then the output contains "successfully" or "to date" or "there are addon upgrades available" - And wait "30 seconds" + And wait "120 seconds" # UPGRADING THEN WORKERS #Scenario: Upgrading Workers From 31228cf62d91a28e25205235b3f4eb23c0c67442 Mon Sep 17 00:00:00 2001 From: atighineanu Date: Fri, 17 Apr 2020 13:18:38 +0000 Subject: [PATCH 48/50] upgrade 1.16- 1.17 --- .../skuba_upgrade/skuba_upgrade-02.feature | 86 +++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 features/skuba_upgrade/skuba_upgrade-02.feature diff --git a/features/skuba_upgrade/skuba_upgrade-02.feature b/features/skuba_upgrade/skuba_upgrade-02.feature new file mode 100644 index 0000000..2d7889f --- /dev/null +++ b/features/skuba_upgrade/skuba_upgrade-02.feature @@ -0,0 +1,86 @@ +# TC: https://github.com/SUSE/caasp-test-cases +# PR: https://github.com/SUSE/skuba/pull/911 +# FEATURE: skuba cluster upgrade + +# You are expected to run this test on a cluster bootstrapped with kubernetes-1.16.2 +Feature: Check if cluster upgrade is fine + +Scenario: Checking if cluster exists + Given "skuba" exist in gopath + And VARIABLE "imba-cluster" I get from CONFIG + When I run "skuba cluster status" in VAR:"imba-cluster" directory + Then the output contains "master" and "worker" + Then the output contains "1.16.2" + When I run "kubectl get all --namespace=kube-system" + Then the output contains "cilium" and "dex" + When I run "skuba version" + Then the output contains "v1.2.4" or "v1.3.1" or "1.2.9" + + When I run "skuba cluster upgrade plan" in VAR:"imba-cluster" directory + Then the output contains "current kubernetes" and "latest kubernetes" + #Then the output contains "upgrade path to update" + #Then the output contains "addon upgrades from" + + When I run "zypper -n in skuba-1.3.1" + Then the output contains "installed" + + When I run "skuba cluster upgrade plan" in VAR:"imba-cluster" directory + Then the output contains "current kubernetes" and "latest kubernetes" + #Then the output contains "upgrade path to update" + #Then the output contains "addon upgrades from" + + When I run "skuba addon upgrade apply" in VAR:"imba-cluster" directory + Then the output contains "congratulations" or "ot all" + +Scenario: Applying upgrade on nodes + When I run "kubectl get pods --namespace=kube-system" + And VARIABLE "imba-cluster" I get from CONFIG + When VARIABLE "privileged-pods" equals ContainersFROMOutput "kured-" + And VARIABLES "commandchecks" equals "kubectl describe pod -n kube-system " plus VAR:"privileged-pods" + And I run VARS:"commandchecks" and IPSFromOutput + + #UPGRADING MASTERS FIRST + When VARIABLES "commandupgrades" equals "skuba node upgrade plan " plus Master Nodes + And I run UPGRADE VARS:"commandupgrades" in VAR:"imba-cluster" directory + Then the output contains "apiserver" and "controller-manager" and "scheduler" + And the output contains "etcd" and "kubelet" and "cri-o" + And I run UPGRADE VARS:"commandupgrades" in VAR:"imba-cluster" directory + Then the output contains "apiserver" and "controller-manager" and "scheduler" + And the output contains "etcd" and "kubelet" and "cri-o" + And I run UPGRADE VARS:"commandupgrades" in VAR:"imba-cluster" directory + Then the output contains "apiserver" and "controller-manager" and "scheduler" + And the output contains "etcd" and "kubelet" and "cri-o" + + When VARIABLES "upgradeapply" equals "skuba node upgrade apply --user sles --sudo --target " plus Master Node IPS + And I run UPGRADE VARS:"upgradeapply" in VAR:"imba-cluster" directory + Then the output contains "successfully" or "to date" or "there are addon upgrades available" + And wait "120 seconds" + And I run UPGRADE VARS:"upgradeapply" in VAR:"imba-cluster" directory + Then the output contains "successfully" or "to date" or "there are addon upgrades available" + And wait "120 seconds" + And I run UPGRADE VARS:"upgradeapply" in VAR:"imba-cluster" directory + Then the output contains "successfully" or "to date" or "there are addon upgrades available" + And wait "120 seconds" + +# UPGRADING THEN WORKERS + #Scenario: Upgrading Workers + When VARIABLES "commandupgrades2" equals "skuba node upgrade plan " plus Worker Nodes + And VARIABLE "imba-cluster" I get from CONFIG + And I run UPGRADE VARS:"commandupgrades2" in VAR:"imba-cluster" directory + Then the output contains "kubelet" and "cri-o" + And I run UPGRADE VARS:"commandupgrades2" in VAR:"imba-cluster" directory + Then the output contains "kubelet" and "cri-o" + + When VARIABLES "upgradeapply2" equals "skuba node upgrade apply --user sles --sudo --target " plus Worker Node IPS + And I run UPGRADE VARS:"upgradeapply2" in VAR:"imba-cluster" directory + Then the output contains "successfully" or "to date" or "there are addon upgrades available" + + When I run "skuba addon upgrade apply" in VAR:"imba-cluster" directory + Then the output contains "not all nodes" or "successfully" or "congratulations" + + When VARIABLES "upgradeapply3" equals "skuba node upgrade apply --user sles --sudo --target " plus Worker Node IPS + And I run UPGRADE VARS:"upgradeapply3" in VAR:"imba-cluster" directory + Then the output contains "successfully" or "to date" or "there are addon upgrades available" + + When I run "skuba addon upgrade apply" in VAR:"imba-cluster" directory + Then the output contains "successfully" or "congratulations" From 0ea92486ed0ea35bac64f5ebea1989dd4b9f4019 Mon Sep 17 00:00:00 2001 From: atighineanu Date: Fri, 17 Apr 2020 13:18:58 +0000 Subject: [PATCH 49/50] added check api function --- internal/skuba_upgrade.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/internal/skuba_upgrade.go b/internal/skuba_upgrade.go index dacd40d..b970be8 100644 --- a/internal/skuba_upgrade.go +++ b/internal/skuba_upgrade.go @@ -3,7 +3,10 @@ package features import ( "fmt" "os" + "os/exec" "strings" + "time" + "log" ) func (test *TestRun) VARIABLESEqualsPlusMasterNodes(arg1, arg2 string) error { @@ -62,10 +65,29 @@ func (test *TestRun) VARIABLESEqualsPlusWorkerNodeIPS(arg1, arg2 string) error { return nil } +func (test *TestRun) CheckKubernetesAPI() (bool, error) { +cmdargs := []string{"kubectl", "get", "all", "-n", "kube-system"} +cmd := exec.Command(cmdargs[0], cmdargs[1:]...) +cmd.Dir = test.Config.ClusterDir +output, err := cmd.CombinedOutput() +if err != nil { +log.Printf("Error: %s\n", err) +} +return strings.Contains(fmt.Sprintf("%s", string(output)), "kured"), err +} + func (test *TestRun) IRunUPGRADEVARSInVARDirectory(arg1, arg2 string) error { var err error for key, _ := range test.VarMap { if strings.Contains(key, arg1) && test.UpgradeCheck[key].PlanDone == false { + for { + log.Println("Waiting for k8s API to come back up...") + trigger,_ := test.CheckKubernetesAPI() + if trigger { + break + } + time.Sleep(5 * time.Second) + } //fmt.Printf("Command we run: %s\n", test.VarMap[key]) test.Output = []byte{1} err = test.IRunInDirectory(test.VarMap[key], test.VarMap[arg2]) From 33d82dc4abe9e348b9ee9c2f9dda1db65c314cb1 Mon Sep 17 00:00:00 2001 From: atighineanu Date: Fri, 19 Jun 2020 13:27:37 +0200 Subject: [PATCH 50/50] small fixes --- .../skuba_upgrade/skuba_upgrade-01.feature | 17 +++--- internal/cilium.go | 42 ------------- internal/utilities.go | 60 +++++++++++++++++++ main_test.go | 1 + 4 files changed, 70 insertions(+), 50 deletions(-) diff --git a/features/skuba_upgrade/skuba_upgrade-01.feature b/features/skuba_upgrade/skuba_upgrade-01.feature index d2d130e..dc1dc0a 100644 --- a/features/skuba_upgrade/skuba_upgrade-01.feature +++ b/features/skuba_upgrade/skuba_upgrade-01.feature @@ -21,8 +21,9 @@ Scenario: Checking if cluster exists #Then the output contains "upgrade path to update" #Then the output contains "addon upgrades from" - When I run "skuba addon upgrade apply" in VAR:"imba-cluster" directory - Then the output contains "congratulations" or "not all" + When I run "skuba addon upgrade apply" expecting ERROR:"unknown addon" in VAR:"imba-cluster" directory + Then the error contains "metrics" and " " + Then the output contains "congratulations" or "not all" or "successfully" Scenario: Applying upgrade on nodes When I run "kubectl get pods --namespace=kube-system" @@ -46,13 +47,13 @@ Scenario: Applying upgrade on nodes When VARIABLES "upgradeapply" equals "skuba node upgrade apply --user sles --sudo --target " plus Master Node IPS And I run UPGRADE VARS:"upgradeapply" in VAR:"imba-cluster" directory Then the output contains "successfully" or "to date" or "there are addon upgrades available" - And wait "30 seconds" + And wait "80 seconds" And I run UPGRADE VARS:"upgradeapply" in VAR:"imba-cluster" directory Then the output contains "successfully" or "to date" or "there are addon upgrades available" - And wait "30 seconds" + And wait "80 seconds" And I run UPGRADE VARS:"upgradeapply" in VAR:"imba-cluster" directory Then the output contains "successfully" or "to date" or "there are addon upgrades available" - And wait "30 seconds" + And wait "80 seconds" # UPGRADING THEN WORKERS #Scenario: Upgrading Workers @@ -67,12 +68,12 @@ Scenario: Applying upgrade on nodes And I run UPGRADE VARS:"upgradeapply2" in VAR:"imba-cluster" directory Then the output contains "successfully" or "to date" or "there are addon upgrades available" - When I run "skuba addon upgrade apply" in VAR:"imba-cluster" directory + When I run "skuba addon upgrade apply" expecting ERROR:"unknown addon" in VAR:"imba-cluster" directory Then the output contains "not all nodes" or "successfully" or "congratulations" When VARIABLES "upgradeapply3" equals "skuba node upgrade apply --user sles --sudo --target " plus Worker Node IPS And I run UPGRADE VARS:"upgradeapply3" in VAR:"imba-cluster" directory Then the output contains "successfully" or "to date" or "there are addon upgrades available" - When I run "skuba addon upgrade apply" in VAR:"imba-cluster" directory - Then the output contains "successfully" or "congratulations" + When I run "skuba addon upgrade apply" expecting ERROR:"unknown addon" in VAR:"imba-cluster" directory + Then the output contains "successfully" or "congratulations" or "not all nodes" diff --git a/internal/cilium.go b/internal/cilium.go index 8ef23a6..2977a06 100644 --- a/internal/cilium.go +++ b/internal/cilium.go @@ -2,8 +2,6 @@ package features import ( "fmt" - "os" - "os/exec" "strconv" "strings" ) @@ -79,46 +77,6 @@ func (test *TestRun) TheErrorContainsAnd(arg1, arg2 string) error { return err } -func (test *TestRun) IRunExpectingERROR(arg1 string) error { - var err error - tmp := strings.Split(arg1, " ") - cmd := exec.Command(tmp[0], tmp[1:]...) - output, err := cmd.CombinedOutput() - if err != nil { - if !strings.Contains(fmt.Sprintf("%s", err), "exit") && strings.Contains(fmt.Sprintf("%s", err), "28") { - fmt.Fprintf(os.Stdout, "error: %s", err) - return err - } - } - test.Output = output - test.Err = err - err = nil - return err -} - -func (test *TestRun) IRunVARExpectingERROR(arg1 string) error { - test.IRunExpectingERROR(test.VarMap[arg1]) - return nil -} - -func (test *TestRun) IRunVARExpectingERRORInVARDirectory(arg1, arg2 string) error { - var err error - tmp := strings.Split(arg1, " ") - cmd := exec.Command(tmp[0], tmp[1:]...) - cmd.Dir = arg2 - output, err := cmd.CombinedOutput() - if err != nil { - if !strings.Contains(fmt.Sprintf("%s", err), "exit code") && strings.Contains(fmt.Sprintf("%s", err), "28") { - fmt.Fprintf(os.Stdout, "error: %s", err) - return err - } - } - test.Output = output - test.Err = err - err = nil - return err -} - func (test *TestRun) IRunVARSAndCheckForAnd(arg1, arg2, arg3 string) error { var err error for i := 0; i < 1000; i++ { diff --git a/internal/utilities.go b/internal/utilities.go index e9023ff..8b75b1c 100644 --- a/internal/utilities.go +++ b/internal/utilities.go @@ -5,6 +5,7 @@ import ( "errors" "fmt" "os" + "os/exec" "strings" ) @@ -115,3 +116,62 @@ func (test *TestRun) VARIABLEIGetFromCONFIG(arg1 string) error { fmt.Printf("VAR: %s = %s", arg1, test.VarMap[arg1]) return nil } + +func (test *TestRun) IRunExpectingERRORInVARDirectory(arg1, arg2, arg3 string) error { + var err error + tmp := strings.Split(arg1, " ") + cmd := exec.Command(tmp[0], tmp[1:]...) + cmd.Dir = arg3 + output, err := cmd.CombinedOutput() + if err != nil { + fmt.Printf("ERROR: %v\n grep: %s", err, arg2) + fmt.Printf("OUTPUT: %s\n", fmt.Sprintf("%s", string(output))) + if !strings.Contains(fmt.Sprintf("%s", err), arg2) { + fmt.Fprintf(os.Stdout, "error: %s", err) + return nil + } + } else { + test.Err = err + } + test.Output = output + return nil +} + +func (test *TestRun) IRunVARExpectingERROR(arg1 string) error { + test.IRunExpectingERROR(test.VarMap[arg1]) + return nil +} + +func (test *TestRun) IRunVARExpectingERRORInVARDirectory(arg1, arg2 string) error { + var err error + tmp := strings.Split(test.VarMap[arg1], " ") + cmd := exec.Command(tmp[0], tmp[1:]...) + cmd.Dir = arg2 + output, err := cmd.CombinedOutput() + if err != nil { + if !strings.Contains(fmt.Sprintf("%s", err), "exit code") && strings.Contains(fmt.Sprintf("%s", err), "28") { + fmt.Fprintf(os.Stdout, "error: %s", err) + return err + } + } + test.Output = output + test.Err = err + return nil +} + +func (test *TestRun) IRunExpectingERROR(arg1 string) error { + var err error + tmp := strings.Split(arg1, " ") + cmd := exec.Command(tmp[0], tmp[1:]...) + output, err := cmd.CombinedOutput() + if err != nil { + if !strings.Contains(fmt.Sprintf("%s", err), "exit") && strings.Contains(fmt.Sprintf("%s", err), "28") { + fmt.Fprintf(os.Stdout, "error: %s", err) + return err + } + } + test.Output = output + test.Err = err + err = nil + return err +} diff --git a/main_test.go b/main_test.go index 6a33659..79ebb04 100644 --- a/main_test.go +++ b/main_test.go @@ -127,6 +127,7 @@ func FeatureContext(s *godog.Suite) { s.Step(`^the output contains "([^"]*)"$`, test.TheOutputContains) s.Step(`^I have the correct go version$`, func() error { return test.IRunInDirectory("make go-version-check", "skuba") }) s.Step(`^grep for "([^"]*)"$`, test.GrepFor) + s.Step(`^I run "([^"]*)" expecting ERROR:"([^"]*)" in VAR:"([^"]*)" directory$`, test.IRunExpectingERRORInVARDirectory) //--------------------Cilium-specific test functions----------------------------------------------- s.Step(`^I run VARS:"([^"]*)" and check for "([^"]*)" and "([^"]*)"$`, test.IRunVARSAndCheckForAnd) s.Step(`^VARIABLE "([^"]*)" equals ContainersFROMOutput "([^"]*)"$`, test.VARIABLEEqualsContainersFROMOutput)