List open transactions in test case teardown
[integration/test.git] / csit / variables / pcepuser / variables.py
index 1db0fbc810f63a93adbf80b8205e6cf1ca9cb615..2a8f03a9c016f937066f81a5970612fac0b01fc1 100644 (file)
@@ -12,14 +12,15 @@ than do manipulation in Robot file."""
 # terms of the Eclipse Public License v1.0 which accompanies this distribution,
 # and is available at http://www.eclipse.org/legal/epl-v10.html
 
+import binascii
+from string import Template
+
+
 __author__ = "Vratko Polak"
 __copyright__ = "Copyright(c) 2015, Cisco Systems, Inc."
 __license__ = "Eclipse Public License v1.0"
 __email__ = "vrpolak@cisco.com"
 
-import binascii
-from string import Template
-
 
 def get_variables(mininet_ip):
     """Return dict of variables for the given IP address of Mininet VM."""
@@ -50,31 +51,18 @@ def get_variables(mininet_ip):
     # First off, there is segment describing PCC which conatins IP address but is otherwise constant.
     # So the top-level template will look like this:
     json_templ = Template('''{
- "topology": [
-  {
-   "node": [
-    {
-     "network-topology-pcep:path-computation-client": {
-      "ip-address": "$IP",
-      "reported-lsp": [$LSPS
-      ],
-      "state-sync": "synchronized",
-      "stateful-tlv": {
-       "odl-pcep-ietf-stateful07:stateful": {
-        "lsp-update-capability": true,
-        "odl-pcep-ietf-initiated00:initiation": true
-       }
-      }
-     },
-     "node-id": "pcc://$IP"
-    }
-   ],
-   "topology-id": "pcep-topology",
-   "topology-types": {
-    "network-topology-pcep:topology-pcep": {}
+ "network-topology-pcep:path-computation-client": {
+  "ip-address": "$IP",
+  "reported-lsp": [$LSPS
+  ],
+  "state-sync": "synchronized",
+  "stateful-tlv": {
+   "odl-pcep-ietf-stateful07:stateful": {
+    "lsp-update-capability": true,
+    "odl-pcep-ietf-initiated00:initiation": true
    }
   }
- ]
+ }
 }''')
     # The _json variables will differ only in $LSPS, but $IP will be present inside.
     # Thus, the $IP substitution will come last, and any auxiliary substitutions before this final one
@@ -86,45 +74,45 @@ def get_variables(mininet_ip):
     # or a pair of delegated and instantiated (separated by comma) LSPS, in appropriate state.
     # Of course, one LSP always follow a structure, for which here is the template:
     lsp_templ = Template('''
-       {
-        "name": "$NAME",
-        "path": [
-         {
-          "ero": {
-           "ignore": false,
-           "processing-rule": false,
-           "subobject": [$HOPS
-           ]
-          },
-          "lsp-id": $ID,
-          "odl-pcep-ietf-stateful07:lsp": {
-           "administrative": true,
-           "delegate": true,
-           "ignore": false,
-           "odl-pcep-ietf-initiated00:create": $CREATED,
-           "operational": "up",
-           "plsp-id": $ID,
-           "processing-rule": false,
-           "remove": false,
-           "sync": true,
-           "tlvs": {
-            "lsp-identifiers": {
-             "ipv4": {
-              "ipv4-extended-tunnel-id": "$IP",
-              "ipv4-tunnel-endpoint-address": "1.1.1.1",
-              "ipv4-tunnel-sender-address": "$IP"
-             },
-             "lsp-id": $ID,
-             "tunnel-id": $ID
-            },
-            "symbolic-path-name": {
-             "path-name": "$CODE"
-            }
-           }
-          }
-         }
-        ]
-       }''')
+   {
+    "name": "$NAME",
+    "path": [
+     {
+      "ero": {
+       "ignore": false,
+       "processing-rule": false,
+       "subobject": [$HOPS
+       ]
+      },
+      "lsp-id": $ID,
+      "odl-pcep-ietf-stateful07:lsp": {
+       "administrative": true,
+       "delegate": true,
+       "ignore": false,
+       "odl-pcep-ietf-initiated00:create": $CREATED,
+       "operational": "up",
+       "plsp-id": $ID,
+       "processing-rule": false,
+       "remove": false,
+       "sync": true,
+       "tlvs": {
+        "lsp-identifiers": {
+         "ipv4": {
+          "ipv4-extended-tunnel-id": "$IP",
+          "ipv4-tunnel-endpoint-address": "1.1.1.1",
+          "ipv4-tunnel-sender-address": "$IP"
+         },
+         "lsp-id": $ID,
+         "tunnel-id": $ID
+        },
+        "symbolic-path-name": {
+         "path-name": "$CODE"
+        }
+       }
+      }
+     }
+    ]
+   }''')
     # IDs were already talked about, IP will be set last. Now, $NAME.
     # Pcc-mock uses a fixed naming scheme for delegated tunnels, so one more template can be written,
     # but it is so simple we can write just the one-line code instead:
@@ -136,14 +124,14 @@ def get_variables(mininet_ip):
     delegated_code = binascii.b2a_base64(delegated_name)[:-1]  # remove endline added by the library function
     instantiated_code = binascii.b2a_base64(instantiated_name)[:-1]
     # The remaining segment is HOPS, and that is the place where default and updated states differ.
-    # Once gain, there is a template for a single hop:
+    # Once again, there is a template for a single hop:
     hop_templ = Template('''
-            {
-             "ip-prefix": {
-              "ip-prefix": "$HOPIP/32"
-             },
-             "loose": false
-            }''')
+        {
+         "ip-prefix": {
+          "ip-prefix": "$HOPIP/32"
+         },
+         "loose": false
+        }''')
     # The low-to-high part of V comes now, it is just substituting and concatenating.
     # Hops:
     final_hop = hop_templ.substitute({'HOPIP': '1.1.1.1'})
@@ -177,58 +165,67 @@ def get_variables(mininet_ip):
     # There are three operations, so let us just write templates from information at
     # https://wiki.opendaylight.org/view/BGP_LS_PCEP:Programmer_Guide#Tunnel_Management_for_draft-ietf-pce-stateful-pce-07_and_draft-ietf-pce-pce-initiated-lsp-00
     # _xml describes content type and also distinguishes from similarly named _json strings.
-    add_xml_templ = Template('''<input xmlns="urn:opendaylight:params:xml:ns:yang:topology:pcep">
- <node>pcc://$IP</node>
- <name>$NAME</name>
- <network-topology-ref xmlns:topo="urn:TBD:params:xml:ns:yang:network-topology">/topo:network-topology/topo:topology'''
-                             + '''[topo:topology-id="pcep-topology"]</network-topology-ref>
- <arguments>
-  <lsp xmlns="urn:opendaylight:params:xml:ns:yang:pcep:ietf:stateful">
-   <delegate>true</delegate>
-   <administrative>true</administrative>
-  </lsp>
-  <endpoints-obj>
-   <ipv4>
-    <source-ipv4-address>$IP</source-ipv4-address>
-    <destination-ipv4-address>1.1.1.1</destination-ipv4-address>
-   </ipv4>
-  </endpoints-obj>
-  <ero>
-   <subobject>
-    <loose>false</loose>
-    <ip-prefix><ip-prefix>1.1.1.1/32</ip-prefix></ip-prefix>
-   </subobject>
-  </ero>
- </arguments>
-</input>''')
-    update_xml_templ = Template('''<input xmlns="urn:opendaylight:params:xml:ns:yang:topology:pcep">
- <node>pcc://$IP</node>
- <name>$NAME</name>
- <network-topology-ref xmlns:topo="urn:TBD:params:xml:ns:yang:network-topology">/topo:network-topology/topo:topology'''
-                                + '''[topo:topology-id="pcep-topology"]</network-topology-ref>
- <arguments>
-  <lsp xmlns="urn:opendaylight:params:xml:ns:yang:pcep:ietf:stateful">
-   <delegate>true</delegate>
-   <administrative>true</administrative>
-  </lsp>
-  <ero>
-   <subobject>
-    <loose>false</loose>
-    <ip-prefix><ip-prefix>2.2.2.2/32</ip-prefix></ip-prefix>
-   </subobject>
-   <subobject>
-    <loose>false</loose>
-    <ip-prefix><ip-prefix>1.1.1.1/32</ip-prefix></ip-prefix>
-   </subobject>
-  </ero>
- </arguments>
-</input>''')
-    remove_xml_templ = Template('''<input xmlns="urn:opendaylight:params:xml:ns:yang:topology:pcep">
- <node>pcc://$IP</node>
- <name>$NAME</name>
- <network-topology-ref xmlns:topo="urn:TBD:params:xml:ns:yang:network-topology">/topo:network-topology/topo:topology'''
-                                + '''[topo:topology-id="pcep-topology"]</network-topology-ref>
-</input>''')
+    add_xml_templ = Template(
+        '<input xmlns="urn:opendaylight:params:xml:ns:yang:topology:pcep">\n'
+        ' <node>pcc://$IP</node>\n'
+        ' <name>$NAME</name>\n'
+        ' <network-topology-ref xmlns:topo="urn:TBD:params:xml:ns:yang:network-topology">'
+        '/topo:network-topology/topo:topology[topo:topology-id="pcep-topology"]'
+        '</network-topology-ref>\n'
+        ' <arguments>\n'
+        '  <lsp xmlns="urn:opendaylight:params:xml:ns:yang:pcep:ietf:stateful">\n'
+        '   <delegate>true</delegate>\n'
+        '   <administrative>true</administrative>\n'
+        '  </lsp>\n'
+        '  <endpoints-obj>\n'
+        '   <ipv4>\n'
+        '    <source-ipv4-address>$IP</source-ipv4-address>\n'
+        '    <destination-ipv4-address>1.1.1.1</destination-ipv4-address>\n'
+        '   </ipv4>\n'
+        '  </endpoints-obj>\n'
+        '  <ero>\n'
+        '   <subobject>\n'
+        '    <loose>false</loose>\n'
+        '    <ip-prefix><ip-prefix>1.1.1.1/32</ip-prefix></ip-prefix>\n'
+        '   </subobject>\n'
+        '  </ero>\n'
+        ' </arguments>\n'
+        '</input>\n'
+    )
+    update_xml_templ = Template(
+        '<input xmlns="urn:opendaylight:params:xml:ns:yang:topology:pcep">\n'
+        ' <node>pcc://$IP</node>\n'
+        ' <name>$NAME</name>\n'
+        ' <network-topology-ref xmlns:topo="urn:TBD:params:xml:ns:yang:network-topology">'
+        '/topo:network-topology/topo:topology[topo:topology-id="pcep-topology"]'
+        '</network-topology-ref>\n'
+        ' <arguments>\n'
+        '  <lsp xmlns="urn:opendaylight:params:xml:ns:yang:pcep:ietf:stateful">\n'
+        '   <delegate>true</delegate>\n'
+        '   <administrative>true</administrative>\n'
+        '  </lsp>\n'
+        '  <ero>\n'
+        '   <subobject>\n'
+        '    <loose>false</loose>\n'
+        '    <ip-prefix><ip-prefix>2.2.2.2/32</ip-prefix></ip-prefix>\n'
+        '   </subobject>\n'
+        '   <subobject>\n'
+        '    <loose>false</loose>\n'
+        '    <ip-prefix><ip-prefix>1.1.1.1/32</ip-prefix></ip-prefix>\n'
+        '   </subobject>\n'
+        '  </ero>\n'
+        ' </arguments>\n'
+        '</input>\n'
+    )
+    remove_xml_templ = Template(
+        '<input xmlns="urn:opendaylight:params:xml:ns:yang:topology:pcep">\n'
+        ' <node>pcc://$IP</node>\n'
+        ' <name>$NAME</name>\n'
+        ' <network-topology-ref xmlns:topo="urn:TBD:params:xml:ns:yang:network-topology">'
+        '/topo:network-topology/topo:topology[topo:topology-id="pcep-topology"]'
+        '</network-topology-ref>\n'
+        '</input>\n'
+    )
     # The operations can be applied to either delegated or instantiated tunnel, NAME is the only distinguishing value.
     # Also, the final IP substitution can be done here.
     repl_dict = {'IP': mininet_ip}