Skip to content

Commit

Permalink
report GA versioning feature
Browse files Browse the repository at this point in the history
  • Loading branch information
nagworld9 committed Feb 3, 2023
1 parent 4c7dc3f commit ac8d364
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 33 deletions.
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
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")

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

0 comments on commit ac8d364

Please sign in to comment.