Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

agent update refactor #2706

Merged
merged 8 commits into from
Dec 14, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
577 changes: 577 additions & 0 deletions azurelinuxagent/ga/agent_update.py

Large diffs are not rendered by default.

657 changes: 14 additions & 643 deletions azurelinuxagent/ga/update.py

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion makepkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from azurelinuxagent.common.version import AGENT_NAME, AGENT_VERSION, \
AGENT_LONG_VERSION
from azurelinuxagent.ga.update import AGENT_MANIFEST_FILE
from azurelinuxagent.ga.agent_update import AGENT_MANIFEST_FILE

MANIFEST = '''[{{
"name": "{0}",
Expand Down
4 changes: 0 additions & 4 deletions tests/data/wire/ext_conf_missing_family.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
<GuestAgentExtension
xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<GAFamilies>
<GAFamily>
<Name>Prod</Name>
<Uris />
</GAFamily>
narrieta marked this conversation as resolved.
Show resolved Hide resolved
<GAFamily>
<Name>Test</Name>
<Uris>
Expand Down
73 changes: 40 additions & 33 deletions tests/ga/mocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import contextlib

from mock import PropertyMock

from azurelinuxagent.ga.agent_update import AgentUpdateHandler
from azurelinuxagent.ga.exthandlers import ExtHandlersHandler
from azurelinuxagent.ga.remoteaccess import RemoteAccessHandler
from azurelinuxagent.ga.update import UpdateHandler, get_update_handler
Expand All @@ -30,6 +32,7 @@ def mock_update_handler(protocol,
on_new_iteration=lambda _: None,
exthandlers_handler=None,
remote_access_handler=None,
agent_update_handler=None,
autoupdate_enabled=False,
check_daemon_running=False,
start_background_threads=False,
Expand Down Expand Up @@ -71,6 +74,9 @@ def is_running(*args): # mock for property UpdateHandler.is_running, which cont
if remote_access_handler is None:
remote_access_handler = RemoteAccessHandler(protocol)

if agent_update_handler is None:
agent_update_handler = AgentUpdateHandler(protocol)

cleanup_functions = []

def patch_object(target, attribute):
Expand All @@ -80,39 +86,40 @@ def patch_object(target, attribute):

try:
with patch("azurelinuxagent.ga.exthandlers.get_exthandlers_handler", return_value=exthandlers_handler):
with patch("azurelinuxagent.ga.remoteaccess.get_remote_access_handler", return_value=remote_access_handler):
with patch("azurelinuxagent.common.conf.get_autoupdate_enabled", return_value=autoupdate_enabled):
with patch.object(UpdateHandler, "is_running", PropertyMock(side_effect=is_running)):
with patch('azurelinuxagent.ga.update.time.sleep', side_effect=lambda _: mock_sleep(0.001)) as sleep:
with patch('sys.exit', side_effect=lambda _: 0) as mock_exit:
if not check_daemon_running:
patch_object(UpdateHandler, "_check_daemon_running")
if not start_background_threads:
patch_object(UpdateHandler, "_start_threads")
if not check_background_threads:
patch_object(UpdateHandler, "_check_threads_running")

def get_exit_code():
if mock_exit.call_count == 0:
raise Exception("The UpdateHandler did not exit")
if mock_exit.call_count != 1:
raise Exception("The UpdateHandler exited multiple times ({0})".format(mock_exit.call_count))
args, _ = mock_exit.call_args
return args[0]

def get_iterations():
return iteration_count[0]

def get_iterations_completed():
return sleep.call_count

update_handler = get_update_handler()
update_handler.protocol_util.get_protocol = Mock(return_value=protocol)
update_handler.get_exit_code = get_exit_code
update_handler.get_iterations = get_iterations
update_handler.get_iterations_completed = get_iterations_completed

yield update_handler
with patch("azurelinuxagent.ga.agent_update.get_agent_update_handler", return_value=agent_update_handler):
with patch("azurelinuxagent.ga.remoteaccess.get_remote_access_handler", return_value=remote_access_handler):
with patch("azurelinuxagent.common.conf.get_autoupdate_enabled", return_value=autoupdate_enabled):
with patch.object(UpdateHandler, "is_running", PropertyMock(side_effect=is_running)):
with patch('azurelinuxagent.ga.update.time.sleep', side_effect=lambda _: mock_sleep(0.001)) as sleep:
with patch('sys.exit', side_effect=lambda _: 0) as mock_exit:
if not check_daemon_running:
patch_object(UpdateHandler, "_check_daemon_running")
if not start_background_threads:
patch_object(UpdateHandler, "_start_threads")
if not check_background_threads:
patch_object(UpdateHandler, "_check_threads_running")

def get_exit_code():
if mock_exit.call_count == 0:
raise Exception("The UpdateHandler did not exit")
if mock_exit.call_count != 1:
raise Exception("The UpdateHandler exited multiple times ({0})".format(mock_exit.call_count))
args, _ = mock_exit.call_args
return args[0]

def get_iterations():
return iteration_count[0]

def get_iterations_completed():
return sleep.call_count

update_handler = get_update_handler()
update_handler.protocol_util.get_protocol = Mock(return_value=protocol)
update_handler.get_exit_code = get_exit_code
update_handler.get_iterations = get_iterations
update_handler.get_iterations_completed = get_iterations_completed

yield update_handler
finally:
for f in cleanup_functions:
f()
Expand Down
Loading