@@ -396,6 +396,32 @@ def _get_sink_volume(self, vm) -> str:
396396 self .fail ("{} sink-input not found in {}" .format (vm .name , audiovm .name ))
397397 assert False
398398
399+ def _reset_sink_volume (self , vm ) -> None :
400+ """Reset VM's sink-input volume to 100% and unmuted"""
401+ audiovm = vm .audiovm
402+
403+ sinks = json .loads (
404+ self ._call_in_audiovm (
405+ audiovm , ["pactl" , "-f" , "json" , "list" , "sink-inputs" ]
406+ )
407+ )
408+
409+ if not sinks :
410+ self .fail ("no sink-inputs found in {}" .format (audiovm .name ))
411+ assert False
412+
413+ for sink in sinks :
414+ if sink ["properties" ]["application.name" ] == vm .name :
415+ self ._call_in_audiovm (
416+ audiovm ,
417+ ["pactl" , "set-sink-input-volume" , sink ["index" ], "100%" ],
418+ )
419+ self ._call_in_audiovm (
420+ audiovm ,
421+ ["pactl" , sink ["index" ], "set-sink-input-mute" , "0" ],
422+ )
423+ break
424+
399425 async def retrieve_audio_input (self , vm , status ):
400426 try :
401427 await asyncio .wait_for (
@@ -784,7 +810,12 @@ def test_261_audio_initial_volume_42_percent(self):
784810 self .testvm1 .features ["audio-initial-volume" ] = "42"
785811 self .loop .run_until_complete (self .testvm1 .start ())
786812 self .wait_for_pulseaudio_startup (self .testvm1 )
787- assert self ._get_sink_volume (self .testvm1 ) == "42%"
813+ try :
814+ assert self ._get_sink_volume (self .testvm1 ) == "42%"
815+ except AssertionError :
816+ raise
817+ finally :
818+ self ._reset_sink_volume (self .testvm1 )
788819
789820 @unittest .skipUnless (
790821 spawn .find_executable ("pactl" ),
@@ -794,7 +825,12 @@ def test_262_audio_initial_volume_mute(self):
794825 self .testvm1 .features ["audio-initial-volume" ] = "mute"
795826 self .loop .run_until_complete (self .testvm1 .start ())
796827 self .wait_for_pulseaudio_startup (self .testvm1 )
797- assert self ._get_sink_volume (self .testvm1 ) == "mute"
828+ try :
829+ assert self ._get_sink_volume (self .testvm1 ) == "mute"
830+ except AssertionError :
831+ raise
832+ finally :
833+ self ._reset_sink_volume (self .testvm1 )
798834
799835
800836def create_testcases_for_templates ():
0 commit comments