Migrate legacy volumes (Daemon.verifyVolumesInfo) before containers are
registered on the Daemon, so state on disk is not overwritten and legacy
fields lost during registration.
Signed-off-by: Fabio Kung <fabio.kung@gmail.com>
... | ... |
@@ -187,17 +187,16 @@ func (daemon *Daemon) restore() error { |
187 | 187 |
delete(containers, id) |
188 | 188 |
continue |
189 | 189 |
} |
190 |
- if err := daemon.Register(c); err != nil { |
|
191 |
- logrus.Errorf("Failed to register container %s: %s", c.ID, err) |
|
192 |
- delete(containers, id) |
|
193 |
- continue |
|
194 |
- } |
|
195 |
- |
|
196 | 190 |
// verify that all volumes valid and have been migrated from the pre-1.7 layout |
197 | 191 |
if err := daemon.verifyVolumesInfo(c); err != nil { |
198 | 192 |
// don't skip the container due to error |
199 | 193 |
logrus.Errorf("Failed to verify volumes for container '%s': %v", c.ID, err) |
200 | 194 |
} |
195 |
+ if err := daemon.Register(c); err != nil { |
|
196 |
+ logrus.Errorf("Failed to register container %s: %s", c.ID, err) |
|
197 |
+ delete(containers, id) |
|
198 |
+ continue |
|
199 |
+ } |
|
201 | 200 |
|
202 | 201 |
// The LogConfig.Type is empty if the container was created before docker 1.12 with default log driver. |
203 | 202 |
// We should rewrite it to use the daemon defaults. |
... | ... |
@@ -274,10 +274,6 @@ func TestMigratePre17Volumes(t *testing.T) { |
274 | 274 |
} |
275 | 275 |
`) |
276 | 276 |
|
277 |
- viewDB, err := container.NewViewDB() |
|
278 |
- if err != nil { |
|
279 |
- t.Fatal(err) |
|
280 |
- } |
|
281 | 277 |
volStore, err := store.New(volumeRoot) |
282 | 278 |
if err != nil { |
283 | 279 |
t.Fatal(err) |
... | ... |
@@ -289,10 +285,9 @@ func TestMigratePre17Volumes(t *testing.T) { |
289 | 289 |
volumedrivers.Register(drv, volume.DefaultDriverName) |
290 | 290 |
|
291 | 291 |
daemon := &Daemon{ |
292 |
- root: rootDir, |
|
293 |
- repository: containerRoot, |
|
294 |
- containersReplica: viewDB, |
|
295 |
- volumes: volStore, |
|
292 |
+ root: rootDir, |
|
293 |
+ repository: containerRoot, |
|
294 |
+ volumes: volStore, |
|
296 | 295 |
} |
297 | 296 |
err = ioutil.WriteFile(filepath.Join(containerRoot, cid, "config.v2.json"), config, 600) |
298 | 297 |
if err != nil { |
... | ... |
@@ -2684,7 +2684,7 @@ func (s *DockerDaemonSuite) TestDaemonBackcompatPre17Volumes(c *check.C) { |
2684 | 2684 |
`) |
2685 | 2685 |
|
2686 | 2686 |
configPath := filepath.Join(d.Root, "containers", id, "config.v2.json") |
2687 |
- err = ioutil.WriteFile(configPath, config, 600) |
|
2687 |
+ c.Assert(ioutil.WriteFile(configPath, config, 600), checker.IsNil) |
|
2688 | 2688 |
d.Start(c) |
2689 | 2689 |
|
2690 | 2690 |
out, err = d.Cmd("inspect", "--type=container", "--format={{ json .Mounts }}", id) |