-
Notifications
You must be signed in to change notification settings - Fork 127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP]add_scrnario_OCP-71253 #1192
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
//go:build e2e | ||
// +build e2e | ||
|
||
package e2e | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os/exec" | ||
"strings" | ||
"time" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
"github.com/openshift/cluster-etcd-operator/test/e2e/framework" | ||
v1 "k8s.io/api/core/v1" | ||
apierrors "k8s.io/apimachinery/pkg/api/errors" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/util/wait" | ||
) | ||
|
||
var _ = Describe("Etcd master node", Ordered, func() { | ||
BeforeAll(func() { | ||
By("creating Kube clients") | ||
}) | ||
|
||
Context("Etcd backup", func() { | ||
It("Avoid caching etcdctl on cluster-backup.sh OCP-71253", func() { | ||
|
||
By("List master node.") | ||
clientSet := framework.NewClientSet("") | ||
masterNodes, err := clientSet.CoreV1Interface.Nodes().List(context.Background(), metav1.ListOptions{LabelSelector: masterNodeLabel}) | ||
Expect(err).NotTo(HaveOccurred()) | ||
if err != nil { | ||
fmt.Errorf("error while listing master nodes") | ||
} | ||
|
||
By("Create debug pod on first master node") | ||
debugNodeName := masterNodes.Items[0].Name | ||
var debugPodName string | ||
createDebugPod(debugNodeName) | ||
defer func() { | ||
fmt.Println("Remove the debug pod now.") | ||
debugPodStr := strings.Split(fmt.Sprintf("delete pod %s -n default", debugPodName), " ") | ||
_, err := exec.Command("oc", debugPodStr...).CombinedOutput() | ||
Expect(err).NotTo(HaveOccurred()) | ||
}() | ||
|
||
By("Wait for debug pod to be in Running phase.") | ||
err = wait.PollUntilContextTimeout(context.Background(), time.Second, 30*time.Minute, true, func(ctx context.Context) (done bool, err error) { | ||
pods, err := clientSet.CoreV1Interface.Pods(debugNamespace).List(ctx, metav1.ListOptions{}) | ||
if err != nil && !apierrors.IsNotFound(err) { | ||
return false, err | ||
} | ||
|
||
for _, pod := range pods.Items { | ||
if strings.Contains(pod.Name, "debug") && pod.Status.Phase == v1.PodRunning { | ||
debugPodName = pod.Name | ||
return true, nil | ||
} | ||
} | ||
return false, nil | ||
}) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
By("Verify no backup exist") | ||
cmdAsStr := fmt.Sprintf("ls -l /host%s", backupPath) | ||
output, err := exec.Command("oc", getOcArgs(debugPodName, cmdAsStr)...).CombinedOutput() | ||
if !strings.Contains(string(output), "No such file or directory") { | ||
fmt.Errorf("The backup file is exist already." ) | ||
} | ||
|
||
By("Run backup") | ||
cmdAsStr = fmt.Sprintf("chroot /host /bin/bash -euxo pipefail /usr/local/bin/cluster-backup.sh --force %s", backupPath) | ||
output, err = exec.Command("oc", getOcArgs(debugPodName, cmdAsStr)...).CombinedOutput() | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
By("Verify backup created") | ||
cmdAsStr = fmt.Sprintf("find /host%s", backupPath) | ||
output, err = exec.Command("oc", getOcArgs(debugPodName, cmdAsStr)...).CombinedOutput() | ||
Expect(err).NotTo(HaveOccurred()) | ||
files := strings.Split(string(output), "\n") | ||
if !backupFilesFound("backup-happy-path", trimFilesPrefix(files)) { | ||
fmt.Errorf("can't find backup file.") | ||
} | ||
|
||
By("Run backup again, and verify no caching etcdctl") | ||
cmdAsStr = fmt.Sprintf("chroot /host /bin/bash -euxo pipefail /usr/local/bin/cluster-backup.sh --force %s", backupPath) | ||
output, err = exec.Command("oc", getOcArgs(debugPodName, cmdAsStr)...).CombinedOutput() | ||
Expect(err).NotTo(HaveOccurred()) | ||
if !strings.Contains(string(output), "etcdctl is already installed") { | ||
fmt.Errorf("caching etcdctl still exist.") | ||
} | ||
|
||
DeferCleanup(func() { | ||
cmdAsStr = fmt.Sprintf("rm -rf /host%s", backupPath) | ||
output, err1 := exec.Command("oc", getOcArgs(debugPodName, cmdAsStr)...).CombinedOutput() | ||
if err1 != nil { | ||
fmt.Errorf("cleanup failed: %s", string(output)) | ||
} | ||
}) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package e2e | ||
|
||
import ( | ||
"fmt" | ||
"os/exec" | ||
"regexp" | ||
"strings" | ||
|
||
. "github.com/onsi/gomega" | ||
) | ||
|
||
func createDebugPod(debugNodeName string) { | ||
debugArgs := strings.Split(fmt.Sprintf("debug node/%s %s %s", debugNodeName, "--to-namespace=default", "--as-root=true"), " ") | ||
output, err := exec.Command("oc", debugArgs...).CombinedOutput() | ||
if err != nil { | ||
fmt.Errorf("Fail to create debug pod on master node %s with err: %s", debugNodeName, string(output)) | ||
} | ||
} | ||
|
||
// a successful backup will look like this: | ||
// ./backup-backup-happy-path-2023-08-03_152313 | ||
// ./backup-backup-happy-path-2023-08-03_152313/static_kuberesources_2023-08-03_152316__POSSIBLY_DIRTY__.tar.gz | ||
// ./backup-backup-happy-path-2023-08-03_152313/snapshot_2023-08-03_152316__POSSIBLY_DIRTY__.db ] | ||
// we assert that there are always at least two files | ||
|
||
func backupFilesFound(name string, files []string) bool { | ||
var matchesTar, matchesSnap bool | ||
for _, file := range files { | ||
matchesTarTag, err := regexp.MatchString(`\./backup-`+name+`-.*.tar.gz`, file) | ||
Expect(err).NotTo(HaveOccurred()) | ||
if matchesTarTag { | ||
matchesTar = true | ||
} | ||
matchesSnapTag, err := regexp.MatchString(`\./backup-`+name+`-.*/snapshot_.*.db`, file) | ||
Expect(err).NotTo(HaveOccurred()) | ||
if matchesSnapTag { | ||
matchesSnap = true | ||
} | ||
} | ||
if matchesTar { | ||
fmt.Printf("Found matching kube resources.\n") | ||
} else { | ||
fmt.Printf("Can't find matching kube resources.\n") | ||
} | ||
if matchesSnap { | ||
fmt.Printf("Found matching snapshot.\n") | ||
} else { | ||
fmt.Printf("Can't find matching snapshot.\n") | ||
} | ||
|
||
return matchesTar && matchesSnap | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @geliu2016 - dunno if you saw this already, but @Elbehery added a very similar test in test/e2e/backup_script_test.go already. I believe you could reuse almost everything in there to write a testcase for that bug.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, @tjungblu Yes, I saw there is similar test in backup_script_test.go already, and it checking the etcd backup feature with go function mode, and QE's test are focus on more complex scenarios, and QE using ginkgo mod to design test case, as I reviewed other sub component teams' e2e, they are also organize e2e test with go functions(Dev's prefer) and ginkgo(QE's prefer), it could co-exist, and I wish this backup case is a beginning, we will contribute QE's scenarios with this ginkgo framework.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer to have ginkgo tests in origin: https://github.com/openshift/origin/tree/master/test/extended/etcd
Otherwise this causes too much confusion and I don't want to maintain two test frameworks in here.