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

Case insensitive parsing or Plugins and PluginSettings #2054

Merged
merged 3 commits into from
Oct 28, 2020
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
7 changes: 4 additions & 3 deletions azurelinuxagent/common/protocol/goal_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,8 +361,9 @@ def _parse_plugin_settings(ext_handler, plugin_settings):
name = ext_handler.name
version = ext_handler.properties.version

ext_handler_plugin_settings = [x for x in plugin_settings if getattrib(x, "name") == name]
if ext_handler_plugin_settings is None or len(ext_handler_plugin_settings) == 0: # pylint: disable=len-as-condition
to_lower = lambda str_to_change: str_to_change.lower() if str_to_change is not None else None
ext_handler_plugin_settings = [x for x in plugin_settings if to_lower(getattrib(x, "name")) == to_lower(name)]
if not ext_handler_plugin_settings:
return

settings = [x for x in ext_handler_plugin_settings if getattrib(x, "version") == version]
Expand All @@ -372,7 +373,7 @@ def _parse_plugin_settings(ext_handler, plugin_settings):
set([getattrib(x, "version") for x in ext_handler_plugin_settings])))
add_event(AGENT_NAME, op=WALAEventOperation.PluginSettingsVersionMismatch, message=msg, log_event=False,
is_success=False)
if len(settings) == 0: # pylint: disable=len-as-condition
if not settings:
# If there is no corresponding settings for the specific extension handler, we will not process it at all,
# this is an unexpected error as we always expect both versions to be in sync.
logger.error(msg)
Expand Down
56 changes: 56 additions & 0 deletions tests/data/wire/ext_conf_settings_case_mismatch.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<Extensions version="1.0.0.0" goalStateIncarnation="9">
<GuestAgentExtension>
<GAFamilies>
<GAFamily>
<Name>Prod</Name>
<Uris>
<Uri>http://mock-goal-state/manifest_of_ga.xml</Uri>
</Uris>
</GAFamily>
<GAFamily>
<Name>Test</Name>
<Uris>
<Uri>http://mock-goal-state/manifest_of_ga.xml</Uri>
</Uris>
</GAFamily>
</GAFamilies>
</GuestAgentExtension>
<Plugins>
<Plugin name="OSTCExtensions.ExampleHandlerLinux" version="1.0.0" location="http://mock-goal-state/rdfepirv2hknprdstr03.blob.core.windows.net/b01058962be54ceca550a390fa5ff064/Microsoft.OSTCExtensions_ExampleHandlerLinux_asiaeast_manifest.xml" config="" state="enabled" autoUpgrade="false" failoverlocation="http://mock-goal-state/rdfepirv2hknprdstr04.blob.core.windows.net/b01058962be54ceca550a390fa5ff064/Microsoft.OSTCExtensions_ExampleHandlerLinux_asiaeast_manifest.xml" runAsStartupTask="false" isJson="true"/>
<Plugin name="Microsoft.Powershell.ExampleExtension" version="1.0.0" location="https://mock-goal-state/zrdfepirv2sn3prdstr06.blob.core.windows.net/3055d769a0ed485d8c5ea8a7cd24073e/Microsoft.Powershell_ExampleExtension_ussouth_manifest.xml" state="enabled" autoUpgrade="true" failoverlocation="https://mock-goal-state/zrdfepirv2sn4prdstr02a.blob.core.windows.net/3055d769a0ed485d8c5ea8a7cd24073e/Microsoft.Powershell_ExampleExtension_ussouth_manifest.xml" runAsStartupTask="false" isJson="true" useExactVersion="false"/>
<Plugin name="Microsoft.EnterpriseCloud.Monitoring.ExampleHandlerLinux" version="1.0.0" location="https://mock-goal-state/rdfepirv2sn3prdstr01.blob.core.windows.net/8b23413e0ce64aa89889a295b6122112/Microsoft.EnterpriseCloud.Monitoring_ExampleHandlerLinux_ussouth_manifest.xml" state="enabled" autoUpgrade="true" failoverlocation="https://mock-goal-state/ardfepirv2sn3prdstr05.blob.core.windows.net/8b23413e0ce64aa89889a295b6122112/Microsoft.EnterpriseCloud.Monitoring_ExampleHandlerLinux_ussouth_manifest.xml" runAsStartupTask="false" isJson="true" useExactVersion="false"/>
<Plugin name="Microsoft.CPlat.Core.ExampleExtensionLinux" version="1.0.0" location="https://mock-goal-state/zrdfepirv2sn4prdstr09a.blob.core.windows.net/f72653efd9e349ed9842c8b99e4c1712/Microsoft.CPlat.Core_ExampleExtensionLinux_ussouth_manifest.xml" state="enabled" autoUpgrade="true" failoverlocation="https://mock-goal-state/ardfepirv2sn3prdstr05.blob.core.windows.net/f72653efd9e349ed9842c8b99e4c1712/Microsoft.CPlat.Core_ExampleExtensionLinux_ussouth_manifest.xml" runAsStartupTask="false" isJson="true" useExactVersion="false"/>
<Plugin name="Microsoft.OSTCExtensions.Edp.ExampleExtensionLinuxInTest" version="1.0.0" location="https://mock-goal-state/zrdfepirv2sn6prdstr05a.blob.core.windows.net/b01058962be54ceca550a390fa5ff064/Microsoft.OSTCExtensions.Edp_ExampleExtensionLinuxInTest_ussouth_manifest.xml" state="enabled" autoUpgrade="true" failoverlocation="https://mock-goal-state/rdfepirv2sn3prdstr01.blob.core.windows.net/b01058962be54ceca550a390fa5ff064/Microsoft.OSTCExtensions.Edp_ExampleExtensionLinuxInTest_ussouth_manifest.xml" runAsStartupTask="false" isJson="true" useExactVersion="false"/>
</Plugins>
<PluginSettings>
<Plugin name="OSTCExtensions.ExampleHandlerLinux" version="1.0.0">
<RuntimeSettings seqNo="0">
{"runtimeSettings":[{"handlerSettings":{"protectedSettingsCertThumbprint":"4037FBF5F1F3014F99B5D6C7799E9B20E6871CB3","protectedSettings":"MIICWgYJK","publicSettings":{"foo":"bar"}}}]}
</RuntimeSettings>
</Plugin>
<Plugin name="Microsoft.Powershell.exampleExtension" version="1.0.0">
<RuntimeSettings seqNo="0">
{"runtimeSettings":[{"handlerSettings":{"protectedSettingsCertThumbprint":"4037FBF5F1F3014F99B5D6C7799E9B20E6871CB3","protectedSettings":"MIICWgYJK","publicSettings":{"foo":"bar"}}}]}
</RuntimeSettings>
</Plugin>
<Plugin name="Microsoft.EnterpriseCloud.Monitoring.Examplehandlerlinux" version="1.0.0">
<RuntimeSettings seqNo="0">
{"runtimeSettings":[{"handlerSettings":{"protectedSettingsCertThumbprint":"4037FBF5F1F3014F99B5D6C7799E9B20E6871CB3","protectedSettings":"MIICWgYJK","publicSettings":{"foo":"bar"}}}]}
</RuntimeSettings>
</Plugin>
<Plugin name="Microsoft.CPlat.Core.exampleextensionlinux" version="1.0.0">
<RuntimeSettings seqNo="0">
{"runtimeSettings":[{"handlerSettings":{"protectedSettingsCertThumbprint":"4037FBF5F1F3014F99B5D6C7799E9B20E6871CB3","protectedSettings":"MIICWgYJK","publicSettings":{"foo":"bar"}}}]}
</RuntimeSettings>
</Plugin>
<Plugin name="Microsoft.OSTCExtensions.Edp.eXAMPLEextensionLINUXIntest" version="1.0.0">
<RuntimeSettings seqNo="0">
{"runtimeSettings":[{"handlerSettings":{"protectedSettingsCertThumbprint":"4037FBF5F1F3014F99B5D6C7799E9B20E6871CB3","protectedSettings":"MIICWgYJK","publicSettings":{"foo":"bar"}}}]}
</RuntimeSettings>
</Plugin>
</PluginSettings>
<StatusUploadBlob statusBlobType="BlockBlob">
https://test.blob.core.windows.net/vhds/test-cs12.test-cs12.test-cs12.status?sr=b&amp;sp=rw&amp;se=9999-01-01&amp;sk=key1&amp;sv=2014-02-14&amp;sig=hfRh7gzUE7sUtYwke78IOlZOrTRCYvkec4hGZ9zZzXo
</StatusUploadBlob>
</Extensions>

26 changes: 26 additions & 0 deletions tests/ga/test_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,32 @@ def test_ext_zip_file_packages_removed_in_update_and_uninstall_case(self, *args)
self._assert_no_handler_status(protocol.report_vm_status)
self._assert_ext_pkg_file_status(expected_to_be_present=False, extension_version="1.2.0")

def test_it_should_ignore_case_when_parsing_plugin_settings(self, mock_get, mock_crypt_util, *args):
test_data = mockwiredata.WireProtocolData(mockwiredata.DATA_FILE_CASE_MISMATCH_EXT)
exthandlers_handler, protocol = self._create_mock(test_data, mock_get, mock_crypt_util, *args)

exthandlers_handler.run()

expected_ext_handlers = ["OSTCExtensions.ExampleHandlerLinux", "Microsoft.Powershell.ExampleExtension",
"Microsoft.EnterpriseCloud.Monitoring.ExampleHandlerLinux",
"Microsoft.CPlat.Core.ExampleExtensionLinux",
"Microsoft.OSTCExtensions.Edp.ExampleExtensionLinuxInTest"]

self.assertTrue(protocol.report_vm_status.called, "Handler status not reported")
args, _ = protocol.report_vm_status.call_args
vm_status = args[0]
self.assertEqual(len(expected_ext_handlers), len(vm_status.vmAgent.extensionHandlers),
"No of Extension handlers dont match")

for handler_status in vm_status.vmAgent.extensionHandlers:
self.assertEqual("Ready", handler_status.status, "Handler is not Ready")
self.assertIn(handler_status.name, expected_ext_handlers, "Handler not reported")
self.assertEqual("1.0.0", handler_status.version, "Handler version not matching")
self.assertEqual(1, len(handler_status.extensions), "No settings were found for this extension")
expected_ext_handlers.remove(handler_status.name)

self.assertEqual(0, len(expected_ext_handlers), "All handlers not reported")

def test_ext_handler_no_settings(self, *args):
test_data = mockwiredata.WireProtocolData(mockwiredata.DATA_FILE_EXT_NO_SETTINGS)
exthandlers_handler, protocol = self._create_mock(test_data, *args) # pylint: disable=no-value-for-parameter
Expand Down
3 changes: 3 additions & 0 deletions tests/protocol/mockwiredata.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@
DATA_FILE_MULTIPLE_EXT = DATA_FILE.copy()
DATA_FILE_MULTIPLE_EXT["ext_conf"] = "wire/ext_conf_multiple_extensions.xml"

DATA_FILE_CASE_MISMATCH_EXT = DATA_FILE.copy()
DATA_FILE_CASE_MISMATCH_EXT["ext_conf"] = "wire/ext_conf_settings_case_mismatch.xml"

DATA_FILE_NO_CERT_FORMAT = DATA_FILE.copy()
DATA_FILE_NO_CERT_FORMAT["certs"] = "wire/certs_no_format_specified.xml"

Expand Down