mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
DiameterAgent with mysql integration tests passing for full path
This commit is contained in:
@@ -172,8 +172,8 @@ func (ar *AgentRequest) SetFields(tplFlds []*config.FCTemplate) (err error) {
|
||||
prevNMItem := valSet[len(valSet)-1] // could be we need nil protection here
|
||||
*nMItm = *prevNMItem // inherit the particularities, ie AttributeName
|
||||
nMItm.Data = utils.IfaceAsString(prevNMItem.Data) + utils.IfaceAsString(out)
|
||||
valSet = valSet[:len(valSet)-1] // discard the last item since we have captured it in nmItem
|
||||
}
|
||||
valSet = valSet[:len(valSet)-1] // discard the last item
|
||||
}
|
||||
valSet = append(valSet, nMItm)
|
||||
switch fldPath[0] {
|
||||
|
||||
@@ -67,7 +67,6 @@ var (
|
||||
|
||||
// Test start here
|
||||
func TestDiamItTcp(t *testing.T) {
|
||||
engine.KillEngine(0)
|
||||
switch *dbType {
|
||||
case utils.MetaInternal:
|
||||
diamConfigDIR = "diamagent_internal"
|
||||
@@ -98,12 +97,10 @@ func TestDiamItDispatcher(t *testing.T) {
|
||||
for _, stest := range sTestsDiam {
|
||||
t.Run(diamConfigDIR, stest)
|
||||
}
|
||||
engine.KillEngine(100)
|
||||
isDispatcherActive = false
|
||||
}
|
||||
|
||||
func TestDiamItSctp(t *testing.T) {
|
||||
engine.KillEngine(0)
|
||||
switch *dbType {
|
||||
case utils.MetaInternal:
|
||||
diamConfigDIR = "diamsctpagent_internal"
|
||||
@@ -122,7 +119,6 @@ func TestDiamItSctp(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDiamItMaxConn(t *testing.T) {
|
||||
engine.KillEngine(0)
|
||||
switch *dbType {
|
||||
case utils.MetaInternal:
|
||||
diamConfigDIR = "diamagentmaxconn_internal"
|
||||
@@ -143,7 +139,6 @@ func TestDiamItMaxConn(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDiamItSessionDisconnect(t *testing.T) {
|
||||
engine.KillEngine(0)
|
||||
switch *dbType {
|
||||
case utils.MetaInternal:
|
||||
diamConfigDIR = "diamagent_internal"
|
||||
@@ -380,6 +375,7 @@ func testDiamItDryRun(t *testing.T) {
|
||||
} else if val != eVal {
|
||||
t.Errorf("expecting: %s, received: <%s>", eVal, val)
|
||||
}
|
||||
|
||||
eVal = "cgrates;1451911932;00082"
|
||||
if avps, err := msg.FindAVPsWithPath([]interface{}{"Session-Id"}, dict.UndefinedVendorID); err != nil {
|
||||
t.Error(err)
|
||||
|
||||
@@ -153,7 +153,8 @@ func (da *DiameterAgent) handleMessage(c diam.Conn, m *diam.Message) {
|
||||
utils.RemoteHost: c.RemoteAddr().String(),
|
||||
}
|
||||
// build the negative error answer
|
||||
diamErr, err := diamErr(m, diam.UnableToComply, reqVars,
|
||||
diamErr, err := diamErr(
|
||||
m, diam.UnableToComply, reqVars,
|
||||
da.cgrCfg.DiameterAgentCfg().Templates[utils.MetaErr],
|
||||
da.cgrCfg.GeneralCfg().DefaultTenant,
|
||||
da.cgrCfg.GeneralCfg().DefaultTimezone,
|
||||
@@ -248,7 +249,7 @@ func (da *DiameterAgent) processRequest(reqProcessor *config.RequestProcessor,
|
||||
reqProcessor.Filters, agReq); err != nil || !pass {
|
||||
return pass, err
|
||||
}
|
||||
if agReq.CGRRequest, err = agReq.AsNavigableMap(reqProcessor.RequestFields); err != nil {
|
||||
if err = agReq.SetFields(reqProcessor.RequestFields); err != nil {
|
||||
return
|
||||
}
|
||||
cgrEv := agReq.CGRRequest.AsCGREvent(agReq.Tenant, utils.NestingSep)
|
||||
@@ -406,10 +407,8 @@ func (da *DiameterAgent) processRequest(reqProcessor *config.RequestProcessor,
|
||||
agReq.CGRReply.Set([]string{utils.Error}, err.Error(), false, false)
|
||||
}
|
||||
}
|
||||
if nM, err := agReq.AsNavigableMap(reqProcessor.ReplyFields); err != nil {
|
||||
return false, err
|
||||
} else {
|
||||
agReq.Reply.Merge(nM)
|
||||
if err = agReq.SetFields(reqProcessor.ReplyFields); err != nil {
|
||||
return
|
||||
}
|
||||
if reqProcessor.Flags.HasKey(utils.MetaLog) {
|
||||
utils.Logger.Info(
|
||||
@@ -454,15 +453,16 @@ func (da *DiameterAgent) V1DisconnectSession(args utils.AttrDisconnectSession, r
|
||||
nil,
|
||||
da.cgrCfg.GeneralCfg().DefaultTenant,
|
||||
da.cgrCfg.GeneralCfg().DefaultTimezone, da.filterS, nil, nil)
|
||||
nM, err := aReq.AsNavigableMap(da.cgrCfg.DiameterAgentCfg().Templates[da.cgrCfg.DiameterAgentCfg().ASRTemplate])
|
||||
if err != nil {
|
||||
if err = aReq.SetFields(da.cgrCfg.DiameterAgentCfg().Templates[da.cgrCfg.DiameterAgentCfg().ASRTemplate]); err != nil {
|
||||
utils.Logger.Warning(
|
||||
fmt.Sprintf("<%s> cannot disconnect session with OriginID: <%s>, err: %s",
|
||||
utils.DiameterAgent, ssID, err.Error()))
|
||||
return utils.ErrServerError
|
||||
}
|
||||
m := diam.NewRequest(dmd.m.Header.CommandCode, dmd.m.Header.ApplicationID, dmd.m.Dictionary())
|
||||
if err = updateDiamMsgFromNavMap(m, nM, da.cgrCfg.GeneralCfg().DefaultTimezone); err != nil {
|
||||
m := diam.NewRequest(dmd.m.Header.CommandCode,
|
||||
dmd.m.Header.ApplicationID, dmd.m.Dictionary())
|
||||
if err = updateDiamMsgFromNavMap(m, aReq.diamreq,
|
||||
da.cgrCfg.GeneralCfg().DefaultTimezone); err != nil {
|
||||
utils.Logger.Warning(
|
||||
fmt.Sprintf("<%s> cannot disconnect session with OriginID: <%s>, err: %s",
|
||||
utils.DiameterAgent, ssID, err.Error()))
|
||||
|
||||
@@ -482,11 +482,10 @@ func diamErr(m *diam.Message, resCode uint32,
|
||||
config.NewNavigableMap(nil),
|
||||
config.NewNavigableMap(nil),
|
||||
nil, tnt, tmz, filterS, nil, nil)
|
||||
var rplyData *config.NavigableMap
|
||||
if rplyData, err = aReq.AsNavigableMap(tpl); err != nil {
|
||||
if err = aReq.SetFields(tpl); err != nil {
|
||||
return
|
||||
}
|
||||
return diamAnswer(m, resCode, true, rplyData, tmz)
|
||||
return diamAnswer(m, resCode, true, aReq.Reply, tmz)
|
||||
}
|
||||
|
||||
func diamBareErr(m *diam.Message, resCode uint32) (a *diam.Message) {
|
||||
|
||||
@@ -417,45 +417,45 @@ const CGRATES_CFG_JSON = `
|
||||
"asr_template": "", // enable AbortSession message being sent to client on DisconnectSession
|
||||
"templates":{ // default message templates
|
||||
"*err": [
|
||||
{"tag": "SessionId", "path": "Session-Id", "type": "*variable",
|
||||
{"tag": "SessionId", "path": "*rep.Session-Id", "type": "*variable",
|
||||
"value": "~*req.Session-Id", "mandatory": true},
|
||||
{"tag": "OriginHost", "path": "Origin-Host", "type": "*variable",
|
||||
{"tag": "OriginHost", "path": "*rep.Origin-Host", "type": "*variable",
|
||||
"value": "~*vars.OriginHost", "mandatory": true},
|
||||
{"tag": "OriginRealm", "path": "Origin-Realm", "type": "*variable",
|
||||
{"tag": "OriginRealm", "path": "*rep.Origin-Realm", "type": "*variable",
|
||||
"value": "~*vars.OriginRealm", "mandatory": true},
|
||||
],
|
||||
"*cca": [
|
||||
{"tag": "SessionId", "path": "Session-Id", "type": "*variable",
|
||||
{"tag": "SessionId", "path": "*rep.Session-Id", "type": "*variable",
|
||||
"value": "~*req.Session-Id", "mandatory": true},
|
||||
{"tag": "ResultCode", "path": "Result-Code", "type": "*constant",
|
||||
{"tag": "ResultCode", "path": "*rep.Result-Code", "type": "*constant",
|
||||
"value": "2001"},
|
||||
{"tag": "OriginHost", "path": "Origin-Host", "type": "*variable",
|
||||
{"tag": "OriginHost", "path": "*rep.Origin-Host", "type": "*variable",
|
||||
"value": "~*vars.OriginHost", "mandatory": true},
|
||||
{"tag": "OriginRealm", "path": "Origin-Realm", "type": "*variable",
|
||||
{"tag": "OriginRealm", "path": "*rep.Origin-Realm", "type": "*variable",
|
||||
"value": "~*vars.OriginRealm", "mandatory": true},
|
||||
{"tag": "AuthApplicationId", "path": "Auth-Application-Id", "type": "*variable",
|
||||
{"tag": "AuthApplicationId", "path": "*rep.Auth-Application-Id", "type": "*variable",
|
||||
"value": "~*vars.*appid", "mandatory": true},
|
||||
{"tag": "CCRequestType", "path": "CC-Request-Type", "type": "*variable",
|
||||
{"tag": "CCRequestType", "path": "*rep.CC-Request-Type", "type": "*variable",
|
||||
"value": "~*req.CC-Request-Type", "mandatory": true},
|
||||
{"tag": "CCRequestNumber", "path": "CC-Request-Number", "type": "*variable",
|
||||
{"tag": "CCRequestNumber", "path": "*rep.CC-Request-Number", "type": "*variable",
|
||||
"value": "~*req.CC-Request-Number", "mandatory": true},
|
||||
],
|
||||
"*asr": [
|
||||
{"tag": "SessionId", "path": "Session-Id", "type": "*variable",
|
||||
{"tag": "SessionId", "path": "*diamreq.Session-Id", "type": "*variable",
|
||||
"value": "~*req.Session-Id", "mandatory": true},
|
||||
{"tag": "OriginHost", "path": "Origin-Host", "type": "*variable",
|
||||
{"tag": "OriginHost", "path": "*diamreq.Origin-Host", "type": "*variable",
|
||||
"value": "~*req.Destination-Host", "mandatory": true},
|
||||
{"tag": "OriginRealm", "path": "Origin-Realm", "type": "*variable",
|
||||
{"tag": "OriginRealm", "path": "*diamreq.Origin-Realm", "type": "*variable",
|
||||
"value": "~*req.Destination-Realm", "mandatory": true},
|
||||
{"tag": "DestinationRealm", "path": "Destination-Realm", "type": "*variable",
|
||||
{"tag": "DestinationRealm", "path": "*diamreq.Destination-Realm", "type": "*variable",
|
||||
"value": "~*req.Origin-Realm", "mandatory": true},
|
||||
{"tag": "DestinationHost", "path": "Destination-Host", "type": "*variable",
|
||||
{"tag": "DestinationHost", "path": "*diamreq.Destination-Host", "type": "*variable",
|
||||
"value": "~*req.Origin-Host", "mandatory": true},
|
||||
{"tag": "AuthApplicationId", "path": "Auth-Application-Id", "type": "*variable",
|
||||
{"tag": "AuthApplicationId", "path": "*diamreq.Auth-Application-Id", "type": "*variable",
|
||||
"value": "~*vars.*appid", "mandatory": true},
|
||||
{"tag": "UserName", "path": "User-Name", "type": "*variable",
|
||||
{"tag": "UserName", "path": "*diamreq.User-Name", "type": "*variable",
|
||||
"value": "~*req.User-Name", "mandatory": true},
|
||||
{"tag": "OriginStateID", "path": "Origin-State-Id", "type": "*constant",
|
||||
{"tag": "OriginStateID", "path": "*diamreq.Origin-State-Id", "type": "*constant",
|
||||
"value": "1"},
|
||||
]
|
||||
},
|
||||
|
||||
@@ -90,19 +90,19 @@
|
||||
},
|
||||
{
|
||||
"tag": "RatingGroup",
|
||||
"path": "*cgreq.Multiple-Services-Credit-Control.Rating-Group",
|
||||
"path": "*rep.Multiple-Services-Credit-Control.Rating-Group",
|
||||
"type": "*constant",
|
||||
"value": "1"
|
||||
},
|
||||
{
|
||||
"tag": "CCTotalOctets1",
|
||||
"path": "*cgreq.Multiple-Services-Credit-Control.Used-Service-Unit.CC-Total-Octets",
|
||||
"path": "*rep.Multiple-Services-Credit-Control.Used-Service-Unit.CC-Total-Octets",
|
||||
"type": "*variable",
|
||||
"value": "~*cgreq.UsedUnits1"
|
||||
},
|
||||
{
|
||||
"tag": "GrantedUsage",
|
||||
"path": "*cgreq.Granted-Service-Unit.CC-Time",
|
||||
"path": "*rep.Granted-Service-Unit.CC-Time",
|
||||
"type": "*sum",
|
||||
"value": "~*cgreq.Val1;~*cgreq.Val2;~*cgreq.Val3"},
|
||||
],
|
||||
|
||||
@@ -270,7 +270,7 @@
|
||||
},
|
||||
{
|
||||
"tag": "LastUsed",
|
||||
"path": "LastUsed",
|
||||
"path": "*cgreq.LastUsed",
|
||||
"type": "*variable",
|
||||
"value": "~*req.Used-Service-Unit.CC-Time:s/(.*)/${1}s/",
|
||||
"mandatory": true
|
||||
|
||||
@@ -296,7 +296,6 @@ func InitDataDb(cfg *config.CGRConfig) error {
|
||||
if err := dm.DataDB().Flush(""); err != nil {
|
||||
return err
|
||||
}
|
||||
//dm.LoadDataDBCache(nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil)
|
||||
// Write version before starting
|
||||
if err := OverwriteDBVersions(dm.dataDB); err != nil {
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user