summaryrefslogtreecommitdiffstats
path: root/patches/fuel-agent/cross-bootstrap/0004-Prevent-common-cross-debootstrap-newaliases-issue.patch
blob: ffe40b5499c21d4d40033aa99525a11b04e2d060 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
: Copyright (c) 2017 Enea AB and others.
:
: All rights reserved. This program and the accompanying materials
: are made available under the terms of the Apache License, Version 2.0
: which accompanies this distribution, and is available at
: http://www.apache.org/licenses/LICENSE-2.0
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
From: Alexandru Avadanii <Alexandru.Avadanii@enea.com>
Date: Tue, 8 Mar 2016 00:44:05 +0100
Subject: [PATCH] Prevent common cross-debootstrap newaliases issue.

While building target images for a different arch (using qemu-user-static),
the following issue prevents the succesful image build:
newaliases: fatal: inet_addr_local[getifaddrs]:
getifaddrs: Address family not supported by protocol

For more information, see [1].

[1] https://bugs.launchpad.net/ubuntu/+source/postfix/+bug/1531299
---
 fuel_agent/manager.py     | 14 ++++++++++++++
 fuel_agent/utils/build.py | 24 ++++++++++++++++++++++++
 2 files changed, 38 insertions(+)

diff --git a/fuel_agent/manager.py b/fuel_agent/manager.py
index 637c99a..86f76b9 100644
--- a/fuel_agent/manager.py
+++ b/fuel_agent/manager.py
@@ -1037,10 +1037,15 @@ class Manager(object):
                 direct_repo_addrs=driver_os.proxies.direct_repo_addr_list)
             self._update_metadata_with_repos(
                 metadata, driver_os.repos)
+            # Prevent common cross-debootstraping problem w/ newaliases & qemu
+            # inet_addr_local[getifaddrs]: getifaddrs: Address family not supp
+            LOG.debug('Preventing newaliases from running inside chroot')
+            bu.prevent_qemu_newaliases(chroot)
             LOG.debug('Installing packages using apt-get: %s',
                       ' '.join(packages))
             # disable hosts/resolv files
             bu.propagate_host_resolv_conf(chroot)
+
             if hasattr(bs_scheme, 'certs') and bs_scheme.certs:
                 bu.copy_update_certs(bs_scheme.certs, chroot)
             bu.run_apt_get(chroot, packages=packages,
@@ -1084,5 +1089,6 @@ class Manager(object):
             # restore disabled hosts/resolv files
             bu.restore_resolv_conf(chroot)
+            bu.restore_newaliases(chroot)
             metadata['all_packages'] = bu.get_installed_packages(chroot)
             # We need to recompress initramfs with new compression:
             bu.recompress_initramfs(
@@ -1175,6 +1181,11 @@ class Manager(object):
             self._update_metadata_with_repos(
                 metadata, driver_os.repos)

+            # Prevent common cross-debootstraping problem w/ newaliases & qemu
+            # inet_addr_local[getifaddrs]: getifaddrs: Address family not supp
+            LOG.debug('Preventing newaliases from running inside chroot')
+            bu.prevent_qemu_newaliases(chroot)
+
             LOG.debug('Installing packages using apt-get: %s',
                       ' '.join(packages))
             bu.run_apt_get(chroot, packages=packages,
@@ -1187,6 +1198,9 @@ class Manager(object):
                             allow_unsigned_file=CONF.allow_unsigned_file,
                             force_ipv4_file=CONF.force_ipv4_file)

+            LOG.debug('Restoring newaliases command inside chroot')
+            bu.restore_newaliases(chroot)
+
             LOG.debug('Making sure there are no running processes '
                       'inside chroot before trying to umount chroot')
             if not bu.stop_chrooted_processes(chroot, signal=signal.SIGTERM):
diff --git a/fuel_agent/utils/build.py b/fuel_agent/utils/build.py
index 1bc0a5f..5761cc5 100644
--- a/fuel_agent/utils/build.py
+++ b/fuel_agent/utils/build.py
@@ -339,6 +339,30 @@ def prevent_qemu_replacement(chroot, arch):
     utils.execute('chroot', chroot, 'ln', '-sf', '/bin/true',
                   '/usr/sbin/update-binfmts')

+def prevent_qemu_newaliases(chroot):
+    """Prevents running newaliases under qemu-user-static inside chroot.
+
+    Use dpkg-divert to prevent running newaliases binary through qemu inside
+    chroot which is necessary to avoid a dpkg --configure error:
+    inet_addr_local[getifaddrs]: getifaddrs: Address family not supported ...
+    """
+    utils.execute('chroot', chroot,
+                  'dpkg-divert', '--local', '--rename', '--add',
+                  '/usr/bin/newaliases')
+    utils.execute('chroot', chroot, 'ln', '-sf', '/bin/true',
+                  '/usr/bin/newaliases')
+
+def restore_newaliases(chroot):
+    """Restores newaliases inside chroot after previous dpkg-divert.
+
+    opposite to prevent_qemu_newaliases
+    """
+    utils.execute('chroot', chroot,
+                  'rm', '-f', '/usr/bin/newaliases')
+    utils.execute('chroot', chroot,
+                  'dpkg-divert', '--local', '--rename', '--remove',
+                  '/usr/bin/newaliases')
+
 def create_sparse_tmp_file(dir, suffix, size=8192):
     """Creates sparse file.