Green-test: VirtualboxProviderHeavyTests::test_stop_action

We can now tell instances to stop

Related to saltstack/salt#27089 Saltcloud virtualbox provider
This commit is contained in:
LoveIsGrief 2016-01-09 16:32:21 +01:00
parent 8111dcb092
commit 8604be624b
2 changed files with 42 additions and 1 deletions

View File

@ -22,7 +22,7 @@ from salt.exceptions import SaltCloudSystemExit
import salt.config as config
import salt.utils.cloud as cloud
from utils.virtualbox import vb_list_machines, vb_clone_vm, HAS_LIBS, vb_machine_exists, vb_destroy_machine, \
vb_machinestate_to_str, vb_get_machine
vb_get_machine, vb_stop_vm, treat_machine_dict
log = logging.getLogger(__name__)
@ -313,6 +313,22 @@ def destroy(name, call=None):
# TODO implement actions e.g start, stop, restart, etc.
def stop(name, call=None):
"""
Stop a running machine.
"""
if call != 'action':
raise SaltCloudSystemExit(
'The instance action must be called with -a or --action.'
)
log.info("Stopping machine: %s" % name)
vb_stop_vm(name)
machine = vb_get_machine(name)
del machine["name"]
return treat_machine_dict(machine)
# TODO implement functions
def show_image(kwargs, call=None):

View File

@ -382,6 +382,31 @@ def vb_xpcom_to_attribute_dict(xpcom
return dict(attribute_tuples)
def treat_machine_dict(machine):
"""
Make machine presentable for outside world.
!!!Modifies the input machine!!!
@param machine:
@type machine: dict
@return: the modified input machine
@rtype: dict
"""
machine.update({
"id": machine.get("id", ""),
"image": machine.get("image", ""),
"size": "%s MB" % machine.get("memorySize", 0),
"state": vb_machinestate_to_str(machine.get("state", -1))[0],
"private_ips": [],
"public_ips": [],
})
# Replaced keys
if "memorySize" in machine:
del machine["memorySize"]
return machine
def vb_machinestate_to_str(machinestate):
"""