Merge ~alejdg/jenkins-agent-charm:master into jenkins-agent-charm:master
- Git
- lp:~alejdg/jenkins-agent-charm
- master
- Merge into master
Proposed by
Alexandre Gomes
Status: | Work in progress |
---|---|
Proposed branch: | ~alejdg/jenkins-agent-charm:master |
Merge into: | jenkins-agent-charm:master |
Diff against target: |
1418 lines (+417/-417) 18 files modified
README.md (+7/-7) config.yaml (+5/-5) dev/null (+0/-248) files/download-agent.sh (+8/-8) files/jenkins-agent-logrotate-config (+1/-1) files/jenkins-agent-systemd-config (+3/-3) files/jenkins-agent-upstart-config (+6/-6) icon.svg (+1/-1) layer.yaml (+1/-1) metadata.yaml (+8/-8) reactive/jenkins_agent.py (+248/-0) templates/jenkins-agent-default (+13/-13) tests/functional/bundles/base-bionic.yaml (+3/-3) tests/functional/bundles/base-focal.yaml (+3/-3) tests/functional/bundles/overlays/local-charm-overlay.yaml.j2 (+2/-2) tests/functional/tests.yaml (+2/-2) tests/unit/files/jenkins-agent-default (+9/-9) tests/unit/test_jenkins_agent.py (+97/-97) |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Jenkins CI Charmers | Pending | ||
Review via email: mp+412480@code.launchpad.net |
Commit message
Rename charm to jenkins-agent
Description of the change
To post a comment you must log in.
- f720aae... by Alexandre Gomes
-
Fix tests after renaming
Unmerged commits
- f720aae... by Alexandre Gomes
-
Fix tests after renaming
- 871848a... by Alexandre Gomes
-
Rename charm to jenkins-agent
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | diff --git a/README.md b/README.md |
2 | index 7541fec..c37458e 100644 |
3 | --- a/README.md |
4 | +++ b/README.md |
5 | @@ -1,28 +1,28 @@ |
6 | # Overview |
7 | |
8 | -This charm provisions a Jenkins slave to connect to a Jenkins master. |
9 | +This charm provisions a Jenkins agent to connect to a Jenkins instance. |
10 | This is the companion to the Jenkins charm. |
11 | |
12 | |
13 | # Usage |
14 | |
15 | -To deploy a Jenkins slave you will also need to deploy the jenkins master |
16 | +To deploy a Jenkins agent you will also need to deploy the jenkins |
17 | charm. This can be done as follows: |
18 | |
19 | juju deploy jenkins |
20 | - juju deploy -n 5 jenkins-slave |
21 | - juju add-relation jenkins jenkins-slave |
22 | + juju deploy -n 5 jenkins-agent |
23 | + juju add-relation jenkins jenkins-agent |
24 | |
25 | There are cases where you want to provision a specific machine that |
26 | provides specific resources for tests, such as CPU architecture or |
27 | -network access. You can deploy the extra slave like this: |
28 | +network access. You can deploy the extra agent like this: |
29 | |
30 | juju add-machine <special-machine-private-ip> |
31 | - juju deploy --to <special-mabine-number> jenkins-slave ppc-slave |
32 | + juju deploy --to <special-mabine-number> jenkins-agent ppc-agent |
33 | |
34 | See the Jenkins charm for more details. |
35 | |
36 | |
37 | # Notes |
38 | |
39 | -We can't use interface:jenkins-slave yet as it's not fully implemented. |
40 | +We can't use interface:jenkins-agent yet as it's not fully implemented. |
41 | diff --git a/config.yaml b/config.yaml |
42 | index 50380ce..6acd231 100644 |
43 | --- a/config.yaml |
44 | +++ b/config.yaml |
45 | @@ -2,17 +2,17 @@ options: |
46 | tools: |
47 | type: string |
48 | default: git gcc make bzr |
49 | - description: Tooling to deploy on jenkins slave node |
50 | + description: Tooling to deploy on jenkins agent node |
51 | labels: |
52 | type: string |
53 | - description: Jenkins labels to associate with jenkins slave node |
54 | + description: Jenkins labels to associate with jenkins agent node |
55 | default: "" |
56 | - master_url: |
57 | + jenkins_url: |
58 | type: string |
59 | default: "" |
60 | description: | |
61 | - Configure the slave to use an explicit jenkins master instead of using |
62 | - the jenkins-slave relation. This allows for the slave and master to |
63 | + Configure the agent to use an explicit jenkins instead of using |
64 | + the jenkins-agent relation. This allows for the agent and jenkins to |
65 | be deployed in different environments. |
66 | nagios_context: |
67 | type: string |
68 | diff --git a/files/download-slave.sh b/files/download-agent.sh |
69 | similarity index 75% |
70 | rename from files/download-slave.sh |
71 | rename to files/download-agent.sh |
72 | index dfe1462..1ed1213 100755 |
73 | --- a/files/download-slave.sh |
74 | +++ b/files/download-agent.sh |
75 | @@ -4,7 +4,7 @@ |
76 | # This file is managed by Juju. Attempt no changes here. |
77 | # |
78 | |
79 | -SLAVE_JAR=/var/run/jenkins/slave.jar |
80 | +AGENT_JAR=/var/run/jenkins/agent.jar |
81 | JENKINS_URL=$1 |
82 | JENKINS_HOSTNAME=$2 |
83 | JENKINS_JNLP=$3 |
84 | @@ -15,19 +15,19 @@ then |
85 | exit 1 |
86 | fi |
87 | |
88 | -# Retrieve Slave JAR from Jenkins |
89 | -echo "Downloading slave.jar from ${JENKINS_URL}..." |
90 | -wget -q -O ${SLAVE_JAR}.new ${JENKINS_URL}/jnlpJars/slave.jar |
91 | +# Retrieve Agent JAR from Jenkins |
92 | +echo "Downloading agent.jar from ${JENKINS_URL}..." |
93 | +wget -q -O ${AGENT_JAR}.new ${JENKINS_URL}/jnlpJars/agent.jar |
94 | |
95 | # Retrive JNLP file from Jenkins |
96 | echo "Downloading agent.jnlp from ${JENKINS_URL}..." |
97 | -wget -q ${JENKINS_URL}/computer/${JENKINS_HOSTNAME}/jenkins-agent.jnlp -O ${JENKINS_JNLP}.new || wget -q ${JENKINS_URL}/computer/${JENKINS_HOSTNAME}/slave-agent.jnlp -O ${JENKINS_JNLP}.new |
98 | +wget -q ${JENKINS_URL}/computer/${JENKINS_HOSTNAME}/jenkins-agent.jnlp -O ${JENKINS_JNLP}.new || wget -q ${JENKINS_URL}/computer/${JENKINS_HOSTNAME}/agent-agent.jnlp -O ${JENKINS_JNLP}.new |
99 | sed -i -r "s|(<argument>-url</argument>.*</argument>)|\1<argument>-url</argument><argument>${JENKINS_URL}</argument>|g" ${JENKINS_JNLP}.new |
100 | |
101 | -# Check to make sure slave.jar and agent.jnlp were downloaded. |
102 | -if [ -s ${SLAVE_JAR}.new ] && [ -s ${JENKINS_JNLP}.new ] |
103 | +# Check to make sure agent.jar and agent.jnlp were downloaded. |
104 | +if [ -s ${AGENT_JAR}.new ] && [ -s ${JENKINS_JNLP}.new ] |
105 | then |
106 | - mv ${SLAVE_JAR}.new ${SLAVE_JAR} |
107 | + mv ${AGENT_JAR}.new ${AGENT_JAR} |
108 | mv ${JENKINS_JNLP}.new ${JENKINS_JNLP} |
109 | exit 0 |
110 | else |
111 | diff --git a/files/jenkins-slave-logrotate-config b/files/jenkins-agent-logrotate-config |
112 | similarity index 91% |
113 | rename from files/jenkins-slave-logrotate-config |
114 | rename to files/jenkins-agent-logrotate-config |
115 | index 8ab641b..bb3dd44 100644 |
116 | --- a/files/jenkins-slave-logrotate-config |
117 | +++ b/files/jenkins-agent-logrotate-config |
118 | @@ -2,7 +2,7 @@ |
119 | # This file is managed by Juju. Attempt no changes here. |
120 | # |
121 | |
122 | -/var/log/jenkins/jenkins-slave.log { |
123 | +/var/log/jenkins/jenkins-agent.log { |
124 | daily |
125 | copytruncate |
126 | missingok |
127 | diff --git a/files/jenkins-slave-sudoers b/files/jenkins-agent-sudoers |
128 | similarity index 100% |
129 | rename from files/jenkins-slave-sudoers |
130 | rename to files/jenkins-agent-sudoers |
131 | diff --git a/files/jenkins-slave-systemd-config b/files/jenkins-agent-systemd-config |
132 | similarity index 66% |
133 | rename from files/jenkins-slave-systemd-config |
134 | rename to files/jenkins-agent-systemd-config |
135 | index 8148aaa..7e209d2 100644 |
136 | --- a/files/jenkins-slave-systemd-config |
137 | +++ b/files/jenkins-agent-systemd-config |
138 | @@ -3,7 +3,7 @@ |
139 | # |
140 | |
141 | [Unit] |
142 | -Description=Jenkins CI Slave Agent |
143 | +Description=Jenkins CI Agent |
144 | After=network.target |
145 | |
146 | [Service] |
147 | @@ -11,8 +11,8 @@ Type=simple |
148 | # Always be Jenkinsing! |
149 | Restart=always |
150 | RestartSec=3 |
151 | -ExecStartPre=/bin/bash -c '[ -r /etc/default/jenkins-slave ] && . /etc/default/jenkins-slave ; [ -n "$JENKINS_URL" ] || { exit 1; }; mkdir $JENKINS_RUN > /dev/null 2>&1 || true ; chown -R $JENKINS_USER $JENKINS_RUN || true ; /usr/local/sbin/download-slave.sh $JENKINS_URL $JENKINS_HOSTNAME $JENKINS_JNLP; chown -R $JENKINS_USER $JENKINS_HOME || true' |
152 | -ExecStart=/bin/bash -c '[ -r /etc/default/jenkins-slave ] && . /etc/default/jenkins-slave ; exec start-stop-daemon --start -c $JENKINS_USER --exec $JAVA --name jenkins-slave -- $JAVA_ARGS -jar $JENKINS_RUN/slave.jar $JENKINS_ARGS' |
153 | +ExecStartPre=/bin/bash -c '[ -r /etc/default/jenkins-agent ] && . /etc/default/jenkins-agent ; [ -n "$JENKINS_URL" ] || { exit 1; }; mkdir $JENKINS_RUN > /dev/null 2>&1 || true ; chown -R $JENKINS_USER $JENKINS_RUN || true ; /usr/local/sbin/download-agent.sh $JENKINS_URL $JENKINS_HOSTNAME $JENKINS_JNLP; chown -R $JENKINS_USER $JENKINS_HOME || true' |
154 | +ExecStart=/bin/bash -c '[ -r /etc/default/jenkins-agent ] && . /etc/default/jenkins-agent ; exec start-stop-daemon --start -c $JENKINS_USER --exec $JAVA --name jenkins-agent -- $JAVA_ARGS -jar $JENKINS_RUN/agent.jar $JENKINS_ARGS' |
155 | |
156 | [Install] |
157 | WantedBy=multi-user.target |
158 | diff --git a/files/jenkins-slave-upstart-config b/files/jenkins-agent-upstart-config |
159 | similarity index 73% |
160 | rename from files/jenkins-slave-upstart-config |
161 | rename to files/jenkins-agent-upstart-config |
162 | index cf8012d..8d62cbd 100644 |
163 | --- a/files/jenkins-slave-upstart-config |
164 | +++ b/files/jenkins-agent-upstart-config |
165 | @@ -2,7 +2,7 @@ |
166 | # This file is managed by Juju. Attempt no changes here. |
167 | # |
168 | |
169 | -description "Jenkins CI Slave Agent" |
170 | +description "Jenkins CI Agent" |
171 | author "James Page <james.page@ubuntu.com>" |
172 | |
173 | start on runlevel [2345] |
174 | @@ -13,18 +13,18 @@ respawn |
175 | respawn limit unlimited |
176 | |
177 | pre-start script |
178 | - [ -r /etc/default/jenkins-slave ] && . /etc/default/jenkins-slave |
179 | + [ -r /etc/default/jenkins-agent ] && . /etc/default/jenkins-agent |
180 | [ -n "$JENKINS_URL" ] || { stop; exit 0; } |
181 | mkdir $JENKINS_RUN > /dev/null 2>&1 || true |
182 | chown -R $JENKINS_USER $JENKINS_RUN || true |
183 | - /usr/local/sbin/download-slave.sh $JENKINS_URL $JENKINS_HOSTNAME $JENKINS_JNLP |
184 | + /usr/local/sbin/download-agent.sh $JENKINS_URL $JENKINS_HOSTNAME $JENKINS_JNLP |
185 | chown -R $JENKINS_USER $JENKINS_HOME || true |
186 | end script |
187 | |
188 | script |
189 | - [ -r /etc/default/jenkins-slave ] && . /etc/default/jenkins-slave |
190 | - exec start-stop-daemon --start -c $JENKINS_USER --exec $JAVA --name jenkins-slave \ |
191 | - -- $JAVA_ARGS -jar $JENKINS_RUN/slave.jar $JENKINS_ARGS |
192 | + [ -r /etc/default/jenkins-agent ] && . /etc/default/jenkins-agent |
193 | + exec start-stop-daemon --start -c $JENKINS_USER --exec $JAVA --name jenkins-agent \ |
194 | + -- $JAVA_ARGS -jar $JENKINS_RUN/agent.jar $JENKINS_ARGS |
195 | end script |
196 | |
197 | # Don't respawn too fast. |
198 | diff --git a/icon.svg b/icon.svg |
199 | index ad21970..9a7e0d0 100644 |
200 | --- a/icon.svg |
201 | +++ b/icon.svg |
202 | @@ -515,7 +515,7 @@ |
203 | sodipodi:role="line" |
204 | id="tspan3083" |
205 | x="-236.76514" |
206 | - y="715.29077">Slave</tspan></text> |
207 | + y="715.29077">Agent</tspan></text> |
208 | </g> |
209 | <g |
210 | inkscape:groupmode="layer" |
211 | diff --git a/layer.yaml b/layer.yaml |
212 | index 52ccf61..8ca6473 100644 |
213 | --- a/layer.yaml |
214 | +++ b/layer.yaml |
215 | @@ -3,4 +3,4 @@ includes: |
216 | - layer:apt |
217 | - layer:nagios |
218 | - layer:status |
219 | -repo: lp:jenkins-slave-charm |
220 | +repo: lp:jenkins-agent-charm |
221 | diff --git a/metadata.yaml b/metadata.yaml |
222 | index 0f7eb5d..8f7c29d 100644 |
223 | --- a/metadata.yaml |
224 | +++ b/metadata.yaml |
225 | @@ -1,14 +1,14 @@ |
226 | -name: jenkins-slave |
227 | +name: jenkins-agent |
228 | maintainer: Jenkins CI Charmers <jenkins-ci-charmers@lists.launchpad.net> |
229 | -summary: Jenkins CI Slave |
230 | +summary: Jenkins CI Agent |
231 | description: | |
232 | Jenkins is a Continuous Integration server supporting |
233 | flexible continuous integration and deployment methodologies |
234 | and more. |
235 | . |
236 | - This charm provides support for jenkins slaves |
237 | + This charm provides support for jenkins agents |
238 | . |
239 | - https://launchpad.net/jenkins-slave-charm |
240 | + https://launchpad.net/jenkins-agent-charm |
241 | tags: |
242 | - applications |
243 | series: |
244 | @@ -17,8 +17,8 @@ series: |
245 | - xenial |
246 | - trusty |
247 | provides: |
248 | - slave: |
249 | - interface: jenkins-slave |
250 | - nrpe-external-master: |
251 | - interface: nrpe-external-master |
252 | + agent: |
253 | + interface: jenkins-agent |
254 | + nrpe: |
255 | + interface: nrpe |
256 | scope: container |
257 | diff --git a/reactive/jenkins_agent.py b/reactive/jenkins_agent.py |
258 | new file mode 100644 |
259 | index 0000000..8c9f426 |
260 | --- /dev/null |
261 | +++ b/reactive/jenkins_agent.py |
262 | @@ -0,0 +1,248 @@ |
263 | +import os |
264 | + |
265 | +from charmhelpers.core import hookenv, host, templating, unitdata |
266 | +from charmhelpers.contrib.charmsupport import nrpe |
267 | +from charmhelpers.fetch import apt_purge |
268 | +from charms import apt, reactive |
269 | +from charms.layer import status |
270 | + |
271 | + |
272 | +@reactive.hook('upgrade-charm') |
273 | +def upgrade_charm(): |
274 | + status.maintenance('forcing reconfiguration on upgrade-charm') |
275 | + reactive.clear_flag('jenkins-agent.active') |
276 | + reactive.clear_flag('jenkins-agent.installed') |
277 | + reactive.clear_flag('nagios-nrpe.configured') |
278 | + |
279 | + |
280 | +@reactive.when_not('jenkins-agent.installed') |
281 | +def install(): |
282 | + status.maintenance('installing jenkins-agent') |
283 | + reactive.clear_flag('jenkins-agent.active') |
284 | + |
285 | + config = hookenv.config() |
286 | + |
287 | + status.maintenance('Adding jenkins-agent dependencies to be installed') |
288 | + packages = ['wget', 'default-jre-headless'] |
289 | + |
290 | + # Install extra packages needed by the agent. |
291 | + tools = config.get('tools') |
292 | + if tools: |
293 | + status.maintenance('Adding jenkins-agent additional tools to be installed: {}'.format(tools)) |
294 | + for package in tools.split(): |
295 | + packages.append(package) |
296 | + apt.queue_install(packages) |
297 | + if not apt.install_queued(): |
298 | + return # apt layer already set blocked state. |
299 | + |
300 | + # Get rid of the legacy jenkins-agent package, including config files. |
301 | + status.maintenance('Removing the old jenkins-agent package... (obsoleted by this charm)') |
302 | + apt_purge(['jenkins-agent']) |
303 | + |
304 | + # Create jenkins user if it doesn't exist. |
305 | + if host.user_exists('jenkins'): |
306 | + status.maintenance('Installing jenkins-agent (user account already exists)...') |
307 | + else: |
308 | + status.maintenance('Installing jenkins-agent (user account)...') |
309 | + host.adduser(username='jenkins', system_user=True, home_dir='/var/lib/jenkins') |
310 | + |
311 | + # And ensure required directories exist and are set up. |
312 | + status.maintenance('Installing jenkins-agent (directories)...') |
313 | + agent_host = hookenv.local_unit().replace('/', '-') |
314 | + for d in [ |
315 | + '/var/lib/jenkins', |
316 | + '/var/lib/jenkins/agents', |
317 | + '/var/lib/jenkins/agents/{}'.format(agent_host), |
318 | + '/var/log/jenkins', |
319 | + ]: |
320 | + host.mkdir(d, owner='jenkins', group='jenkins', perms=0o755) |
321 | + |
322 | + status.maintenance('Installing jenkins-agent (common files)...') |
323 | + write_default_conf() |
324 | + file_to_units('files/download-agent.sh', '/usr/local/sbin/download-agent.sh') |
325 | + file_to_units('files/jenkins-agent-logrotate-config', '/etc/logrotate.d/jenkins-agent') |
326 | + |
327 | + if host.lsb_release()['DISTRIB_CODENAME'] == 'trusty': |
328 | + status.maintenance('Installing jenkins-agent (upstart job)...') |
329 | + file_to_units('files/jenkins-agent-upstart-config', '/etc/init/jenkins-agent.conf') |
330 | + else: |
331 | + status.maintenance('Installing jenkins-agent (system unit)...') |
332 | + file_to_units('files/jenkins-agent-systemd-config', '/lib/systemd/system/jenkins-agent.service') |
333 | + host.service('enable', 'jenkins-agent') |
334 | + |
335 | + status.maintenance('Installing jenkins-agent... done.') |
336 | + reactive.clear_flag('jenkins-agent.configured') |
337 | + reactive.set_flag('jenkins-agent.installed') |
338 | + |
339 | + |
340 | +@reactive.when('config.changed') |
341 | +def config_changed(): |
342 | + status.maintenance('Configuration changed') |
343 | + reactive.clear_flag('jenkins-agent.configured') |
344 | + reactive.clear_flag('nagios-nrpe.configured') |
345 | + |
346 | + |
347 | +@reactive.when('jenkins-agent.installed') |
348 | +@reactive.when_not('jenkins-agent.configured') |
349 | +def configure_jenkins_agent(): |
350 | + status.maintenance('configuring jenkins-agent') |
351 | + reactive.clear_flag('jenkins-agent.active') |
352 | + |
353 | + config = hookenv.config() |
354 | + kv = unitdata.kv() |
355 | + |
356 | + if config.get('jenkins_url'): |
357 | + status.maintenance("Using 'jenkins_url' to configure the agent.") |
358 | + write_default_conf(config.get('jenkins_url')) |
359 | + elif kv.get('url'): |
360 | + status.maintenance("Using url from relation as 'jenkins_url'") |
361 | + write_default_conf(kv.get('url'), secret=kv.get('secret')) |
362 | + else: |
363 | + status.maintenance("No 'jenkins_url' set; not configuring agent at this time.") |
364 | + status.blocked("requires either agent relation or 'jenkins_url'") |
365 | + reactive.clear_flag('jenkins-agent.active') |
366 | + return |
367 | + |
368 | + file_to_units('files/jenkins-agent-sudoers', '/etc/sudoers.d/jenkins', perms=0o440) |
369 | + |
370 | + reactive.clear_flag('nagios-nrpe.configured') |
371 | + reactive.set_flag('jenkins-agent.configured') |
372 | + |
373 | + |
374 | +@reactive.when('jenkins-agent.configured') |
375 | +@reactive.when('jenkins-agent.active') |
376 | +@reactive.when('nrpe.available') |
377 | +@reactive.when_not('nagios-nrpe.configured') |
378 | +def configure_nagios(nagios): |
379 | + status.maintenance('setting up NRPE checks') |
380 | + reactive.clear_flag('jenkins-agent.active') |
381 | + |
382 | + # Use charmhelpers.contrib.charmsupport's nrpe to determine hostname |
383 | + hostname = nrpe.get_nagios_hostname() |
384 | + nrpe_setup = nrpe.NRPE(hostname=hostname, primary=True) |
385 | + |
386 | + cmd = '/usr/lib/nagios/plugins/check_procs -c 1:1 -a agent.jar' |
387 | + nrpe_setup.add_check('jenkins_agent_ps', 'Jenkins Agent Process', cmd) |
388 | + |
389 | + nrpe_setup.write() |
390 | + reactive.set_flag('nagios-nrpe.configured') |
391 | + status.maintenance('NRPE configured') |
392 | + |
393 | + |
394 | +@reactive.when('jenkins-agent.configured') |
395 | +@reactive.when_not('jenkins-agent.active') |
396 | +def set_active(): |
397 | + config = hookenv.config() |
398 | + kv = unitdata.kv() |
399 | + |
400 | + # Startup the jenkins-agent service. This is called in the |
401 | + # install, config-changed and upgrade-charm paths. It needs to be |
402 | + # tolerant of a running or stopped jenkins-agent. |
403 | + if host.service_running('jenkins-agent'): |
404 | + status.maintenance('Restarting jenkins-agent...') |
405 | + host.service_restart('jenkins-agent') |
406 | + else: |
407 | + status.maintenance('Starting jenkins-agent...') |
408 | + host.service_start('jenkins-agent') |
409 | + |
410 | + jenkins_url = config.get('jenkins_url') |
411 | + if jenkins_url: |
412 | + status.active('ready - using jenkins {} (jenkins_url)'.format(jenkins_url)) |
413 | + elif kv.get('url'): |
414 | + status.active('ready - using jenkins from relation') |
415 | + else: |
416 | + status.blocked("set_active() but no jenkins") |
417 | + return |
418 | + |
419 | + reactive.set_flag('jenkins-agent.active') |
420 | + |
421 | + |
422 | +# We can't use interface:jenkins-agent yet as it's not implemented. |
423 | +@reactive.hook('agent-relation-joined', 'agent-relation-changed') |
424 | +def agent_relation_changed(): |
425 | + reactive.set_flag('agent-relation.available') |
426 | + reactive.clear_flag('jenkins-agent.configured') |
427 | + reactive.clear_flag('agent-relation.configured') |
428 | + |
429 | + |
430 | +@reactive.hook('agent-relation-departed', 'agent-relation-broken') |
431 | +def agent_relation_removed(): |
432 | + kv = unitdata.kv() |
433 | + kv.set('url', None) |
434 | + kv.set('secret', None) |
435 | + reactive.clear_flag('agent-relation.available') |
436 | + |
437 | + |
438 | +@reactive.when('agent-relation.available') |
439 | +@reactive.when_not('agent-relation.configured') |
440 | +def agent_relation(): |
441 | + status.maintenance('setting up jenkins via agent relation') |
442 | + |
443 | + config = hookenv.config() |
444 | + kv = unitdata.kv() |
445 | + |
446 | + if config.get('jenkins_url'): |
447 | + hookenv.log("Config option 'jenkins_url' is set. Can't use agent relation.") |
448 | + reactive.set_flag('agent-relation.configured') |
449 | + return |
450 | + |
451 | + url = hookenv.relation_get('url') |
452 | + if url: |
453 | + secret = hookenv.relation_get('secret') |
454 | + kv.set('url', url) |
455 | + kv.set('secret', secret) |
456 | + write_default_conf(url, secret=secret) |
457 | + else: |
458 | + hookenv.log("Jenkins hasn't exported its url yet, exiting...") |
459 | + return |
460 | + |
461 | + reactive.clear_flag('jenkins-agent.active') |
462 | + |
463 | + # Set the agent hostname to match the juju unit |
464 | + # in the jenkins instance |
465 | + agent_host = hookenv.local_unit().replace('/', '-') |
466 | + agent_address = hookenv.unit_private_ip() |
467 | + noexecutors = os.cpu_count() |
468 | + config_labels = config.get('labels') |
469 | + |
470 | + if config_labels: |
471 | + labels = config_labels |
472 | + else: |
473 | + labels = os.uname()[4] |
474 | + |
475 | + # Set all relations |
476 | + hookenv.relation_set(executors=noexecutors) |
477 | + hookenv.relation_set(labels=labels) |
478 | + hookenv.relation_set(agenthost=agent_host) |
479 | + hookenv.relation_set(agentaddress=agent_address) |
480 | + reactive.set_flag('agent-relation.configured') |
481 | + |
482 | + |
483 | +def file_to_units(local_path, unit_path, perms=None, owner='root', group='root'): |
484 | + """copy a file from the charm onto our unit(s)""" |
485 | + file_perms = perms |
486 | + if not perms: |
487 | + # Let's try manually work it out |
488 | + if local_path[-3:] == '.py' or local_path[-3:] == '.sh': |
489 | + file_perms = 0o755 |
490 | + else: |
491 | + file_perms = 0o644 |
492 | + |
493 | + with open(local_path, 'r') as fh: |
494 | + host.write_file(path=unit_path, content=fh.read().encode(), owner=owner, group=group, perms=file_perms) |
495 | + |
496 | + |
497 | +def write_default_conf( |
498 | + jenkins_url=None, owner='root', group='root', conf_path='/etc/default/jenkins-agent', secret=None |
499 | +): |
500 | + templates_dir = os.path.join(hookenv.charm_dir(), 'templates') |
501 | + agent_host = hookenv.local_unit().replace('/', '-') |
502 | + templating.render( |
503 | + 'jenkins-agent-default', |
504 | + conf_path, |
505 | + {'jenkins_url': jenkins_url, 'agent_host': agent_host, 'secret': secret}, |
506 | + owner=owner, |
507 | + group=group, |
508 | + perms=0o444, |
509 | + templates_dir=templates_dir, |
510 | + ) |
511 | diff --git a/reactive/jenkins_slave.py b/reactive/jenkins_slave.py |
512 | deleted file mode 100644 |
513 | index dcb947d..0000000 |
514 | --- a/reactive/jenkins_slave.py |
515 | +++ /dev/null |
516 | @@ -1,248 +0,0 @@ |
517 | -import os |
518 | - |
519 | -from charmhelpers.core import hookenv, host, templating, unitdata |
520 | -from charmhelpers.contrib.charmsupport import nrpe |
521 | -from charmhelpers.fetch import apt_purge |
522 | -from charms import apt, reactive |
523 | -from charms.layer import status |
524 | - |
525 | - |
526 | -@reactive.hook('upgrade-charm') |
527 | -def upgrade_charm(): |
528 | - status.maintenance('forcing reconfiguration on upgrade-charm') |
529 | - reactive.clear_flag('jenkins-slave.active') |
530 | - reactive.clear_flag('jenkins-slave.installed') |
531 | - reactive.clear_flag('nagios-nrpe.configured') |
532 | - |
533 | - |
534 | -@reactive.when_not('jenkins-slave.installed') |
535 | -def install(): |
536 | - status.maintenance('installing jenkins-slave') |
537 | - reactive.clear_flag('jenkins-slave.active') |
538 | - |
539 | - config = hookenv.config() |
540 | - |
541 | - status.maintenance('Adding jenkins-slave dependencies to be installed') |
542 | - packages = ['wget', 'default-jre-headless'] |
543 | - |
544 | - # Install extra packages needed by the slave. |
545 | - tools = config.get('tools') |
546 | - if tools: |
547 | - status.maintenance('Adding jenkins-slave additional tools to be installed: {}'.format(tools)) |
548 | - for package in tools.split(): |
549 | - packages.append(package) |
550 | - apt.queue_install(packages) |
551 | - if not apt.install_queued(): |
552 | - return # apt layer already set blocked state. |
553 | - |
554 | - # Get rid of the legacy jenkins-slave package, including config files. |
555 | - status.maintenance('Removing the old jenkins-slave package... (obsoleted by this charm)') |
556 | - apt_purge(['jenkins-slave']) |
557 | - |
558 | - # Create jenkins user if it doesn't exist. |
559 | - if host.user_exists('jenkins'): |
560 | - status.maintenance('Installing jenkins-slave (user account already exists)...') |
561 | - else: |
562 | - status.maintenance('Installing jenkins-slave (user account)...') |
563 | - host.adduser(username='jenkins', system_user=True, home_dir='/var/lib/jenkins') |
564 | - |
565 | - # And ensure required directories exist and are set up. |
566 | - status.maintenance('Installing jenkins-slave (directories)...') |
567 | - slave_host = hookenv.local_unit().replace('/', '-') |
568 | - for d in [ |
569 | - '/var/lib/jenkins', |
570 | - '/var/lib/jenkins/slaves', |
571 | - '/var/lib/jenkins/slaves/{}'.format(slave_host), |
572 | - '/var/log/jenkins', |
573 | - ]: |
574 | - host.mkdir(d, owner='jenkins', group='jenkins', perms=0o755) |
575 | - |
576 | - status.maintenance('Installing jenkins-slave (common files)...') |
577 | - write_default_conf() |
578 | - file_to_units('files/download-slave.sh', '/usr/local/sbin/download-slave.sh') |
579 | - file_to_units('files/jenkins-slave-logrotate-config', '/etc/logrotate.d/jenkins-slave') |
580 | - |
581 | - if host.lsb_release()['DISTRIB_CODENAME'] == 'trusty': |
582 | - status.maintenance('Installing jenkins-slave (upstart job)...') |
583 | - file_to_units('files/jenkins-slave-upstart-config', '/etc/init/jenkins-slave.conf') |
584 | - else: |
585 | - status.maintenance('Installing jenkins-slave (system unit)...') |
586 | - file_to_units('files/jenkins-slave-systemd-config', '/lib/systemd/system/jenkins-slave.service') |
587 | - host.service('enable', 'jenkins-slave') |
588 | - |
589 | - status.maintenance('Installing jenkins-slave... done.') |
590 | - reactive.clear_flag('jenkins-slave.configured') |
591 | - reactive.set_flag('jenkins-slave.installed') |
592 | - |
593 | - |
594 | -@reactive.when('config.changed') |
595 | -def config_changed(): |
596 | - status.maintenance('Configuration changed') |
597 | - reactive.clear_flag('jenkins-slave.configured') |
598 | - reactive.clear_flag('nagios-nrpe.configured') |
599 | - |
600 | - |
601 | -@reactive.when('jenkins-slave.installed') |
602 | -@reactive.when_not('jenkins-slave.configured') |
603 | -def configure_jenkins_slave(): |
604 | - status.maintenance('configuring jenkins-slave') |
605 | - reactive.clear_flag('jenkins-slave.active') |
606 | - |
607 | - config = hookenv.config() |
608 | - kv = unitdata.kv() |
609 | - |
610 | - if config.get('master_url'): |
611 | - status.maintenance("Using 'master_url' to configure the slave.") |
612 | - write_default_conf(config.get('master_url')) |
613 | - elif kv.get('url'): |
614 | - status.maintenance("Using url from relation as 'master_url'") |
615 | - write_default_conf(kv.get('url'), secret=kv.get('secret')) |
616 | - else: |
617 | - status.maintenance("No 'master_url' set; not configuring slave at this time.") |
618 | - status.blocked("requires either slave relation or 'master_url'") |
619 | - reactive.clear_flag('jenkins-slave.active') |
620 | - return |
621 | - |
622 | - file_to_units('files/jenkins-slave-sudoers', '/etc/sudoers.d/jenkins', perms=0o440) |
623 | - |
624 | - reactive.clear_flag('nagios-nrpe.configured') |
625 | - reactive.set_flag('jenkins-slave.configured') |
626 | - |
627 | - |
628 | -@reactive.when('jenkins-slave.configured') |
629 | -@reactive.when('jenkins-slave.active') |
630 | -@reactive.when('nrpe-external-master.available') |
631 | -@reactive.when_not('nagios-nrpe.configured') |
632 | -def configure_nagios(nagios): |
633 | - status.maintenance('setting up NRPE checks') |
634 | - reactive.clear_flag('jenkins-slave.active') |
635 | - |
636 | - # Use charmhelpers.contrib.charmsupport's nrpe to determine hostname |
637 | - hostname = nrpe.get_nagios_hostname() |
638 | - nrpe_setup = nrpe.NRPE(hostname=hostname, primary=True) |
639 | - |
640 | - cmd = '/usr/lib/nagios/plugins/check_procs -c 1:1 -a slave.jar' |
641 | - nrpe_setup.add_check('jenkins_slave_ps', 'Jenkins Slave Process', cmd) |
642 | - |
643 | - nrpe_setup.write() |
644 | - reactive.set_flag('nagios-nrpe.configured') |
645 | - status.maintenance('NRPE configured') |
646 | - |
647 | - |
648 | -@reactive.when('jenkins-slave.configured') |
649 | -@reactive.when_not('jenkins-slave.active') |
650 | -def set_active(): |
651 | - config = hookenv.config() |
652 | - kv = unitdata.kv() |
653 | - |
654 | - # Startup the jenkins-slave service. This is called in the |
655 | - # install, config-changed and upgrade-charm paths. It needs to be |
656 | - # tolerant of a running or stopped jenkins-slave. |
657 | - if host.service_running('jenkins-slave'): |
658 | - status.maintenance('Restarting jenkins-slave...') |
659 | - host.service_restart('jenkins-slave') |
660 | - else: |
661 | - status.maintenance('Starting jenkins-slave...') |
662 | - host.service_start('jenkins-slave') |
663 | - |
664 | - master_url = config.get('master_url') |
665 | - if master_url: |
666 | - status.active('ready - using jenkins {} (master_url)'.format(master_url)) |
667 | - elif kv.get('url'): |
668 | - status.active('ready - using jenkins from relation') |
669 | - else: |
670 | - status.blocked("set_active() but no jenkins master") |
671 | - return |
672 | - |
673 | - reactive.set_flag('jenkins-slave.active') |
674 | - |
675 | - |
676 | -# We can't use interface:jenkins-slave yet as it's not implemented. |
677 | -@reactive.hook('slave-relation-joined', 'slave-relation-changed') |
678 | -def slave_relation_changed(): |
679 | - reactive.set_flag('slave-relation.available') |
680 | - reactive.clear_flag('jenkins-slave.configured') |
681 | - reactive.clear_flag('slave-relation.configured') |
682 | - |
683 | - |
684 | -@reactive.hook('slave-relation-departed', 'slave-relation-broken') |
685 | -def slave_relation_removed(): |
686 | - kv = unitdata.kv() |
687 | - kv.set('url', None) |
688 | - kv.set('secret', None) |
689 | - reactive.clear_flag('slave-relation.available') |
690 | - |
691 | - |
692 | -@reactive.when('slave-relation.available') |
693 | -@reactive.when_not('slave-relation.configured') |
694 | -def slave_relation(): |
695 | - status.maintenance('setting up jenkins via slave relation') |
696 | - |
697 | - config = hookenv.config() |
698 | - kv = unitdata.kv() |
699 | - |
700 | - if config.get('master_url'): |
701 | - hookenv.log("Config option 'master_url' is set. Can't use slave relation.") |
702 | - reactive.set_flag('slave-relation.configured') |
703 | - return |
704 | - |
705 | - url = hookenv.relation_get('url') |
706 | - if url: |
707 | - secret = hookenv.relation_get('secret') |
708 | - kv.set('url', url) |
709 | - kv.set('secret', secret) |
710 | - write_default_conf(url, secret=secret) |
711 | - else: |
712 | - hookenv.log("Master hasn't exported its url yet, exiting...") |
713 | - return |
714 | - |
715 | - reactive.clear_flag('jenkins-slave.active') |
716 | - |
717 | - # Set the slave hostname to match the juju unit |
718 | - # in the jenkins master instance |
719 | - slave_host = hookenv.local_unit().replace('/', '-') |
720 | - slave_address = hookenv.unit_private_ip() |
721 | - noexecutors = os.cpu_count() |
722 | - config_labels = config.get('labels') |
723 | - |
724 | - if config_labels: |
725 | - labels = config_labels |
726 | - else: |
727 | - labels = os.uname()[4] |
728 | - |
729 | - # Set all relations |
730 | - hookenv.relation_set(executors=noexecutors) |
731 | - hookenv.relation_set(labels=labels) |
732 | - hookenv.relation_set(slavehost=slave_host) |
733 | - hookenv.relation_set(slaveaddress=slave_address) |
734 | - reactive.set_flag('slave-relation.configured') |
735 | - |
736 | - |
737 | -def file_to_units(local_path, unit_path, perms=None, owner='root', group='root'): |
738 | - """copy a file from the charm onto our unit(s)""" |
739 | - file_perms = perms |
740 | - if not perms: |
741 | - # Let's try manually work it out |
742 | - if local_path[-3:] == '.py' or local_path[-3:] == '.sh': |
743 | - file_perms = 0o755 |
744 | - else: |
745 | - file_perms = 0o644 |
746 | - |
747 | - with open(local_path, 'r') as fh: |
748 | - host.write_file(path=unit_path, content=fh.read().encode(), owner=owner, group=group, perms=file_perms) |
749 | - |
750 | - |
751 | -def write_default_conf( |
752 | - master_url=None, owner='root', group='root', conf_path='/etc/default/jenkins-slave', secret=None |
753 | -): |
754 | - templates_dir = os.path.join(hookenv.charm_dir(), 'templates') |
755 | - slave_host = hookenv.local_unit().replace('/', '-') |
756 | - templating.render( |
757 | - 'jenkins-slave-default', |
758 | - conf_path, |
759 | - {'master_url': master_url, 'slave_host': slave_host, 'secret': secret}, |
760 | - owner=owner, |
761 | - group=group, |
762 | - perms=0o444, |
763 | - templates_dir=templates_dir, |
764 | - ) |
765 | diff --git a/templates/jenkins-slave-default b/templates/jenkins-agent-default |
766 | similarity index 77% |
767 | rename from templates/jenkins-slave-default |
768 | rename to templates/jenkins-agent-default |
769 | index b3b2148..93c0774 100644 |
770 | --- a/templates/jenkins-slave-default |
771 | +++ b/templates/jenkins-agent-default |
772 | @@ -2,11 +2,11 @@ |
773 | # This file is managed by Juju. Attempt no changes here. |
774 | # |
775 | |
776 | -# defaults for jenkins-slave component of the jenkins continuous integration |
777 | +# defaults for jenkins-agent component of the jenkins continuous integration |
778 | # system |
779 | |
780 | # pulled in from the init script; makes things easier. |
781 | -NAME=jenkins-slave |
782 | +NAME=jenkins-agent |
783 | |
784 | # location of java |
785 | JAVA=/usr/bin/java |
786 | @@ -31,25 +31,25 @@ JENKINS_HOME=/var/lib/jenkins |
787 | JENKINS_RUN=/var/run/jenkins |
788 | |
789 | # URL of jenkins server to connect to |
790 | -# Not specifying this parameter will stop the slave |
791 | +# Not specifying this parameter will stop the agent |
792 | # job from running. |
793 | -{% if master_url %} |
794 | -JENKINS_URL="{{ master_url }}" |
795 | +{% if jenkins_url %} |
796 | +JENKINS_URL="{{ jenkins_url }}" |
797 | {% else %} |
798 | #JENKINS_URL="" |
799 | {% endif %} |
800 | |
801 | -# Name of slave configuration to use at JENKINS_URL |
802 | +# Name of agent configuration to use at JENKINS_URL |
803 | # Override if it need to be something other than the |
804 | -# hostname of the server the slave is running on. |
805 | -{% if slave_host %} |
806 | -JENKINS_HOSTNAME="{{ slave_host }}" |
807 | +# hostname of the server the agent is running on. |
808 | +{% if agent_host %} |
809 | +JENKINS_HOSTNAME="{{ agent_host }}" |
810 | {% else %} |
811 | JENKINS_HOSTNAME="$(hostname)" |
812 | {% endif %} |
813 | |
814 | # Log file location for use in Debian init script |
815 | -JENKINS_SLAVE_LOG=/var/log/jenkins/$NAME.log |
816 | +JENKINS_Agent_LOG=/var/log/jenkins/$NAME.log |
817 | |
818 | # OS LIMITS SETUP |
819 | # comment this out to observe /etc/security/limits.conf |
820 | @@ -63,11 +63,11 @@ MAXOPENFILES=8192 |
821 | # Jenkins jnlp file |
822 | JENKINS_JNLP="${JENKINS_HOME}/agent.jnlp" |
823 | |
824 | -# Arguments to pass to jenkins slave on startup |
825 | +# Arguments to pass to jenkins agent on startup |
826 | {% if secret %} |
827 | -JENKINS_SLAVE_SECRET="{{ secret }}" |
828 | +JENKINS_Agent_SECRET="{{ secret }}" |
829 | |
830 | -JENKINS_ARGS="-jnlpUrl file:${JENKINS_JNLP} -secret ${JENKINS_SLAVE_SECRET}" |
831 | +JENKINS_ARGS="-jnlpUrl file:${JENKINS_JNLP} -secret ${JENKINS_Agent_SECRET}" |
832 | {% else %} |
833 | JENKINS_ARGS="-jnlpUrl file:${JENKINS_JNLP}" |
834 | {% endif %} |
835 | diff --git a/tests/functional/bundles/base-bionic.yaml b/tests/functional/bundles/base-bionic.yaml |
836 | index cb92d23..a4ac440 100644 |
837 | --- a/tests/functional/bundles/base-bionic.yaml |
838 | +++ b/tests/functional/bundles/base-bionic.yaml |
839 | @@ -9,7 +9,7 @@ applications: |
840 | password: admin |
841 | expose: true |
842 | |
843 | - jenkins-slave: |
844 | + jenkins-agent: |
845 | num_units: 1 |
846 | |
847 | nrpe: |
848 | @@ -17,6 +17,6 @@ applications: |
849 | |
850 | relations: |
851 | - - jenkins |
852 | - - jenkins-slave |
853 | - - - jenkins-slave |
854 | + - jenkins-agent |
855 | + - - jenkins-agent |
856 | - nrpe |
857 | diff --git a/tests/functional/bundles/base-focal.yaml b/tests/functional/bundles/base-focal.yaml |
858 | index 786b92a..54b8961 100644 |
859 | --- a/tests/functional/bundles/base-focal.yaml |
860 | +++ b/tests/functional/bundles/base-focal.yaml |
861 | @@ -6,7 +6,7 @@ applications: |
862 | num_units: 1 |
863 | expose: true |
864 | |
865 | - jenkins-slave: |
866 | + jenkins-agent: |
867 | num_units: 1 |
868 | |
869 | nrpe: |
870 | @@ -14,6 +14,6 @@ applications: |
871 | |
872 | relations: |
873 | - - jenkins |
874 | - - jenkins-slave |
875 | - - - jenkins-slave |
876 | + - jenkins-agent |
877 | + - - jenkins-agent |
878 | - nrpe |
879 | diff --git a/tests/functional/bundles/overlays/local-charm-overlay.yaml.j2 b/tests/functional/bundles/overlays/local-charm-overlay.yaml.j2 |
880 | index 1adcb54..8486e62 100644 |
881 | --- a/tests/functional/bundles/overlays/local-charm-overlay.yaml.j2 |
882 | +++ b/tests/functional/bundles/overlays/local-charm-overlay.yaml.j2 |
883 | @@ -1,3 +1,3 @@ |
884 | applications: |
885 | - jenkins-slave: |
886 | - charm: /tmp/charm-builds/jenkins-slave |
887 | + jenkins-agent: |
888 | + charm: /tmp/charm-builds/jenkins-agent |
889 | diff --git a/tests/functional/tests.yaml b/tests/functional/tests.yaml |
890 | index 25f3335..a0413cb 100644 |
891 | --- a/tests/functional/tests.yaml |
892 | +++ b/tests/functional/tests.yaml |
893 | @@ -1,4 +1,4 @@ |
894 | -charm_name: jenkins-slave |
895 | +charm_name: jenkins-agent |
896 | tests: |
897 | - zaza.charm_tests.noop.tests.NoopTest |
898 | configure: |
899 | @@ -15,5 +15,5 @@ smoke_bundles: |
900 | target_deploy_status: |
901 | jenkins: |
902 | workload-status-message: Jenkins is running |
903 | - jenkins-slave: |
904 | + jenkins-agent: |
905 | workload-status-message: ready - using jenkins from relation |
906 | diff --git a/tests/unit/files/jenkins-slave-default b/tests/unit/files/jenkins-agent-default |
907 | similarity index 79% |
908 | rename from tests/unit/files/jenkins-slave-default |
909 | rename to tests/unit/files/jenkins-agent-default |
910 | index c76f8e1..ca5d5ec 100644 |
911 | --- a/tests/unit/files/jenkins-slave-default |
912 | +++ b/tests/unit/files/jenkins-agent-default |
913 | @@ -2,11 +2,11 @@ |
914 | # This file is managed by Juju. Attempt no changes here. |
915 | # |
916 | |
917 | -# defaults for jenkins-slave component of the jenkins continuous integration |
918 | +# defaults for jenkins-agent component of the jenkins continuous integration |
919 | # system |
920 | |
921 | # pulled in from the init script; makes things easier. |
922 | -NAME=jenkins-slave |
923 | +NAME=jenkins-agent |
924 | |
925 | # location of java |
926 | JAVA=/usr/bin/java |
927 | @@ -30,21 +30,21 @@ JENKINS_HOME=/var/lib/jenkins |
928 | JENKINS_RUN=/var/run/jenkins |
929 | |
930 | # URL of jenkins server to connect to |
931 | -# Not specifying this parameter will stop the slave |
932 | +# Not specifying this parameter will stop the agent |
933 | # job from running. |
934 | |
935 | #JENKINS_URL="" |
936 | |
937 | |
938 | -# Name of slave configuration to use at JENKINS_URL |
939 | +# Name of agent configuration to use at JENKINS_URL |
940 | # Override if it need to be something other than the |
941 | -# hostname of the server the slave is running on. |
942 | +# hostname of the server the agent is running on. |
943 | |
944 | -JENKINS_HOSTNAME="jenkins-slave-3" |
945 | +JENKINS_HOSTNAME="jenkins-agent-3" |
946 | |
947 | |
948 | # Log file location for use in Debian init script |
949 | -JENKINS_SLAVE_LOG=/var/log/jenkins/$NAME.log |
950 | +JENKINS_Agent_LOG=/var/log/jenkins/$NAME.log |
951 | |
952 | # OS LIMITS SETUP |
953 | # comment this out to observe /etc/security/limits.conf |
954 | @@ -55,5 +55,5 @@ JENKINS_SLAVE_LOG=/var/log/jenkins/$NAME.log |
955 | # to change the OS limits setup. |
956 | MAXOPENFILES=8192 |
957 | |
958 | -# Arguments to pass to jenkins slave on startup |
959 | -JENKINS_ARGS="-jnlpUrl $JENKINS_URL/computer/$JENKINS_HOSTNAME/slave-agent.jnlp" |
960 | \ No newline at end of file |
961 | +# Arguments to pass to jenkins agent on startup |
962 | +JENKINS_ARGS="-jnlpUrl $JENKINS_URL/computer/$JENKINS_HOSTNAME/agent-agent.jnlp" |
963 | \ No newline at end of file |
964 | diff --git a/tests/unit/test_jenkins_slave.py b/tests/unit/test_jenkins_agent.py |
965 | similarity index 64% |
966 | rename from tests/unit/test_jenkins_slave.py |
967 | rename to tests/unit/test_jenkins_agent.py |
968 | index 1300c73..18f6965 100644 |
969 | --- a/tests/unit/test_jenkins_slave.py |
970 | +++ b/tests/unit/test_jenkins_agent.py |
971 | @@ -19,10 +19,10 @@ from charms.layer import status # NOQA: E402 |
972 | |
973 | # Add path to where our reactive layer lives and import. |
974 | sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))) |
975 | -from reactive import jenkins_slave # NOQA: E402 |
976 | +from reactive import jenkins_agent # NOQA: E402 |
977 | |
978 | |
979 | -INITIAL_CONF = 'tests/unit/files/jenkins-slave-default' |
980 | +INITIAL_CONF = 'tests/unit/files/jenkins-agent-default' |
981 | |
982 | |
983 | class TestSetDefaultConf(unittest.TestCase): |
984 | @@ -56,7 +56,7 @@ class TestSetDefaultConf(unittest.TestCase): |
985 | patcher = mock.patch('charmhelpers.core.hookenv.local_unit') |
986 | self.mock_local_unit = patcher.start() |
987 | self.addCleanup(patcher.stop) |
988 | - self.mock_local_unit.return_value = 'mock-jenkins-slave/0' |
989 | + self.mock_local_unit.return_value = 'mock-jenkins-agent/0' |
990 | |
991 | patcher = mock.patch('charmhelpers.core.hookenv.unit_private_ip') |
992 | self.mock_local_unit = patcher.start() |
993 | @@ -73,7 +73,7 @@ class TestSetDefaultConf(unittest.TestCase): |
994 | self.addCleanup(patcher.stop) |
995 | self.mock_log.return_value = ( |
996 | 'Linux', |
997 | - 'mock-jenkins-slave', |
998 | + 'mock-jenkins-agent', |
999 | '4.15.0-46-generic', |
1000 | '#49-Ubuntu SMP Wed Feb 6 09:33:07 UTC 2019', |
1001 | 'x86_64', |
1002 | @@ -92,11 +92,11 @@ class TestSetDefaultConf(unittest.TestCase): |
1003 | @mock.patch('charms.reactive.clear_flag') |
1004 | def test_hook_upgrade_charm_flags(self, clear_flag): |
1005 | '''Test correct flags set via upgrade-charm hook''' |
1006 | - jenkins_slave.upgrade_charm() |
1007 | + jenkins_agent.upgrade_charm() |
1008 | self.assertFalse(status.maintenance.assert_called()) |
1009 | expected = [ |
1010 | - mock.call('jenkins-slave.active'), |
1011 | - mock.call('jenkins-slave.installed'), |
1012 | + mock.call('jenkins-agent.active'), |
1013 | + mock.call('jenkins-agent.installed'), |
1014 | mock.call('nagios-nrpe.configured'), |
1015 | ] |
1016 | self.assertFalse(clear_flag.assert_has_calls(expected, any_order=True)) |
1017 | @@ -104,9 +104,9 @@ class TestSetDefaultConf(unittest.TestCase): |
1018 | @mock.patch('charms.reactive.clear_flag') |
1019 | def test_hook_config_changed(self, clear_flag): |
1020 | '''Test correct flags are set via config-changed charm hook''' |
1021 | - jenkins_slave.config_changed() |
1022 | + jenkins_agent.config_changed() |
1023 | self.assertFalse(status.maintenance.assert_called()) |
1024 | - expected = [mock.call('jenkins-slave.configured'), mock.call('nagios-nrpe.configured')] |
1025 | + expected = [mock.call('jenkins-agent.configured'), mock.call('nagios-nrpe.configured')] |
1026 | self.assertFalse(clear_flag.assert_has_calls(expected, any_order=True)) |
1027 | |
1028 | @mock.patch('charmhelpers.core.hookenv.config') |
1029 | @@ -114,33 +114,33 @@ class TestSetDefaultConf(unittest.TestCase): |
1030 | @mock.patch('charmhelpers.core.host.mkdir') |
1031 | @mock.patch('charmhelpers.core.host.service') |
1032 | @mock.patch('charmhelpers.core.host.user_exists') |
1033 | - @mock.patch('reactive.jenkins_slave.apt_purge') |
1034 | - @mock.patch('reactive.jenkins_slave.file_to_units') |
1035 | - @mock.patch('reactive.jenkins_slave.write_default_conf') |
1036 | + @mock.patch('reactive.jenkins_agent.apt_purge') |
1037 | + @mock.patch('reactive.jenkins_agent.file_to_units') |
1038 | + @mock.patch('reactive.jenkins_agent.write_default_conf') |
1039 | def test_hook_install( |
1040 | self, write_default_conf, file_to_units, apt_purge, user_exists, service, mkdir, adduser, config |
1041 | ): |
1042 | config.return_value = {'tools': 'some-tools-package'} |
1043 | apt.install_queued.return_value = True |
1044 | user_exists.return_value = False |
1045 | - jenkins_slave.install() |
1046 | + jenkins_agent.install() |
1047 | self.assertFalse(status.maintenance.assert_called()) |
1048 | |
1049 | expected = [mock.call(home_dir='/var/lib/jenkins', system_user=True, username='jenkins')] |
1050 | self.assertFalse(adduser.assert_has_calls(expected, any_order=True)) |
1051 | expected = [ |
1052 | mock.call('/var/lib/jenkins', group='jenkins', owner='jenkins', perms=0o755), |
1053 | - mock.call('/var/lib/jenkins/slaves', group='jenkins', owner='jenkins', perms=0o755), |
1054 | - mock.call('/var/lib/jenkins/slaves/mock-jenkins-slave-0', group='jenkins', owner='jenkins', perms=0o755), |
1055 | + mock.call('/var/lib/jenkins/agents', group='jenkins', owner='jenkins', perms=0o755), |
1056 | + mock.call('/var/lib/jenkins/agents/mock-jenkins-agent-0', group='jenkins', owner='jenkins', perms=0o755), |
1057 | mock.call('/var/log/jenkins', group='jenkins', owner='jenkins', perms=0o755), |
1058 | ] |
1059 | self.assertFalse(mkdir.assert_has_calls(expected, any_order=True)) |
1060 | - self.assertFalse(service.assert_has_calls([mock.call('enable', 'jenkins-slave')], any_order=True)) |
1061 | - self.assertFalse(apt_purge.assert_has_calls([mock.call(['jenkins-slave'])], any_order=True)) |
1062 | + self.assertFalse(service.assert_has_calls([mock.call('enable', 'jenkins-agent')], any_order=True)) |
1063 | + self.assertFalse(apt_purge.assert_has_calls([mock.call(['jenkins-agent'])], any_order=True)) |
1064 | expected = [ |
1065 | - mock.call('files/download-slave.sh', '/usr/local/sbin/download-slave.sh'), |
1066 | - mock.call('files/jenkins-slave-logrotate-config', '/etc/logrotate.d/jenkins-slave'), |
1067 | - mock.call('files/jenkins-slave-systemd-config', '/lib/systemd/system/jenkins-slave.service'), |
1068 | + mock.call('files/download-agent.sh', '/usr/local/sbin/download-agent.sh'), |
1069 | + mock.call('files/jenkins-agent-logrotate-config', '/etc/logrotate.d/jenkins-agent'), |
1070 | + mock.call('files/jenkins-agent-systemd-config', '/lib/systemd/system/jenkins-agent.service'), |
1071 | ] |
1072 | self.assertFalse(file_to_units.assert_has_calls(expected, any_order=True)) |
1073 | self.assertFalse(write_default_conf.assert_called()) |
1074 | @@ -152,96 +152,96 @@ class TestSetDefaultConf(unittest.TestCase): |
1075 | |
1076 | apt.install_queued.return_value = False |
1077 | apt_purge.reset_mock() |
1078 | - jenkins_slave.install() |
1079 | + jenkins_agent.install() |
1080 | self.assertFalse(apt_purge.assert_not_called()) |
1081 | |
1082 | apt.install_queued.return_value = True |
1083 | user_exists.return_value = True |
1084 | adduser.reset_mock() |
1085 | - jenkins_slave.install() |
1086 | + jenkins_agent.install() |
1087 | self.assertFalse(adduser.assert_not_called()) |
1088 | |
1089 | @mock.patch('charmhelpers.core.host.lsb_release') |
1090 | @mock.patch('charmhelpers.core.host.adduser') |
1091 | @mock.patch('charmhelpers.core.host.mkdir') |
1092 | - @mock.patch('reactive.jenkins_slave.file_to_units') |
1093 | - @mock.patch('reactive.jenkins_slave.write_default_conf') |
1094 | + @mock.patch('reactive.jenkins_agent.file_to_units') |
1095 | + @mock.patch('reactive.jenkins_agent.write_default_conf') |
1096 | def test_hook_install_trusty(self, write_default_conf, file_to_units, mkdir, adduser, lsb_release): |
1097 | apt.install_queued.return_value = True |
1098 | lsb_release.return_value = {'DISTRIB_CODENAME': 'trusty'} |
1099 | - jenkins_slave.install() |
1100 | + jenkins_agent.install() |
1101 | self.assertFalse(status.maintenance.assert_called()) |
1102 | |
1103 | - # file_to_units('files/jenkins-slave-upstart-config', '/etc/init/jenkins-slave.conf') |
1104 | - expected = [mock.call('files/jenkins-slave-upstart-config', '/etc/init/jenkins-slave.conf')] |
1105 | + # file_to_units('files/jenkins-agent-upstart-config', '/etc/init/jenkins-agent.conf') |
1106 | + expected = [mock.call('files/jenkins-agent-upstart-config', '/etc/init/jenkins-agent.conf')] |
1107 | self.assertFalse(file_to_units.assert_has_calls(expected, any_order=True)) |
1108 | |
1109 | @mock.patch('charms.reactive.clear_flag') |
1110 | @mock.patch('charms.reactive.set_flag') |
1111 | @mock.patch('charmhelpers.core.hookenv.config') |
1112 | @mock.patch('charmhelpers.core.unitdata.kv') |
1113 | - @mock.patch('reactive.jenkins_slave.write_default_conf') |
1114 | - @mock.patch('reactive.jenkins_slave.file_to_units') |
1115 | - def test_configure_jenkins_slave_no_url( |
1116 | + @mock.patch('reactive.jenkins_agent.write_default_conf') |
1117 | + @mock.patch('reactive.jenkins_agent.file_to_units') |
1118 | + def test_configure_jenkins_agent_no_url( |
1119 | self, file_to_units, write_default_conf, unitdata_kv, config, set_flag, clear_flag |
1120 | ): |
1121 | config.return_value = {} |
1122 | unitdata_kv.return_value = {} |
1123 | - jenkins_slave.configure_jenkins_slave() |
1124 | + jenkins_agent.configure_jenkins_agent() |
1125 | self.assertFalse(write_default_conf.assert_not_called()) |
1126 | self.assertFalse(status.blocked.assert_called()) |
1127 | - self.assertFalse(clear_flag.assert_has_calls([mock.call('jenkins-slave.active')], any_order=True)) |
1128 | + self.assertFalse(clear_flag.assert_has_calls([mock.call('jenkins-agent.active')], any_order=True)) |
1129 | |
1130 | @mock.patch('charms.reactive.clear_flag') |
1131 | @mock.patch('charms.reactive.set_flag') |
1132 | @mock.patch('charmhelpers.core.hookenv.config') |
1133 | @mock.patch('charmhelpers.core.unitdata.kv') |
1134 | - @mock.patch('reactive.jenkins_slave.write_default_conf') |
1135 | - @mock.patch('reactive.jenkins_slave.file_to_units') |
1136 | - def test_configure_jenkins_slave_master_url( |
1137 | + @mock.patch('reactive.jenkins_agent.write_default_conf') |
1138 | + @mock.patch('reactive.jenkins_agent.file_to_units') |
1139 | + def test_configure_jenkins_agent_jenkins_url( |
1140 | self, file_to_units, write_default_conf, unitdata_kv, config, set_flag, clear_flag |
1141 | ): |
1142 | - config.return_value = {'master_url': 'http://10.1.1.1:8080'} |
1143 | + config.return_value = {'jenkins_url': 'http://10.1.1.1:8080'} |
1144 | unitdata_kv.return_value = {} |
1145 | - jenkins_slave.configure_jenkins_slave() |
1146 | + jenkins_agent.configure_jenkins_agent() |
1147 | self.assertFalse(write_default_conf.assert_called_once_with('http://10.1.1.1:8080')) |
1148 | - self.assertFalse(set_flag.assert_has_calls([mock.call('jenkins-slave.configured')], any_order=True)) |
1149 | - expected = [mock.call('jenkins-slave.active'), mock.call('nagios-nrpe.configured')] |
1150 | + self.assertFalse(set_flag.assert_has_calls([mock.call('jenkins-agent.configured')], any_order=True)) |
1151 | + expected = [mock.call('jenkins-agent.active'), mock.call('nagios-nrpe.configured')] |
1152 | self.assertFalse(clear_flag.assert_has_calls(expected, any_order=True)) |
1153 | |
1154 | @mock.patch('charms.reactive.clear_flag') |
1155 | @mock.patch('charms.reactive.set_flag') |
1156 | @mock.patch('charmhelpers.core.hookenv.config') |
1157 | @mock.patch('charmhelpers.core.unitdata.kv') |
1158 | - @mock.patch('reactive.jenkins_slave.write_default_conf') |
1159 | - @mock.patch('reactive.jenkins_slave.file_to_units') |
1160 | - def test_configure_jenkins_slave_relation_url( |
1161 | + @mock.patch('reactive.jenkins_agent.write_default_conf') |
1162 | + @mock.patch('reactive.jenkins_agent.file_to_units') |
1163 | + def test_configure_jenkins_agent_relation_url( |
1164 | self, file_to_units, write_default_conf, unitdata_kv, config, set_flag, clear_flag |
1165 | ): |
1166 | config.return_value = {} |
1167 | unitdata_kv.return_value = {'url': 'http://10.22.22.22:8080'} |
1168 | - jenkins_slave.configure_jenkins_slave() |
1169 | + jenkins_agent.configure_jenkins_agent() |
1170 | self.assertTrue(write_default_conf.called_once_with('http://10.22.22.22:8080')) |
1171 | self.assertEqual(write_default_conf.call_args_list, [mock.call('http://10.22.22.22:8080', secret=None)]) |
1172 | - self.assertFalse(set_flag.assert_has_calls([mock.call('jenkins-slave.configured')], any_order=True)) |
1173 | - expected = [mock.call('jenkins-slave.active'), mock.call('nagios-nrpe.configured')] |
1174 | + self.assertFalse(set_flag.assert_has_calls([mock.call('jenkins-agent.configured')], any_order=True)) |
1175 | + expected = [mock.call('jenkins-agent.active'), mock.call('nagios-nrpe.configured')] |
1176 | self.assertFalse(clear_flag.assert_has_calls(expected, any_order=True)) |
1177 | |
1178 | @mock.patch('charms.reactive.clear_flag') |
1179 | @mock.patch('charms.reactive.set_flag') |
1180 | @mock.patch('charmhelpers.core.hookenv.config') |
1181 | @mock.patch('charmhelpers.core.unitdata.kv') |
1182 | - @mock.patch('reactive.jenkins_slave.write_default_conf') |
1183 | - @mock.patch('reactive.jenkins_slave.file_to_units') |
1184 | - def test_configure_jenkins_slave_relation_url_with_secret( |
1185 | + @mock.patch('reactive.jenkins_agent.write_default_conf') |
1186 | + @mock.patch('reactive.jenkins_agent.file_to_units') |
1187 | + def test_configure_jenkins_agent_relation_url_with_secret( |
1188 | self, file_to_units, write_default_conf, unitdata_kv, config, set_flag, clear_flag |
1189 | ): |
1190 | config.return_value = {} |
1191 | unitdata_kv.return_value = {'url': 'http://10.22.22.22:8080', 'secret': 'sekrit'} |
1192 | - jenkins_slave.configure_jenkins_slave() |
1193 | + jenkins_agent.configure_jenkins_agent() |
1194 | self.assertEqual(write_default_conf.call_args_list, [mock.call('http://10.22.22.22:8080', secret='sekrit')]) |
1195 | - self.assertFalse(set_flag.assert_has_calls([mock.call('jenkins-slave.configured')], any_order=True)) |
1196 | - expected = [mock.call('jenkins-slave.active'), mock.call('nagios-nrpe.configured')] |
1197 | + self.assertFalse(set_flag.assert_has_calls([mock.call('jenkins-agent.configured')], any_order=True)) |
1198 | + expected = [mock.call('jenkins-agent.active'), mock.call('nagios-nrpe.configured')] |
1199 | self.assertFalse(clear_flag.assert_has_calls(expected, any_order=True)) |
1200 | |
1201 | @mock.patch('charmhelpers.core.host.service_running') |
1202 | @@ -250,10 +250,10 @@ class TestSetDefaultConf(unittest.TestCase): |
1203 | def test_set_active_running(self, service_start, service_restart, service_running): |
1204 | '''Test service restarted when already running''' |
1205 | service_running.return_value = True |
1206 | - jenkins_slave.set_active() |
1207 | + jenkins_agent.set_active() |
1208 | self.assertFalse(status.maintenance.assert_called()) |
1209 | self.assertFalse(service_start.assert_not_called()) |
1210 | - self.assertFalse(service_restart.assert_called_once_with('jenkins-slave')) |
1211 | + self.assertFalse(service_restart.assert_called_once_with('jenkins-agent')) |
1212 | |
1213 | @mock.patch('charmhelpers.core.host.service_running') |
1214 | @mock.patch('charmhelpers.core.host.service_restart') |
1215 | @@ -261,9 +261,9 @@ class TestSetDefaultConf(unittest.TestCase): |
1216 | def test_set_active_not_running(self, service_start, service_restart, service_running): |
1217 | '''Test service restarted when not running''' |
1218 | service_running.return_value = False |
1219 | - jenkins_slave.set_active() |
1220 | + jenkins_agent.set_active() |
1221 | self.assertFalse(status.maintenance.assert_called()) |
1222 | - self.assertFalse(service_start.assert_called_once_with('jenkins-slave')) |
1223 | + self.assertFalse(service_start.assert_called_once_with('jenkins-agent')) |
1224 | self.assertFalse(service_restart.assert_not_called()) |
1225 | |
1226 | @mock.patch('charms.reactive.set_flag') |
1227 | @@ -271,29 +271,29 @@ class TestSetDefaultConf(unittest.TestCase): |
1228 | @mock.patch('charmhelpers.core.unitdata.kv') |
1229 | @mock.patch('charmhelpers.core.host.service_running') |
1230 | @mock.patch('charmhelpers.core.host.service_start') |
1231 | - def test_set_active_master_url_or_relation(self, service_start, service_running, unitdata_kv, config, set_flag): |
1232 | + def test_set_active_jenkins_url_or_relation(self, service_start, service_running, unitdata_kv, config, set_flag): |
1233 | service_running.return_value = False |
1234 | - config.return_value = {'master_url': 'http://ext-jenkins-be.internal:8080'} |
1235 | - jenkins_slave.set_active() |
1236 | - status.active.assert_called_once_with('ready - using jenkins http://ext-jenkins-be.internal:8080 (master_url)') |
1237 | + config.return_value = {'jenkins_url': 'http://ext-jenkins-be.internal:8080'} |
1238 | + jenkins_agent.set_active() |
1239 | + status.active.assert_called_once_with('ready - using jenkins http://ext-jenkins-be.internal:8080 (jenkins_url)') |
1240 | |
1241 | config.return_value = {} |
1242 | status.active.reset_mock() |
1243 | - jenkins_slave.set_active() |
1244 | + jenkins_agent.set_active() |
1245 | status.active.assert_called_once_with('ready - using jenkins from relation') |
1246 | |
1247 | @mock.patch('charms.reactive.clear_flag') |
1248 | @mock.patch('charms.reactive.set_flag') |
1249 | - def test_hook_slave_relation_changed_flags(self, set_flag, clear_flag): |
1250 | - jenkins_slave.slave_relation_changed() |
1251 | - expected = [mock.call('jenkins-slave.configured'), mock.call('slave-relation.configured')] |
1252 | + def test_hook_agent_relation_changed_flags(self, set_flag, clear_flag): |
1253 | + jenkins_agent.agent_relation_changed() |
1254 | + expected = [mock.call('jenkins-agent.configured'), mock.call('agent-relation.configured')] |
1255 | self.assertFalse(clear_flag.assert_has_calls(expected, any_order=True)) |
1256 | - self.assertFalse(set_flag.assert_has_calls([mock.call('slave-relation.available')], any_order=True)) |
1257 | + self.assertFalse(set_flag.assert_has_calls([mock.call('agent-relation.available')], any_order=True)) |
1258 | |
1259 | @mock.patch('charms.reactive.clear_flag') |
1260 | - def test_hook_slave_relation_removed_flags(self, clear_flag): |
1261 | - jenkins_slave.slave_relation_removed() |
1262 | - self.assertFalse(clear_flag.assert_has_calls([mock.call('slave-relation.available')], any_order=True)) |
1263 | + def test_hook_agent_relation_removed_flags(self, clear_flag): |
1264 | + jenkins_agent.agent_relation_removed() |
1265 | + self.assertFalse(clear_flag.assert_has_calls([mock.call('agent-relation.available')], any_order=True)) |
1266 | |
1267 | @mock.patch('charms.reactive.clear_flag') |
1268 | @mock.patch('charms.reactive.set_flag') |
1269 | @@ -301,55 +301,55 @@ class TestSetDefaultConf(unittest.TestCase): |
1270 | @mock.patch('charmhelpers.core.hookenv.relation_get') |
1271 | @mock.patch('charmhelpers.core.hookenv.relation_set') |
1272 | @mock.patch('charmhelpers.core.unitdata.kv') |
1273 | - @mock.patch('reactive.jenkins_slave.write_default_conf') |
1274 | - def test_hook_slave_relation( |
1275 | + @mock.patch('reactive.jenkins_agent.write_default_conf') |
1276 | + def test_hook_agent_relation( |
1277 | self, write_default_conf, unitdata_kv, relation_set, relation_get, config, set_flag, clear_flag |
1278 | ): |
1279 | - config.return_value = {'master_url': ''} |
1280 | + config.return_value = {'jenkins_url': ''} |
1281 | relation_get.return_value = 'http://10.1.1.1:8080' |
1282 | - jenkins_slave.slave_relation() |
1283 | + jenkins_agent.agent_relation() |
1284 | expected = [mock.call('url'), mock.call('secret')] |
1285 | self.assertFalse(relation_get.assert_has_calls(expected)) |
1286 | - self.assertFalse(clear_flag.assert_called_once_with('jenkins-slave.active')) |
1287 | - self.assertFalse(set_flag.assert_called_once_with('slave-relation.configured')) |
1288 | + self.assertFalse(clear_flag.assert_called_once_with('jenkins-agent.active')) |
1289 | + self.assertFalse(set_flag.assert_called_once_with('agent-relation.configured')) |
1290 | expected = [ |
1291 | mock.call(executors=3), |
1292 | mock.call(labels='x86_64'), |
1293 | - mock.call(slavehost='mock-jenkins-slave-0'), |
1294 | - mock.call(slaveaddress='10.1.2.3'), |
1295 | + mock.call(agenthost='mock-jenkins-agent-0'), |
1296 | + mock.call(agentaddress='10.1.2.3'), |
1297 | ] |
1298 | self.assertFalse(relation_set.assert_has_calls(expected, any_order=True)) |
1299 | |
1300 | - config.return_value = {'master_url': '', 'labels': 'label1 label2'} |
1301 | + config.return_value = {'jenkins_url': '', 'labels': 'label1 label2'} |
1302 | relation_get.return_value = 'http://10.1.1.1:8080' |
1303 | relation_set.reset_mock() |
1304 | - jenkins_slave.slave_relation() |
1305 | + jenkins_agent.agent_relation() |
1306 | expected = [ |
1307 | mock.call(executors=3), |
1308 | mock.call(labels='label1 label2'), |
1309 | - mock.call(slavehost='mock-jenkins-slave-0'), |
1310 | - mock.call(slaveaddress='10.1.2.3'), |
1311 | + mock.call(agenthost='mock-jenkins-agent-0'), |
1312 | + mock.call(agentaddress='10.1.2.3'), |
1313 | ] |
1314 | self.assertFalse(relation_set.assert_has_calls(expected, any_order=True)) |
1315 | |
1316 | @mock.patch('charmhelpers.core.hookenv.config') |
1317 | @mock.patch('charmhelpers.core.hookenv.relation_get') |
1318 | @mock.patch('charms.reactive.set_flag') |
1319 | - def test_hook_slave_relation_master_url_set(self, set_flag, relation_get, config): |
1320 | - config.return_value = {'master_url': 'http://10.1.1.1:8080'} |
1321 | + def test_hook_agent_relation_jenkins_url_set(self, set_flag, relation_get, config): |
1322 | + config.return_value = {'jenkins_url': 'http://10.1.1.1:8080'} |
1323 | relation_get.return_value = '' |
1324 | - jenkins_slave.slave_relation() |
1325 | + jenkins_agent.agent_relation() |
1326 | self.assertFalse(relation_get.assert_not_called()) |
1327 | - self.assertFalse(set_flag.assert_called_once_with('slave-relation.configured')) |
1328 | + self.assertFalse(set_flag.assert_called_once_with('agent-relation.configured')) |
1329 | |
1330 | @mock.patch('charms.reactive.clear_flag') |
1331 | @mock.patch('charms.reactive.set_flag') |
1332 | @mock.patch('charmhelpers.core.hookenv.config') |
1333 | @mock.patch('charmhelpers.core.hookenv.relation_get') |
1334 | - def test_hook_slave_relation_relation_url_not_set(self, relation_get, config, set_flag, clear_flag): |
1335 | - config.return_value = {'master_url': ''} |
1336 | + def test_hook_agent_relation_relation_url_not_set(self, relation_get, config, set_flag, clear_flag): |
1337 | + config.return_value = {'jenkins_url': ''} |
1338 | relation_get.return_value = '' |
1339 | - jenkins_slave.slave_relation() |
1340 | + jenkins_agent.agent_relation() |
1341 | self.assertFalse(clear_flag.assert_not_called()) |
1342 | |
1343 | @mock.patch('charms.reactive.set_flag') |
1344 | @@ -358,11 +358,11 @@ class TestSetDefaultConf(unittest.TestCase): |
1345 | def test_configure_nagios(self, nrpe, get_nagios_hostname, set_flag): |
1346 | get_nagios_hostname.return_value = 'some-host.local' |
1347 | nrpe_instance_mock = nrpe(get_nagios_hostname(), primary=True) |
1348 | - jenkins_slave.configure_nagios(None) |
1349 | + jenkins_agent.configure_nagios(None) |
1350 | status.maintenance.assert_called() |
1351 | want = [ |
1352 | mock.call( |
1353 | - 'jenkins_slave_ps', 'Jenkins Slave Process', '/usr/lib/nagios/plugins/check_procs -c 1:1 -a slave.jar' |
1354 | + 'jenkins_agent_ps', 'Jenkins Agent Process', '/usr/lib/nagios/plugins/check_procs -c 1:1 -a agent.jar' |
1355 | ) |
1356 | ] |
1357 | nrpe_instance_mock.add_check.assert_has_calls(want, any_order=True) |
1358 | @@ -373,17 +373,17 @@ class TestSetDefaultConf(unittest.TestCase): |
1359 | set_flag.assert_has_calls(want, any_order=True) |
1360 | |
1361 | def test_write_default_conf_update(self): |
1362 | - jenkins_slave.write_default_conf('http://10.1.1.1:8080', self.user, self.group, self.conf_file) |
1363 | + jenkins_agent.write_default_conf('http://10.1.1.1:8080', self.user, self.group, self.conf_file) |
1364 | self.assertTrue(conf_match(self.conf_file, 'JENKINS_URL', 'http://10.1.1.1:8080')) |
1365 | |
1366 | def test_write_default_conf_reset(self): |
1367 | - jenkins_slave.write_default_conf(None, self.user, self.group, self.conf_file) |
1368 | + jenkins_agent.write_default_conf(None, self.user, self.group, self.conf_file) |
1369 | self.assertTrue(conf_match(self.conf_file, '#JENKINS_URL', '')) |
1370 | |
1371 | def test_file_to_units_executable_sh(self): |
1372 | - source = os.path.join(self.charm_dir, 'files/download-slave.sh') |
1373 | + source = os.path.join(self.charm_dir, 'files/download-agent.sh') |
1374 | dest = os.path.join(self.tmpdir, os.path.basename(source)) |
1375 | - jenkins_slave.file_to_units(source, dest, owner=self.user, group=self.group) |
1376 | + jenkins_agent.file_to_units(source, dest, owner=self.user, group=self.group) |
1377 | with open(dest, 'rb') as fh: |
1378 | want = fh.read().decode('utf-8') |
1379 | self.assertTrue(conf_equals(source, want)) |
1380 | @@ -394,7 +394,7 @@ class TestSetDefaultConf(unittest.TestCase): |
1381 | def test_file_to_units_executable_py(self): |
1382 | source = os.path.join(self.charm_dir, 'tests/unit/files/somefile.py') |
1383 | dest = os.path.join(self.tmpdir, os.path.basename(source)) |
1384 | - jenkins_slave.file_to_units(source, dest, owner=self.user, group=self.group) |
1385 | + jenkins_agent.file_to_units(source, dest, owner=self.user, group=self.group) |
1386 | with open(dest, 'rb') as fh: |
1387 | want = fh.read().decode('utf-8') |
1388 | self.assertTrue(conf_equals(source, want)) |
1389 | @@ -403,9 +403,9 @@ class TestSetDefaultConf(unittest.TestCase): |
1390 | self.assertTrue(os.access(dest, os.X_OK)) |
1391 | |
1392 | def test_file_to_units_non_executable(self): |
1393 | - source = os.path.join(self.charm_dir, 'files/jenkins-slave-logrotate-config') |
1394 | + source = os.path.join(self.charm_dir, 'files/jenkins-agent-logrotate-config') |
1395 | dest = os.path.join(self.tmpdir, os.path.basename(source)) |
1396 | - jenkins_slave.file_to_units(source, dest, owner=self.user, group=self.group) |
1397 | + jenkins_agent.file_to_units(source, dest, owner=self.user, group=self.group) |
1398 | with open(dest, 'rb') as fh: |
1399 | want = fh.read().decode('utf-8') |
1400 | self.assertTrue(conf_equals(dest, want)) |
1401 | @@ -416,7 +416,7 @@ class TestSetDefaultConf(unittest.TestCase): |
1402 | def test_file_to_units_non_executable_x_on_disk(self): |
1403 | source = os.path.join(self.charm_dir, 'tests/unit/files/somefile') |
1404 | dest = os.path.join(self.tmpdir, os.path.basename(source)) |
1405 | - jenkins_slave.file_to_units(source, dest, owner=self.user, group=self.group) |
1406 | + jenkins_agent.file_to_units(source, dest, owner=self.user, group=self.group) |
1407 | with open(dest, 'rb') as fh: |
1408 | want = fh.read().decode('utf-8') |
1409 | self.assertTrue(conf_equals(source, want)) |
1410 | @@ -427,7 +427,7 @@ class TestSetDefaultConf(unittest.TestCase): |
1411 | def test_file_to_units_with_perms(self): |
1412 | source = os.path.join(self.charm_dir, 'tests/unit/files/somefile') |
1413 | dest = os.path.join(self.tmpdir, os.path.basename(source)) |
1414 | - jenkins_slave.file_to_units(source, dest, owner=self.user, group=self.group, perms=0o640) |
1415 | + jenkins_agent.file_to_units(source, dest, owner=self.user, group=self.group, perms=0o640) |
1416 | with open(dest, 'rb') as fh: |
1417 | want = fh.read().decode('utf-8') |
1418 | self.assertTrue(conf_equals(source, want)) |