[libconfig-model-dpkg-perl] 07/10: add support for Autopkgtest

dod at debian.org dod at debian.org
Mon Nov 13 17:29:41 UTC 2017


This is an automated email from the git hooks/post-receive script.

dod pushed a commit to branch master
in repository libconfig-model-dpkg-perl.

commit 2d03cfc0e976d1814b55d420f4195e87f29c1cfb
Author: Dominique Dumont <dod at debian.org>
Date:   Fri Nov 10 19:15:21 2017 +0100

    add support for Autopkgtest
---
 lib/Config/Model/Backend/Dpkg/Autopkgtest.pm   | 167 +++++++++++++++++++++++++
 lib/Config/Model/models/Dpkg.pl                |  17 +++
 lib/Config/Model/models/Dpkg/Control/Source.pl |   2 +-
 lib/Config/Model/models/Dpkg/Tests/Control.pl  | 105 ++++++++++++++++
 4 files changed, 290 insertions(+), 1 deletion(-)

diff --git a/lib/Config/Model/Backend/Dpkg/Autopkgtest.pm b/lib/Config/Model/Backend/Dpkg/Autopkgtest.pm
new file mode 100644
index 0000000..a570127
--- /dev/null
+++ b/lib/Config/Model/Backend/Dpkg/Autopkgtest.pm
@@ -0,0 +1,167 @@
+package Config::Model::Backend::Dpkg::Autopkgtest;
+
+use strict;
+use warnings;
+use Mouse;
+
+extends 'Config::Model::Backend::Any';
+
+with 'Config::Model::Backend::DpkgSyntax';
+with 'Config::Model::Backend::DpkgStoreRole';
+
+use 5.20.1;
+
+use feature qw/postderef signatures/;
+no warnings qw/experimental::postderef experimental::signatures/;
+
+use Carp;
+use Config::Model::Exception;
+use Log::Log4perl qw(get_logger :levels);
+use IO::File;
+
+my $logger = get_logger("Backend::Dpkg::Autopkgtest");
+
+sub suffix { return ''; }
+
+sub read {
+    my $self = shift;
+    my %args = @_;
+
+    # args is:
+    # object     => $obj,         # Config::Model::Node object
+    # root       => './my_test',  # fake root directory, userd for tests
+    # config_dir => /etc/foo',    # absolute path
+    # file       => 'foo.conf',   # file name
+    # file_path  => './my_test/etc/foo/foo.conf'
+    # io_handle  => $io           # IO::File object
+    # check      => yes|no|skip
+
+    # io_handle is not defined as no file is specified in model
+
+    return 0 unless defined $args{io_handle} ;
+
+    $logger->info("Parsing $args{file_path}");
+    # load autopkgtest control file
+    my $c = $self -> parse_dpkg_file ($args{file_path}, $args{io_handle}, $args{check}, 1 ) ;
+
+    Config::Model::Exception::Syntax->throw(
+        message => "More than 1 section in $args{file_path}",
+        parsed_file => $args{file_path},
+    )
+          if @$c > 2; # $c contains [ line_nb, section_ref ]
+
+    my ( $section_line, $section ) = @$c;
+    my $node = $args{object};
+    my $check = $args{check};
+
+    foreach ( my $i = 0 ; $i < $#$section ; $i += 2 ) {
+        my $key = $section->[$i];
+        my $v_ref = $section->[ $i + 1 ];
+        if ( my $found = $node->find_element( $key, case => 'any' ) ) {
+            my $elt = $found ;
+            my $to_store = $v_ref;
+
+            my $elt_obj = $node->fetch_element($elt);
+            if ($node->element_type($elt) eq 'list') {
+                $self->store_section_list_element ( $logger, $elt_obj, $check, $to_store);
+            }
+            else {
+                $self->store_section_leaf_element ( $logger, $elt_obj, $check, $to_store);
+            }
+        }
+        else {
+            warn "Unknown parameter found in $args{file_path}: $key";
+        }
+    }
+
+    return 1;
+}
+
+sub write {
+    my $self = shift;
+    my %args = @_;
+
+    # args is:
+    # object     => $obj,         # Config::Model::Node object
+    # root       => './my_test',  # fake root directory, userd for tests
+    # config_dir => /etc/foo',    # absolute path
+    # file       => 'foo.conf',   # file name
+    # file_path  => './my_test/etc/foo/foo.conf'
+    # io_handle  => $io           # IO::File object
+
+    # io_handle is not defined as no file is specified in model
+
+    croak "Undefined file handle to write"
+      unless defined $args{io_handle} ;
+
+    my $node = $args{object} ;
+    my $io  = $args{io_handle} ;
+
+    # write all parameters
+    foreach my $elt ( $node -> get_element_name ) {
+        my $v =  $node->fetch_element($elt)->fetch;
+
+        next unless defined $v;
+
+        $io->print("$elt: ");
+        $self->write_dpkg_text($io,$v) ;
+    }
+
+    return 1;
+}
+
+1;
+
+__END__
+
+=head1 NAME
+
+Config::Model::Backend::Dpkg::Autopkgtest - Read and write Debian Dpkg Autopkgtest information
+
+=head1 SYNOPSIS
+
+No synopsis. This class is dedicated to configuration class C<Dpkg::Autopkgtest>
+
+=head1 DESCRIPTION
+
+This module is used directly by L<Config::Model> to read or write the
+content of Debian C<Autopkgtest> file.
+
+All C<Autopkgtest> files keyword are read in a case-insensitive manner.
+
+=head1 CONSTRUCTOR
+
+=head2 new ( node => $node_obj, name => 'Dpkg::Autopkgtest' ) ;
+
+Inherited from L<Config::Model::Backend::Any>. The constructor will be
+called by L<Config::Model::AutoRead>.
+
+=head2 read ( io_handle => ... )
+
+Of all parameters passed to this read call-back, only C<io_handle> is
+used. This parameter must be L<IO::File> object already opened for
+read. 
+
+It can also be undef. In this case, C<read()> will return 0.
+
+When a file is read,  C<read()> will return 1.
+
+=head2 write ( io_handle => ... )
+
+Of all parameters passed to this write call-back, only C<io_handle> is
+used. This parameter must be L<IO::File> object already opened for
+write. 
+
+C<write()> will return 1.
+
+=head1 AUTHOR
+
+Dominique Dumont, (ddumont at cpan dot org)
+
+=head1 SEE ALSO
+
+L<Config::Model>, 
+L<Config::Model::AutoRead>, 
+L<Config::Model::Backend::Any>, 
+
+=cut
diff --git a/lib/Config/Model/models/Dpkg.pl b/lib/Config/Model/models/Dpkg.pl
index c0c6993..732743c 100644
--- a/lib/Config/Model/models/Dpkg.pl
+++ b/lib/Config/Model/models/Dpkg.pl
@@ -221,6 +221,23 @@ By default, it will include all existing files in the top-level source directory
         'description' => 'watch file used by L<uscan> to monitor upstream sources',
         'type' => 'leaf',
         'value_type' => 'string'
+      },
+      'test-control',
+      {
+        'config_class_name' => 'Dpkg::Tests::Control',
+        'level' => 'hidden',
+        'type' => 'warped_node',
+        'warp' => {
+          'follow' => {
+            'testsuite' => '- control source Testsuite'
+          },
+          'rules' => [
+            'not $testsuite',
+            {
+              'level' => 'normal'
+            }
+          ]
+        }
       }
     ],
     'license' => 'LGPL2',
diff --git a/lib/Config/Model/models/Dpkg/Control/Source.pl b/lib/Config/Model/models/Dpkg/Control/Source.pl
index 19d54da..a64a516 100644
--- a/lib/Config/Model/models/Dpkg/Control/Source.pl
+++ b/lib/Config/Model/models/Dpkg/Control/Source.pl
@@ -157,7 +157,7 @@ $_ = $str ? \'autopkgtest-pkg-\'.$str : undef;',
           'team-test' => {
             'code' => 'my $m = $self->grab_value(\'- Maintainer\');
 my ($team) = ( $m =~ /(pkg-(?:perl|ruby|go))/ );
-not defined $_ or not defined $team or $_ eq \'autopkgtest-\'.$team ;',
+not defined $_ or not defined $team or $_ eq \'autopkgtest-\'.$team  or -e \'debian/tests/control\';',
             'fix' => 'my $m = $self->grab_value(\'- Maintainer\');
 my ($str) = ($m =~ /pkg-(perl|ruby|go)/);
 $_ = $str ? \'autopkgtest-pkg-\'.$str : undef;',
diff --git a/lib/Config/Model/models/Dpkg/Tests/Control.pl b/lib/Config/Model/models/Dpkg/Tests/Control.pl
new file mode 100644
index 0000000..43200a4
--- /dev/null
+++ b/lib/Config/Model/models/Dpkg/Tests/Control.pl
@@ -0,0 +1,105 @@
+[
+  {
+    'class_description' => 'describes how autopkgtest interprets and executes tests found in Debian source packages.
+
+See L<https://people.debian.org/~mpitt/autopkgtest/README.package-tests.html>',
+    'element' => [
+      'Tests',
+      {
+        'cargo' => {
+          'type' => 'leaf',
+          'value_type' => 'uniline'
+        },
+        'type' => 'list'
+      },
+      'Test-Command',
+      {
+        'type' => 'leaf',
+        'value_type' => 'uniline'
+      },
+      'Restrictions',
+      {
+        'choice' => [
+          'rw-build-tree',
+          'breaks-testbed',
+          'needs-root',
+          'build-needed',
+          'allow-stderr',
+          'isolation-container',
+          'isolation-machine',
+          'needs-reboot',
+          'needs-recommends'
+        ],
+        'description' => 'Declares some restrictions or problems with the tests defined in this stanza. Depending on the test environment capabilities, user requests, and so on, restrictions can cause tests to be skipped or can cause the test to be run in a different manner.',
+        'help' => {
+          'allow-stderr' => 'Output to stderr is not considered a failure. This is useful for tests which write e. g. lots of logging to stderr.',
+          'breaks-testbed' => 'The test, when run, is liable to break the testbed system. This includes causing data loss, causing services that the machine is running to malfunction, or permanently disabling services; it does not include causing services on the machine to temporarily fail.
+
+When this restriction is present the test will usually be skipped unless the testbed\'s virtualisation arrangements are sufficiently powerful, or alternatively if the user explicitly requests.
+',
+          'build-needed' => 'The tests need to be run from a built source tree. The test runner will build the source tree (honouring the source package\'s build dependencies), before running the tests. However, the tests are not entitled to assume that the source package\'s build dependencies will be installed when the test is run.
+
+Please use this considerately, as for large builds it unnecessarily builds the entire project when you only need a tiny subset (like the tests/ subdirectory). It is often possible to run C<make -C tests> instead, or copy the test code to C<$AUTOPKGTEST_TMP> and build it there with some custom commands. This cuts down the load on the Continuous Integration servers and also makes tests more robust as it prevents accidentally running them against the built source tree instead of the install [...]
+',
+          'isolation-container' => 'The test wants to start services or open network TCP ports. This commonly fails in a simple chroot/schroot, so tests need to be run in their own container (e. g. autopkgtest-virt-lxc) or their own machine/VM (e. g. autopkgtest-virt-qemu or autopkgtest-virt-null). When running the test in a virtualization server which does not provide this (like autopkgtest-schroot) it will be skipped.',
+          'isolation-machine' => 'The test wants to interact with the kernel, reboot the machine, or other things which fail in a simple schroot and even a container. Those tests need to be run in their own machine/VM (e. g. autopkgtest-virt-qemu or autopkgtest-virt-null). When running the test in a virtualization server which does not provide this it will be skipped.',
+          'needs-reboot' => 'The test wants to reboot the machine using /tmp/autopkgtest-reboot. See L<https://people.debian.org/~mpitt/autopkgtest/README.package-tests.html>',
+          'needs-recommends' => 'Enable installation of recommended packages in apt for the test dependencies. This does not affect build dependencies.',
+          'needs-root' => 'The test script must be run as root.',
+          'rw-build-tree' => 'The test(s) needs write access to the built source tree (so it may need to be copied first). Even with this restriction, the test is not allowed to make any change to the built source tree which (i) isn\'t cleaned up by debian/rules clean, (ii) affects the future results of any test, or (iii) affects binary packages produced by the build tree in the future.'
+        },
+        'type' => 'check_list'
+      },
+      'Features',
+      {
+        'description' => '    Declares some additional capabilities or good properties of the tests defined in this stanza. Any unknown features declared will be completely ignored. See below for the defined features.
+',
+        'type' => 'leaf',
+        'value_type' => 'uniline'
+      },
+      'Depends',
+      {
+        'default' => '@',
+        'description' => 'Declares that the specified packages must be installed for the test to go ahead. This supports all features of dpkg dependencies (see L<https://www.debian.org/doc/debian-policy/ch-relationships.html>), plus the following extensions:
+
+@ stands for the package(s) generated by the source package containing the tests; each dependency (strictly, or-clause, which may contain |s but not commas) containing @ is replicated once for each such binary package, with the binary package name substituted for each @ (but normally @ should occur only once and without a version restriction).
+
+ at builddeps@ will be replaced by the package\'s C<Build-Depends:>, C<Build-Depends-Indep:>, and build-essential. This is useful if you have many build dependencies which are only necessary for running the test suite and you don\'t want to replicate them in the test C<Depends:>. However, please use this sparingly, as this can easily lead to missing binary package dependencies being overlooked if they get pulled in via build dependencies.
+
+If no Depends field is present, C<Depends: @> is assumed. Note that the source tree\'s Build-Dependencies are not necessarily installed, and if you specify any Depends, no binary packages from the source are installed unless explicitly requested.
+',
+        'type' => 'leaf',
+        'value_type' => 'string'
+      },
+      'Tests-Directory',
+      {
+        'description' => 'Replaces the path segment debian/tests in the filenames of the test programs with path. I. e., the tests are run by executing built/source/tree/path/testname. path must be a relative path and is interpreted starting from the root of the built source tree.
+
+This allows tests to live outside the debian/ metadata area, so that they can more palatably be shared with non-Debian distributions.
+',
+        'type' => 'leaf',
+        'value_type' => 'uniline'
+      },
+      'Classes',
+      {
+        'description' => 'Most package tests should work in a minimal environment and are usually not hardware specific. However, some packages like the kernel, X.org, or graphics drivers should be tested on particular hardware, and also run on a set of different platforms rather than just a single virtual testbeds.
+
+This field can specify a list of abstract class names such as "desktop" or "graphics-driver". Consumers of autopkgtest can then map these class names to particular machines/platforms/policies. Unknown class names should be ignored.
+
+This is purely an informational field for autopkgtest itself and will be ignored.',
+        'type' => 'leaf',
+        'value_type' => 'uniline'
+      }
+    ],
+    'name' => 'Dpkg::Tests::Control',
+    'rw_config' => {
+      'auto_create' => '1',
+      'auto_delete' => '1',
+      'backend' => 'Dpkg::Autopkgtest',
+      'config_dir' => 'debian/tests',
+      'file' => 'control'
+    }
+  }
+]
+;
+

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libconfig-model-dpkg-perl.git



More information about the Pkg-perl-cvs-commits mailing list