Skip to content

Commit

Permalink
ci: add disk tags integration tests
Browse files Browse the repository at this point in the history
    - Add tags with provision
    - Remove tags from provisioned blockdevice
    - Add tags to provisioned blockdevice

Signed-off-by: Vicente Cheng <vicente.cheng@suse.com>
  • Loading branch information
Vicente-Cheng committed Dec 4, 2023
1 parent ff30429 commit 1d25abf
Showing 1 changed file with 52 additions and 1 deletion.
53 changes: 52 additions & 1 deletion tests/integration/test_0_single_disk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
}

0 comments on commit 1d25abf

Please sign in to comment.