6d0ce2fa91365ecda167a8bd35e7d9bfd4946296
[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 def get_variables(mininet_ip):
30     """Return dict of variables for the given IPv4 address of Mininet VM."""
31     # TODO: Document in 'V' fashion, as in pcepuser/variables.py using more systematic local variable names.
32     # Dict of variables to return, starts empty and grows as function proceeds.
33     variables = {}
34     # Given mininet_ip, this will be the sympolic name uf tunnel under test.
35     tunnelname = 'pcc_' + mininet_ip + '_tunnel_1'
36     # Base64 code for the symbolic name, as that is present in datastore.
37     tunnelname_bytes = tunnelname.encode('ascii')
38     pathcode_encoded = base64.b64encode(tunnelname_bytes)
39     pathcode = pathcode_encoded.decode('ascii')
40     variables['pcc_name'] = tunnelname
41     variables['pcc_name_code'] = pathcode
42     # JSON response when pcep-topology is ready but no PCC is connected.
43     variables['offjson'] = '''{
44  "topology": [
45   {
46    "topology-id": "pcep-topology",
47    "topology-types": {
48     "network-topology-pcep:topology-pcep": {}
49    }
50   }
51  ]
52 }'''
53     # Template of JSON response with pcep-topology seeing 1 PCC 1 LSP.
54     onjsontempl = Template('''{
55  "topology": [
56   {
57    "node": [
58     {
59      "network-topology-pcep:path-computation-client": {
60       "ip-address": "$IP",
61       "reported-lsp": [
62        {
63         "name": "$NAME",
64         "path": [
65          {
66           "ero": {
67            "ignore": false,
68            "processing-rule": false,
69            "subobject": [
70             {
71              "ip-prefix": {
72               "ip-prefix": "1.1.1.1/32"
73              },
74              "loose": false
75             }
76            ]
77           },
78           "lsp-id": 1,
79           "odl-pcep-ietf-stateful07:lsp": {
80            "administrative": true,
81            "delegate": true,
82            "ignore": false,
83            "odl-pcep-ietf-initiated00:create": false,
84            "operational": "up",
85            "plsp-id": 1,
86            "processing-rule": false,
87            "remove": false,
88            "sync": true,
89            "tlvs": {
90             "lsp-identifiers": {
91              "ipv4": {
92               "ipv4-extended-tunnel-id": "$IP",
93               "ipv4-tunnel-endpoint-address": "1.1.1.1",
94               "ipv4-tunnel-sender-address": "$IP"
95              },
96              "lsp-id": 1,
97              "tunnel-id": 1
98             },
99             "symbolic-path-name": {
100              "path-name": "$CODE"
101             }
102            }
103           }
104          }
105         ]
106        }
107       ],
108       "state-sync": "synchronized",
109       "stateful-tlv": {
110        "odl-pcep-ietf-stateful07:stateful": {
111         "lsp-update-capability": true,
112         "odl-pcep-ietf-initiated00:initiation": true
113        }
114       }
115      },
116      "node-id": "pcc://$IP"
117     }
118    ],
119    "topology-id": "pcep-topology",
120    "topology-types": {
121     "network-topology-pcep:topology-pcep": {}
122    }
123   }
124  ]
125 }''')
126     # Dictionly which tells values for placeholders.
127     repl_dict = {'IP': mininet_ip, 'NAME': tunnelname, 'CODE': pathcode}
128     # The finalized JSON.
129     variables['onjson'] = onjsontempl.substitute(repl_dict)
130     # The following strings are XML data.
131     # See https://wiki.opendaylight.org/view/BGP_LS_PCEP:TCP_MD5_Guide#RESTCONF_Configuration
132     # For curl, string is suitable to became -d argument only after
133     # replacing ' -> '"'"' and enclosing in single quotes.
134     variables['key_access_module'] = '''<module xmlns="urn:opendaylight:params:xml:ns:yang:controller:config">
135  <type xmlns:x="urn:opendaylight:params:xml:ns:yang:controller:tcpmd5:jni:cfg">x:native-key-access-factory</type>
136  <name>global-key-access-factory</name>
137 </module>'''
138     variables['key_access_service'] = '''<service xmlns="urn:opendaylight:params:xml:ns:yang:controller:config">
139  <type xmlns:x="urn:opendaylight:params:xml:ns:yang:controller:tcpmd5:cfg">x:key-access-factory</type>
140  <instance>
141   <name>global-key-access-factory</name>
142   <provider>/modules/module[type='native-key-access-factory'][name='global-key-access-factory']</provider>
143  </instance>
144 </service>'''
145     variables['client_channel_module'] = '''<module xmlns="urn:opendaylight:params:xml:ns:yang:controller:config">
146  <type xmlns:x="urn:opendaylight:params:xml:ns:yang:controller:tcpmd5:netty:cfg">x:md5-client-channel-factory</type>
147  <name>md5-client-channel-factory</name>
148  <key-access-factory xmlns="urn:opendaylight:params:xml:ns:yang:controller:tcpmd5:netty:cfg">
149   <type xmlns:x="urn:opendaylight:params:xml:ns:yang:controller:tcpmd5:cfg">x:key-access-factory</type>
150   <name>global-key-access-factory</name>
151  </key-access-factory>
152 </module>'''
153     variables['client_channel_service'] = '''<service xmlns="urn:opendaylight:params:xml:ns:yang:controller:config">
154  <type xmlns:x="urn:opendaylight:params:xml:ns:yang:controller:tcpmd5:netty:cfg">x:md5-channel-factory</type>
155  <instance>
156   <name>md5-client-channel-factory</name>
157   <provider>/modules/module[type='md5-client-channel-factory'][name='md5-client-channel-factory']</provider>
158  </instance>
159 </service>'''
160     variables['server_channel_module'] = '''<module xmlns="urn:opendaylight:params:xml:ns:yang:controller:config">
161  <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:tcpmd5:netty:cfg">'''
162     # What is your favourite way to concatenate strings without resembling tuple?
163     variables['server_channel_module'] += '''prefix:md5-server-channel-factory-impl</type>
164  <name>md5-server-channel-factory</name>
165  <server-key-access-factory xmlns="urn:opendaylight:params:xml:ns:yang:controller:tcpmd5:netty:cfg">
166   <type xmlns:x="urn:opendaylight:params:xml:ns:yang:controller:tcpmd5:cfg">x:key-access-factory</type>
167   <name>global-key-access-factory</name>
168  </server-key-access-factory>
169 </module>'''
170     variables['server_channel_service'] = '''<service xmlns="urn:opendaylight:params:xml:ns:yang:controller:config">
171  <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:tcpmd5:netty:cfg">'''
172     variables['server_channel_service'] += '''prefix:md5-server-channel-factory</type>
173  <instance>
174   <name>md5-server-channel-factory</name>
175   <provider>/modules/module[type='md5-server-channel-factory-impl'][name='md5-server-channel-factory']</provider>
176  </instance>
177 </service>'''
178     variables['pcep_dispatcher_module'] = '''<module xmlns="urn:opendaylight:params:xml:ns:yang:controller:config">
179  <type xmlns:x="urn:opendaylight:params:xml:ns:yang:controller:pcep:impl">x:pcep-dispatcher-impl</type>
180  <name>global-pcep-dispatcher</name>
181  <md5-channel-factory xmlns="urn:opendaylight:params:xml:ns:yang:controller:pcep:impl">
182   <type xmlns:x="urn:opendaylight:params:xml:ns:yang:controller:tcpmd5:netty:cfg">x:md5-channel-factory</type>
183   <name>md5-client-channel-factory</name>
184  </md5-channel-factory>
185  <md5-server-channel-factory xmlns="urn:opendaylight:params:xml:ns:yang:controller:pcep:impl">
186   <type xmlns:x="urn:opendaylight:params:xml:ns:yang:controller:tcpmd5:netty:cfg">x:md5-server-channel-factory</type>
187   <name>md5-server-channel-factory</name>
188  </md5-server-channel-factory>
189 </module>'''
190     # Template to set password.
191     passwd_templ = Template('''<module xmlns="urn:opendaylight:params:xml:ns:yang:controller:config">
192  <type xmlns:x="urn:opendaylight:params:xml:ns:yang:controller:pcep:topology:provider">x:pcep-topology-provider</type>
193  <name>pcep-topology</name>
194  <client xmlns="urn:opendaylight:params:xml:ns:yang:controller:pcep:topology:provider">
195   <address xmlns="urn:opendaylight:params:xml:ns:yang:controller:pcep:topology:provider">$IP</address>
196 $PASSWD </client>
197 </module>''')
198     # We use three template instantiations. No password:
199     repl_dict = {'IP': mininet_ip, 'PASSWD': ''}
200     variables['no_passwd_module'] = passwd_templ.substitute(repl_dict)
201     changeme = '''  <password>changeme</password>
202 '''
203     # wrong password
204     repl_dict = {'IP': mininet_ip, 'PASSWD': changeme}
205     variables['passwd_changeme_module'] = passwd_templ.substitute(repl_dict)
206     # and correct password.
207     topsecret = '''  <password>topsecret</password>
208 '''
209     repl_dict = {'IP': mininet_ip, 'PASSWD': topsecret}
210     variables['passwd_topsecret_module'] = passwd_templ.substitute(repl_dict)
211     # All variables set, return dict to Robot.
212     return variables