aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRitu Sood <ritu.sood@intel.com>2020-09-28 23:51:43 +0000
committerGerrit Code Review <gerrit@onap.org>2020-09-28 23:51:43 +0000
commit603a68284970205fa95dec67d4f9b88ae99e8d2c (patch)
treed16937051fd21723fe37e558a71e35ca3fcadadd /src
parent5a8a4cc2fa457c334ea8254762725d70371cf56a (diff)
parent20da89d07ad69a2cb067ceb0c416752e558bcf62 (diff)
Merge "Add a couple of sanity checks in DCM"
Diffstat (limited to 'src')
-rw-r--r--src/dcm/api/logicalCloudHandler.go7
-rw-r--r--src/dcm/pkg/module/logicalcloud.go7
-rw-r--r--src/dcm/pkg/module/logicalcloud_test.go8
3 files changed, 21 insertions, 1 deletions
diff --git a/src/dcm/api/logicalCloudHandler.go b/src/dcm/api/logicalCloudHandler.go
index 2e1811b7..fb0f0c63 100644
--- a/src/dcm/api/logicalCloudHandler.go
+++ b/src/dcm/api/logicalCloudHandler.go
@@ -186,6 +186,13 @@ func (h logicalCloudHandler) applyHandler(w http.ResponseWriter, r *http.Request
return
}
+ _, ctxVal, err := h.client.GetLogicalCloudContext(name)
+ if ctxVal != "" {
+ err = pkgerrors.New("Logical Cloud already applied")
+ http.Error(w, err.Error(), http.StatusConflict)
+ return
+ }
+
// Get Clusters
clusters, err := h.clusterClient.GetAllClusters(project, name)
diff --git a/src/dcm/pkg/module/logicalcloud.go b/src/dcm/pkg/module/logicalcloud.go
index 9b8ff703..61d7b7a5 100644
--- a/src/dcm/pkg/module/logicalcloud.go
+++ b/src/dcm/pkg/module/logicalcloud.go
@@ -199,7 +199,12 @@ func (v *LogicalCloudClient) Delete(project, logicalCloudName string) error {
Project: project,
LogicalCloudName: logicalCloudName,
}
- err := v.util.DBRemove(v.storeName, key)
+ //Check if this Logical Cloud exists
+ _, err := v.Get(project, logicalCloudName)
+ if err != nil {
+ return pkgerrors.New("Logical Cloud does not exist")
+ }
+ err = v.util.DBRemove(v.storeName, key)
if err != nil {
return pkgerrors.Wrap(err, "Delete Logical Cloud")
}
diff --git a/src/dcm/pkg/module/logicalcloud_test.go b/src/dcm/pkg/module/logicalcloud_test.go
index 0a0e2f5d..4700eff0 100644
--- a/src/dcm/pkg/module/logicalcloud_test.go
+++ b/src/dcm/pkg/module/logicalcloud_test.go
@@ -117,7 +117,15 @@ func TestDeleteLogicalCloud(t *testing.T) {
myMocks := new(mockValues)
+ data1 := [][]byte{
+ []byte("abc"),
+ }
+ data2 := []byte("abc")
+
myMocks.On("DBRemove", "test_dcm", key).Return(nil)
+ myMocks.On("DBFind", "test_dcm", key, "test_meta").Return(data1, nil)
+ myMocks.On("DBUnmarshal", data2).Return(nil)
+ // TODO also test for when the logical cloud doesn't exist
lcClient := LogicalCloudClient{"test_dcm", "test_meta", "test_context", myMocks}
err := lcClient.Delete("test_project", "test_asdf")