state: Refactor code to move all the state load code

Refactor so that all code to load state, devices, network
takes place at one place. This is in line with the experimental api
for new storage that also loads all the necessary items here all at once.

Signed-off-by: Archana Shinde <archana.m.shinde@intel.com>
This commit is contained in:
Archana Shinde 2019-10-08 16:25:36 -07:00
parent fa4acad4aa
commit f6a10bcae7

View File

@ -477,24 +477,6 @@ func createSandbox(ctx context.Context, sandboxConfig SandboxConfig, factory Fac
s.Logger().WithField("features", s.config.Experimental).Infof("Enable experimental features")
}
if s.supportNewStore() {
// Restored successfully from newstore before.
if s.state.State != "" {
return s, nil
}
} else {
// Fetch sandbox network to be able to access it from the sandbox structure.
var networkNS NetworkNamespace
if err := s.store.Load(store.Network, &networkNS); err == nil {
s.networkNS = networkNS
}
devices, err := s.store.LoadDevices()
if err != nil {
s.Logger().WithError(err).WithField("sandboxid", s.id).Warning("load sandbox devices failed")
}
s.devManager = deviceManager.NewDeviceManager(sandboxConfig.HypervisorConfig.BlockDeviceDriver, devices)
// Sandbox state has been loaded from storage.
// If the Stae is not empty, this is a re-creation, i.e.
// we don't need to talk to the guest's agent, but only
@ -502,7 +484,6 @@ func createSandbox(ctx context.Context, sandboxConfig SandboxConfig, factory Fac
if s.state.State != "" {
return s, nil
}
}
// Below code path is called only during create, because of earlier check.
if err := s.agent.createSandbox(s); err != nil {
@ -586,6 +567,18 @@ func newSandbox(ctx context.Context, sandboxConfig SandboxConfig, factory Factor
return nil, err
}
} else {
// Fetch sandbox network to be able to access it from the sandbox structure.
var networkNS NetworkNamespace
if err = s.store.Load(store.Network, &networkNS); err == nil {
s.networkNS = networkNS
}
devices, err := s.store.LoadDevices()
if err != nil {
s.Logger().WithError(err).WithField("sandboxid", s.id).Warning("load sandbox devices failed")
}
s.devManager = deviceManager.NewDeviceManager(sandboxConfig.HypervisorConfig.BlockDeviceDriver, devices)
// Load sandbox state. The hypervisor.createSandbox call, may need to access statei.
state, err := s.store.LoadState()
if err == nil {