All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH OSSTEST] ts-xen-install: Rewrite /etc/hosts to comment out 127.0.1.1 entry
@ 2015-09-07 12:58 Ian Campbell
  2015-09-09 17:31 ` Ian Jackson
  0 siblings, 1 reply; 3+ messages in thread
From: Ian Campbell @ 2015-09-07 12:58 UTC (permalink / raw)
  To: ian.jackson, xen-devel; +Cc: Ian Campbell

Debian creates an entry such as:
127.0.1.1             lace-bug.xs.citrite.net         lace-bug

This causes local lookups of the FQDN to get 127.0.1.1, which is
unhelpful if you are looking for an address to bind to and were hoping
to get the public IP address, as libvirt does on the target host for
migration.

Here we remove (actually, comment) any 127.0.1.1 line in /etc/hosts.
This means that lookups of a hosts own name (fqdn or just dn) now rely
on DNS, which may not be ideal. However for a host which uses DHCP I'm
not aware of a way to keep /etc/hosts up to date with the actual IP
address the machine has.  In our infra the test host IP addresses are
all static, but I don't think we want to rely on at any more that we
already do.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
---
 ts-xen-install | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/ts-xen-install b/ts-xen-install
index e039173..7c80a13 100755
--- a/ts-xen-install
+++ b/ts-xen-install
@@ -229,6 +229,24 @@ END
     target_cmd_root($ho, $cmd);
 }
 
+sub hosts () {
+    # Debian installer generates a line like:
+    #
+    # 127.0.1.1             lace-bug.xs.citrite.net         lace-bug
+    #
+    # Where xs.citrite.net is $c{TestHostDomain} and lace-bug is the
+    # hostname, this causes lookups of the hosts FQDN to result in
+    # 127.0.1.1 which is not useful if the reason for the lookup was
+    # to be able to bind to the externally accessible IP address.
+    target_editfile_root($ho, "/etc/hosts", "etc-hosts", sub {
+        my $hn = $ho->{Name};
+        while (<EI>) {
+	    s|^127.0.1.1|#$&|;
+	    print EO;
+        }
+    });
+}
+
 sub nodhcp () {
     target_editfile_root($ho, "/etc/network/interfaces",
                          "etc-network-interfaces", sub {
@@ -350,4 +368,5 @@ if ($checkmode) {
     setupboot();
     setupinitd();
     nodhcp();
+    hosts();
 }
-- 
2.5.1

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH OSSTEST] ts-xen-install: Rewrite /etc/hosts to comment out 127.0.1.1 entry
  2015-09-07 12:58 [PATCH OSSTEST] ts-xen-install: Rewrite /etc/hosts to comment out 127.0.1.1 entry Ian Campbell
@ 2015-09-09 17:31 ` Ian Jackson
  2015-09-09 18:06   ` Ian Campbell
  0 siblings, 1 reply; 3+ messages in thread
From: Ian Jackson @ 2015-09-09 17:31 UTC (permalink / raw)
  To: Ian Campbell; +Cc: xen-devel

Ian Campbell writes ("[PATCH OSSTEST] ts-xen-install: Rewrite /etc/hosts to comment out 127.0.1.1 entry"):
> +	    s|^127.0.1.1|#$&|;

I think you mean

    s|^\Q127.0.1.1\E\b|#$&|;

or

    s|^127\.0\.1\.1\b|#$&|;

(I have tested both of these ad-hoc.)
    
Also

> +        my $hn = $ho->{Name};

This seems unused ?

With those two this corrected.

Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>

Ian.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH OSSTEST] ts-xen-install: Rewrite /etc/hosts to comment out 127.0.1.1 entry
  2015-09-09 17:31 ` Ian Jackson
@ 2015-09-09 18:06   ` Ian Campbell
  0 siblings, 0 replies; 3+ messages in thread
From: Ian Campbell @ 2015-09-09 18:06 UTC (permalink / raw)
  To: Ian Jackson; +Cc: xen-devel

On Wed, 2015-09-09 at 18:31 +0100, Ian Jackson wrote:
> Ian Campbell writes ("[PATCH OSSTEST] ts-xen-install: Rewrite
> /etc/hosts to comment out 127.0.1.1 entry"):
> > +	    s|^127.0.1.1|#$&|;
> 
> I think you mean
> 
>     s|^\Q127.0.1.1\E\b|#$&|;
> 
> or
> 
>     s|^127\.0\.1\.1\b|#$&|;
> 
> (I have tested both of these ad-hoc.)

Yes, I went with the former.
    
> Also
> 
> > +        my $hn = $ho->{Name};
> 
> This seems unused ?

Right, it was a remnant of a previous attempt.

> With those two this corrected.
> 
> Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>

Thanks, I've added the following to pretest.

Ian.

commit e1adb8b552dda5c653958083c9c7457f0398ad09
Author: Ian Campbell <ian.campbell@citrix.com>
Date:   Mon Sep 7 13:58:29 2015 +0100

    ts-xen-install: Rewrite /etc/hosts to comment out 127.0.1.1 entry
    
    Debian creates an entry such as:
    127.0.1.1             lace-bug.xs.citrite.net         lace-bug
    
    This causes local lookups of the FQDN to get 127.0.1.1, which is
    unhelpful if you are looking for an address to bind to and were hoping
    to get the public IP address, as libvirt does on the target host for
    migration.
    
    Here we remove (actually, comment) any 127.0.1.1 line in /etc/hosts.
    This means that lookups of a hosts own name (fqdn or just dn) now rely
    on DNS, which may not be ideal. However for a host which uses DHCP I'm
    not aware of a way to keep /etc/hosts up to date with the actual IP
    address the machine has.  In our infra the test host IP addresses are
    all static, but I don't think we want to rely on at any more that we
    already do.
    
    Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
    Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>

diff --git a/ts-xen-install b/ts-xen-install
index 070e74d..b511e2b 100755
--- a/ts-xen-install
+++ b/ts-xen-install
@@ -230,6 +230,23 @@ END
     target_cmd_root($ho, $cmd);
 }
 
+sub hosts () {
+    # Debian installer generates a line like:
+    #
+    # 127.0.1.1             lace-bug.xs.citrite.net         lace-bug
+    #
+    # Where xs.citrite.net is $c{TestHostDomain} and lace-bug is the
+    # hostname, this causes lookups of the hosts FQDN to result in
+    # 127.0.1.1 which is not useful if the reason for the lookup was
+    # to be able to bind to the externally accessible IP address.
+    target_editfile_root($ho, "/etc/hosts", "etc-hosts", sub {
+        while (<EI>) {
+           s|^\Q127.0.1.1\E\b|#$&|;
+           print EO;
+        }
+    });
+}
+
 sub nodhcp () {
     target_editfile_root($ho, "/etc/network/interfaces",
                          "etc-network-interfaces", sub {
@@ -351,4 +368,5 @@ if ($checkmode) {
     setupboot();
     setupinitd();
     nodhcp();
+    hosts();
 }

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-09-09 18:06 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-09-07 12:58 [PATCH OSSTEST] ts-xen-install: Rewrite /etc/hosts to comment out 127.0.1.1 entry Ian Campbell
2015-09-09 17:31 ` Ian Jackson
2015-09-09 18:06   ` Ian Campbell

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.