~brad-marshall/charms/trusty/ceph-osd/add-nrpe-checks

« back to all changes in this revision

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

  • Committer: james.page at ubuntu
  • Date: 2014-10-06 22:09:58 UTC
  • mfrom: (27.1.5 ceph-osd)
  • Revision ID: james.page@ubuntu.com-20141006220958-c00zdv2dk50h6ajd
[coreycb,r=james-page] Add amulet tests.

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 testing and other_services are the other services that
 
28
           are being used in the local amulet tests.
 
29
           """
 
30
        if this_service['name'] != os.path.basename(os.getcwd()):
 
31
            s = this_service['name']
 
32
            msg = "The charm's root directory name needs to be {}".format(s)
 
33
            amulet.raise_status(amulet.FAIL, msg=msg)
 
34
 
 
35
        if 'units' not in this_service:
 
36
            this_service['units'] = 1
 
37
 
 
38
        self.d.add(this_service['name'], units=this_service['units'])
 
39
 
 
40
        for svc in other_services:
 
41
            if 'location' in svc:
 
42
                branch_location = svc['location']
 
43
            elif self.series:
 
44
                branch_location = 'cs:{}/{}'.format(self.series, svc['name']),
 
45
            else:
 
46
                branch_location = None
 
47
 
 
48
            if 'units' not in svc:
 
49
                svc['units'] = 1
 
50
 
 
51
            self.d.add(svc['name'], charm=branch_location, units=svc['units'])
 
52
 
 
53
    def _add_relations(self, relations):
 
54
        """Add all of the relations for the services."""
 
55
        for k, v in relations.iteritems():
 
56
            self.d.relate(k, v)
 
57
 
 
58
    def _configure_services(self, configs):
 
59
        """Configure all of the services."""
 
60
        for service, config in configs.iteritems():
 
61
            self.d.configure(service, config)
 
62
 
 
63
    def _deploy(self):
 
64
        """Deploy environment and wait for all hooks to finish executing."""
 
65
        try:
 
66
            self.d.setup(timeout=900)
 
67
            self.d.sentry.wait(timeout=900)
 
68
        except amulet.helpers.TimeoutError:
 
69
            amulet.raise_status(amulet.FAIL, msg="Deployment timed out")
 
70
        except Exception:
 
71
            raise
 
72
 
 
73
    def run_tests(self):
 
74
        """Run all of the methods that are prefixed with 'test_'."""
 
75
        for test in dir(self):
 
76
            if test.startswith('test_'):
 
77
                getattr(self, test)()