Fix virtualbox lifecycle acctests

Two fixes:

 1. Allow us to make it through Vagrant::Environment initialization when
    there's no project yet, fixing box add and init commands.
 2. Don't prune UNKNOWN targets from state... as VBox looks like it
    leaves things in that state when it runs suspend.
This commit is contained in:
Paul Hinze 2022-07-13 18:36:11 -05:00
parent 1235930d6f
commit da77316f9a
No known key found for this signature in database
GPG Key ID: 70B94C31D170FB29
2 changed files with 16 additions and 1 deletions

View File

@ -751,7 +751,6 @@ func (p *Project) scrubTargets() (err error) {
}
if resp.Target.State == vagrant_server.Operation_NOT_CREATED ||
resp.Target.State == vagrant_server.Operation_UNKNOWN ||
resp.Target.State == vagrant_server.Operation_DESTROYED {
p.logger.Trace("target does not exist, removing",
"target", resp.Target,

View File

@ -29,6 +29,9 @@ import (
// when merging
type LoadLocation uint8
// DEFAULT_VM_NAME is the name that a target gets when none has been specified.
const DEFAULT_VM_NAME = "default"
const (
VAGRANTFILE_BOX LoadLocation = iota // Box
VAGRANTFILE_BASIS // Basis
@ -1133,6 +1136,7 @@ func (v *Vagrantfile) targetNameLookup(
if cname, ok := v.cache.Fetch("lookup" + nameOrId); ok {
return cname.(string), nil
}
// Run a lookup first to verify if this target actually exists. If it does,
// then request it.
resp, err := v.factory.client.FindTarget(v.factory.ctx,
@ -1145,6 +1149,18 @@ func (v *Vagrantfile) targetNameLookup(
},
)
if err != nil {
// When we are in Basis-only mode (VAGRANT_CWD does not have a
// Vagrantfile), legacy Vagrant still expects to be able to retrieve config
// for the default vm in order to successfully bootstrap its
// Vagrant::Environment. In order to retain that behavior, we allow the
// DEFAULT_VM_NAME to pass through successfully even when no targets
// exist. Note we are specifically skipping the cache registration
// below for this short circuit - we only want to do that when a target
// exists.
if s := status.Convert(err); s.Code() == codes.NotFound && nameOrId == DEFAULT_VM_NAME {
v.logger.Info("ignoring target not found error for DEFAULT_VM_NAME")
return DEFAULT_VM_NAME, nil
}
return "", err
}