本文整理汇总了Golang中github.com/openshift/origin/test/util.NewDockerClient函数的典型用法代码示例。如果您正苦于以下问题:Golang NewDockerClient函数的具体用法?Golang NewDockerClient怎么用?Golang NewDockerClient使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewDockerClient函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: InspectImage
//InspectImage initiates the equivalent of a `docker inspect` for the "name" parameter
func InspectImage(name string) (*dockerClient.Image, error) {
client, err := tutil.NewDockerClient()
if err != nil {
return nil, err
}
return client.InspectImage(name)
}
开发者ID:Xmagicer,项目名称:origin,代码行数:8,代码来源:docker.go
示例2: getDockerVersion
// getDockerVersion returns a version of running Docker daemon which is questioned only during the first
// invocation.
func getDockerVersion(logger io.Writer) (major, minor int, version string, err error) {
reVersion := regexp.MustCompile(`^(\d+)\.(\d+)`)
if dockerVersion == "" {
client, err2 := testutil.NewDockerClient()
if err = err2; err != nil {
return
}
env, err2 := client.Version()
if err = err2; err != nil {
return
}
dockerVersion = env.Get("Version")
if logger != nil {
logger.Write([]byte(fmt.Sprintf("Using docker version %s\n", version)))
}
}
version = dockerVersion
matches := reVersion.FindStringSubmatch(version)
if len(matches) < 3 {
return 0, 0, "", fmt.Errorf("failed to parse version string %s", version)
}
major, _ = strconv.Atoi(matches[1])
minor, _ = strconv.Atoi(matches[2])
return
}
开发者ID:Xmagicer,项目名称:origin,代码行数:29,代码来源:helper.go
示例3: TestRouterHealthzEndpoint
// TestRouterHealthzEndpoint tests that the router is listening on and
// exposing the /healthz endpoint for the default haproxy router image.
func TestRouterHealthzEndpoint(t *testing.T) {
testCases := []struct {
name string
port int
}{
{
name: "stats port enabled",
port: statsPort,
},
{
name: "stats port disabled",
port: 0,
},
{
name: "custom stats port",
port: 6391,
},
}
fakeMasterAndPod := tr.NewTestHttpService()
err := fakeMasterAndPod.Start()
if err != nil {
t.Fatalf("Unable to start http server: %v", err)
}
defer fakeMasterAndPod.Stop()
validateServer(fakeMasterAndPod, t)
dockerCli, err := testutil.NewDockerClient()
if err != nil {
t.Fatalf("Unable to get docker client: %v", err)
}
for _, tc := range testCases {
routerId, err := createAndStartRouterContainer(dockerCli, fakeMasterAndPod.MasterHttpAddr, tc.port, 0)
if err != nil {
t.Fatalf("Test with %q error starting container %s : %v", tc.name, getRouterImage(), err)
}
defer cleanUp(dockerCli, routerId)
time.Sleep(time.Second * 10)
host := "127.0.0.1"
port := tc.port
if tc.port == 0 {
port = statsPort
}
uri := fmt.Sprintf("%s:%d/healthz", host, port)
resp, err := getRoute(uri, host, "http", nil, "")
if err != nil {
t.Errorf("Test with %q unable to verify response: %v", tc.name, err)
}
if len(resp) < 1 {
t.Errorf("TestRouterHealthzEndpoint with %q failed! No Response body.", tc.name)
}
}
}
开发者ID:Vitogee,项目名称:origin,代码行数:62,代码来源:router_test.go
示例4: buildAndPushTestImagesTo
// buildAndPushTestImagesTo builds a given number of test images. The images are pushed to a new image stream
// of given name under <tagPrefix><X> where X is a number of image starting from 1.
func buildAndPushTestImagesTo(oc *exutil.CLI, isName string, tagPrefix string, numberOfImages int) (tag2Image map[string]imageapi.Image, err error) {
dClient, err := testutil.NewDockerClient()
if err != nil {
return
}
tag2Image = make(map[string]imageapi.Image)
for i := 1; i <= numberOfImages; i++ {
tag := fmt.Sprintf("%s%d", tagPrefix, i)
dgst, err := imagesutil.BuildAndPushImageOfSizeWithDocker(oc, dClient, isName, tag, imageSize, 2, g.GinkgoWriter, true)
if err != nil {
return nil, err
}
ist, err := oc.Client().ImageStreamTags(oc.Namespace()).Get(isName, tag)
if err != nil {
return nil, err
}
if dgst != ist.Image.Name {
return nil, fmt.Errorf("digest of built image does not match stored: %s != %s", dgst, ist.Image.Name)
}
tag2Image[tag] = ist.Image
}
return
}
开发者ID:LalatenduMohanty,项目名称:origin,代码行数:27,代码来源:limitrange_admission.go
示例5: TestRouterStatsPort
// TestRouterStatsPort tests that the router is listening on and
// exposing statistics for the default haproxy router image.
func TestRouterStatsPort(t *testing.T) {
fakeMasterAndPod := tr.NewTestHttpService()
err := fakeMasterAndPod.Start()
if err != nil {
t.Fatalf("Unable to start http server: %v", err)
}
defer fakeMasterAndPod.Stop()
validateServer(fakeMasterAndPod, t)
dockerCli, err := testutil.NewDockerClient()
if err != nil {
t.Fatalf("Unable to get docker client: %v", err)
}
routerId, err := createAndStartRouterContainer(dockerCli, fakeMasterAndPod.MasterHttpAddr, statsPort, 1)
if err != nil {
t.Fatalf("Error starting container %s : %v", getRouterImage(), err)
}
defer cleanUp(t, dockerCli, routerId)
waitForRouterToBecomeAvailable("127.0.0.1", statsPort)
statsHostPort := fmt.Sprintf("%s:%d", "127.0.0.1", statsPort)
creds := fmt.Sprintf("%s:%s", statsUser, statsPassword)
auth := fmt.Sprintf("Basic: %s", base64.StdEncoding.EncodeToString([]byte(creds)))
headers := map[string]string{"Authorization": auth}
if err := waitForRoute(statsHostPort, statsHostPort, "http", headers, ""); err != ErrUnauthenticated {
t.Fatalf("Unable to verify response: %v", err)
}
}
开发者ID:ncdc,项目名称:origin,代码行数:34,代码来源:router_test.go
示例6: PushImage
//PushImage initiates the equivalent of a `docker push` for the "name" parameter to the local registry
func PushImage(name string, authCfg dockerClient.AuthConfiguration) error {
client, err := tutil.NewDockerClient()
if err != nil {
return err
}
opts := dockerClient.PushImageOptions{
Name: name,
Tag: "latest",
}
return client.PushImage(opts, authCfg)
}
开发者ID:Xmagicer,项目名称:origin,代码行数:12,代码来源:docker.go
示例7: PullImage
//PullImage, as the name implies, initiates the equivalent of a `docker pull` for the "name" parameter
func PullImage(name string) error {
client, err := tutil.NewDockerClient()
if err != nil {
return err
}
opts := dockerClient.PullImageOptions{
Repository: name,
Tag: "latest",
}
return client.PullImage(opts, dockerClient.AuthConfiguration{})
}
开发者ID:nitintutlani,项目名称:origin,代码行数:12,代码来源:docker.go
示例8: TagImage
//TagImage will apply the "tagor" tag string to the image current tagged by "tagee"
func TagImage(tagee, tagor string) error {
client, dcerr := tutil.NewDockerClient()
if dcerr != nil {
return dcerr
}
opts := dockerClient.TagImageOptions{
Repo: tagee,
Tag: "latest",
Force: true,
}
return client.TagImage(tagor, opts)
}
开发者ID:Xmagicer,项目名称:origin,代码行数:13,代码来源:docker.go
示例9: ListImages
//ListImages initiates the equivalent of a `docker images`
func ListImages() ([]string, error) {
client, err := tutil.NewDockerClient()
if err != nil {
return nil, err
}
imageList, err := client.ListImages(dockerClient.ListImagesOptions{})
if err != nil {
return nil, err
}
returnIds := make([]string, 0)
for _, image := range imageList {
for _, tag := range image.RepoTags {
returnIds = append(returnIds, tag)
}
}
return returnIds, nil
}
开发者ID:Xmagicer,项目名称:origin,代码行数:18,代码来源:docker.go
示例10: GetImageIDForTags
//GetImageIDForTags will obtain the hexadecimal IDs for the array of human readible image tags IDs provided
func GetImageIDForTags(comps []string) ([]string, error) {
client, dcerr := tutil.NewDockerClient()
if dcerr != nil {
return nil, dcerr
}
imageList, serr := client.ListImages(dockerClient.ListImagesOptions{})
if serr != nil {
return nil, serr
}
returnTags := make([]string, 0)
missingTags := make([]string, 0)
for _, comp := range comps {
var found bool
for _, image := range imageList {
for _, repTag := range image.RepoTags {
if repTag == comp {
found = true
returnTags = append(returnTags, image.ID)
break
}
}
if found {
break
}
}
if !found {
returnTags = append(returnTags, "")
missingTags = append(missingTags, comp)
}
}
if len(missingTags) == 0 {
return returnTags, nil
} else {
mte := MissingTagError{
Tags: missingTags,
}
return returnTags, mte
}
}
开发者ID:Xmagicer,项目名称:origin,代码行数:43,代码来源:docker.go
示例11: TestRouterStatsPort
// TestRouterStatsPort tests that the router is listening on and
// exposing statistics for the default haproxy router image.
func TestRouterStatsPort(t *testing.T) {
fakeMasterAndPod := tr.NewTestHttpService()
err := fakeMasterAndPod.Start()
if err != nil {
t.Fatalf("Unable to start http server: %v", err)
}
defer fakeMasterAndPod.Stop()
validateServer(fakeMasterAndPod, t)
dockerCli, err := testutil.NewDockerClient()
if err != nil {
t.Fatalf("Unable to get docker client: %v", err)
}
routerId, err := createAndStartRouterContainer(dockerCli, fakeMasterAndPod.MasterHttpAddr, statsPort, 0)
if err != nil {
t.Fatalf("Error starting container %s : %v", getRouterImage(), err)
}
defer cleanUp(dockerCli, routerId)
time.Sleep(time.Second * 10)
statsHostPort := fmt.Sprintf("%s:%d", "127.0.0.1", statsPort)
creds := fmt.Sprintf("%s:%s", statsUser, statsPassword)
auth := fmt.Sprintf("Basic: %s", base64.StdEncoding.EncodeToString([]byte(creds)))
headers := map[string]string{"Authorization": auth}
resp, err := getRoute(statsHostPort, statsHostPort, "http", headers, "")
if err != nil {
t.Errorf("Unable to verify response: %v", err)
}
if len(resp) < 1 {
t.Errorf("TestRouterStatsPort failed! No Response body.")
}
}
开发者ID:Vitogee,项目名称:origin,代码行数:40,代码来源:router_test.go
示例12: TestRouterPathSpecificity
// TestRouterPathSpecificity tests that the router is matching routes from most specific to least when using
// a combination of path AND host based routes. It also ensures that a host based route still allows path based
// matches via the host header.
//
// For example, the http server simulator acts as if it has a directory structure like:
// /var/www
// index.html (Hello Pod)
// /test
// index.html (Hello Pod Path)
//
// With just a path based route for www.example.com/test I should get Hello Pod Path for a curl to www.example.com/test
// A curl to www.example.com should fall through to the default handlers. In the test environment it will fall through
// to a call to 0.0.0.0:8080 which is the master simulator
//
// If a host based route for www.example.com is added into the mix I should then be able to curl www.example.com and get
// Hello Pod and still be able to curl www.example.com/test and get Hello Pod Path
//
// If the path based route is deleted I should still be able to curl both routes successfully using the host based path
func TestRouterPathSpecificity(t *testing.T) {
fakeMasterAndPod := tr.NewTestHttpService()
err := fakeMasterAndPod.Start()
if err != nil {
t.Fatalf("Unable to start http server: %v", err)
}
defer fakeMasterAndPod.Stop()
validateServer(fakeMasterAndPod, t)
dockerCli, err := testutil.NewDockerClient()
if err != nil {
t.Fatalf("Unable to get docker client: %v", err)
}
routerId, err := createAndStartRouterContainer(dockerCli, fakeMasterAndPod.MasterHttpAddr)
if err != nil {
t.Fatalf("Error starting container %s : %v", getRouterImage(), err)
}
defer cleanUp(dockerCli, routerId)
httpEndpoint, err := getEndpoint(fakeMasterAndPod.PodHttpAddr)
if err != nil {
t.Fatalf("Couldn't get http endpoint: %v", err)
}
//create path based route
endpointEvent := &watch.Event{
Type: watch.Added,
Object: &kapi.Endpoints{
ObjectMeta: kapi.ObjectMeta{
Name: "myService",
Namespace: "default",
},
Subsets: []kapi.EndpointSubset{httpEndpoint},
},
}
routeEvent := &watch.Event{
Type: watch.Added,
Object: &routeapi.Route{
ObjectMeta: kapi.ObjectMeta{
Name: "path",
Namespace: "default",
},
Host: "www.example.com",
Path: "/test",
ServiceName: "myService",
},
}
fakeMasterAndPod.EndpointChannel <- eventString(endpointEvent)
fakeMasterAndPod.RouteChannel <- eventString(routeEvent)
time.Sleep(time.Second * tcWaitSeconds)
//ensure you can curl path but not main host
validateRoute("0.0.0.0/test", "www.example.com", "http", tr.HelloPodPath, t)
//should fall through to the default backend which is 127.0.0.1:8080 where the test server is simulating a master
validateRoute("0.0.0.0", "www.example.com", "http", tr.HelloMaster, t)
//create host based route
routeEvent = &watch.Event{
Type: watch.Added,
Object: &routeapi.Route{
ObjectMeta: kapi.ObjectMeta{
Name: "host",
Namespace: "default",
},
Host: "www.example.com",
ServiceName: "myService",
},
}
fakeMasterAndPod.RouteChannel <- eventString(routeEvent)
time.Sleep(time.Second * tcWaitSeconds)
//ensure you can curl path and host
validateRoute("0.0.0.0/test", "www.example.com", "http", tr.HelloPodPath, t)
validateRoute("0.0.0.0", "www.example.com", "http", tr.HelloPod, t)
//delete path based route
routeEvent = &watch.Event{
Type: watch.Deleted,
Object: &routeapi.Route{
ObjectMeta: kapi.ObjectMeta{
Name: "path",
//.........这里部分代码省略.........
开发者ID:jhadvig,项目名称:origin,代码行数:101,代码来源:router_test.go
示例13: TestRouterPathSpecificity
// TestRouterPathSpecificity tests that the router is matching routes from most specific to least when using
// a combination of path AND host based routes. It also ensures that a host based route still allows path based
// matches via the host header.
//
// For example, the http server simulator acts as if it has a directory structure like:
// /var/www
// index.html (Hello Pod)
// /test
// index.html (Hello Pod Path)
//
// With just a path based route for www.example.com/test I should get Hello Pod Path for a curl to www.example.com/test
// A curl to www.example.com should fall through to the default handlers. In the test environment it will fall through
// to a call to 0.0.0.0:8080 which is the master simulator
//
// If a host based route for www.example.com is added into the mix I should then be able to curl www.example.com and get
// Hello Pod and still be able to curl www.example.com/test and get Hello Pod Path
//
// If the path based route is deleted I should still be able to curl both routes successfully using the host based path
func TestRouterPathSpecificity(t *testing.T) {
fakeMasterAndPod := tr.NewTestHttpService()
err := fakeMasterAndPod.Start()
if err != nil {
t.Fatalf("Unable to start http server: %v", err)
}
defer fakeMasterAndPod.Stop()
validateServer(fakeMasterAndPod, t)
dockerCli, err := testutil.NewDockerClient()
if err != nil {
t.Fatalf("Unable to get docker client: %v", err)
}
routerId, err := createAndStartRouterContainer(dockerCli, fakeMasterAndPod.MasterHttpAddr)
if err != nil {
t.Fatalf("Error starting container %s : %v", getRouterImage(), err)
}
defer cleanUp(dockerCli, routerId)
httpEndpoint, err := getEndpoint(fakeMasterAndPod.PodHttpAddr)
if err != nil {
t.Fatalf("Couldn't get http endpoint: %v", err)
}
//create path based route
endpointEvent := &watch.Event{
Type: watch.Added,
Object: &kapi.Endpoints{
ObjectMeta: kapi.ObjectMeta{
Name: "myService",
Namespace: "default",
},
Subsets: []kapi.EndpointSubset{httpEndpoint},
},
}
routeEvent := &watch.Event{
Type: watch.Added,
Object: &routeapi.Route{
ObjectMeta: kapi.ObjectMeta{
Name: "path",
Namespace: "default",
},
Host: "www.example.com",
Path: "/test",
ServiceName: "myService",
},
}
fakeMasterAndPod.EndpointChannel <- eventString(endpointEvent)
fakeMasterAndPod.RouteChannel <- eventString(routeEvent)
time.Sleep(time.Second * tcWaitSeconds)
//ensure you can curl path but not main host
validateRoute("0.0.0.0/test", "www.example.com", "http", tr.HelloPodPath, t)
//should fall through to the default backend and get a 503.
resp, err := getRoute("0.0.0.0", "www.example.com", "http", "")
if err != nil {
t.Fatalf("Error getting route to default backend: %v", err)
}
// We can get back an empty response or a 503 page. A better check
// here would be to verify the response code is 503 but that needs
// getRoute + wrappers around that to change.
if resp != "" && !strings.Contains(resp, "<h1>503 Service Unavailable</h1>") {
t.Fatalf("Expected a 503 service unavailable got response :%v:", resp)
}
//create host based route
routeEvent = &watch.Event{
Type: watch.Added,
Object: &routeapi.Route{
ObjectMeta: kapi.ObjectMeta{
Name: "host",
Namespace: "default",
},
Host: "www.example.com",
ServiceName: "myService",
},
}
fakeMasterAndPod.RouteChannel <- eventString(routeEvent)
time.Sleep(time.Second * tcWaitSeconds)
//.........这里部分代码省略.........
开发者ID:nikkomega,项目名称:origin,代码行数:101,代码来源:router_test.go
示例14:
})
// needs to be run at the of of each It; cannot be run in AfterEach which is run after the project
// is destroyed
tearDown := func(oc *exutil.CLI) {
g.By(fmt.Sprintf("Deleting limit range %s", limitRangeName))
oc.AdminKubeClient().Core().LimitRanges(oc.Namespace()).Delete(limitRangeName, nil)
deleteTestImagesAndStreams(oc)
}
g.It(fmt.Sprintf("should deny a push of built image exceeding %s limit", imageapi.LimitTypeImage), func() {
oc.SetOutputDir(exutil.TestContext.OutputDir)
defer tearDown(oc)
dClient, err := testutil.NewDockerClient()
o.Expect(err).NotTo(o.HaveOccurred())
_, err = createLimitRangeOfType(oc, imageapi.LimitTypeImage, kapi.ResourceList{
kapi.ResourceStorage: resource.MustParse("10Ki"),
})
o.Expect(err).NotTo(o.HaveOccurred())
g.By(fmt.Sprintf("trying to push an image exceeding size limit with just 1 layer"))
err = imagesutil.BuildAndPushImageOfSizeWithBuilder(oc, dClient, oc.Namespace(), "sized", "middle", 16000, 1, false)
o.Expect(err).NotTo(o.HaveOccurred())
g.By(fmt.Sprintf("trying to push an image exceeding size limit in total"))
err = imagesutil.BuildAndPushImageOfSizeWithBuilder(oc, dClient, oc.Namespace(), "sized", "middle", 16000, 5, false)
o.Expect(err).NotTo(o.HaveOccurred())
开发者ID:LalatenduMohanty,项目名称:origin,代码行数:30,代码来源:limitrange_admission.go
示例15:
testutil "github.com/openshift/origin/test/util"
)
var _ = g.Describe("security: supplemental groups", func() {
defer g.GinkgoRecover()
var (
f = e2e.NewFramework("security-supgroups")
)
g.Describe("Ensure supplemental groups propagate to docker", func() {
g.It("should propagate requested groups to the docker host config", func() {
// Before running any of this test we need to first check that
// the docker version being used supports the supplemental groups feature
g.By("ensuring the feature is supported")
dockerCli, err := testutil.NewDockerClient()
o.Expect(err).NotTo(o.HaveOccurred())
env, err := dockerCli.Version()
o.Expect(err).NotTo(o.HaveOccurred(), "error getting docker environment")
version := env.Get("Version")
supports, err, requiredVersion := supportsSupplementalGroups(version)
if !supports || err != nil {
msg := fmt.Sprintf("skipping supplemental groups test, docker version %s does not meet required version %s", version, requiredVersion)
if err != nil {
msg = fmt.Sprintf("%s - encountered error: %v", msg, err)
}
g.Skip(msg)
}
开发者ID:piggyvenus,项目名称:origin,代码行数:30,代码来源:supplemental_groups.go
示例16: testPruneImages
func testPruneImages(oc *exutil.CLI, schemaVersion int) {
var mediaType string
switch schemaVersion {
case 1:
mediaType = schema1.MediaTypeManifest
case 2:
mediaType = schema2.MediaTypeManifest
default:
g.Fail(fmt.Sprintf("unexpected schema version %d", schemaVersion))
}
oc.SetOutputDir(exutil.TestContext.OutputDir)
outSink := g.GinkgoWriter
cleanUp := cleanUpContainer{}
defer tearDownPruneImagesTest(oc, &cleanUp)
dClient, err := testutil.NewDockerClient()
o.Expect(err).NotTo(o.HaveOccurred())
g.By(fmt.Sprintf("build two images using Docker and push them as schema %d", schemaVersion))
imgPruneName, err := BuildAndPushImageOfSizeWithDocker(oc, dClient, "prune", "latest", testImageSize, 2, outSink, true)
o.Expect(err).NotTo(o.HaveOccurred())
cleanUp.imageNames = append(cleanUp.imageNames, imgPruneName)
pruneSize, err := getRegistryStorageSize(oc)
o.Expect(err).NotTo(o.HaveOccurred())
imgKeepName, err := BuildAndPushImageOfSizeWithDocker(oc, dClient, "prune", "latest", testImageSize, 2, outSink, true)
o.Expect(err).NotTo(o.HaveOccurred())
cleanUp.imageNames = append(cleanUp.imageNames, imgKeepName)
keepSize, err := getRegistryStorageSize(oc)
o.Expect(err).NotTo(o.HaveOccurred())
o.Expect(pruneSize < keepSize).To(o.BeTrue())
g.By(fmt.Sprintf("ensure uploaded image is of schema %d", schemaVersion))
imgPrune, err := oc.AsAdmin().Client().Images().Get(imgPruneName)
o.Expect(err).NotTo(o.HaveOccurred())
o.Expect(imgPrune.DockerImageManifestMediaType).To(o.Equal(mediaType))
imgKeep, err := oc.AsAdmin().Client().Images().Get(imgKeepName)
o.Expect(err).NotTo(o.HaveOccurred())
o.Expect(imgKeep.DockerImageManifestMediaType).To(o.Equal(mediaType))
g.By("prune the first image uploaded (dry-run)")
output, err := oc.WithoutNamespace().Run("adm").Args("prune", "images", "--keep-tag-revisions=1", "--keep-younger-than=0").Output()
g.By("verify images, layers and configs about to be pruned")
o.Expect(output).To(o.ContainSubstring(imgPruneName))
if schemaVersion == 1 {
o.Expect(output).NotTo(o.ContainSubstring(imgPrune.DockerImageMetadata.ID))
} else {
o.Expect(output).To(o.ContainSubstring(imgPrune.DockerImageMetadata.ID))
}
for _, layer := range imgPrune.DockerImageLayers {
if !strings.Contains(output, layer.Name) {
o.Expect(output).To(o.ContainSubstring(layer.Name))
}
}
o.Expect(output).NotTo(o.ContainSubstring(imgKeepName))
o.Expect(output).NotTo(o.ContainSubstring(imgKeep.DockerImageMetadata.ID))
for _, layer := range imgKeep.DockerImageLayers {
if !strings.Contains(output, layer.Name) {
o.Expect(output).NotTo(o.ContainSubstring(layer.Name))
}
}
noConfirmSize, err := getRegistryStorageSize(oc)
o.Expect(err).NotTo(o.HaveOccurred())
o.Expect(noConfirmSize).To(o.Equal(keepSize))
g.By("prune the first image uploaded (confirm)")
output, err = oc.WithoutNamespace().Run("adm").Args("prune", "images", "--keep-tag-revisions=1", "--keep-younger-than=0", "--confirm").Output()
g.By("verify images, layers and configs about to be pruned")
o.Expect(output).To(o.ContainSubstring(imgPruneName))
if schemaVersion == 1 {
o.Expect(output).NotTo(o.ContainSubstring(imgPrune.DockerImageMetadata.ID))
} else {
o.Expect(output).To(o.ContainSubstring(imgPrune.DockerImageMetadata.ID))
}
for _, layer := range imgPrune.DockerImageLayers {
if !strings.Contains(output, layer.Name) {
o.Expect(output).To(o.ContainSubstring(layer.Name))
}
}
o.Expect(output).NotTo(o.ContainSubstring(imgKeepName))
o.Expect(output).NotTo(o.ContainSubstring(imgKeep.DockerImageMetadata.ID))
for _, layer := range imgKeep.DockerImageLayers {
if !strings.Contains(output, layer.Name) {
o.Expect(output).NotTo(o.ContainSubstring(layer.Name))
}
}
confirmSize, err := getRegistryStorageSize(oc)
o.Expect(err).NotTo(o.HaveOccurred())
g.By(fmt.Sprintf("confirming storage size: sizeOfKeepImage=%d <= sizeAfterPrune=%d < beforePruneSize=%d", imgKeep.DockerImageMetadata.Size, confirmSize, keepSize))
o.Expect(confirmSize >= imgKeep.DockerImageMetadata.Size).To(o.BeTrue())
o.Expect(confirmSize < keepSize).To(o.BeTrue())
g.By(fmt.Sprintf("confirming pruned size: sizeOfPruneImage=%d <= (sizeAfterPrune=%d - sizeBeforePrune=%d)", imgPrune, keepSize, confirmSize))
o.Expect(imgPrune.DockerImageMetadata.Size <= keepSize-confirmSize).To(o.BeTrue())
//.........这里部分代码省略.........
开发者ID:LalatenduMohanty,项目名称:origin,代码行数:101,代码来源:prune.go
示例17: TestRouterPathSpecificity
// TestRouterPathSpecificity tests that the router is matching routes from most specific to least when using
// a combination of path AND host based routes. It also ensures that a host based route still allows path based
// matches via the host header.
//
// For example, the http server simulator acts as if it has a directory structure like:
// /var/www
// index.html (Hello Pod)
// /test
// index.html (Hello Pod Path)
//
// With just a path based route for www.example.com/test I should get Hello Pod Path for a curl to www.example.com/test
// A curl to www.example.com should fall through to the default handlers. In the test environment it will fall through
// to a call to 0.0.0.0:8080 which is the master simulator
//
// If a host based route for www.example.com is added into the mix I should then be able to curl www.example.com and get
// Hello Pod and still be able to curl www.example.com/test and get Hello Pod Path
//
// If the path based route is deleted I should still be able to curl both routes successfully using the host based path
func TestRouterPathSpecificity(t *testing.T) {
fakeMasterAndPod := tr.NewTestHttpService()
err := fakeMasterAndPod.Start()
if err != nil {
t.Fatalf("Unable to start http server: %v", err)
}
defer fakeMasterAndPod.Stop()
validateServer(fakeMasterAndPod, t)
dockerCli, err := testutil.NewDockerClient()
if err != nil {
t.Fatalf("Unable to get docker client: %v", err)
}
routerId, err := createAndStartRouterContainer(dockerCli, fakeMasterAndPod.MasterHttpAddr, statsPort, 1)
if err != nil {
t.Fatalf("Error starting container %s : %v", getRouterImage(), err)
}
defer cleanUp(dockerCli, routerId)
httpEndpoint, err := getEndpoint(fakeMasterAndPod.PodHttpAddr)
if err != nil {
t.Fatalf("Couldn't get http endpoint: %v", err)
}
alternateHttpEndpoint, err := getEndpoint(fakeMasterAndPod.AlternatePodHttpAddr)
if err != nil {
t.Fatalf("Couldn't get http endpoint: %v", err)
}
waitForRouterToBecomeAvailable("127.0.0.1", statsPort)
now := unversioned.Now()
//create path based route
endpointEvent := &watch.Event{
Type: watch.Added,
Object: &kapi.Endpoints{
ObjectMeta: kapi.ObjectMeta{
CreationTimestamp: now,
Name: "myService",
Namespace: "default",
},
Subsets: []kapi.EndpointSubset{httpEndpoint},
},
}
routeEvent := &watch.Event{
Type: watch.Added,
Object: &routeapi.Route{
ObjectMeta: kapi.ObjectMeta{
Name: "path",
Namespace: "default",
},
Spec: routeapi.RouteSpec{
Host: "www.example.com",
Path: "/test",
To: kapi.ObjectReference{
Name: "myService",
},
},
},
}
routeAddress := getRouteAddress()
routeTestAddress := fmt.Sprintf("%s/test", routeAddress)
fakeMasterAndPod.EndpointChannel <- eventString(endpointEvent)
fakeMasterAndPod.RouteChannel <- eventString(routeEvent)
time.Sleep(time.Second * tcWaitSeconds)
//ensure you can curl path but not main host
if valid, response := isValidRoute(routeTestAddress, "www.example.com", "http", tr.HelloPodPath); !valid {
t.Errorf("unexpected response: %q", response)
}
//create newer, conflicting path based route
endpointEvent = &watch.Event{
Type: watch.Added,
Object: &kapi.Endpoints{
ObjectMeta: kapi.ObjectMeta{
Name: "altService",
Namespace: "alt",
//.........这里部分代码省略.........
开发者ID:poomsujarit,项目名称:origin,代码行数:101,代码来源:router_test.go
示例18: TestRouter
// TestRouter is the table based test for routers. It will initialize a fake master/client and expect to deploy
// a router image in docker. It then sends watch events through the simulator and makes http client requests that
// should go through the deployed router and return data from the client simulator.
func TestRouter(t *testing.T) {
//create a server which will act as a user deployed application that
//serves http and https as well as act as a master to simulate watches
fakeMasterAndPod := tr.NewTestHttpService()
defer fakeMasterAndPod.Stop()
err := fakeMasterAndPod.Start()
validateServer(fakeMasterAndPod, t)
if err != nil {
t.Fatalf("Unable to start http server: %v", err)
}
//deploy router docker container
dockerCli, err := testutil.NewDockerClient()
if err != nil {
t.Fatalf("Unable to get docker client: %v", err)
}
routerId, err := createAndStartRouterContainer(dockerCli, fakeMasterAndPod.MasterHttpAddr, statsPort, 1)
if err != nil {
t.Fatalf("Error starting container %s : %v", getRouterImage(), err)
}
defer cleanUp(t, dockerCli, routerId)
httpEndpoint, err := getEndpoint(fakeMasterAndPod.PodHttpAddr)
if err != nil {
t.Fatalf("Couldn't get http endpoint: %v", err)
}
httpsEndpoint, err := getEndpoint(fakeMasterAndPod.PodHttpsAddr)
if err != nil {
t.Fatalf("Couldn't get https endpoint: %v", err)
}
alternateHttpEndpoint, err := getEndpoint(fakeMasterAndPod.AlternatePodHttpAddr)
if err != nil {
t.Fatalf("Couldn't get http endpoint: %v", err)
}
routeAddress := getRouteAddress()
routeTestAddress := fmt.Sprintf("%s/test", routeAddress)
//run through test cases now that environment is set up
testCases := []struct {
name string
serviceName string
endpoints []kapi.EndpointSubset
routeAlias string
routePath string
endpointEventType watch.EventType
routeEventType watch.EventType
protocol string
expectedResponse string
routeTLS *routeapi.TLSConfig
routerUrl string
preferredPort *routeapi.RoutePort
}{
{
name: "non-secure",
serviceName: "example",
endpoints: []kapi.EndpointSubset{httpEndpoint},
routeAlias: "www.example-unsecure.com",
endpointEventType: watch.Added,
routeEventType: watch.Added,
protocol: "http",
expectedResponse: tr.HelloPod,
routeTLS: nil,
routerUrl: routeAddress,
},
{
name: "non-secure-path",
serviceName: "example-path",
endpoints: []kapi.EndpointSubset{httpEndpoint},
routeAlias: "www.example-unsecure.com",
routePath: "/test",
endpointEventType: watch.Added,
routeEventType: watch.Added,
protocol: "http",
expectedResponse: tr.HelloPodPath,
routeTLS: nil,
routerUrl: routeTestAddress,
},
{
name: "preferred-port",
serviceName: "example-preferred-port",
endpoints: []kapi.EndpointSubset{alternateHttpEndpoint, httpEndpoint},
routeAlias: "www.example-unsecure.com",
endpointEventType: watch.Added,
routeEventType: watch.Added,
protocol: "http",
expectedResponse: tr.HelloPod,
routeTLS: nil,
routerUrl: routeAddress,
preferredPort: &routeapi.RoutePort{TargetPort: intstr.FromInt(8888)},
},
//.........这里部分代码省略.........
开发者ID:ncdc,项目名称:origin,代码行数:101,代码来源:router_test.go
示例19: TestRouterReloadCoalesce
// TestRouterReloadCoalesce tests that router reloads are coalesced.
func TestRouterReloadCoalesce(t *testing.T) {
//create a server which will act as a user deployed application that
//serves http and https as well as act as a master to simulate watches
fakeMasterAndPod := tr.NewTestHttpService()
defer fakeMasterAndPod.Stop()
err := fakeMasterAndPod.Start()
validateServer(fakeMasterAndPod, t)
if err != nil {
t.Fatalf("Unable to start http server: %v", err)
}
//deploy router docker container
dockerCli, err := testutil.NewDockerClient()
if err != nil {
t.Fatalf("Unable to get docker client: %v", err)
}
reloadInterval := 7
routerId, err := createAndStartRouterContainer(dockerCli, fakeMasterAndPod.MasterHttpAddr, statsPort, reloadInterval)
if err != nil {
t.Fatalf("Error starting container %s : %v", getRouterImage(), err)
}
defer cleanUp(t, dockerCli, routerId)
httpEndpoint, err := getEndpoint(fakeMasterAndPod.PodHttpAddr)
if err != nil {
t.Fatalf("Couldn't get http endpoint: %v", err)
}
_, err = getEndpoint(fakeMasterAndPod.PodHttpsAddr)
if err != nil {
t.Fatalf("Couldn't get https endpoint: %v", err)
}
_, err = getEndpoint(fakeMasterAndPod.AlternatePodHttpAddr)
if err != nil {
t.Fatalf("Couldn't get http endpoint: %v", err)
}
routeAddress := getRouteAddress()
routeAlias := "www.example.test"
serviceName := "example"
endpoints := []kapi.EndpointSubset{httpEndpoint}
numRoutes := 10
for i := 1; i <= numRoutes; i++ {
routeName := fmt.Sprintf("coalesce-route-%v", i)
routeAlias = fmt.Sprintf("www.example-coalesce-%v.test", i)
// Send the add events.
generateTestEvents(t, fakeMasterAndPod, false, serviceName, routeName, routeAlias, endpoints)
}
// Wait for the last routeAlias to become available.
if err := waitForRoute(routeAddress, routeAlias, "http", nil, tr.HelloPod); err != nil {
t.Fatal(err)
}
// And ensure all the coalesce route aliases are available.
for i := 1; i <= numRoutes; i++ {
routeAlias := fmt.Sprintf("www.example-coalesce-%v.test", i)
if err := waitForRoute(routeAddress, routeAlias, "http", nil, tr.HelloPod); err != nil {
t.Fatalf("Unable to verify response for %q: %v", routeAlias, err)
}
}
for i := 1; i <= numRoutes; i++ {
routeName := fmt.Sprintf("coalesce-route-%v", i)
routeAlias = fmt.Sprintf("www.example-coalesce-%v.test", i)
// Send the cleanup events.
generateTestEvents(t, fakeMasterAndPod, true, serviceName, routeName, routeAlias, endpoints)
}
// Wait for the first routeAlias to become unavailable.
routeAlias = "www.example-coalesce-1.test"
if err := wait.Poll(time.Millisecond*100, time.Duration(reloadInterval)*2*time.Second, func() (bool, error) {
if _, err := getRoute(routeAddress, routeAlias, "http", nil, tr.HelloPod); err != nil {
return true, nil
}
return false, nil
}); err != nil {
t.Fatalf("Route did not become unavailable: %v", err)
}
// And ensure all the route aliases are gone.
for i := 1; i <= numRoutes; i++ {
routeAlias := fmt.Sprintf("www.example-coalesce-%v.test", i)
if _, err := getRoute(routeAddress, routeAlias, "http", nil, tr.HelloPod); err != ErrUnavailable {
t.Errorf("Unable to verify route deletion for %q: %+v", routeAlias, err)
}
}
}
开发者ID:ncdc,项目名称:origin,代码行数:99,代码来源:router_test.go
示例20: TestRouter
// TestRouter is the table based test for routers. It will initialize a fake master/client and expect to deploy
// a router image in docker. It then sends watch events through the simulator and makes http client requests that
// should go through the deployed router and return data from the client simulator.
func TestRouter(t *testing.T) {
//create a server which will act as a user deployed application that
//serves http and https as well as act as a master to simulate watches
fakeMasterAndPod := tr.NewTestHttpService()
defer fakeMasterAndPod.Stop()
err := fakeMasterAndPod.Start()
validateServer(fakeMasterAndPod, t)
if err != nil {
t.Fatalf("Unable to start http server: %v", err)
}
//deploy router docker container
dockerCli, err := testutil.NewDockerClient()
if err != nil {
t.Fatalf("Unable to get docker client: %v", err)
}
routerId, err := createAndStartRouterContainer(dockerCli, fakeMasterAndPod.MasterHttpAddr, statsPort, 1)
if err != nil {
t.Fatalf("Error starting container %s : %v", getRouterImage(), err)
}
defer cleanUp(dockerCli, routerId)
httpEndpoint, err := getEndpoint(fakeMasterAndPod.PodHttpAddr)
if err != nil {
t.Fatalf("Couldn't get http endpoint: %v", err)
}
httpsEndpoint, err := getEndpoint(fakeMasterAndPod.PodHttpsAddr)
if err != nil {
t.Fatalf("Couldn't get https endpoint: %v", err)
}
alternateHttpEndpoint, err := getEndpoint(fakeMasterAndPod.AlternatePodHttpAddr)
if err != nil {
t.Fatalf("Couldn't get http endpoint: %v", err)
}
routeAddress := getRouteAddress()
routeTestAddress := fmt.Sprintf("%s/test", routeAddress)
routerEchoHttpAddress := fmt.Sprintf("%s:80/echo", routeAddress)
routerEchoHttpsAddress := fmt.Sprintf("%s:443/echo", routeAddress)
//run through test cases now that environment is set up
testCases := []stru
|
请发表评论