Merge pull request #288 from hashicorp/docker-provider-up

Docker provider up
This commit is contained in:
Sophia Castellarin 2022-06-30 09:12:28 -05:00 committed by GitHub
commit 6669cd0f87
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 52 additions and 11 deletions

View File

@ -98,6 +98,17 @@ func (m *Machine) Box() (b core.Box, err error) {
// Guest implements core.Machine
func (m *Machine) Guest() (g core.Guest, err error) {
comm, err := m.Communicate()
if err != nil {
return nil, err
}
isReady, err := comm.Ready(m)
if err != nil {
return nil, err
}
if !isReady {
return nil, fmt.Errorf("unable to communicate with guest")
}
defer func() {
if g != nil {
err = seedPlugin(g, m)

View File

@ -138,6 +138,14 @@ func TestMachineGetExistentBox(t *testing.T) {
}
func TestMachineConfigedGuest(t *testing.T) {
commMock := BuildTestCommunicatorPlugin("ssh")
commMock.On("Ready", mock.AnythingOfType("*core.Machine")).Return(true, nil)
commPlugin := plugin.TestPlugin(t,
commMock,
plugin.WithPluginName("ssh"),
plugin.WithPluginTypes(component.CommunicatorType),
)
type test struct {
config *component.ConfigData
errors bool
@ -157,6 +165,7 @@ func TestMachineConfigedGuest(t *testing.T) {
plugin.WithPluginName("myguest"),
plugin.WithPluginTypes(component.GuestType),
),
commPlugin,
)
for _, tc := range tests {
@ -178,6 +187,14 @@ func TestMachineConfigedGuest(t *testing.T) {
}
func TestMachineNoConfigGuest(t *testing.T) {
commMock := BuildTestCommunicatorPlugin("ssh")
commMock.On("Ready", mock.AnythingOfType("*core.Machine")).Return(true, nil)
commPlugin := plugin.TestPlugin(t,
commMock,
plugin.WithPluginName("ssh"),
plugin.WithPluginTypes(component.CommunicatorType),
)
guestMock := BuildTestGuestPlugin("myguest", "")
guestMock.On("Detect", mock.AnythingOfType("*core.Machine")).Return(true, nil)
guestMock.On("Parent").Return("", nil)
@ -211,12 +228,12 @@ func TestMachineNoConfigGuest(t *testing.T) {
}
tests := []test{
{plugins: []*plugin.Plugin{detectingPlugin}, errors: false, expectedPluginName: "myguest"},
{plugins: []*plugin.Plugin{detectingChildPlugin}, errors: true, expectedPluginName: "myguest-child"},
{plugins: []*plugin.Plugin{detectingChildPlugin, detectingPlugin}, errors: false, expectedPluginName: "myguest-child"},
{plugins: []*plugin.Plugin{detectingPlugin, nonDetectingPlugin}, errors: false, expectedPluginName: "myguest"},
{plugins: []*plugin.Plugin{nonDetectingPlugin}, errors: true},
{plugins: []*plugin.Plugin{}, errors: true},
{plugins: []*plugin.Plugin{commPlugin, detectingPlugin}, errors: false, expectedPluginName: "myguest"},
{plugins: []*plugin.Plugin{commPlugin, detectingChildPlugin}, errors: true, expectedPluginName: "myguest-child"},
{plugins: []*plugin.Plugin{commPlugin, detectingChildPlugin, detectingPlugin}, errors: false, expectedPluginName: "myguest-child"},
{plugins: []*plugin.Plugin{commPlugin, detectingPlugin, nonDetectingPlugin}, errors: false, expectedPluginName: "myguest"},
{plugins: []*plugin.Plugin{commPlugin, nonDetectingPlugin}, errors: true},
{plugins: []*plugin.Plugin{commPlugin}, errors: true},
}
for _, tc := range tests {
@ -230,13 +247,13 @@ func TestMachineNoConfigGuest(t *testing.T) {
require.Nil(t, guest)
require.Nil(t, tm.cache.Get("guest"))
} else {
require.NoError(t, err)
require.NotNil(t, guest)
require.NotNil(t, tm.cache.Get("guest"))
n, _ := guest.PluginName()
if n != tc.expectedPluginName {
t.Error("Found unexpected plugin, ", n)
}
require.NoError(t, err)
require.NotNil(t, guest)
require.NotNil(t, tm.cache.Get("guest"))
}
}
}

View File

@ -28,6 +28,11 @@ func (p *PluginWithParent) SetParentComponent(in interface{}) {
p.parentPlugin = in
}
type TestCommunicatorPlugin struct {
plugin.TestPluginWithFakeBroker
coremocks.Communicator
}
type TestGuestPlugin struct {
PluginWithParent
plugin.TestPluginWithFakeBroker
@ -46,6 +51,14 @@ type TestSyncedFolderPlugin struct {
coremocks.SyncedFolder
}
func BuildTestCommunicatorPlugin(name string) *TestCommunicatorPlugin {
c := &TestCommunicatorPlugin{}
c.On("Seed", mock.AnythingOfType("*core.Seeds")).Return(nil)
c.On("Seeds").Return(core.NewSeeds(), nil)
c.On("PluginName").Return(name, nil)
return c
}
func BuildTestGuestPlugin(name string, parent string) *TestGuestPlugin {
p := &TestGuestPlugin{}
p.On("SetPluginName", mock.AnythingOfType("string")).Return(nil)

View File

@ -85,6 +85,7 @@ module Vagrant
end
def guest
raise Errors::MachineGuestNotReady if !communicate.ready?
if !@guest
@guest = Guest.new(self, nil, nil)
end

View File

@ -37,7 +37,6 @@ module VagrantPlugins
end
# @return [Guest] machine guest
# TODO: This needs to be loaded properly
def guest
g = client.guest(Empty.new)
Guest.load(g, broker: broker)

View File

@ -8,7 +8,7 @@ module VagrantPlugins
logger.debug("generating ready spec")
funcspec(
args: [
SDK::Target::Machine,
SDK::Args::Target::Machine,
],
result: SDK::Communicator::ReadyResp,
)