mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Added test for DNSAgent reload
This commit is contained in:
committed by
Dan Christian Bogos
parent
e38875ab0c
commit
4fae6f8e87
@@ -510,6 +510,38 @@ func TestCGRConfigReloadERs(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestCGRConfigReloadDNSAgent(t *testing.T) {
|
||||
cfg, err := NewDefaultCGRConfig()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
cfg.SessionSCfg().Enabled = true
|
||||
var reply string
|
||||
if err = cfg.V1ReloadConfig(&ConfigReloadWithArgDispatcher{
|
||||
Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "dnsagent_reload"),
|
||||
Section: DNSAgentJson,
|
||||
}, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if reply != utils.OK {
|
||||
t.Errorf("Expected OK received: %s", reply)
|
||||
}
|
||||
expAttr := &DNSAgentCfg{
|
||||
Enabled: true,
|
||||
Listen: ":2053",
|
||||
ListenNet: "udp",
|
||||
SessionSConns: []*RemoteHost{
|
||||
&RemoteHost{
|
||||
Address: utils.MetaInternal,
|
||||
},
|
||||
},
|
||||
// Timezone string
|
||||
// RequestProcessors []*RequestProcessor
|
||||
}
|
||||
if !reflect.DeepEqual(expAttr, cfg.DNSAgentCfg()) {
|
||||
t.Errorf("Expected %s , received: %s ", utils.ToJSON(expAttr), utils.ToJSON(cfg.DNSAgentCfg()))
|
||||
}
|
||||
}
|
||||
|
||||
func TestCgrCfgV1ReloadConfigSection(t *testing.T) {
|
||||
for _, dir := range []string{"/tmp/ers/in", "/tmp/ers/out"} {
|
||||
if err := os.RemoveAll(dir); err != nil {
|
||||
|
||||
90
data/conf/samples/dnsagent_reload/cgrates.json
Normal file
90
data/conf/samples/dnsagent_reload/cgrates.json
Normal file
@@ -0,0 +1,90 @@
|
||||
{
|
||||
|
||||
// Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments
|
||||
// Copyright (C) ITsysCOM GmbH
|
||||
//
|
||||
// This file contains the default configuration hardcoded into CGRateS.
|
||||
// This is what you get when you load CGRateS with an empty configuration file.
|
||||
|
||||
|
||||
"general": {
|
||||
"log_level": 7, // control the level of messages logged (0-emerg to 7-debug)
|
||||
},
|
||||
|
||||
|
||||
"stor_db": {
|
||||
"db_password": "CGRateS.org",
|
||||
},
|
||||
|
||||
|
||||
"scheduler": {
|
||||
"enabled": true,
|
||||
"cdrs_conns": [
|
||||
{"address": "*internal"},
|
||||
],
|
||||
},
|
||||
|
||||
|
||||
"sessions": {
|
||||
"enabled": true,
|
||||
"attributes_conns": [
|
||||
{"address": "127.0.0.1:2012", "transport": "*json"}
|
||||
],
|
||||
"rals_conns": [
|
||||
{"address": "*internal"}
|
||||
],
|
||||
"cdrs_conns": [
|
||||
{"address": "*internal"}
|
||||
],
|
||||
"chargers_conns": [
|
||||
{"address": "*internal"}
|
||||
],
|
||||
"suppliers_conns": [
|
||||
{"address": "127.0.0.1:2012", "transport": "*json"}
|
||||
],
|
||||
},
|
||||
|
||||
|
||||
"rals": {
|
||||
"enabled": true,
|
||||
},
|
||||
|
||||
|
||||
"cdrs": {
|
||||
"enabled": true,
|
||||
"rals_conns": [
|
||||
{"address": "*internal"}
|
||||
],
|
||||
},
|
||||
|
||||
|
||||
"chargers": {
|
||||
"enabled": true,
|
||||
},
|
||||
|
||||
|
||||
"attributes": {
|
||||
"enabled": true,
|
||||
},
|
||||
|
||||
|
||||
"suppliers": {
|
||||
"enabled": true,
|
||||
},
|
||||
|
||||
|
||||
"dns_agent": {
|
||||
"enabled": true,
|
||||
"listen": ":2053",
|
||||
"sessions_conns": [
|
||||
{"address": "*internal"}
|
||||
],
|
||||
},
|
||||
|
||||
|
||||
"apier": {
|
||||
"scheduler_conns": [ // connections to SchedulerS for reloads
|
||||
{"address": "*internal"},
|
||||
],
|
||||
},
|
||||
}
|
||||
85
services/dnsagent_it_test.go
Normal file
85
services/dnsagent_it_test.go
Normal file
@@ -0,0 +1,85 @@
|
||||
// +build integration
|
||||
|
||||
/*
|
||||
Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments
|
||||
Copyright (C) ITsysCOM GmbH
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
package services
|
||||
|
||||
import (
|
||||
"path"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/cgrates/cgrates/config"
|
||||
"github.com/cgrates/cgrates/engine"
|
||||
"github.com/cgrates/cgrates/servmanager"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
"github.com/cgrates/rpcclient"
|
||||
)
|
||||
|
||||
func TestDNSAgentReload(t *testing.T) {
|
||||
cfg, err := config.NewDefaultCGRConfig()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
cfg.SessionSCfg().Enabled = true
|
||||
utils.Newlogger(utils.MetaSysLog, cfg.GeneralCfg().NodeID)
|
||||
utils.Logger.SetLogLevel(7)
|
||||
filterSChan := make(chan *engine.FilterS, 1)
|
||||
filterSChan <- nil
|
||||
engineShutdown := make(chan bool, 1)
|
||||
chS := engine.NewCacheS(cfg, nil)
|
||||
|
||||
cacheSChan := make(chan rpcclient.RpcClientConnection, 1)
|
||||
cacheSChan <- chS
|
||||
|
||||
server := utils.NewServer()
|
||||
srvMngr := servmanager.NewServiceManager(cfg /*dm*/, nil,
|
||||
/*cdrStorage*/ nil,
|
||||
/*loadStorage*/ nil, filterSChan,
|
||||
server, nil, engineShutdown)
|
||||
srvMngr.SetCacheS(chS)
|
||||
srv := NewDNSAgent()
|
||||
srvMngr.AddService(srv, NewSessionService(), &CacheService{connChan: cacheSChan})
|
||||
if err = srvMngr.StartServices(); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if srv.IsRunning() {
|
||||
t.Errorf("Expected service to be down")
|
||||
}
|
||||
var reply string
|
||||
if err := cfg.V1ReloadConfig(&config.ConfigReloadWithArgDispatcher{
|
||||
Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "dnsagent_reload"),
|
||||
Section: config.DNSAgentJson,
|
||||
}, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if reply != utils.OK {
|
||||
t.Errorf("Expecting OK ,received %s", reply)
|
||||
}
|
||||
time.Sleep(10 * time.Millisecond) //need to switch to gorutine
|
||||
if !srv.IsRunning() {
|
||||
t.Errorf("Expected service to be running")
|
||||
}
|
||||
cfg.DNSAgentCfg().Enabled = false
|
||||
cfg.GetReloadChan(config.DNSAgentJson) <- struct{}{}
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
if srv.IsRunning() {
|
||||
t.Errorf("Expected service to be down")
|
||||
}
|
||||
engineShutdown <- true
|
||||
time.Sleep(10 * time.Millisecond) // wait to stop session bijsonrpc server
|
||||
}
|
||||
Reference in New Issue
Block a user