Skip to content
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

Skip test on NuoDB version #208

Merged
merged 8 commits into from
May 19, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.14

require (
cloud.google.com/go v0.61.0 // indirect
github.com/Masterminds/semver v1.5.0
github.com/aws/aws-sdk-go v1.33.9 // indirect
github.com/ghodss/yaml v1.0.0
github.com/go-errors/errors v1.1.1 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ github.com/Azure/go-autorest/tracing v0.5.0/go.mod h1:r/s2XiOKccPW3HrqB+W0TQzfbt
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/GoogleCloudPlatform/k8s-cloud-provider v0.0.0-20190822182118-27a4ced34534/go.mod h1:iroGtC8B3tQiqtds1l+mgk/BBOrxbqjH+eUfFQYRc14=
github.com/Masterminds/semver v1.5.0 h1:H65muMkzWKEuNDnfl9d70GUjFniHKHRbFPGBuZ3QEww=
github.com/Masterminds/semver v1.5.0/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y=
github.com/Microsoft/go-winio v0.4.14/go.mod h1:qXqCSQ3Xa7+6tgxaGTIe4Kpcdsi+P8jBhyzoq1bpyYA=
github.com/NYTimes/gziphandler v0.0.0-20170623195520-56545f4a5d46/go.mod h1:3wb06e3pkSAbeQ52E9H9iFoQsEEwGN64994WTCIhntQ=
github.com/PuerkitoBio/purell v1.0.0/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0=
Expand Down
10 changes: 10 additions & 0 deletions test/minikube/minikube_long_restore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ func TestKubernetesRestoreWithStorageGroups(t *testing.T) {
if os.Getenv("NUODB_LICENSE") != "ENTERPRISE" && os.Getenv("NUODB_LICENSE_CONTENT") == "" {
t.Skip("Cannot test multiple SMs without the Enterprise Edition")
}
testlib.SkipTestOnNuoDBVersionCondition(t, "< 4.2")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

love it!

testlib.AwaitTillerUp(t)
defer testlib.VerifyTeardown(t)
defer testlib.Teardown(testlib.TEARDOWN_ADMIN)
Expand Down Expand Up @@ -186,6 +187,7 @@ func TestKubernetesRestoreWithStorageGroups(t *testing.T) {
smPodNameTemplate := fmt.Sprintf("sm-%s-nuodb-%s-%s", databaseChartName, opt.ClusterName, opt.DbName)
hcSmPodNameTemplate := fmt.Sprintf("%s-hotcopy", smPodNameTemplate)
hcSmPodName0 := fmt.Sprintf("%s-0", hcSmPodNameTemplate)
hcSmPodName1 := fmt.Sprintf("%s-1", hcSmPodNameTemplate)

// Create 2 storage groups, each served by only one archive
k8s.RunKubectl(t, kubectlOptions, "exec", admin0, "--",
Expand Down Expand Up @@ -220,13 +222,21 @@ func TestKubernetesRestoreWithStorageGroups(t *testing.T) {
tePodName := testlib.GetPodName(t, namespaceName, tePodNameTemplate)
go testlib.GetAppLog(t, namespaceName, tePodName, "_pre-restart", &corev1.PodLogOptions{Follow: true})
go testlib.GetAppLog(t, namespaceName, hcSmPodName0, "_pre-restart", &corev1.PodLogOptions{Follow: true})
go testlib.GetAppLog(t, namespaceName, hcSmPodName1, "_pre-restart", &corev1.PodLogOptions{Follow: true})

defer testlib.Teardown(testlib.TEARDOWN_RESTORE)

// Get SM pod logs if the test fails
testlib.AddDiagnosticTeardown(testlib.TEARDOWN_DATABASE, t, func() {
testlib.GetAppLog(t, namespaceName, hcSmPodName0, "_post-restore", &corev1.PodLogOptions{})
testlib.GetAppLog(t, namespaceName, hcSmPodName1, "_post-restore", &corev1.PodLogOptions{})
})

// restore database
databaseOptions.SetValues["restore.source"] = backupset
testlib.RestoreDatabase(t, namespaceName, admin0, &databaseOptions)
testlib.AwaitPodLog(t, namespaceName, hcSmPodName0, "_post-restart")
testlib.AwaitPodLog(t, namespaceName, hcSmPodName1, "_post-restart")

// verify that the database does NOT contain the data from AFTER the backup

Expand Down
53 changes: 53 additions & 0 deletions test/testlib/nuodb_database_utilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os"
"path"
"path/filepath"
"regexp"
"strconv"
"strings"
"testing"
Expand All @@ -14,6 +15,7 @@ import (
corev1 "k8s.io/api/core/v1"
v12 "k8s.io/api/core/v1"

"github.com/Masterminds/semver"
"github.com/gruntwork-io/terratest/modules/helm"
"github.com/gruntwork-io/terratest/modules/k8s"
"github.com/gruntwork-io/terratest/modules/random"
Expand Down Expand Up @@ -355,3 +357,54 @@ func ServePodFileViaHTTP(t *testing.T, namespaceName string, srcPodName string,
k8s.RunKubectl(t, kubectlOptions, "cp", localFilePath, nginxPod+":/usr/share/nginx/html/"+fileName)
return fmt.Sprintf("http://nginx.%s.svc.cluster.local/%s", namespaceName, fileName)
}

func GetNuoDBVersion(t *testing.T, options *helm.Options) string {
kubectlOptions := k8s.NewKubectlOptions("", "", "default")
sivanov-nuodb marked this conversation as resolved.
Show resolved Hide resolved
podName := "nuodb-version"
InferVersionFromTemplate(t, options)
InjectTestValues(t, options)
defer func() {
// Delete the pod just in case "--rm" doesn't do it
k8s.RunKubectlE(t, kubectlOptions, "delete", "pod", podName)
}()
nuodbImage := fmt.Sprintf(
"%s/%s:%s",
options.SetValues["nuodb.image.registry"],
options.SetValues["nuodb.image.repository"],
options.SetValues["nuodb.image.tag"])
output, err := k8s.RunKubectlAndGetOutputE(
t, kubectlOptions, "run", podName,
"--image", nuodbImage, "--restart=Never", "--rm", "--attach", "--command", "--",
"nuodb", "--version")
require.NoError(t, err, "Unable to check NuoDB version in helper pod")
match := regexp.MustCompile("NuoDB Server build (.*)").FindStringSubmatch(output)
require.NotNil(t, match, "Unable to match NuoDB version from output")
return match[1]
}

func SkipTestOnNuoDBVersion(t *testing.T, versionCheckFunc func(*semver.Version) bool) {
versionString := GetNuoDBVersion(t, &helm.Options{})
// Select only the main NuoDB version (i.e 4.2.1) from the full version string
versionString = regexp.MustCompile(`^([0-9]+\.[0-9]+(?:\.[0-9]+)?).*$`).
ReplaceAllString(versionString, "${1}")
version, err := semver.NewVersion(versionString)
require.NoError(t, err, "Unable to parse NuoDB version", versionString)
if versionCheckFunc(version) {
t.Skip("Skipping test when using NuoDB version", version)
}
}

/**
* Skip test if NuoDB version matches the provided condition.
*
* For more information about supported condition strings, please
* check https://github.com/Masterminds/semver.
*
*/
func SkipTestOnNuoDBVersionCondition(t *testing.T, condition string) {
SkipTestOnNuoDBVersion(t, func(version *semver.Version) bool {
c, err := semver.NewConstraint(condition)
require.NoError(t, err)
return c.Check(version)
})
}