2018-02-05 21:05:59 +00:00
|
|
|
package system // import "github.com/docker/docker/integration/system"
|
2017-12-08 08:01:34 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2018-02-22 06:00:05 +00:00
|
|
|
"encoding/json"
|
volumes: only send "create" event when actually creating volume
The VolumesService did not have information wether or not a volume
was _created_ or if a volume already existed in the driver, and
the existing volume was used.
As a result, multiple "create" events could be generated for the
same volume. For example:
1. Run `docker events` in a shell to start listening for events
2. Create a volume:
docker volume create myvolume
3. Start a container that uses that volume:
docker run -dit -v myvolume:/foo busybox
4. Check the events that were generated:
2021-02-15T18:49:55.874621004+01:00 volume create myvolume (driver=local)
2021-02-15T18:50:11.442759052+01:00 volume create myvolume (driver=local)
2021-02-15T18:50:11.487104176+01:00 container create 45112157c8b1382626bf5e01ef18445a4c680f3846c5e32d01775dddee8ca6d1 (image=busybox, name=gracious_hypatia)
2021-02-15T18:50:11.519288102+01:00 network connect a19f6bb8d44ff84d478670fa4e34c5bf5305f42786294d3d90e790ac74b6d3e0 (container=45112157c8b1382626bf5e01ef18445a4c680f3846c5e32d01775dddee8ca6d1, name=bridge, type=bridge)
2021-02-15T18:50:11.526407799+01:00 volume mount myvolume (container=45112157c8b1382626bf5e01ef18445a4c680f3846c5e32d01775dddee8ca6d1, destination=/foo, driver=local, propagation=, read/write=true)
2021-02-15T18:50:11.864134043+01:00 container start 45112157c8b1382626bf5e01ef18445a4c680f3846c5e32d01775dddee8ca6d1 (image=busybox, name=gracious_hypatia)
5. Notice that a "volume create" event is created twice;
- once when `docker volume create` was ran
- once when `docker run ...` was ran
This patch moves the generation of (most) events to the volume _store_, and only
generates an event if the volume did not yet exist.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2021-02-15 17:45:15 +00:00
|
|
|
"errors"
|
2018-02-22 06:00:05 +00:00
|
|
|
"io"
|
|
|
|
"net/http"
|
|
|
|
"net/url"
|
|
|
|
"strconv"
|
2017-12-08 08:01:34 +00:00
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/docker/docker/api/types"
|
volumes: only send "create" event when actually creating volume
The VolumesService did not have information wether or not a volume
was _created_ or if a volume already existed in the driver, and
the existing volume was used.
As a result, multiple "create" events could be generated for the
same volume. For example:
1. Run `docker events` in a shell to start listening for events
2. Create a volume:
docker volume create myvolume
3. Start a container that uses that volume:
docker run -dit -v myvolume:/foo busybox
4. Check the events that were generated:
2021-02-15T18:49:55.874621004+01:00 volume create myvolume (driver=local)
2021-02-15T18:50:11.442759052+01:00 volume create myvolume (driver=local)
2021-02-15T18:50:11.487104176+01:00 container create 45112157c8b1382626bf5e01ef18445a4c680f3846c5e32d01775dddee8ca6d1 (image=busybox, name=gracious_hypatia)
2021-02-15T18:50:11.519288102+01:00 network connect a19f6bb8d44ff84d478670fa4e34c5bf5305f42786294d3d90e790ac74b6d3e0 (container=45112157c8b1382626bf5e01ef18445a4c680f3846c5e32d01775dddee8ca6d1, name=bridge, type=bridge)
2021-02-15T18:50:11.526407799+01:00 volume mount myvolume (container=45112157c8b1382626bf5e01ef18445a4c680f3846c5e32d01775dddee8ca6d1, destination=/foo, driver=local, propagation=, read/write=true)
2021-02-15T18:50:11.864134043+01:00 container start 45112157c8b1382626bf5e01ef18445a4c680f3846c5e32d01775dddee8ca6d1 (image=busybox, name=gracious_hypatia)
5. Notice that a "volume create" event is created twice;
- once when `docker volume create` was ran
- once when `docker run ...` was ran
This patch moves the generation of (most) events to the volume _store_, and only
generates an event if the volume did not yet exist.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2021-02-15 17:45:15 +00:00
|
|
|
"github.com/docker/docker/api/types/events"
|
2017-12-08 08:01:34 +00:00
|
|
|
"github.com/docker/docker/api/types/filters"
|
volumes: only send "create" event when actually creating volume
The VolumesService did not have information wether or not a volume
was _created_ or if a volume already existed in the driver, and
the existing volume was used.
As a result, multiple "create" events could be generated for the
same volume. For example:
1. Run `docker events` in a shell to start listening for events
2. Create a volume:
docker volume create myvolume
3. Start a container that uses that volume:
docker run -dit -v myvolume:/foo busybox
4. Check the events that were generated:
2021-02-15T18:49:55.874621004+01:00 volume create myvolume (driver=local)
2021-02-15T18:50:11.442759052+01:00 volume create myvolume (driver=local)
2021-02-15T18:50:11.487104176+01:00 container create 45112157c8b1382626bf5e01ef18445a4c680f3846c5e32d01775dddee8ca6d1 (image=busybox, name=gracious_hypatia)
2021-02-15T18:50:11.519288102+01:00 network connect a19f6bb8d44ff84d478670fa4e34c5bf5305f42786294d3d90e790ac74b6d3e0 (container=45112157c8b1382626bf5e01ef18445a4c680f3846c5e32d01775dddee8ca6d1, name=bridge, type=bridge)
2021-02-15T18:50:11.526407799+01:00 volume mount myvolume (container=45112157c8b1382626bf5e01ef18445a4c680f3846c5e32d01775dddee8ca6d1, destination=/foo, driver=local, propagation=, read/write=true)
2021-02-15T18:50:11.864134043+01:00 container start 45112157c8b1382626bf5e01ef18445a4c680f3846c5e32d01775dddee8ca6d1 (image=busybox, name=gracious_hypatia)
5. Notice that a "volume create" event is created twice;
- once when `docker volume create` was ran
- once when `docker run ...` was ran
This patch moves the generation of (most) events to the volume _store_, and only
generates an event if the volume did not yet exist.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2021-02-15 17:45:15 +00:00
|
|
|
"github.com/docker/docker/api/types/mount"
|
2017-12-08 08:01:34 +00:00
|
|
|
"github.com/docker/docker/api/types/strslice"
|
volumes: only send "create" event when actually creating volume
The VolumesService did not have information wether or not a volume
was _created_ or if a volume already existed in the driver, and
the existing volume was used.
As a result, multiple "create" events could be generated for the
same volume. For example:
1. Run `docker events` in a shell to start listening for events
2. Create a volume:
docker volume create myvolume
3. Start a container that uses that volume:
docker run -dit -v myvolume:/foo busybox
4. Check the events that were generated:
2021-02-15T18:49:55.874621004+01:00 volume create myvolume (driver=local)
2021-02-15T18:50:11.442759052+01:00 volume create myvolume (driver=local)
2021-02-15T18:50:11.487104176+01:00 container create 45112157c8b1382626bf5e01ef18445a4c680f3846c5e32d01775dddee8ca6d1 (image=busybox, name=gracious_hypatia)
2021-02-15T18:50:11.519288102+01:00 network connect a19f6bb8d44ff84d478670fa4e34c5bf5305f42786294d3d90e790ac74b6d3e0 (container=45112157c8b1382626bf5e01ef18445a4c680f3846c5e32d01775dddee8ca6d1, name=bridge, type=bridge)
2021-02-15T18:50:11.526407799+01:00 volume mount myvolume (container=45112157c8b1382626bf5e01ef18445a4c680f3846c5e32d01775dddee8ca6d1, destination=/foo, driver=local, propagation=, read/write=true)
2021-02-15T18:50:11.864134043+01:00 container start 45112157c8b1382626bf5e01ef18445a4c680f3846c5e32d01775dddee8ca6d1 (image=busybox, name=gracious_hypatia)
5. Notice that a "volume create" event is created twice;
- once when `docker volume create` was ran
- once when `docker run ...` was ran
This patch moves the generation of (most) events to the volume _store_, and only
generates an event if the volume did not yet exist.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2021-02-15 17:45:15 +00:00
|
|
|
"github.com/docker/docker/api/types/volume"
|
2018-02-10 23:01:37 +00:00
|
|
|
"github.com/docker/docker/integration/internal/container"
|
2018-02-22 06:00:05 +00:00
|
|
|
"github.com/docker/docker/pkg/jsonmessage"
|
2019-08-29 20:52:40 +00:00
|
|
|
"github.com/docker/docker/testutil/request"
|
|
|
|
req "github.com/docker/docker/testutil/request"
|
2020-02-07 13:39:24 +00:00
|
|
|
"gotest.tools/v3/assert"
|
|
|
|
is "gotest.tools/v3/assert/cmp"
|
|
|
|
"gotest.tools/v3/skip"
|
2017-12-08 08:01:34 +00:00
|
|
|
)
|
|
|
|
|
2018-05-04 21:15:00 +00:00
|
|
|
func TestEventsExecDie(t *testing.T) {
|
2023-06-14 09:46:00 +00:00
|
|
|
skip.If(t, testEnv.DaemonInfo.OSType == "windows", "FIXME. Suspect may need to wait until container is running before exec")
|
2023-07-14 18:02:38 +00:00
|
|
|
ctx := setupTest(t)
|
2019-01-02 13:16:25 +00:00
|
|
|
client := testEnv.APIClient()
|
2017-12-08 08:01:34 +00:00
|
|
|
|
2019-06-06 11:15:31 +00:00
|
|
|
cID := container.Run(ctx, t, client)
|
2017-12-08 08:01:34 +00:00
|
|
|
|
2018-02-10 23:01:37 +00:00
|
|
|
id, err := client.ContainerExecCreate(ctx, cID,
|
2017-12-08 08:01:34 +00:00
|
|
|
types.ExecConfig{
|
|
|
|
Cmd: strslice.StrSlice([]string{"echo", "hello"}),
|
|
|
|
},
|
|
|
|
)
|
2018-03-13 19:28:34 +00:00
|
|
|
assert.NilError(t, err)
|
2017-12-08 08:01:34 +00:00
|
|
|
|
2023-04-25 13:15:50 +00:00
|
|
|
msg, errs := client.Events(ctx, types.EventsOptions{
|
|
|
|
Filters: filters.NewArgs(
|
|
|
|
filters.Arg("container", cID),
|
2023-08-26 13:24:46 +00:00
|
|
|
filters.Arg("event", string(events.ActionExecDie)),
|
2023-04-25 13:15:50 +00:00
|
|
|
),
|
2017-12-08 08:01:34 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
err = client.ContainerExecStart(ctx, id.ID,
|
|
|
|
types.ExecStartCheck{
|
|
|
|
Detach: true,
|
|
|
|
Tty: false,
|
|
|
|
},
|
|
|
|
)
|
2018-03-13 19:28:34 +00:00
|
|
|
assert.NilError(t, err)
|
2017-12-08 08:01:34 +00:00
|
|
|
|
|
|
|
select {
|
|
|
|
case m := <-msg:
|
2023-08-27 20:24:29 +00:00
|
|
|
assert.Equal(t, m.Type, events.ContainerEventType)
|
2018-03-13 19:28:34 +00:00
|
|
|
assert.Equal(t, m.Actor.ID, cID)
|
2023-08-26 13:24:46 +00:00
|
|
|
assert.Equal(t, m.Action, events.ActionExecDie)
|
2018-03-13 19:28:34 +00:00
|
|
|
assert.Equal(t, m.Actor.Attributes["execID"], id.ID)
|
|
|
|
assert.Equal(t, m.Actor.Attributes["exitCode"], "0")
|
2023-04-25 13:15:50 +00:00
|
|
|
case err = <-errs:
|
2019-01-13 21:36:25 +00:00
|
|
|
assert.NilError(t, err)
|
2017-12-08 08:01:34 +00:00
|
|
|
case <-time.After(time.Second * 3):
|
|
|
|
t.Fatal("timeout hit")
|
|
|
|
}
|
|
|
|
}
|
2018-02-22 06:00:05 +00:00
|
|
|
|
|
|
|
// Test case for #18888: Events messages have been switched from generic
|
|
|
|
// `JSONMessage` to `events.Message` types. The switch does not break the
|
|
|
|
// backward compatibility so old `JSONMessage` could still be used.
|
|
|
|
// This test verifies that backward compatibility maintains.
|
|
|
|
func TestEventsBackwardsCompatible(t *testing.T) {
|
2023-06-14 09:46:00 +00:00
|
|
|
skip.If(t, testEnv.DaemonInfo.OSType == "windows", "Windows doesn't support back-compat messages")
|
2023-07-14 18:02:38 +00:00
|
|
|
ctx := setupTest(t)
|
2019-01-02 13:16:25 +00:00
|
|
|
client := testEnv.APIClient()
|
2018-02-22 06:00:05 +00:00
|
|
|
|
|
|
|
since := request.DaemonTime(ctx, t, client, testEnv)
|
|
|
|
ts := strconv.FormatInt(since.Unix(), 10)
|
|
|
|
|
2019-06-06 11:00:37 +00:00
|
|
|
cID := container.Create(ctx, t, client)
|
2018-02-22 06:00:05 +00:00
|
|
|
|
|
|
|
// In case there is no events, the API should have responded immediately (not blocking),
|
|
|
|
// The test here makes sure the response time is less than 3 sec.
|
|
|
|
expectedTime := time.Now().Add(3 * time.Second)
|
2023-07-14 18:02:38 +00:00
|
|
|
emptyResp, emptyBody, err := req.Get(ctx, "/events")
|
2018-03-13 19:28:34 +00:00
|
|
|
assert.NilError(t, err)
|
2018-02-22 06:00:05 +00:00
|
|
|
defer emptyBody.Close()
|
2018-03-13 19:28:34 +00:00
|
|
|
assert.Check(t, is.DeepEqual(http.StatusOK, emptyResp.StatusCode))
|
|
|
|
assert.Check(t, time.Now().Before(expectedTime), "timeout waiting for events api to respond, should have responded immediately")
|
2018-02-22 06:00:05 +00:00
|
|
|
|
|
|
|
// We also test to make sure the `events.Message` is compatible with `JSONMessage`
|
|
|
|
q := url.Values{}
|
|
|
|
q.Set("since", ts)
|
2023-07-14 18:02:38 +00:00
|
|
|
_, body, err := req.Get(ctx, "/events?"+q.Encode())
|
2018-03-13 19:28:34 +00:00
|
|
|
assert.NilError(t, err)
|
2018-02-22 06:00:05 +00:00
|
|
|
defer body.Close()
|
|
|
|
|
|
|
|
dec := json.NewDecoder(body)
|
|
|
|
var containerCreateEvent *jsonmessage.JSONMessage
|
|
|
|
for {
|
|
|
|
var event jsonmessage.JSONMessage
|
|
|
|
if err := dec.Decode(&event); err != nil {
|
|
|
|
if err == io.EOF {
|
|
|
|
break
|
|
|
|
}
|
2019-01-13 21:36:25 +00:00
|
|
|
assert.NilError(t, err)
|
2018-02-22 06:00:05 +00:00
|
|
|
}
|
|
|
|
if event.Status == "create" && event.ID == cID {
|
|
|
|
containerCreateEvent = &event
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-13 19:28:34 +00:00
|
|
|
assert.Check(t, containerCreateEvent != nil)
|
|
|
|
assert.Check(t, is.Equal("create", containerCreateEvent.Status))
|
|
|
|
assert.Check(t, is.Equal(cID, containerCreateEvent.ID))
|
|
|
|
assert.Check(t, is.Equal("busybox", containerCreateEvent.From))
|
2018-02-22 06:00:05 +00:00
|
|
|
}
|
volumes: only send "create" event when actually creating volume
The VolumesService did not have information wether or not a volume
was _created_ or if a volume already existed in the driver, and
the existing volume was used.
As a result, multiple "create" events could be generated for the
same volume. For example:
1. Run `docker events` in a shell to start listening for events
2. Create a volume:
docker volume create myvolume
3. Start a container that uses that volume:
docker run -dit -v myvolume:/foo busybox
4. Check the events that were generated:
2021-02-15T18:49:55.874621004+01:00 volume create myvolume (driver=local)
2021-02-15T18:50:11.442759052+01:00 volume create myvolume (driver=local)
2021-02-15T18:50:11.487104176+01:00 container create 45112157c8b1382626bf5e01ef18445a4c680f3846c5e32d01775dddee8ca6d1 (image=busybox, name=gracious_hypatia)
2021-02-15T18:50:11.519288102+01:00 network connect a19f6bb8d44ff84d478670fa4e34c5bf5305f42786294d3d90e790ac74b6d3e0 (container=45112157c8b1382626bf5e01ef18445a4c680f3846c5e32d01775dddee8ca6d1, name=bridge, type=bridge)
2021-02-15T18:50:11.526407799+01:00 volume mount myvolume (container=45112157c8b1382626bf5e01ef18445a4c680f3846c5e32d01775dddee8ca6d1, destination=/foo, driver=local, propagation=, read/write=true)
2021-02-15T18:50:11.864134043+01:00 container start 45112157c8b1382626bf5e01ef18445a4c680f3846c5e32d01775dddee8ca6d1 (image=busybox, name=gracious_hypatia)
5. Notice that a "volume create" event is created twice;
- once when `docker volume create` was ran
- once when `docker run ...` was ran
This patch moves the generation of (most) events to the volume _store_, and only
generates an event if the volume did not yet exist.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2021-02-15 17:45:15 +00:00
|
|
|
|
|
|
|
// TestEventsVolumeCreate verifies that volume create events are only fired
|
|
|
|
// once: when creating the volume, and not when attaching to a container.
|
|
|
|
func TestEventsVolumeCreate(t *testing.T) {
|
2023-06-14 09:46:00 +00:00
|
|
|
skip.If(t, testEnv.DaemonInfo.OSType == "windows", "FIXME: Windows doesn't trigger the events? Could be a race")
|
volumes: only send "create" event when actually creating volume
The VolumesService did not have information wether or not a volume
was _created_ or if a volume already existed in the driver, and
the existing volume was used.
As a result, multiple "create" events could be generated for the
same volume. For example:
1. Run `docker events` in a shell to start listening for events
2. Create a volume:
docker volume create myvolume
3. Start a container that uses that volume:
docker run -dit -v myvolume:/foo busybox
4. Check the events that were generated:
2021-02-15T18:49:55.874621004+01:00 volume create myvolume (driver=local)
2021-02-15T18:50:11.442759052+01:00 volume create myvolume (driver=local)
2021-02-15T18:50:11.487104176+01:00 container create 45112157c8b1382626bf5e01ef18445a4c680f3846c5e32d01775dddee8ca6d1 (image=busybox, name=gracious_hypatia)
2021-02-15T18:50:11.519288102+01:00 network connect a19f6bb8d44ff84d478670fa4e34c5bf5305f42786294d3d90e790ac74b6d3e0 (container=45112157c8b1382626bf5e01ef18445a4c680f3846c5e32d01775dddee8ca6d1, name=bridge, type=bridge)
2021-02-15T18:50:11.526407799+01:00 volume mount myvolume (container=45112157c8b1382626bf5e01ef18445a4c680f3846c5e32d01775dddee8ca6d1, destination=/foo, driver=local, propagation=, read/write=true)
2021-02-15T18:50:11.864134043+01:00 container start 45112157c8b1382626bf5e01ef18445a4c680f3846c5e32d01775dddee8ca6d1 (image=busybox, name=gracious_hypatia)
5. Notice that a "volume create" event is created twice;
- once when `docker volume create` was ran
- once when `docker run ...` was ran
This patch moves the generation of (most) events to the volume _store_, and only
generates an event if the volume did not yet exist.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2021-02-15 17:45:15 +00:00
|
|
|
|
2023-07-14 18:02:38 +00:00
|
|
|
ctx := setupTest(t)
|
|
|
|
ctx, cancel := context.WithCancel(ctx)
|
volumes: only send "create" event when actually creating volume
The VolumesService did not have information wether or not a volume
was _created_ or if a volume already existed in the driver, and
the existing volume was used.
As a result, multiple "create" events could be generated for the
same volume. For example:
1. Run `docker events` in a shell to start listening for events
2. Create a volume:
docker volume create myvolume
3. Start a container that uses that volume:
docker run -dit -v myvolume:/foo busybox
4. Check the events that were generated:
2021-02-15T18:49:55.874621004+01:00 volume create myvolume (driver=local)
2021-02-15T18:50:11.442759052+01:00 volume create myvolume (driver=local)
2021-02-15T18:50:11.487104176+01:00 container create 45112157c8b1382626bf5e01ef18445a4c680f3846c5e32d01775dddee8ca6d1 (image=busybox, name=gracious_hypatia)
2021-02-15T18:50:11.519288102+01:00 network connect a19f6bb8d44ff84d478670fa4e34c5bf5305f42786294d3d90e790ac74b6d3e0 (container=45112157c8b1382626bf5e01ef18445a4c680f3846c5e32d01775dddee8ca6d1, name=bridge, type=bridge)
2021-02-15T18:50:11.526407799+01:00 volume mount myvolume (container=45112157c8b1382626bf5e01ef18445a4c680f3846c5e32d01775dddee8ca6d1, destination=/foo, driver=local, propagation=, read/write=true)
2021-02-15T18:50:11.864134043+01:00 container start 45112157c8b1382626bf5e01ef18445a4c680f3846c5e32d01775dddee8ca6d1 (image=busybox, name=gracious_hypatia)
5. Notice that a "volume create" event is created twice;
- once when `docker volume create` was ran
- once when `docker run ...` was ran
This patch moves the generation of (most) events to the volume _store_, and only
generates an event if the volume did not yet exist.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2021-02-15 17:45:15 +00:00
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
client := testEnv.APIClient()
|
|
|
|
|
|
|
|
since := request.DaemonUnixTime(ctx, t, client, testEnv)
|
|
|
|
volName := t.Name()
|
|
|
|
getEvents := func(messages <-chan events.Message, errs <-chan error) ([]events.Message, error) {
|
|
|
|
var evts []events.Message
|
|
|
|
|
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case m := <-messages:
|
|
|
|
evts = append(evts, m)
|
|
|
|
case err := <-errs:
|
|
|
|
if err == io.EOF {
|
|
|
|
return evts, nil
|
|
|
|
}
|
|
|
|
return nil, err
|
|
|
|
case <-time.After(time.Second * 3):
|
|
|
|
return nil, errors.New("timeout hit")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-05 22:25:55 +00:00
|
|
|
_, err := client.VolumeCreate(ctx, volume.CreateOptions{Name: volName})
|
volumes: only send "create" event when actually creating volume
The VolumesService did not have information wether or not a volume
was _created_ or if a volume already existed in the driver, and
the existing volume was used.
As a result, multiple "create" events could be generated for the
same volume. For example:
1. Run `docker events` in a shell to start listening for events
2. Create a volume:
docker volume create myvolume
3. Start a container that uses that volume:
docker run -dit -v myvolume:/foo busybox
4. Check the events that were generated:
2021-02-15T18:49:55.874621004+01:00 volume create myvolume (driver=local)
2021-02-15T18:50:11.442759052+01:00 volume create myvolume (driver=local)
2021-02-15T18:50:11.487104176+01:00 container create 45112157c8b1382626bf5e01ef18445a4c680f3846c5e32d01775dddee8ca6d1 (image=busybox, name=gracious_hypatia)
2021-02-15T18:50:11.519288102+01:00 network connect a19f6bb8d44ff84d478670fa4e34c5bf5305f42786294d3d90e790ac74b6d3e0 (container=45112157c8b1382626bf5e01ef18445a4c680f3846c5e32d01775dddee8ca6d1, name=bridge, type=bridge)
2021-02-15T18:50:11.526407799+01:00 volume mount myvolume (container=45112157c8b1382626bf5e01ef18445a4c680f3846c5e32d01775dddee8ca6d1, destination=/foo, driver=local, propagation=, read/write=true)
2021-02-15T18:50:11.864134043+01:00 container start 45112157c8b1382626bf5e01ef18445a4c680f3846c5e32d01775dddee8ca6d1 (image=busybox, name=gracious_hypatia)
5. Notice that a "volume create" event is created twice;
- once when `docker volume create` was ran
- once when `docker run ...` was ran
This patch moves the generation of (most) events to the volume _store_, and only
generates an event if the volume did not yet exist.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2021-02-15 17:45:15 +00:00
|
|
|
assert.NilError(t, err)
|
|
|
|
|
|
|
|
filter := filters.NewArgs(
|
|
|
|
filters.Arg("type", "volume"),
|
|
|
|
filters.Arg("event", "create"),
|
|
|
|
filters.Arg("volume", volName),
|
|
|
|
)
|
|
|
|
messages, errs := client.Events(ctx, types.EventsOptions{
|
|
|
|
Since: since,
|
|
|
|
Until: request.DaemonUnixTime(ctx, t, client, testEnv),
|
|
|
|
Filters: filter,
|
|
|
|
})
|
|
|
|
|
|
|
|
volEvents, err := getEvents(messages, errs)
|
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.Equal(t, len(volEvents), 1, "expected volume create event when creating a volume")
|
|
|
|
|
|
|
|
container.Create(ctx, t, client, container.WithMount(mount.Mount{
|
|
|
|
Type: mount.TypeVolume,
|
|
|
|
Source: volName,
|
|
|
|
Target: "/tmp/foo",
|
|
|
|
}))
|
|
|
|
|
|
|
|
messages, errs = client.Events(ctx, types.EventsOptions{
|
|
|
|
Since: since,
|
|
|
|
Until: request.DaemonUnixTime(ctx, t, client, testEnv),
|
|
|
|
Filters: filter,
|
|
|
|
})
|
|
|
|
|
|
|
|
volEvents, err = getEvents(messages, errs)
|
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.Equal(t, len(volEvents), 1, "expected volume create event to be fired only once")
|
|
|
|
}
|