3
# This Amulet test exercises the configuration options for rabbitmq-server.
9
from deploy_common import CA
11
# The number of seconds to wait for the environment to setup.
13
# Get the directory in this way to load the files from the tests directory.
14
path = os.path.abspath(os.path.dirname(__file__))
18
privateKey = ca.get_key()
19
certificate = ca.get_cert()
21
# Create a dictionary of all the configuration values.
22
rabbit_configuration = {
23
'management_plugin': True,
26
'ssl_key': privateKey,
27
'ssl_cert': certificate,
30
d = amulet.Deployment(series='trusty')
31
# Add the rabbitmq-server charm to the deployment.
32
d.add('rabbitmq-server')
33
# Configure all the options on rabbitmq-server.
34
d.configure('rabbitmq-server', rabbit_configuration)
35
# Expose the rabbitmq-server.
36
d.expose('rabbitmq-server')
39
# Execute the deployer with the current mapping.
40
d.setup(timeout=seconds)
41
# Wait for the relation to finish the transations.
42
d.sentry.wait(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)
50
rabbit_unit = d.sentry.unit['rabbitmq-server/0']
51
###############################################################################
52
# Verify that the rabbit service is running on the deployed server.
53
###############################################################################
54
# Create the command that checks if the rabbitmq-server service is running.
55
command = 'rabbitmqctl status'
57
# Execute the command on the deployed service.
58
output, code = rabbit_unit.run(command)
60
# Check the return code for the success and failure of this test.
62
message = 'The ' + command + ' did not return the expected code of 0.'
63
amulet.raise_status(amulet.FAIL, msg=message)
65
print('The rabbitmq-server is running.')
67
###############################################################################
68
# Verify the configuration values.
69
###############################################################################
70
# Get the contents of the private key from the rabbitmq-server
71
contents = rabbit_unit.file_contents('/etc/rabbitmq/rabbit-server-privkey.pem')
72
# Verify the private key was saved on the rabbitmq server correctly.
73
if contents != privateKey:
74
message = 'The private keys did not match!'
75
amulet.raise_status(amulet.FAIL, msg=message)
77
print('The private keys was configured properly on the rabbitmq server.')
79
# Get the contents of the certificate from the rabbitmq-server.
80
contents = rabbit_unit.file_contents('/etc/rabbitmq/rabbit-server-cert.pem')
81
# Verify the certificate was saved on the rabbitmq server correctly.
82
if contents != certificate:
83
message = 'The certificates did not match!'
84
amulet.raise_status(amulet.FAIL, msg=message)
86
print('The certificate was configured properly on the rabbitmq server.')
88
# Get the public address for rabbitmq-server instance.
89
rabbit_host = rabbit_unit.info['public-address']
91
###############################################################################
92
# Verify that SSL is set up on the non-default port.
93
###############################################################################
94
# Get the port for ssl_port instance.
95
ssl_port = rabbit_configuration['ssl_port']
98
# Create a normal socket.
99
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
100
# Require a certificate from the server, since a self-signed certificate
101
# was used, the ca_certs must be the server certificate file itself.
102
ssl_sock = ssl.wrap_socket(s, ca_certs=ca.ca_cert_path(),
103
cert_reqs=ssl.CERT_REQUIRED)
104
# Connect to the rabbitmq server using ssl.
105
ssl_sock.connect((rabbit_host, ssl_port))
106
# Get the certificate.
107
certificate = ssl_sock.getpeercert()
108
# SSL scoket connected and got the certificate, this passes the ssl test!
109
print('Connected to the rabbitmq-server {0}:{1} using ssl!'.format(
110
rabbit_host, ssl_port))
111
except Exception as e:
112
message = 'Failed to create an ssl connection to {0}:{1}\n{2}'.format(
113
rabbit_host, ssl_port, str(e))
114
amulet.raise_status(amulet.FAIL, msg=message)
118
print('The rabbitmq-server passed the configuration tests.')