2024-10-05 21:03:26 +00:00
|
|
|
package network
|
|
|
|
|
|
|
|
import (
|
2024-10-24 17:52:08 +00:00
|
|
|
"isle/bootstrap"
|
|
|
|
"isle/daemon/daecommon"
|
|
|
|
"isle/garage"
|
|
|
|
"isle/jsonutil"
|
|
|
|
"isle/nebula"
|
2024-10-05 21:03:26 +00:00
|
|
|
"testing"
|
2024-10-24 17:52:08 +00:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2024-10-05 21:03:26 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestCreate(t *testing.T) {
|
|
|
|
var (
|
2024-10-06 17:38:35 +00:00
|
|
|
h = newIntegrationHarness(t)
|
|
|
|
network = h.createNetwork(t, "primus", nil)
|
2024-10-05 21:03:26 +00:00
|
|
|
)
|
|
|
|
|
2024-10-07 20:41:46 +00:00
|
|
|
gotCreationParams, err := LoadCreationParams(network.stateDir)
|
2024-10-24 17:52:08 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, gotCreationParams, network.creationParams)
|
2024-10-05 21:03:26 +00:00
|
|
|
}
|
2024-10-07 20:41:46 +00:00
|
|
|
|
|
|
|
func TestLoad(t *testing.T) {
|
|
|
|
var (
|
|
|
|
h = newIntegrationHarness(t)
|
|
|
|
network = h.createNetwork(t, "primus", &createNetworkOpts{
|
|
|
|
manualShutdown: true,
|
|
|
|
})
|
|
|
|
)
|
|
|
|
|
|
|
|
t.Log("Shutting down network")
|
2024-10-24 17:52:08 +00:00
|
|
|
assert.NoError(t, network.Shutdown())
|
2024-10-07 20:41:46 +00:00
|
|
|
|
|
|
|
t.Log("Calling Load")
|
|
|
|
loadedNetwork, err := Load(
|
|
|
|
h.ctx,
|
|
|
|
h.logger.WithNamespace("loadedNetwork"),
|
|
|
|
network.networkConfig,
|
|
|
|
getEnvBinDirPath(),
|
|
|
|
network.stateDir,
|
|
|
|
h.mkDir(t, "runtime"),
|
|
|
|
network.opts,
|
|
|
|
)
|
2024-10-24 17:52:08 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2024-10-07 20:41:46 +00:00
|
|
|
t.Cleanup(func() {
|
|
|
|
t.Log("Shutting down loadedNetwork")
|
2024-10-24 17:52:08 +00:00
|
|
|
assert.NoError(t, loadedNetwork.Shutdown())
|
2024-10-07 20:41:46 +00:00
|
|
|
})
|
|
|
|
}
|
2024-10-14 10:12:43 +00:00
|
|
|
|
|
|
|
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)
|
2024-10-24 17:52:08 +00:00
|
|
|
assert.NoError(t, err)
|
2024-10-14 10:12:43 +00:00
|
|
|
|
|
|
|
secondusHosts, err := secondus.GetHosts(h.ctx)
|
2024-10-24 17:52:08 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
assert.Equal(t, primusHosts, secondusHosts)
|
2024-10-14 10:12:43 +00:00
|
|
|
}
|
2024-10-23 18:18:11 +00:00
|
|
|
|
|
|
|
func TestNetwork_GetConfig(t *testing.T) {
|
|
|
|
var (
|
|
|
|
h = newIntegrationHarness(t)
|
|
|
|
network = h.createNetwork(t, "primus", nil)
|
|
|
|
)
|
|
|
|
|
|
|
|
config, err := network.GetConfig(h.ctx)
|
2024-10-24 17:52:08 +00:00
|
|
|
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,
|
2024-10-23 18:18:11 +00:00
|
|
|
network.networkConfig,
|
2024-10-24 17:52:08 +00:00
|
|
|
network.opts.GarageAdminToken,
|
|
|
|
storedBootstrap,
|
2024-10-23 18:18:11 +00:00
|
|
|
)
|
2024-10-24 17:52:08 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
})
|
2024-10-23 18:18:11 +00:00
|
|
|
}
|