~openstack-charm-testers/openstack-charm-testing/openstack-monitoring

« back to all changes in this revision

Viewing changes to tools/render2.sh

  • Committer: Edward Hope-Morley
  • Date: 2016-12-05 15:01:45 UTC
  • mfrom: (220.1.37 openstack-charm-testing)
  • Revision ID: edward.hope-morley@canonical.com-20161205150145-5xs44qcs5ifqsnl5
rebase

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/bash -e
 
2
 
 
3
function usage() {
 
4
  echo -e "
 
5
Renders one or more Juju 1+2 bundles from an old-style multiple-inheritance
 
6
bundle.  The source bundle must use "charm: cs:foo" (not branch: foo).
 
7
 
 
8
New/updated bundles will be written/overwritten to a "rendered" subdir.
 
9
 
 
10
  Syntax:
 
11
    ./render2.sh -t <optional space-separated list of targets> <bundle file(s)>
 
12
 
 
13
  Usage examples:
 
14
    Render specific inheritance targets from a bundle:
 
15
    ./render2.sh -t \"trusty-liberty trusty-mitaka\" foo/source_bundle.yaml
 
16
 
 
17
    Render specific inheritance targets from all bundles in a dir:
 
18
    ./render2.sh -t \"trusty-liberty trusty-mitaka\" foo/*.yaml
 
19
 
 
20
    Render the default inheritance targets from a bundle:
 
21
    ./render2.sh foo/source_bundle.yaml
 
22
 
 
23
    Render the default inheritance targets from a wildcard:
 
24
    ./render2.sh foo/*.yaml
 
25
 
 
26
    In all of these examples, the rendered files will reside in the
 
27
    foo/rendered/ dir.
 
28
"
 
29
}
 
30
 
 
31
while getopts ":t:" opt
 
32
   do
 
33
     case $opt in
 
34
        t ) TARGETS=$OPTARG;;
 
35
        * ) usage; exit 1;;
 
36
     esac
 
37
done
 
38
 
 
39
shift $(($OPTIND - 1))
 
40
SRC_BUNDLE_FILES=$@
 
41
[[ -z "$SRC_BUNDLE_FILES" ]] && (usage; exit 1)
 
42
 
 
43
TARGETS_DEFAULT="trusty-liberty trusty-mitaka xenial-mitaka"
 
44
TARGETS="${TARGETS-$TARGETS_DEFAULT}"
 
45
WARNING_TXT="# Do not edit this file by hand.  Changes may be lost as it was rendered from another bundle."
 
46
 
 
47
echo "Bundle files: $SRC_BUNDLE_FILES"
 
48
echo "Targets: $TARGETS"
 
49
 
 
50
if [[ ! -d $HOME/tools/bot-control ]]; then
 
51
  mkdir -vp $HOME/tools
 
52
  git clone https://github.com/openstack-charmers/bot-control $HOME/tools/bot-control
 
53
fi
 
54
 
 
55
for SRC_BUNDLE in $SRC_BUNDLE_FILES;do
 
56
  RENDER_DIR="$(dirname "$SRC_BUNDLE")/rendered"
 
57
  [[ ! -d "$RENDER_DIR" ]] && mkdir -vp $RENDER_DIR
 
58
 
 
59
  for COMBO in $TARGETS; do
 
60
    # Reduce bundle to one specific inheritance target
 
61
    OUT_FILE="$RENDER_DIR/$(basename $SRC_BUNDLE .yaml)-$COMBO.yaml"
 
62
    $HOME/tools/bot-control/tools/bundle-reducer -y -i $SRC_BUNDLE -o $OUT_FILE -t $COMBO
 
63
 
 
64
    # Add warning comment to the top of all rendered files
 
65
    sed -i "1i${WARNING_TXT}" $OUT_FILE
 
66
  done
 
67
done