34
35
def validate_hooks(client, unit_state, hook_names):
36
37
# Assemble a list of valid hooks for the formula.
38
valid_hooks = ["start", "stop", "install"]
38
39
service_manager = ServiceStateManager(client)
39
40
endpoints = yield service_manager.get_relation_endpoints(
40
41
unit_state.service_name)
41
42
endpoint_names = [ep.relation_name for ep in endpoints]
42
43
for endpoint_name in endpoint_names:
43
valid_hooks.append("%s-relation-changed" % endpoint_name)
44
valid_hooks.append("%s-relation-broken" % endpoint_name)
45
valid_hooks.extend(["start", "stop", "install"])
45
endpoint_name + "-relation-joined",
46
endpoint_name + "-relation-changed",
47
endpoint_name + "-relation-departed",
48
endpoint_name + "-relation-broken",
47
51
# Verify the debug names.
48
52
for hook_name in hook_names:
91
95
"Enabling hook debug on unit (%r)..." % options.unit_name)
92
96
yield unit.enable_hook_debug(options.hook_names)
94
# Connect via ssh and start screen.
98
# Connect via ssh and start tmux.
95
99
options.log.info("Connecting to remote machine...")
97
"ssh -t ubuntu@%s sudo byobu -xRS %s-hook-debug -t shell" % (
98
ip_address, options.unit_name.replace("/", "-")))
101
# Encode the script as base64 so that we can deliver it with a single
102
# ssh command while still retaining standard input on the terminal fd.
103
script = SCRIPT.replace("{unit_name}", options.unit_name)
104
script_b64 = base64.encodestring(script).replace("\n", "").strip()
105
cmd = '"F=`mktemp`; echo %s | base64 -d > \$F; . \$F"' % script_b64
107
# Yield to facilitate testing.
108
yield os.system("ssh -t ubuntu@%s 'sudo /bin/bash -c %s'" % (ip_address, cmd))
100
110
options.log.info("Debug session ended.")
101
111
# Ends hook debugging.
102
112
yield client.close()
116
# Wait for tmux to be installed.
117
while [ ! -f /usr/bin/tmux ]; do
121
# Create a sane configuration (no green bars, please!)
122
[ -f ~/.tmux.conf ] || cat > ~/.tmux.conf <<END
125
set-option -g status-bg black
126
set-option -g status-fg white
128
set-window-option -g window-status-current-bg red
129
set-window-option -g window-status-current-attr bright
131
set-option -g status-right ''
134
set-option -g pane-border-fg white
135
set-option -g pane-active-border-fg white
137
# Monitor activity on windows
138
set-window-option -g monitor-activity on
140
# Screen bindings, since people are more familiar with that.
141
set-option -g prefix C-a
145
bind | split-window -h
146
bind - split-window -v
148
# Fix CTRL-PGUP/PGDOWN for vim
149
set-window-option -g xterm-keys on
151
# Prevent ESC key from adding delay and breaking Vim's ESC > arrow key
152
set-option -s escape-time 0
156
tmux new-session -d -s {unit_name} 2> /dev/null || true
157
tmux attach -t {unit_name}