Revision 3ade0e0e

b/Makefile.am
786 786
	test/htools-text-backend.test
787 787

  
788 788
python_tests = \
789
	doc/examples/rapi_testutils.py \
789 790
	test/ganeti.asyncnotifier_unittest.py \
790 791
	test/ganeti.backend_unittest.py \
791 792
	test/ganeti.bdev_unittest.py \
b/autotools/run-in-tempdir
8 8
tmpdir=$(mktemp -d -t gntbuild.XXXXXXXX)
9 9
trap "rm -rf $tmpdir" EXIT
10 10

  
11
mkdir $tmpdir/doc
12

  
11 13
cp -r autotools daemons scripts lib tools test $tmpdir
14
cp -r doc/examples $tmpdir/doc
15

  
12 16
mv $tmpdir/lib $tmpdir/ganeti
13 17
ln -T -s $tmpdir/ganeti $tmpdir/lib
14 18
mkdir -p $tmpdir/htools
b/doc/examples/rapi_testutils.py
1
#!/usr/bin/python
2
#
3

  
4
# Copyright (C) 2012 Google Inc.
5
#
6
# This program is free software; you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License as published by
8
# the Free Software Foundation; either version 2 of the License, or
9
# (at your option) any later version.
10
#
11
# This program is distributed in the hope that it will be useful, but
12
# WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
# General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License
17
# along with this program; if not, write to the Free Software
18
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19
# 02110-1301, USA.
20

  
21

  
22
"""Example for using L{ganeti.rapi.testutils}"""
23

  
24
import logging
25

  
26
from ganeti import rapi
27

  
28
import ganeti.rapi.testutils
29

  
30

  
31
def main():
32
  # Disable log output
33
  logging.getLogger("").setLevel(logging.CRITICAL)
34

  
35
  cl = rapi.testutils.InputTestClient()
36

  
37
  print "Testing features ..."
38
  assert isinstance(cl.GetFeatures(), list)
39

  
40
  print "Testing node evacuation ..."
41
  result = cl.EvacuateNode("inst1.example.com",
42
                           mode=rapi.client.NODE_EVAC_PRI)
43
  assert result is NotImplemented
44

  
45
  print "Testing listing instances ..."
46
  for bulk in [False, True]:
47
    result = cl.GetInstances(bulk=bulk)
48
    assert result is NotImplemented
49

  
50
  print "Testing renaming instance ..."
51
  result = cl.RenameInstance("inst1.example.com", "inst2.example.com")
52
  assert result is NotImplemented
53

  
54
  print "Testing renaming instance with error ..."
55
  try:
56
    # This test deliberately uses an invalid value for the boolean parameter
57
    # "ip_check"
58
    result = cl.RenameInstance("inst1.example.com", "inst2.example.com",
59
                               ip_check=["non-boolean", "value"])
60
  except rapi.testutils.VerificationError:
61
    # Verification failed as expected
62
    pass
63
  else:
64
    raise Exception("This test should have failed")
65

  
66
  print "Success!"
67

  
68

  
69
if __name__ == "__main__":
70
  main()

Also available in: Unified diff