forked from hashicorp/vault
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added etcd server container to run etcd3 tests automatically. * Removed etcd2 test case: it fails the backend tests but the failure is unrelated to the uplift. The etcd2 backend implementation does not remove empty nested nodes when removing leaf (see comments in hashicorp#11980). Signed-off-by: Tero Saarni <tero.saarni@est.tech>
- Loading branch information
Showing
9 changed files
with
189 additions
and
218 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```release-note:improvement | ||
physical/etcd: Upgrade etcd3 client to v3.5.0 and etcd2 to v2.305.0 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package etcd | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net/url" | ||
"os" | ||
"testing" | ||
"time" | ||
|
||
"github.com/hashicorp/vault/helper/testhelpers/docker" | ||
clientv3 "go.etcd.io/etcd/client/v3" | ||
) | ||
|
||
type Config struct { | ||
docker.ServiceURL | ||
} | ||
|
||
// PrepareTestContainer creates etcd docker container. If environment variabe | ||
// ETCD_ADDR is set, the tests are executed against specified address and etcd | ||
// container is not launched. | ||
func PrepareTestContainer(t *testing.T, version string) (func(), *Config) { | ||
if addr := os.Getenv("ETCD_ADDR"); addr != "" { | ||
url, err := docker.NewServiceURLParse(addr) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
return func() {}, &Config{ServiceURL: *url} | ||
} | ||
|
||
// Check https://github.com/etcd-io/etcd/releases for latest releases. | ||
runner, err := docker.NewServiceRunner(docker.RunOptions{ | ||
ContainerName: "etcd", | ||
ImageRepo: "gcr.io/etcd-development/etcd", | ||
ImageTag: version, | ||
Cmd: []string{"/usr/local/bin/etcd", | ||
"--name", "s1", | ||
"--listen-client-urls", "http://0.0.0.0:2379", | ||
"--advertise-client-urls", "http://0.0.0.0:2379", | ||
"--listen-peer-urls", "http://0.0.0.0:2380", | ||
"--initial-advertise-peer-urls", "http://0.0.0.0:2380", | ||
"--initial-cluster", "s1=http://0.0.0.0:2380", | ||
"--initial-cluster-token", "tkn", | ||
"--initial-cluster-state", "new", | ||
"--log-level", "info", | ||
"--logger", "zap", | ||
"--log-outputs", "stderr", | ||
}, | ||
Ports: []string{"2379/tcp"}, | ||
}) | ||
if err != nil { | ||
t.Fatalf("Could not start docker etcd container: %s", err) | ||
} | ||
|
||
svc, err := runner.StartService(context.Background(), func(ctx context.Context, host string, port int) (docker.ServiceConfig, error) { | ||
address := fmt.Sprintf("%s:%d", host, port) | ||
s := docker.NewServiceURL(url.URL{ | ||
Scheme: "http", | ||
Host: address, | ||
}) | ||
|
||
client, err := clientv3.New(clientv3.Config{ | ||
Endpoints: []string{address}, | ||
DialTimeout: 2 * time.Minute, | ||
}) | ||
if err != nil { | ||
return nil, fmt.Errorf("could not connect to etcd container: %w", err) | ||
} | ||
|
||
// Enable authentication for the tests. | ||
client.RoleAdd(ctx, "root") | ||
client.UserAdd(ctx, "root", "insecure") | ||
client.UserGrantRole(ctx, "root", "root") | ||
client.AuthEnable(ctx) | ||
client.Close() | ||
|
||
return &Config{ | ||
ServiceURL: *s, | ||
}, nil | ||
}) | ||
if err != nil { | ||
t.Fatalf("Could not start docker etcd container: %s", err) | ||
} | ||
|
||
return svc.Cleanup, svc.Config.(*Config) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.