From 2e308fc94ae7c6ca184380222e53c6d1a2351d59 Mon Sep 17 00:00:00 2001 From: Ian Wienand Date: Fri, 28 Apr 2017 15:18:52 +1000 Subject: [PATCH] Move jenkins cache to /opt/cache For whatever reason, the source-repositories caching element is running in the very early extra-data phase of disk-image-builder. cache-devstack is instructing source-repositories to put the cached urls into /home/jenkins/cache/files (55-cache-devstack-repos makes up the list of images to download from devstack; the other two are just pre-configured URLS). This causes a problem when trying to add the jenkins user later in jenkins-slave/install.d/20-jenkins-slave. Since source repositories has already created /home/jenkins, useradd won't do it again and does not copy in any of the skeleton files. This moves the extra-data phase caching into /opt/cache, which is probably a more logical place for it anyway. To maintain the status quo, after we create the jenkins user, symlink ~jenkins/cache/files to this new location. This was probably going wrong with puppet too. I'm guessing it just ignored the existing homedir when creating the user. I have tested this by building trusty and stopping the build before and after the useradd calls in 20-jenkins-slave. "/home" was empty, the useradd creates the user, group & directory, the symlink is made correctly and /opt/cache/files appears populated as usual. Change-Id: Ibca6867f29b257a5110cb5522a5cca3a97fa9377 --- .../cache-devstack/extra-data.d/55-cache-devstack-repos | 2 +- nodepool/elements/cache-devstack/source-repository-pip | 2 +- .../elements/cache-devstack/source-repository-stackviz | 2 +- .../elements/jenkins-slave/install.d/20-jenkins-slave | 9 +++++++++ 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/nodepool/elements/cache-devstack/extra-data.d/55-cache-devstack-repos b/nodepool/elements/cache-devstack/extra-data.d/55-cache-devstack-repos index f80c9f7171..0f36244fa1 100755 --- a/nodepool/elements/cache-devstack/extra-data.d/55-cache-devstack-repos +++ b/nodepool/elements/cache-devstack/extra-data.d/55-cache-devstack-repos @@ -160,7 +160,7 @@ def main(): image_filenames.append(fname) args = dict( name=fname, - location=os.path.join('/home/jenkins/cache/files', fname), + location=os.path.join('/opt/cache/files', fname), url=url) images_list.write(line_template % args) diff --git a/nodepool/elements/cache-devstack/source-repository-pip b/nodepool/elements/cache-devstack/source-repository-pip index 17ebe80a69..e5c6dea8f0 100644 --- a/nodepool/elements/cache-devstack/source-repository-pip +++ b/nodepool/elements/cache-devstack/source-repository-pip @@ -1 +1 @@ -get-pip-py file /home/jenkins/cache/files/get-pip.py https://bootstrap.pypa.io/get-pip.py +get-pip-py file /opt/cache/files/get-pip.py https://bootstrap.pypa.io/get-pip.py diff --git a/nodepool/elements/cache-devstack/source-repository-stackviz b/nodepool/elements/cache-devstack/source-repository-stackviz index b855e51c2b..ff79ecf0a9 100644 --- a/nodepool/elements/cache-devstack/source-repository-stackviz +++ b/nodepool/elements/cache-devstack/source-repository-stackviz @@ -1 +1 @@ -stackviz file /home/jenkins/cache/files/stackviz-latest.tar.gz http://tarballs.openstack.org/package-stackviz-element/stackviz-latest.tar.gz +stackviz file /opt/cache/files/stackviz-latest.tar.gz http://tarballs.openstack.org/package-stackviz-element/stackviz-latest.tar.gz diff --git a/nodepool/elements/jenkins-slave/install.d/20-jenkins-slave b/nodepool/elements/jenkins-slave/install.d/20-jenkins-slave index d72da14564..eabb9c5316 100755 --- a/nodepool/elements/jenkins-slave/install.d/20-jenkins-slave +++ b/nodepool/elements/jenkins-slave/install.d/20-jenkins-slave @@ -6,9 +6,18 @@ fi set -eu set -o pipefail +# Add jenkins user and group. Note we don't want to rely on +# "useradd"'s group adding behaviour, because it might differ across +# distros. groupadd jenkins useradd -g jenkins -m jenkins -s /bin/bash +# a lot of caching happens in extra-data.d (for "historical" reasons). +# We've put the cache stuff into /opt/cache/files, but again, for +# "historical" reasons, ensure this is available in /home/jenkins +mkdir -p /home/jenkins/cache +ln -sf /opt/cache/files /home/jenkins/cache/files + # this was copied from outside the chroot by extras.d _pub_key=/tmp/in_target.d/jenkins-user-ssh-public-key if [ ! -f $_pub_key ]; then