Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
e3861cd6
Commit
e3861cd6
authored
Feb 16, 2016
by
liangchenye
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use phase to test container status
Signed-off-by:
liangchenye
<
liangchenye@huawei.com
>
parent
7d411649
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
47 deletions
+42
-47
conformance_test.go
test/e2e_node/conformance_test.go
+34
-15
container.go
test/e2e_node/container.go
+8
-32
No files found.
test/e2e_node/conformance_test.go
View file @
e3861cd6
/*
/*
Copyright 201
5
The Kubernetes Authors All rights reserved.
Copyright 201
6
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
...
@@ -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() {
...
@@ -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
:
"gc
c.io/google_testcontainers/busybox
"
,
Image
:
"gc
r.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 'terminat
ed' [Conformance]"
,
func
()
{
It
(
"it should report its
phase as 'succeed
ed' [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() {
...
@@ -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 'wait
ing' [Conformance]"
,
func
()
{
It
(
"it should report its
phase as 'pend
ing' [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
))
...
...
test/e2e_node/container.go
View file @
e3861cd6
/*
/*
Copyright 201
5
The Kubernetes Authors All rights reserved.
Copyright 201
6
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 (
...
@@ -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 {
...
@@ -68,7 +69,7 @@ func (cc *ConformanceContainer) Create() error {
Namespace
:
api
.
NamespaceDefault
,
Namespace
:
api
.
NamespaceDefault
,
},
},
Spec
:
api
.
PodSpec
{
Spec
:
api
.
PodSpec
{
NodeName
:
*
n
odeName
,
NodeName
:
cc
.
N
odeName
,
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 {
...
@@ -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) {
...
@@ -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
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment