Skip to content

Commit 70e1379

Browse files
Fix DriverName missing in 0.3.1 => 0.5.0 migration
Signed-off-by: Nathan LeClaire <nathan.leclaire@gmail.com> Signed-off-by: David Gageot <david@gageot.net>
1 parent 952539d commit 70e1379

File tree

3 files changed

+34
-4
lines changed

3 files changed

+34
-4
lines changed

libmachine/host/migrate_v0_v1.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"github.com/docker/machine/libmachine/swarm"
77
)
88

9-
// In the 0.0.1 => 0.0.2 transition, the JSON representation of
9+
// In the 0.1.0 => 0.2.0 transition, the JSON representation of
1010
// machines changed from a "flat" to a more "nested" structure
1111
// for various options and configuration settings. To preserve
1212
// compatibility with existing machines, these migration functions
@@ -17,11 +17,15 @@ import (
1717
// this is used for configuration updates
1818
func MigrateHostV0ToHostV1(hostV0 *HostV0) *HostV1 {
1919
hostV1 := &HostV1{
20-
Driver: hostV0.Driver,
20+
Driver: hostV0.Driver,
21+
DriverName: hostV0.DriverName,
2122
}
2223

2324
hostV1.HostOptions = &HostOptionsV1{}
24-
hostV1.HostOptions.EngineOptions = &engine.EngineOptions{}
25+
hostV1.HostOptions.EngineOptions = &engine.EngineOptions{
26+
TlsVerify: true,
27+
InstallURL: "https://get.docker.com",
28+
}
2529
hostV1.HostOptions.SwarmOptions = &swarm.SwarmOptions{
2630
Address: "",
2731
Discovery: hostV0.SwarmDiscovery,

libmachine/host/migrate_v0_v1_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ func TestMigrateHostV0ToV1(t *testing.T) {
3838
ServerCertPath: "/tmp/migration/certs/server.pem",
3939
ServerKeyPath: "/tmp/migration/certs/server-key.pem",
4040
},
41-
EngineOptions: &engine.EngineOptions{},
41+
EngineOptions: &engine.EngineOptions{
42+
InstallURL: "https://get.docker.com",
43+
TlsVerify: true,
44+
},
4245
}
4346

4447
expectedHost := &HostV1{
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package host
2+
3+
import "testing"
4+
5+
var (
6+
v0conf = []byte(`{"DriverName":"virtualbox","Driver":{"IPAddress":"192.168.99.100","SSHUser":"docker","SSHPort":53507,"MachineName":"dev","CaCertPath":"/Users/ljrittle/.docker/machine/certs/ca.pem","PrivateKeyPath":"/Users/ljrittle/.docker/machine/certs/ca-key.pem","SwarmMaster":false,"SwarmHost":"tcp://0.0.0.0:3376","SwarmDiscovery":"","CPU":-1,"Memory":1024,"DiskSize":20000,"Boot2DockerURL":"","Boot2DockerImportVM":"","HostOnlyCIDR":""},"StorePath":"/Users/ljrittle/.docker/machine/machines/dev","HostOptions":{"Driver":"","Memory":0,"Disk":0,"EngineOptions":{"ArbitraryFlags":null,"Dns":null,"GraphDir":"","Ipv6":false,"InsecureRegistry":null,"Labels":null,"LogLevel":"","StorageDriver":"","SelinuxEnabled":false,"TlsCaCert":"","TlsCert":"","TlsKey":"","TlsVerify":false,"RegistryMirror":null,"InstallURL":""},"SwarmOptions":{"IsSwarm":false,"Address":"","Discovery":"","Master":false,"Host":"tcp://0.0.0.0:3376","Image":"","Strategy":"","Heartbeat":0,"Overcommit":0,"TlsCaCert":"","TlsCert":"","TlsKey":"","TlsVerify":false,"ArbitraryFlags":null},"AuthOptions":{"StorePath":"/Users/ljrittle/.docker/machine/machines/dev","CaCertPath":"/Users/ljrittle/.docker/machine/certs/ca.pem","CaCertRemotePath":"","ServerCertPath":"/Users/ljrittle/.docker/machine/certs/server.pem","ServerKeyPath":"/Users/ljrittle/.docker/machine/certs/server-key.pem","ClientKeyPath":"/Users/ljrittle/.docker/machine/certs/key.pem","ServerCertRemotePath":"","ServerKeyRemotePath":"","PrivateKeyPath":"/Users/ljrittle/.docker/machine/certs/ca-key.pem","ClientCertPath":"/Users/ljrittle/.docker/machine/certs/cert.pem"}}}`)
7+
)
8+
9+
func TestMigrateHostV0ToHostV3(t *testing.T) {
10+
h := &Host{}
11+
migratedHost, migrationPerformed, err := MigrateHost(h, v0conf)
12+
if err != nil {
13+
t.Fatalf("Error attempting to migrate host: %s", err)
14+
}
15+
16+
if !migrationPerformed {
17+
t.Fatal("Expected a migration to be reported as performed but it was not")
18+
}
19+
20+
if migratedHost.DriverName != "virtualbox" {
21+
t.Fatalf("Expected %q, got %q for the driver name", "virtualbox", migratedHost.DriverName)
22+
}
23+
}

0 commit comments

Comments
 (0)