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