Merge pull request #10490 from chrisroberts/f-snapshot-behavior

Update behavior of `snapshot restore` and `snapshot pop`
This commit is contained in:
Chris Roberts 2018-12-13 09:18:20 -08:00 committed by GitHub
commit 2daafd9586
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 88 additions and 1 deletions

View File

@ -17,6 +17,9 @@ module VagrantPlugins
def execute
options = {}
options[:snapshot_delete] = true
options[:provision_ignore_sentinel] = false
options[:snapshot_start] = true
opts = OptionParser.new do |o|
o.banner = "Usage: vagrant snapshot pop [options] [vm-name]"
o.separator ""
@ -26,6 +29,9 @@ module VagrantPlugins
o.on("--no-delete", "Don't delete the snapshot after the restore") do
options[:snapshot_delete] = false
end
o.on("--no-start", "Don't start the snapshot after the restore") do
options[:snapshot_start] = false
end
end
# Parse the options

View File

@ -13,12 +13,18 @@ module VagrantPlugins
def execute
options = {}
options[:provision_ignore_sentinel] = false
options[:snapshot_start] = true
opts = OptionParser.new do |o|
o.banner = "Usage: vagrant snapshot restore [options] [vm-name] <name>"
o.separator ""
build_start_options(o, options)
o.separator "Restore a snapshot taken previously with snapshot save."
o.on("--no-start", "Don't start the snapshot after the restore") do
options[:snapshot_start] = false
end
end
# Parse the options

View File

@ -267,7 +267,11 @@ module VagrantPlugins
end
end
b2.use action_start
b2.use Call, IsEnvSet, :snapshot_start do |env2, b3|
if env2[:result]
b3.use action_start
end
end
end
end
end

View File

@ -25,6 +25,12 @@ describe VagrantPlugins::CommandSnapshot::Command::Pop do
end
describe "execute" do
before do
machine.id = "mach"
allow(machine.provider).to receive(:capability).
with(:snapshot_list).and_return(["push_2_0"])
end
it "calls snapshot_restore with the last pushed snapshot" do
machine.id = "foo"
@ -48,5 +54,33 @@ describe VagrantPlugins::CommandSnapshot::Command::Pop do
expect(machine).to_not receive(:action)
expect(subject.execute).to eq(0)
end
it "should disable ignoring sentinel file for provisioning" do
expect(machine).to receive(:action) do |name, opts|
expect(name).to eq(:snapshot_restore)
expect(opts[:provision_ignore_sentinel]).to eq(false)
end
subject.execute
end
it "should start the snapshot" do
expect(machine).to receive(:action) do |name, opts|
expect(name).to eq(:snapshot_restore)
expect(opts[:snapshot_start]).to eq(true)
end
subject.execute
end
context "when --no-start flag is provided" do
let(:argv) { ["--no-start"] }
it "should not start the snapshot" do
expect(machine).to receive(:action) do |name, opts|
expect(name).to eq(:snapshot_restore)
expect(opts[:snapshot_start]).to eq(false)
end
subject.execute
end
end
end
end

View File

@ -12,6 +12,7 @@ describe VagrantPlugins::CommandSnapshot::Command::Restore do
env.create_vagrant_env
end
let(:snapshot_name) { "snapshot_name" }
let(:guest) { double("guest") }
let(:host) { double("host") }
let(:machine) { iso_env.machine(iso_env.machine_names[0], :dummy) }
@ -31,6 +32,11 @@ describe VagrantPlugins::CommandSnapshot::Command::Restore do
end
describe "execute" do
before do
allow(machine.provider).to receive(:capability).
with(:snapshot_list).and_return([snapshot_name])
end
context "with no arguments" do
it "shows help" do
expect { subject.execute }.
@ -93,5 +99,32 @@ describe VagrantPlugins::CommandSnapshot::Command::Restore do
to raise_error(Vagrant::Errors::SnapshotNotFound)
end
end
it "should disable ignoring sentinel file for provisioning" do
argv << snapshot_name
expect(machine).to receive(:action) do |_, opts|
expect(opts[:provision_ignore_sentinel]).to eq(false)
end
subject.execute
end
it "should start the snapshot" do
argv << snapshot_name
expect(machine).to receive(:action) do |_, opts|
expect(opts[:snapshot_start]).to eq(true)
end
subject.execute
end
context "when --no-start flag is provided" do
let(:argv) { [snapshot_name, "--no-start"] }
it "should not start the snapshot" do
expect(machine).to receive(:action) do |_, opts|
expect(opts[:snapshot_start]).to eq(false)
end
subject.execute
end
end
end
end

View File

@ -56,6 +56,8 @@ the pushed state.
* `--no-delete` - Prevents deletion of the snapshot after restoring
(so that you can restore to the same point again later).
* `--no-start` - Prevents the guest from being started after restore
# Snapshot Save
**Command: `vagrant snapshot save [vm-name] NAME`**
@ -72,6 +74,8 @@ This command restores the named snapshot.
* `--[no-]provision` - Force the provisioners to run (or prevent them
from doing so).
* `--no-start` - Prevents the guest from being started after restore
# Snapshot List
**Command: `vagrant snapshot list`**