9
from deploy_common import CA
11
11
# The number of seconds to wait for the environment to setup.
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:
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()
18
privateKey = ca.get_key()
19
certificate = ca.get_cert()
24
21
# Create a dictionary of all the configuration values.
25
22
rabbit_configuration = {
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.
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.')
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']
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()
109
#print('Successfully authenticated to the management console at %s' %
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']
118
# Get the path to the certificate authority file.
119
ca_cert_path = os.path.join(path, 'rabbit-server-cacert.pem')
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))