|
| 1 | +// Copyright 2018-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"). You may |
| 4 | +// not use this file except in compliance with the License. A copy of the |
| 5 | +// License is located at |
| 6 | +// |
| 7 | +// http://aws.amazon.com/apache2.0/ |
| 8 | +// |
| 9 | +// or in the "license" file accompanying this file. This file is distributed |
| 10 | +// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either |
| 11 | +// express or implied. See the License for the specific language governing |
| 12 | +// permissions and limitations under the License. |
| 13 | +package main |
| 14 | + |
| 15 | +import ( |
| 16 | + "context" |
| 17 | + "testing" |
| 18 | + |
| 19 | + "github.com/containerd/containerd" |
| 20 | + "github.com/containerd/containerd/namespaces" |
| 21 | + "github.com/containerd/containerd/oci" |
| 22 | + "github.com/stretchr/testify/assert" |
| 23 | + "github.com/stretchr/testify/require" |
| 24 | +) |
| 25 | + |
| 26 | +func TestDiskLimit_Isolated(t *testing.T) { |
| 27 | + prepareIntegTest(t) |
| 28 | + |
| 29 | + assert := assert.New(t) |
| 30 | + require := require.New(t) |
| 31 | + |
| 32 | + ctx := namespaces.WithNamespace(context.Background(), "default") |
| 33 | + |
| 34 | + client, err := containerd.New(containerdSockPath, containerd.WithDefaultRuntime(firecrackerRuntime)) |
| 35 | + require.NoError(err, "unable to create client to containerd service at %s, is containerd running?", containerdSockPath) |
| 36 | + defer client.Close() |
| 37 | + |
| 38 | + image, err := alpineImage(ctx, client, defaultSnapshotterName()) |
| 39 | + require.NoError(err, "failed to get alpine image") |
| 40 | + |
| 41 | + // Right now, both naive snapshotter and devmapper snapshotter are configured to have 1024MB image size. |
| 42 | + // The former is hard-coded since the snapshotter is not for production. The latter is configured in tools/docker/entrypoint.sh. |
| 43 | + sh := containerd.WithNewSpec( |
| 44 | + oci.WithProcessArgs("dd", "if=/dev/zero", "of=/tmp/fill", "bs=1M", "count=2000"), |
| 45 | + oci.WithDefaultPathEnv, |
| 46 | + ) |
| 47 | + |
| 48 | + container, err := client.NewContainer(ctx, |
| 49 | + "container", |
| 50 | + containerd.WithSnapshotter(defaultSnapshotterName()), |
| 51 | + containerd.WithNewSnapshot("snapshot", image), |
| 52 | + sh, |
| 53 | + ) |
| 54 | + defer func() { |
| 55 | + err = container.Delete(ctx, containerd.WithSnapshotCleanup) |
| 56 | + require.NoError(err, "failed to delete a container") |
| 57 | + }() |
| 58 | + |
| 59 | + result, err := runTask(ctx, container) |
| 60 | + require.NoError(err, "failed to create a container") |
| 61 | + |
| 62 | + assert.Equal(uint32(1), result.exitCode, "writing 2GB must fail") |
| 63 | + assert.Equal(`952+0 records in |
| 64 | +951+0 records out |
| 65 | +`, result.stderr, "but it must be able to write ~1024MB") |
| 66 | +} |
0 commit comments