diff --git a/.coveragerc b/.coveragerc new file mode 100644 index 0000000..d80a427 --- /dev/null +++ b/.coveragerc @@ -0,0 +1,6 @@ +[report] +# Regexes for lines to exclude from consideration +exclude_lines = + if __name__ == .__main__.: +include= + hooks/swift_* diff --git a/Makefile b/Makefile index 2b96e5f..fe95b50 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ PYTHON := /usr/bin/env python lint: @flake8 --exclude hooks/charmhelpers --ignore=E125 hooks - #@flake8 --exclude hooks/charmhelpers --ignore=E125 unit_tests + @flake8 --exclude hooks/charmhelpers --ignore=E125 unit_tests @charm proof test: diff --git a/README.md b/README.md index f2467f6..e600038 100644 --- a/README.md +++ b/README.md @@ -46,13 +46,13 @@ this charm, a deployment would look something like: replicas: 3 swift-storage-zone1: zone: 1 - block-device: sdb + block-device: /etc/swift/storage.img|2G swift-storage-zone2: zone: 2 - block-device: sdb + block-device: /etc/swift/storage.img|2G swift-storage-zone3: zone: 3 - block-device: sdb + block-device: /etc/swift/storage.img|2G END $ juju deploy --config=swift.cfg swift-proxy $ juju deploy --config=swift.cfg swift-storage swift-storage-zone1 @@ -82,7 +82,7 @@ assigned to that service unit will be distributed evenly across zones. replicas: 3 swift-storage: zone: 1 - block-device: sdb + block-device: /etc/swift/storage.img|2G END $ juju deploy --config=swift.cfg swift-proxy $ juju deploy --config=swift.cfg swift-storage diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..72c20b2 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,5 @@ +[nosetests] +verbosity=1 +with-coverage=1 +cover-erase=1 +cover-package=hooks diff --git a/templates/essex/proxy-server.conf b/templates/essex/proxy-server.conf index 4f77b05..0a887be 100644 --- a/templates/essex/proxy-server.conf +++ b/templates/essex/proxy-server.conf @@ -45,16 +45,11 @@ auth_uri = {{ auth_protocol }}://{{ keystone_host }}:{{ service_port }} admin_tenant_name = {{ service_tenant }} admin_user = {{ service_user }} admin_password = {{ service_password }} -{% if os_release == 'essex' %} {% if delay_auth_decision|lower == 'true' %} delay_auth_decision = 1 {% else %} delay_auth_decision = 0 {% endif %} -{% else %} -delay_auth_decision = {{ delay_auth_decision|lower }} -{% endif %} -{% if os_release != 'essex' %}signing_dir = /etc/swift{% endif %} [filter:s3token] @@ -68,6 +63,5 @@ auth_token = {{ admin_token }} admin_token = {{ admin_token }} [filter:swift3] -{% if os_release == 'essex' %}use = egg:swift#swift3{% else %}use = egg:swift3#swift3 -{% endif %} +use = egg:swift#swift3 {% endif %} diff --git a/templates/grizzly/proxy-server.conf b/templates/grizzly/proxy-server.conf index adb7bcd..6ae45c6 100644 --- a/templates/grizzly/proxy-server.conf +++ b/templates/grizzly/proxy-server.conf @@ -46,7 +46,7 @@ admin_tenant_name = {{ service_tenant }} admin_user = {{ service_user }} admin_password = {{ service_password }} delay_auth_decision = {{ delay_auth_decision|lower }} -{% if os_release != 'essex' %}signing_dir = /etc/swift{% endif %} +signing_dir = /etc/swift [filter:s3token] paste.filter_factory = keystone.middleware.s3_token:filter_factory @@ -59,6 +59,5 @@ auth_token = {{ admin_token }} admin_token = {{ admin_token }} [filter:swift3] -{% if os_release == 'essex' %}use = egg:swift#swift3{% else %}use = egg:swift3#swift3 -{% endif %} +use = egg:swift3#swift3 {% endif %} diff --git a/templates/havana/proxy-server.conf b/templates/havana/proxy-server.conf index 36e4587..b1baef9 100644 --- a/templates/havana/proxy-server.conf +++ b/templates/havana/proxy-server.conf @@ -46,7 +46,7 @@ admin_tenant_name = {{ service_tenant }} admin_user = {{ service_user }} admin_password = {{ service_password }} delay_auth_decision = {{ delay_auth_decision|lower }} -{% if os_release != 'essex' %}signing_dir = /etc/swift{% endif %} +signing_dir = /etc/swift cache = swift.cache [filter:s3token] @@ -60,6 +60,5 @@ auth_token = {{ admin_token }} admin_token = {{ admin_token }} [filter:swift3] -{% if os_release == 'essex' %}use = egg:swift#swift3{% else %}use = egg:swift3#swift3 -{% endif %} +use = egg:swift3#swift3 {% endif %} diff --git a/unit_tests/__init__.py b/unit_tests/__init__.py new file mode 100644 index 0000000..f80aab3 --- /dev/null +++ b/unit_tests/__init__.py @@ -0,0 +1,2 @@ +import sys +sys.path.append('hooks') diff --git a/unit_tests/test_templates.py b/unit_tests/test_templates.py new file mode 100644 index 0000000..0740ad3 --- /dev/null +++ b/unit_tests/test_templates.py @@ -0,0 +1,65 @@ +import mock +import unittest + +from jinja2 import Environment + +from charmhelpers.contrib.openstack.templating import get_loader + + +class ProxyServerTemplateTestCase(unittest.TestCase): + + @mock.patch('charmhelpers.contrib.openstack.templating.log') + def get_template_for_release(self, os_release, mock_log): + loader = get_loader('./templates', os_release) + env = Environment(loader=loader) + + return env.get_template('proxy-server.conf') + + def test_essex_keystone_includes_correct_egg(self): + """Regression test for bug 1251551.""" + template = self.get_template_for_release('essex') + + result = template.render(auth_type='keystone') + + self.assertIn("use = egg:swift#swift3", result) + + def test_essex_keystone_includes_correct_delay_auth_true(self): + """Regression test for bug 1251551.""" + template = self.get_template_for_release('essex') + + result = template.render(auth_type='keystone', + delay_auth_decision='true') + + self.assertIn("delay_auth_decision = 1", result) + + def test_essex_keystone_includes_correct_delay_auth_false(self): + """Regression test for bug 1251551.""" + template = self.get_template_for_release('essex') + + result = template.render(auth_type='keystone', + delay_auth_decision='anything') + + self.assertIn("delay_auth_decision = 0", result) + + def test_os_release_not_in_templates(self): + """Regression test for bug 1251551. + + The os_release is no longer provided as context to the templates. + """ + for release in ('essex', 'grizzly', 'havana'): + template = self.get_template_for_release(release) + with open(template.filename, 'r') as template_orig: + self.assertNotIn( + 'os_release', template_orig.read(), + "The template '{}' contains os_release which is " + "no longer provided in the context.".format( + template.filename)) + + def test_config_renders_for_all_releases(self): + """The configs render without syntax error.""" + for release in ('essex', 'grizzly', 'havana'): + template = self.get_template_for_release(release) + + result = template.render() + + self.assertTrue(result.startswith("[DEFAULT]"))