~le-charmers/charms/trusty/rabbitmq-server/leadership-election

« back to all changes in this revision

Viewing changes to tests/30_configuration_test.py

  • Committer: Liam Young
  • Date: 2015-05-11 08:03:57 UTC
  • mfrom: (83.1.14 rabbitmq-server)
  • Revision ID: liam.young@canonical.com-20150511080357-3ftop9kxb6o0e3mq
Merged trunk in + LE charmhelper sync

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
 
5
5
import amulet
6
6
import os
7
 
import requests
8
7
import socket
9
8
import ssl
 
9
from deploy_common import CA
10
10
 
11
11
# The number of seconds to wait for the environment to setup.
12
 
seconds = 900
 
12
seconds = 2700
13
13
# Get the directory in this way to load the files from the tests directory.
14
14
path = os.path.abspath(os.path.dirname(__file__))
15
 
key_path = os.path.join(path, 'rabbit-server-privkey.pem')
16
 
# Read the private key file.
17
 
with open(key_path) as f:
18
 
    privateKey = f.read()
19
 
cert_path = os.path.join(path, 'rabbit-server-cert.pem')
20
 
# Read the certificate file.
21
 
with open(cert_path) as f:
22
 
    certificate = f.read()
 
15
 
 
16
ca = CA()
 
17
 
 
18
privateKey = ca.get_key()
 
19
certificate = ca.get_cert()
23
20
 
24
21
# Create a dictionary of all the configuration values.
25
22
rabbit_configuration = {
27
24
    'ssl_enabled': True,
28
25
    'ssl_port': 5999,
29
26
    'ssl_key': privateKey,
30
 
    'ssl_cert': certificate
 
27
    'ssl_cert': certificate,
31
28
}
32
29
 
33
30
d = amulet.Deployment(series='trusty')
42
39
    # Execute the deployer with the current mapping.
43
40
    d.setup(timeout=seconds)
44
41
    # Wait for the relation to finish the transations.
45
 
    #d.sentry.wait(seconds)
 
42
    d.sentry.wait(seconds)
46
43
except amulet.helpers.TimeoutError:
47
44
    message = 'The environment did not setup in %d seconds.' % seconds
48
45
    # The SKIP status enables skip or fail the test based on configuration.
52
49
 
53
50
rabbit_unit = d.sentry.unit['rabbitmq-server/0']
54
51
###############################################################################
55
 
## Verify that the rabbit service is running on the deployed server.
 
52
# Verify that the rabbit service is running on the deployed server.
56
53
###############################################################################
57
54
# Create the command that checks if the rabbitmq-server service is running.
58
55
command = 'rabbitmqctl status'
68
65
    print('The rabbitmq-server is running.')
69
66
 
70
67
###############################################################################
71
 
## Verify the configuration values.
 
68
# Verify the configuration values.
72
69
###############################################################################
73
70
# Get the contents of the private key from the rabbitmq-server
74
71
contents = rabbit_unit.file_contents('/etc/rabbitmq/rabbit-server-privkey.pem')
92
89
rabbit_host = rabbit_unit.info['public-address']
93
90
 
94
91
###############################################################################
95
 
## Verify the management plugin is running and responding on correct port.
96
 
## According to this: http://www.rabbitmq.com/access-control.html
97
 
## The guest account can only log in from local host.
98
 
## Since this test runs on a different system there is no way to test
99
 
## the management plugin.
100
 
###############################################################################
101
 
# Create a url for the rabbitmq server's managment plugin (uses 55672).
102
 
#management_url = 'http://{0}:55672'.format(rabbit_host)
103
 
#print(management_url)
104
 
# Get the management url with the authentication for guest.
105
 
#r = requests.get(management_url, auth=('guest', 'guest'))
106
 
# Raise an exception if response is not 200 OK.
107
 
#r.raise_for_status()
108
 
#print(str(r))
109
 
#print('Successfully authenticated to the management console at %s' %
110
 
#      management_url)
111
 
 
112
 
###############################################################################
113
 
## Verify that SSL is set up on the non-default port.
 
92
# Verify that SSL is set up on the non-default port.
114
93
###############################################################################
115
94
# Get the port for ssl_port instance.
116
95
ssl_port = rabbit_configuration['ssl_port']
117
96
 
118
 
# Get the path to the certificate authority file.
119
 
ca_cert_path = os.path.join(path, 'rabbit-server-cacert.pem')
120
 
 
121
97
try:
122
98
    # Create a normal socket.
123
99
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
124
100
    # Require a certificate from the server, since a self-signed certificate
125
101
    # was used, the ca_certs must be the server certificate file itself.
126
 
    ssl_sock = ssl.wrap_socket(s, ca_certs=ca_cert_path,
 
102
    ssl_sock = ssl.wrap_socket(s, ca_certs=ca.ca_cert_path(),
127
103
                               cert_reqs=ssl.CERT_REQUIRED)
128
104
    # Connect to the rabbitmq server using ssl.
129
105
    ssl_sock.connect((rabbit_host, ssl_port))