From 79f6dcebb8f111b0d286bed72fbf8a55ef06ce9f Mon Sep 17 00:00:00 2001 From: Yue Zhang Date: Wed, 20 Jan 2016 12:25:31 +0800 Subject: [PATCH] Fix parsing xml event --- azurelinuxagent/distro/default/monitor.py | 6 ++--- azurelinuxagent/distro/default/osutil.py | 4 +-- tests/data/ext/event.xml | 1 + tests/distro/test_monitor.py | 32 +++++++++++++++++++++++ 4 files changed, 38 insertions(+), 5 deletions(-) create mode 100755 tests/data/ext/event.xml create mode 100644 tests/distro/test_monitor.py diff --git a/azurelinuxagent/distro/default/monitor.py b/azurelinuxagent/distro/default/monitor.py index 4486bd4..3b26c9a 100644 --- a/azurelinuxagent/distro/default/monitor.py +++ b/azurelinuxagent/distro/default/monitor.py @@ -66,6 +66,7 @@ def parse_xml_event(data_str): param_nodes = findall(xml_doc, 'Param') for param_node in param_nodes: event.parameters.append(parse_xml_param(param_node)) + return event except Exception as e: raise ValueError(ustr(e)) @@ -153,8 +154,7 @@ class MonitorHandler(object): event.parameters.extend(self.sysinfo) event_list.events.append(event) except (ValueError, ProtocolError) as e: - logger.info("Failed to decode event file: {0}", e) - logger.info(data_str) + logger.warn("Failed to decode event file: {0}", e) continue if len(event_list.events) == 0: @@ -178,5 +178,5 @@ class MonitorHandler(object): try: self.collect_and_send_events() except Exception as e: - logger.verb("Failed to send events: {0}", e) + logger.warn("Failed to send events: {0}", e) time.sleep(60) diff --git a/azurelinuxagent/distro/default/osutil.py b/azurelinuxagent/distro/default/osutil.py index 19efd73..18ab2ba 100644 --- a/azurelinuxagent/distro/default/osutil.py +++ b/azurelinuxagent/distro/default/osutil.py @@ -609,13 +609,13 @@ class DefaultOSUtil(object): raise OSUtilError("Failed to get procerssor cores") def set_admin_access_to_ip(self, dest_ip): - #This root allow root to access dest_ip + #This allows root to access dest_ip rm_old= "iptables -D OUTPUT -d {0} -j ACCEPT -m owner --uid-owner 0" rule = "iptables -A OUTPUT -d {0} -j ACCEPT -m owner --uid-owner 0" shellutil.run(rm_old.format(dest_ip), chk_err=False) shellutil.run(rule.format(dest_ip)) - #This root blocks all users to access dest_ip + #This blocks all other users to access dest_ip rm_old = "iptables -D OUTPUT -d {0} -j DROP" rule = "iptables -A OUTPUT -d {0} -j DROP" shellutil.run(rm_old.format(dest_ip), chk_err=False) diff --git a/tests/data/ext/event.xml b/tests/data/ext/event.xml new file mode 100755 index 0000000..436de44 --- /dev/null +++ b/tests/data/ext/event.xml @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/tests/distro/test_monitor.py b/tests/distro/test_monitor.py new file mode 100644 index 0000000..1dd7740 --- /dev/null +++ b/tests/distro/test_monitor.py @@ -0,0 +1,32 @@ +# Copyright 2014 Microsoft Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Requires Python 2.4+ and Openssl 1.0+ +# +# Implements parts of RFC 2131, 1541, 1497 and +# http://msdn.microsoft.com/en-us/library/cc227282%28PROT.10%29.aspx +# http://msdn.microsoft.com/en-us/library/cc227259%28PROT.13%29.aspx + +from tests.tools import * +from azurelinuxagent.exception import * +from azurelinuxagent.distro.default.monitor import * + +class TestMonitor(AgentTestCase): + def test_parse_xml_event(self): + data_str = load_data('ext/event.xml') + event = parse_xml_event(data_str) + self.assertNotEquals(None, event) + self.assertNotEquals(0, event.parameters) + self.assertNotEquals(None, event.parameters[0]) +