diff options
author | Michael DeHaan <mdehaan@redhat.com> | 2008-10-17 12:28:54 -0400 |
---|---|---|
committer | Michael DeHaan <mdehaan@redhat.com> | 2008-10-17 12:28:54 -0400 |
commit | 8bc2b1929f9cc0deb9dd2a5a15af17854679bb97 (patch) | |
tree | 9b130caf5738bcbd1a171b8972fff73aa3eed564 | |
parent | ab0b0b2014c59ebfb6e6445e1006948d3df39f34 (diff) | |
download | cobbler-8bc2b1929f9cc0deb9dd2a5a15af17854679bb97.tar.gz cobbler-8bc2b1929f9cc0deb9dd2a5a15af17854679bb97.tar.xz cobbler-8bc2b1929f9cc0deb9dd2a5a15af17854679bb97.zip |
Moved the older test code under the main tree so it gets installed with the RPM. Beginings of adding testcases for XMLRPC that will exercise read only and read-write XMLRPC through Apache. Right now, there is only some basic read-only testing to verify koan's calls remain operational. We'll also want to write tests for the mod_python components.
-rw-r--r-- | Makefile | 6 | ||||
-rwxr-xr-x | cobbler/cobbler.py | 6 | ||||
-rw-r--r-- | cobbler/modules/serializer_catalog.py | 3 | ||||
-rw-r--r-- | cobbler/remote.py | 103 | ||||
-rw-r--r-- | cobbler/test_basic.py (renamed from tests/tests.py) | 18 | ||||
-rw-r--r-- | tests/README | 6 |
6 files changed, 99 insertions, 43 deletions
@@ -22,12 +22,12 @@ test: make savestate make eraseconfig make install - -make nosetests + -(make nosetests) make restorestate nosetests: - #nosetests tests cobbler tests.py --with-coverage --cover-package=cobbler --cover-erase --quiet | tee test.log - nosetests tests cobbler | tee test.log + #nosetests tests -w cobbler --with-coverage --cover-package=cobbler --cover-erase --quiet | tee test.log + nosetests cobbler/*.py -v | tee test.log build: clean manpage updatewui python setup.py build -f diff --git a/cobbler/cobbler.py b/cobbler/cobbler.py index bab7ce6f..cf3d503e 100755 --- a/cobbler/cobbler.py +++ b/cobbler/cobbler.py @@ -88,8 +88,10 @@ def main(): return 1 def test_hello(): - # trivial command line testing, by no means exhaustive - assert BootCLI().run(["/usr/bin/cobbler", "cobbler", "--help"]) == 0 + # extra trivial command line testing, by no means exhaustive + rc = main() + print "rc=%s" % rc + assert rc == 0 if __name__ == "__main__": sys.exit(main()) diff --git a/cobbler/modules/serializer_catalog.py b/cobbler/modules/serializer_catalog.py index 6b410f36..35d1517a 100644 --- a/cobbler/modules/serializer_catalog.py +++ b/cobbler/modules/serializer_catalog.py @@ -52,7 +52,8 @@ def serialize_item(obj, item): def serialize_delete(obj, item): filename = "/var/lib/cobbler/config/%ss.d/%s" % (obj.collection_type(),item.name) - os.remove(filename) + if os.path.exists(filename): + os.remove(filename) return True def deserialize_item_raw(collection_type, item_name): diff --git a/cobbler/remote.py b/cobbler/remote.py index f3819567..d9e32e0d 100644 --- a/cobbler/remote.py +++ b/cobbler/remote.py @@ -1304,36 +1304,97 @@ class CobblerReadWriteXMLRPCServer(SimpleXMLRPCServer.SimpleXMLRPCServer): # ********************************************************************* # ********************************************************************* -def test_bootstrap_start_clean() - - # first some API calls (non-remote) to prep our data - # clean out the distribution list - api = cobbler_api.BootAPI() - for d in api.distros(): - self.api.remove_distro(d,recursive=True) - for i in api.images() - self.api.remove_image(i) - for r in api.repos() - self.api.remove_repo(r) +def test_bootstrap_start_clean(): + + subprocess.call("rm -rf /var/lib/cobbler/config/distros.d/*",shell=True) + subprocess.call("rm -rf /var/lib/cobbler/config/profiles.d/*",shell=True) + subprocess.call("rm -rf /var/lib/cobbler/config/systems.d/*",shell=True) + subprocess.call("rm -rf /var/lib/cobbler/config/images.d/*",shell=True) + subprocess.call("rm -rf /var/lib/cobbler/config/repos.d/*",shell=True) + rc1 = subprocess.call("/sbin/service cobblerd restart",shell=True) + assert rc1 == 0 + rc2 = subprocess.call("/sbin/service httpd restart",shell=True) + assert rc2 == 0 + time.sleep(2) -def test_xmlrpc_ro() +def test_xmlrpc_ro(): test_bootstrap_start_clean() + server = xmlrpclib.Server("http://127.0.0.1/cobbler_api_rw") + time.sleep(2) - rc1 = subprocess.call("/sbin/service cobblerd restart") - assert rc1 == 0, "cobblerd restart ok" - - rc2 = subprocess.call("/sbin/service httpd restart") - assert rc2 == 0, "httpd restart ok" + # delete all distributions + distros = server.get_distros() + profiles = server.get_profiles() + systems = server.get_systems() + repos = server.get_repos() + images = server.get_systems() + settings = server.get_settings() + + assert distros == [] + assert profiles == [] + assert systems == [] + assert repos == [] + assert images == [] + assert type(settings) == type({}) - xmlrpclib.server = Server("127.0.0.1/cobbler_api_rw") + # now populate with something more useful + # using the non-remote API - # delete all distributions - distros = xmlrpclib.server.get_distros() + api = cobbler_api.BootAPI() + distro = api.new_distro() + distro.set_name("distro0") + distro.set_kernel("/etc/hosts") + distro.set_initrd("/etc/hosts") + api.add_distro(distro) + + profile = api.new_profile() + profile.set_name("profile0") + profile.set_distro("distro0") + api.add_profile(profile) + + system = api.new_system() + system.set_name("system0") + system.set_profile("profile0") + api.add_system(system) + + repo = api.new_repo() + repo.set_name("repo0") + repo.set_mirror("/tmp") + api.add_repo(repo) + + image = api.new_image() + image.set_name("image0") + image.set_file("/etc/hosts") + api.add_image(image) + # verify we have the new config in cobblerd + server.update() + + distros = server.get_distros() + assert len(distros) == 1 + assert distros[0]["name"] == "distro0" + + profiles = server.get_profiles() + assert len(profiles) == 1 + assert profiles[0]["name"] == "profile0" + + systems = server.get_systems() + assert len(systems) == 1 + assert systems[0]["name"] == "system0" + + repos = server.get_repos() + assert len(repos) == 1 + assert repos[0]["name"] == "repo0" + + images = server.get_images() + assert len(images) == 1 + assert images[0]["name"] == "image0" + + # now test specific gets that koan uses -def test_xmlrpc_rw() +def test_xmlrpc_rw(): # need tests for the various auth modes, not just one pass diff --git a/tests/tests.py b/cobbler/test_basic.py index 19213432..877f0aac 100644 --- a/tests/tests.py +++ b/cobbler/test_basic.py @@ -10,8 +10,8 @@ import tempfile import shutil import traceback -from cobbler.cexceptions import * -from cobbler import acls +from cexceptions import * +import acls #from cobbler import settings #from cobbler import collection_distros @@ -19,12 +19,10 @@ from cobbler import acls #from cobbler import collection_systems #from cobbler import collection_repos #from cobbler import collection_images -import cobbler.modules.authz_ownership as authz_module - -from cobbler import api - -from cobbler import config -from cobbler import utils +import modules.authz_ownership as authz_module +import api +import config +import utils utils.TEST_MODE = True FAKE_INITRD="initrd-2.6.15-1.2054_FAKE.img" @@ -103,12 +101,12 @@ class BootTest(unittest.TestCase): fd.close() self.assertTrue(repo.set_name("test_repo")) self.assertTrue(repo.set_mirror("/tmp/test_example_cobbler_repo")) - self.assertTrue(self.api.repos().add(repo)) + self.assertTrue(self.api.add_repo(repo)) image = self.api.new_image() self.assertTrue(image.set_name("test_image")) self.assertTrue(image.set_file("/etc/hosts")) # meaningless path - self.assertTrue(self.api.images().add(image)) + self.assertTrue(self.api.add_image(image)) class DuplicateNamesAndIpPrevention(BootTest): diff --git a/tests/README b/tests/README deleted file mode 100644 index d17ba9d0..00000000 --- a/tests/README +++ /dev/null @@ -1,6 +0,0 @@ -Do the following to enable "make test" from top-level - -yum install python-nose -easy_install coverage - - |