The JSON output of ovs-appctl ovs/router/rule/show command printed the
'user' field as integer instead of a boolean. Fix that and add a unit
test that checks standard router rules in JSON format.

Fixes: e2a241560080 ("ovs-router: Introduce ovs/route/rule/{add, del} 
commands.")
Signed-off-by: Dima Chumak <[email protected]>
---
 lib/ovs-router.c    |  2 +-
 tests/ovs-router.at | 48 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 49 insertions(+), 1 deletion(-)

diff --git a/lib/ovs-router.c b/lib/ovs-router.c
index 5ed6b785943c..c11a52764505 100644
--- a/lib/ovs-router.c
+++ b/lib/ovs-router.c
@@ -863,7 +863,7 @@ ovs_router_rules_show_json(struct json *rule_entries, bool 
ipv6)
         entry = json_object_create();
 
         json_object_put(entry, "priority", json_integer_create(rule->prio));
-        json_object_put(entry, "user", json_integer_create(rule->user));
+        json_object_put(entry, "user", json_boolean_create(rule->user));
         json_object_put(entry, "invert", json_boolean_create(rule->invert));
         json_object_put(entry, "ipv4", json_boolean_create(rule->ipv4));
         json_object_put(entry, "src-prefix",
diff --git a/tests/ovs-router.at b/tests/ovs-router.at
index 27667d5bcb9a..b5282fd1957b 100644
--- a/tests/ovs-router.at
+++ b/tests/ovs-router.at
@@ -258,6 +258,54 @@ Cached: 0: from all lookup local
 Cached: 32766: from all lookup main
 ])
 
+dnl Check JSON output for standard rules.
+AT_CHECK([ovs-appctl --format=json --pretty ovs/route/rule/show], [0], [dnl
+[[
+  {
+    "from": "all",
+    "invert": false,
+    "ipv4": true,
+    "lookup": 255,
+    "priority": 0,
+    "src-prefix": 0,
+    "user": false},
+  {
+    "from": "all",
+    "invert": false,
+    "ipv4": true,
+    "lookup": 254,
+    "priority": 32766,
+    "src-prefix": 0,
+    "user": false},
+  {
+    "from": "all",
+    "invert": false,
+    "ipv4": true,
+    "lookup": 253,
+    "priority": 32767,
+    "src-prefix": 0,
+    "user": false}]]
+])
+AT_CHECK([ovs-appctl --format=json --pretty ovs/route/rule/show -6], [0], [dnl
+[[
+  {
+    "from": "all",
+    "invert": false,
+    "ipv4": false,
+    "lookup": 255,
+    "priority": 0,
+    "src-prefix": 0,
+    "user": false},
+  {
+    "from": "all",
+    "invert": false,
+    "ipv4": false,
+    "lookup": 254,
+    "priority": 32766,
+    "src-prefix": 0,
+    "user": false}]]
+])
+
 OVS_VSWITCHD_STOP
 AT_CLEANUP
 
-- 
2.52.0

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

Reply via email to