-
Notifications
You must be signed in to change notification settings - Fork 3
/
qpc-tests-pipeline.groovy
551 lines (452 loc) · 16.3 KB
/
qpc-tests-pipeline.groovy
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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
// {release} {install_type}
def qpc_version = getQPCVersion()
def image_name = "quipucords:${{qpc_version}}"
def tarfile = "quipucords.${{qpc_version}}.tar"
def targzfile = "${{tarfile}}.gz"
def install_tar = "quipucords.install.tar"
def install_targzfile = "${{install_tar}}.gz"
def getQPCVersion() {{
if ('{release}' == 'master') {{
return "1.0.0"
}} else {{
return "{release}"
}}
}}
/////////////////////////
//// Setup Functions ////
/////////////////////////
def setupDocker() {{
sh """\
echo "OPTIONS=--log-driver=journald" > docker.conf
echo "DOCKER_CERT_PATH=/etc/docker" >> docker.conf
echo "INSECURE_REGISTRY=\\"--insecure-registry \${{DOCKER_REGISTRY}}\\"" >> docker.conf
sudo cp docker.conf /etc/sysconfig/docker
""".stripIndent()
}}
/////////////////////////////////////
//// Configure & Start Functions ////
/////////////////////////////////////
def startQPCServer = {{
sh """\
echo 'startQPCServer'
pwd
ls -lah
sudo systemctl start docker # Ensure docker running
QPC_DB=\$(sudo docker ps | grep qpc-db || true)
QPC_CONTAINER=\$(sudo docker ps | grep ${{image_name}} || true)
# Stop containers if they are running before restarting or testing
if [ \"\$QPC_DB\" != '' ] || [ \"\$QPC_CONTAINER\" != '' ]
then
sudo docker rm \$(sudo docker stop \$(sudo docker ps -aq))
fi
# Start up docker contaienrs
sudo docker run --name qpc-db -e POSTGRES_PASSWORD=password -d postgres:9.6.10
sudo docker run -d -p '9443:443' --link qpc-db:qpc-link \\
-e QPC_DBMS_HOST=qpc-db \\
-e QPC_DBMS_PASSWORD=password \\
-v /tmp:/tmp \
-v /home/jenkins/.ssh:/home/jenkins/.ssh \\
-v \${{PWD}}/log:/var/log \\
-i ${{image_name}}
""".stripIndent()
sh '''\
for i in {{1..30}}; do
SERVER_ID="$(curl -ks https://localhost:9443/api/v1/status/ | grep server_id || true)"
if [ "${{SERVER_ID}}" ]; then
break
fi
if [ $i -eq 30 ]; then
echo "Server took too long to start"
exit 1
fi
sleep 1
done
'''.stripIndent()
}}
//////////////////////////////
//// Get Builds Functions ////
//////////////////////////////
def getQuipucords() {{
// get QPC
echo 'getQuipucords'
if ('{release}' == 'master') {{
getMasterQPC()
}} else {{
getReleasedQPC()
}}
}}
def getQuipucordsBuild() {{
// Grabs the quipucords build
sh 'ls -la'
echo "getQuipucords: Copying Latest build artifact..."
copyArtifacts filter: 'quipucords_server_image.tar.gz', fingerprintArtifacts: true,
projectName: 'quipucords-{release}-build-job', selector: lastCompleted()
copyArtifacts filter: 'quipucords_install.tar.gz', fingerprintArtifacts:
true, projectName: 'quipucords-installer-{release}-build-job', selector: lastCompleted()
copyArtifacts filter: 'postgres.*.tar.gz', fingerprintArtifacts: true, projectName: 'quipucords-{release}-build-job', selector: lastCompleted()
sh 'ls -la'
}}
def getMasterQPC() {{
// Grabs the master qpc builds and sets it up
echo 'getMasterQPC'
def qpc_version = getQPCVersion()
getQuipucordsBuild()
sh 'ls -lah'
echo 'Extract the installer script'
sh """\
echo ${{qpc_version}}
tar -xvzf quipucords_install.tar.gz
""".stripIndent()
echo 'Copy container to installer packages directory'
sh '''\
mkdir -p install/packages
'''.stripIndent()
}}
def getReleasedQPC() {{
echo 'Get released QPC'
// Clean up QPC package if here...
sh '''\
ls -l
if [ -f quipucords.*tar.gz ]; then
rm quipucords.*.tar.gz
fi
'''.stripIndent()
// Pulls down Released Container
echo "load docker container from tarball"
sh "curl -k -O -sSL https://github.com/quipucords/quipucords/releases/download/{release}/quipucords.{release}.tar.gz"
// Pulls down Released Install
sh "curl -k -O -sSL https://github.com/quipucords/quipucords/releases/download/{release}/quipucords.{release}.install.tar.gz"
echo "extract the installer into ${{WORKSPACE}}/install"
sh "tar -xvzf ${{WORKSPACE}}/quipucords.{release}.install.tar.gz"
}}
///////////////////////////
//// Install Functions ////
///////////////////////////
def installQPC(distro) {{
// Install QPC
if ('{install_type}' == 'nosupervisord') {{
installQPCNoSupervisorD()
}} else if ('{install_type}' == 'container') {{
containerInstall(distro)
}} else {{
defaultInstall()
}}
}}
def defaultInstall() {{
echo "Execute install.sh to install"
dir("${{WORKSPACE}}/install") {{
sh 'pwd'
sh 'ls -l'
sh 'sudo ./install.sh -e server_install_dir=${{WORKSPACE}}'
}}
}}
def installQPCNoSupervisorD() {{
echo "Execute install.sh to install without supervisord"
dir("${{WORKSPACE}}/install") {{
sh 'pwd'
sh 'ls -l'
sh 'sudo ./install.sh -e server_install_dir=${{WORKSPACE}} -e use_supervisord=false'
// Docker log to check for supervisord
sh 'sudo docker ps -a'
sh 'sudo docker logs quipucords | grep -i "Running without supervisord"'
}}
}}
def containerInstall(distro) {{
echo "Execute docker container install"
def qpc_version = getQPCVersion()
if (distro == 'rhel6') {{
echo 'No systemd, Docker should already be started.'
}} else {{
echo 'Starting Docker using Systemd'
sh 'sudo systemctl start docker'
sh 'sudo systemctl status docker'
}}
sh """\
sudo docker load -i quipucords_server_image.tar.gz
# make log dir to save server logs
mkdir -p log
""".stripIndent()
}}
def installQPCClient(distro) {{
// Install the qpc client
echo 'Install QPC Client'
// Pull Latest repo source from Copr
sh '''\
sudo wget -O /etc/yum.repos.d/group_quipucords-qpc-fedora-28.repo https://copr.fedorainfracloud.org/coprs/g/quipucords/qpc/repo/fedora-28/group_quipucords-qpc-fedora28.repo
ls -la /etc/yum.repos.d/
'''.stripIndent()
if ('{release}' == 'master') {{
installMasterQPCClient(distro)
}} else {{
installReleasedQPCClient()
}}
}}
def installMasterQPCClient(distro) {{
// Install latest qpc
if (distro ==~ /f\d\d/) {{
sh 'sudo dnf -y install qpc'
}} else {{
sh 'sudo yum -y install qpc'
}}
}}
def installReleasedQPCClient() {{
// Pulls down current released cli
dir("${{WORKSPACE}}/install") {{
sh '''\
CLI_VERSION=$(cat ./install.sh | grep CLI_PACKAGE_VERSION= | cut -d"=" -f3)
echo "${{CLI_VERSION: :-1}}"
wget -O qpc-client.rpm "https://github.com/quipucords/qpc/releases/download/0.0.46/qpc-${{CLI_VERSION: :-1}}.fc28.noarch.rpm"
ls -la
# Install the rpm
if grep -q -i "Fedora" /etc/redhat-release; then
sudo dnf install -y qpc-client.rpm
else
sudo yum install -y qpc-client.rpm
fi
'''.stripIndent()
}}
}}
////////////////////
//// Test Setup ////
////////////////////
def setupScanUsers() {{
dir('ci') {{
git 'https://github.com/quipucords/ci.git'
}}
sshagent(['390bdc1f-73c6-457e-81de-9e794478e0e']) {{
withCredentials([file(credentialsId: '50dc19ce-555f-422c-af38-3b5ede422bb4', variable: 'ID_JENKINS_RSA_PUB')]) {{
sh 'sudo dnf -y install ansible'
sh '''\
cat > jenkins-slave-hosts <<EOF
[jenkins-slave]
${{OPENSTACK_PUBLIC_IP}}
[jenkins-slave:vars]
ansible_user=jenkins
ansible_ssh_extra_args=-o StrictHostKeyChecking=no
ssh_public_key_file=$(cat ${{ID_JENKINS_RSA_PUB}})
EOF
'''.stripIndent()
sh 'ansible-playbook -b -i jenkins-slave-hosts ci/ansible/sonar-setup-scan-users.yaml'
}}
}}
}}
def setupCamayoc() {{
dir('camayoc') {{
git 'https://github.com/quipucords/camayoc.git'
}}
sh '''\
sudo pip install ./camayoc[dev]
cp camayoc/pytest.ini .
'''.stripIndent()
withCredentials([file(credentialsId: '4c692211-c5e1-4354-8e1b-b9d0276c29d9', variable: 'ID_JENKINS_RSA')]) {{
sh '''\
mkdir -p /home/jenkins/.ssh
cp "${{ID_JENKINS_RSA}}" /home/jenkins/.ssh/id_rsa
chmod 0600 /home/jenkins/.ssh/id_rsa
'''.stripIndent()
}}
configFileProvider([configFile(fileId: '62cf0ccc-220e-4177-9eab-f39701bff8d7', targetLocation: 'camayoc/config.yaml')]) {{
sh '''\
sed -i "s/{{jenkins_slave_ip}}/${{OPENSTACK_PUBLIC_IP}}/" camayoc/config.yaml
'''.stripIndent()
}}
}}
////////////////////////
//// Test Functions ////
////////////////////////
def runInstallTests(distro) {{
if (distro ==~ /f\d\d/) {{
sh 'sudo dnf -y install python-pip'
}} else {{
sh 'sudo yum -y install python-pip'
}}
if (distro == 'rhel6') {{
sh 'sudo pip install pexpect nose'
sh '''\
set +e
nosetests --with-xunit --xunit-file=junit.xml ci/scripts/quipucords/master/install/test_install.py
set -e
'''.stripIndent()
}} else {{
sh 'sudo pip install -U pip'
sh 'sudo pip install pexpect pytest'
sh """\
set +e
pytest --junit-prefix ${{distro}} --junit-xml junit.xml ci/scripts/quipucords/master/install/test_install.py
set -e
""".stripIndent()
}}
junit "junit.xml"
}}
def runCamayocTest(testset) {{
echo "Running ${{testset}} Tests"
sh 'cat camayoc/config.yaml'
sh 'ls -lah'
sshagent(['390bdc1f-73c6-457e-81de-9e794478e0e']) {{
sh """
export XDG_CONFIG_HOME=\$(pwd)
set +e
py.test -c pytest.ini -l -ra -s -vvv --junit-xml $testset-junit.xml --rootdir camayoc/camayoc/tests/qpc camayoc/camayoc/tests/qpc/$testset
set -e
sudo docker rm \$(sudo docker stop \$(sudo docker ps -aq))
tar -cvzf test-$testset-logs.tar.gz log
sudo rm -rf log
""".stripIndent()
}}
echo 'Archiving artifacts'
archiveArtifacts "test-$testset-logs.tar.gz"
junit "$testset-junit.xml"
}}
def runCamayocUITest(browser) {{
echo "Running ${{browser}} Tests"
sh 'cat camayoc/config.yaml'
sh 'ls -lah'
sshagent(['390bdc1f-73c6-457e-81de-9e794478e0e']) {{
sh "sudo docker run --net='host' -d -p 4444:4444 -v /dev/shm:/dev/shm:z -v /tmp:/tmp:z selenium/standalone-$browser"
sleep 3
sh """\
export XDG_CONFIG_HOME=\$PWD
export SELENIUM_DRIVER=$browser
set +e
py.test -c pytest.ini -l -ra -vvv --junit-prefix $browser --junit-xml ui-$browser-junit.xml --rootdir camayoc/camayoc/tests/qpc camayoc/camayoc/tests/qpc/ui
set -e
sudo docker rm \$(sudo docker stop \$(sudo docker ps -aq))
tar -cvzf test-ui-$browser-logs.tar.gz log
sudo rm -rf log
""".stripIndent()
}}
echo 'Archiving artifacts'
archiveArtifacts "test-ui-$browser-logs.tar.gz"
junit "ui-$browser-junit.xml"
}}
////////////////////////
//// Pipeline Stage ////
////////////////////////
stage('Run Tests') {{
parallel 'CentOS 7 Install': {{
node('centos7-os') {{
stage('Centos7 Install') {{
dir('ci') {{
git 'https://github.com/quipucords/ci.git'
}}
sshagent(['390bdc1f-73c6-457e-81de-9e794478e0e']) {{
withCredentials([file(credentialsId:
'4c692211-c5e1-4354-8e1b-b9d0276c29d9', variable: 'ID_JENKINS_RSA')]) {{
withEnv(['DISTRO=centos7', 'RELEASE={release}']) {{
sh """\
echo 'Testing qpc_version variable'
echo ${{qpc_version}}
""".stripIndent()
echo "Testing inline qpc_version variable: ${{qpc_version}}"
getQuipucords()
installQPC 'centos7'
}}
}}
}}
}}
}}
}},
'Fedora 28': {{
node('f28-os') {{
stage('Fedora 28 Install') {{
dir('ci') {{
git 'https://github.com/quipucords/ci.git'
}}
sshagent(['390bdc1f-73c6-457e-81de-9e794478e0e']) {{
withCredentials([file(credentialsId:
'4c692211-c5e1-4354-8e1b-b9d0276c29d9', variable: 'ID_JENKINS_RSA')]) {{
withEnv(['DISTRO=f28', 'RELEASE={release}']) {{
echo 'Fedora 28: Configure Docker'
setupDocker()
getQuipucords()
installQPC 'f28'
}}
}}
}}
}}
stage('F28: Setup Integration Tests') {{
echo 'Fedora 28: Install QPC Client'
installQPCClient 'f28'
echo 'Fedora 28: Setup Scan Users'
setupScanUsers()
echo 'Fedora 28: Setup Camayoc'
setupCamayoc()
}}
stage('F28: test api') {{
echo 'Fedora 28: Test API'
startQPCServer()
runCamayocTest 'api'
}}
stage('F28: Test CLI') {{
echo 'Fedora 28: Test CLI'
startQPCServer()
runCamayocTest 'cli'
}}
stage('F28: Test UI Chrome') {{
echo 'Fedora 28: Test UI Chrome'
startQPCServer()
runCamayocUITest 'chrome'
}}
stage('F28: Test UI Firefox') {{
echo 'Fedora 28: Test UI Firefox'
startQPCServer()
runCamayocUITest 'firefox'
}}
stage('F28: Install Tests') {{
runInstallTests 'f28'
}}
}}
}},
'RHEL6 Install': {{
node('rhel6-os') {{
stage('rhel6 Install') {{
dir('ci') {{
git 'https://github.com/quipucords/ci.git'
}}
configFileProvider([configFile(fileId:
'5b276700-674e-4a0f-af91-3e725ed7a311', targetLocation: 'rhel6-custom.repo')]) {{
sshagent(['390bdc1f-73c6-457e-81de-9e794478e0e']) {{
withCredentials([file(credentialsId:
'4c692211-c5e1-4354-8e1b-b9d0276c29d9', variable: 'ID_JENKINS_RSA')]) {{
withEnv(['DISTRO=rhel6', 'RELEASE={release}']) {{
setupDocker()
sh '''\
sudo cp ${{WORKSPACE}}/rhel6-custom.repo /etc/yum.repos.d/rhel6-rcm-internal.repo
sudo yum clean all
sudo yum-config-manager --disable base
sudo yum-config-manager --disable optional
'''.stripIndent()
getQuipucords()
installQPC 'rhel6'
}}
}}
}}
}}
}}
}}
}}, 'RHEL7 Install': {{
node('rhel7-os') {{
stage('rhel7 Install') {{ dir('ci') {{
git 'https://github.com/quipucords/ci.git'
}}
configFileProvider([configFile(fileId:
'0f157b1a-7068-4c75-a672-3b1b90f97ddd', targetLocation: 'rhel7-custom.repo')]) {{
sshagent(['390bdc1f-73c6-457e-81de-9e794478e0e']) {{
withCredentials([file(credentialsId:
'4c692211-c5e1-4354-8e1b-b9d0276c29d9', variable: 'ID_JENKINS_RSA')]) {{
withEnv(['DISTRO=rhel7', 'RELEASE={release}']) {{
echo 'Install Docker?'
// TODO: Better solution
sh 'sudo yum install docker -y'
setupDocker()
sh 'sudo cp rhel7-custom.repo /etc/yum.repos.d/rhel7-rcm-internal.repo'
getQuipucords()
installQPC 'rhel7'
}}
}}
}}
}}
}}
}}
}}
}}