From bb54952d7fe619612e02edb3841152675ddd4fd3 Mon Sep 17 00:00:00 2001 From: Matt Fellows Date: Tue, 28 Jun 2016 07:11:33 +1000 Subject: [PATCH] fix issue #21 - run folder test command twice on provision for new PoSH setup --- lib/vagrant-dsc/provisioner.rb | 6 +++++- spec/provisioner/provisioner_spec.rb | 16 ++++++++-------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/lib/vagrant-dsc/provisioner.rb b/lib/vagrant-dsc/provisioner.rb index 480aedd..80f0baa 100644 --- a/lib/vagrant-dsc/provisioner.rb +++ b/lib/vagrant-dsc/provisioner.rb @@ -10,7 +10,7 @@ class DSCError < Vagrant::Errors::VagrantError end class DSCUnsupportedOperation < DSCError error_key(:unsupported_operation) - end + end # DSC Provisioner Plugin. # @@ -219,6 +219,10 @@ def run_dsc_apply # on the guest machine. def verify_shared_folders(folders) folders.each do |folder| + # Warm up PoSH communicator for new instances - any stderr results + # in failure: https://github.com/mefellows/vagrant-dsc/issues/21 + @machine.communicate.test("test -d #{folder}", sudo: true) + @logger.info("Checking for shared folder: #{folder}") if !@machine.communicate.test("test -d #{folder}", sudo: true) raise DSCError, :missing_shared_folders diff --git a/spec/provisioner/provisioner_spec.rb b/spec/provisioner/provisioner_spec.rb index 948cf40..6852ef3 100644 --- a/spec/provisioner/provisioner_spec.rb +++ b/spec/provisioner/provisioner_spec.rb @@ -89,7 +89,7 @@ it "should raise error if folders not shared" do root_config.synced_folder_type = "nfs" - expect(communicator).to receive(:test).with("test -d foo/modules", {:sudo=>true}).and_return(false) + expect(communicator).to receive(:test).twice.with("test -d foo/modules", {:sudo=>true}).and_return(false) subject.configure(root_config) @@ -100,9 +100,9 @@ it "should ensure shared folders are properly shared" do root_config.synced_folder_type = "nfs" - expect(communicator).to receive(:test).with("test -d foo/modules", {:sudo=>true}).and_return(true) - expect(communicator).to receive(:test).with("test -d foo/modules2", {:sudo=>true}).and_return(true) - expect(communicator).to receive(:test).with("test -d manifests", {:sudo=>true}).and_return(true) + expect(communicator).to receive(:test).twice.with("test -d foo/modules", {:sudo=>true}).and_return(true) + expect(communicator).to receive(:test).twice.with("test -d foo/modules2", {:sudo=>true}).and_return(true) + expect(communicator).to receive(:test).twice.with("test -d manifests", {:sudo=>true}).and_return(true) subject.configure(root_config) @@ -183,12 +183,12 @@ expect(subject).to receive(:run_dsc_apply) subject.provision - end + end it "should ensure shared folders are properly configured" do allow(communicator).to receive(:test) allow(communicator).to receive(:sudo) - allow(communicator).to receive(:upload) + allow(communicator).to receive(:upload) allow(subject).to receive(:verify_dsc).and_return(true) allow(subject).to receive(:run_dsc_apply).and_return(true) allow(guest).to receive(:capability?) @@ -225,7 +225,7 @@ it "should raise an error if Powershell version is invalid" do - end + end end describe "DSC runner script" do @@ -288,7 +288,7 @@ def get_and_update_counter(name=nil) 1 end it "should generate a valid powershell command" do root_config.manifests_path = "../manifests" root_config.configuration_file = configuration_file - + script = subject.generate_dsc_runner_script expect_script = "# # DSC Runner.