forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-rpm.sh
executable file
·169 lines (138 loc) · 4.24 KB
/
test-rpm.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#!/bin/bash
# This script ensures RPM's build properly and can
# be installed as expected
set -o nounset
set -o pipefail
# Values that can be overridden
RPM_TEST_PRODUCT=${RPM_TEST_PRODUCT:-"origin"} # origin or atomic-openshift
RPM_TEST_OUTPUT_DIR=${RPM_TEST_OUTPUT_DIR:-"/tmp/tito/"} # Output for all build artifacts
RPM_TEST_SKIP_LINT=${RPM_TEST_SKIP_LINT:-""} # Set to anything to disable rpmlint test
# Values that should be left alone
REQUIRED_PACKAGES="rpmlint rpm-build tito" # Required packages to build and test
RPM_DIR=$RPM_TEST_OUTPUT_DIR/`arch` # Convenience. Path to the RPM output directory
SERVICE_PREFIX="origin" # Used as both RPM name and service script prefix
if [ $RPM_TEST_PRODUCT == "atomic-openshift" ]; then
SERVICE_PREFIX="atomic-openshift"
fi
# ===
# Testing helper functions
# Show info line
function info()
{
printf "\033[1;37mINFO\033[0m: $1\n"
}
# Show a test pass line
function pass()
{
printf "\033[0;32mPASS\033[0m: $1\n"
}
# Show an error line
function error()
{
printf "\033[0;33mError\033[0m: $1\n"
}
# Show a test fail line
function fail()
{
printf "\033[0;31mFAIL\033[0m: $1\n"
}
# Show a failure and exit if the expected return code isn't returned
function fail_out()
{
if [ $1 -ne 0 ]; then
fail "$2"
exit 1
fi
}
# Show an error and exit if the expected return code isn't returned
function error_out()
{
if [ $1 -ne 0 ]; then
error "$2"
exit 1
fi
}
# ====
# Root check
if [ `id -u` -eq 0 ]; then
error_out 1 'Do not run tests as root.'
fi
# Verifies the environment can produce rpms
function check_environment()
{
info "Checking environment for suitability"
# Check for required packages
for required_rpm in $REQUIRED_PACKAGES; do
rpm -q $required_rpm > /dev/null
error_out $? "$required_rpm is missing. $REQUIRED_PACKAGES must all be installed."
done
pass "Environment looks good. Tests can run."
}
# Cleans out the generated RPM directory
function clean_output_dir_of_rpms()
{
rm -rf $RPM_TEST_OUTPUT_DIR/`arch`
info "Cleaned output dir of rpms."
}
# Builds the RPMs for a product
function build_rpm()
{
mkdir -p $RPM_TEST_OUTPUT_DIR
clean_output_dir_of_rpms
info "Starting tito build."
dist=""
if [ $RPM_TEST_PRODUCT == "atomic-openshift" ]; then
dist="--dist=.el7aos"
fi
tito build --rpm --test --offline $dist -o "$RPM_TEST_OUTPUT_DIR"
if [ $? -ne 0 ]; then
fail "tito failed to build rpms"
exit 1
fi
pass "Build RPMS"
}
# Uses rpmlint to check for errors
function lint_rpms()
{
rpmlint -V
rpmlint -i $RPM_DIR/*rpm
if [ $? -eq 64 ]; then
fail "rpmlint reported errors. (Warnings ignored...)"
exit 1
fi
pass "Lint RPMS"
}
# Ensures the proper services are in the generated RPMs
function verify_expected_services()
{
rpm -qpl $RPM_DIR/$SERVICE_PREFIX-master*rpm | grep $SERVICE_PREFIX-master.service > /dev/null
fail_out $? "$SERVICE_PREFIX-master.service not in the $SERVICE_PREFIX-master rpm"
rpm -qpl $RPM_DIR/$SERVICE_PREFIX-node*rpm | grep $SERVICE_PREFIX-node.service > /dev/null
fail_out $? "$SERVICE_PREFIX-node.service not in the $SERVICE_PREFIX-node rpm"
pass "Verify Expected Services"
}
# Verifies that installation can happen
function test_install()
{
info "Verifying install cases..."
info "Testing install of all rpms"
rpm -ivh --test $RPM_DIR/*rpm
fail_out $? "Unable to install all packages together"
rpm_version=`rpm -qp --qf "%{VERSION}" $RPM_DIR/$SERVICE_PREFIX-master*.rpm`
info "Testing install of main and master"
rpm -ivh --test $RPM_DIR/$SERVICE_PREFIX-$rpm_version*.rpm $RPM_DIR/$SERVICE_PREFIX-master*.rpm
fail_out $? "Unable to install main and master"
info "Testing install of main, node and tuned"
rpm -ivh --test $RPM_DIR/$SERVICE_PREFIX-$rpm_version*.rpm $RPM_DIR/$SERVICE_PREFIX-node*.rpm $RPM_DIR/tuned-profiles-$SERVICE_PREFIX-node*rpm
fail_out $? "Unable to install main, node and tuned"
pass "Test Install"
}
# Run the build tests
check_environment
build_rpm
if [ -e $RPM_TEST_SKIP_LINT ]; then
lint_rpms
fi
test_install
verify_expected_services
exit 0