Skip to content

Commit e49fadc

Browse files
committed
[#2475] Rename a struct
1 parent 4189b7e commit e49fadc

2 files changed

Lines changed: 24 additions & 23 deletions

File tree

backend/server/daemons/kea/configdatabaseiterator.go

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@ import (
1111
dbmodel "isc.org/stork/server/database/model"
1212
)
1313

14-
// Uniquely identifies a cb_cmds config-backend target. Two daemons that share
15-
// the same config database will have the same configBackendKey and therefore
16-
// receive only one remote-subnet*-set command with multiple
17-
// server tags, instead of one command per daemon.
18-
type configBackendKey struct {
14+
// Uniquely identifies a configuration target (the Config Backend database or
15+
// daemon configuration). Two daemons that share the same CB database will
16+
// have the same configTargetKey and therefore receive only one
17+
// remote-subnet*-set command with multiple server tags, instead of one command
18+
// per daemon.
19+
type configTargetKey struct {
1920
// These fields should be filled for daemons using cb_cmds hook. Otherwise,
2021
// they must be left empty.
2122
DBName string
@@ -26,20 +27,20 @@ type configBackendKey struct {
2627
DaemonID int64
2728
}
2829

29-
// Constructs a configBackendKey for a local subnet's cb_cmds daemon.
30+
// Constructs a configTargetKey for a local subnet's cb_cmds daemon.
3031
// The daemon's config databases list must not be empty.
31-
func buildConfigBackendKey(daemon *dbmodel.Daemon) (configBackendKey, error) {
32+
func buildConfigTargetKey(daemon *dbmodel.Daemon) (configTargetKey, error) {
3233
config := daemon.KeaDaemon.Config
3334

3435
dbs := config.GetAllDatabases().Config
3536
if len(dbs) == 0 {
36-
return configBackendKey{}, errors.Errorf(
37+
return configTargetKey{}, errors.Errorf(
3738
"daemon [%d] has libdhcp_cb_cmds loaded but no config databases configured",
3839
daemon.ID,
3940
)
4041
}
4142
db := dbs[0]
42-
return configBackendKey{
43+
return configTargetKey{
4344
DBName: db.Name,
4445
DBHost: db.Host,
4546
DBPort: db.Port,
@@ -66,18 +67,18 @@ func forEachUniqueConfigSource(
6667
localSubnets []*dbmodel.LocalSubnet,
6768
fn func(localSubnets []*dbmodel.LocalSubnet) error,
6869
) error {
69-
localSubnetsByBackend := map[configBackendKey][]*dbmodel.LocalSubnet{}
70+
localSubnetsByBackend := map[configTargetKey][]*dbmodel.LocalSubnet{}
7071

7172
for _, ls := range localSubnets {
7273
hook := ls.Daemon.KeaDaemon.Config.GetHookLibraries().GetSubnetAndSharedNetworkAlteringHookLibrary()
7374
switch hook {
7475
case keaconfig.SubnetAndSharedNetworkAlteringHookLibrarySubnetCmds:
75-
// For non-cb_cmds daemons, the config source is the daemon config,
76+
// For non-cb_cmds daemons, the config target is the daemon config,
7677
// they are not grouped.
77-
key := configBackendKey{DaemonID: ls.DaemonID}
78+
key := configTargetKey{DaemonID: ls.DaemonID}
7879
localSubnetsByBackend[key] = []*dbmodel.LocalSubnet{ls}
7980
case keaconfig.SubnetAndSharedNetworkAlteringHookLibraryCBCmds:
80-
key, err := buildConfigBackendKey(ls.Daemon)
81+
key, err := buildConfigTargetKey(ls.Daemon)
8182
if err != nil {
8283
log.WithError(err).Warnf(
8384
"Skipping local subnet [%d] "+

backend/server/daemons/kea/configdatabaseiterator_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ import (
1111
storkutil "isc.org/stork/util"
1212
)
1313

14-
// Tests that config backend key fields are extracted correctly.
15-
func TestBuildConfigBackendKeyNoServerTag(t *testing.T) {
14+
// Tests that config target key fields are extracted correctly.
15+
func TestBuildConfigTargetKeyNoServerTag(t *testing.T) {
1616
// Arrange
1717
daemon := newTestDaemonWithConfig(t, daemonname.DHCPv4, nil, keaconfig.SubnetAndSharedNetworkAlteringHookLibraryCBCmds)
1818

1919
// Act
20-
id, err := buildConfigBackendKey(daemon)
20+
id, err := buildConfigTargetKey(daemon)
2121

2222
// Assert
2323
require.NoError(t, err)
@@ -26,13 +26,13 @@ func TestBuildConfigBackendKeyNoServerTag(t *testing.T) {
2626
require.EqualValues(t, 5432, id.DBPort)
2727
}
2828

29-
// Tests that the server tag is included in the config backend ID.
30-
func TestBuildConfigBackendIDWithServerTag(t *testing.T) {
29+
// Tests that the server tag is included in the config target key.
30+
func TestBuildConfigTargetKeyWithServerTag(t *testing.T) {
3131
// Arrange
3232
daemon := newTestDaemonWithConfig(t, daemonname.DHCPv4, storkutil.Ptr("server1"), keaconfig.SubnetAndSharedNetworkAlteringHookLibraryCBCmds)
3333

3434
// Act
35-
id, err := buildConfigBackendKey(daemon)
35+
id, err := buildConfigTargetKey(daemon)
3636

3737
// Assert
3838
require.NoError(t, err)
@@ -42,7 +42,7 @@ func TestBuildConfigBackendIDWithServerTag(t *testing.T) {
4242
}
4343

4444
// Tests that an error is returned when no config databases are configured.
45-
func TestBuildConfigBackendKeyNoConfigDB(t *testing.T) {
45+
func TestBuildConfigTargetKeyNoConfigDB(t *testing.T) {
4646
// Arrange
4747
daemon := &dbmodel.Daemon{
4848
Name: daemonname.DHCPv4,
@@ -53,14 +53,14 @@ func TestBuildConfigBackendKeyNoConfigDB(t *testing.T) {
5353
require.NoError(t, err)
5454

5555
// Act
56-
_, err = buildConfigBackendKey(daemon)
56+
_, err = buildConfigTargetKey(daemon)
5757

5858
// Assert
5959
require.ErrorContains(t, err, "no config databases configured")
6060
}
6161

62-
// Tests that target iterator groups daemons sharing the same config backend
63-
// and calls the callback exactly once for that backend. The daemons with the
62+
// Tests that target iterator groups daemons sharing the same config target
63+
// and calls the callback exactly once for that target. The daemons with the
6464
// subnet_cmds hook are not grouped. The daemons with no hooks or both hooks
6565
// are silently skipped.
6666
func TestForEachUniqueConfigSource(t *testing.T) {

0 commit comments

Comments
 (0)