Require client to be set and provide stub on initial startup

When running in server mode, make the Environment validate a client
option is provided on instantiation. If no client option is provided,
raise an exception since it is required in server mode.

Since an initial Environment is required during start, include a
stub value for the client so the initial Environment can be instantiated
successfully and the GRPC service can be started.
This commit is contained in:
Chris Roberts 2021-08-05 10:52:41 -07:00 committed by Paul Hinze
parent 3ca9519f5c
commit fe293dfd1f
No known key found for this signature in database
GPG Key ID: B69DEDF2D55501C0
2 changed files with 11 additions and 1 deletions

View File

@ -197,6 +197,12 @@ begin
# Check if we are running the server
if sub_cmd == "serve"
Vagrant.enable_server_mode!
# NOTE: We stub the client option to allow the environment to
# be initialized for startup since it will raise an
# exception if it is unset. We don't care about the
# initially created environment, we just need it long
# enough for our serve command to get executed.
opts[:client] = :stub
end
# Create the environment, which is the cwd of wherever the

View File

@ -11,6 +11,10 @@ module Vagrant
def initialize(opts={})
super
@client = opts[:client]
if @client.nil?
raise ArgumentError,
"Remote client is required for `#{self.class.name}'"
end
end
# Gets a target (machine) by name
@ -18,7 +22,7 @@ module Vagrant
# @param [String] machine name
# return [VagrantPlugins::CommandServe::Client::Machine]
def get_target(name)
return @client.target(name)
client.target(name)
end
end
end