From 5ac4217ee9c4f84dbc47d4eee1ca643960325ecb Mon Sep 17 00:00:00 2001 From: "Chris St. Pierre" Date: Tue, 4 Sep 2012 09:58:06 -0400 Subject: fixed up tools documentation, added tests for tools doco --- testsuite/Testtools/__init__.py | 98 +++++++++++++++++++++++++++++++ tools/README | 26 ++++++--- tools/create-debian-pkglist.pl | 124 ---------------------------------------- tools/upgrade/1.1/README | 6 ++ tools/upgrade/1.2/README | 9 +++ tools/upgrade/1.3/README | 14 +++++ 6 files changed, 144 insertions(+), 133 deletions(-) create mode 100644 testsuite/Testtools/__init__.py delete mode 100644 tools/create-debian-pkglist.pl create mode 100644 tools/upgrade/1.1/README create mode 100644 tools/upgrade/1.2/README create mode 100644 tools/upgrade/1.3/README diff --git a/testsuite/Testtools/__init__.py b/testsuite/Testtools/__init__.py new file mode 100644 index 000000000..73687eb5f --- /dev/null +++ b/testsuite/Testtools/__init__.py @@ -0,0 +1,98 @@ +import os +import re +import sys + +# add all parent testsuite directories to sys.path to allow (most) +# relative imports in python 2.4 +path = os.path.dirname(__file__) +while path != "/": + if os.path.basename(path).lower().startswith("test"): + sys.path.append(path) + if os.path.basename(path) == "testsuite": + break + path = os.path.dirname(path) +from common import XI_NAMESPACE, XI, inPy3k, call, builtins, u, can_skip, \ + skip, skipIf, skipUnless, Bcfg2TestCase, DBModelTestCase, syncdb, \ + patchIf, datastore + +TOOLSDIR = os.path.abspath(os.path.join(os.path.dirname(__file__), + "..", "..", "tools")) + +class TestToolsDocs(Bcfg2TestCase): + blankline = re.compile(r'^\s*$') + + @skipUnless(os.path.exists(TOOLSDIR), + "%s does not exist, skipping tools/ tests" % TOOLSDIR) + def tools_in_README(self, toolsdir=None): + if toolsdir is None: + toolsdir = TOOLSDIR + script = None + desc = None + started = False + rv = dict() + for line in open(os.path.join(toolsdir, "README")).readlines(): + if not started: + # skip up to the first blank line + if self.blankline.match(line): + started = True + elif not self.blankline.match(line): + match = re.match(r'^(\S+)', line) + if match: + script = match.group(1) + desc = '' + else: + match = re.match(r'^\s+(?:-\s+)?(.*)$', line) + if match: + desc += match.group(1) + else: + # blank line + if script and desc: + rv[script] = desc + if script and desc: + rv[script] = desc + return rv + + @skipUnless(os.path.exists(TOOLSDIR), + "%s does not exist, skipping tools/ tests" % TOOLSDIR) + def test_all_scripts_in_README(self, prefix=''): + toolsdir = os.path.join(TOOLSDIR, prefix) + tools = self.tools_in_README(toolsdir=toolsdir) + for fname in os.listdir(toolsdir): + if fname == 'README': + continue + dname = os.path.join(prefix, fname) # display name + fpath = os.path.join(toolsdir, fname) + if os.path.isfile(fpath): + self.assertIn(fname, tools, + msg="%s has no entry in README" % dname) + self.assertNotRegexpMatches(tools[fname], r'^(\s|\?)*$', + msg="%s has an empty entry in README" % + dname) + + @skipUnless(os.path.exists(TOOLSDIR), + "%s does not exist, skipping tools/ tests" % TOOLSDIR) + def test_no_extras_in_README(self, prefix=''): + toolsdir = os.path.join(TOOLSDIR, prefix) + tools = self.tools_in_README(toolsdir=toolsdir) + for fname in tools.keys(): + dname = os.path.join(prefix, fname) # display name + fpath = os.path.join(toolsdir, fname) + self.assertTrue(os.path.exists(fpath), + msg="%s is listed in README but does not exist" % + dname) + + @skipUnless(os.path.exists(TOOLSDIR), + "%s does not exist, skipping tools/ tests" % TOOLSDIR) + def test_upgrade_scripts_documented(self): + upgrade = os.path.join(TOOLSDIR, "upgrade") + for udir in os.listdir(upgrade): + upath = os.path.join(upgrade, udir) + dname = os.path.join("upgrade", udir) # display name + self.assertTrue(os.path.isdir(upath), + msg="Unexpected script %s found in %s" % (udir, + dname)) + self.assertTrue(os.path.exists(os.path.join(upath, 'README')), + msg="%s has no README" % dname) + self.test_all_scripts_in_README(dname) + + diff --git a/tools/README b/tools/README index 738ec1731..302337d94 100644 --- a/tools/README +++ b/tools/README @@ -1,10 +1,14 @@ This directory contains repository maintenance tools. +accounts2xml.py + - Generate an XML description of accounts on a machine from + /etc/passwd + basebuilder.py - builds v2 base.xml from bcfg1 repo batchadd.py - - ??? + - Add records to Hostbase bcfg2-completion.bash - Bash tab completion for bcfg2-admin @@ -30,14 +34,11 @@ create-debian-pkglist-gp.py - Generate Pkgmgr XML files from etc/debian-pkglist.conf. See http://trac.mcs.anl.gov/projects/bcfg2/wiki/Tools/DebianPkgmgrCreationScript -create-debian-pkglist.pl - - ??? - create-debian-pkglist.py - Generate Pkgmgr XML files for Debian packages create-rpm-pkglist.py - - ??? + - Generate list of installed RPM packages encap-util-count.sh - Produce a count of encap packages per directory @@ -58,10 +59,10 @@ export.sh - Export a tagged version of the Bcfg2 source hostbasepush.py - - ??? + - Call the Hostbase.rebuildState XML-RPC method hostbase.py {-l|-c} - - ??? + - Display or create host information for Hostbase hostinfo.py {-q |--showfields} - Query the hostbase databse @@ -75,14 +76,21 @@ pkgmgr_update.py RPMS rpmlisting.py - - ??? + - Generate Pkgmgr XML files for RPM packages + +selinux_baseline.py + - Create a Bundle with all base SELinux entries on a client. This + is useful because different versions of the SELinux libraries + have different capabilities, and some clients may have very, + very large baselines. selinux_baseline.py can be used to ensure + that there are no 'extra' SELinux entries on such a client. upgrade - This directory contains scripts used to upgrade to the specified version. E.g., upgrade/1.2 has scripts needed to upgrade to Bcfg2 1.2.x from bcfg2 1.1.x -yum-listpkgs.xml.py +yum-listpkgs-xml.py - Produces a list of all packages installed and available in a format suitable for use by Packages or Pkgmgr diff --git a/tools/create-debian-pkglist.pl b/tools/create-debian-pkglist.pl deleted file mode 100644 index 1567f5aa2..000000000 --- a/tools/create-debian-pkglist.pl +++ /dev/null @@ -1,124 +0,0 @@ -#!/usr/bin/perl - -#some quicksetup to make sure everything is in place -system('mkdir -p /disks/tmp/bcfg2-packagelists' ); - - -#pull the correct package lists from the security sites. -#this needs to be abstracted better -system( "wget http://security.debian.org/dists/stable/updates/main/binary-i386/Packages -O /disks/tmp/bcfg2-packagelists/security-main.Packages -q" ); -system( "wget http://security.debian.org/dists/stable/updates/contrib/binary-i386/Packages -O /disks/tmp/bcfg2-packagelists/security-contrib.Packages -q" ); -system( "wget http://security.debian.org/dists/stable/updates/non-free/binary-i386/Packages -O /disks/tmp/bcfg2-packagelists/security-nonfree.Packages -q" ); - -system('cat /disks/tmp/bcfg2-packagelists/security-main.Packages /disks/tmp/bcfg2-packagelists/security-contrib.Packages /disks/tmp/bcfg2-packagelists/security-nonfree.Packages > /disks/tmp/bcfg2-packagelists/debian-stable-security.Packages'); -system('rm /disks/tmp/bcfg2-packagelists/security-main.Packages /disks/tmp/bcfg2-packagelists/security-contrib.Packages /disks/tmp/bcfg2-packagelists/security-nonfree.Packages'); - -#pull the correct package lists from the security sites. -#this needs to be abstracted better -system( "wget http://volatile.debian.net/debian-volatile/dists/stable/volatile/main/binary-i386/Packages -O /disks/tmp/bcfg2-packagelists/volatile-main.Packages -q" ); -system( "wget http://volatile.debian.net/debian-volatile/dists/stable/volatile/contrib/binary-i386/Packages -O /disks/tmp/bcfg2-packagelists/volatile-contrib.Packages -q" ); -system( "wget http://volatile.debian.net/debian-volatile/dists/stable/volatile/non-free/binary-i386/Packages -O /disks/tmp/bcfg2-packagelists/volatile-nonfree.Packages -q" ); - -system('cat /disks/tmp/bcfg2-packagelists/volatile-main.Packages /disks/tmp/bcfg2-packagelists/volatile-contrib.Packages /disks/tmp/bcfg2-packagelists/volatile-nonfree.Packages > /disks/tmp/bcfg2-packagelists/debian-stable-volatile.Packages'); -system('rm /disks/tmp/bcfg2-packagelists/volatile-main.Packages /disks/tmp/bcfg2-packagelists/volatile-contrib.Packages /disks/tmp/bcfg2-packagelists/volatile-nonfree.Packages'); - -#pull the correct package lists from the security sites. -#this needs to be abstracted better -system( "wget ftp://ftp.nerim.net/debian-marillat/dists/sarge/main/binary-i386/Packages -O /disks/tmp/bcfg2-packagelists/debian-sarge-mplayer.Packages -q" ); - -#this is to fix local files so that my naming hack thing will playout. -system('cp /disks/debian/sarge/Packages /disks/tmp/bcfg2-packagelists/debian-sarge-local.Packages'); - -system('cat /disks/distro/debian/dists/sarge/main/binary-i386/Packages /disks/distro/debian/dists/sarge/contrib/binary-i386/Packages /disks/distro/debian/dists/sarge/non-free/binary-i386/Packages > /disks/tmp/bcfg2-packagelists/debian-sarge-distro.Packages'); - -system('cat /disks/distro/debian-non-US/dists/sarge/non-US/main/binary-i386/Packages /disks/distro/debian-non-US/dists/sarge/non-US/contrib/binary-i386/Packages /disks/distro/debian-non-US/dists/sarge/non-US/non-free/binary-i386/Packages > /disks/tmp/bcfg2-packagelists/debian-sarge-nonUS.Packages'); - -#this is currently still a hack, because ordering is important. -#for future refernce you must do security and then local.. then the rest.. - -@files = ( - "/disks/tmp/bcfg2-packagelists/debian-stable-volatile.Packages", - "/disks/tmp/bcfg2-packagelists/debian-stable-security.Packages", - "/disks/tmp/bcfg2-packagelists/debian-sarge-local.Packages", - "/disks/tmp/bcfg2-packagelists/debian-sarge-mplayer.Packages", - "/disks/tmp/bcfg2-packagelists/debian-sarge-distro.Packages", - "/disks/tmp/bcfg2-packagelists/debian-sarge-nonUS.Packages", -); - -$priority = 89; -@tmpfiles = (); - -#first come the security fixes -foreach $file ( @files ){ - - push( @tmpfiles, $file ); - #first we open up the imput file - open( INFILE, "$file" ) or die("could not open $file\n"); - - #then we change the name and open the output file. - $file =~ s/Packages/xml/ ; - #print "Opening $file for writing\n"; - open( OUTFILE, ">$file" ); - - - #start by putting in the default stuff - print OUTFILE "\n"; - print OUTFILE "\n"; - - #decrement the priority since we are going highest to lowest - $priority = $priority - 10; - - - #the loop that builds the actually file. - $known_package=0; - while( $line = ){ - if( $line =~ /^Package:/ ){ - ($filler,$basename)=split( ' ', $line ); - - #Now to find the version of the package. - $found = 0; - while( !$found ){ - $line = ; - if( $line =~ /^Version:/ ){ - ($filler,$version)=split( ' ', $line ); - if ( ! $known_package ){ - print OUTFILE "\t\n" ; - push @mypackages, $basename; } - $found =1; - } - } - } - #end of file builder loop - - } - close( INFILE ); - print OUTFILE "\n\n"; - close( OUTFILE ); -} - - -#this is where I do clean up and set up for distributing the files to other -#servers. - -#clean up the temp files -foreach $file (@tmpfiles){ - #print "removing file: $file\n"; - system("rm -f $file"); -} - -#get rid of old tarball -#print "Removing old tarball\n"; -system('rm -f /disks/debian/pkglists/bcfg2-packagelists.tgz'); - -#create new tarball for distribution -#print "Creating new tarball\n"; -system('cd /disks/tmp/ ; tar czf /disks/debian/pkglists/bcfg2-packagelists.tgz bcfg2-packagelists 2&>1 >/dev/null' ); - -#move the files into place on the local machine -#for testing purposes and also until we get netzero converted to 0.8 -#system('mv /disks/tmp/bcfg2-packagelists/*.xml /disks/tmp/bcfg2/Pkgmgr/'); -#for real -system('mv /disks/tmp/bcfg2-packagelists/*.xml /disks/bcfg2/Pkgmgr/'); - -#final clean up -system('rmdir /disks/tmp/bcfg2-packagelists' ); diff --git a/tools/upgrade/1.1/README b/tools/upgrade/1.1/README new file mode 100644 index 000000000..e57f8c0a6 --- /dev/null +++ b/tools/upgrade/1.1/README @@ -0,0 +1,6 @@ +This directory contains scripts to help upgrading from Bcfg2 1.0 to 1.1. + +posixunified.py + - Change all ConfigFile, Directory, Directory, Permissions, and + Symlink entries in Base and Bundler to Path type="" + entries in Rules. diff --git a/tools/upgrade/1.2/README b/tools/upgrade/1.2/README new file mode 100644 index 000000000..1879ebbf8 --- /dev/null +++ b/tools/upgrade/1.2/README @@ -0,0 +1,9 @@ +This directory contains scripts to help upgrading from Bcfg2 1.1 to 1.2. + +nagiosgen-convert.py + - Convert configuration from Properties/NagiosGen.xml to + NagiosGen/config.xml and NagiosGen/parents.xml + +packages-convert.py + - Convert configuration from Packages/config.xml to + Packages/packages.conf and Packages/sources.xml diff --git a/tools/upgrade/1.3/README b/tools/upgrade/1.3/README new file mode 100644 index 000000000..6c9382550 --- /dev/null +++ b/tools/upgrade/1.3/README @@ -0,0 +1,14 @@ +This directory contains scripts to help with upgrading from Bcfg2 1.2 +to 1.3. + +migrate_info.py + - Convert info and :info files to info.xml files + +migrate_configs.py + - Migrate configuration in Rules/rules.conf and + Packages/packages.conf to bcfg2.conf; move database + configuration from [statistics] to [database] + +service_modes.py + - Convert Service tags from "mode" attribute to separate "restart" + and "install" attributes -- cgit v1.2.3-1-g7c22