~zyga/checkbox/foo

« back to all changes in this revision

Viewing changes to support/provision-testing-environment

  • Committer: Daniel Manrique
  • Date: 2014-05-05 19:39:51 UTC
  • mto: This revision was merged to the branch mainline in revision 2976.
  • Revision ID: roadmr@ubuntu.com-20140505193951-4y395e5u9fbxao3a
provision-vagrant: A few changes to support other container systems.

This is preliminary work to remove some Vagrant assumptions, to enable
using the same provisioning script with other container/virtualization
systems (particularly to add support for LXC).

- Renamed support/provision-vagrant to provision-test-environment
  to remove the assumption that it only works with vagrant. Vagrantfile
  was updated accordingly.
- Short explanation of how the script runs
- Made CHECKBOX_TOP relocatable to the parameter the script receives,
  though we default to /vagrant if we didn't receive anything else.
  This is because test-in-lxc can place the source tree in an
  unpredictable location and provision needs to be aware of the
  location.
- Made the Vagrant sanity check conditional on $CHECKBOX_TOP being
  /vagrant.
- Modified the code to create the $HOME/src symlink to account for
  different container/VM engines since lxc behavior is different from
  Vagrant, this is explained in the comment for the last section of
  the script.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/sh
 
2
# This file is part of Checkbox.
 
3
#
 
4
# Copyright 2013 Canonical Ltd.
 
5
# Written by:
 
6
#   Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
 
7
#
 
8
# Checkbox is free software: you can redistribute it and/or modify
 
9
# it under the terms of the GNU General Public License version 3,
 
10
# as published by the Free Software Foundation.
 
11
 
 
12
#
 
13
# Checkbox is distributed in the hope that it will be useful,
 
14
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
# GNU General Public License for more details.
 
17
#
 
18
# You should have received a copy of the GNU General Public License
 
19
# along with Checkbox.  If not, see <http://www.gnu.org/licenses/>.
 
20
 
 
21
# Helper script to provision testing containers or environments
 
22
# =============================================================
 
23
 
 
24
# Vagrant and LXC are explicitly supported, other types of containers (KVM)
 
25
# can be made to work but aren't yet guaranteed to.
 
26
#
 
27
# This script is entirely run *inside* the VM/container.
 
28
 
 
29
# Set CHECKBOX_TOP for all shared scripts. This should indicate the location
 
30
# of the checkbox source tree in the VM/container.
 
31
# If not passed as the first argument to the script, it defaults to /vagrant
 
32
# since by default vagrant mounts the current directory in the host system
 
33
# as /vagrant in the VM.
 
34
export CHECKBOX_TOP=${1:-/vagrant}
 
35
 
 
36
# Make sure that dpkg never stops to have a chat with the user
 
37
export DEBIAN_FRONTEND=noninteractive
 
38
 
 
39
if [ $CHECKBOX_TOP = "/vagrant" ] ; then
 
40
        # Vagrant sanity check, see if /vagrant really works.
 
41
        #
 
42
        # On various installations of Ubuntu this is not the case as the cloud images
 
43
        # we depend on seem to have broken virtualbox tools installation inside.  This
 
44
        # causes the filesystem mounted on /vagrant to crash horribly and kill all
 
45
        # processes attempting to use it.
 
46
        if ! find /vagrant -mindepth 1 -maxdepth 1 >/dev/null; then
 
47
            cat <<__EOM__
 
48
        E: It seems that /vagrant directory is broken
 
49
        E: This is a known issue.
 
50
        E: See this link for a workaround if you have recent-enough VirtualBox:
 
51
        E: https://bugs.launchpad.net/ubuntu/+source/virtualbox/+bug/1252872
 
52
        E: Alternatively you can use NFS on any version of VirtualBox:
 
53
        E: http://docs.vagrantup.com/v2/synced-folders/nfs.html
 
54
__EOM__
 
55
            exit 1
 
56
        else
 
57
            echo "I: it seems that /vagrant is working okay"
 
58
        fi
 
59
fi
 
60
# Add any necessary PPA repositories
 
61
$CHECKBOX_TOP/support/install-ppa-dependencies
 
62
 
 
63
# Update to have the latest packages, this is needed because the image comes
 
64
# with an old (and no longer working) apt cache and links to many packages no
 
65
# longer work. This is also needed if the step above actually added any PPAs.
 
66
apt-get update
 
67
 
 
68
# Update all packages to latest version
 
69
# NOTE: this is disabled as it takes a lot of time and we haven't found the
 
70
# need to run this. It might have to be re-enabled later if we find that some
 
71
# bug (that gets fixed) is affecting our behavior but so far that has not been
 
72
# the case.
 
73
# apt-get dist-upgrade --yes
 
74
 
 
75
# Ensure that certain Debian dependencies are *not* installed
 
76
$CHECKBOX_TOP/support/remove-deb-anty-dependencies
 
77
 
 
78
set -e
 
79
$CHECKBOX_TOP/support/install-deb-dependencies
 
80
$CHECKBOX_TOP/support/get-external-tarballs
 
81
$CHECKBOX_TOP/support/install-pip-from-source
 
82
# Pip executable name is a variable that depends on python version
 
83
export PIP=/usr/local/bin/pip-3.*
 
84
$CHECKBOX_TOP/support/install-pip-dependencies
 
85
$CHECKBOX_TOP/support/develop-projects
 
86
 
 
87
# Create a cool symlink so that everyone knows where to go to.
 
88
#
 
89
# Vagrant runs the provision script as root, but we want the symlink to /vagrant,
 
90
# so we're reduced to assuming the stuff is there and blindly linking.
 
91
if [ -d /vagrant ]; then
 
92
    [ -d /home/vagrant ] && ln --no-dereference --force --symbolic /vagrant /home/vagrant/src
 
93
elif [ "$container" = "lxc" ]; then
 
94
    # In LXC, $HOME is inherited from the invoking environment. Link the source
 
95
    # location to /home/$user-invoking-lxc/src.  This should work consistently
 
96
    # since all the lxc-attach commands will use the same inherited environment, so
 
97
    # $user-invoking-lxc should always point to the same place.  Under LXC,
 
98
    # however, the home dir may not exist (as lxc creates only the ubuntu user by
 
99
    # default), so we need to create the home dir ourselves.
 
100
    [ ! -d $HOME ] && mkdir -p $HOME
 
101
    ln --no-dereference --force --symbolic $CHECKBOX_TOP $HOME/src
 
102
fi
 
103
 
 
104
 
 
105