Repository: qpid-dispatch
Updated Branches:
  refs/heads/master 5066613c6 -> e6473b4ce


DISPATCH-967: Add policy_manager log_warning interface

Add a self test that generates a policy warning and verify that the
router does not exit with a critical error.


Project: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/commit/e6473b4c
Tree: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/tree/e6473b4c
Diff: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/diff/e6473b4c

Branch: refs/heads/master
Commit: e6473b4ced6dddcb1a2ab33fa8651ca0b4ae07ee
Parents: 5066613
Author: Chuck Rolke <cro...@redhat.com>
Authored: Fri Apr 13 09:40:16 2018 -0400
Committer: Chuck Rolke <cro...@redhat.com>
Committed: Fri Apr 13 09:40:16 2018 -0400

----------------------------------------------------------------------
 .../policy/policy_manager.py                    |  7 ++--
 tests/policy-6/vhost-bad-attribute.json         | 34 ++++++++++++++++++++
 tests/system_tests_policy.py                    | 29 +++++++++++++++++
 3 files changed, 68 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/e6473b4c/python/qpid_dispatch_internal/policy/policy_manager.py
----------------------------------------------------------------------
diff --git a/python/qpid_dispatch_internal/policy/policy_manager.py 
b/python/qpid_dispatch_internal/policy/policy_manager.py
index 3d0c8d9..34deabb 100644
--- a/python/qpid_dispatch_internal/policy/policy_manager.py
+++ b/python/qpid_dispatch_internal/policy/policy_manager.py
@@ -24,7 +24,7 @@
 import json
 import traceback
 from policy_local import PolicyLocal
-from ..dispatch import LogAdapter, LOG_INFO, LOG_TRACE, LOG_DEBUG, LOG_ERROR
+from ..dispatch import LogAdapter, LOG_INFO, LOG_TRACE, LOG_DEBUG, LOG_ERROR, 
LOG_WARNING
 
 
 
@@ -64,6 +64,9 @@ class PolicyManager(object):
     def log_error(self, text):
         self._log(LOG_ERROR, text)
 
+    def log_warning(self, text):
+        self._log(LOG_WARNING, text)
+
     def get_agent(self):
         return self._agent
 
@@ -185,4 +188,4 @@ def policy_lookup_settings(mgr, vhost, name, upolicy):
     @param upolicy:
     @return:
     """
-    return mgr.lookup_settings(vhost, name, upolicy)
\ No newline at end of file
+    return mgr.lookup_settings(vhost, name, upolicy)

http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/e6473b4c/tests/policy-6/vhost-bad-attribute.json
----------------------------------------------------------------------
diff --git a/tests/policy-6/vhost-bad-attribute.json 
b/tests/policy-6/vhost-bad-attribute.json
new file mode 100644
index 0000000..c36939f
--- /dev/null
+++ b/tests/policy-6/vhost-bad-attribute.json
@@ -0,0 +1,34 @@
+##
+## Licensed to the Apache Software Foundation (ASF) under one
+## or more contributor license agreements.  See the NOTICE file
+## distributed with this work for additional information
+## regarding copyright ownership.  The ASF licenses this file
+## to you 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
+##
+[
+    ["vhost", {
+        "hostname": "nousers",
+        "allowUnknownUser": false,
+        "groups" : {
+             "nousers": {
+                "badAttribute": true,
+                "remoteHosts": "*",
+                "allowDynamicSource": true,
+                "allowAnonymousSender": true,
+                "sources": "*",
+                "targets": "*"
+            }
+       }
+    }]
+]

http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/e6473b4c/tests/system_tests_policy.py
----------------------------------------------------------------------
diff --git a/tests/system_tests_policy.py b/tests/system_tests_policy.py
index 7abaa14..275ad75 100644
--- a/tests/system_tests_policy.py
+++ b/tests/system_tests_policy.py
@@ -565,6 +565,35 @@ class VhostPolicyNameField(TestCase):
         self.assertFalse(isoFound)
 
 
+class PolicyWarnings(TestCase):
+    """
+    Verify that specifying a policy that generates a warning does
+    not cause the router to exit without showing the warning.
+    """
+    @classmethod
+    def setUpClass(cls):
+        """Start the router"""
+        super(PolicyWarnings, cls).setUpClass()
+        listen_port = cls.tester.get_port()
+        policy_config_path = os.path.join(DIR, 'policy-6')
+        config = Qdrouterd.Config([
+            ('router', {'mode': 'standalone', 'id': 'QDR.Policy'}),
+            ('listener', {'port': listen_port}),
+            ('policy', {'maxConnections': 2, 'policyDir': policy_config_path, 
'enableVhostPolicy': 'true'})
+        ])
+
+        cls.router = cls.tester.qdrouterd('PolicyWarnings', config, wait=False)
+        try:
+            cls.router.wait_ready(timeout = 5)
+        except Exception,  e:
+            pass
+
+    def test_03_policy_warnings(self):
+        with  open('../setUpClass/PolicyWarnings.log', 'r') as router_log:
+            log_lines = router_log.read().split("\n")
+            critical_lines = [s for s in log_lines if "'PolicyManager' object 
has no attribute 'log_warning'" in s]
+            self.assertTrue(len(critical_lines) == 0, msg='Policy manager does 
not forward policy warnings and shuts down instead.')
+
 
 if __name__ == '__main__':
     unittest.main(main_module())


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@qpid.apache.org
For additional commands, e-mail: commits-h...@qpid.apache.org

Reply via email to