Skip to content

Commit

Permalink
ovsdb-data: Don't put strings with digits in quotes.
Browse files Browse the repository at this point in the history
No need to use quotes for strings like "br0".

Keeping UUIDs always in quotes to avoid different treatment of those
that starts with digits and those that starts with letters.

Signed-off-by: Ilya Maximets <i.maximets@samsung.com>
Acked-by: Ben Pfaff <blp@ovn.org>
  • Loading branch information
igsilya committed Jul 25, 2019
1 parent d560bc1 commit 29004db
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 39 deletions.
7 changes: 6 additions & 1 deletion lib/ovsdb-data.c
Expand Up @@ -674,14 +674,15 @@ string_needs_quotes(const char *s)
{
const char *p = s;
unsigned char c;
struct uuid uuid;

c = *p++;
if (!isalpha(c) && c != '_') {
return true;
}

while ((c = *p++) != '\0') {
if (!isalpha(c) && c != '_' && c != '-' && c != '.') {
if (!isalpha(c) && !isdigit(c) && c != '_' && c != '-' && c != '.') {
return true;
}
}
Expand All @@ -690,6 +691,10 @@ string_needs_quotes(const char *s)
return true;
}

if (uuid_from_string(&uuid, s)) {
return true;
}

return false;
}

Expand Down
8 changes: 4 additions & 4 deletions tests/ovn-controller-vtep.at
Expand Up @@ -136,28 +136,28 @@ AT_CHECK([ovn-sbctl --columns=ip list Encap | cut -d ':' -f2 | tr -d ' '], [0],
AT_CHECK([vtep-ctl add-ls lswitch0 -- bind-ls br-vtep p0 100 lswitch0 -- bind-ls br-vtep p0 200 lswitch0 -- bind-ls br-vtep p1 300 lswitch0])
OVS_WAIT_UNTIL([test -n "`ovn-sbctl list Chassis | grep -- lswitch0`"])
AT_CHECK([ovn-sbctl --columns=vtep_logical_switches list Chassis | cut -d ':' -f2 | tr -d ' ' ], [0], [dnl
[["lswitch0"]]
[[lswitch0]]
])

# adds another logical switch and new vlan_bindings.
AT_CHECK([vtep-ctl add-ls lswitch1 -- bind-ls br-vtep p0 300 lswitch1])
OVS_WAIT_UNTIL([test -n "`ovn-sbctl list Chassis | grep -- lswitch1`"])
AT_CHECK([ovn-sbctl --columns=vtep_logical_switches list Chassis | cut -d ':' -f2 | tr -d ' '], [0], [dnl
[["lswitch0","lswitch1"]]
[[lswitch0,lswitch1]]
])

# unbinds one port from lswitch0, nothing should change.
AT_CHECK([vtep-ctl unbind-ls br-vtep p0 200])
OVS_WAIT_UNTIL([test -z "`vtep-ctl --columns=vlan_bindings list physical_port p0 | grep -- '200='`"])
AT_CHECK([ovn-sbctl --columns=vtep_logical_switches list Chassis | cut -d ':' -f2 | tr -d ' ' ], [0], [dnl
[["lswitch0","lswitch1"]]
[[lswitch0,lswitch1]]
])

# unbinds all ports from lswitch0.
AT_CHECK([vtep-ctl unbind-ls br-vtep p0 100 -- unbind-ls br-vtep p1 300])
OVS_WAIT_UNTIL([test -z "`ovn-sbctl list Chassis | grep -- br-vtep_lswitch0`"])
AT_CHECK([ovn-sbctl --columns=vtep_logical_switches list Chassis | cut -d ':' -f2 | tr -d ' ' ], [0], [dnl
[["lswitch1"]]
[[lswitch1]]
])

# unbinds all ports from lswitch1.
Expand Down
6 changes: 3 additions & 3 deletions tests/ovn-nbctl.at
Expand Up @@ -1594,7 +1594,7 @@ OVN_NBCTL_TEST([ovn_nbctl_port_groups], [port groups], [
dnl Check that port group can be looked up by name
AT_CHECK([ovn-nbctl create Port_Group name=pg0], [0], [ignore])
AT_CHECK([ovn-nbctl get Port_Group pg0 name], [0], [dnl
"pg0"
pg0
])])

OVN_NBCTL_TEST([ovn_nbctl_extra_newlines], [extra newlines], [
Expand All @@ -1603,10 +1603,10 @@ dnl daemon mode. All we have to do is ensure that each time we list database
dnl information, there is not an extra newline at the beginning of the output.
AT_CHECK([ovn-nbctl ls-add sw1], [0], [ignore])
AT_CHECK([ovn-nbctl --columns=name list logical_switch sw1], [0], [dnl
name : "sw1"
name : sw1
])
AT_CHECK([ovn-nbctl --columns=name list logical_switch sw1], [0], [dnl
name : "sw1"
name : sw1
])])

OVN_NBCTL_TEST([ovn_nbctl_table_formatting], [table formatting], [
Expand Down
20 changes: 10 additions & 10 deletions tests/ovn-sbctl.at
Expand Up @@ -79,11 +79,11 @@ AT_CHECK([ovn-nbctl --wait=sb sync])
AT_CHECK([ovn-sbctl lsp-bind vif0 ch0])

AT_CHECK([ovn-sbctl show], [0], [dnl
Chassis "ch0"
Chassis ch0
Encap stt
ip: "1.2.3.5"
options: {csum="true"}
Port_Binding "vif0"
Port_Binding vif0
])

# adds another 'vif1'
Expand All @@ -92,29 +92,29 @@ AT_CHECK([ovn-nbctl lsp-set-addresses vif1 f0:ab:cd:ef:01:03])
AT_CHECK([ovn-sbctl lsp-bind vif1 ch0])

AT_CHECK([ovn-sbctl show | sed 's/vif[[0-9]]/vif/'], [0], [dnl
Chassis "ch0"
Chassis ch0
Encap stt
ip: "1.2.3.5"
options: {csum="true"}
Port_Binding "vif"
Port_Binding "vif"
Port_Binding vif
Port_Binding vif
])

# deletes 'vif1'
AT_CHECK([ovn-nbctl lsp-del vif1])
AT_CHECK([ovn-nbctl --wait=sb sync])

AT_CHECK([ovn-sbctl show], [0], [dnl
Chassis "ch0"
Chassis ch0
Encap stt
ip: "1.2.3.5"
options: {csum="true"}
Port_Binding "vif0"
Port_Binding vif0
])

uuid=$(ovn-sbctl --columns=_uuid list Chassis ch0 | cut -d ':' -f2 | tr -d ' ')
AT_CHECK_UNQUOTED([ovn-sbctl --columns=logical_port,mac,chassis list Port_Binding], [0], [dnl
logical_port : "vif0"
logical_port : vif0
mac : [["f0:ab:cd:ef:01:02"]]
chassis : ${uuid}
])
Expand All @@ -126,10 +126,10 @@ AT_CHECK([ovn-nbctl lsp-set-options vtep0 vtep_physical_switch=p0 vtep_logical_s

AT_CHECK([ovn-sbctl --timeout=10 wait-until Port_Binding vtep0 options!={}])
AT_CHECK([ovn-sbctl --columns=logical_port,mac,type,options list Port_Binding vtep0], [0], [dnl
logical_port : "vtep0"
logical_port : vtep0
mac : [[]]
type : vtep
options : {vtep_logical_switch="l0", vtep_physical_switch="p0"}
options : {vtep_logical_switch=l0, vtep_physical_switch=p0}
])

OVN_SBCTL_TEST_STOP
Expand Down
32 changes: 16 additions & 16 deletions tests/ovs-vsctl.at
Expand Up @@ -453,19 +453,19 @@ value0
key0=othervalue


{"key1"="value1"}
{"key2"="value2", "key3"="value3"}
{"key4"="value4"}
{key1=value1}
{key2=value2, key3=value3}
{key4=value4}
])
AT_CHECK([RUN_OVS_VSCTL_TOGETHER(
[br-get-external-id a],
[get port a1 external-ids],
[get interface a2 external-ids],
[get interface a3 external-ids])], [0],
[
{"key1"="value1"}
{"key2"="value2", "key3"="value3"}
{"key4"="value4"}
{key1=value1}
{key2=value2, key3=value3}
{key4=value4}
])
CHECK_BRIDGES([a, a, 0])
CHECK_PORTS([a], [a1], [bond0])
Expand Down Expand Up @@ -731,7 +731,7 @@ flow_tables : {}
ipfix : []
mcast_snooping_enable: false
mirrors : []
name : "br0"
name : br0
netflow : []
other_config : {}
ports : []
Expand All @@ -747,14 +747,14 @@ AT_CHECK(
[RUN_OVS_VSCTL([--columns=fail_mode,name,datapath_type list bridge])],
[0],
[[fail_mode : []
name : "br0"
name : br0
datapath_type : ""
]], [ignore])
AT_CHECK(
[RUN_OVS_VSCTL([--columns=fail_mode,name,datapath_type find bridge])],
[0],
[[fail_mode : []
name : "br0"
name : br0
datapath_type : ""
]], [ignore])
AT_CHECK([
Expand All @@ -766,8 +766,8 @@ AT_CHECK(
[RUN_OVS_VSCTL([--columns=name find bridge datapath_type!=foo])], [0], [stdout],
[ignore])
AT_CHECK([sed -n '/./p' stdout | sort], [0],
[[name : "br0"
name : "br2"
[[name : br0
name : br2
]])
AT_CHECK(
[RUN_OVS_VSCTL(
Expand Down Expand Up @@ -1142,9 +1142,9 @@ AT_CHECK(
AT_CHECK(
[sed -n -e '/uuid/p' -e '/name/p' -e '/mirrors/p' -e '/select/p' -e '/output/p' < stdout | uuidfilt], [0], [dnl
[_uuid : <0>
name : "eth0"
name : eth0
_uuid : <1>
name : "eth1"
name : eth1
_uuid : <2>
name : mymirror
output_port : <1>
Expand All @@ -1155,7 +1155,7 @@ select_src_port : [<0>]
select_vlan : []
_uuid : <3>
mirrors : [<2>]
name : "br0"
name : br0
]])
OVS_VSCTL_CLEANUP
AT_CLEANUP
Expand Down Expand Up @@ -1214,7 +1214,7 @@ flow_tables : {}
ipfix : []
mcast_snooping_enable: false
mirrors : []
name : "br0"
name : br0
netflow : []
other_config : {}
ports : []
Expand Down Expand Up @@ -1357,7 +1357,7 @@ OVS_VSCTL_SETUP
dnl First check that the database commands can refer to row by database UUID.
AT_CHECK([RUN_OVS_VSCTL([add-br br0])])
uuid=`[]RUN_OVS_VSCTL(get port br0 _uuid)`
AT_CHECK([RUN_OVS_VSCTL([get port $uuid name])], [0], ["br0"
AT_CHECK([RUN_OVS_VSCTL([get port $uuid name])], [0], [br0
])

dnl Next check that, if a database row is given a name that has the same form
Expand Down
6 changes: 3 additions & 3 deletions tests/ovsdb-server.at
Expand Up @@ -1203,8 +1203,8 @@ for i in `seq 1 $n_iterations`; do
trigger_big_update $i
done
AT_CHECK([ovs-appctl -t ovsdb-client ovsdb-client/unblock])
OVS_WAIT_UNTIL([grep "\"xyzzy$counter\"" ovsdb-client.out])
OVS_WAIT_UNTIL([grep "\"xyzzy$counter\"" ovsdb-client-nonblock.out])
OVS_WAIT_UNTIL([grep "xyzzy$counter" ovsdb-client.out])
OVS_WAIT_UNTIL([grep "xyzzy$counter" ovsdb-client-nonblock.out])
OVS_APP_EXIT_AND_WAIT([ovsdb-client])
AT_CHECK([kill `cat nonblock.pid`])

Expand All @@ -1221,7 +1221,7 @@ echo "logged_updates=$logged_updates (expected less than $logged_nonblock_update
AT_CHECK([test $logged_nonblock_updates -le $n_updates])
AT_CHECK([test $logged_updates -lt $logged_nonblock_updates])
AT_CHECK_UNQUOTED([ovs-vsctl get open_vswitch . system_version], [0],
["xyzzy$counter"
[xyzzy$counter
])
OVS_APP_EXIT_AND_WAIT([ovsdb-server])
AT_CLEANUP
Expand Down
4 changes: 2 additions & 2 deletions tests/vtep-ctl.at
Expand Up @@ -939,9 +939,9 @@ AT_CHECK([vtep-ctl --timeout=5 -vreconnect:emer --db=unix:socket show | tail -n+
Physical_Switch a
management_ips: [["4.3.2.1"]]
tunnel_ips: [["1.2.3.4"]]
Physical_Port "a1"
Physical_Port a1
vlan_bindings:
100="ls1"
100=ls1
], [], [VTEP_CTL_CLEANUP])

VTEP_CTL_CLEANUP
Expand Down

0 comments on commit 29004db

Please sign in to comment.