* Unittest suite can be run with 'make unittests'
* Run individual tests with: 'py.test test-22'
---
tests/factory/run_test | 219 ----------------------------------
tests/factory/test_factory.py | 258 +++++++++++++++++++++++++++++++++++++++++
tests/tdl/run_test | 129 --------------------
tests/tdl/test_tdl.py | 155 ++++++++++++++++++++++++
4 files changed, 413 insertions(+), 348 deletions(-)
delete mode 100755 tests/factory/run_test
create mode 100755 tests/factory/test_factory.py
delete mode 100755 tests/tdl/run_test
create mode 100644 tests/tdl/test_tdl.py
diff --git a/tests/factory/run_test b/tests/factory/run_test
deleted file mode 100755
index 1f52678..0000000
--- a/tests/factory/run_test
+++ /dev/null
@@ -1,219 +0,0 @@
-#!/usr/bin/python
-
-import sys
-sys.path.insert(0, "../..")
-
-import oz.TDL
-import oz.GuestFactory
-import ConfigParser
-import StringIO
-import logging
-import os
-
-success = 0
-fail = 0
-
-def default_route():
- route_file = "/proc/net/route"
- d = file(route_file)
-
- defn = 0
- for line in d.xreadlines():
- info = line.split()
- if (len(info) != 11): # 11 = typical num of fields in the file
- logging.warn(_("Invalid line length while parsing %s.") %
- (route_file))
- break
- try:
- route = int(info[1], 16)
- if route == 0:
- return info[0]
- except ValueError:
- continue
- raise Exception, "Could not find default route"
-
-# we find the default route for this machine. Note that this very well
-# may not be a bridge, but for the purposes of testing the factory, it
-# doesn't really matter; it just has to have an IP address
-route = default_route()
-
-def test_distro(distro, version, arch, installtype):
- global route
-
- tdlxml = """
-<template>
- <name>tester</name>
- <os>
- <name>%s</name>
- <version>%s</version>
- <arch>%s</arch>
- <install type='%s'>
- <%s>http://example.org</%s>
- </install>
- <key></key>
- </os>
-</template>
-""" % (distro, version, arch, installtype, installtype, installtype)
-
- tdl = oz.TDL.TDL(tdlxml)
-
- config = ConfigParser.SafeConfigParser()
-
config.readfp(StringIO.StringIO("[libvirt]\nuri=qemu:///session\nbridge_name=%s"
% route))
-
- if os.getenv('DEBUG') != None:
- logging.basicConfig(level=logging.DEBUG, format="%(message)s")
- else:
- logging.basicConfig(level=logging.ERROR, format="%(message)s")
-
- guest = oz.GuestFactory.guest_factory(tdl, config, None)
-
-def runtest(distro, version, arch, installtype, expect_success):
- global success
- global fail
-
- print "Testing %s-%s-%s-%s..." % (distro, version, arch, installtype),
- try:
- test_distro(distro, version, arch, installtype)
- if expect_success:
- success += 1
- print "OK"
- else:
- fail += 1
- print "FAIL"
- except Exception, e:
- if expect_success:
- fail += 1
- print e
- print "FAIL"
- else:
- success += 1
- print "OK"
-
-def expect_success(distro, version, arch, installtype):
- return runtest(distro, version, arch, installtype, True)
-
-def expect_fail(distro, version, arch, installtype):
- return runtest(distro, version, arch, installtype, False)
-
-# bad distro
-expect_fail("foo", "1", "i386", "url")
-# bad installtype
-expect_fail("Fedora", "14", "i386", "dong")
-# bad arch
-expect_fail("Fedora", "14", "ia64", "iso")
-
-# FedoraCore
-for version in ["1", "2", "3", "4",
"5", "6"]:
- for arch in ["i386", "x86_64"]:
- for installtype in ["url", "iso"]:
- expect_success("FedoraCore", version, arch, installtype)
-# bad FedoraCore version
-expect_fail("FedoraCore", "24", "x86_64", "iso")
-
-# Fedora
-for version in ["7", "8", "9", "10",
"11", "12", "13", "14", "15"]:
- for arch in ["i386", "x86_64"]:
- for installtype in ["url", "iso"]:
- expect_success("Fedora", version, arch, installtype)
-# bad Fedora version
-expect_fail("Fedora", "24", "x86_64", "iso")
-
-# RHL
-for version in ["7.0", "7.1", "7.2", "7.3",
"8", "9"]:
- expect_success("RHL", version, "i386", "url")
-# bad RHL version
-expect_fail("RHL", "10", "i386", "url")
-# bad RHL arch
-expect_fail("RHL", "9", "x86_64", "url")
-# bad RHL installtype
-expect_fail("RHL", "9", "x86_64", "iso")
-
-# RHEL-2.1
-for version in ["GOLD", "U2", "U3", "U4",
"U5", "U6"]:
- expect_success("RHEL-2.1", version, "i386", "url")
-# bad RHEL-2.1 version
-expect_fail("RHEL-2.1", "U7", "i386", "url")
-# bad RHEL-2.1 arch
-expect_fail("RHEL-2.1", "U6", "x86_64", "url")
-# bad RHEL-2.1 installtype
-expect_fail("RHEL-2.1", "U6", "i386", "iso")
-
-# RHEL-3
-for version in ["GOLD", "U1", "U2", "U3",
"U4", "U5", "U6", "U7", "U8",
"U9"]:
- for arch in ["i386", "x86_64"]:
- expect_success("RHEL-3", version, arch, "url")
-# bad RHEL-3 version
-expect_fail("RHEL-3", "U10", "x86_64", "url")
-# invalid RHEL-3 installtype
-expect_fail("RHEL-3", "U9", "x86_64", "iso")
-
-# RHEL-4/CentOS-4
-for distro in ["RHEL-4", "CentOS-4"]:
- for version in ["GOLD", "U1", "U2", "U3",
"U4", "U5", "U6", "U7", "U8",
"U9"]:
- for arch in ["i386", "x86_64"]:
- for installtype in ["url", "iso"]:
- expect_success(distro, version, arch, installtype)
-# bad RHEL-4 version
-expect_fail("RHEL-4", "U10", "x86_64", "url")
-
-# RHEL-5/CentOS-5
-for distro in ["RHEL-5", "CentOS-5"]:
- for version in ["GOLD", "U1", "U2", "U3",
"U4", "U5", "U6", "U7"]:
- for arch in ["i386", "x86_64"]:
- for installtype in ["url", "iso"]:
- expect_success(distro, version, arch, installtype)
-# bad RHEL-5 version
-expect_fail("RHEL-5", "U10", "x86_64", "url")
-
-# RHEL-6
-for version in ["0", "1"]:
- for arch in ["i386", "x86_64"]:
- for installtype in ["url", "iso"]:
- expect_success("RHEL-6", version, arch, installtype)
-# bad RHEL-6 version
-expect_fail("RHEL-6", "U10", "x86_64", "url")
-
-# Debian
-for version in ["5", "6"]:
- for arch in ["i386", "x86_64"]:
- expect_success("Debian", version, arch, "iso")
-# bad Debian version
-expect_fail("Debian", "12", "i386", "iso")
-# invalid Debian installtype
-expect_fail("Debian", "6", "x86_64", "url")
-
-# Windows
-expect_success("Windows", "2000", "i386", "iso")
-for version in ["XP", "2003", "2008", "7"]:
- for arch in ["i386", "x86_64"]:
- expect_success("Windows", version, arch, "iso")
-# bad Windows 2000 arch
-expect_fail("Windows", "2000", "x86_64", "iso")
-# bad Windows version
-expect_fail("Windows", "1999", "x86_64", "iso")
-# invalid Windows installtype
-expect_fail("Windows", "2008", "x86_64", "url")
-
-# OpenSUSE
-for version in ["11.0", "11.1", "11.2", "11.3",
"11.4"]:
- for arch in ["i386", "x86_64"]:
- expect_success("OpenSUSE", version, arch, "iso")
-# bad OpenSUSE version
-expect_fail("OpenSUSE", "16", "x86_64", "iso")
-# invalid OpenSUSE installtype
-expect_fail("OpenSUSE", "11.4", "x86_64", "url")
-
-# Ubuntu
-for version in ["6.06", "6.06.1", "6.06.2",
"6.10", "7.04", "7.10", "8.04",
- "8.04.1", "8.04.2", "8.04.3",
"8.04.4", "8.10", "9.04", "9.10",
- "10.04", "10.04.1", "10.04.2",
"10.04.3", "10.10", "11.04"]:
- for arch in ["i386", "x86_64"]:
- expect_success("Ubuntu", version, arch, "iso")
-# bad Ubuntu version
-expect_fail("Ubuntu", "10.9", "i386", "iso")
-# bad Ubuntu installtype
-expect_fail("Ubuntu", "10.10", "i386", "url")
-
-print "SUCCESS: %d, FAIL: %d" % (success, fail)
-
-sys.exit(fail)
diff --git a/tests/factory/test_factory.py b/tests/factory/test_factory.py
new file mode 100755
index 0000000..895bd5a
--- /dev/null
+++ b/tests/factory/test_factory.py
@@ -0,0 +1,258 @@
+#!/usr/bin/python
+
+import sys
+import ConfigParser
+import StringIO
+import logging
+import os
+import collections
+
+# Find oz library
+prefix = '.'
+for i in range(0,3):
+ if os.path.isdir(os.path.join(prefix, 'oz')):
+ sys.path.insert(0, prefix)
+ break
+ else:
+ prefix = '../' + prefix
+
+try:
+ import oz.TDL
+ import oz.GuestFactory
+except ImportError, e:
+ print 'Unable to import oz. Is oz installed or in your PYTHONPATH?'
+ sys.exit(1)
+
+try:
+ import py.test
+except ImportError:
+ print 'Unable to import py.test. Is py.test installed?'
+ sys.exit(1)
+
+# Define a list to collect all tests
+alltests = list()
+
+# Define an object to record test results
+class TestResult(object):
+ def __init__(self, *args, **kwargs):
+ if len(args) == 4:
+ (self.distro, self.version, self.arch, self.installtype) = args
+ for k,v in kwargs.items():
+ setattr(self, k, v)
+
+ def __repr__(self):
+ '''String representation of object'''
+ return "test-{0}-{1}-{2}-{3}".format(*self.test_args())
+
+ @property
+ def name(self):
+ '''Convenience property for test name'''
+ return self.__repr__()
+
+ def test_args(self):
+ return (self.distro, self.version, self.arch, self.installtype)
+
+ def execute(self):
+ if self.expect_pass:
+ return (self.name, runtest, self.test_args())
+ else:
+ return (self.name, handle_exception, self.test_args())
+
+def default_route():
+ route_file = "/proc/net/route"
+ d = file(route_file)
+
+ defn = 0
+ for line in d.xreadlines():
+ info = line.split()
+ if (len(info) != 11): # 11 = typical num of fields in the file
+ logging.warn(_("Invalid line length while parsing %s.") %
+ (route_file))
+ break
+ try:
+ route = int(info[1], 16)
+ if route == 0:
+ return info[0]
+ except ValueError:
+ continue
+ raise Exception, "Could not find default route"
+
+# we find the default route for this machine. Note that this very well
+# may not be a bridge, but for the purposes of testing the factory, it
+# doesn't really matter; it just has to have an IP address
+route = default_route()
+
+def runtest(args):
+ global route
+
+ (distro, version, arch, installtype) = args
+ print "Testing %s-%s-%s-%s..." % (distro, version, arch, installtype),
+
+ tdlxml = """
+<template>
+ <name>tester</name>
+ <os>
+ <name>%s</name>
+ <version>%s</version>
+ <arch>%s</arch>
+ <install type='%s'>
+ <%s>http://example.org</%s>
+ </install>
+ <key></key>
+ </os>
+</template>
+""" % (distro, version, arch, installtype, installtype, installtype)
+
+ tdl = oz.TDL.TDL(tdlxml)
+
+ config = ConfigParser.SafeConfigParser()
+
config.readfp(StringIO.StringIO("[libvirt]\nuri=qemu:///session\nbridge_name=%s"
% route))
+
+ if os.getenv('DEBUG') != None:
+ logging.basicConfig(level=logging.DEBUG, format="%(message)s")
+ else:
+ logging.basicConfig(level=logging.ERROR, format="%(message)s")
+
+ guest = oz.GuestFactory.guest_factory(tdl, config, None)
+
+def expect_success(*args):
+ '''Create a TestResult object using provided arguments. Append result
to
+ global 'alltests' list.'''
+ global alltests
+ alltests.append(TestResult(*args, expect_pass=True))
+
+def expect_fail(*args):
+ '''Create a TestResult object using provided arguments. Append result
to
+ global 'alltests' list.'''
+ global alltests
+ alltests.append(TestResult(*args, expect_pass=False))
+
+def handle_exception(args):
+ '''Helper method to capture OzException when executing
'runtest'.'''
+ with py.test.raises(oz.OzException.OzException):
+ runtest(args)
+
+def test_all():
+
+ # bad distro
+ expect_fail("foo", "1", "i386", "url")
+ # bad installtype
+ expect_fail("Fedora", "14", "i386", "dong")
+ # bad arch
+ expect_fail("Fedora", "14", "ia64", "iso")
+
+ # FedoraCore
+ for version in ["1", "2", "3", "4",
"5", "6"]:
+ for arch in ["i386", "x86_64"]:
+ for installtype in ["url", "iso"]:
+ expect_success("FedoraCore", version, arch, installtype)
+ # bad FedoraCore version
+ expect_fail("FedoraCore", "24", "x86_64",
"iso")
+
+ # Fedora
+ for version in ["7", "8", "9", "10",
"11", "12", "13", "14", "15"]:
+ for arch in ["i386", "x86_64"]:
+ for installtype in ["url", "iso"]:
+ expect_success("Fedora", version, arch, installtype)
+ # bad Fedora version
+ expect_fail("Fedora", "24", "x86_64", "iso")
+
+ # RHL
+ for version in ["7.0", "7.1", "7.2", "7.3",
"8", "9"]:
+ expect_success("RHL", version, "i386", "url")
+ # bad RHL version
+ expect_fail("RHL", "10", "i386", "url")
+ # bad RHL arch
+ expect_fail("RHL", "9", "x86_64", "url")
+ # bad RHL installtype
+ expect_fail("RHL", "9", "x86_64", "iso")
+
+ # RHEL-2.1
+ for version in ["GOLD", "U2", "U3", "U4",
"U5", "U6"]:
+ expect_success("RHEL-2.1", version, "i386", "url")
+ # bad RHEL-2.1 version
+ expect_fail("RHEL-2.1", "U7", "i386", "url")
+ # bad RHEL-2.1 arch
+ expect_fail("RHEL-2.1", "U6", "x86_64",
"url")
+ # bad RHEL-2.1 installtype
+ expect_fail("RHEL-2.1", "U6", "i386", "iso")
+
+ # RHEL-3
+ for version in ["GOLD", "U1", "U2", "U3",
"U4", "U5", "U6", "U7", "U8",
"U9"]:
+ for arch in ["i386", "x86_64"]:
+ expect_success("RHEL-3", version, arch, "url")
+ # bad RHEL-3 version
+ expect_fail("RHEL-3", "U10", "x86_64",
"url")
+ # invalid RHEL-3 installtype
+ expect_fail("RHEL-3", "U9", "x86_64", "iso")
+
+ # RHEL-4/CentOS-4
+ for distro in ["RHEL-4", "CentOS-4"]:
+ for version in ["GOLD", "U1", "U2", "U3",
"U4", "U5", "U6", "U7", "U8",
"U9"]:
+ for arch in ["i386", "x86_64"]:
+ for installtype in ["url", "iso"]:
+ expect_success(distro, version, arch, installtype)
+ # bad RHEL-4 version
+ expect_fail("RHEL-4", "U10", "x86_64",
"url")
+
+ # RHEL-5/CentOS-5
+ for distro in ["RHEL-5", "CentOS-5"]:
+ for version in ["GOLD", "U1", "U2", "U3",
"U4", "U5", "U6", "U7"]:
+ for arch in ["i386", "x86_64"]:
+ for installtype in ["url", "iso"]:
+ expect_success(distro, version, arch, installtype)
+ # bad RHEL-5 version
+ expect_fail("RHEL-5", "U10", "x86_64",
"url")
+
+ # RHEL-6
+ for version in ["0", "1"]:
+ for arch in ["i386", "x86_64"]:
+ for installtype in ["url", "iso"]:
+ expect_success("RHEL-6", version, arch, installtype)
+ # bad RHEL-6 version
+ expect_fail("RHEL-6", "U10", "x86_64",
"url")
+
+ # Debian
+ for version in ["5", "6"]:
+ for arch in ["i386", "x86_64"]:
+ expect_success("Debian", version, arch, "iso")
+ # bad Debian version
+ expect_fail("Debian", "12", "i386", "iso")
+ # invalid Debian installtype
+ expect_fail("Debian", "6", "x86_64", "url")
+
+ # Windows
+ expect_success("Windows", "2000", "i386",
"iso")
+ for version in ["XP", "2003", "2008", "7"]:
+ for arch in ["i386", "x86_64"]:
+ expect_success("Windows", version, arch, "iso")
+ # bad Windows 2000 arch
+ expect_fail("Windows", "2000", "x86_64",
"iso")
+ # bad Windows version
+ expect_fail("Windows", "1999", "x86_64",
"iso")
+ # invalid Windows installtype
+ expect_fail("Windows", "2008", "x86_64",
"url")
+
+ # OpenSUSE
+ for version in ["11.0", "11.1", "11.2",
"11.3", "11.4"]:
+ for arch in ["i386", "x86_64"]:
+ expect_success("OpenSUSE", version, arch, "iso")
+ # bad OpenSUSE version
+ expect_fail("OpenSUSE", "16", "x86_64",
"iso")
+ # invalid OpenSUSE installtype
+ expect_fail("OpenSUSE", "11.4", "x86_64",
"url")
+
+ # Ubuntu
+ for version in ["6.06", "6.06.1", "6.06.2",
"6.10", "7.04", "7.10", "8.04",
+ "8.04.1", "8.04.2", "8.04.3",
"8.04.4", "8.10", "9.04", "9.10",
+ "10.04", "10.04.1", "10.04.2",
"10.04.3", "10.10", "11.04"]:
+ for arch in ["i386", "x86_64"]:
+ expect_success("Ubuntu", version, arch, "iso")
+ # bad Ubuntu version
+ expect_fail("Ubuntu", "10.9", "i386", "iso")
+ # bad Ubuntu installtype
+ expect_fail("Ubuntu", "10.10", "i386",
"url")
+
+ # Now run all the tests
+ for tst in alltests:
+ yield tst.execute()
diff --git a/tests/tdl/run_test b/tests/tdl/run_test
deleted file mode 100755
index 1045aaf..0000000
--- a/tests/tdl/run_test
+++ /dev/null
@@ -1,129 +0,0 @@
-#!/usr/bin/python
-
-import sys
-sys.path.insert(0, "../..")
-
-import libxml2
-import os
-import traceback
-
-import oz.TDL
-
-debug = os.getenv('DEBUG')
-
-# the tests dictionary lists all of the test we will run. The key for the
-# dictionary is the filename of the test, and the value is whether the test
-# is expected to succeed (True) or not (False)
-tests = {
- "test-01-simple-iso.tdl": True,
- "test-02-simple-url.tdl": True,
- "test-03-empty-template.tdl": False,
- "test-04-no-os.tdl": False,
- "test-05-no-name.tdl": False,
- "test-06-simple-iso-description.tdl": True,
- "test-07-packages-no-package.tdl": True,
- "test-08-repositories-no-repository.tdl": True,
- "test-09-os-invalid-arch.tdl": False,
- "test-10-os-invalid-install-type.tdl": False,
- "test-11-description-packages-repositories.tdl": True,
- "test-12-os-no-name.tdl": False,
- "test-13-os-no-version.tdl": False,
- "test-14-os-no-arch.tdl": False,
- "test-15-os-no-install.tdl": False,
- "test-16-signed-repository.tdl": True,
- "test-17-repo-invalid-signed.tdl": False,
- "test-18-rootpw.tdl": True,
- "test-19-key.tdl": True,
- "test-20-multiple-install.tdl": False,
- "test-21-missing-install-type.tdl": False,
- "test-22-md5sum.tdl": True,
- "test-23-sha1sum.tdl": True,
- "test-24-sha256sum.tdl": True,
- "test-25-md5sum-and-sha1sum.tdl": False,
- "test-26-md5sum-and-sha256sum.tdl": False,
- "test-27-sha1sum-and-sha256sum.tdl": False,
- "test-28-package-no-name.tdl": False,
- "test-29-files.tdl": True,
- "test-30-file-no-name.tdl": False,
- "test-31-file-raw-type.tdl": True,
- "test-32-file-base64-type.tdl": True,
- "test-33-file-invalid-type.tdl": False,
- "test-34-file-invalid-base64.tdl": False,
- "test-35-repository-no-name.tdl": False,
- "test-36-repository-no-url.tdl": False,
- "test-37-command.tdl": True,
- "test-38-command-no-name.tdl": False,
- "test-39-command-raw-type.tdl": True,
- "test-40-command-base64-type.tdl": True,
- "test-41-command-bogus-base64.tdl": False,
- "test-42-command-bogus-type.tdl": False,
-}
-
-success = 0
-fail = 0
-
-def succeeded():
- global success
- print "OK"
- success += 1
-
-def failed():
- global fail
- print "FAIL"
- fail += 1
-
-def validate_ozlib(tdl, succeed):
- print "Testing Parsing " + tdl + "...",
- try:
- oz.TDL.TDL(open(tdl, 'r').read())
- if succeed:
- succeeded()
- else:
- failed()
- except Exception, e:
- if debug:
- traceback.print_exc(file=sys.stdout)
- if succeed:
- failed()
- else:
- succeeded()
-
-def validate_schema(tdl, succeed):
- errout = ['']
-
- def libxml2_relaxng_errcb(msg, item):
- errout[0] = errout[0] + msg
-
- print "Testing Schema " + tdl + "...",
-
- schema = open('../../docs/tdl.rng', 'r').read()
- rngp = libxml2.relaxNGNewMemParserCtxt(schema, len(schema))
- rngs = rngp.relaxNGParse()
- rngctxt = rngs.relaxNGNewValidCtxt()
- rngctxt.setValidityErrorHandler(libxml2_relaxng_errcb, None)
-
- xml = open(tdl, 'r').read()
- if debug:
- print xml
-
- doc = libxml2.parseDoc(xml)
- ret = doc.relaxNGValidateDoc(rngctxt)
- if debug:
- print errout[0]
-
- if ret == 0:
- if succeed:
- succeeded()
- else:
- failed()
- else:
- if succeed:
- failed()
- else:
- succeeded()
-
-for tdl in sorted(tests.iterkeys()):
- validate_schema(tdl, tests[tdl])
- validate_ozlib(tdl, tests[tdl])
-
-print "SUCCESS: %d, FAIL: %d" % (success, fail)
diff --git a/tests/tdl/test_tdl.py b/tests/tdl/test_tdl.py
new file mode 100644
index 0000000..b5df164
--- /dev/null
+++ b/tests/tdl/test_tdl.py
@@ -0,0 +1,155 @@
+#!/usr/bin/python
+
+import sys
+import os
+
+try:
+ import libxml2
+except ImportError:
+ print 'Unable to import libxml2. Is libxml2-python installed?'
+ sys.exit(1)
+
+try:
+ import py.test
+except ImportError:
+ print 'Unable to import py.test. Is py.test installed?'
+ sys.exit(1)
+
+# Find oz
+prefix = '.'
+for i in range(0,3):
+ if os.path.isdir(os.path.join(prefix, 'oz')):
+ sys.path.insert(0, prefix)
+ break
+ else:
+ prefix = '../' + prefix
+
+try:
+ import oz
+ import oz.TDL
+except ImportError:
+ print 'Unable to import oz. Is oz installed?'
+ sys.exit(1)
+
+# the tests dictionary lists all of the test we will run. The key for the
+# dictionary is the filename of the test, and the value is whether the test
+# is expected to succeed (True) or not (False)
+tests = {
+ "test-01-simple-iso.tdl": True,
+ "test-02-simple-url.tdl": True,
+ "test-03-empty-template.tdl": False,
+ "test-04-no-os.tdl": False,
+ "test-05-no-name.tdl": False,
+ "test-06-simple-iso-description.tdl": True,
+ "test-07-packages-no-package.tdl": True,
+ "test-08-repositories-no-repository.tdl": True,
+ "test-09-os-invalid-arch.tdl": False,
+ "test-10-os-invalid-install-type.tdl": False,
+ "test-11-description-packages-repositories.tdl": True,
+ "test-12-os-no-name.tdl": False,
+ "test-13-os-no-version.tdl": False,
+ "test-14-os-no-arch.tdl": False,
+ "test-15-os-no-install.tdl": False,
+ "test-16-signed-repository.tdl": True,
+ "test-17-repo-invalid-signed.tdl": False,
+ "test-18-rootpw.tdl": True,
+ "test-19-key.tdl": True,
+ "test-20-multiple-install.tdl": False,
+ "test-21-missing-install-type.tdl": False,
+ "test-22-md5sum.tdl": True,
+ "test-23-sha1sum.tdl": True,
+ "test-24-sha256sum.tdl": True,
+ "test-25-md5sum-and-sha1sum.tdl": False,
+ "test-26-md5sum-and-sha256sum.tdl": False,
+ "test-27-sha1sum-and-sha256sum.tdl": False,
+ "test-28-package-no-name.tdl": False,
+ "test-29-files.tdl": True,
+ "test-30-file-no-name.tdl": False,
+ "test-31-file-raw-type.tdl": True,
+ "test-32-file-base64-type.tdl": True,
+ "test-33-file-invalid-type.tdl": False,
+ "test-34-file-invalid-base64.tdl": False,
+ "test-35-repository-no-name.tdl": False,
+ "test-36-repository-no-url.tdl": False,
+ "test-37-command.tdl": True,
+ "test-38-command-no-name.tdl": False,
+ "test-39-command-raw-type.tdl": True,
+ "test-40-command-base64-type.tdl": True,
+ "test-41-command-bogus-base64.tdl": False,
+ "test-42-command-bogus-type.tdl": False,
+}
+
+# Validate oz handling of tdl file
+def validate_ozlib(tdl_file):
+ xmldata = open(tdl_file, 'r').read()
+ tdl = oz.TDL.TDL(xmldata)
+
+# Validate schema
+def validate_schema(tdl_file):
+
+ # Locate relaxng schema
+ rng_file = None
+ for tryme in ['../../docs/tdl.rng',
+ '../docs/tdl.rng',
+ 'docs/tdl.rng',
+ 'tdl.rng',]:
+ if os.path.isfile(tryme):
+ rng_file = tryme
+ break
+
+ if rng_file is None:
+ raise Exception('RelaxNG schema file not found: tdl.rng')
+
+ # Load relaxng schema
+ schema = open(rng_file, 'r').read()
+ rngp = libxml2.relaxNGNewMemParserCtxt(schema, len(schema))
+ rngs = rngp.relaxNGParse()
+
+ # Define callback for error handling
+ def error_cb(ctx, str):
+ print "%s: %s" % (ctx, str.strip())
+ libxml2.registerErrorHandler(error_cb, tdl_file)
+
+ # Attempt to validate
+ reader = libxml2.newTextReaderFilename(tdl_file)
+ #reader.SetParserProp(libxml2.PARSER_VALIDATE, 1)
+ reader.RelaxNGSetSchema(rngs)
+ ret = reader.Read()
+ while ret == 1:
+ ret = reader.Read()
+
+ if ret != 0:
+ raise Exception('Error parsing the document: %s' % tdl_file)
+ if reader.IsValid() != 1:
+ raise Exception('Document failed to validate: %s' % tdl_file)
+
+# Test generator that iterates over all .tdl files
+def test():
+
+ # Define a helper to expect an exception
+ def handle_exception(func, *args):
+ with py.test.raises(Exception):
+ func(*args)
+
+ # Sanity check to see if any tests are unaccounted for in the config file
+ for (tdl, expected_pass) in tests.items():
+
+ # locate full path for tdl file
+ tdl_prefix = ''
+ for tdl_prefix in ['tests/tdl/', 'tdl/', '']:
+ if os.path.isfile(tdl_prefix + tdl):
+ break
+ tdl_file = tdl_prefix + tdl
+ test_name = os.path.splitext(tdl,)[0]
+
+ # Generate a unique unittest test for each validate_* method
+ for tst in (validate_ozlib, validate_schema, ):
+ # We need a unique method name
+ unique_name = test_name + tst.func_name
+
+ # Are we expecting the test to fail?
+ if expected_pass:
+ yield '%s_%s' % (test_name, tst.func_name), tst, tdl_file
+ else:
+ yield '%s_%s' % (test_name, tst.func_name), handle_exception,\
+ tst, tdl_file
--
1.7.6.2