~corey.bryant/charms/trusty/nova-cloud-controller/amulet-updates

« back to all changes in this revision

Viewing changes to unit_tests/test_nova_cc_hooks.py

  • Committer: james.page at ubuntu
  • Date: 2014-06-24 11:43:28 UTC
  • mfrom: (78.2.7 nova-cloud-controller)
  • Revision ID: james.page@ubuntu.com-20140624114328-6wgs55qr9qn0oldq
[gnuoy,r=james-page] Refactoring to support split-out of Neutron functionality.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
from mock import MagicMock, patch
2
 
from test_utils import CharmTestCase
3
 
 
 
2
from test_utils import CharmTestCase, patch_open
 
3
import os
4
4
with patch('charmhelpers.core.hookenv.config') as config:
5
5
    config.return_value = 'neutron'
6
6
    import nova_cc_utils as utils
38
38
    'ssh_known_hosts_b64',
39
39
    'ssh_authorized_keys_b64',
40
40
    'save_script_rc',
 
41
    'service_running',
 
42
    'service_stop',
41
43
    'execd_preinstall',
42
44
    'network_manager',
43
45
    'volume_service',
107
109
 
108
110
    @patch.object(hooks, '_auth_config')
109
111
    def test_compute_joined_neutron(self, auth_config):
 
112
        self.is_relation_made.return_value = False
110
113
        self.network_manager.return_value = 'neutron'
111
114
        self.eligible_leader = True
112
115
        self.keystone_ca_cert_b64.return_value = 'foocert64'
122
125
            relation_id=None,
123
126
            quantum_url='http://nova-cc-host1:9696',
124
127
            ca_cert='foocert64',
 
128
            quantum_port=9696,
 
129
            quantum_host='nova-cc-host1',
125
130
            quantum_security_groups='no',
126
131
            region='RegionOne',
127
132
            volume_service='cinder',
129
134
            quantum_plugin='nvp',
130
135
            network_manager='neutron', **FAKE_KS_AUTH_CFG)
131
136
 
 
137
    @patch.object(hooks, 'NeutronAPIContext')
 
138
    @patch.object(hooks, '_auth_config')
 
139
    def test_compute_joined_neutron_api_rel(self, auth_config, napi):
 
140
        def mock_NeutronAPIContext():
 
141
            return {
 
142
                'neutron_plugin': 'bob',
 
143
                'neutron_security_groups': 'yes',
 
144
                'neutron_url': 'http://nova-cc-host1:9696',
 
145
            }
 
146
        napi.return_value = mock_NeutronAPIContext
 
147
        self.is_relation_made.return_value = True
 
148
        self.network_manager.return_value = 'neutron'
 
149
        self.eligible_leader = True
 
150
        self.keystone_ca_cert_b64.return_value = 'foocert64'
 
151
        self.volume_service.return_value = 'cinder'
 
152
        self.unit_get.return_value = 'nova-cc-host1'
 
153
        self.canonical_url.return_value = 'http://nova-cc-host1'
 
154
        self.api_port.return_value = '9696'
 
155
        self.neutron_plugin.return_value = 'nvp'
 
156
        auth_config.return_value = FAKE_KS_AUTH_CFG
 
157
        hooks.compute_joined()
 
158
        self.relation_set.assert_called_with(
 
159
            relation_id=None,
 
160
            quantum_url='http://nova-cc-host1:9696',
 
161
            ca_cert='foocert64',
 
162
            quantum_port=9696,
 
163
            quantum_host='nova-cc-host1',
 
164
            quantum_security_groups='yes',
 
165
            region='RegionOne',
 
166
            volume_service='cinder',
 
167
            ec2_host='nova-cc-host1',
 
168
            quantum_plugin='bob',
 
169
            network_manager='neutron', **FAKE_KS_AUTH_CFG)
 
170
 
132
171
    @patch.object(hooks, '_auth_config')
133
172
    def test_nova_vmware_joined(self, auth_config):
134
173
        auth_config.return_value = FAKE_KS_AUTH_CFG
231
270
        self._postgresql_db_test(configs)
232
271
        self.assertTrue(configs.write_all.called)
233
272
        self.migrate_database.assert_called_with()
 
273
 
 
274
    @patch.object(os, 'rename')
 
275
    @patch.object(os.path, 'isfile')
 
276
    @patch.object(hooks, 'CONFIGS')
 
277
    def test_neutron_api_relation_joined(self, configs, isfile, rename):
 
278
        neutron_conf = '/etc/neutron/neutron.conf'
 
279
        nova_url = 'http://novaurl:8774/v2'
 
280
        isfile.return_value = True
 
281
        self.service_running.return_value = True
 
282
        _identity_joined = self.patch('identity_joined')
 
283
        self.relation_ids.side_effect = ['relid']
 
284
        self.canonical_url.return_value = 'http://novaurl'
 
285
        with patch_open() as (_open, _file):
 
286
            hooks.neutron_api_relation_joined()
 
287
            self.service_stop.assert_called_with('neutron-server')
 
288
            rename.assert_called_with(neutron_conf, neutron_conf + '_unused')
 
289
            self.assertTrue(_identity_joined.called)
 
290
            self.relation_set.assert_called_with(relation_id=None,
 
291
                                                 nova_url=nova_url)
 
292
 
 
293
    @patch.object(hooks, 'CONFIGS')
 
294
    def test_neutron_api_relation_changed(self, configs):
 
295
        self.relation_ids.return_value = ['relid']
 
296
        _compute_joined = self.patch('compute_joined')
 
297
        _quantum_joined = self.patch('quantum_joined')
 
298
        hooks.neutron_api_relation_changed()
 
299
        self.assertTrue(configs.write.called_with('/etc/nova/nova.conf'))
 
300
        self.assertTrue(_compute_joined.called)
 
301
        self.assertTrue(_quantum_joined.called)
 
302
 
 
303
    @patch.object(os, 'remove')
 
304
    @patch.object(os.path, 'isfile')
 
305
    @patch.object(hooks, 'CONFIGS')
 
306
    def test_neutron_api_relation_broken(self, configs, isfile, remove):
 
307
        isfile.return_value = True
 
308
        self.relation_ids.return_value = ['relid']
 
309
        _compute_joined = self.patch('compute_joined')
 
310
        _quantum_joined = self.patch('quantum_joined')
 
311
        hooks.neutron_api_relation_broken()
 
312
        remove.assert_called_with('/etc/init/neutron-server.override')
 
313
        self.assertTrue(configs.write_all.called)
 
314
        self.assertTrue(_compute_joined.called)
 
315
        self.assertTrue(_quantum_joined.called)