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

« back to all changes in this revision

Viewing changes to tests/deploy_common.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:
 
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')