1
# Copyright 2014-2015 Canonical Limited.
3
# This file is part of charm-helpers.
5
# charm-helpers is free software: you can redistribute it and/or modify
6
# it under the terms of the GNU Lesser General Public License version 3 as
7
# published by the Free Software Foundation.
9
# charm-helpers is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU Lesser General Public License for more details.
14
# You should have received a copy of the GNU Lesser General Public License
15
# along with charm-helpers. If not, see <http://www.gnu.org/licenses/>.
22
class AmuletDeployment(object):
25
This class provides generic Amulet deployment and test runner
29
def __init__(self, series=None):
30
"""Initialize the deployment environment."""
35
self.d = amulet.Deployment(series=self.series)
37
self.d = amulet.Deployment()
39
def _add_services(self, this_service, other_services):
42
Add services to the deployment where this_service is the local charm
43
that we're testing and other_services are the other services that
44
are being used in the local amulet tests.
46
if this_service['name'] != os.path.basename(os.getcwd()):
47
s = this_service['name']
48
msg = "The charm's root directory name needs to be {}".format(s)
49
amulet.raise_status(amulet.FAIL, msg=msg)
51
if 'units' not in this_service:
52
this_service['units'] = 1
54
self.d.add(this_service['name'], units=this_service['units'],
55
constraints=this_service.get('constraints'))
57
for svc in other_services:
59
branch_location = svc['location']
61
branch_location = 'cs:{}/{}'.format(self.series, svc['name']),
63
branch_location = None
65
if 'units' not in svc:
68
self.d.add(svc['name'], charm=branch_location, units=svc['units'],
69
constraints=svc.get('constraints'))
71
def _add_relations(self, relations):
72
"""Add all of the relations for the services."""
73
for k, v in six.iteritems(relations):
76
def _configure_services(self, configs):
77
"""Configure all of the services."""
78
for service, config in six.iteritems(configs):
79
self.d.configure(service, config)
82
"""Deploy environment and wait for all hooks to finish executing."""
84
self.d.setup(timeout=900)
85
self.d.sentry.wait(timeout=900)
86
except amulet.helpers.TimeoutError:
87
amulet.raise_status(amulet.FAIL, msg="Deployment timed out")
92
"""Run all of the methods that are prefixed with 'test_'."""
93
for test in dir(self):
94
if test.startswith('test_'):