Merge lp:~rvb/maas/amt_wsman-1.7 into lp:maas/1.7
- amt_wsman-1.7
- Merge into 1.7
Status: | Merged | ||||
---|---|---|---|---|---|
Merged at revision: | 3349 | ||||
Proposed branch: | lp:~rvb/maas/amt_wsman-1.7 | ||||
Merge into: | lp:maas/1.7 | ||||
Diff against target: |
278 lines (+180/-19) 1 file modified
etc/maas/templates/power/amt.template (+180/-19) |
||||
To merge this branch: | bzr merge lp:~rvb/maas/amt_wsman-1.7 | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Raphaël Badin (community) | Approve | ||
Review via email: mp+251618@code.launchpad.net |
Commit message
Backport revision 3567: AMT power template changes to use in place of for any AMT versions > 8.
Description of the change
MAAS Lander (maas-lander) wrote : | # |
The attempt to merge lp:~rvb/maas/amt_wsman-1.7 into lp:maas/1.7 failed. Below is the output from the failed tests.
Ign http://
Get:1 http://
Get:2 http://
Ign http://
Ign http://
Hit http://
Get:3 http://
Hit http://
Get:4 http://
Get:5 http://
Get:6 http://
Hit http://
Get:7 http://
Get:8 http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Get:9 http://
Get:10 http://
Get:11 http://
Get:12 http://
Hit http://
Hit http://
Ign http://
Ign http://
Fetched 1,509 kB in 3s (503 kB/s)
Reading package lists...
sudo DEBIAN_
--
MAAS Lander (maas-lander) wrote : | # |
The attempt to merge lp:~rvb/maas/amt_wsman-1.7 into lp:maas/1.7 failed. Below is the output from the failed tests.
Ign http://
Get:1 http://
Ign http://
Get:2 http://
Ign http://
Hit http://
Get:3 http://
Hit http://
Get:4 http://
Get:5 http://
Get:6 http://
Hit http://
Get:7 http://
Get:8 http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Get:9 http://
Get:10 http://
Get:11 http://
Get:12 http://
Hit http://
Hit http://
Ign http://
Ign http://
Fetched 1,509 kB in 4s (359 kB/s)
Reading package lists...
sudo DEBIAN_
--
MAAS Lander (maas-lander) wrote : | # |
The attempt to merge lp:~rvb/maas/amt_wsman-1.7 into lp:maas/1.7 failed. Below is the output from the failed tests.
Ign http://
Get:1 http://
Get:2 http://
Ign http://
Ign http://
Hit http://
Get:3 http://
Hit http://
Get:4 http://
Get:5 http://
Get:6 http://
Hit http://
Get:7 http://
Get:8 http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Get:9 http://
Get:10 http://
Get:11 http://
Get:12 http://
Hit http://
Hit http://
Ign http://
Ign http://
Fetched 1,509 kB in 3s (407 kB/s)
Reading package lists...
sudo DEBIAN_
--
MAAS Lander (maas-lander) wrote : | # |
The attempt to merge lp:~rvb/maas/amt_wsman-1.7 into lp:maas/1.7 failed. Below is the output from the failed tests.
Ign http://
Hit http://
Ign http://
Hit http://
Ign http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Ign http://
Ign http://
Reading package lists...
sudo DEBIAN_
--
MAAS Lander (maas-lander) wrote : | # |
The attempt to merge lp:~rvb/maas/amt_wsman-1.7 into lp:maas/1.7 failed. Below is the output from the failed tests.
Ign http://
Get:1 http://
Get:2 http://
Ign http://
Ign http://
Hit http://
Get:3 http://
Hit http://
Get:4 http://
Get:5 http://
Get:6 http://
Get:7 http://
Hit http://
Get:8 http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Get:9 http://
Get:10 http://
Get:11 http://
Get:12 http://
Hit http://
Hit http://
Ign http://
Ign http://
Fetched 1,509 kB in 3s (405 kB/s)
Reading package lists...
sudo DEBIAN_
--
Preview Diff
1 | === modified file 'etc/maas/templates/power/amt.template' | |||
2 | --- etc/maas/templates/power/amt.template 2015-01-29 17:17:57 +0000 | |||
3 | +++ etc/maas/templates/power/amt.template 2015-03-03 15:50:25 +0000 | |||
4 | @@ -38,17 +38,27 @@ | |||
5 | 38 | exit $1 | 38 | exit $1 |
6 | 39 | } | 39 | } |
7 | 40 | 40 | ||
8 | 41 | # XXX: bladernr 2015-02-04 bug=1331214: AMT ver > 8 needs wsman not amttool | ||
9 | 42 | # Check the version of AMT on node. | ||
10 | 43 | check_amt_version() { | ||
11 | 44 | amt_version=$(issue_amt_command info 2>&1 | grep version | awk '{print $NF}') | ||
12 | 45 | major_version=$(echo $amt_version | awk -F'.' '{print $1}') | ||
13 | 46 | return $major_version | ||
14 | 47 | } | ||
15 | 48 | |||
16 | 41 | 49 | ||
17 | 42 | # Perform a command using amttool. | 50 | # Perform a command using amttool. |
18 | 43 | issue_amt_command() { | 51 | issue_amt_command() { |
19 | 44 | LC_ALL='C' AMT_PASSWORD="$power_pass" amttool "$ip_address" "$@" | 52 | LC_ALL='C' AMT_PASSWORD="$power_pass" amttool "$ip_address" "$@" |
20 | 45 | } | 53 | } |
21 | 46 | 54 | ||
22 | 55 | |||
23 | 47 | # Check that amttool is present. | 56 | # Check that amttool is present. |
24 | 48 | check_amt_command() { | 57 | check_amt_command() { |
25 | 49 | command -v amttool >/dev/null 2>&1 || { fail 2 "Missing amttool (amtterm package)"; } | 58 | command -v amttool >/dev/null 2>&1 || { fail 2 "Missing amttool (amtterm package)"; } |
26 | 50 | } | 59 | } |
27 | 51 | 60 | ||
28 | 61 | |||
29 | 52 | # Check that a node host has been passed. | 62 | # Check that a node host has been passed. |
30 | 53 | check_bmc_host() { | 63 | check_bmc_host() { |
31 | 54 | if [ -z "$ip_address" ]; then | 64 | if [ -z "$ip_address" ]; then |
32 | @@ -59,11 +69,11 @@ | |||
33 | 59 | fi | 69 | fi |
34 | 60 | } | 70 | } |
35 | 61 | 71 | ||
38 | 62 | # Ask for node's power state: 'on' or 'off'. | 72 | |
39 | 63 | query_state() { | 73 | # Ask for node's power state: 'on' or 'off', via amttool. |
40 | 74 | amt_query_state() { | ||
41 | 64 | # Retry the state if it fails because it often fails the first time. | 75 | # Retry the state if it fails because it often fails the first time. |
42 | 65 | local state= | 76 | local state= |
43 | 66 | local count= | ||
44 | 67 | for attempts in $(seq 0 10) | 77 | for attempts in $(seq 0 10) |
45 | 68 | do | 78 | do |
46 | 69 | state=$(issue_amt_command info | grep '^Powerstate:' | awk '{print $2}') | 79 | state=$(issue_amt_command info | grep '^Powerstate:' | awk '{print $2}') |
47 | @@ -91,21 +101,20 @@ | |||
48 | 91 | } | 101 | } |
49 | 92 | 102 | ||
50 | 93 | 103 | ||
53 | 94 | # Power-cycle the machine, and boot it using the requested boot mode. | 104 | # Power-cycle the machine via amttool, and boot it using the requested boot mode. |
54 | 95 | restart() { | 105 | amt_restart() { |
55 | 96 | yes | issue_amt_command powercycle "$amt_boot_mode" | 106 | yes | issue_amt_command powercycle "$amt_boot_mode" |
56 | 97 | } | 107 | } |
57 | 98 | 108 | ||
58 | 99 | 109 | ||
62 | 100 | # Power the machine on, and boot it using PXE. | 110 | # Power the machine on via amttool, and boot it using PXE. |
63 | 101 | power_on() { | 111 | amt_power_on() { |
61 | 102 | local attempts= | ||
64 | 103 | # Try several times. Power commands often fail the first time. | 112 | # Try several times. Power commands often fail the first time. |
65 | 104 | for attempts in $(seq 0 10) | 113 | for attempts in $(seq 0 10) |
66 | 105 | do | 114 | do |
67 | 106 | # Issue the AMT command; amttool will prompt for confirmation. | 115 | # Issue the AMT command; amttool will prompt for confirmation. |
68 | 107 | yes | issue_amt_command powerup "$amt_boot_mode" | 116 | yes | issue_amt_command powerup "$amt_boot_mode" |
70 | 108 | if [ "$(query_state)" = 'on' ] | 117 | if [ "$(amt_query_state)" = 'on' ] |
71 | 109 | then | 118 | then |
72 | 110 | # Success. Machine is on. | 119 | # Success. Machine is on. |
73 | 111 | return 0 | 120 | return 0 |
74 | @@ -116,13 +125,12 @@ | |||
75 | 116 | } | 125 | } |
76 | 117 | 126 | ||
77 | 118 | 127 | ||
81 | 119 | # Power the machine off. | 128 | # Power the machine off amttool. |
82 | 120 | power_off() { | 129 | amt_power_off() { |
80 | 121 | local attempts= | ||
83 | 122 | # Try several times. Power commands often fail the first time. | 130 | # Try several times. Power commands often fail the first time. |
84 | 123 | for attempts in $(seq 0 10) | 131 | for attempts in $(seq 0 10) |
85 | 124 | do | 132 | do |
87 | 125 | if [ "$(query_state)" = 'off' ] | 133 | if [ "$(amt_query_state)" = 'off' ] |
88 | 126 | then | 134 | then |
89 | 127 | # Success. Machine is off. | 135 | # Success. Machine is off. |
90 | 128 | return 0 | 136 | return 0 |
91 | @@ -135,28 +143,181 @@ | |||
92 | 135 | } | 143 | } |
93 | 136 | 144 | ||
94 | 137 | 145 | ||
95 | 146 | # Check that wsman is present. | ||
96 | 147 | check_wsman_command() { | ||
97 | 148 | command -v wsman >/dev/null 2>&1 || { fail 2 "Missing wsman (wsmancli package)"; } | ||
98 | 149 | } | ||
99 | 150 | |||
100 | 151 | # Issue the wsman command. | ||
101 | 152 | issue_wsman_command() { | ||
102 | 153 | POWER_TEMPLATE_HEAD=' | ||
103 | 154 | <p:RequestPowerStateChange_INPUT xmlns:p="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_PowerManagementService"> | ||
104 | 155 | <p:PowerState>' | ||
105 | 156 | POWER_TEMPLATE_TAIL='</p:PowerState> | ||
106 | 157 | <p:ManagedElement xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" | ||
107 | 158 | xmlns:wsman="http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd"> | ||
108 | 159 | <wsa:Address>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:Address> | ||
109 | 160 | <wsa:ReferenceParameters> | ||
110 | 161 | <wsman:ResourceURI>http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ComputerSystem</wsman:ResourceURI> | ||
111 | 162 | <wsman:SelectorSet> | ||
112 | 163 | <wsman:Selector Name="CreationClassName">CIM_ComputerSystem</wsman:Selector> | ||
113 | 164 | <wsman:Selector Name="Name">ManagedSystem</wsman:Selector> | ||
114 | 165 | </wsman:SelectorSet> | ||
115 | 166 | </wsa:ReferenceParameters> | ||
116 | 167 | </p:ManagedElement> | ||
117 | 168 | </p:RequestPowerStateChange_INPUT> | ||
118 | 169 | ' | ||
119 | 170 | # Usage: issue_wsman_command on|off|restart|query | ||
120 | 171 | ACTION="invoke -a RequestPowerStateChange" | ||
121 | 172 | SCHEMA_URI='http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_PowerManagementService?SystemCreationClassName="CIM_ComputerSystem",SystemName="Intel(r) AMT",CreationClassName="CIM_PowerManagementService",Name="Intel(r) AMT Power Management Service"' | ||
122 | 173 | OPTS="--port 16992 --hostname $ip_address --username admin -p $power_pass -V -v" | ||
123 | 174 | case $1 in | ||
124 | 175 | on) | ||
125 | 176 | template=${POWER_TEMPLATE_HEAD}2${POWER_TEMPLATE_TAIL} | ||
126 | 177 | echo ${template} | wsman ${ACTION} "${SCHEMA_URI}" ${OPTS} -J - | ||
127 | 178 | ;; | ||
128 | 179 | off) | ||
129 | 180 | template=${POWER_TEMPLATE_HEAD}8${POWER_TEMPLATE_TAIL} | ||
130 | 181 | echo ${template} | wsman ${ACTION} "${SCHEMA_URI}" ${OPTS} -J - | ||
131 | 182 | ;; | ||
132 | 183 | restart) | ||
133 | 184 | template=${POWER_TEMPLATE_HEAD}10${POWER_TEMPLATE_TAIL} | ||
134 | 185 | echo ${template} | wsman ${ACTION} "${SCHEMA_URI}" ${OPTS} -J - | ||
135 | 186 | ;; | ||
136 | 187 | query) | ||
137 | 188 | ACTION="enumerate" | ||
138 | 189 | SCHEMA_URI='http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_AssociatedPowerManagementService' | ||
139 | 190 | OPTS="${OPTS} -o -j utf-8" | ||
140 | 191 | wsman ${ACTION} "${SCHEMA_URI}" ${OPTS} | ||
141 | 192 | ;; | ||
142 | 193 | *) | ||
143 | 194 | fail 2 "Unknown command issued to wsman" | ||
144 | 195 | ;; | ||
145 | 196 | esac | ||
146 | 197 | } | ||
147 | 198 | |||
148 | 199 | |||
149 | 200 | # Ask for node's power state: 'on' or 'off', via wsman. | ||
150 | 201 | wsman_query_state() { | ||
151 | 202 | # Retry the state if it fails because it often fails the first time. | ||
152 | 203 | local state= | ||
153 | 204 | for attempts in $(seq 0 10) | ||
154 | 205 | do | ||
155 | 206 | state=$(issue_wsman_command query | grep "h:PowerState" | awk -F [\<\>] '{print $3}') | ||
156 | 207 | if [ -n "$state" ] | ||
157 | 208 | then | ||
158 | 209 | break | ||
159 | 210 | fi | ||
160 | 211 | # Wait 1 second between retries. AMT controllers are generally very | ||
161 | 212 | # light and may not be comfortable with more frequent queries. | ||
162 | 213 | sleep 1 | ||
163 | 214 | done | ||
164 | 215 | case "$state" in | ||
165 | 216 | # There are a LOT of possible power states | ||
166 | 217 | # 1: Other 9: Power Cycle (Off - Hard) | ||
167 | 218 | # 2: On 10: Master Bus Reset | ||
168 | 219 | # 3: Sleep - Light 11: Diagnostic Interrupt (NMI) | ||
169 | 220 | # 4: Sleep - Deep 12: Off - Soft Graceful | ||
170 | 221 | # 5: Power Cycle (Off - Soft) 13: Off - Hard Graceful | ||
171 | 222 | # 6: Off - Hard 14: Master Bus Reset Graceful | ||
172 | 223 | # 7: Hibernate (Off - Soft) 15: Power Cycle (Off - Soft Graceful) | ||
173 | 224 | # 8: Off - Soft 16: Power Cycle (Off - Hard Graceful | ||
174 | 225 | # 17: Diagnostic Interrupt (INIT) | ||
175 | 226 | |||
176 | 227 | # These are all power states that indicate that the system is either ON or | ||
177 | 228 | # will resume function in an ON or Powered Up state (e.g. being power | ||
178 | 229 | # cycled currently) | ||
179 | 230 | [2,3,4,5,7,9,10,14,15,16]) | ||
180 | 231 | echo 'on' | ||
181 | 232 | ;; | ||
182 | 233 | # These 4 states should leave system completely powered down | ||
183 | 234 | [6,8,12,13]) | ||
184 | 235 | echo 'off' | ||
185 | 236 | ;; | ||
186 | 237 | *) | ||
187 | 238 | fail 1 "Got unknown power state from node: '$state'" | ||
188 | 239 | ;; | ||
189 | 240 | esac | ||
190 | 241 | } | ||
191 | 242 | |||
192 | 243 | |||
193 | 244 | # Power-cycle the machine via wsman, and boot it using the requested boot mode. | ||
194 | 245 | wsman_restart() { | ||
195 | 246 | issue_wsman_command restart | ||
196 | 247 | } | ||
197 | 248 | |||
198 | 249 | |||
199 | 250 | # Power the machine on via wsman, and boot it using PXE. | ||
200 | 251 | wsman_power_on() { | ||
201 | 252 | # Issue the wsman command to change power state | ||
202 | 253 | issue_wsman_command on | ||
203 | 254 | # Check power state several times. It usually takes a second or two to get | ||
204 | 255 | # the correct state. | ||
205 | 256 | for attempts in $(seq 0 10) | ||
206 | 257 | do | ||
207 | 258 | if [ "$(wsman_query_state)" = 'on' ] | ||
208 | 259 | then | ||
209 | 260 | # Success. Machine is on. | ||
210 | 261 | return 0 | ||
211 | 262 | fi | ||
212 | 263 | sleep 1 | ||
213 | 264 | done | ||
214 | 265 | fail 1 "Machine is not powering on. Giving up." | ||
215 | 266 | } | ||
216 | 267 | |||
217 | 268 | # Power the machine off via wsman. | ||
218 | 269 | # Currently commented out because we need a way to power query the machines | ||
219 | 270 | wsman_power_off() { | ||
220 | 271 | # Issue the wsman command to change power state | ||
221 | 272 | issue_wsman_command off | ||
222 | 273 | # Check power state several times. It usually takes a second or two to get | ||
223 | 274 | # the correct state | ||
224 | 275 | for attempts in $(seq 0 10) | ||
225 | 276 | do | ||
226 | 277 | if [ "$(wsman_query_state)" = 'off' ] | ||
227 | 278 | then | ||
228 | 279 | # Success. Machine is off. | ||
229 | 280 | return 0 | ||
230 | 281 | fi | ||
231 | 282 | sleep 1 | ||
232 | 283 | done | ||
233 | 284 | fail 1 "Machine is not powering off. Giving up." | ||
234 | 285 | } | ||
235 | 286 | |||
236 | 138 | main() { | 287 | main() { |
237 | 139 | check_bmc_host | 288 | check_bmc_host |
238 | 140 | check_amt_command | 289 | check_amt_command |
239 | 290 | # Check AMT version | ||
240 | 291 | check_amt_version | ||
241 | 292 | amt_version=$? | ||
242 | 293 | if [ ${amt_version} -gt 8 ]; then | ||
243 | 294 | # version > 8, use wsman | ||
244 | 295 | check_wsman_command | ||
245 | 296 | tool="wsman" | ||
246 | 297 | else | ||
247 | 298 | # Use amttool | ||
248 | 299 | tool="amt" | ||
249 | 300 | fi | ||
250 | 301 | |||
251 | 141 | case "${power_change}" in | 302 | case "${power_change}" in |
252 | 142 | 'on') | 303 | 'on') |
254 | 143 | if [ "$(query_state)" = 'on' ] | 304 | if [ "${tool}_query_state" = 'on' ] |
255 | 144 | then | 305 | then |
256 | 145 | # The machine is already up, so powering it up will do nothing. | 306 | # The machine is already up, so powering it up will do nothing. |
257 | 146 | # Cycle the power instead. | 307 | # Cycle the power instead. |
259 | 147 | restart | 308 | ${tool}_restart |
260 | 148 | else | 309 | else |
262 | 149 | power_on | 310 | ${tool}_power_on |
263 | 150 | fi | 311 | fi |
264 | 151 | ;; | 312 | ;; |
265 | 152 | 'off') | 313 | 'off') |
267 | 153 | if [ "$(query_state)" != 'off' ] | 314 | if [ "${tool}_query_state" != 'off' ] |
268 | 154 | then | 315 | then |
270 | 155 | power_off | 316 | ${tool}_power_off |
271 | 156 | fi | 317 | fi |
272 | 157 | ;; | 318 | ;; |
273 | 158 | 'query') | 319 | 'query') |
275 | 159 | query_state | 320 | ${tool}_query_state |
276 | 160 | ;; | 321 | ;; |
277 | 161 | *) | 322 | *) |
278 | 162 | fail 1 "Unknown power command: '$1'" | 323 | fail 1 "Unknown power command: '$1'" |
Simple backport: self-approving.