-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathjenkins-cs-djeep-bare-metal
executable file
·152 lines (132 loc) · 4.77 KB
/
jenkins-cs-djeep-bare-metal
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
#!/bin/bash
set -e
set -x
# Setup host variables
SSH_OPTS='-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no'
DJEEP_HOST=${DJEEP_HOST:-10.127.52.107}
CONTROLLER_HOST=${CONTROLLER_HOST:-10.127.52.108}
CONTROLLER_DRAC=${CONTROLLER_DRAC:-10.127.55.108}
COMPUTE01_HOST=${COMPUTE01_HOST:-10.127.52.109}
COMPUTE01_DRAC=${COMPUTE01_DRAC:-10.127.55.109}
#COMPUTE02_HOST=${COMPUTE02_HOST:-10.127.52.110}
#COMPUTE02_DRAC=${COMPUTE02_DRAC:-10.127.55.110}
DRACUSER=${DRACUSER:-root}
DRACPASS=${DRACPASS:-calvincalvin}
function ipmi_restart() {
set +x
# $1 - IP
ip=$1
echo "Running ipmi_restart using:"
echo " ip: ${ip}"
# First check the status
# This will return "Chassis Power is off|on"
status=$(ssh ${SSH_OPTS} root@${DJEEP_HOST} "ipmitool -I lanplus -H ${ip} -U ${DRACUSER} -P ${DRACPASS} chassis power status | cut -d ' ' -f4")
if [ $status == "on" ]; then
# Power is on, we can powercycle
# Gonna wilk it up here
for i in $(seq 1 4); do
ssh ${SSH_OPTS} root@${DJEEP_HOST} "ipmitool -I lanplus -H ${ip} -U ${DRACUSER} -P ${DRACPASS} chassis power off"
done
for i in $(seq 1 4); do
ssh ${SSH_OPTS} root@${DJEEP_HOST} "ipmitool -I lanplus -H ${ip} -U ${DRACUSER} -P ${DRACPASS} chassis power on"
done
else
# Power is off, we can poweron
# Gonna wilk it up here
for i in $(seq 1 4); do
ssh ${SSH_OPTS} root@${DJEEP_HOST} "ipmitool -I lanplus -H ${ip} -U ${DRACUSER} -P ${DRACPASS} chassis power on"
done
fi
# we need to sleep for 5 seconds and make sure the box came back online
sleep 15s
status=$(ssh ${SSH_OPTS} root@${DJEEP_HOST} "ipmitool -I lanplus -H ${ip} -U ${DRACUSER} -P ${DRACPASS} chassis power status | cut -d ' ' -f4")
if [ $status == "off" ]; then
# Server did not come back online
sleep "Unable to powercycle server successfully"
exit 1
fi
set -x
}
function wait_for_ssh() {
# $1 - IP
ip=$1
echo "Running ping_and_ssh using:"
echo " ip: ${ip}"
count=1
while [ $count -lt 25 ]; do
count=$(( count + 1 ))
sleep 60s
if ( nc ${ip} 22 -w 1 -q 0 < /dev/null ); then
sleep 60s
break
fi
if [ $count -eq 25 ]; then
echo "Server is not responding to ping"
exit 1
fi
done
}
# clean up chef nodes
knife node delete -y os-controller.rcbops.me || :
knife node delete -y os-compute01.rcbops.me || :
knife node delete -y os-compute02.rcbops.me || :
# clean up chef clients
knife client delete -y os-controller.rcbops.me || :
knife client delete -y os-compute01.rcbops.me || :
knife client delete -y os-compute02.rcbops.me || :
# clean up chef environment
knife environment delete -y essex_baremetal_multinode || :
# Copy over bootstrap files
scp ${SSH_OPTS} ~/jenkins-build/files/djeep-bootstrap.sh root@${DJEEP_HOST}:~
scp ${SSH_OPTS} ~/jenkins-build/files/djeep-jenkins.yaml root@${DJEEP_HOST}:~
ssh ${SSH_OPTS} root@${DJEEP_HOST} "chmod 755 djeep-bootstrap.sh"
# Rebuild djeep
if ! ( ssh ${SSH_OPTS} root@${DJEEP_HOST} "./djeep-bootstrap.sh" ); then
echo "DJEEP Bootstrap did not complete successfully"
exit 1
fi
# Kick the Controller
ipmi_restart ${CONTROLLER_DRAC}
wait_for_ssh ${CONTROLLER_HOST}
if ! ( knife node list | grep "os-controller.rcbops.me" ); then
echo "Node: os-controller.rcbops.me, not found in knife node list"
exit 1
fi
# Push the roles for the controller
knife node run_list add os-controller.rcbops.me role[single-controller]
knife node run_list add os-controller.rcbops.me recipe[exerstack]
knife node run_list add os-controller.rcbops.me recipe[kong]
#if ! ( ssh root@${CONTROLLER_HOST} 'chef-client' ); then
# echo "Chef-client run failed"
# exit 1
#fi
if ! ( knife node show os-controller.rcbops.me ); then
echo "Node show failed for os-controller.rcbops.me"
exit 1
fi
## Kick the Controller
#ipmi_restart ${COMPUTE01_DRAC}
#wait_for_ssh ${COMPUTE01_HOST}
#if ! ( knife node list | grep "os-compute01.rcbops.me" ); then
# echo "Node: os-compute01.rcbops.me, not found in knife node list"
# exit 1
#fi
## Push the roles for the compute node
#knife node run_list add os-compute01.rcbops.me role[single-compute]
#if ! ( ssh root@${COMPUTE01_HOST} 'chef-client' ); then
# echo "Chef-client run failed"
# exit 1
#fi
## Kick the Controller
#ipmi_restart ${COMPUTE02_DRAC}
#wait_for_ssh ${COMPUTE02_HOST}
#if ! ( knife node list | grep "os-compute02.rcbops.me" ); then
# echo "Node: os-compute02.rcbops.me, not found in knife node list"
# exit 1
#fi
## Push the roles for the compute node
#knife node run_list add os-compute02.rcbops.me role[single-compute]
#if ! ( ssh root@${COMPUTE02_HOST} 'chef-client' ); then
# echo "Chef-client run failed"
# exit 1
#fi