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

report GA versioning supported feature. #2752

Merged
merged 2 commits into from
Feb 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
16 changes: 15 additions & 1 deletion azurelinuxagent/common/agent_supported_feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class SupportedFeatureNames(object):
MultiConfig = "MultipleExtensionsPerHandler"
ExtensionTelemetryPipeline = "ExtensionTelemetryPipeline"
FastTrack = "FastTrack"
GAVersioningGovernance = "VersioningGovernance" # Guest Agent Versioning


class AgentSupportedFeature(object):
Expand Down Expand Up @@ -72,9 +73,22 @@ def __init__(self):
supported=self.__SUPPORTED)


class _GAVersioningGovernanceFeature(AgentSupportedFeature):

__NAME = SupportedFeatureNames.GAVersioningGovernance
__VERSION = "1.0"
__SUPPORTED = True

def __init__(self):
super(_GAVersioningGovernanceFeature, self).__init__(name=self.__NAME,
version=self.__VERSION,
supported=self.__SUPPORTED)


# This is the list of features that Agent supports and we advertise to CRP
__CRP_ADVERTISED_FEATURES = {
SupportedFeatureNames.MultiConfig: _MultiConfigFeature()
SupportedFeatureNames.MultiConfig: _MultiConfigFeature(),
SupportedFeatureNames.GAVersioningGovernance: _GAVersioningGovernanceFeature()
}


Expand Down
9 changes: 9 additions & 0 deletions azurelinuxagent/common/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ def load_conf_from_file(conf_file_path, conf=__conf__):
"ResourceDisk.EnableSwapEncryption": False,
"AutoUpdate.Enabled": True,
"EnableOverProvisioning": True,
"GAUpdates.Enabled": True,
#
# "Debug" options are experimental and may be removed in later
# versions of the Agent.
Expand Down Expand Up @@ -502,6 +503,14 @@ def get_monitor_network_configuration_changes(conf=__conf__):
return conf.get_switch("Monitor.NetworkConfigurationChanges", False)


def get_ga_updates_enabled(conf=__conf__):
"""
If True, the agent go through update logic to look for new agents otherwise it will stop agent updates.
NOTE: This option is needed in e2e tests to control agent updates.
"""
return conf.get_switch("GAUpdates.Enabled", True)


def get_cgroup_check_period(conf=__conf__):
"""
How often to perform checks on cgroups (are the processes in the cgroups as expected,
Expand Down
4 changes: 2 additions & 2 deletions azurelinuxagent/ga/agent_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ def __log_event(level, msg_, success_=True):

def run(self, goal_state):
try:
# Ignore new agents if update is disabled
if not self._autoupdate_enabled:
# Ignore new agents if update is disabled. The latter flag only used in e2e tests.
if not self._autoupdate_enabled or not conf.get_ga_updates_enabled():
return

self._gs_id = goal_state.extensions_goal_state.id
Expand Down
18 changes: 18 additions & 0 deletions tests/common/test_agent_supported_feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,21 @@ def test_it_should_return_extension_supported_features_properly(self):
self.assertEqual(SupportedFeatureNames.ExtensionTelemetryPipeline,
get_supported_feature_by_name(SupportedFeatureNames.ExtensionTelemetryPipeline).name,
"Invalid/Wrong feature returned")

def test_it_should_return_ga_versioning_governance_feature_properly(self):
with patch("azurelinuxagent.common.agent_supported_feature._GAVersioningGovernanceFeature.is_supported", True):
self.assertIn(SupportedFeatureNames.GAVersioningGovernance, get_agent_supported_features_list_for_crp(),
"GAVersioningGovernance should be fetched in crp_supported_features")

with patch("azurelinuxagent.common.agent_supported_feature._GAVersioningGovernanceFeature.is_supported", False):
self.assertNotIn(SupportedFeatureNames.GAVersioningGovernance, get_agent_supported_features_list_for_crp(),
"GAVersioningGovernance should not be fetched in crp_supported_features as not supported")

self.assertEqual(SupportedFeatureNames.GAVersioningGovernance,
get_supported_feature_by_name(SupportedFeatureNames.GAVersioningGovernance).name,
"Invalid/Wrong feature returned")

# Raise error if feature name not found
with self.assertRaises(NotImplementedError):
get_supported_feature_by_name("ABC")

10 changes: 5 additions & 5 deletions tests/ga/test_agent_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def test_it_should_not_agent_update_if_last_attempted_update_time_not_elapsed(se
with self.__get_agent_update_handler(test_data=data_file, autoupdate_frequency=10) as (agent_update_handler, mock_telemetry):
agent_update_handler._protocol.mock_wire_data.set_extension_config_requested_version(version)
agent_update_handler._protocol.mock_wire_data.set_incarnation(2)
agent_update_handler._protocol.update_goal_state()
agent_update_handler._protocol.client.update_goal_state()
agent_update_handler.run(agent_update_handler._protocol.get_goal_state())

self.__assert_agent_requested_version_in_goal_state(mock_telemetry, inc=2, version=version)
Expand Down Expand Up @@ -151,7 +151,7 @@ def test_it_should_not_agent_update_if_requested_version_is_same_as_current_vers
agent_update_handler._protocol.mock_wire_data.set_extension_config_requested_version(
str(CURRENT_VERSION))
agent_update_handler._protocol.mock_wire_data.set_incarnation(2)
agent_update_handler._protocol.update_goal_state()
agent_update_handler._protocol.client.update_goal_state()
agent_update_handler.run(agent_update_handler._protocol.get_goal_state())
self.assertEqual(0, len([kwarg['message'] for _, kwarg in mock_telemetry.call_args_list if
"requesting a new agent version" in kwarg['message'] and kwarg[
Expand Down Expand Up @@ -187,7 +187,7 @@ def test_it_should_downgrade_agent_if_requested_version_is_available_less_than_c
with self.__get_agent_update_handler(test_data=data_file) as (agent_update_handler, mock_telemetry):
agent_update_handler._protocol.mock_wire_data.set_extension_config_requested_version(downgraded_version)
agent_update_handler._protocol.mock_wire_data.set_incarnation(2)
agent_update_handler._protocol.update_goal_state()
agent_update_handler._protocol.client.update_goal_state()
with self.assertRaises(AgentUpgradeExitException) as context:
agent_update_handler.run(agent_update_handler._protocol.get_goal_state())
self.__assert_agent_requested_version_in_goal_state(mock_telemetry, inc=2, version=downgraded_version)
Expand All @@ -208,7 +208,7 @@ def test_handles_if_requested_version_not_found_in_pkgs_to_download(self):
with self.__get_agent_update_handler(test_data=data_file) as (agent_update_handler, mock_telemetry):
agent_update_handler._protocol.mock_wire_data.set_extension_config_requested_version(version)
agent_update_handler._protocol.mock_wire_data.set_incarnation(2)
agent_update_handler._protocol.update_goal_state()
agent_update_handler._protocol.client.update_goal_state()
agent_update_handler.run(agent_update_handler._protocol.get_goal_state())

self.__assert_agent_requested_version_in_goal_state(mock_telemetry, inc=2, version=version)
Expand Down Expand Up @@ -245,7 +245,7 @@ def test_it_should_report_update_status_with_success(self):
agent_update_handler._protocol.mock_wire_data.set_extension_config_requested_version(
str(CURRENT_VERSION))
agent_update_handler._protocol.mock_wire_data.set_incarnation(2)
agent_update_handler._protocol.update_goal_state()
agent_update_handler._protocol.client.update_goal_state()
agent_update_handler.run(agent_update_handler._protocol.get_goal_state())
vm_agent_update_status = agent_update_handler.get_vmagent_update_status()
self.assertEqual(VMAgentUpdateStatuses.Success, vm_agent_update_status.status)
Expand Down
83 changes: 51 additions & 32 deletions tests/protocol/test_wire.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,41 +360,60 @@ def mock_http_put(url, *args, **__):
exthandlers_handler = get_exthandlers_handler(protocol)

with patch("azurelinuxagent.common.agent_supported_feature._MultiConfigFeature.is_supported", True):
exthandlers_handler.run()
exthandlers_handler.report_ext_handlers_status()

self.assertIsNotNone(protocol.aggregate_status, "Aggregate status should not be None")
self.assertIn("supportedFeatures", protocol.aggregate_status, "supported features not reported")
multi_config_feature = get_supported_feature_by_name(SupportedFeatureNames.MultiConfig)
found = False
for feature in protocol.aggregate_status['supportedFeatures']:
if feature['Key'] == multi_config_feature.name and feature['Value'] == multi_config_feature.version:
found = True
break
self.assertTrue(found, "Multi-config name should be present in supportedFeatures")
with patch("azurelinuxagent.common.agent_supported_feature._GAVersioningGovernanceFeature.is_supported", True):
exthandlers_handler.run()
exthandlers_handler.report_ext_handlers_status()

self.assertIsNotNone(protocol.aggregate_status, "Aggregate status should not be None")
self.assertIn("supportedFeatures", protocol.aggregate_status, "supported features not reported")
multi_config_feature = get_supported_feature_by_name(SupportedFeatureNames.MultiConfig)
found = False
for feature in protocol.aggregate_status['supportedFeatures']:
if feature['Key'] == multi_config_feature.name and feature['Value'] == multi_config_feature.version:
found = True
break
self.assertTrue(found, "Multi-config name should be present in supportedFeatures")

ga_versioning_feature = get_supported_feature_by_name(SupportedFeatureNames.GAVersioningGovernance)
found = False
for feature in protocol.aggregate_status['supportedFeatures']:
if feature['Key'] == ga_versioning_feature.name and feature['Value'] == ga_versioning_feature.version:
found = True
break
self.assertTrue(found, "ga versioning name should be present in supportedFeatures")

# Feature should not be reported if not present
with patch("azurelinuxagent.common.agent_supported_feature._MultiConfigFeature.is_supported", False):
exthandlers_handler.run()
exthandlers_handler.report_ext_handlers_status()

self.assertIsNotNone(protocol.aggregate_status, "Aggregate status should not be None")
if "supportedFeatures" not in protocol.aggregate_status:
# In the case Multi-config was the only feature available, 'supportedFeatures' should not be
# reported in the status blob as its not supported as of now.
# Asserting no other feature was available to report back to crp
self.assertEqual(0, len(get_agent_supported_features_list_for_crp()),
"supportedFeatures should be available if there are more features")
return

# If there are other features available, confirm MultiConfig was not reported
multi_config_feature = get_supported_feature_by_name(SupportedFeatureNames.MultiConfig)
found = False
for feature in protocol.aggregate_status['supportedFeatures']:
if feature['Key'] == multi_config_feature.name and feature['Value'] == multi_config_feature.version:
found = True
break
self.assertFalse(found, "Multi-config name should be present in supportedFeatures")
with patch("azurelinuxagent.common.agent_supported_feature._GAVersioningGovernanceFeature.is_supported", False):

exthandlers_handler.run()
exthandlers_handler.report_ext_handlers_status()

self.assertIsNotNone(protocol.aggregate_status, "Aggregate status should not be None")
if "supportedFeatures" not in protocol.aggregate_status:
# In the case Multi-config and GA Versioning only features available, 'supportedFeatures' should not be
# reported in the status blob as its not supported as of now.
# Asserting no other feature was available to report back to crp
self.assertEqual(0, len(get_agent_supported_features_list_for_crp()),
"supportedFeatures should be available if there are more features")
return

# If there are other features available, confirm MultiConfig and GA versioning was not reported
multi_config_feature = get_supported_feature_by_name(SupportedFeatureNames.MultiConfig)
found = False
for feature in protocol.aggregate_status['supportedFeatures']:
if feature['Key'] == multi_config_feature.name and feature['Value'] == multi_config_feature.version:
found = True
break
self.assertFalse(found, "Multi-config name should not be present in supportedFeatures")

ga_versioning_feature = get_supported_feature_by_name(SupportedFeatureNames.GAVersioningGovernance)
found = False
for feature in protocol.aggregate_status['supportedFeatures']:
if feature['Key'] == ga_versioning_feature.name and feature['Value'] == ga_versioning_feature.version:
found = True
break
self.assertFalse(found, "ga versioning name should not be present in supportedFeatures")

@patch("azurelinuxagent.common.utils.restutil.http_request")
def test_send_encoded_event(self, mock_http_request, *args):
Expand Down
1 change: 1 addition & 0 deletions tests/test_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
Extensions.Enabled = True
Extensions.GoalStatePeriod = 6
Extensions.InitialGoalStatePeriod = 6
GAUpdates.Enabled = True
HttpProxy.Host = None
HttpProxy.Port = None
Lib.Dir = /var/lib/waagent
Expand Down