~dpb/charms/trusty/haproxy/merge-services-fix

« back to all changes in this revision

Viewing changes to hooks/tests/test_reverseproxy_hooks.py

  • Committer: Christopher Glass
  • Date: 2015-04-14 16:50:37 UTC
  • mfrom: (89.1.7 advertise-public-ip)
  • Revision ID: christopher.glass@canonical.com-20150414165037-j88nmjsv8y51vtwk
Merge lp:~free.ekanayaka/charms/trusty/haproxy/advertise-public-ip [a=free.ekanayaka] [r=tribaal]

Add a reverseproxy-relation-joined hook that will expose the unit's public IP and public SSL certificate, in case related services need it.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import base64
1
2
import yaml
2
3
 
3
4
from testtools import TestCase
487
488
 
488
489
        expected = {'service_name': 'left', 'foo': 'bar', 'bar': 'baz'}
489
490
        self.assertEqual(expected, hooks.merge_service(s1, s2))
 
491
 
 
492
    def test_join_reverseproxy_relation(self):
 
493
        """
 
494
        When haproxy joins a reverseproxy relation it advertises its public
 
495
        IP and public certificate by setting values on the relation.
 
496
        """
 
497
        ssl_cert = base64.b64encode("<cert data>")
 
498
        self.config_get.return_value = {"ssl_cert": ssl_cert}
 
499
        unit_get = self.patch_hook("unit_get")
 
500
        unit_get.return_value = "1.2.3.4"
 
501
        relation_id = self.patch_hook("relation_id")
 
502
        relation_id.return_value = "reverseproxy:1"
 
503
        relation_set = self.patch_hook("relation_set")
 
504
        hooks.reverseproxy_interface(hook_name="joined")
 
505
        unit_get.assert_called_once_with("public-address")
 
506
        relation_set.assert_called_once_with(
 
507
            relation_id="reverseproxy:1",
 
508
            relation_settings={
 
509
                "public-address": "1.2.3.4",
 
510
                "ssl_cert": ssl_cert})
 
511
 
 
512
    def test_join_reverseproxy_relation_with_selfsigned_cert(self):
 
513
        """
 
514
        When haproxy joins a reverseproxy relation and a self-signed
 
515
        certificate is configured, then it's included in the relation.
 
516
        """
 
517
        self.config_get.return_value = {"ssl_cert": "SELFSIGNED"}
 
518
        unit_get = self.patch_hook("unit_get")
 
519
        unit_get.return_value = "1.2.3.4"
 
520
        relation_id = self.patch_hook("relation_id")
 
521
        relation_id.return_value = "reverseproxy:1"
 
522
        get_selfsigned_cert = self.patch_hook("get_selfsigned_cert")
 
523
        get_selfsigned_cert.return_value = ("<self-signed>", None)
 
524
        relation_set = self.patch_hook("relation_set")
 
525
        hooks.reverseproxy_interface(hook_name="joined")
 
526
        unit_get.assert_called_once_with("public-address")
 
527
        ssl_cert = base64.b64encode("<self-signed>")
 
528
        relation_set.assert_called_once_with(
 
529
            relation_id="reverseproxy:1",
 
530
            relation_settings={
 
531
                "public-address": "1.2.3.4",
 
532
                "ssl_cert": ssl_cert})