blob: bdca06e8a37daf8e2b68f69d3cdacfce288aa37c [file] [log] [blame]
Dean Troyerdec00f62011-12-30 17:43:20 -06001#!/usr/bin/env bash
Dean Troyere62ba4d2012-06-27 22:07:34 -05002
3# **info.sh**
4
5# Produce a report on the state of devstack installs
Dean Troyerdec00f62011-12-30 17:43:20 -06006#
7# Output fields are separated with '|' chars
8# Output types are git,localrc,os,pip,pkg:
9# git|<project>|<branch>[<shaq>]
10# localtc|<var>=<value>
11# os|<var>=<value>
12# pip|<package>|<version>
13# pkg|<package>|<version>
14
15function usage {
16 echo "$0 - Report on the devstack configuration"
17 echo ""
18 echo "Usage: $0"
19 exit 1
20}
21
22if [ "$1" = "-h" ]; then
23 usage
24fi
25
26# Keep track of the current directory
27TOOLS_DIR=$(cd $(dirname "$0") && pwd)
28TOP_DIR=$(cd $TOOLS_DIR/..; pwd)
29cd $TOP_DIR
30
31# Source params
32source $TOP_DIR/stackrc
33
34DEST=${DEST:-/opt/stack}
35FILES=$TOP_DIR/files
36if [[ ! -d $FILES ]]; then
37 echo "ERROR: missing devstack/files - did you grab more than just stack.sh?"
38 exit 1
39fi
40
41# Repos
42# -----
43
44# git_report <dir>
45function git_report() {
46 local dir=$1
47 local proj ref branch head
48 if [[ -d $dir/.git ]]; then
49 pushd $dir >/dev/null
50 proj=$(basename $dir)
51 ref=$(git symbolic-ref HEAD)
52 branch=${ref##refs/heads/}
53 head=$(git show-branch --sha1-name $branch | cut -d' ' -f1)
54 echo "git|${proj}|${branch}${head}"
55 popd >/dev/null
56 fi
57}
58
59for i in $DEST/*; do
60 if [[ -d $i ]]; then
61 git_report $i
62 fi
63done
64
65# OS
66# --
67
68GetOSInfo() {
69 # Figure out which vedor we are
70 if [ -r /etc/lsb-release ]; then
71 . /etc/lsb-release
72 VENDORNAME=$DISTRIB_ID
73 RELEASE=$DISTRIB_RELEASE
74 else
75 for r in RedHat CentOS Fedora; do
76 VENDORPKG="`echo $r | tr [:upper:] [:lower:]`-release"
77 VENDORNAME=$r
78 RELEASE=`rpm -q --queryformat '%{VERSION}' $VENDORPKG`
79 if [ $? = 0 ]; then
80 break
81 fi
82 VENDORNAME=""
83 done
84 # Get update level
85 if [ -n "`grep Update /etc/redhat-release`" ]; then
86 # Get update
87 UPDATE=`cat /etc/redhat-release | sed s/.*Update\ // | sed s/\)$//`
88 else
89 # Assume update 0
90 UPDATE=0
91 fi
92 fi
93
94 echo "os|vendor=$VENDORNAME"
95 echo "os|release=$RELEASE"
96 if [ -n "$UPDATE" ]; then
97 echo "os|version=$UPDATE"
98 fi
99}
100
101GetOSInfo
102
103# Packages
104# --------
105
106# - We are going to check packages only for the services needed.
107# - We are parsing the packages files and detecting metadatas.
108# - If we have the meta-keyword dist:DISTRO or
109# dist:DISTRO1,DISTRO2 it will be installed only for those
110# distros (case insensitive).
111function get_packages() {
112 local file_to_parse="general"
113 local service
114
115 for service in ${ENABLED_SERVICES//,/ }; do
116 # Allow individual services to specify dependencies
117 if [[ -e $FILES/apts/${service} ]]; then
118 file_to_parse="${file_to_parse} $service"
119 fi
120 if [[ $service == n-* ]]; then
121 if [[ ! $file_to_parse =~ nova ]]; then
122 file_to_parse="${file_to_parse} nova"
123 fi
124 elif [[ $service == g-* ]]; then
125 if [[ ! $file_to_parse =~ glance ]]; then
126 file_to_parse="${file_to_parse} glance"
127 fi
128 elif [[ $service == key* ]]; then
129 if [[ ! $file_to_parse =~ keystone ]]; then
130 file_to_parse="${file_to_parse} keystone"
131 fi
132 fi
133 done
134
135 for file in ${file_to_parse}; do
136 local fname=${FILES}/apts/${file}
137 local OIFS line package distros distro
138 [[ -e $fname ]] || { echo "missing: $fname"; exit 1; }
139
140 OIFS=$IFS
141 IFS=$'\n'
142 for line in $(<${fname}); do
143 if [[ $line =~ (.*)#.*dist:([^ ]*) ]]; then # We are using BASH regexp matching feature.
144 package=${BASH_REMATCH[1]}
145 distros=${BASH_REMATCH[2]}
146 for distro in ${distros//,/ }; do #In bash ${VAR,,} will lowecase VAR
147 [[ ${distro,,} == ${DISTRO,,} ]] && echo $package
148 done
149 continue
150 fi
151
152 echo ${line%#*}
153 done
154 IFS=$OIFS
155 done
156}
157
158for p in $(get_packages); do
159 ver=$(dpkg -s $p 2>/dev/null | grep '^Version: ' | cut -d' ' -f2)
160 echo "pkg|${p}|${ver}"
161done
162
163# Pips
164# ----
165
166function get_pips() {
167 cat $FILES/pips/* | uniq
168}
169
170# Pip tells us what is currently installed
171FREEZE_FILE=$(mktemp --tmpdir freeze.XXXXXX)
172pip freeze >$FREEZE_FILE 2>/dev/null
173
174# Loop through our requirements and look for matches
175for p in $(get_pips); do
176 [[ "$p" = "-e" ]] && continue
177 if [[ "$p" =~ \+?([^#]*)#? ]]; then
178 # Get the URL from a remote reference
179 p=${BASH_REMATCH[1]}
180 fi
181 line="`grep -i $p $FREEZE_FILE`"
182 if [[ -n "$line" ]]; then
183 if [[ "$line" =~ \+(.*)@(.*)#egg=(.*) ]]; then
184 # Handle URLs
185 p=${BASH_REMATCH[1]}
186 ver=${BASH_REMATCH[2]}
187 elif [[ "$line" =~ (.*)[=\<\>]=(.*) ]]; then
188 # Normal pip packages
189 p=${BASH_REMATCH[1]}
190 ver=${BASH_REMATCH[2]}
191 else
192 # Unhandled format in freeze file
193 #echo "unknown: $p"
194 continue
195 fi
196 echo "pip|${p}|${ver}"
197 else
198 # No match in freeze file
199 #echo "unknown: $p"
200 continue
201 fi
202done
203
204rm $FREEZE_FILE
205
206# localrc
207# -------
208
209# Dump localrc with 'localrc|' prepended and comments and passwords left out
210if [[ -r $TOP_DIR/localrc ]]; then
211 sed -e '
212 /PASSWORD/d;
213 /^#/d;
214 s/^/localrc\|/;
215 ' $TOP_DIR/localrc | sort
216fi