added mock testbed for unit testing.
[nepi.git] / test / lib / mock / metadata_v01.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3
4 from constants import TESTBED_ID
5 from nepi.core import metadata
6 from nepi.core.attributes import Attribute
7 from nepi.util import validation
8 from nepi.util.constants import STATUS_FINISHED
9
10 NODE = "Node"
11 IFACE = "Interface"
12 APP = "Application"
13
14 ### Connection functions ####
15
16 ### Creation functions ###
17
18 def create_node(testbed_instance, guid, parameters, factory_parameters):
19     element = NODE 
20     testbed_instance.elements[guid] = element
21
22 def create_iface(testbed_instance, guid, parameters, factory_parameters):
23      element = IFACE
24      testbed_instance.elements[guid] = element
25
26 def create_application(testbed_instance, guid, parameters, factory_parameters):
27      element = APP
28      testbed_instance.elements[guid] = element
29
30 ### Start/Stop functions ###
31
32 ### Status functions ###
33
34 def status_application(testbed_instance, guid):
35     return STATUS_FINISHED
36
37 ### Factory information ###
38
39 connector_types = dict({
40     "apps": dict({
41                 "help": "Connector from node to applications", 
42                 "name": "apps",
43                 "max": -1, 
44                 "min": 0
45             }),
46     "devs": dict({
47                 "help": "Connector from node to network interfaces", 
48                 "name": "devs",
49                 "max": -1, 
50                 "min": 0
51             }),
52     "node": dict({
53                 "help": "Connector to a Node", 
54                 "name": "node",
55                 "max": 1, 
56                 "min": 1
57             }),
58     "iface": dict({
59                 "help": "Connector to a Interface", 
60                 "name": "iface",
61                 "max": 1, 
62                 "min": 0
63             }),
64    })
65
66 connections = [
67     dict({
68         "from": (TESTBED_ID, NODE, "devs"),
69         "to":   (TESTBED_ID, IFACE, "node"),
70         "code": None,
71         "can_cross": False
72     }),
73     dict({
74         "from": (TESTBED_ID, IFACE, "iface"),
75         "to":   (TESTBED_ID, IFACE, "iface"),
76         "code": None,
77         "can_cross": False
78     }),
79     dict({
80         "from": (TESTBED_ID, NODE, "apps"),
81         "to":   (TESTBED_ID, APP, "node"),
82         "code": None,
83         "can_cross": False
84     })
85 ]
86
87 attributes = dict({
88     "fake": dict({
89                 "name": "fake",
90                 "help": "fake attribute",
91                 "type": Attribute.BOOL,
92                 "value": False,
93                 "range": None,
94                 "allowed": None,
95                 "validation_function": validation.is_bool
96             }),
97     })
98
99 traces = dict({
100     "fake": dict({
101                 "name": "fake",
102                 "help": "fake trace"
103               }),
104     })
105
106 factories_order = [ NODE, IFACE, APP ]
107
108 factories_info = dict({
109     NODE: dict({
110             "help": "Fake node",
111             "category": "topology",
112             "create_function": create_node,
113             "start_function": None,
114             "stop_function": None,
115             "status_function": None,
116             "box_attributes": ["fake"],
117             "connector_types": ["devs", "apps"]
118        }),
119     IFACE: dict({
120             "help": "Fake iface",
121             "category": "devices",
122             "create_function": create_iface,
123             "start_function": None,
124             "stop_function": None,
125             "status_function": None,
126             "factory_attributes": ["fake"],
127             "box_attributes": ["fake"],
128             "connector_types": ["node", "iface"]
129        }),
130     APP: dict({
131             "help": "Fake application",
132             "category": "applications",
133             "create_function": create_application,
134             "start_function": None,
135             "stop_function": None,
136             "status_function": status_application,
137             "box_attributes": ["fake"],
138             "connector_types": ["node"],
139             "traces": ["fake"]
140         }),
141 })
142
143 testbed_attributes = dict({
144         "fake": dict({
145                 "name": "fake",
146                 "help": "fake attribute",
147                 "type": Attribute.BOOL,
148                 "value": False,
149                 "range": None,
150                 "allowed": None,
151                 "validation_function": validation.is_bool
152             }),
153     })
154
155 class VersionedMetadataInfo(metadata.VersionedMetadataInfo):
156     @property
157     def connections_types(self):
158         return connection_types
159
160     @property
161     def connections(self):
162         return connections
163
164     @property
165     def attributes(self):
166         return attributes
167
168     @property
169     def traces(self):
170         return traces
171
172     @property
173     def factories_order(self):
174         return factories_order
175
176     @property
177     def factories_info(self):
178         return factories_info
179
180     @property
181     def testbed_attributes(self):
182         return testbed_attributes
183