2 Variables file for tcpmd5user suite.
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.
11 # Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
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
18 from string import Template
21 __author__ = "Vratko Polak"
22 __copyright__ = "Copyright(c) 2015, Cisco Systems, Inc."
23 __license__ = "Eclipse Public License v1.0"
24 __email__ = "vrpolak@cisco.com"
27 # FIXME: Migrate values shared by other suites to separate Python module.
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.
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'] = '''{
42 "topology-id": "pcep-topology",
44 "network-topology-pcep:topology-pcep": {}
49 # Template of JSON response with pcep-topology seeing 1 PCC 1 LSP.
50 onjsontempl = Template('''{
55 "network-topology-pcep:path-computation-client": {
64 "processing-rule": false,
68 "ip-prefix": "1.1.1.1/32"
75 "odl-pcep-ietf-stateful07:lsp": {
76 "administrative": true,
79 "odl-pcep-ietf-initiated00:create": false,
82 "processing-rule": false,
88 "ipv4-extended-tunnel-id": "$IP",
89 "ipv4-tunnel-endpoint-address": "1.1.1.1",
90 "ipv4-tunnel-sender-address": "$IP"
95 "symbolic-path-name": {
104 "state-sync": "synchronized",
106 "odl-pcep-ietf-stateful07:stateful": {
107 "lsp-update-capability": true,
108 "odl-pcep-ietf-initiated00:initiation": true
112 "node-id": "pcc://$IP"
115 "topology-id": "pcep-topology",
117 "network-topology-pcep:topology-pcep": {}
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>
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>
137 <name>global-key-access-factory</name>
138 <provider>/modules/module[type='native-key-access-factory'][name='global-key-access-factory']</provider>
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>
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>
152 <name>md5-client-channel-factory</name>
153 <provider>/modules/module[type='md5-client-channel-factory'][name='md5-client-channel-factory']</provider>
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>
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>
170 <name>md5-server-channel-factory</name>
171 <provider>/modules/module[type='md5-server-channel-factory-impl'][name='md5-server-channel-factory']</provider>
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>
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>
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>
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>
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.