0ba35563fdcf22e104fb7b431e74012f652b194b
[integration/test.git] / csit / variables / tcpmd5user / variables.py
1 """
2 Variables file for tcpmd5user suite.
3
4 Expected JSON templates are fairly long,
5 therefore there are moved out of testcase file.
6 Also, it is needed to generate base64 encoded tunnel name
7 from Mininet IP (which is not known beforehand),
8 so it is easier to employ Python here,
9 than do manipulation in Robot file.
10 """
11 # Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
12 #
13 # This program and the accompanying materials are made available under the
14 # terms of the Eclipse Public License v1.0 which accompanies this distribution,
15 # and is available at http://www.eclipse.org/legal/epl-v10.html
16
17 import base64
18 from string import Template
19
20
21 __author__ = "Vratko Polak"
22 __copyright__ = "Copyright(c) 2015, Cisco Systems, Inc."
23 __license__ = "Eclipse Public License v1.0"
24 __email__ = "vrpolak@cisco.com"
25
26
27 # FIXME: Migrate values shared by other suites to separate Python module.
28
29
30 def get_variables(mininet_ip):
31     """Return dict of variables for the given IPv4 address of Mininet VM."""
32     # TODO: Document in 'V' fashion, as in pcepuser/variables.py using more systematic local variable names.
33     # Dict of variables to return, starts empty and grows as function proceeds.
34     variables = {}
35     # Given mininet_ip, this will be the sympolic name uf tunnel under test.
36     tunnelname = "pcc_" + mininet_ip + "_tunnel_1"
37     # Base64 code for the symbolic name, as that is present in datastore.
38     tunnelname_bytes = tunnelname.encode("ascii")
39     pathcode_encoded = base64.b64encode(tunnelname_bytes)
40     pathcode = pathcode_encoded.decode("ascii")
41     variables["pcc_name"] = tunnelname
42     variables["pcc_name_code"] = pathcode
43     # JSON response when pcep-topology is ready but no PCC is connected.
44     variables[
45         "offjson"
46     ] = """{
47  "topology": [
48   {
49    "topology-id": "pcep-topology",
50    "topology-types": {
51     "network-topology-pcep:topology-pcep": {}
52    }
53   }
54  ]
55 }"""
56     # Template of JSON response with pcep-topology seeing 1 PCC 1 LSP.
57     onjsontempl = Template(
58         """{
59  "topology": [
60   {
61    "node": [
62     {
63      "network-topology-pcep:path-computation-client": {
64       "ip-address": "$IP",
65       "reported-lsp": [
66        {
67         "name": "$NAME",
68         "path": [
69          {
70           "ero": {
71            "ignore": false,
72            "processing-rule": false,
73            "subobject": [
74             {
75              "ip-prefix": {
76               "ip-prefix": "1.1.1.1/32"
77              },
78              "loose": false
79             }
80            ]
81           },
82           "lsp-id": 1,
83           "odl-pcep-ietf-stateful07:lsp": {
84            "administrative": true,
85            "delegate": true,
86            "ignore": false,
87            "odl-pcep-ietf-initiated00:create": false,
88            "operational": "up",
89            "plsp-id": 1,
90            "processing-rule": false,
91            "remove": false,
92            "sync": true,
93            "tlvs": {
94             "lsp-identifiers": {
95              "ipv4": {
96               "ipv4-extended-tunnel-id": "$IP",
97               "ipv4-tunnel-endpoint-address": "1.1.1.1",
98               "ipv4-tunnel-sender-address": "$IP"
99              },
100              "lsp-id": 1,
101              "tunnel-id": 1
102             },
103             "symbolic-path-name": {
104              "path-name": "$CODE"
105             }
106            }
107           }
108          }
109         ]
110        }
111       ],
112       "state-sync": "synchronized",
113       "stateful-tlv": {
114        "odl-pcep-ietf-stateful07:stateful": {
115         "lsp-update-capability": true,
116         "odl-pcep-ietf-initiated00:initiation": true
117        }
118       }
119      },
120      "node-id": "pcc://$IP"
121     }
122    ],
123    "topology-id": "pcep-topology",
124    "topology-types": {
125     "network-topology-pcep:topology-pcep": {}
126    }
127   }
128  ]
129 }"""
130     )
131     # Dictionly which tells values for placeholders.
132     repl_dict = {"IP": mininet_ip, "NAME": tunnelname, "CODE": pathcode}
133     # The finalized JSON.
134     variables["onjson"] = onjsontempl.substitute(repl_dict)
135     # The following strings are XML data.
136     # See https://wiki.opendaylight.org/view/BGP_LS_PCEP:TCP_MD5_Guide#RESTCONF_Configuration
137     # For curl, string is suitable to became -d argument only after
138     # replacing ' -> '"'"' and enclosing in single quotes.
139     variables[
140         "key_access_module"
141     ] = """<module xmlns="urn:opendaylight:params:xml:ns:yang:controller:config">
142  <type xmlns:x="urn:opendaylight:params:xml:ns:yang:controller:tcpmd5:jni:cfg">x:native-key-access-factory</type>
143  <name>global-key-access-factory</name>
144 </module>"""
145     variables[
146         "key_access_service"
147     ] = """<service xmlns="urn:opendaylight:params:xml:ns:yang:controller:config">
148  <type xmlns:x="urn:opendaylight:params:xml:ns:yang:controller:tcpmd5:cfg">x:key-access-factory</type>
149  <instance>
150   <name>global-key-access-factory</name>
151   <provider>/modules/module[type='native-key-access-factory'][name='global-key-access-factory']</provider>
152  </instance>
153 </service>"""
154     variables[
155         "client_channel_module"
156     ] = """<module xmlns="urn:opendaylight:params:xml:ns:yang:controller:config">
157  <type xmlns:x="urn:opendaylight:params:xml:ns:yang:controller:tcpmd5:netty:cfg">x:md5-client-channel-factory</type>
158  <name>md5-client-channel-factory</name>
159  <key-access-factory xmlns="urn:opendaylight:params:xml:ns:yang:controller:tcpmd5:netty:cfg">
160   <type xmlns:x="urn:opendaylight:params:xml:ns:yang:controller:tcpmd5:cfg">x:key-access-factory</type>
161   <name>global-key-access-factory</name>
162  </key-access-factory>
163 </module>"""
164     variables[
165         "client_channel_service"
166     ] = """<service xmlns="urn:opendaylight:params:xml:ns:yang:controller:config">
167  <type xmlns:x="urn:opendaylight:params:xml:ns:yang:controller:tcpmd5:netty:cfg">x:md5-channel-factory</type>
168  <instance>
169   <name>md5-client-channel-factory</name>
170   <provider>/modules/module[type='md5-client-channel-factory'][name='md5-client-channel-factory']</provider>
171  </instance>
172 </service>"""
173     variables[
174         "server_channel_module"
175     ] = """<module xmlns="urn:opendaylight:params:xml:ns:yang:controller:config">
176  <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:tcpmd5:netty:cfg">"""
177     # What is your favourite way to concatenate strings without resembling tuple?
178     variables[
179         "server_channel_module"
180     ] += """prefix:md5-server-channel-factory-impl</type>
181  <name>md5-server-channel-factory</name>
182  <server-key-access-factory xmlns="urn:opendaylight:params:xml:ns:yang:controller:tcpmd5:netty:cfg">
183   <type xmlns:x="urn:opendaylight:params:xml:ns:yang:controller:tcpmd5:cfg">x:key-access-factory</type>
184   <name>global-key-access-factory</name>
185  </server-key-access-factory>
186 </module>"""
187     variables[
188         "server_channel_service"
189     ] = """<service xmlns="urn:opendaylight:params:xml:ns:yang:controller:config">
190  <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:tcpmd5:netty:cfg">"""
191     variables[
192         "server_channel_service"
193     ] += """prefix:md5-server-channel-factory</type>
194  <instance>
195   <name>md5-server-channel-factory</name>
196   <provider>/modules/module[type='md5-server-channel-factory-impl'][name='md5-server-channel-factory']</provider>
197  </instance>
198 </service>"""
199     variables[
200         "pcep_dispatcher_module"
201     ] = """<module xmlns="urn:opendaylight:params:xml:ns:yang:controller:config">
202  <type xmlns:x="urn:opendaylight:params:xml:ns:yang:controller:pcep:impl">x:pcep-dispatcher-impl</type>
203  <name>global-pcep-dispatcher</name>
204  <md5-channel-factory xmlns="urn:opendaylight:params:xml:ns:yang:controller:pcep:impl">
205   <type xmlns:x="urn:opendaylight:params:xml:ns:yang:controller:tcpmd5:netty:cfg">x:md5-channel-factory</type>
206   <name>md5-client-channel-factory</name>
207  </md5-channel-factory>
208  <md5-server-channel-factory xmlns="urn:opendaylight:params:xml:ns:yang:controller:pcep:impl">
209   <type xmlns:x="urn:opendaylight:params:xml:ns:yang:controller:tcpmd5:netty:cfg">x:md5-server-channel-factory</type>
210   <name>md5-server-channel-factory</name>
211  </md5-server-channel-factory>
212 </module>"""
213     # Template to set password.
214     passwd_templ = Template(
215         """<module xmlns="urn:opendaylight:params:xml:ns:yang:controller:config">
216  <type xmlns:x="urn:opendaylight:params:xml:ns:yang:controller:pcep:topology:provider">x:pcep-topology-provider</type>
217  <name>pcep-topology</name>
218  <client xmlns="urn:opendaylight:params:xml:ns:yang:controller:pcep:topology:provider">
219   <address xmlns="urn:opendaylight:params:xml:ns:yang:controller:pcep:topology:provider">$IP</address>
220 $PASSWD </client>
221 </module>"""
222     )
223     # We use three template instantiations. No password:
224     repl_dict = {"IP": mininet_ip, "PASSWD": ""}
225     variables["no_passwd_module"] = passwd_templ.substitute(repl_dict)
226     changeme = """  <password>changeme</password>
227 """
228     # wrong password
229     repl_dict = {"IP": mininet_ip, "PASSWD": changeme}
230     variables["passwd_changeme_module"] = passwd_templ.substitute(repl_dict)
231     # and correct password.
232     topsecret = """  <password>topsecret</password>
233 """
234     repl_dict = {"IP": mininet_ip, "PASSWD": topsecret}
235     variables["passwd_topsecret_module"] = passwd_templ.substitute(repl_dict)
236     # All variables set, return dict to Robot.
237     return variables