[Michael Nelson] Fixup templates for essex release, add template unit tests for changes
[James Page] Add standard unit test fixtures for openstack charms
This commit is contained in:
6
.coveragerc
Normal file
6
.coveragerc
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
[report]
|
||||||
|
# Regexes for lines to exclude from consideration
|
||||||
|
exclude_lines =
|
||||||
|
if __name__ == .__main__.:
|
||||||
|
include=
|
||||||
|
hooks/swift_*
|
||||||
2
Makefile
2
Makefile
@@ -3,7 +3,7 @@ PYTHON := /usr/bin/env python
|
|||||||
|
|
||||||
lint:
|
lint:
|
||||||
@flake8 --exclude hooks/charmhelpers --ignore=E125 hooks
|
@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
|
@charm proof
|
||||||
|
|
||||||
test:
|
test:
|
||||||
|
|||||||
@@ -46,13 +46,13 @@ this charm, a deployment would look something like:
|
|||||||
replicas: 3
|
replicas: 3
|
||||||
swift-storage-zone1:
|
swift-storage-zone1:
|
||||||
zone: 1
|
zone: 1
|
||||||
block-device: sdb
|
block-device: /etc/swift/storage.img|2G
|
||||||
swift-storage-zone2:
|
swift-storage-zone2:
|
||||||
zone: 2
|
zone: 2
|
||||||
block-device: sdb
|
block-device: /etc/swift/storage.img|2G
|
||||||
swift-storage-zone3:
|
swift-storage-zone3:
|
||||||
zone: 3
|
zone: 3
|
||||||
block-device: sdb
|
block-device: /etc/swift/storage.img|2G
|
||||||
END
|
END
|
||||||
$ juju deploy --config=swift.cfg swift-proxy
|
$ juju deploy --config=swift.cfg swift-proxy
|
||||||
$ juju deploy --config=swift.cfg swift-storage swift-storage-zone1
|
$ 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
|
replicas: 3
|
||||||
swift-storage:
|
swift-storage:
|
||||||
zone: 1
|
zone: 1
|
||||||
block-device: sdb
|
block-device: /etc/swift/storage.img|2G
|
||||||
END
|
END
|
||||||
$ juju deploy --config=swift.cfg swift-proxy
|
$ juju deploy --config=swift.cfg swift-proxy
|
||||||
$ juju deploy --config=swift.cfg swift-storage
|
$ juju deploy --config=swift.cfg swift-storage
|
||||||
|
|||||||
5
setup.cfg
Normal file
5
setup.cfg
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
[nosetests]
|
||||||
|
verbosity=1
|
||||||
|
with-coverage=1
|
||||||
|
cover-erase=1
|
||||||
|
cover-package=hooks
|
||||||
@@ -45,16 +45,11 @@ auth_uri = {{ auth_protocol }}://{{ keystone_host }}:{{ service_port }}
|
|||||||
admin_tenant_name = {{ service_tenant }}
|
admin_tenant_name = {{ service_tenant }}
|
||||||
admin_user = {{ service_user }}
|
admin_user = {{ service_user }}
|
||||||
admin_password = {{ service_password }}
|
admin_password = {{ service_password }}
|
||||||
{% if os_release == 'essex' %}
|
|
||||||
{% if delay_auth_decision|lower == 'true' %}
|
{% if delay_auth_decision|lower == 'true' %}
|
||||||
delay_auth_decision = 1
|
delay_auth_decision = 1
|
||||||
{% else %}
|
{% else %}
|
||||||
delay_auth_decision = 0
|
delay_auth_decision = 0
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% else %}
|
|
||||||
delay_auth_decision = {{ delay_auth_decision|lower }}
|
|
||||||
{% endif %}
|
|
||||||
{% if os_release != 'essex' %}signing_dir = /etc/swift{% endif %}
|
|
||||||
|
|
||||||
|
|
||||||
[filter:s3token]
|
[filter:s3token]
|
||||||
@@ -68,6 +63,5 @@ auth_token = {{ admin_token }}
|
|||||||
admin_token = {{ admin_token }}
|
admin_token = {{ admin_token }}
|
||||||
|
|
||||||
[filter:swift3]
|
[filter:swift3]
|
||||||
{% if os_release == 'essex' %}use = egg:swift#swift3{% else %}use = egg:swift3#swift3
|
use = egg:swift#swift3
|
||||||
{% endif %}
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ admin_tenant_name = {{ service_tenant }}
|
|||||||
admin_user = {{ service_user }}
|
admin_user = {{ service_user }}
|
||||||
admin_password = {{ service_password }}
|
admin_password = {{ service_password }}
|
||||||
delay_auth_decision = {{ delay_auth_decision|lower }}
|
delay_auth_decision = {{ delay_auth_decision|lower }}
|
||||||
{% if os_release != 'essex' %}signing_dir = /etc/swift{% endif %}
|
signing_dir = /etc/swift
|
||||||
|
|
||||||
[filter:s3token]
|
[filter:s3token]
|
||||||
paste.filter_factory = keystone.middleware.s3_token:filter_factory
|
paste.filter_factory = keystone.middleware.s3_token:filter_factory
|
||||||
@@ -59,6 +59,5 @@ auth_token = {{ admin_token }}
|
|||||||
admin_token = {{ admin_token }}
|
admin_token = {{ admin_token }}
|
||||||
|
|
||||||
[filter:swift3]
|
[filter:swift3]
|
||||||
{% if os_release == 'essex' %}use = egg:swift#swift3{% else %}use = egg:swift3#swift3
|
use = egg:swift3#swift3
|
||||||
{% endif %}
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ admin_tenant_name = {{ service_tenant }}
|
|||||||
admin_user = {{ service_user }}
|
admin_user = {{ service_user }}
|
||||||
admin_password = {{ service_password }}
|
admin_password = {{ service_password }}
|
||||||
delay_auth_decision = {{ delay_auth_decision|lower }}
|
delay_auth_decision = {{ delay_auth_decision|lower }}
|
||||||
{% if os_release != 'essex' %}signing_dir = /etc/swift{% endif %}
|
signing_dir = /etc/swift
|
||||||
cache = swift.cache
|
cache = swift.cache
|
||||||
|
|
||||||
[filter:s3token]
|
[filter:s3token]
|
||||||
@@ -60,6 +60,5 @@ auth_token = {{ admin_token }}
|
|||||||
admin_token = {{ admin_token }}
|
admin_token = {{ admin_token }}
|
||||||
|
|
||||||
[filter:swift3]
|
[filter:swift3]
|
||||||
{% if os_release == 'essex' %}use = egg:swift#swift3{% else %}use = egg:swift3#swift3
|
use = egg:swift3#swift3
|
||||||
{% endif %}
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|||||||
2
unit_tests/__init__.py
Normal file
2
unit_tests/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
import sys
|
||||||
|
sys.path.append('hooks')
|
||||||
65
unit_tests/test_templates.py
Normal file
65
unit_tests/test_templates.py
Normal file
@@ -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]"))
|
||||||
Reference in New Issue
Block a user