Skip to content

Commit

Permalink
test(upgrade): add v20.11 upgrade tests in query package (#8954)
Browse files Browse the repository at this point in the history
  • Loading branch information
mangalaman93 authored Aug 16, 2023
1 parent 8631dab commit 7793eb3
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 17 deletions.
29 changes: 29 additions & 0 deletions dgraphtest/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ func (hc *HTTPClient) LoginUsingToken(ns uint64) error {
}

func (hc *HTTPClient) LoginIntoNamespace(user, password string, ns uint64) error {
// This is useful for v20.11 which does not support multi-tenancy
if ns == 0 {
return hc.LoginIntoNamespaceV20(user, password)
}

q := `mutation login($userId: String, $password: String, $namespace: Int) {
login(userId: $userId, password: $password, namespace: $namespace) {
response {
Expand All @@ -158,6 +163,30 @@ func (hc *HTTPClient) LoginIntoNamespace(user, password string, ns uint64) error
return hc.doLogin(params, true)
}

func (hc *HTTPClient) LoginIntoNamespaceV20(user, password string) error {
q := `mutation login($userId: String, $password: String) {
login(userId: $userId, password: $password) {
response {
accessJWT
refreshJWT
}
}
}`
params := GraphQLParams{
Query: q,
Variables: map[string]interface{}{
"userId": user,
"password": password,
},
}

hc.HttpToken = &HttpToken{
UserId: user,
Password: password,
}
return hc.doLogin(params, true)
}

func (hc *HTTPClient) doLogin(params GraphQLParams, isAdmin bool) error {
resp, err := hc.RunGraphqlQuery(params, isAdmin)
if err != nil {
Expand Down
8 changes: 7 additions & 1 deletion dgraphtest/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type UpgradeCombo struct {
Strategy UpgradeStrategy
}

func AllUpgradeCombos() []UpgradeCombo {
func AllUpgradeCombos(v20 bool) []UpgradeCombo {
fixedVersionCombos := []UpgradeCombo{
// OPEN SOURCE RELEASES
{"v21.03.0", "v23.0.1", BackupRestore},
Expand Down Expand Up @@ -66,6 +66,12 @@ func AllUpgradeCombos() []UpgradeCombo {
{"0c9f60156", "v23.0.1", InPlace}, // v21.03.0-92-g0c9f60156
}

if v20 {
fixedVersionCombos = append(fixedVersionCombos, []UpgradeCombo{
{"v20.11.3", localVersion, BackupRestore},
}...)
}

mainCombos := []UpgradeCombo{
{"v23.0.1", localVersion, BackupRestore},
{"v23.0.1", localVersion, InPlace},
Expand Down
33 changes: 26 additions & 7 deletions dgraphtest/dgraph.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,14 @@ func (z *zero) bindings(offset int) nat.PortMap {

func (z *zero) cmd(c *LocalCluster) []string {
zcmd := []string{"/gobin/dgraph", "zero", fmt.Sprintf("--my=%s:%v", z.aname(), zeroGrpcPort), "--bindall",
fmt.Sprintf(`--replicas=%v`, c.conf.replicas), fmt.Sprintf(`--raft=idx=%v`, z.id+1), "--logtostderr",
fmt.Sprintf("-v=%d", c.conf.verbosity),
fmt.Sprintf(`--limit=refill-interval=%v;uid-lease=%v`, c.conf.refillInterval, c.conf.uidLease)}
fmt.Sprintf(`--replicas=%v`, c.conf.replicas), "--logtostderr", fmt.Sprintf("-v=%d", c.conf.verbosity)}

if c.lowerThanV21 {
zcmd = append(zcmd, fmt.Sprintf(`--idx=%v`, z.id+1))
} else {
zcmd = append(zcmd, fmt.Sprintf(`--raft=idx=%v`, z.id+1),
fmt.Sprintf(`--limit=refill-interval=%v;uid-lease=%v`, c.conf.refillInterval, c.conf.uidLease))
}

if z.id > 0 {
zcmd = append(zcmd, "--peer="+c.zeros[0].aname()+":"+zeroGrpcPort)
Expand Down Expand Up @@ -227,14 +232,28 @@ func (a *alpha) bindings(offset int) nat.PortMap {

func (a *alpha) cmd(c *LocalCluster) []string {
acmd := []string{"/gobin/dgraph", "alpha", fmt.Sprintf("--my=%s:%v", a.aname(), alphaInterPort),
"--bindall", "--logtostderr", fmt.Sprintf("-v=%d", c.conf.verbosity),
`--security=whitelist=10.0.0.0/8,172.16.0.0/12,192.168.0.0/16`}
"--bindall", "--logtostderr", fmt.Sprintf("-v=%d", c.conf.verbosity)}

if c.lowerThanV21 {
acmd = append(acmd, `--whitelist=10.0.0.0/8,172.16.0.0/12,192.168.0.0/16`)
} else {
acmd = append(acmd, `--security=whitelist=10.0.0.0/8,172.16.0.0/12,192.168.0.0/16`)
}

if c.conf.acl {
acmd = append(acmd, fmt.Sprintf(`--acl=secret-file=%s;access-ttl=%s`, aclSecretMountPath, c.conf.aclTTL))
if c.lowerThanV21 {
acmd = append(acmd, fmt.Sprintf(`--acl_secret_file=%s`, aclSecretMountPath),
fmt.Sprintf(`--acl_access_ttl=%s`, c.conf.aclTTL))
} else {
acmd = append(acmd, fmt.Sprintf(`--acl=secret-file=%s;access-ttl=%s`, aclSecretMountPath, c.conf.aclTTL))
}
}
if c.conf.encryption {
acmd = append(acmd, fmt.Sprintf(`--encryption=key-file=%v`, encKeyMountPath))
if c.lowerThanV21 {
acmd = append(acmd, fmt.Sprintf(`--encryption_key_file=%v`, encKeyMountPath))
} else {
acmd = append(acmd, fmt.Sprintf(`--encryption=key-file=%v`, encKeyMountPath))
}
}

zeroAddrsArg, delimiter := "--zero=", ""
Expand Down
35 changes: 30 additions & 5 deletions dgraphtest/local_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ type cnet struct {

// LocalCluster is a local dgraph cluster
type LocalCluster struct {
conf ClusterConfig
tempBinDir string
conf ClusterConfig
tempBinDir string
lowerThanV21 bool

// resources
dcli *docker.Client
Expand Down Expand Up @@ -115,6 +116,12 @@ func (c *LocalCluster) init() error {
return errors.Wrap(err, "error while making binDir")
}

higher, err := IsHigherVersion(c.GetVersion(), "v21.03.0")
if err != nil {
return errors.Wrapf(err, "error checking if version %s is older than v21.03.0", c.GetVersion())
}
c.lowerThanV21 = !higher

for _, vol := range c.conf.volumes {
if err := c.createVolume(vol); err != nil {
return err
Expand Down Expand Up @@ -492,6 +499,18 @@ func (c *LocalCluster) recreateContainers() error {
return nil
}

func (c *LocalCluster) changeVersion(version string) error {
c.conf.version = version

higher, err := IsHigherVersion(c.GetVersion(), "v21.03.0")
if err != nil {
return errors.Wrapf(err, "error checking if version %s is older than v21.03.0", c.GetVersion())
}
c.lowerThanV21 = !higher

return nil
}

// Upgrades the cluster to the provided dgraph version
func (c *LocalCluster) Upgrade(version string, strategy UpgradeStrategy) error {
if version == c.conf.version {
Expand All @@ -517,7 +536,9 @@ func (c *LocalCluster) Upgrade(version string, strategy UpgradeStrategy) error {
return err
}

c.conf.version = version
if err := c.changeVersion(version); err != nil {
return err
}
if err := c.setupBinary(); err != nil {
return err
}
Expand Down Expand Up @@ -567,7 +588,9 @@ func (c *LocalCluster) Upgrade(version string, strategy UpgradeStrategy) error {
return err
}

c.conf.version = version
if err := c.changeVersion(version); err != nil {
return err
}
if err := c.setupBinary(); err != nil {
return err
}
Expand All @@ -586,7 +609,9 @@ func (c *LocalCluster) Upgrade(version string, strategy UpgradeStrategy) error {
if err := c.Stop(); err != nil {
return err
}
c.conf.version = version
if err := c.changeVersion(version); err != nil {
return err
}
if err := c.setupBinary(); err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion ee/acl/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (asuite *AclTestSuite) Upgrade() {
}

func TestACLSuite(t *testing.T) {
for _, uc := range dgraphtest.AllUpgradeCombos() {
for _, uc := range dgraphtest.AllUpgradeCombos(false) {
log.Printf("running upgrade tests for confg: %+v", uc)
aclSuite := AclTestSuite{uc: uc}
suite.Run(t, &aclSuite)
Expand Down
2 changes: 1 addition & 1 deletion query/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func TestMain(m *testing.M) {
}
}

for _, uc := range dgraphtest.AllUpgradeCombos() {
for _, uc := range dgraphtest.AllUpgradeCombos(true) {
log.Printf("running upgrade tests for confg: %+v", uc)
runTest(uc)
}
Expand Down
2 changes: 1 addition & 1 deletion systest/license/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (lsuite *LicenseTestSuite) Upgrade() {
}

func TestLicenseTestSuite(t *testing.T) {
for _, uc := range dgraphtest.AllUpgradeCombos() {
for _, uc := range dgraphtest.AllUpgradeCombos(false) {
log.Printf("running: backup in [%v], restore in [%v]", uc.Before, uc.After)
var tsuite LicenseTestSuite
tsuite.uc = uc
Expand Down
2 changes: 1 addition & 1 deletion systest/multi-tenancy/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (msuite *MultitenancyTestSuite) Upgrade() {
}

func TestMultitenancySuite(t *testing.T) {
for _, uc := range dgraphtest.AllUpgradeCombos() {
for _, uc := range dgraphtest.AllUpgradeCombos(false) {
log.Printf("running upgrade tests for confg: %+v", uc)
var msuite MultitenancyTestSuite
msuite.uc = uc
Expand Down

0 comments on commit 7793eb3

Please sign in to comment.