diff options
author | Igor D.C <igor.duarte.cardoso@intel.com> | 2020-09-26 01:55:04 +0000 |
---|---|---|
committer | Igor D.C <igor.duarte.cardoso@intel.com> | 2020-09-26 01:56:19 +0000 |
commit | 20da89d07ad69a2cb067ceb0c416752e558bcf62 (patch) | |
tree | ccfdd709555f5c2564c296c8b37de56f394df4ac /src/dcm/pkg | |
parent | 8c0cc1278cc4d84863b076b2014b9bc9d8805218 (diff) |
Add a couple of sanity checks in DCM
When applying, check whether logical cloud is already applied.
When deleting logical cloud, check if it exists.
Issue-ID: MULTICLOUD-1143
Change-Id: I6aa11d8921db76e3d9e9632f915b55fe7ab8efab
Signed-off-by: Igor D.C <igor.duarte.cardoso@intel.com>
Diffstat (limited to 'src/dcm/pkg')
-rw-r--r-- | src/dcm/pkg/module/logicalcloud.go | 7 | ||||
-rw-r--r-- | src/dcm/pkg/module/logicalcloud_test.go | 8 |
2 files changed, 14 insertions, 1 deletions
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") |