]> git.proxmox.com Git - pve-container.git/commitdiff
fix dns setup when using host dns configuration
authorDietmar Maurer <dietmar@proxmox.com>
Thu, 23 Apr 2015 07:49:33 +0000 (09:49 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Thu, 23 Apr 2015 07:49:33 +0000 (09:49 +0200)
src/PVE/LXCSetup/Base.pm
src/test/run_tests.pl
src/test/test2/etc/hosts.exp
src/test/test4/etc/hosts.exp

index 5365006d66eb9f629ec4ce8dcfef8b7525b4b96e..8fd86b512ab10018bd42b4e82fe16a15ccdbcb78 100644 (file)
@@ -8,8 +8,42 @@ use Digest::SHA;
 use IO::File;
 use Encode;
 
+use PVE::INotify;
 use PVE::Tools;
 
+
+my $lookup_dns_conf = sub {
+    my ($conf) = @_;
+
+    my $nameserver = $conf->{'pve.nameserver'};
+    my $searchdomains = $conf->{'pve.searchdomain'};
+
+    if (!($nameserver && $searchdomains)) {
+
+       if ($conf->{'pve.test_mode'}) {
+           
+           $nameserver = "8.8.8.8 8.8.8.9";
+           $searchdomains = "promxox.com";
+       
+       } else {
+
+           my $host_resolv_conf = PVE::INotify::read_file('resolvconf');
+
+           $searchdomains = $host_resolv_conf->{search};
+
+           my @list = ();
+           foreach my $k ("dns1", "dns2", "dns3") {
+               if (my $ns = $host_resolv_conf->{$k}) {
+                   push @list, $ns;
+               }
+           }
+           $nameserver = join(' ', @list);
+       }
+    }
+
+    return ($searchdomains, $nameserver);
+};
+
 my $update_etc_hosts = sub {
     my ($etc_hosts_data, $hostip, $oldname, $newname, $searchdomains) = @_;
 
@@ -88,22 +122,7 @@ my $update_etc_hosts = sub {
 sub set_dns {
     my ($class, $conf) = @_;
 
-    my $nameserver = $conf->{'pve.nameserver'};
-    my $searchdomains = $conf->{'pve.searchdomain'};
-
-    my $host_resolv_conf = PVE::INotify::read_file('resolvconf');
-
-    if (!($nameserver && $searchdomains)) {
-       $searchdomains = $host_resolv_conf->{search};
-
-       my @list = ();
-       foreach my $k ("dns1", "dns2", "dns3") {
-           if (my $ns = $host_resolv_conf->{$k}) {
-               push @list, $ns;
-           }
-       }
-       $nameserver = join(' ', @list);
-    }
+    my ($searchdomains, $nameserver) = &$lookup_dns_conf($conf);
     
     my $rootfs = $conf->{'lxc.rootfs'};
     
@@ -143,10 +162,12 @@ sub set_hostname {
 
     my ($ipv4, $ipv6) = PVE::LXC::get_primary_ips($conf);
     my $hostip = $ipv4 || $ipv6;
+
+    my ($searchdomains) = &$lookup_dns_conf($conf);
+
     $etc_hosts_data = &$update_etc_hosts($etc_hosts_data, $hostip, $oldname, 
-                                        $hostname, $conf->{'pve.searchdomain'});
-  
+                                        $hostname, $searchdomains);
+    
     PVE::Tools::file_set_contents($hostname_fn, "$hostname\n");
     PVE::Tools::file_set_contents($hosts_fn, $etc_hosts_data);
 }
index 9d52393ee3d8662eb9155c2a10c71b9ddeaf194b..e3ceca0a8add48aa46e3808c24cff182d7d376d2 100755 (executable)
@@ -34,6 +34,7 @@ sub run_test {
     my $conf = PVE::LXC::parse_lxc_config("/lxc/100/config", $raw);
 
     $conf->{'lxc.rootfs'} = $rootfs;
+    $conf->{'pve.test_mode'} = 1;
     
     my $lxc_setup = PVE::LXCSetup->new($conf);
 
index ed6e36ad3cf8014e91e6b065763172b75d057389..67c9944b06e328ecdcb855aa278f133dd4184436 100644 (file)
@@ -1,2 +1,2 @@
 127.0.0.1 localhost.localnet localhost
-1.2.3.4  test1
+1.2.3.4 test1.promxox.com test1
index 8e26f561206ea0e11eff52cdf44011a0c0bb7171..1e0a5d02df323611fd3f331a5d7fc4e0c19275a7 100644 (file)
@@ -1,2 +1,2 @@
 127.0.0.1 localhost.localnet localhost
-1.2.3.2  test3
+1.2.3.2 test3.promxox.com test3