From c04ead5fb131f2f3a6847d075be8bee47eade4bf Mon Sep 17 00:00:00 2001 From: Odin Ugedal Date: Thu, 9 Jan 2020 09:49:38 +0100 Subject: [PATCH] Add error check for instance insert Not all errors will happen in sync during Instances.Insert(...).Do(), so it is important to verify the operation object to see why insert fails. An example is when exceeding the resource quota. Eg. could not create instance test-cos-beta-80-12739-29-0: [&{Code:QUOTA_EXCEEDED Location: Message:Quota 'CPUS' exceeded. Limit: 24.0 in region europe-west6. ForceSendFields:[] NullFields:[]} This fixes the issue where tests will fail "silently" when instance insert fails. --- test/e2e_node/runner/remote/run_remote.go | 30 ++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/test/e2e_node/runner/remote/run_remote.go b/test/e2e_node/runner/remote/run_remote.go index 11c4487e3c3..095a82e5380 100644 --- a/test/e2e_node/runner/remote/run_remote.go +++ b/test/e2e_node/runner/remote/run_remote.go @@ -623,8 +623,10 @@ func createInstance(imageConfig *internalGCEImage) (string, error) { } i.Scheduling = &scheduling i.Metadata = imageConfig.metadata + var insertionOperationName string if _, err := computeService.Instances.Get(*project, *zone, i.Name).Do(); err != nil { op, err := computeService.Instances.Insert(*project, *zone, i).Do() + if err != nil { ret := fmt.Sprintf("could not create instance %s: API error: %v", name, err) if op != nil { @@ -632,15 +634,37 @@ func createInstance(imageConfig *internalGCEImage) (string, error) { } return "", fmt.Errorf(ret) } else if op.Error != nil { - return "", fmt.Errorf("could not create instance %s: %+v", name, op.Error) - } - } + var errs []string + for _, insertErr := range op.Error.Errors { + errs = append(errs, fmt.Sprintf("%+v", insertErr)) + } + return "", fmt.Errorf("could not create instance %s: %+v", name, errs) + } + insertionOperationName = op.Name + } instanceRunning := false for i := 0; i < 30 && !instanceRunning; i++ { if i > 0 { time.Sleep(time.Second * 20) } + var insertionOperation *compute.Operation + insertionOperation, err = computeService.ZoneOperations.Get(*project, *zone, insertionOperationName).Do() + if err != nil { + continue + } + if strings.ToUpper(insertionOperation.Status) != "DONE" { + err = fmt.Errorf("instance insert operation %s not in state DONE, was %s", name, insertionOperation.Status) + continue + } + if insertionOperation.Error != nil { + var errs []string + for _, insertErr := range insertionOperation.Error.Errors { + errs = append(errs, fmt.Sprintf("%+v", insertErr)) + } + return name, fmt.Errorf("could not create instance %s: %+v", name, errs) + } + var instance *compute.Instance instance, err = computeService.Instances.Get(*project, *zone, name).Do() if err != nil {