mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-08-05 05:24:16 -04:00
AB#2260 Refactor disk-mapper recovery (#82)
* Refactor disk-mapper recovery * Adapt constellation recover command to use new disk-mapper recovery API * Fix Cilium connectivity on rebooting nodes (#89) * Lower CoreDNS reschedule timeout to 10 seconds (#93) Signed-off-by: Daniel Weiße <dw@edgeless.systems>
This commit is contained in:
parent
a7b20b2a11
commit
8cb155d5c5
40 changed files with 1600 additions and 1130 deletions
98
disk-mapper/internal/test/integration_test.go
Normal file
98
disk-mapper/internal/test/integration_test.go
Normal file
|
@ -0,0 +1,98 @@
|
|||
//go:build integration
|
||||
|
||||
/*
|
||||
Copyright (c) Edgeless Systems GmbH
|
||||
|
||||
SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
package integration
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"testing"
|
||||
|
||||
"github.com/edgelesssys/constellation/disk-mapper/internal/mapper"
|
||||
"github.com/edgelesssys/constellation/internal/logger"
|
||||
"github.com/martinjungblut/go-cryptsetup"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"go.uber.org/goleak"
|
||||
)
|
||||
|
||||
const (
|
||||
devicePath = "testDevice"
|
||||
mappedDevice = "mappedDevice"
|
||||
)
|
||||
|
||||
var diskPath = flag.String("disk", "", "Path to the disk to use for the benchmark")
|
||||
|
||||
func setup(sizeGB int) error {
|
||||
return exec.Command("/bin/dd", "if=/dev/random", fmt.Sprintf("of=%s", devicePath), "bs=1G", fmt.Sprintf("count=%d", sizeGB)).Run()
|
||||
}
|
||||
|
||||
func teardown() error {
|
||||
return exec.Command("/bin/rm", "-f", devicePath).Run()
|
||||
}
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
flag.Parse()
|
||||
|
||||
if os.Getuid() != 0 {
|
||||
fmt.Printf("This test suite requires root privileges, as libcrypsetup uses the kernel's device mapper.\n")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
goleak.VerifyTestMain(m,
|
||||
// https://github.com/census-instrumentation/opencensus-go/issues/1262
|
||||
goleak.IgnoreTopFunction("go.opencensus.io/stats/view.(*worker).start"),
|
||||
)
|
||||
|
||||
result := m.Run()
|
||||
os.Exit(result)
|
||||
}
|
||||
|
||||
func TestMapper(t *testing.T) {
|
||||
cryptsetup.SetDebugLevel(cryptsetup.CRYPT_LOG_ERROR)
|
||||
cryptsetup.SetLogCallback(func(_ int, message string) { fmt.Println(message) })
|
||||
|
||||
assert := assert.New(t)
|
||||
require := require.New(t)
|
||||
require.NoError(setup(1), "failed to setup test disk")
|
||||
defer func() { require.NoError(teardown(), "failed to delete test disk") }()
|
||||
|
||||
mapper, err := mapper.New(devicePath, logger.NewTest(t))
|
||||
require.NoError(err, "failed to initialize crypt device")
|
||||
defer func() { require.NoError(mapper.Close(), "failed to close crypt device") }()
|
||||
|
||||
assert.False(mapper.IsLUKSDevice())
|
||||
|
||||
// Format and map disk
|
||||
passphrase := "unit-test"
|
||||
require.NoError(mapper.FormatDisk(passphrase), "failed to format disk")
|
||||
require.NoError(mapper.MapDisk(mappedDevice, passphrase), "failed to map disk")
|
||||
require.NoError(mapper.UnmapDisk(mappedDevice), "failed to remove disk mapping")
|
||||
|
||||
assert.True(mapper.IsLUKSDevice())
|
||||
|
||||
// Try to map disk with incorrect passphrase
|
||||
assert.Error(mapper.MapDisk(mappedDevice, "invalid-passphrase"), "was able to map disk with incorrect passphrase")
|
||||
}
|
||||
|
||||
/*
|
||||
type fakeMetadataAPI struct{}
|
||||
|
||||
func (f *fakeMetadataAPI) List(ctx context.Context) ([]metadata.InstanceMetadata, error) {
|
||||
return []metadata.InstanceMetadata{
|
||||
{
|
||||
Name: "instanceName",
|
||||
ProviderID: "fake://instance-id",
|
||||
Role: role.Unknown,
|
||||
VPCIP: "192.0.2.1",
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
*/
|
Loading…
Add table
Add a link
Reference in a new issue