@@ -20,6 +20,7 @@ import (
2020
2121 diskv1 "github.com/harvester/node-disk-manager/pkg/apis/harvesterhci.io/v1beta1"
2222 clientset "github.com/harvester/node-disk-manager/pkg/generated/clientset/versioned"
23+ "github.com/harvester/node-disk-manager/pkg/utils"
2324)
2425
2526/*
@@ -44,6 +45,7 @@ type HotPlugTestSuite struct {
4445 clientSet * clientset.Clientset
4546 targetNodeName string
4647 targetDiskName string
48+ curBusPath string // to make sure which path we deployed
4749}
4850
4951func (s * HotPlugTestSuite ) SetupSuite () {
@@ -148,6 +150,43 @@ func (s *HotPlugTestSuite) Test_2_HotPlugAddDisk() {
148150 require .Equal (s .T (), err , nil , "Get Blockdevices should not get error" )
149151
150152 require .Equal (s .T (), curBlockdevice .Status .State , diskv1 .BlockDeviceActive , "Disk status should be inactive after we add disk" )
153+ s .curBusPath = curBlockdevice .Status .DeviceStatus .Details .BusPath
154+ }
155+
156+ func (s * HotPlugTestSuite ) Test_3_AddDuplicatedWWNDsik () {
157+ // create another another disk raw file and xml
158+ const (
159+ originalDeviceRaw = "/tmp/hotplug_disks/node1-sda.qcow2"
160+ duplicatedDeviceXML = "/tmp/hotplug_disks/node1-sdb.xml"
161+ duplicatedDeviceRaw = "/tmp/hotplug_disks/node1-sdb.qcow2"
162+ )
163+ cmdCpyRawFile := fmt .Sprintf ("cp %s %s" , originalDeviceRaw , duplicatedDeviceRaw )
164+ _ , _ , err := doCommand (cmdCpyRawFile )
165+ require .Equal (s .T (), err , nil , "Running command `cp the raw device file` should not get error" )
166+
167+ disk , err := utils .DiskXMLReader (hotplugDiskXMLFileName )
168+ require .Equal (s .T (), err , nil , "Read xml file should not get error" )
169+ disk .Source .File = duplicatedDeviceRaw
170+ disk .Target .Dev = "sdb"
171+ err = utils .XMLWriter (duplicatedDeviceXML , disk )
172+ require .Equal (s .T (), err , nil , "Write xml file should not get error" )
173+
174+ cmd := fmt .Sprintf ("virsh attach-device --domain %s --file %s --live" , hotplugTargetNodeName , duplicatedDeviceXML )
175+ _ , _ , err = doCommand (cmd )
176+ require .Equal (s .T (), err , nil , "Running command `virsh attach-device` should not get error" )
177+
178+ // wait for controller handling
179+ time .Sleep (5 * time .Second )
180+
181+ // check disk status
182+ require .NotEqual (s .T (), s .targetDiskName , "" , "target disk name should not be empty before we start hotplug (add) test" )
183+ bdi := s .clientSet .HarvesterhciV1beta1 ().BlockDevices ("longhorn-system" )
184+ blockdeviceList , err := bdi .List (context .TODO (), v1.ListOptions {})
185+ require .Equal (s .T (), err , nil , "Get BlockdevicesList should not get error" )
186+ require .Equal (s .T (), 1 , len (blockdeviceList .Items ), "We should have one disks because duplicated wwn should not added" )
187+ curBlockdevice , err := bdi .Get (context .TODO (), s .targetDiskName , v1.GetOptions {})
188+ require .Equal (s .T (), err , nil , "Get Blockdevices should not get error" )
189+ require .Equal (s .T (), s .curBusPath , curBlockdevice .Status .DeviceStatus .Details .BusPath , "Disk path should not replace by duplicated wwn disk" )
151190
152191}
153192
0 commit comments