diff --git a/Makefile.am b/Makefile.am index f769518b3f4f870c4fffc4be2cceeb39a3a50f28..31cd8fa5c08af389509e167252f6986ffb67ab47 100644 --- a/Makefile.am +++ b/Makefile.am @@ -786,6 +786,7 @@ TEST_FILES = \ test/htools-text-backend.test python_tests = \ + doc/examples/rapi_testutils.py \ test/ganeti.asyncnotifier_unittest.py \ test/ganeti.backend_unittest.py \ test/ganeti.bdev_unittest.py \ diff --git a/autotools/run-in-tempdir b/autotools/run-in-tempdir index 6e0b758cfe5b1d342c97c47cdb615bdad2ad1e85..e656ffe732a37fd25538b954f986d7673dadf08c 100755 --- a/autotools/run-in-tempdir +++ b/autotools/run-in-tempdir @@ -8,7 +8,11 @@ set -e tmpdir=$(mktemp -d -t gntbuild.XXXXXXXX) trap "rm -rf $tmpdir" EXIT +mkdir $tmpdir/doc + cp -r autotools daemons scripts lib tools test $tmpdir +cp -r doc/examples $tmpdir/doc + mv $tmpdir/lib $tmpdir/ganeti ln -T -s $tmpdir/ganeti $tmpdir/lib mkdir -p $tmpdir/htools diff --git a/doc/examples/rapi_testutils.py b/doc/examples/rapi_testutils.py new file mode 100755 index 0000000000000000000000000000000000000000..8a4ceab4bac3456260c0938cff0efa0c3f23435e --- /dev/null +++ b/doc/examples/rapi_testutils.py @@ -0,0 +1,70 @@ +#!/usr/bin/python +# + +# Copyright (C) 2012 Google Inc. +# +# 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; either version 2 of the License, or +# (at your option) any later version. +# +# 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 +# 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., 51 Franklin Street, Fifth Floor, Boston, MA +# 02110-1301, USA. + + +"""Example for using L{ganeti.rapi.testutils}""" + +import logging + +from ganeti import rapi + +import ganeti.rapi.testutils + + +def main(): + # Disable log output + logging.getLogger("").setLevel(logging.CRITICAL) + + cl = rapi.testutils.InputTestClient() + + print "Testing features ..." + assert isinstance(cl.GetFeatures(), list) + + print "Testing node evacuation ..." + result = cl.EvacuateNode("inst1.example.com", + mode=rapi.client.NODE_EVAC_PRI) + assert result is NotImplemented + + print "Testing listing instances ..." + for bulk in [False, True]: + result = cl.GetInstances(bulk=bulk) + assert result is NotImplemented + + print "Testing renaming instance ..." + result = cl.RenameInstance("inst1.example.com", "inst2.example.com") + assert result is NotImplemented + + print "Testing renaming instance with error ..." + try: + # This test deliberately uses an invalid value for the boolean parameter + # "ip_check" + result = cl.RenameInstance("inst1.example.com", "inst2.example.com", + ip_check=["non-boolean", "value"]) + except rapi.testutils.VerificationError: + # Verification failed as expected + pass + else: + raise Exception("This test should have failed") + + print "Success!" + + +if __name__ == "__main__": + main()