157 lines
3.6 KiB
Go
157 lines
3.6 KiB
Go
package network
|
|
|
|
import (
|
|
"isle/bootstrap"
|
|
"isle/daemon/daecommon"
|
|
"isle/garage"
|
|
"isle/jsonutil"
|
|
"isle/nebula"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestCreate(t *testing.T) {
|
|
var (
|
|
h = newIntegrationHarness(t)
|
|
network = h.createNetwork(t, "primus", nil)
|
|
)
|
|
|
|
gotCreationParams, err := LoadCreationParams(network.stateDir)
|
|
assert.NoError(t, err)
|
|
assert.Equal(t, gotCreationParams, network.creationParams)
|
|
}
|
|
|
|
func TestLoad(t *testing.T) {
|
|
var (
|
|
h = newIntegrationHarness(t)
|
|
network = h.createNetwork(t, "primus", &createNetworkOpts{
|
|
manualShutdown: true,
|
|
})
|
|
)
|
|
|
|
t.Log("Shutting down network")
|
|
assert.NoError(t, network.Shutdown())
|
|
|
|
t.Log("Calling Load")
|
|
loadedNetwork, err := Load(
|
|
h.ctx,
|
|
h.logger.WithNamespace("loadedNetwork"),
|
|
network.networkConfig,
|
|
getEnvBinDirPath(),
|
|
network.stateDir,
|
|
h.mkDir(t, "runtime"),
|
|
network.opts,
|
|
)
|
|
assert.NoError(t, err)
|
|
|
|
t.Cleanup(func() {
|
|
t.Log("Shutting down loadedNetwork")
|
|
assert.NoError(t, loadedNetwork.Shutdown())
|
|
})
|
|
}
|
|
|
|
func TestJoin(t *testing.T) {
|
|
var (
|
|
h = newIntegrationHarness(t)
|
|
primus = h.createNetwork(t, "primus", nil)
|
|
secondus = h.joinNetwork(t, primus, "secondus", nil)
|
|
)
|
|
|
|
primusHosts, err := primus.GetHosts(h.ctx)
|
|
assert.NoError(t, err)
|
|
|
|
secondusHosts, err := secondus.GetHosts(h.ctx)
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, primusHosts, secondusHosts)
|
|
}
|
|
|
|
func TestNetwork_GetConfig(t *testing.T) {
|
|
var (
|
|
h = newIntegrationHarness(t)
|
|
network = h.createNetwork(t, "primus", nil)
|
|
)
|
|
|
|
config, err := network.GetConfig(h.ctx)
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, config, network.networkConfig)
|
|
}
|
|
|
|
func TestNetwork_SetConfig(t *testing.T) {
|
|
t.Run("adding storage alloc", func(t *testing.T) {
|
|
var (
|
|
h = newIntegrationHarness(t)
|
|
network = h.createNetwork(t, "primus", nil)
|
|
)
|
|
|
|
network.networkConfig.Storage.Allocations = append(
|
|
network.networkConfig.Storage.Allocations,
|
|
daecommon.ConfigStorageAllocation{
|
|
DataPath: h.mkDir(t, "data").Path,
|
|
MetaPath: h.mkDir(t, "meta").Path,
|
|
Capacity: 1,
|
|
S3APIPort: 4900,
|
|
RPCPort: 4901,
|
|
AdminPort: 4902,
|
|
},
|
|
)
|
|
|
|
assert.NoError(t, network.SetConfig(h.ctx, network.networkConfig))
|
|
|
|
// Check that the Host information was updated
|
|
newHosts, err := network.GetHosts(h.ctx)
|
|
assert.NoError(t, err)
|
|
|
|
newHostsByName := map[nebula.HostName]bootstrap.Host{}
|
|
for _, h := range newHosts {
|
|
newHostsByName[h.Name] = h
|
|
}
|
|
|
|
newHost, ok := newHostsByName[network.hostName]
|
|
assert.True(t, ok)
|
|
|
|
allocs := newHost.HostConfigured.Garage.Instances
|
|
assert.Len(t, allocs, 4)
|
|
|
|
newAlloc := allocs[3]
|
|
assert.NotEmpty(t, newAlloc.ID)
|
|
newAlloc.ID = ""
|
|
assert.Equal(t, bootstrap.GarageHostInstance{
|
|
S3APIPort: 4900,
|
|
RPCPort: 4901,
|
|
}, newAlloc)
|
|
|
|
// Check that the bootstrap file was written with the new host config
|
|
var storedBootstrap bootstrap.Bootstrap
|
|
assert.NoError(t, jsonutil.LoadFile(
|
|
&storedBootstrap, bootstrap.StateDirPath(network.stateDir.Path),
|
|
))
|
|
assert.Equal(t, newHostsByName, storedBootstrap.Hosts)
|
|
|
|
// Check that garage layout contains the new allocation
|
|
garageAdminClient := newGarageAdminClient(
|
|
h.logger,
|
|
network.networkConfig,
|
|
network.opts.GarageAdminToken,
|
|
storedBootstrap,
|
|
)
|
|
|
|
layout, err := garageAdminClient.GetLayout(h.ctx)
|
|
assert.NoError(t, err)
|
|
|
|
expPeers := make([]garage.PeerLayout, len(allocs))
|
|
for i := range allocs {
|
|
expPeers[i] = garage.PeerLayout{
|
|
ID: allocs[i].ID,
|
|
Capacity: 1_000_000_000,
|
|
Zone: string(network.hostName),
|
|
Tags: []string{},
|
|
}
|
|
}
|
|
|
|
assert.ElementsMatch(t, expPeers, layout.Peers)
|
|
})
|
|
}
|