refactor: import dependancy from upgrade module to cosmovisor module (#10442)
<!-- The default pull request template is for types feat, fix, or refactor. For other templates, add one of the following parameters to the url: - template=docs.md - template=other.md --> ## Description Closes: #10378 Cosmovisor module copies the data type `UpgradeInfo` and constant `upgradeFilename` from upgrade module to cosmovisor module. This pr will directly import the datatype and const from cosmos-sdk/upgrade module: `UpgradeInfo` -> `upgradetypes.Plan` `upgradeFilename` -> `upgradekeeper.UpgradeInfoFilename` <!-- Add a description of the changes that this PR introduces and the files that are the most critical to review. --> --- ### Author Checklist *All items are required. Please add a note to the item if the item is not applicable and please add links to any relevant follow up issues.* I have... - [x] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] added `!` to the type prefix if API or client breaking change - [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting)) - [ ] provided a link to the relevant issue or specification - [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules) - [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing) - [ ] added a changelog entry to `CHANGELOG.md` - [ ] included comments for [documenting Go code](https://blog.golang.org/godoc) - [ ] updated the relevant documentation or specification - [ ] reviewed "Files changed" and left comments if necessary - [ ] confirmed all CI checks have passed ### Reviewers Checklist *All items are required. Please add a note if the item is not applicable and please add your handle next to the items reviewed if you only reviewed selected items.* I have... - [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] confirmed `!` in the type prefix if API or client breaking change - [ ] confirmed all author checklist items have been addressed - [ ] reviewed state machine logic - [ ] reviewed API design and naming - [ ] reviewed documentation is accurate - [ ] reviewed tests and test coverage - [ ] manually tested (if applicable)
This commit is contained in:
parent
3e2b203097
commit
23942663d9
|
@ -14,6 +14,8 @@ import (
|
|||
"github.com/rs/zerolog"
|
||||
|
||||
cverrors "github.com/cosmos/cosmos-sdk/cosmovisor/errors"
|
||||
upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper"
|
||||
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
|
||||
)
|
||||
|
||||
// environment variable names
|
||||
|
@ -32,7 +34,6 @@ const (
|
|||
genesisDir = "genesis"
|
||||
upgradesDir = "upgrades"
|
||||
currentLink = "current"
|
||||
upgradeFilename = "upgrade-info.json"
|
||||
)
|
||||
|
||||
// must be the same as x/upgrade/types.UpgradeInfoFilename
|
||||
|
@ -49,7 +50,7 @@ type Config struct {
|
|||
PreupgradeMaxRetries int
|
||||
|
||||
// currently running upgrade
|
||||
currentUpgrade UpgradeInfo
|
||||
currentUpgrade upgradetypes.Plan
|
||||
}
|
||||
|
||||
// Root returns the root directory where all info lives
|
||||
|
@ -220,7 +221,7 @@ func (cfg *Config) validate() []error {
|
|||
}
|
||||
|
||||
// SetCurrentUpgrade sets the named upgrade to be the current link, returns error if this binary doesn't exist
|
||||
func (cfg *Config) SetCurrentUpgrade(u UpgradeInfo) error {
|
||||
func (cfg *Config) SetCurrentUpgrade(u upgradetypes.Plan) error {
|
||||
// ensure named upgrade exists
|
||||
bin := cfg.UpgradeBin(u.Name)
|
||||
|
||||
|
@ -244,7 +245,7 @@ func (cfg *Config) SetCurrentUpgrade(u UpgradeInfo) error {
|
|||
}
|
||||
|
||||
cfg.currentUpgrade = u
|
||||
f, err := os.Create(filepath.Join(upgrade, upgradeFilename))
|
||||
f, err := os.Create(filepath.Join(upgrade, upgradekeeper.UpgradeInfoFileName))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -258,14 +259,14 @@ func (cfg *Config) SetCurrentUpgrade(u UpgradeInfo) error {
|
|||
return f.Close()
|
||||
}
|
||||
|
||||
func (cfg *Config) UpgradeInfo() UpgradeInfo {
|
||||
func (cfg *Config) UpgradeInfo() upgradetypes.Plan {
|
||||
if cfg.currentUpgrade.Name != "" {
|
||||
return cfg.currentUpgrade
|
||||
}
|
||||
|
||||
filename := filepath.Join(cfg.Root(), currentLink, upgradeFilename)
|
||||
filename := filepath.Join(cfg.Root(), currentLink, upgradekeeper.UpgradeInfoFileName)
|
||||
_, err := os.Lstat(filename)
|
||||
var u UpgradeInfo
|
||||
var u upgradetypes.Plan
|
||||
var bz []byte
|
||||
if err != nil { // no current directory
|
||||
goto returnError
|
||||
|
|
|
@ -3,9 +3,11 @@ module github.com/cosmos/cosmos-sdk/cosmovisor
|
|||
go 1.17
|
||||
|
||||
require (
|
||||
github.com/cosmos/cosmos-sdk v0.44.3
|
||||
github.com/hashicorp/go-cleanhttp v0.5.1 // indirect
|
||||
github.com/hashicorp/go-getter v1.4.1
|
||||
github.com/otiai10/copy v1.4.2
|
||||
github.com/otiai10/copy v1.6.0
|
||||
github.com/rs/zerolog v1.25.0
|
||||
github.com/stretchr/testify v1.7.0
|
||||
google.golang.org/api v0.44.0 // indirect
|
||||
google.golang.org/genproto v0.0.0-20210602131652-f16073e35f0c // indirect
|
||||
|
@ -15,31 +17,112 @@ require (
|
|||
require (
|
||||
cloud.google.com/go v0.81.0 // indirect
|
||||
cloud.google.com/go/storage v1.10.0 // indirect
|
||||
github.com/aws/aws-sdk-go v1.15.78 // indirect
|
||||
filippo.io/edwards25519 v1.0.0-beta.2 // indirect
|
||||
github.com/99designs/keyring v1.1.6 // indirect
|
||||
github.com/ChainSafe/go-schnorrkel v0.0.0-20200405005733-88cbf1b4c40d // indirect
|
||||
github.com/DataDog/zstd v1.4.5 // indirect
|
||||
github.com/armon/go-metrics v0.3.9 // indirect
|
||||
github.com/aws/aws-sdk-go v1.27.0 // indirect
|
||||
github.com/beorn7/perks v1.0.1 // indirect
|
||||
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect
|
||||
github.com/bgentry/speakeasy v0.1.0 // indirect
|
||||
github.com/btcsuite/btcd v0.22.0-beta // indirect
|
||||
github.com/cespare/xxhash v1.1.0 // indirect
|
||||
github.com/cespare/xxhash/v2 v2.1.1 // indirect
|
||||
github.com/confio/ics23/go v0.6.6 // indirect
|
||||
github.com/cosmos/go-bip39 v1.0.0 // indirect
|
||||
github.com/cosmos/iavl v0.17.1 // indirect
|
||||
github.com/cosmos/ledger-cosmos-go v0.11.1 // indirect
|
||||
github.com/cosmos/ledger-go v0.9.2 // indirect
|
||||
github.com/danieljoos/wincred v1.0.2 // indirect
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/dgraph-io/badger/v2 v2.2007.2 // indirect
|
||||
github.com/dgraph-io/ristretto v0.0.3 // indirect
|
||||
github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13 // indirect
|
||||
github.com/dustin/go-humanize v1.0.0 // indirect
|
||||
github.com/dvsekhvalnov/jose2go v0.0.0-20200901110807-248326c1351b // indirect
|
||||
github.com/enigmampc/btcutil v1.0.3-0.20200723161021-e2fb6adb2a25 // indirect
|
||||
github.com/fsnotify/fsnotify v1.4.9 // indirect
|
||||
github.com/go-kit/kit v0.10.0 // indirect
|
||||
github.com/go-logfmt/logfmt v0.5.0 // indirect
|
||||
github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 // indirect
|
||||
github.com/gogo/protobuf v1.3.3 // indirect
|
||||
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect
|
||||
github.com/golang/protobuf v1.5.2 // indirect
|
||||
github.com/golang/snappy v0.0.3-0.20201103224600-674baa8c7fc3 // indirect
|
||||
github.com/google/btree v1.0.0 // indirect
|
||||
github.com/googleapis/gax-go/v2 v2.0.5 // indirect
|
||||
github.com/gorilla/mux v1.8.0 // indirect
|
||||
github.com/gorilla/websocket v1.4.2 // indirect
|
||||
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 // indirect
|
||||
github.com/grpc-ecosystem/grpc-gateway v1.16.0 // indirect
|
||||
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c // indirect
|
||||
github.com/gtank/merlin v0.1.1 // indirect
|
||||
github.com/gtank/ristretto255 v0.1.2 // indirect
|
||||
github.com/hashicorp/go-immutable-radix v1.0.0 // indirect
|
||||
github.com/hashicorp/go-safetemp v1.0.0 // indirect
|
||||
github.com/hashicorp/go-version v1.1.0 // indirect
|
||||
github.com/jmespath/go-jmespath v0.0.0-20160202185014-0b12d6b521d8 // indirect
|
||||
github.com/hashicorp/go-version v1.2.0 // indirect
|
||||
github.com/hashicorp/golang-lru v0.5.4 // indirect
|
||||
github.com/hashicorp/hcl v1.0.0 // indirect
|
||||
github.com/hdevalence/ed25519consensus v0.0.0-20210204194344-59a8610d2b87 // indirect
|
||||
github.com/inconshreveable/mousetrap v1.0.0 // indirect
|
||||
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af // indirect
|
||||
github.com/jmhodges/levigo v1.0.0 // indirect
|
||||
github.com/jstemmer/go-junit-report v0.9.1 // indirect
|
||||
github.com/mitchellh/go-homedir v1.0.0 // indirect
|
||||
github.com/keybase/go-keychain v0.0.0-20190712205309-48d3d31d256d // indirect
|
||||
github.com/libp2p/go-buffer-pool v0.0.2 // indirect
|
||||
github.com/magiconair/properties v1.8.5 // indirect
|
||||
github.com/mattn/go-isatty v0.0.14 // indirect
|
||||
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
|
||||
github.com/mimoo/StrobeGo v0.0.0-20181016162300-f8f6d4d2b643 // indirect
|
||||
github.com/mitchellh/go-homedir v1.1.0 // indirect
|
||||
github.com/mitchellh/go-testing-interface v1.0.0 // indirect
|
||||
github.com/mitchellh/mapstructure v1.4.1 // indirect
|
||||
github.com/mtibben/percent v0.2.1 // indirect
|
||||
github.com/pelletier/go-toml v1.9.3 // indirect
|
||||
github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5 // indirect
|
||||
github.com/pkg/errors v0.9.1 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
github.com/rs/zerolog v1.25.0 // indirect
|
||||
github.com/prometheus/client_golang v1.11.0 // indirect
|
||||
github.com/prometheus/client_model v0.2.0 // indirect
|
||||
github.com/prometheus/common v0.29.0 // indirect
|
||||
github.com/prometheus/procfs v0.6.0 // indirect
|
||||
github.com/rcrowley/go-metrics v0.0.0-20200313005456-10cdbea86bc0 // indirect
|
||||
github.com/regen-network/cosmos-proto v0.3.1 // indirect
|
||||
github.com/sasha-s/go-deadlock v0.2.1-0.20190427202633-1595213edefa // indirect
|
||||
github.com/spf13/afero v1.6.0 // indirect
|
||||
github.com/spf13/cast v1.3.1 // indirect
|
||||
github.com/spf13/cobra v1.2.1 // indirect
|
||||
github.com/spf13/jwalterweatherman v1.1.0 // indirect
|
||||
github.com/spf13/pflag v1.0.5 // indirect
|
||||
github.com/spf13/viper v1.8.1 // indirect
|
||||
github.com/subosito/gotenv v1.2.0 // indirect
|
||||
github.com/syndtr/goleveldb v1.0.1-0.20200815110645-5c35d600f0ca // indirect
|
||||
github.com/tecbot/gorocksdb v0.0.0-20191217155057-f0fad39f321c // indirect
|
||||
github.com/tendermint/btcd v0.1.1 // indirect
|
||||
github.com/tendermint/crypto v0.0.0-20191022145703-50d29ede1e15 // indirect
|
||||
github.com/tendermint/go-amino v0.16.0 // indirect
|
||||
github.com/tendermint/tendermint v0.34.14 // indirect
|
||||
github.com/tendermint/tm-db v0.6.4 // indirect
|
||||
github.com/ulikunitz/xz v0.5.5 // indirect
|
||||
github.com/zondax/hid v0.9.0 // indirect
|
||||
go.etcd.io/bbolt v1.3.5 // indirect
|
||||
go.opencensus.io v0.23.0 // indirect
|
||||
golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a // indirect
|
||||
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 // indirect
|
||||
golang.org/x/mod v0.4.2 // indirect
|
||||
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4 // indirect
|
||||
golang.org/x/oauth2 v0.0.0-20210402161424-2e8d93401602 // indirect
|
||||
golang.org/x/sys v0.0.0-20210510120138-977fb7262007 // indirect
|
||||
golang.org/x/text v0.3.5 // indirect
|
||||
golang.org/x/net v0.0.0-20210903162142-ad29c8ab022f // indirect
|
||||
golang.org/x/oauth2 v0.0.0-20210514164344-f6687ab2804c // indirect
|
||||
golang.org/x/sys v0.0.0-20210903071746-97244b99971b // indirect
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 // indirect
|
||||
golang.org/x/text v0.3.6 // indirect
|
||||
golang.org/x/tools v0.1.5 // indirect
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
|
||||
google.golang.org/appengine v1.6.7 // indirect
|
||||
google.golang.org/grpc v1.38.0 // indirect
|
||||
google.golang.org/protobuf v1.26.0 // indirect
|
||||
google.golang.org/grpc v1.40.0 // indirect
|
||||
google.golang.org/protobuf v1.27.1 // indirect
|
||||
gopkg.in/ini.v1 v1.62.0 // indirect
|
||||
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||
)
|
||||
|
||||
replace github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -14,6 +14,8 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/otiai10/copy"
|
||||
|
||||
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
|
||||
)
|
||||
|
||||
type Launcher struct {
|
||||
|
@ -111,7 +113,7 @@ func doBackup(cfg *Config) error {
|
|||
// take backup if `UNSAFE_SKIP_BACKUP` is not set.
|
||||
if !cfg.UnsafeSkipBackup {
|
||||
// check if upgrade-info.json is not empty.
|
||||
var uInfo UpgradeInfo
|
||||
var uInfo upgradetypes.Plan
|
||||
upgradeInfoFile, err := os.ReadFile(filepath.Join(cfg.Home, "data", "upgrade-info.json"))
|
||||
if err != nil {
|
||||
return fmt.Errorf("error while reading upgrade-info.json: %w", err)
|
||||
|
@ -192,7 +194,7 @@ func executePreUpgradeCmd(cfg *Config) error {
|
|||
}
|
||||
|
||||
// IsSkipUpgradeHeight checks if pre-upgrade script must be run. If the height in the upgrade plan matches any of the heights provided in --safe-skip-upgrade, the script is not run
|
||||
func IsSkipUpgradeHeight(args []string, upgradeInfo UpgradeInfo) bool {
|
||||
func IsSkipUpgradeHeight(args []string, upgradeInfo upgradetypes.Plan) bool {
|
||||
skipUpgradeHeights := UpgradeSkipHeights(args)
|
||||
for _, h := range skipUpgradeHeights {
|
||||
if h == int(upgradeInfo.Height) {
|
||||
|
|
|
@ -10,6 +10,7 @@ import (
|
|||
"github.com/stretchr/testify/suite"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/cosmovisor"
|
||||
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
|
||||
)
|
||||
|
||||
type processTestSuite struct {
|
||||
|
@ -133,27 +134,27 @@ func (s *processTestSuite) TestLaunchProcessWithDownloads() {
|
|||
func TestSkipUpgrade(t *testing.T) {
|
||||
cases := []struct {
|
||||
args []string
|
||||
upgradeInfo cosmovisor.UpgradeInfo
|
||||
upgradeInfo upgradetypes.Plan
|
||||
expectRes bool
|
||||
}{{
|
||||
args: []string{"appb", "start", "--unsafe-skip-upgrades"},
|
||||
upgradeInfo: cosmovisor.UpgradeInfo{Name: "upgrade1", Info: "some info", Height: 123},
|
||||
upgradeInfo: upgradetypes.Plan{Name: "upgrade1", Info: "some info", Height: 123},
|
||||
expectRes: false,
|
||||
}, {
|
||||
args: []string{"appb", "start", "--unsafe-skip-upgrades", "--abcd"},
|
||||
upgradeInfo: cosmovisor.UpgradeInfo{Name: "upgrade1", Info: "some info", Height: 123},
|
||||
upgradeInfo: upgradetypes.Plan{Name: "upgrade1", Info: "some info", Height: 123},
|
||||
expectRes: false,
|
||||
}, {
|
||||
args: []string{"appb", "start", "--unsafe-skip-upgrades", "10", "--abcd"},
|
||||
upgradeInfo: cosmovisor.UpgradeInfo{Name: "upgrade1", Info: "some info", Height: 11},
|
||||
upgradeInfo: upgradetypes.Plan{Name: "upgrade1", Info: "some info", Height: 11},
|
||||
expectRes: false,
|
||||
}, {
|
||||
args: []string{"appb", "start", "--unsafe-skip-upgrades", "10", "20", "--abcd"},
|
||||
upgradeInfo: cosmovisor.UpgradeInfo{Name: "upgrade1", Info: "some info", Height: 20},
|
||||
upgradeInfo: upgradetypes.Plan{Name: "upgrade1", Info: "some info", Height: 20},
|
||||
expectRes: true,
|
||||
}, {
|
||||
args: []string{"appb", "start", "--unsafe-skip-upgrades", "10", "20", "--abcd", "34"},
|
||||
upgradeInfo: cosmovisor.UpgradeInfo{Name: "upgrade1", Info: "some info", Height: 34},
|
||||
upgradeInfo: upgradetypes.Plan{Name: "upgrade1", Info: "some info", Height: 34},
|
||||
expectRes: false,
|
||||
}}
|
||||
|
||||
|
|
|
@ -7,21 +7,16 @@ import (
|
|||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
)
|
||||
|
||||
// UpgradeInfo is the update details created by `x/upgrade/keeper.DumpUpgradeInfoToDisk`.
|
||||
type UpgradeInfo struct {
|
||||
Name string `json:"name"`
|
||||
Info string `json:"info"`
|
||||
Height uint `json:"height"`
|
||||
}
|
||||
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
|
||||
)
|
||||
|
||||
type fileWatcher struct {
|
||||
// full path to a watched file
|
||||
filename string
|
||||
interval time.Duration
|
||||
|
||||
currentInfo UpgradeInfo
|
||||
currentInfo upgradetypes.Plan
|
||||
lastModTime time.Time
|
||||
cancel chan bool
|
||||
ticker *time.Ticker
|
||||
|
@ -45,7 +40,7 @@ func newUpgradeFileWatcher(filename string, interval time.Duration) (*fileWatche
|
|||
return nil, fmt.Errorf("wrong path, %s must be an existing directory, [%w]", dirname, err)
|
||||
}
|
||||
|
||||
return &fileWatcher{filenameAbs, interval, UpgradeInfo{}, time.Time{}, make(chan bool), time.NewTicker(interval), false, false}, nil
|
||||
return &fileWatcher{filenameAbs, interval, upgradetypes.Plan{}, time.Time{}, make(chan bool), time.NewTicker(interval), false, false}, nil
|
||||
}
|
||||
|
||||
func (fw *fileWatcher) Stop() {
|
||||
|
@ -55,7 +50,7 @@ func (fw *fileWatcher) Stop() {
|
|||
// pools the filesystem to check for new upgrade currentInfo. currentName is the name
|
||||
// of currently running upgrade. The check is rejected if it finds an upgrade with the same
|
||||
// name.
|
||||
func (fw *fileWatcher) MonitorUpdate(currentUpgrade UpgradeInfo) <-chan struct{} {
|
||||
func (fw *fileWatcher) MonitorUpdate(currentUpgrade upgradetypes.Plan) <-chan struct{} {
|
||||
fw.ticker.Reset(fw.interval)
|
||||
done := make(chan struct{})
|
||||
fw.cancel = make(chan bool)
|
||||
|
@ -80,7 +75,7 @@ func (fw *fileWatcher) MonitorUpdate(currentUpgrade UpgradeInfo) <-chan struct{}
|
|||
// CheckUpdate reads update plan from file and checks if there is a new update request
|
||||
// currentName is the name of currently running upgrade. The check is rejected if it finds
|
||||
// an upgrade with the same name.
|
||||
func (fw *fileWatcher) CheckUpdate(currentUpgrade UpgradeInfo) bool {
|
||||
func (fw *fileWatcher) CheckUpdate(currentUpgrade upgradetypes.Plan) bool {
|
||||
if fw.needsUpdate {
|
||||
return true
|
||||
}
|
||||
|
@ -117,8 +112,8 @@ func (fw *fileWatcher) CheckUpdate(currentUpgrade UpgradeInfo) bool {
|
|||
return false
|
||||
}
|
||||
|
||||
func parseUpgradeInfoFile(filename string) (UpgradeInfo, error) {
|
||||
var ui UpgradeInfo
|
||||
func parseUpgradeInfoFile(filename string) (upgradetypes.Plan, error) {
|
||||
var ui upgradetypes.Plan
|
||||
f, err := os.Open(filename)
|
||||
if err != nil {
|
||||
return ui, err
|
||||
|
@ -131,7 +126,7 @@ func parseUpgradeInfoFile(filename string) (UpgradeInfo, error) {
|
|||
}
|
||||
// required values must be set
|
||||
if ui.Height == 0 || ui.Name == "" {
|
||||
return UpgradeInfo{}, fmt.Errorf("invalid upgrade-info.json content. Name and Hight must be not empty. Got: %v", ui)
|
||||
return upgradetypes.Plan{}, fmt.Errorf("invalid upgrade-info.json content. Name and Hight must be not empty. Got: %v", ui)
|
||||
}
|
||||
return ui, err
|
||||
}
|
||||
|
|
|
@ -5,44 +5,46 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
|
||||
)
|
||||
|
||||
func TestParseUpgradeInfoFile(t *testing.T) {
|
||||
cases := []struct {
|
||||
filename string
|
||||
expectUpgrade UpgradeInfo
|
||||
expectUpgrade upgradetypes.Plan
|
||||
expectErr bool
|
||||
}{{
|
||||
filename: "f1-good.json",
|
||||
expectUpgrade: UpgradeInfo{Name: "upgrade1", Info: "some info", Height: 123},
|
||||
expectUpgrade: upgradetypes.Plan{Name: "upgrade1", Info: "some info", Height: 123},
|
||||
expectErr: false,
|
||||
}, {
|
||||
filename: "f2-bad-type.json",
|
||||
expectUpgrade: UpgradeInfo{},
|
||||
expectUpgrade: upgradetypes.Plan{},
|
||||
expectErr: true,
|
||||
}, {
|
||||
filename: "f2-bad-type-2.json",
|
||||
expectUpgrade: UpgradeInfo{},
|
||||
expectUpgrade: upgradetypes.Plan{},
|
||||
expectErr: true,
|
||||
}, {
|
||||
filename: "f3-empty.json",
|
||||
expectUpgrade: UpgradeInfo{},
|
||||
expectUpgrade: upgradetypes.Plan{},
|
||||
expectErr: true,
|
||||
}, {
|
||||
filename: "f4-empty-obj.json",
|
||||
expectUpgrade: UpgradeInfo{},
|
||||
expectUpgrade: upgradetypes.Plan{},
|
||||
expectErr: true,
|
||||
}, {
|
||||
filename: "f5-partial-obj-1.json",
|
||||
expectUpgrade: UpgradeInfo{},
|
||||
expectUpgrade: upgradetypes.Plan{},
|
||||
expectErr: true,
|
||||
}, {
|
||||
filename: "f5-partial-obj-2.json",
|
||||
expectUpgrade: UpgradeInfo{},
|
||||
expectUpgrade: upgradetypes.Plan{},
|
||||
expectErr: true,
|
||||
}, {
|
||||
filename: "unknown.json",
|
||||
expectUpgrade: UpgradeInfo{},
|
||||
expectUpgrade: upgradetypes.Plan{},
|
||||
expectErr: true,
|
||||
}}
|
||||
|
||||
|
|
|
@ -12,12 +12,14 @@ import (
|
|||
|
||||
"github.com/hashicorp/go-getter"
|
||||
"github.com/otiai10/copy"
|
||||
|
||||
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
|
||||
)
|
||||
|
||||
// DoUpgrade will be called after the log message has been parsed and the process has terminated.
|
||||
// We can now make any changes to the underlying directory without interference and leave it
|
||||
// in a state, so we can make a proper restart
|
||||
func DoUpgrade(cfg *Config, info UpgradeInfo) error {
|
||||
func DoUpgrade(cfg *Config, info upgradetypes.Plan) error {
|
||||
// Simplest case is to switch the link
|
||||
err := EnsureBinary(cfg.UpgradeBin(info.Name))
|
||||
if err == nil {
|
||||
|
@ -50,7 +52,7 @@ func DoUpgrade(cfg *Config, info UpgradeInfo) error {
|
|||
}
|
||||
|
||||
// DownloadBinary will grab the binary and place it in the proper directory
|
||||
func DownloadBinary(cfg *Config, info UpgradeInfo) error {
|
||||
func DownloadBinary(cfg *Config, info upgradetypes.Plan) error {
|
||||
url, err := GetDownloadURL(info)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -103,7 +105,7 @@ type UpgradeConfig struct {
|
|||
}
|
||||
|
||||
// GetDownloadURL will check if there is an arch-dependent binary specified in Info
|
||||
func GetDownloadURL(info UpgradeInfo) (string, error) {
|
||||
func GetDownloadURL(info upgradetypes.Plan) (string, error) {
|
||||
doc := strings.TrimSpace(info.Info)
|
||||
// if this is a url, then we download that and try to get a new doc with the real info
|
||||
if _, err := url.Parse(doc); err == nil {
|
||||
|
|
|
@ -10,12 +10,13 @@ import (
|
|||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/otiai10/copy"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
||||
"github.com/otiai10/copy"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/cosmovisor"
|
||||
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
|
||||
)
|
||||
|
||||
type upgradeTestSuite struct {
|
||||
|
@ -37,7 +38,7 @@ func (s *upgradeTestSuite) TestCurrentBin() {
|
|||
|
||||
// ensure we cannot set this to an invalid value
|
||||
for _, name := range []string{"missing", "nobin", "noexec"} {
|
||||
s.Require().Error(cfg.SetCurrentUpgrade(cosmovisor.UpgradeInfo{Name: name}), name)
|
||||
s.Require().Error(cfg.SetCurrentUpgrade(upgradetypes.Plan{Name: name}), name)
|
||||
|
||||
currentBin, err := cfg.CurrentBin()
|
||||
s.Require().NoError(err)
|
||||
|
@ -48,7 +49,7 @@ func (s *upgradeTestSuite) TestCurrentBin() {
|
|||
// try a few times to make sure this can be reproduced
|
||||
for _, name := range []string{"chain2", "chain3", "chain2"} {
|
||||
// now set it to a valid upgrade and make sure CurrentBin is now set properly
|
||||
err = cfg.SetCurrentUpgrade(cosmovisor.UpgradeInfo{Name: name})
|
||||
err = cfg.SetCurrentUpgrade(upgradetypes.Plan{Name: name})
|
||||
s.Require().NoError(err)
|
||||
// we should see current point to the new upgrade dir
|
||||
currentBin, err := cfg.CurrentBin()
|
||||
|
@ -67,7 +68,7 @@ func (s *upgradeTestSuite) TestCurrentAlwaysSymlinkToDirectory() {
|
|||
s.Require().Equal(cfg.GenesisBin(), currentBin)
|
||||
s.assertCurrentLink(cfg, "genesis")
|
||||
|
||||
err = cfg.SetCurrentUpgrade(cosmovisor.UpgradeInfo{Name: "chain2"})
|
||||
err = cfg.SetCurrentUpgrade(upgradetypes.Plan{Name: "chain2"})
|
||||
s.Require().NoError(err)
|
||||
currentBin, err = cfg.CurrentBin()
|
||||
s.Require().NoError(err)
|
||||
|
@ -100,7 +101,7 @@ func (s *upgradeTestSuite) TestDoUpgradeNoDownloadUrl() {
|
|||
|
||||
// do upgrade ignores bad files
|
||||
for _, name := range []string{"missing", "nobin", "noexec"} {
|
||||
info := cosmovisor.UpgradeInfo{Name: name}
|
||||
info := upgradetypes.Plan{Name: name}
|
||||
err = cosmovisor.DoUpgrade(cfg, info)
|
||||
s.Require().Error(err, name)
|
||||
currentBin, err := cfg.CurrentBin()
|
||||
|
@ -111,7 +112,7 @@ func (s *upgradeTestSuite) TestDoUpgradeNoDownloadUrl() {
|
|||
// make sure it updates a few times
|
||||
for _, upgrade := range []string{"chain2", "chain3"} {
|
||||
// now set it to a valid upgrade and make sure CurrentBin is now set properly
|
||||
info := cosmovisor.UpgradeInfo{Name: upgrade}
|
||||
info := upgradetypes.Plan{Name: upgrade}
|
||||
err = cosmovisor.DoUpgrade(cfg, info)
|
||||
s.Require().NoError(err)
|
||||
// we should see current point to the new upgrade dir
|
||||
|
@ -175,7 +176,7 @@ func (s *upgradeTestSuite) TestGetDownloadURL() {
|
|||
|
||||
for name, tc := range cases {
|
||||
s.Run(name, func() {
|
||||
url, err := cosmovisor.GetDownloadURL(cosmovisor.UpgradeInfo{Info: tc.info})
|
||||
url, err := cosmovisor.GetDownloadURL(upgradetypes.Plan{Info: tc.info})
|
||||
if tc.err != "" {
|
||||
s.Require().Error(err)
|
||||
s.Require().Contains(err.Error(), tc.err)
|
||||
|
@ -248,7 +249,7 @@ func (s *upgradeTestSuite) TestDownloadBinary() {
|
|||
}
|
||||
|
||||
upgrade := "amazonas"
|
||||
info := cosmovisor.UpgradeInfo{
|
||||
info := upgradetypes.Plan{
|
||||
Name: upgrade,
|
||||
Info: fmt.Sprintf(`{"binaries":{"%s": "%s"}}`, cosmovisor.OSArch(), url),
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue