scripts/tests: fix gateway tests

Change-Id: I9a23ef08794043ad615066ae5929df9ff3a02d69
This commit is contained in:
Jessica Grebenschikov 2020-10-27 07:23:41 -07:00
parent 92a2be2abd
commit 99c88efbbf
3 changed files with 63 additions and 32 deletions

View File

@ -88,7 +88,7 @@ install-sim: ## install storj-sim
## install exact version of storj/gateway
mkdir -p .build/gateway-tmp
-cd .build/gateway-tmp && go mod init gatewaybuild
cd .build/gateway-tmp && go mod edit -replace github.com/minio/minio=github.com/storj/minio@storj && GO111MODULE=on go get storj.io/gateway@master
cd .build/gateway-tmp && GO111MODULE=on go get storj.io/gateway@latest
##@ Test

View File

@ -8,7 +8,6 @@ import (
"errors"
"fmt"
"io/ioutil"
"log"
"net"
"net/url"
"os"
@ -41,6 +40,10 @@ const (
folderPermissions = 0744
)
var (
defaultAccess = "17jgVrPRktsquJQFzpT533WHmZnF6QDkuv8w3Ry5XPzAkh3vj7D1dbJ5MatQRiyRE2ZEiA1Y6fYnhoWqr2n7VgycdXSUPz1QzhthBsHqGXCrRcjSp8RbbVE1VJqDej9nLgB5YDPh3Q5JrVjQeMe9saHAL5rE5tUYJAeynVdre8HeTJMXcwau5"
)
const (
// The following values of peer class and endpoints are used
// to create a port with a consistent format for storj-sim services.
@ -434,7 +437,6 @@ func newNetwork(flags *Flags) (*Processes, error) {
// Create gateways for each satellite
for i, satellite := range satellites {
i := i
satellite := satellite
process := processes.New(Info{
Name: fmt.Sprintf("gateway/%d", i),
@ -446,9 +448,15 @@ func newNetwork(flags *Flags) (*Processes, error) {
// gateway must wait for the corresponding satellite to start up
process.WaitForStart(satellite)
accessData := defaultAccess
process.Arguments = withCommon(process.Directory, Arguments{
"setup": {
"--non-interactive",
"--access", accessData,
"--server.address", process.Address,
"--debug.addr", net.JoinHostPort(host, port(gatewayPeer, i, debugHTTP)),
},
@ -461,42 +469,65 @@ func newNetwork(flags *Flags) (*Processes, error) {
return err
}
var consoleAddress string
err = readConfigString(&consoleAddress, satellite.Directory, "console.address")
if err != nil {
vip := viper.New()
vip.AddConfigPath(process.Directory)
if err := vip.ReadInConfig(); err != nil {
return err
}
// try with 100ms delays until we hit 3s
apiKey, start := "", time.Now()
for apiKey == "" {
apiKey, err = newConsoleEndpoints(consoleAddress).createOrGetAPIKey()
if err != nil && time.Since(start) > 3*time.Second {
log.Printf("Failed retrieving GATEWAY_%d_ACCESS: %s\n", i, err.Error())
return nil
// TODO: maybe all the config flags should be exposed for all processes?
// check if gateway config has an api key, if it's not
// create example project with key and add it to the config
// so that gateway can have access to the satellite
if runAccessData := vip.GetString("access"); !flags.OnlyEnv && runAccessData == accessData {
var consoleAddress string
err := readConfigString(&consoleAddress, satellite.Directory, "console.address")
if err != nil {
return err
}
// try with 100ms delays until we hit 3s
apiKey, start := "", time.Now()
for apiKey == "" {
apiKey, err = newConsoleEndpoints(consoleAddress).createOrGetAPIKey()
if err != nil && time.Since(start) > 3*time.Second {
return err
}
time.Sleep(100 * time.Millisecond)
}
satNodeID, err := identity.NodeIDFromCertPath(filepath.Join(satellite.Directory, "identity.cert"))
if err != nil {
return err
}
nodeURL := storj.NodeURL{
ID: satNodeID,
Address: satellite.Address,
}
access, err := uplink.RequestAccessWithPassphrase(context.Background(), nodeURL.String(), apiKey, "")
if err != nil {
return err
}
accessData, err := access.Serialize()
if err != nil {
return err
}
vip.Set("access", accessData)
if err := vip.WriteConfig(); err != nil {
return err
}
time.Sleep(100 * time.Millisecond)
}
satNodeID, err := identity.NodeIDFromCertPath(filepath.Join(satellite.Directory, "identity.cert"))
if err != nil {
return err
}
nodeURL := storj.NodeURL{
ID: satNodeID,
Address: satellite.Address,
if runAccessData := vip.GetString("access"); runAccessData != accessData {
process.AddExtra("ACCESS", runAccessData)
}
access, err := uplink.RequestAccessWithPassphrase(context.Background(), nodeURL.String(), apiKey, "")
if err != nil {
return err
}
accessData, err := access.Serialize()
if err != nil {
return err
}
process.AddExtra("ACCESS", accessData)
process.AddExtra("ACCESS_KEY", vip.GetString("minio.access-key"))
process.AddExtra("SECRET_KEY", vip.GetString("minio.secret-key"))
return nil
}

View File

@ -117,7 +117,7 @@ install_sim(){
rm -rf .build/gateway-tmp
mkdir -p .build/gateway-tmp
pushd .build/gateway-tmp
go mod init gatewaybuild && go mod edit -replace github.com/minio/minio=github.com/storj/minio@storj && GOBIN=${bin_dir} GO111MODULE=on go get storj.io/gateway@master
go mod init gatewaybuild && GOBIN=${bin_dir} GO111MODULE=on go get storj.io/gateway@latest
popd
fi
}