~landscape/charms/trusty/nova-charm-controller/trunk

« back to all changes in this revision

Viewing changes to unit_tests/test_nova_cc_hooks.py

  • Committer: Billy Olsen
  • Date: 2015-06-18 23:42:48 UTC
  • mfrom: (163.2.2 nova-cloud-controller)
  • Revision ID: billy.olsen@canonical.com-20150618234248-lqou5e1ra057bp2s
[billy-olsen,r=corey.bryant] Add support for overriding public endpoint addresses.

Adds in the config option for overriding public endpoint addresses
and introduces a unit tests to ensure that the override for the
public address is functioning correctly.

Backported from /next
Closes-Bug: #1398182

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
    'api_port',
26
26
    'apt_update',
27
27
    'apt_install',
28
 
    'canonical_url',
29
28
    'configure_installation_source',
30
29
    'charm_dir',
31
30
    'do_openstack_upgrade',
32
31
    'openstack_upgrade_available',
33
32
    'cmd_all_services',
34
33
    'config',
 
34
    'determine_endpoints',
35
35
    'determine_packages',
36
36
    'determine_ports',
37
37
    'disable_services',
115
115
        mock_filter_packages.assert_called_with([])
116
116
 
117
117
    @patch.object(hooks, 'filter_installed_packages')
 
118
    @patch('charmhelpers.contrib.openstack.ip.service_name',
 
119
           lambda *args: 'nova-cloud-controller')
118
120
    @patch.object(hooks, 'cluster_joined')
119
121
    @patch.object(hooks, 'identity_joined')
120
122
    @patch.object(hooks, 'neutron_api_relation_joined')
193
195
        self.assertEquals(sorted(self.relation_set.call_args_list),
194
196
                          sorted(expected_relations))
195
197
 
 
198
    @patch.object(hooks, 'canonical_url')
196
199
    @patch.object(utils, 'config')
197
200
    @patch.object(hooks, '_auth_config')
198
 
    def test_compute_joined_neutron(self, auth_config, _util_config):
 
201
    def test_compute_joined_neutron(self, auth_config, _util_config,
 
202
                                    _canonical_url):
199
203
        _util_config.return_value = None
200
204
        self.is_relation_made.return_value = False
201
205
        self.network_manager.return_value = 'neutron'
203
207
        self.keystone_ca_cert_b64.return_value = 'foocert64'
204
208
        self.volume_service.return_value = 'cinder'
205
209
        self.unit_get.return_value = 'nova-cc-host1'
206
 
        self.canonical_url.return_value = 'http://nova-cc-host1'
 
210
        _canonical_url.return_value = 'http://nova-cc-host1'
207
211
        self.api_port.return_value = '9696'
208
212
        self.neutron_plugin.return_value = 'nvp'
209
213
        auth_config.return_value = FAKE_KS_AUTH_CFG
222
226
            quantum_plugin='nvp',
223
227
            network_manager='neutron', **FAKE_KS_AUTH_CFG)
224
228
 
 
229
    @patch.object(hooks, 'canonical_url')
225
230
    @patch.object(utils, 'config')
226
231
    @patch.object(hooks, 'NeutronAPIContext')
227
232
    @patch.object(hooks, '_auth_config')
228
233
    def test_compute_joined_neutron_api_rel(self, auth_config, napi,
229
 
                                            _util_config):
 
234
                                            _util_config, _canonical_url):
230
235
        def mock_NeutronAPIContext():
231
236
            return {
232
237
                'neutron_plugin': 'bob',
241
246
        self.keystone_ca_cert_b64.return_value = 'foocert64'
242
247
        self.volume_service.return_value = 'cinder'
243
248
        self.unit_get.return_value = 'nova-cc-host1'
244
 
        self.canonical_url.return_value = 'http://nova-cc-host1'
 
249
        _canonical_url.return_value = 'http://nova-cc-host1'
245
250
        self.api_port.return_value = '9696'
246
251
        self.neutron_plugin.return_value = 'nvp'
247
252
        auth_config.return_value = FAKE_KS_AUTH_CFG
259
264
            quantum_plugin='bob',
260
265
            network_manager='neutron', **FAKE_KS_AUTH_CFG)
261
266
 
 
267
    @patch.object(hooks, 'canonical_url')
262
268
    @patch.object(hooks, '_auth_config')
263
 
    def test_nova_vmware_joined(self, auth_config):
 
269
    def test_nova_vmware_joined(self, auth_config, _canonical_url):
264
270
        auth_config.return_value = FAKE_KS_AUTH_CFG
265
271
        # quantum-security-groups, plugin
266
272
        self.neutron_plugin.return_value = 'nvp'
267
273
        self.network_manager.return_value = 'neutron'
268
 
        self.canonical_url.return_value = 'http://nova-cc-host1'
 
274
        _canonical_url.return_value = 'http://nova-cc-host1'
269
275
        self.api_port.return_value = '9696'
270
276
        hooks.nova_vmware_relation_joined()
271
277
        self.relation_set.assert_called_with(
283
289
                                             nova_hostname='nova.foohost.com')
284
290
        self.unit_get.assert_called_with('private-address')
285
291
 
 
292
    @patch('charmhelpers.contrib.openstack.ip.service_name',
 
293
           lambda *args: 'nova-cloud-controller')
 
294
    @patch('charmhelpers.contrib.openstack.ip.unit_get')
 
295
    @patch('charmhelpers.contrib.openstack.ip.is_clustered')
 
296
    @patch('charmhelpers.contrib.openstack.ip.config')
 
297
    def test_identity_joined(self, _ip_config, _is_clustered, _unit_get):
 
298
        _is_clustered.return_value = False
 
299
        _unit_get.return_value = '127.0.0.1'
 
300
        _ip_config.side_effect = self.test_config.get
 
301
 
 
302
        self.test_config.set('os-public-hostname', 'ncc.example.com')
 
303
        hooks.identity_joined()
 
304
 
 
305
        self.determine_endpoints.asssert_called_with(
 
306
            public_url='http://ncc.example.com',
 
307
            internal_url='http://127.0.0.1',
 
308
            admin_url='http://127.0.0.1'
 
309
        )
 
310
 
286
311
    def test_postgresql_nova_db_joined(self):
287
312
        self.is_relation_made.return_value = False
288
313
        hooks.pgsql_nova_db_joined()
447
472
                           call('/etc/neutron/neutron.conf')])
448
473
        cell_joined.assert_called_with(rid='nova-cell-api/0')
449
474
 
450
 
    def test_nova_cell_relation_joined(self):
 
475
    @patch.object(hooks, 'canonical_url')
 
476
    def test_nova_cell_relation_joined(self, _canonical_url):
451
477
        self.uuid.uuid4.return_value = 'bob'
452
 
        self.canonical_url.return_value = 'http://novaurl'
 
478
        _canonical_url.return_value = 'http://novaurl'
453
479
        hooks.nova_cell_relation_joined(rid='rid',
454
480
                                        remote_restart=True)
455
481
        self.relation_set.assert_called_with(restart_trigger='bob',
468
494
        }
469
495
        self.assertEquals(hooks.get_cell_type(), 'parent')
470
496
 
 
497
    @patch.object(hooks, 'canonical_url')
471
498
    @patch.object(os, 'rename')
472
499
    @patch.object(os.path, 'isfile')
473
500
    @patch.object(hooks, 'CONFIGS')
474
501
    @patch.object(hooks, 'get_cell_type')
475
502
    def test_neutron_api_relation_joined(self, get_cell_type, configs, isfile,
476
 
                                         rename):
 
503
                                         rename, _canonical_url):
477
504
        neutron_conf = '/etc/neutron/neutron.conf'
478
505
        nova_url = 'http://novaurl:8774/v2'
479
506
        isfile.return_value = True
480
507
        self.service_running.return_value = True
481
508
        _identity_joined = self.patch('identity_joined')
482
509
        self.relation_ids.return_value = ['relid']
483
 
        self.canonical_url.return_value = 'http://novaurl'
 
510
        _canonical_url.return_value = 'http://novaurl'
484
511
        get_cell_type.return_value = 'parent'
485
512
        self.uuid.uuid4.return_value = 'bob'
486
513
        with patch_open() as (_open, _file):
517
544
        self.assertTrue(_compute_joined.called)
518
545
        self.assertTrue(_quantum_joined.called)
519
546
 
 
547
    @patch.object(hooks, 'canonical_url')
520
548
    @patch.object(utils, 'config')
521
 
    def test_console_settings_vnc(self, _utils_config):
 
549
    def test_console_settings_vnc(self, _utils_config, _canonical_url):
522
550
        _utils_config.return_value = 'vnc'
523
551
        _cc_host = "nova-cc-host1"
524
 
        self.canonical_url.return_value = 'http://' + _cc_host
 
552
        _canonical_url.return_value = 'http://' + _cc_host
525
553
        _con_sets = hooks.console_settings()
526
554
        console_settings = {
527
555
            'console_proxy_novnc_address': 'http://%s:6080/vnc_auto.html' %
537
565
        }
538
566
        self.assertEqual(_con_sets, console_settings)
539
567
 
 
568
    @patch.object(hooks, 'canonical_url')
540
569
    @patch.object(utils, 'config')
541
 
    def test_console_settings_xvpvnc(self, _utils_config):
 
570
    def test_console_settings_xvpvnc(self, _utils_config, _canonical_url):
542
571
        _utils_config.return_value = 'xvpvnc'
543
572
        _cc_host = "nova-cc-host1"
544
 
        self.canonical_url.return_value = 'http://' + _cc_host
 
573
        _canonical_url.return_value = 'http://' + _cc_host
545
574
        _con_sets = hooks.console_settings()
546
575
        console_settings = {
547
576
            'console_access_protocol': 'xvpvnc',
553
582
        }
554
583
        self.assertEqual(_con_sets, console_settings)
555
584
 
 
585
    @patch.object(hooks, 'canonical_url')
556
586
    @patch.object(utils, 'config')
557
 
    def test_console_settings_novnc(self, _utils_config):
 
587
    def test_console_settings_novnc(self, _utils_config, _canonical_url):
558
588
        _utils_config.return_value = 'novnc'
559
589
        _cc_host = "nova-cc-host1"
560
 
        self.canonical_url.return_value = 'http://' + _cc_host
 
590
        _canonical_url.return_value = 'http://' + _cc_host
561
591
        _con_sets = hooks.console_settings()
562
592
        console_settings = {
563
593
            'console_proxy_novnc_address': 'http://%s:6080/vnc_auto.html' %
569
599
        }
570
600
        self.assertEqual(_con_sets, console_settings)
571
601
 
 
602
    @patch.object(hooks, 'canonical_url')
572
603
    @patch.object(utils, 'config')
573
 
    def test_console_settings_spice(self, _utils_config):
 
604
    def test_console_settings_spice(self, _utils_config, _canonical_url):
574
605
        _utils_config.return_value = 'spice'
575
606
        _cc_host = "nova-cc-host1"
576
 
        self.canonical_url.return_value = 'http://' + _cc_host
 
607
        _canonical_url.return_value = 'http://' + _cc_host
577
608
        _con_sets = hooks.console_settings()
578
609
        console_settings = {
579
610
            'console_proxy_spice_address': 'http://%s:6082/spice_auto.html' %
585
616
        }
586
617
        self.assertEqual(_con_sets, console_settings)
587
618
 
 
619
    @patch.object(hooks, 'canonical_url')
588
620
    @patch.object(utils, 'config')
589
 
    def test_console_settings_explicit_ip(self, _utils_config):
 
621
    def test_console_settings_explicit_ip(self, _utils_config,
 
622
                                          _canonical_url):
590
623
        _utils_config.return_value = 'spice'
591
624
        _cc_public_host = "public-host"
592
625
        _cc_private_host = "private-host"
593
626
        self.test_config.set('console-proxy-ip', _cc_public_host)
594
627
        _con_sets = hooks.console_settings()
595
 
        self.canonical_url.return_value = 'http://' + _cc_private_host
 
628
        _canonical_url.return_value = 'http://' + _cc_private_host
596
629
        console_settings = {
597
630
            'console_proxy_spice_address': 'http://%s:6082/spice_auto.html' %
598
631
                                           (_cc_public_host),