Skip to content

Commit

Permalink
Merge branch 'main' of github.com:dragonflyoss/Dragonfly2 into releas…
Browse files Browse the repository at this point in the history
…e-2.0.9
  • Loading branch information
gaius-qi committed Apr 12, 2023
2 parents a2117ef + 0216655 commit 58af079
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 21 deletions.
2 changes: 1 addition & 1 deletion client/config/dynconfig_local.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func (d *dynconfigLocal) Deregister(l Observer) {

// Notify publishes new events to listeners.
func (d *dynconfigLocal) Notify() error {
var data *DynconfigData
data := &DynconfigData{}
for _, schedulerAddr := range d.config.Scheduler.NetAddrs {
addr := schedulerAddr.Addr
host, port, err := net.SplitHostPort(addr)
Expand Down
9 changes: 4 additions & 5 deletions client/config/peerhost.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,10 @@ func (p *DaemonOption) Validate() error {
if p.Scheduler.Manager.RefreshInterval == 0 {
return errors.New("manager refreshInterval is not specified")
}
return nil
}

if len(p.Scheduler.NetAddrs) == 0 {
return errors.New("empty schedulers and config server is not specified")
} else {
if len(p.Scheduler.NetAddrs) == 0 {
return errors.New("empty schedulers and config server is not specified")
}
}

if int64(p.Download.TotalRateLimit.Limit) < DefaultMinRate.ToNumber() {
Expand Down
7 changes: 0 additions & 7 deletions client/config/peerhost_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"golang.org/x/time/rate"

"d7y.io/dragonfly/v2/client/util"
"d7y.io/dragonfly/v2/pkg/dfnet"
"d7y.io/dragonfly/v2/pkg/net/fqdn"
"d7y.io/dragonfly/v2/pkg/rpc"
"d7y.io/dragonfly/v2/pkg/types"
Expand All @@ -48,12 +47,6 @@ var peerHostConfig = func() *DaemonOption {
},
},
},
NetAddrs: []dfnet.NetAddr{
{
Type: dfnet.TCP,
Addr: "127.0.0.1:8002",
},
},
ScheduleTimeout: util.Duration{Duration: DefaultScheduleTimeout},
},
Host: HostOption{
Expand Down
7 changes: 0 additions & 7 deletions client/config/peerhost_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"golang.org/x/time/rate"

"d7y.io/dragonfly/v2/client/util"
"d7y.io/dragonfly/v2/pkg/dfnet"
"d7y.io/dragonfly/v2/pkg/net/fqdn"
"d7y.io/dragonfly/v2/pkg/rpc"
"d7y.io/dragonfly/v2/pkg/types"
Expand All @@ -48,12 +47,6 @@ var peerHostConfig = func() *DaemonOption {
},
},
},
NetAddrs: []dfnet.NetAddr{
{
Type: dfnet.TCP,
Addr: "127.0.0.1:8002",
},
},
ScheduleTimeout: util.Duration{Duration: DefaultScheduleTimeout},
},
Host: HostOption{
Expand Down
63 changes: 62 additions & 1 deletion client/config/peerhost_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,14 @@ func TestPeerHostOption_Validate(t *testing.T) {
{
name: "valid config",
config: NewDaemonConfig(),
mock: func(cfg *DaemonConfig) {},
mock: func(cfg *DaemonConfig) {
cfg.Scheduler.NetAddrs = []dfnet.NetAddr{
{
Type: dfnet.TCP,
Addr: "127.0.0.1:8002",
},
}
},
expect: func(t *testing.T, err error) {
assert := assert.New(t)
assert.NoError(err)
Expand Down Expand Up @@ -585,6 +592,12 @@ func TestPeerHostOption_Validate(t *testing.T) {
name: "download rate limit must be greater",
config: NewDaemonConfig(),
mock: func(cfg *DaemonConfig) {
cfg.Scheduler.NetAddrs = []dfnet.NetAddr{
{
Type: dfnet.TCP,
Addr: "127.0.0.1:8002",
},
}
cfg.Download.TotalRateLimit.Limit = rate.Limit(10 * unit.MB)
},
expect: func(t *testing.T, err error) {
Expand All @@ -597,6 +610,12 @@ func TestPeerHostOption_Validate(t *testing.T) {
name: "upload rate limit must be greater",
config: NewDaemonConfig(),
mock: func(cfg *DaemonConfig) {
cfg.Scheduler.NetAddrs = []dfnet.NetAddr{
{
Type: dfnet.TCP,
Addr: "127.0.0.1:8002",
},
}
cfg.Upload.RateLimit.Limit = rate.Limit(10 * unit.MB)
},
expect: func(t *testing.T, err error) {
Expand All @@ -609,6 +628,12 @@ func TestPeerHostOption_Validate(t *testing.T) {
name: "max replicas must be greater than 0",
config: NewDaemonConfig(),
mock: func(cfg *DaemonConfig) {
cfg.Scheduler.NetAddrs = []dfnet.NetAddr{
{
Type: dfnet.TCP,
Addr: "127.0.0.1:8002",
},
}
cfg.ObjectStorage.Enable = true
cfg.ObjectStorage.MaxReplicas = 0
},
Expand All @@ -621,6 +646,12 @@ func TestPeerHostOption_Validate(t *testing.T) {
name: "reload interval too short, must great than 1 second",
config: NewDaemonConfig(),
mock: func(cfg *DaemonConfig) {
cfg.Scheduler.NetAddrs = []dfnet.NetAddr{
{
Type: dfnet.TCP,
Addr: "127.0.0.1:8002",
},
}
cfg.Reload.Interval.Duration = time.Millisecond
},
expect: func(t *testing.T, err error) {
Expand All @@ -632,6 +663,12 @@ func TestPeerHostOption_Validate(t *testing.T) {
name: "gcInterval must be greater than 0",
config: NewDaemonConfig(),
mock: func(cfg *DaemonConfig) {
cfg.Scheduler.NetAddrs = []dfnet.NetAddr{
{
Type: dfnet.TCP,
Addr: "127.0.0.1:8002",
},
}
cfg.GCInterval.Duration = 0
},
expect: func(t *testing.T, err error) {
Expand All @@ -643,6 +680,12 @@ func TestPeerHostOption_Validate(t *testing.T) {
name: "security requires parameter caCert",
config: NewDaemonConfig(),
mock: func(cfg *DaemonConfig) {
cfg.Scheduler.NetAddrs = []dfnet.NetAddr{
{
Type: dfnet.TCP,
Addr: "127.0.0.1:8002",
},
}
cfg.Security.AutoIssueCert = true
cfg.Security.CACert = ""
},
Expand All @@ -655,6 +698,12 @@ func TestPeerHostOption_Validate(t *testing.T) {
name: "certSpec requires parameter ipAddresses",
config: NewDaemonConfig(),
mock: func(cfg *DaemonConfig) {
cfg.Scheduler.NetAddrs = []dfnet.NetAddr{
{
Type: dfnet.TCP,
Addr: "127.0.0.1:8002",
},
}
cfg.Security.AutoIssueCert = true
cfg.Security.CACert = "test"
cfg.Security.CertSpec.IPAddresses = nil
Expand All @@ -668,6 +717,12 @@ func TestPeerHostOption_Validate(t *testing.T) {
name: "certSpec requires parameter dnsNames",
config: NewDaemonConfig(),
mock: func(cfg *DaemonConfig) {
cfg.Scheduler.NetAddrs = []dfnet.NetAddr{
{
Type: dfnet.TCP,
Addr: "127.0.0.1:8002",
},
}
cfg.Security.AutoIssueCert = true
cfg.Security.CACert = "test"
cfg.Security.CertSpec.IPAddresses = []net.IP{net.ParseIP("127.0.0.1")}
Expand All @@ -682,6 +737,12 @@ func TestPeerHostOption_Validate(t *testing.T) {
name: "certSpec requires parameter validityPeriod",
config: NewDaemonConfig(),
mock: func(cfg *DaemonConfig) {
cfg.Scheduler.NetAddrs = []dfnet.NetAddr{
{
Type: dfnet.TCP,
Addr: "127.0.0.1:8002",
},
}
cfg.Security.AutoIssueCert = true
cfg.Security.CACert = "testcert"
cfg.Security.CertSpec.ValidityPeriod = 0
Expand Down

0 comments on commit 58af079

Please sign in to comment.