Skip to content

Commit 824380e

Browse files
committed
ovs: quote external-ids and other-config values
For complex values, ovs-vsctl requires that they are quoted or it will error out. LP: #2070318 While here, add some debugging information so we can see the ovs-vsctl command executed by "netplan apply" with --debug.
1 parent 150090a commit 824380e

File tree

6 files changed

+77
-74
lines changed

6 files changed

+77
-74
lines changed

netplan_cli/cli/ovs.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import logging
1919
import os
2020
import subprocess
21-
import re
2221

2322
from .utils import systemctl_is_active, systemctl_is_installed
2423

@@ -52,21 +51,22 @@ def _del_col(type, iface, column, value):
5251
default = DEFAULTS.get(column)
5352
if default is None:
5453
# removes the exact value only if it was set by netplan
55-
subprocess.check_call([OPENVSWITCH_OVS_VSCTL, 'remove', type, iface, column, value])
54+
cmd = [OPENVSWITCH_OVS_VSCTL, 'remove', type, iface, column, value]
55+
logging.debug('Running: %s' % ' '.join(cmd))
56+
subprocess.check_call(cmd)
5657
elif default and default != value:
5758
# reset to default, if its not the default already
58-
subprocess.check_call([OPENVSWITCH_OVS_VSCTL, 'set', type, iface, '%s=%s' % (column, default)])
59+
cmd = [OPENVSWITCH_OVS_VSCTL, 'set', type, iface, '%s=%s' % (column, default)]
60+
logging.debug('Running: %s' % ' '.join(cmd))
61+
subprocess.check_call(cmd)
5962

6063

6164
def _del_dict(type, iface, column, key, value):
6265
"""Cleanup values from a dictionary (i.e. "column:key=value")"""
6366
# removes the exact value only if it was set by netplan
64-
subprocess.check_call([OPENVSWITCH_OVS_VSCTL, 'remove', type, iface, column, key, _escape_colon(value)])
65-
66-
67-
# for ovsdb remove: column key's value can not contain bare ':', need to escape with '\'
68-
def _escape_colon(literal):
69-
return re.sub(r'([^\\]):', r'\g<1>\:', literal)
67+
cmd = [OPENVSWITCH_OVS_VSCTL, 'remove', type, iface, column, '%s=\"%s\"' % (key, value)]
68+
logging.debug('Running: %s' % ' '.join(cmd))
69+
subprocess.check_call(cmd)
7070

7171

7272
def _del_global(type, iface, key, value):

src/openvswitch.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ write_ovs_tag_setting(const gchar* id, const char* type, const char* col, const
134134
g_string_append_printf(s, "%s", col);
135135
if (key)
136136
g_string_append_printf(s, "/%s", key);
137-
g_string_append_printf(s, "=%s", clean_value);
137+
g_string_append_printf(s, "=\"%s\"", clean_value);
138138
append_systemd_cmd(cmds, OPENVSWITCH_OVS_VSCTL " set %s %s %s", type, id, s->str);
139139
g_string_free(s, TRUE);
140140
}
@@ -150,7 +150,7 @@ write_ovs_additional_data(GHashTable *data, const char* type, const gchar* id, G
150150
while (g_hash_table_iter_next(&iter, (gpointer) &key, (gpointer) &value)) {
151151
/* XXX: we need to check what happens when an invalid key=value pair
152152
gets supplied here. We might want to handle this somehow. */
153-
append_systemd_cmd(cmds, OPENVSWITCH_OVS_VSCTL " set %s %s %s:%s=%s",
153+
append_systemd_cmd(cmds, OPENVSWITCH_OVS_VSCTL " set %s %s %s:%s=\"%s\"",
154154
type, id, setting, key, value);
155155
write_ovs_tag_setting(id, type, setting, key, value, cmds);
156156
}
@@ -210,7 +210,7 @@ STATIC void
210210
write_ovs_tag_netplan(const gchar* id, const char* type, GString* cmds)
211211
{
212212
/* Mark this bridge/port/interface as created by netplan */
213-
append_systemd_cmd(cmds, OPENVSWITCH_OVS_VSCTL " set %s %s external-ids:netplan=true",
213+
append_systemd_cmd(cmds, OPENVSWITCH_OVS_VSCTL " set %s %s external-ids:netplan=\"true\"",
214214
type, id);
215215
}
216216

tests/generator/base.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,11 @@
6565
OVS_PHYSICAL = _OVS_BASE + 'Requires=sys-subsystem-net-devices-%(iface)s.device\nAfter=sys-subsystem-net-devices-%(iface)s\
6666
.device\nAfter=netplan-ovs-cleanup.service\nBefore=network.target\nWants=network.target\n%(extra)s'
6767
OVS_VIRTUAL = _OVS_BASE + 'After=netplan-ovs-cleanup.service\nBefore=network.target\nWants=network.target\n%(extra)s'
68-
OVS_BR_DEFAULT = 'ExecStart=/usr/bin/ovs-vsctl set Bridge %(iface)s external-ids:netplan=true\nExecStart=/usr/bin/ovs-vsctl \
68+
OVS_BR_DEFAULT = 'ExecStart=/usr/bin/ovs-vsctl set Bridge %(iface)s external-ids:netplan=\"true\"\nExecStart=/usr/bin/ovs-vsctl \
6969
set-fail-mode %(iface)s standalone\nExecStart=/usr/bin/ovs-vsctl set Bridge %(iface)s external-ids:netplan/global/set-fail-mode=\
70-
standalone\nExecStart=/usr/bin/ovs-vsctl set Bridge %(iface)s mcast_snooping_enable=false\nExecStart=/usr/bin/ovs-vsctl set \
71-
Bridge %(iface)s external-ids:netplan/mcast_snooping_enable=false\nExecStart=/usr/bin/ovs-vsctl set Bridge %(iface)s \
72-
rstp_enable=false\nExecStart=/usr/bin/ovs-vsctl set Bridge %(iface)s external-ids:netplan/rstp_enable=false\n'
70+
\"standalone\"\nExecStart=/usr/bin/ovs-vsctl set Bridge %(iface)s mcast_snooping_enable=false\nExecStart=/usr/bin/ovs-vsctl set \
71+
Bridge %(iface)s external-ids:netplan/mcast_snooping_enable="false"\nExecStart=/usr/bin/ovs-vsctl set Bridge %(iface)s \
72+
rstp_enable=false\nExecStart=/usr/bin/ovs-vsctl set Bridge %(iface)s external-ids:netplan/rstp_enable=\"false\"\n'
7373
OVS_BR_EMPTY = _OVS_BASE + 'After=netplan-ovs-cleanup.service\nBefore=network.target\nWants=network.target\n\n[Service]\n\
7474
Type=oneshot\nTimeoutStartSec=10s\nExecStart=/usr/bin/ovs-vsctl --may-exist add-br %(iface)s\n' + OVS_BR_DEFAULT
7575
OVS_CLEANUP = _OVS_BASE + 'ConditionFileIsExecutable=/usr/bin/ovs-vsctl\nBefore=network.target\nWants=network.target\n\n\

0 commit comments

Comments
 (0)