From 3eb8bf2ad566b7f28b6982b58f0d293cd037901c Mon Sep 17 00:00:00 2001 From: Vicente Cheng Date: Mon, 13 May 2024 10:37:30 +0800 Subject: [PATCH] integration: add the test for interactive device removing Signed-off-by: Vicente Cheng --- tests/integration/test_1_disk_hotplug_test.go | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/tests/integration/test_1_disk_hotplug_test.go b/tests/integration/test_1_disk_hotplug_test.go index 555a1099..d82f8a74 100644 --- a/tests/integration/test_1_disk_hotplug_test.go +++ b/tests/integration/test_1_disk_hotplug_test.go @@ -190,6 +190,38 @@ func (s *HotPlugTestSuite) Test_3_AddDuplicatedWWNDsik() { } +func (s *HotPlugTestSuite) Test_4_RemoveInactiveDisk() { + // remove disk dynamically + cmd := fmt.Sprintf("virsh detach-disk %s %s --live", hotplugTargetNodeName, hotplugTargetDiskName) + _, _, err := doCommand(cmd) + require.Equal(s.T(), err, nil, "Running command `virsh detach-disk` should not get error") + + // wait for controller handling + time.Sleep(5 * time.Second) + + // check disk status + require.NotEqual(s.T(), s.targetDiskName, "", "target disk name should not be empty before we start hotplug (remove) test") + bdi := s.clientSet.HarvesterhciV1beta1().BlockDevices("longhorn-system") + curBlockdevice, err := bdi.Get(context.TODO(), s.targetDiskName, v1.GetOptions{}) + require.Equal(s.T(), nil, err, "Get Blockdevices should not get error") + + require.Equal(s.T(), diskv1.BlockDeviceInactive, curBlockdevice.Status.State, "Disk status should be inactive after we remove disk") + + // remove this inactive device from Harvester + newBlockdevice := curBlockdevice.DeepCopy() + newBlockdevice.Spec.FileSystem.Provisioned = false + bdi.Update(context.TODO(), newBlockdevice, v1.UpdateOptions{}) + + // sleep 30 seconds to wait controller handle. jitter is between 7~13 seconds so 30 seconds would be enough to run twice + time.Sleep(30 * time.Second) + + // check for the removed 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.Equal(s.T(), curBlockdevice.Status.DeviceStatus.FileSystem.MountPoint, "", "Mountpoint should be empty after we remove disk!") + require.Equal(s.T(), diskv1.ProvisionPhaseUnprovisioned, curBlockdevice.Status.ProvisionPhase, "Block device provisionPhase should be Provisioned") +} + func doCommand(cmdString string) (string, string, error) { var stdout bytes.Buffer var stderr bytes.Buffer