summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTommyLike <tommylikehu@gmail.com>2017-07-11 17:22:05 +0800
committerTommyLike <tommylikehu@gmail.com>2017-07-12 16:47:38 +0800
commit7c3621dafe2e5a2d98ef9678dbcae8b0ca0abf70 (patch)
tree7016ec0fcbf1e5c4146ea123eaf2c555d5776767
parent5d76e78009018e5bde3154c49cbe6af46dc28b35 (diff)
downloadoslo-policy-7c3621dafe2e5a2d98ef9678dbcae8b0ca0abf70.tar.gz
Fix parsing bug when config file is empty.
Method 'parse_file_contents' is expected to return dict object after parsing the policy file, but it will return None if file is empty currently. Fix it. Change-Id: I2841ccdb0f657fdb583e94d889cdd2685d7068b4
-rw-r--r--oslo_policy/policy.py2
-rw-r--r--oslo_policy/tests/test_policy.py5
2 files changed, 6 insertions, 1 deletions
diff --git a/oslo_policy/policy.py b/oslo_policy/policy.py
index 6480767..6c9dceb 100644
--- a/oslo_policy/policy.py
+++ b/oslo_policy/policy.py
@@ -350,7 +350,7 @@ def parse_file_contents(data):
# For backwards-compatibility, convert yaml error to ValueError,
# which is what JSON loader raised.
raise ValueError(six.text_type(e))
- return parsed
+ return parsed or {}
class Rules(dict):
diff --git a/oslo_policy/tests/test_policy.py b/oslo_policy/tests/test_policy.py
index c0506df..3853951 100644
--- a/oslo_policy/tests/test_policy.py
+++ b/oslo_policy/tests/test_policy.py
@@ -130,6 +130,11 @@ class RulesTestCase(test_base.BaseTestCase):
'default')
@mock.patch.object(_parser, 'parse_rule', lambda x: x)
+ def test_load_empty_data(self):
+ result = policy.Rules.load('', 'default')
+ self.assertEqual(result, {})
+
+ @mock.patch.object(_parser, 'parse_rule', lambda x: x)
def test_load_yaml(self):
# Test that simplified YAML can be used with load().
# Show that YAML allows useful comments.