Skip to content

Commit

Permalink
Move upgrade repository test function
Browse files Browse the repository at this point in the history
  • Loading branch information
chaitalisg committed Aug 22, 2022
1 parent 708074f commit f8f89e4
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 28 deletions.
9 changes: 3 additions & 6 deletions tests/robustness/robustness_test/main_test.go
Expand Up @@ -57,18 +57,15 @@ func TestMain(m *testing.M) {
if os.Getenv("UPGRADE_REPOSITORY_FORMAT_VERSION") == "ON" {
log.Print("Upgrading the repository.")

err := th.upgrader.ConnectRepo("filesystem", "--path="+dataRepoPath)
exitOnError("failed to connect to repository", err)

rs, err := th.upgrader.GetRepositoryStatus()
rs, err := th.snapshotter.GetRepositoryStatus()
exitOnError("failed to get repository status before upgrade", err)

prev := rs.ContentFormat.MutableParameters.Version

log.Println("Old repository format:", prev)
th.upgrader.UpgradeRepository(dataRepoPath)
th.snapshotter.UpgradeRepository()

rs, err = th.upgrader.GetRepositoryStatus()
rs, err = th.snapshotter.GetRepositoryStatus()
exitOnError("failed to get repository status after upgrade", err)

curr := rs.ContentFormat.MutableParameters.Version
Expand Down
22 changes: 22 additions & 0 deletions tests/robustness/snapmeta/kopia_snapshotter.go
Expand Up @@ -5,11 +5,13 @@ package snapmeta

import (
"context"
"encoding/json"
"io"
"log"
"os/exec"
"strconv"

"github.com/kopia/kopia/cli"
"github.com/kopia/kopia/internal/clock"
"github.com/kopia/kopia/tests/robustness"
"github.com/kopia/kopia/tests/tools/fswalker"
Expand Down Expand Up @@ -178,3 +180,23 @@ func (ks *KopiaSnapshotter) ConnectOrCreateFilesystemWithServer(serverAddr, repo
func (ks *KopiaSnapshotter) Cleanup() {
ks.snap.Cleanup()
}

// GetRepositoryStatus returns the repository status in JSON format.
func (ks *KopiaSnapshotter) GetRepositoryStatus() (cli.RepositoryStatus, error) {
a1, _, _ := ks.snap.Run("repository", "status", "--json")

var rs cli.RepositoryStatus
if err := json.Unmarshal([]byte(a1), &rs); err != nil {
return rs, err
}

return rs, nil
}

// UpgradeRepository upgrades the given kopia repository
// from current format version to latest stable format version.
func (ks *KopiaSnapshotter) UpgradeRepository() error {
_, _, err := ks.snap.Run("repository", "set-parameters", "--upgrade")

return err
}
22 changes: 0 additions & 22 deletions tests/tools/kopiarunner/kopia_snapshotter.go
Expand Up @@ -5,7 +5,6 @@ import (
"crypto/sha256"
"crypto/x509"
"encoding/hex"
"encoding/json"
"encoding/pem"
"fmt"
"os"
Expand All @@ -18,7 +17,6 @@ import (

"github.com/pkg/errors"

"github.com/kopia/kopia/cli"
"github.com/kopia/kopia/internal/retry"
)

Expand Down Expand Up @@ -481,23 +479,3 @@ func certKeyExist(ctx context.Context, tlsCertFile, tlsKeyFile string) error {
func errIsACLEnabled(stdErr string) bool {
return strings.Contains(stdErr, aclEnabledMatchStr)
}

// GetRepositoryStatus returns the repository status in JSON format.
func (ks *KopiaSnapshotter) GetRepositoryStatus() (cli.RepositoryStatus, error) {
a1, _, _ := ks.Runner.Run("repository", "status", "--json")

var rs cli.RepositoryStatus
if err := json.Unmarshal([]byte(a1), &rs); err != nil {
return rs, err
}

return rs, nil
}

// UpgradeRepository upgrades the given kopia repository
// from current format version to latest stable format version.
func (ks *KopiaSnapshotter) UpgradeRepository(repoPath string) error {
_, _, err := ks.Runner.Run("repository", "set-parameters", "--upgrade")

return err
}

0 comments on commit f8f89e4

Please sign in to comment.