1
2
3
4
5
6
7
8
9
10
11
12
13
14 import sys
15 import logging
16 logging.basicConfig()
17 root = logging.getLogger()
18 root.setLevel(logging.CRITICAL)
19
20 import Globals
21
22 from utils import importClass, importClasses
23 from Products.ZenRelations.Exceptions import ZenSchemaError
24
26 """
27 Walk all relationship schema definitions and confirm that they
28 have reciprical peers on the remote class.
29 """
30 for relname, rel in cls._relations:
31 try:
32 remoteClass = importClass(rel.remoteClass, None)
33 except AttributeError, e:
34 logging.critical("RemoteClass '%s' from '%s.%s' not found",
35 rel.remoteClass, cls.__name__, relname)
36 continue
37
38 try:
39 rschema = remoteClass.lookupSchema(rel.remoteName)
40 except ZenSchemaError, e:
41 logging.critical("Inverse def '%s' for '%s.%s' not found on '%s'",
42 rel.remoteName, cls.__name__, relname,rel.remoteClass)
43 continue
44 except Exception, e:
45 logging.critical("RemoteClass '%s' for '%s.%s' problem.",
46 rel.remoteName, cls.__name__, relname)
47 logging.critical(e)
48 try:
49 localClass = importClass(rschema.remoteClass, None)
50 except AttributeError, e:
51 logging.critical(e)
52 if not issubclass(cls, localClass):
53 logging.critical("Inverse def '%s' from '%s.%s' wrong "
54 "remoteClass: '%s'", rel.remoteName, cls.__name__,
55 relname,rschema.remoteClass)
56 if rschema.remoteName != relname:
57 logging.critical("Inverse def '%s' from '%s.%s' wrong "
58 "remoteName: '%s'", rel.remoteName, cls.__name__, relname,
59 rschema.remoteName)
60 if rel.remoteType != rschema.__class__:
61 logging.critical("'%s.%s' inverse '%s' type %s != %s",
62 cls.__name__, relname, rel.remoteName,
63 rschema.__class__.__name__, rel.remoteType.__name__)
64
65
66 baseModule = None
67 if len(sys.argv) > 1:
68 baseModule = sys.argv[1]
69
70 classList = importClasses(basemodule=baseModule,
71 skipnames=("ZentinelPortal", "ZDeviceLoader"))
72
73 for classdef in classList:
74 if hasattr(classdef, "lookupSchema"):
75 logging.info("checking class %s...", classdef.__name__)
76 checkRelationshipSchema(classdef, baseModule)
77