tests/acceptance: test hot(un)plug of ccw devices
PATCH v2 1/1 tests/acceptance: test hot(un)plug of ccw devices
Hotplug a virtio-net-ccw device, and then hotunplug it again.
---
v1->v2:
- switch device id
- clear out dmesg before looking for CRW messages
--- tests/acceptance/machine_s390_ccw_virtio.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
tests/acceptance/machine_s390_ccw_virtio.py +16 -0
@@ -97,3 +97,19 @@ class S390CCWVirtioMachine(Test): exec_command_and_wait_for_pattern(self, 'cat /sys/bus/pci/devices/000a\:00\:00.0/function_id', '0x0000000c') + # add another device + exec_command_and_wait_for_pattern(self, 'dmesg -c', ' ') + self.vm.command('device_add', driver='virtio-net-ccw', + devno='fe.0.4711', id='net_4711') + exec_command_and_wait_for_pattern(self, 'dmesg', 'CRW') + exec_command_and_wait_for_pattern(self, 'ls /sys/bus/ccw/devices/', + '0.0.4711') + # and detach it again + exec_command_and_wait_for_pattern(self, 'dmesg -c', ' ') + self.vm.command('device_del', id='net_4711') + self.vm.event_wait(name='DEVICE_DELETED', + match={'data': {'device': 'net_4711'}}) + exec_command_and_wait_for_pattern(self, 'dmesg', 'CRW') + exec_command_and_wait_for_pattern(self, + 'ls /sys/bus/ccw/devices/0.0.4711', + 'No such file or directory')
Signature · 1 line
2.26.2
Hi,
Quoted 18 lines · Cornelia Huck
Hotplug a virtio-net-ccw device, and then hotunplug it again.
Signed-off-by Cornelia Huck <[email protected]>---
v1->v2:
- switch device id
- clear out dmesg before looking for CRW messages--- tests/acceptance/machine_s390_ccw_virtio.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)tests/acceptance/machine_s390_ccw_virtio.py +0
-0
tests/acceptance/machine_s390_ccw_virtio.py class S390CCWVirtioMachine(Test): · line 101
Quoted 5 lines
tests/acceptance/machine_s390_ccw_virtio.py +2
-0@@ -97,3 +97,19 @@ class S390CCWVirtioMachine(Test): exec_command_and_wait_for_pattern(self, 'cat /sys/bus/pci/devices/000a\:00\:00.0/function_id', '0x0000000c') + # add another device + exec_command_and_wait_for_pattern(self, 'dmesg -c', ' ')
The problem is that dmesg -c will fail if you run the test with unprivileged user.
- Wainer
Quoted 14 lines
tests/acceptance/machine_s390_ccw_virtio.py +14
-0+ self.vm.command('device_add', driver='virtio-net-ccw', + devno='fe.0.4711', id='net_4711') + exec_command_and_wait_for_pattern(self, 'dmesg', 'CRW') + exec_command_and_wait_for_pattern(self, 'ls /sys/bus/ccw/devices/', + '0.0.4711') + # and detach it again + exec_command_and_wait_for_pattern(self, 'dmesg -c', ' ') + self.vm.command('device_del', id='net_4711') + self.vm.event_wait(name='DEVICE_DELETED', + match={'data': {'device': 'net_4711'}}) + exec_command_and_wait_for_pattern(self, 'dmesg', 'CRW') + exec_command_and_wait_for_pattern(self, + 'ls /sys/bus/ccw/devices/0.0.4711', + 'No such file or directory')
Quoted 16 lines · On Fri, 4 Dec 2020 11:05:34 -0300 Wainer dos Santos Moschetta…
Hi,
Quoted 13 lines · Cornelia Huck
Hotplug a virtio-net-ccw device, and then hotunplug it again.
Signed-off-by Cornelia Huck <[email protected]>---
v1->v2:
- switch device id
- clear out dmesg before looking for CRW messages--- tests/acceptance/machine_s390_ccw_virtio.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
Quoted 14 lines
tests/acceptance/machine_s390_ccw_virtio.py class S390CCWVirtioMachine(Test): · line 101
Quoted 10 lines
tests/acceptance/machine_s390_ccw_virtio.py +2
-0@@ -97,3 +97,19 @@ class S390CCWVirtioMachine(Test): exec_command_and_wait_for_pattern(self, 'cat /sys/bus/pci/devices/000a\:00\:00.0/function_id', '0x0000000c') + # add another device + exec_command_and_wait_for_pattern(self, 'dmesg -c', ' ')The problem is that
dmesg -cwill fail if you run the test with unprivileged user.
Hm, why should that make a difference for a guest command?
Quoted 17 lines
- Wainer
Quoted 14 lines
tests/acceptance/machine_s390_ccw_virtio.py +14
-0+ self.vm.command('device_add', driver='virtio-net-ccw', + devno='fe.0.4711', id='net_4711') + exec_command_and_wait_for_pattern(self, 'dmesg', 'CRW') + exec_command_and_wait_for_pattern(self, 'ls /sys/bus/ccw/devices/', + '0.0.4711') + # and detach it again + exec_command_and_wait_for_pattern(self, 'dmesg -c', ' ') + self.vm.command('device_del', id='net_4711') + self.vm.event_wait(name='DEVICE_DELETED', + match={'data': {'device': 'net_4711'}}) + exec_command_and_wait_for_pattern(self, 'dmesg', 'CRW') + exec_command_and_wait_for_pattern(self, + 'ls /sys/bus/ccw/devices/0.0.4711', + 'No such file or directory')
Wainer dos Santos Moschetta
Reviewed-byQuoted 32 lines · Cornelia Huck
Quoted 16 lines · On Fri, 4 Dec 2020 11:05:34 -0300 Wainer dos Santos Moschetta…
Hi,
Quoted 13 lines · Cornelia Huck
Hotplug a virtio-net-ccw device, and then hotunplug it again.
Signed-off-by Cornelia Huck <[email protected]>---
v1->v2:
- switch device id
- clear out dmesg before looking for CRW messages--- tests/acceptance/machine_s390_ccw_virtio.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)Quoted 13 lines
tests/acceptance/machine_s390_ccw_virtio.py class S390CCWVirtioMachine(Test): · line 101
Quoted 10 lines
tests/acceptance/machine_s390_ccw_virtio.py +2
-0@@ -97,3 +97,19 @@ class S390CCWVirtioMachine(Test): exec_command_and_wait_for_pattern(self, 'cat /sys/bus/pci/devices/000a\:00\:00.0/function_id', '0x0000000c') + # add another device + exec_command_and_wait_for_pattern(self, 'dmesg -c', ' ')The problem is that
dmesg -cwill fail if you run the test with unprivileged user.
Quoted 1 line
Hm, why should that make a difference for a guest command?
Never mind, my brain mix host and guest very often....
Quoted 17 lines
Quoted 17 lines
- Wainer
Quoted 14 lines
tests/acceptance/machine_s390_ccw_virtio.py +14
-0+ self.vm.command('device_add', driver='virtio-net-ccw', + devno='fe.0.4711', id='net_4711') + exec_command_and_wait_for_pattern(self, 'dmesg', 'CRW') + exec_command_and_wait_for_pattern(self, 'ls /sys/bus/ccw/devices/', + '0.0.4711') + # and detach it again + exec_command_and_wait_for_pattern(self, 'dmesg -c', ' ') + self.vm.command('device_del', id='net_4711') + self.vm.event_wait(name='DEVICE_DELETED', + match={'data': {'device': 'net_4711'}}) + exec_command_and_wait_for_pattern(self, 'dmesg', 'CRW') + exec_command_and_wait_for_pattern(self, + 'ls /sys/bus/ccw/devices/0.0.4711', + 'No such file or directory')
Quoted 33 lines · On Fri, 4 Dec 2020 17:13:22 -0300 Wainer dos Santos Moschetta…
Quoted 32 lines · Cornelia Huck
Quoted 29 lines · On Fri, 4 Dec 2020 11:05:34 -0300 Wainer dos Santos Moschetta…
Hi,
Quoted 18 lines · Cornelia Huck
Hotplug a virtio-net-ccw device, and then hotunplug it again.
Signed-off-by Cornelia Huck <[email protected]>---
v1->v2:
- switch device id
- clear out dmesg before looking for CRW messages--- tests/acceptance/machine_s390_ccw_virtio.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)tests/acceptance/machine_s390_ccw_virtio.py +0
-0tests/acceptance/machine_s390_ccw_virtio.py class S390CCWVirtioMachine(Test): · line 101
Quoted 5 lines
tests/acceptance/machine_s390_ccw_virtio.py +2
-0@@ -97,3 +97,19 @@ class S390CCWVirtioMachine(Test): exec_command_and_wait_for_pattern(self, 'cat /sys/bus/pci/devices/000a\:00\:00.0/function_id', '0x0000000c') + # add another device + exec_command_and_wait_for_pattern(self, 'dmesg -c', ' ')The problem is that
dmesg -cwill fail if you run the test with unprivileged user.
Quoted 4 lines
Quoted 1 line
Hm, why should that make a difference for a guest command?
Never mind, my brain mix host and guest very often....
I'm sure you're not the only one :)
Quoted 2 lines
Reviewed-by Wainer dos Santos Moschetta <[email protected]>
Thanks!
Quoted 19 lines
Quoted 19 lines
Quoted 19 lines
- Wainer
Quoted 14 lines
tests/acceptance/machine_s390_ccw_virtio.py +14
-0+ self.vm.command('device_add', driver='virtio-net-ccw', + devno='fe.0.4711', id='net_4711') + exec_command_and_wait_for_pattern(self, 'dmesg', 'CRW') + exec_command_and_wait_for_pattern(self, 'ls /sys/bus/ccw/devices/', + '0.0.4711') + # and detach it again + exec_command_and_wait_for_pattern(self, 'dmesg -c', ' ') + self.vm.command('device_del', id='net_4711') + self.vm.event_wait(name='DEVICE_DELETED', + match={'data': {'device': 'net_4711'}}) + exec_command_and_wait_for_pattern(self, 'dmesg', 'CRW') + exec_command_and_wait_for_pattern(self, + 'ls /sys/bus/ccw/devices/0.0.4711', + 'No such file or directory')
Quoted 18 lines · Cornelia Huck
Hotplug a virtio-net-ccw device, and then hotunplug it again.
Signed-off-by Cornelia Huck <[email protected]>---
v1->v2:
- switch device id
- clear out dmesg before looking for CRW messages--- tests/acceptance/machine_s390_ccw_virtio.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)tests/acceptance/machine_s390_ccw_virtio.py +0
-0
tests/acceptance/machine_s390_ccw_virtio.py class S390CCWVirtioMachine(Test): · line 104
Quoted 8 lines
tests/acceptance/machine_s390_ccw_virtio.py +5
-0@@ -97,3 +97,19 @@ class S390CCWVirtioMachine(Test): exec_command_and_wait_for_pattern(self, 'cat /sys/bus/pci/devices/000a\:00\:00.0/function_id', '0x0000000c') + # add another device + exec_command_and_wait_for_pattern(self, 'dmesg -c', ' ') + self.vm.command('device_add', driver='virtio-net-ccw', + devno='fe.0.4711', id='net_4711') + exec_command_and_wait_for_pattern(self, 'dmesg', 'CRW')
Looking at this twice, I'm a little bit afraid that this could be racy - what if the kernel decides to emit the line with the "CRW" just after we executed the dmesg command? I'd maybe use something like this instead:
exec_command_and_wait_for_pattern(self,
'while ! dmesg -c | grep CRW ; do sleep 1 ; done', '~ #')
tests/acceptance/machine_s390_ccw_virtio.py class S390CCWVirtioMachine(Test): · line 108
Quoted 4 lines
tests/acceptance/machine_s390_ccw_virtio.py +4
-0+ exec_command_and_wait_for_pattern(self, 'ls /sys/bus/ccw/devices/', + '0.0.4711') + # and detach it again + exec_command_and_wait_for_pattern(self, 'dmesg -c', ' ')
If adapt my above change, you could also get rid of this dmesg -c here (since it's done in the while loop already)
tests/acceptance/machine_s390_ccw_virtio.py class S390CCWVirtioMachine(Test): · line 112
Quoted 4 lines
tests/acceptance/machine_s390_ccw_virtio.py +4
-0+ self.vm.command('device_del', id='net_4711') + self.vm.event_wait(name='DEVICE_DELETED', + match={'data': {'device': 'net_4711'}}) + exec_command_and_wait_for_pattern(self, 'dmesg', 'CRW')
dito
tests/acceptance/machine_s390_ccw_virtio.py class S390CCWVirtioMachine(Test): · line 115
Quoted 3 lines
tests/acceptance/machine_s390_ccw_virtio.py +3
-0+ exec_command_and_wait_for_pattern(self, + 'ls /sys/bus/ccw/devices/0.0.4711', + 'No such file or directory')
With my suggestion applied:
Quoted 32 lines · On Mon, 7 Dec 2020 15:28:47 +0100 Thomas Huth <[email protected]> wrote:
Quoted 18 lines · Cornelia Huck
Hotplug a virtio-net-ccw device, and then hotunplug it again.
Signed-off-by Cornelia Huck <[email protected]>---
v1->v2:
- switch device id
- clear out dmesg before looking for CRW messages--- tests/acceptance/machine_s390_ccw_virtio.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)tests/acceptance/machine_s390_ccw_virtio.py +0
-0tests/acceptance/machine_s390_ccw_virtio.py class S390CCWVirtioMachine(Test): · line 104
Quoted 8 lines
tests/acceptance/machine_s390_ccw_virtio.py +5
-0@@ -97,3 +97,19 @@ class S390CCWVirtioMachine(Test): exec_command_and_wait_for_pattern(self, 'cat /sys/bus/pci/devices/000a\:00\:00.0/function_id', '0x0000000c') + # add another device + exec_command_and_wait_for_pattern(self, 'dmesg -c', ' ') + self.vm.command('device_add', driver='virtio-net-ccw', + devno='fe.0.4711', id='net_4711') + exec_command_and_wait_for_pattern(self, 'dmesg', 'CRW')Looking at this twice, I'm a little bit afraid that this could be racy - what if the kernel decides to emit the line with the "CRW" just after we executed the dmesg command? I'd maybe use something like this instead:
Quoted 2 lines
exec_command_and_wait_for_pattern(self,
'while ! dmesg -c | grep CRW ; do sleep 1 ; done', '~ #')
Yes, you're right. Unless anyone can think of a better incantation?
Quoted 8 lines
tests/acceptance/machine_s390_ccw_virtio.py class S390CCWVirtioMachine(Test): · line 108
Quoted 5 lines
tests/acceptance/machine_s390_ccw_virtio.py +4
-0+ exec_command_and_wait_for_pattern(self, 'ls /sys/bus/ccw/devices/', + '0.0.4711') + # and detach it again + exec_command_and_wait_for_pattern(self, 'dmesg -c', ' ')If adapt my above change, you could also get rid of this dmesg -c here (since it's done in the while loop already)
I don't think so (there are two CRWs posted, and the loop might have caught the first one only.)
Quoted 15 lines
tests/acceptance/machine_s390_ccw_virtio.py class S390CCWVirtioMachine(Test): · line 112
Quoted 5 lines
tests/acceptance/machine_s390_ccw_virtio.py +4
-0+ self.vm.command('device_del', id='net_4711') + self.vm.event_wait(name='DEVICE_DELETED', + match={'data': {'device': 'net_4711'}}) + exec_command_and_wait_for_pattern(self, 'dmesg', 'CRW')dito
tests/acceptance/machine_s390_ccw_virtio.py class S390CCWVirtioMachine(Test): · line 115
Quoted 3 lines
tests/acceptance/machine_s390_ccw_virtio.py +3
-0+ exec_command_and_wait_for_pattern(self, + 'ls /sys/bus/ccw/devices/0.0.4711', + 'No such file or directory')With my suggestion applied:
Reviewed-by Thomas Huth <[email protected]>
Quoted 35 lines · Cornelia Huck
Quoted 32 lines · On Mon, 7 Dec 2020 15:28:47 +0100 Thomas Huth <[email protected]> wrote:
Quoted 18 lines · Cornelia Huck
Hotplug a virtio-net-ccw device, and then hotunplug it again.
Signed-off-by Cornelia Huck <[email protected]>---
v1->v2:
- switch device id
- clear out dmesg before looking for CRW messages--- tests/acceptance/machine_s390_ccw_virtio.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)tests/acceptance/machine_s390_ccw_virtio.py +0
-0tests/acceptance/machine_s390_ccw_virtio.py class S390CCWVirtioMachine(Test): · line 104
Quoted 8 lines
tests/acceptance/machine_s390_ccw_virtio.py +5
-0@@ -97,3 +97,19 @@ class S390CCWVirtioMachine(Test): exec_command_and_wait_for_pattern(self, 'cat /sys/bus/pci/devices/000a\:00\:00.0/function_id', '0x0000000c') + # add another device + exec_command_and_wait_for_pattern(self, 'dmesg -c', ' ') + self.vm.command('device_add', driver='virtio-net-ccw', + devno='fe.0.4711', id='net_4711') + exec_command_and_wait_for_pattern(self, 'dmesg', 'CRW')Looking at this twice, I'm a little bit afraid that this could be racy - what if the kernel decides to emit the line with the "CRW" just after we executed the dmesg command? I'd maybe use something like this instead:
Quoted 4 lines
Quoted 2 lines
exec_command_and_wait_for_pattern(self,
'while ! dmesg -c | grep CRW ; do sleep 1 ; done', '~ #')Yes, you're right. Unless anyone can think of a better incantation?
You could maybe drop the sleep 1 to avoid delays... but that might burn more CPU cycles, so not sure what's better here?
(Unfortunately, that "sleep" in the initrd does not support fractions, otherwise I'd suggest "sleep 0.1" instead)
Quoted 11 lines
Quoted 8 lines
tests/acceptance/machine_s390_ccw_virtio.py class S390CCWVirtioMachine(Test): · line 108
Quoted 5 lines
tests/acceptance/machine_s390_ccw_virtio.py +4
-0+ exec_command_and_wait_for_pattern(self, 'ls /sys/bus/ccw/devices/', + '0.0.4711') + # and detach it again + exec_command_and_wait_for_pattern(self, 'dmesg -c', ' ')If adapt my above change, you could also get rid of this dmesg -c here (since it's done in the while loop already)
I don't think so (there are two CRWs posted, and the loop might have caught the first one only.)
Oh, you're right. So let's better be safe than sorry and keep this dmesg -c.
Thomas
Quoted 10 lines · Thomas Huth
Quoted 8 lines · Cornelia Huck
Quoted 5 lines · On Mon, 7 Dec 2020 15:28:47 +0100 Thomas Huth <[email protected]> wrote:
Quoted 4 lines · Cornelia Huck
Hotplug a virtio-net-ccw device, and then hotunplug it again.
Signed-off-by Cornelia Huck <[email protected]>---
[...]
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
tests/acceptance/machine_s390_ccw_virtio.py +4
-0+ exec_command_and_wait_for_pattern(self, 'ls /sys/bus/ccw/devices/', + '0.0.4711') + # and detach it again + exec_command_and_wait_for_pattern(self, 'dmesg -c', ' ')
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
If adapt my above change, you could also get rid of this dmesg -c here (since it's done in the while loop already)
I don't think so (there are two CRWs posted, and the loop might have caught the first one only.)
Oh, you're right. So let's better be safe than sorry and keep this dmesg -c.
Ok, as we had to discover during some testing, it's a bad idea to only wait for ' ' after the 'dmesg -c' since it matches too early, so that the device gets added while the dmesg command is still running.
The following code is working for me instead:
# add another device
exec_command_and_wait_for_pattern(self,
'dmesg -c > /dev/null; echo dm-clear\ 1', 'dm-clear 1')
self.vm.command('device_add', driver='virtio-net-ccw',
devno='fe.0.4711', id='net_4711')
exec_command_and_wait_for_pattern(self,
'while ! (dmesg -c | grep CRW) ; do sleep 1 ; done',
'CRW reports')
exec_command_and_wait_for_pattern(self, 'ls /sys/bus/ccw/devices/',
'0.0.4711')
# and detach it again
exec_command_and_wait_for_pattern(self,
'dmesg -c > /dev/null; echo dm-clear\ 2', 'dm-clear 2')
self.vm.command('device_del', id='net_4711')
self.vm.event_wait(name='DEVICE_DELETED',
match={'data': {'device': 'net_4711'}})
exec_command_and_wait_for_pattern(self,
'while ! (dmesg -c | grep CRW) ; do sleep 1 ; done',
'CRW reports')
exec_command_and_wait_for_pattern(self,
'ls /sys/bus/ccw/devices/0.0.4711',
'No such file or directory') HTH,
Thomas
Quoted 45 lines · On Mon, 7 Dec 2020 19:40:36 +0100 Thomas Huth <[email protected]> wrote:
Quoted 10 lines · Thomas Huth
Quoted 8 lines · Cornelia Huck
Quoted 5 lines · On Mon, 7 Dec 2020 15:28:47 +0100 Thomas Huth <[email protected]> wrote:
Quoted 4 lines · Cornelia Huck
Hotplug a virtio-net-ccw device, and then hotunplug it again.
Signed-off-by Cornelia Huck <[email protected]>---
[...]
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
tests/acceptance/machine_s390_ccw_virtio.py +4
-0+ exec_command_and_wait_for_pattern(self, 'ls /sys/bus/ccw/devices/', + '0.0.4711') + # and detach it again + exec_command_and_wait_for_pattern(self, 'dmesg -c', ' ')Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
If adapt my above change, you could also get rid of this dmesg -c here (since it's done in the while loop already)
I don't think so (there are two CRWs posted, and the loop might have caught the first one only.)
Oh, you're right. So let's better be safe than sorry and keep this dmesg -c.
Ok, as we had to discover during some testing, it's a bad idea to only wait for ' ' after the 'dmesg -c' since it matches too early, so that the device gets added while the dmesg command is still running.
The following code is working for me instead:
# add another device exec_command_and_wait_for_pattern(self, 'dmesg -c > /dev/null; echo dm-clear\ 1', 'dm-clear 1') self.vm.command('device_add', driver='virtio-net-ccw', devno='fe.0.4711', id='net_4711') exec_command_and_wait_for_pattern(self, 'while ! (dmesg -c | grep CRW) ; do sleep 1 ; done', 'CRW reports') exec_command_and_wait_for_pattern(self, 'ls /sys/bus/ccw/devices/', '0.0.4711') # and detach it again exec_command_and_wait_for_pattern(self, 'dmesg -c > /dev/null; echo dm-clear\ 2', 'dm-clear 2') self.vm.command('device_del', id='net_4711')
Quoted 8 lines
self.vm.event_wait(name='DEVICE_DELETED',
match={'data': {'device': 'net_4711'}})
exec_command_and_wait_for_pattern(self,
'while ! (dmesg -c | grep CRW) ; do sleep 1 ; done',
'CRW reports')
exec_command_and_wait_for_pattern(self,
'ls /sys/bus/ccw/devices/0.0.4711',
'No such file or directory')Thanks for tracking this down, this works for me as well. I'll send a v3.