Error when no validators provided on status waiter initialization

Signed-off-by: Daniel Weiße <dw@edgeless.systems>
This commit is contained in:
Daniel Weiße 2022-04-27 08:30:47 +02:00 committed by Daniel Weiße
parent 0acf1c34ac
commit ddf94c7373
6 changed files with 23 additions and 7 deletions

View File

@ -107,7 +107,9 @@ func initialize(ctx context.Context, cmd *cobra.Command, protCl protoClient, ser
endpoints := ipsToEndpoints(append(coordinators.PublicIPs(), nodes.PublicIPs()...), *config.CoordinatorPort)
cmd.Println("Waiting for cloud provider to finish resource creation ...")
waiter.InitializeValidators(validators.V())
if err := waiter.InitializeValidators(validators.V()); err != nil {
return err
}
if err := waiter.WaitForAll(ctx, endpoints, coordinatorstate.AcceptingInit); err != nil {
return fmt.Errorf("failed to wait for peer status: %w", err)
}

View File

@ -8,6 +8,6 @@ import (
)
type statusWaiter interface {
InitializeValidators([]atls.Validator)
InitializeValidators([]atls.Validator) error
WaitForAll(ctx context.Context, endpoints []string, status ...state.State) error
}

View File

@ -10,11 +10,13 @@ import (
type stubStatusWaiter struct {
initialized bool
initializeErr error
waitForAllErr error
}
func (s *stubStatusWaiter) InitializeValidators([]atls.Validator) {
func (s *stubStatusWaiter) InitializeValidators([]atls.Validator) error {
s.initialized = true
return s.initializeErr
}
func (s *stubStatusWaiter) WaitForAll(ctx context.Context, endpoints []string, status ...state.State) error {

View File

@ -34,9 +34,13 @@ func NewWaiter() *Waiter {
}
// InitializeValidators initializes the validators for the attestation.
func (w *Waiter) InitializeValidators(validators []atls.Validator) {
func (w *Waiter) InitializeValidators(validators []atls.Validator) error {
if len(validators) == 0 {
return errors.New("no validators provided to initialize status waiter")
}
w.newConn = newAttestedConnGenerator(validators)
w.initialized = true
return nil
}
// WaitFor waits for a PeerStatusServer, which is reachable under the given endpoint

View File

@ -6,6 +6,8 @@ import (
"testing"
"time"
"github.com/edgelesssys/constellation/coordinator/atls"
"github.com/edgelesssys/constellation/coordinator/core"
"github.com/edgelesssys/constellation/coordinator/pubapi/pubproto"
"github.com/edgelesssys/constellation/coordinator/state"
"github.com/stretchr/testify/assert"
@ -23,7 +25,11 @@ func TestInitializeValidators(t *testing.T) {
// Uninitialized waiter fails.
assert.Error(waiter.WaitFor(context.Background(), "someIP", state.IsNode))
waiter.InitializeValidators(nil)
// Initializing waiter with no validators fails
assert.Error(waiter.InitializeValidators(nil))
// Initialized waiter succeeds
assert.NoError(waiter.InitializeValidators([]atls.Validator{core.NewMockValidator()}))
assert.NoError(waiter.WaitFor(context.Background(), "someIP", state.IsNode))
}

View File

@ -45,11 +45,13 @@ func main() {
// wait for coordinator to come online
waiter := status.NewWaiter()
waiter.InitializeValidators([]atls.Validator{
if err := waiter.InitializeValidators([]atls.Validator{
azure.NewValidator(map[uint32][]byte{}),
gcp.NewValidator(map[uint32][]byte{}),
gcp.NewNonCVMValidator(map[uint32][]byte{}),
})
}); err != nil {
log.Fatal(err)
}
if err := waiter.WaitFor(ctx, addr, state.AcceptingInit, state.ActivatingNodes, state.IsNode, state.NodeWaitingForClusterJoin); err != nil {
log.Fatal(err)
}