Incorporated the recent problems in Comon into the QA test for vsys.
[tests.git] / system / TestApiserver.py
1 # $Id$
2 # wrapper to xmlrpc server, that support dry-run commands
3 # we dont want to have to depend on PLCAPI, so:
4 import xmlrpclib
5
6 server_methods = [ ('GetNodes' ,  []),
7                    ('AddNode' , True),
8                    ('DeleteNode' , True),
9                    ('UpdateNode' , True),
10                    ('AddInterface' , True),
11                    ('GetInterfaces' , True),
12                    ('GetTagTypes' , []),
13                    ('AddTagType' , True),
14                    ('AddInterfaceSetting' , True),
15                    ('GetBootMedium' , True),
16                    ('GetNodeGroups' , True),
17                    ('AddNodeGroup' , True),
18                    ('DeleteNodeGroup', True),
19                    ('GetNodeTags', True),
20                    ('AddNodeTag', True),
21                    ('AddInitScript' , True),
22                    ('DeleteInitScript', True),
23                    ('GetInitScripts', True),
24                    ('AddSite' , True),
25                    ('AddSiteAddress' , True),
26                    ('DeleteSite' , True),
27                    ('DeleteSlice' , True),
28                    ('AddSlice' , True),
29                    ('AddPersonToSlice' , True),
30                    ('AddSliceToNodes' , True),
31                    ('AddSliceAttribute' , True),
32                    ('AddPerson' , True),
33                    ('UpdatePerson' , True),
34                    ('AddRoleToPerson' , True),
35                    ('AddPersonToSite' , True),
36                    ('DeletePerson' , True),
37                    ('AddPersonKey' , True),
38                    ('GetPlcRelease', {'build': {'target-arch':'i386'}}),
39                    ('GetSites', []),
40                    ]
41
42 class TestApiserver:
43     class Callable:
44         def __init__(self,server,dry_run,method,defaults):
45             self.server=server
46             self.dry_run=dry_run
47             self.method=method
48             self.defaults=defaults
49         def __call__ (self, *args):
50             if self.dry_run:
51                 print "dry_run:",self.method,
52                 if len(args)>0 and type(args[0])==type({}) and args[0].has_key('AuthMethod'):
53                     print '<auth>',
54                     args=args[1:]
55                 print '(',args,')'
56                 return self.defaults
57             else:
58                 actual_method=getattr(self.server,self.method)
59                 return actual_method(*args)
60
61     def __init__(self,url,dry_run=False):
62         self.apiserver = xmlrpclib.Server(url,allow_none=True)
63         self.dry_run=dry_run
64         for (method,defaults) in server_methods:
65             setattr(self,method,TestApiserver.Callable(self.apiserver,dry_run,method,defaults))