github.com/openebs/node-disk-manager@v1.9.1-0.20230225014141-4531f06ffa1e/integration_tests/sanity/size_change_test.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 . "github.com/onsi/ginkgo" 21 . "github.com/onsi/gomega" 22 "github.com/onsi/gomega/types" 23 24 "github.com/openebs/node-disk-manager/integration_tests/k8s" 25 "github.com/openebs/node-disk-manager/integration_tests/udev" 26 ) 27 28 const newDiskCapacity int64 = 500 * 1024 * 1024 29 30 var _ = Describe("Size change detection tests", func() { 31 var kcli k8s.K8sClient 32 disk := udev.NewDisk(DiskImageSize) 33 34 var bdName, bdNamespace string 35 36 BeforeEach(func() { 37 By("initializing up k8s cli", initK8sCli(&kcli)) 38 By("creating up ndm daemonset", createAndStartNDMDaemonset(&kcli)) 39 By("attaching disk", attachDisk(&disk)) 40 By("waiting for etcd update", k8s.WaitForStateChange) 41 By("verifying disk added to etcd", verifyDiskAddedToEtcd(&kcli, disk.Name, 42 &bdName, &bdNamespace)) 43 }) 44 AfterEach(func() { 45 By("detaching disk", detachDisk(&disk)) 46 By("destroying ndm daemonset", stopAndDeleteNDMDaemonset(&kcli)) 47 }) 48 49 It("should detect size change and update bd capacity", func() { 50 By("Changing disk size", changeDiskSize(&disk)) 51 By("Waiting for etcd update", k8s.WaitForStateChange) 52 By("Verifying bd capacity update in etcd", 53 verifyDiskCapacityUpdate(&kcli, bdName, bdNamespace, 54 Equal(uint64(newDiskCapacity)))) 55 56 }) 57 }) 58 59 func changeDiskSize(disk *udev.Disk) func() { 60 return func() { 61 Expect(disk.Resize(newDiskCapacity)).ToNot(HaveOccurred()) 62 } 63 } 64 65 func verifyDiskCapacityUpdate(cli *k8s.K8sClient, bdName, bdNamespace string, 66 matcher types.GomegaMatcher) func() { 67 return func() { 68 bd, err := cli.GetBlockDevice(bdName, bdNamespace) 69 Expect(err).ToNot(HaveOccurred()) 70 Expect(bd).ToNot(BeNil()) 71 Expect(bd.Name).To(Equal(bdName)) 72 Expect(bd.Namespace).To(Equal(bdNamespace)) 73 Expect(bd.Spec.Capacity.Storage).To(matcher) 74 } 75 }