Exemple #1
0
def get_cert_data(barbican_client, listener):
    cert_data = Certificate()
    cert_ref = listener.tls_certificate_id
    cert_container = barbican_client.containers.get(container_ref=cert_ref)
    cert_data = Certificate(cert_filename=cert_container.certificate.name,
                            key_filename=cert_container.private_key.name,
                            cert_content=cert_container.certificate.payload,
                            key_content=cert_container.private_key.payload,
                            key_pass=cert_container.private_key_passphrase,
                            template_name=listener.id)
    return cert_data
Exemple #2
0
def get_cert_data(barbican_client, listener):
    cert_data = Certificate()
    cert_ref = listener.tls_certificate_id
    try:
        cert_container = barbican_client.containers.get(container_ref=cert_ref)
        cert_data = Certificate(cert_filename=cert_container.certificate.name,
                                key_filename=cert_container.private_key.name,
                                cert_content=cert_container.certificate.payload,
                                key_content=cert_container.private_key.payload,
                                key_pass=cert_container.private_key_passphrase,
                                template_name=listener.id)
    except Exception as e:
        LOG.exception("Failed to fetch cert containers: %s", str(e))
        raise
    return cert_data
from a10_octavia.common.data_models import VThunder
from a10_octavia.controller.worker.tasks import cert_tasks
from a10_octavia.tests.common import a10constants as a10_test_constants
from a10_octavia.tests.unit.base import BaseTaskTestCase

LB = o_data_models.LoadBalancer(id=a10_test_constants.MOCK_LOAD_BALANCER_ID,
                                project_id=t_constants.MOCK_PROJECT_ID)
LISTENER = o_data_models.Listener(protocol='TERMINATED_HTTPS',
                                  protocol_port=2222,
                                  load_balancer=LB,
                                  tls_certificate_id='certificate-id-1')
VTHUNDER = VThunder()

CERT_DATA = Certificate(cert_filename=a10_test_constants.MOCK_CERT_FILENAME,
                        cert_content=a10_test_constants.MOCK_CERT_CONTENT,
                        key_filename=a10_test_constants.MOCK_KEY_FILENAME,
                        key_content=a10_test_constants.MOCK_KEY_CONTENT,
                        template_name=a10_test_constants.MOCK_TEMPLATE_NAME,
                        key_pass=a10_test_constants.MOCK_KEY_PASS)


class TestCertHandlerTasks(BaseTaskTestCase):
    def setUp(self):
        super(TestCertHandlerTasks, self).setUp()
        imp.reload(cert_tasks)
        self.listener = copy.deepcopy(LISTENER)
        self.client_mock = mock.Mock()

    # SSL Cert
    @patch.object(BarbicanACLAuth, 'get_barbican_client')
    @mock.patch('a10_octavia.controller.worker.tasks.utils.get_cert_data',
                return_value=CERT_DATA)