From e63f1d1743035e79488b8aaca496d46083c3f2c1 Mon Sep 17 00:00:00 2001 From: chengwang86 Date: Tue, 14 Feb 2017 09:21:04 -0800 Subject: [PATCH 01/58] initial design proposal for docker rename --- doc/design/docker-rename.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/design/docker-rename.md b/doc/design/docker-rename.md index 543dbc2b17..d96f9dcd97 100644 --- a/doc/design/docker-rename.md +++ b/doc/design/docker-rename.md @@ -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. \ No newline at end of file From f080eb7ec7afc23d81f8e26d6e47e2699f932b72 Mon Sep 17 00:00:00 2001 From: chengwang86 Date: Thu, 23 Feb 2017 14:39:58 -0800 Subject: [PATCH 02/58] reconfigure the VM display name right after VM creation. --- lib/portlayer/exec/commit.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/lib/portlayer/exec/commit.go b/lib/portlayer/exec/commit.go index 354881048c..3cd514e157 100644 --- a/lib/portlayer/exec/commit.go +++ b/lib/portlayer/exec/commit.go @@ -26,10 +26,13 @@ import ( "github.com/vmware/vic/pkg/vsphere/session" "github.com/vmware/vic/pkg/vsphere/tasks" "github.com/vmware/vic/pkg/vsphere/vm" + "github.com/vmware/vic/lib/spec/" log "github.com/Sirupsen/logrus" ) +const maxVMNameLength = 80 + // Commit executes the requires steps on the handle func Commit(ctx context.Context, sess *session.Session, h *Handle, waitTime *int32) error { defer trace.End(trace.Begin(h.ExecConfig.ID)) @@ -92,6 +95,25 @@ func Commit(ctx context.Context, sess *session.Session, h *Handle, waitTime *int // clear the spec as we've acted on it - this prevents a reconfigure from occurring in follow-on // processing h.Spec = nil + + // reconfigure vm display name to containerName-containerID + nameMaxLen := maxVMNameLength - len(c.ExecConfig.ID) + prettyName := c.ExecConfig.Name + if len(prettyName) > nameMaxLen-1 { + prettyName = prettyName[:nameMaxLen-1] + } + + fullName := fmt.Sprintf("%s-%s", prettyName, c.ExecConfig.ID) + task, err := h.vm.VirtualMachine.Rename(ctx, fullName) + if err != nil { + return err + } + + _, err = task.WaitForResult(ctx, nil) + if err != nil { + return err + } + } // if we're stopping the VM, do so before the reconfigure to preserve the extraconfig From 660806673b83b5076a4ed08aa25d5ad64feb7fb3 Mon Sep 17 00:00:00 2001 From: chengwang86 Date: Thu, 23 Feb 2017 15:05:20 -0800 Subject: [PATCH 03/58] add test case in docker create and check the VM display name --- .../Group1-Docker-Commands/1-04-Docker-Create.md | 2 ++ .../Group1-Docker-Commands/1-04-Docker-Create.robot | 9 ++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/tests/test-cases/Group1-Docker-Commands/1-04-Docker-Create.md b/tests/test-cases/Group1-Docker-Commands/1-04-Docker-Create.md index 2b25972f91..018872d4fd 100644 --- a/tests/test-cases/Group1-Docker-Commands/1-04-Docker-Create.md +++ b/tests/test-cases/Group1-Docker-Commands/1-04-Docker-Create.md @@ -40,6 +40,7 @@ This test requires that a vSphere server is running and available 27. Create a container with a custom amount of Memory in KB 28. Create a container with a custom amount of Memory in Bytes 29. Create a container using a rest api call without HostConfig in the form data +30. Create a container, then check the vm display name in vsphere through govc #Expected Outcome: * Steps 3-7 should all return without error and printing the container ID on return @@ -55,6 +56,7 @@ This test requires that a vSphere server is running and available * Step 23 should return with the following error message - Error response from daemon: No command specified * Steps 24-28 should return without error. * Step 29 should return without error. +* Step 30 should show that the VM display name equals to containerName-containerID #Possible Problems: None diff --git a/tests/test-cases/Group1-Docker-Commands/1-04-Docker-Create.robot b/tests/test-cases/Group1-Docker-Commands/1-04-Docker-Create.robot index fe7c057e34..6986d0938a 100644 --- a/tests/test-cases/Group1-Docker-Commands/1-04-Docker-Create.robot +++ b/tests/test-cases/Group1-Docker-Commands/1-04-Docker-Create.robot @@ -180,4 +180,11 @@ Create a container with custom amount of memory in Bytes Create a container using rest api call without HostConfig in the form data ${output}= Run curl -sk --cert %{DOCKER_CERT_PATH}/cert.pem --key %{DOCKER_CERT_PATH}/key.pem -H "Content-Type: application/json" -d '{"Image": "busybox", "Cmd": ["ping", "127.0.0.1"], "NetworkMode": "bridge"}' https://%{VCH-IP}:2376/containers/create Log ${output} - Should contain ${output} "Warnings":null \ No newline at end of file + Should contain ${output} "Warnings":null + +Create a container and check the VM display name + ${rc} ${id}= Run And Return Rc And Output docker %{VCH-PARAMS} create -it --name busy3 busybox + Should Be Equal As Integers ${rc} 0 + ${rc} ${output}= Run And Return Rc And Output govc vm.info busy3-${id} + Should contain ${output} busy3-${id} + Should Be Equal As Integers ${rc} 0 \ No newline at end of file From d26775d5934b10af9e7c615c99fd70576e9a1048 Mon Sep 17 00:00:00 2001 From: chengwang86 Date: Mon, 27 Feb 2017 07:34:14 -0800 Subject: [PATCH 04/58] set the VM display name to containerID when creating the container --- lib/spec/spec.go | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/spec/spec.go b/lib/spec/spec.go index b743f1e38e..395aadfc1c 100644 --- a/lib/spec/spec.go +++ b/lib/spec/spec.go @@ -94,16 +94,17 @@ func NewVirtualMachineConfigSpec(ctx context.Context, session *session.Session, // TEMPORARY // set VM name to prettyname-ID, to make it readable a little bit // if prettyname-ID is longer than max vm name length, truncate pretty name, instead of UUID, to make it unique - nameMaxLen := maxVMNameLength - len(config.ID) - prettyName := config.Name - if len(prettyName) > nameMaxLen-1 { - prettyName = prettyName[:nameMaxLen-1] - } - fullName := fmt.Sprintf("%s-%s", prettyName, config.ID) - config.VMFullName = fullName + //nameMaxLen := maxVMNameLength - len(config.ID) + //prettyName := config.Name + //if len(prettyName) > nameMaxLen-1 { + // prettyName = prettyName[:nameMaxLen-1] + //} + //fullName := fmt.Sprintf("%s-%s", prettyName, config.ID) + //config.VMFullName = fullName + config.VMFullName = config.ID s := &types.VirtualMachineConfigSpec{ - Name: fullName, + Name: config.ID, Uuid: config.BiosUUID, Files: &types.VirtualMachineFileInfo{ VmPathName: config.VMPathName, From 4b10dd59969413a20c850cc494bcdeba164c53ea Mon Sep 17 00:00:00 2001 From: chengwang86 Date: Mon, 27 Feb 2017 07:40:22 -0800 Subject: [PATCH 05/58] check go fmt and goimport --- lib/portlayer/exec/commit.go | 1 - lib/spec/spec.go | 1 - 2 files changed, 2 deletions(-) diff --git a/lib/portlayer/exec/commit.go b/lib/portlayer/exec/commit.go index 3cd514e157..07dff7b691 100644 --- a/lib/portlayer/exec/commit.go +++ b/lib/portlayer/exec/commit.go @@ -26,7 +26,6 @@ import ( "github.com/vmware/vic/pkg/vsphere/session" "github.com/vmware/vic/pkg/vsphere/tasks" "github.com/vmware/vic/pkg/vsphere/vm" - "github.com/vmware/vic/lib/spec/" log "github.com/Sirupsen/logrus" ) diff --git a/lib/spec/spec.go b/lib/spec/spec.go index 395aadfc1c..5c757556ba 100644 --- a/lib/spec/spec.go +++ b/lib/spec/spec.go @@ -15,7 +15,6 @@ package spec import ( - "fmt" "net/url" "context" From 5470a29857dfa8521162ddfabbd33bb53a109151 Mon Sep 17 00:00:00 2001 From: chengwang86 Date: Mon, 27 Feb 2017 07:53:31 -0800 Subject: [PATCH 06/58] update the test case for vm reconfigure --- .../Group1-Docker-Commands/1-04-Docker-Create.robot | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test-cases/Group1-Docker-Commands/1-04-Docker-Create.robot b/tests/test-cases/Group1-Docker-Commands/1-04-Docker-Create.robot index 6986d0938a..fa1313bdde 100644 --- a/tests/test-cases/Group1-Docker-Commands/1-04-Docker-Create.robot +++ b/tests/test-cases/Group1-Docker-Commands/1-04-Docker-Create.robot @@ -186,5 +186,5 @@ Create a container and check the VM display name ${rc} ${id}= Run And Return Rc And Output docker %{VCH-PARAMS} create -it --name busy3 busybox Should Be Equal As Integers ${rc} 0 ${rc} ${output}= Run And Return Rc And Output govc vm.info busy3-${id} - Should contain ${output} busy3-${id} - Should Be Equal As Integers ${rc} 0 \ No newline at end of file + Should Be Equal As Integers ${rc} 0 + Should contain ${output} busy3-${id} \ No newline at end of file From 661886d5a27f5eed28fc0c7335573d8b668a1f5a Mon Sep 17 00:00:00 2001 From: chengwang86 Date: Mon, 27 Feb 2017 10:43:51 -0800 Subject: [PATCH 07/58] update test --- .../1-04-Docker-Create.robot | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/tests/test-cases/Group1-Docker-Commands/1-04-Docker-Create.robot b/tests/test-cases/Group1-Docker-Commands/1-04-Docker-Create.robot index fa1313bdde..3de1cb95c3 100644 --- a/tests/test-cases/Group1-Docker-Commands/1-04-Docker-Create.robot +++ b/tests/test-cases/Group1-Docker-Commands/1-04-Docker-Create.robot @@ -18,6 +18,15 @@ Resource ../../resources/Util.robot Suite Setup Install VIC Appliance To Test Server Suite Teardown Cleanup VIC Appliance On Test Server +*** Keywords *** +Obtain VM name from container id + [Arguments] ${id} + ${rc} ${name}= Run And Return Rc And Output docker %{VCH-PARAMS} inspect --format='{{.Name}}' ${id} + Should Be Equal As Integers ${rc} 0 + ${name}= Get Substring ${name} 1 + ${vmName}= Catenate SEPARATOR=- ${name} ${id} + [Return] ${vmName} + *** Test Cases *** Simple creates ${rc} ${output}= Run And Return Rc And Output docker %{VCH-PARAMS} pull busybox @@ -120,8 +129,7 @@ Create a container with no command specified Create a container with custom CPU count ${rc} ${id}= Run And Return Rc And Output docker %{VCH-PARAMS} create -it --cpuset-cpus 3 busybox Should Be Equal As Integers ${rc} 0 - ${rc} ${id}= Run And Return Rc And Output govc datastore.ls |grep ${id} - Should Be Equal As Integers ${rc} 0 + ${id}= Obtain VM name from container id ${id} ${rc} ${output}= Run Keyword If '%{HOST_TYPE}' == 'VC' Run And Return Rc And Output govc vm.info %{VCH-NAME}/${id} |awk '/CPU:/ {print $2}' Run Keyword If '%{HOST_TYPE}' == 'VC' Should Be Equal As Integers ${rc} 0 Run Keyword If '%{HOST_TYPE}' == 'VC' Should Contain ${output} 3 @@ -132,8 +140,7 @@ Create a container with custom CPU count Create a container with custom amount of memory in GB ${rc} ${id}= Run And Return Rc And Output docker %{VCH-PARAMS} create -it -m 4G busybox Should Be Equal As Integers ${rc} 0 - ${rc} ${id}= Run And Return Rc And Output govc datastore.ls |grep ${id} - Should Be Equal As Integers ${rc} 0 + ${id}= Obtain VM name from container id ${id} ${rc} ${output}= Run Keyword If '%{HOST_TYPE}' == 'VC' Run And Return Rc And Output govc vm.info %{VCH-NAME}/${id} |awk '/Memory:/ {print $2}' Run Keyword If '%{HOST_TYPE}' == 'VC' Should Be Equal As Integers ${rc} 0 Run Keyword If '%{HOST_TYPE}' == 'VC' Should Contain ${output} 4096MB @@ -144,8 +151,7 @@ Create a container with custom amount of memory in GB Create a container with custom amount of memory in MB ${rc} ${id}= Run And Return Rc And Output docker %{VCH-PARAMS} create -it -m 2048M busybox Should Be Equal As Integers ${rc} 0 - ${rc} ${id}= Run And Return Rc And Output govc datastore.ls |grep ${id} - Should Be Equal As Integers ${rc} 0 + ${id}= Obtain VM name from container id ${id} ${rc} ${output}= Run Keyword If '%{HOST_TYPE}' == 'VC' Run And Return Rc And Output govc vm.info %{VCH-NAME}/${id} |awk '/Memory:/ {print $2}' Run Keyword If '%{HOST_TYPE}' == 'VC' Should Be Equal As Integers ${rc} 0 Run Keyword If '%{HOST_TYPE}' == 'VC' Should Contain ${output} 2048MB @@ -156,8 +162,7 @@ Create a container with custom amount of memory in MB Create a container with custom amount of memory in KB ${rc} ${id}= Run And Return Rc And Output docker %{VCH-PARAMS} create -it -m 2097152K busybox Should Be Equal As Integers ${rc} 0 - ${rc} ${id}= Run And Return Rc And Output govc datastore.ls |grep ${id} - Should Be Equal As Integers ${rc} 0 + ${id}= Obtain VM name from container id ${id} ${rc} ${output}= Run Keyword If '%{HOST_TYPE}' == 'VC' Run And Return Rc And Output govc vm.info %{VCH-NAME}/${id} |awk '/Memory:/ {print $2}' Run Keyword If '%{HOST_TYPE}' == 'VC' Should Be Equal As Integers ${rc} 0 Run Keyword If '%{HOST_TYPE}' == 'VC' Should Contain ${output} 2048MB @@ -168,8 +173,7 @@ Create a container with custom amount of memory in KB Create a container with custom amount of memory in Bytes ${rc} ${id}= Run And Return Rc And Output docker %{VCH-PARAMS} create -it -m 2147483648B busybox Should Be Equal As Integers ${rc} 0 - ${rc} ${id}= Run And Return Rc And Output govc datastore.ls |grep ${id} - Should Be Equal As Integers ${rc} 0 + ${id}= Obtain VM name from container id ${id} ${rc} ${output}= Run Keyword If '%{HOST_TYPE}' == 'VC' Run And Return Rc And Output govc vm.info %{VCH-NAME}/${id} |awk '/Memory:/ {print $2}' Run Keyword If '%{HOST_TYPE}' == 'VC' Should Be Equal As Integers ${rc} 0 Run Keyword If '%{HOST_TYPE}' == 'VC' Should Contain ${output} 2048MB @@ -185,6 +189,8 @@ Create a container using rest api call without HostConfig in the form data Create a container and check the VM display name ${rc} ${id}= Run And Return Rc And Output docker %{VCH-PARAMS} create -it --name busy3 busybox Should Be Equal As Integers ${rc} 0 + ${vmName}= Obtain VM name from container id ${id} + Should Be Equal ${vmName} busy3-${id} ${rc} ${output}= Run And Return Rc And Output govc vm.info busy3-${id} Should Be Equal As Integers ${rc} 0 Should contain ${output} busy3-${id} \ No newline at end of file From 564de55ba7cab0227aa475823963fc53449ffd4b Mon Sep 17 00:00:00 2001 From: chengwang86 Date: Tue, 28 Feb 2017 08:59:36 -0800 Subject: [PATCH 08/58] use containerShortID --- lib/portlayer/exec/commit.go | 6 ++++-- .../test-cases/Group1-Docker-Commands/1-04-Docker-Create.md | 2 +- .../Group1-Docker-Commands/1-04-Docker-Create.robot | 1 + 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/portlayer/exec/commit.go b/lib/portlayer/exec/commit.go index 07dff7b691..461cdfcd4b 100644 --- a/lib/portlayer/exec/commit.go +++ b/lib/portlayer/exec/commit.go @@ -28,6 +28,7 @@ import ( "github.com/vmware/vic/pkg/vsphere/vm" log "github.com/Sirupsen/logrus" + "github.com/docker/docker/pkg/stringid" ) const maxVMNameLength = 80 @@ -96,13 +97,14 @@ func Commit(ctx context.Context, sess *session.Session, h *Handle, waitTime *int h.Spec = nil // reconfigure vm display name to containerName-containerID - nameMaxLen := maxVMNameLength - len(c.ExecConfig.ID) + shortID := stringid.TruncateID(c.ExecConfig.ID) + nameMaxLen := maxVMNameLength - len(shortID) prettyName := c.ExecConfig.Name if len(prettyName) > nameMaxLen-1 { prettyName = prettyName[:nameMaxLen-1] } - fullName := fmt.Sprintf("%s-%s", prettyName, c.ExecConfig.ID) + fullName := fmt.Sprintf("%s-%s", prettyName, shortID) task, err := h.vm.VirtualMachine.Rename(ctx, fullName) if err != nil { return err diff --git a/tests/test-cases/Group1-Docker-Commands/1-04-Docker-Create.md b/tests/test-cases/Group1-Docker-Commands/1-04-Docker-Create.md index 018872d4fd..9e102bdba4 100644 --- a/tests/test-cases/Group1-Docker-Commands/1-04-Docker-Create.md +++ b/tests/test-cases/Group1-Docker-Commands/1-04-Docker-Create.md @@ -56,7 +56,7 @@ This test requires that a vSphere server is running and available * Step 23 should return with the following error message - Error response from daemon: No command specified * Steps 24-28 should return without error. * Step 29 should return without error. -* Step 30 should show that the VM display name equals to containerName-containerID +* Step 30 should show that the VM display name equals to containerName-containerShortID #Possible Problems: None diff --git a/tests/test-cases/Group1-Docker-Commands/1-04-Docker-Create.robot b/tests/test-cases/Group1-Docker-Commands/1-04-Docker-Create.robot index 3de1cb95c3..8c85bfc7a7 100644 --- a/tests/test-cases/Group1-Docker-Commands/1-04-Docker-Create.robot +++ b/tests/test-cases/Group1-Docker-Commands/1-04-Docker-Create.robot @@ -24,6 +24,7 @@ Obtain VM name from container id ${rc} ${name}= Run And Return Rc And Output docker %{VCH-PARAMS} inspect --format='{{.Name}}' ${id} Should Be Equal As Integers ${rc} 0 ${name}= Get Substring ${name} 1 + ${id}= Get Subsring ${id} 0 13 ${vmName}= Catenate SEPARATOR=- ${name} ${id} [Return] ${vmName} From e76636bed5aebe0a4b13d59f5c60dec612a4acde Mon Sep 17 00:00:00 2001 From: chengwang86 Date: Tue, 28 Feb 2017 14:13:39 -0800 Subject: [PATCH 09/58] correct error in the test case for docker create --- .../1-04-Docker-Create.robot | 102 +----------------- 1 file changed, 5 insertions(+), 97 deletions(-) diff --git a/tests/test-cases/Group1-Docker-Commands/1-04-Docker-Create.robot b/tests/test-cases/Group1-Docker-Commands/1-04-Docker-Create.robot index 8c85bfc7a7..14abc7baa9 100644 --- a/tests/test-cases/Group1-Docker-Commands/1-04-Docker-Create.robot +++ b/tests/test-cases/Group1-Docker-Commands/1-04-Docker-Create.robot @@ -24,7 +24,7 @@ Obtain VM name from container id ${rc} ${name}= Run And Return Rc And Output docker %{VCH-PARAMS} inspect --format='{{.Name}}' ${id} Should Be Equal As Integers ${rc} 0 ${name}= Get Substring ${name} 1 - ${id}= Get Subsring ${id} 0 13 + ${id}= Get Substring ${id} 0 12 ${vmName}= Catenate SEPARATOR=- ${name} ${id} [Return] ${vmName} @@ -33,99 +33,6 @@ Simple creates ${rc} ${output}= Run And Return Rc And Output docker %{VCH-PARAMS} pull busybox Should Be Equal As Integers ${rc} 0 Should Not Contain ${output} Error - ${rc} ${output}= Run And Return Rc And Output docker %{VCH-PARAMS} create busybox - Should Be Equal As Integers ${rc} 0 - Should Not Contain ${output} Error - ${rc} ${output}= Run And Return Rc And Output docker %{VCH-PARAMS} create -t -i busybox - Should Be Equal As Integers ${rc} 0 - Should Not Contain ${output} Error - ${rc} ${output}= Run And Return Rc And Output docker %{VCH-PARAMS} create --name test1 busybox - Should Be Equal As Integers ${rc} 0 - Should Not Contain ${output} Error - -Create with anonymous volume - ${rc} ${output}= Run And Return Rc And Output docker %{VCH-PARAMS} create -v /var/log busybox ls /var/log - Should Be Equal As Integers ${rc} 0 - Should Not Contain ${output} Error - ${rc} ${output}= Run And Return Rc And Output docker %{VCH-PARAMS} start ${output} - Should Be Equal As Integers ${rc} 0 - Should Not Contain ${output} Error - ${rc} ${output}= Run And Return Rc And Output docker %{VCH-PARAMS} logs --follow ${output} - Should Be Equal As Integers ${rc} 0 - Should Not Contain ${output} Error - -Create with named volume - ${disk-size}= Run docker %{VCH-PARAMS} logs $(docker %{VCH-PARAMS} start $(docker %{VCH-PARAMS} create -v test-named-vol:/testdir busybox /bin/df -Ph) && sleep 10) | grep by-label | awk '{print $2}' - Should Be Equal As Strings ${disk-size} 975.9M - -Create with a directory as a volume - ${rc} ${output}= Run And Return Rc And Output docker %{VCH-PARAMS} create -v /dir:/dir busybox - Should Be Equal As Integers ${rc} 1 - Should Contain ${output} Error response from daemon: Bad request error from portlayer: vSphere Integrated Containers does not support mounting directories as a data volume. - -Create simple top example - ${rc} ${output}= Run And Return Rc And Output docker %{VCH-PARAMS} create busybox /bin/top - Should Be Equal As Integers ${rc} 0 - Should Not Contain ${output} Error - -Create fakeimage image - ${rc} ${output}= Run And Return Rc And Output docker %{VCH-PARAMS} create fakeimage - Should Be Equal As Integers ${rc} 1 - Should Contain ${output} Error: image library/fakeimage not found - -Create fakeImage repository - ${rc} ${output}= Run And Return Rc And Output docker %{VCH-PARAMS} create fakeImage - Should Be Equal As Integers ${rc} 1 - Should Contain ${output} Error parsing reference: "fakeImage" is not a valid repository/tag - -Create and start named container - ${rc} ${output}= Run And Return Rc And Output docker %{VCH-PARAMS} create --name busy1 busybox /bin/top - Should Be Equal As Integers ${rc} 0 - Should Not Contain ${output} Error - ${rc} ${output}= Run And Return Rc And Output docker %{VCH-PARAMS} start busy1 - Should Be Equal As Integers ${rc} 0 - Should Not Contain ${output} Error - -Create linked containers that can ping - ${rc} ${output}= Run And Return Rc And Output docker %{VCH-PARAMS} pull debian - Should Be Equal As Integers ${rc} 0 - - ${rc} ${output}= Run And Return Rc And Output docker %{VCH-PARAMS} create --link busy1:busy1 --name busy2 debian ping -c2 busy1 - Should Be Equal As Integers ${rc} 0 - Should Not Contain ${output} Error - ${rc} ${output}= Run And Return Rc And Output docker %{VCH-PARAMS} start busy2 - Should Be Equal As Integers ${rc} 0 - Should Not Contain ${output} Error - ${rc} ${output}= Run And Return Rc And Output docker %{VCH-PARAMS} wait busy2 - Should Be Equal As Integers ${rc} 0 - Should Not Contain ${output} Error - ${rc} ${output}= Run And Return Rc And Output docker %{VCH-PARAMS} logs busy2 - Should Be Equal As Integers ${rc} 0 - Should Contain ${output} 2 packets transmitted, 2 packets received - -Create a container after the last container is removed - ${rc} ${output}= Run And Return Rc And Output docker %{VCH-PARAMS} pull busybox - Should Be Equal As Integers ${rc} 0 - Should Not Contain ${output} Error - ${rc} ${cid}= Run And Return Rc And Output docker %{VCH-PARAMS} create busybox - Should Be Equal As Integers ${rc} 0 - Should Not Contain ${cid} Error - ${rc} ${output}= Run And Return Rc And Output docker %{VCH-PARAMS} rm ${cid} - Should Be Equal As Integers ${rc} 0 - Should Not Contain ${output} Error - ${rc} ${cid2}= Run And Return Rc And Output docker %{VCH-PARAMS} create busybox - Should Be Equal As Integers ${rc} 0 - Should Not Contain ${cid2} Error - -Create a container from an image that has not been pulled yet - ${rc} ${output}= Run And Return Rc And Output docker %{VCH-PARAMS} create alpine bash - Should Be Equal As Integers ${rc} 0 - Should Not Contain ${output} Error - -Create a container with no command specified - ${rc} ${output}= Run And Return Rc And Output docker %{VCH-PARAMS} create alpine - Should Be Equal As Integers ${rc} 1 - Should Contain ${output} Error response from daemon: No command specified Create a container with custom CPU count ${rc} ${id}= Run And Return Rc And Output docker %{VCH-PARAMS} create -it --cpuset-cpus 3 busybox @@ -191,7 +98,8 @@ Create a container and check the VM display name ${rc} ${id}= Run And Return Rc And Output docker %{VCH-PARAMS} create -it --name busy3 busybox Should Be Equal As Integers ${rc} 0 ${vmName}= Obtain VM name from container id ${id} - Should Be Equal ${vmName} busy3-${id} - ${rc} ${output}= Run And Return Rc And Output govc vm.info busy3-${id} + ${shortID}= Get Substring ${id} 0 12 + Should Be Equal ${vmName} busy3-${shortID} + ${rc} ${output}= Run And Return Rc And Output govc vm.info ${vmName} Should Be Equal As Integers ${rc} 0 - Should contain ${output} busy3-${id} \ No newline at end of file + Should contain ${output} ${vmName} \ No newline at end of file From f686b89ff108ba206cbed15b4d83f0d0d38e4cb8 Mon Sep 17 00:00:00 2001 From: chengwang86 Date: Thu, 2 Mar 2017 10:54:53 -0800 Subject: [PATCH 10/58] add common2 and use it for vm creation; here the name in common2 is set to "hidden" so that it could be persisted after rename --- cmd/tether/attach_test.go | 10 +++++----- cmd/vic-init/restart_test.go | 2 +- .../restapi/handlers/containers_handlers.go | 2 +- lib/config/executor/container_vm.go | 17 ++++++++++++++++- lib/spec/spec.go | 12 ------------ lib/tether/cmd_test.go | 12 ++++++------ lib/tether/config_test.go | 2 +- lib/tether/net_linux_test.go | 2 +- lib/tether/net_test.go | 4 ++-- 9 files changed, 33 insertions(+), 30 deletions(-) diff --git a/cmd/tether/attach_test.go b/cmd/tether/attach_test.go index b05f5379eb..e9b2a3e9f5 100644 --- a/cmd/tether/attach_test.go +++ b/cmd/tether/attach_test.go @@ -232,7 +232,7 @@ func attachCase(t *testing.T, runblock bool) { testServer, _ := server.(*testAttachServer) cfg := executor.ExecutorConfig{ - Common: executor.Common{ + Common2: executor.Common2{ ID: "attach", Name: "tether_test_executor", }, @@ -336,7 +336,7 @@ func TestAttachTTY(t *testing.T) { testServer, _ := server.(*testAttachServer) cfg := executor.ExecutorConfig{ - Common: executor.Common{ + Common2: executor.Common2{ ID: "attach", Name: "tether_test_executor", }, @@ -435,7 +435,7 @@ func TestAttachMultiple(t *testing.T) { testServer, _ := server.(*testAttachServer) cfg := executor.ExecutorConfig{ - Common: executor.Common{ + Common2: executor.Common2{ ID: "tee1", Name: "tether_test_executor", }, @@ -603,7 +603,7 @@ func TestAttachInvalid(t *testing.T) { testServer, _ := server.(*testAttachServer) cfg := executor.ExecutorConfig{ - Common: executor.Common{ + Common2: executor.Common2{ ID: "attachinvalid", Name: "tether_test_executor", }, @@ -740,7 +740,7 @@ func TestReattach(t *testing.T) { testServer, _ := server.(*testAttachServer) cfg := executor.ExecutorConfig{ - Common: executor.Common{ + Common2: executor.Common2{ ID: "attach", Name: "tether_test_executor", }, diff --git a/cmd/vic-init/restart_test.go b/cmd/vic-init/restart_test.go index b4466a825d..b679a29ecc 100644 --- a/cmd/vic-init/restart_test.go +++ b/cmd/vic-init/restart_test.go @@ -39,7 +39,7 @@ func TestRestart(t *testing.T) { defer testTeardown(t) cfg := executor.ExecutorConfig{ - Common: executor.Common{ + Common2: executor.Common2{ ID: "pathlookup", Name: "tether_test_executor", }, diff --git a/lib/apiservers/portlayer/restapi/handlers/containers_handlers.go b/lib/apiservers/portlayer/restapi/handlers/containers_handlers.go index fceaf44fce..5c2a180808 100644 --- a/lib/apiservers/portlayer/restapi/handlers/containers_handlers.go +++ b/lib/apiservers/portlayer/restapi/handlers/containers_handlers.go @@ -88,7 +88,7 @@ func (handler *ContainersHandlersImpl) CreateHandler(params containers.CreatePar } m := &executor.ExecutorConfig{ - Common: executor.Common{ + Common2: executor.Common2{ ID: id, Name: params.CreateConfig.Name, }, diff --git a/lib/config/executor/container_vm.go b/lib/config/executor/container_vm.go index caee26e4e5..ee81889bf9 100644 --- a/lib/config/executor/container_vm.go +++ b/lib/config/executor/container_vm.go @@ -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 Common2 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 @@ -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"` + Common2 `vic:"0.1" scope:"read-only" key:"common"` // CreateTime stamp CreateTime int64 `vic:"0.1" scope:"read-write" key:"createtime"` diff --git a/lib/spec/spec.go b/lib/spec/spec.go index 5c757556ba..015402971f 100644 --- a/lib/spec/spec.go +++ b/lib/spec/spec.go @@ -33,8 +33,6 @@ const ( pciSlotNumberBegin int32 = 0xc0 pciSlotNumberEnd int32 = 1 << 10 pciSlotNumberInc int32 = 1 << 5 - - maxVMNameLength = 80 ) // VirtualMachineConfigSpecConfig holds the config values @@ -90,16 +88,6 @@ type VirtualMachineConfigSpec struct { func NewVirtualMachineConfigSpec(ctx context.Context, session *session.Session, config *VirtualMachineConfigSpecConfig) (*VirtualMachineConfigSpec, error) { defer trace.End(trace.Begin(config.ID)) - // TEMPORARY - // set VM name to prettyname-ID, to make it readable a little bit - // if prettyname-ID is longer than max vm name length, truncate pretty name, instead of UUID, to make it unique - //nameMaxLen := maxVMNameLength - len(config.ID) - //prettyName := config.Name - //if len(prettyName) > nameMaxLen-1 { - // prettyName = prettyName[:nameMaxLen-1] - //} - //fullName := fmt.Sprintf("%s-%s", prettyName, config.ID) - //config.VMFullName = fullName config.VMFullName = config.ID s := &types.VirtualMachineConfigSpec{ diff --git a/lib/tether/cmd_test.go b/lib/tether/cmd_test.go index 0cca6e4054..1fdd52102b 100644 --- a/lib/tether/cmd_test.go +++ b/lib/tether/cmd_test.go @@ -37,7 +37,7 @@ func TestPathLookup(t *testing.T) { defer testTeardown(t, mocker) cfg := executor.ExecutorConfig{ - Common: executor.Common{ + Common2: executor.Common2{ ID: "pathlookup", Name: "tether_test_executor", }, @@ -77,7 +77,7 @@ func TestRelativePath(t *testing.T) { defer testTeardown(t, mocker) cfg := executor.ExecutorConfig{ - Common: executor.Common{ + Common2: executor.Common2{ ID: "relpath", Name: "tether_test_executor", }, @@ -117,7 +117,7 @@ func TestAbsPath(t *testing.T) { defer testTeardown(t, mocker) cfg := executor.ExecutorConfig{ - Common: executor.Common{ + Common2: executor.Common2{ ID: "abspath", Name: "tether_test_executor", }, @@ -175,7 +175,7 @@ func TestHalt(t *testing.T) { defer testTeardown(t, mocker) cfg := executor.ExecutorConfig{ - Common: executor.Common{ + Common2: executor.Common2{ ID: "abspath", Name: "tether_test_executor", }, @@ -251,7 +251,7 @@ func TestMissingBinary(t *testing.T) { defer testTeardown(t, mocker) cfg := executor.ExecutorConfig{ - Common: executor.Common{ + Common2: executor.Common2{ ID: "missing", Name: "tether_test_executor", }, @@ -300,7 +300,7 @@ func TestMissingRelativeBinary(t *testing.T) { defer testTeardown(t, mocker) cfg := executor.ExecutorConfig{ - Common: executor.Common{ + Common2: executor.Common2{ ID: "missing", Name: "tether_test_executor", }, diff --git a/lib/tether/config_test.go b/lib/tether/config_test.go index 2bfda7126d..f55d6681d4 100644 --- a/lib/tether/config_test.go +++ b/lib/tether/config_test.go @@ -32,7 +32,7 @@ var ( func TestToExtraConfig(t *testing.T) { exec := executor.ExecutorConfig{ - Common: executor.Common{ + Common2: executor.Common2{ ID: "deadbeef", Name: "configtest", }, diff --git a/lib/tether/net_linux_test.go b/lib/tether/net_linux_test.go index 19305bb85c..9ff4f55fb6 100644 --- a/lib/tether/net_linux_test.go +++ b/lib/tether/net_linux_test.go @@ -74,7 +74,7 @@ func TestSetIpAddress(t *testing.T) { secondIP, _ := netlink.ParseIPNet("172.16.0.10/24") gwIP, _ := netlink.ParseIPNet("172.16.0.1/24") cfg := executor.ExecutorConfig{ - Common: executor.Common{ + Common2: executor.Common2{ ID: "ipconfig", Name: "tether_test_executor", }, diff --git a/lib/tether/net_test.go b/lib/tether/net_test.go index 67fa19a703..83e5c441fa 100644 --- a/lib/tether/net_test.go +++ b/lib/tether/net_test.go @@ -27,7 +27,7 @@ func TestSetHostname(t *testing.T) { defer testTeardown(t, mocker) cfg := executor.ExecutorConfig{ - Common: executor.Common{ + Common2: executor.Common2{ ID: "sethostname", Name: "tether_test_executor", }, @@ -54,7 +54,7 @@ func TestNoNetwork(t *testing.T) { defer testTeardown(t, mocker) cfg := executor.ExecutorConfig{ - Common: executor.Common{ + Common2: executor.Common2{ ID: "ipconfig", Name: "tether_test_executor", }, From 12e44ba7d99b566613f65c37f2a49c1f2d67a955 Mon Sep 17 00:00:00 2001 From: chengwang86 Date: Thu, 2 Mar 2017 12:36:56 -0800 Subject: [PATCH 11/58] update test cases so that they use the new naming convention for VM display name --- tests/resources/Docker-Util.robot | 14 +++ .../1-04-Docker-Create.robot | 117 +++++++++++++++--- .../1-07-Docker-Stop.robot | 10 +- .../1-10-Docker-PS.robot | 5 +- .../1-11-Docker-RM.robot | 5 +- .../Group13-VAC/13-01-VAC-GuestFullName.robot | 5 +- 6 files changed, 129 insertions(+), 27 deletions(-) diff --git a/tests/resources/Docker-Util.robot b/tests/resources/Docker-Util.robot index ad3dc82a90..dcead333ce 100644 --- a/tests/resources/Docker-Util.robot +++ b/tests/resources/Docker-Util.robot @@ -51,6 +51,20 @@ Get Container IP Should Be Equal As Integers ${rc} 0 [Return] ${ip} +Get container shortID + [Arguments] ${id} + ${shortID}= Get Substring ${id} 0 12 + [Return] ${shortID} + +Get VM display name + [Arguments] ${id} + ${rc} ${name}= Run And Return Rc And Output docker %{VCH-PARAMS} inspect --format='{{.Name}}' ${id} + Should Be Equal As Integers ${rc} 0 + ${name}= Get Substring ${name} 1 + ${shortID}= Get container shortID ${id} + ${vmName}= Catenate SEPARATOR=- ${name} ${shortID} + [Return] ${vmName} + Run Regression Tests ${rc} ${output}= Run And Return Rc And Output docker %{VCH-PARAMS} pull busybox Should Be Equal As Integers ${rc} 0 diff --git a/tests/test-cases/Group1-Docker-Commands/1-04-Docker-Create.robot b/tests/test-cases/Group1-Docker-Commands/1-04-Docker-Create.robot index 14abc7baa9..a1e396760a 100644 --- a/tests/test-cases/Group1-Docker-Commands/1-04-Docker-Create.robot +++ b/tests/test-cases/Group1-Docker-Commands/1-04-Docker-Create.robot @@ -18,26 +18,109 @@ Resource ../../resources/Util.robot Suite Setup Install VIC Appliance To Test Server Suite Teardown Cleanup VIC Appliance On Test Server -*** Keywords *** -Obtain VM name from container id - [Arguments] ${id} - ${rc} ${name}= Run And Return Rc And Output docker %{VCH-PARAMS} inspect --format='{{.Name}}' ${id} - Should Be Equal As Integers ${rc} 0 - ${name}= Get Substring ${name} 1 - ${id}= Get Substring ${id} 0 12 - ${vmName}= Catenate SEPARATOR=- ${name} ${id} - [Return] ${vmName} - *** Test Cases *** Simple creates ${rc} ${output}= Run And Return Rc And Output docker %{VCH-PARAMS} pull busybox Should Be Equal As Integers ${rc} 0 Should Not Contain ${output} Error + ${rc} ${output}= Run And Return Rc And Output docker %{VCH-PARAMS} create busybox + Should Be Equal As Integers ${rc} 0 + Should Not Contain ${output} Error + ${rc} ${output}= Run And Return Rc And Output docker %{VCH-PARAMS} create -t -i busybox + Should Be Equal As Integers ${rc} 0 + Should Not Contain ${output} Error + ${rc} ${output}= Run And Return Rc And Output docker %{VCH-PARAMS} create --name test1 busybox + Should Be Equal As Integers ${rc} 0 + Should Not Contain ${output} Error + +Create with anonymous volume + ${rc} ${output}= Run And Return Rc And Output docker %{VCH-PARAMS} create -v /var/log busybox ls /var/log + Should Be Equal As Integers ${rc} 0 + Should Not Contain ${output} Error + ${rc} ${output}= Run And Return Rc And Output docker %{VCH-PARAMS} start ${output} + Should Be Equal As Integers ${rc} 0 + Should Not Contain ${output} Error + ${rc} ${output}= Run And Return Rc And Output docker %{VCH-PARAMS} logs --follow ${output} + Should Be Equal As Integers ${rc} 0 + Should Not Contain ${output} Error + +Create with named volume + ${disk-size}= Run docker %{VCH-PARAMS} logs $(docker %{VCH-PARAMS} start $(docker %{VCH-PARAMS} create -v test-named-vol:/testdir busybox /bin/df -Ph) && sleep 10) | grep by-label | awk '{print $2}' + Should Be Equal As Strings ${disk-size} 975.9M + +Create with a directory as a volume + ${rc} ${output}= Run And Return Rc And Output docker %{VCH-PARAMS} create -v /dir:/dir busybox + Should Be Equal As Integers ${rc} 1 + Should Contain ${output} Error response from daemon: Bad request error from portlayer: vSphere Integrated Containers does not support mounting directories as a data volume. + +Create simple top example + ${rc} ${output}= Run And Return Rc And Output docker %{VCH-PARAMS} create busybox /bin/top + Should Be Equal As Integers ${rc} 0 + Should Not Contain ${output} Error + +Create fakeimage image + ${rc} ${output}= Run And Return Rc And Output docker %{VCH-PARAMS} create fakeimage + Should Be Equal As Integers ${rc} 1 + Should Contain ${output} Error: image library/fakeimage not found + +Create fakeImage repository + ${rc} ${output}= Run And Return Rc And Output docker %{VCH-PARAMS} create fakeImage + Should Be Equal As Integers ${rc} 1 + Should Contain ${output} Error parsing reference: "fakeImage" is not a valid repository/tag + +Create and start named container + ${rc} ${output}= Run And Return Rc And Output docker %{VCH-PARAMS} create --name busy1 busybox /bin/top + Should Be Equal As Integers ${rc} 0 + Should Not Contain ${output} Error + ${rc} ${output}= Run And Return Rc And Output docker %{VCH-PARAMS} start busy1 + Should Be Equal As Integers ${rc} 0 + Should Not Contain ${output} Error + +Create linked containers that can ping + ${rc} ${output}= Run And Return Rc And Output docker %{VCH-PARAMS} pull debian + Should Be Equal As Integers ${rc} 0 + + ${rc} ${output}= Run And Return Rc And Output docker %{VCH-PARAMS} create --link busy1:busy1 --name busy2 debian ping -c2 busy1 + Should Be Equal As Integers ${rc} 0 + Should Not Contain ${output} Error + ${rc} ${output}= Run And Return Rc And Output docker %{VCH-PARAMS} start busy2 + Should Be Equal As Integers ${rc} 0 + Should Not Contain ${output} Error + ${rc} ${output}= Run And Return Rc And Output docker %{VCH-PARAMS} wait busy2 + Should Be Equal As Integers ${rc} 0 + Should Not Contain ${output} Error + ${rc} ${output}= Run And Return Rc And Output docker %{VCH-PARAMS} logs busy2 + Should Be Equal As Integers ${rc} 0 + Should Contain ${output} 2 packets transmitted, 2 packets received + +Create a container after the last container is removed + ${rc} ${output}= Run And Return Rc And Output docker %{VCH-PARAMS} pull busybox + Should Be Equal As Integers ${rc} 0 + Should Not Contain ${output} Error + ${rc} ${cid}= Run And Return Rc And Output docker %{VCH-PARAMS} create busybox + Should Be Equal As Integers ${rc} 0 + Should Not Contain ${cid} Error + ${rc} ${output}= Run And Return Rc And Output docker %{VCH-PARAMS} rm ${cid} + Should Be Equal As Integers ${rc} 0 + Should Not Contain ${output} Error + ${rc} ${cid2}= Run And Return Rc And Output docker %{VCH-PARAMS} create busybox + Should Be Equal As Integers ${rc} 0 + Should Not Contain ${cid2} Error + +Create a container from an image that has not been pulled yet + ${rc} ${output}= Run And Return Rc And Output docker %{VCH-PARAMS} create alpine bash + Should Be Equal As Integers ${rc} 0 + Should Not Contain ${output} Error + +Create a container with no command specified + ${rc} ${output}= Run And Return Rc And Output docker %{VCH-PARAMS} create alpine + Should Be Equal As Integers ${rc} 1 + Should Contain ${output} Error response from daemon: No command specified Create a container with custom CPU count ${rc} ${id}= Run And Return Rc And Output docker %{VCH-PARAMS} create -it --cpuset-cpus 3 busybox Should Be Equal As Integers ${rc} 0 - ${id}= Obtain VM name from container id ${id} + ${id}= Get VM display name ${id} ${rc} ${output}= Run Keyword If '%{HOST_TYPE}' == 'VC' Run And Return Rc And Output govc vm.info %{VCH-NAME}/${id} |awk '/CPU:/ {print $2}' Run Keyword If '%{HOST_TYPE}' == 'VC' Should Be Equal As Integers ${rc} 0 Run Keyword If '%{HOST_TYPE}' == 'VC' Should Contain ${output} 3 @@ -48,7 +131,7 @@ Create a container with custom CPU count Create a container with custom amount of memory in GB ${rc} ${id}= Run And Return Rc And Output docker %{VCH-PARAMS} create -it -m 4G busybox Should Be Equal As Integers ${rc} 0 - ${id}= Obtain VM name from container id ${id} + ${id}= Get VM display name ${id} ${rc} ${output}= Run Keyword If '%{HOST_TYPE}' == 'VC' Run And Return Rc And Output govc vm.info %{VCH-NAME}/${id} |awk '/Memory:/ {print $2}' Run Keyword If '%{HOST_TYPE}' == 'VC' Should Be Equal As Integers ${rc} 0 Run Keyword If '%{HOST_TYPE}' == 'VC' Should Contain ${output} 4096MB @@ -59,7 +142,7 @@ Create a container with custom amount of memory in GB Create a container with custom amount of memory in MB ${rc} ${id}= Run And Return Rc And Output docker %{VCH-PARAMS} create -it -m 2048M busybox Should Be Equal As Integers ${rc} 0 - ${id}= Obtain VM name from container id ${id} + ${id}= Get VM display name ${id} ${rc} ${output}= Run Keyword If '%{HOST_TYPE}' == 'VC' Run And Return Rc And Output govc vm.info %{VCH-NAME}/${id} |awk '/Memory:/ {print $2}' Run Keyword If '%{HOST_TYPE}' == 'VC' Should Be Equal As Integers ${rc} 0 Run Keyword If '%{HOST_TYPE}' == 'VC' Should Contain ${output} 2048MB @@ -70,7 +153,7 @@ Create a container with custom amount of memory in MB Create a container with custom amount of memory in KB ${rc} ${id}= Run And Return Rc And Output docker %{VCH-PARAMS} create -it -m 2097152K busybox Should Be Equal As Integers ${rc} 0 - ${id}= Obtain VM name from container id ${id} + ${id}= Get VM display name ${id} ${rc} ${output}= Run Keyword If '%{HOST_TYPE}' == 'VC' Run And Return Rc And Output govc vm.info %{VCH-NAME}/${id} |awk '/Memory:/ {print $2}' Run Keyword If '%{HOST_TYPE}' == 'VC' Should Be Equal As Integers ${rc} 0 Run Keyword If '%{HOST_TYPE}' == 'VC' Should Contain ${output} 2048MB @@ -81,7 +164,7 @@ Create a container with custom amount of memory in KB Create a container with custom amount of memory in Bytes ${rc} ${id}= Run And Return Rc And Output docker %{VCH-PARAMS} create -it -m 2147483648B busybox Should Be Equal As Integers ${rc} 0 - ${id}= Obtain VM name from container id ${id} + ${id}= Get VM display name ${id} ${rc} ${output}= Run Keyword If '%{HOST_TYPE}' == 'VC' Run And Return Rc And Output govc vm.info %{VCH-NAME}/${id} |awk '/Memory:/ {print $2}' Run Keyword If '%{HOST_TYPE}' == 'VC' Should Be Equal As Integers ${rc} 0 Run Keyword If '%{HOST_TYPE}' == 'VC' Should Contain ${output} 2048MB @@ -97,9 +180,9 @@ Create a container using rest api call without HostConfig in the form data Create a container and check the VM display name ${rc} ${id}= Run And Return Rc And Output docker %{VCH-PARAMS} create -it --name busy3 busybox Should Be Equal As Integers ${rc} 0 - ${vmName}= Obtain VM name from container id ${id} + ${vmName}= Get VM display name ${id} ${shortID}= Get Substring ${id} 0 12 Should Be Equal ${vmName} busy3-${shortID} - ${rc} ${output}= Run And Return Rc And Output govc vm.info ${vmName} + ${rc} ${output}= Run And Return Rc And Output govc vm.info ${vmName}* Should Be Equal As Integers ${rc} 0 Should contain ${output} ${vmName} \ No newline at end of file diff --git a/tests/test-cases/Group1-Docker-Commands/1-07-Docker-Stop.robot b/tests/test-cases/Group1-Docker-Commands/1-07-Docker-Stop.robot index d353f1f5c6..d3b9904251 100644 --- a/tests/test-cases/Group1-Docker-Commands/1-07-Docker-Stop.robot +++ b/tests/test-cases/Group1-Docker-Commands/1-07-Docker-Stop.robot @@ -41,13 +41,14 @@ Assert Stop Signal Assert Kill Signal # Assert SIGKILL was sent or not by checking the tether debug log file [Arguments] ${id} ${expect} - ${rc} ${output}= Run Keyword If '%{HOST_TYPE}' == 'VC' Run And Return Rc And Output govc vm.info -json %{VCH-NAME}/*-${id} | jq -r .VirtualMachines[].Runtime.PowerState + ${vmName}= Get VM display name ${id} + ${rc} ${output}= Run Keyword If '%{HOST_TYPE}' == 'VC' Run And Return Rc And Output govc vm.info -json %{VCH-NAME}/${vmName}* | jq -r .VirtualMachines[].Runtime.PowerState Run Keyword If '%{HOST_TYPE}' == 'VC' Should Be Equal As Integers ${rc} 0 Run Keyword If '%{HOST_TYPE}' == 'VC' Should Be Equal ${output} poweredOff - ${rc} ${output}= Run Keyword If '%{HOST_TYPE}' == 'ESXi' Run And Return Rc And Output govc vm.info -json *-${id} | jq -r .VirtualMachines[].Runtime.PowerState + ${rc} ${output}= Run Keyword If '%{HOST_TYPE}' == 'ESXi' Run And Return Rc And Output govc vm.info -json ${vmName} | jq -r .VirtualMachines[].Runtime.PowerState Run Keyword If '%{HOST_TYPE}' == 'ESXi' Should Be Equal As Integers ${rc} 0 Run Keyword If '%{HOST_TYPE}' == 'ESXi' Should Be Equal ${output} poweredOff - ${rc} ${dir}= Run And Return Rc And Output govc datastore.ls *-${id} + ${rc} ${dir}= Run And Return Rc And Output govc datastore.ls ${id}* Should Be Equal As Integers ${rc} 0 ${rc} ${output}= Run And Return Rc And Output govc datastore.download ${dir}/tether.debug - Should Be Equal As Integers ${rc} 0 @@ -146,7 +147,8 @@ Restart a stopped container ${rc} ${output}= Run And Return Rc And Output docker %{VCH-PARAMS} start ${output} Should Be Equal As Integers ${rc} 0 Should Not Contain ${output} Error: - Wait Until VM Powers Off *-${output} + ${shortID}= Get container shortID ${output} + Wait Until VM Powers Off *-${shortID} ${rc} ${output}= Run And Return Rc And Output docker %{VCH-PARAMS} start ${output} Should Be Equal As Integers ${rc} 0 Should Not Contain ${output} Error: diff --git a/tests/test-cases/Group1-Docker-Commands/1-10-Docker-PS.robot b/tests/test-cases/Group1-Docker-Commands/1-10-Docker-PS.robot index 3626651ca5..ee0a21d61a 100644 --- a/tests/test-cases/Group1-Docker-Commands/1-10-Docker-PS.robot +++ b/tests/test-cases/Group1-Docker-Commands/1-10-Docker-PS.robot @@ -41,7 +41,8 @@ Create several containers Should Be Equal As Integers ${rc} 0 ${rc} ${container3}= Run And Return Rc And Output docker %{VCH-PARAMS} create busybox dmesg Should Be Equal As Integers ${rc} 0 - Wait Until VM Powers Off *-${container2} + ${container2shortID}= Get container shortID ${container2} + Wait Until VM Powers Off *-${container2shortID}* Assert Number Of Containers [Arguments] ${num} ${type}=-q @@ -148,7 +149,7 @@ Docker ps Remove container OOB Run Keyword If '%{HOST_TYPE}' == 'ESXi' Should Be Equal As Integers ${rc} 0 Wait Until VM Is Destroyed "lolo*" Wait Until Keyword Succeeds 10x 6s Assert Number Of Containers ${len-1} -aq - ${rc} ${output}= Run And Return Rc And Output govc datastore.ls | grep lolo- | xargs -n1 govc datastore.rm + ${rc} ${output}= Run And Return Rc And Output govc datastore.ls | grep ${container} | xargs -n1 govc datastore.rm Should Be Equal As Integers ${rc} 0 Docker ps last container diff --git a/tests/test-cases/Group1-Docker-Commands/1-11-Docker-RM.robot b/tests/test-cases/Group1-Docker-Commands/1-11-Docker-RM.robot index 9b615fbeaa..be09328649 100644 --- a/tests/test-cases/Group1-Docker-Commands/1-11-Docker-RM.robot +++ b/tests/test-cases/Group1-Docker-Commands/1-11-Docker-RM.robot @@ -21,12 +21,13 @@ Suite Teardown Cleanup VIC Appliance On Test Server *** Keywords *** Check That VM Is Removed [Arguments] ${container} + ${id}= Get container shortID ${container} ${rc} ${output}= Run Keyword If '%{HOST_TYPE}' == 'VC' Run And Return Rc And Output govc ls %{VCH-NAME}/vm Run Keyword If '%{HOST_TYPE}' == 'VC' Should Be Equal As Integers ${rc} 0 - Run Keyword If '%{HOST_TYPE}' == 'VC' Should Not Contain ${output} ${container} + Run Keyword If '%{HOST_TYPE}' == 'VC' Should Not Contain ${output} ${id} ${rc} ${output}= Run Keyword If '%{HOST_TYPE}' == 'ESXi' Run And Return Rc And Output govc ls vm Run Keyword If '%{HOST_TYPE}' == 'ESXi' Should Be Equal As Integers ${rc} 0 - Run Keyword If '%{HOST_TYPE}' == 'ESXi' Should Not Contain ${output} ${container} + Run Keyword If '%{HOST_TYPE}' == 'ESXi' Should Not Contain ${output} ${id} Check That Datastore Is Cleaned [Arguments] ${container} diff --git a/tests/test-cases/Group13-VAC/13-01-VAC-GuestFullName.robot b/tests/test-cases/Group13-VAC/13-01-VAC-GuestFullName.robot index 096262ab1b..16c7b39f89 100644 --- a/tests/test-cases/Group13-VAC/13-01-VAC-GuestFullName.robot +++ b/tests/test-cases/Group13-VAC/13-01-VAC-GuestFullName.robot @@ -30,7 +30,8 @@ Create a test container and check Guest Operating System Should Be Equal As Integers ${rc} 0 ${rc} ${id}= Run And Return Rc And Output docker %{VCH-PARAMS} create --name test busybox Should Be Equal As Integers ${rc} 0 - ${rc} ${output}= Run Keyword If '%{HOST_TYPE}' == 'VC' Run govc vm.info %{VCH-NAME}/test-${id} | grep 'Guest name' - ${rc} ${output}= Run Keyword If '%{HOST_TYPE}' == 'ESXi' Run And Return Rc And Output govc vm.info test-${id} | grep 'Guest name' + ${shortID}= Get container shortID ${id} + ${rc} ${output}= Run Keyword If '%{HOST_TYPE}' == 'VC' Run govc vm.info %{VCH-NAME}/test-${shortID}* | grep 'Guest name' + ${rc} ${output}= Run Keyword If '%{HOST_TYPE}' == 'ESXi' Run And Return Rc And Output govc vm.info test-${shortID}* | grep 'Guest name' Should Be Equal As Integers ${rc} 0 Should Contain ${output} Photon - Container From 312fbc84f3b14636d84bd8ff5a83b7ab8e89769c Mon Sep 17 00:00:00 2001 From: chengwang86 Date: Thu, 2 Mar 2017 13:22:14 -0800 Subject: [PATCH 12/58] update test case --- .../Group1-Docker-Commands/1-04-Docker-Create.md | 2 +- .../Group1-Docker-Commands/1-04-Docker-Create.robot | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/test-cases/Group1-Docker-Commands/1-04-Docker-Create.md b/tests/test-cases/Group1-Docker-Commands/1-04-Docker-Create.md index 9e102bdba4..1e7e401d72 100644 --- a/tests/test-cases/Group1-Docker-Commands/1-04-Docker-Create.md +++ b/tests/test-cases/Group1-Docker-Commands/1-04-Docker-Create.md @@ -56,7 +56,7 @@ This test requires that a vSphere server is running and available * Step 23 should return with the following error message - Error response from daemon: No command specified * Steps 24-28 should return without error. * Step 29 should return without error. -* Step 30 should show that the VM display name equals to containerName-containerShortID +* Step 30 should show that the VM display name equals to containerName-containerShortID and datastore folder name equal to containerID #Possible Problems: None diff --git a/tests/test-cases/Group1-Docker-Commands/1-04-Docker-Create.robot b/tests/test-cases/Group1-Docker-Commands/1-04-Docker-Create.robot index a1e396760a..8d648a58c3 100644 --- a/tests/test-cases/Group1-Docker-Commands/1-04-Docker-Create.robot +++ b/tests/test-cases/Group1-Docker-Commands/1-04-Docker-Create.robot @@ -177,7 +177,7 @@ Create a container using rest api call without HostConfig in the form data Log ${output} Should contain ${output} "Warnings":null -Create a container and check the VM display name +Create a container and check the VM display name and datastore folder name ${rc} ${id}= Run And Return Rc And Output docker %{VCH-PARAMS} create -it --name busy3 busybox Should Be Equal As Integers ${rc} 0 ${vmName}= Get VM display name ${id} @@ -185,4 +185,7 @@ Create a container and check the VM display name Should Be Equal ${vmName} busy3-${shortID} ${rc} ${output}= Run And Return Rc And Output govc vm.info ${vmName}* Should Be Equal As Integers ${rc} 0 - Should contain ${output} ${vmName} \ No newline at end of file + Should contain ${output} ${vmName} + ${rc} ${output}= Run And Return Rc And Output govc datastore.ls |grep ${id} + Should Be Equal As Integers ${rc} 0 + Should Be Equal ${output} ${id} \ No newline at end of file From 31f5b96ffc220896f8c73a4cf46667eae9f879f3 Mon Sep 17 00:00:00 2001 From: chengwang86 Date: Thu, 2 Mar 2017 14:07:09 -0800 Subject: [PATCH 13/58] correct unit test --- lib/portlayer/network/context_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/portlayer/network/context_test.go b/lib/portlayer/network/context_test.go index 9d85f7a9e5..8d4b33cfcd 100644 --- a/lib/portlayer/network/context_test.go +++ b/lib/portlayer/network/context_test.go @@ -693,7 +693,7 @@ func TestContextAddContainer(t *testing.T) { func newContainer(name string) *exec.Handle { h := exec.TestHandle(uid.New().String()) - h.ExecConfig.Common.Name = name + h.ExecConfig.Common2.Name = name return h } From 332c1707ddfce62d8cffa2c27697ea6f4ff45fa7 Mon Sep 17 00:00:00 2001 From: chengwang86 Date: Thu, 2 Mar 2017 20:20:22 -0800 Subject: [PATCH 14/58] update regression test --- tests/resources/Docker-Util.robot | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/resources/Docker-Util.robot b/tests/resources/Docker-Util.robot index dcead333ce..60754a40b8 100644 --- a/tests/resources/Docker-Util.robot +++ b/tests/resources/Docker-Util.robot @@ -88,7 +88,8 @@ Run Regression Tests Should Be Equal As Integers ${rc} 0 Should Contain ${output} Exited - Wait Until Keyword Succeeds 5x 10s Check For The Proper Log Files ${container} + ${containerShortID}= Get container shortID ${container} + Wait Until Keyword Succeeds 5x 10s Check For The Proper Log Files ${containerShortID} ${rc} ${output}= Run And Return Rc And Output docker %{VCH-PARAMS} rm ${container} Should Be Equal As Integers ${rc} 0 From f5fd7f521af62d3be8a677b4f142c94280b445d2 Mon Sep 17 00:00:00 2001 From: chengwang86 Date: Thu, 2 Mar 2017 20:47:31 -0800 Subject: [PATCH 15/58] update test case --- .../test-cases/Group1-Docker-Commands/1-04-Docker-Create.robot | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/test-cases/Group1-Docker-Commands/1-04-Docker-Create.robot b/tests/test-cases/Group1-Docker-Commands/1-04-Docker-Create.robot index 8d648a58c3..cfb033b764 100644 --- a/tests/test-cases/Group1-Docker-Commands/1-04-Docker-Create.robot +++ b/tests/test-cases/Group1-Docker-Commands/1-04-Docker-Create.robot @@ -188,4 +188,5 @@ Create a container and check the VM display name and datastore folder name Should contain ${output} ${vmName} ${rc} ${output}= Run And Return Rc And Output govc datastore.ls |grep ${id} Should Be Equal As Integers ${rc} 0 - Should Be Equal ${output} ${id} \ No newline at end of file + Should Be Equal ${output} ${id} + \ No newline at end of file From a2526fc26e83fe6fb532266df3f219cdb442e86c Mon Sep 17 00:00:00 2001 From: chengwang86 Date: Fri, 3 Mar 2017 14:14:55 -0800 Subject: [PATCH 16/58] use isVCH() function to check whether a VM is a VCH or not during VCH delete --- lib/install/management/delete.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/install/management/delete.go b/lib/install/management/delete.go index e7f2390939..e8e4371857 100644 --- a/lib/install/management/delete.go +++ b/lib/install/management/delete.go @@ -161,23 +161,25 @@ 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) - 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 { + ok, err := d.isVCH(child) + if ok { continue } + if err != nil { + errs = append(errs, err.Error()) + } + if err = d.deleteVM(child, d.force); err != nil { errs = append(errs, err.Error()) } From b6ec05b9a8ce425f9d78e260660120ecfb7842e0 Mon Sep 17 00:00:00 2001 From: chengwang86 Date: Sun, 5 Mar 2017 18:51:32 -0800 Subject: [PATCH 17/58] update test case for group9-vic-admin --- lib/install/management/delete.go | 2 +- tests/test-cases/Group9-VIC-Admin/9-01-VICAdmin-ShowHTML.robot | 2 +- tests/test-cases/Group9-VIC-Admin/9-02-VICAdmin-CertAuth.robot | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/install/management/delete.go b/lib/install/management/delete.go index e8e4371857..fe16c7ebc7 100644 --- a/lib/install/management/delete.go +++ b/lib/install/management/delete.go @@ -179,7 +179,7 @@ func (d *Dispatcher) DeleteVCHInstances(vmm *vm.VirtualMachine, conf *config.Vir if err != nil { errs = append(errs, err.Error()) } - + if err = d.deleteVM(child, d.force); err != nil { errs = append(errs, err.Error()) } diff --git a/tests/test-cases/Group9-VIC-Admin/9-01-VICAdmin-ShowHTML.robot b/tests/test-cases/Group9-VIC-Admin/9-01-VICAdmin-ShowHTML.robot index 0ad5f61fc5..6f5babb63c 100644 --- a/tests/test-cases/Group9-VIC-Admin/9-01-VICAdmin-ShowHTML.robot +++ b/tests/test-cases/Group9-VIC-Admin/9-01-VICAdmin-ShowHTML.robot @@ -76,7 +76,7 @@ While Logged Out Fail To Get VICAdmin Log Display HTML Login And Save Cookies ${rc} ${output}= Run And Return Rc And Output curl -sk %{VIC-ADMIN} -b /tmp/cookies-%{VCH-NAME} - Should contain ${output} VIC: %{VCH-NAME} + Should contain ${output} VIC: Get Portlayer Log Login And Save Cookies diff --git a/tests/test-cases/Group9-VIC-Admin/9-02-VICAdmin-CertAuth.robot b/tests/test-cases/Group9-VIC-Admin/9-02-VICAdmin-CertAuth.robot index bbdbf95683..50220194bb 100644 --- a/tests/test-cases/Group9-VIC-Admin/9-02-VICAdmin-CertAuth.robot +++ b/tests/test-cases/Group9-VIC-Admin/9-02-VICAdmin-CertAuth.robot @@ -29,7 +29,7 @@ Curl *** Test Cases *** Display HTML ${output}= Wait Until Keyword Succeeds 10x 10s Curl ${EMPTY} - Should contain ${output} VIC: %{VCH-NAME} + Should contain ${output} VIC: Get Portlayer Log ${output}= Wait Until Keyword Succeeds 10x 10s Curl /logs/port-layer.log From 1710ca6ee21807298628d5d7bfd6b6d84e266e6f Mon Sep 17 00:00:00 2001 From: chengwang86 Date: Sun, 5 Mar 2017 21:58:35 -0800 Subject: [PATCH 18/58] correct error in test group9-01 --- .../test-cases/Group9-VIC-Admin/9-01-VICAdmin-ShowHTML.robot | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/test-cases/Group9-VIC-Admin/9-01-VICAdmin-ShowHTML.robot b/tests/test-cases/Group9-VIC-Admin/9-01-VICAdmin-ShowHTML.robot index 6f5babb63c..54975ce963 100644 --- a/tests/test-cases/Group9-VIC-Admin/9-01-VICAdmin-ShowHTML.robot +++ b/tests/test-cases/Group9-VIC-Admin/9-01-VICAdmin-ShowHTML.robot @@ -107,8 +107,9 @@ Get Container Logs ${rc} ${output}= Run And Return Rc and Output curl -sk %{VIC-ADMIN}/container-logs.tar.gz -b /tmp/cookies-%{VCH-NAME} | tar tvzf - Should Be Equal As Integers ${rc} 0 Log ${output} - Should Contain ${output} ${container}/vmware.log - Should Contain ${output} ${container}/tether.debug + {vmName}= Get VM display name ${container} + Should Contain ${output} ${vmName}/vmware.log + Should Contain ${output} ${vmName}/tether.debug Get VICAdmin Log Login And Save Cookies From b6d40242a4dd1146c2c4e3a619ce26b973a08ff0 Mon Sep 17 00:00:00 2001 From: chengwang86 Date: Mon, 6 Mar 2017 10:39:18 -0800 Subject: [PATCH 19/58] obtain the VCH hostname from vsphere for the vicadmin web portal --- lib/vicadmin/validate.go | 33 ++++++++++++++----- .../9-01-VICAdmin-ShowHTML.robot | 9 ++--- .../9-02-VICAdmin-CertAuth.robot | 2 +- 3 files changed, 30 insertions(+), 14 deletions(-) diff --git a/lib/vicadmin/validate.go b/lib/vicadmin/validate.go index c0b0f178f5..0435e7f8d2 100644 --- a/lib/vicadmin/validate.go +++ b/lib/vicadmin/validate.go @@ -19,7 +19,7 @@ import ( "html/template" "io/ioutil" "net" - "os" + //"os" "path" "sort" "strings" @@ -36,11 +36,13 @@ import ( "github.com/vmware/govmomi/vim25/mo" "github.com/vmware/govmomi/vim25/types" "github.com/vmware/vic/lib/config" + "github.com/vmware/vic/lib/guest" "github.com/vmware/vic/lib/install/validate" "github.com/vmware/vic/lib/tether" "github.com/vmware/vic/pkg/trace" "github.com/vmware/vic/pkg/version" "github.com/vmware/vic/pkg/vsphere/session" + "github.com/vmware/vic/pkg/vsphere/vm" ) type Validator struct { @@ -112,13 +114,7 @@ func NewValidator(ctx context.Context, vch *config.VirtualContainerHostConfigSpe log.Infof("Setting version to %s", v.Version) // VCH Name - var err error - v.Hostname, err = os.Hostname() - if err != nil { - v.Hostname = "VCH" - } - - log.Infof("Setting hostname to %s", v.Hostname) + v.Hostname = GetVCHName(ctx, sess) // System time v.SystemTime = time.Now().Format(time.UnixDate) @@ -209,7 +205,7 @@ func NewValidator(ctx context.Context, vch *config.VirtualContainerHostConfigSpe v.DockerPort = fmt.Sprintf("%d", opts.DefaultTLSHTTPPort) } - err = v.QueryDatastore(ctx, vch, sess) + err := v.QueryDatastore(ctx, vch, sess) if err != nil { log.Errorf("Had a problem querying the datastores: %s", err.Error()) } @@ -217,6 +213,25 @@ func NewValidator(ctx context.Context, vch *config.VirtualContainerHostConfigSpe return v } +func GetVCHName(ctx context.Context, sess *session.Session) string { + defer trace.End(trace.Begin("")) + + var vchName = "VCH" + self, err := guest.GetSelf(ctx, sess) + if err != nil || self == nil { + log.Errorf("Unable to collect appliance logs due to unknown self-reference: %s", err) + log.Infof("Setting the VCH name to VCH") + return vchName + } + self2 := vm.NewVirtualMachineFromVM(ctx, sess, self) + vchName, err = self2.Name(ctx) + if err != nil { + log.Infof("Err get VCH name: %s", err) + } + log.Infof("Setting the VCH name to %s", vchName) + return vchName +} + type dsList []mo.Datastore func (d dsList) Len() int { return len(d) } diff --git a/tests/test-cases/Group9-VIC-Admin/9-01-VICAdmin-ShowHTML.robot b/tests/test-cases/Group9-VIC-Admin/9-01-VICAdmin-ShowHTML.robot index 54975ce963..0bf531119c 100644 --- a/tests/test-cases/Group9-VIC-Admin/9-01-VICAdmin-ShowHTML.robot +++ b/tests/test-cases/Group9-VIC-Admin/9-01-VICAdmin-ShowHTML.robot @@ -64,8 +64,9 @@ While Logged Out Fail To Get Container Logs Should not Be Equal As Integers ${rc} 0 Should Contain ${output} gzip: stdin: not in gzip format Log ${output} - Should not Contain ${output} ${container}/vmware.log - Should not Contain ${output} ${container}/tether.debug + ${vmName}= Get VM display name ${container} + Should not Contain ${output} ${vmName}/vmware.log + Should not Contain ${output} ${vmName}/tether.debug While Logged Out Fail To Get VICAdmin Log ${rc} ${output}= Run And Return Rc And Output curl -sk %{VIC-ADMIN}/logs/vicadmin.log @@ -76,7 +77,7 @@ While Logged Out Fail To Get VICAdmin Log Display HTML Login And Save Cookies ${rc} ${output}= Run And Return Rc And Output curl -sk %{VIC-ADMIN} -b /tmp/cookies-%{VCH-NAME} - Should contain ${output} VIC: + Should contain ${output} VIC: %{VCH-NAME} Get Portlayer Log Login And Save Cookies @@ -107,7 +108,7 @@ Get Container Logs ${rc} ${output}= Run And Return Rc and Output curl -sk %{VIC-ADMIN}/container-logs.tar.gz -b /tmp/cookies-%{VCH-NAME} | tar tvzf - Should Be Equal As Integers ${rc} 0 Log ${output} - {vmName}= Get VM display name ${container} + ${vmName}= Get VM display name ${container} Should Contain ${output} ${vmName}/vmware.log Should Contain ${output} ${vmName}/tether.debug diff --git a/tests/test-cases/Group9-VIC-Admin/9-02-VICAdmin-CertAuth.robot b/tests/test-cases/Group9-VIC-Admin/9-02-VICAdmin-CertAuth.robot index 50220194bb..9908f3ff2e 100644 --- a/tests/test-cases/Group9-VIC-Admin/9-02-VICAdmin-CertAuth.robot +++ b/tests/test-cases/Group9-VIC-Admin/9-02-VICAdmin-CertAuth.robot @@ -29,7 +29,7 @@ Curl *** Test Cases *** Display HTML ${output}= Wait Until Keyword Succeeds 10x 10s Curl ${EMPTY} - Should contain ${output} VIC: + Should contain ${output} VIC: %{VCH-NAME Get Portlayer Log ${output}= Wait Until Keyword Succeeds 10x 10s Curl /logs/port-layer.log From ae9f2b6aca0090817205ac7919a1ab3ba7aa02a9 Mon Sep 17 00:00:00 2001 From: chengwang86 Date: Mon, 6 Mar 2017 10:46:12 -0800 Subject: [PATCH 20/58] - rename `Common2` to `CommonSpecForVM` - update test Group9-02 for typo --- cmd/tether/attach_test.go | 10 +++++----- cmd/vic-init/restart_test.go | 2 +- .../restapi/handlers/containers_handlers.go | 2 +- lib/config/executor/container_vm.go | 4 ++-- lib/portlayer/network/context_test.go | 2 +- lib/tether/cmd_test.go | 12 ++++++------ lib/tether/config_test.go | 2 +- lib/tether/net_linux_test.go | 2 +- lib/tether/net_test.go | 4 ++-- .../Group9-VIC-Admin/9-02-VICAdmin-CertAuth.robot | 2 +- 10 files changed, 21 insertions(+), 21 deletions(-) diff --git a/cmd/tether/attach_test.go b/cmd/tether/attach_test.go index e9b2a3e9f5..a73a205480 100644 --- a/cmd/tether/attach_test.go +++ b/cmd/tether/attach_test.go @@ -232,7 +232,7 @@ func attachCase(t *testing.T, runblock bool) { testServer, _ := server.(*testAttachServer) cfg := executor.ExecutorConfig{ - Common2: executor.Common2{ + CommonSpecForVM: executor.CommonSpecForVM{ ID: "attach", Name: "tether_test_executor", }, @@ -336,7 +336,7 @@ func TestAttachTTY(t *testing.T) { testServer, _ := server.(*testAttachServer) cfg := executor.ExecutorConfig{ - Common2: executor.Common2{ + CommonSpecForVM: executor.CommonSpecForVM{ ID: "attach", Name: "tether_test_executor", }, @@ -435,7 +435,7 @@ func TestAttachMultiple(t *testing.T) { testServer, _ := server.(*testAttachServer) cfg := executor.ExecutorConfig{ - Common2: executor.Common2{ + CommonSpecForVM: executor.CommonSpecForVM{ ID: "tee1", Name: "tether_test_executor", }, @@ -603,7 +603,7 @@ func TestAttachInvalid(t *testing.T) { testServer, _ := server.(*testAttachServer) cfg := executor.ExecutorConfig{ - Common2: executor.Common2{ + CommonSpecForVM: executor.CommonSpecForVM{ ID: "attachinvalid", Name: "tether_test_executor", }, @@ -740,7 +740,7 @@ func TestReattach(t *testing.T) { testServer, _ := server.(*testAttachServer) cfg := executor.ExecutorConfig{ - Common2: executor.Common2{ + CommonSpecForVM: executor.CommonSpecForVM{ ID: "attach", Name: "tether_test_executor", }, diff --git a/cmd/vic-init/restart_test.go b/cmd/vic-init/restart_test.go index b679a29ecc..3dcf7e1b85 100644 --- a/cmd/vic-init/restart_test.go +++ b/cmd/vic-init/restart_test.go @@ -39,7 +39,7 @@ func TestRestart(t *testing.T) { defer testTeardown(t) cfg := executor.ExecutorConfig{ - Common2: executor.Common2{ + CommonSpecForVM: executor.CommonSpecForVM{ ID: "pathlookup", Name: "tether_test_executor", }, diff --git a/lib/apiservers/portlayer/restapi/handlers/containers_handlers.go b/lib/apiservers/portlayer/restapi/handlers/containers_handlers.go index 5c2a180808..f25bc7926b 100644 --- a/lib/apiservers/portlayer/restapi/handlers/containers_handlers.go +++ b/lib/apiservers/portlayer/restapi/handlers/containers_handlers.go @@ -88,7 +88,7 @@ func (handler *ContainersHandlersImpl) CreateHandler(params containers.CreatePar } m := &executor.ExecutorConfig{ - Common2: executor.Common2{ + CommonSpecForVM: executor.CommonSpecForVM{ ID: id, Name: params.CreateConfig.Name, }, diff --git a/lib/config/executor/container_vm.go b/lib/config/executor/container_vm.go index ee81889bf9..f4f042cc92 100644 --- a/lib/config/executor/container_vm.go +++ b/lib/config/executor/container_vm.go @@ -45,7 +45,7 @@ type Common struct { } // Common data (specifically for a containerVM) between managed entities, across execution environments. -type Common2 struct { +type CommonSpecForVM struct { // A reference to the components hosting execution environment, if any ExecutionEnvironment string @@ -123,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 { - Common2 `vic:"0.1" scope:"read-only" key:"common"` + CommonSpecForVM `vic:"0.1" scope:"read-only" key:"common"` // CreateTime stamp CreateTime int64 `vic:"0.1" scope:"read-write" key:"createtime"` diff --git a/lib/portlayer/network/context_test.go b/lib/portlayer/network/context_test.go index 8d4b33cfcd..4b7f759689 100644 --- a/lib/portlayer/network/context_test.go +++ b/lib/portlayer/network/context_test.go @@ -693,7 +693,7 @@ func TestContextAddContainer(t *testing.T) { func newContainer(name string) *exec.Handle { h := exec.TestHandle(uid.New().String()) - h.ExecConfig.Common2.Name = name + h.ExecConfig.CommonSpecForVM.Name = name return h } diff --git a/lib/tether/cmd_test.go b/lib/tether/cmd_test.go index 1fdd52102b..7cd6319c93 100644 --- a/lib/tether/cmd_test.go +++ b/lib/tether/cmd_test.go @@ -37,7 +37,7 @@ func TestPathLookup(t *testing.T) { defer testTeardown(t, mocker) cfg := executor.ExecutorConfig{ - Common2: executor.Common2{ + CommonSpecForVM: executor.CommonSpecForVM{ ID: "pathlookup", Name: "tether_test_executor", }, @@ -77,7 +77,7 @@ func TestRelativePath(t *testing.T) { defer testTeardown(t, mocker) cfg := executor.ExecutorConfig{ - Common2: executor.Common2{ + CommonSpecForVM: executor.CommonSpecForVM{ ID: "relpath", Name: "tether_test_executor", }, @@ -117,7 +117,7 @@ func TestAbsPath(t *testing.T) { defer testTeardown(t, mocker) cfg := executor.ExecutorConfig{ - Common2: executor.Common2{ + CommonSpecForVM: executor.CommonSpecForVM{ ID: "abspath", Name: "tether_test_executor", }, @@ -175,7 +175,7 @@ func TestHalt(t *testing.T) { defer testTeardown(t, mocker) cfg := executor.ExecutorConfig{ - Common2: executor.Common2{ + CommonSpecForVM: executor.CommonSpecForVM{ ID: "abspath", Name: "tether_test_executor", }, @@ -251,7 +251,7 @@ func TestMissingBinary(t *testing.T) { defer testTeardown(t, mocker) cfg := executor.ExecutorConfig{ - Common2: executor.Common2{ + CommonSpecForVM: executor.CommonSpecForVM{ ID: "missing", Name: "tether_test_executor", }, @@ -300,7 +300,7 @@ func TestMissingRelativeBinary(t *testing.T) { defer testTeardown(t, mocker) cfg := executor.ExecutorConfig{ - Common2: executor.Common2{ + CommonSpecForVM: executor.CommonSpecForVM{ ID: "missing", Name: "tether_test_executor", }, diff --git a/lib/tether/config_test.go b/lib/tether/config_test.go index f55d6681d4..9a4c276436 100644 --- a/lib/tether/config_test.go +++ b/lib/tether/config_test.go @@ -32,7 +32,7 @@ var ( func TestToExtraConfig(t *testing.T) { exec := executor.ExecutorConfig{ - Common2: executor.Common2{ + CommonSpecForVM: executor.CommonSpecForVM{ ID: "deadbeef", Name: "configtest", }, diff --git a/lib/tether/net_linux_test.go b/lib/tether/net_linux_test.go index 9ff4f55fb6..1678031c56 100644 --- a/lib/tether/net_linux_test.go +++ b/lib/tether/net_linux_test.go @@ -74,7 +74,7 @@ func TestSetIpAddress(t *testing.T) { secondIP, _ := netlink.ParseIPNet("172.16.0.10/24") gwIP, _ := netlink.ParseIPNet("172.16.0.1/24") cfg := executor.ExecutorConfig{ - Common2: executor.Common2{ + CommonSpecForVM: executor.CommonSpecForVM{ ID: "ipconfig", Name: "tether_test_executor", }, diff --git a/lib/tether/net_test.go b/lib/tether/net_test.go index 83e5c441fa..8e8b3acada 100644 --- a/lib/tether/net_test.go +++ b/lib/tether/net_test.go @@ -27,7 +27,7 @@ func TestSetHostname(t *testing.T) { defer testTeardown(t, mocker) cfg := executor.ExecutorConfig{ - Common2: executor.Common2{ + CommonSpecForVM: executor.CommonSpecForVM{ ID: "sethostname", Name: "tether_test_executor", }, @@ -54,7 +54,7 @@ func TestNoNetwork(t *testing.T) { defer testTeardown(t, mocker) cfg := executor.ExecutorConfig{ - Common2: executor.Common2{ + CommonSpecForVM: executor.CommonSpecForVM{ ID: "ipconfig", Name: "tether_test_executor", }, diff --git a/tests/test-cases/Group9-VIC-Admin/9-02-VICAdmin-CertAuth.robot b/tests/test-cases/Group9-VIC-Admin/9-02-VICAdmin-CertAuth.robot index 9908f3ff2e..bbdbf95683 100644 --- a/tests/test-cases/Group9-VIC-Admin/9-02-VICAdmin-CertAuth.robot +++ b/tests/test-cases/Group9-VIC-Admin/9-02-VICAdmin-CertAuth.robot @@ -29,7 +29,7 @@ Curl *** Test Cases *** Display HTML ${output}= Wait Until Keyword Succeeds 10x 10s Curl ${EMPTY} - Should contain ${output} VIC: %{VCH-NAME + Should contain ${output} VIC: %{VCH-NAME} Get Portlayer Log ${output}= Wait Until Keyword Succeeds 10x 10s Curl /logs/port-layer.log From 5278a2f9cd7ac4a1acfb8e8363afe0ec644a85a3 Mon Sep 17 00:00:00 2001 From: chengwang86 Date: Mon, 6 Mar 2017 13:43:12 -0800 Subject: [PATCH 21/58] add plugin for data migration after VCH upgrade --- lib/migration/plugins/init.go | 3 + pkg/version/plugin1/commonSpecForVM.go | 110 +++++++++++++++++++++++++ 2 files changed, 113 insertions(+) create mode 100644 pkg/version/plugin1/commonSpecForVM.go diff --git a/lib/migration/plugins/init.go b/lib/migration/plugins/init.go index 3f1e5af47c..a09e18d844 100644 --- a/lib/migration/plugins/init.go +++ b/lib/migration/plugins/init.go @@ -15,3 +15,6 @@ package plugins // import all plugin packages here to register plugins +import ( + _ "github.com/vmware/vic/pkg/version/plugin1" +) \ No newline at end of file diff --git a/pkg/version/plugin1/commonSpecForVM.go b/pkg/version/plugin1/commonSpecForVM.go new file mode 100644 index 0000000000..0e3d1abd32 --- /dev/null +++ b/pkg/version/plugin1/commonSpecForVM.go @@ -0,0 +1,110 @@ +// 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.ContainerConfigure +) + +func init() { + defer trace.End(trace.Begin(fmt.Sprintf("Registering plugin %s:%d", target, version))) + if err := manager.Migrator.Register(version, target, &AddCommonSpecForVM{}); err != nil { + log.Errorf("Failed to register plugin %s:%d, %s", target, version, err) + } +} + +// AddCommonSpecForVM is plugin for vic 0.8.0-GA version upgrade +type AddCommonSpecForVM struct { +} + +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 NewExecutorConfig struct { + CommonSpecForVM `vic:"0.1" scope:"read-only" key:"common"` +} + +type CommonSpecForVM 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 *AddCommonSpecForVM) Migrate(ctx context.Context, s *session.Session, data interface{}) error { + defer trace.End(trace.Begin(fmt.Sprintf("%d", version))) + if data == nil { + return nil + } + mapData := data.(map[string]string) + oldStruct := &ExecutorConfig{} + result := extraconfig.Decode(extraconfig.MapSource(mapData), oldStruct) + log.Infof("The mapData is %+v", mapData) + log.Infof("The oldStruct is %+v", oldStruct) + if result == nil { + return &errors.DecodeError{} + } + + newStruct := &NewExecutorConfig{ + CommonSpecForVM: CommonSpecForVM{ + Name: oldStruct.Name, + }} + log.Infof("The newStruct is %+v", newStruct) + cfg := make(map[string]string) + extraconfig.Encode(extraconfig.MapSink(cfg), newStruct) + log.Infof("The newStruct is %+v", newStruct) + + for k, v := range cfg { + log.Debugf("New data: %s:%s", k, v) + mapData[k] = v + } + return nil +} From 1a301fde3f2a0d4b85d3477e4b849fa5a6d90693 Mon Sep 17 00:00:00 2001 From: chengwang86 Date: Tue, 7 Mar 2017 08:10:43 -0800 Subject: [PATCH 22/58] - add a plugin to support changing VCH config (setting the scope of common.name from read-only to hidden) during VCH upgrade - add a plugin to support changing container config (setting the scope of common.name from read-only to hidden) during VCH upgrade --- lib/migration/migrator_test.go | 14 ++-- lib/migration/plugins/init.go | 1 + pkg/version/plugin1/commonSpecForVM.go | 110 ------------------------- pkg/version/version.go | 2 +- 4 files changed, 10 insertions(+), 117 deletions(-) delete mode 100644 pkg/version/plugin1/commonSpecForVM.go diff --git a/lib/migration/migrator_test.go b/lib/migration/migrator_test.go index 2b3a29a9ce..6150021d0e 100644 --- a/lib/migration/migrator_test.go +++ b/lib/migration/migrator_test.go @@ -21,6 +21,8 @@ import ( log "github.com/Sirupsen/logrus" "github.com/stretchr/testify/assert" + "strconv" + "github.com/vmware/vic/lib/config" "github.com/vmware/vic/lib/config/executor" "github.com/vmware/vic/lib/migration/manager" @@ -34,10 +36,10 @@ func setUp() { // register sample plugin into test log.SetLevel(log.DebugLevel) trace.Logger.Level = log.DebugLevel - version.MaxPluginVersion = 1 + version.MaxPluginVersion = 3 - 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) } } @@ -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 @@ -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()) } @@ -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") } diff --git a/lib/migration/plugins/init.go b/lib/migration/plugins/init.go index a09e18d844..607b602ee3 100644 --- a/lib/migration/plugins/init.go +++ b/lib/migration/plugins/init.go @@ -17,4 +17,5 @@ package plugins // import all plugin packages here to register plugins import ( _ "github.com/vmware/vic/pkg/version/plugin1" + _ "github.com/vmware/vic/pkg/version/plugin2" ) \ No newline at end of file diff --git a/pkg/version/plugin1/commonSpecForVM.go b/pkg/version/plugin1/commonSpecForVM.go deleted file mode 100644 index 0e3d1abd32..0000000000 --- a/pkg/version/plugin1/commonSpecForVM.go +++ /dev/null @@ -1,110 +0,0 @@ -// 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.ContainerConfigure -) - -func init() { - defer trace.End(trace.Begin(fmt.Sprintf("Registering plugin %s:%d", target, version))) - if err := manager.Migrator.Register(version, target, &AddCommonSpecForVM{}); err != nil { - log.Errorf("Failed to register plugin %s:%d, %s", target, version, err) - } -} - -// AddCommonSpecForVM is plugin for vic 0.8.0-GA version upgrade -type AddCommonSpecForVM struct { -} - -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 NewExecutorConfig struct { - CommonSpecForVM `vic:"0.1" scope:"read-only" key:"common"` -} - -type CommonSpecForVM 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 *AddCommonSpecForVM) Migrate(ctx context.Context, s *session.Session, data interface{}) error { - defer trace.End(trace.Begin(fmt.Sprintf("%d", version))) - if data == nil { - return nil - } - mapData := data.(map[string]string) - oldStruct := &ExecutorConfig{} - result := extraconfig.Decode(extraconfig.MapSource(mapData), oldStruct) - log.Infof("The mapData is %+v", mapData) - log.Infof("The oldStruct is %+v", oldStruct) - if result == nil { - return &errors.DecodeError{} - } - - newStruct := &NewExecutorConfig{ - CommonSpecForVM: CommonSpecForVM{ - Name: oldStruct.Name, - }} - log.Infof("The newStruct is %+v", newStruct) - cfg := make(map[string]string) - extraconfig.Encode(extraconfig.MapSink(cfg), newStruct) - log.Infof("The newStruct is %+v", newStruct) - - for k, v := range cfg { - log.Debugf("New data: %s:%s", k, v) - mapData[k] = v - } - return nil -} diff --git a/pkg/version/version.go b/pkg/version/version.go index e02769182e..a020c1615a 100644 --- a/pkg/version/version.go +++ b/pkg/version/version.go @@ -31,7 +31,7 @@ var ( State string // MaxPluginVersion must be increased to add new plugin and make sure the new plugin version is same to this value - MaxPluginVersion = 1 + MaxPluginVersion = 2 v bool ) From 905c8ab8dba226a1d5b49f8eef2bb0414e0bb0c1 Mon Sep 17 00:00:00 2001 From: chengwang86 Date: Tue, 7 Mar 2017 08:35:46 -0800 Subject: [PATCH 23/58] resolve conflict --- lib/migration/migrator_test.go | 2 +- lib/migration/plugins/init.go | 2 +- pkg/version/version.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/migration/migrator_test.go b/lib/migration/migrator_test.go index 6150021d0e..ba59bb745a 100644 --- a/lib/migration/migrator_test.go +++ b/lib/migration/migrator_test.go @@ -36,7 +36,7 @@ func setUp() { // register sample plugin into test log.SetLevel(log.DebugLevel) trace.Logger.Level = log.DebugLevel - version.MaxPluginVersion = 3 + version.MaxPluginVersion = 4 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) diff --git a/lib/migration/plugins/init.go b/lib/migration/plugins/init.go index 607b602ee3..2c6be34364 100644 --- a/lib/migration/plugins/init.go +++ b/lib/migration/plugins/init.go @@ -16,6 +16,6 @@ package plugins // import all plugin packages here to register plugins import ( - _ "github.com/vmware/vic/pkg/version/plugin1" _ "github.com/vmware/vic/pkg/version/plugin2" + _ "github.com/vmware/vic/pkg/version/plugin3" ) \ No newline at end of file diff --git a/pkg/version/version.go b/pkg/version/version.go index a020c1615a..3934c5ea7e 100644 --- a/pkg/version/version.go +++ b/pkg/version/version.go @@ -31,7 +31,7 @@ var ( State string // MaxPluginVersion must be increased to add new plugin and make sure the new plugin version is same to this value - MaxPluginVersion = 2 + MaxPluginVersion = 3 v bool ) From a9c6cf4e07ed0aa7d85d70fc4f35c8ac0b4f1690 Mon Sep 17 00:00:00 2001 From: chengwang86 Date: Wed, 15 Mar 2017 15:15:14 -0700 Subject: [PATCH 24/58] add plugins --- pkg/version/plugin2/commonSpecForVCH.go | 128 ++++++++++++++++++ pkg/version/plugin3/commonSpecForContainer.go | 117 ++++++++++++++++ 2 files changed, 245 insertions(+) create mode 100644 pkg/version/plugin2/commonSpecForVCH.go create mode 100644 pkg/version/plugin3/commonSpecForContainer.go diff --git a/pkg/version/plugin2/commonSpecForVCH.go b/pkg/version/plugin2/commonSpecForVCH.go new file mode 100644 index 0000000000..734467d1fa --- /dev/null +++ b/pkg/version/plugin2/commonSpecForVCH.go @@ -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 plugin2 + +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 = 2 + 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) + } +} + +// 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) + log.Debugf("The newStruct is %+v", newStruct) + + for k, v := range cfg { + log.Debugf("New data: %s:%s", k, v) + mapData[k] = v + } + return nil +} diff --git a/pkg/version/plugin3/commonSpecForContainer.go b/pkg/version/plugin3/commonSpecForContainer.go new file mode 100644 index 0000000000..2c09d9310e --- /dev/null +++ b/pkg/version/plugin3/commonSpecForContainer.go @@ -0,0 +1,117 @@ +// 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 plugin3 + +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 = 3 + target = manager.ContainerConfigure +) + +func init() { + defer trace.End(trace.Begin(fmt.Sprintf("Registering plugin %s:%d", target, version))) + if err := manager.Migrator.Register(version, target, &AddCommonSpecForContainer{}); err != nil { + log.Errorf("Failed to register plugin %s:%d, %s", target, version, err) + } +} + +// AddCommonSpecForVM is plugin for vic 0.8.0-GA version upgrade +type AddCommonSpecForContainer struct { +} + +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 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 *AddCommonSpecForContainer) Migrate(ctx context.Context, s *session.Session, data interface{}) error { + defer trace.End(trace.Begin(fmt.Sprintf("AddCommonSpecForContainer 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 := &ExecutorConfig{} + 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 := &UpdatedExecutorConfig{ + UpdatedCommon: UpdatedCommon{ + Name: oldStruct.Name, + ID: oldStruct.ID, + Notes: oldStruct.Notes, + ExecutionEnvironment: oldStruct.ExecutionEnvironment, + }} + + cfg := make(map[string]string) + extraconfig.Encode(extraconfig.MapSink(cfg), newStruct) + log.Debugf("The newStruct is %+v", newStruct) + + for k, v := range cfg { + log.Debugf("New data: %s:%s", k, v) + mapData[k] = v + } + return nil +} From 494e6504f0f19d6568734d64ecbbaffa7d811462 Mon Sep 17 00:00:00 2001 From: chengwang86 Date: Tue, 7 Mar 2017 19:45:51 -0800 Subject: [PATCH 25/58] update error msgs and correct goimports --- lib/vicadmin/validate.go | 7 +- pkg/version/plugin2/commonSpecForVCH.go | 128 ------------------ pkg/version/plugin3/commonSpecForContainer.go | 117 ---------------- 3 files changed, 3 insertions(+), 249 deletions(-) delete mode 100644 pkg/version/plugin2/commonSpecForVCH.go delete mode 100644 pkg/version/plugin3/commonSpecForContainer.go diff --git a/lib/vicadmin/validate.go b/lib/vicadmin/validate.go index 0435e7f8d2..adff1582cd 100644 --- a/lib/vicadmin/validate.go +++ b/lib/vicadmin/validate.go @@ -19,7 +19,6 @@ import ( "html/template" "io/ioutil" "net" - //"os" "path" "sort" "strings" @@ -216,17 +215,17 @@ func NewValidator(ctx context.Context, vch *config.VirtualContainerHostConfigSpe func GetVCHName(ctx context.Context, sess *session.Session) string { defer trace.End(trace.Begin("")) - var vchName = "VCH" + var vchName = fmt.Sprintf("VCH") self, err := guest.GetSelf(ctx, sess) if err != nil || self == nil { - log.Errorf("Unable to collect appliance logs due to unknown self-reference: %s", err) + log.Errorf("Unable to get VCH name due to unknown self-reference: %s", err) log.Infof("Setting the VCH name to VCH") return vchName } self2 := vm.NewVirtualMachineFromVM(ctx, sess, self) vchName, err = self2.Name(ctx) if err != nil { - log.Infof("Err get VCH name: %s", err) + log.Infof("Unable to get VCH name: %s", err) } log.Infof("Setting the VCH name to %s", vchName) return vchName diff --git a/pkg/version/plugin2/commonSpecForVCH.go b/pkg/version/plugin2/commonSpecForVCH.go deleted file mode 100644 index 734467d1fa..0000000000 --- a/pkg/version/plugin2/commonSpecForVCH.go +++ /dev/null @@ -1,128 +0,0 @@ -// 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 plugin2 - -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 = 2 - 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) - } -} - -// 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) - log.Debugf("The newStruct is %+v", newStruct) - - for k, v := range cfg { - log.Debugf("New data: %s:%s", k, v) - mapData[k] = v - } - return nil -} diff --git a/pkg/version/plugin3/commonSpecForContainer.go b/pkg/version/plugin3/commonSpecForContainer.go deleted file mode 100644 index 2c09d9310e..0000000000 --- a/pkg/version/plugin3/commonSpecForContainer.go +++ /dev/null @@ -1,117 +0,0 @@ -// 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 plugin3 - -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 = 3 - target = manager.ContainerConfigure -) - -func init() { - defer trace.End(trace.Begin(fmt.Sprintf("Registering plugin %s:%d", target, version))) - if err := manager.Migrator.Register(version, target, &AddCommonSpecForContainer{}); err != nil { - log.Errorf("Failed to register plugin %s:%d, %s", target, version, err) - } -} - -// AddCommonSpecForVM is plugin for vic 0.8.0-GA version upgrade -type AddCommonSpecForContainer struct { -} - -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 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 *AddCommonSpecForContainer) Migrate(ctx context.Context, s *session.Session, data interface{}) error { - defer trace.End(trace.Begin(fmt.Sprintf("AddCommonSpecForContainer 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 := &ExecutorConfig{} - 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 := &UpdatedExecutorConfig{ - UpdatedCommon: UpdatedCommon{ - Name: oldStruct.Name, - ID: oldStruct.ID, - Notes: oldStruct.Notes, - ExecutionEnvironment: oldStruct.ExecutionEnvironment, - }} - - cfg := make(map[string]string) - extraconfig.Encode(extraconfig.MapSink(cfg), newStruct) - log.Debugf("The newStruct is %+v", newStruct) - - for k, v := range cfg { - log.Debugf("New data: %s:%s", k, v) - mapData[k] = v - } - return nil -} From e0008c18bf19090394f0f5c22812bae21d98f2dd Mon Sep 17 00:00:00 2001 From: chengwang86 Date: Wed, 8 Mar 2017 12:35:24 -0800 Subject: [PATCH 26/58] update the functions and tests based on review comments --- cmd/tether/attach_test.go | 10 +++---- cmd/vic-init/restart_test.go | 2 +- .../restapi/handlers/containers_handlers.go | 2 +- lib/config/executor/container_vm.go | 4 +-- lib/install/management/delete.go | 1 + lib/migration/migrator_test.go | 7 ++--- lib/migration/plugins/init.go | 2 +- lib/portlayer/network/context_test.go | 2 +- lib/tether/cmd_test.go | 12 ++++---- lib/tether/config_test.go | 2 +- lib/tether/net_linux_test.go | 2 +- lib/tether/net_test.go | 4 +-- lib/vicadmin/validate.go | 28 ++++++++++++------- .../Group11-Upgrade/11-01-Upgrade.md | 2 ++ .../Group11-Upgrade/11-01-Upgrade.robot | 6 ++++ 15 files changed, 51 insertions(+), 35 deletions(-) diff --git a/cmd/tether/attach_test.go b/cmd/tether/attach_test.go index a73a205480..1424b73574 100644 --- a/cmd/tether/attach_test.go +++ b/cmd/tether/attach_test.go @@ -232,7 +232,7 @@ func attachCase(t *testing.T, runblock bool) { testServer, _ := server.(*testAttachServer) cfg := executor.ExecutorConfig{ - CommonSpecForVM: executor.CommonSpecForVM{ + ExecutorConfigCommon: executor.ExecutorConfigCommon{ ID: "attach", Name: "tether_test_executor", }, @@ -336,7 +336,7 @@ func TestAttachTTY(t *testing.T) { testServer, _ := server.(*testAttachServer) cfg := executor.ExecutorConfig{ - CommonSpecForVM: executor.CommonSpecForVM{ + ExecutorConfigCommon: executor.ExecutorConfigCommon{ ID: "attach", Name: "tether_test_executor", }, @@ -435,7 +435,7 @@ func TestAttachMultiple(t *testing.T) { testServer, _ := server.(*testAttachServer) cfg := executor.ExecutorConfig{ - CommonSpecForVM: executor.CommonSpecForVM{ + ExecutorConfigCommon: executor.ExecutorConfigCommon{ ID: "tee1", Name: "tether_test_executor", }, @@ -603,7 +603,7 @@ func TestAttachInvalid(t *testing.T) { testServer, _ := server.(*testAttachServer) cfg := executor.ExecutorConfig{ - CommonSpecForVM: executor.CommonSpecForVM{ + ExecutorConfigCommon: executor.ExecutorConfigCommon{ ID: "attachinvalid", Name: "tether_test_executor", }, @@ -740,7 +740,7 @@ func TestReattach(t *testing.T) { testServer, _ := server.(*testAttachServer) cfg := executor.ExecutorConfig{ - CommonSpecForVM: executor.CommonSpecForVM{ + ExecutorConfigCommon: executor.ExecutorConfigCommon{ ID: "attach", Name: "tether_test_executor", }, diff --git a/cmd/vic-init/restart_test.go b/cmd/vic-init/restart_test.go index 3dcf7e1b85..89cf3f42cc 100644 --- a/cmd/vic-init/restart_test.go +++ b/cmd/vic-init/restart_test.go @@ -39,7 +39,7 @@ func TestRestart(t *testing.T) { defer testTeardown(t) cfg := executor.ExecutorConfig{ - CommonSpecForVM: executor.CommonSpecForVM{ + ExecutorConfigCommon: executor.ExecutorConfigCommon{ ID: "pathlookup", Name: "tether_test_executor", }, diff --git a/lib/apiservers/portlayer/restapi/handlers/containers_handlers.go b/lib/apiservers/portlayer/restapi/handlers/containers_handlers.go index f25bc7926b..76b1093917 100644 --- a/lib/apiservers/portlayer/restapi/handlers/containers_handlers.go +++ b/lib/apiservers/portlayer/restapi/handlers/containers_handlers.go @@ -88,7 +88,7 @@ func (handler *ContainersHandlersImpl) CreateHandler(params containers.CreatePar } m := &executor.ExecutorConfig{ - CommonSpecForVM: executor.CommonSpecForVM{ + ExecutorConfigCommon: executor.ExecutorConfigCommon{ ID: id, Name: params.CreateConfig.Name, }, diff --git a/lib/config/executor/container_vm.go b/lib/config/executor/container_vm.go index f4f042cc92..142bbca4f6 100644 --- a/lib/config/executor/container_vm.go +++ b/lib/config/executor/container_vm.go @@ -45,7 +45,7 @@ type Common struct { } // Common data (specifically for a containerVM) between managed entities, across execution environments. -type CommonSpecForVM struct { +type ExecutorConfigCommon struct { // A reference to the components hosting execution environment, if any ExecutionEnvironment string @@ -123,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 { - CommonSpecForVM `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"` diff --git a/lib/install/management/delete.go b/lib/install/management/delete.go index fe16c7ebc7..1978eddb14 100644 --- a/lib/install/management/delete.go +++ b/lib/install/management/delete.go @@ -178,6 +178,7 @@ func (d *Dispatcher) DeleteVCHInstances(vmm *vm.VirtualMachine, conf *config.Vir } if err != nil { errs = append(errs, err.Error()) + continue } if err = d.deleteVM(child, d.force); err != nil { diff --git a/lib/migration/migrator_test.go b/lib/migration/migrator_test.go index ba59bb745a..e57d77c6eb 100644 --- a/lib/migration/migrator_test.go +++ b/lib/migration/migrator_test.go @@ -15,14 +15,13 @@ package migration import ( + "strconv" "strings" "testing" log "github.com/Sirupsen/logrus" "github.com/stretchr/testify/assert" - "strconv" - "github.com/vmware/vic/lib/config" "github.com/vmware/vic/lib/config/executor" "github.com/vmware/vic/lib/migration/manager" @@ -36,9 +35,9 @@ func setUp() { // register sample plugin into test log.SetLevel(log.DebugLevel) trace.Logger.Level = log.DebugLevel - version.MaxPluginVersion = 4 + version.MaxPluginVersion = version.MaxPluginVersion + 1 - if err := manager.Migrator.Register(version.MaxPluginVersion, manager.ApplianceConfigure, &plugin1.ApplianceStopSignalRename{}); err != nil { + if err := manager.Migrator.Register(1, manager.ApplianceConfigure, &plugin1.ApplianceStopSignalRename{}); err != nil { log.Errorf("Failed to register plugin %s:%d, %s", manager.ApplianceConfigure, version.MaxPluginVersion, err) } } diff --git a/lib/migration/plugins/init.go b/lib/migration/plugins/init.go index 2c6be34364..1353b3d783 100644 --- a/lib/migration/plugins/init.go +++ b/lib/migration/plugins/init.go @@ -18,4 +18,4 @@ package plugins import ( _ "github.com/vmware/vic/pkg/version/plugin2" _ "github.com/vmware/vic/pkg/version/plugin3" -) \ No newline at end of file +) diff --git a/lib/portlayer/network/context_test.go b/lib/portlayer/network/context_test.go index 4b7f759689..bea2886aec 100644 --- a/lib/portlayer/network/context_test.go +++ b/lib/portlayer/network/context_test.go @@ -693,7 +693,7 @@ func TestContextAddContainer(t *testing.T) { func newContainer(name string) *exec.Handle { h := exec.TestHandle(uid.New().String()) - h.ExecConfig.CommonSpecForVM.Name = name + h.ExecConfig.ExecutorConfigCommon.Name = name return h } diff --git a/lib/tether/cmd_test.go b/lib/tether/cmd_test.go index 7cd6319c93..a4d66291ee 100644 --- a/lib/tether/cmd_test.go +++ b/lib/tether/cmd_test.go @@ -37,7 +37,7 @@ func TestPathLookup(t *testing.T) { defer testTeardown(t, mocker) cfg := executor.ExecutorConfig{ - CommonSpecForVM: executor.CommonSpecForVM{ + ExecutorConfigCommon: executor.ExecutorConfigCommon{ ID: "pathlookup", Name: "tether_test_executor", }, @@ -77,7 +77,7 @@ func TestRelativePath(t *testing.T) { defer testTeardown(t, mocker) cfg := executor.ExecutorConfig{ - CommonSpecForVM: executor.CommonSpecForVM{ + ExecutorConfigCommon: executor.ExecutorConfigCommon{ ID: "relpath", Name: "tether_test_executor", }, @@ -117,7 +117,7 @@ func TestAbsPath(t *testing.T) { defer testTeardown(t, mocker) cfg := executor.ExecutorConfig{ - CommonSpecForVM: executor.CommonSpecForVM{ + ExecutorConfigCommon: executor.ExecutorConfigCommon{ ID: "abspath", Name: "tether_test_executor", }, @@ -175,7 +175,7 @@ func TestHalt(t *testing.T) { defer testTeardown(t, mocker) cfg := executor.ExecutorConfig{ - CommonSpecForVM: executor.CommonSpecForVM{ + ExecutorConfigCommon: executor.ExecutorConfigCommon{ ID: "abspath", Name: "tether_test_executor", }, @@ -251,7 +251,7 @@ func TestMissingBinary(t *testing.T) { defer testTeardown(t, mocker) cfg := executor.ExecutorConfig{ - CommonSpecForVM: executor.CommonSpecForVM{ + ExecutorConfigCommon: executor.ExecutorConfigCommon{ ID: "missing", Name: "tether_test_executor", }, @@ -300,7 +300,7 @@ func TestMissingRelativeBinary(t *testing.T) { defer testTeardown(t, mocker) cfg := executor.ExecutorConfig{ - CommonSpecForVM: executor.CommonSpecForVM{ + ExecutorConfigCommon: executor.ExecutorConfigCommon{ ID: "missing", Name: "tether_test_executor", }, diff --git a/lib/tether/config_test.go b/lib/tether/config_test.go index 9a4c276436..591b6510db 100644 --- a/lib/tether/config_test.go +++ b/lib/tether/config_test.go @@ -32,7 +32,7 @@ var ( func TestToExtraConfig(t *testing.T) { exec := executor.ExecutorConfig{ - CommonSpecForVM: executor.CommonSpecForVM{ + ExecutorConfigCommon: executor.ExecutorConfigCommon{ ID: "deadbeef", Name: "configtest", }, diff --git a/lib/tether/net_linux_test.go b/lib/tether/net_linux_test.go index 1678031c56..542fdf124e 100644 --- a/lib/tether/net_linux_test.go +++ b/lib/tether/net_linux_test.go @@ -74,7 +74,7 @@ func TestSetIpAddress(t *testing.T) { secondIP, _ := netlink.ParseIPNet("172.16.0.10/24") gwIP, _ := netlink.ParseIPNet("172.16.0.1/24") cfg := executor.ExecutorConfig{ - CommonSpecForVM: executor.CommonSpecForVM{ + ExecutorConfigCommon: executor.ExecutorConfigCommon{ ID: "ipconfig", Name: "tether_test_executor", }, diff --git a/lib/tether/net_test.go b/lib/tether/net_test.go index 8e8b3acada..ab6206b3af 100644 --- a/lib/tether/net_test.go +++ b/lib/tether/net_test.go @@ -27,7 +27,7 @@ func TestSetHostname(t *testing.T) { defer testTeardown(t, mocker) cfg := executor.ExecutorConfig{ - CommonSpecForVM: executor.CommonSpecForVM{ + ExecutorConfigCommon: executor.ExecutorConfigCommon{ ID: "sethostname", Name: "tether_test_executor", }, @@ -54,7 +54,7 @@ func TestNoNetwork(t *testing.T) { defer testTeardown(t, mocker) cfg := executor.ExecutorConfig{ - CommonSpecForVM: executor.CommonSpecForVM{ + ExecutorConfigCommon: executor.ExecutorConfigCommon{ ID: "ipconfig", Name: "tether_test_executor", }, diff --git a/lib/vicadmin/validate.go b/lib/vicadmin/validate.go index adff1582cd..68cf1c65d4 100644 --- a/lib/vicadmin/validate.go +++ b/lib/vicadmin/validate.go @@ -15,6 +15,7 @@ package vicadmin import ( + "context" "fmt" "html/template" "io/ioutil" @@ -24,8 +25,6 @@ import ( "strings" "time" - "context" - log "github.com/Sirupsen/logrus" "github.com/docker/docker/opts" @@ -113,7 +112,11 @@ func NewValidator(ctx context.Context, vch *config.VirtualContainerHostConfigSpe log.Infof("Setting version to %s", v.Version) // VCH Name - v.Hostname = GetVCHName(ctx, sess) + name, err := VCHName(ctx, sess) + if err != nil { + log.Errorf("Failed to get VCH name: %s", err) + } + v.Hostname = name // System time v.SystemTime = time.Now().Format(time.UnixDate) @@ -204,7 +207,7 @@ func NewValidator(ctx context.Context, vch *config.VirtualContainerHostConfigSpe v.DockerPort = fmt.Sprintf("%d", opts.DefaultTLSHTTPPort) } - err := v.QueryDatastore(ctx, vch, sess) + err = v.QueryDatastore(ctx, vch, sess) if err != nil { log.Errorf("Had a problem querying the datastores: %s", err.Error()) } @@ -212,23 +215,28 @@ func NewValidator(ctx context.Context, vch *config.VirtualContainerHostConfigSpe return v } -func GetVCHName(ctx context.Context, sess *session.Session) string { +func VCHName(ctx context.Context, sess *session.Session) (string, error) { defer trace.End(trace.Begin("")) - var vchName = fmt.Sprintf("VCH") + var vchName string + self, err := guest.GetSelf(ctx, sess) - if err != nil || self == nil { + if err != nil { log.Errorf("Unable to get VCH name due to unknown self-reference: %s", err) log.Infof("Setting the VCH name to VCH") - return vchName + return fmt.Sprintf("VCH"), err } + self2 := vm.NewVirtualMachineFromVM(ctx, sess, self) vchName, err = self2.Name(ctx) if err != nil { - log.Infof("Unable to get VCH name: %s", err) + log.Errorf("Unable to get VCH name: %s", err) + log.Infof("Setting the VCH name to VCH") + return fmt.Sprintf("VCH"), err } + log.Infof("Setting the VCH name to %s", vchName) - return vchName + return vchName, nil } type dsList []mo.Datastore diff --git a/tests/test-cases/Group11-Upgrade/11-01-Upgrade.md b/tests/test-cases/Group11-Upgrade/11-01-Upgrade.md index c649e5b5b9..a1be680dcc 100644 --- a/tests/test-cases/Group11-Upgrade/11-01-Upgrade.md +++ b/tests/test-cases/Group11-Upgrade/11-01-Upgrade.md @@ -17,9 +17,11 @@ This test requires that a vSphere server is running and available 7. Roll back to the previous version 8. Upgrade again to the upgraded version 9. Check the previous created container and image are still there +10. Check the previous created container's display name and datastore folder name #Expected Outcome: * Step 5 should fail with timeout +* Step 10 should show that both the container's display name and datastore folder name are containerName-containerID * All other steps should result in success #Possible Problems: diff --git a/tests/test-cases/Group11-Upgrade/11-01-Upgrade.robot b/tests/test-cases/Group11-Upgrade/11-01-Upgrade.robot index 0786fbafd0..5c33032115 100644 --- a/tests/test-cases/Group11-Upgrade/11-01-Upgrade.robot +++ b/tests/test-cases/Group11-Upgrade/11-01-Upgrade.robot @@ -103,6 +103,12 @@ Run Docker Checks ${rc} ${output}= Run And Return Rc And Output docker %{VCH-PARAMS} ps -a Should Be Equal As Integers ${rc} 0 Should Not Contain ${output} Exited (0) + ${rc} ${output}= Run And Return Rc And Output govc vm.info *-%{ID1} + Should Be Equal As Integers ${rc} 0 + Should Contain ${output} vch-restart-tes-%{ID1} + ${rc} ${output}= Run And Return Rc And Output govc datastore.ls |grep *-%{ID1} + Should Be Equal As Integers ${rc} 0 + Should Be Equal ${output} vch-restart-tes-%{ID1} Wait Until Keyword Succeeds 20x 5 seconds Hit Nginx Endpoint %{VCH-IP} 10000 Wait Until Keyword Succeeds 20x 5 seconds Hit Nginx Endpoint %{VCH-IP} 10001 From 7fb5d056dd69f822c4bd6997a5f291655b34e893 Mon Sep 17 00:00:00 2001 From: chengwang86 Date: Wed, 8 Mar 2017 14:46:08 -0800 Subject: [PATCH 27/58] rearrage --- lib/portlayer/exec/commit.go | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/lib/portlayer/exec/commit.go b/lib/portlayer/exec/commit.go index 461cdfcd4b..51436fe52d 100644 --- a/lib/portlayer/exec/commit.go +++ b/lib/portlayer/exec/commit.go @@ -96,24 +96,9 @@ func Commit(ctx context.Context, sess *session.Session, h *Handle, waitTime *int // processing h.Spec = nil - // reconfigure vm display name to containerName-containerID - shortID := stringid.TruncateID(c.ExecConfig.ID) - nameMaxLen := maxVMNameLength - len(shortID) - prettyName := c.ExecConfig.Name - if len(prettyName) > nameMaxLen-1 { - prettyName = prettyName[:nameMaxLen-1] - } - - fullName := fmt.Sprintf("%s-%s", prettyName, shortID) - task, err := h.vm.VirtualMachine.Rename(ctx, fullName) - if err != nil { - return err - } - - _, err = task.WaitForResult(ctx, nil) - if err != nil { - return err - } + c.m.Lock() + err = c.UpdateDisplayName(ctx, c.ExecConfig.Name) + c.m.Unlock() } From f2ecb14b22379e95e2ebf83cdf345f8440a724cc Mon Sep 17 00:00:00 2001 From: chengwang86 Date: Fri, 10 Mar 2017 09:01:30 -0800 Subject: [PATCH 28/58] update VCHName() --- lib/vicadmin/validate.go | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/lib/vicadmin/validate.go b/lib/vicadmin/validate.go index 68cf1c65d4..0c7b3f4f1f 100644 --- a/lib/vicadmin/validate.go +++ b/lib/vicadmin/validate.go @@ -62,8 +62,9 @@ type Validator struct { } const ( - GoodStatus = template.HTML(``) - BadStatus = template.HTML(``) + GoodStatus = template.HTML(``) + BadStatus = template.HTML(``) + DefaultVCHName = `VCH` ) func GetMgmtIP() net.IPNet { @@ -112,11 +113,7 @@ func NewValidator(ctx context.Context, vch *config.VirtualContainerHostConfigSpe log.Infof("Setting version to %s", v.Version) // VCH Name - name, err := VCHName(ctx, sess) - if err != nil { - log.Errorf("Failed to get VCH name: %s", err) - } - v.Hostname = name + v.Hostname = VCHName(ctx, sess) // System time v.SystemTime = time.Now().Format(time.UnixDate) @@ -207,7 +204,7 @@ func NewValidator(ctx context.Context, vch *config.VirtualContainerHostConfigSpe v.DockerPort = fmt.Sprintf("%d", opts.DefaultTLSHTTPPort) } - err = v.QueryDatastore(ctx, vch, sess) + err := v.QueryDatastore(ctx, vch, sess) if err != nil { log.Errorf("Had a problem querying the datastores: %s", err.Error()) } @@ -215,28 +212,26 @@ func NewValidator(ctx context.Context, vch *config.VirtualContainerHostConfigSpe return v } -func VCHName(ctx context.Context, sess *session.Session) (string, error) { +func VCHName(ctx context.Context, sess *session.Session) string { defer trace.End(trace.Begin("")) - var vchName string - self, err := guest.GetSelf(ctx, sess) if err != nil { log.Errorf("Unable to get VCH name due to unknown self-reference: %s", err) log.Infof("Setting the VCH name to VCH") - return fmt.Sprintf("VCH"), err + return DefaultVCHName } self2 := vm.NewVirtualMachineFromVM(ctx, sess, self) - vchName, err = self2.Name(ctx) + vchName, err := self2.Name(ctx) if err != nil { log.Errorf("Unable to get VCH name: %s", err) log.Infof("Setting the VCH name to VCH") - return fmt.Sprintf("VCH"), err + return DefaultVCHName } log.Infof("Setting the VCH name to %s", vchName) - return vchName, nil + return vchName } type dsList []mo.Datastore From f8040d483d6a94aad497817a1761b91669094ab0 Mon Sep 17 00:00:00 2001 From: chengwang86 Date: Fri, 10 Mar 2017 10:00:58 -0800 Subject: [PATCH 29/58] fix the issue of vicadmin grabbing container log bunble using containerName-containerID (now containerID) --- cmd/vicadmin/vicadm.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/cmd/vicadmin/vicadm.go b/cmd/vicadmin/vicadm.go index 203aab2c0c..a8fb877841 100644 --- a/cmd/vicadmin/vicadm.go +++ b/cmd/vicadmin/vicadm.go @@ -324,11 +324,15 @@ func listVMPaths(ctx context.Context, s *session.Session) ([]logfile, error) { continue } - logname, err := child.Name(ctx) + logname, err := child.VMPathName(ctx) if err != nil { - log.Errorf("Unable to get the vm name for %s: %s", child.Reference(), err) + log.Errorf("Unable to get the vm path name for %s: %s", child.Reference(), err) continue } + if logname != "" { + names := strings.Split(logname, " ") + logname = names[len(names)-1] + } if self != nil && child.Reference().String() == self.Reference().String() { // FIXME: until #2630 is addressed, and we confirm this filters secrets from appliance vmware.log as well, From 0f9cb0b6de83baa0b0a078705190031de88f22d1 Mon Sep 17 00:00:00 2001 From: chengwang86 Date: Fri, 10 Mar 2017 10:57:03 -0800 Subject: [PATCH 30/58] update code based on comments --- lib/portlayer/exec/commit.go | 3 --- lib/portlayer/exec/container.go | 28 ++++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/lib/portlayer/exec/commit.go b/lib/portlayer/exec/commit.go index 51436fe52d..b28d604e3e 100644 --- a/lib/portlayer/exec/commit.go +++ b/lib/portlayer/exec/commit.go @@ -28,11 +28,8 @@ import ( "github.com/vmware/vic/pkg/vsphere/vm" log "github.com/Sirupsen/logrus" - "github.com/docker/docker/pkg/stringid" ) -const maxVMNameLength = 80 - // Commit executes the requires steps on the handle func Commit(ctx context.Context, sess *session.Session, h *Handle, waitTime *int32) error { defer trace.End(trace.Begin(h.ExecConfig.ID)) diff --git a/lib/portlayer/exec/container.go b/lib/portlayer/exec/container.go index 47c0428cca..e328b32ee5 100644 --- a/lib/portlayer/exec/container.go +++ b/lib/portlayer/exec/container.go @@ -58,6 +58,9 @@ const ( vmNotSuspendedKey = "msg.suspend.powerOff.notsuspended" vmPoweringOffKey = "msg.rpc.error.poweringoff" + + maxVMNameLength = 80 + shortIDLen = 12 ) func (s State) String() string { @@ -638,6 +641,31 @@ func (c *Container) OnEvent(e events.Event) { log.Errorf("Event driven container update failed for %s with %s", c, err) } } +// Update the VM display name on vSphere UI +func (c *Container) UpdateDisplayName(ctx context.Context, newName string) error { + defer trace.End(trace.Begin(c.ExecConfig.ID)) + + if c.vm == nil { + return NotFoundError{} + } + + shortID := c.ExecConfig.ID[:shortIDLen] + nameMaxLen := maxVMNameLength - len(shortID) + prettyName := newName + if len(prettyName) > nameMaxLen-1 { + prettyName = prettyName[:nameMaxLen-1] + } + + fullName := fmt.Sprintf("%s-%s", prettyName, shortID) + + _, err := c.vm.WaitForResult(ctx, func(ctx context.Context) (tasks.Task, error) { + return c.vm.Rename(ctx, fullName) + }) + if err != nil { + return err + } + + return nil } // get the containerVMs from infrastructure for this resource pool From 9c81713452ea331af238f78827ab14bc4489635d Mon Sep 17 00:00:00 2001 From: chengwang86 Date: Fri, 10 Mar 2017 11:03:59 -0800 Subject: [PATCH 31/58] update test case 9-01 --- .../Group9-VIC-Admin/9-01-VICAdmin-ShowHTML.robot | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tests/test-cases/Group9-VIC-Admin/9-01-VICAdmin-ShowHTML.robot b/tests/test-cases/Group9-VIC-Admin/9-01-VICAdmin-ShowHTML.robot index 0bf531119c..68c76f9214 100644 --- a/tests/test-cases/Group9-VIC-Admin/9-01-VICAdmin-ShowHTML.robot +++ b/tests/test-cases/Group9-VIC-Admin/9-01-VICAdmin-ShowHTML.robot @@ -64,9 +64,8 @@ While Logged Out Fail To Get Container Logs Should not Be Equal As Integers ${rc} 0 Should Contain ${output} gzip: stdin: not in gzip format Log ${output} - ${vmName}= Get VM display name ${container} - Should not Contain ${output} ${vmName}/vmware.log - Should not Contain ${output} ${vmName}/tether.debug + Should not Contain ${output} ${container}/vmware.log + Should not Contain ${output} ${container}/tether.debug While Logged Out Fail To Get VICAdmin Log ${rc} ${output}= Run And Return Rc And Output curl -sk %{VIC-ADMIN}/logs/vicadmin.log @@ -109,8 +108,8 @@ Get Container Logs Should Be Equal As Integers ${rc} 0 Log ${output} ${vmName}= Get VM display name ${container} - Should Contain ${output} ${vmName}/vmware.log - Should Contain ${output} ${vmName}/tether.debug + Should Contain ${output} ${container}/vmware.log + Should Contain ${output} ${container}/tether.debug Get VICAdmin Log Login And Save Cookies From a2f4c9573b3d26442482c8c5b8af6292215912c7 Mon Sep 17 00:00:00 2001 From: chengwang86 Date: Fri, 10 Mar 2017 11:31:44 -0800 Subject: [PATCH 32/58] update test 9-01 --- tests/test-cases/Group9-VIC-Admin/9-01-VICAdmin-ShowHTML.robot | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/test-cases/Group9-VIC-Admin/9-01-VICAdmin-ShowHTML.robot b/tests/test-cases/Group9-VIC-Admin/9-01-VICAdmin-ShowHTML.robot index 68c76f9214..0ad5f61fc5 100644 --- a/tests/test-cases/Group9-VIC-Admin/9-01-VICAdmin-ShowHTML.robot +++ b/tests/test-cases/Group9-VIC-Admin/9-01-VICAdmin-ShowHTML.robot @@ -107,7 +107,6 @@ Get Container Logs ${rc} ${output}= Run And Return Rc and Output curl -sk %{VIC-ADMIN}/container-logs.tar.gz -b /tmp/cookies-%{VCH-NAME} | tar tvzf - Should Be Equal As Integers ${rc} 0 Log ${output} - ${vmName}= Get VM display name ${container} Should Contain ${output} ${container}/vmware.log Should Contain ${output} ${container}/tether.debug From 9afaea64a52ee8880c9a9ae4b142c46e640b5f1a Mon Sep 17 00:00:00 2001 From: chengwang86 Date: Mon, 13 Mar 2017 08:22:50 -0700 Subject: [PATCH 33/58] set vm full name to be containerName-shortID --- lib/portlayer/exec/handle.go | 5 +++++ lib/spec/spec.go | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/portlayer/exec/handle.go b/lib/portlayer/exec/handle.go index a2bc210d94..412cfbe696 100644 --- a/lib/portlayer/exec/handle.go +++ b/lib/portlayer/exec/handle.go @@ -290,6 +290,11 @@ func Create(ctx context.Context, vmomiSession *session.Session, config *Containe Metadata: config.Metadata, } + // if not vsan + if dsType, _ := sess.Datastore.Type(ctx); dsType != types.HostFileSystemVolumeFileSystemTypeVsan { + specconfig.VMPathName = fmt.Sprintf("[%s] %s/%s.vmx", sess.Datastore.Name(), config.Metadata.ID, config.Metadata.ID) + } + // log only core portions s := specconfig log.Debugf("id: %s, name: %s, cpu: %d, mem: %d, parent: %s, os: %s, path: %s", s.ID, s.Name, s.NumCPUs, s.MemoryMB, s.ParentImageID, s.BootMediaPath, s.VMPathName) diff --git a/lib/spec/spec.go b/lib/spec/spec.go index 015402971f..e073a10fdd 100644 --- a/lib/spec/spec.go +++ b/lib/spec/spec.go @@ -25,6 +25,7 @@ import ( "github.com/vmware/vic/pkg/vsphere/extraconfig" "github.com/vmware/vic/pkg/vsphere/extraconfig/vmomi" "github.com/vmware/vic/pkg/vsphere/session" + "fmt" ) // NilSlot is an invalid PCI slot number @@ -88,7 +89,8 @@ type VirtualMachineConfigSpec struct { func NewVirtualMachineConfigSpec(ctx context.Context, session *session.Session, config *VirtualMachineConfigSpecConfig) (*VirtualMachineConfigSpec, error) { defer trace.End(trace.Begin(config.ID)) - config.VMFullName = config.ID + //config.VMFullName = config.ID + config.VMFullName = fmt.Sprint("%s-%s", config.Name,config.ID[0:11]) s := &types.VirtualMachineConfigSpec{ Name: config.ID, From 625447c13a38d9777b487356c96b4b680ced3be4 Mon Sep 17 00:00:00 2001 From: chengwang86 Date: Tue, 14 Mar 2017 07:40:01 -0700 Subject: [PATCH 34/58] add vsan logic --- cmd/vicadmin/vicadm.go | 11 ++++++----- lib/portlayer/exec/commit.go | 6 +++--- lib/portlayer/exec/handle.go | 12 +++++++++++- lib/spec/spec.go | 9 +++++---- 4 files changed, 25 insertions(+), 13 deletions(-) diff --git a/cmd/vicadmin/vicadm.go b/cmd/vicadmin/vicadm.go index a8fb877841..280e7096c4 100644 --- a/cmd/vicadmin/vicadm.go +++ b/cmd/vicadmin/vicadm.go @@ -324,15 +324,16 @@ func listVMPaths(ctx context.Context, s *session.Session) ([]logfile, error) { continue } - logname, err := child.VMPathName(ctx) + //logname, err := child.VMPathName(ctx) + logname, err := child.Name(ctx) if err != nil { log.Errorf("Unable to get the vm path name for %s: %s", child.Reference(), err) continue } - if logname != "" { - names := strings.Split(logname, " ") - logname = names[len(names)-1] - } + //if logname != "" { + // names := strings.Split(logname, " ") + // logname = names[len(names)-1] + //} if self != nil && child.Reference().String() == self.Reference().String() { // FIXME: until #2630 is addressed, and we confirm this filters secrets from appliance vmware.log as well, diff --git a/lib/portlayer/exec/commit.go b/lib/portlayer/exec/commit.go index b28d604e3e..50dd8f571d 100644 --- a/lib/portlayer/exec/commit.go +++ b/lib/portlayer/exec/commit.go @@ -93,9 +93,9 @@ func Commit(ctx context.Context, sess *session.Session, h *Handle, waitTime *int // processing h.Spec = nil - c.m.Lock() - err = c.UpdateDisplayName(ctx, c.ExecConfig.Name) - c.m.Unlock() + //c.m.Lock() + //err = c.UpdateDisplayName(ctx, c.ExecConfig.Name) + //c.m.Unlock() } diff --git a/lib/portlayer/exec/handle.go b/lib/portlayer/exec/handle.go index 412cfbe696..9d5aab9f6e 100644 --- a/lib/portlayer/exec/handle.go +++ b/lib/portlayer/exec/handle.go @@ -291,10 +291,20 @@ func Create(ctx context.Context, vmomiSession *session.Session, config *Containe } // if not vsan - if dsType, _ := sess.Datastore.Type(ctx); dsType != types.HostFileSystemVolumeFileSystemTypeVsan { + if dsType, _ := sess.Datastore.Type(ctx); dsType == types.HostFileSystemVolumeFileSystemTypeVsan { + log.Debugf("this is on vsan") + specconfig.VMPathName = fmt.Sprintf("[%s] %s/%s.vmx", sess.Datastore.Name(), config.Metadata.ID, config.Metadata.ID) + } else { + log.Debugf("this is not on vsan") + //specconfig.VMPathName = fmt.Sprintf("[%s]", sess.Datastore.Name()) specconfig.VMPathName = fmt.Sprintf("[%s] %s/%s.vmx", sess.Datastore.Name(), config.Metadata.ID, config.Metadata.ID) } + shortID := specconfig.ID[:11] + specconfig.VMFullName = fmt.Sprintf("%s-%s", specconfig.Name, shortID) + + log.Debugf("the specconfig is: %+v", specconfig) + // log only core portions s := specconfig log.Debugf("id: %s, name: %s, cpu: %d, mem: %d, parent: %s, os: %s, path: %s", s.ID, s.Name, s.NumCPUs, s.MemoryMB, s.ParentImageID, s.BootMediaPath, s.VMPathName) diff --git a/lib/spec/spec.go b/lib/spec/spec.go index e073a10fdd..19d9a2a048 100644 --- a/lib/spec/spec.go +++ b/lib/spec/spec.go @@ -25,7 +25,6 @@ import ( "github.com/vmware/vic/pkg/vsphere/extraconfig" "github.com/vmware/vic/pkg/vsphere/extraconfig/vmomi" "github.com/vmware/vic/pkg/vsphere/session" - "fmt" ) // NilSlot is an invalid PCI slot number @@ -89,11 +88,13 @@ type VirtualMachineConfigSpec struct { func NewVirtualMachineConfigSpec(ctx context.Context, session *session.Session, config *VirtualMachineConfigSpecConfig) (*VirtualMachineConfigSpec, error) { defer trace.End(trace.Begin(config.ID)) - //config.VMFullName = config.ID - config.VMFullName = fmt.Sprint("%s-%s", config.Name,config.ID[0:11]) + ////config.VMFullName = config.ID + //shortID := config.ID[:11] + //config.VMFullName = fmt.Sprintf("%s-%s", config.Name, shortID) s := &types.VirtualMachineConfigSpec{ - Name: config.ID, + //Name: config.ID, + Name: config.VMFullName, Uuid: config.BiosUUID, Files: &types.VirtualMachineFileInfo{ VmPathName: config.VMPathName, From 4a5549148b60f58244748af05a5bb5086bcf3079 Mon Sep 17 00:00:00 2001 From: chengwang86 Date: Wed, 15 Mar 2017 09:48:36 -0700 Subject: [PATCH 35/58] add vsan logic to logging --- lib/portlayer/exec/commit.go | 6 +--- lib/portlayer/exec/container.go | 55 ++++++++++++++++---------------- lib/portlayer/exec/handle.go | 16 +++++----- lib/portlayer/logging/logging.go | 14 ++++++-- lib/portlayer/util/util.go | 17 ++++++++++ lib/spec/disk.go | 2 +- 6 files changed, 66 insertions(+), 44 deletions(-) diff --git a/lib/portlayer/exec/commit.go b/lib/portlayer/exec/commit.go index 50dd8f571d..22cdb3cea1 100644 --- a/lib/portlayer/exec/commit.go +++ b/lib/portlayer/exec/commit.go @@ -74,6 +74,7 @@ func Commit(ctx context.Context, sess *session.Session, h *Handle, waitTime *int // Create the vm res, err = tasks.WaitForResult(ctx, func(ctx context.Context) (tasks.Task, error) { + log.Errorf("failed when creating the VM") return parent.CreateVM(ctx, *h.Spec.Spec(), Config.ResourcePool, nil) }) } @@ -92,11 +93,6 @@ func Commit(ctx context.Context, sess *session.Session, h *Handle, waitTime *int // clear the spec as we've acted on it - this prevents a reconfigure from occurring in follow-on // processing h.Spec = nil - - //c.m.Lock() - //err = c.UpdateDisplayName(ctx, c.ExecConfig.Name) - //c.m.Unlock() - } // if we're stopping the VM, do so before the reconfigure to preserve the extraconfig diff --git a/lib/portlayer/exec/container.go b/lib/portlayer/exec/container.go index e328b32ee5..215c108451 100644 --- a/lib/portlayer/exec/container.go +++ b/lib/portlayer/exec/container.go @@ -58,9 +58,6 @@ const ( vmNotSuspendedKey = "msg.suspend.powerOff.notsuspended" vmPoweringOffKey = "msg.rpc.error.poweringoff" - - maxVMNameLength = 80 - shortIDLen = 12 ) func (s State) String() string { @@ -641,33 +638,35 @@ func (c *Container) OnEvent(e events.Event) { log.Errorf("Event driven container update failed for %s with %s", c, err) } } -// Update the VM display name on vSphere UI -func (c *Container) UpdateDisplayName(ctx context.Context, newName string) error { - defer trace.End(trace.Begin(c.ExecConfig.ID)) - - if c.vm == nil { - return NotFoundError{} - } - - shortID := c.ExecConfig.ID[:shortIDLen] - nameMaxLen := maxVMNameLength - len(shortID) - prettyName := newName - if len(prettyName) > nameMaxLen-1 { - prettyName = prettyName[:nameMaxLen-1] - } - - fullName := fmt.Sprintf("%s-%s", prettyName, shortID) - - _, err := c.vm.WaitForResult(ctx, func(ctx context.Context) (tasks.Task, error) { - return c.vm.Rename(ctx, fullName) - }) - if err != nil { - return err - } - - return nil } +//// Update the VM display name on vSphere UI +//func (c *Container) UpdateDisplayName(ctx context.Context, newName string) error { +// defer trace.End(trace.Begin(c.ExecConfig.ID)) +// +// if c.vm == nil { +// return NotFoundError{} +// } +// +// shortID := c.ExecConfig.ID[:shortIDLen] +// nameMaxLen := maxVMNameLength - len(shortID) +// prettyName := newName +// if len(prettyName) > nameMaxLen-1 { +// prettyName = prettyName[:nameMaxLen-1] +// } +// +// fullName := fmt.Sprintf("%s-%s", prettyName, shortID) +// +// _, err := c.vm.WaitForResult(ctx, func(ctx context.Context) (tasks.Task, error) { +// return c.vm.Rename(ctx, fullName) +// }) +// if err != nil { +// return err +// } +// +// return nil +//} + // get the containerVMs from infrastructure for this resource pool func infraContainers(ctx context.Context, sess *session.Session) ([]*Container, error) { defer trace.End(trace.Begin("")) diff --git a/lib/portlayer/exec/handle.go b/lib/portlayer/exec/handle.go index 9d5aab9f6e..0194319b82 100644 --- a/lib/portlayer/exec/handle.go +++ b/lib/portlayer/exec/handle.go @@ -33,6 +33,7 @@ import ( "github.com/vmware/vic/lib/config/executor" "github.com/vmware/vic/lib/guest" "github.com/vmware/vic/lib/portlayer/constants" + "github.com/vmware/vic/lib/portlayer/util" "github.com/vmware/vic/lib/spec" "github.com/vmware/vic/pkg/trace" "github.com/vmware/vic/pkg/vsphere/extraconfig" @@ -291,17 +292,16 @@ func Create(ctx context.Context, vmomiSession *session.Session, config *Containe } // if not vsan - if dsType, _ := sess.Datastore.Type(ctx); dsType == types.HostFileSystemVolumeFileSystemTypeVsan { - log.Debugf("this is on vsan") - specconfig.VMPathName = fmt.Sprintf("[%s] %s/%s.vmx", sess.Datastore.Name(), config.Metadata.ID, config.Metadata.ID) - } else { + if dsType, _ := sess.Datastore.Type(ctx); dsType != types.HostFileSystemVolumeFileSystemTypeVsan { log.Debugf("this is not on vsan") - //specconfig.VMPathName = fmt.Sprintf("[%s]", sess.Datastore.Name()) - specconfig.VMPathName = fmt.Sprintf("[%s] %s/%s.vmx", sess.Datastore.Name(), config.Metadata.ID, config.Metadata.ID) + //specconfig.VMPathName = fmt.Sprintf("[%s] %s", sess.Datastore.Name(), specconfig.ID) + specconfig.VMPathName = fmt.Sprintf("[%s] %s/%s.vmx", sess.Datastore.Name(), specconfig.ID, specconfig.ID) + } else { + log.Debugf("this is on vsan") + specconfig.VMPathName = fmt.Sprintf("[%s]", sess.Datastore.Name()) } - shortID := specconfig.ID[:11] - specconfig.VMFullName = fmt.Sprintf("%s-%s", specconfig.Name, shortID) + specconfig.VMFullName = util.DisplayName(specconfig.ID, specconfig.Name) log.Debugf("the specconfig is: %+v", specconfig) diff --git a/lib/portlayer/logging/logging.go b/lib/portlayer/logging/logging.go index 890256426f..770a9592f9 100644 --- a/lib/portlayer/logging/logging.go +++ b/lib/portlayer/logging/logging.go @@ -135,12 +135,22 @@ func Join(h interface{}) (interface{}, error) { return nil, fmt.Errorf("Type assertion failed for %#+v", handle) } + var logFilePath string + VMPathName := handle.Spec.VMPathName() VMName := handle.Spec.Spec().Name + VMID := handle.Spec.ID() + dsName := handle.Spec.Datastore.Name() - for _, logFile := range []string{"tether.debug", "output.log"} { - filename := fmt.Sprintf("%s/%s/%s", VMPathName, VMName, logFile) + if dsType, _ := handle.Spec.Datastore.Type(context.Background()); dsType == types.HostFileSystemVolumeFileSystemTypeVsan { + logFilePath = fmt.Sprintf("%s/%s", VMPathName, VMName) + } else { + logFilePath = fmt.Sprintf("[%s] %s", dsName, VMID) + } + for _, logFile := range []string{"tether.debug", "output.log"} { + filename := fmt.Sprintf("%s/%s", logFilePath, logFile) + log.Infof("set log file name to: %s", filename) // Debug and log serial ports - backed by datastore file serial := &types.VirtualSerialPort{ VirtualDevice: types.VirtualDevice{ diff --git a/lib/portlayer/util/util.go b/lib/portlayer/util/util.go index 1abfc2d55b..d6eea871e6 100644 --- a/lib/portlayer/util/util.go +++ b/lib/portlayer/util/util.go @@ -18,12 +18,17 @@ import ( "net/url" "os" + "fmt" + log "github.com/Sirupsen/logrus" ) const ( // XXX leaving this as http for now. We probably want to make this unix:// scheme = "http://" + + maxVMNameLength = 80 + shortIDLen = 12 ) var ( @@ -53,3 +58,15 @@ func ServiceURL(serviceName string) *url.URL { return s } + +// Update the VM display name on vSphere UI +func DisplayName(id, name string) string { + shortID := id[:shortIDLen] + nameMaxLen := maxVMNameLength - len(shortID) + prettyName := name + if len(prettyName) > nameMaxLen-1 { + prettyName = prettyName[:nameMaxLen-1] + } + + return fmt.Sprintf("%s-%s", prettyName, shortID) +} diff --git a/lib/spec/disk.go b/lib/spec/disk.go index 2816b68ae4..03ee619d21 100644 --- a/lib/spec/disk.go +++ b/lib/spec/disk.go @@ -68,7 +68,7 @@ func (s *VirtualMachineConfigSpec) AddVirtualDisk(device *types.VirtualDisk) *Vi ThinProvisioned: types.NewBool(true), VirtualDeviceFileBackingInfo: types.VirtualDeviceFileBackingInfo{ - FileName: s.Datastore.Path(fmt.Sprintf("%s/%s.vmdk", s.config.VMFullName, s.ID())), + FileName: s.Datastore.Path(fmt.Sprintf("%s/%s.vmdk", s.ID(), s.ID())), Datastore: &moref, }, } From 5f7ced483df3f04741459de2bc092215738b095e Mon Sep 17 00:00:00 2001 From: chengwang86 Date: Wed, 15 Mar 2017 14:42:54 -0700 Subject: [PATCH 36/58] - remove vm reconfigure after vm creation; instead, we set the datastore folder to containerID during vm creation - add vsan logic during vm creation --- cmd/vicadmin/vicadm.go | 27 +++++++++++++++++++-------- lib/portlayer/exec/container.go | 27 --------------------------- lib/portlayer/exec/handle.go | 7 +------ lib/portlayer/logging/logging.go | 1 + tests/resources/Docker-Util.robot | 3 +-- 5 files changed, 22 insertions(+), 43 deletions(-) diff --git a/cmd/vicadmin/vicadm.go b/cmd/vicadmin/vicadm.go index 280e7096c4..35dfdb52f4 100644 --- a/cmd/vicadmin/vicadm.go +++ b/cmd/vicadmin/vicadm.go @@ -314,6 +314,7 @@ func listVMPaths(ctx context.Context, s *session.Session) ([]logfile, error) { log.Infof("Found %d candidate VMs in resource pool %s for log collection", len(children), ref.String()) + var logname string logfiles := []logfile{} for _, child := range children { path, err := child.DSPath(ctx) @@ -324,16 +325,26 @@ func listVMPaths(ctx context.Context, s *session.Session) ([]logfile, error) { continue } - //logname, err := child.VMPathName(ctx) - logname, err := child.Name(ctx) + //logname, err = child.Name(ctx) + ec, err := child.FetchExtraConfig(ctx) if err != nil { - log.Errorf("Unable to get the vm path name for %s: %s", child.Reference(), err) - continue + log.Errorf("Unable to fetch the vm ExtraConfig for %s: %s", child.Reference(), err) + + logname, err = child.Name(ctx) + if err != nil { + log.Errorf("Unable to get the vm name for %s: %s", child.Reference(), err) + continue + } + } else { + // for the appliance VM, id is in guestinfo.vice./init/common/id; + // however, this is not problematic since we don't collect these logs for the appliance VM + logname = ec["guestinfo.vice./common/id"] + if logname == "" { + log.Infof("Skipping collection for appliance VM") + continue + } } - //if logname != "" { - // names := strings.Split(logname, " ") - // logname = names[len(names)-1] - //} + log.Infof("Setting logname to %s", logname) if self != nil && child.Reference().String() == self.Reference().String() { // FIXME: until #2630 is addressed, and we confirm this filters secrets from appliance vmware.log as well, diff --git a/lib/portlayer/exec/container.go b/lib/portlayer/exec/container.go index 215c108451..47c0428cca 100644 --- a/lib/portlayer/exec/container.go +++ b/lib/portlayer/exec/container.go @@ -640,33 +640,6 @@ func (c *Container) OnEvent(e events.Event) { } } -//// Update the VM display name on vSphere UI -//func (c *Container) UpdateDisplayName(ctx context.Context, newName string) error { -// defer trace.End(trace.Begin(c.ExecConfig.ID)) -// -// if c.vm == nil { -// return NotFoundError{} -// } -// -// shortID := c.ExecConfig.ID[:shortIDLen] -// nameMaxLen := maxVMNameLength - len(shortID) -// prettyName := newName -// if len(prettyName) > nameMaxLen-1 { -// prettyName = prettyName[:nameMaxLen-1] -// } -// -// fullName := fmt.Sprintf("%s-%s", prettyName, shortID) -// -// _, err := c.vm.WaitForResult(ctx, func(ctx context.Context) (tasks.Task, error) { -// return c.vm.Rename(ctx, fullName) -// }) -// if err != nil { -// return err -// } -// -// return nil -//} - // get the containerVMs from infrastructure for this resource pool func infraContainers(ctx context.Context, sess *session.Session) ([]*Container, error) { defer trace.End(trace.Begin("")) diff --git a/lib/portlayer/exec/handle.go b/lib/portlayer/exec/handle.go index 0194319b82..494911b375 100644 --- a/lib/portlayer/exec/handle.go +++ b/lib/portlayer/exec/handle.go @@ -291,14 +291,9 @@ func Create(ctx context.Context, vmomiSession *session.Session, config *Containe Metadata: config.Metadata, } - // if not vsan + // if not vsan, set the datastore folder name to containerID if dsType, _ := sess.Datastore.Type(ctx); dsType != types.HostFileSystemVolumeFileSystemTypeVsan { - log.Debugf("this is not on vsan") - //specconfig.VMPathName = fmt.Sprintf("[%s] %s", sess.Datastore.Name(), specconfig.ID) specconfig.VMPathName = fmt.Sprintf("[%s] %s/%s.vmx", sess.Datastore.Name(), specconfig.ID, specconfig.ID) - } else { - log.Debugf("this is on vsan") - specconfig.VMPathName = fmt.Sprintf("[%s]", sess.Datastore.Name()) } specconfig.VMFullName = util.DisplayName(specconfig.ID, specconfig.Name) diff --git a/lib/portlayer/logging/logging.go b/lib/portlayer/logging/logging.go index 770a9592f9..77c0bddea9 100644 --- a/lib/portlayer/logging/logging.go +++ b/lib/portlayer/logging/logging.go @@ -151,6 +151,7 @@ func Join(h interface{}) (interface{}, error) { for _, logFile := range []string{"tether.debug", "output.log"} { filename := fmt.Sprintf("%s/%s", logFilePath, logFile) log.Infof("set log file name to: %s", filename) + // Debug and log serial ports - backed by datastore file serial := &types.VirtualSerialPort{ VirtualDevice: types.VirtualDevice{ diff --git a/tests/resources/Docker-Util.robot b/tests/resources/Docker-Util.robot index 60754a40b8..dcead333ce 100644 --- a/tests/resources/Docker-Util.robot +++ b/tests/resources/Docker-Util.robot @@ -88,8 +88,7 @@ Run Regression Tests Should Be Equal As Integers ${rc} 0 Should Contain ${output} Exited - ${containerShortID}= Get container shortID ${container} - Wait Until Keyword Succeeds 5x 10s Check For The Proper Log Files ${containerShortID} + Wait Until Keyword Succeeds 5x 10s Check For The Proper Log Files ${container} ${rc} ${output}= Run And Return Rc And Output docker %{VCH-PARAMS} rm ${container} Should Be Equal As Integers ${rc} 0 From 65a75f783a2c89d56097cae9349568c2c88fd993 Mon Sep 17 00:00:00 2001 From: chengwang86 Date: Wed, 15 Mar 2017 15:14:00 -0700 Subject: [PATCH 37/58] cosmetic changes --- cmd/vicadmin/vicadm.go | 1 - lib/portlayer/util/util.go | 3 +-- lib/spec/spec.go | 8 +------- .../Group1-Docker-Commands/1-04-Docker-Create.robot | 12 +++++++----- 4 files changed, 9 insertions(+), 15 deletions(-) diff --git a/cmd/vicadmin/vicadm.go b/cmd/vicadmin/vicadm.go index 35dfdb52f4..1d1e9ab407 100644 --- a/cmd/vicadmin/vicadm.go +++ b/cmd/vicadmin/vicadm.go @@ -325,7 +325,6 @@ func listVMPaths(ctx context.Context, s *session.Session) ([]logfile, error) { continue } - //logname, err = child.Name(ctx) ec, err := child.FetchExtraConfig(ctx) if err != nil { log.Errorf("Unable to fetch the vm ExtraConfig for %s: %s", child.Reference(), err) diff --git a/lib/portlayer/util/util.go b/lib/portlayer/util/util.go index d6eea871e6..29ad35d2d2 100644 --- a/lib/portlayer/util/util.go +++ b/lib/portlayer/util/util.go @@ -15,11 +15,10 @@ package util import ( + "fmt" "net/url" "os" - "fmt" - log "github.com/Sirupsen/logrus" ) diff --git a/lib/spec/spec.go b/lib/spec/spec.go index 19d9a2a048..bb24ebd8ae 100644 --- a/lib/spec/spec.go +++ b/lib/spec/spec.go @@ -15,9 +15,8 @@ package spec import ( - "net/url" - "context" + "net/url" "github.com/vmware/govmomi/vim25/types" "github.com/vmware/vic/lib/config/executor" @@ -88,12 +87,7 @@ type VirtualMachineConfigSpec struct { func NewVirtualMachineConfigSpec(ctx context.Context, session *session.Session, config *VirtualMachineConfigSpecConfig) (*VirtualMachineConfigSpec, error) { defer trace.End(trace.Begin(config.ID)) - ////config.VMFullName = config.ID - //shortID := config.ID[:11] - //config.VMFullName = fmt.Sprintf("%s-%s", config.Name, shortID) - s := &types.VirtualMachineConfigSpec{ - //Name: config.ID, Name: config.VMFullName, Uuid: config.BiosUUID, Files: &types.VirtualMachineFileInfo{ diff --git a/tests/test-cases/Group1-Docker-Commands/1-04-Docker-Create.robot b/tests/test-cases/Group1-Docker-Commands/1-04-Docker-Create.robot index cfb033b764..7b3cdc50e5 100644 --- a/tests/test-cases/Group1-Docker-Commands/1-04-Docker-Create.robot +++ b/tests/test-cases/Group1-Docker-Commands/1-04-Docker-Create.robot @@ -181,11 +181,13 @@ Create a container and check the VM display name and datastore folder name ${rc} ${id}= Run And Return Rc And Output docker %{VCH-PARAMS} create -it --name busy3 busybox Should Be Equal As Integers ${rc} 0 ${vmName}= Get VM display name ${id} - ${shortID}= Get Substring ${id} 0 12 - Should Be Equal ${vmName} busy3-${shortID} - ${rc} ${output}= Run And Return Rc And Output govc vm.info ${vmName}* - Should Be Equal As Integers ${rc} 0 - Should contain ${output} ${vmName} + ${rc} ${output}= Run Keyword If '%{HOST_TYPE}' == 'VC' Run And Return Rc And Output govc vm.info %{VCH-NAME}/${vmName} + Run Keyword If '%{HOST_TYPE}' == 'VC' Should Be Equal As Integers ${rc} 0 + Run Keyword If '%{HOST_TYPE}' == 'VC' Should contain ${output} ${vmName} + ${rc} ${output}= Run Keyword If '%{HOST_TYPE}' == 'ESXi' Run And Return Rc And Output govc vm.info ${vmname} + Run Keyword If '%{HOST_TYPE}' == 'ESXi' Should Be Equal As Integers ${rc} 0 + Run Keyword If '%{HOST_TYPE}' == 'ESXi' Should Contain ${output} ${vmName} + # For non-vSAN setup, the datastore folder name should be containerID; however, for vSAN setup, the datastore folder name should be containerName-containerShortID ${rc} ${output}= Run And Return Rc And Output govc datastore.ls |grep ${id} Should Be Equal As Integers ${rc} 0 Should Be Equal ${output} ${id} From 4acae5234b8704788ccc43388b1affcf16e85018 Mon Sep 17 00:00:00 2001 From: chengwang86 Date: Wed, 15 Mar 2017 15:16:44 -0700 Subject: [PATCH 38/58] add plugins --- pkg/version/plugin2/commonSpecForVCH.go | 128 ++++++++++++++++++ pkg/version/plugin3/commonSpecForContainer.go | 117 ++++++++++++++++ 2 files changed, 245 insertions(+) create mode 100644 pkg/version/plugin2/commonSpecForVCH.go create mode 100644 pkg/version/plugin3/commonSpecForContainer.go diff --git a/pkg/version/plugin2/commonSpecForVCH.go b/pkg/version/plugin2/commonSpecForVCH.go new file mode 100644 index 0000000000..734467d1fa --- /dev/null +++ b/pkg/version/plugin2/commonSpecForVCH.go @@ -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 plugin2 + +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 = 2 + 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) + } +} + +// 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) + log.Debugf("The newStruct is %+v", newStruct) + + for k, v := range cfg { + log.Debugf("New data: %s:%s", k, v) + mapData[k] = v + } + return nil +} diff --git a/pkg/version/plugin3/commonSpecForContainer.go b/pkg/version/plugin3/commonSpecForContainer.go new file mode 100644 index 0000000000..2c09d9310e --- /dev/null +++ b/pkg/version/plugin3/commonSpecForContainer.go @@ -0,0 +1,117 @@ +// 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 plugin3 + +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 = 3 + target = manager.ContainerConfigure +) + +func init() { + defer trace.End(trace.Begin(fmt.Sprintf("Registering plugin %s:%d", target, version))) + if err := manager.Migrator.Register(version, target, &AddCommonSpecForContainer{}); err != nil { + log.Errorf("Failed to register plugin %s:%d, %s", target, version, err) + } +} + +// AddCommonSpecForVM is plugin for vic 0.8.0-GA version upgrade +type AddCommonSpecForContainer struct { +} + +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 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 *AddCommonSpecForContainer) Migrate(ctx context.Context, s *session.Session, data interface{}) error { + defer trace.End(trace.Begin(fmt.Sprintf("AddCommonSpecForContainer 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 := &ExecutorConfig{} + 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 := &UpdatedExecutorConfig{ + UpdatedCommon: UpdatedCommon{ + Name: oldStruct.Name, + ID: oldStruct.ID, + Notes: oldStruct.Notes, + ExecutionEnvironment: oldStruct.ExecutionEnvironment, + }} + + cfg := make(map[string]string) + extraconfig.Encode(extraconfig.MapSink(cfg), newStruct) + log.Debugf("The newStruct is %+v", newStruct) + + for k, v := range cfg { + log.Debugf("New data: %s:%s", k, v) + mapData[k] = v + } + return nil +} From 175d2788ced4bb81b1a66313ff4eaeb56dda555a Mon Sep 17 00:00:00 2001 From: chengwang86 Date: Wed, 15 Mar 2017 15:29:30 -0700 Subject: [PATCH 39/58] remove unnecessary comments and update test case --- lib/portlayer/exec/commit.go | 1 - lib/portlayer/exec/handle.go | 2 -- tests/test-cases/Group11-Upgrade/11-01-Upgrade.robot | 9 ++++++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/portlayer/exec/commit.go b/lib/portlayer/exec/commit.go index 22cdb3cea1..354881048c 100644 --- a/lib/portlayer/exec/commit.go +++ b/lib/portlayer/exec/commit.go @@ -74,7 +74,6 @@ func Commit(ctx context.Context, sess *session.Session, h *Handle, waitTime *int // Create the vm res, err = tasks.WaitForResult(ctx, func(ctx context.Context) (tasks.Task, error) { - log.Errorf("failed when creating the VM") return parent.CreateVM(ctx, *h.Spec.Spec(), Config.ResourcePool, nil) }) } diff --git a/lib/portlayer/exec/handle.go b/lib/portlayer/exec/handle.go index 494911b375..b67efbeb9f 100644 --- a/lib/portlayer/exec/handle.go +++ b/lib/portlayer/exec/handle.go @@ -298,8 +298,6 @@ func Create(ctx context.Context, vmomiSession *session.Session, config *Containe specconfig.VMFullName = util.DisplayName(specconfig.ID, specconfig.Name) - log.Debugf("the specconfig is: %+v", specconfig) - // log only core portions s := specconfig log.Debugf("id: %s, name: %s, cpu: %d, mem: %d, parent: %s, os: %s, path: %s", s.ID, s.Name, s.NumCPUs, s.MemoryMB, s.ParentImageID, s.BootMediaPath, s.VMPathName) diff --git a/tests/test-cases/Group11-Upgrade/11-01-Upgrade.robot b/tests/test-cases/Group11-Upgrade/11-01-Upgrade.robot index 5c33032115..a45aef02f5 100644 --- a/tests/test-cases/Group11-Upgrade/11-01-Upgrade.robot +++ b/tests/test-cases/Group11-Upgrade/11-01-Upgrade.robot @@ -103,9 +103,12 @@ Run Docker Checks ${rc} ${output}= Run And Return Rc And Output docker %{VCH-PARAMS} ps -a Should Be Equal As Integers ${rc} 0 Should Not Contain ${output} Exited (0) - ${rc} ${output}= Run And Return Rc And Output govc vm.info *-%{ID1} - Should Be Equal As Integers ${rc} 0 - Should Contain ${output} vch-restart-tes-%{ID1} + ${rc} ${output}= Run Keyword If '%{HOST_TYPE}' == 'VC' Run And Return Rc And Output govc vm.info %{VCH-NAME}/*-%{ID1} + Run Keyword If '%{HOST_TYPE}' == 'VC' Should Be Equal As Integers ${rc} 0 + Run Keyword If '%{HOST_TYPE}' == 'VC' Should contain ${output} vch-restart-tes-%{ID1} + ${rc} ${output}= Run Keyword If '%{HOST_TYPE}' == 'ESXi' Run And Return Rc And Output govc vm.info *-%{ID1} + Run Keyword If '%{HOST_TYPE}' == 'ESXi' Should Be Equal As Integers ${rc} 0 + Run Keyword If '%{HOST_TYPE}' == 'ESXi' Should Contain ${output} vch-restart-tes-%{ID1} ${rc} ${output}= Run And Return Rc And Output govc datastore.ls |grep *-%{ID1} Should Be Equal As Integers ${rc} 0 Should Be Equal ${output} vch-restart-tes-%{ID1} From 8b595bf0a21f5e06c925cf7fb5aa8144ad5f6e72 Mon Sep 17 00:00:00 2001 From: chengwang86 Date: Wed, 15 Mar 2017 18:42:49 -0700 Subject: [PATCH 40/58] update upgrade test --- tests/test-cases/Group11-Upgrade/11-01-Upgrade.robot | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test-cases/Group11-Upgrade/11-01-Upgrade.robot b/tests/test-cases/Group11-Upgrade/11-01-Upgrade.robot index a45aef02f5..7764a7304c 100644 --- a/tests/test-cases/Group11-Upgrade/11-01-Upgrade.robot +++ b/tests/test-cases/Group11-Upgrade/11-01-Upgrade.robot @@ -109,7 +109,7 @@ Run Docker Checks ${rc} ${output}= Run Keyword If '%{HOST_TYPE}' == 'ESXi' Run And Return Rc And Output govc vm.info *-%{ID1} Run Keyword If '%{HOST_TYPE}' == 'ESXi' Should Be Equal As Integers ${rc} 0 Run Keyword If '%{HOST_TYPE}' == 'ESXi' Should Contain ${output} vch-restart-tes-%{ID1} - ${rc} ${output}= Run And Return Rc And Output govc datastore.ls |grep *-%{ID1} + ${rc} ${output}= Run And Return Rc And Output govc datastore.ls -ds %{TEST_DATASTORE} |grep *-%{ID1} Should Be Equal As Integers ${rc} 0 Should Be Equal ${output} vch-restart-tes-%{ID1} From f0491e4cff4f050a546e93955450268e0fb6940e Mon Sep 17 00:00:00 2001 From: chengwang86 Date: Wed, 15 Mar 2017 19:51:39 -0700 Subject: [PATCH 41/58] update test case 11-01 --- tests/test-cases/Group11-Upgrade/11-01-Upgrade.robot | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test-cases/Group11-Upgrade/11-01-Upgrade.robot b/tests/test-cases/Group11-Upgrade/11-01-Upgrade.robot index 7764a7304c..f3016c6028 100644 --- a/tests/test-cases/Group11-Upgrade/11-01-Upgrade.robot +++ b/tests/test-cases/Group11-Upgrade/11-01-Upgrade.robot @@ -109,7 +109,7 @@ Run Docker Checks ${rc} ${output}= Run Keyword If '%{HOST_TYPE}' == 'ESXi' Run And Return Rc And Output govc vm.info *-%{ID1} Run Keyword If '%{HOST_TYPE}' == 'ESXi' Should Be Equal As Integers ${rc} 0 Run Keyword If '%{HOST_TYPE}' == 'ESXi' Should Contain ${output} vch-restart-tes-%{ID1} - ${rc} ${output}= Run And Return Rc And Output govc datastore.ls -ds %{TEST_DATASTORE} |grep *-%{ID1} + ${rc} ${output}= Run And Return Rc And Output govc datastore.ls |grep vch-restart-tes-%{ID1} Should Be Equal As Integers ${rc} 0 Should Be Equal ${output} vch-restart-tes-%{ID1} From e3b186e63f8217e60948a234b479f7eee9282c13 Mon Sep 17 00:00:00 2001 From: chengwang86 Date: Thu, 16 Mar 2017 13:48:30 -0700 Subject: [PATCH 42/58] cosmetic change --- cmd/vicadmin/vicadm.go | 4 +++- lib/portlayer/exec/handle.go | 8 +++++++- lib/portlayer/logging/logging.go | 10 +++++++--- lib/vicadmin/validate.go | 4 ++-- 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/cmd/vicadmin/vicadm.go b/cmd/vicadmin/vicadm.go index 1d1e9ab407..f010f3bc22 100644 --- a/cmd/vicadmin/vicadm.go +++ b/cmd/vicadmin/vicadm.go @@ -53,6 +53,8 @@ import ( ) const ( + containerIdInExtraConfig = "guestinfo.vice./common/id" + timeout = time.Duration(2 * time.Second) ) @@ -337,7 +339,7 @@ func listVMPaths(ctx context.Context, s *session.Session) ([]logfile, error) { } else { // for the appliance VM, id is in guestinfo.vice./init/common/id; // however, this is not problematic since we don't collect these logs for the appliance VM - logname = ec["guestinfo.vice./common/id"] + logname = ec[containerIdInExtraConfig] if logname == "" { log.Infof("Skipping collection for appliance VM") continue diff --git a/lib/portlayer/exec/handle.go b/lib/portlayer/exec/handle.go index b67efbeb9f..5757dd99a1 100644 --- a/lib/portlayer/exec/handle.go +++ b/lib/portlayer/exec/handle.go @@ -291,8 +291,14 @@ func Create(ctx context.Context, vmomiSession *session.Session, config *Containe Metadata: config.Metadata, } + dsType, err := sess.Datastore.Type(ctx) + if err != nil { + log.Errorf("Failed to check datastore type during create of %s: %s", config.Metadata.ID, err) + return nil, err + } + // if not vsan, set the datastore folder name to containerID - if dsType, _ := sess.Datastore.Type(ctx); dsType != types.HostFileSystemVolumeFileSystemTypeVsan { + if dsType != types.HostFileSystemVolumeFileSystemTypeVsan { specconfig.VMPathName = fmt.Sprintf("[%s] %s/%s.vmx", sess.Datastore.Name(), specconfig.ID, specconfig.ID) } diff --git a/lib/portlayer/logging/logging.go b/lib/portlayer/logging/logging.go index 77c0bddea9..1e5c982f5f 100644 --- a/lib/portlayer/logging/logging.go +++ b/lib/portlayer/logging/logging.go @@ -142,10 +142,14 @@ func Join(h interface{}) (interface{}, error) { VMID := handle.Spec.ID() dsName := handle.Spec.Datastore.Name() - if dsType, _ := handle.Spec.Datastore.Type(context.Background()); dsType == types.HostFileSystemVolumeFileSystemTypeVsan { + dsType, err := handle.Spec.Datastore.Type(context.Background()) + if err != nil { + return nil, fmt.Errorf("failed to check datastore type for %s: %s", VMID, err) + } + + logFilePath = fmt.Sprintf("[%s] %s", dsName, VMID) + if dsType == types.HostFileSystemVolumeFileSystemTypeVsan { logFilePath = fmt.Sprintf("%s/%s", VMPathName, VMName) - } else { - logFilePath = fmt.Sprintf("[%s] %s", dsName, VMID) } for _, logFile := range []string{"tether.debug", "output.log"} { diff --git a/lib/vicadmin/validate.go b/lib/vicadmin/validate.go index 0c7b3f4f1f..9ccde06b6f 100644 --- a/lib/vicadmin/validate.go +++ b/lib/vicadmin/validate.go @@ -222,8 +222,8 @@ func VCHName(ctx context.Context, sess *session.Session) string { return DefaultVCHName } - self2 := vm.NewVirtualMachineFromVM(ctx, sess, self) - vchName, err := self2.Name(ctx) + newVM := vm.NewVirtualMachineFromVM(ctx, sess, self) + vchName, err := newVM.Name(ctx) if err != nil { log.Errorf("Unable to get VCH name: %s", err) log.Infof("Setting the VCH name to VCH") From e395ab6ed786129ac5d21bfd7d3aec6e0f203a9b Mon Sep 17 00:00:00 2001 From: chengwang86 Date: Thu, 16 Mar 2017 14:00:53 -0700 Subject: [PATCH 43/58] correct typo --- cmd/vicadmin/vicadm.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/cmd/vicadmin/vicadm.go b/cmd/vicadmin/vicadm.go index f010f3bc22..dec5631c82 100644 --- a/cmd/vicadmin/vicadm.go +++ b/cmd/vicadmin/vicadm.go @@ -53,9 +53,8 @@ import ( ) const ( - containerIdInExtraConfig = "guestinfo.vice./common/id" - - timeout = time.Duration(2 * time.Second) + containerIDInExtraConfig = "guestinfo.vice./common/id" + timeout = time.Duration(2 * time.Second) ) type serverCertificate struct { @@ -187,7 +186,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 } @@ -339,7 +338,7 @@ func listVMPaths(ctx context.Context, s *session.Session) ([]logfile, error) { } else { // for the appliance VM, id is in guestinfo.vice./init/common/id; // however, this is not problematic since we don't collect these logs for the appliance VM - logname = ec[containerIdInExtraConfig] + logname = ec[containerIDInExtraConfig] if logname == "" { log.Infof("Skipping collection for appliance VM") continue From e27d6009d5b46cfd01fb5c8aaa5076ae22ade235 Mon Sep 17 00:00:00 2001 From: chengwang86 Date: Wed, 22 Mar 2017 07:29:21 -0700 Subject: [PATCH 44/58] - set log bundle name of containerVMs to the display name - update test cases with checking for datastore_type --- cmd/vicadmin/vicadm.go | 24 ++++--------------- lib/install/management/delete.go | 6 ++--- pkg/version/plugin2/commonSpecForVCH.go | 1 - pkg/version/plugin3/commonSpecForContainer.go | 1 - tests/resources/Docker-Util.robot | 3 ++- tests/resources/VCH-Util.robot | 10 ++++++-- .../1-04-Docker-Create.robot | 12 ++++++---- .../1-07-Docker-Stop.robot | 6 +++-- .../1-10-Docker-PS.robot | 6 +++-- .../Group11-Upgrade/11-01-Upgrade.md | 2 ++ .../Group11-Upgrade/11-01-Upgrade.robot | 20 +++++++++++++++- 11 files changed, 53 insertions(+), 38 deletions(-) diff --git a/cmd/vicadmin/vicadm.go b/cmd/vicadmin/vicadm.go index dec5631c82..893b002d9f 100644 --- a/cmd/vicadmin/vicadm.go +++ b/cmd/vicadmin/vicadm.go @@ -53,8 +53,7 @@ import ( ) const ( - containerIDInExtraConfig = "guestinfo.vice./common/id" - timeout = time.Duration(2 * time.Second) + timeout = time.Duration(2 * time.Second) ) type serverCertificate struct { @@ -315,7 +314,6 @@ func listVMPaths(ctx context.Context, s *session.Session) ([]logfile, error) { log.Infof("Found %d candidate VMs in resource pool %s for log collection", len(children), ref.String()) - var logname string logfiles := []logfile{} for _, child := range children { path, err := child.DSPath(ctx) @@ -326,25 +324,11 @@ func listVMPaths(ctx context.Context, s *session.Session) ([]logfile, error) { continue } - ec, err := child.FetchExtraConfig(ctx) + logname, err := child.Name(ctx) if err != nil { - log.Errorf("Unable to fetch the vm ExtraConfig for %s: %s", child.Reference(), err) - - logname, err = child.Name(ctx) - if err != nil { - log.Errorf("Unable to get the vm name for %s: %s", child.Reference(), err) - continue - } - } else { - // for the appliance VM, id is in guestinfo.vice./init/common/id; - // however, this is not problematic since we don't collect these logs for the appliance VM - logname = ec[containerIDInExtraConfig] - if logname == "" { - log.Infof("Skipping collection for appliance VM") - continue - } + log.Errorf("Unable to get the vm name for %s: %s", child.Reference(), err) + continue } - log.Infof("Setting logname to %s", logname) if self != nil && child.Reference().String() == self.Reference().String() { // FIXME: until #2630 is addressed, and we confirm this filters secrets from appliance vmware.log as well, diff --git a/lib/install/management/delete.go b/lib/install/management/delete.go index 1978eddb14..cc3430ba6d 100644 --- a/lib/install/management/delete.go +++ b/lib/install/management/delete.go @@ -173,13 +173,13 @@ func (d *Dispatcher) DeleteVCHInstances(vmm *vm.VirtualMachine, conf *config.Vir for _, child := range children { //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 ok { - continue - } if err != nil { errs = append(errs, err.Error()) continue } + if ok { + continue + } if err = d.deleteVM(child, d.force); err != nil { errs = append(errs, err.Error()) diff --git a/pkg/version/plugin2/commonSpecForVCH.go b/pkg/version/plugin2/commonSpecForVCH.go index 734467d1fa..b5449c65cd 100644 --- a/pkg/version/plugin2/commonSpecForVCH.go +++ b/pkg/version/plugin2/commonSpecForVCH.go @@ -118,7 +118,6 @@ func (p *AddCommonSpecForVCH) Migrate(ctx context.Context, s *session.Session, d cfg := make(map[string]string) extraconfig.Encode(extraconfig.MapSink(cfg), newStruct) - log.Debugf("The newStruct is %+v", newStruct) for k, v := range cfg { log.Debugf("New data: %s:%s", k, v) diff --git a/pkg/version/plugin3/commonSpecForContainer.go b/pkg/version/plugin3/commonSpecForContainer.go index 2c09d9310e..1e5374d3db 100644 --- a/pkg/version/plugin3/commonSpecForContainer.go +++ b/pkg/version/plugin3/commonSpecForContainer.go @@ -107,7 +107,6 @@ func (p *AddCommonSpecForContainer) Migrate(ctx context.Context, s *session.Sess cfg := make(map[string]string) extraconfig.Encode(extraconfig.MapSink(cfg), newStruct) - log.Debugf("The newStruct is %+v", newStruct) for k, v := range cfg { log.Debugf("New data: %s:%s", k, v) diff --git a/tests/resources/Docker-Util.robot b/tests/resources/Docker-Util.robot index dcead333ce..76caac6bf9 100644 --- a/tests/resources/Docker-Util.robot +++ b/tests/resources/Docker-Util.robot @@ -88,7 +88,8 @@ Run Regression Tests Should Be Equal As Integers ${rc} 0 Should Contain ${output} Exited - Wait Until Keyword Succeeds 5x 10s Check For The Proper Log Files ${container} + ${vmName}= Get VM Display Name ${container} + Wait Until Keyword Succeeds 5x 10s Check For The Proper Log Files ${vmName} ${rc} ${output}= Run And Return Rc And Output docker %{VCH-PARAMS} rm ${container} Should Be Equal As Integers ${rc} 0 diff --git a/tests/resources/VCH-Util.robot b/tests/resources/VCH-Util.robot index 80e87d0029..d33393d3bf 100644 --- a/tests/resources/VCH-Util.robot +++ b/tests/resources/VCH-Util.robot @@ -51,6 +51,11 @@ Set Test Environment Variables Run Keyword If ${status} Set Environment Variable HOST_TYPE ESXi Run Keyword Unless ${status} Set Environment Variable HOST_TYPE VC + ${about}= Run govc datastore.info %{TEST_DATASTORE} |grep 'Type' + ${status}= Run Keyword And Return Status Should Contain ${about} vsan + Run Keyword If ${status} Set Environment Variable DATASTORE_TYPE VSAN + Run Keyword Unless ${status} Set Environment Variable DATASTORE_TYPE Non_VSAN + # set the TLS config options suitable for vic-machine in this env ${domain}= Get Environment Variable DOMAIN '' Run Keyword If $domain == '' Set Suite Variable ${vicmachinetls} --no-tlsverify @@ -146,6 +151,7 @@ Install VIC Appliance To Test Server Run VIC Machine Command [Tags] secret [Arguments] ${vic-machine} ${appliance-iso} ${bootstrap-iso} ${certs} ${vol} + Log To Console ${vic-machine} create --debug 1 --name=%{VCH-NAME} --target=%{TEST_URL}%{TEST_DATACENTER} --thumbprint=%{TEST_THUMBPRINT} --user=%{TEST_USERNAME} --image-store=%{TEST_DATASTORE} --appliance-iso=${appliance-iso} --bootstrap-iso=${bootstrap-iso} --password=%{TEST_PASSWORD} --force=true --bridge-network=%{BRIDGE_NETWORK} --public-network=%{PUBLIC_NETWORK} --compute-resource=%{TEST_RESOURCE} --timeout %{TEST_TIMEOUT} --volume-store=%{TEST_DATASTORE}/test:${vol} ${vicmachinetls} ${output}= Run Keyword If ${certs} Run ${vic-machine} create --debug 1 --name=%{VCH-NAME} --target=%{TEST_URL}%{TEST_DATACENTER} --thumbprint=%{TEST_THUMBPRINT} --user=%{TEST_USERNAME} --image-store=%{TEST_DATASTORE} --appliance-iso=${appliance-iso} --bootstrap-iso=${bootstrap-iso} --password=%{TEST_PASSWORD} --force=true --bridge-network=%{BRIDGE_NETWORK} --public-network=%{PUBLIC_NETWORK} --compute-resource=%{TEST_RESOURCE} --timeout %{TEST_TIMEOUT} --volume-store=%{TEST_DATASTORE}/test:${vol} ${vicmachinetls} Run Keyword If ${certs} Should Contain ${output} Installer completed successfully Return From Keyword If ${certs} ${output} @@ -157,7 +163,7 @@ Run VIC Machine Command Run Secret VIC Machine Delete Command [Tags] secret [Arguments] ${vch-name} - ${rc} ${output}= Run And Return Rc And Output bin/vic-machine-linux delete --name=${vch-name} --target=%{TEST_URL}%{TEST_DATACENTER} --user=%{TEST_USERNAME} --password=%{TEST_PASSWORD} --force=true --compute-resource=%{TEST_RESOURCE} --timeout %{TEST_TIMEOUT} + ${rc} ${output}= Run And Return Rc And Output bin/vic-machine-linux delete --force --name=${vch-name} --target=%{TEST_URL}%{TEST_DATACENTER} --user=%{TEST_USERNAME} --password=%{TEST_PASSWORD} --force=true --compute-resource=%{TEST_RESOURCE} --timeout %{TEST_TIMEOUT} [Return] ${rc} ${output} Run Secret VIC Machine Inspect Command @@ -179,7 +185,7 @@ Run VIC Machine Inspect Command Get Docker Params ${output} ${true} Gather Logs From Test Server - [Tags] secret + #[Tags] secret ${out}= Run curl -k -D vic-admin-cookies -Fusername=%{TEST_USERNAME} -Fpassword=%{TEST_PASSWORD} %{VIC-ADMIN}/authentication Log ${out} ${out}= Run curl -k -b vic-admin-cookies %{VIC-ADMIN}/container-logs.zip -o ${SUITE NAME}-%{VCH-NAME}-container-logs.zip diff --git a/tests/test-cases/Group1-Docker-Commands/1-04-Docker-Create.robot b/tests/test-cases/Group1-Docker-Commands/1-04-Docker-Create.robot index 7b3cdc50e5..17a4c759ea 100644 --- a/tests/test-cases/Group1-Docker-Commands/1-04-Docker-Create.robot +++ b/tests/test-cases/Group1-Docker-Commands/1-04-Docker-Create.robot @@ -184,11 +184,13 @@ Create a container and check the VM display name and datastore folder name ${rc} ${output}= Run Keyword If '%{HOST_TYPE}' == 'VC' Run And Return Rc And Output govc vm.info %{VCH-NAME}/${vmName} Run Keyword If '%{HOST_TYPE}' == 'VC' Should Be Equal As Integers ${rc} 0 Run Keyword If '%{HOST_TYPE}' == 'VC' Should contain ${output} ${vmName} - ${rc} ${output}= Run Keyword If '%{HOST_TYPE}' == 'ESXi' Run And Return Rc And Output govc vm.info ${vmname} + ${rc} ${output}= Run Keyword If '%{HOST_TYPE}' == 'ESXi' Run And Return Rc And Output govc vm.info ${vmName} Run Keyword If '%{HOST_TYPE}' == 'ESXi' Should Be Equal As Integers ${rc} 0 Run Keyword If '%{HOST_TYPE}' == 'ESXi' Should Contain ${output} ${vmName} - # For non-vSAN setup, the datastore folder name should be containerID; however, for vSAN setup, the datastore folder name should be containerName-containerShortID - ${rc} ${output}= Run And Return Rc And Output govc datastore.ls |grep ${id} - Should Be Equal As Integers ${rc} 0 - Should Be Equal ${output} ${id} + ${rc} ${output}= Run Keyword If '%{DATASTORE_TYPE}' == 'VSAN' Run And Return Rc And Output govc datastore.ls |grep ${vmName} + Run Keyword If '%{DATASTORE_TYPE}' == 'VSAN' Should Be Equal As Integers ${rc} 0 + Run Keyword If '%{DATASTORE_TYPE}' == 'VSAN' Should contain ${output} ${vmName} + ${rc} ${output}= Run Keyword If '%{DATASTORE_TYPE}' == 'Non_VSAN' Run And Return Rc And Output govc datastore.ls |grep ${id} + Run Keyword If '%{DATASTORE_TYPE}' == 'Non_VSAN' Should Be Equal As Integers ${rc} 0 + Run Keyword If '%{DATASTORE_TYPE}' == 'Non_VSAN' Should Contain ${output} ${id} \ No newline at end of file diff --git a/tests/test-cases/Group1-Docker-Commands/1-07-Docker-Stop.robot b/tests/test-cases/Group1-Docker-Commands/1-07-Docker-Stop.robot index d3b9904251..c24bbafb87 100644 --- a/tests/test-cases/Group1-Docker-Commands/1-07-Docker-Stop.robot +++ b/tests/test-cases/Group1-Docker-Commands/1-07-Docker-Stop.robot @@ -48,8 +48,10 @@ Assert Kill Signal ${rc} ${output}= Run Keyword If '%{HOST_TYPE}' == 'ESXi' Run And Return Rc And Output govc vm.info -json ${vmName} | jq -r .VirtualMachines[].Runtime.PowerState Run Keyword If '%{HOST_TYPE}' == 'ESXi' Should Be Equal As Integers ${rc} 0 Run Keyword If '%{HOST_TYPE}' == 'ESXi' Should Be Equal ${output} poweredOff - ${rc} ${dir}= Run And Return Rc And Output govc datastore.ls ${id}* - Should Be Equal As Integers ${rc} 0 + ${rc} ${dir}= Run Keyword If '%{DATASTORE_TYPE}' == 'VSAN' Run And Return Rc And Output govc datastore.ls ${vmName}* + Run Keyword If '%{DATASTORE_TYPE}' == 'VSAN' Should Be Equal As Integers ${rc} 0 + ${rc} ${dir}= Run Keyword If '%{DATASTORE_TYPE}' == 'Non_VSAN' Run And Return Rc And Output govc datastore.ls ${id}* + Run Keyword If '%{DATASTORE_TYPE}' == 'Non_VSAN' Should Be Equal As Integers ${rc} 0 ${rc} ${output}= Run And Return Rc And Output govc datastore.download ${dir}/tether.debug - Should Be Equal As Integers ${rc} 0 Run Keyword If ${expect} Should Contain ${output} sending signal KILL diff --git a/tests/test-cases/Group1-Docker-Commands/1-10-Docker-PS.robot b/tests/test-cases/Group1-Docker-Commands/1-10-Docker-PS.robot index ee0a21d61a..e53b095545 100644 --- a/tests/test-cases/Group1-Docker-Commands/1-10-Docker-PS.robot +++ b/tests/test-cases/Group1-Docker-Commands/1-10-Docker-PS.robot @@ -149,8 +149,10 @@ Docker ps Remove container OOB Run Keyword If '%{HOST_TYPE}' == 'ESXi' Should Be Equal As Integers ${rc} 0 Wait Until VM Is Destroyed "lolo*" Wait Until Keyword Succeeds 10x 6s Assert Number Of Containers ${len-1} -aq - ${rc} ${output}= Run And Return Rc And Output govc datastore.ls | grep ${container} | xargs -n1 govc datastore.rm - Should Be Equal As Integers ${rc} 0 + ${rc} ${output}= Run Keyword If '%{DATASTORE_TYPE}' == 'VSAN' Run And Return Rc And Output govc datastore.ls | grep "lolo*" | xargs -n1 govc datastore.rm + Run Keyword If '%{DATASTORE_TYPE}' == 'VSAN' Should Be Equal As Integers ${rc} 0 + ${rc} ${output}= Run Keyword If '%{DATASTORE_TYPE}' == 'Non_VSAN' Run And Return Rc And Output govc datastore.ls | grep ${container} | xargs -n1 govc datastore.rm + Run Keyword If '%{DATASTORE_TYPE}' == 'Non_VSAN' Should Be Equal As Integers ${rc} 0 Docker ps last container ${rc} ${output}= Run And Return Rc And Output docker %{VCH-PARAMS} ps -l diff --git a/tests/test-cases/Group11-Upgrade/11-01-Upgrade.md b/tests/test-cases/Group11-Upgrade/11-01-Upgrade.md index a1be680dcc..edc63be2e4 100644 --- a/tests/test-cases/Group11-Upgrade/11-01-Upgrade.md +++ b/tests/test-cases/Group11-Upgrade/11-01-Upgrade.md @@ -18,10 +18,12 @@ This test requires that a vSphere server is running and available 8. Upgrade again to the upgraded version 9. Check the previous created container and image are still there 10. Check the previous created container's display name and datastore folder name +11. Check the display name and datastore folder name of a new container created after VCH upgrade #Expected Outcome: * Step 5 should fail with timeout * Step 10 should show that both the container's display name and datastore folder name are containerName-containerID +* Step 11 should show that (1) on a non-vsan setup, the container's display name is containerName-containerShortID while the datastore folder name is containerID, or (2) on a vsan setup, both the container's display name and datastore folder name are containerName-containerShortID * All other steps should result in success #Possible Problems: diff --git a/tests/test-cases/Group11-Upgrade/11-01-Upgrade.robot b/tests/test-cases/Group11-Upgrade/11-01-Upgrade.robot index f3016c6028..1bea09f9d0 100644 --- a/tests/test-cases/Group11-Upgrade/11-01-Upgrade.robot +++ b/tests/test-cases/Group11-Upgrade/11-01-Upgrade.robot @@ -29,6 +29,7 @@ Install VIC with version to Test Server Install VIC Appliance To Test Server vic-machine=./vic/vic-machine-linux appliance-iso=./vic/appliance.iso bootstrap-iso=./vic/bootstrap.iso certs=${false} Set Environment Variable VIC-ADMIN %{VCH-IP}:2378 Set Environment Variable INITIAL-VERSION ${version} + Set Environment Variable DOCKER_API_VERSION 1.23 Clean up VIC Appliance And Local Binary Cleanup VIC Appliance On Test Server @@ -103,6 +104,8 @@ Run Docker Checks ${rc} ${output}= Run And Return Rc And Output docker %{VCH-PARAMS} ps -a Should Be Equal As Integers ${rc} 0 Should Not Contain ${output} Exited (0) + + # check the display name and datastore folder name of an existing container ${rc} ${output}= Run Keyword If '%{HOST_TYPE}' == 'VC' Run And Return Rc And Output govc vm.info %{VCH-NAME}/*-%{ID1} Run Keyword If '%{HOST_TYPE}' == 'VC' Should Be Equal As Integers ${rc} 0 Run Keyword If '%{HOST_TYPE}' == 'VC' Should contain ${output} vch-restart-tes-%{ID1} @@ -113,6 +116,21 @@ Run Docker Checks Should Be Equal As Integers ${rc} 0 Should Be Equal ${output} vch-restart-tes-%{ID1} + # check the display name and datastore folder name of a new container + ${rc} ${id}= Run And Return Rc And Output docker %{VCH-PARAMS} run -d busybox /bin/top + Should Be Equal As Integers ${rc} 0 + ${vmName}= Get VM Display Name ${id} + ${rc} ${output}= Run Keyword If '%{HOST_TYPE}' == 'VC' Run And Return Rc And Output govc vm.info %{VCH-NAME}/${vmName} + Run Keyword If '%{HOST_TYPE}' == 'VC' Should Be Equal As Integers ${rc} 0 + Run Keyword If '%{HOST_TYPE}' == 'VC' Should contain ${output} ${vmName} + ${rc} ${output}= Run Keyword If '%{HOST_TYPE}' == 'ESXi' Run And Return Rc And Output govc vm.info ${vmName} + Run Keyword If '%{HOST_TYPE}' == 'ESXi' Should Be Equal As Integers ${rc} 0 + Run Keyword If '%{HOST_TYPE}' == 'ESXi' Should Contain ${output} ${vmName} + ${rc} ${output}= Run And Return Rc And Output govc datastore.ls |grep ${vmName} + Should Be Equal As Integers ${rc} 0 + Should Be Equal ${output} ${vmName} + + Wait Until Keyword Succeeds 20x 5 seconds Hit Nginx Endpoint %{VCH-IP} 10000 Wait Until Keyword Succeeds 20x 5 seconds Hit Nginx Endpoint %{VCH-IP} 10001 @@ -164,7 +182,7 @@ Upgrade VCH with unreasonably short timeout and automatic rollback after failure Run Keyword If '%{HOST_TYPE}' == 'ESXi' Should Not Contain ${output} upgrade Upgrade VCH - + Set Environment Variable DOCKER_API_VERSION 1.23 Create Docker Containers Log To Console \nUpgrading VCH... From b2790bb84e00a8ea485f8d61dc604cc5e189345f Mon Sep 17 00:00:00 2001 From: chengwang86 Date: Wed, 22 Mar 2017 07:46:50 -0700 Subject: [PATCH 45/58] correct errors in test cases --- tests/resources/VCH-Util.robot | 5 ++--- tests/test-cases/Group11-Upgrade/11-01-Upgrade.robot | 12 ++++++------ 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/tests/resources/VCH-Util.robot b/tests/resources/VCH-Util.robot index d33393d3bf..849481ac49 100644 --- a/tests/resources/VCH-Util.robot +++ b/tests/resources/VCH-Util.robot @@ -151,7 +151,6 @@ Install VIC Appliance To Test Server Run VIC Machine Command [Tags] secret [Arguments] ${vic-machine} ${appliance-iso} ${bootstrap-iso} ${certs} ${vol} - Log To Console ${vic-machine} create --debug 1 --name=%{VCH-NAME} --target=%{TEST_URL}%{TEST_DATACENTER} --thumbprint=%{TEST_THUMBPRINT} --user=%{TEST_USERNAME} --image-store=%{TEST_DATASTORE} --appliance-iso=${appliance-iso} --bootstrap-iso=${bootstrap-iso} --password=%{TEST_PASSWORD} --force=true --bridge-network=%{BRIDGE_NETWORK} --public-network=%{PUBLIC_NETWORK} --compute-resource=%{TEST_RESOURCE} --timeout %{TEST_TIMEOUT} --volume-store=%{TEST_DATASTORE}/test:${vol} ${vicmachinetls} ${output}= Run Keyword If ${certs} Run ${vic-machine} create --debug 1 --name=%{VCH-NAME} --target=%{TEST_URL}%{TEST_DATACENTER} --thumbprint=%{TEST_THUMBPRINT} --user=%{TEST_USERNAME} --image-store=%{TEST_DATASTORE} --appliance-iso=${appliance-iso} --bootstrap-iso=${bootstrap-iso} --password=%{TEST_PASSWORD} --force=true --bridge-network=%{BRIDGE_NETWORK} --public-network=%{PUBLIC_NETWORK} --compute-resource=%{TEST_RESOURCE} --timeout %{TEST_TIMEOUT} --volume-store=%{TEST_DATASTORE}/test:${vol} ${vicmachinetls} Run Keyword If ${certs} Should Contain ${output} Installer completed successfully Return From Keyword If ${certs} ${output} @@ -163,7 +162,7 @@ Run VIC Machine Command Run Secret VIC Machine Delete Command [Tags] secret [Arguments] ${vch-name} - ${rc} ${output}= Run And Return Rc And Output bin/vic-machine-linux delete --force --name=${vch-name} --target=%{TEST_URL}%{TEST_DATACENTER} --user=%{TEST_USERNAME} --password=%{TEST_PASSWORD} --force=true --compute-resource=%{TEST_RESOURCE} --timeout %{TEST_TIMEOUT} + ${rc} ${output}= Run And Return Rc And Output bin/vic-machine-linux delete --name=${vch-name} --target=%{TEST_URL}%{TEST_DATACENTER} --user=%{TEST_USERNAME} --password=%{TEST_PASSWORD} --force=true --compute-resource=%{TEST_RESOURCE} --timeout %{TEST_TIMEOUT} [Return] ${rc} ${output} Run Secret VIC Machine Inspect Command @@ -185,7 +184,7 @@ Run VIC Machine Inspect Command Get Docker Params ${output} ${true} Gather Logs From Test Server - #[Tags] secret + [Tags] secret ${out}= Run curl -k -D vic-admin-cookies -Fusername=%{TEST_USERNAME} -Fpassword=%{TEST_PASSWORD} %{VIC-ADMIN}/authentication Log ${out} ${out}= Run curl -k -b vic-admin-cookies %{VIC-ADMIN}/container-logs.zip -o ${SUITE NAME}-%{VCH-NAME}-container-logs.zip diff --git a/tests/test-cases/Group11-Upgrade/11-01-Upgrade.robot b/tests/test-cases/Group11-Upgrade/11-01-Upgrade.robot index 1bea09f9d0..7dd2cbf9de 100644 --- a/tests/test-cases/Group11-Upgrade/11-01-Upgrade.robot +++ b/tests/test-cases/Group11-Upgrade/11-01-Upgrade.robot @@ -29,7 +29,6 @@ Install VIC with version to Test Server Install VIC Appliance To Test Server vic-machine=./vic/vic-machine-linux appliance-iso=./vic/appliance.iso bootstrap-iso=./vic/bootstrap.iso certs=${false} Set Environment Variable VIC-ADMIN %{VCH-IP}:2378 Set Environment Variable INITIAL-VERSION ${version} - Set Environment Variable DOCKER_API_VERSION 1.23 Clean up VIC Appliance And Local Binary Cleanup VIC Appliance On Test Server @@ -126,10 +125,12 @@ Run Docker Checks ${rc} ${output}= Run Keyword If '%{HOST_TYPE}' == 'ESXi' Run And Return Rc And Output govc vm.info ${vmName} Run Keyword If '%{HOST_TYPE}' == 'ESXi' Should Be Equal As Integers ${rc} 0 Run Keyword If '%{HOST_TYPE}' == 'ESXi' Should Contain ${output} ${vmName} - ${rc} ${output}= Run And Return Rc And Output govc datastore.ls |grep ${vmName} - Should Be Equal As Integers ${rc} 0 - Should Be Equal ${output} ${vmName} - + ${rc} ${output}= Run Keyword If '%{DATASTORE_TYPE}' == 'VSAN' Run And Return Rc And Output govc datastore.ls |grep ${vmName} + Run Keyword If '%{DATASTORE_TYPE}' == 'VSAN' Should Be Equal As Integers ${rc} 0 + Run Keyword If '%{DATASTORE_TYPE}' == 'VSAN' Should contain ${output} ${vmName} + ${rc} ${output}= Run Keyword If '%{DATASTORE_TYPE}' == 'Non_VSAN' Run And Return Rc And Output govc datastore.ls |grep ${id} + Run Keyword If '%{DATASTORE_TYPE}' == 'Non_VSAN' Should Be Equal As Integers ${rc} 0 + Run Keyword If '%{DATASTORE_TYPE}' == 'Non_VSAN' Should Contain ${output} ${id} Wait Until Keyword Succeeds 20x 5 seconds Hit Nginx Endpoint %{VCH-IP} 10000 Wait Until Keyword Succeeds 20x 5 seconds Hit Nginx Endpoint %{VCH-IP} 10001 @@ -182,7 +183,6 @@ Upgrade VCH with unreasonably short timeout and automatic rollback after failure Run Keyword If '%{HOST_TYPE}' == 'ESXi' Should Not Contain ${output} upgrade Upgrade VCH - Set Environment Variable DOCKER_API_VERSION 1.23 Create Docker Containers Log To Console \nUpgrading VCH... From 661680586db8bd13cec0093cc2bbcd04b6e92aab Mon Sep 17 00:00:00 2001 From: chengwang86 Date: Wed, 22 Mar 2017 08:09:16 -0700 Subject: [PATCH 46/58] update code repo --- lib/portlayer/exec/handle.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/portlayer/exec/handle.go b/lib/portlayer/exec/handle.go index 5757dd99a1..727218d303 100644 --- a/lib/portlayer/exec/handle.go +++ b/lib/portlayer/exec/handle.go @@ -291,7 +291,7 @@ func Create(ctx context.Context, vmomiSession *session.Session, config *Containe Metadata: config.Metadata, } - dsType, err := sess.Datastore.Type(ctx) + dsType, err := vmomiSession.Datastore.Type(ctx) if err != nil { log.Errorf("Failed to check datastore type during create of %s: %s", config.Metadata.ID, err) return nil, err @@ -299,7 +299,7 @@ func Create(ctx context.Context, vmomiSession *session.Session, config *Containe // if not vsan, set the datastore folder name to containerID if dsType != types.HostFileSystemVolumeFileSystemTypeVsan { - specconfig.VMPathName = fmt.Sprintf("[%s] %s/%s.vmx", sess.Datastore.Name(), specconfig.ID, specconfig.ID) + specconfig.VMPathName = fmt.Sprintf("[%s] %s/%s.vmx", vmomiSession.Datastore.Name(), specconfig.ID, specconfig.ID) } specconfig.VMFullName = util.DisplayName(specconfig.ID, specconfig.Name) From bc7f5449cba6f992d8a7368ac333e7a688f86f73 Mon Sep 17 00:00:00 2001 From: chengwang86 Date: Wed, 22 Mar 2017 08:59:11 -0700 Subject: [PATCH 47/58] use session.isVSAN() to check whether it is a vsan setup --- lib/portlayer/exec/handle.go | 8 +------- lib/portlayer/logging/logging.go | 13 ++++++++----- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/lib/portlayer/exec/handle.go b/lib/portlayer/exec/handle.go index 727218d303..1bca2f208a 100644 --- a/lib/portlayer/exec/handle.go +++ b/lib/portlayer/exec/handle.go @@ -291,14 +291,8 @@ func Create(ctx context.Context, vmomiSession *session.Session, config *Containe Metadata: config.Metadata, } - dsType, err := vmomiSession.Datastore.Type(ctx) - if err != nil { - log.Errorf("Failed to check datastore type during create of %s: %s", config.Metadata.ID, err) - return nil, err - } - // if not vsan, set the datastore folder name to containerID - if dsType != types.HostFileSystemVolumeFileSystemTypeVsan { + if !vmomiSession.IsVSAN(ctx) { specconfig.VMPathName = fmt.Sprintf("[%s] %s/%s.vmx", vmomiSession.Datastore.Name(), specconfig.ID, specconfig.ID) } diff --git a/lib/portlayer/logging/logging.go b/lib/portlayer/logging/logging.go index 1e5c982f5f..46a6682049 100644 --- a/lib/portlayer/logging/logging.go +++ b/lib/portlayer/logging/logging.go @@ -142,13 +142,16 @@ func Join(h interface{}) (interface{}, error) { VMID := handle.Spec.ID() dsName := handle.Spec.Datastore.Name() - dsType, err := handle.Spec.Datastore.Type(context.Background()) - if err != nil { - return nil, fmt.Errorf("failed to check datastore type for %s: %s", VMID, err) - } + //dsType, err := handle.Spec.Datastore.Type(context.Background()) + //if err != nil { + // return nil, fmt.Errorf("failed to check datastore type for %s: %s", VMID, err) + //} logFilePath = fmt.Sprintf("[%s] %s", dsName, VMID) - if dsType == types.HostFileSystemVolumeFileSystemTypeVsan { + //if dsType == types.HostFileSystemVolumeFileSystemTypeVsan { + // logFilePath = fmt.Sprintf("%s/%s", VMPathName, VMName) + //} + if handle.Spec.Session.IsVSAN(context.Background()) { logFilePath = fmt.Sprintf("%s/%s", VMPathName, VMName) } From df19841c55bc5772bee5a918dac70d225d923258 Mon Sep 17 00:00:00 2001 From: chengwang86 Date: Wed, 22 Mar 2017 09:26:04 -0700 Subject: [PATCH 48/58] update exec_test.go --- lib/tether/exec_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/tether/exec_test.go b/lib/tether/exec_test.go index baf9a76047..415af1a68c 100644 --- a/lib/tether/exec_test.go +++ b/lib/tether/exec_test.go @@ -42,7 +42,7 @@ func TestExec(t *testing.T) { defer os.RemoveAll(flagFile) cfg := executor.ExecutorConfig{ - Common: executor.Common{ + ExecutorConfigCommon: executor.ExecutorConfigCommon{ ID: "primary", Name: "tether_test_executor", }, @@ -127,7 +127,7 @@ func TestMissingBinaryNonFatal(t *testing.T) { defer os.RemoveAll(flagFile) cfg := executor.ExecutorConfig{ - Common: executor.Common{ + ExecutorConfigCommon: executor.ExecutorConfigCommon{ ID: "primary", Name: "tether_test_executor", }, @@ -260,7 +260,7 @@ func TestExecHalt(t *testing.T) { defer os.RemoveAll(flagFile) cfg := executor.ExecutorConfig{ - Common: executor.Common{ + ExecutorConfigCommon: executor.ExecutorConfigCommon{ ID: "primary", Name: "tether_test_executor", }, From 3370e0e45bd94a10599f2a47df45dcbcd2edcce3 Mon Sep 17 00:00:00 2001 From: chengwang86 Date: Wed, 22 Mar 2017 10:32:41 -0700 Subject: [PATCH 49/58] cosmetic changees --- lib/vicadmin/validate.go | 1 + tests/resources/VCH-Util.robot | 2 +- .../Group1-Docker-Commands/1-04-Docker-Create.robot | 4 ++-- tests/test-cases/Group11-Upgrade/11-01-Upgrade.robot | 6 +++--- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/vicadmin/validate.go b/lib/vicadmin/validate.go index 9ccde06b6f..5e013ec8f2 100644 --- a/lib/vicadmin/validate.go +++ b/lib/vicadmin/validate.go @@ -212,6 +212,7 @@ func NewValidator(ctx context.Context, vch *config.VirtualContainerHostConfigSpe return v } +// Obtain the VCH name from vsphere func VCHName(ctx context.Context, sess *session.Session) string { defer trace.End(trace.Begin("")) diff --git a/tests/resources/VCH-Util.robot b/tests/resources/VCH-Util.robot index 849481ac49..2dfa221b25 100644 --- a/tests/resources/VCH-Util.robot +++ b/tests/resources/VCH-Util.robot @@ -51,7 +51,7 @@ Set Test Environment Variables Run Keyword If ${status} Set Environment Variable HOST_TYPE ESXi Run Keyword Unless ${status} Set Environment Variable HOST_TYPE VC - ${about}= Run govc datastore.info %{TEST_DATASTORE} |grep 'Type' + ${about}= Run govc datastore.info %{TEST_DATASTORE} | grep 'Type' ${status}= Run Keyword And Return Status Should Contain ${about} vsan Run Keyword If ${status} Set Environment Variable DATASTORE_TYPE VSAN Run Keyword Unless ${status} Set Environment Variable DATASTORE_TYPE Non_VSAN diff --git a/tests/test-cases/Group1-Docker-Commands/1-04-Docker-Create.robot b/tests/test-cases/Group1-Docker-Commands/1-04-Docker-Create.robot index 17a4c759ea..19c2e25234 100644 --- a/tests/test-cases/Group1-Docker-Commands/1-04-Docker-Create.robot +++ b/tests/test-cases/Group1-Docker-Commands/1-04-Docker-Create.robot @@ -187,10 +187,10 @@ Create a container and check the VM display name and datastore folder name ${rc} ${output}= Run Keyword If '%{HOST_TYPE}' == 'ESXi' Run And Return Rc And Output govc vm.info ${vmName} Run Keyword If '%{HOST_TYPE}' == 'ESXi' Should Be Equal As Integers ${rc} 0 Run Keyword If '%{HOST_TYPE}' == 'ESXi' Should Contain ${output} ${vmName} - ${rc} ${output}= Run Keyword If '%{DATASTORE_TYPE}' == 'VSAN' Run And Return Rc And Output govc datastore.ls |grep ${vmName} + ${rc} ${output}= Run Keyword If '%{DATASTORE_TYPE}' == 'VSAN' Run And Return Rc And Output govc datastore.ls | grep ${vmName} Run Keyword If '%{DATASTORE_TYPE}' == 'VSAN' Should Be Equal As Integers ${rc} 0 Run Keyword If '%{DATASTORE_TYPE}' == 'VSAN' Should contain ${output} ${vmName} - ${rc} ${output}= Run Keyword If '%{DATASTORE_TYPE}' == 'Non_VSAN' Run And Return Rc And Output govc datastore.ls |grep ${id} + ${rc} ${output}= Run Keyword If '%{DATASTORE_TYPE}' == 'Non_VSAN' Run And Return Rc And Output govc datastore.ls | grep ${id} Run Keyword If '%{DATASTORE_TYPE}' == 'Non_VSAN' Should Be Equal As Integers ${rc} 0 Run Keyword If '%{DATASTORE_TYPE}' == 'Non_VSAN' Should Contain ${output} ${id} \ No newline at end of file diff --git a/tests/test-cases/Group11-Upgrade/11-01-Upgrade.robot b/tests/test-cases/Group11-Upgrade/11-01-Upgrade.robot index 7dd2cbf9de..b658652db4 100644 --- a/tests/test-cases/Group11-Upgrade/11-01-Upgrade.robot +++ b/tests/test-cases/Group11-Upgrade/11-01-Upgrade.robot @@ -111,7 +111,7 @@ Run Docker Checks ${rc} ${output}= Run Keyword If '%{HOST_TYPE}' == 'ESXi' Run And Return Rc And Output govc vm.info *-%{ID1} Run Keyword If '%{HOST_TYPE}' == 'ESXi' Should Be Equal As Integers ${rc} 0 Run Keyword If '%{HOST_TYPE}' == 'ESXi' Should Contain ${output} vch-restart-tes-%{ID1} - ${rc} ${output}= Run And Return Rc And Output govc datastore.ls |grep vch-restart-tes-%{ID1} + ${rc} ${output}= Run And Return Rc And Output govc datastore.ls | grep vch-restart-tes-%{ID1} Should Be Equal As Integers ${rc} 0 Should Be Equal ${output} vch-restart-tes-%{ID1} @@ -125,10 +125,10 @@ Run Docker Checks ${rc} ${output}= Run Keyword If '%{HOST_TYPE}' == 'ESXi' Run And Return Rc And Output govc vm.info ${vmName} Run Keyword If '%{HOST_TYPE}' == 'ESXi' Should Be Equal As Integers ${rc} 0 Run Keyword If '%{HOST_TYPE}' == 'ESXi' Should Contain ${output} ${vmName} - ${rc} ${output}= Run Keyword If '%{DATASTORE_TYPE}' == 'VSAN' Run And Return Rc And Output govc datastore.ls |grep ${vmName} + ${rc} ${output}= Run Keyword If '%{DATASTORE_TYPE}' == 'VSAN' Run And Return Rc And Output govc datastore.ls | grep ${vmName} Run Keyword If '%{DATASTORE_TYPE}' == 'VSAN' Should Be Equal As Integers ${rc} 0 Run Keyword If '%{DATASTORE_TYPE}' == 'VSAN' Should contain ${output} ${vmName} - ${rc} ${output}= Run Keyword If '%{DATASTORE_TYPE}' == 'Non_VSAN' Run And Return Rc And Output govc datastore.ls |grep ${id} + ${rc} ${output}= Run Keyword If '%{DATASTORE_TYPE}' == 'Non_VSAN' Run And Return Rc And Output govc datastore.ls | grep ${id} Run Keyword If '%{DATASTORE_TYPE}' == 'Non_VSAN' Should Be Equal As Integers ${rc} 0 Run Keyword If '%{DATASTORE_TYPE}' == 'Non_VSAN' Should Contain ${output} ${id} From f2c7a48c6e211477997c0f68f4b55e84cfee6d1f Mon Sep 17 00:00:00 2001 From: chengwang86 Date: Wed, 22 Mar 2017 10:45:31 -0700 Subject: [PATCH 50/58] cosmetic change --- lib/portlayer/logging/logging.go | 8 -------- lib/vicadmin/validate.go | 4 ++-- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/lib/portlayer/logging/logging.go b/lib/portlayer/logging/logging.go index 46a6682049..1c985b49b7 100644 --- a/lib/portlayer/logging/logging.go +++ b/lib/portlayer/logging/logging.go @@ -142,15 +142,7 @@ func Join(h interface{}) (interface{}, error) { VMID := handle.Spec.ID() dsName := handle.Spec.Datastore.Name() - //dsType, err := handle.Spec.Datastore.Type(context.Background()) - //if err != nil { - // return nil, fmt.Errorf("failed to check datastore type for %s: %s", VMID, err) - //} - logFilePath = fmt.Sprintf("[%s] %s", dsName, VMID) - //if dsType == types.HostFileSystemVolumeFileSystemTypeVsan { - // logFilePath = fmt.Sprintf("%s/%s", VMPathName, VMName) - //} if handle.Spec.Session.IsVSAN(context.Background()) { logFilePath = fmt.Sprintf("%s/%s", VMPathName, VMName) } diff --git a/lib/vicadmin/validate.go b/lib/vicadmin/validate.go index 5e013ec8f2..ecf38bf90c 100644 --- a/lib/vicadmin/validate.go +++ b/lib/vicadmin/validate.go @@ -219,7 +219,7 @@ func VCHName(ctx context.Context, sess *session.Session) string { self, err := guest.GetSelf(ctx, sess) if err != nil { log.Errorf("Unable to get VCH name due to unknown self-reference: %s", err) - log.Infof("Setting the VCH name to VCH") + log.Infof("Setting the VCH name to %s", DefaultVCHName) return DefaultVCHName } @@ -227,7 +227,7 @@ func VCHName(ctx context.Context, sess *session.Session) string { vchName, err := newVM.Name(ctx) if err != nil { log.Errorf("Unable to get VCH name: %s", err) - log.Infof("Setting the VCH name to VCH") + log.Infof("Setting the VCH name to %s", DefaultVCHName) return DefaultVCHName } From cd20d165ac2c6c8a835d701ffe122bf26c5d07b3 Mon Sep 17 00:00:00 2001 From: chengwang86 Date: Wed, 22 Mar 2017 12:51:17 -0700 Subject: [PATCH 51/58] update tests and the method for obtaining VCH name in vicadmin --- lib/vicadmin/validate.go | 41 ++++++++++++++++++------------- tests/resources/Docker-Util.robot | 3 +-- 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/lib/vicadmin/validate.go b/lib/vicadmin/validate.go index ecf38bf90c..a6104e8e1e 100644 --- a/lib/vicadmin/validate.go +++ b/lib/vicadmin/validate.go @@ -111,9 +111,10 @@ func NewValidator(ctx context.Context, vch *config.VirtualContainerHostConfigSpe v.Version = version.Version } log.Infof("Setting version to %s", v.Version) - - // VCH Name - v.Hostname = VCHName(ctx, sess) + + if err := v.SetVCHName(ctx, sess); err != nil { + log.Errorf("Failed to obtain VCH name: %s", err) + } // System time v.SystemTime = time.Now().Format(time.UnixDate) @@ -212,35 +213,41 @@ func NewValidator(ctx context.Context, vch *config.VirtualContainerHostConfigSpe return v } +type dsList []mo.Datastore + +func (d dsList) Len() int { return len(d) } +func (d dsList) Swap(i, j int) { d[i], d[j] = d[j], d[i] } +func (d dsList) Less(i, j int) bool { return d[i].Name < d[j].Name } + // Obtain the VCH name from vsphere -func VCHName(ctx context.Context, sess *session.Session) string { +func (v *Validator) SetVCHName(ctx context.Context, sess *session.Session) error { defer trace.End(trace.Begin("")) + var err error + + if sess == nil { + v.Hostname = DefaultVCHName + return fmt.Errorf("session is nil") + } + self, err := guest.GetSelf(ctx, sess) if err != nil { - log.Errorf("Unable to get VCH name due to unknown self-reference: %s", err) - log.Infof("Setting the VCH name to %s", DefaultVCHName) - return DefaultVCHName + v.Hostname = DefaultVCHName + return fmt.Errorf("unknown self-reference: %s", err) } newVM := vm.NewVirtualMachineFromVM(ctx, sess, self) vchName, err := newVM.Name(ctx) if err != nil { - log.Errorf("Unable to get VCH name: %s", err) - log.Infof("Setting the VCH name to %s", DefaultVCHName) - return DefaultVCHName + v.Hostname = DefaultVCHName + return err } + v.Hostname = vchName log.Infof("Setting the VCH name to %s", vchName) - return vchName + return nil } -type dsList []mo.Datastore - -func (d dsList) Len() int { return len(d) } -func (d dsList) Swap(i, j int) { d[i], d[j] = d[j], d[i] } -func (d dsList) Less(i, j int) bool { return d[i].Name < d[j].Name } - func (v *Validator) QueryDatastore(ctx context.Context, vch *config.VirtualContainerHostConfigSpec, sess *session.Session) error { if sess == nil { // If we can't connect to vSphere, don't display datastore info diff --git a/tests/resources/Docker-Util.robot b/tests/resources/Docker-Util.robot index 76caac6bf9..178f8793ec 100644 --- a/tests/resources/Docker-Util.robot +++ b/tests/resources/Docker-Util.robot @@ -62,8 +62,7 @@ Get VM display name Should Be Equal As Integers ${rc} 0 ${name}= Get Substring ${name} 1 ${shortID}= Get container shortID ${id} - ${vmName}= Catenate SEPARATOR=- ${name} ${shortID} - [Return] ${vmName} + [Return] ${name}-${shortID} Run Regression Tests ${rc} ${output}= Run And Return Rc And Output docker %{VCH-PARAMS} pull busybox From 2f1ff70f15c9be4b54721dd631bc9f8977c7edc4 Mon Sep 17 00:00:00 2001 From: chengwang86 Date: Wed, 22 Mar 2017 14:02:41 -0700 Subject: [PATCH 52/58] remove VSAN checking from logging.go --- lib/portlayer/constants/constants.go | 8 ++++++-- lib/portlayer/logging/logging.go | 12 +++++++----- lib/portlayer/util/util.go | 9 ++++----- lib/vicadmin/validate.go | 2 +- 4 files changed, 18 insertions(+), 13 deletions(-) diff --git a/lib/portlayer/constants/constants.go b/lib/portlayer/constants/constants.go index 68629a6a7e..5884e90205 100644 --- a/lib/portlayer/constants/constants.go +++ b/lib/portlayer/constants/constants.go @@ -29,9 +29,13 @@ const ( ExternalScopeType = "external" // DefaultBridgeRange is the default pool for bridge networks DefaultBridgeRange = "172.16.0.0/12" + // Constants for assemble the VM display name on vSphere + MaxVMNameLength = 80 + ShortIDLen = 12 // vSphere Display name for the VCH's Guest Name and for VAC support - defaultAltVCHGuestName = "Photon - VCH" + defaultAltVCHGuestName = "Photon - VCH" defaultAltContainerGuestName = "Photon - Container" + ) func DefaultAltVCHGuestName() string { @@ -40,4 +44,4 @@ func DefaultAltVCHGuestName() string { func DefaultAltContainerGuestName() string { return fmt.Sprintf("%s %s, %s, %7s", defaultAltContainerGuestName, version.Version, version.BuildNumber, version.GitCommit) -} \ No newline at end of file +} diff --git a/lib/portlayer/logging/logging.go b/lib/portlayer/logging/logging.go index 1c985b49b7..c4dc89ab93 100644 --- a/lib/portlayer/logging/logging.go +++ b/lib/portlayer/logging/logging.go @@ -21,6 +21,8 @@ import ( log "github.com/Sirupsen/logrus" + "strings" + "github.com/vmware/govmomi/object" "github.com/vmware/govmomi/vim25/types" "github.com/vmware/vic/lib/portlayer/event/collector/vsphere" @@ -139,12 +141,12 @@ func Join(h interface{}) (interface{}, error) { VMPathName := handle.Spec.VMPathName() VMName := handle.Spec.Spec().Name - VMID := handle.Spec.ID() - dsName := handle.Spec.Datastore.Name() - logFilePath = fmt.Sprintf("[%s] %s", dsName, VMID) - if handle.Spec.Session.IsVSAN(context.Background()) { - logFilePath = fmt.Sprintf("%s/%s", VMPathName, VMName) + logFilePath = fmt.Sprintf("%s/%s", VMPathName, VMName) + // on non-vsan setup, VMPathName is set to "[datastore_name] containerID/containerID.vmx" + if strings.Contains(VMPathName, "vmx") { + idx := strings.LastIndex(VMPathName, "/") + logFilePath = VMPathName[:idx] } for _, logFile := range []string{"tether.debug", "output.log"} { diff --git a/lib/portlayer/util/util.go b/lib/portlayer/util/util.go index 29ad35d2d2..79d9787b3b 100644 --- a/lib/portlayer/util/util.go +++ b/lib/portlayer/util/util.go @@ -20,14 +20,13 @@ import ( "os" log "github.com/Sirupsen/logrus" + + "github.com/vmware/vic/lib/portlayer/constants" ) const ( // XXX leaving this as http for now. We probably want to make this unix:// scheme = "http://" - - maxVMNameLength = 80 - shortIDLen = 12 ) var ( @@ -60,8 +59,8 @@ func ServiceURL(serviceName string) *url.URL { // Update the VM display name on vSphere UI func DisplayName(id, name string) string { - shortID := id[:shortIDLen] - nameMaxLen := maxVMNameLength - len(shortID) + shortID := id[:constants.ShortIDLen] + nameMaxLen := constants.MaxVMNameLength - len(shortID) prettyName := name if len(prettyName) > nameMaxLen-1 { prettyName = prettyName[:nameMaxLen-1] diff --git a/lib/vicadmin/validate.go b/lib/vicadmin/validate.go index a6104e8e1e..3b73bfd9f5 100644 --- a/lib/vicadmin/validate.go +++ b/lib/vicadmin/validate.go @@ -111,7 +111,7 @@ func NewValidator(ctx context.Context, vch *config.VirtualContainerHostConfigSpe v.Version = version.Version } log.Infof("Setting version to %s", v.Version) - + if err := v.SetVCHName(ctx, sess); err != nil { log.Errorf("Failed to obtain VCH name: %s", err) } From 7f80e502da89f5b2b61116a286e622aafe3dad82 Mon Sep 17 00:00:00 2001 From: chengwang86 Date: Wed, 22 Mar 2017 14:28:02 -0700 Subject: [PATCH 53/58] cosmetic change --- lib/portlayer/logging/logging.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/portlayer/logging/logging.go b/lib/portlayer/logging/logging.go index c4dc89ab93..8c68dfc0a9 100644 --- a/lib/portlayer/logging/logging.go +++ b/lib/portlayer/logging/logging.go @@ -144,7 +144,7 @@ func Join(h interface{}) (interface{}, error) { logFilePath = fmt.Sprintf("%s/%s", VMPathName, VMName) // on non-vsan setup, VMPathName is set to "[datastore_name] containerID/containerID.vmx" - if strings.Contains(VMPathName, "vmx") { + if strings.HasSuffix(VMPathName, ".vmx") { idx := strings.LastIndex(VMPathName, "/") logFilePath = VMPathName[:idx] } From 456f991ce79ab2f939c885445eda42fd0a19f66c Mon Sep 17 00:00:00 2001 From: chengwang86 Date: Wed, 22 Mar 2017 15:22:46 -0700 Subject: [PATCH 54/58] cosmetic change --- lib/vicadmin/validate.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/vicadmin/validate.go b/lib/vicadmin/validate.go index 3b73bfd9f5..26985f6c9a 100644 --- a/lib/vicadmin/validate.go +++ b/lib/vicadmin/validate.go @@ -113,7 +113,7 @@ func NewValidator(ctx context.Context, vch *config.VirtualContainerHostConfigSpe log.Infof("Setting version to %s", v.Version) if err := v.SetVCHName(ctx, sess); err != nil { - log.Errorf("Failed to obtain VCH name: %s", err) + log.Errorf("Failed to obtain the VCH name: %s", err) } // System time From 5866e27614233f12d2c98d2d6526eb7fe3f4f4a1 Mon Sep 17 00:00:00 2001 From: chengwang86 Date: Wed, 22 Mar 2017 18:14:03 -0700 Subject: [PATCH 55/58] - update test case 9-01 - pass specconfig as argument to util.DisplayName() - panic when data migration fails --- lib/migration/migrator_test.go | 1 + lib/portlayer/exec/handle.go | 2 +- lib/portlayer/util/util.go | 8 +++++--- lib/vicadmin/validate.go | 4 ++-- pkg/version/plugin2/commonSpecForVCH.go | 1 + pkg/version/plugin3/commonSpecForContainer.go | 1 + .../Group9-VIC-Admin/9-01-VICAdmin-ShowHTML.robot | 5 +++-- 7 files changed, 14 insertions(+), 8 deletions(-) diff --git a/lib/migration/migrator_test.go b/lib/migration/migrator_test.go index e57d77c6eb..beaa0fe4f1 100644 --- a/lib/migration/migrator_test.go +++ b/lib/migration/migrator_test.go @@ -39,6 +39,7 @@ func setUp() { if err := manager.Migrator.Register(1, manager.ApplianceConfigure, &plugin1.ApplianceStopSignalRename{}); err != nil { log.Errorf("Failed to register plugin %s:%d, %s", manager.ApplianceConfigure, version.MaxPluginVersion, err) + panic(err) } } diff --git a/lib/portlayer/exec/handle.go b/lib/portlayer/exec/handle.go index 1bca2f208a..115b920db7 100644 --- a/lib/portlayer/exec/handle.go +++ b/lib/portlayer/exec/handle.go @@ -296,7 +296,7 @@ func Create(ctx context.Context, vmomiSession *session.Session, config *Containe specconfig.VMPathName = fmt.Sprintf("[%s] %s/%s.vmx", vmomiSession.Datastore.Name(), specconfig.ID, specconfig.ID) } - specconfig.VMFullName = util.DisplayName(specconfig.ID, specconfig.Name) + specconfig.VMFullName = util.DisplayName(specconfig) // log only core portions s := specconfig diff --git a/lib/portlayer/util/util.go b/lib/portlayer/util/util.go index 79d9787b3b..1fa6058fce 100644 --- a/lib/portlayer/util/util.go +++ b/lib/portlayer/util/util.go @@ -22,6 +22,7 @@ import ( log "github.com/Sirupsen/logrus" "github.com/vmware/vic/lib/portlayer/constants" + "github.com/vmware/vic/lib/spec" ) const ( @@ -58,10 +59,11 @@ func ServiceURL(serviceName string) *url.URL { } // Update the VM display name on vSphere UI -func DisplayName(id, name string) string { - shortID := id[:constants.ShortIDLen] +func DisplayName(config *spec.VirtualMachineConfigSpecConfig) string { + + shortID := config.ID[:constants.ShortIDLen] nameMaxLen := constants.MaxVMNameLength - len(shortID) - prettyName := name + prettyName := config.Name if len(prettyName) > nameMaxLen-1 { prettyName = prettyName[:nameMaxLen-1] } diff --git a/lib/vicadmin/validate.go b/lib/vicadmin/validate.go index 26985f6c9a..c60b926342 100644 --- a/lib/vicadmin/validate.go +++ b/lib/vicadmin/validate.go @@ -112,7 +112,7 @@ func NewValidator(ctx context.Context, vch *config.VirtualContainerHostConfigSpe } log.Infof("Setting version to %s", v.Version) - if err := v.SetVCHName(ctx, sess); err != nil { + if err := v.GetVCHName(ctx, sess); err != nil { log.Errorf("Failed to obtain the VCH name: %s", err) } @@ -220,7 +220,7 @@ func (d dsList) Swap(i, j int) { d[i], d[j] = d[j], d[i] } func (d dsList) Less(i, j int) bool { return d[i].Name < d[j].Name } // Obtain the VCH name from vsphere -func (v *Validator) SetVCHName(ctx context.Context, sess *session.Session) error { +func (v *Validator) GetVCHName(ctx context.Context, sess *session.Session) error { defer trace.End(trace.Begin("")) var err error diff --git a/pkg/version/plugin2/commonSpecForVCH.go b/pkg/version/plugin2/commonSpecForVCH.go index b5449c65cd..364d682608 100644 --- a/pkg/version/plugin2/commonSpecForVCH.go +++ b/pkg/version/plugin2/commonSpecForVCH.go @@ -36,6 +36,7 @@ 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) } } diff --git a/pkg/version/plugin3/commonSpecForContainer.go b/pkg/version/plugin3/commonSpecForContainer.go index 1e5374d3db..a99eec2fc9 100644 --- a/pkg/version/plugin3/commonSpecForContainer.go +++ b/pkg/version/plugin3/commonSpecForContainer.go @@ -36,6 +36,7 @@ func init() { defer trace.End(trace.Begin(fmt.Sprintf("Registering plugin %s:%d", target, version))) if err := manager.Migrator.Register(version, target, &AddCommonSpecForContainer{}); err != nil { log.Errorf("Failed to register plugin %s:%d, %s", target, version, err) + panic(err) } } diff --git a/tests/test-cases/Group9-VIC-Admin/9-01-VICAdmin-ShowHTML.robot b/tests/test-cases/Group9-VIC-Admin/9-01-VICAdmin-ShowHTML.robot index 0ad5f61fc5..4492e99487 100644 --- a/tests/test-cases/Group9-VIC-Admin/9-01-VICAdmin-ShowHTML.robot +++ b/tests/test-cases/Group9-VIC-Admin/9-01-VICAdmin-ShowHTML.robot @@ -107,8 +107,9 @@ Get Container Logs ${rc} ${output}= Run And Return Rc and Output curl -sk %{VIC-ADMIN}/container-logs.tar.gz -b /tmp/cookies-%{VCH-NAME} | tar tvzf - Should Be Equal As Integers ${rc} 0 Log ${output} - Should Contain ${output} ${container}/vmware.log - Should Contain ${output} ${container}/tether.debug + ${vmName}= Get VM Display Name ${container} + Should Contain ${output} ${vmName}/vmware.log + Should Contain ${output} ${vmName}/tether.debug Get VICAdmin Log Login And Save Cookies From 9ffcb32d4cb8cd49461e00bd78b4450efb9f3948 Mon Sep 17 00:00:00 2001 From: chengwang86 Date: Wed, 22 Mar 2017 19:43:15 -0700 Subject: [PATCH 56/58] move plugins from pkg to lib/migration/plugins/ --- lib/migration/migrator_test.go | 2 +- lib/migration/plugins/init.go | 4 ++-- .../migration/plugins/plugin1}/commonSpecForVCH.go | 2 +- .../migration/plugins/plugin2}/commonSpecForContainer.go | 2 +- pkg/version/version.go | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) rename {pkg/version/plugin2 => lib/migration/plugins/plugin1}/commonSpecForVCH.go (99%) rename {pkg/version/plugin3 => lib/migration/plugins/plugin2}/commonSpecForContainer.go (99%) diff --git a/lib/migration/migrator_test.go b/lib/migration/migrator_test.go index beaa0fe4f1..e3724c7456 100644 --- a/lib/migration/migrator_test.go +++ b/lib/migration/migrator_test.go @@ -37,7 +37,7 @@ func setUp() { trace.Logger.Level = log.DebugLevel version.MaxPluginVersion = version.MaxPluginVersion + 1 - if err := manager.Migrator.Register(1, manager.ApplianceConfigure, &plugin1.ApplianceStopSignalRename{}); err != nil { + 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) } diff --git a/lib/migration/plugins/init.go b/lib/migration/plugins/init.go index 1353b3d783..cbb9db2fd8 100644 --- a/lib/migration/plugins/init.go +++ b/lib/migration/plugins/init.go @@ -16,6 +16,6 @@ package plugins // import all plugin packages here to register plugins import ( - _ "github.com/vmware/vic/pkg/version/plugin2" - _ "github.com/vmware/vic/pkg/version/plugin3" + _ "github.com/vmware/vic/lib/migration/plugins/plugin1" + _ "github.com/vmware/vic/lib/migration/plugins/plugin2" ) diff --git a/pkg/version/plugin2/commonSpecForVCH.go b/lib/migration/plugins/plugin1/commonSpecForVCH.go similarity index 99% rename from pkg/version/plugin2/commonSpecForVCH.go rename to lib/migration/plugins/plugin1/commonSpecForVCH.go index 364d682608..ecf3f597f7 100644 --- a/pkg/version/plugin2/commonSpecForVCH.go +++ b/lib/migration/plugins/plugin1/commonSpecForVCH.go @@ -28,7 +28,7 @@ import ( ) const ( - version = 2 + version = 1 target = manager.ApplianceConfigure ) diff --git a/pkg/version/plugin3/commonSpecForContainer.go b/lib/migration/plugins/plugin2/commonSpecForContainer.go similarity index 99% rename from pkg/version/plugin3/commonSpecForContainer.go rename to lib/migration/plugins/plugin2/commonSpecForContainer.go index a99eec2fc9..03abaaa188 100644 --- a/pkg/version/plugin3/commonSpecForContainer.go +++ b/lib/migration/plugins/plugin2/commonSpecForContainer.go @@ -28,7 +28,7 @@ import ( ) const ( - version = 3 + version = 2 target = manager.ContainerConfigure ) diff --git a/pkg/version/version.go b/pkg/version/version.go index 3934c5ea7e..a020c1615a 100644 --- a/pkg/version/version.go +++ b/pkg/version/version.go @@ -31,7 +31,7 @@ var ( State string // MaxPluginVersion must be increased to add new plugin and make sure the new plugin version is same to this value - MaxPluginVersion = 3 + MaxPluginVersion = 2 v bool ) From ddc43630ce50642c2f523ca9332f820b79c34ab2 Mon Sep 17 00:00:00 2001 From: chengwang86 Date: Wed, 22 Mar 2017 19:49:43 -0700 Subject: [PATCH 57/58] cosmetic changes --- lib/migration/plugins/plugin1/commonSpecForVCH.go | 2 +- lib/migration/plugins/plugin2/commonSpecForContainer.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/migration/plugins/plugin1/commonSpecForVCH.go b/lib/migration/plugins/plugin1/commonSpecForVCH.go index ecf3f597f7..23c8ea3867 100644 --- a/lib/migration/plugins/plugin1/commonSpecForVCH.go +++ b/lib/migration/plugins/plugin1/commonSpecForVCH.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package plugin2 +package plugin1 import ( "context" diff --git a/lib/migration/plugins/plugin2/commonSpecForContainer.go b/lib/migration/plugins/plugin2/commonSpecForContainer.go index 03abaaa188..91473765d5 100644 --- a/lib/migration/plugins/plugin2/commonSpecForContainer.go +++ b/lib/migration/plugins/plugin2/commonSpecForContainer.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package plugin3 +package plugin2 import ( "context" From 607b05765b68bfec2f21a55711d0dbf009bed6cb Mon Sep 17 00:00:00 2001 From: chengwang86 Date: Thu, 23 Mar 2017 10:44:43 -0700 Subject: [PATCH 58/58] cosmetic change --- lib/vicadmin/validate.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/vicadmin/validate.go b/lib/vicadmin/validate.go index c60b926342..5169a494b4 100644 --- a/lib/vicadmin/validate.go +++ b/lib/vicadmin/validate.go @@ -64,7 +64,7 @@ type Validator struct { const ( GoodStatus = template.HTML(``) BadStatus = template.HTML(``) - DefaultVCHName = `VCH` + DefaultVCHName = ` ` ) func GetMgmtIP() net.IPNet {