3
# This Amulet test performs a basic deploy and checks if rabbitmq is running.
9
# The number of seconds to wait for the environment to setup.
11
# Get the directory in this way to load the files from the tests directory.
12
path = os.path.abspath(os.path.dirname(__file__))
14
key_path = os.path.join(path, 'rabbit-server-privkey.pem')
15
# Read the private key file.
16
with open(key_path) as f:
18
# Read the certificate file.
19
cert_path = os.path.join(path, 'rabbit-server-cert.pem')
20
with open(cert_path) as f:
21
certificate = f.read()
23
# Create a dictionary for the rabbitmq configuration.
24
rabbitmq_configuration = {
25
'stats_cron_schedule': '*/1 * * * *'
27
d = amulet.Deployment(series='trusty')
28
# Add the rabbitmq-server charm to the deployment.
29
d.add('rabbitmq-server')
30
# Configure options on the rabbitmq-server.
31
d.configure('rabbitmq-server', rabbitmq_configuration)
32
# Expose the server so we can connect.
33
d.expose('rabbitmq-server')
34
# XXX Remove charm= once this branch lands in the charm store
35
d.add('nrpe-external-master',
36
charm='lp:~gnuoy/charms/trusty/nrpe/services-rewrite')
37
d.relate('rabbitmq-server:nrpe-external-master',
38
'nrpe-external-master:nrpe-external-master')
41
# Execute the deployer with the current mapping.
42
d.setup(timeout=seconds)
43
except amulet.helpers.TimeoutError:
44
message = 'The environment did not setup in %d seconds.' % seconds
45
# The SKIP status enables skip or fail the test based on configuration.
46
amulet.raise_status(amulet.SKIP, msg=message)
49
print('The rabbitmq-server has been successfully deployed and related '
50
'to nrpe-external-master.')
52
###############################################################################
53
# # Verify nagios checks
54
###############################################################################
55
rabbitmq_sentry = d.sentry.unit['rabbitmq-server/0']
57
command = 'bash -c "$(egrep -oh /usr/local.* ' \
58
'/etc/nagios/nrpe.d/check_rabbitmq.cfg)"'
60
output, code = rabbitmq_sentry.run(command)
63
message = 'The ' + command + ' did not return the expected code of 0.'
64
amulet.raise_status(amulet.FAIL, msg=message)
66
print('The rabbitmq-server check_rabbitmq is OK')
68
print('Sleeping 70 seconds to make sure the monitoring cron has run')
71
command = 'bash -c "$(egrep -oh /usr/local.* ' \
72
'/etc/nagios/nrpe.d/check_rabbitmq_queue.cfg)"'
74
output, code = rabbitmq_sentry.run(command)
77
message = 'The ' + command + ' did not return the expected code of 0.'
78
amulet.raise_status(amulet.FAIL, msg=message)
80
print('The rabbitmq-server check_rabbitmq_queue is OK')
83
print('The rabbitmq-server passed the monitoring tests!')