From: Ben Pfaff Date: Fri, 29 Jan 2010 00:18:43 +0000 (-0800) Subject: ovs-vsctl: Add tests for database commands. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5c414a2ed8c21762292776ecee294a11e0b5468b;p=openvswitch ovs-vsctl: Add tests for database commands. Bug #2396. --- diff --git a/tests/ovs-vsctl.at b/tests/ovs-vsctl.at index b7b37f98..2abc0773 100644 --- a/tests/ovs-vsctl.at +++ b/tests/ovs-vsctl.at @@ -444,3 +444,183 @@ AT_CHECK([RUN_OVS_VSCTL([del-br xapi1])]) CHECK_BRIDGES OVS_VSCTL_CLEANUP AT_CLEANUP + +dnl ---------------------------------------------------------------------- +AT_BANNER([ovs-vsctl unit tests -- database commands]) + +AT_SETUP([database commands -- positive checks]) +AT_KEYWORDS([ovs-vsctl]) +OVS_VSCTL_SETUP +AT_CHECK([RUN_OVS_VSCTL([--force create b name=br0])], + [0], [stdout], [], [OVS_VSCTL_CLEANUP]) +cp stdout out1 +AT_CHECK([RUN_OVS_VSCTL([list b])], + [0], [stdout], [], [OVS_VSCTL_CLEANUP]) +cp stdout out2 +AT_CHECK([perl $srcdir/uuidfilt.pl out1 out2], [0], + [[<0> +_uuid (RO): <0> +controller (RO): [] +datapath_id (RO): [] +datapath_type (RO): "" +external_ids (RW): {} +flood_vlans (RW): [] +mirrors (RO): [] +name (RO): "br0" +netflow (RO): [] +other_config (RW): {} +ports (RO): [] +]], [ignore], [test ! -e pid || kill `cat pid`]) +AT_CHECK( + [RUN_OVS_VSCTL( + [set bridge br0 \ + 'other_config:datapath_id="0123456789ab"' \ + 'other_config:hwaddr="00:11:22:33:44:55"' \ + 'external-ids={"xs-network-uuids"="9c45f225-a7cf-439d-976d-83db6271fda1"}' -- \ + add bridge br0 external_ids '"xs-network-names"="local; remote; cloud"'])], + [0], [], [], [OVS_VSCTL_CLEANUP]) +AT_CHECK([RUN_OVS_VSCTL_ONELINE([get bridge br0 other_config external-ids])], + [0], [{datapath_id="0123456789ab", hwaddr="00:11:22:33:44:55"}\n{xs-network-names="local; remote; cloud", xs-network-uuids="9c45f225-a7cf-439d-976d-83db6271fda1"} +], [], [OVS_VSCTL_CLEANUP]) +AT_CHECK([RUN_OVS_VSCTL([get bridge br0 other_config:hwaddr -- --if-exists get bridge br0 other-config:nonexistent])], + [0], ["00:11:22:33:44:55" + +], [], [OVS_VSCTL_CLEANUP]) +AT_CHECK([RUN_OVS_VSCTL([remove br br0 other_config hwaddr 'datapath_id=""' -- get br br0 other_config])], + [0], [{datapath_id="0123456789ab"} +], [], [OVS_VSCTL_CLEANUP]) +AT_CHECK([RUN_OVS_VSCTL([remove br br0 other_config 'datapath_id="0123456789ab"' -- get br br0 other_config])], + [0], [{} +], [], [OVS_VSCTL_CLEANUP]) +AT_CHECK([RUN_OVS_VSCTL([clear br br0 external-ids -- get br br0 external_ids])], + [0], [{} +], [], [OVS_VSCTL_CLEANUP]) +AT_CHECK([RUN_OVS_VSCTL([--force destroy b br0])], + [0], [stdout], [], [OVS_VSCTL_CLEANUP]) +AT_CHECK([RUN_OVS_VSCTL([list b])], + [0], [], [], [OVS_VSCTL_CLEANUP]) +OVS_VSCTL_CLEANUP +AT_CLEANUP + +AT_SETUP([database commands -- negative checks]) +AT_KEYWORDS([ovs-vsctl]) +OVS_VSCTL_SETUP +AT_CHECK([RUN_OVS_VSCTL([--force create b name=br0])], + [0], [ignore], [], [OVS_VSCTL_CLEANUP]) +AT_CHECK([RUN_OVS_VSCTL([add-br br1])], + [0], [ignore], [], [OVS_VSCTL_CLEANUP]) +AT_CHECK([RUN_OVS_VSCTL([set-controller br1 tcp:127.0.0.1])], + [0], [ignore], [], [OVS_VSCTL_CLEANUP]) +AT_CHECK([RUN_OVS_VSCTL([--force create n targets='"1.2.3.4:567"'])], + [0], [stdout], [], [OVS_VSCTL_CLEANUP]) +cp stdout netflow-uuid +AT_CHECK([RUN_OVS_VSCTL([list n `cat netflow-uuid`])], + [0], [stdout], [], [OVS_VSCTL_CLEANUP]) +AT_CHECK([perl $srcdir/uuidfilt.pl netflow-uuid stdout], [0], + [[<0> +_uuid (RO): <0> +active_timeout (RW): 0 +add_id_to_interface (RW): false +engine_id (RW): [] +engine_type (RW): [] +targets (RW): ["1.2.3.4:567"] +]], [ignore], [test ! -e pid || kill `cat pid`]) +AT_CHECK([RUN_OVS_VSCTL([list interx x])], + [1], [], [ovs-vsctl: unknown table "interx" +], [OVS_VSCTL_CLEANUP]) +AT_CHECK([RUN_OVS_VSCTL([list b x])], + [1], [], [ovs-vsctl: no row "x" in table Bridge +], [OVS_VSCTL_CLEANUP]) +AT_CHECK([RUN_OVS_VSCTL([list b br])], + [1], [], [ovs-vsctl: multiple rows in Bridge match "br" +], [OVS_VSCTL_CLEANUP]) +AT_CHECK([RUN_OVS_VSCTL([get b br0 d])], + [1], [], [ovs-vsctl: Bridge contains more than one column whose name matches "d" +], [OVS_VSCTL_CLEANUP]) +AT_CHECK([RUN_OVS_VSCTL([get b br0 x])], + [1], [], [ovs-vsctl: Bridge does not contain a column whose name matches "x" +], [OVS_VSCTL_CLEANUP]) +AT_CHECK([RUN_OVS_VSCTL([get b br0 :y=z])], + [1], [], [ovs-vsctl: :y=z: missing column name +], [OVS_VSCTL_CLEANUP]) +AT_CHECK([RUN_OVS_VSCTL([get b br0 datapath_id:y=z])], + [1], [], [ovs-vsctl: datapath_id:y=z: value not accepted here +], [OVS_VSCTL_CLEANUP]) +AT_CHECK([RUN_OVS_VSCTL([get b br0 datapath_id::])], + [1], [], [ovs-vsctl: datapath_id::: trailing garbage ":" in argument +], [OVS_VSCTL_CLEANUP]) +AT_CHECK([RUN_OVS_VSCTL([get b br0 datapath_id:x])], + [1], [], [ovs-vsctl: cannot specify key to get for non-map column datapath_id +], [OVS_VSCTL_CLEANUP]) +AT_CHECK([RUN_OVS_VSCTL([get b br0 external_ids:x])], + [1], [], [ovs-vsctl: no key "x" in Bridge record "br0" column external_ids +], [OVS_VSCTL_CLEANUP]) +AT_CHECK([RUN_OVS_VSCTL([set b br0 flood_vlans=-1])], + [1], [], [ovs-vsctl: -1 is outside the valid range 1 to 4095 (inclusive) +], [OVS_VSCTL_CLEANUP]) +AT_CHECK([RUN_OVS_VSCTL([set b br0 flood_vlans=4096])], + [1], [], [ovs-vsctl: 4096 is outside the valid range 1 to 4095 (inclusive) +], [OVS_VSCTL_CLEANUP]) +AT_CHECK([RUN_OVS_VSCTL([set b br0 datapath_id=4096])], + [1], [], [ovs-vsctl: datapath_id=4096: cannot modify read-only column datapath_id in table Bridge +], [OVS_VSCTL_CLEANUP]) +AT_CHECK([RUN_OVS_VSCTL([set c br1 'connection-mode=xyz'])], + [1], [], [ovs-vsctl: xyz is not valid (it does not match ^in-band|out-of-band$) +], [OVS_VSCTL_CLEANUP]) +AT_CHECK([RUN_OVS_VSCTL([set c br1 connection-mode:x=y])], + [1], [], [ovs-vsctl: cannot specify key to set for non-map column connection_mode +], [OVS_VSCTL_CLEANUP]) +AT_CHECK([RUN_OVS_VSCTL([add b br1 datapath_id x=y])], + [1], [], [ovs-vsctl: cannot modify read-only column datapath_id in table Bridge +], [OVS_VSCTL_CLEANUP]) +AT_CHECK([RUN_OVS_VSCTL([--force add b br1 datapath_id x y])], + [1], [], [ovs-vsctl: "add" operation would put 2 values in column datapath_id of table Bridge but the maximum number is 1 +], [OVS_VSCTL_CLEANUP]) +AT_CHECK([RUN_OVS_VSCTL([remove b br1 datapath_id x=y])], + [1], [], [ovs-vsctl: cannot modify read-only column datapath_id in table Bridge +], [OVS_VSCTL_CLEANUP]) +AT_CHECK([RUN_OVS_VSCTL([remove n `cat netflow-uuid` targets '"1.2.3.4:567"'])], + [1], [], [ovs-vsctl: "remove" operation would put 0 values in column targets of table NetFlow but the minimun number is 1 +], [OVS_VSCTL_CLEANUP]) +AT_CHECK([RUN_OVS_VSCTL([clear bri br0 netflow])], + [1], [], [ovs-vsctl: cannot modify read-only column netflow in table Bridge +], [OVS_VSCTL_CLEANUP]) +AT_CHECK([RUN_OVS_VSCTL([clear n `cat netflow-uuid` targets])], + [1], [], [ovs-vsctl: "clear" operation cannot be applied to column targets of table NetFlow, which is not allowed to be empty +], [OVS_VSCTL_CLEANUP]) +AT_CHECK([RUN_OVS_VSCTL([create b name=br2])], + [1], [], [ovs-vsctl: "create" requires --force +], [OVS_VSCTL_CLEANUP]) +AT_CHECK([RUN_OVS_VSCTL([destroy b br0])], + [1], [], [ovs-vsctl: "destroy" requires --force +], [OVS_VSCTL_CLEANUP]) +AT_CHECK([RUN_OVS_VSCTL([--force destroy b br2])], + [1], [], [ovs-vsctl: no row "br2" in table Bridge +], [OVS_VSCTL_CLEANUP]) +OVS_VSCTL_CLEANUP +AT_CLEANUP + +dnl This test really shows a bug -- "create" followed by "list" in +dnl the same execution shows the wrong UUID on the "list" command. +dnl The bug is documented in ovs-vsctl.8. +AT_SETUP([created row UUID is wrong in same execution]) +AT_KEYWORDS([ovs-vsctl]) +OVS_VSCTL_SETUP +AT_CHECK([RUN_OVS_VSCTL([--force create Bridge name=br0 -- list b])], + [0], [stdout], [], [OVS_VSCTL_CLEANUP]) +AT_CHECK([perl $srcdir/uuidfilt.pl stdout], [0], + [[<0> +_uuid (RO): <1> +controller (RO): [] +datapath_id (RO): [] +datapath_type (RO): "" +external_ids (RW): {} +flood_vlans (RW): [] +mirrors (RO): [] +name (RO): "br0" +netflow (RO): [] +other_config (RW): {} +ports (RO): [] +]], [ignore], [test ! -e pid || kill `cat pid`]) +OVS_VSCTL_CLEANUP +AT_CLEANUP diff --git a/tests/ovsdb-data.at b/tests/ovsdb-data.at index e7125fea..e868477d 100644 --- a/tests/ovsdb-data.at +++ b/tests/ovsdb-data.at @@ -1,6 +1,6 @@ AT_BANNER([OVSDB -- atoms]) -OVSDB_CHECK_POSITIVE([integer atom], +OVSDB_CHECK_POSITIVE([integer atom from JSON], [[parse-atoms '["integer"]' \ '[0]' \ '[-1]' \ @@ -13,7 +13,20 @@ OVSDB_CHECK_POSITIVE([integer atom], 9223372036854775807 -9223372036854775808]) -OVSDB_CHECK_POSITIVE([real atom], +OVSDB_CHECK_POSITIVE([integer atom from string], + [[parse-atom-strings -- '["integer"]' \ + '0' \ + '-1' \ + '+1000' \ + '9223372036854775807' \ + '-9223372036854775808' ]], + [0 +-1 +1000 +9223372036854775807 +-9223372036854775808]) + +OVSDB_CHECK_POSITIVE([real atom from JSON], [[parse-atoms '["real"]' \ '[0]' \ '[0.0]' \ @@ -30,21 +43,62 @@ OVSDB_CHECK_POSITIVE([real atom], 1e+37 0.00390625]) -OVSDB_CHECK_POSITIVE([boolean atom], +OVSDB_CHECK_POSITIVE([real atom from string], + [[parse-atom-strings -- '["real"]' \ + '0' \ + '0.0' \ + '-0.0' \ + '-1.25' \ + '1e3' \ + '1e37' \ + '0.00390625' ]], + [0 +0 +0 +-1.25 +1000 +1e+37 +0.00390625]) + +OVSDB_CHECK_POSITIVE([boolean atom from JSON], [[parse-atoms '["boolean"]' '[true]' '[false]' ]], [true false]) -OVSDB_CHECK_POSITIVE([string atom], +OVSDB_CHECK_POSITIVE([boolean atom from string], + [[parse-atom-strings '["boolean"]' 'true' 'false' ]], + [true +false]) + +OVSDB_CHECK_POSITIVE([string atom from JSON], [[parse-atoms '["string"]' '[""]' '["true"]' '["\"\\\/\b\f\n\r\t"]']], ["" "true" "\"\\/\b\f\n\r\t"]) -OVSDB_CHECK_POSITIVE([uuid atom], +OVSDB_CHECK_POSITIVE([string atom from string], + [[parse-atom-strings '["string"]' \ + 'unquoted' \ + '"quoted-string"' \ + '"needs quotes"' \ + '""' \ + '"true"' \ + '"\"\\\/\b\f\n\r\t"']], + [unquoted +quoted-string +"needs quotes" +"" +"true" +"\"\\/\b\f\n\r\t"]) + +OVSDB_CHECK_POSITIVE([uuid atom from JSON], [[parse-atoms '["uuid"]' '["uuid", "550e8400-e29b-41d4-a716-446655440000"]']], [[["uuid","550e8400-e29b-41d4-a716-446655440000"]]]) +OVSDB_CHECK_POSITIVE([uuid atom from string], + [[parse-atom-strings '["uuid"]' '550e8400-e29b-41d4-a716-446655440000']], + [550e8400-e29b-41d4-a716-446655440000]) + OVSDB_CHECK_POSITIVE([integer atom sorting], [[sort-atoms '["integer"]' '[55,0,-1,2,1]']], [[[-1,0,1,2,55]]]) @@ -98,50 +152,95 @@ OVSDB_CHECK_POSITIVE([uuid atom sorting], ["uuid", "00001000-0000-0000-0000-000000000000"]]']], [[[["uuid","00000000-0000-0000-0000-000000000000"],["uuid","00000000-0000-0000-0000-000000000001"],["uuid","00000000-0000-0000-0000-000000000010"],["uuid","00000000-0000-0000-0000-000000000100"],["uuid","00000000-0000-0000-0000-000000001000"],["uuid","00000000-0000-0000-0000-000000010000"],["uuid","00000000-0000-0000-0000-000000100000"],["uuid","00000000-0000-0000-0000-000001000000"],["uuid","00000000-0000-0000-0000-000010000000"],["uuid","00000000-0000-0000-0000-000100000000"],["uuid","00000000-0000-0000-0000-001000000000"],["uuid","00000000-0000-0000-0000-010000000000"],["uuid","00000000-0000-0000-0000-100000000000"],["uuid","00000000-0000-0000-0001-000000000000"],["uuid","00000000-0000-0000-0010-000000000000"],["uuid","00000000-0000-0000-0100-000000000000"],["uuid","00000000-0000-0000-1000-000000000000"],["uuid","00000000-0000-0001-0000-000000000000"],["uuid","00000000-0000-0010-0000-000000000000"],["uuid","00000000-0000-0100-0000-000000000000"],["uuid","00000000-0000-1000-0000-000000000000"],["uuid","00000000-0001-0000-0000-000000000000"],["uuid","00000000-0010-0000-0000-000000000000"],["uuid","00000000-0100-0000-0000-000000000000"],["uuid","00000000-1000-0000-0000-000000000000"],["uuid","00000001-0000-0000-0000-000000000000"],["uuid","00000010-0000-0000-0000-000000000000"],["uuid","00000100-0000-0000-0000-000000000000"],["uuid","00001000-0000-0000-0000-000000000000"],["uuid","00010000-0000-0000-0000-000000000000"],["uuid","00100000-0000-0000-0000-000000000000"],["uuid","01000000-0000-0000-0000-000000000000"],["uuid","10000000-0000-0000-0000-000000000000"]]]]) -OVSDB_CHECK_NEGATIVE([real not acceptable integer atom], +OVSDB_CHECK_NEGATIVE([real not acceptable integer JSON atom], [[parse-atoms '["integer"]' '[0.5]' ]], [expected integer]) -OVSDB_CHECK_NEGATIVE([string "true" not acceptable boolean atom], +OVSDB_CHECK_NEGATIVE([real not acceptable integer string atom], + [[parse-atom-strings '["integer"]' '0.5' ]], + ["0.5" is not a valid integer]) + +OVSDB_CHECK_NEGATIVE([string "true" not acceptable boolean JSON atom], [[parse-atoms '["boolean"]' '["true"]' ]], [expected boolean]) -OVSDB_CHECK_NEGATIVE([integer not acceptable string atom], +OVSDB_CHECK_NEGATIVE([string "true" not acceptable boolean string atom], + [[parse-atom-strings '["boolean"]' '"true"' ]], + [""true"" is not a valid boolean (use "true" or "false")]) + +OVSDB_CHECK_NEGATIVE([integer not acceptable string JSON atom], [[parse-atoms '["string"]' '[1]']], [expected string]) -OVSDB_CHECK_NEGATIVE([uuid atom must be expressed as array], +OVSDB_CHECK_NEGATIVE([uuid atom must be expressed as JSON array], [[parse-atoms '["uuid"]' '["550e8400-e29b-41d4-a716-446655440000"]']], [[expected ["uuid", ]]]) +OVSDB_CHECK_NEGATIVE([empty string atom must be quoted], + [[parse-atom-strings '["string"]' '']], + [An empty string is not valid as input; use "" to represent the empty string]) + +OVSDB_CHECK_NEGATIVE([quotes must be balanced], + [parse-atom-strings '[["string"]]' '"asdf'], + ["asdf: missing quote at end of quoted string]) + +OVSDB_CHECK_NEGATIVE([uuids must be valid], + [parse-atom-strings '[["uuid"]]' '1234-5678'], + ["1234-5678" is not a valid UUID]) + AT_BANNER([OSVDB -- simple data]) -OVSDB_CHECK_POSITIVE([integer datum], +OVSDB_CHECK_POSITIVE([integer JSON datum], [[parse-data '["integer"]' '[0]' '[1]' '[-1]']], [0 1 -1]) -OVSDB_CHECK_POSITIVE([real datum], +OVSDB_CHECK_POSITIVE([integer string datum], + [[parse-data-strings -- '["integer"]' '0' '1' '-1' '+1']], + [0 +1 +-1 +1]) + +OVSDB_CHECK_POSITIVE([real JSON datum], [[parse-data '["real"]' '[0]' '[1.0]' '[-1.25]']], [0 1 -1.25]) -OVSDB_CHECK_POSITIVE([boolean datum], +OVSDB_CHECK_POSITIVE([real string datum], + [[parse-data-strings -- '["real"]' '0' '1.0' '-1.25']], + [0 +1 +-1.25]) + +OVSDB_CHECK_POSITIVE([boolean JSON datum], [[parse-data '["boolean"]' '[true]' '[false]' ]], [true false]) -OVSDB_CHECK_POSITIVE([string datum], +OVSDB_CHECK_POSITIVE([boolean string datum], + [[parse-data-strings '["boolean"]' 'true' 'false' ]], + [true +false]) + +OVSDB_CHECK_POSITIVE([string JSON datum], [[parse-data '["string"]' '[""]' '["true"]' '["\"\\\/\b\f\n\r\t"]']], ["" "true" "\"\\/\b\f\n\r\t"]) +OVSDB_CHECK_POSITIVE([string string datum], + [[parse-data-strings '["string"]' '"x"' '""' '"true"' '"\"\\\/\b\f\n\r\t"']], + [x +"" +"true" +"\"\\/\b\f\n\r\t"]) + AT_BANNER([OVSDB -- set data]) -OVSDB_CHECK_POSITIVE([optional boolean], +OVSDB_CHECK_POSITIVE([JSON optional boolean], [[parse-data '{"key": "boolean", "min": 0}' \ '["set", [true]]' \ '["set", [false]]' \ @@ -151,7 +250,17 @@ OVSDB_CHECK_POSITIVE([optional boolean], ["set",[]]]], [set]) -OVSDB_CHECK_POSITIVE([set of 0 or more integers], +OVSDB_CHECK_POSITIVE([string optional boolean], + [[parse-data-strings '{"key": "boolean", "min": 0}' \ + 'true' \ + 'false' \ + '[]']], + [[true +false +[]]], + [set]) + +OVSDB_CHECK_POSITIVE([JSON set of 0 or more integers], [[parse-data '{"key": "integer", "min": 0, "max": "unlimited"}' \ '["set", [0]]' \ '["set", [0, 1]]' \ @@ -166,7 +275,22 @@ OVSDB_CHECK_POSITIVE([set of 0 or more integers], ["set",[0,1,2,3,4,5,6,7,8]] ["set",[0,1,2,3,4,5,6,7,8,9,10]]]]) -OVSDB_CHECK_POSITIVE([set of 1 to 3 uuids], +OVSDB_CHECK_POSITIVE([string set of 0 or more integers], + [[parse-data-strings '{"key": "integer", "min": 0, "max": "unlimited"}' \ + '0' \ + '0,1' \ + '0, 1, 2' \ + '[0, 1,2, 3, 4, 5]' \ + '0, 1,2, 3,4, 5, 6, 7, 8' \ + '[0, 1, 2, 3, 4,5, 6,7, 8, 9, 10]']], + [[[0] +[0, 1] +[0, 1, 2] +[0, 1, 2, 3, 4, 5] +[0, 1, 2, 3, 4, 5, 6, 7, 8] +[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]]]) + +OVSDB_CHECK_POSITIVE([JSON set of 1 to 3 uuids], [[parse-data '{"key": "uuid", "min": 1, "max": 3}' \ '["set", [["uuid", "550e8400-e29b-41d4-a716-446655440000"]]]' \ '["set", [["uuid", "c5051240-30ff-43ed-b4b9-93cf3f050813"], @@ -175,7 +299,16 @@ OVSDB_CHECK_POSITIVE([set of 1 to 3 uuids], [[["set",[["uuid","550e8400-e29b-41d4-a716-446655440000"]]] ["set",[["uuid","550e8400-e29b-41d4-a716-446655440000"],["uuid","90558331-09af-4d2f-a572-509cad2e9088"],["uuid","c5051240-30ff-43ed-b4b9-93cf3f050813"]]]]]) -OVSDB_CHECK_POSITIVE([set of 0 to 3 strings], +OVSDB_CHECK_POSITIVE([string set of 1 to 3 uuids], + [[parse-data-strings '{"key": "uuid", "min": 1, "max": 3}' \ + '[550e8400-e29b-41d4-a716-446655440000]' \ + '[c5051240-30ff-43ed-b4b9-93cf3f050813, + 90558331-09af-4d2f-a572-509cad2e9088, + 550e8400-e29b-41d4-a716-446655440000]']], + [[[550e8400-e29b-41d4-a716-446655440000] +[550e8400-e29b-41d4-a716-446655440000, 90558331-09af-4d2f-a572-509cad2e9088, c5051240-30ff-43ed-b4b9-93cf3f050813]]]) + +OVSDB_CHECK_POSITIVE([JSON set of 0 to 3 strings], [[parse-data '{"key": "string", "min": 0, "max": 3}' \ '["set", []]' \ '["set", ["a relatively long string"]]' \ @@ -186,37 +319,76 @@ OVSDB_CHECK_POSITIVE([set of 0 to 3 strings], ["set",["a relatively long string","short string"]] ["set",["a relatively long string","short string","zzz"]]]]) -OVSDB_CHECK_NEGATIVE([duplicate boolean not allowed in set], +OVSDB_CHECK_POSITIVE([string set of 0 to 3 strings], + [[parse-data-strings '{"key": "string", "min": 0, "max": 3}' \ + '[]' \ + '"a relatively long string"' \ + '["short string", "a relatively long string"]' \ + '"zzz","short string","a relatively long string"']], + [[[] +["a relatively long string"] +["a relatively long string", "short string"] +["a relatively long string", "short string", zzz]]]) + +OVSDB_CHECK_NEGATIVE([duplicate boolean not allowed in JSON set], [[parse-data '{"key": "boolean", "max": 5}' '["set", [true, true]]']], [ovsdb error: set contains duplicate]) -OVSDB_CHECK_NEGATIVE([duplicate integer not allowed in set], +OVSDB_CHECK_NEGATIVE([duplicate boolean not allowed in string set], + [[parse-data-strings '{"key": "boolean", "max": 5}' 'true, true']], + [set contains duplicate value]) + +OVSDB_CHECK_NEGATIVE([duplicate integer not allowed in JSON set], [[parse-data '{"key": "integer", "max": 5}' '["set", [1, 2, 3, 1]]']], [ovsdb error: set contains duplicate]) -OVSDB_CHECK_NEGATIVE([duplicate real not allowed in set], +OVSDB_CHECK_NEGATIVE([duplicate integer not allowed in string set], + [[parse-data-strings '{"key": "integer", "max": 5}' '[1, 2, 3, 1]']], + [set contains duplicate value]) + +OVSDB_CHECK_NEGATIVE([duplicate real not allowed in JSON set], [[parse-data '{"key": "real", "max": 5}' '["set", [0.0, -0.0]]']], [ovsdb error: set contains duplicate]) -OVSDB_CHECK_NEGATIVE([duplicate string not allowed in set], +OVSDB_CHECK_NEGATIVE([duplicate real not allowed in string set], + [[parse-data-strings '{"key": "real", "max": 5}' '0.0, -0.0']], + [set contains duplicate value]) + +OVSDB_CHECK_NEGATIVE([duplicate string not allowed in JSON set], [[parse-data '{"key": "string", "max": 5}' '["set", ["asdf", "ASDF", "asdf"]]']], [ovsdb error: set contains duplicate]) -OVSDB_CHECK_NEGATIVE([duplicate uuid not allowed in set], +OVSDB_CHECK_NEGATIVE([duplicate string not allowed in string set], + [[parse-data-strings '{"key": "string", "max": 5}' 'asdf, ASDF, "asdf"']], + [set contains duplicate value]) + +OVSDB_CHECK_NEGATIVE([duplicate uuid not allowed in JSON set], [[parse-data '{"key": "uuid", "max": 5}' \ '["set", [["uuid", "7ef21525-0088-4a28-a418-5518413e43ea"], ["uuid", "355ad037-f1da-40aa-b47c-ff9c7e8c6a38"], ["uuid", "7ef21525-0088-4a28-a418-5518413e43ea"]]]']], [ovsdb error: set contains duplicate]) +OVSDB_CHECK_NEGATIVE([duplicate uuid not allowed in string set], + [[parse-data-strings '{"key": "uuid", "max": 5}' \ + '7ef21525-0088-4a28-a418-5518413e43ea, + 355ad037-f1da-40aa-b47c-ff9c7e8c6a38, + 7ef21525-0088-4a28-a418-5518413e43ea']], + [set contains duplicate value]) + AT_BANNER([OVSDB -- map data]) -OVSDB_CHECK_POSITIVE([map of 1 integer to boolean], +OVSDB_CHECK_POSITIVE([JSON map of 1 integer to boolean], [[parse-data '{"key": "integer", "value": "boolean"}' \ '["map", [[1, true]]]']], [[["map",[[1,true]]]]]) -OVSDB_CHECK_POSITIVE([map of at least 1 integer to boolean], +OVSDB_CHECK_POSITIVE([string map of 1 integer to boolean], + [[parse-data-strings '{"key": "integer", "value": "boolean"}' \ + '1=true']], + [[1=true]]) + +OVSDB_CHECK_POSITIVE([JSON map of at least 1 integer to boolean], [[parse-data '{"key": "integer", "value": "boolean", "max": "unlimited"}' \ '["map", [[1, true]]]' \ '["map", [[0, true], [1, false], [2, true], [3, true], [4, true]]]' \ @@ -225,12 +397,26 @@ OVSDB_CHECK_POSITIVE([map of at least 1 integer to boolean], ["map",[[0,true],[1,false],[2,true],[3,true],[4,true]]] ["map",[[0,true],[3,false],[4,false]]]]]) -OVSDB_CHECK_POSITIVE([map of 1 boolean to integer], +OVSDB_CHECK_POSITIVE([string map of at least 1 integer to boolean], + [[parse-data-strings '{"key": "integer", "value": "boolean", "max": "unlimited"}' \ + '1=true' \ + '0=true 1=false 2=true, 3=true 4=true,' \ + '3=false,0=true ,4=false']], + [[{1=true} +{0=true, 1=false, 2=true, 3=true, 4=true} +{0=true, 3=false, 4=false}]]) + +OVSDB_CHECK_POSITIVE([JSON map of 1 boolean to integer], [[parse-data '{"key": "boolean", "value": "integer"}' \ '["map", [[true, 1]]]']], [[["map",[[true,1]]]]]) -OVSDB_CHECK_POSITIVE([map of 1 uuid to real], +OVSDB_CHECK_POSITIVE([string map of 1 boolean to integer], + [[parse-data-strings '{"key": "boolean", "value": "integer"}' \ + 'true=1']], + [[true=1]]) + +OVSDB_CHECK_POSITIVE([JSON map of 1 uuid to real], [[parse-data '{"key": "uuid", "value": "real", "min": 1, "max": 5}' \ '["map", [[["uuid", "cad8542b-6ee1-486b-971b-7dcbf6e14979"], 1.0], [["uuid", "6b94b968-2702-4f64-9457-314a34d69b8c"], 2.0], @@ -239,7 +425,16 @@ OVSDB_CHECK_POSITIVE([map of 1 uuid to real], [["uuid", "1c92b8ca-d5e4-4628-a85d-1dc2d099a99a"], 5.0]]]']], [[["map",[[["uuid","1c92b8ca-d5e4-4628-a85d-1dc2d099a99a"],5],[["uuid","25bfa475-d072-4f60-8be1-00f48643e9cb"],4],[["uuid","6b94b968-2702-4f64-9457-314a34d69b8c"],2],[["uuid","cad8542b-6ee1-486b-971b-7dcbf6e14979"],1],[["uuid","d2c4a168-24de-47eb-a8a3-c1abfc814979"],3]]]]]) -OVSDB_CHECK_POSITIVE([map of 10 string to string], +OVSDB_CHECK_POSITIVE([string map of 1 uuid to real], + [[parse-data-strings '{"key": "uuid", "value": "real", "min": 1, "max": 5}' \ + 'cad8542b-6ee1-486b-971b-7dcbf6e14979=1.0, + 6b94b968-2702-4f64-9457-314a34d69b8c=2.0, + d2c4a168-24de-47eb-a8a3-c1abfc814979=3.0, + 25bfa475-d072-4f60-8be1-00f48643e9cb=4.0, + 1c92b8ca-d5e4-4628-a85d-1dc2d099a99a=5.0']], + [[{1c92b8ca-d5e4-4628-a85d-1dc2d099a99a=5, 25bfa475-d072-4f60-8be1-00f48643e9cb=4, 6b94b968-2702-4f64-9457-314a34d69b8c=2, cad8542b-6ee1-486b-971b-7dcbf6e14979=1, d2c4a168-24de-47eb-a8a3-c1abfc814979=3}]]) + +OVSDB_CHECK_POSITIVE([JSON map of 10 string to string], [[parse-data '{"key": "string", "value": "string", "min": 1, "max": 10}' \ '["map", [["2 gills", "1 chopin"], ["2 chopins", "1 pint"], @@ -253,7 +448,26 @@ OVSDB_CHECK_POSITIVE([map of 10 string to string], ["2 kilderkins", "1 barrel"]]]']], [[["map",[["2 chopins","1 pint"],["2 demibushel","1 firkin"],["2 firkins","1 kilderkin"],["2 gallons","1 peck"],["2 gills","1 chopin"],["2 kilderkins","1 barrel"],["2 pecks","1 demibushel"],["2 pints","1 quart"],["2 pottles","1 gallon"],["2 quarts","1 pottle"]]]]]) -OVSDB_CHECK_NEGATIVE([duplicate integer key not allowed in map], +OVSDB_CHECK_POSITIVE([string map of 10 string to string], + [[parse-data-strings '{"key": "string", "value": "string", "min": 1, "max": 10}' \ + '{"2 gills"="1 chopin", + "2 chopins"= "1 pint", + "2 pints"= "1 quart", + "2 quarts"= "1 pottle", + "2 pottles"= "1 gallon", + "2 gallons"= "1 peck", + "2 pecks"= "1 demibushel", + "2 demibushel"= "1 firkin", + "2 firkins"= "1 kilderkin", + "2 kilderkins"= "1 barrel"}']], + [[{"2 chopins"="1 pint", "2 demibushel"="1 firkin", "2 firkins"="1 kilderkin", "2 gallons"="1 peck", "2 gills"="1 chopin", "2 kilderkins"="1 barrel", "2 pecks"="1 demibushel", "2 pints"="1 quart", "2 pottles"="1 gallon", "2 quarts"="1 pottle"}]]) + +OVSDB_CHECK_NEGATIVE([duplicate integer key not allowed in JSON map], [[parse-data '{"key": "integer", "value": "boolean", "max": 5}' \ '["map", [[1, true], [2, false], [1, false]]]']], [ovsdb error: map contains duplicate key]) + +OVSDB_CHECK_NEGATIVE([duplicate integer key not allowed in string map], + [[parse-data-strings '{"key": "integer", "value": "boolean", "max": 5}' \ + '1=true 2=false 1=false']], + [map contains duplicate key]) diff --git a/tests/test-ovsdb.c b/tests/test-ovsdb.c index ede79226..18f8c46e 100644 --- a/tests/test-ovsdb.c +++ b/tests/test-ovsdb.c @@ -24,6 +24,7 @@ #include #include "command-line.h" +#include "dynamic-string.h" #include "json.h" #include "jsonrpc.h" #include "ovsdb-data.h" @@ -125,11 +126,15 @@ usage(void) " parse-type JSON\n" " parse JSON as OVSDB type, and re-serialize\n" " parse-atoms TYPE ATOM...\n" - " parse ATOMs as atoms of given TYPE, and re-serialize\n" + " parse JSON ATOMs as atoms of TYPE, and re-serialize\n" + " parse-atom-strings TYPE ATOM...\n" + " parse string ATOMs as atoms of given TYPE, and re-serialize\n" " sort-atoms TYPE ATOM...\n" - " print ATOMs in sorted order, and re-serialize\n" + " print JSON ATOMs in sorted order\n" " parse-data TYPE DATUM...\n" - " parse DATUMs as data of given TYPE, and re-serialize\n" + " parse JSON DATUMs as data of given TYPE, and re-serialize\n" + " parse-data-strings TYPE DATUM...\n" + " parse string DATUMs as data of given TYPE, and re-serialize\n" " parse-column NAME OBJECT\n" " parse column NAME with info OBJECT, and re-serialize\n" " parse-table NAME OBJECT\n" @@ -231,6 +236,14 @@ check_ovsdb_error(struct ovsdb_error *error) ovs_fatal(0, "%s", ovsdb_error_to_string(error)); } } + +static void +die_if_error(char *error) +{ + if (error) { + ovs_fatal(0, "%s", error); + } +} /* Command implementations. */ @@ -352,6 +365,32 @@ do_parse_atoms(int argc, char *argv[]) } } +static void +do_parse_atom_strings(int argc, char *argv[]) +{ + enum ovsdb_atomic_type type; + struct json *json; + int i; + + json = unbox_json(parse_json(argv[1])); + check_ovsdb_error(ovsdb_atomic_type_from_json(&type, json)); + json_destroy(json); + + for (i = 2; i < argc; i++) { + union ovsdb_atom atom; + struct ds out; + + die_if_error(ovsdb_atom_from_string(&atom, type, argv[i])); + + ds_init(&out); + ovsdb_atom_to_string(&atom, type, &out); + puts(ds_cstr(&out)); + ds_destroy(&out); + + ovsdb_atom_destroy(&atom, type); + } +} + static void do_parse_data(int argc, char *argv[]) { @@ -376,6 +415,32 @@ do_parse_data(int argc, char *argv[]) } } +static void +do_parse_data_strings(int argc, char *argv[]) +{ + struct ovsdb_type type; + struct json *json; + int i; + + json = unbox_json(parse_json(argv[1])); + check_ovsdb_error(ovsdb_type_from_json(&type, json)); + json_destroy(json); + + for (i = 2; i < argc; i++) { + struct ovsdb_datum datum; + struct ds out; + + die_if_error(ovsdb_datum_from_string(&datum, &type, argv[i])); + + ds_init(&out); + ovsdb_datum_to_string(&datum, &type, &out); + puts(ds_cstr(&out)); + ds_destroy(&out); + + ovsdb_datum_destroy(&datum, &type); + } +} + static enum ovsdb_atomic_type compare_atoms_atomic_type; static int @@ -1711,7 +1776,9 @@ static struct command all_commands[] = { { "parse-atomic-type", 1, 1, do_parse_atomic_type }, { "parse-type", 1, 1, do_parse_type }, { "parse-atoms", 2, INT_MAX, do_parse_atoms }, + { "parse-atom-strings", 2, INT_MAX, do_parse_atom_strings }, { "parse-data", 2, INT_MAX, do_parse_data }, + { "parse-data-strings", 2, INT_MAX, do_parse_data_strings }, { "sort-atoms", 2, 2, do_sort_atoms }, { "parse-column", 2, 2, do_parse_column }, { "parse-table", 2, 2, do_parse_table },