Implement uninstall of xApp 15/9715/1
authorsubhash kumar singh <subh.singh@samsung.com>
Fri, 18 Nov 2022 12:05:59 +0000 (12:05 +0000)
committersubhash kumar singh <subh.singh@samsung.com>
Fri, 18 Nov 2022 12:05:59 +0000 (12:05 +0000)
Implemtend delete api for xApp deployment.

Signed-off-by: subhash kumar singh <subh.singh@samsung.com>
Change-Id: I9c8e64984a3924d39a617fa7dbe6c310646ebbda

api/ric-dms-api-2.0.yaml
pkg/deploy/deployment_manager.go
pkg/deploy/types.go
pkg/resthooks/resthooks.go
pkg/resthooks/resthooks_test.go

index 24cfc6e..f9e8434 100644 (file)
@@ -194,7 +194,7 @@ paths:
           description: successful un-deploy xApp
           schema:
             type: object
-        '501':
+        '500':
           description: un-deployment failed
           schema:
             $ref: '#/definitions/error_message'
index 8d55b9e..fdc2259 100644 (file)
@@ -24,6 +24,7 @@ import (
        "fmt"
        "io"
        "os"
+       "strings"
 
        "gerrit.o-ran-sc.org/r/ric-plt/ricdms/pkg/ricdms"
        "helm.sh/helm/v3/pkg/action"
@@ -42,7 +43,9 @@ const (
 )
 
 func NewDeploymentManager() IDeploy {
-       return &DeploymentManager{}
+       return &DeploymentManager{
+               settings: cli.New(),
+       }
 }
 
 func (d *DeploymentManager) install(chartPath, appName, version, namesapce string) error {
@@ -55,7 +58,7 @@ func (d *DeploymentManager) install(chartPath, appName, version, namesapce strin
        }
 
        install := action.NewInstall(&conf)
-       install.ReleaseName = fmt.Sprintf(RELESE_NAME_FORMAT, appName, version)
+       install.ReleaseName = fmt.Sprintf(RELESE_NAME_FORMAT, appName, strings.ReplaceAll(version, ".", ""))
        install.Namespace = namesapce
 
        cp, err := install.ChartPathOptions.LocateChart(chartPath, d.settings)
@@ -111,3 +114,25 @@ func (d *DeploymentManager) Deploy(reader io.ReadCloser, appname, version, names
        }
        return nil
 }
+
+func (d *DeploymentManager) Uninstall(appname, version, namespace string) error {
+       conf := action.Configuration{}
+
+       err := conf.Init(d.settings.RESTClientGetter(), namespace, os.Getenv(HELM_DRIVER), ricdms.Logger.Debug)
+       if err != nil {
+               ricdms.Logger.Error("Not able to prepare uninstall configuration: %v", err)
+               return err
+       }
+
+       uninstall := action.NewUninstall(&conf)
+       uninstall.Wait = true
+
+       resp, err := uninstall.Run(fmt.Sprintf(RELESE_NAME_FORMAT, appname, strings.ReplaceAll(version, ".", "")))
+       if err != nil {
+               ricdms.Logger.Error("Error while uninstalling deployment: %v", err)
+               return err
+       }
+
+       ricdms.Logger.Info("deployment uninstallation comlete : %", resp.Info)
+       return nil
+}
index 115caca..0078816 100644 (file)
 
 package deploy
 
-import "io"
+import (
+       "io"
+)
 
 type IDeploy interface {
        Deploy(reader io.ReadCloser, appname, version, namespace string) error
+       Uninstall(appname, version, namespace string) error
 }
index 5940694..7cc8efe 100644 (file)
@@ -117,3 +117,14 @@ func (rh *Resthook) DownloadAndInstallChart(appname, version, namespace string)
        }
        return dp.NewPostDeployCreated()
 }
+
+func (rh *Resthook) UninstallChart(appname, version, namespace string) middleware.Responder {
+       ricdms.Logger.Debug("Uninstall chart is invoked")
+       err := rh.DeployMgr.Uninstall(appname, version, namespace)
+       if err != nil {
+               ricdms.Logger.Error("Uninstall failed: %v", err)
+               return dp.NewDeleteDeployInternalServerError()
+       }
+
+       return dp.NewDeleteDeployCreated()
+}
index 991fbec..7b65f15 100644 (file)
@@ -213,6 +213,13 @@ func TestDownloadAndInstall(t *testing.T) {
 
 }
 
+func TestUninstallxApp(t *testing.T) {
+       response := rh.UninstallChart("test", "test", "test")
+       if _, ok := response.(*d.DeleteDeployInternalServerError); !ok {
+               assert.Fail(t, "response type did not match actual: %T", response)
+       }
+}
+
 type HealthCheckerMock struct {
        mock.Mock
 }