~brad-marshall/charms/trusty/ubuntu/nrpe-interface

« back to all changes in this revision

Viewing changes to tests/10-deploy-test.py

  • Committer: Marco Ceppi
  • Date: 2014-02-05 10:21:23 UTC
  • mfrom: (6.1.1 ubuntu)
  • Revision ID: marco@ceppi.net-20140205102123-zle26abuw46n9oml
[a.rosales] Add basic Amulet based tests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python3
 
2
 
 
3
# This Amulet based tests
 
4
# The goal is to ensure the Ubuntu charm
 
5
# sucessfully deploys and can be accessed.
 
6
# Note the Ubuntu charm does not have any 
 
7
# relations or config options.
 
8
 
 
9
import amulet
 
10
#import os
 
11
#import requests
 
12
 
 
13
# Timeout value, in seconds to deploy the environment
 
14
seconds = 900
 
15
 
 
16
# Set up the deployer module to interact and set up the environment.
 
17
d = amulet.Deployment()
 
18
 
 
19
# Define the environment in terms of charms, their config, and relations.
 
20
 
 
21
# Add the Ubuntu charm to the deployment.
 
22
d.add('ubuntu')
 
23
 
 
24
# Deploy the environment currently defined
 
25
try:
 
26
    # Wait the defined about amount of time to deploy the environment.
 
27
    # Setup makes sure the services are deployed, related, and in a
 
28
    # "started" state.
 
29
    d.setup(timeout=seconds)
 
30
    # Use a sentry to ensure there are no remaining hooks being execute
 
31
    # on any of the nodes
 
32
##    d.sentry.wait()
 
33
except amulet.helpers.TimeoutError:
 
34
    # Pending the configuration the test will fail or be skipped
 
35
    # if not deployed properly.
 
36
    error_message = 'The environment did not deploy in %d seconds.' % seconds
 
37
    amulet.raise_status(amulet.SKIP, msg=error_message)
 
38
except:
 
39
    # Something else has gone wrong, raise the error so we can see it and this
 
40
    # will automatically "FAIL" the test.
 
41
    raise
 
42
 
 
43
# Access the Ubuntu instance to ensure it has been deployed correctly 
 
44
 
 
45
# Define the commands to be ran
 
46
lsb_release_command = 'cat /etc/lsb-release'
 
47
uname_command = 'uname -a'
 
48
 
 
49
# Cat the release information
 
50
output, code = d.sentry.unit['ubuntu/0'].run(lsb_release_command)
 
51
# Confirm the lsb-release command was ran successfully
 
52
if (code != 0):
 
53
    error_message = 'The ' + lsb_release_command + ' did not return the expected return code of 0.'
 
54
    print(output)
 
55
    amulet.raise_status(amulet.FAIL, msg=error_message)
 
56
else:
 
57
    message = 'The lsb-release command successfully executed.'
 
58
    print(output)
 
59
    print(message)
 
60
 
 
61
# Get the uname -a output 
 
62
output, code = d.sentry.unit['ubuntu/0'].run(uname_command)
 
63
# Confirm the uname command was ran successfully
 
64
if (code != 0):
 
65
    error_message = 'The ' + uname_command + ' did not return the expected return code of 0.'
 
66
    print(output)
 
67
    amulet.raise_status(amulet.FAIL, msg=error_message)
 
68
else:
 
69
    message = 'The uname command successfully executed.'
 
70
    print(output)
 
71
    print(message)