From 529240d7d14e2644132bc401c38daa8d0946acb6 Mon Sep 17 00:00:00 2001 From: Victor Seva Date: Fri, 17 Oct 2014 11:53:26 +0200 Subject: [PATCH] MT#9579 ngcp-sync-constants: fix check for master host Previously we were using the IP not the hostname Backporting to mr3.5 from trunk, otherwise upgrade mr3.4->mr3.5 is broken: > sp2 not found at /var/lib/mysql/master.info. Fix replication manually Change-Id: I48e2bb57da5ac32879d11ca51dd675db2b817ba6 (cherry picked from commit 10ea8aba6987187332e72482e196c6dab034af2c) --- debian/control | 2 ++ sbin/ngcp-sync-constants | 15 ++++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/debian/control b/debian/control index b7ddde62..a98d2de4 100644 --- a/debian/control +++ b/debian/control @@ -14,6 +14,7 @@ Build-Depends: asciidoc, liblist-moreutils-perl, libnet-netmask-perl, libregexp-ipv6-perl, + libsocket-perl, libsys-hostname-long-perl, libtemplate-perl, libyaml-perl, @@ -36,6 +37,7 @@ Depends: etckeeper, liblist-moreutils-perl, libnet-netmask-perl, libregexp-ipv6-perl, + libsocket-perl, libsys-hostname-long-perl, libtemplate-perl, libyaml-perl, diff --git a/sbin/ngcp-sync-constants b/sbin/ngcp-sync-constants index f2ab2a8c..f6641d38 100755 --- a/sbin/ngcp-sync-constants +++ b/sbin/ngcp-sync-constants @@ -8,6 +8,9 @@ use YAML::Tiny; use Getopt::Long; use Sys::Hostname; use Data::Dumper; +use Socket; +use List::MoreUtils qw(any); +use Data::Validate::IP qw(is_ipv4 is_ipv6); use IPC::System::Simple qw(system capturex); #---------------------------------------------------------------------- use constant CONSTANTS_YML => "/etc/ngcp-config/constants.yml"; @@ -209,6 +212,12 @@ sub sync_repuser { my $minfo = "/var/lib/mysql$dbid/master.info"; my $mhost = $args{mhost}; my $mport = $args{mport} || 3306; + my $mhost_ip = $args{mhost}; + + unless ( is_ipv4($mhost) or is_ipv6($mhost) ) { + $mhost_ip = inet_ntoa(scalar(gethostbyname($mhost))); + print " --> $mhost => $mhost_ip\n" if $debug; + } print " --> syncing replication user '$user' for master host '$mhost'\n" if $debug; if(-f $minfo) { @@ -220,12 +229,12 @@ sub sync_repuser { } my @minfo_content = <$mfh>; close $mfh; - unless(grep {/^${mhost}\s*$/}@minfo_content) { - print STDERR "${mhost} not found at $minfo. Fix replication manually"; + unless(any {/^(${mhost}|${mhost_ip})\s*$/} @minfo_content) { + print STDERR "${mhost} or ${mhost_ip} were not found at $minfo. Fix replication manually"; $error = 2; return; } - unless(grep {/^${pass}\s*$/} @minfo_content) { + unless(any {/^${pass}\s*$/} @minfo_content) { set_master_pass( dbh => $dbh, user => $user, pass => $pass