Re: [Avocado-devel] document for jenkins

2018-02-09 Thread Lukáš Doktor
Dne 8.2.2018 v 20:08 Yesuraj Abraham napsal(a):
> Hi,
> 
> Is there a documentation which describes how to integrate Jenkins so that I
> should be able to do
> 
> 1.   Triggering the test from Jenkins
> 
> 2.   View all the results in Jenkins
> 
> 
> 
> For example, there are 3 machines that I would use
> 
> 1.   Remote DUT (where the test runs)
> 
> 2.   Linux host machine- which triggers the test using
> --remote-hostname option.
> 
> 3.   A Jenkins server where Jenkins is installed
> 
> 
> 
> I access the Jenkins via web interface, add Linux host machine as a node
> and I can run the test. However I don’t know how to populate all the
> results in Jenkins web interface
> 

Hello Yasuraj,

we meant to write a simple howto: 
https://trello.com/c/9zTcfa0v/904-add-avocado-based-solution-for-jenkins-solutions-for-python
 but had no time to actually do it yet. If you are a blog-person, it'd be nice 
if you could take notes and create a guide :-)

As for me I'm using Avocado and Avocado-vt via `jenkins-job-builder` using 
following templates:

Parameter:

```yaml
- parameter:
name: avocado-run
parameters:
- node:
name: NODE
default-slaves:
- "{machine}"
allowed-multiselect: false
ignore-offline-nodes: false
description: "Use node you reserved in beaker!"
- string:
name: TESTS
default: "{tests}"
description: "List of space-separated tests"
- string:
name: EXTRA_PARAMS
default: "{extra-params}"
description: "Custom avocado params (eg. --vt-qemu-bin)"
- string:
name: GUEST_OS
default: "{guest-os}"
description: "Avocado-vt guest os"
```

Builder:

```yaml
- builder:
name: avocado-run
builders:
- shell: |
#!/bin/bash
rpm -q qemu-kvm-rhev || rpm -q qemu-kvm || rpm -q kvm
echo -n "kernel-"
uname -r
- shell: |
#!/bin/bash -x
unset AUTOTEST_PATH
avocado run $EXTRA_PARAMS --xunit "$WORKSPACE/results.xml" 
--job-results-dir "$WORKSPACE" --vt-guest-os "$GUEST_OS" --vt-arch 
"{guest-arch}" --vt-machine-type "{vt-machine}" -- $TESTS
ERR=$?
[ -f "$WORKSPACE/results.xml" ] || {{ echo "Result file not found, 
avocado exited with $ERR" ; exit -1; }}
```

Publisher:

```yaml
- publisher:
name: avocado-run
publishers:
- archive:
artifacts: latest/**/*
latest-only: false
allow-empty: true
- junit:
results: results.xml
- email-ext:
recipients: "{mailto}"
content-type: text
body: |
${{PROJECT_NAME}} - Build #${{BUILD_NUMBER}} - ${{BUILD_STATUS}}

Results: ${{BUILD_URL}}testReport/(root)/

$BUILD_LOG
attach-build-log: false
failure: false
fixed: true
improvement: true
regression: true
```


But currently I'm slowly moving to pipeline, but the workflow is quite similar 
(only with pipeline I can merge the results from multiple jobs/machines and 
postprocess them before publishing).

For triggers I'm using daily, weekly and triggered by external events via 
`curl`. In jjb it's quite simple to chain multiple jobs so my usual workflow is 
"provision_machine(s)->compile_qemu->trigger_several_jobs" plus I have some 
other jobs to recover in case of failure (eg. to try previous nightly build to 
get at least some coverage). One snippet to reboot machine after provisioning 
before running tests:

```
- job-template:
name: "{name}-arm64-provision"
builders:
- shell: |
# Update
yum update -y
# Update Avocado
curl https://x.y.z/avocado-setup-internal.sh | sh -x
# Make sure the node enables itself after reboot
if [ ! -e "/usr/local/jenkins-enable-node.sh" ]; then
# Add content of scripts/jenkins-enable-node.sh
cat > /usr/local/bin/jenkins-enable-node.sh << \EOF
#!/bin/bash
curl -k 
https://$USER:$to...@jenkins.example.org/computer/$(hostname)/api/json | grep 
-q '"temporarilyOffline":true' && curl -k 
https://$USER:$to...@jenkins.example.org/computer/$(hostname)/toggleOffline 
--request 'POST'
curl -k 
https://$USER:$to...@jenkins.example.org/computer/$(hostname)/launchSlaveAgent 
--request 'POST'
EOF
chmod +x /usr/local/bin/jenkins-enable-node.sh
fi
grep -q "jenkins-enable-node.sh" /etc/crontab || echo "@reboot root 
/usr/local/bin/jenkins-enable-node.sh" >> /etc/crontab

# Mark the node offline and reboot
curl -k 
https://$USER:$to...@jenkins.example.org/computer/$(hostname)/toggleOffline 
--request 'POST' --data 

Re: [Avocado-devel] document for jenkins

2018-02-09 Thread Dmitry Monakhov
Yesuraj Abraham  writes:

> Hi,
>
> Is there a documentation which describes how to integrate Jenkins so that I
> should be able to do
Functionality is present and works (see below), but there is no guide
which explain this particular case(important one IMHO) feel free to add
bug for documentation, or even more, you can send a patch which fix it.
>
> 1.   Triggering the test from Jenkins
>
> 2.   View all the results in Jenkins
>
>
>
> For example, there are 3 machines that I would use
>
> 1.   Remote DUT (where the test runs)
>
> 2.   Linux host machine- which triggers the test using
> --remote-hostname option.
>
> 3.   A Jenkins server where Jenkins is installed
>
>
>
> I access the Jenkins via web interface, add Linux host machine as a node
> and I can run the test. However I don’t know how to populate all the
> results in Jenkins web interface
avocado  produces result.xml in xUnit format. Jenkins has rich toolchain
for importing  jUnit/xUnit from external tests. All you need is to add
corresponding hook to your pipeline. In case of junit plugin it will be:
junit '~/avocado/job-results/**'

Hereis a good article about external test integration
https://jenkins.io/blog/2016/10/31/xunit-reporting/