From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ian Jackson Subject: [OSSTEST PATCH 3/3] ts-xen-install: nodhcp: Make idempotent Date: Thu, 17 Apr 2014 16:13:24 +0100 Message-ID: <1397747604-9321-3-git-send-email-ian.jackson@eu.citrix.com> References: <1397660720.24638.208.camel@kazak.uk.xensource.com> <1397747604-9321-1-git-send-email-ian.jackson@eu.citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1Wao0h-0006FQ-IU for xen-devel@lists.xenproject.org; Thu, 17 Apr 2014 15:13:55 +0000 In-Reply-To: <1397747604-9321-1-git-send-email-ian.jackson@eu.citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel@lists.xenproject.org Cc: Ian Jackson , Ian Campbell List-Id: xen-devel@lists.xenproject.org If run more than once, this function would erroneously determine that xenbr0 was the primary physical interface name and try to enroll it into the bridge (also named xenbr0). Instead, spot the "bridge_ports" line and use it to extract the physical interface name. Eliminate from consideration any interfaces matching xenbr\d+. Signed-off-by: Ian Jackson --- ts-xen-install | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/ts-xen-install b/ts-xen-install index c59fdd3..4215ed3 100755 --- a/ts-xen-install +++ b/ts-xen-install @@ -217,6 +217,7 @@ sub nodhcp () { if (!defined $physif) { # preread /etc/network/interfaces to figure out the interface my %candidates; + my @bridges; while () { if ( m{^ \s* ( auto \s+ (\S+) ) \s* $}x || @@ -225,10 +226,24 @@ sub nodhcp () { ) { push @{ $candidates{$2} }, $1; } + if ( + ( + (m{^ \s* iface \s+ (xenbr\w*) \s+ inet \s+ }x + ? ((push @bridges, $1), 1) : 0) + ... + !m{^ [ \t] }x + ) + && + m{^ \s+ bridge_ports \s+ (\S+) \s }x + ) { + push @{ $candidates{$1} }, "$bridges[$#bridges] $_"; + } } EI->error and die $!; delete $candidates{'lo'}; - die Dumper(\%candidates)." -- cannot determine default interface" + delete $candidates{$_} foreach @bridges; + die Dumper(\%candidates, \@bridges). + " -- cannot determine default interface" unless (scalar keys %candidates) == 1; ($physif,) = keys %candidates; seek EI,0,0 or die $!; -- 1.7.10.4