~kissiel/checkbox/validation-rework

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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/bin/sh
# This file is part of Checkbox.
#
# Copyright 2013 Canonical Ltd.
# Written by:
#   Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
#
# Checkbox is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3,
# as published by the Free Software Foundation.

#
# Checkbox is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Checkbox.  If not, see <http://www.gnu.org/licenses/>.

# Helper script to provision testing containers or environments
# =============================================================

# Vagrant and LXC are explicitly supported, other types of containers (KVM)
# can be made to work but aren't yet guaranteed to.
#
# This script is entirely run *inside* the VM/container.

# Set CHECKBOX_TOP for all shared scripts. This should indicate the location
# of the checkbox source tree in the VM/container.
# If not passed as the first argument to the script, it defaults to /vagrant
# since by default vagrant mounts the current directory in the host system
# as /vagrant in the VM.
export CHECKBOX_TOP=${1:-/vagrant}

# Make sure that dpkg never stops to have a chat with the user
export DEBIAN_FRONTEND=noninteractive

if [ $CHECKBOX_TOP = "/vagrant" ] ; then
	# Vagrant sanity check, see if /vagrant really works.
	#
	# On various installations of Ubuntu this is not the case as the cloud images
	# we depend on seem to have broken virtualbox tools installation inside.  This
	# causes the filesystem mounted on /vagrant to crash horribly and kill all
	# processes attempting to use it.
	if ! find /vagrant -mindepth 1 -maxdepth 1 >/dev/null; then
	    cat <<__EOM__
	E: It seems that /vagrant directory is broken
	E: This is a known issue.
	E: See this link for a workaround if you have recent-enough VirtualBox:
	E: https://bugs.launchpad.net/ubuntu/+source/virtualbox/+bug/1252872
	E: Alternatively you can use NFS on any version of VirtualBox:
	E: http://docs.vagrantup.com/v2/synced-folders/nfs.html
__EOM__
	    exit 1
	else
	    echo "I: it seems that /vagrant is working okay"
	fi
fi
# Add any necessary PPA repositories
$CHECKBOX_TOP/support/install-ppa-dependencies

# Update to have the latest packages, this is needed because the image comes
# with an old (and no longer working) apt cache and links to many packages no
# longer work. This is also needed if the step above actually added any PPAs.
apt-get update

# Update all packages to latest version
# NOTE: this is disabled as it takes a lot of time and we haven't found the
# need to run this. It might have to be re-enabled later if we find that some
# bug (that gets fixed) is affecting our behavior but so far that has not been
# the case.
# apt-get dist-upgrade --yes

# Ensure that certain Debian dependencies are *not* installed
$CHECKBOX_TOP/support/remove-deb-anty-dependencies

set -e
$CHECKBOX_TOP/support/install-deb-dependencies
$CHECKBOX_TOP/support/get-external-tarballs
$CHECKBOX_TOP/support/install-pip-from-source
# Pip executable name is a variable that depends on python version
export PIP=/usr/local/bin/pip-3.*
$CHECKBOX_TOP/support/install-pip-dependencies
$CHECKBOX_TOP/support/develop-projects

export PROVIDERPATH=/usr/local/share/plainbox-providers-1
mkdir -p "$PROVIDERPATH"
$CHECKBOX_TOP/support/develop-providers

# Create a cool symlink so that everyone knows where to go to.
#
# Vagrant runs the provision script as root, but we want the symlink to /vagrant,
# so we're reduced to assuming the stuff is there and blindly linking.
if [ -d /vagrant ]; then
    [ -d /home/vagrant ] && ln --no-dereference --force --symbolic /vagrant /home/vagrant/src
elif [ "$container" = "lxc" ]; then
    # In LXC, $HOME is inherited from the invoking environment. Link the source
    # location to /home/$user-invoking-lxc/src.  This should work consistently
    # since all the lxc-attach commands will use the same inherited environment, so
    # $user-invoking-lxc should always point to the same place.  Under LXC,
    # however, the home dir may not exist (as lxc creates only the ubuntu user by
    # default), so we need to create the home dir ourselves.
    [ ! -d $HOME ] && mkdir -p $HOME
    ln --no-dereference --force --symbolic $CHECKBOX_TOP $HOME/src
fi

# Patch pkg-resources to fix https://bugs.launchpad.net/plainbox/+bug/1456560
if patch -p0 /usr/lib/python3/dist-packages/pkg_resources.py << EOF
--- pkg_resources.py.orig	2014-05-15 19:39:38.365807720 +0000
+++ pkg_resources.py	2014-05-15 19:44:50.449807720 +0000
@@ -1749,11 +1749,16 @@
                     for dist in find_distributions(os.path.join(path_item, entry)):
                         yield dist
                 elif not only and lower.endswith('.egg-link'):
-                    for line in open(os.path.join(path_item, entry)):
-                        if not line.strip(): continue
-                        for item in find_distributions(os.path.join(path_item,line.rstrip())):
-                            yield item
-                        break
+                    try:
+                        entry_file = open(os.path.join(path_item, entry))
+                        for line in entry_file:
+                            if not line.strip(): continue
+                            for item in find_distributions(os.path.join(path_item,line.rstrip())):
+                                yield item
+                            break
+                    finally:
+                        entry_file.close()
+
 register_finder(ImpWrapper,find_on_path)

 _declare_state('dict', _namespace_handlers={})
EOF
then
	echo "Patching pkg_resources.py succeeded"
else
	echo "Patching pkg_resources.py failed"
	echo "This is not necessarily bad, this is only needed on precise"
fi