370af4da9ef35bcc3c094aea0baf7785e96d2913
[nepi.git] / test / lib / mock / metadata.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3
4 from constants import TESTBED_ID, TESTBED_VERSION
5 from nepi.core import metadata
6 from nepi.core.attributes import Attribute
7 from nepi.util import validation, tags
8 from nepi.util.constants import ApplicationStatus as AS
9
10 NODE = "Node"
11 IFACE = "Interface"
12 APP = "Application"
13
14 ### Connection functions ####
15
16 def connect_cross(testbed_instance, guid, cross_data):
17     connected = True
18     testbed_instance.set(guid, "cross", True)
19
20 ### Creation functions ###
21
22 def create_node(testbed_instance, guid):
23     testbed_instance.elements[guid] = NODE
24
25 def create_iface(testbed_instance, guid):
26      testbed_instance.elements[guid] = IFACE
27
28 def create_application(testbed_instance, guid):
29      testbed_instance.elements[guid] = APP
30
31 ### Start/Stop functions ###
32
33 ### Status functions ###
34
35 def status_application(testbed_instance, guid):
36     return AS.STATUS_FINISHED
37
38 ### Factory information ###
39
40 connector_types = dict({
41     "apps": dict({
42                 "help": "Connector from node to applications", 
43                 "name": "apps",
44                 "max": -1, 
45                 "min": 0
46             }),
47     "devs": dict({
48                 "help": "Connector from node to network interfaces", 
49                 "name": "devs",
50                 "max": -1, 
51                 "min": 0
52             }),
53     "node": dict({
54                 "help": "Connector to a Node", 
55                 "name": "node",
56                 "max": 1, 
57                 "min": 1
58             }),
59     "iface": dict({
60                 "help": "Connector to a Interface", 
61                 "name": "iface",
62                 "max": 1, 
63                 "min": 0
64             }),
65     "cross": dict({
66                 "help": "Connector to an Interface in other testbed", 
67                 "name": "cross",
68                 "max": 1, 
69                 "min": 0
70             }),
71    })
72
73 connections = [
74     dict({
75         "from": (TESTBED_ID, NODE, "devs"),
76         "to":   (TESTBED_ID, IFACE, "node"),
77         "can_cross": False
78     }),
79     dict({
80         "from": (TESTBED_ID, IFACE, "iface"),
81         "to":   (TESTBED_ID, IFACE, "iface"),
82         "can_cross": False
83     }),
84     dict({
85         "from": (TESTBED_ID, NODE, "apps"),
86         "to":   (TESTBED_ID, APP, "node"),
87         "can_cross": False
88     }),
89     dict({
90         "from": (TESTBED_ID, IFACE, "cross"),
91         "to":   ("mock2", IFACE, "cross"),
92         "init_code": connect_cross,
93         "can_cross": True,
94     })]
95
96 attributes = dict({
97     "fake": dict({
98                 "name": "fake",
99                 "help": "fake attribute",
100                 "type": Attribute.BOOL,
101                 "value": False,
102                 "validation_function": validation.is_bool
103             }),
104     "test": dict({
105                 "name": "test",
106                 "help": "test attribute",
107                 "type": Attribute.STRING,
108                 "validation_function": validation.is_string
109             }),
110     "cross": dict({
111                 "name": "cross",
112                 "help": "Attribute that indicates if cross connection was performed",
113                 "type": Attribute.BOOL,
114                 "value": False,
115                 "validation_function": validation.is_bool
116         }),
117     "maxAddresses": dict({
118                 "name": "maxAddresses",
119                 "help": "Attribute that indicates the maximum number of addresses for an interface",
120                 "type": Attribute.INTEGER,
121                 "value": 3,
122                 "flags" : Attribute.DesignReadOnly |\
123                     Attribute.ExecInvisible |\
124                     Attribute.Metadata,
125                 "validation_function": validation.is_integer
126        })
127     })
128
129 traces = dict({
130     "fake": dict({
131                 "name": "fake",
132                 "help": "fake trace"
133               }),
134     })
135
136 factories_order = [ NODE, IFACE, APP ]
137
138 factories_info = dict({
139     NODE: dict({
140             "help": "Fake node",
141             "category": "topology",
142             "create_function": create_node,
143             "start_function": None,
144             "stop_function": None,
145             "status_function": None,
146             "box_attributes": ["fake","test"],
147             "connector_types": ["devs", "apps"],
148             "tags": [tags.MOBILE, tags.NODE, tags.ALLOW_ROUTES],
149        }),
150     IFACE: dict({
151             "help": "Fake iface",
152             "category": "devices",
153             "create_function": create_iface,
154             "start_function": None,
155             "stop_function": None,
156             "status_function": None,
157             "allow_addresses": True,
158             "factory_attributes": ["fake", "maxAddresses"],
159             "box_attributes": ["fake", "test", "cross"],
160             "connector_types": ["node", "iface", "cross"],
161             "tags": [tags.INTERFACE, tags.ALLOW_ADDRESSES],
162        }),
163     APP: dict({
164             "help": "Fake application",
165             "category": "applications",
166             "create_function": create_application,
167             "start_function": None,
168             "stop_function": None,
169             "status_function": status_application,
170             "box_attributes": ["fake", "test"],
171             "connector_types": ["node"],
172             "traces": ["fake"],
173             "tags": [tags.APPLICATION],
174         }),
175 })
176
177 testbed_attributes = dict({
178         "fake": dict({
179                 "name": "fake",
180                 "help": "fake attribute",
181                 "type": Attribute.BOOL,
182                 "value": False,
183                 "range": None,
184                 "allowed": None,
185                 "validation_function": validation.is_bool
186             }),
187         "test": dict({
188                 "name": "test",
189                 "help": "test attribute",
190                 "type": Attribute.STRING,
191                 "validation_function": validation.is_string
192             }),
193     })
194
195 class MetadataInfo(metadata.MetadataInfo):
196     @property
197     def connector_types(self):
198         return connector_types
199
200     @property
201     def connections(self):
202         return connections
203
204     @property
205     def attributes(self):
206         return attributes
207
208     @property
209     def traces(self):
210         return traces
211
212     @property
213     def create_order(self):
214         return factories_order
215
216     @property
217     def configure_order(self):
218         return factories_order
219
220     @property
221     def factories_info(self):
222         return factories_info
223
224     @property
225     def testbed_attributes(self):
226         return testbed_attributes
227
228     @property
229     def testbed_id(self):
230         return TESTBED_ID
231
232     @property
233     def testbed_version(self):
234         return TESTBED_VERSION
235