-
Notifications
You must be signed in to change notification settings - Fork 931
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Notifier update; MemberState update (#14294)
This includes preparatory changes as described in #14247: - Notifier improvements - Use `state.ServerClustered` - Don't query for `OfflineThreshold` unless needed (see commit msg) - Allow passing `db.NodeInfo` to `NewNotifier` - Pass `db.NodeInfo` to the notifier hook to reduce the need for extra http calls for basic info (like the target server's name) - Member state updates - Add `CPUThreads` to `ClusterMemberSysInfo` (name tbd) - Refactor `MemberState` to expose local `ClusterMemberSysinfo` - Implement helper to collect member state from all cluster members, using the notifier improvements above - Other odds and ends Performance improvements for project limits will be in a separate PR.
- Loading branch information
Showing
26 changed files
with
316 additions
and
119 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
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 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,77 @@ | ||
package cluster_test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/canonical/lxd/lxd/cluster" | ||
"github.com/canonical/lxd/lxd/db" | ||
"github.com/canonical/lxd/lxd/node" | ||
"github.com/canonical/lxd/lxd/state" | ||
"github.com/canonical/lxd/shared" | ||
) | ||
|
||
func TestClusterState(t *testing.T) { | ||
state, cleanup := state.NewTestState(t) | ||
defer cleanup() | ||
|
||
cert := shared.TestingKeyPair() | ||
|
||
state.ServerCert = func() *shared.CertInfo { return cert } | ||
|
||
f := notifyFixtures{t: t, state: state} | ||
cleanupF := f.Nodes(cert, 3) | ||
defer cleanupF() | ||
|
||
// Populate state.LocalConfig after nodes created above. | ||
var err error | ||
var nodeConfig *node.Config | ||
err = state.DB.Node.Transaction(context.TODO(), func(ctx context.Context, tx *db.NodeTx) error { | ||
nodeConfig, err = node.ConfigLoad(ctx, tx) | ||
return err | ||
}) | ||
require.NoError(t, err) | ||
|
||
state.LocalConfig = nodeConfig | ||
|
||
states, err := cluster.ClusterState(state, cert) | ||
require.NoError(t, err) | ||
|
||
assert.Equal(t, 3, len(states)) | ||
|
||
for clusterMemberName, state := range states { | ||
// Local cluster member | ||
if clusterMemberName == "0" { | ||
assert.Greater(t, state.SysInfo.LogicalCPUs, uint64(0)) | ||
continue | ||
} | ||
|
||
assert.Equal(t, uint64(24), state.SysInfo.LogicalCPUs) | ||
} | ||
|
||
var members []db.NodeInfo | ||
err = state.DB.Cluster.Transaction(context.TODO(), func(ctx context.Context, tx *db.ClusterTx) error { | ||
members, err = tx.GetNodes(ctx) | ||
return err | ||
}) | ||
require.NoError(t, err) | ||
|
||
for i, memberInfo := range members { | ||
if memberInfo.Name == "0" { | ||
members[i] = members[len(members)-1] | ||
members = members[:len(members)-1] | ||
break | ||
} | ||
} | ||
|
||
states, err = cluster.ClusterState(state, cert, members...) | ||
require.NoError(t, err) | ||
|
||
assert.Equal(t, 2, len(states)) | ||
for _, state := range states { | ||
assert.Equal(t, uint64(24), state.SysInfo.LogicalCPUs) | ||
} | ||
} |
Oops, something went wrong.