Skip to content

Commit

Permalink
qemu: add env COSA_TEST_CDROM_UNPLUG to test cdrom unplug
Browse files Browse the repository at this point in the history
The context is to hacky code to test openshift/os#1346

According to Colin's pointer
openshift/os#1350 (comment)

The cdrom should be `scsi-cd`, as `ide` device can not be
hotplugging. So should not pass `-cdrom` to qemu as it is `ide`
by default which could not work.
```
[coreos-assembler]$ env COSA_TEST_CDROM_UNPLUG=5s cosa run qemu.qcow2 --debug -- \
-drive id=cdrom0,if=none,readonly=on,file=/srv/test.iso \
-device virtio-scsi-pci,id=scsi0 \
-device scsi-cd,bus=scsi0.0,drive=cdrom0
...
2023-09-12T10:54:08Z platform: get cdrom id /machine/peripheral-anon/device[2]
[STARTUP] '2023-09-12T10:54:13Z platform: delete cdrom
...
[core@cosa-devsh ~]$ ls /dev/sr0
ls: cannot access '/dev/sr0': No such file or directory
```
  • Loading branch information
HuijingHei authored and cgwalters committed Sep 13, 2023
1 parent cd3937f commit a1a0047
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions mantle/platform/qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -1910,6 +1910,43 @@ func (builder *QemuBuilder) Exec() (*QemuInstance, error) {
return nil, fmt.Errorf("failed to connect over qmp to qemu instance")
}

// Hacky code to test https://github.com/openshift/os/pull/1346
if timeout, ok := os.LookupEnv("COSA_TEST_CDROM_UNPLUG"); ok {
val, err := time.ParseDuration(timeout)
if err != nil {
return nil, err
}
go func() {
devs, err := inst.listDevices()
if err != nil {
plog.Error("failed to list devices")
return
}

var cdrom string
for _, dev := range devs.Return {
switch dev.Type {
case "child<scsi-cd>":
cdrom = filepath.Join("/machine/peripheral-anon", dev.Name)
default:
break
}
}
if cdrom == "" {
plog.Errorf("failed to get scsi-cd id")
return
}

plog.Debugf("get cdrom id %s", cdrom)
time.Sleep(val)
if err := inst.deleteBlockDevice(cdrom); err != nil {
plog.Errorf("failed to delete block device: %s", cdrom)
return
}
plog.Info("delete cdrom")
}()
}

return &inst, nil
}

Expand Down

0 comments on commit a1a0047

Please sign in to comment.