[macgreagoir] Make heat.conf instance_user item configurable.
This commit is contained in:
parent
08d5474e65
commit
74a78e5f58
4
Makefile
4
Makefile
@ -21,4 +21,8 @@ sync: bin/charm_helpers_sync.py
|
|||||||
unit_test:
|
unit_test:
|
||||||
@$(PYTHON) /usr/bin/nosetests --nologcapture --with-coverage unit_tests
|
@$(PYTHON) /usr/bin/nosetests --nologcapture --with-coverage unit_tests
|
||||||
|
|
||||||
|
test:
|
||||||
|
@echo "Running amulet tests: "
|
||||||
|
@for f in tests/*; do $$f; done
|
||||||
|
|
||||||
all: unit_test lint
|
all: unit_test lint
|
||||||
|
@ -22,6 +22,13 @@ options:
|
|||||||
default: heat
|
default: heat
|
||||||
type: string
|
type: string
|
||||||
description: Database name
|
description: Database name
|
||||||
|
instance-user:
|
||||||
|
default:
|
||||||
|
type: string
|
||||||
|
description: |
|
||||||
|
The default user for new instances. This option is deprecated as of Juno.
|
||||||
|
If left empty, Heat will use the default user set up with your cloud
|
||||||
|
image (for OS::Nova::Server) or 'ec2-user' (for AWS::EC2::Instance).
|
||||||
region:
|
region:
|
||||||
default: RegionOne
|
default: RegionOne
|
||||||
type: string
|
type: string
|
||||||
|
@ -96,3 +96,15 @@ class HeatApacheSSLContext(context.ApacheSSLContext):
|
|||||||
|
|
||||||
external_ports = API_PORTS.values()
|
external_ports = API_PORTS.values()
|
||||||
service_namespace = 'heat'
|
service_namespace = 'heat'
|
||||||
|
|
||||||
|
|
||||||
|
class InstanceUserContext(context.OSContextGenerator):
|
||||||
|
|
||||||
|
def __call__(self):
|
||||||
|
ctxt = {}
|
||||||
|
|
||||||
|
instance_user = ''
|
||||||
|
if config('instance-user'):
|
||||||
|
instance_user = config('instance-user')
|
||||||
|
ctxt['instance_user'] = instance_user
|
||||||
|
return ctxt
|
||||||
|
@ -29,6 +29,7 @@ from heat_context import (
|
|||||||
API_PORTS,
|
API_PORTS,
|
||||||
HeatIdentityServiceContext,
|
HeatIdentityServiceContext,
|
||||||
EncryptionContext,
|
EncryptionContext,
|
||||||
|
InstanceUserContext,
|
||||||
HeatApacheSSLContext,
|
HeatApacheSSLContext,
|
||||||
HeatHAProxyContext,
|
HeatHAProxyContext,
|
||||||
)
|
)
|
||||||
@ -68,6 +69,7 @@ CONFIG_FILES = OrderedDict([
|
|||||||
HeatIdentityServiceContext(service=SVC, service_user=SVC),
|
HeatIdentityServiceContext(service=SVC, service_user=SVC),
|
||||||
HeatHAProxyContext(),
|
HeatHAProxyContext(),
|
||||||
EncryptionContext(),
|
EncryptionContext(),
|
||||||
|
InstanceUserContext(),
|
||||||
context.SyslogContext()]
|
context.SyslogContext()]
|
||||||
}),
|
}),
|
||||||
(HEAT_API_PASTE, {
|
(HEAT_API_PASTE, {
|
||||||
|
@ -3,7 +3,9 @@ use_syslog = {{ use_syslog }}
|
|||||||
debug = False
|
debug = False
|
||||||
verbose = False
|
verbose = False
|
||||||
log_dir = /var/log/heat
|
log_dir = /var/log/heat
|
||||||
instance_user=ec2-user
|
# Icehouse expects 'instance_user=' to allow the image's default user
|
||||||
|
# Not including instance_user at all results in 'ec2-user' being used
|
||||||
|
instance_user={{ instance_user }}
|
||||||
instance_driver=heat.engine.nova
|
instance_driver=heat.engine.nova
|
||||||
plugin_dirs=/usr/lib64/heat,/usr/lib/heat
|
plugin_dirs=/usr/lib64/heat,/usr/lib/heat
|
||||||
environment_dir=/etc/heat/environment.d
|
environment_dir=/etc/heat/environment.d
|
||||||
|
5
tests/00-setup
Executable file
5
tests/00-setup
Executable file
@ -0,0 +1,5 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
sudo add-apt-repository ppa:juju/stable -y
|
||||||
|
sudo apt-get update
|
||||||
|
sudo apt-get install amulet python3-requests -y
|
66
tests/50-basic-deploy
Executable file
66
tests/50-basic-deploy
Executable file
@ -0,0 +1,66 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
import amulet
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
|
||||||
|
class TestDeployment(unittest.TestCase):
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def setUpClass(cls):
|
||||||
|
try:
|
||||||
|
cls.d = amulet.Deployment(series='trusty')
|
||||||
|
cls.d.add('heat')
|
||||||
|
cls.d.configure('heat', {'instance-user': 'ubuntu'})
|
||||||
|
cls.d.setup(timeout=1800)
|
||||||
|
cls.d.sentry.wait()
|
||||||
|
|
||||||
|
cls.u = cls.d.sentry.unit['heat/0']
|
||||||
|
except amulet.helpers.TimeoutError:
|
||||||
|
msg = "Environment wasn't stood up in time"
|
||||||
|
amulet.raise_status(amulet.SKIP, msg=msg)
|
||||||
|
except:
|
||||||
|
raise
|
||||||
|
|
||||||
|
# amulet.raise_status():
|
||||||
|
# - amulet.PASS
|
||||||
|
# - amulet.FAIL
|
||||||
|
# - amulet.SKIP
|
||||||
|
# Each unit has the following methods:
|
||||||
|
# - .info - An array of the information of that unit from Juju
|
||||||
|
# - .file(PATH) - Get the details of a file on that unit
|
||||||
|
# - .file_contents(PATH) - Get plain text output of PATH file from that unit
|
||||||
|
# - .directory(PATH) - Get details of directory
|
||||||
|
# - .directory_contents(PATH) - List files and folders in PATH on that unit
|
||||||
|
# - .relation(relation, service:rel) - Get relation data from return service
|
||||||
|
# add tests here to confirm service is up and working properly
|
||||||
|
# - .run(something)
|
||||||
|
# For example, to confirm that it has a functioning HTTP server:
|
||||||
|
# page = requests.get('http://{}'.format(self.unit.info['public-address']))
|
||||||
|
# page.raise_for_status()
|
||||||
|
# More information on writing Amulet tests can be found at:
|
||||||
|
# https://juju.ubuntu.com/docs/tools-amulet.html
|
||||||
|
|
||||||
|
def check_file_content(self, name, find):
|
||||||
|
"""Check that the named file exists and contains the find text."""
|
||||||
|
stat = TestDeployment.u.file(name)
|
||||||
|
if stat is None:
|
||||||
|
msg = "Could not retrieve status of %s" % name
|
||||||
|
amulet.raise_status(amulet.FAIL, msg=msg)
|
||||||
|
content = TestDeployment.u.file_contents(name)
|
||||||
|
if content.find(find) < 0:
|
||||||
|
msg = "%s does not contain the required text (%s)" % (name, find)
|
||||||
|
amulet.raise_status(amulet.FAIL, msg=msg)
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
print("%s contains the required text (%s)" % (name, find))
|
||||||
|
return True
|
||||||
|
|
||||||
|
def test_instance_user(self):
|
||||||
|
"""Check that /etc/heat/heat.conf has instance_user item"""
|
||||||
|
# finding only 'instance_user=' will catch comments too
|
||||||
|
self.check_file_content(name='/etc/heat/heat.conf', find='instance_user=ubuntu')
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
@ -4,7 +4,8 @@ from test_utils import CharmTestCase
|
|||||||
|
|
||||||
TO_PATCH = [
|
TO_PATCH = [
|
||||||
'get_encryption_key',
|
'get_encryption_key',
|
||||||
'generate_ec2_tokens'
|
'generate_ec2_tokens',
|
||||||
|
'config'
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
@ -19,6 +20,12 @@ class TestHeatContext(CharmTestCase):
|
|||||||
heat_context.EncryptionContext()(),
|
heat_context.EncryptionContext()(),
|
||||||
{'encryption_key': 'key'})
|
{'encryption_key': 'key'})
|
||||||
|
|
||||||
|
def test_instance_user_empty_configuration(self):
|
||||||
|
self.config.return_value = None
|
||||||
|
self.assertEquals(
|
||||||
|
heat_context.InstanceUserContext()(),
|
||||||
|
{'instance_user': ''})
|
||||||
|
|
||||||
@patch('charmhelpers.contrib.openstack.'
|
@patch('charmhelpers.contrib.openstack.'
|
||||||
'context.IdentityServiceContext.__call__')
|
'context.IdentityServiceContext.__call__')
|
||||||
def test_identity_configuration(self, __call__):
|
def test_identity_configuration(self, __call__):
|
||||||
|
Loading…
Reference in New Issue
Block a user