From 6fb818d4560e11fbd883541f1d1dfd697da131d8 Mon Sep 17 00:00:00 2001 From: Vicente Cheng Date: Mon, 4 Dec 2023 23:38:47 +0800 Subject: [PATCH] ci: add disk tags integration tests - deploy longhorn v1.5.3 - update the deployment CRD - Add tags with provision - Remove tags from provisioned blockdevice - Add tags to provisioned blockdevice Signed-off-by: Vicente Cheng --- .github/workflows/basic-ci.yaml | 2 +- .../crds/harvesterhci.io_blockdevices.yaml | 10 ++++ tests/integration/test_0_single_disk_test.go | 53 ++++++++++++++++++- 3 files changed, 63 insertions(+), 2 deletions(-) diff --git a/.github/workflows/basic-ci.yaml b/.github/workflows/basic-ci.yaml index 2896166d..5f5ae869 100644 --- a/.github/workflows/basic-ci.yaml +++ b/.github/workflows/basic-ci.yaml @@ -46,7 +46,7 @@ jobs: git clone https://github.com/harvester/vagrant-rancherd ndm-vagrant-rancherd pushd ndm-vagrant-rancherd ./new_cluster.sh - yq e -i ".longhorn_version = \"1.4.2\"" settings.yaml + yq e -i ".longhorn_version = \"1.5.3\"" settings.yaml ./scripts/deploy_longhorn.sh cp ../ci/scripts/deploy_ndm.sh ./deploy_ndm.sh ./deploy_ndm.sh diff --git a/deploy/charts/harvester-node-disk-manager/templates/crds/harvesterhci.io_blockdevices.yaml b/deploy/charts/harvester-node-disk-manager/templates/crds/harvesterhci.io_blockdevices.yaml index 58c08361..b896b49d 100644 --- a/deploy/charts/harvester-node-disk-manager/templates/crds/harvesterhci.io_blockdevices.yaml +++ b/deploy/charts/harvester-node-disk-manager/templates/crds/harvesterhci.io_blockdevices.yaml @@ -84,6 +84,11 @@ spec: nodeName: description: name of the node to which the block device is attached type: string + tags: + description: a string with for device tag for provisioner, e.g. "default,small,ssd" + items: + type: string + type: array required: - devPath - fileSystem @@ -277,6 +282,11 @@ spec: - Inactive - Unknown type: string + tags: + description: The current Tags of the blockdevice + items: + type: string + type: array required: - provisionPhase - state diff --git a/tests/integration/test_0_single_disk_test.go b/tests/integration/test_0_single_disk_test.go index dc079e0d..cccc6a7d 100644 --- a/tests/integration/test_0_single_disk_test.go +++ b/tests/integration/test_0_single_disk_test.go @@ -151,6 +151,8 @@ func (s *SingleDiskSuite) Test_2_ManuallyProvisionSingleDisk() { require.Equal(s.T(), curBlockdevice.Status.State, diskv1.BlockDeviceActive, "Block device state should be Active") newBlockdevice := curBlockdevice.DeepCopy() newBlockdevice.Spec.FileSystem.Provisioned = true + targetTags := []string{"default", "test-disk"} + newBlockdevice.Spec.Tags = targetTags bdi.Update(context.TODO(), newBlockdevice, v1.UpdateOptions{}) // sleep 3 seconds to wait controller handle @@ -159,7 +161,56 @@ func (s *SingleDiskSuite) Test_2_ManuallyProvisionSingleDisk() { // check for the added status curBlockdevice, err = bdi.Get(context.TODO(), s.targetDiskName, v1.GetOptions{}) require.Equal(s.T(), err, nil, "Get BlockdevicesList should not get error before we want to check remove") - require.NotEqual(s.T(), curBlockdevice.Status.DeviceStatus.FileSystem.MountPoint, "", "Mountpoint should be empty after we remove disk!") + require.NotEqual(s.T(), curBlockdevice.Status.DeviceStatus.FileSystem.MountPoint, "", "Mountpoint should not be empty after we provision disk!") require.Equal(s.T(), diskv1.ProvisionPhaseProvisioned, curBlockdevice.Status.ProvisionPhase, "Block device provisionPhase should be Provisioned") require.Equal(s.T(), diskv1.BlockDeviceActive, curBlockdevice.Status.State, "Block device State should be Active") + require.Equal(s.T(), targetTags, curBlockdevice.Status.Tags, "Block device tags should be the same") +} + +func (s *SingleDiskSuite) Test_3_RemoveTags() { + require.NotEqual(s.T(), s.targetDiskName, "", "target disk name should not be empty before we do the remove test") + bdi := s.clientSet.HarvesterhciV1beta1().BlockDevices("longhorn-system") + curBlockdevice, err := bdi.Get(context.TODO(), s.targetDiskName, v1.GetOptions{}) + require.Equal(s.T(), err, nil, "Get Blockdevices should not get error") + + require.Equal(s.T(), curBlockdevice.Status.State, diskv1.BlockDeviceActive, "Block device state should be Active") + newBlockdevice := curBlockdevice.DeepCopy() + targetTags := []string{"default"} + newBlockdevice.Spec.Tags = targetTags + bdi.Update(context.TODO(), newBlockdevice, v1.UpdateOptions{}) + + // sleep 3 seconds to wait controller handle + time.Sleep(3 * time.Second) + + // check for the added status + curBlockdevice, err = bdi.Get(context.TODO(), s.targetDiskName, v1.GetOptions{}) + require.Equal(s.T(), err, nil, "Get BlockdevicesList should not get error before we want to check remove") + require.NotEqual(s.T(), curBlockdevice.Status.DeviceStatus.FileSystem.MountPoint, "", "Mountpoint should not be empty after we provision disk!") + require.Equal(s.T(), diskv1.ProvisionPhaseProvisioned, curBlockdevice.Status.ProvisionPhase, "Block device provisionPhase should be Provisioned") + require.Equal(s.T(), diskv1.BlockDeviceActive, curBlockdevice.Status.State, "Block device State should be Active") + require.Equal(s.T(), targetTags, curBlockdevice.Status.Tags, "Block device tags should be the same") +} + +func (s *SingleDiskSuite) Test_4_AddTags() { + require.NotEqual(s.T(), s.targetDiskName, "", "target disk name should not be empty before we do the remove test") + bdi := s.clientSet.HarvesterhciV1beta1().BlockDevices("longhorn-system") + curBlockdevice, err := bdi.Get(context.TODO(), s.targetDiskName, v1.GetOptions{}) + require.Equal(s.T(), err, nil, "Get Blockdevices should not get error") + + require.Equal(s.T(), curBlockdevice.Status.State, diskv1.BlockDeviceActive, "Block device state should be Active") + newBlockdevice := curBlockdevice.DeepCopy() + targetTags := []string{"default", "test-disk-2"} + newBlockdevice.Spec.Tags = targetTags + bdi.Update(context.TODO(), newBlockdevice, v1.UpdateOptions{}) + + // sleep 3 seconds to wait controller handle + time.Sleep(3 * time.Second) + + // check for the added status + curBlockdevice, err = bdi.Get(context.TODO(), s.targetDiskName, v1.GetOptions{}) + require.Equal(s.T(), err, nil, "Get BlockdevicesList should not get error before we want to check remove") + require.NotEqual(s.T(), curBlockdevice.Status.DeviceStatus.FileSystem.MountPoint, "", "Mountpoint should not be empty after we provision disk!") + require.Equal(s.T(), diskv1.ProvisionPhaseProvisioned, curBlockdevice.Status.ProvisionPhase, "Block device provisionPhase should be Provisioned") + require.Equal(s.T(), diskv1.BlockDeviceActive, curBlockdevice.Status.State, "Block device State should be Active") + require.Equal(s.T(), targetTags, curBlockdevice.Status.Tags, "Block device tags should be the same") }