Merge pull request #10126 from briancain/docker-machine-name
Only write box metadata if guest has box object
This commit is contained in:
commit
c61f58049c
|
@ -10,9 +10,11 @@ module VagrantPlugins
|
||||||
class StoreBoxMetadata
|
class StoreBoxMetadata
|
||||||
def initialize(app, env)
|
def initialize(app, env)
|
||||||
@app = app
|
@app = app
|
||||||
|
@logger = Log4r::Logger.new("vagrant::up::storeboxmetadata")
|
||||||
end
|
end
|
||||||
|
|
||||||
def call(env)
|
def call(env)
|
||||||
|
if env[:machine].box
|
||||||
box = env[:machine].box
|
box = env[:machine].box
|
||||||
box_meta = {
|
box_meta = {
|
||||||
name: box.name,
|
name: box.name,
|
||||||
|
@ -21,9 +23,13 @@ module VagrantPlugins
|
||||||
directory: box.directory.sub(Vagrant.user_data_path.to_s + "/", "")
|
directory: box.directory.sub(Vagrant.user_data_path.to_s + "/", "")
|
||||||
}
|
}
|
||||||
meta_file = env[:machine].data_dir.join("box_meta")
|
meta_file = env[:machine].data_dir.join("box_meta")
|
||||||
|
@logger.debug("Writing box metadata file to #{meta_file}")
|
||||||
File.open(meta_file.to_s, "w+") do |file|
|
File.open(meta_file.to_s, "w+") do |file|
|
||||||
file.write(JSON.dump(box_meta))
|
file.write(JSON.dump(box_meta))
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
@logger.debug("No box data found for #{env[:machine].name} with provider #{env[:machine].provider_name}")
|
||||||
|
end
|
||||||
@app.call(env)
|
@app.call(env)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -26,6 +26,21 @@ describe VagrantPlugins::CommandUp::StoreBoxMetadata do
|
||||||
let(:subject) { described_class.new(app, env) }
|
let(:subject) { described_class.new(app, env) }
|
||||||
|
|
||||||
describe "#call" do
|
describe "#call" do
|
||||||
|
context "with no box file" do
|
||||||
|
let(:machine) { double("machine", name: "guest", provider_name: "provider") }
|
||||||
|
let(:env) { {machine: machine} }
|
||||||
|
|
||||||
|
before do
|
||||||
|
allow(machine).to receive(:box).and_return(nil)
|
||||||
|
expect(app).to receive(:call).with(env)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
it "does not write the metadata file" do
|
||||||
|
expect(File).to_not receive(:open)
|
||||||
|
subject.call(env)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
let(:meta_file) { double("meta_file") }
|
let(:meta_file) { double("meta_file") }
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue