else:
    print('The rabbitmq-server is running on %s' % server_address)

###############################################################################
# Test the ssl certificate.
###############################################################################
# Get the port for ssl_port instance.
server_port = rabbitmq_configuration['ssl_port']

print('Testing ssl connection to rabbitmq-server.')
try:
    # Create a normal socket.
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    # Require a certificate from the server, since a self-signed certificate
    # was used, the ca_certs must be the server certificate file itself.
    ssl_sock = ssl.wrap_socket(s, ca_certs=ca.ca_cert_path(),
                               cert_reqs=ssl.CERT_REQUIRED)
    # Connect to the rabbitmq server using ssl.
    ssl_sock.connect((server_address, server_port))
    # Get the certificate.
    certificate = ssl_sock.getpeercert()
    # SSL socket connected and got the certificate, this passes the ssl test!
    print('Connected to the rabbitmq-server {0}:{1} using ssl!'.format(
          server_address, server_port))
except Exception as e:
    message = 'Failed to create an ssl connection to {0}:{1}\n{2}'.format(
              server_address, server_port, str(e))
    amulet.raise_status(amulet.FAIL, msg=message)
finally:
    ssl_sock.close()
    print("The certificate was configured properly on the rabbitmq server.")

# Get the public address for rabbitmq-server instance.
rabbit_host = rabbit_unit.info["public-address"]

###############################################################################
# Verify that SSL is set up on the non-default port.
###############################################################################
# Get the port for ssl_port instance.
ssl_port = rabbit_configuration["ssl_port"]

try:
    # Create a normal socket.
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    # Require a certificate from the server, since a self-signed certificate
    # was used, the ca_certs must be the server certificate file itself.
    ssl_sock = ssl.wrap_socket(s, ca_certs=ca.ca_cert_path(), cert_reqs=ssl.CERT_REQUIRED)
    # Connect to the rabbitmq server using ssl.
    ssl_sock.connect((rabbit_host, ssl_port))
    # Get the certificate.
    certificate = ssl_sock.getpeercert()
    # SSL scoket connected and got the certificate, this passes the ssl test!
    print("Connected to the rabbitmq-server {0}:{1} using ssl!".format(rabbit_host, ssl_port))
except Exception as e:
    message = "Failed to create an ssl connection to {0}:{1}\n{2}".format(rabbit_host, ssl_port, str(e))
    amulet.raise_status(amulet.FAIL, msg=message)
finally:
    ssl_sock.close()

print("The rabbitmq-server passed the configuration tests.")