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

Removing infinite download of extension manifest without a new GS #1874

Merged
merged 8 commits into from
May 22, 2020
24 changes: 9 additions & 15 deletions azurelinuxagent/ga/exthandlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,13 @@ def handle_ext_handler(self, ext_handler, etag):

try:
state = ext_handler.properties.state

larohra marked this conversation as resolved.
Show resolved Hide resolved
if self.last_etag == etag:
if self.log_etag:
ext_handler_i.logger.verbose("Incarnation {0} did not change, not processing GoalState", etag)
self.log_etag = False
return

if ext_handler_i.decide_version(target_state=state) is None:
version = ext_handler_i.ext_handler.properties.version
name = ext_handler_i.ext_handler.name
Expand All @@ -432,15 +439,6 @@ def handle_ext_handler(self, ext_handler, etag):
ext_handler_i.report_event(message=ustr(err_msg), is_success=False)
return

self.get_artifact_error_state.reset()
if self.last_etag == etag:
if self.log_etag:
ext_handler_i.logger.verbose("Version {0} is current for etag {1}",
ext_handler_i.pkg.version,
etag)
self.log_etag = False
return

self.log_etag = True

ext_handler_i.logger.info("Target handler state: {0} [incarnation {1}]", state, etag)
Expand Down Expand Up @@ -474,12 +472,8 @@ def handle_ext_handler_download_error(self, ext_handler_i, e, code=-1):
msg = ustr(e)
ext_handler_i.set_handler_status(message=msg, code=code)

self.get_artifact_error_state.incr()
larohra marked this conversation as resolved.
Show resolved Hide resolved
if self.get_artifact_error_state.is_triggered():
report_event(op=WALAEventOperation.Download, is_success=False, log_event=True,
message="Failed to get artifact for over "
"{0}: {1}".format(self.get_artifact_error_state.min_timedelta, msg))
self.get_artifact_error_state.reset()
report_event(op=WALAEventOperation.Download, is_success=False, log_event=True,
message="Failed to download artifacts: {0}".format(msg))

def handle_enable(self, ext_handler_i):
self.log_process = True
Expand Down
30 changes: 30 additions & 0 deletions tests/ga/test_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,36 @@ def test_ext_handler(self, *args):
exthandlers_handler.run()
self._assert_no_handler_status(protocol.report_vm_status)

def test_it_should_only_download_extension_manifest_once_per_goal_state(self, *args):

def _assert_handler_status_and_manifest_download_count(protocol, test_data, manifest_count):
self._assert_handler_status(protocol.report_vm_status, "Ready", 1, "1.0.0")
self._assert_ext_status(protocol.report_ext_status, "success", 0)
self.assertEqual(test_data.call_counts['manifest.xml'], manifest_count,
"We should have downloaded extension manifest {0} times".format(manifest_count))

test_data = mockwiredata.WireProtocolData(mockwiredata.DATA_FILE)
exthandlers_handler, protocol = self._create_mock(test_data, *args)
exthandlers_handler.run()
_assert_handler_status_and_manifest_download_count(protocol, test_data, 1)

for _ in range(5):
exthandlers_handler.run()
# The extension manifest should only be downloaded once as incarnation did not change
_assert_handler_status_and_manifest_download_count(protocol, test_data, 1)

# Update Incarnation
test_data.set_incarnation(2)
protocol.update_goal_state()

exthandlers_handler.run()
_assert_handler_status_and_manifest_download_count(protocol, test_data, 2)

for _ in range(5):
exthandlers_handler.run()
# The extension manifest should be downloaded twice now as incarnation changed once
_assert_handler_status_and_manifest_download_count(protocol, test_data, 2)

def test_ext_zip_file_packages_removed_in_update_case(self, *args):
# Test enable scenario.
test_data = mockwiredata.WireProtocolData(mockwiredata.DATA_FILE)
Expand Down