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