Differences between revisions 41 and 42
Revision 41 as of 2009-09-14 12:30:14
Size: 19653
Comment: Added openssh example
Revision 42 as of 2009-09-14 12:32:30
Size: 19659
Comment: Fix attachment name
Deletions are marked like this. Additions are marked like this.
Line 355: Line 355:
That's it. There's no need to do more. See [[attachment:dh-cm-upgrade]] patch That's it. There's no need to do more. See [[attachment:dh-cm-upgrade.patch]] patch

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 :

  • The structure of the configuration model. This structure is a tree that can be flat (for simple files like approx.conf) or quite deep (for complex configuration like xorg.conf). The configuration tree nodes are instances of configuration class and the tree leaves contain the configuration values.

  • The constraints of the leaf values (i.e. integer, enum type, min values, max values ...)

  • the default values where the default value must be written in the configuration file.

  • the built-in default value where the value need not be written in the configuration file. This default value is built in the application.

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:

  • Upgrade the packages files as usual (including upgrade of configuration model)
  • In postinst, run config-edit to load old configuration file using new configuration model and write back the updated data in new configuration file (i.e. merged values from user's data and data from new configuration model).

  • If the last step fails, launch config-edit in interactive mode (using Debconf as a user interface ?) or fall-back to ucf (any other alternative ?)

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:

  • 10 configuration parameters, either boolean, integer or string. All of them have default built in approx.
  • a hash containing distribution names and their URL. These will be modeled with a hash of uniline values

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:

  • parse the old configuration file
  • validate all values (possibly discarding or migrating obsolete parameters) FIXME add link to details
  • add new values declared in N+1 model (if any)
  • write back the configuration file (-save option)

/!\ 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:

  • addition of Approx model file (debian/config-model/Approx.pm)

  • addition of Approx reader/writer (debian/config-model/model/Approx.pl)

  • modification of debian/approx.postinst with addition of:

    config-edit -model Approx -ui none -save 
  • addition of the following lines in debian/approx.install:

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} 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:

  • Comments can be preserved only if Augeas is used with Config::Model. For this, a lens must be created for approx.conf. This is another layer of abstraction which is not really easy to grasp, thus more work for package maintainers if the lens is not provided by Augeas.

  • Some information regarding Approx parameters are written as comments by Config::Model. Thus the produced configuration file have some comments to provide the summary or description information stored in Approx model. But, without Augeas, Config::Model cannot preserve modifications done to comments1.

  • Config::Model will be enhanced to offer annotation through the GUI. This annotation will serve the same purpose as comments in the file but would be stored elsewhere.
  • Should we offer to skip upgrade part for users that want to keep the comments ? (if they want to keep the comments, they are probably able to manually upgrade their configuration)

I want to try

=== Approx ==

The author hereby humble admits that he could not fi

To try this upgrade proposal, you will have to:

  • apt-get install libconfig-model-perl (>= 0.637) from Sid/unstable or Karmic

  • apt-get build-dep approx

  • apt-get source approx

  • apply upgrade-minimal.patch in approx source directory (path -p1 < dh-upgrade.patch)

  • build the package (dpkg-buildpackage -uc -us)

  • install the new package (this installation will trigger the upgrade done by Config::Model)

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

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

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 :\

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 (yet ?).

Open questions

  • How to handle errors in user's approx.conf file ?
    • Should bad data be discarded (possible with -force option of config-edit)

    • Should we skip data migration (as is done currently)
  • How to handle missing data ? (this scenario is not relevant with current Approx model, but may become relevant if mandatory values are added to Approx model). In this case, should Config::Model be run in approx.config script and connect to Debconf to ask question to user ? (Could use Config::Moldel::WizardHelper to scan configuration tree and ask question in case of error or missing mandatory values)

Thanks

  • To Damyan Ivanov (first review)
  • To Jonas Smedegaard for the constructive exchange and the helper scripts and /var/lib/ storage ideas
  • The Gregor Hermann for sponsoring all the libconfig-model-* packages



CategoryDebianDevelopment

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