Browse code

Utility functions for building test images

These functions allow images to be built using diskimage-builder which
contain packages built from local project checkouts:
build_dib_pip_repo() - Builds a local pip repo from local projects and configures
apache to serve it
disk_image_create_upload() - Creates and uploads a diskimage-builder built image

The unused function lib/heat disk_image_create has been deleted.

Change-Id: Ia75c7c35bfd48dbe6ae3cb9c3241de0b598cbf84

Steve Baker authored on 2014/05/27 09:24:40
Showing 3 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,15 @@
0
+Listen %DIB_PIP_REPO_PORT%
1
+
2
+<VirtualHost *:%DIB_PIP_REPO_PORT%>
3
+    DocumentRoot %DIB_PIP_REPO%
4
+    <Directory %DIB_PIP_REPO%>
5
+        DirectoryIndex index.html
6
+        Require all granted
7
+        Order allow,deny
8
+        allow from all
9
+    </Directory>
10
+
11
+    ErrorLog /var/log/%APACHE_NAME%/dib_pip_repo_error.log
12
+    LogLevel warn
13
+    CustomLog /var/log/%APACHE_NAME%/dib_pip_repo_access.log combined
14
+</VirtualHost>
... ...
@@ -21,6 +21,8 @@ set +o xtrace
21 21
 DIB_DIR=$DEST/diskimage-builder
22 22
 TIE_DIR=$DEST/tripleo-image-elements
23 23
 DIB_IMAGE_CACHE=$DATA_DIR/diskimage-builder/image-create
24
+DIB_PIP_REPO=$DATA_DIR/diskimage-builder/pip-repo
25
+DIB_PIP_REPO_PORT=${DIB_PIP_REPO_PORT:-8899}
24 26
 OCC_DIR=$DEST/os-collect-config
25 27
 ORC_DIR=$DEST/os-refresh-config
26 28
 OAC_DIR=$DEST/os-apply-config
... ...
@@ -42,6 +44,86 @@ function install_dib {
42 42
     mkdir -p $DIB_IMAGE_CACHE
43 43
 }
44 44
 
45
+# build_dib_pip_repo() - Builds a local pip repo from local projects
46
+function build_dib_pip_repo {
47
+    local project_dirs=$1
48
+    local projpath proj package
49
+
50
+    rm -rf $DIB_PIP_REPO
51
+    mkdir -p $DIB_PIP_REPO
52
+
53
+    echo "<html><body>" > $DIB_PIP_REPO/index.html
54
+    for projpath in $project_dirs; do
55
+        proj=$(basename $projpath)
56
+        mkdir -p $DIB_PIP_REPO/$proj
57
+        pushd $projpath
58
+        rm -rf dist
59
+        python setup.py sdist
60
+        pushd dist
61
+        package=$(ls *)
62
+        mv $package $DIB_PIP_REPO/$proj/$package
63
+        popd
64
+
65
+        echo "<html><body><a href=\"$package\">$package</a></body></html>" > $DIB_PIP_REPO/$proj/index.html
66
+        echo "<a href=\"$proj\">$proj</a><br/>" >> $DIB_PIP_REPO/index.html
67
+
68
+        popd
69
+    done
70
+
71
+    echo "</body></html>" >> $DIB_PIP_REPO/index.html
72
+
73
+    local dib_pip_repo_apache_conf=$(apache_site_config_for dib_pip_repo)
74
+
75
+    sudo cp $FILES/apache-dib-pip-repo.template $dib_pip_repo_apache_conf
76
+    sudo sed -e "
77
+        s|%DIB_PIP_REPO%|$DIB_PIP_REPO|g;
78
+        s|%DIB_PIP_REPO_PORT%|$DIB_PIP_REPO_PORT|g;
79
+        s|%APACHE_NAME%|$APACHE_NAME|g;
80
+    " -i $dib_pip_repo_apache_conf
81
+    enable_apache_site dib_pip_repo
82
+}
83
+
84
+# disk_image_create_upload() - Creates and uploads a diskimage-builder built image
85
+function disk_image_create_upload {
86
+
87
+    local image_name=$1
88
+    local image_elements=$2
89
+    local elements_path=$3
90
+
91
+    local image_path=$TOP_DIR/files/$image_name.qcow2
92
+
93
+    # Set the local pip repo as the primary index mirror so the
94
+    # image is built with local packages
95
+    local pypi_mirror_url=http://$SERVICE_HOST:$DIB_PIP_REPO_PORT/
96
+    local pypi_mirror_url_1
97
+
98
+    if [ -a $HOME/.pip/pip.conf ]; then
99
+        # Add the current pip.conf index-url as an extra-index-url
100
+        # in the image build
101
+        pypi_mirror_url_1=$(iniget $HOME/.pip/pip.conf global index-url)
102
+    else
103
+        # If no pip.conf, set upstream pypi as an extra mirror
104
+        # (this also sets the .pydistutils.cfg index-url)
105
+        pypi_mirror_url_1=http://pypi.python.org/simple
106
+    fi
107
+
108
+    # The disk-image-create command to run
109
+    ELEMENTS_PATH=$elements_path \
110
+    PYPI_MIRROR_URL=$pypi_mirror_url \
111
+    PYPI_MIRROR_URL_1=$pypi_mirror_url_1 \
112
+    disk-image-create -a amd64 $image_elements \
113
+        --image-cache $DIB_IMAGE_CACHE \
114
+        -o $image_path
115
+
116
+    local token=$(keystone token-get | grep ' id ' | get_field 2)
117
+    die_if_not_set $LINENO token "Keystone fail to get token"
118
+
119
+    glance --os-auth-token $token --os-image-url http://$GLANCE_HOSTPORT \
120
+        image-create --name $image_name --is-public True \
121
+        --container-format=bare --disk-format qcow2 \
122
+        < $image_path
123
+}
124
+
45 125
 # Restore xtrace
46 126
 $XTRACE
47 127
 
... ...
@@ -204,21 +204,6 @@ function stop_heat {
204 204
     done
205 205
 }
206 206
 
207
-function disk_image_create {
208
-    local elements_path=$1
209
-    local elements=$2
210
-    local arch=$3
211
-    local output=$TOP_DIR/files/$4
212
-    if [[ -f "$output.qcow2" ]]; then
213
-        echo "Image file already exists: $output_file"
214
-    else
215
-        ELEMENTS_PATH=$elements_path disk-image-create \
216
-            $elements -a $arch -o $output
217
-    fi
218
-    # upload with fake URL so that image in $TOP_DIR/files is used
219
-    upload_image "http://localhost/$output.qcow2" $TOKEN
220
-}
221
-
222 207
 # create_heat_accounts() - Set up common required heat accounts
223 208
 function create_heat_accounts {
224 209
     # migrated from files/keystone_data.sh