From fd6542d5b4693d01d50c033e4cfc3a292d95c51c Mon Sep 17 00:00:00 2001
From: Malte Bauch <malte.bauch@stud.h-da.de>
Date: Wed, 22 Nov 2023 10:59:11 +0000
Subject: [PATCH] Resolve "Segmentation fault through plugin client"

See merge request danet/gosdn!619
---
 .gitlab/ci/.integration-test-containerlab.yml |  2 +-
 .gitlab/ci/.integration-test.yml              | 13 ++++----
 controller/plugin/shared/client.go            | 31 ++++++++++++++++---
 3 files changed, 35 insertions(+), 11 deletions(-)

diff --git a/.gitlab/ci/.integration-test-containerlab.yml b/.gitlab/ci/.integration-test-containerlab.yml
index 2e1518a28..467fce876 100644
--- a/.gitlab/ci/.integration-test-containerlab.yml
+++ b/.gitlab/ci/.integration-test-containerlab.yml
@@ -45,7 +45,7 @@ containerlab-destroy:
     needs:
         [
             "containerlab-deploy",
-            "integration-test:nucleus",
+            #"integration-test:nucleus",
             "integration-test:api"
 
         ]
diff --git a/.gitlab/ci/.integration-test.yml b/.gitlab/ci/.integration-test.yml
index ae7525b17..2825458dd 100644
--- a/.gitlab/ci/.integration-test.yml
+++ b/.gitlab/ci/.integration-test.yml
@@ -10,12 +10,13 @@
         GOSDN_TEST_USER: "admin"
         GOSDN_TEST_PASSWORD: "admin"
 
-integration-test:nucleus:
-    <<: *integration-test
-    script:
-        - ${CI_PROJECT_DIR}/.gitlab/ci/scripts/wait-for-it.sh ${CEOS_TEST_ENDPOINT} -s -t 180 -- echo "CEOS is up"
-        - cd controller/
-        - make integration-test-nucleus
+            # NOTE: Current test setup and runners are changed, therefore this test is not possible to run at the moment
+            #integration-test:nucleus:
+            #    <<: *integration-test
+            #    script:
+            #        - ${CI_PROJECT_DIR}/.gitlab/ci/scripts/wait-for-it.sh ${CEOS_TEST_ENDPOINT} -s -t 180 -- echo "CEOS is up"
+            #        - cd controller/
+            #        - make integration-test-nucleus
 
 integration-test:api:
     <<: *integration-test
diff --git a/controller/plugin/shared/client.go b/controller/plugin/shared/client.go
index 4bdfdb839..a44a983a7 100644
--- a/controller/plugin/shared/client.go
+++ b/controller/plugin/shared/client.go
@@ -27,6 +27,7 @@ func (m *DeviceModelClient) Unmarshal(json []byte, path *gpb.Path) error {
 		Json: json,
 		Path: path,
 	})
+
 	return err
 }
 
@@ -38,6 +39,7 @@ func (m *DeviceModelClient) SetNode(path *gpb.Path, value *gpb.TypedValue) error
 		Path:  path,
 		Value: value,
 	})
+
 	return err
 }
 
@@ -50,7 +52,11 @@ func (m *DeviceModelClient) GetNode(path *gpb.Path, requestForIntendedState bool
 		Path:                    path,
 		RequestForIntendedState: requestForIntendedState,
 	})
-	return resp.GetNodes(), err
+	if err != nil {
+		return nil, err
+	}
+
+	return resp.GetNodes(), nil
 }
 
 // DeleteNode calls the DeleteNode method of the DeviceModelClients client. A
@@ -60,6 +66,7 @@ func (m *DeviceModelClient) DeleteNode(path *gpb.Path) error {
 	_, err := m.client.DeleteNode(context.Background(), &pb.DeleteNodeRequest{
 		Path: path,
 	})
+
 	return err
 }
 
@@ -71,7 +78,11 @@ func (m *DeviceModelClient) Model(filterReadOnly bool) ([]byte, error) {
 	resp, err := m.client.Model(context.Background(), &pb.ModelRequest{
 		FilterReadOnly: filterReadOnly,
 	})
-	return resp.Json, err
+	if err != nil {
+		return nil, err
+	}
+
+	return resp.Json, nil
 }
 
 // Diff calls the Diff method of the DeviceModelClients client. A request is
@@ -82,7 +93,11 @@ func (m *DeviceModelClient) Diff(original, modified []byte) (*gpb.Notification,
 		Original: original,
 		Modified: modified,
 	})
-	return resp.GetNotification(), err
+	if err != nil {
+		return nil, err
+	}
+
+	return resp.GetNotification(), nil
 }
 
 // ValidateChange calls the ValidateChange method of the DeviceModelClients
@@ -95,7 +110,11 @@ func (m *DeviceModelClient) ValidateChange(operation mnepb.ApiOperation, path *g
 		Path:      path,
 		Value:     value,
 	})
-	return resp.GetModel(), err
+	if err != nil {
+		return nil, err
+	}
+
+	return resp.GetModel(), nil
 }
 
 // PruneConfigFalse calls the PruneConfigFalse method of the DeviceModelClients
@@ -106,6 +125,10 @@ func (m *DeviceModelClient) PruneConfigFalse(value []byte) ([]byte, error) {
 	resp, err := m.client.PruneConfigFalse(context.Background(), &pb.PruneConfigFalseRequest{
 		Value: value,
 	})
+	if err != nil {
+		return nil, err
+	}
+
 	return resp.GetModel(), err
 }
 
-- 
GitLab