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 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'] = '''{
46 "topology-id": "pcep-topology",
48 "network-topology-pcep:topology-pcep": {}
53 # Template of JSON response with pcep-topology seeing 1 PCC 1 LSP.
54 onjsontempl = Template('''{
59 "network-topology-pcep:path-computation-client": {
68 "processing-rule": false,
72 "ip-prefix": "1.1.1.1/32"
79 "odl-pcep-ietf-stateful07:lsp": {
80 "administrative": true,
83 "odl-pcep-ietf-initiated00:create": false,
86 "processing-rule": false,
92 "ipv4-extended-tunnel-id": "$IP",
93 "ipv4-tunnel-endpoint-address": "1.1.1.1",
94 "ipv4-tunnel-sender-address": "$IP"
99 "symbolic-path-name": {
108 "state-sync": "synchronized",
110 "odl-pcep-ietf-stateful07:stateful": {
111 "lsp-update-capability": true,
112 "odl-pcep-ietf-initiated00:initiation": true
116 "node-id": "pcc://$IP"
119 "topology-id": "pcep-topology",
121 "network-topology-pcep:topology-pcep": {}
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>
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>
141 <name>global-key-access-factory</name>
142 <provider>/modules/module[type='native-key-access-factory'][name='global-key-access-factory']</provider>
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>
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>
156 <name>md5-client-channel-factory</name>
157 <provider>/modules/module[type='md5-client-channel-factory'][name='md5-client-channel-factory']</provider>
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>
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>
174 <name>md5-server-channel-factory</name>
175 <provider>/modules/module[type='md5-server-channel-factory-impl'][name='md5-server-channel-factory']</provider>
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>
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>
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>
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>
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.