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

« back to all changes in this revision

Viewing changes to tests/10_basic_deploy_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:
6
6
import os
7
7
import socket
8
8
import ssl
 
9
from deploy_common import CA
9
10
 
10
11
# The number of seconds to wait for the environment to setup.
11
12
seconds = 900
12
13
# Get the directory in this way to load the files from the tests directory.
13
14
path = os.path.abspath(os.path.dirname(__file__))
14
15
 
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
 
# Read the certificate file.
20
 
cert_path = os.path.join(path, 'rabbit-server-cert.pem')
21
 
with open(cert_path) as f:
22
 
    certificate = f.read()
 
16
ca = CA()
23
17
 
24
18
# Create a dictionary for the rabbitmq configuration.
25
19
rabbitmq_configuration = {
26
20
    'ssl_enabled': True,
27
 
    'ssl_key': privateKey,
28
 
    'ssl_cert': certificate,
 
21
    'ssl_key': ca.get_key(),
 
22
    'ssl_cert': ca.get_cert(),
29
23
    'ssl_port': 5671
30
24
}
31
25
 
49
43
print('The rabbitmq-server has been successfully deployed.')
50
44
 
51
45
###############################################################################
52
 
## Verify that the rabbit service is running on the deployed server.
 
46
# Verify that the rabbit service is running on the deployed server.
53
47
###############################################################################
54
48
rabbitmq_sentry = d.sentry.unit['rabbitmq-server/0']
55
49
# Get the public address for rabbitmq-server instance.
68
62
    print('The rabbitmq-server is running on %s' % server_address)
69
63
 
70
64
###############################################################################
71
 
## Test the ssl certificate.
 
65
# Test the ssl certificate.
72
66
###############################################################################
73
67
# Get the port for ssl_port instance.
74
68
server_port = rabbitmq_configuration['ssl_port']
75
69
 
76
 
# Get the path to the certificate authority file.
77
 
ca_cert_path = os.path.join(path, 'rabbit-server-cacert.pem')
78
 
 
79
70
print('Testing ssl connection to rabbitmq-server.')
80
71
try:
81
72
    # Create a normal socket.
82
73
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
83
74
    # Require a certificate from the server, since a self-signed certificate
84
75
    # was used, the ca_certs must be the server certificate file itself.
85
 
    ssl_sock = ssl.wrap_socket(s, ca_certs=ca_cert_path,
 
76
    ssl_sock = ssl.wrap_socket(s, ca_certs=ca.ca_cert_path(),
86
77
                               cert_reqs=ssl.CERT_REQUIRED)
87
78
    # Connect to the rabbitmq server using ssl.
88
79
    ssl_sock.connect((server_address, server_port))