def config_changed(): if config('prefer-ipv6'): setup_ipv6() status_set('maintenance', 'Sync DB') sync_db_with_multi_ipv6_addresses(config('database'), config('database-user')) if not config('action-managed-upgrade'): if openstack_upgrade_available('glance-common'): status_set('maintenance', 'Upgrading OpenStack release') do_openstack_upgrade(CONFIGS) open_port(9292) configure_https() update_nrpe_config() # Pickup and changes due to network reference architecture # configuration [keystone_joined(rid) for rid in relation_ids('identity-service')] [image_service_joined(rid) for rid in relation_ids('image-service')] [cluster_joined(rid) for rid in relation_ids('cluster')] for r_id in relation_ids('ha'): ha_relation_joined(relation_id=r_id) # NOTE(jamespage): trigger any configuration related changes # for cephx permissions restrictions ceph_changed() update_image_location_policy()
def upgrade_charm(): apt_install(filter_installed_packages(determine_packages()), fatal=True) reinstall_paste_ini() configure_https() update_nrpe_config() update_image_location_policy() CONFIGS.write_all()
def config_changed(): if config('prefer-ipv6'): setup_ipv6() status_set('maintenance', 'Sync DB') sync_db_with_multi_ipv6_addresses(config('database'), config('database-user')) if not config('action-managed-upgrade'): if openstack_upgrade_available('glance-common'): status_set('maintenance', 'Upgrading OpenStack release') do_openstack_upgrade(CONFIGS) open_port(9292) configure_https() update_nrpe_config() # Pickup and changes due to network reference architecture # configuration [keystone_joined(rid) for rid in relation_ids('identity-service')] [image_service_joined(rid) for rid in relation_ids('image-service')] [cluster_joined(rid) for rid in relation_ids('cluster')] for r_id in relation_ids('ha'): ha_relation_joined(relation_id=r_id) # NOTE(jamespage): trigger any configuration related changes # for cephx permissions restrictions ceph_changed() update_image_location_policy()
def upgrade_charm(): apt_install(filter_installed_packages(determine_packages()), fatal=True) packages_removed = remove_old_packages() reinstall_paste_ini(force_reinstall=packages_removed) configure_https() update_nrpe_config() update_image_location_policy() CONFIGS.write_all() if packages_removed: juju_log("Package purge detected, restarting services", "INFO") for s in services(): service_restart(s)
def upgrade_charm(): apt_install(filter_installed_packages(determine_packages()), fatal=True) packages_removed = remove_old_packages() reinstall_paste_ini(force_reinstall=packages_removed) configure_https() update_nrpe_config() update_image_location_policy() CONFIGS.write_all() if packages_removed: juju_log("Package purge detected, restarting services", "INFO") for s in services(): service_restart(s)
def object_store_joined(): if 'identity-service' not in CONFIGS.complete_contexts(): juju_log('Deferring swift storage configuration until ' 'an identity-service relation exists') return if 'object-store' not in CONFIGS.complete_contexts(): juju_log('swift relation incomplete') return [image_service_joined(rid) for rid in relation_ids('image-service')] update_image_location_policy() CONFIGS.write(GLANCE_API_CONF)
def object_store_joined(): if 'identity-service' not in CONFIGS.complete_contexts(): juju_log('Deferring swift storage configuration until ' 'an identity-service relation exists') return if 'object-store' not in CONFIGS.complete_contexts(): juju_log('swift relation incomplete') return [image_service_joined(rid) for rid in relation_ids('image-service')] update_image_location_policy() CONFIGS.write(GLANCE_API_CONF)
def test_update_image_location_policy(self, mock_os_release, mock_kv, mock_update_json_file, mock_json, mock_config): db_vals = {} config = {'restrict-image-location-operations': False} def fake_config(key): return config.get(key) def fake_db_get(key): return db_vals.get(key) db_obj = mock_kv.return_value db_obj.get = MagicMock() db_obj.get.side_effect = fake_db_get db_obj.set = MagicMock() mock_config.side_effect = fake_config fake_open = mock_open() with patch.object(utils, 'open', fake_open, create=True): mock_json.loads.return_value = {'get_image_location': '', 'set_image_location': '', 'delete_image_location': ''} mock_os_release.return_value = 'icehouse' utils.update_image_location_policy() self.assertFalse(mock_kv.called) # Function has no effect in ussuri onwards mock_os_release.return_value = 'ussuri' utils.update_image_location_policy() self.assertFalse(mock_kv.called) mock_os_release.return_value = 'kilo' utils.update_image_location_policy() self.assertTrue(mock_kv.called) mock_update_json_file.assert_has_calls([ call('/etc/glance/policy.json', {'get_image_location': '', 'set_image_location': '', 'delete_image_location': ''})]) mock_update_json_file.reset_mock() config['restrict-image-location-operations'] = True utils.update_image_location_policy() mock_update_json_file.assert_has_calls([ call('/etc/glance/policy.json', {'get_image_location': 'role:admin', 'set_image_location': 'role:admin', 'delete_image_location': 'role:admin'})]) db_obj.get.assert_has_calls([call('policy_get_image_location'), call('policy_set_image_location'), call('policy_delete_image_location')])
def test_update_image_location_policy(self, mock_os_release, mock_kv, mock_update_json_file, mock_json, mock_config): db_vals = {} config = {'restrict-image-location-operations': False} def fake_config(key): return config.get(key) def fake_db_get(key): return db_vals.get(key) db_obj = mock_kv.return_value db_obj.get = MagicMock() db_obj.get.side_effect = fake_db_get db_obj.set = MagicMock() mock_config.side_effect = fake_config fake_open = mock_open() with patch.object(utils, 'open', fake_open, create=True): mock_json.loads.return_value = {'get_image_location': '', 'set_image_location': '', 'delete_image_location': ''} mock_os_release.return_value = 'icehouse' utils.update_image_location_policy() self.assertFalse(mock_kv.called) mock_os_release.return_value = 'kilo' utils.update_image_location_policy() self.assertTrue(mock_kv.called) mock_update_json_file.assert_has_calls([ call('/etc/glance/policy.json', {'get_image_location': ''}), call('/etc/glance/policy.json', {'set_image_location': ''}), call('/etc/glance/policy.json', {'delete_image_location': ''})]) mock_update_json_file.reset_mock() config['restrict-image-location-operations'] = True utils.update_image_location_policy() mock_update_json_file.assert_has_calls([ call('/etc/glance/policy.json', {'get_image_location': 'role:admin'}), call('/etc/glance/policy.json', {'set_image_location': 'role:admin'}), call('/etc/glance/policy.json', {'delete_image_location': 'role:admin'})]) db_obj.get.assert_has_calls([call('policy_get_image_location'), call('policy_set_image_location'), call('policy_delete_image_location')]) db_obj.set.assert_has_calls([call('policy_get_image_location', ''), call('policy_set_image_location', ''), call('policy_delete_image_location', '')])