def test_config_changed_with_upgrade( self, mock_nova_cell_api_relation_joined, mock_compute_joined, conf_https, neutron_api_joined, identity_joined, cluster_joined, mock_filter_packages, db_joined, mock_relids, mock_unit_get, mock_quantum_joined, mock_is_db_initialised, mock_update_aws_compat_services, mock_resource_map, mock_update_nrpe_config, mock_get_shared_metadatasecret, mock_set_shared_metadatasecret): mock_resource_map.return_value = {} self.determine_packages.return_value = [] mock_is_db_initialised.return_value = False self.openstack_upgrade_available.return_value = True self.relation_ids.return_value = ['generic_rid'] self.test_config.set('console-access-protocol', 'dummy') mock_relids.return_value = [] mock_unit_get.return_value = '127.0.0.1' self.os_release.return_value = 'diablo' hooks.resolve_CONFIGS() hooks.config_changed() self.assertTrue(self.do_openstack_upgrade.called) self.assertTrue(neutron_api_joined.called) self.assertTrue(identity_joined.called) self.assertTrue(cluster_joined.called) self.assertTrue(db_joined.called) self.assertTrue(self.save_script_rc.called) mock_filter_packages.assert_called_with([]) self.assertTrue(mock_quantum_joined.called) self.assertTrue(mock_update_aws_compat_services.called)
def test_config_changed_region_change(self, mock_compute_changed, mock_compute_joined, mock_config_https, mock_filter_packages, mock_is_db_initialised, mock_update_aws_compat_services, mock_relation_ids, mock_resource_map, mock_update_nrpe_config, mock_get_shared_metadatasecret, mock_set_shared_metadatasecret): mock_resource_map.return_value = {} self.openstack_upgrade_available.return_value = False self.config_value_changed.return_value = True self.related_units.return_value = ['unit/0'] self.relation_ids.side_effect = \ lambda x: ['generic_rid'] if x == 'cloud-compute' else [] mock_is_db_initialised.return_value = False self.os_release.return_value = 'diablo' hooks.resolve_CONFIGS() hooks.config_changed() mock_compute_changed.assert_has_calls([call('generic_rid', 'unit/0')]) mock_compute_joined.assert_has_calls( [call(rid='generic_rid', remote_restart=False)]) self.assertTrue(mock_update_aws_compat_services.called)
def test_config_changed_with_upgrade(self, mock_nova_cell_api_relation_joined, mock_compute_joined, conf_https, neutron_api_joined, identity_joined, cluster_joined, mock_filter_packages, db_joined, mock_relids, mock_unit_get, mock_quantum_joined, mock_is_db_initialised, mock_update_aws_compat_services, mock_resource_map, mock_update_nrpe_config, mock_get_shared_metadatasecret, mock_set_shared_metadatasecret): mock_resource_map.return_value = {} self.determine_packages.return_value = [] mock_is_db_initialised.return_value = False self.openstack_upgrade_available.return_value = True self.relation_ids.return_value = ['generic_rid'] self.test_config.set('console-access-protocol', 'dummy') mock_relids.return_value = [] mock_unit_get.return_value = '127.0.0.1' self.os_release.return_value = 'diablo' hooks.resolve_CONFIGS() hooks.config_changed() self.assertTrue(self.do_openstack_upgrade.called) self.assertTrue(neutron_api_joined.called) self.assertTrue(identity_joined.called) self.assertTrue(cluster_joined.called) self.assertTrue(db_joined.called) self.assertTrue(self.save_script_rc.called) mock_filter_packages.assert_called_with([]) self.assertTrue(mock_quantum_joined.called) self.assertTrue(mock_update_aws_compat_services.called)
def test_config_changed_no_upgrade_juno_no_neutron_server( self, conf_https, mock_filter_packages, mock_is_db_initialised, mock_update_aws_compat_services, mock_sub_ctxt, mock_resource_map, mock_update_nrpe_config, mock_get_shared_metadatasecret, mock_set_shared_metadatasecret): mock_resource_map.return_value = {} self.determine_packages.return_value = [] self.test_config.set('console-access-protocol', 'dummy') self.openstack_upgrade_available.return_value = False mock_is_db_initialised.return_value = False self.os_release.return_value = 'juno' self.service_pause.side_effect = ValueError hooks.resolve_CONFIGS() with patch.object(hooks.CONFIGS, 'write_all'): hooks.config_changed() self.assertTrue(self.save_script_rc.called) mock_filter_packages.assert_called_with([]) self.assertTrue(mock_update_aws_compat_services.called) self.service_pause.assert_called_with('neutron-server')
def test_config_changed_ocata(self, conf_https, mock_filter_packages, mock_is_db_initialised, mock_update_aws_compat_services, mock_update_nrpe_config, mock_sub_ctxt, mock_get_shared_metadatasecret, mock_set_shared_metadatasecret): mock_get_shared_metadatasecret.return_value = None self.is_leader.return_value = True self.determine_packages.return_value = [] self.test_config.set('console-access-protocol', 'dummy') self.openstack_upgrade_available.return_value = False mock_is_db_initialised.return_value = False self.os_release.return_value = 'diablo' hooks.resolve_CONFIGS() # probably need the with patch.object from below with patch.object(hooks.CONFIGS, 'write_all') as wa: hooks.config_changed() self.assertTrue(wa.called) self.assertTrue(self.save_script_rc.called) mock_filter_packages.assert_called_with([]) self.assertTrue(mock_update_aws_compat_services.called) mock_set_shared_metadatasecret.assert_called_once_with()
def openstack_upgrade(): """Upgrade packages to config-set Openstack version. If the charm was installed from source we cannot upgrade it. For backwards compatibility a config flag must be set for this code to run, otherwise a full service level upgrade will fire on config-changed.""" # If attempting to upgrade from Stein->Train, block until Placement # charm is related. Status is set in check_optional_relations(). release = ch_utils.os_release('nova-common') cmp_os_release = ch_utils.CompareOpenStackReleases(release) if (cmp_os_release == 'stein' and not hookenv.relation_ids('placement')): return if (ch_utils.do_action_openstack_upgrade('nova-common', utils.do_openstack_upgrade, hooks.CONFIGS)): for rid in hookenv.relation_ids('neutron-api'): hooks.neutron_api_relation_joined(rid=rid, remote_restart=True) # NOTE(thedac): Force re-fire of shared-db joined hook # to ensure that nova_api database is setup if required. for r_id in hookenv.relation_ids('shared-db'): hooks.db_joined(relation_id=r_id) hooks.config_changed()
def openstack_upgrade(): """Upgrade packages to config-set Openstack version. If the charm was installed from source we cannot upgrade it. For backwards compatibility a config flag must be set for this code to run, otherwise a full service level upgrade will fire on config-changed.""" if (ch_utils.do_action_openstack_upgrade('nova-common', utils.do_openstack_upgrade, hooks.CONFIGS)): for rid in hookenv.relation_ids('neutron-api'): hooks.neutron_api_relation_joined(rid=rid, remote_restart=True) # NOTE(thedac): Force re-fire of shared-db joined hook # to ensure that nova_api database is setup if required. for r_id in hookenv.relation_ids('shared-db'): hooks.db_joined(relation_id=r_id) hooks.config_changed()
def test_config_changed_no_upgrade_juno( self, conf_https, mock_filter_packages, mock_is_db_initialised, mock_update_aws_compat_services, mock_update_nrpe_config, mock_sub_ctxt, mock_get_shared_metadatasecret, mock_set_shared_metadatasecret): self.determine_packages.return_value = [] self.test_config.set('console-access-protocol', 'dummy') self.openstack_upgrade_available.return_value = False mock_is_db_initialised.return_value = False self.os_release.return_value = 'juno' hooks.resolve_CONFIGS() with patch.object(hooks.CONFIGS, 'write_all') as wa: hooks.config_changed() self.assertTrue(wa.called) self.assertTrue(self.save_script_rc.called) mock_filter_packages.assert_called_with([]) self.assertTrue(mock_update_aws_compat_services.called) self.service_pause.assert_called_with('neutron-server')
def test_config_changed_no_upgrade( self, conf_https, mock_filter_packages, mock_is_db_initialised, mock_update_aws_compat_services, mock_resource_map, mock_update_nrpe_config, mock_get_shared_metadatasecret, mock_set_shared_metadatasecret): mock_resource_map.return_value = {} self.get_shared_metadatasecret = None self.determine_packages.return_value = [] self.is_leader.return_value = True self.test_config.set('console-access-protocol', 'dummy') self.openstack_upgrade_available.return_value = False mock_is_db_initialised.return_value = False self.os_release.return_value = 'diablo' hooks.resolve_CONFIGS() hooks.config_changed() self.assertTrue(self.save_script_rc.called) mock_filter_packages.assert_called_with([]) self.assertTrue(mock_update_aws_compat_services.called)
def test_config_changed_no_upgrade(self, conf_https, mock_filter_packages, mock_is_db_initialised, mock_update_aws_compat_services, mock_resource_map, mock_update_nrpe_config, mock_get_shared_metadatasecret, mock_set_shared_metadatasecret): mock_resource_map.return_value = {} self.get_shared_metadatasecret = None self.determine_packages.return_value = [] self.is_leader.return_value = True self.test_config.set('console-access-protocol', 'dummy') self.openstack_upgrade_available.return_value = False mock_is_db_initialised.return_value = False self.os_release.return_value = 'diablo' hooks.resolve_CONFIGS() hooks.config_changed() self.assertTrue(self.save_script_rc.called) mock_filter_packages.assert_called_with([]) self.assertTrue(mock_update_aws_compat_services.called)
def test_config_changed_region_change( self, mock_set_region_on_relation_from_config, mock_compute_joined, mock_config_https, mock_filter_packages, mock_is_db_initialised, mock_update_aws_compat_services, mock_relation_ids, mock_resource_map, mock_update_nrpe_config, mock_get_shared_metadatasecret, mock_set_shared_metadatasecret): mock_resource_map.return_value = {} self.openstack_upgrade_available.return_value = False self.config_value_changed.return_value = True self.related_units.return_value = ['unit/0'] self.relation_ids.side_effect = \ lambda x: ['generic_rid'] if x == 'cloud-compute' else [] mock_set_region_on_relation_from_config.return_value = False self.os_release.return_value = 'diablo' hooks.resolve_CONFIGS() hooks.config_changed() mock_set_region_on_relation_from_config.assert_has_calls( [call('generic_rid')]) mock_compute_joined.assert_has_calls( [call(rid='generic_rid', remote_restart=False)]) self.assertTrue(mock_update_aws_compat_services.called)