diff --git a/uaclient/cli/__init__.py b/uaclient/cli/__init__.py index a8c38a52d9..1d02e01ad5 100644 --- a/uaclient/cli/__init__.py +++ b/uaclient/cli/__init__.py @@ -180,7 +180,7 @@ def assert_lock_file(lock_holder=None): def wrapper(f): @wraps(f) def new_f(*args, cfg, **kwargs): - with lock.SingleAttemptLock(cfg=cfg, lock_holder=lock_holder): + with lock.SpinLock(cfg=cfg, lock_holder=lock_holder, sleep_time=1): retval = f(*args, cfg=cfg, **kwargs) return retval diff --git a/uaclient/cli/tests/test_cli_attach.py b/uaclient/cli/tests/test_cli_attach.py index ef1df08d7d..3429095db4 100644 --- a/uaclient/cli/tests/test_cli_attach.py +++ b/uaclient/cli/tests/test_cli_attach.py @@ -176,10 +176,12 @@ def test_already_attached(self, capsys, FakeConfig, event): } assert expected == json.loads(capsys.readouterr()[0]) + @mock.patch("time.sleep") @mock.patch("uaclient.system.subp") def test_lock_file_exists( self, m_subp, + m_sleep, capsys, FakeConfig, event, @@ -189,7 +191,7 @@ def test_lock_file_exists( cfg.write_cache("lock", "123:pro disable") with pytest.raises(LockHeldError) as exc_info: action_attach(mock.MagicMock(), cfg=cfg) - assert [mock.call(["ps", "123"])] == m_subp.call_args_list + assert [mock.call(["ps", "123"])] * 12 == m_subp.call_args_list assert ( "Unable to perform: pro attach.\n" "Operation in progress: pro disable (pid:123)" diff --git a/uaclient/cli/tests/test_cli_detach.py b/uaclient/cli/tests/test_cli_detach.py index c058615a4d..9e769c5bf8 100644 --- a/uaclient/cli/tests/test_cli_detach.py +++ b/uaclient/cli/tests/test_cli_detach.py @@ -103,10 +103,12 @@ def test_unattached_error_message( } assert expected == json.loads(capsys.readouterr()[0]) + @mock.patch("time.sleep") @mock.patch("uaclient.system.subp") def test_lock_file_exists( self, m_subp, + m_sleep, m_prompt, FakeConfig, capsys, @@ -118,7 +120,7 @@ def test_lock_file_exists( cfg.write_cache("lock", "123:pro enable") with pytest.raises(exceptions.LockHeldError) as err: action_detach(args, cfg=cfg) - assert [mock.call(["ps", "123"])] == m_subp.call_args_list + assert [mock.call(["ps", "123"])] * 12 == m_subp.call_args_list expected_error_msg = messages.E_LOCK_HELD_ERROR.format( lock_request="pro detach", lock_holder="pro enable", pid="123" ) diff --git a/uaclient/cli/tests/test_cli_disable.py b/uaclient/cli/tests/test_cli_disable.py index c3a64bbc0a..12670a0bd2 100644 --- a/uaclient/cli/tests/test_cli_disable.py +++ b/uaclient/cli/tests/test_cli_disable.py @@ -532,10 +532,12 @@ def test_unattached_error_message( expected["errors"][0]["additional_info"] = expected_info assert expected == json.loads(fake_stdout.getvalue()) + @mock.patch("time.sleep") @mock.patch("uaclient.system.subp") def test_lock_file_exists( self, m_subp, + m_sleep, FakeConfig, event, ): @@ -549,7 +551,7 @@ def test_lock_file_exists( with pytest.raises(exceptions.LockHeldError) as err: args.service = ["esm-infra"] action_disable(args, cfg) - assert [mock.call(["ps", "123"])] == m_subp.call_args_list + assert [mock.call(["ps", "123"])] * 12 == m_subp.call_args_list assert expected_error.msg == err.value.msg args.assume_yes = True diff --git a/uaclient/cli/tests/test_cli_enable.py b/uaclient/cli/tests/test_cli_enable.py index a53b08d6df..248830027f 100644 --- a/uaclient/cli/tests/test_cli_enable.py +++ b/uaclient/cli/tests/test_cli_enable.py @@ -131,10 +131,12 @@ def test_non_root_users_are_rejected( } assert expected == json.loads(capsys.readouterr()[0]) + @mock.patch("time.sleep") @mock.patch("uaclient.system.subp") def test_lock_file_exists( self, m_subp, + m_sleep, _refresh, capsys, event, @@ -147,7 +149,7 @@ def test_lock_file_exists( with pytest.raises(exceptions.LockHeldError) as err: action_enable(args, cfg=cfg) - assert [mock.call(["ps", "123"])] == m_subp.call_args_list + assert [mock.call(["ps", "123"])] * 12 == m_subp.call_args_list expected_message = messages.E_LOCK_HELD_ERROR.format( lock_request="pro enable", lock_holder="pro disable", pid="123" diff --git a/uaclient/cli/tests/test_cli_refresh.py b/uaclient/cli/tests/test_cli_refresh.py index 5e2c461b62..32facff7c7 100644 --- a/uaclient/cli/tests/test_cli_refresh.py +++ b/uaclient/cli/tests/test_cli_refresh.py @@ -75,14 +75,15 @@ def test_not_attached_errors( else: action_refresh(mock.MagicMock(target=target), cfg=cfg) + @mock.patch("time.sleep") @mock.patch("uaclient.system.subp") - def test_lock_file_exists(self, m_subp, FakeConfig): + def test_lock_file_exists(self, m_subp, m_sleep, FakeConfig): """Check inability to refresh if operation holds lock file.""" cfg = FakeConfig().for_attached_machine() cfg.write_cache("lock", "123:pro disable") with pytest.raises(exceptions.LockHeldError) as err: action_refresh(mock.MagicMock(), cfg=cfg) - assert [mock.call(["ps", "123"])] == m_subp.call_args_list + assert [mock.call(["ps", "123"])] * 12 == m_subp.call_args_list assert ( "Unable to perform: pro refresh.\n" "Operation in progress: pro disable (pid:123)"