Skip to content

Commit

Permalink
VM control methods (stop, save, etc.) work again
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchellh committed Dec 24, 2010
1 parent fd5fc2e commit 91676f7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 15 deletions.
14 changes: 4 additions & 10 deletions lib/virtualbox/vm.rb
Expand Up @@ -538,16 +538,10 @@ def discard_state
# @param [String] command The command to run on controlvm
# @return [Boolean] True if command was successful, false otherwise.
def control(command, *args)
# Grab the session using an existing session
session = Lib.lib.session
interface.parent.open_existing_session(session, uuid)

# Send the proper command, waiting if we have to
result = session.console.send(command, *args)
result.wait_for_completion(-1) if result.is_a?(COM::Util.versioned_interface(:Progress))
ensure
# Close the session
session.close if session && session.state == :open
with_open_session do |session|
result = session.console.send(command, *args)
result.wait if result.is_a?(COM::Util.versioned_interface(:Progress))
end
end

# Destroys the virtual machine. This method also removes all attached
Expand Down
9 changes: 4 additions & 5 deletions test/virtualbox/vm_test.rb
Expand Up @@ -281,30 +281,29 @@ def setup_session_mocks
setup do
setup_session_mocks

@parent.stubs(:open_existing_session)

@console = mock("console")
@console.stubs(:send)
@session.stubs(:console).returns(@console)
@session.stubs(:state).returns(:open)

@instance.stubs(:with_open_session).yields(@session)

@method = :foo
end

should "get an existing, session, send the command, and close" do
method = :foo
control_seq = sequence("control_seq")
@parent.expects(:open_existing_session).with(@session, @uuid).once.in_sequence(control_seq)
@instance.expects(:with_open_session).yields(@session).in_sequence(control_seq)
@console.expects(:send).with(@method).once.in_sequence(control_seq)
@session.expects(:close).in_sequence(control_seq)

@instance.control(@method)
end

should "wait for completion if an IProgress is returned" do
progress = mock("IProgress")
progress.stubs(:is_a?).with(VirtualBox::COM::Util.versioned_interface(:Progress)).returns(true)
progress.expects(:wait_for_completion).with(-1).once
progress.expects(:wait).once
@console.expects(:send).with(@method).returns(progress)
@instance.control(@method)
end
Expand Down

0 comments on commit 91676f7

Please sign in to comment.