~ivoks/charms/trusty/neutron-gateway/mtu-vlan

« back to all changes in this revision

Viewing changes to tests/charmhelpers/contrib/amulet/deployment.py

  • Committer: Corey Bryant
  • Date: 2014-07-09 19:25:29 UTC
  • mto: This revision was merged to the branch mainline in revision 54.
  • Revision ID: corey.bryant@canonical.com-20140709192529-c2azv58whgj6dnmd
Sync with charm-helpers

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import amulet
 
2
import re
 
3
 
 
4
 
 
5
class AmuletDeployment(object):
 
6
    """This class provides generic Amulet deployment and test runner
 
7
       methods."""
 
8
 
 
9
    def __init__(self, series):
 
10
        """Initialize the deployment environment."""
 
11
        self.series = series
 
12
        self.d = amulet.Deployment(series=self.series)
 
13
 
 
14
    def _get_charm_name(self, service_name):
 
15
        """Gets the charm name from the service name. Unique service names can
 
16
           be specified with a '-service#' suffix (e.g. mysql-service1)."""
 
17
        if re.match(r"^.*-service\d{1,3}$", service_name):
 
18
            charm_name = re.sub('\-service\d{1,3}$', '', service_name)
 
19
        else:
 
20
            charm_name = service_name
 
21
        return charm_name
 
22
 
 
23
    def _add_services(self, this_service, other_services):
 
24
        """Add services to the deployment where this_service is the local charm
 
25
           that we're focused on testing and other_services are the other
 
26
           charms that come from the charm store."""
 
27
        name, units = range(2)
 
28
 
 
29
        charm_name = self._get_charm_name(this_service[name])
 
30
        self.d.add(this_service[name],
 
31
                   units=this_service[units])
 
32
 
 
33
        for svc in other_services:
 
34
            charm_name = self._get_charm_name(svc[name])
 
35
            self.d.add(svc[name],
 
36
                       charm='cs:{}/{}'.format(self.series, charm_name),
 
37
                       units=svc[units])
 
38
 
 
39
    def _add_relations(self, relations):
 
40
        """Add all of the relations for the services."""
 
41
        for k, v in relations.iteritems():
 
42
            self.d.relate(k, v)
 
43
 
 
44
    def _configure_services(self, configs):
 
45
        """Configure all of the services."""
 
46
        for service, config in configs.iteritems():
 
47
            self.d.configure(service, config)
 
48
 
 
49
    def _deploy(self):
 
50
        """Deploy environment and wait for all hooks to finish executing."""
 
51
        try:
 
52
            self.d.setup()
 
53
            self.d.sentry.wait()
 
54
        except amulet.helpers.TimeoutError:
 
55
            amulet.raise_status(amulet.FAIL, msg="Deployment timed out")
 
56
        except:
 
57
            raise
 
58
 
 
59
    def run_tests(self):
 
60
        """Run all of the methods that are prefixed with 'test_'."""
 
61
        for test in dir(self):
 
62
            if test.startswith('test_'):
 
63
                getattr(self, test)()