diff --git a/cmd/microcloud/main_init.go b/cmd/microcloud/main_init.go index fc4b87588..c576cac31 100644 --- a/cmd/microcloud/main_init.go +++ b/cmd/microcloud/main_init.go @@ -885,8 +885,18 @@ func (c *initConfig) setupCluster(s *service.Handler) error { fmt.Println("Configuring cluster-wide devices ...") - var ovnConfig string - if s.Services[types.MicroOVN] != nil { + // Update LXD's global config. + server, _, err := lxdClient.GetServer() + if err != nil { + return err + } + + config := make(map[string]string) + + // LXD can dynamically determine the OVN northbound DB connection string from MicroOVN's `ovn.env` file. + // This feature was added with the ovn_dynamic_northbound_connection API extension. + // Only set the connection string in case of an older LXD. + if s.Services[types.MicroOVN] != nil && !lxdClient.HasExtension("ovn_dynamic_northbound_connection") { serviceOVN := s.Services[types.MicroOVN].(*service.OVNService) services, err := serviceOVN.GetServices(context.Background()) @@ -911,14 +921,7 @@ func (c *initConfig) setupCluster(s *service.Handler) error { } } - ovnConfig = strings.Join(conns, ",") - } - - config := map[string]string{"network.ovn.northbound_connection": ovnConfig} - // Update LXD's global config. - server, _, err := lxdClient.GetServer() - if err != nil { - return err + config["network.ovn.northbound_connection"] = strings.Join(conns, ",") } newServer := server.Writable() diff --git a/test/includes/microcloud.sh b/test/includes/microcloud.sh index c5efd3dd7..9b5aee89b 100644 --- a/test/includes/microcloud.sh +++ b/test/includes/microcloud.sh @@ -550,16 +550,19 @@ validate_system_lxd_ovn() { echo " ${name} Validating OVN network" - num_conns=3 - if [ "${num_peers}" -lt "${num_conns}" ]; then - num_conns="${num_peers}" - fi + # Check if the connection string is set correctly. + if ! check_api_extension ovn_dynamic_northbound_connection "${name}"; then + num_conns=3 + if [ "${num_peers}" -lt "${num_conns}" ]; then + num_conns="${num_peers}" + fi - [ "$(lxc config get network.ovn.northbound_connection --target "${name}" | sed -e 's/,/\n/g' | wc -l)" = "${num_conns}" ] + [ "$(lxc config get network.ovn.northbound_connection --target "${name}" | sed -e 's/,/\n/g' | wc -l)" = "${num_conns}" ] - # Make sure there's no empty addresses. - ! lxc config get network.ovn.northbound_connection --target "${name}" | sed -e 's/,/\n/g' | grep -q '^ssl:$' || false - ! lxc config get network.ovn.northbound_connection --target "${name}" | sed -e 's/,/\n/g' | grep -q '^ssl::' || false + # Make sure there's no empty addresses. + ! lxc config get network.ovn.northbound_connection --target "${name}" | sed -e 's/,/\n/g' | grep -q '^ssl:$' || false + ! lxc config get network.ovn.northbound_connection --target "${name}" | sed -e 's/,/\n/g' | grep -q '^ssl::' || false + fi # Check that the created UPLINK network has the right DNS servers. if [ -n "${dns_namesersers}" ] ; then