mirror of https://github.com/k3s-io/k3s
use phase to test container status
Signed-off-by: liangchenye <liangchenye@huawei.com>pull/6/head
parent
7d41164931
commit
e3861cd6fc
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
Copyright 2015 The Kubernetes Authors All rights reserved.
|
Copyright 2016 The Kubernetes Authors All rights reserved.
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
|
@ -19,10 +19,15 @@ package e2e_node
|
||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
. "github.com/onsi/ginkgo"
|
|
||||||
. "github.com/onsi/gomega"
|
|
||||||
"k8s.io/kubernetes/pkg/api"
|
"k8s.io/kubernetes/pkg/api"
|
||||||
client "k8s.io/kubernetes/pkg/client/unversioned"
|
client "k8s.io/kubernetes/pkg/client/unversioned"
|
||||||
|
|
||||||
|
. "github.com/onsi/ginkgo"
|
||||||
|
. "github.com/onsi/gomega"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
serviceCreateTimeout = 2 * time.Minute
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ = Describe("Container Conformance Test", func() {
|
var _ = Describe("Container Conformance Test", func() {
|
||||||
|
@ -39,24 +44,31 @@ var _ = Describe("Container Conformance Test", func() {
|
||||||
BeforeEach(func() {
|
BeforeEach(func() {
|
||||||
terminateCase = ConformanceContainer{
|
terminateCase = ConformanceContainer{
|
||||||
Container: api.Container{
|
Container: api.Container{
|
||||||
Image: "gcc.io/google_testcontainers/busybox",
|
Image: "gcr.io/google_containers/busybox:1.24",
|
||||||
Name: "busybox",
|
Name: "busybox",
|
||||||
Command: []string{"echo", "'Hello World'"},
|
Command: []string{"sh", "-c", "env"},
|
||||||
ImagePullPolicy: api.PullIfNotPresent,
|
ImagePullPolicy: api.PullIfNotPresent,
|
||||||
},
|
},
|
||||||
Status: "terminated",
|
|
||||||
Client: cl,
|
Client: cl,
|
||||||
|
Phase: api.PodSucceeded,
|
||||||
|
NodeName: *nodeName,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
It("it should start successfully [Conformance]", func() {
|
It("it should start successfully [Conformance]", func() {
|
||||||
err := terminateCase.Create()
|
err := terminateCase.Create()
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
Eventually(func() bool {
|
phase := api.PodPending
|
||||||
return terminateCase.IsStarted()
|
for start := time.Now(); time.Since(start) < serviceCreateTimeout; time.Sleep(time.Second * 30) {
|
||||||
}, time.Minute*1, time.Second*30).Should(BeTrue())
|
ccontainer, err := terminateCase.Get()
|
||||||
|
if err != nil || ccontainer.Phase != api.PodPending {
|
||||||
|
phase = ccontainer.Phase
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Expect(phase).Should(Equal(terminateCase.Phase))
|
||||||
})
|
})
|
||||||
It("it should report its status as 'terminated' [Conformance]", func() {
|
It("it should report its phase as 'succeeded' [Conformance]", func() {
|
||||||
ccontainer, err := terminateCase.Get()
|
ccontainer, err := terminateCase.Get()
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
Expect(ccontainer).Should(CContainerEqual(terminateCase))
|
Expect(ccontainer).Should(CContainerEqual(terminateCase))
|
||||||
|
@ -76,19 +88,26 @@ var _ = Describe("Container Conformance Test", func() {
|
||||||
Command: []string{"foo", "'Should not work'"},
|
Command: []string{"foo", "'Should not work'"},
|
||||||
ImagePullPolicy: api.PullIfNotPresent,
|
ImagePullPolicy: api.PullIfNotPresent,
|
||||||
},
|
},
|
||||||
Status: "waiting",
|
|
||||||
Client: cl,
|
Client: cl,
|
||||||
|
Phase: api.PodPending,
|
||||||
|
NodeName: *nodeName,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
It("it should not start successfully [Conformance]", func() {
|
It("it should not start successfully [Conformance]", func() {
|
||||||
err := invalidImageCase.Create()
|
err := invalidImageCase.Create()
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
Eventually(func() bool {
|
phase := api.PodPending
|
||||||
return invalidImageCase.IsStarted()
|
for start := time.Now(); time.Since(start) < serviceCreateTimeout; time.Sleep(time.Second * 30) {
|
||||||
}, time.Minute*1, time.Second*30).ShouldNot(BeTrue())
|
ccontainer, err := invalidImageCase.Get()
|
||||||
|
if err != nil || ccontainer.Phase != api.PodPending {
|
||||||
|
phase = ccontainer.Phase
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Expect(phase).Should(Equal(invalidImageCase.Phase))
|
||||||
})
|
})
|
||||||
It("it should report its status as 'waiting' [Conformance]", func() {
|
It("it should report its phase as 'pending' [Conformance]", func() {
|
||||||
ccontainer, err := invalidImageCase.Get()
|
ccontainer, err := invalidImageCase.Get()
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
Expect(ccontainer).Should(CContainerEqual(invalidImageCase))
|
Expect(ccontainer).Should(CContainerEqual(invalidImageCase))
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
Copyright 2015 The Kubernetes Authors All rights reserved.
|
Copyright 2016 The Kubernetes Authors All rights reserved.
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
|
@ -20,18 +20,19 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/onsi/gomega/format"
|
|
||||||
"github.com/onsi/gomega/types"
|
|
||||||
|
|
||||||
"k8s.io/kubernetes/pkg/api"
|
"k8s.io/kubernetes/pkg/api"
|
||||||
client "k8s.io/kubernetes/pkg/client/unversioned"
|
client "k8s.io/kubernetes/pkg/client/unversioned"
|
||||||
|
|
||||||
|
"github.com/onsi/gomega/format"
|
||||||
|
"github.com/onsi/gomega/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
//One pod one container
|
//One pod one container
|
||||||
type ConformanceContainer struct {
|
type ConformanceContainer struct {
|
||||||
Container api.Container
|
Container api.Container
|
||||||
Client *client.Client
|
Client *client.Client
|
||||||
Status string
|
Phase api.PodPhase
|
||||||
|
NodeName string
|
||||||
}
|
}
|
||||||
|
|
||||||
type ConformanceContainerEqualMatcher struct {
|
type ConformanceContainerEqualMatcher struct {
|
||||||
|
@ -68,7 +69,7 @@ func (cc *ConformanceContainer) Create() error {
|
||||||
Namespace: api.NamespaceDefault,
|
Namespace: api.NamespaceDefault,
|
||||||
},
|
},
|
||||||
Spec: api.PodSpec{
|
Spec: api.PodSpec{
|
||||||
NodeName: *nodeName,
|
NodeName: cc.NodeName,
|
||||||
RestartPolicy: api.RestartPolicyNever,
|
RestartPolicy: api.RestartPolicyNever,
|
||||||
Containers: []api.Container{
|
Containers: []api.Container{
|
||||||
cc.Container,
|
cc.Container,
|
||||||
|
@ -80,16 +81,6 @@ func (cc *ConformanceContainer) Create() error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cc *ConformanceContainer) IsStarted() bool {
|
|
||||||
if ccontainer, err := cc.Get(); err != nil {
|
|
||||||
return false
|
|
||||||
} else if ccontainer.Status == "running" || ccontainer.Status == "terminated" {
|
|
||||||
return true
|
|
||||||
} else {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//Same with 'delete'
|
//Same with 'delete'
|
||||||
func (cc *ConformanceContainer) Stop() error {
|
func (cc *ConformanceContainer) Stop() error {
|
||||||
return cc.Client.Pods(api.NamespaceDefault).Delete(cc.Container.Name, &api.DeleteOptions{})
|
return cc.Client.Pods(api.NamespaceDefault).Delete(cc.Container.Name, &api.DeleteOptions{})
|
||||||
|
@ -109,20 +100,5 @@ func (cc *ConformanceContainer) Get() (ConformanceContainer, error) {
|
||||||
if containers == nil || len(containers) != 1 {
|
if containers == nil || len(containers) != 1 {
|
||||||
return ConformanceContainer{}, errors.New("Failed to get container")
|
return ConformanceContainer{}, errors.New("Failed to get container")
|
||||||
}
|
}
|
||||||
|
return ConformanceContainer{containers[0], cc.Client, pod.Status.Phase, cc.NodeName}, nil
|
||||||
cstatuss := pod.Status.ContainerStatuses
|
|
||||||
if cstatuss == nil || len(cstatuss) != 1 {
|
|
||||||
return ConformanceContainer{}, errors.New("Failed to get container status")
|
|
||||||
}
|
|
||||||
|
|
||||||
var status string
|
|
||||||
if cstatuss[0].State.Running != nil {
|
|
||||||
status = "running"
|
|
||||||
} else if cstatuss[0].State.Terminated != nil {
|
|
||||||
status = "terminated"
|
|
||||||
} else {
|
|
||||||
status = "waiting"
|
|
||||||
}
|
|
||||||
|
|
||||||
return ConformanceContainer{containers[0], cc.Client, status}, nil
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue