Skip to content

Commit dc68f5f

Browse files
author
David Galloway
committed
Add ceph-cm-ansible-prs job
Signed-off-by: David Galloway <[email protected]>
1 parent 248aebb commit dc68f5f

File tree

4 files changed

+348
-0
lines changed

4 files changed

+348
-0
lines changed

ansible/examples/slave_teuthology.yml

+145
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
---
2+
# This playbook should only be run against a teuthology host or a machine inside the Sepia test lab that can lock testnodes.
3+
# See ceph-cm-ansible/README.rst
4+
5+
- hosts: all
6+
become: true
7+
user: cm
8+
vars:
9+
- jenkins_user: 'jenkins-build'
10+
# jenkins API credentials:
11+
- api_user: 'ceph-jenkins'
12+
- token: '{{ token }}'
13+
- api_uri: 'https://jenkins.ceph.com'
14+
- jenkins_credentials_uuid: '39fa150b-b2a1-416e-b334-29a9a2c0b32d'
15+
- nodename: 'teuthology'
16+
- labels: 'teuthology'
17+
18+
tasks:
19+
- name: "create a {{ jenkins_user }} user"
20+
user:
21+
name: "{{ jenkins_user }}"
22+
append: yes
23+
comment: "Jenkins Build Slave User"
24+
25+
- name: "create a {{ jenkins_user }} home directory"
26+
file:
27+
path: "/home/{{ jenkins_user }}/"
28+
state: directory
29+
owner: "{{ jenkins_user }}"
30+
31+
- name: Create .ssh directory
32+
file:
33+
path: "/home/{{ jenkins_user }}/.ssh"
34+
state: directory
35+
owner: "{{ jenkins_user }}"
36+
37+
- name: set the authorized keys
38+
authorized_key:
39+
user: "{{ jenkins_user }}"
40+
key: "{{ lookup('file', 'files/ssh/keys/jenkins_build.pub') }}"
41+
42+
- name: Write ~/.ssh/config
43+
blockinfile:
44+
path: "/home/{{ jenkins_user }}/.ssh/config"
45+
create: yes
46+
block: |
47+
Host *
48+
StrictHostKeyChecking no
49+
UserKnownHostsFile=/dev/null
50+
51+
- name: set utf-8 for LC_ALL
52+
lineinfile:
53+
dest: "/home/{{ jenkins_user }}/.bashrc"
54+
regexp: '^export LC_ALL='
55+
line: "export LC_ALL=en_US.UTF-8"
56+
create: true
57+
state: present
58+
59+
- name: set utf-8 for LANG
60+
lineinfile:
61+
dest: "/home/{{ jenkins_user }}/.bashrc"
62+
regexp: '^export LANG='
63+
line: "export LANG=en_US.UTF-8"
64+
65+
- name: set utf-8 for LANGUAGE
66+
lineinfile:
67+
dest: "/home/{{ jenkins_user }}/.bashrc"
68+
regexp: '^export LANGUAGE='
69+
line: "export LANGUAGE=en_US.UTF-8"
70+
71+
- name: ensure the build dir exists
72+
file:
73+
path: "/home/{{ jenkins_user }}/build"
74+
state: directory
75+
owner: "{{ jenkins_user }}"
76+
77+
- name: ensure the home dir has the right owner permissions
78+
file:
79+
path: "/home/{{ jenkins_user }}"
80+
state: directory
81+
owner: "{{ jenkins_user }}"
82+
group: "{{ jenkins_user }}"
83+
recurse: yes
84+
85+
- name: ensure the gitconfig file exists
86+
shell: printf "[user]\name=Ceph CI\[email protected]\n" > /home/{{ jenkins_user }}/.gitconfig
87+
88+
- name: ensure the gitconfig file has right permissions
89+
file:
90+
path: "/home/{{ jenkins_user }}/.gitconfig"
91+
owner: "{{ jenkins_user }}"
92+
93+
- name: install six, latest one
94+
pip:
95+
name: six
96+
state: latest
97+
98+
- name: install python-jenkins
99+
# https://review.openstack.org/460363
100+
pip:
101+
name: python-jenkins
102+
version: 0.4.15
103+
104+
- name: add github.com host key
105+
known_hosts:
106+
path: '/etc/ssh/ssh_known_hosts'
107+
# we need to use 'host' here because prado currently uses ansible-playbook==1.9.1
108+
host: 'github.com'
109+
# github.com.pub is the output of `ssh-keyscan github.com`
110+
key: "{{ lookup('file', 'files/ssh/hostkeys/github.com.pub') }}"
111+
112+
- name: register the new slave to jenkins master with jnlp
113+
jenkins_node:
114+
username: "{{ api_user }}"
115+
uri: "{{ api_uri }}"
116+
password: "{{ token }}"
117+
# relies on a convention to set a unique name that allows a reverse
118+
# mapping from Jenkins back to whatever service created the current
119+
# node
120+
name: "{{ ansible_default_ipv4.address }}+{{ nodename }}"
121+
labels: "{{ labels }}"
122+
host: "{{ ansible_default_ipv4.address }}"
123+
credentialsId: "{{ jenkins_credentials_uuid }}"
124+
launcher: 'hudson.slaves.JNLPLauncher'
125+
remoteFS: '/home/{{ jenkins_user }}/build'
126+
# XXX this should be configurable, not all nodes should have one executor
127+
executors: '{{ executors|default(1) }}'
128+
exclusive: true
129+
130+
- name: Download slave.jar
131+
get_url:
132+
url: "{{ api_uri }}/jnlpJars/slave.jar"
133+
dest: "/home/{{ jenkins_user }}/slave.jar"
134+
force: yes
135+
136+
- name: install the systemd unit file for jenkins
137+
template:
138+
src: "templates/systemd/jenkins.service.j2"
139+
dest: "/etc/systemd/system/jenkins.service"
140+
141+
- name: start jenkins service
142+
service:
143+
name: jenkins
144+
state: started
145+
enabled: yes

ceph-cm-ansible-prs/README.rst

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
ceph-cm-ansible-prs
2+
===================
3+
4+
This job tests changes to the ceph-cm-ansible_ repo. It locks one testnode per machine type **and** distro and runs the ``ansible_managed`` and ``testnodes`` playbooks.
5+
6+
Prerequisites
7+
-------------
8+
9+
These steps should only have to be performed when a new teuthology host is being set up but it's good to have documented.
10+
11+
#. Run the ``ansible/examples/slave_teuthology.yml`` playbook against the teuthology host.
12+
13+
#. As the ``jenkins-build`` user on the teuthology host, generate a new RSA SSH key (``ssh-keygen -t rsa``).
14+
15+
#. Copy the public key to jenkins-build.pub_ in the keys repo. (This is so the jenkins-build user can ssh to testnodes and VPSHOSTs)
16+
17+
#. Copy/create ``/home/jenkins-build/.config/libvirt/libvirt.conf`` so the jenkins-build user can downburst VPSes.
18+
19+
#. Run the ceph-cm-ansible_ ``users`` playbook against VPSHOSTs so the jenkins-build pubkey is added to the ubuntu user's authorized_keys on the VPSHOSTs.
20+
21+
**NOTE:** This job also relies on:
22+
23+
- teuthology.yaml_ -- If the job is being run on the teuthology host, this should already be in place at ``/etc/teuthology.yaml``.
24+
- ceph-sepia-secrets_ -- If the job is being run on a teuthology host, ``/etc/ansible`` should already be symlinked to a ceph-sepia-secrets checkout.
25+
26+
.. _ceph-cm-ansible: https://github.com/ceph/ceph-cm-ansible
27+
.. _jenkins-build.pub: https://github.com/ceph/keys/blob/master/ssh/jenkins-build.pub
28+
.. _teuthology.yaml: http://docs.ceph.com/teuthology/docs/siteconfig.html
29+
.. _ceph-sepia-secrets: https://github.com/ceph/ceph-sepia-secrets/

ceph-cm-ansible-prs/build/build

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#!/bin/bash
2+
# NOTE: Commented code was my attempt at creating this as a matrix job.
3+
# I couldn't get the child jobs to share the same checkout/venv of teuthology
4+
# so I left the code in place in case I (or somebody else) wants to take a
5+
# crack at it in the future.
6+
7+
set -ex
8+
9+
# Clone or update teuthology
10+
if [ ! -d teuthology ]; then
11+
git clone https://github.com/ceph/teuthology
12+
cd teuthology
13+
else
14+
cd teuthology
15+
git pull
16+
fi
17+
18+
# Bootstrap teuthology
19+
./bootstrap
20+
21+
cd $WORKSPACE
22+
23+
# Clone or update teuthology
24+
if [ ! -d downburst ]; then
25+
git clone https://github.com/ceph/downburst
26+
cd downburst
27+
else
28+
cd downburst
29+
git pull
30+
fi
31+
32+
# Bootstrap downburst
33+
./bootstrap
34+
35+
# Activate our virtualenv containing teuthology and ansible
36+
source $WORKSPACE/teuthology/virtualenv/bin/activate
37+
38+
# Add downburst to path
39+
PATH=$PATH:$WORKSPACE/downburst/virtualenv/bin
40+
41+
#if [ $DISTRO == "xenial" ]; then
42+
# DISTRO="ubuntu"
43+
# DISTRO_VERSION="16.04"
44+
#elif [ $DISTRO == "trusty" ]; then
45+
# DISTRO="ubuntu"
46+
# DISTRO_VERSION="14.04"
47+
#elif [ $DISTRO == "centos" ]; then
48+
# DISTRO="centos"
49+
# DISTRO_VERSION="7.3"
50+
#else
51+
# echo "Unknown distro: $DISTRO"
52+
# exit 1
53+
#fi
54+
55+
# Don't bail since we'll almost certainly not lock every machine/os type on the first try
56+
set +e
57+
58+
for machine_type in smithi mira vps; do
59+
LOCK_TRUSTY_CMD="teuthology-lock --lock-many 1 --machine-type $machine_type --os-type ubuntu --os-version 14.04"
60+
LOCK_XENIAL_CMD="teuthology-lock --lock-many 1 --machine-type $machine_type --os-type ubuntu --os-version 16.04"
61+
LOCK_CENTOS_CMD="teuthology-lock --lock-many 1 --machine-type $machine_type --os-type centos --os-version 7.3"
62+
$LOCK_TRUSTY_CMD; while [ $? -ne 0 ]; do sleep 5; $LOCK_TRUSTY_CMD; done
63+
$LOCK_XENIAL_CMD; while [ $? -ne 0 ]; do sleep 5; $LOCK_XENIAL_CMD; done
64+
$LOCK_CENTOS_CMD; while [ $? -ne 0 ]; do sleep 5; $LOCK_CENTOS_CMD; done
65+
done
66+
67+
#LOCK_CMD="teuthology-lock --lock-many 1 --machine-type $MACHINE_TYPE --os-type $DISTRO --os-version $DISTRO_VERSION"
68+
#
69+
## Keep trying to lock a machine
70+
#$LOCK_CMD; while [ $? -ne 0 ]; do sleep 5; $LOCK_CMD; done
71+
72+
set -e
73+
74+
locked_machines=$(teuthology-lock --brief | awk '{ print $1 }' | paste -sd "," -)
75+
#locked_machines=$(teuthology-lock --brief --machine-type $MACHINE_TYPE --os-type $DISTRO --os-version $DISTRO_VERSION | awk '{ print $1 }' | paste -sd "," -)
76+
77+
cd $WORKSPACE/ceph-cm-ansible
78+
79+
# Erase line about the vault password since testnodes don't need any secrets
80+
sed -i '/vault_password_file/d' ./ansible.cfg
81+
82+
ansible-playbook -vv ansible_managed.yml --limit=\"$locked_machines\"
83+
#ansible-playbook -vvv ansible_managed.yml --limit=\"$locked_machine\"
84+
85+
ansible-playbook -vv testnodes.yml -e ansible_ssh_user=ubuntu --limit=\"$locked_machines\"
86+
#ansible-playbook -vvv testnodes.yml -e ansible_ssh_user=ubuntu --limit=\"$locked_machine\"
87+
88+
teuthology-lock --unlock -t <(teuthology-lock --list-targets)
89+
#teuthology-lock --unlock $locked_machine
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
- scm:
2+
name: ceph-cm-ansible
3+
scm:
4+
- git:
5+
url: https://github.com/ceph/ceph-cm-ansible
6+
branches:
7+
- ${sha1}
8+
refspec: +refs/pull/*:refs/remotes/origin/pr/*
9+
browser: auto
10+
timeout: 20
11+
basedir: "ceph-cm-ansible"
12+
skip-tag: true
13+
wipe-workspace: true
14+
15+
- job:
16+
name: ceph-cm-ansible-pull-requests
17+
description: Tests changes to ceph-cm-ansible testnode playbook
18+
project-type: freestyle
19+
# project-type: matrix
20+
node: teuthology
21+
block-downstream: false
22+
block-upstream: false
23+
defaults: global
24+
display-name: 'ceph-cm-ansible: Pull Requests'
25+
quiet-period: 5
26+
# execution-strategy:
27+
# sequential: false
28+
# axes:
29+
# - axis:
30+
# type: user-defined
31+
# name: MACHINE_TYPE
32+
# values:
33+
# - smithi
34+
# - mira
35+
# - vps
36+
# - axis:
37+
# type: user-defined
38+
# name: DISTRO
39+
# values:
40+
# - trusty
41+
# - xenial
42+
# - centos
43+
# - axis:
44+
# type: label-expression
45+
# name: teuthology
46+
# values:
47+
# - teuthology
48+
49+
logrotate:
50+
daysToKeep: 14
51+
52+
properties:
53+
- github:
54+
url: https://github.com/ceph/ceph-cm-ansible/
55+
56+
parameters:
57+
- string:
58+
name: sha1
59+
description: "A pull request ID, like 'origin/pr/72/head'"
60+
61+
triggers:
62+
- github-pull-request:
63+
admin-list:
64+
- djgalloway
65+
- zmc
66+
org-list:
67+
- ceph
68+
only-trigger-phrase: false
69+
github-hooks: true
70+
permit-all: true
71+
auto-close-on-fail: false
72+
73+
scm:
74+
- ceph-cm-ansible
75+
76+
builders:
77+
- shell:
78+
!include-raw:
79+
- ../../../scripts/build_utils.sh
80+
- ../../build/build
81+
#
82+
# wrappers:
83+
# - pre-scm-buildstep:
84+
# - shell:
85+
# !include-raw: ../../build/setup

0 commit comments

Comments
 (0)