Statistics
| Branch: | Tag: | Revision:

root / doc / examples / rapi_testutils.py @ ab6536ba

History | View | Annotate | Download (2 kB)

1 3ade0e0e Michael Hanselmann
#!/usr/bin/python
2 3ade0e0e Michael Hanselmann
#
3 3ade0e0e Michael Hanselmann
4 3ade0e0e Michael Hanselmann
# Copyright (C) 2012 Google Inc.
5 3ade0e0e Michael Hanselmann
#
6 3ade0e0e Michael Hanselmann
# This program is free software; you can redistribute it and/or modify
7 3ade0e0e Michael Hanselmann
# it under the terms of the GNU General Public License as published by
8 3ade0e0e Michael Hanselmann
# the Free Software Foundation; either version 2 of the License, or
9 3ade0e0e Michael Hanselmann
# (at your option) any later version.
10 3ade0e0e Michael Hanselmann
#
11 3ade0e0e Michael Hanselmann
# This program is distributed in the hope that it will be useful, but
12 3ade0e0e Michael Hanselmann
# WITHOUT ANY WARRANTY; without even the implied warranty of
13 3ade0e0e Michael Hanselmann
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 3ade0e0e Michael Hanselmann
# General Public License for more details.
15 3ade0e0e Michael Hanselmann
#
16 3ade0e0e Michael Hanselmann
# You should have received a copy of the GNU General Public License
17 3ade0e0e Michael Hanselmann
# along with this program; if not, write to the Free Software
18 3ade0e0e Michael Hanselmann
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 3ade0e0e Michael Hanselmann
# 02110-1301, USA.
20 3ade0e0e Michael Hanselmann
21 3ade0e0e Michael Hanselmann
22 3ade0e0e Michael Hanselmann
"""Example for using L{ganeti.rapi.testutils}"""
23 3ade0e0e Michael Hanselmann
24 3ade0e0e Michael Hanselmann
import logging
25 3ade0e0e Michael Hanselmann
26 3ade0e0e Michael Hanselmann
from ganeti import rapi
27 3ade0e0e Michael Hanselmann
28 3ade0e0e Michael Hanselmann
import ganeti.rapi.testutils
29 3ade0e0e Michael Hanselmann
30 3ade0e0e Michael Hanselmann
31 3ade0e0e Michael Hanselmann
def main():
32 3ade0e0e Michael Hanselmann
  # Disable log output
33 3ade0e0e Michael Hanselmann
  logging.getLogger("").setLevel(logging.CRITICAL)
34 3ade0e0e Michael Hanselmann
35 3ade0e0e Michael Hanselmann
  cl = rapi.testutils.InputTestClient()
36 3ade0e0e Michael Hanselmann
37 3ade0e0e Michael Hanselmann
  print "Testing features ..."
38 3ade0e0e Michael Hanselmann
  assert isinstance(cl.GetFeatures(), list)
39 3ade0e0e Michael Hanselmann
40 3ade0e0e Michael Hanselmann
  print "Testing node evacuation ..."
41 3ade0e0e Michael Hanselmann
  result = cl.EvacuateNode("inst1.example.com",
42 3ade0e0e Michael Hanselmann
                           mode=rapi.client.NODE_EVAC_PRI)
43 3ade0e0e Michael Hanselmann
  assert result is NotImplemented
44 3ade0e0e Michael Hanselmann
45 3ade0e0e Michael Hanselmann
  print "Testing listing instances ..."
46 3ade0e0e Michael Hanselmann
  for bulk in [False, True]:
47 3ade0e0e Michael Hanselmann
    result = cl.GetInstances(bulk=bulk)
48 3ade0e0e Michael Hanselmann
    assert result is NotImplemented
49 3ade0e0e Michael Hanselmann
50 3ade0e0e Michael Hanselmann
  print "Testing renaming instance ..."
51 3ade0e0e Michael Hanselmann
  result = cl.RenameInstance("inst1.example.com", "inst2.example.com")
52 3ade0e0e Michael Hanselmann
  assert result is NotImplemented
53 3ade0e0e Michael Hanselmann
54 3ade0e0e Michael Hanselmann
  print "Testing renaming instance with error ..."
55 3ade0e0e Michael Hanselmann
  try:
56 3ade0e0e Michael Hanselmann
    # This test deliberately uses an invalid value for the boolean parameter
57 3ade0e0e Michael Hanselmann
    # "ip_check"
58 3ade0e0e Michael Hanselmann
    result = cl.RenameInstance("inst1.example.com", "inst2.example.com",
59 3ade0e0e Michael Hanselmann
                               ip_check=["non-boolean", "value"])
60 3ade0e0e Michael Hanselmann
  except rapi.testutils.VerificationError:
61 3ade0e0e Michael Hanselmann
    # Verification failed as expected
62 3ade0e0e Michael Hanselmann
    pass
63 3ade0e0e Michael Hanselmann
  else:
64 3ade0e0e Michael Hanselmann
    raise Exception("This test should have failed")
65 3ade0e0e Michael Hanselmann
66 3ade0e0e Michael Hanselmann
  print "Success!"
67 3ade0e0e Michael Hanselmann
68 3ade0e0e Michael Hanselmann
69 3ade0e0e Michael Hanselmann
if __name__ == "__main__":
70 3ade0e0e Michael Hanselmann
  main()