#12 Add some basic testing, with dummy rpm creation and simple README
Merged 8 years ago by . Opened 8 years ago by maxamillion.
maxamillion/pungi add_tests  into  master

file modified
+13 -5
@@ -922,7 +922,6 @@ 

                  pprint.pformat(list(sorted(failed)))))

              self.logger.info("Couldn't find %i of %i srpms." % (

                  len(failed), len(self.src_by_bin)))

-             raise RuntimeError("Could not find all srpms.")

  

      def add_srpms(self, po_list=None):

          """Cycle through the list of package objects and
@@ -932,11 +931,14 @@ 

          srpms = set()

          po_list = po_list or self.po_list

          for po in sorted(po_list):

-             srpm_po = self.sourcerpm_srpmpo_map[po.sourcerpm]

-             if srpm_po in self.completed_add_srpms:

+             try:

+                 srpm_po = self.sourcerpm_srpmpo_map[po.sourcerpm]

+             except KeyError:

+                 self.logger.error("Cannot get source RPM '%s' for %s" % (po.sourcerpm, po.nvra))

+                 srpm_po = None

+ 

+             if srpm_po is None:

                  continue

-             msg = "Added source package %s.%s (repo: %s)" % (srpm_po.name, srpm_po.arch, srpm_po.repoid)

-             self.add_source(srpm_po, msg)

  

              # flags

              if po in self.input_packages:
@@ -948,6 +950,12 @@ 

              if po in self.multilib_packages:

                  self.multilib_packages.add(srpm_po)

  

+             if srpm_po in self.completed_add_srpms:

+                 continue

+ 

+             msg = "Added source package %s.%s (repo: %s)" % (srpm_po.name, srpm_po.arch, srpm_po.repoid)

+             self.add_source(srpm_po, msg)

+ 

              self.completed_add_srpms.add(srpm_po)

              srpms.add(srpm_po)

          return srpms

file added
+44
@@ -0,0 +1,44 @@ 

+ Running pungi4 tests

+ 

+ Pungi4 is an utility to perform composes of rpms, as such we will need some

+ rpms to perform composes on.

+ 

+ In this directory you will find a small utility called 'createtestdata.py' that

+ takes two arguments, first is the package manifest JSON file that will contain

+ the list of packages that are architecture specific, the list of architectures

+ to build them for, and finally the packages that are noarch. (Don't worry about

+ your dev machine being the wrong arch as needed to be produced, we're using an

+ utility library called rpmfluff[0] that's faking a lot of this for us)

+ 

+ Before we run any tests we will need to create a repo to work with using the

+ 'createtestdata.py' script. NOTE: This script requires both the 'python-click

+ and 'python-rpmfluff' packages.

+ 

+     $ ./createtestdata.py --pkgfile pkgs.json --outdir .

+ 

+ You will now find a directory called ./repo in the current directory, this is

+ setup exactly as the pungi tests need it and you are now ready to run tests.

+ 

+ Next you will find a hand full of scripts named test_* and these are to run the

+ actual tests. There is also a small wrapper called 'run_all_tests.sh' that will

+ run all scripts prefixed with test_* in the current directory.

+ 

+     $ ./run_all_tests.sh

+ 

+ Or alternatively, select the tests you want to run and run them one by one:

+ 

+     $ ./test_arch.py

+     ......

+     ----------------------------------------------------------------------

+     Ran 6 tests in 0.001s

+ 

+     OK

+ 

+     $ ./test_pathmatch.py

+     ...

+     ----------------------------------------------------------------------

+     Ran 3 tests in 0.001s

+ 

+     OK

+ 

+ [0] - https://fedorahosted.org/rpmfluff/

@@ -0,0 +1,150 @@ 

+ #!/usr/bin/env python2

+ # -*- coding: utf-8 -*-

+ 

+ 

+ # This program is free software; you can redistribute it and/or modify

+ # it under the terms of the GNU General Public License as published by

+ # the Free Software Foundation; version 2 of the License.

+ #

+ # This program is distributed in the hope that it will be useful,

+ # but WITHOUT ANY WARRANTY; without even the implied warranty of

+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the

+ # GNU Library General Public License for more details.

+ #

+ # You should have received a copy of the GNU General Public License

+ # along with this program; if not, write to the Free Software

+ # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

+ 

+ import os

+ import tempfile

+ import shutil

+ import libcomps

+ from contextlib import contextmanager

+ 

+ #import pungi.phases.pkgsets.pkgsets

+ from rpmfluff import SimpleRpmBuild

+ 

+ # helpers for creating RPMs to test with

+ @contextmanager

+ def in_tempdir(outdir, prefix='_'):

+     """

+     py:class:: in_tempdir(prefix='_')

+ 

+     Context manager for the rpmbuild tempdir

+     """

+     oldcwd = os.getcwd()

+     tmpdir = tempfile.mkdtemp(prefix=prefix)

+     os.chdir(tmpdir)

+     yield

+     os.chdir(oldcwd)

+     shutil.rmtree(tmpdir)

+ 

+ @contextmanager

+ def in_dir(directory):

+     """

+     py:class:: in_dir(dir)

+ 

+     Context manager to handle things in a generic method

+     """

+     oldcwd = os.getcwd()

+     tmpdir = tempfile.mkdtemp()

+     os.chdir(tmpdir)

+     yield

+     os.chdir(oldcwd)

+ 

+ def make_rpm(outdir, archlist, name, version='1.0', release='1'):

+     """

+     py:function:: make_rpm(outdir, name='test', version='1.0', release='1', archlist=None)

+ 

+     Create the fake test rpms

+     """

+ 

+     if (archlist is None):

+         raise TypeError( "No defined architectures for make_rpm")

+ 

+     abs_outdir = os.path.abspath(outdir)

+ 

+     if not os.path.isdir(abs_outdir):

+         os.mkdir(abs_outdir)

+ 

+     p = SimpleRpmBuild(name, version, release, archlist)

+     with in_tempdir(abs_outdir, prefix="tmppkgs"):

+         p.make()

+ 

+         srpm_outdir = os.path.join(

+             abs_outdir,

+             "repo",

+             "src",

+         )

+ 

+         if not os.path.isdir(srpm_outdir):

+             os.makedirs(srpm_outdir)

+ 

+         srpmfile = p.get_built_srpm()

+         src_outfile = os.path.join(

+             os.path.abspath(abs_outdir),

+             "repo",

+             'src',

+             os.path.basename(srpmfile)

+         )

+         shutil.move(srpmfile, src_outfile)

+ 

+         for arch in archlist:

+ 

+             arch_outdir = os.path.join(

+                 abs_outdir,

+                 "repo",

+                 arch,

+             )

+             if not os.path.isdir(arch_outdir):

+                 os.makedirs(arch_outdir)

+ 

+ 

+             rpmfile = p.get_built_rpm(arch)

+             bin_outfile = os.path.join(

+                 os.path.abspath(abs_outdir),

+                 "repo",

+                 arch,

+                 os.path.basename(rpmfile)

+             )

+             shutil.move(rpmfile, bin_outfile)

+     return p

+ 

+ def get_rpm_list_from_comps(compspath):

+     """

+     py:function:: get_rpm_list_from_comps(compspath)

+ 

+     Return a list of rpms from a compsfile

+     """

+ 

+     pkg_list = []

+ 

+     comps = libcomps.Comps()

+     comps.fromxml_f(compspath)

+ 

+     for group in comps.groups:

+         for pkg in comps.groups[group.id].packages:

+             pkg_list.append(pkg.name)

+ 

+     return pkg_list

+ 

+ 

+ if __name__ == "__main__":

+     import click

+     import json

+ 

+     @click.command()

+     @click.option('--pkgfile', default=None, required=True,

+                   help="Path to json pkg file")

+     @click.option('--outdir', default=None, required=True,

+                   help="Directory to create temp dummy repo")

+     def createtestdata(pkgfile, outdir):

+         pkgdata = json.loads(open(pkgfile,'r').read())

+         for pkg in pkgdata['archpkgs']:

+             make_rpm(outdir, pkgdata['archs'], pkg)

+         for pkg in pkgdata['noarchpkgs']:

+             make_rpm(outdir, ['noarch'], pkg)

+ 

+         os.popen('/usr/bin/createrepo %s' % os.path.join(outdir, "repo"))

+ 

+     createtestdata()

file added
+163
@@ -0,0 +1,163 @@ 

+ <?xml version="1.0" encoding="UTF-8"?>

+ <!DOCTYPE comps PUBLIC "-//Red Hat, Inc.//DTD Comps info//EN" "comps.dtd">

+ <comps>

+ 

+   <!-- GROUPS -->

+ 

+   <group>

+     <id>core</id>

+     <name>Core</name>

+     <description>Smallest possible installation</description>

+     <default>true</default>

+     <uservisible>false</uservisible>

+     <packagelist>

+       <packagereq type="mandatory">dummy-bash</packagereq>

+     </packagelist>

+   </group>

+ 

+   <group>

+     <id>standard</id>

+     <name>Standard</name>

+     <description>Common set of utilities that extend the minimal installation.</description>

+     <default>false</default>

+     <uservisible>true</uservisible>

+     <packagelist>

+       <packagereq>dummy-lvm2</packagereq>

+     </packagelist>

+   </group>

+ 

+   <group>

+     <id>text-internet</id>

+     <name>Text-based Internet</name>

+     <description>This group includes text-based email, Web, and chat clients.  These applications do not require the X Window System.</description>

+     <default>false</default>

+     <uservisible>true</uservisible>

+     <packagelist>

+       <packagereq type="optional">dummy-elinks</packagereq>

+       <packagereq type="optional">dummy-tftp</packagereq>

+     </packagelist>

+   </group>

+ 

+   <group>

+     <id>firefox</id>

+     <name>Firefox Web Browser</name>

+     <description>The Firefox web browser</description>

+     <default>false</default>

+     <uservisible>false</uservisible>

+     <packagelist>

+       <packagereq>dummy-firefox</packagereq>

+       <packagereq>dummy-icedtea-web</packagereq>

+     </packagelist>

+   </group>

+ 

+   <group arch="i386 x86_64">

+     <id>skype</id>

+     <name>Skype</name>

+     <description>Free internet telephony</description>

+     <default>false</default>

+     <uservisible>true</uservisible>

+     <packagelist>

+       <packagereq>dummy-skype</packagereq>

+     </packagelist>

+   </group>

+ 

+   <group arch="x86_64">

+     <id>resilient-storage</id>

+     <name>Resilient Storage</name>

+     <description>Clustered storage, including the GFS2 filesystem.</description>

+     <default>false</default>

+     <uservisible>true</uservisible>

+     <packagelist>

+       <packagereq type="mandatory">dummy-gfs2-utils</packagereq>

+       <packagereq type="mandatory">dummy-lvm2-cluster</packagereq>

+       <packagereq type="mandatory">dummy-pacemaker</packagereq>

+       <packagereq type="mandatory">dummy-resource-agents</packagereq>

+     </packagelist>

+   </group>

+ 

+   <group>

+     <id>gluster</id>

+     <name>Gluster</name>

+     <description>GlusterFS support packages</description>

+     <default>false</default>

+     <uservisible>true</uservisible>

+     <packagelist>

+       <packagereq type="mandatory">dummy-glusterfs-resource-agents</packagereq>

+     </packagelist>

+   </group>

+ 

+   <group>

+     <id>basic-desktop</id>

+     <name>Desktop</name>

+     <description>Basic Desktop packages</description>

+     <default>true</default>

+     <uservisible>true</uservisible>

+     <packagelist>

+       <packagereq type="conditional" requires="dummy-imsettings">dummy-imsettings-gnome</packagereq>

+     </packagelist>

+   </group>

+ 

+   <!-- ENVIRONMENTS -->

+ 

+   <environment>

+     <id>minimal</id>

+     <name>Minimal install</name>

+     <description>Basic functionality.</description>

+     <display_order>99</display_order>

+     <grouplist>

+       <groupid>core</groupid>

+     </grouplist>

+     <optionlist>

+     </optionlist>

+   </environment>

+ 

+   <environment>

+     <id>desktop</id>

+     <name>Desktop</name>

+     <description>Desktop.</description>

+     <display_order>10</display_order>

+     <grouplist>

+       <groupid>core</groupid>

+       <groupid>standard</groupid>

+       <groupid>basic-desktop</groupid>

+     </grouplist>

+     <optionlist>

+     </optionlist>

+   </environment>

+ 

+   <environment>

+     <id>empty</id>

+     <name>Empty</name>

+     <description>Should not appear in the repos.</description>

+     <display_order>10</display_order>

+     <grouplist>

+       <groupid>does-not-exist</groupid>

+     </grouplist>

+   </environment>

+ 

+   <!-- LANGPACKS -->

+ 

+   <langpacks>

+     <match install="LabPlot-doc-%s" name="LabPlot-doc"/>

+     <match install="aspell-%s" name="aspell"/>

+     <match install="autocorr-%s" name="autocorr-en"/>

+     <match install="calligra-l10n-%s" name="calligra-core"/>

+     <match install="childsplay-alphabet_sounds_%s" name="childsplay"/>

+     <match install="eclipse-nls-%s" name="eclipse-platform"/>

+     <match install="firefox-langpack-%s" name="firefox"/>

+     <match install="gcompris-sound-%s" name="gcompris"/>

+     <match install="gimp-help-%s" name="gimp-help"/>

+     <match install="hunspell-%s" name="hunspell"/>

+     <match install="hyphen-%s" name="hyphen"/>

+     <match install="kde-l10n-%s" name="kdelibs"/>

+     <match install="kde-i18n-%s" name="kdelibs3"/>

+     <match install="libreoffice-langpack-%s" name="libreoffice-core"/>

+     <match install="man-pages-%s" name="man-pages"/>

+     <match install="moodle-%s" name="moodle"/>

+     <match install="mythes-%s" name="mythes"/>

+     <match install="nqc-doc-%s" name="nqc-doc"/>

+     <match install="openoffice.org-langpack-%s" name="openoffice.org-core"/>

+     <match install="tesseract-langpack-%s" name="tesseract"/>

+     <match install="tkgate-%s" name="tkgate"/>

+   </langpacks>

+ </comps>

file added
+139
@@ -0,0 +1,139 @@ 

+ # PRODUCT (RELEASE) INFO

+ product_name = "Dummy Product"

+ product_short = "DP"

+ product_version = "1.0"

+ product_is_layered = False

+ product_type = "ga"

+ 

+ 

+ # GENERAL SETTINGS

+ bootable = False

+ comps_file = "dummy-comps.xml"

+ variants_file = "dummy-variants.xml"

+ sigkeys = [None] # None = unsigned

+ 

+ # limit tree architectures

+ # if undefined, all architectures from variants.xml will be included

+ atree_arches = ["x86_64"]

+ 

+ # limit tree variants

+ # if undefined, all variants from variants.xml will be included

+ #tree_variants = ["Server"]

+ 

+ multilib_arches = ["ppc64", "x86_64", "s390x"]

+ multilib_methods = ["devel", "runtime"] # devel (recommended), all, base, file, kernel, none, runtime

+ 

+ 

+ # RUNROOT settings

+ runroot = False

+ #runroot_channel = ""

+ #runroot_tag = ""

+ 

+ 

+ # PKGSET

+ pkgset_source = "repos" # koji, repos

+ 

+ # PKGSET - REPOS

+ # pkgset_repos format: {arch: [repo1_url, repo2_url, ...]}

+ pkgset_repos = {

+     "i386": [

+         "repo",

+     ],

+     "x86_64": [

+         "repo",

+     ],

+     "s390x": [

+         "repo",

+     ],

+ }

+ 

+ # PKGSET - KOJI

+ #pkgset_koji_path_prefix = "/mnt/koji"

+ #pkgset_koji_url = ""

+ #pkgset_koji_tag = ""

+ 

+ 

+ # GATHER

+ gather_source = "comps"

+ gather_method = "deps"

+ check_deps = False

+ greedy_method = "build"

+ 

+ # fomat: [(variant_uid_regex, {arch|*: [repos]})]

+ # gather_lookaside_repos = []

+ 

+ # GATHER - JSON

+ # format: {variant_uid: {arch: package: [arch1, arch2, None (for any arch)]}}

+ #gather_source_mapping = "/path/to/mapping.json"

+ 

+ 

+ # CREATEREPO

+ # TODO: checksum type - mandatory

+ createrepo_c = True

+ 

+ 

+ # BUILDINSTALL

+ 

+ 

+ # PRODUCTIMG

+ 

+ 

+ # CREATEISO

+ create_optional_isos = False

+ symlink_isos_to = None

+ 

+ 

+ # fomat: [(variant_uid_regex, {arch|*: [packages]})]

+ additional_packages = [

+     ('^Server$', {

+         '*': [

+ #            'dummy-lvm2-devel',

+              'dummy-libtool',

+         ],

+     }),

+     ('^Client-optional$', {

+         '*': [

+             'dummy-httpd',

+         ],

+     }),

+ ]

+ 

+ filter_packages = [

+     ('^.*$', {

+         '*': [

+             'dummy-pacemaker',

+         ],

+     }),

+     ('^Client$', {

+         '*': [

+             'dummy-httpd',

+         ],

+     }),

+     ('^Server-optional$', {

+         '*': [

+             'dummy-httpd.i686',

+         ],

+     }),

+     ('^.*-ResilientStorage$', {

+         '*': [

+             'dummy-glusterfs-resource-agents',

+         ],

+     }),

+ ]

+ 

+ 

+ # format: {arch|*: [packages]}

+ multilib_blacklist = {

+     "*": [

+         "kernel-devel",

+         "httpd-devel",

+         "*",

+ #        "dummy-glibc",

+     ],

+ }

+ 

+ multilib_whitelist = {

+     "*": [

+         "dummy-glibc",

+     ],

+ }

@@ -0,0 +1,70 @@ 

+ <?xml version="1.0" encoding="UTF-8"?>

+ <!DOCTYPE variants PUBLIC "-//Red Hat, Inc.//DTD Variants info//EN" "variants.dtd">

+ 

+ <variants>

+   <variant id="ResilientStorage" name="Resilient Storage" type="addon">

+     <arches>

+       <arch>x86_64</arch>

+     </arches>

+     <groups>

+       <group default="true">resilient-storage</group>

+     </groups>

+   </variant>

+ 

+   <variant id="Gluster" name="Gluster Layered Product" type="layered-product">

+     <product name="Gluster" version="2.3" short="Gluster" />

+     <arches>

+       <arch>x86_64</arch>

+     </arches>

+     <groups>

+       <group default="true">gluster</group>

+     </groups>

+   </variant>

+ 

+   <variant id="Client" name="Client" type="variant" has_optional="true">

+     <arches>

+       <arch>i386</arch>

+       <arch>x86_64</arch>

+     </arches>

+     <groups>

+       <group default="true">core</group>

+       <group default="true">standard</group>

+       <group default="false">text-internet</group>

+       <group default="true" uservisible="false">firefox</group>

+       <group>skype</group>

+     </groups>

+     <environments>

+       <environment>minimal</environment>

+       <environment display_order="1000">desktop</environment>

+     </environments>

+   </variant>

+ 

+   <variant id="Server" name="Server" type="variant" has_optional="true">

+     <arches>

+       <arch>x86_64</arch>

+       <arch>s390x</arch>

+     </arches>

+     <groups>

+       <group default="true" uservisible="true">core</group>

+       <group default="true">standard</group>

+       <group default="true">text-internet</group>

+     </groups>

+     <environments>

+       <environment>minimal</environment>

+     </environments>

+     <variants>

+       <ref id="ResilientStorage"/>

+       <ref id="Gluster"/>

+       <variant id="optional" name="optional" type="optional">

+         <arches>

+           <arch>x86_64</arch>

+           <arch>s390x</arch>

+         </arches>

+         <groups>

+           <group default="false">firefox</group>

+         </groups>

+       </variant>

+     </variants>

+   </variant>

+ 

+ </variants>

file added
+116
@@ -0,0 +1,116 @@ 

+ {

+     "archpkgs" : [

+         "dummy-AdobeReader_enu",

+         "dummy-atlas",

+         "dummy-atlas-3dnow",

+         "dummy-atlas-3dnow-devel",

+         "dummy-atlas-devel",

+         "dummy-atlas-sse",

+         "dummy-atlas-sse2",

+         "dummy-atlas-sse2-devel",

+         "dummy-atlas-sse3",

+         "dummy-atlas-sse3-devel",

+         "dummy-atlas-sse-devel",

+         "dummy-atlas-z10",

+         "dummy-atlas-z10-devel",

+         "dummy-atlas-z196",

+         "dummy-atlas-z196-devel",

+         "dummy-basesystem",

+         "dummy-bash",

+         "dummy-bash-debuginfo",

+         "dummy-bash-doc",

+         "dummy-elinks",

+         "dummy-elinks-debuginfo",

+         "dummy-fcoe-target-utils",

+         "dummy-filesystem",

+         "dummy-firefox",

+         "dummy-firefox-debuginfo",

+         "dummy-foo32",

+         "dummy-foo32-doc",

+         "dummy-freeipa",

+         "dummy-freeipa-server",

+         "dummy-gfs2-utils",

+         "dummy-gfs2-utils-debuginfo",

+         "dummy-glibc",

+         "dummy-glibc-common",

+         "dummy-glibc-debuginfo",

+         "dummy-glibc-debuginfo-common",

+         "dummy-glusterfs-resource-agents",

+         "dummy-httpd",

+         "dummy-httpd-debuginfo",

+         "dummy-imsettings",

+         "dummy-imsettings-gnome",

+         "dummy-imsettings-qt",

+         "dummy-ipw3945-kmod",

+         "dummy-ipw3945-kmod-debuginfo",

+         "dummy-kernel",

+         "dummy-kernel-doc",

+         "dummy-kernel-headers",

+         "dummy-kmod-ipw3945",

+         "dummy-kmod-ipw3945-xen",

+         "dummy-krb5",

+         "dummy-krb5-debuginfo",

+         "dummy-krb5-devel",

+         "dummy-krb5-libs",

+         "dummy-krb5-workstation",

+         "dummy-lvm2",

+         "dummy-lvm2-cluster",

+         "dummy-lvm2-debuginfo",

+         "dummy-lvm2-devel",

+         "dummy-lvm2-libs",

+         "dummy-nscd",

+         "dummy-postfix",

+         "dummy-postfix-debuginfo",

+         "dummy-release-client",

+         "dummy-release-client-workstation",

+         "dummy-release-notes",

+         "dummy-release-notes-cs-CZ",

+         "dummy-release-notes-en-US",

+         "dummy-release-server",

+         "dummy-resource-agents",

+         "dummy-resource-agents-debuginfo",

+         "dummy-selinux-policy",

+         "dummy-selinux-policy-doc",

+         "dummy-selinux-policy-minimal",

+         "dummy-selinux-policy-mls",

+         "dummy-selinux-policy-targeted",

+         "dummy-sendmail",

+         "dummy-sendmail-debuginfo",

+         "dummy-skype",

+         "dummy-tftp",

+         "dummy-tftp-debuginfo",

+         "dummy-vacation",

+         "dummy-vacation-debuginfo",

+         "dummy-xulrunner",

+         "dummy-xulrunner-debuginfo"

+     ],

+ 

+     "archs" : [

+         "i486",

+         "i586",

+         "i686",

+         "ppc",

+         "ppc64",

+         "s390",

+         "s390x",

+         "x86_64",

+         "src"

+     ],

+ 

+     "noarchpkgs" : [

+         "dummy-basesystem",

+         "dummy-bash-doc",

+         "dummy-bash-doc",

+         "dummy-fcoe-target-utils",

+         "dummy-foo32-doc",

+         "dummy-kernel-doc",

+         "dummy-release-notes",

+         "dummy-release-notes-cs-CZ",

+         "dummy-release-notes-en-US",

+         "dummy-selinux-policy-doc",

+         "dummy-selinux-policy-minimal",

+         "dummy-selinux-policy-mls",

+         "dummy-selinux-policy-targeted"

+     ]

+ 

+ }

@@ -0,0 +1,7 @@ 

+ #!/bin/bash

+ 

+ # Thin wrapper to run all tests

+ for t in $(dirname $0)/test_*

+ do

+     $t

+ done

@@ -0,0 +1,12 @@ 

+ #!/bin/sh

+ 

+ export PYTHONPATH=$(pwd)/pmd:$(pwd)/../

+ export PATH=$(pwd)/../bin:$PATH

+ 

+ mkdir -p _composes

+ 

+ pungi-koji \

+ --target-dir=_composes \

+ --old-composes=_composes \

+ --config=dummy-pungi.conf \

+ --test