From 0d028383c5b5df7b73683bcdbd7062ef893b6c3f Mon Sep 17 00:00:00 2001
From: Michal Skalski <mskalski@mirantis.com>
Date: Sat, 16 Jul 2016 20:16:17 +0200
Subject: [PATCH] Build new cache when list of packages has changed

Create a new cache of f_repobuild job when list of packages required by
plugins has changed.

JIRA: FUEL-150

Change-Id: I079950eaa9e3b32ea7baa3f6d4a37cc37f99f3a7
Signed-off-by: Michal Skalski <mskalski@mirantis.com>
---
 build/cache.sh                        | 22 ++++++++++++++++++++++
 build/f_isoroot/f_repobuild/Makefile  |  8 +++-----
 build/f_isoroot/f_repobuild/config.mk | 13 +++++++++++++
 3 files changed, 38 insertions(+), 5 deletions(-)
 create mode 100644 build/f_isoroot/f_repobuild/config.mk

diff --git a/build/cache.sh b/build/cache.sh
index 7a2a06385..d4b2c45dd 100755
--- a/build/cache.sh
+++ b/build/cache.sh
@@ -21,6 +21,7 @@ trap exit_trap EXIT
 CACHETRANSPORT=${CACHETRANSPORT:-"curl --silent"}
 CACHEMAXAGE=${CACHEMAXAGE:-$[14*24*3600]}
 CACHEDEBUG=${CACHEDEBUG:-1}
+PLUGINS_MATCH="${BUILD_BASE}/f_isoroot/*/"
 
 debugmsg () {
     if [ "$CACHEDEBUG" -eq 1 ]; then
@@ -138,7 +139,22 @@ getcommitid() {
     fi
 }
 
+packages() {
+    local PLUGINS_SHA1=''
 
+    # globbing expansion is alphabetical
+    for plugin in $PLUGINS_MATCH ; do
+        if [ -f "${plugin}packages.yaml" ]
+        then
+            PLUGINS_SHA1+=$(sha1sum ${plugin}packages.yaml)
+        fi
+    done
+
+    if [ -n "${PLUGINS_SHA1}" ]
+    then
+        echo -n $PLUGINS_SHA1 | sha1sum
+    fi
+}
 
 if [ -z "$CACHEBASE" ]; then
   errorexit "CACHEBASE not set - exiting..."
@@ -176,6 +192,12 @@ case $1 in
         $1 $2
         exit $rc
         ;;
+    packages)
+        if [ $# -ne 1 ]; then
+            errorexit "No arguments can be given to packages!"
+        fi
+        packages
+        ;;
     *)
         errorexit "I only know about getcommitid, getid, check, get and put!"
 esac
diff --git a/build/f_isoroot/f_repobuild/Makefile b/build/f_isoroot/f_repobuild/Makefile
index cbf81fe4e..8312f5e55 100644
--- a/build/f_isoroot/f_repobuild/Makefile
+++ b/build/f_isoroot/f_repobuild/Makefile
@@ -11,13 +11,9 @@
 SHELL := /bin/bash
 TOP := $(shell pwd)
 TMP_ROOT_DIR := $(shell echo "$(MIRROR_UBUNTU_ROOT)" | cut -d "/" -f2)
-# Enable use of exact repo commit if defined, else use Fuel main branch
-FUEL_MIRROR_REPO?=https://github.com/openstack/fuel-mirror
-# Point to the commit where 302 redirects are handled
-# https://bugs.launchpad.net/fuel/mitaka/+bug/1593674
-FUEL_MIRROR_COMMIT?=192a3d9f8f993afb12c5108dd9339c6688c23e11 #$(FUEL_MAIN_TAG)
 
 include ../../config.mk
+include config.mk
 
 export MOS_VERSION
 export OPENSTACK_VERSION
@@ -69,6 +65,8 @@ release:nailgun
 .cacheid:
 	date +"Repocache %G%V" > .cachedata
 	sha1sum Makefile >> .cachedata
+	sha1sum config.mk >> .cachedata
+	$(CACHETOOL) packages >> .cachedata
 	cat .cachedata | $(CACHETOOL) getid > .cacheid
 
 # Clean local data related to caching - called prior to ordinary build
diff --git a/build/f_isoroot/f_repobuild/config.mk b/build/f_isoroot/f_repobuild/config.mk
new file mode 100644
index 000000000..d81732849
--- /dev/null
+++ b/build/f_isoroot/f_repobuild/config.mk
@@ -0,0 +1,13 @@
+##############################################################################
+# Copyright (c) 2016 Ericsson AB and others.
+# mskalski@mirantis.com
+# 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
+##############################################################################
+
+FUEL_MIRROR_REPO?=https://github.com/openstack/fuel-mirror
+# Point to the commit where 302 redirects are handled
+# https://bugs.launchpad.net/fuel/mitaka/+bug/1593674
+FUEL_MIRROR_COMMIT?=192a3d9f8f993afb12c5108dd9339c6688c23e11
-- 
2.16.6