diff --git a/test/gui/shared/scripts/bdd_hooks.py b/test/gui/shared/scripts/bdd_hooks.py index 72790b98b19..eed20f49887 100644 --- a/test/gui/shared/scripts/bdd_hooks.py +++ b/test/gui/shared/scripts/bdd_hooks.py @@ -23,7 +23,7 @@ from helpers.SyncHelper import close_socket_connection, clear_waited_after_sync from helpers.SpaceHelper import delete_project_spaces from helpers.api.provisioning import delete_created_groups, delete_created_users -from helpers.SetupClientHelper import wait_until_app_killed, unlock_keyring +from helpers.SetupClientHelper import wait_until_app_killed, check_keyring from helpers.ConfigHelper import ( init_config, get_config, @@ -62,7 +62,7 @@ def hook(context): # Order: 1 @OnScenarioStart def hook(context): - unlock_keyring() + check_keyring() clear_scenario_config() diff --git a/test/gui/shared/scripts/helpers/SetupClientHelper.py b/test/gui/shared/scripts/helpers/SetupClientHelper.py index 32849b168d9..bc0b4fdde3c 100644 --- a/test/gui/shared/scripts/helpers/SetupClientHelper.py +++ b/test/gui/shared/scripts/helpers/SetupClientHelper.py @@ -13,7 +13,7 @@ from helpers.SyncHelper import listen_sync_status_for_item from helpers.api.utils import url_join from helpers.UserHelper import get_displayname_for_user -from helpers.ReportHelper import is_video_enabled, take_screenshot +from helpers.ReportHelper import is_video_enabled def substitute_inline_codes(value): @@ -230,10 +230,46 @@ def generate_uuidv4(): # sometimes the keyring is locked during the test execution, and we need to unlock it -def unlock_keyring(): +def check_keyring(): if is_windows(): return + if is_keyring_locked(): + test.log('Keyring is locked or service is down. Unlocking...') + wait_until_keyring_unlocked() + + +def unlock_keyring(): + password = os.getenv('VNC_PW') + command = f'echo -n "{password}" | gnome-keyring-daemon -r --unlock' + stdout, stderr, returncode = run_sys_command(command, True) + + output = '' + if stdout: + output = stdout.decode('utf-8') + if stderr: + output = stderr.decode('utf-8') + test.log(f'Unlock output: {output}') + # wait for keyring to unlock + squish.snooze(1) + + if returncode: + return False + + return not is_keyring_locked() + + +def wait_until_keyring_unlocked(): + timeout = 5 * 1000 + unlocked = squish.waitFor( + lambda: unlock_keyring(), # pylint: disable=unnecessary-lambda + timeout, + ) + if not unlocked: + test.fail(f'Timeout. Keyring was not unlocked within {timeout} milliseconds') + + +def is_keyring_locked(): stdout, stderr, _ = run_sys_command( [ 'busctl', @@ -250,63 +286,8 @@ def unlock_keyring(): output = stdout.decode('utf-8') if stderr: output = stderr.decode('utf-8') - - test.log(f'Keyring status: {output}') - command = 'ps aux | grep keyring | grep -v grep' - stdout, stderr, returncode = run_sys_command(command, True) - pso = '' - if stdout: - pso = stdout.decode('utf-8') - if stderr: - pso = stderr.decode('utf-8') - test.log('PS: -------------------') - test.log(pso) - test.log(':-------------------') - - if not output.strip().endswith('false'): - test.log('[INFO] Keyring is locked...') - squish.snooze(5) - # command = 'ps aux | grep dbus | grep -v grep' - # stdout, stderr, returncode = run_sys_command(command, True) - # if stdout: - # output = stdout.decode('utf-8') - # if stderr: - # output = stderr.decode('utf-8') - # test.log(f'dbus ps: {output}') - - start_client() - take_screenshot('keyring_locked.png') - - password = os.getenv('VNC_PW') - command = f'echo -n "{password}" | gnome-keyring-daemon -r -d --unlock' - stdout, stderr, returncode = run_sys_command(command, True) - if stdout: - output = stdout.decode('utf-8') - if stderr: - output = stderr.decode('utf-8') - test.log(f'unlock: {output}') - squish.snooze(5) - command = 'ps aux | grep keyring | grep -v grep' - stdout, stderr, returncode = run_sys_command(command, True) - if stdout: - output = stdout.decode('utf-8') - if stderr: - output = stderr.decode('utf-8') - test.log('PS: -------------------') - test.log(output) - test.log(':-------------------') - - take_screenshot('keyring_unlocked.png') - - for ctx in squish.applicationContextList(): - # get pid before detaching - pid = ctx.pid - ctx.detach() - wait_until_app_killed(pid) - test.fail('debug') - - if returncode: - test.log(f'Failed to unlock keyring:\n{output}') + test.log(f'Keyring Locked: {output}') + return not output.strip().endswith('false') def run_sys_command(command=None, shell=False):