Before the patch, system-id could be configured via a global config
option in ovsdb. This patch adds another option - configure system-id
via a file. This is achieved by writing the desired system-id into the
following file location: ${OVN_SYSCONFDIR}/system-id-override.The file is read on controller startup. The file setting overrides configuration stored in ovsdb, if any. This may be useful when running multiple containerized controller instances using the same vswitchd. Signed-off-by: Ihar Hrachyshka <[email protected]> --- controller/chassis.c | 6 +++++ controller/chassis.h | 2 ++ controller/ovn-controller.8.xml | 5 ++++- controller/ovn-controller.c | 39 +++++++++++++++++++++++++++++++++ tests/ovn.at | 36 ++++++++++++++++++++++++++++++ tests/ovs-macros.at | 2 ++ 6 files changed, 89 insertions(+), 1 deletion(-) diff --git a/controller/chassis.c b/controller/chassis.c index 38e17144b..af7a0bab3 100644 --- a/controller/chassis.c +++ b/controller/chassis.c @@ -37,6 +37,8 @@ VLOG_DEFINE_THIS_MODULE(chassis); #define HOST_NAME_MAX 255 #endif /* HOST_NAME_MAX */ +char *file_system_id = NULL; + /* * Structure for storing the chassis config parsed from the ovs table. */ @@ -827,6 +829,10 @@ chassis_get_mac(const struct sbrec_chassis *chassis_rec, const char * get_ovs_chassis_id(const struct ovsrec_open_vswitch_table *ovs_table) { + if (file_system_id) { + return file_system_id; + } + const struct ovsrec_open_vswitch *cfg = ovsrec_open_vswitch_table_first(ovs_table); const char *chassis_id = cfg ? smap_get(&cfg->external_ids, "system-id") diff --git a/controller/chassis.h b/controller/chassis.h index 243bde282..53ad1d803 100644 --- a/controller/chassis.h +++ b/controller/chassis.h @@ -33,6 +33,8 @@ struct sset; struct eth_addr; struct smap; +extern char *file_system_id; + void chassis_register_ovs_idl(struct ovsdb_idl *); const struct sbrec_chassis *chassis_run( struct ovsdb_idl_txn *ovnsb_idl_txn, diff --git a/controller/ovn-controller.8.xml b/controller/ovn-controller.8.xml index 14fb15752..1783209c1 100644 --- a/controller/ovn-controller.8.xml +++ b/controller/ovn-controller.8.xml @@ -73,7 +73,10 @@ not directly supported. Users have two options: either first gracefully stop <code>ovn-controller</code> or manually delete the stale <code>Chassis</code> and <code>Chassis_Private</code> records - after changing the <code>system-id</code>.</dd> + after changing the <code>system-id</code>. Note that the chassis name can + also be provided via the <code>system-id-override</code> file in the + local OVN "etc" directory. The file configuration overrides the one from + the database, if both are present.</dd> <dt><code>external_ids:hostname</code></dt> <dd>The hostname to use in the Chassis table.</dd> diff --git a/controller/ovn-controller.c b/controller/ovn-controller.c index 1a1fa5686..c9f9eb036 100644 --- a/controller/ovn-controller.c +++ b/controller/ovn-controller.c @@ -20,6 +20,7 @@ #include <errno.h> #include <getopt.h> #include <signal.h> +#include <stdio.h> #include <stdlib.h> #include <string.h> @@ -55,6 +56,7 @@ #include "lib/ip-mcast-index.h" #include "lib/mac-binding-index.h" #include "lib/mcast-group-index.h" +#include "lib/ovn-dirs.h" #include "lib/ovn-sb-idl.h" #include "lib/ovn-util.h" #include "patch.h" @@ -152,6 +154,37 @@ struct pending_pkt { /* Registered ofctrl seqno type for nb_cfg propagation. */ static size_t ofctrl_seq_type_nb_cfg; +static void +remove_newline(char *s) +{ + char *last = &s[strlen(s) - 1]; + switch (*last) { + case '\n': + case '\r': + *last = '\0'; + default: + return; + } +} + +static char *get_file_system_id(void) +{ + char *ret = NULL; + char *filename = xasprintf("%s/system-id-override", ovn_sysconfdir()); + errno = 0; + FILE *f = fopen(filename, "r"); + if (f) { + char system_id[64]; + if (fgets(system_id, sizeof system_id, f)) { + remove_newline(system_id); + ret = xstrdup(system_id); + } + fclose(f); + } + free(filename); + return ret; +} + static unsigned int update_sb_monitors(struct ovsdb_idl *ovnsb_idl, const struct sbrec_chassis *chassis, @@ -3611,6 +3644,9 @@ main(int argc, char *argv[]) struct ovn_controller_exit_args exit_args = {&exiting, &restart}; int retval; + /* Read from system-id-override file once on startup. */ + file_system_id = get_file_system_id(); + ovs_cmdl_proctitle_init(argc, argv); ovn_set_program_name(argv[0]); service_start(&argc, &argv); @@ -4588,6 +4624,9 @@ loop_done: ovs_feature_support_destroy(); free(ovs_remote); + if (file_system_id) { + free(file_system_id); + } service_stop(); exit(retval); diff --git a/tests/ovn.at b/tests/ovn.at index 16ba4b0e1..4197e67da 100644 --- a/tests/ovn.at +++ b/tests/ovn.at @@ -33490,3 +33490,39 @@ check_column "" Encap ip chassis_name=hv1 type=vxlan OVN_CLEANUP([hv1],[hv2]) AT_CLEANUP ]) + +OVN_FOR_EACH_NORTHD([ +AT_SETUP([chassis name override via file]) +ovn_start +net_add n1 + +sim_add hv1 +as hv1 +ovs-vsctl add-br br-phys + +ovs-vsctl \ + -- set Open_vSwitch . external-ids:ovn-encap-type-hv3=geneve \ + -- set Open_vSwitch . external-ids:ovn-encap-ip-hv3=192.168.1.1 + +as hv1 ovs-vsctl set-ssl \ + $PKIDIR/testpki-hv3-privkey.pem \ + $PKIDIR/testpki-hv3-cert.pem \ + $PKIDIR/testpki-cacert.pem + +echo hv3 > ${OVN_SYSCONFDIR}/system-id-override +ovn_attach n1 br-phys 192.168.0.1 24 vxlan + +sim_add hv2 +as hv2 +ovs-vsctl add-br br-phys +ovn_attach n1 br-phys 192.168.0.2 24 geneve + +# despite that we configured ovn-encap-ip=192.168.0.1, this setting is +# overridden by chassis specific ovn-encap-ip-hv3 +wait_column 192.168.1.1 Encap ip chassis_name=hv3 type=geneve + +check_column "" Encap ip chassis_name=hv1 type=vxlan + +OVN_CLEANUP([hv1],[hv2]) +AT_CLEANUP +]) diff --git a/tests/ovs-macros.at b/tests/ovs-macros.at index 5a06fe956..36b58b5ae 100644 --- a/tests/ovs-macros.at +++ b/tests/ovs-macros.at @@ -88,7 +88,9 @@ ovs_setenv() { OVS_LOGDIR=$ovs_dir; export OVS_LOGDIR OVS_DBDIR=$ovs_dir; export OVS_DBDIR OVS_SYSCONFDIR=$ovs_dir; export OVS_SYSCONFDIR + OVN_SYSCONFDIR=$ovs_dir; export OVN_SYSCONFDIR OVS_PKGDATADIR=$ovs_dir; export OVS_PKGDATADIR + OVN_PKGDATADIR=$ovs_dir; export OVN_PKGDATADIR } # Prints the integers from $1 to $2, increasing by $3 (default 1) on stdout. -- 2.38.1 _______________________________________________ dev mailing list [email protected] https://mail.openvswitch.org/mailman/listinfo/ovs-dev
