-
Notifications
You must be signed in to change notification settings - Fork 11
/
utils.sh
210 lines (168 loc) · 6.01 KB
/
utils.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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
container_name="packstack"
namespace_name=konveyor-forklift
# create logical volume
function lv_create {
size=$1
loopdev=$(losetup -f)
dd if=/dev/zero of=/tmp/cinder-volumes bs=1 count=0 seek=${size}G
losetup ${loopdev} /tmp/cinder-volumes
pvcreate ${loopdev}
vgcreate cinder-volumes ${loopdev}
lvcreate -T -L 2g cinder-volumes/cinder-volumes-pool
}
# cleanup logical volume
function lv_remove {
lvremove cinder-volumes/cinder-volumes-pool -y
for pv in $(pvdisplay -qC | grep dev | awk -e '{print $1}') ; do pvremove $pv --force --force -y ; done
pvremove cinder-volumes -y
vgremove cinder-volumes -y
rm -rf /dev/cinder-volumes
rm -rf /tmp/cinder-volumes
}
function get_osp_services {
systemctl | grep -P "neutr|openstack|mariadb|glance|rabbit|libv|httpd" | awk '{print $1}'
}
function healthcheck {
echo "systemctl state is $(systemctl is-system-running)"
for svc in `get_osp_services`; do
echo " $(systemctl status $svc | head -n 3)"
echo " $(systemctl status $svc | grep Memory)"
done
}
function source_keystonerc {
docker cp ${container_name}:/root/keystonerc_admin keystonerc_admin
source keystonerc_admin
rm -rf keystonerc_admin
}
function openstack_wrapper {
command=$@
cat<<EOF >/tmp/test.cmd
#!/bin/bash
source /root/keystonerc_admin
openstack ${command}
EOF
docker cp /tmp/test.cmd ${container_name}:/test.sh
docker exec -i ${container_name} bash /test.sh
}
function echo_pod_name {
pod_name=$(kubectl get pods -o=name -n ${namespace_name} | grep $container_name | cut -d/ -f2)
echo $pod_name
}
function openstack_pod {
command=$@
cat<<EOF >/tmp/test.cmd
#!/bin/bash
source /root/keystonerc_admin
openstack ${command}
EOF
kubectl cp /tmp/test.cmd ${namespace_name}/$(echo_pod_name):/test.sh
kubectl exec -n ${namespace_name} -i deploy/${container_name} -- bash /test.sh
}
function get_keystonerc {
localpath=$1
kubectl cp ${namespace_name}/$(echo_pod_name):/root/keystonerc_admin ${localpath}
}
function run_command_deployment {
command=$@
kubectl cp cluster/providers/openstack/utils.sh ${namespace_name}/$(echo_pod_name):/utils.sh
kubectl exec -n ${namespace_name} -i deploy/packstack -- bash<<EOF
source /utils.sh
$command
EOF
}
function run_command {
command=$@
docker cp cluster/providers/openstack/utils.sh ${container_name}:/utils.sh
docker exec -i ${container_name} bash<<EOF
source /utils.sh
$command
EOF
}
function openstack_container {
command=$@
openstack_wrapper "$command"
}
function packstack_create_cirros {
source /root/keystonerc_admin
nova-manage cell_v2 discover_hosts
sleep 2
wget https://download.cirros-cloud.net/0.6.1/cirros-0.6.1-x86_64-disk.img -O /tmp/cirros-0.6.1.img
openstack network create net-int
openstack subnet create sub-int --network net-int --subnet-range 192.0.2.0/24
openstack image create "cirros" --disk-format qcow2 \
--container-format bare --public \
--file /tmp/cirros-0.6.1.img
sleep 10
openstack server create --image cirros --flavor m1.tiny --wait cirros --network net-int
}
function packstack_create_cirros_volume {
source /root/keystonerc_admin
nova-manage cell_v2 discover_hosts
# create cinder empty volume
openstack volume create --size 1 empty_volume
# create cinder volume from image
openstack volume create --image cirros --size 1 cirros-volume
# wait for the volume to be created
sleep 10
# boot VM instance from volume
openstack server create --flavor m1.tiny --volume cirros-volume cirros-volume
sleep 15
openstack volume list
openstack server list
}
function fix_nova_mount {
mkdir -p /var/lib/cinder/mnt/
ln -s /var/lib/cinder/mnt/ /var/lib/nova/mnt
}
function packstack_update_endpoints {
source /root/keystonerc_admin
openstack endpoint list --interface public -c ID -c URL -f value | grep 127.0.0.1 >/tmp/output
new_host="packstack.${namespace_name}"
while IFS=" " read -r id url; do
openstack endpoint set --url ${url/127.0.0.1/"$new_host"} $id
done < /tmp/output
}
function packstack_test_snapshot_creation {
source /root/keystonerc_admin
# create snapshot from cirros-volume
snaphot_id=$(openstack volume snapshot create cirros-volume --force -c id -f value 2>&1)
[ $? -ne 0 ] && { echo "error creating snapshot: ${snaphot_id}" ; return 2; }
sleep 2
snapshot_status=$(openstack volume snapshot show ${snaphot_id} -c status -f value)
[ "${snapshot_status}" != "available" ] && \
{ echo "snapshot ${snapshot_id} status ${snapshot_status}"; return 2;}
}
# retry connecting to port until its reachable
function retry_port_reachable {
local port=$1
curl --connect-timeout 5 \
--max-time 10 \
--retry 5 \
--retry-delay 0 \
--retry-connrefused \
--retry-max-time 30 http://localhost:${port}
}
function set_cinder_ip {
local ext_ip=$1
sed -ie "s/127.0.0.1/${ext_ip}/" /etc/cinder/nfs_shares.conf
systemctl restart openstack-cinder-volume.service
}
# patch packstack to allow NFS volume snapshots creation
function packstack_patch_snapshots_support {
[ -f "/etc/cinder/cinder.conf.orig" ] && return
cat /etc/cinder/cinder.conf | grep -v '#' | grep -v -e "^$" >/etc/cinder/cinder.conf.new
sed -ie "s/\[backend_defaults\]//" /etc/cinder/cinder.conf.new
cat <<__EOF__ >>/etc/cinder/cinder.conf.new
[backend_defaults]
nfs_snapshot_support = true
nas_secure_file_operations = false
nas_secure_file_permissions = false
__EOF__
mv /etc/cinder/cinder.conf /etc/cinder/cinder.conf.orig
mv /etc/cinder/cinder.conf.new /etc/cinder/cinder.conf
# workaround for https://bugzilla.redhat.com/show_bug.cgi?id=1936281
# until we find better solution
sed -ie "s/context.project_domain_id/'default'/" /usr/lib/python3.6/site-packages/cinder/compute/nova.py
systemctl restart openstack-cinder-api.service openstack-cinder-volume.service openstack-cinder-scheduler.service
retry_port_reachable "8776"
}