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
17 __author__ = "Vratko Polak"
18 __copyright__ = "Copyright(c) 2015, Cisco Systems, Inc."
19 __license__ = "Eclipse Public License v1.0"
20 __email__ = "vrpolak@cisco.com"
23 from string import Template
26 # FIXME: Migrate values shared by other suites to separate Python module.
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.
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'] = '''{
41 "topology-id": "pcep-topology",
43 "network-topology-pcep:topology-pcep": {}
48 # Template of JSON response with pcep-topology seeing 1 PCC 1 LSP.
49 onjsontempl = Template('''{
54 "network-topology-pcep:path-computation-client": {
63 "processing-rule": false,
67 "ip-prefix": "1.1.1.1/32"
74 "odl-pcep-ietf-stateful07:lsp": {
75 "administrative": true,
78 "odl-pcep-ietf-initiated00:create": false,
81 "processing-rule": false,
87 "ipv4-extended-tunnel-id": "$IP",
88 "ipv4-tunnel-endpoint-address": "1.1.1.1",
89 "ipv4-tunnel-sender-address": "$IP"
94 "symbolic-path-name": {
103 "state-sync": "synchronized",
105 "odl-pcep-ietf-stateful07:stateful": {
106 "lsp-update-capability": true,
107 "odl-pcep-ietf-initiated00:initiation": true
111 "node-id": "pcc://$IP"
114 "topology-id": "pcep-topology",
116 "network-topology-pcep:topology-pcep": {}
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>
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>
136 <name>global-key-access-factory</name>
137 <provider>/modules/module[type='native-key-access-factory'][name='global-key-access-factory']</provider>
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>
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>
151 <name>md5-client-channel-factory</name>
152 <provider>/modules/module[type='md5-client-channel-factory'][name='md5-client-channel-factory']</provider>
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>
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>
169 <name>md5-server-channel-factory</name>
170 <provider>/modules/module[type='md5-server-channel-factory-impl'][name='md5-server-channel-factory']</provider>
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>
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>
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>
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>
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.