Merge lp:~julian-edwards/maas/vm-pause-state-bug-1394382 into lp:~maas-committers/maas/trunk

Proposed by Julian Edwards
Status: Merged
Approved by: Julian Edwards
Approved revision: no longer in the source branch.
Merged at revision: 3395
Proposed branch: lp:~julian-edwards/maas/vm-pause-state-bug-1394382
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 41 lines (+22/-5)
1 file modified
src/provisioningserver/drivers/hardware/virsh.py (+22/-5)
To merge this branch: bzr merge lp:~julian-edwards/maas/vm-pause-state-bug-1394382
Reviewer Review Type Date Requested Status
Graham Binns (community) Approve
Review via email: mp+243361@code.launchpad.net

Commit message

Handle more of the known states in which a virsh machine can be, instead of crashing.

Description of the change

The existing tests cover the functionality, nothing has changed other than adding the lookup table with extra states.

To post a comment you must log in.
Revision history for this message
Graham Binns (gmb) wrote :

It's worth adding a tests that shows that for each VM state in VirshVMState, power_state_virsh() returns a value that makes sense. Other than that, LGTM.

review: Approve
Revision history for this message
Julian Edwards (julian-edwards) wrote :

On Tuesday 02 Dec 2014 07:21:07 you wrote:
> Review: Approve
>
> It's worth adding a tests that shows that for each VM state in VirshVMState,
> power_state_virsh() returns a value that makes sense. Other than that,
> LGTM.

Thanks for the review.

I'm not sure what that would be really testing. There are already tests for
the happy path and the unhappy path. The rest of it is just mappings that
I've added.

Revision history for this message
Graham Binns (gmb) wrote :

On 2 December 2014 at 08:03, Julian Edwards <email address hidden>
wrote:

>
> I'm not sure what that would be really testing. There are already tests
> for
> the happy path and the unhappy path. The rest of it is just mappings that
> I've added.
>

Ah, so there are. In my morning-brain state I didn't see them. Fair enough.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/provisioningserver/drivers/hardware/virsh.py'
--- src/provisioningserver/drivers/hardware/virsh.py 2014-09-15 14:28:28 +0000
+++ src/provisioningserver/drivers/hardware/virsh.py 2014-12-02 05:59:23 +0000
@@ -33,6 +33,24 @@
33class VirshVMState:33class VirshVMState:
34 OFF = "shut off"34 OFF = "shut off"
35 ON = "running"35 ON = "running"
36 NO_STATE = "no state"
37 IDLE = "idle"
38 PAUSED = "paused"
39 IN_SHUTDOWN = "in shutdown"
40 CRASHED = "crashed"
41 PM_SUSPENDED = "pmsuspended"
42
43
44VM_STATE_TO_POWER_STATE = {
45 VirshVMState.OFF: "off",
46 VirshVMState.ON: "on",
47 VirshVMState.NO_STATE: "off",
48 VirshVMState.IDLE: "off",
49 VirshVMState.PAUSED: "off",
50 VirshVMState.IN_SHUTDOWN: "on",
51 VirshVMState.CRASHED: "off",
52 VirshVMState.PM_SUSPENDED: "off",
53 }
3654
3755
38class VirshError(Exception):56class VirshError(Exception):
@@ -238,8 +256,7 @@
238 if state is None:256 if state is None:
239 raise VirshError('Failed to get domain: %s' % machine)257 raise VirshError('Failed to get domain: %s' % machine)
240258
241 if state == VirshVMState.OFF:259 try:
242 return 'off'260 return VM_STATE_TO_POWER_STATE[state]
243 elif state == VirshVMState.ON:261 except KeyError:
244 return 'on'262 raise VirshError('Unknown state: %s' % state)
245 raise VirshError('Unknown state: %s' % state)