2016-07-01 17:39:46 +01:00
|
|
|
# Copyright 2016 Canonical Ltd
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
|
2014-06-19 16:54:21 +01:00
|
|
|
import os
|
2015-05-22 11:32:59 -03:00
|
|
|
import tempfile
|
2014-11-20 12:07:29 -03:00
|
|
|
|
2016-03-22 21:00:42 +00:00
|
|
|
import yaml
|
|
|
|
|
|
|
|
from mock import MagicMock, patch, call
|
2016-04-08 10:42:07 +01:00
|
|
|
from test_utils import CharmTestCase
|
2016-03-22 21:00:42 +00:00
|
|
|
|
2014-03-27 12:46:44 +01:00
|
|
|
with patch('charmhelpers.core.hookenv.config') as config:
|
2016-08-10 13:51:25 +00:00
|
|
|
with patch('charmhelpers.contrib.openstack.utils.get_os_codename_package'):
|
|
|
|
config.return_value = 'neutron'
|
|
|
|
import nova_cc_utils as utils
|
2013-08-01 20:42:16 -07:00
|
|
|
|
|
|
|
_reg = utils.register_configs
|
|
|
|
_map = utils.restart_map
|
|
|
|
|
|
|
|
utils.register_configs = MagicMock()
|
|
|
|
utils.restart_map = MagicMock()
|
|
|
|
|
2016-03-22 21:00:42 +00:00
|
|
|
with patch('charmhelpers.contrib.hardening.harden.harden') as mock_dec:
|
|
|
|
mock_dec.side_effect = (lambda *dargs, **dkwargs: lambda f:
|
|
|
|
lambda *args, **kwargs: f(*args, **kwargs))
|
|
|
|
with patch('nova_cc_utils.guard_map') as gmap:
|
|
|
|
with patch('charmhelpers.core.hookenv.config') as config:
|
|
|
|
config.return_value = False
|
|
|
|
gmap.return_value = {}
|
|
|
|
import nova_cc_hooks as hooks
|
2013-08-01 20:42:16 -07:00
|
|
|
|
|
|
|
utils.register_configs = _reg
|
|
|
|
utils.restart_map = _map
|
|
|
|
|
|
|
|
TO_PATCH = [
|
|
|
|
'apt_update',
|
|
|
|
'apt_install',
|
|
|
|
'configure_installation_source',
|
2013-08-16 17:36:55 -07:00
|
|
|
'charm_dir',
|
2013-08-01 20:42:16 -07:00
|
|
|
'do_openstack_upgrade',
|
|
|
|
'openstack_upgrade_available',
|
2014-08-12 12:56:20 +00:00
|
|
|
'cmd_all_services',
|
2013-08-01 20:42:16 -07:00
|
|
|
'config',
|
2016-02-12 10:38:21 -07:00
|
|
|
'config_value_changed',
|
2015-06-02 17:06:30 -07:00
|
|
|
'determine_endpoints',
|
2013-08-01 20:42:16 -07:00
|
|
|
'determine_packages',
|
|
|
|
'determine_ports',
|
2014-08-12 12:56:20 +00:00
|
|
|
'disable_services',
|
|
|
|
'enable_services',
|
2014-09-29 12:37:55 +00:00
|
|
|
'NovaCellContext',
|
2013-08-01 20:42:16 -07:00
|
|
|
'open_port',
|
2014-03-27 12:46:44 +01:00
|
|
|
'is_relation_made',
|
2014-08-28 08:55:09 +01:00
|
|
|
'local_unit',
|
2014-03-27 12:46:44 +01:00
|
|
|
'log',
|
2014-10-01 09:20:32 +01:00
|
|
|
'os_release',
|
2016-02-17 10:24:59 -07:00
|
|
|
'related_units',
|
2013-09-04 09:47:58 -07:00
|
|
|
'relation_get',
|
|
|
|
'relation_set',
|
2014-03-27 12:46:44 +01:00
|
|
|
'relation_ids',
|
2017-02-08 18:40:04 +00:00
|
|
|
'placement_api_enabled',
|
2013-09-04 09:47:58 -07:00
|
|
|
'ssh_compute_add',
|
2014-05-22 10:47:41 +02:00
|
|
|
'ssh_known_hosts_lines',
|
|
|
|
'ssh_authorized_keys_lines',
|
2013-08-01 20:42:16 -07:00
|
|
|
'save_script_rc',
|
2015-03-30 18:26:30 +01:00
|
|
|
'service_reload',
|
2014-09-29 14:58:29 +01:00
|
|
|
'services',
|
2013-10-29 19:28:46 -07:00
|
|
|
'execd_preinstall',
|
|
|
|
'network_manager',
|
|
|
|
'unit_get',
|
2014-09-29 12:37:55 +00:00
|
|
|
'uuid',
|
2017-02-14 02:50:05 +00:00
|
|
|
'is_leader',
|
2013-10-29 19:28:46 -07:00
|
|
|
'keystone_ca_cert_b64',
|
2017-02-14 02:50:05 +00:00
|
|
|
'migrate_nova_databases',
|
2014-09-29 14:58:29 +01:00
|
|
|
'uuid',
|
2014-11-12 09:40:22 +00:00
|
|
|
'get_hacluster_config',
|
|
|
|
'get_iface_for_address',
|
2015-01-13 14:44:54 +00:00
|
|
|
'get_netmask_for_address',
|
2015-01-12 14:23:34 +00:00
|
|
|
'update_nrpe_config',
|
2015-04-15 14:17:56 +00:00
|
|
|
'git_install',
|
|
|
|
'git_install_requested',
|
2015-10-07 09:32:28 +00:00
|
|
|
'status_set',
|
2016-06-14 15:16:28 -07:00
|
|
|
'update_dns_ha_resource_params',
|
2016-09-15 11:31:51 +01:00
|
|
|
'serial_console_settings',
|
2017-04-18 10:56:09 -07:00
|
|
|
'get_relation_ip',
|
2013-08-01 20:42:16 -07:00
|
|
|
]
|
|
|
|
|
|
|
|
|
2013-10-29 19:28:46 -07:00
|
|
|
FAKE_KS_AUTH_CFG = {
|
|
|
|
'auth_host': 'kshost',
|
|
|
|
'auth_port': '5000',
|
|
|
|
'service_port': 'token',
|
|
|
|
'service_username': 'admin_user',
|
|
|
|
'service_password': 'admin_passwd',
|
|
|
|
'service_tenant_name': 'admin_tenant',
|
|
|
|
'auth_uri': 'http://kshost:5000/v2',
|
|
|
|
# quantum-gateway interface deviates a bit.
|
|
|
|
'keystone_host': 'kshost',
|
|
|
|
'service_tenant': 'service_tenant',
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-08-01 20:42:16 -07:00
|
|
|
class NovaCCHooksTests(CharmTestCase):
|
2013-11-08 13:41:39 +08:00
|
|
|
|
2013-08-01 20:42:16 -07:00
|
|
|
def setUp(self):
|
|
|
|
super(NovaCCHooksTests, self).setUp(hooks, TO_PATCH)
|
2015-05-22 11:32:59 -03:00
|
|
|
(tmpfd, hooks.NOVA_CONSOLEAUTH_OVERRIDE) = tempfile.mkstemp()
|
2014-03-31 12:56:09 +01:00
|
|
|
|
2013-08-01 20:42:16 -07:00
|
|
|
self.config.side_effect = self.test_config.get
|
2013-09-04 09:47:58 -07:00
|
|
|
self.relation_get.side_effect = self.test_relation.get
|
2013-08-16 17:36:55 -07:00
|
|
|
self.charm_dir.return_value = '/var/lib/juju/charms/nova/charm'
|
2013-08-01 20:42:16 -07:00
|
|
|
|
2015-05-22 11:32:59 -03:00
|
|
|
def tearDown(self):
|
|
|
|
try:
|
|
|
|
os.remove(hooks.NOVA_CONSOLEAUTH_OVERRIDE)
|
|
|
|
except OSError:
|
|
|
|
pass
|
|
|
|
|
|
|
|
super(NovaCCHooksTests, self).tearDown()
|
|
|
|
|
2013-08-01 20:42:16 -07:00
|
|
|
def test_install_hook(self):
|
|
|
|
self.determine_packages.return_value = [
|
|
|
|
'nova-scheduler', 'nova-api-ec2']
|
|
|
|
self.determine_ports.return_value = [80, 81, 82]
|
|
|
|
hooks.install()
|
|
|
|
self.apt_install.assert_called_with(
|
|
|
|
['nova-scheduler', 'nova-api-ec2'], fatal=True)
|
2015-09-24 17:29:26 +01:00
|
|
|
self.assertTrue(self.execd_preinstall.called)
|
|
|
|
self.assertTrue(self.disable_services.called)
|
2014-08-12 14:46:24 +00:00
|
|
|
self.cmd_all_services.assert_called_with('stop')
|
2013-08-01 20:42:16 -07:00
|
|
|
|
2015-04-15 14:17:56 +00:00
|
|
|
def test_install_hook_git(self):
|
|
|
|
self.git_install_requested.return_value = True
|
|
|
|
self.determine_packages.return_value = ['foo', 'bar']
|
|
|
|
self.determine_ports.return_value = [80, 81, 82]
|
|
|
|
repo = 'cloud:trusty-juno'
|
|
|
|
openstack_origin_git = {
|
|
|
|
'repositories': [
|
|
|
|
{'name': 'requirements',
|
|
|
|
'repository': 'git://git.openstack.org/openstack/requirements', # noqa
|
|
|
|
'branch': 'stable/juno'},
|
|
|
|
{'name': 'nova',
|
|
|
|
'repository': 'git://git.openstack.org/openstack/nova',
|
|
|
|
'branch': 'stable/juno'}
|
|
|
|
],
|
|
|
|
'directory': '/mnt/openstack-git',
|
|
|
|
}
|
|
|
|
projects_yaml = yaml.dump(openstack_origin_git)
|
|
|
|
self.test_config.set('openstack-origin', repo)
|
|
|
|
self.test_config.set('openstack-origin-git', projects_yaml)
|
|
|
|
hooks.install()
|
|
|
|
self.git_install.assert_called_with(projects_yaml)
|
|
|
|
self.apt_install.assert_called_with(['foo', 'bar'], fatal=True)
|
2015-09-24 17:29:26 +01:00
|
|
|
self.assertTrue(self.execd_preinstall.called)
|
|
|
|
self.assertTrue(self.disable_services.called)
|
2015-04-15 14:17:56 +00:00
|
|
|
self.cmd_all_services.assert_called_with('stop')
|
|
|
|
|
2017-02-14 02:50:05 +00:00
|
|
|
@patch.object(hooks, 'is_db_initialised')
|
2016-09-15 11:31:51 +01:00
|
|
|
@patch.object(hooks, 'determine_packages')
|
2016-06-20 18:28:14 -04:00
|
|
|
@patch.object(utils, 'service_resume')
|
|
|
|
@patch.object(utils, 'config')
|
2015-06-12 14:03:50 +01:00
|
|
|
@patch.object(hooks, 'filter_installed_packages')
|
2013-08-01 20:42:16 -07:00
|
|
|
@patch.object(hooks, 'configure_https')
|
2016-06-20 18:28:14 -04:00
|
|
|
def test_config_changed_no_upgrade(self, conf_https, mock_filter_packages,
|
2016-09-15 11:31:51 +01:00
|
|
|
utils_config, mock_service_resume,
|
2017-02-14 02:50:05 +00:00
|
|
|
mock_determine_packages,
|
|
|
|
mock_is_db_initialised):
|
2016-09-15 11:31:51 +01:00
|
|
|
mock_determine_packages.return_value = []
|
2016-06-20 18:28:14 -04:00
|
|
|
utils_config.side_effect = self.test_config.get
|
|
|
|
self.test_config.set('console-access-protocol', 'dummy')
|
2015-04-15 14:17:56 +00:00
|
|
|
self.git_install_requested.return_value = False
|
2013-08-01 20:42:16 -07:00
|
|
|
self.openstack_upgrade_available.return_value = False
|
2017-02-14 02:50:05 +00:00
|
|
|
mock_is_db_initialised.return_value = False
|
2017-04-04 17:53:31 +01:00
|
|
|
self.os_release.return_value = 'diablo'
|
2013-08-01 20:42:16 -07:00
|
|
|
hooks.config_changed()
|
|
|
|
self.assertTrue(self.save_script_rc.called)
|
2015-06-12 14:03:50 +01:00
|
|
|
mock_filter_packages.assert_called_with([])
|
2013-08-01 20:42:16 -07:00
|
|
|
|
2017-02-14 02:50:05 +00:00
|
|
|
@patch.object(hooks, 'is_db_initialised')
|
2016-06-20 18:28:14 -04:00
|
|
|
@patch.object(utils, 'service_resume')
|
2015-04-15 14:17:56 +00:00
|
|
|
@patch.object(hooks, 'configure_https')
|
2017-02-14 02:50:05 +00:00
|
|
|
def test_config_changed_git(self, configure_https, mock_service_resume,
|
|
|
|
mock_is_db_initialised):
|
2015-04-15 14:17:56 +00:00
|
|
|
self.git_install_requested.return_value = True
|
|
|
|
repo = 'cloud:trusty-juno'
|
|
|
|
openstack_origin_git = {
|
|
|
|
'repositories': [
|
|
|
|
{'name': 'requirements',
|
|
|
|
'repository':
|
|
|
|
'git://git.openstack.org/openstack/requirements',
|
|
|
|
'branch': 'stable/juno'},
|
|
|
|
{'name': 'nova',
|
|
|
|
'repository': 'git://git.openstack.org/openstack/nova',
|
|
|
|
'branch': 'stable/juno'}
|
|
|
|
],
|
|
|
|
'directory': '/mnt/openstack-git',
|
|
|
|
}
|
|
|
|
projects_yaml = yaml.dump(openstack_origin_git)
|
|
|
|
self.test_config.set('openstack-origin', repo)
|
|
|
|
self.test_config.set('openstack-origin-git', projects_yaml)
|
2017-02-14 02:50:05 +00:00
|
|
|
mock_is_db_initialised.return_value = False
|
2017-04-04 17:53:31 +01:00
|
|
|
self.os_release.return_value = 'diablo'
|
2015-04-15 14:17:56 +00:00
|
|
|
hooks.config_changed()
|
|
|
|
self.git_install.assert_called_with(projects_yaml)
|
|
|
|
self.assertFalse(self.do_openstack_upgrade.called)
|
|
|
|
|
2017-02-14 02:50:05 +00:00
|
|
|
@patch.object(hooks, 'is_db_initialised')
|
2017-02-02 12:42:07 +00:00
|
|
|
@patch.object(hooks, 'quantum_joined')
|
2016-09-15 11:31:51 +01:00
|
|
|
@patch.object(hooks, 'determine_packages')
|
2016-06-20 18:28:14 -04:00
|
|
|
@patch.object(utils, 'service_resume')
|
|
|
|
@patch('charmhelpers.contrib.openstack.ip.unit_get')
|
|
|
|
@patch('charmhelpers.contrib.hahelpers.cluster.relation_ids')
|
|
|
|
@patch.object(utils, 'config')
|
2016-03-11 11:22:31 +00:00
|
|
|
@patch.object(hooks, 'db_joined')
|
2015-06-12 14:03:50 +01:00
|
|
|
@patch.object(hooks, 'filter_installed_packages')
|
2015-06-04 16:33:12 -07:00
|
|
|
@patch('charmhelpers.contrib.openstack.ip.service_name',
|
|
|
|
lambda *args: 'nova-cloud-controller')
|
2014-10-02 10:22:36 +01:00
|
|
|
@patch.object(hooks, 'cluster_joined')
|
2014-09-29 14:58:29 +01:00
|
|
|
@patch.object(hooks, 'identity_joined')
|
|
|
|
@patch.object(hooks, 'neutron_api_relation_joined')
|
2013-08-01 20:42:16 -07:00
|
|
|
@patch.object(hooks, 'configure_https')
|
2014-09-29 14:58:29 +01:00
|
|
|
def test_config_changed_with_upgrade(self, conf_https, neutron_api_joined,
|
2015-06-12 14:03:50 +01:00
|
|
|
identity_joined, cluster_joined,
|
2016-06-20 18:28:14 -04:00
|
|
|
mock_filter_packages, db_joined,
|
|
|
|
utils_config, mock_relids,
|
|
|
|
mock_unit_get,
|
2016-09-15 11:31:51 +01:00
|
|
|
mock_service_resume,
|
2017-02-02 12:42:07 +00:00
|
|
|
mock_determine_packages,
|
2017-02-14 02:50:05 +00:00
|
|
|
mock_quantum_joined,
|
|
|
|
mock_is_db_initialised):
|
2016-09-15 11:31:51 +01:00
|
|
|
mock_determine_packages.return_value = []
|
2017-02-14 02:50:05 +00:00
|
|
|
mock_is_db_initialised.return_value = False
|
2015-04-15 14:17:56 +00:00
|
|
|
self.git_install_requested.return_value = False
|
2013-08-01 20:42:16 -07:00
|
|
|
self.openstack_upgrade_available.return_value = True
|
2014-09-29 14:58:29 +01:00
|
|
|
self.relation_ids.return_value = ['generic_rid']
|
2014-10-20 14:13:04 +00:00
|
|
|
_zmq_joined = self.patch('zeromq_configuration_relation_joined')
|
2016-06-20 18:28:14 -04:00
|
|
|
utils_config.side_effect = self.test_config.get
|
|
|
|
self.test_config.set('console-access-protocol', 'dummy')
|
|
|
|
mock_relids.return_value = []
|
|
|
|
mock_unit_get.return_value = '127.0.0.1'
|
2017-04-04 17:53:31 +01:00
|
|
|
self.os_release.return_value = 'diablo'
|
2013-08-01 20:42:16 -07:00
|
|
|
hooks.config_changed()
|
|
|
|
self.assertTrue(self.do_openstack_upgrade.called)
|
2014-09-29 14:58:29 +01:00
|
|
|
self.assertTrue(neutron_api_joined.called)
|
|
|
|
self.assertTrue(identity_joined.called)
|
2014-10-20 14:13:04 +00:00
|
|
|
self.assertTrue(_zmq_joined.called)
|
2014-10-02 10:22:36 +01:00
|
|
|
self.assertTrue(cluster_joined.called)
|
2016-03-11 11:22:31 +00:00
|
|
|
self.assertTrue(db_joined.called)
|
2013-08-01 20:42:16 -07:00
|
|
|
self.assertTrue(self.save_script_rc.called)
|
2015-06-12 14:03:50 +01:00
|
|
|
mock_filter_packages.assert_called_with([])
|
2017-02-02 12:42:07 +00:00
|
|
|
self.assertTrue(mock_quantum_joined.called)
|
2013-09-04 09:47:58 -07:00
|
|
|
|
2017-02-14 02:50:05 +00:00
|
|
|
@patch.object(hooks, 'is_db_initialised')
|
2016-06-20 18:28:14 -04:00
|
|
|
@patch.object(utils, 'service_resume')
|
2016-02-12 10:38:21 -07:00
|
|
|
@patch.object(hooks, 'filter_installed_packages')
|
|
|
|
@patch.object(hooks, 'configure_https')
|
|
|
|
@patch.object(hooks, 'compute_changed')
|
|
|
|
def test_config_changed_region_change(self, mock_compute_changed,
|
|
|
|
mock_config_https,
|
2016-06-20 18:28:14 -04:00
|
|
|
mock_filter_packages,
|
2017-02-14 02:50:05 +00:00
|
|
|
mock_service_resume,
|
|
|
|
mock_is_db_initialised):
|
2016-02-12 10:38:21 -07:00
|
|
|
self.git_install_requested.return_value = False
|
|
|
|
self.openstack_upgrade_available.return_value = False
|
|
|
|
self.config_value_changed.return_value = True
|
2016-02-17 10:24:59 -07:00
|
|
|
self.related_units.return_value = ['unit/0']
|
2016-02-12 10:38:21 -07:00
|
|
|
self.relation_ids.side_effect = \
|
|
|
|
lambda x: ['generic_rid'] if x == 'cloud-compute' else []
|
2017-02-14 02:50:05 +00:00
|
|
|
mock_is_db_initialised.return_value = False
|
2017-04-04 17:53:31 +01:00
|
|
|
self.os_release.return_value = 'diablo'
|
2016-02-12 10:38:21 -07:00
|
|
|
hooks.config_changed()
|
2016-02-17 10:24:59 -07:00
|
|
|
mock_compute_changed.assert_has_calls([call('generic_rid', 'unit/0')])
|
2016-02-12 10:38:21 -07:00
|
|
|
|
2017-02-17 18:29:50 +00:00
|
|
|
@patch.object(hooks, 'is_db_initialised')
|
2016-02-03 11:38:43 -08:00
|
|
|
@patch.object(hooks, 'nova_api_relation_joined')
|
2017-02-17 18:29:50 +00:00
|
|
|
def test_compute_changed_nova_api_trigger(self, api_joined,
|
|
|
|
mock_is_db_initialised):
|
2016-02-03 11:38:43 -08:00
|
|
|
self.relation_ids.return_value = ['nova-api/0']
|
2017-02-17 18:29:50 +00:00
|
|
|
mock_is_db_initialised.return_value = False
|
2016-02-03 11:38:43 -08:00
|
|
|
hooks.compute_changed()
|
|
|
|
api_joined.assert_called_with(rid='nova-api/0')
|
|
|
|
|
2017-02-17 18:29:50 +00:00
|
|
|
@patch.object(hooks, 'is_db_initialised')
|
|
|
|
def test_compute_changed_ssh_migration(self, mock_is_db_initialised):
|
2013-09-04 09:47:58 -07:00
|
|
|
self.test_relation.set({
|
|
|
|
'migration_auth_type': 'ssh', 'ssh_public_key': 'fookey',
|
2016-02-12 10:38:21 -07:00
|
|
|
'private-address': '10.0.0.1', 'region': 'RegionOne'})
|
2014-05-22 10:47:41 +02:00
|
|
|
self.ssh_known_hosts_lines.return_value = [
|
|
|
|
'k_h_0', 'k_h_1', 'k_h_2']
|
|
|
|
self.ssh_authorized_keys_lines.return_value = [
|
|
|
|
'auth_0', 'auth_1', 'auth_2']
|
2017-02-17 18:29:50 +00:00
|
|
|
mock_is_db_initialised.return_value = False
|
2013-09-04 09:47:58 -07:00
|
|
|
hooks.compute_changed()
|
2014-07-16 11:40:00 +02:00
|
|
|
self.ssh_compute_add.assert_called_with('fookey', rid=None, unit=None)
|
2014-05-22 10:47:41 +02:00
|
|
|
expected_relations = [
|
2014-05-27 16:00:56 +02:00
|
|
|
call(relation_settings={'authorized_keys_0': 'auth_0'},
|
|
|
|
relation_id=None),
|
|
|
|
call(relation_settings={'authorized_keys_1': 'auth_1'},
|
|
|
|
relation_id=None),
|
|
|
|
call(relation_settings={'authorized_keys_2': 'auth_2'},
|
|
|
|
relation_id=None),
|
|
|
|
call(relation_settings={'known_hosts_0': 'k_h_0'},
|
|
|
|
relation_id=None),
|
|
|
|
call(relation_settings={'known_hosts_1': 'k_h_1'},
|
|
|
|
relation_id=None),
|
|
|
|
call(relation_settings={'known_hosts_2': 'k_h_2'},
|
|
|
|
relation_id=None),
|
2014-05-27 15:45:33 +02:00
|
|
|
call(authorized_keys_max_index=3, relation_id=None),
|
|
|
|
call(known_hosts_max_index=3, relation_id=None)]
|
2014-05-22 10:47:41 +02:00
|
|
|
self.assertEquals(sorted(self.relation_set.call_args_list),
|
|
|
|
sorted(expected_relations))
|
2013-10-29 19:28:46 -07:00
|
|
|
|
2017-02-14 02:50:05 +00:00
|
|
|
@patch.object(hooks, 'is_db_initialised')
|
|
|
|
def test_compute_changed_nova_public_key(self, mock_is_db_initialised):
|
2014-05-22 14:23:16 +02:00
|
|
|
self.test_relation.set({
|
2014-05-27 15:45:33 +02:00
|
|
|
'migration_auth_type': 'sasl', 'nova_ssh_public_key': 'fookey',
|
2016-02-12 10:38:21 -07:00
|
|
|
'private-address': '10.0.0.1', 'region': 'RegionOne'})
|
2014-05-22 14:23:16 +02:00
|
|
|
self.ssh_known_hosts_lines.return_value = [
|
|
|
|
'k_h_0', 'k_h_1', 'k_h_2']
|
|
|
|
self.ssh_authorized_keys_lines.return_value = [
|
|
|
|
'auth_0', 'auth_1', 'auth_2']
|
2017-02-14 02:50:05 +00:00
|
|
|
mock_is_db_initialised.return_value = False
|
2014-05-22 14:23:16 +02:00
|
|
|
hooks.compute_changed()
|
2014-05-27 16:00:56 +02:00
|
|
|
self.ssh_compute_add.assert_called_with('fookey', user='nova',
|
2014-07-16 11:40:00 +02:00
|
|
|
rid=None, unit=None)
|
2014-05-22 14:23:16 +02:00
|
|
|
expected_relations = [
|
2014-05-27 16:00:56 +02:00
|
|
|
call(relation_settings={'nova_authorized_keys_0': 'auth_0'},
|
|
|
|
relation_id=None),
|
|
|
|
call(relation_settings={'nova_authorized_keys_1': 'auth_1'},
|
|
|
|
relation_id=None),
|
|
|
|
call(relation_settings={'nova_authorized_keys_2': 'auth_2'},
|
|
|
|
relation_id=None),
|
|
|
|
call(relation_settings={'nova_known_hosts_0': 'k_h_0'},
|
|
|
|
relation_id=None),
|
|
|
|
call(relation_settings={'nova_known_hosts_1': 'k_h_1'},
|
|
|
|
relation_id=None),
|
|
|
|
call(relation_settings={'nova_known_hosts_2': 'k_h_2'},
|
|
|
|
relation_id=None),
|
|
|
|
call(relation_settings={'nova_known_hosts_max_index': 3},
|
|
|
|
relation_id=None),
|
|
|
|
call(relation_settings={'nova_authorized_keys_max_index': 3},
|
|
|
|
relation_id=None)]
|
2014-05-22 14:23:16 +02:00
|
|
|
self.assertEquals(sorted(self.relation_set.call_args_list),
|
|
|
|
sorted(expected_relations))
|
2013-10-29 19:28:46 -07:00
|
|
|
|
2015-06-02 17:06:30 -07:00
|
|
|
@patch.object(hooks, 'canonical_url')
|
2014-07-10 13:39:30 +01:00
|
|
|
@patch.object(utils, 'config')
|
2013-10-29 19:28:46 -07:00
|
|
|
@patch.object(hooks, '_auth_config')
|
2015-06-02 17:06:30 -07:00
|
|
|
def test_compute_joined_neutron(self, auth_config, _util_config,
|
|
|
|
_canonical_url):
|
2014-07-29 14:34:37 +00:00
|
|
|
_util_config.return_value = None
|
2014-06-19 16:54:21 +01:00
|
|
|
self.is_relation_made.return_value = False
|
2013-10-29 19:28:46 -07:00
|
|
|
self.network_manager.return_value = 'neutron'
|
2017-02-14 02:50:05 +00:00
|
|
|
self.is_leader = True
|
2013-10-29 19:28:46 -07:00
|
|
|
self.keystone_ca_cert_b64.return_value = 'foocert64'
|
|
|
|
self.unit_get.return_value = 'nova-cc-host1'
|
2016-09-15 11:31:51 +01:00
|
|
|
self.serial_console_settings.return_value = {
|
|
|
|
'enable_serial_console': 'false',
|
|
|
|
'serial_console_base_url': 'ws://controller:6803',
|
|
|
|
}
|
2015-06-02 17:06:30 -07:00
|
|
|
_canonical_url.return_value = 'http://nova-cc-host1'
|
2013-10-29 19:28:46 -07:00
|
|
|
auth_config.return_value = FAKE_KS_AUTH_CFG
|
|
|
|
hooks.compute_joined()
|
|
|
|
|
|
|
|
self.relation_set.assert_called_with(
|
|
|
|
relation_id=None,
|
|
|
|
ca_cert='foocert64',
|
|
|
|
region='RegionOne',
|
|
|
|
volume_service='cinder',
|
|
|
|
ec2_host='nova-cc-host1',
|
2016-09-15 11:31:51 +01:00
|
|
|
network_manager='neutron',
|
|
|
|
enable_serial_console='false',
|
|
|
|
serial_console_base_url='ws://controller:6803',
|
|
|
|
**FAKE_KS_AUTH_CFG)
|
2013-10-29 19:28:46 -07:00
|
|
|
|
2015-06-02 17:06:30 -07:00
|
|
|
@patch.object(hooks, 'canonical_url')
|
2014-07-10 13:39:30 +01:00
|
|
|
@patch.object(utils, 'config')
|
2014-06-19 16:54:21 +01:00
|
|
|
@patch.object(hooks, 'NeutronAPIContext')
|
|
|
|
@patch.object(hooks, '_auth_config')
|
2014-07-10 13:39:30 +01:00
|
|
|
def test_compute_joined_neutron_api_rel(self, auth_config, napi,
|
2015-06-02 17:06:30 -07:00
|
|
|
_util_config, _canonical_url):
|
2014-06-19 16:54:21 +01:00
|
|
|
def mock_NeutronAPIContext():
|
|
|
|
return {
|
2014-06-20 09:59:07 +01:00
|
|
|
'neutron_plugin': 'bob',
|
|
|
|
'neutron_security_groups': 'yes',
|
|
|
|
'neutron_url': 'http://nova-cc-host1:9696',
|
|
|
|
}
|
2014-07-29 14:34:37 +00:00
|
|
|
_util_config.return_value = None
|
2014-06-19 16:54:21 +01:00
|
|
|
napi.return_value = mock_NeutronAPIContext
|
|
|
|
self.is_relation_made.return_value = True
|
|
|
|
self.network_manager.return_value = 'neutron'
|
2017-02-14 02:50:05 +00:00
|
|
|
self.is_leader = True
|
2014-06-19 16:54:21 +01:00
|
|
|
self.keystone_ca_cert_b64.return_value = 'foocert64'
|
|
|
|
self.unit_get.return_value = 'nova-cc-host1'
|
2016-09-15 11:31:51 +01:00
|
|
|
self.serial_console_settings.return_value = {
|
|
|
|
'enable_serial_console': 'false',
|
|
|
|
'serial_console_base_url': 'ws://controller:6803',
|
|
|
|
}
|
2015-06-02 17:06:30 -07:00
|
|
|
_canonical_url.return_value = 'http://nova-cc-host1'
|
2014-06-19 16:54:21 +01:00
|
|
|
auth_config.return_value = FAKE_KS_AUTH_CFG
|
|
|
|
hooks.compute_joined()
|
|
|
|
self.relation_set.assert_called_with(
|
|
|
|
relation_id=None,
|
|
|
|
quantum_url='http://nova-cc-host1:9696',
|
|
|
|
ca_cert='foocert64',
|
2014-06-20 09:59:07 +01:00
|
|
|
quantum_port=9696,
|
2014-06-19 16:54:21 +01:00
|
|
|
quantum_host='nova-cc-host1',
|
|
|
|
quantum_security_groups='yes',
|
|
|
|
region='RegionOne',
|
|
|
|
volume_service='cinder',
|
|
|
|
ec2_host='nova-cc-host1',
|
|
|
|
quantum_plugin='bob',
|
2016-09-15 11:31:51 +01:00
|
|
|
network_manager='neutron',
|
|
|
|
enable_serial_console='false',
|
|
|
|
serial_console_base_url='ws://controller:6803',
|
|
|
|
**FAKE_KS_AUTH_CFG)
|
2014-06-19 16:54:21 +01:00
|
|
|
|
2015-06-02 17:06:30 -07:00
|
|
|
@patch.object(hooks, 'canonical_url')
|
2013-10-29 19:28:46 -07:00
|
|
|
@patch.object(hooks, '_auth_config')
|
2015-06-02 17:06:30 -07:00
|
|
|
def test_nova_vmware_joined(self, auth_config, _canonical_url):
|
2013-10-29 19:28:46 -07:00
|
|
|
auth_config.return_value = FAKE_KS_AUTH_CFG
|
2016-04-08 10:42:07 +01:00
|
|
|
self.is_relation_made.return_value = False
|
2013-10-29 19:28:46 -07:00
|
|
|
self.network_manager.return_value = 'neutron'
|
2015-06-02 17:06:30 -07:00
|
|
|
_canonical_url.return_value = 'http://nova-cc-host1'
|
2013-10-29 19:28:46 -07:00
|
|
|
hooks.nova_vmware_relation_joined()
|
|
|
|
self.relation_set.assert_called_with(
|
2016-04-08 10:42:07 +01:00
|
|
|
network_manager='neutron',
|
2013-11-08 13:41:39 +08:00
|
|
|
relation_id=None,
|
2013-10-29 19:28:46 -07:00
|
|
|
**FAKE_KS_AUTH_CFG)
|
2014-03-27 12:46:44 +01:00
|
|
|
|
|
|
|
def test_db_joined(self):
|
2017-04-18 10:56:09 -07:00
|
|
|
self.get_relation_ip.return_value = '10.10.10.10'
|
2014-03-27 12:46:44 +01:00
|
|
|
self.is_relation_made.return_value = False
|
2017-04-04 17:53:31 +01:00
|
|
|
self.os_release.return_value = 'diablo'
|
2014-03-27 12:46:44 +01:00
|
|
|
hooks.db_joined()
|
|
|
|
self.relation_set.assert_called_with(nova_database='nova',
|
|
|
|
nova_username='nova',
|
2017-04-18 10:56:09 -07:00
|
|
|
nova_hostname='10.10.10.10',
|
2016-03-11 11:22:31 +00:00
|
|
|
relation_id=None)
|
2017-04-18 10:56:09 -07:00
|
|
|
self.get_relation_ip.assert_called_with('shared-db',
|
|
|
|
cidr_network=None)
|
2016-03-11 11:22:31 +00:00
|
|
|
|
2016-04-12 15:12:03 +01:00
|
|
|
def test_db_joined_spaces(self):
|
2017-04-18 10:56:09 -07:00
|
|
|
self.get_relation_ip.return_value = '192.168.20.1'
|
2016-04-12 15:12:03 +01:00
|
|
|
self.unit_get.return_value = 'nova.foohost.com'
|
|
|
|
self.is_relation_made.return_value = False
|
2017-04-04 17:53:31 +01:00
|
|
|
self.os_release.return_value = 'diablo'
|
2016-04-12 15:12:03 +01:00
|
|
|
hooks.db_joined()
|
|
|
|
self.relation_set.assert_called_with(nova_database='nova',
|
|
|
|
nova_username='nova',
|
|
|
|
nova_hostname='192.168.20.1',
|
|
|
|
relation_id=None)
|
|
|
|
|
2016-03-11 11:22:31 +00:00
|
|
|
def test_db_joined_mitaka(self):
|
2017-04-18 10:56:09 -07:00
|
|
|
self.get_relation_ip.return_value = '10.10.10.10'
|
2016-03-11 11:22:31 +00:00
|
|
|
self.os_release.return_value = 'mitaka'
|
|
|
|
self.is_relation_made.return_value = False
|
|
|
|
hooks.db_joined()
|
|
|
|
self.relation_set.assert_has_calls([
|
|
|
|
call(nova_database='nova',
|
|
|
|
nova_username='nova',
|
2017-04-18 10:56:09 -07:00
|
|
|
nova_hostname='10.10.10.10',
|
2016-03-11 11:22:31 +00:00
|
|
|
relation_id=None),
|
|
|
|
call(novaapi_database='nova_api',
|
|
|
|
novaapi_username='nova',
|
2017-04-18 10:56:09 -07:00
|
|
|
novaapi_hostname='10.10.10.10',
|
2016-03-11 11:22:31 +00:00
|
|
|
relation_id=None),
|
|
|
|
])
|
|
|
|
|
2017-04-18 10:56:09 -07:00
|
|
|
self.get_relation_ip.assert_called_with('shared-db',
|
|
|
|
cidr_network=None)
|
2014-03-27 12:46:44 +01:00
|
|
|
|
2015-06-04 16:33:12 -07:00
|
|
|
@patch('charmhelpers.contrib.openstack.ip.service_name',
|
|
|
|
lambda *args: 'nova-cloud-controller')
|
2015-06-02 17:06:30 -07:00
|
|
|
@patch('charmhelpers.contrib.openstack.ip.unit_get')
|
|
|
|
@patch('charmhelpers.contrib.openstack.ip.is_clustered')
|
|
|
|
@patch('charmhelpers.contrib.openstack.ip.config')
|
|
|
|
def test_identity_joined(self, _ip_config, _is_clustered, _unit_get):
|
|
|
|
_is_clustered.return_value = False
|
|
|
|
_unit_get.return_value = '127.0.0.1'
|
|
|
|
_ip_config.side_effect = self.test_config.get
|
|
|
|
|
2015-06-03 11:27:55 -07:00
|
|
|
self.test_config.set('os-public-hostname', 'ncc.example.com')
|
2015-06-02 17:06:30 -07:00
|
|
|
hooks.identity_joined()
|
|
|
|
|
|
|
|
self.determine_endpoints.asssert_called_with(
|
|
|
|
public_url='http://ncc.example.com',
|
|
|
|
internal_url='http://127.0.0.1',
|
|
|
|
admin_url='http://127.0.0.1'
|
|
|
|
)
|
|
|
|
|
2014-03-27 12:46:44 +01:00
|
|
|
def test_postgresql_nova_db_joined(self):
|
|
|
|
self.is_relation_made.return_value = False
|
|
|
|
hooks.pgsql_nova_db_joined()
|
2014-03-31 12:56:09 +01:00
|
|
|
self.relation_set.assert_called_with(database='nova')
|
2014-03-27 12:46:44 +01:00
|
|
|
|
|
|
|
def test_db_joined_with_postgresql(self):
|
|
|
|
self.is_relation_made.return_value = True
|
|
|
|
|
|
|
|
with self.assertRaises(Exception) as context:
|
|
|
|
hooks.db_joined()
|
|
|
|
self.assertEqual(context.exception.message,
|
2014-04-10 17:05:53 +01:00
|
|
|
'Attempting to associate a mysql database when'
|
|
|
|
' there is already associated a postgresql one')
|
2014-03-27 12:46:44 +01:00
|
|
|
|
|
|
|
def test_postgresql_nova_joined_with_db(self):
|
|
|
|
self.is_relation_made.return_value = True
|
|
|
|
|
|
|
|
with self.assertRaises(Exception) as context:
|
|
|
|
hooks.pgsql_nova_db_joined()
|
|
|
|
self.assertEqual(context.exception.message,
|
2014-04-10 17:05:53 +01:00
|
|
|
'Attempting to associate a postgresql database when'
|
|
|
|
' there is already associated a mysql one')
|
2014-03-27 12:46:44 +01:00
|
|
|
|
|
|
|
@patch.object(hooks, 'CONFIGS')
|
|
|
|
def test_db_changed_missing_relation_data(self, configs):
|
|
|
|
configs.complete_contexts = MagicMock()
|
|
|
|
configs.complete_contexts.return_value = []
|
|
|
|
hooks.db_changed()
|
|
|
|
self.log.assert_called_with(
|
|
|
|
'shared-db relation incomplete. Peer not ready?'
|
|
|
|
)
|
|
|
|
|
|
|
|
@patch.object(hooks, 'CONFIGS')
|
|
|
|
def test_postgresql_nova_db_changed_missing_relation_data(self, configs):
|
|
|
|
configs.complete_contexts = MagicMock()
|
|
|
|
configs.complete_contexts.return_value = []
|
|
|
|
hooks.postgresql_nova_db_changed()
|
|
|
|
self.log.assert_called_with(
|
|
|
|
'pgsql-nova-db relation incomplete. Peer not ready?'
|
|
|
|
)
|
|
|
|
|
|
|
|
def _shared_db_test(self, configs):
|
|
|
|
configs.complete_contexts = MagicMock()
|
|
|
|
configs.complete_contexts.return_value = ['shared-db']
|
|
|
|
configs.write = MagicMock()
|
|
|
|
hooks.db_changed()
|
|
|
|
|
|
|
|
def _postgresql_db_test(self, configs):
|
|
|
|
configs.complete_contexts = MagicMock()
|
|
|
|
configs.complete_contexts.return_value = ['pgsql-nova-db']
|
|
|
|
configs.write = MagicMock()
|
|
|
|
hooks.postgresql_nova_db_changed()
|
|
|
|
|
2016-02-03 11:38:43 -08:00
|
|
|
@patch.object(hooks, 'nova_api_relation_joined')
|
2016-01-08 12:30:31 +00:00
|
|
|
@patch.object(hooks, 'is_db_initialised')
|
2014-03-27 12:46:44 +01:00
|
|
|
@patch.object(hooks, 'CONFIGS')
|
2016-04-08 10:42:07 +01:00
|
|
|
def test_db_changed(self, configs,
|
2016-02-03 11:38:43 -08:00
|
|
|
mock_is_db_initialised, api_joined):
|
|
|
|
self.relation_ids.return_value = ['nova-api/0']
|
2016-01-08 12:30:31 +00:00
|
|
|
mock_is_db_initialised.return_value = False
|
2015-05-12 15:17:42 +00:00
|
|
|
'No database migration is attempted when ACL list is not present'
|
2017-04-04 17:53:31 +01:00
|
|
|
self.os_release.return_value = 'diablo'
|
2014-03-27 12:46:44 +01:00
|
|
|
self._shared_db_test(configs)
|
2014-04-11 17:41:42 +01:00
|
|
|
self.assertTrue(configs.write_all.called)
|
2017-02-14 02:50:05 +00:00
|
|
|
self.assertFalse(self.migrate_nova_databases.called)
|
2016-02-03 11:38:43 -08:00
|
|
|
api_joined.asert_called_with(rid='nova-api/0')
|
2014-03-27 12:46:44 +01:00
|
|
|
|
2016-01-08 12:30:31 +00:00
|
|
|
@patch.object(hooks, 'is_db_initialised')
|
2014-08-28 08:55:09 +01:00
|
|
|
@patch.object(hooks, 'CONFIGS')
|
2016-01-08 12:30:31 +00:00
|
|
|
def test_db_changed_allowed(self, configs, mock_is_db_initialised):
|
|
|
|
mock_is_db_initialised.return_value = False
|
2014-08-28 08:55:09 +01:00
|
|
|
allowed_units = 'nova-cloud-controller/0 nova-cloud-controller/3'
|
|
|
|
self.test_relation.set({
|
|
|
|
'nova_allowed_units': allowed_units,
|
|
|
|
})
|
|
|
|
self.local_unit.return_value = 'nova-cloud-controller/3'
|
2017-04-04 17:53:31 +01:00
|
|
|
self.os_release.return_value = 'diablo'
|
2014-08-28 08:55:09 +01:00
|
|
|
self._shared_db_test(configs)
|
|
|
|
self.assertTrue(configs.write_all.called)
|
2017-02-14 02:50:05 +00:00
|
|
|
self.migrate_nova_databases.assert_called_with()
|
2014-08-28 08:55:09 +01:00
|
|
|
|
2016-01-08 12:30:31 +00:00
|
|
|
@patch.object(hooks, 'is_db_initialised')
|
2014-08-28 08:55:09 +01:00
|
|
|
@patch.object(hooks, 'CONFIGS')
|
2016-01-08 12:30:31 +00:00
|
|
|
def test_db_changed_not_allowed(self, configs, mock_is_db_initialised):
|
|
|
|
mock_is_db_initialised.return_value = False
|
2014-08-28 08:55:09 +01:00
|
|
|
allowed_units = 'nova-cloud-controller/0 nova-cloud-controller/3'
|
|
|
|
self.test_relation.set({
|
|
|
|
'nova_allowed_units': allowed_units,
|
|
|
|
})
|
|
|
|
self.local_unit.return_value = 'nova-cloud-controller/1'
|
2017-04-04 17:53:31 +01:00
|
|
|
self.os_release.return_value = 'diablo'
|
2014-08-28 08:55:09 +01:00
|
|
|
self._shared_db_test(configs)
|
|
|
|
self.assertTrue(configs.write_all.called)
|
2017-02-14 02:50:05 +00:00
|
|
|
self.assertFalse(self.migrate_nova_databases.called)
|
2014-08-28 08:55:09 +01:00
|
|
|
|
2016-04-14 09:18:30 +01:00
|
|
|
@patch.object(hooks, 'quantum_joined')
|
2016-02-03 11:38:43 -08:00
|
|
|
@patch.object(hooks, 'nova_api_relation_joined')
|
2016-01-08 12:30:31 +00:00
|
|
|
@patch.object(hooks, 'is_db_initialised')
|
2014-03-27 12:46:44 +01:00
|
|
|
@patch.object(hooks, 'CONFIGS')
|
2016-02-03 11:38:43 -08:00
|
|
|
def test_postgresql_db_changed(self, configs, mock_is_db_initialised,
|
2016-04-14 09:18:30 +01:00
|
|
|
api_joined, quantum_joined):
|
2016-02-03 11:38:43 -08:00
|
|
|
self.relation_ids.side_effect = [
|
|
|
|
[],
|
2016-04-14 09:18:30 +01:00
|
|
|
['neutron-gateway/0'],
|
2016-02-03 11:38:43 -08:00
|
|
|
['nova-api/0']]
|
2016-01-08 12:30:31 +00:00
|
|
|
mock_is_db_initialised.return_value = False
|
2017-04-04 17:53:31 +01:00
|
|
|
self.os_release.return_value = 'diablo'
|
2014-03-27 12:46:44 +01:00
|
|
|
self._postgresql_db_test(configs)
|
2014-04-11 17:41:42 +01:00
|
|
|
self.assertTrue(configs.write_all.called)
|
2017-02-14 02:50:05 +00:00
|
|
|
self.migrate_nova_databases.assert_called_with()
|
2016-02-03 11:38:43 -08:00
|
|
|
api_joined.assert_called_with(rid='nova-api/0')
|
2014-06-19 16:54:21 +01:00
|
|
|
|
2016-04-14 09:18:30 +01:00
|
|
|
@patch.object(hooks, 'quantum_joined')
|
2016-01-08 12:30:31 +00:00
|
|
|
@patch.object(hooks, 'is_db_initialised')
|
2014-09-29 09:03:49 +00:00
|
|
|
@patch.object(hooks, 'nova_cell_relation_joined')
|
|
|
|
@patch.object(hooks, 'compute_joined')
|
|
|
|
@patch.object(hooks, 'CONFIGS')
|
|
|
|
def test_db_changed_remote_restarts(self, configs, comp_joined,
|
2016-04-14 09:18:30 +01:00
|
|
|
cell_joined, mock_is_db_initialised,
|
|
|
|
quantum_joined):
|
2016-01-08 12:30:31 +00:00
|
|
|
mock_is_db_initialised.return_value = False
|
|
|
|
|
2014-09-29 09:03:49 +00:00
|
|
|
def _relation_ids(rel):
|
|
|
|
relid = {
|
|
|
|
'cloud-compute': ['nova-compute/0'],
|
|
|
|
'cell': ['nova-cell-api/0'],
|
2014-09-30 07:28:34 +01:00
|
|
|
'neutron-api': ['neutron-api/0'],
|
2016-04-14 09:18:30 +01:00
|
|
|
'quantum-network-service': ['neutron-gateway/0']
|
2014-09-29 09:03:49 +00:00
|
|
|
}
|
|
|
|
return relid[rel]
|
|
|
|
self.relation_ids.side_effect = _relation_ids
|
|
|
|
allowed_units = 'nova-cloud-controller/0'
|
|
|
|
self.test_relation.set({
|
|
|
|
'nova_allowed_units': allowed_units,
|
|
|
|
})
|
|
|
|
self.local_unit.return_value = 'nova-cloud-controller/0'
|
2017-04-04 17:53:31 +01:00
|
|
|
self.os_release.return_value = 'diablo'
|
2014-09-29 09:03:49 +00:00
|
|
|
self._shared_db_test(configs)
|
|
|
|
comp_joined.assert_called_with(remote_restart=True,
|
|
|
|
rid='nova-compute/0')
|
|
|
|
cell_joined.assert_called_with(remote_restart=True,
|
|
|
|
rid='nova-cell-api/0')
|
2016-04-14 09:18:30 +01:00
|
|
|
quantum_joined.assert_called_with(remote_restart=True,
|
|
|
|
rid='neutron-gateway/0')
|
2017-02-14 02:50:05 +00:00
|
|
|
self.migrate_nova_databases.assert_called_with()
|
2014-09-29 09:03:49 +00:00
|
|
|
|
2014-09-29 12:37:55 +00:00
|
|
|
@patch.object(hooks, 'nova_cell_relation_joined')
|
|
|
|
@patch.object(hooks, 'CONFIGS')
|
|
|
|
def test_amqp_relation_broken(self, configs, cell_joined):
|
|
|
|
configs.write = MagicMock()
|
|
|
|
self.relation_ids.return_value = ['nova-cell-api/0']
|
|
|
|
hooks.relation_broken()
|
|
|
|
self.assertTrue(configs.write_all.called)
|
|
|
|
cell_joined.assert_called_with(rid='nova-cell-api/0')
|
|
|
|
|
2017-02-14 02:50:05 +00:00
|
|
|
@patch.object(hooks, 'leader_init_db_if_ready_allowed_units')
|
|
|
|
@patch.object(hooks, 'is_db_initialised')
|
2016-06-28 16:48:01 +01:00
|
|
|
@patch.object(hooks, 'quantum_joined')
|
2016-02-03 11:38:43 -08:00
|
|
|
@patch.object(hooks, 'nova_api_relation_joined')
|
2014-09-29 09:03:49 +00:00
|
|
|
@patch.object(hooks, 'nova_cell_relation_joined')
|
|
|
|
@patch.object(hooks, 'CONFIGS')
|
2016-06-28 16:48:01 +01:00
|
|
|
def test_amqp_changed_api_rel(self, configs, cell_joined, api_joined,
|
2017-02-14 02:50:05 +00:00
|
|
|
quantum_joined, mock_is_db_initialised,
|
|
|
|
init_db_allowed):
|
2016-06-28 16:48:01 +01:00
|
|
|
self.relation_ids.side_effect = [
|
|
|
|
['nova-cell-api/0'],
|
|
|
|
['nova-api/0'],
|
|
|
|
['quantum-service/0'],
|
|
|
|
]
|
2017-02-14 02:50:05 +00:00
|
|
|
mock_is_db_initialised.return_value = False
|
2014-09-29 09:03:49 +00:00
|
|
|
configs.complete_contexts = MagicMock()
|
|
|
|
configs.complete_contexts.return_value = ['amqp']
|
|
|
|
configs.write = MagicMock()
|
2017-04-04 17:53:31 +01:00
|
|
|
self.os_release.return_value = 'diablo'
|
2014-09-29 09:03:49 +00:00
|
|
|
self.is_relation_made.return_value = True
|
|
|
|
hooks.amqp_changed()
|
|
|
|
self.assertEquals(configs.write.call_args_list,
|
|
|
|
[call('/etc/nova/nova.conf')])
|
2016-06-28 16:48:01 +01:00
|
|
|
cell_joined.assert_called_with(rid='nova-cell-api/0')
|
2016-02-03 11:38:43 -08:00
|
|
|
api_joined.assert_called_with(rid='nova-api/0')
|
2016-06-28 16:48:01 +01:00
|
|
|
quantum_joined.assert_called_with(rid='quantum-service/0',
|
|
|
|
remote_restart=True)
|
2014-09-29 09:03:49 +00:00
|
|
|
|
2017-02-14 02:50:05 +00:00
|
|
|
@patch.object(hooks, 'leader_init_db_if_ready_allowed_units')
|
|
|
|
@patch.object(hooks, 'is_db_initialised')
|
2016-06-28 16:48:01 +01:00
|
|
|
@patch.object(hooks, 'quantum_joined')
|
2016-02-03 11:38:43 -08:00
|
|
|
@patch.object(hooks, 'nova_api_relation_joined')
|
2014-09-29 09:03:49 +00:00
|
|
|
@patch.object(hooks, 'nova_cell_relation_joined')
|
|
|
|
@patch.object(hooks, 'CONFIGS')
|
2016-06-28 16:48:01 +01:00
|
|
|
def test_amqp_changed_noapi_rel(self, configs, cell_joined, api_joined,
|
2017-02-14 02:50:05 +00:00
|
|
|
quantum_joined, mock_is_db_initialised,
|
|
|
|
init_db_allowed):
|
|
|
|
mock_is_db_initialised.return_value = False
|
2014-09-29 09:03:49 +00:00
|
|
|
configs.complete_contexts = MagicMock()
|
|
|
|
configs.complete_contexts.return_value = ['amqp']
|
|
|
|
configs.write = MagicMock()
|
2016-02-03 11:38:43 -08:00
|
|
|
self.relation_ids.side_effect = [
|
|
|
|
['nova-cell-api/0'],
|
|
|
|
['nova-api/0'],
|
2016-06-28 16:48:01 +01:00
|
|
|
['quantum-service/0'],
|
2016-02-03 11:38:43 -08:00
|
|
|
]
|
2014-09-29 09:03:49 +00:00
|
|
|
self.is_relation_made.return_value = False
|
|
|
|
self.network_manager.return_value = 'neutron'
|
2017-04-04 17:53:31 +01:00
|
|
|
self.os_release.return_value = 'diablo'
|
2014-09-29 09:03:49 +00:00
|
|
|
hooks.amqp_changed()
|
|
|
|
self.assertEquals(configs.write.call_args_list,
|
2016-04-08 10:42:07 +01:00
|
|
|
[call('/etc/nova/nova.conf')])
|
2014-09-29 09:03:49 +00:00
|
|
|
cell_joined.assert_called_with(rid='nova-cell-api/0')
|
2016-02-03 11:38:43 -08:00
|
|
|
api_joined.assert_called_with(rid='nova-api/0')
|
2016-06-28 16:48:01 +01:00
|
|
|
quantum_joined.assert_called_with(rid='quantum-service/0',
|
|
|
|
remote_restart=True)
|
2014-09-29 09:03:49 +00:00
|
|
|
|
2015-06-02 17:06:30 -07:00
|
|
|
@patch.object(hooks, 'canonical_url')
|
|
|
|
def test_nova_cell_relation_joined(self, _canonical_url):
|
2014-09-29 12:37:55 +00:00
|
|
|
self.uuid.uuid4.return_value = 'bob'
|
2015-06-02 17:06:30 -07:00
|
|
|
_canonical_url.return_value = 'http://novaurl'
|
2014-09-29 12:37:55 +00:00
|
|
|
hooks.nova_cell_relation_joined(rid='rid',
|
|
|
|
remote_restart=True)
|
|
|
|
self.relation_set.assert_called_with(restart_trigger='bob',
|
2014-10-13 17:18:58 +01:00
|
|
|
nova_url='http://novaurl:8774/v2',
|
2014-09-29 12:37:55 +00:00
|
|
|
relation_id='rid')
|
|
|
|
|
|
|
|
@patch.object(hooks, 'CONFIGS')
|
|
|
|
def test_nova_cell_relation_changed(self, configs):
|
|
|
|
hooks.nova_cell_relation_changed()
|
|
|
|
configs.write.assert_called_with('/etc/nova/nova.conf')
|
|
|
|
|
|
|
|
def test_get_cell_type(self):
|
|
|
|
self.NovaCellContext().return_value = {
|
|
|
|
'cell_type': 'parent',
|
|
|
|
'cell_name': 'api',
|
|
|
|
}
|
|
|
|
self.assertEquals(hooks.get_cell_type(), 'parent')
|
|
|
|
|
2015-06-02 17:06:30 -07:00
|
|
|
@patch.object(hooks, 'canonical_url')
|
2014-06-19 16:54:21 +01:00
|
|
|
@patch.object(os, 'rename')
|
|
|
|
@patch.object(os.path, 'isfile')
|
|
|
|
@patch.object(hooks, 'CONFIGS')
|
2014-09-28 14:11:26 +00:00
|
|
|
@patch.object(hooks, 'get_cell_type')
|
|
|
|
def test_neutron_api_relation_joined(self, get_cell_type, configs, isfile,
|
2015-06-02 17:06:30 -07:00
|
|
|
rename, _canonical_url):
|
2014-06-20 09:59:07 +01:00
|
|
|
nova_url = 'http://novaurl:8774/v2'
|
2014-06-19 16:54:21 +01:00
|
|
|
isfile.return_value = True
|
|
|
|
_identity_joined = self.patch('identity_joined')
|
2014-09-29 12:37:55 +00:00
|
|
|
self.relation_ids.return_value = ['relid']
|
2015-06-02 17:06:30 -07:00
|
|
|
_canonical_url.return_value = 'http://novaurl'
|
2014-09-28 14:11:26 +00:00
|
|
|
get_cell_type.return_value = 'parent'
|
2014-09-29 14:58:29 +01:00
|
|
|
self.uuid.uuid4.return_value = 'bob'
|
2016-04-08 10:42:07 +01:00
|
|
|
hooks.neutron_api_relation_joined(remote_restart=True)
|
|
|
|
self.assertTrue(_identity_joined.called)
|
|
|
|
self.relation_set.assert_called_with(relation_id=None,
|
|
|
|
cell_type='parent',
|
|
|
|
nova_url=nova_url,
|
|
|
|
restart_trigger='bob')
|
2014-06-19 16:54:21 +01:00
|
|
|
|
|
|
|
@patch.object(hooks, 'CONFIGS')
|
|
|
|
def test_neutron_api_relation_changed(self, configs):
|
|
|
|
self.relation_ids.return_value = ['relid']
|
|
|
|
_compute_joined = self.patch('compute_joined')
|
|
|
|
_quantum_joined = self.patch('quantum_joined')
|
|
|
|
hooks.neutron_api_relation_changed()
|
|
|
|
self.assertTrue(configs.write.called_with('/etc/nova/nova.conf'))
|
|
|
|
self.assertTrue(_compute_joined.called)
|
|
|
|
self.assertTrue(_quantum_joined.called)
|
|
|
|
|
|
|
|
@patch.object(os, 'remove')
|
|
|
|
@patch.object(os.path, 'isfile')
|
|
|
|
@patch.object(hooks, 'CONFIGS')
|
|
|
|
def test_neutron_api_relation_broken(self, configs, isfile, remove):
|
|
|
|
isfile.return_value = True
|
|
|
|
self.relation_ids.return_value = ['relid']
|
|
|
|
_compute_joined = self.patch('compute_joined')
|
|
|
|
_quantum_joined = self.patch('quantum_joined')
|
|
|
|
hooks.neutron_api_relation_broken()
|
|
|
|
self.assertTrue(configs.write_all.called)
|
|
|
|
self.assertTrue(_compute_joined.called)
|
|
|
|
self.assertTrue(_quantum_joined.called)
|
2014-07-10 13:39:30 +01:00
|
|
|
|
2015-07-22 20:01:24 +08:00
|
|
|
@patch.object(hooks, 'canonical_url')
|
2014-07-10 13:39:30 +01:00
|
|
|
@patch.object(utils, 'config')
|
2015-07-22 20:01:24 +08:00
|
|
|
def test_console_settings_vnc(self, _utils_config, _canonical_url):
|
2014-07-10 13:39:30 +01:00
|
|
|
_utils_config.return_value = 'vnc'
|
|
|
|
_cc_host = "nova-cc-host1"
|
2015-07-22 20:01:24 +08:00
|
|
|
_canonical_url.return_value = 'http://' + _cc_host
|
2014-07-10 13:39:30 +01:00
|
|
|
_con_sets = hooks.console_settings()
|
|
|
|
console_settings = {
|
|
|
|
'console_proxy_novnc_address': 'http://%s:6080/vnc_auto.html' %
|
|
|
|
(_cc_host),
|
|
|
|
'console_proxy_novnc_port': 6080,
|
|
|
|
'console_access_protocol': 'vnc',
|
|
|
|
'console_proxy_novnc_host': _cc_host,
|
|
|
|
'console_proxy_xvpvnc_port': 6081,
|
|
|
|
'console_proxy_xvpvnc_host': _cc_host,
|
|
|
|
'console_proxy_xvpvnc_address': 'http://%s:6081/console' %
|
|
|
|
(_cc_host),
|
|
|
|
'console_keymap': 'en-us'
|
|
|
|
}
|
|
|
|
self.assertEqual(_con_sets, console_settings)
|
|
|
|
|
2015-07-22 20:01:24 +08:00
|
|
|
@patch.object(hooks, 'canonical_url')
|
2014-07-10 13:39:30 +01:00
|
|
|
@patch.object(utils, 'config')
|
2015-07-22 20:01:24 +08:00
|
|
|
def test_console_settings_xvpvnc(self, _utils_config, _canonical_url):
|
2014-07-10 13:39:30 +01:00
|
|
|
_utils_config.return_value = 'xvpvnc'
|
|
|
|
_cc_host = "nova-cc-host1"
|
2015-07-22 20:01:24 +08:00
|
|
|
_canonical_url.return_value = 'http://' + _cc_host
|
2014-07-10 13:39:30 +01:00
|
|
|
_con_sets = hooks.console_settings()
|
|
|
|
console_settings = {
|
|
|
|
'console_access_protocol': 'xvpvnc',
|
|
|
|
'console_keymap': 'en-us',
|
|
|
|
'console_proxy_xvpvnc_port': 6081,
|
|
|
|
'console_proxy_xvpvnc_host': _cc_host,
|
|
|
|
'console_proxy_xvpvnc_address': 'http://%s:6081/console' %
|
|
|
|
(_cc_host),
|
|
|
|
}
|
|
|
|
self.assertEqual(_con_sets, console_settings)
|
|
|
|
|
2015-07-22 20:01:24 +08:00
|
|
|
@patch.object(hooks, 'canonical_url')
|
2014-07-10 13:39:30 +01:00
|
|
|
@patch.object(utils, 'config')
|
2015-07-22 20:01:24 +08:00
|
|
|
def test_console_settings_novnc(self, _utils_config, _canonical_url):
|
2014-07-10 13:39:30 +01:00
|
|
|
_utils_config.return_value = 'novnc'
|
|
|
|
_cc_host = "nova-cc-host1"
|
2015-07-22 20:01:24 +08:00
|
|
|
_canonical_url.return_value = 'http://' + _cc_host
|
2014-07-10 13:39:30 +01:00
|
|
|
_con_sets = hooks.console_settings()
|
|
|
|
console_settings = {
|
|
|
|
'console_proxy_novnc_address': 'http://%s:6080/vnc_auto.html' %
|
|
|
|
(_cc_host),
|
|
|
|
'console_proxy_novnc_port': 6080,
|
|
|
|
'console_access_protocol': 'novnc',
|
|
|
|
'console_proxy_novnc_host': _cc_host,
|
|
|
|
'console_keymap': 'en-us'
|
|
|
|
}
|
|
|
|
self.assertEqual(_con_sets, console_settings)
|
|
|
|
|
2015-07-22 20:01:24 +08:00
|
|
|
@patch.object(hooks, 'canonical_url')
|
2014-07-10 13:39:30 +01:00
|
|
|
@patch.object(utils, 'config')
|
2015-07-22 20:01:24 +08:00
|
|
|
def test_console_settings_spice(self, _utils_config, _canonical_url):
|
2014-07-10 13:39:30 +01:00
|
|
|
_utils_config.return_value = 'spice'
|
|
|
|
_cc_host = "nova-cc-host1"
|
2015-07-22 20:01:24 +08:00
|
|
|
_canonical_url.return_value = 'http://' + _cc_host
|
2014-07-10 13:39:30 +01:00
|
|
|
_con_sets = hooks.console_settings()
|
|
|
|
console_settings = {
|
|
|
|
'console_proxy_spice_address': 'http://%s:6082/spice_auto.html' %
|
|
|
|
(_cc_host),
|
|
|
|
'console_proxy_spice_host': _cc_host,
|
|
|
|
'console_proxy_spice_port': 6082,
|
|
|
|
'console_access_protocol': 'spice',
|
|
|
|
'console_keymap': 'en-us'
|
|
|
|
}
|
|
|
|
self.assertEqual(_con_sets, console_settings)
|
|
|
|
|
2015-07-22 20:01:24 +08:00
|
|
|
@patch.object(hooks, 'https')
|
2014-07-10 13:39:30 +01:00
|
|
|
@patch.object(utils, 'config')
|
2015-07-22 20:01:24 +08:00
|
|
|
def test_console_settings_explicit_ip(self, _utils_config, _https):
|
2014-07-10 13:39:30 +01:00
|
|
|
_utils_config.return_value = 'spice'
|
2015-07-22 20:01:24 +08:00
|
|
|
_https.return_value = False
|
2014-07-10 13:39:30 +01:00
|
|
|
_cc_public_host = "public-host"
|
|
|
|
self.test_config.set('console-proxy-ip', _cc_public_host)
|
|
|
|
_con_sets = hooks.console_settings()
|
|
|
|
console_settings = {
|
|
|
|
'console_proxy_spice_address': 'http://%s:6082/spice_auto.html' %
|
|
|
|
(_cc_public_host),
|
|
|
|
'console_proxy_spice_host': _cc_public_host,
|
|
|
|
'console_proxy_spice_port': 6082,
|
|
|
|
'console_access_protocol': 'spice',
|
|
|
|
'console_keymap': 'en-us'
|
|
|
|
}
|
|
|
|
self.assertEqual(_con_sets, console_settings)
|
2014-09-29 14:58:29 +01:00
|
|
|
|
2015-07-22 20:01:24 +08:00
|
|
|
@patch.object(hooks, 'https')
|
|
|
|
@patch.object(utils, 'config')
|
|
|
|
def test_console_settings_explicit_ip_with_https(self, _utils_config,
|
|
|
|
_https):
|
|
|
|
_utils_config.return_value = 'spice'
|
|
|
|
_https.return_value = True
|
|
|
|
_cc_public_host = "public-host"
|
|
|
|
self.test_config.set('console-proxy-ip', _cc_public_host)
|
|
|
|
_con_sets = hooks.console_settings()
|
|
|
|
console_settings = {
|
|
|
|
'console_proxy_spice_address': 'https://%s:6082/spice_auto.html' %
|
|
|
|
(_cc_public_host),
|
|
|
|
'console_proxy_spice_host': _cc_public_host,
|
|
|
|
'console_proxy_spice_port': 6082,
|
|
|
|
'console_access_protocol': 'spice',
|
|
|
|
'console_keymap': 'en-us'
|
|
|
|
}
|
|
|
|
self.assertEqual(_con_sets, console_settings)
|
|
|
|
|
2015-02-19 11:28:05 -03:00
|
|
|
@patch('nova_cc_utils.config')
|
|
|
|
def test_ha_relation_joined_no_bound_ip(self, config):
|
2014-11-12 09:40:22 +00:00
|
|
|
self.get_hacluster_config.return_value = {
|
|
|
|
'ha-bindiface': 'em0',
|
|
|
|
'ha-mcastport': '8080',
|
|
|
|
'vip': '10.10.10.10',
|
|
|
|
}
|
|
|
|
self.test_config.set('vip_iface', 'eth120')
|
|
|
|
self.test_config.set('vip_cidr', '21')
|
2015-02-19 12:51:12 -03:00
|
|
|
config.return_value = None
|
2014-11-12 09:40:22 +00:00
|
|
|
self.get_iface_for_address.return_value = None
|
|
|
|
self.get_netmask_for_address.return_value = None
|
|
|
|
hooks.ha_joined()
|
|
|
|
args = {
|
2016-06-14 15:16:28 -07:00
|
|
|
'relation_id': None,
|
2014-11-12 09:40:22 +00:00
|
|
|
'corosync_bindiface': 'em0',
|
|
|
|
'corosync_mcastport': '8080',
|
|
|
|
'init_services': {'res_nova_haproxy': 'haproxy'},
|
|
|
|
'resources': {'res_nova_eth120_vip': 'ocf:heartbeat:IPaddr2',
|
|
|
|
'res_nova_haproxy': 'lsb:haproxy'},
|
|
|
|
'resource_params': {
|
|
|
|
'res_nova_eth120_vip': 'params ip="10.10.10.10"'
|
|
|
|
' cidr_netmask="21" nic="eth120"',
|
|
|
|
'res_nova_haproxy': 'op monitor interval="5s"'},
|
2015-02-19 11:28:05 -03:00
|
|
|
'colocations': {},
|
2014-11-12 09:40:22 +00:00
|
|
|
'clones': {'cl_nova_haproxy': 'res_nova_haproxy'}
|
|
|
|
}
|
|
|
|
self.relation_set.assert_has_calls([
|
|
|
|
call(groups={'grp_nova_vips': 'res_nova_eth120_vip'}),
|
|
|
|
call(**args),
|
|
|
|
])
|
2015-02-19 12:36:35 -03:00
|
|
|
|
2016-06-14 15:16:28 -07:00
|
|
|
def test_ha_joined_dns_ha(self):
|
|
|
|
def _fake_update(resources, resource_params, relation_id=None):
|
|
|
|
resources.update({'res_nova_public_hostname': 'ocf:maas:dns'})
|
|
|
|
resource_params.update({'res_nova_public_hostname':
|
|
|
|
'params fqdn="nova.maas" '
|
|
|
|
'ip_address="10.0.0.1"'})
|
|
|
|
|
|
|
|
self.test_config.set('dns-ha', True)
|
|
|
|
self.get_hacluster_config.return_value = {
|
|
|
|
'vip': None,
|
|
|
|
'ha-bindiface': 'em0',
|
|
|
|
'ha-mcastport': '8080',
|
|
|
|
'os-admin-hostname': None,
|
|
|
|
'os-internal-hostname': None,
|
|
|
|
'os-public-hostname': 'nova.maas',
|
|
|
|
}
|
|
|
|
args = {
|
|
|
|
'relation_id': None,
|
|
|
|
'corosync_bindiface': 'em0',
|
|
|
|
'corosync_mcastport': '8080',
|
|
|
|
'init_services': {'res_nova_haproxy': 'haproxy'},
|
|
|
|
'resources': {'res_nova_public_hostname': 'ocf:maas:dns',
|
|
|
|
'res_nova_haproxy': 'lsb:haproxy'},
|
|
|
|
'resource_params': {
|
|
|
|
'res_nova_public_hostname': 'params fqdn="nova.maas" '
|
|
|
|
'ip_address="10.0.0.1"',
|
|
|
|
'res_nova_haproxy': 'op monitor interval="5s"'},
|
|
|
|
'clones': {'cl_nova_haproxy': 'res_nova_haproxy'},
|
|
|
|
'colocations': {},
|
|
|
|
}
|
|
|
|
self.update_dns_ha_resource_params.side_effect = _fake_update
|
|
|
|
|
|
|
|
hooks.ha_joined()
|
|
|
|
self.assertTrue(self.update_dns_ha_resource_params.called)
|
|
|
|
self.relation_set.assert_called_with(**args)
|
|
|
|
|
2015-02-19 12:36:35 -03:00
|
|
|
@patch('nova_cc_utils.config')
|
|
|
|
def test_ha_relation_multi_consoleauth(self, config):
|
2014-11-12 09:40:22 +00:00
|
|
|
self.get_hacluster_config.return_value = {
|
|
|
|
'ha-bindiface': 'em0',
|
|
|
|
'ha-mcastport': '8080',
|
|
|
|
'vip': '10.10.10.10',
|
|
|
|
}
|
|
|
|
self.test_config.set('vip_iface', 'eth120')
|
|
|
|
self.test_config.set('vip_cidr', '21')
|
2015-02-19 12:36:35 -03:00
|
|
|
self.test_config.set('single-nova-consoleauth', False)
|
2015-02-19 12:51:12 -03:00
|
|
|
config.return_value = 'novnc'
|
2014-11-12 09:40:22 +00:00
|
|
|
self.get_iface_for_address.return_value = None
|
|
|
|
self.get_netmask_for_address.return_value = None
|
|
|
|
hooks.ha_joined()
|
|
|
|
args = {
|
2016-06-14 15:16:28 -07:00
|
|
|
'relation_id': None,
|
2014-11-12 09:40:22 +00:00
|
|
|
'corosync_bindiface': 'em0',
|
|
|
|
'corosync_mcastport': '8080',
|
|
|
|
'init_services': {'res_nova_haproxy': 'haproxy'},
|
|
|
|
'resources': {'res_nova_eth120_vip': 'ocf:heartbeat:IPaddr2',
|
|
|
|
'res_nova_haproxy': 'lsb:haproxy'},
|
|
|
|
'resource_params': {
|
|
|
|
'res_nova_eth120_vip': 'params ip="10.10.10.10"'
|
|
|
|
' cidr_netmask="21" nic="eth120"',
|
|
|
|
'res_nova_haproxy': 'op monitor interval="5s"'},
|
2015-02-19 12:36:35 -03:00
|
|
|
'colocations': {},
|
2014-11-12 09:40:22 +00:00
|
|
|
'clones': {'cl_nova_haproxy': 'res_nova_haproxy'}
|
|
|
|
}
|
|
|
|
self.relation_set.assert_has_calls([
|
|
|
|
call(groups={'grp_nova_vips': 'res_nova_eth120_vip'}),
|
|
|
|
call(**args),
|
|
|
|
])
|
2015-02-19 12:36:35 -03:00
|
|
|
|
|
|
|
@patch('nova_cc_utils.config')
|
|
|
|
def test_ha_relation_single_consoleauth(self, config):
|
|
|
|
self.get_hacluster_config.return_value = {
|
|
|
|
'ha-bindiface': 'em0',
|
|
|
|
'ha-mcastport': '8080',
|
|
|
|
'vip': '10.10.10.10',
|
|
|
|
}
|
|
|
|
self.test_config.set('vip_iface', 'eth120')
|
|
|
|
self.test_config.set('vip_cidr', '21')
|
2015-02-19 12:51:12 -03:00
|
|
|
config.return_value = 'novnc'
|
2015-02-19 12:36:35 -03:00
|
|
|
self.get_iface_for_address.return_value = None
|
|
|
|
self.get_netmask_for_address.return_value = None
|
|
|
|
hooks.ha_joined()
|
|
|
|
args = {
|
2016-06-14 15:16:28 -07:00
|
|
|
'relation_id': None,
|
2015-02-19 12:36:35 -03:00
|
|
|
'corosync_bindiface': 'em0',
|
|
|
|
'corosync_mcastport': '8080',
|
|
|
|
'init_services': {'res_nova_haproxy': 'haproxy',
|
|
|
|
'res_nova_consoleauth': 'nova-consoleauth'},
|
|
|
|
'resources': {'res_nova_eth120_vip': 'ocf:heartbeat:IPaddr2',
|
|
|
|
'res_nova_haproxy': 'lsb:haproxy',
|
2015-03-06 12:52:52 -03:00
|
|
|
'res_nova_consoleauth':
|
2015-03-02 11:32:49 -03:00
|
|
|
'ocf:openstack:nova-consoleauth'},
|
2015-02-19 12:36:35 -03:00
|
|
|
'resource_params': {
|
|
|
|
'res_nova_eth120_vip': 'params ip="10.10.10.10"'
|
|
|
|
' cidr_netmask="21" nic="eth120"',
|
|
|
|
'res_nova_haproxy': 'op monitor interval="5s"',
|
|
|
|
'res_nova_consoleauth': 'op monitor interval="5s"'},
|
|
|
|
'colocations': {
|
|
|
|
'vip_consoleauth': 'inf: res_nova_consoleauth grp_nova_vips'
|
|
|
|
},
|
|
|
|
'clones': {'cl_nova_haproxy': 'res_nova_haproxy'}
|
|
|
|
}
|
|
|
|
self.relation_set.assert_has_calls([
|
|
|
|
call(groups={'grp_nova_vips': 'res_nova_eth120_vip'}),
|
|
|
|
call(**args),
|
|
|
|
])
|
|
|
|
|
2017-02-14 02:50:05 +00:00
|
|
|
@patch.object(hooks, 'is_db_initialised')
|
2016-09-15 11:31:51 +01:00
|
|
|
@patch.object(hooks, 'determine_packages')
|
2017-05-29 13:52:31 -04:00
|
|
|
@patch.object(hooks, 'service_pause')
|
2015-06-12 14:03:50 +01:00
|
|
|
@patch.object(hooks, 'filter_installed_packages')
|
2015-02-19 12:36:35 -03:00
|
|
|
@patch('nova_cc_hooks.configure_https')
|
|
|
|
@patch('nova_cc_utils.config')
|
2015-06-12 14:03:50 +01:00
|
|
|
def test_config_changed_single_consoleauth(self, mock_config,
|
|
|
|
mock_configure_https,
|
2016-06-20 18:28:14 -04:00
|
|
|
mock_filter_packages,
|
2016-09-15 11:31:51 +01:00
|
|
|
mock_service_pause,
|
2017-02-14 02:50:05 +00:00
|
|
|
mock_determine_packages,
|
|
|
|
mock_is_db_initialised):
|
2016-09-15 11:31:51 +01:00
|
|
|
mock_determine_packages.return_value = []
|
2017-02-14 02:50:05 +00:00
|
|
|
mock_is_db_initialised.return_value = False
|
2016-02-12 10:38:21 -07:00
|
|
|
self.config_value_changed.return_value = False
|
2015-06-10 15:50:47 +00:00
|
|
|
self.git_install_requested.return_value = False
|
2017-04-04 17:53:31 +01:00
|
|
|
self.os_release.return_value = 'diablo'
|
2017-05-29 13:52:31 -04:00
|
|
|
|
|
|
|
def cfg(k, v):
|
|
|
|
if k == "single-nova-authconsole":
|
|
|
|
return True
|
|
|
|
return 'novnc'
|
|
|
|
|
|
|
|
config.side_effect = cfg
|
2015-02-19 12:36:35 -03:00
|
|
|
rids = {'ha': ['ha:1']}
|
|
|
|
|
|
|
|
def f(r):
|
|
|
|
return rids.get(r, [])
|
|
|
|
|
|
|
|
self.relation_ids.side_effect = f
|
|
|
|
hooks.config_changed()
|
|
|
|
args = {
|
2015-03-18 00:44:06 -03:00
|
|
|
'delete_resources': [],
|
2015-02-19 12:36:35 -03:00
|
|
|
'init_services': {'res_nova_consoleauth': 'nova-consoleauth'},
|
2015-03-06 12:52:52 -03:00
|
|
|
'resources': {'res_nova_consoleauth':
|
2015-03-02 11:32:49 -03:00
|
|
|
'ocf:openstack:nova-consoleauth'},
|
2015-02-19 12:36:35 -03:00
|
|
|
'resource_params': {
|
|
|
|
'res_nova_consoleauth': 'op monitor interval="5s"'},
|
|
|
|
'colocations': {
|
|
|
|
'vip_consoleauth': 'inf: res_nova_consoleauth grp_nova_vips'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
self.relation_set.assert_has_calls([
|
|
|
|
call(v, **args) for v in rids['ha']
|
|
|
|
])
|
2015-06-12 14:03:50 +01:00
|
|
|
|
2017-05-29 13:52:31 -04:00
|
|
|
mock_service_pause.assert_has_calls([
|
|
|
|
call('nova-consoleauth')]
|
|
|
|
)
|
2015-06-12 14:03:50 +01:00
|
|
|
mock_filter_packages.assert_called_with([])
|
2016-02-03 11:38:43 -08:00
|
|
|
|
|
|
|
@patch.object(hooks, 'is_api_ready')
|
|
|
|
def _test_nova_api_relation_joined(self, tgt, is_api_ready):
|
|
|
|
is_api_ready.return_value = tgt
|
|
|
|
exp = 'yes' if tgt else 'no'
|
|
|
|
hooks.nova_api_relation_joined(rid='foo')
|
|
|
|
self.relation_set.assert_called_with(
|
|
|
|
'foo', **{'nova-api-ready': exp})
|
|
|
|
|
|
|
|
def test_nova_api_relation_joined_ready(self):
|
|
|
|
self._test_nova_api_relation_joined(True)
|
|
|
|
|
|
|
|
def test_nova_api_relation_joined_not_ready(self):
|
|
|
|
self._test_nova_api_relation_joined(False)
|
2017-04-21 10:22:11 +01:00
|
|
|
|
|
|
|
@patch.object(hooks, 'memcached_common')
|
|
|
|
def test_memcache_joined(self, _memcached_common):
|
|
|
|
self.get_relation_ip.return_value = 'foo'
|
|
|
|
hooks.memcached_joined()
|
|
|
|
self.get_relation_ip.assert_called_once_with('memcache')
|
|
|
|
self.relation_set.assert_called_once_with(
|
|
|
|
relation_id=None,
|
|
|
|
relation_settings={'private-address': 'foo'})
|
|
|
|
hooks.memcached_joined()
|