Translation(s): none

(!) Discussion


This page contains a proposal for a way to handle upgrade where user's data and package maintainer data are merged with minimal interaction with user. The package approx will be used as an example.

Configuration upgrade by package

Status

This page is a proposal. It is not (yet?) accepted by Debian project. Stay tuned.

Introduction

For a casual user (like you mother-in-law or your neighbour), the questions asked during package upgrades can be intimidating. Casual users barely know that some files exist outside of their home directory and are completely lost when looking at the /etc directory. Unfortunately, during package upgrade, user is faced with cryptic questions whether to keep his configuration, use the maintainers configuration or look at a diff. The casual user will seldom know what to do in this case.

This situation can be made worse if user's configuration was edited with a tool (e.g. cups configuration is edited through a web browser): the user has no knowledge of the syntax of the configuration file.

This proposal aims to provide a way for Debian package to minimize the number of questions raised to the user when upgrading packages. If questions are necessary, an interface will be provided to the user. Hopefully, manual edition of configuration files will not be necessary.

Upgrades with Config::Model

Config-Model provides a framework for editing and validating the content of any configuration file or data. With a configuration model (expressed in a data structure), Config-Model provides a user interface and a tool to validate configuration.

The configuration model contains the following specifications :

This notion of default value versus built-in default value is important to distinguish:

  1. the values that were customized by the user (or sysadmin)
  2. the value that are recommended by the package maintainer (and specified as default in the model)

  3. the value that are provided upstream (specified as upstream_default)

During a package upgrade we want to: * propagate values from the old configuration file to new configuration file. * discard obsolete data (if any) * introduce new mandatory values (if any) * migrate (or translate) data in old format to new format

So the idea is:

The same principles can be applied to downgrade with some limitations (see below for more details)

Well, that was the theory. Let's experiment with Approx configuration file and work out the details.

Approx example

configuration analysis

From approx.conf(5) man page, we find that approx has a very simple configuration. Approx will need one configuration class that will have:

The syntax of approx.conf is fairly simple but there's no Perl module available to read and write it. A dedicated parser/writer will be required.

Approx configuration model

To create the Approx configuration model, you can use the GUI provided by libconfig-model-itself-perl.

In a empty directory, run config-edit-model -model Approx and fill the fields as required. This model creation process is shown in this flash movie. In order to reduce the length of the movie, only 3 out of 10 configuration items were created in this movie. (Please do not mind the error message that pops in the middle of the movie, this bug has been fixed since ;-) ).

In the end you will get some kind of a translation of approx.conf(5) man page in this model (reformated and expunged of help text for brevity):

[
 {
  'name' => 'Approx',
  'element' 
  => [
      'max_rate'     , { type => 'leaf', value_type => 'uniline',                      },
      'max_redirects', { type => 'leaf', value_type => 'integer', upstream_default => '5'      },
      'user'         , { type => 'leaf', value_type => 'uniline', upstream_default => 'approx' },
      'group'        , { type => 'leaf', value_type => 'uniline', upstream_default => 'approx' },
      'syslog'       , { type => 'leaf', value_type => 'uniline', upstream_default => 'daemon' },
      'pdiffs'       , { type => 'leaf', value_type => 'boolean', upstream_default => '1'      },
      'offline'      , { type => 'leaf', value_type => 'boolean', upstream_default => '0'      },
      'max_wait'     , { type => 'leaf', value_type => 'integer', upstream_default => '10'     },
      'verbose'      , { type => 'leaf', value_type => 'boolean', upstream_default => '0'      },
      'debug'        , { type => 'leaf', value_type => 'boolean', upstream_default => '0'      },
      'distributions', { type => 'hash', index_type => 'string' ,
                         cargo => { value_type => 'uniline', type => 'leaf',},
                       }
      ]
 }
] ;

You can view the actual model on Approx model SVN

/!\ Any Debian specific requirement (e.g. default value) will have to be implemented in the model and not in the template configuration file provided to the user (e.g. not in /etc/approx/approx.conf)

Parsing and writing approx configuration file

First, how to read or write the configuration file must declared in Approx model using the autoread feature. For more detail see this movie. The reader writer class must be declared in Approx model:

   read_config => [
                   {
                    backend    => 'custom',
                    class      => 'Config::Model::Approx',
                    config_dir => '/etc/approx',
                    file       => 'approx.conf',
                   }
                 ],

This indicates that a custom will be used to read /etc/approx/approx.conf. The class Config::Model::Approx must provide a read method. By default, the same setup is used to write back approx.conf with the write method.

The read method is specified in Config::Model::Approx. (Note that approx.conf comments are discarded):

sub read {
    my %args = @_ ;

    foreach ($args{io_handle}->getlines) {
        chomp;
        s/#.*//;
        s/\s+/=/; # translate file in string loadable by C::M::Loader
        next unless $_; # skip empty lines
        my $load = s/^\$// ? $_ : "distributions:".$_;
        $args{object}->load($load) ;
    }

    return 1;
}

Likewise, the write method is provided in Config::Model::Approx. Note that some documentation is extracted from Approx model and used in the comments of the generated file. So any user reviewing approx.conf will have minimal documentation:

sub write {
    my %args = @_ ;

    my $node = $args{object} ;
    my $ioh  = $args{io_handle} ;

    $ioh->print("# This file was written by Config::Model with Approx model\n");
    $ioh->print("# You may modify the content of this file. Configuration \n");
    $ioh->print("# modification will be preserved. Modification in the comments\n");
    $ioh->print("# will be discarded\n\n");

    foreach my $elt ($node->get_element_name) {
        next if $elt eq 'distributions';

        # write some documentation in comments
        $ioh->print("# $elt:", $node->get_help(summary => $elt));
        my $upstream_default = $node->fetch_element($elt) -> fetch('upstream_default') ;
        $ioh->print(" ($upstream_default)") if defined $upstream_default;
        $ioh->print("\n") ;

        # write value
        my $v = $node->grab_value($elt) ;
        $ioh->printf("\$%-10s %s\n",$elt,$v) if defined $v ;
        $ioh->print("\n") ;
    }

    my $h = $node->fetch_element('distributions') ;
    $ioh->print("# ", $node->get_help(summary => 'distributions'),"\n");
    foreach my $dname ($h->get_all_indexes) {
        $ioh->printf("%-10s %s\n",$dname,
                     $node->grab_value("distributions:$dname")
                    ) ;
    }
    return 1;
}

Config::Model commands to manage configuration upgrade

{i} These commands are not specific to Debian and can be applied to other distros or OS.

Let's start with a simple approx.conf file:

debian          http://ftp.fr.debian.org/debian
$max_wait       12

Simple upgrade case

In most cases, simply running config-edit will be enough to upgrade a configuration files. Even if the configuration model is changed from package version N to version N+1, the upgrade will work most to the time. config-edit will exit on error if some data to upgrade are not recognized.

Upgrading the configuration is done by postinst script with

   config-edit -model Approx -ui none -save

config-edit will:

/!\ Without Augeas and a dedicated lens for approx, original comments will be lost during an upgrade

After upgrade, approx.conf has:

# This file was written by Config::Model with Approx model
# You may modify the content of this file. Configuration
# modification will be preserved. Modification in the comments
# will be discarded

# max_rate:maximum download rate from remote repositories

# max_redirects:maximum number of HTTP redirections (5)

# user:user that owns the files in the approx cache (approx)

# group:group that owns the files in the approx cache (approx)

# syslog:syslog(3) facility to use when logging (daemon)

# pdiffs:support IndexFile diffs (1)

# offline:use cached files when offline (0)

# max_wait:max wait for concurrent file download (10)
$max_wait   12

# verbose: (0)

# debug: (0)

# remote repositories
debian     http://ftp.fr.debian.org/debian

More complex upgrade

See PackageConfigComplexUpgrade

Integrate simple upgrade command in package scripts

To get configuration upgrade on package upgrade, approx package needs to be modified this way:

    config-edit -model Approx -ui none -save 

debian/config-model/Approx.pm usr/share/perl5/Config/Model
debian/config-model/model/Approx.pl usr/share/perl5/Config/Model/models

/!\ FIXME: Define what can be done if config-edit fails. Should we abort of retry with -force option which discard invalid data ? Should user be queried with debconf ou should -force option always be used ?

The cherry on the pie

With the addition proposed above, your user will also get a GUI to edit approx.conf when running config-edit -model Approx:

gui.png

Simple upgrade cases

package installation or upgrade

During installation of approx package, existing approx.conf (application version N) are upgraded by Config::Model using configuration model from version N+1.

package downgrade

Mostly the same scenario as upgrade apply. The configuration data for N+1 are digested by Config::Model using configuration model from N.

/!\ If N+1 did obsolete or migrate parameters, some informations will be lost.

dh_config_model_upgrade

The approx package modification described above can also be done with a new dh helper script: dh_config_model_upgrade

The synopsis is

 dh_config_model_upgrade [ -p pkg ]
 [ debhelper options ] [ -model_name xx ] [ -model_package xx [ -model_version yy ] ]

The complete doc is written in pod and can be seen at the end of the source code in svn

{i} This probably can be better integrated in CDBS. Suggestions are welcome

{i} dh_config_model_upgrade is a work in progress that could use feedback from experienced Debian developers

Limitations

User comments

When upgrading, the original layout and the user comments are not preserved. approx.conf is written back in a canonical order specified by the model. I.e. all parameters are written back using the parameter order of Approx model. Most casual users will not mind as they are reluctant to manually edit file in /etc. But advanced users may frown upon the loss of their comments.

That said, there are several possibility to address this problem:

Examples

Approx

This simple patch will use the brand new lib-config-model-approx-perl to provide the upgrade capacity.

The patch features:

To try this example, you will have to:

The author hereby humbly admits that he could not figure out how to use dh_config_model_upgrade in the cdbs scripts used by Approx :\

As an exercise, one can also provide the configuration model within approx package. Thus the upgrade capacity may not depend on a dedicated model package.

The patch will add:

To try this example, you will have to:

If you want to modify Approx configuration model provided by the approx-add-model patch, use the following command:

$ config-model-edit -dir debian/config-model/models -model Approx

OpenSsh

Let's modify OpenSsh packages to use dh_config_model_upgrade script. Unlike Approx, the configuration model is already provided in Debian, so there's no need to include it in a patch.

The modifications are: * Update rules file so that build openssh-server package will call dh_config_model_upgrade * Some small modification to make openssh package work with dh_*

Let's view the call to dh_config_model_upgrade:

        dh_config_model_upgrade --model_name Sshd -p openssh-server \
           --model_package --model_version 1.206

This command will modify postinst using Sshd configuration model provided by package libconfig-model-openssh-perl (with version >> 1.206).

That's it. There's no need to do more. See dh-cm-upgrade.patch patch

/!\ dh_config_model_upgrade cannot be called for openssh-client, because package upgrade cannot upgrade user's configuration (except when they explicitly volunteer - see ikiwiki-mass-rebuild(8) in the ikiwiki package for an example).

Other packages based on dh

Packages using tiny rules should use the --with config_model option. E.g:

%:
         dh --with config_model $@

and provide a debian/<pkg>.config-model file.

See this example for open-ssh server package:

$ cat debian/openssh-server.config-model
model_name: Sshd
model_package: lib-config-model-openssh-perl
model_version: 1.206

Open questions

Working with Debconf

Warning: work in progress

Main ideas:

Fortunately, the semantic of Config::Model value_type mostly matches debconf's type:

Thanks



CategoryDebianDevelopment

  1. Preserving comments is very hard because associating comments with configuration data is guesswork (1)

PackageConfigUpgrade (last edited 2009-12-01 12:13:46 by DominiqueDumont)