~charmers/charms/wily/ubuntu/trunk

« back to all changes in this revision

Viewing changes to tests/basic_deployment.py

  • Committer: Tim Van Steenburgh
  • Date: 2015-05-01 10:12:08 UTC
  • mfrom: (10.1.4 ubuntu)
  • Revision ID: tim.van.steenburgh@canonical.com-20150501101208-7jvqc9dtmlfz7kvk
[1chb1n] Remove hooks and lxc stuff; update tests

Revert charm to have no hooks and no config options; add functional tests for all currently-supported Ubuntu releases; add bundletester usage examples.

Charm is now compatible with both 'juju test' and bundletester.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python3
 
2
"""
 
3
Ubuntu charm functional test.  Take note that the Ubuntu
 
4
charm does not have any relations or config options
 
5
to exercise.
 
6
"""
 
7
 
 
8
import amulet
 
9
from charmhelpers.contrib.amulet.utils import AmuletUtils
 
10
import logging
 
11
 
 
12
 
 
13
def ubuntu_basic_deployment(series):
 
14
    """ Common test routines to run per-series. """
 
15
 
 
16
    # Initialize
 
17
    seconds = 900
 
18
    u = AmuletUtils(logging.DEBUG)
 
19
    d = amulet.Deployment(series=series)
 
20
    d.add('ubuntu')
 
21
    unit = 'ubuntu/0'
 
22
    lsb_command = 'lsb_release -cs'
 
23
 
 
24
    # Deploy services, wait for started state.  Fail or skip on timeout.
 
25
    try:
 
26
        d.setup(timeout=seconds)
 
27
    except amulet.helpers.TimeoutError:
 
28
        message = 'Deployment timed out ({}s)'.format(seconds)
 
29
        amulet.raise_status(amulet.SKIP, msg=message)
 
30
    except:
 
31
        raise
 
32
 
 
33
    # Confirm Ubuntu release name from the unit.
 
34
    u.log.debug('Command:  {}'.format(lsb_command))
 
35
    output, code = d.sentry.unit[unit].run(lsb_command)
 
36
    u.log.debug('Output:  {}'.format(output))
 
37
 
 
38
    if (code != 0):
 
39
        message = 'Command FAIL:  {}'.format(lsb_command)
 
40
        u.log.error(message)
 
41
        amulet.raise_status(amulet.FAIL, msg=message)
 
42
    else:
 
43
        if series in output:
 
44
            message = 'Series:  OK'
 
45
            u.log.info(message)
 
46
        else:
 
47
            message = 'Series:  FAIL ({})'.format(output)
 
48
            u.log.error(message)
 
49
            amulet.raise_status(amulet.FAIL, msg=message)