~openstack-charmers-archive/charms/trusty/ceph/next

« back to all changes in this revision

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

  • Committer: Corey Bryant
  • Date: 2014-08-25 18:42:17 UTC
  • mto: This revision was merged to the branch mainline in revision 81.
  • Revision ID: corey.bryant@canonical.com-20140825184217-509a40kksblxwm18
Sync with charm-helpers

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import amulet
 
2
 
 
3
import os
 
4
 
 
5
 
 
6
class AmuletDeployment(object):
 
7
    """Amulet deployment.
 
8
 
 
9
       This class provides generic Amulet deployment and test runner
 
10
       methods.
 
11
       """
 
12
 
 
13
    def __init__(self, series=None):
 
14
        """Initialize the deployment environment."""
 
15
        self.series = None
 
16
 
 
17
        if series:
 
18
            self.series = series
 
19
            self.d = amulet.Deployment(series=self.series)
 
20
        else:
 
21
            self.d = amulet.Deployment()
 
22
 
 
23
    def _add_services(self, this_service, other_services):
 
24
        """Add services.
 
25
 
 
26
           Add services to the deployment where this_service is the local charm
 
27
           that we're focused on testing and other_services are the other
 
28
           charms that come from the charm store.
 
29
           """
 
30
        name, units = range(2)
 
31
 
 
32
        if this_service[name] != os.path.basename(os.getcwd()):
 
33
            s = this_service[name]
 
34
            msg = "The charm's root directory name needs to be {}".format(s)
 
35
            amulet.raise_status(amulet.FAIL, msg=msg)
 
36
 
 
37
        self.d.add(this_service[name], units=this_service[units])
 
38
 
 
39
        for svc in other_services:
 
40
            if self.series:
 
41
                self.d.add(svc[name],
 
42
                           charm='cs:{}/{}'.format(self.series, svc[name]),
 
43
                           units=svc[units])
 
44
            else:
 
45
                self.d.add(svc[name], units=svc[units])
 
46
 
 
47
    def _add_relations(self, relations):
 
48
        """Add all of the relations for the services."""
 
49
        for k, v in relations.iteritems():
 
50
            self.d.relate(k, v)
 
51
 
 
52
    def _configure_services(self, configs):
 
53
        """Configure all of the services."""
 
54
        for service, config in configs.iteritems():
 
55
            self.d.configure(service, config)
 
56
 
 
57
    def _deploy(self):
 
58
        """Deploy environment and wait for all hooks to finish executing."""
 
59
        try:
 
60
            self.d.setup()
 
61
            self.d.sentry.wait(timeout=900)
 
62
        except amulet.helpers.TimeoutError:
 
63
            amulet.raise_status(amulet.FAIL, msg="Deployment timed out")
 
64
        except Exception:
 
65
            raise
 
66
 
 
67
    def run_tests(self):
 
68
        """Run all of the methods that are prefixed with 'test_'."""
 
69
        for test in dir(self):
 
70
            if test.startswith('test_'):
 
71
                getattr(self, test)()