~hopem/charms/trusty/nova-cloud-controller/lp1499435

« back to all changes in this revision

Viewing changes to unit_tests/test_nova_cc_hooks.py

[freyes,r=wolsen,hopem] Add option for a single nova-consoleauth instance.

Introduces a new configuration option for ensuring that only a single nova-consoleauth
daemon is running within the nova-cloud-controller cluster. This allows a deployment
which does not pair with a shared key/value store for auth tokens (e.g. memcached) to
serve consistent authtokens for console access.

Closes-Bug: #1418597

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
from mock import MagicMock, patch, call
2
2
from test_utils import CharmTestCase, patch_open
3
3
import os
 
4
import tempfile
4
5
 
5
6
with patch('charmhelpers.core.hookenv.config') as config:
6
7
    config.return_value = 'neutron'
90
91
 
91
92
    def setUp(self):
92
93
        super(NovaCCHooksTests, self).setUp(hooks, TO_PATCH)
 
94
        (tmpfd, hooks.NOVA_CONSOLEAUTH_OVERRIDE) = tempfile.mkstemp()
93
95
 
94
96
        self.config.side_effect = self.test_config.get
95
97
        self.relation_get.side_effect = self.test_relation.get
96
98
        self.charm_dir.return_value = '/var/lib/juju/charms/nova/charm'
97
99
 
 
100
    def tearDown(self):
 
101
        try:
 
102
            os.remove(hooks.NOVA_CONSOLEAUTH_OVERRIDE)
 
103
        except OSError:
 
104
            pass
 
105
 
 
106
        super(NovaCCHooksTests, self).tearDown()
 
107
 
98
108
    def test_install_hook(self):
99
109
        self.determine_packages.return_value = [
100
110
            'nova-scheduler', 'nova-api-ec2']
622
632
            'neutron-api charm.'
623
633
        )
624
634
 
625
 
    def test_ha_relation_joined_no_bound_ip(self):
626
 
        self.get_hacluster_config.return_value = {
627
 
            'ha-bindiface': 'em0',
628
 
            'ha-mcastport': '8080',
629
 
            'vip': '10.10.10.10',
630
 
        }
631
 
        self.test_config.set('vip_iface', 'eth120')
632
 
        self.test_config.set('vip_cidr', '21')
633
 
        self.get_iface_for_address.return_value = None
634
 
        self.get_netmask_for_address.return_value = None
635
 
        hooks.ha_joined()
636
 
        args = {
637
 
            'corosync_bindiface': 'em0',
638
 
            'corosync_mcastport': '8080',
639
 
            'init_services': {'res_nova_haproxy': 'haproxy'},
640
 
            'resources': {'res_nova_eth120_vip': 'ocf:heartbeat:IPaddr2',
641
 
                          'res_nova_haproxy': 'lsb:haproxy'},
642
 
            'resource_params': {
643
 
                'res_nova_eth120_vip': 'params ip="10.10.10.10"'
644
 
                ' cidr_netmask="21" nic="eth120"',
645
 
                'res_nova_haproxy': 'op monitor interval="5s"'},
646
 
            'clones': {'cl_nova_haproxy': 'res_nova_haproxy'}
647
 
        }
648
 
        self.relation_set.assert_has_calls([
649
 
            call(groups={'grp_nova_vips': 'res_nova_eth120_vip'}),
650
 
            call(**args),
 
635
    @patch('nova_cc_utils.config')
 
636
    def test_ha_relation_joined_no_bound_ip(self, config):
 
637
        self.get_hacluster_config.return_value = {
 
638
            'ha-bindiface': 'em0',
 
639
            'ha-mcastport': '8080',
 
640
            'vip': '10.10.10.10',
 
641
        }
 
642
        self.test_config.set('vip_iface', 'eth120')
 
643
        self.test_config.set('vip_cidr', '21')
 
644
        config.return_value = None
 
645
        self.get_iface_for_address.return_value = None
 
646
        self.get_netmask_for_address.return_value = None
 
647
        hooks.ha_joined()
 
648
        args = {
 
649
            'corosync_bindiface': 'em0',
 
650
            'corosync_mcastport': '8080',
 
651
            'init_services': {'res_nova_haproxy': 'haproxy'},
 
652
            'resources': {'res_nova_eth120_vip': 'ocf:heartbeat:IPaddr2',
 
653
                          'res_nova_haproxy': 'lsb:haproxy'},
 
654
            'resource_params': {
 
655
                'res_nova_eth120_vip': 'params ip="10.10.10.10"'
 
656
                ' cidr_netmask="21" nic="eth120"',
 
657
                'res_nova_haproxy': 'op monitor interval="5s"'},
 
658
            'colocations': {},
 
659
            'clones': {'cl_nova_haproxy': 'res_nova_haproxy'}
 
660
        }
 
661
        self.relation_set.assert_has_calls([
 
662
            call(groups={'grp_nova_vips': 'res_nova_eth120_vip'}),
 
663
            call(**args),
 
664
        ])
 
665
 
 
666
    @patch('nova_cc_utils.config')
 
667
    def test_ha_relation_multi_consoleauth(self, config):
 
668
        self.get_hacluster_config.return_value = {
 
669
            'ha-bindiface': 'em0',
 
670
            'ha-mcastport': '8080',
 
671
            'vip': '10.10.10.10',
 
672
        }
 
673
        self.test_config.set('vip_iface', 'eth120')
 
674
        self.test_config.set('vip_cidr', '21')
 
675
        self.test_config.set('single-nova-consoleauth', False)
 
676
        config.return_value = 'novnc'
 
677
        self.get_iface_for_address.return_value = None
 
678
        self.get_netmask_for_address.return_value = None
 
679
        hooks.ha_joined()
 
680
        args = {
 
681
            'corosync_bindiface': 'em0',
 
682
            'corosync_mcastport': '8080',
 
683
            'init_services': {'res_nova_haproxy': 'haproxy'},
 
684
            'resources': {'res_nova_eth120_vip': 'ocf:heartbeat:IPaddr2',
 
685
                          'res_nova_haproxy': 'lsb:haproxy'},
 
686
            'resource_params': {
 
687
                'res_nova_eth120_vip': 'params ip="10.10.10.10"'
 
688
                ' cidr_netmask="21" nic="eth120"',
 
689
                'res_nova_haproxy': 'op monitor interval="5s"'},
 
690
            'colocations': {},
 
691
            'clones': {'cl_nova_haproxy': 'res_nova_haproxy'}
 
692
        }
 
693
        self.relation_set.assert_has_calls([
 
694
            call(groups={'grp_nova_vips': 'res_nova_eth120_vip'}),
 
695
            call(**args),
 
696
        ])
 
697
 
 
698
    @patch('nova_cc_utils.config')
 
699
    def test_ha_relation_single_consoleauth(self, config):
 
700
        self.get_hacluster_config.return_value = {
 
701
            'ha-bindiface': 'em0',
 
702
            'ha-mcastport': '8080',
 
703
            'vip': '10.10.10.10',
 
704
        }
 
705
        self.test_config.set('vip_iface', 'eth120')
 
706
        self.test_config.set('vip_cidr', '21')
 
707
        config.return_value = 'novnc'
 
708
        self.get_iface_for_address.return_value = None
 
709
        self.get_netmask_for_address.return_value = None
 
710
        hooks.ha_joined()
 
711
        args = {
 
712
            'corosync_bindiface': 'em0',
 
713
            'corosync_mcastport': '8080',
 
714
            'init_services': {'res_nova_haproxy': 'haproxy',
 
715
                              'res_nova_consoleauth': 'nova-consoleauth'},
 
716
            'resources': {'res_nova_eth120_vip': 'ocf:heartbeat:IPaddr2',
 
717
                          'res_nova_haproxy': 'lsb:haproxy',
 
718
                          'res_nova_consoleauth':
 
719
                          'ocf:openstack:nova-consoleauth'},
 
720
            'resource_params': {
 
721
                'res_nova_eth120_vip': 'params ip="10.10.10.10"'
 
722
                ' cidr_netmask="21" nic="eth120"',
 
723
                'res_nova_haproxy': 'op monitor interval="5s"',
 
724
                'res_nova_consoleauth': 'op monitor interval="5s"'},
 
725
            'colocations': {
 
726
                'vip_consoleauth': 'inf: res_nova_consoleauth grp_nova_vips'
 
727
            },
 
728
            'clones': {'cl_nova_haproxy': 'res_nova_haproxy'}
 
729
        }
 
730
        self.relation_set.assert_has_calls([
 
731
            call(groups={'grp_nova_vips': 'res_nova_eth120_vip'}),
 
732
            call(**args),
 
733
        ])
 
734
 
 
735
    @patch('nova_cc_hooks.configure_https')
 
736
    @patch('nova_cc_utils.config')
 
737
    def test_config_changed_single_consoleauth(self, config, *args):
 
738
        config.return_value = 'novnc'
 
739
        rids = {'ha': ['ha:1']}
 
740
 
 
741
        def f(r):
 
742
            return rids.get(r, [])
 
743
 
 
744
        self.relation_ids.side_effect = f
 
745
        hooks.config_changed()
 
746
        args = {
 
747
            'delete_resources': [],
 
748
            'init_services': {'res_nova_consoleauth': 'nova-consoleauth'},
 
749
            'resources': {'res_nova_consoleauth':
 
750
                          'ocf:openstack:nova-consoleauth'},
 
751
            'resource_params': {
 
752
                'res_nova_consoleauth': 'op monitor interval="5s"'},
 
753
            'colocations': {
 
754
                'vip_consoleauth': 'inf: res_nova_consoleauth grp_nova_vips'
 
755
            }
 
756
        }
 
757
        self.relation_set.assert_has_calls([
 
758
            call(v, **args) for v in rids['ha']
651
759
        ])