2018-03-01 17:51:11 -05:00
|
|
|
package config // import "github.com/docker/docker/integration/config"
|
2018-02-09 16:44:28 -05:00
|
|
|
|
|
|
|
import (
|
2017-06-15 15:06:08 -04:00
|
|
|
"bytes"
|
2018-04-19 18:30:59 -04:00
|
|
|
"context"
|
2018-02-26 18:23:18 -05:00
|
|
|
"encoding/json"
|
2019-06-15 00:59:07 -04:00
|
|
|
"io/ioutil"
|
|
|
|
"path/filepath"
|
2018-02-09 16:44:28 -05:00
|
|
|
"sort"
|
|
|
|
"testing"
|
2017-06-15 15:06:08 -04:00
|
|
|
"time"
|
2018-02-09 16:44:28 -05:00
|
|
|
|
|
|
|
"github.com/docker/docker/api/types"
|
|
|
|
"github.com/docker/docker/api/types/filters"
|
|
|
|
swarmtypes "github.com/docker/docker/api/types/swarm"
|
|
|
|
"github.com/docker/docker/client"
|
|
|
|
"github.com/docker/docker/integration/internal/swarm"
|
2017-06-15 15:06:08 -04:00
|
|
|
"github.com/docker/docker/pkg/stdcopy"
|
2019-08-29 16:52:40 -04:00
|
|
|
"github.com/docker/docker/testutil/daemon"
|
2020-02-07 08:39:24 -05:00
|
|
|
"gotest.tools/v3/assert"
|
|
|
|
is "gotest.tools/v3/assert/cmp"
|
|
|
|
"gotest.tools/v3/poll"
|
|
|
|
"gotest.tools/v3/skip"
|
2018-02-09 16:44:28 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestConfigList(t *testing.T) {
|
2018-04-19 05:14:15 -04:00
|
|
|
skip.If(t, testEnv.DaemonInfo.OSType == "windows")
|
2018-02-09 16:44:28 -05:00
|
|
|
|
|
|
|
defer setupTest(t)()
|
|
|
|
d := swarm.NewSwarm(t, testEnv)
|
|
|
|
defer d.Stop(t)
|
2018-04-13 11:02:56 -04:00
|
|
|
client := d.NewClientT(t)
|
|
|
|
defer client.Close()
|
2018-02-09 16:44:28 -05:00
|
|
|
|
|
|
|
ctx := context.Background()
|
|
|
|
|
2018-02-11 18:43:24 -05:00
|
|
|
// This test case is ported from the original TestConfigsEmptyList
|
|
|
|
configs, err := client.ConfigList(ctx, types.ConfigListOptions{})
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.Check(t, is.Equal(len(configs), 0))
|
2018-02-11 18:43:24 -05:00
|
|
|
|
2018-04-06 06:06:02 -04:00
|
|
|
testName0 := "test0-" + t.Name()
|
|
|
|
testName1 := "test1-" + t.Name()
|
2018-02-09 16:44:28 -05:00
|
|
|
testNames := []string{testName0, testName1}
|
|
|
|
sort.Strings(testNames)
|
|
|
|
|
|
|
|
// create config test0
|
|
|
|
createConfig(ctx, t, client, testName0, []byte("TESTINGDATA0"), map[string]string{"type": "test"})
|
|
|
|
|
|
|
|
config1ID := createConfig(ctx, t, client, testName1, []byte("TESTINGDATA1"), map[string]string{"type": "production"})
|
|
|
|
|
|
|
|
// test by `config ls`
|
|
|
|
entries, err := client.ConfigList(ctx, types.ConfigListOptions{})
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2018-07-13 17:29:02 -04:00
|
|
|
assert.Check(t, is.DeepEqual(configNamesFromList(entries), testNames))
|
2018-02-09 16:44:28 -05:00
|
|
|
|
|
|
|
testCases := []struct {
|
|
|
|
filters filters.Args
|
|
|
|
expected []string
|
|
|
|
}{
|
|
|
|
// test filter by name `config ls --filter name=xxx`
|
|
|
|
{
|
|
|
|
filters: filters.NewArgs(filters.Arg("name", testName0)),
|
|
|
|
expected: []string{testName0},
|
|
|
|
},
|
|
|
|
// test filter by id `config ls --filter id=xxx`
|
|
|
|
{
|
|
|
|
filters: filters.NewArgs(filters.Arg("id", config1ID)),
|
|
|
|
expected: []string{testName1},
|
|
|
|
},
|
|
|
|
// test filter by label `config ls --filter label=xxx`
|
|
|
|
{
|
|
|
|
filters: filters.NewArgs(filters.Arg("label", "type")),
|
|
|
|
expected: testNames,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
filters: filters.NewArgs(filters.Arg("label", "type=test")),
|
|
|
|
expected: []string{testName0},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
filters: filters.NewArgs(filters.Arg("label", "type=production")),
|
|
|
|
expected: []string{testName1},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tc := range testCases {
|
|
|
|
entries, err = client.ConfigList(ctx, types.ConfigListOptions{
|
|
|
|
Filters: tc.filters,
|
|
|
|
})
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2018-07-13 17:29:02 -04:00
|
|
|
assert.Check(t, is.DeepEqual(configNamesFromList(entries), tc.expected))
|
2018-02-09 16:44:28 -05:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func createConfig(ctx context.Context, t *testing.T, client client.APIClient, name string, data []byte, labels map[string]string) string {
|
|
|
|
config, err := client.ConfigCreate(ctx, swarmtypes.ConfigSpec{
|
|
|
|
Annotations: swarmtypes.Annotations{
|
|
|
|
Name: name,
|
|
|
|
Labels: labels,
|
|
|
|
},
|
|
|
|
Data: data,
|
|
|
|
})
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.Check(t, config.ID != "")
|
2018-02-09 16:44:28 -05:00
|
|
|
return config.ID
|
|
|
|
}
|
2018-02-11 18:43:24 -05:00
|
|
|
|
|
|
|
func TestConfigsCreateAndDelete(t *testing.T) {
|
2018-04-19 05:14:15 -04:00
|
|
|
skip.If(t, testEnv.DaemonInfo.OSType == "windows")
|
2018-02-11 18:43:24 -05:00
|
|
|
|
|
|
|
defer setupTest(t)()
|
|
|
|
d := swarm.NewSwarm(t, testEnv)
|
|
|
|
defer d.Stop(t)
|
2018-04-13 11:02:56 -04:00
|
|
|
client := d.NewClientT(t)
|
|
|
|
defer client.Close()
|
2018-02-11 18:43:24 -05:00
|
|
|
|
|
|
|
ctx := context.Background()
|
|
|
|
|
2018-04-06 06:06:02 -04:00
|
|
|
testName := "test_config-" + t.Name()
|
2018-02-11 18:43:24 -05:00
|
|
|
|
|
|
|
// This test case is ported from the original TestConfigsCreate
|
|
|
|
configID := createConfig(ctx, t, client, testName, []byte("TESTINGDATA"), nil)
|
|
|
|
|
|
|
|
insp, _, err := client.ConfigInspectWithRaw(ctx, configID)
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.Check(t, is.Equal(insp.Spec.Name, testName))
|
2018-02-11 18:43:24 -05:00
|
|
|
|
|
|
|
// This test case is ported from the original TestConfigsDelete
|
|
|
|
err = client.ConfigRemove(ctx, configID)
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2018-02-11 18:43:24 -05:00
|
|
|
|
|
|
|
insp, _, err = client.ConfigInspectWithRaw(ctx, configID)
|
2018-05-20 18:06:50 -04:00
|
|
|
assert.Check(t, is.ErrorContains(err, "No such config"))
|
2018-02-11 18:43:24 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfigsUpdate(t *testing.T) {
|
2018-04-19 05:14:15 -04:00
|
|
|
skip.If(t, testEnv.DaemonInfo.OSType == "windows")
|
2018-02-11 18:43:24 -05:00
|
|
|
|
|
|
|
defer setupTest(t)()
|
|
|
|
d := swarm.NewSwarm(t, testEnv)
|
|
|
|
defer d.Stop(t)
|
2018-04-13 11:02:56 -04:00
|
|
|
client := d.NewClientT(t)
|
|
|
|
defer client.Close()
|
2018-02-11 18:43:24 -05:00
|
|
|
|
|
|
|
ctx := context.Background()
|
|
|
|
|
2018-04-06 06:06:02 -04:00
|
|
|
testName := "test_config-" + t.Name()
|
2018-02-11 18:43:24 -05:00
|
|
|
|
|
|
|
// This test case is ported from the original TestConfigsCreate
|
|
|
|
configID := createConfig(ctx, t, client, testName, []byte("TESTINGDATA"), nil)
|
|
|
|
|
|
|
|
insp, _, err := client.ConfigInspectWithRaw(ctx, configID)
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.Check(t, is.Equal(insp.ID, configID))
|
2018-02-11 18:43:24 -05:00
|
|
|
|
|
|
|
// test UpdateConfig with full ID
|
|
|
|
insp.Spec.Labels = map[string]string{"test": "test1"}
|
|
|
|
err = client.ConfigUpdate(ctx, configID, insp.Version, insp.Spec)
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2018-02-11 18:43:24 -05:00
|
|
|
|
|
|
|
insp, _, err = client.ConfigInspectWithRaw(ctx, configID)
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.Check(t, is.Equal(insp.Spec.Labels["test"], "test1"))
|
2018-02-11 18:43:24 -05:00
|
|
|
|
|
|
|
// test UpdateConfig with full name
|
|
|
|
insp.Spec.Labels = map[string]string{"test": "test2"}
|
|
|
|
err = client.ConfigUpdate(ctx, testName, insp.Version, insp.Spec)
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2018-02-11 18:43:24 -05:00
|
|
|
|
|
|
|
insp, _, err = client.ConfigInspectWithRaw(ctx, configID)
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.Check(t, is.Equal(insp.Spec.Labels["test"], "test2"))
|
2018-02-11 18:43:24 -05:00
|
|
|
|
|
|
|
// test UpdateConfig with prefix ID
|
|
|
|
insp.Spec.Labels = map[string]string{"test": "test3"}
|
|
|
|
err = client.ConfigUpdate(ctx, configID[:1], insp.Version, insp.Spec)
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2018-02-11 18:43:24 -05:00
|
|
|
|
|
|
|
insp, _, err = client.ConfigInspectWithRaw(ctx, configID)
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.Check(t, is.Equal(insp.Spec.Labels["test"], "test3"))
|
2018-02-11 18:43:24 -05:00
|
|
|
|
|
|
|
// test UpdateConfig in updating Data which is not supported in daemon
|
|
|
|
// this test will produce an error in func UpdateConfig
|
|
|
|
insp.Spec.Data = []byte("TESTINGDATA2")
|
|
|
|
err = client.ConfigUpdate(ctx, configID, insp.Version, insp.Spec)
|
2018-05-20 18:06:50 -04:00
|
|
|
assert.Check(t, is.ErrorContains(err, "only updates to Labels are allowed"))
|
2018-02-11 18:43:24 -05:00
|
|
|
}
|
2017-06-15 15:06:08 -04:00
|
|
|
|
|
|
|
func TestTemplatedConfig(t *testing.T) {
|
2018-04-19 05:14:15 -04:00
|
|
|
skip.If(t, testEnv.DaemonInfo.OSType == "windows")
|
2017-06-15 15:06:08 -04:00
|
|
|
d := swarm.NewSwarm(t, testEnv)
|
|
|
|
defer d.Stop(t)
|
2018-04-13 11:02:56 -04:00
|
|
|
client := d.NewClientT(t)
|
|
|
|
defer client.Close()
|
2017-06-15 15:06:08 -04:00
|
|
|
ctx := context.Background()
|
|
|
|
|
2018-04-06 06:06:02 -04:00
|
|
|
referencedSecretName := "referencedsecret-" + t.Name()
|
2017-06-15 15:06:08 -04:00
|
|
|
referencedSecretSpec := swarmtypes.SecretSpec{
|
|
|
|
Annotations: swarmtypes.Annotations{
|
2018-04-06 06:06:02 -04:00
|
|
|
Name: referencedSecretName,
|
2017-06-15 15:06:08 -04:00
|
|
|
},
|
|
|
|
Data: []byte("this is a secret"),
|
|
|
|
}
|
|
|
|
referencedSecret, err := client.SecretCreate(ctx, referencedSecretSpec)
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.Check(t, err)
|
2017-06-15 15:06:08 -04:00
|
|
|
|
2018-04-06 06:06:02 -04:00
|
|
|
referencedConfigName := "referencedconfig-" + t.Name()
|
2017-06-15 15:06:08 -04:00
|
|
|
referencedConfigSpec := swarmtypes.ConfigSpec{
|
|
|
|
Annotations: swarmtypes.Annotations{
|
2018-04-06 06:06:02 -04:00
|
|
|
Name: referencedConfigName,
|
2017-06-15 15:06:08 -04:00
|
|
|
},
|
|
|
|
Data: []byte("this is a config"),
|
|
|
|
}
|
|
|
|
referencedConfig, err := client.ConfigCreate(ctx, referencedConfigSpec)
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.Check(t, err)
|
2017-06-15 15:06:08 -04:00
|
|
|
|
2018-04-06 06:06:02 -04:00
|
|
|
templatedConfigName := "templated_config-" + t.Name()
|
2017-06-15 15:06:08 -04:00
|
|
|
configSpec := swarmtypes.ConfigSpec{
|
|
|
|
Annotations: swarmtypes.Annotations{
|
2018-04-06 06:06:02 -04:00
|
|
|
Name: templatedConfigName,
|
2017-06-15 15:06:08 -04:00
|
|
|
},
|
|
|
|
Templating: &swarmtypes.Driver{
|
|
|
|
Name: "golang",
|
|
|
|
},
|
|
|
|
Data: []byte("SERVICE_NAME={{.Service.Name}}\n" +
|
|
|
|
"{{secret \"referencedsecrettarget\"}}\n" +
|
|
|
|
"{{config \"referencedconfigtarget\"}}\n"),
|
|
|
|
}
|
|
|
|
|
|
|
|
templatedConfig, err := client.ConfigCreate(ctx, configSpec)
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.Check(t, err)
|
2017-06-15 15:06:08 -04:00
|
|
|
|
|
|
|
serviceID := swarm.CreateService(t, d,
|
|
|
|
swarm.ServiceWithConfig(
|
|
|
|
&swarmtypes.ConfigReference{
|
|
|
|
File: &swarmtypes.ConfigReferenceFileTarget{
|
2018-04-06 06:06:02 -04:00
|
|
|
Name: "/" + templatedConfigName,
|
2017-06-15 15:06:08 -04:00
|
|
|
UID: "0",
|
|
|
|
GID: "0",
|
|
|
|
Mode: 0600,
|
|
|
|
},
|
|
|
|
ConfigID: templatedConfig.ID,
|
2018-04-06 06:06:02 -04:00
|
|
|
ConfigName: templatedConfigName,
|
2017-06-15 15:06:08 -04:00
|
|
|
},
|
|
|
|
),
|
|
|
|
swarm.ServiceWithConfig(
|
|
|
|
&swarmtypes.ConfigReference{
|
|
|
|
File: &swarmtypes.ConfigReferenceFileTarget{
|
|
|
|
Name: "referencedconfigtarget",
|
|
|
|
UID: "0",
|
|
|
|
GID: "0",
|
|
|
|
Mode: 0600,
|
|
|
|
},
|
|
|
|
ConfigID: referencedConfig.ID,
|
2018-04-06 06:06:02 -04:00
|
|
|
ConfigName: referencedConfigName,
|
2017-06-15 15:06:08 -04:00
|
|
|
},
|
|
|
|
),
|
|
|
|
swarm.ServiceWithSecret(
|
|
|
|
&swarmtypes.SecretReference{
|
|
|
|
File: &swarmtypes.SecretReferenceFileTarget{
|
|
|
|
Name: "referencedsecrettarget",
|
|
|
|
UID: "0",
|
|
|
|
GID: "0",
|
|
|
|
Mode: 0600,
|
|
|
|
},
|
|
|
|
SecretID: referencedSecret.ID,
|
2018-04-06 06:06:02 -04:00
|
|
|
SecretName: referencedSecretName,
|
2017-06-15 15:06:08 -04:00
|
|
|
},
|
|
|
|
),
|
|
|
|
swarm.ServiceWithName("svc"),
|
|
|
|
)
|
|
|
|
|
|
|
|
var tasks []swarmtypes.Task
|
2019-01-14 22:54:52 -05:00
|
|
|
getRunningTasks := func(log poll.LogT) poll.Result {
|
2019-01-13 15:15:34 -05:00
|
|
|
tasks = swarm.GetRunningTasks(t, client, serviceID)
|
2019-01-14 22:54:52 -05:00
|
|
|
if len(tasks) > 0 {
|
|
|
|
return poll.Success()
|
|
|
|
}
|
|
|
|
return poll.Continue("task still waiting")
|
|
|
|
}
|
|
|
|
poll.WaitOn(t, getRunningTasks, swarm.ServicePoll, poll.WithTimeout(1*time.Minute))
|
2017-06-15 15:06:08 -04:00
|
|
|
|
|
|
|
task := tasks[0]
|
2019-01-14 22:54:52 -05:00
|
|
|
getTask := func(log poll.LogT) poll.Result {
|
2017-06-15 15:06:08 -04:00
|
|
|
if task.NodeID == "" || (task.Status.ContainerStatus == nil || task.Status.ContainerStatus.ContainerID == "") {
|
|
|
|
task, _, _ = client.TaskInspectWithRaw(context.Background(), task.ID)
|
|
|
|
}
|
2019-01-14 22:54:52 -05:00
|
|
|
if task.NodeID != "" && task.Status.ContainerStatus != nil && task.Status.ContainerStatus.ContainerID != "" {
|
|
|
|
return poll.Success()
|
|
|
|
}
|
|
|
|
return poll.Continue("task still waiting")
|
|
|
|
}
|
|
|
|
poll.WaitOn(t, getTask, swarm.ServicePoll, poll.WithTimeout(1*time.Minute))
|
2017-06-15 15:06:08 -04:00
|
|
|
|
|
|
|
attach := swarm.ExecTask(t, d, task, types.ExecConfig{
|
2018-04-06 06:06:02 -04:00
|
|
|
Cmd: []string{"/bin/cat", "/" + templatedConfigName},
|
2017-06-15 15:06:08 -04:00
|
|
|
AttachStdout: true,
|
|
|
|
AttachStderr: true,
|
|
|
|
})
|
|
|
|
|
|
|
|
expect := "SERVICE_NAME=svc\n" +
|
|
|
|
"this is a secret\n" +
|
|
|
|
"this is a config\n"
|
2018-01-17 10:49:58 -05:00
|
|
|
assertAttachedStream(t, attach, expect)
|
|
|
|
|
|
|
|
attach = swarm.ExecTask(t, d, task, types.ExecConfig{
|
|
|
|
Cmd: []string{"mount"},
|
|
|
|
AttachStdout: true,
|
|
|
|
AttachStderr: true,
|
|
|
|
})
|
2018-04-06 06:06:02 -04:00
|
|
|
assertAttachedStream(t, attach, "tmpfs on /"+templatedConfigName+" type tmpfs")
|
2018-01-17 10:49:58 -05:00
|
|
|
}
|
2017-06-15 15:06:08 -04:00
|
|
|
|
2018-01-17 10:49:58 -05:00
|
|
|
func assertAttachedStream(t *testing.T, attach types.HijackedResponse, expect string) {
|
|
|
|
buf := bytes.NewBuffer(nil)
|
|
|
|
_, err := stdcopy.StdCopy(buf, buf, attach.Reader)
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.Check(t, is.Contains(buf.String(), expect))
|
2017-06-15 15:06:08 -04:00
|
|
|
}
|
|
|
|
|
2018-02-26 18:23:18 -05:00
|
|
|
func TestConfigInspect(t *testing.T) {
|
2018-04-19 05:14:15 -04:00
|
|
|
skip.If(t, testEnv.DaemonInfo.OSType == "windows")
|
2018-02-26 18:23:18 -05:00
|
|
|
|
|
|
|
defer setupTest(t)()
|
|
|
|
d := swarm.NewSwarm(t, testEnv)
|
|
|
|
defer d.Stop(t)
|
2018-04-13 11:02:56 -04:00
|
|
|
client := d.NewClientT(t)
|
|
|
|
defer client.Close()
|
2018-02-26 18:23:18 -05:00
|
|
|
|
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
testName := t.Name()
|
|
|
|
configID := createConfig(ctx, t, client, testName, []byte("TESTINGDATA"), nil)
|
|
|
|
|
|
|
|
insp, body, err := client.ConfigInspectWithRaw(ctx, configID)
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.Check(t, is.Equal(insp.Spec.Name, testName))
|
2018-02-26 18:23:18 -05:00
|
|
|
|
|
|
|
var config swarmtypes.Config
|
|
|
|
err = json.Unmarshal(body, &config)
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.Check(t, is.DeepEqual(config, insp))
|
2018-02-26 18:23:18 -05:00
|
|
|
}
|
2018-07-13 17:29:02 -04:00
|
|
|
|
|
|
|
func TestConfigCreateWithLabels(t *testing.T) {
|
|
|
|
skip.If(t, testEnv.DaemonInfo.OSType != "linux")
|
|
|
|
|
|
|
|
defer setupTest(t)()
|
|
|
|
d := swarm.NewSwarm(t, testEnv)
|
|
|
|
defer d.Stop(t)
|
|
|
|
client := d.NewClientT(t)
|
|
|
|
defer client.Close()
|
|
|
|
|
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
labels := map[string]string{
|
|
|
|
"key1": "value1",
|
|
|
|
"key2": "value2",
|
|
|
|
}
|
|
|
|
testName := t.Name()
|
|
|
|
configID := createConfig(ctx, t, client, testName, []byte("TESTINGDATA"), labels)
|
|
|
|
|
|
|
|
insp, _, err := client.ConfigInspectWithRaw(ctx, configID)
|
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.Check(t, is.Equal(insp.Spec.Name, testName))
|
|
|
|
assert.Check(t, is.Equal(2, len(insp.Spec.Labels)))
|
|
|
|
assert.Check(t, is.Equal("value1", insp.Spec.Labels["key1"]))
|
|
|
|
assert.Check(t, is.Equal("value2", insp.Spec.Labels["key2"]))
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test case for 28884
|
|
|
|
func TestConfigCreateResolve(t *testing.T) {
|
|
|
|
skip.If(t, testEnv.DaemonInfo.OSType != "linux")
|
|
|
|
|
|
|
|
defer setupTest(t)()
|
|
|
|
d := swarm.NewSwarm(t, testEnv)
|
|
|
|
defer d.Stop(t)
|
|
|
|
client := d.NewClientT(t)
|
|
|
|
defer client.Close()
|
|
|
|
|
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
configName := "test_config_" + t.Name()
|
|
|
|
|
|
|
|
configID := createConfig(ctx, t, client, configName, []byte("foo"), nil)
|
|
|
|
fakeName := configID
|
|
|
|
fakeID := createConfig(ctx, t, client, fakeName, []byte("fake foo"), nil)
|
|
|
|
|
|
|
|
entries, err := client.ConfigList(ctx, types.ConfigListOptions{})
|
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.Assert(t, is.Contains(configNamesFromList(entries), configName))
|
|
|
|
assert.Assert(t, is.Contains(configNamesFromList(entries), fakeName))
|
|
|
|
|
|
|
|
err = client.ConfigRemove(ctx, configID)
|
|
|
|
assert.NilError(t, err)
|
|
|
|
|
|
|
|
// Fake one will remain
|
|
|
|
entries, err = client.ConfigList(ctx, types.ConfigListOptions{})
|
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.Assert(t, is.DeepEqual(configNamesFromList(entries), []string{fakeName}))
|
|
|
|
|
|
|
|
// Remove based on name prefix of the fake one
|
|
|
|
// (which is the same as the ID of foo one) should not work
|
|
|
|
// as search is only done based on:
|
|
|
|
// - Full ID
|
|
|
|
// - Full Name
|
|
|
|
// - Partial ID (prefix)
|
|
|
|
err = client.ConfigRemove(ctx, configID[:5])
|
|
|
|
assert.Assert(t, nil != err)
|
|
|
|
entries, err = client.ConfigList(ctx, types.ConfigListOptions{})
|
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.Assert(t, is.DeepEqual(configNamesFromList(entries), []string{fakeName}))
|
|
|
|
|
|
|
|
// Remove based on ID prefix of the fake one should succeed
|
|
|
|
err = client.ConfigRemove(ctx, fakeID[:5])
|
|
|
|
assert.NilError(t, err)
|
|
|
|
entries, err = client.ConfigList(ctx, types.ConfigListOptions{})
|
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.Assert(t, is.Equal(0, len(entries)))
|
|
|
|
}
|
|
|
|
|
2019-06-15 00:59:07 -04:00
|
|
|
func TestConfigDaemonLibtrustID(t *testing.T) {
|
|
|
|
skip.If(t, testEnv.DaemonInfo.OSType != "linux")
|
|
|
|
defer setupTest(t)()
|
|
|
|
|
|
|
|
d := daemon.New(t)
|
|
|
|
defer d.Stop(t)
|
|
|
|
|
|
|
|
trustKey := filepath.Join(d.RootDir(), "key.json")
|
|
|
|
err := ioutil.WriteFile(trustKey, []byte(`{"crv":"P-256","d":"dm28PH4Z4EbyUN8L0bPonAciAQa1QJmmyYd876mnypY","kid":"WTJ3:YSIP:CE2E:G6KJ:PSBD:YX2Y:WEYD:M64G:NU2V:XPZV:H2CR:VLUB","kty":"EC","x":"Mh5-JINSjaa_EZdXDttri255Z5fbCEOTQIZjAcScFTk","y":"eUyuAjfxevb07hCCpvi4Zi334Dy4GDWQvEToGEX4exQ"}`), 0644)
|
|
|
|
assert.NilError(t, err)
|
|
|
|
|
|
|
|
config := filepath.Join(d.RootDir(), "daemon.json")
|
|
|
|
err = ioutil.WriteFile(config, []byte(`{"deprecated-key-path": "`+trustKey+`"}`), 0644)
|
|
|
|
assert.NilError(t, err)
|
|
|
|
|
|
|
|
d.Start(t, "--config-file", config)
|
|
|
|
info := d.Info(t)
|
|
|
|
assert.Equal(t, info.ID, "WTJ3:YSIP:CE2E:G6KJ:PSBD:YX2Y:WEYD:M64G:NU2V:XPZV:H2CR:VLUB")
|
|
|
|
}
|
|
|
|
|
2018-07-13 17:29:02 -04:00
|
|
|
func configNamesFromList(entries []swarmtypes.Config) []string {
|
|
|
|
var values []string
|
|
|
|
for _, entry := range entries {
|
|
|
|
values = append(values, entry.Spec.Name)
|
|
|
|
}
|
|
|
|
sort.Strings(values)
|
|
|
|
return values
|
|
|
|
}
|