Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitcba250f

Browse files
committed
Check whether locksmithctl is installed
When running tasks that depend on it. The package is uninstalled by Puppetwhen `govuk_unattended_reboots::enabled` is false (default). This results inthe following output when a task is run: (fabric)➜ fabric-scripts git:(master) fab preview locksmith.status [etcd-1.management] run: /usr/bin/locksmithctl -endpoint='http://etcd-1.management:4001,http://etcd-2.management:4001,http://etcd-3.management:4001' status [etcd-1.management] out: /bin/bash: /usr/bin/locksmithctl: No such file or directory [etcd-1.management] out: Fatal error: run() received nonzero return code 127 while executing! Requested: /usr/bin/locksmithctl -endpoint='http://etcd-1.management:4001,http://etcd-2.management:4001,http://etcd-3.management:4001' status Executed: /bin/bash -l -c "/usr/bin/locksmithctl -endpoint='http://etcd-1.management:4001,http://etcd-2.management:4001,http://etcd-3.management:4001' status" Aborting. Disconnecting from etcd-1.management... done. Disconnecting from jumpbox.preview.alphagov.co.uk... done.By checking whether the command is present first we can provide a simplererror with more context: (fabric)➜ fabric-scripts git:(check_locksmithctl_installed) fab preview locksmith.status Fatal error: locksmithctl is not installed. Perhaps unattended_reboots are disabled? Aborting. Disconnecting from etcd-1.management... done. Disconnecting from jumpbox.preview.alphagov.co.uk... done.I thought about decorating this with `@runs_once` but actually we probablywon't call locksmith multiple times in the same run, we'd want to check forevery machine it's run on, and it's pretty cheap to check.
1 parent43c8289 commitcba250f

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

‎locksmith.py‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
11
fromfabric.apiimportrun,task
2+
fromfabric.utilsimporterror
3+
importfabric.contrib.files
24
importutil
35

46
etcd_cluster='http://etcd-1.management:4001,http://etcd-2.management:4001,http://etcd-3.management:4001'
7+
locksmithctl='/usr/bin/locksmithctl'
8+
9+
defcheck_locksmithctl():
10+
ifnotfabric.contrib.files.exists(locksmithctl):
11+
error('locksmithctl is not installed. Perhaps unattended_reboots are disabled?')
512

613
@task
714
defstatus():
815
"""Get the status of locksmith"""
916
util.use_random_host('class-etcd')
10-
run("/usr/bin/locksmithctl -endpoint='{0}' status".format(etcd_cluster))
17+
check_locksmithctl()
18+
run("{0} -endpoint='{1}' status".format(locksmithctl,etcd_cluster))
1119

1220
@task
1321
defunlock(machine_name):
1422
"""Unlock a machine with locksmith"""
1523
util.use_random_host('class-etcd')
16-
run("/usr/bin/locksmithctl -endpoint='{0}' unlock '{1}'".format(etcd_cluster,machine_name))
24+
check_locksmithctl()
25+
run("{0} -endpoint='{1}' unlock '{2}'".format(locksmithctl,etcd_cluster,machine_name))

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp