diff mbox series

[ovs-dev] Backup and remove existing DB when joining cluster

Message ID 20211020194449.3971906-1-twilson@redhat.com
State Superseded
Headers show
Series [ovs-dev] Backup and remove existing DB when joining cluster | expand

Checks

Context Check Description
ovsrobot/apply-robot success apply and check: success
ovsrobot/github-robot-_Build_and_Test success github build: passed

Commit Message

Terry Wilson Oct. 20, 2021, 7:44 p.m. UTC
ovsdb-tool join-cluster requires a remote addr, so the existing
code that tried to join a cluster without it when there was an
existing $DB_FILE would fail.

Instead, if we are trying to specifically join a cluster and there
is an existing $DB_FILE, back it up and remove the original before
continuing to join the cluster.

Signed-off-by: Terry Wilson <twilson@redhat.com>
---
 utilities/ovs-lib.in | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

Comments

Terry Wilson Oct. 20, 2021, 7:57 p.m. UTC | #1
On Wed, Oct 20, 2021 at 2:45 PM Terry Wilson <twilson@redhat.com> wrote:
>
> ovsdb-tool join-cluster requires a remote addr, so the existing
> code that tried to join a cluster without it when there was an
> existing $DB_FILE would fail.
>
> Instead, if we are trying to specifically join a cluster and there
> is an existing $DB_FILE, back it up and remove the original before
> continuing to join the cluster.
>
> Signed-off-by: Terry Wilson <twilson@redhat.com>
> ---
>  utilities/ovs-lib.in | 10 ++++------
>  1 file changed, 4 insertions(+), 6 deletions(-)
>
> diff --git a/utilities/ovs-lib.in b/utilities/ovs-lib.in
> index 3eda01d3c..06f4319d5 100644
> --- a/utilities/ovs-lib.in
> +++ b/utilities/ovs-lib.in
> @@ -519,13 +519,11 @@ join_cluster() {
>      LOCAL_ADDR="$3"
>      REMOTE_ADDR="$4"
>
> -    if test ! -e "$DB_FILE"; then
> -        ovsdb_tool join-cluster "$DB_FILE" "$SCHEMA_NAME" "$LOCAL_ADDR" "$REMOTE_ADDR"
> -    elif ovsdb_tool db-is-standalone "$DB_FILE"; then
> -        # Backup standalone database and join cluster.
> +    if test -e "$DB_FILE" && ovsdb_tool db-is-standalone "$DB_FILE"; then
>          backup_db || return 1
> -        action "Joining $DB_FILE to cluster" \
> -               ovsdb_tool join-cluster "$DB_FILE" "$SCHEMA_NAME" "$LOCAL_ADDR"
> +        rm $DB_FILE
> +    else
> +        ovsdb_tool join-cluster "$DB_FILE" "$SCHEMA_NAME" "$LOCAL_ADDR" "$REMOTE_ADDR"
>      fi
>  }
>
> --
> 2.31.1

I tested this and it fixes things for me when upgrading where the
non-inital controller nodes had existing DBs, but looking at it again,
the behavior would change in the case where there was a DB_FILE that
was *not* standalone. I'll re-spin this.

Terry
diff mbox series

Patch

diff --git a/utilities/ovs-lib.in b/utilities/ovs-lib.in
index 3eda01d3c..06f4319d5 100644
--- a/utilities/ovs-lib.in
+++ b/utilities/ovs-lib.in
@@ -519,13 +519,11 @@  join_cluster() {
     LOCAL_ADDR="$3"
     REMOTE_ADDR="$4"
 
-    if test ! -e "$DB_FILE"; then
-        ovsdb_tool join-cluster "$DB_FILE" "$SCHEMA_NAME" "$LOCAL_ADDR" "$REMOTE_ADDR"
-    elif ovsdb_tool db-is-standalone "$DB_FILE"; then
-        # Backup standalone database and join cluster.
+    if test -e "$DB_FILE" && ovsdb_tool db-is-standalone "$DB_FILE"; then
         backup_db || return 1
-        action "Joining $DB_FILE to cluster" \
-               ovsdb_tool join-cluster "$DB_FILE" "$SCHEMA_NAME" "$LOCAL_ADDR"
+        rm $DB_FILE
+    else
+        ovsdb_tool join-cluster "$DB_FILE" "$SCHEMA_NAME" "$LOCAL_ADDR" "$REMOTE_ADDR"
     fi
 }