~tribaal/charms/trusty/rabbitmq-server/backport-lp1500204-with-next-tests

« back to all changes in this revision

Viewing changes to tests/deploy_common.py

  • Committer: Christopher Glass
  • Date: 2015-10-13 17:08:50 UTC
  • Revision ID: christopher.glass@canonical.com-20151013170850-99awo9ad2e0yu3ei
Ripped out and grafted the -next tests to the stable branch.

"Cursed, cursed creator! Why did I live?"

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright 2015 Canonical Limited.
2
 
# This file provides common functions for amulet tests for the rabbitmq-server
3
 
# juju charm.
4
 
 
5
 
import os
6
 
from charmhelpers.contrib.ssl.service import ServiceCA
7
 
 
8
 
 
9
 
class CA(object):
10
 
    """
11
 
    Represents the certificate authority for use in RabbitMQ amulet tests.
12
 
    """
13
 
    # The name of the rabbit certificate authority.
14
 
    CA_NAME = 'rabbit-server-ca'
15
 
 
16
 
    # Put the certificate authority in a temporary location since
17
 
    # it is rebuilt for each amulet run.
18
 
    CA_PATH = '/tmp/rabbit-server-ca'
19
 
 
20
 
    # The common name for the certificate itself.
21
 
    COMMON_NAME = 'rabbitmq-server'
22
 
 
23
 
    def __init__(self):
24
 
        self.ca = ServiceCA(self.CA_NAME, self.CA_PATH)
25
 
        self.ca.init()
26
 
        self.ca.get_or_create_cert(self.COMMON_NAME)
27
 
 
28
 
    def _load_file(self, path):
29
 
        contents = None
30
 
        with open(path) as f:
31
 
            contents = f.read()
32
 
        return contents
33
 
 
34
 
    def get_key(self):
35
 
        """
36
 
        Returns the contents of the rabbitmq private key.
37
 
        """
38
 
        key_path = os.path.join(self.CA_PATH, 'certs', 'rabbitmq-server.key')
39
 
        return self._load_file(key_path)
40
 
 
41
 
    def get_cert(self):
42
 
        """
43
 
        Returns the contents of the rabbitmq certificate.
44
 
        """
45
 
        cert_path = os.path.join(self.CA_PATH, 'certs', 'rabbitmq-server.crt')
46
 
        return self._load_file(cert_path)
47
 
 
48
 
    def ca_cert_path(self):
49
 
        """
50
 
        Returns the certificate authority certificate path.
51
 
        """
52
 
        return os.path.join(self.CA_PATH, 'cacert.pem')