Hi Ales,

This change works fine since we apply regexes and print lines one-by-one.

Acked-by: Mark Michelson <[email protected]>

On 2/11/25 05:09, Ales Musil wrote:
Make sure we keep the original indentation of the stdin. At the same
time check the indentation of each block and adjust the ovn-detrace
output to match that indentation. This makes it easier to read paths
of cloned packets.

Signed-off-by: Ales Musil <[email protected]>
---
  tests/ovn-util.at           | 63 +++++++++++++++++++------------------
  utilities/ovn_detrace.py.in | 17 +++++++---
  2 files changed, 45 insertions(+), 35 deletions(-)

diff --git a/tests/ovn-util.at b/tests/ovn-util.at
index a0a558c3d..004799b4c 100644
--- a/tests/ovn-util.at
+++ b/tests/ovn-util.at
@@ -39,50 +39,51 @@ ingress=$(ovn-debug uuid-to-cookie $(fetch_column 
logical_flow _uuid \
  egress=$(ovn-debug uuid-to-cookie $(fetch_column logical_flow _uuid \
      table_id=$egress_table pipeline=egress match="1"))
+# There is artificial indentation just to check it's kept with ovn-detrace.
  cat << EOF > trace
  0. in_port=1, priority 100, cookie $pb_vm0
-set_field:0x4/0xffff->reg13
-set_field:0x1->reg11
-set_field:0x1->reg12
-set_field:0x1->metadata
-set_field:0x1->reg14
-set_field:0/0xffff0000->reg13
-resubmit(,??)
+    set_field:0x4/0xffff->reg13
+    set_field:0x1->reg11
+    set_field:0x1->reg12
+    set_field:0x1->metadata
+    set_field:0x1->reg14
+    set_field:0/0xffff0000->reg13
+    resubmit(,??)
  8. metadata=0x1, priority 50, cookie $ingress
-set_field:0/0x1000->reg10
-resubmit(,??)
-51. metadata=0x1, priority 0, cookie $egress
-resubmit(,??)
-65. reg15=0x2,metadata=0x1, priority 100, cookie $pb_vm1
-output:2
+    set_field:0/0x1000->reg10
+    resubmit(,??)
+    51. metadata=0x1, priority 0, cookie $egress
+        resubmit(,??)
+        65. reg15=0x2,metadata=0x1, priority 100, cookie $pb_vm1
+            output:2
  EOF
AT_CHECK_UNQUOTED([cat trace | $PYTHON $top_srcdir/utilities/ovn_detrace.py.in], [0], [dnl
  0. in_port=1, priority 100, cookie $pb_vm0
-set_field:0x4/0xffff->reg13
-set_field:0x1->reg11
-set_field:0x1->reg12
-set_field:0x1->metadata
-set_field:0x1->reg14
-set_field:0/0xffff0000->reg13
-resubmit(,??)
+    set_field:0x4/0xffff->reg13
+    set_field:0x1->reg11
+    set_field:0x1->reg12
+    set_field:0x1->metadata
+    set_field:0x1->reg14
+    set_field:0/0xffff0000->reg13
+    resubmit(,??)
    * Logical datapath: "ls" ($dp_uuid)
    * Port Binding: logical_port "vm0", tunnel_key 10, chassis-name "hv1", chassis-str 
"hv1"
  8. metadata=0x1, priority 50, cookie $ingress
-set_field:0/0x1000->reg10
-resubmit(,??)
+    set_field:0/0x1000->reg10
+    resubmit(,??)
    * Logical datapaths:
    *     "ls" ($dp_uuid) [[ingress]]
    * Logical flow: table=$ingress_table (ls_in_check_port_sec), priority=50, 
match=(1), actions=(reg0[[15]] = check_in_port_sec(); next;)
-51. metadata=0x1, priority 0, cookie $egress
-resubmit(,??)
-  * Logical datapaths:
-  *     "ls" ($dp_uuid) [[egress]]
-  * Logical flow: table=$egress_table (ls_out_apply_port_sec), priority=0, 
match=(1), actions=(output;)
-65. reg15=0x2,metadata=0x1, priority 100, cookie $pb_vm1
-output:2
-  * Logical datapath: "ls" ($dp_uuid)
-  * Port Binding: logical_port "vm1", tunnel_key 11, chassis-name "hv1", chassis-str 
"hv1"
+    51. metadata=0x1, priority 0, cookie $egress
+        resubmit(,??)
+      * Logical datapaths:
+      *     "ls" ($dp_uuid) [[egress]]
+      * Logical flow: table=$egress_table (ls_out_apply_port_sec), priority=0, 
match=(1), actions=(output;)
+        65. reg15=0x2,metadata=0x1, priority 100, cookie $pb_vm1
+            output:2
+          * Logical datapath: "ls" ($dp_uuid)
+          * Port Binding: logical_port "vm1", tunnel_key 11, chassis-name "hv1", 
chassis-str "hv1"
]) diff --git a/utilities/ovn_detrace.py.in b/utilities/ovn_detrace.py.in
index f6159cda1..0c8b9dc72 100755
--- a/utilities/ovn_detrace.py.in
+++ b/utilities/ovn_detrace.py.in
@@ -62,13 +62,20 @@ The following options are also available:
class Printer(object):
      def __init__(self):
-        pass
+        self.level = 0
+
+    def set_level(self, level):
+        self.level = level
def print_p(self, string):
-        print('  * ' + string)
+        self._print(2, string)
def print_h(self, string):
-        print('   * ' + string)
+        self._print(3, string)
+
+    def _print(self, extra_indent, string):
+        prefix_len = self.level * 4 + extra_indent
+        print(' ' * prefix_len + '* ' + string)
def datapath_str(datapath):
      return '"%s" (%s)' % (str(datapath.external_ids.get('name')),
@@ -543,13 +550,15 @@ def main():
                      print_record_from_cookie(ovsdb_ovnnb, handlers, cookie)
                  cookies = []
- print(line.strip())
+        print(line.rstrip())
          if line == '':
              break
for regex, handlers in regex_handlers:
              m = regex.match(line)
              if m:
+                # Set indentation level to match the line indentation
+                printer.set_level((len(line) - len(line.lstrip(' '))) // 4)
                  cookies.append((m.group(1), handlers))

_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to