github.com/openebs/node-disk-manager@v1.9.1-0.20230225014141-4531f06ffa1e/integration_tests/sanity/grpc_tests.go (about)

     1  /*
     2  Copyright 2020 The OpenEBS Authors
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package sanity
    18  
    19  import (
    20  	"context"
    21  
    22  	apiservice "github.com/openebs/node-disk-manager/cmd/ndm_daemonset/grpc"
    23  	"github.com/openebs/node-disk-manager/integration_tests/k8s"
    24  	"github.com/openebs/node-disk-manager/integration_tests/udev"
    25  	"github.com/openebs/node-disk-manager/integration_tests/utils"
    26  	protos "github.com/openebs/node-disk-manager/spec/ndm"
    27  
    28  	. "github.com/onsi/ginkgo"
    29  	. "github.com/onsi/gomega"
    30  	"google.golang.org/grpc"
    31  	"k8s.io/klog/v2"
    32  )
    33  
    34  var address = apiservice.DefaultAddress
    35  
    36  var _ = Describe("gRPC tests", func() {
    37  
    38  	var err error
    39  	var k8sClient k8s.K8sClient
    40  	physicalDisk := udev.NewDisk(DiskImageSize)
    41  	err = physicalDisk.AttachDisk()
    42  
    43  	BeforeEach(func() {
    44  		Expect(err).NotTo(HaveOccurred())
    45  		By("getting a new client set")
    46  		k8sClient, _ = k8s.GetClientSet()
    47  
    48  		By("creating the NDM Daemonset")
    49  		err = k8sClient.CreateNDMDaemonSet()
    50  		Expect(err).NotTo(HaveOccurred())
    51  
    52  		By("waiting for the daemonset pod to be running")
    53  		ok := WaitForPodToBeRunningEventually(DaemonSetPodPrefix)
    54  		Expect(ok).To(BeTrue())
    55  
    56  		k8s.WaitForReconciliation()
    57  
    58  	})
    59  	AfterEach(func() {
    60  		By("deleting the NDM deamonset")
    61  		err := k8sClient.DeleteNDMDaemonSet()
    62  		Expect(err).NotTo(HaveOccurred())
    63  
    64  		By("waiting for the pod to be removed")
    65  		ok := WaitForPodToBeDeletedEventually(DaemonSetPodPrefix)
    66  		Expect(ok).To(BeTrue())
    67  		err = nil
    68  	})
    69  	Context("gRPC services", func() {
    70  
    71  		It("iSCSI test", func() {
    72  			conn, err := grpc.Dial(address, grpc.WithInsecure())
    73  			Expect(err).NotTo(HaveOccurred())
    74  			defer conn.Close()
    75  
    76  			isc := protos.NewNodeClient(conn)
    77  			ctx := context.Background()
    78  			null := &protos.Null{}
    79  
    80  			By("Checking when ISCSI is disabled")
    81  			// This needs to be done to be sure that iscsi is not running.
    82  			err = utils.RunCommandWithSudo("sudo systemctl stop iscsid")
    83  			Expect(err).NotTo(HaveOccurred())
    84  			res, err := isc.ISCSIStatus(ctx, null)
    85  			Expect(err).NotTo(HaveOccurred())
    86  			Expect(res.GetStatus()).To(BeFalse())
    87  
    88  			By("Checking when ISCSI is enabled ")
    89  			err = utils.RunCommandWithSudo("sudo systemctl enable iscsid")
    90  			Expect(err).NotTo(HaveOccurred())
    91  			err = utils.RunCommandWithSudo("sudo systemctl start iscsid")
    92  			Expect(err).NotTo(HaveOccurred())
    93  			res, err = isc.ISCSIStatus(ctx, null)
    94  			Expect(err).NotTo(HaveOccurred())
    95  			Expect(res.GetStatus()).To(BeTrue())
    96  
    97  		})
    98  
    99  		It("List Block Devices test", func() {
   100  			conn, err := grpc.Dial(address, grpc.WithInsecure())
   101  			Expect(err).NotTo(HaveOccurred())
   102  			defer conn.Close()
   103  
   104  			ns := protos.NewNodeClient(conn)
   105  
   106  			ctx := context.Background()
   107  			null := &protos.Null{}
   108  
   109  			res, err := ns.ListBlockDevices(ctx, null)
   110  			Expect(err).NotTo(HaveOccurred())
   111  			Expect(res).NotTo(BeNil())
   112  
   113  			bd := &protos.BlockDevice{
   114  				Name: physicalDisk.Name,
   115  				Type: "Disk",
   116  			}
   117  			bds := make([]*protos.BlockDevice, 0)
   118  			bds = append(bds, bd)
   119  			_ = &protos.BlockDevices{
   120  				Blockdevices: bds,
   121  			}
   122  			for _, bdn := range res.GetBlockdevices() {
   123  				if bdn.Name == bd.Name {
   124  					Expect(bd.Name).To(Equal(bd.Name))
   125  				}
   126  			}
   127  
   128  		})
   129  
   130  		It("Huge pages test", func() {
   131  			conn, err := grpc.Dial(address, grpc.WithInsecure())
   132  			Expect(err).NotTo(HaveOccurred())
   133  			defer conn.Close()
   134  
   135  			ns := protos.NewNodeClient(conn)
   136  
   137  			ctx := context.Background()
   138  			pages := &protos.Hugepages{
   139  				Pages: 512,
   140  			}
   141  
   142  			setRes, err := ns.SetHugepages(ctx, pages)
   143  			Expect(err).NotTo(HaveOccurred())
   144  			klog.Info(setRes)
   145  
   146  			Expect(setRes.GetResult()).To(BeTrue())
   147  
   148  		})
   149  		It("Rescan test", func() {
   150  			conn, err := grpc.Dial(address, grpc.WithInsecure())
   151  			Expect(err).NotTo(HaveOccurred())
   152  			defer conn.Close()
   153  
   154  			ns := protos.NewNodeClient(conn)
   155  
   156  			ctx := context.Background()
   157  			null := &protos.Null{}
   158  
   159  			res, err := ns.Rescan(ctx, null)
   160  			Expect(err).NotTo(HaveOccurred())
   161  			Expect(res.GetMsg()).To(Equal("Rescan initiated"))
   162  
   163  		})
   164  
   165  	})
   166  
   167  })