Skip to content

Commit

Permalink
[specific ci=Group11-Upgrade] Reconfigure VM display name (#4134)
Browse files Browse the repository at this point in the history
  • Loading branch information
chengwang86 authored Mar 23, 2017
1 parent 07f0b7b commit 27186d0
Show file tree
Hide file tree
Showing 36 changed files with 490 additions and 95 deletions.
10 changes: 5 additions & 5 deletions cmd/tether/attach_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ func attachCase(t *testing.T, runblock bool) {
testServer, _ := server.(*testAttachServer)

cfg := executor.ExecutorConfig{
Common: executor.Common{
ExecutorConfigCommon: executor.ExecutorConfigCommon{
ID: "attach",
Name: "tether_test_executor",
},
Expand Down Expand Up @@ -336,7 +336,7 @@ func TestAttachTTY(t *testing.T) {
testServer, _ := server.(*testAttachServer)

cfg := executor.ExecutorConfig{
Common: executor.Common{
ExecutorConfigCommon: executor.ExecutorConfigCommon{
ID: "attach",
Name: "tether_test_executor",
},
Expand Down Expand Up @@ -435,7 +435,7 @@ func TestAttachMultiple(t *testing.T) {
testServer, _ := server.(*testAttachServer)

cfg := executor.ExecutorConfig{
Common: executor.Common{
ExecutorConfigCommon: executor.ExecutorConfigCommon{
ID: "tee1",
Name: "tether_test_executor",
},
Expand Down Expand Up @@ -603,7 +603,7 @@ func TestAttachInvalid(t *testing.T) {
testServer, _ := server.(*testAttachServer)

cfg := executor.ExecutorConfig{
Common: executor.Common{
ExecutorConfigCommon: executor.ExecutorConfigCommon{
ID: "attachinvalid",
Name: "tether_test_executor",
},
Expand Down Expand Up @@ -740,7 +740,7 @@ func TestReattach(t *testing.T) {
testServer, _ := server.(*testAttachServer)

cfg := executor.ExecutorConfig{
Common: executor.Common{
ExecutorConfigCommon: executor.ExecutorConfigCommon{
ID: "attach",
Name: "tether_test_executor",
},
Expand Down
2 changes: 1 addition & 1 deletion cmd/vic-init/restart_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func TestRestart(t *testing.T) {
defer testTeardown(t)

cfg := executor.ExecutorConfig{
Common: executor.Common{
ExecutorConfigCommon: executor.ExecutorConfigCommon{
ID: "pathlookup",
Name: "tether_test_executor",
},
Expand Down
2 changes: 1 addition & 1 deletion cmd/vicadmin/vicadm.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ func newBytesEntry(name string, b []byte) entry {

type versionReader string

func (path versionReader) open() (entry,error) {
func (path versionReader) open() (entry, error) {
defer trace.End(trace.Begin(string(path)))
return newBytesEntry(string(path), []byte(version.Version)), nil
}
Expand Down
2 changes: 1 addition & 1 deletion doc/design/docker-rename.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ Robot scripts will be written to test the following:
- `docker-compose up –force-recreate` when there are existing containers for the same service even if the configuration or image has not been changed

3. Backward compatibility
- Add a test case in the upgrade test. Create a container using a VCH that does not support `docker rename`. After upgrading the VCH, the basic docker operations that are supported by the old VCH should work.
- Add a test case in the upgrade test. Create a container using a VCH that does not support `docker rename`. After upgrading the VCH, the basic docker operations that are supported by the old VCH should work.
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (handler *ContainersHandlersImpl) CreateHandler(params containers.CreatePar
}

m := &executor.ExecutorConfig{
Common: executor.Common{
ExecutorConfigCommon: executor.ExecutorConfigCommon{
ID: id,
Name: params.CreateConfig.Name,
},
Expand Down
17 changes: 16 additions & 1 deletion lib/config/executor/container_vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,21 @@ type Common struct {
Notes string `vic:"0.1" scope:"hidden" key:"notes"`
}

// Common data (specifically for a containerVM) between managed entities, across execution environments.
type ExecutorConfigCommon struct {
// A reference to the components hosting execution environment, if any
ExecutionEnvironment string

// Unambiguous ID with meaning in the context of its hosting execution environment
ID string `vic:"0.1" scope:"read-only" key:"id"`

// Convenience field to record a human readable name
Name string `vic:"0.1" scope:"hidden" key:"name"`

// Freeform notes related to the entity
Notes string `vic:"0.1" scope:"hidden" key:"notes"`
}

// Diagnostics records some basic control and lifecycle information for diagnostic purposes
type Diagnostics struct {
// Should debugging be enabled on whatever component this is and at what level
Expand Down Expand Up @@ -108,7 +123,7 @@ type ContainerVM struct {
// in that there is no process inherently associated - this is closer to a ThreadPool than a Thread and
// is the owner of the shared filesystem environment. This is the guest visible complement to ContainerVM.
type ExecutorConfig struct {
Common `vic:"0.1" scope:"read-only" key:"common"`
ExecutorConfigCommon `vic:"0.1" scope:"read-only" key:"common"`

// CreateTime stamp
CreateTime int64 `vic:"0.1" scope:"read-write" key:"createtime"`
Expand Down
9 changes: 6 additions & 3 deletions lib/install/management/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,23 +161,26 @@ func (d *Dispatcher) DeleteVCHInstances(vmm *vm.VirtualMachine, conf *config.Vir
if err != nil {
return err
}

if children, err = d.parentResourcepool.GetChildrenVMs(d.ctx, d.session); err != nil {
return err
}

if d.session.Datastore, err = d.getImageDatastore(vmm, conf, d.force); err != nil {
return err
}

for _, child := range children {
name, err := child.Name(d.ctx)
//Leave VCH appliance there until everything else is removed, cause it has VCH configuration. Then user could retry delete in case of any failure.
ok, err := d.isVCH(child)
if err != nil {
errs = append(errs, err.Error())
continue
}
//Leave VCH appliance there until everything else is removed, cause it has VCH configuration. Then user could retry delete in case of any failure.
if name == conf.Name {
if ok {
continue
}

if err = d.deleteVM(child, d.force); err != nil {
errs = append(errs, err.Error())
}
Expand Down
14 changes: 8 additions & 6 deletions lib/migration/migrator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package migration

import (
"strconv"
"strings"
"testing"

Expand All @@ -34,10 +35,11 @@ func setUp() {
// register sample plugin into test
log.SetLevel(log.DebugLevel)
trace.Logger.Level = log.DebugLevel
version.MaxPluginVersion = 1
version.MaxPluginVersion = version.MaxPluginVersion + 1

if err := manager.Migrator.Register(1, manager.ApplianceConfigure, &plugin1.ApplianceStopSignalRename{}); err != nil {
log.Errorf("Failed to register plugin %s:%d, %s", manager.ApplianceConfigure, 1, err)
if err := manager.Migrator.Register(version.MaxPluginVersion, manager.ApplianceConfigure, &plugin1.ApplianceStopSignalRename{}); err != nil {
log.Errorf("Failed to register plugin %s:%d, %s", manager.ApplianceConfigure, version.MaxPluginVersion, err)
panic(err)
}
}

Expand Down Expand Up @@ -72,7 +74,7 @@ func TestMigrateConfigure(t *testing.T) {
assert.True(t, migrated, "should be migrated")

latestVer := newData[manager.ApplianceVersionKey]
assert.Equal(t, "1", latestVer, "upgrade version mismatch")
assert.Equal(t, strconv.Itoa(version.MaxPluginVersion), latestVer, "upgrade version mismatch")

// check new data
var found bool
Expand Down Expand Up @@ -102,7 +104,7 @@ func TestMigrateConfigure(t *testing.T) {
newConf := &config.VirtualContainerHostConfigSpec{}
extraconfig.Decode(extraconfig.MapSource(newData), newConf)

assert.Equal(t, 1, newConf.Version.PluginVersion, "should not be migrated")
assert.Equal(t, version.MaxPluginVersion, newConf.Version.PluginVersion, "should not be migrated")
t.Logf("other version fields: %s", newConf.Version.String())
}

Expand Down Expand Up @@ -139,5 +141,5 @@ func TestIsDataOlder(t *testing.T) {

older, err = ContainerDataIsOlder(mapData)
assert.Equal(t, nil, err, "should not have error")
assert.False(t, older, "Test data should not be older than latest, no container update plugin registered yet")
assert.True(t, older, "Test data should be older than latest since a container update plugin has been registered")
}
4 changes: 4 additions & 0 deletions lib/migration/plugins/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@
package plugins

// import all plugin packages here to register plugins
import (
_ "github.com/vmware/vic/lib/migration/plugins/plugin1"
_ "github.com/vmware/vic/lib/migration/plugins/plugin2"
)
128 changes: 128 additions & 0 deletions lib/migration/plugins/plugin1/commonSpecForVCH.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
// Copyright 2017 VMware, Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package plugin1

import (
"context"
"fmt"

"github.com/vmware/vic/lib/migration/manager"

log "github.com/Sirupsen/logrus"
"github.com/vmware/vic/lib/migration/errors"
"github.com/vmware/vic/pkg/trace"
"github.com/vmware/vic/pkg/vsphere/extraconfig"
"github.com/vmware/vic/pkg/vsphere/session"
)

const (
version = 1
target = manager.ApplianceConfigure
)

func init() {
defer trace.End(trace.Begin(fmt.Sprintf("Registering plugin %s:%d", target, version)))
if err := manager.Migrator.Register(version, target, &AddCommonSpecForVCH{}); err != nil {
log.Errorf("Failed to register plugin %s:%d, %s", target, version, err)
panic(err)
}
}

// AddCommonSpecForVM is plugin for vic 0.8.0-GA version upgrade
type AddCommonSpecForVCH struct {
}

type VirtualContainerHostConfigSpec struct {
ExecutorConfig `vic:"0.1" scope:"read-only" key:"init"`
}

type ExecutorConfig struct {
Common `vic:"0.1" scope:"read-only" key:"common"`
}

type Common struct {
// A reference to the components hosting execution environment, if any
ExecutionEnvironment string

// Unambiguous ID with meaning in the context of its hosting execution environment
ID string `vic:"0.1" scope:"read-only" key:"id"`

// Convenience field to record a human readable name
Name string `vic:"0.1" scope:"read-only" key:"name"`

// Freeform notes related to the entity
Notes string `vic:"0.1" scope:"hidden" key:"notes"`
}

type UpdatedVCHConfigSpec struct {
UpdatedExecutorConfig `vic:"0.1" scope:"read-only" key:"init"`
}

type UpdatedExecutorConfig struct {
UpdatedCommon `vic:"0.1" scope:"read-only" key:"common"`
}

type UpdatedCommon struct {
// A reference to the components hosting execution environment, if any
ExecutionEnvironment string

// Unambiguous ID with meaning in the context of its hosting execution environment
ID string `vic:"0.1" scope:"read-only" key:"id"`

// Convenience field to record a human readable name
Name string `vic:"0.1" scope:"hidden" key:"name"`

// Freeform notes related to the entity
Notes string `vic:"0.1" scope:"hidden" key:"notes"`
}

func (p *AddCommonSpecForVCH) Migrate(ctx context.Context, s *session.Session, data interface{}) error {
defer trace.End(trace.Begin(fmt.Sprintf("AddCommonSpecForVCH version: %d", version)))
if data == nil {
return nil
}
mapData, ok := data.(map[string]string)
if !ok {
// Log the error here and return nil so that other plugins can proceed
log.Errorf("Migration data format is not map: %+v", data)
return nil
}
oldStruct := &VirtualContainerHostConfigSpec{}
result := extraconfig.Decode(extraconfig.MapSource(mapData), oldStruct)
log.Debugf("The oldStruct is %+v", oldStruct)
if result == nil {
return &errors.DecodeError{Err: fmt.Errorf("decode oldStruct %+v failed", oldStruct)}
}

newStruct := &UpdatedVCHConfigSpec{
UpdatedExecutorConfig: UpdatedExecutorConfig{
UpdatedCommon: UpdatedCommon{
Name: oldStruct.Name,
ID: oldStruct.ID,
ExecutionEnvironment: oldStruct.ExecutionEnvironment,
Notes: oldStruct.Notes,
},
},
}

cfg := make(map[string]string)
extraconfig.Encode(extraconfig.MapSink(cfg), newStruct)

for k, v := range cfg {
log.Debugf("New data: %s:%s", k, v)
mapData[k] = v
}
return nil
}
Loading

0 comments on commit 27186d0

Please sign in to comment.