~gnuoy/charms/trusty/nova-compute/resurrect-peer-relation

« back to all changes in this revision

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

  • Committer: james.page at ubuntu
  • Date: 2014-07-28 11:36:16 UTC
  • mfrom: (68.1.3 nova-compute)
  • Revision ID: james.page@ubuntu.com-20140728113616-spl81505m0q840sy
[corey.bryant,r=james-page] Add amulet tests

Show diffs side-by-side

added added

removed removed

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