Skip to content

Commit

Permalink
infra e2e neg tests (#849)
Browse files Browse the repository at this point in the history
  • Loading branch information
gainsley committed Mar 11, 2020
1 parent 2f732aa commit f7eafb8
Show file tree
Hide file tree
Showing 19 changed files with 556 additions and 328 deletions.
45 changes: 30 additions & 15 deletions controller/app_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,37 @@ func (s *AppApi) DeleteApp(ctx context.Context, in *edgeproto.App) (*edgeproto.R
// disallow delete if static instances are present
return &edgeproto.Result{}, errors.New("Application in use by static AppInst")
}
// set state to prevent new AppInsts from being created from this App
err := s.sync.ApplySTMWait(ctx, func(stm concurrency.STM) error {
if !s.store.STMGet(stm, &in.Key, in) {
return in.Key.NotFoundError()
}
in.DeletePrepare = true
s.store.STMPut(stm, in)
return nil
})
if err != nil {
return &edgeproto.Result{}, err
}

// delete auto-appinsts
if err = appInstApi.AutoDelete(ctx, &in.Key); err != nil {
// failed, so remove delete prepare and don't delete
unseterr := s.sync.ApplySTMWait(ctx, func(stm concurrency.STM) error {
if !s.store.STMGet(stm, &in.Key, in) {
return in.Key.NotFoundError()
}
in.DeletePrepare = false
s.store.STMPut(stm, in)
return nil
})
if unseterr != nil {
log.SpanLog(ctx, log.DebugLevelApi, "Delete App unset delete prepare", "unseterr", unseterr)
}
return &edgeproto.Result{}, err
}

err = s.sync.ApplySTMWait(ctx, func(stm concurrency.STM) error {
app := edgeproto.App{}
if !s.store.STMGet(stm, &in.Key, &app) {
// already deleted
Expand All @@ -436,21 +466,6 @@ func (s *AppApi) DeleteApp(ctx context.Context, in *edgeproto.App) (*edgeproto.R
s.store.STMDel(stm, &in.Key)
return nil
})
if err == nil && len(dynInsts) > 0 {
// delete dynamic instances
for key, _ := range dynInsts {
appInst := edgeproto.AppInst{Key: key}
stream := streamoutAppInst{}
stream.ctx = ctx
stream.debugLvl = log.DebugLevelApi
derr := appInstApi.DeleteAppInst(&appInst, &stream)
if derr != nil {
log.DebugLog(log.DebugLevelApi,
"Failed to delete dynamic AppInst",
"err", derr)
}
}
}
return &edgeproto.Result{}, err
}

Expand Down
34 changes: 34 additions & 0 deletions controller/appinst_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,37 @@ func (s *AppInstApi) AutoDeleteAppInsts(key *edgeproto.ClusterInstKey, crmoverri
return nil
}

func (s *AppInstApi) AutoDelete(ctx context.Context, in *edgeproto.AppKey) error {
log.SpanLog(ctx, log.DebugLevelApi, "Auto-deleting AppInsts for App", "app", in)
appinsts := make(map[edgeproto.AppInstKey]*edgeproto.AppInst)
s.cache.Mux.Lock()
for key, val := range s.cache.Objs {
if key.AppKey.Matches(in) {
appinsts[key] = val
}
}
s.cache.Mux.Unlock()
failed := 0
deleted := 0
for key, val := range appinsts {
log.SpanLog(ctx, log.DebugLevelApi, "Auto-delete AppInst for App", "AppInst", key)
stream := streamoutAppInst{}
stream.ctx = ctx
stream.debugLvl = log.DebugLevelApi
err := s.DeleteAppInst(val, &stream)
if err != nil {
log.SpanLog(ctx, log.DebugLevelApi, "Failed to auto-delete AppInst", "AppInst", key)
failed++
} else {
deleted++
}
}
if failed > 0 {
return fmt.Errorf("Auto-deleted %d AppInsts but failed to delete %d AppInsts for App", deleted, failed)
}
return nil
}

func (s *AppInstApi) UsesFlavor(key *edgeproto.FlavorKey) bool {
s.cache.Mux.Lock()
defer s.cache.Mux.Unlock()
Expand Down Expand Up @@ -355,6 +386,9 @@ func (s *AppInstApi) createAppInstInternal(cctx *CallContext, in *edgeproto.AppI
if !appApi.store.STMGet(stm, &in.Key.AppKey, &app) {
return in.Key.AppKey.NotFoundError()
}
if app.DeletePrepare {
return fmt.Errorf("Cannot create AppInst against App which is being deleted")
}

// Now that we have a cloudlet, and cloudletInfo, we can validate the flavor requested
if in.Flavor.Name == "" {
Expand Down
139 changes: 71 additions & 68 deletions edgeproto/alldata.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions edgeproto/alldata.proto
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ message AllData {
repeated AutoProvPolicyCloudlet auto_prov_policy_cloudlets = 12 [(gogoproto.nullable) = false];
repeated AutoScalePolicy auto_scale_policies = 13 [(gogoproto.nullable) = false];
repeated PrivacyPolicy privacy_policies = 14 [(gogoproto.nullable) = false];
repeated App apps = 15 [(gogoproto.nullable) = false];
repeated ClusterInst cluster_insts = 16 [(gogoproto.nullable) = false];
repeated ClusterInst cluster_insts = 15 [(gogoproto.nullable) = false];
repeated App apps = 16 [(gogoproto.nullable) = false];
repeated AppInst app_instances = 17 [(gogoproto.nullable) = false];
option (protogen.e2edata) = true;
option (protogen.generate_copy_in_fields) = false;
Expand Down

0 comments on commit f7eafb8

Please sign in to comment.