mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-01-26 23:37:08 -05:00
Error when no validators provided on status waiter initialization
Signed-off-by: Daniel Weiße <dw@edgeless.systems>
This commit is contained in:
parent
0acf1c34ac
commit
ddf94c7373
@ -107,7 +107,9 @@ func initialize(ctx context.Context, cmd *cobra.Command, protCl protoClient, ser
|
|||||||
endpoints := ipsToEndpoints(append(coordinators.PublicIPs(), nodes.PublicIPs()...), *config.CoordinatorPort)
|
endpoints := ipsToEndpoints(append(coordinators.PublicIPs(), nodes.PublicIPs()...), *config.CoordinatorPort)
|
||||||
|
|
||||||
cmd.Println("Waiting for cloud provider to finish resource creation ...")
|
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 {
|
if err := waiter.WaitForAll(ctx, endpoints, coordinatorstate.AcceptingInit); err != nil {
|
||||||
return fmt.Errorf("failed to wait for peer status: %w", err)
|
return fmt.Errorf("failed to wait for peer status: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,6 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type statusWaiter interface {
|
type statusWaiter interface {
|
||||||
InitializeValidators([]atls.Validator)
|
InitializeValidators([]atls.Validator) error
|
||||||
WaitForAll(ctx context.Context, endpoints []string, status ...state.State) error
|
WaitForAll(ctx context.Context, endpoints []string, status ...state.State) error
|
||||||
}
|
}
|
||||||
|
@ -10,11 +10,13 @@ import (
|
|||||||
|
|
||||||
type stubStatusWaiter struct {
|
type stubStatusWaiter struct {
|
||||||
initialized bool
|
initialized bool
|
||||||
|
initializeErr error
|
||||||
waitForAllErr error
|
waitForAllErr error
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *stubStatusWaiter) InitializeValidators([]atls.Validator) {
|
func (s *stubStatusWaiter) InitializeValidators([]atls.Validator) error {
|
||||||
s.initialized = true
|
s.initialized = true
|
||||||
|
return s.initializeErr
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *stubStatusWaiter) WaitForAll(ctx context.Context, endpoints []string, status ...state.State) error {
|
func (s *stubStatusWaiter) WaitForAll(ctx context.Context, endpoints []string, status ...state.State) error {
|
||||||
|
@ -34,9 +34,13 @@ func NewWaiter() *Waiter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// InitializeValidators initializes the validators for the attestation.
|
// 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.newConn = newAttestedConnGenerator(validators)
|
||||||
w.initialized = true
|
w.initialized = true
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// WaitFor waits for a PeerStatusServer, which is reachable under the given endpoint
|
// WaitFor waits for a PeerStatusServer, which is reachable under the given endpoint
|
||||||
|
@ -6,6 +6,8 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"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/pubapi/pubproto"
|
||||||
"github.com/edgelesssys/constellation/coordinator/state"
|
"github.com/edgelesssys/constellation/coordinator/state"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
@ -23,7 +25,11 @@ func TestInitializeValidators(t *testing.T) {
|
|||||||
// Uninitialized waiter fails.
|
// Uninitialized waiter fails.
|
||||||
assert.Error(waiter.WaitFor(context.Background(), "someIP", state.IsNode))
|
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))
|
assert.NoError(waiter.WaitFor(context.Background(), "someIP", state.IsNode))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,11 +45,13 @@ func main() {
|
|||||||
|
|
||||||
// wait for coordinator to come online
|
// wait for coordinator to come online
|
||||||
waiter := status.NewWaiter()
|
waiter := status.NewWaiter()
|
||||||
waiter.InitializeValidators([]atls.Validator{
|
if err := waiter.InitializeValidators([]atls.Validator{
|
||||||
azure.NewValidator(map[uint32][]byte{}),
|
azure.NewValidator(map[uint32][]byte{}),
|
||||||
gcp.NewValidator(map[uint32][]byte{}),
|
gcp.NewValidator(map[uint32][]byte{}),
|
||||||
gcp.NewNonCVMValidator(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 {
|
if err := waiter.WaitFor(ctx, addr, state.AcceptingInit, state.ActivatingNodes, state.IsNode, state.NodeWaitingForClusterJoin); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user