Add integration test for starting engine from ConfigS from http

This commit is contained in:
TeoV
2020-09-07 17:08:40 +03:00
committed by Dan Christian Bogos
parent 124f00753b
commit 2605c34d79
4 changed files with 79 additions and 105 deletions

View File

@@ -21,7 +21,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
package v1
import (
"fmt"
"net/rpc"
"net/rpc/jsonrpc"
"os/exec"
"path"
"reflect"
"testing"
@@ -47,6 +50,9 @@ var (
testConfigSReloadConfigFromJSONSessionS,
testConfigSReloadConfigFromJSONEEs,
testConfigSKillEngine,
testConfigStartEngineWithConfigs,
testConfigStartEngineFromHTTP,
testConfigSKillEngine,
}
)
@@ -242,3 +248,57 @@ func testConfigSKillEngine(t *testing.T) {
t.Error(err)
}
}
func testConfigStartEngineWithConfigs(t *testing.T) {
var err error
configCfgPath = path.Join(*dataDir, "conf", "samples", "configs_active")
configCfg, err = config.NewCGRConfigFromPath(configCfgPath)
if err != nil {
t.Error(err)
}
if _, err := engine.StopStartEngine(configCfgPath, *waitRater); err != nil {
t.Fatal(err)
}
configRPC, err = newRPCClient(configCfg.ListenCfg()) // We connect over JSON so we can also troubleshoot if needed
if err != nil {
t.Fatal(err)
}
var rply map[string]interface{}
if err := configRPC.Call(utils.CoreSv1Status, &utils.TenantWithOpts{}, &rply); err != nil {
t.Error(err)
} else if rply[utils.NodeID] != "EngineWithConfigSActive" {
t.Errorf("Expected %+v , received: %+v ", "EngineWithConfigSActive", rply)
}
}
func testConfigStartEngineFromHTTP(t *testing.T) {
enginePath, err := exec.LookPath("cgr-engine")
if err != nil {
t.Error(err)
}
engine := exec.Command(enginePath, "-config_path", "http://127.0.0.1:3080/configs/tutmysql/cgrates.json")
if err := engine.Start(); err != nil {
t.Error(err)
}
fib := utils.Fib()
var jsonClnt *rpc.Client
var connected bool
for i := 0; i < 200; i++ {
time.Sleep(time.Duration(fib()) * time.Millisecond)
if jsonClnt, err = jsonrpc.Dial(utils.TCP, "localhost:2012"); err != nil {
utils.Logger.Warning(fmt.Sprintf("Error <%s> when opening test connection to: <%s>",
err.Error(), "localhost:2012"))
} else {
connected = true
break
}
}
if !connected {
t.Errorf("engine did not open port <%s>", "localhost:2012")
}
time.Sleep(time.Duration(500) * time.Millisecond)
var rply map[string]interface{}
if err := jsonClnt.Call(utils.CoreSv1Status, &utils.TenantWithOpts{}, &rply); err != nil {
t.Error(err)
}
}

View File

@@ -1021,7 +1021,8 @@ func testCGRConfigReloadAll(t *testing.T) {
}
func testHttpHandlerConfigSForNotExistFile(t *testing.T) {
req := httptest.NewRequest("GET", "http://127.0.0.1/usr/share/cgrates/conf/samples/NotExists/cgrates.json", nil)
cgrCfg.configSCfg.RootDir = "/usr/share/cgrates/"
req := httptest.NewRequest("GET", "http://127.0.0.1/conf/samples/NotExists/cgrates.json", nil)
w := httptest.NewRecorder()
HandlerConfigS(w, req)
@@ -1038,7 +1039,8 @@ func testHttpHandlerConfigSForNotExistFile(t *testing.T) {
}
func testHttpHandlerConfigSForFile(t *testing.T) {
req := httptest.NewRequest("GET", "http://127.0.0.1/usr/share/cgrates/conf/samples/tutmysql/cgrates.json", nil)
cgrCfg.configSCfg.RootDir = "/usr/share/cgrates/"
req := httptest.NewRequest("GET", "http://127.0.0.1/conf/samples/tutmysql/cgrates.json", nil)
w := httptest.NewRecorder()
HandlerConfigS(w, req)
@@ -1056,7 +1058,8 @@ func testHttpHandlerConfigSForFile(t *testing.T) {
}
func testHttpHandlerConfigSForNotExistFolder(t *testing.T) {
req := httptest.NewRequest("GET", "http://127.0.0.1/usr/share/cgrates/conf/samples/NotExists/", nil)
cgrCfg.configSCfg.RootDir = "/usr/share/cgrates/"
req := httptest.NewRequest("GET", "http://127.0.0.1/conf/samples/NotExists/", nil)
w := httptest.NewRecorder()
HandlerConfigS(w, req)
@@ -1066,14 +1069,15 @@ func testHttpHandlerConfigSForNotExistFolder(t *testing.T) {
if resp.Status != "404 Not Found" {
t.Errorf("Expected %+v , received: %+v ", "200 OK", resp.Status)
}
httpBodyMsgError := "stat /usr/share/cgrates/conf/samples/NotExists/: no such file or directory"
httpBodyMsgError := "stat /usr/share/cgrates/conf/samples/NotExists: no such file or directory"
if httpBodyMsgError != string(body) {
t.Errorf("Expected %s , received: %s ", httpBodyMsgError, string(body))
}
}
func testHttpHandlerConfigSForFolder(t *testing.T) {
req := httptest.NewRequest("GET", "http://127.0.0.1/usr/share/cgrates/conf/samples/diamagent_internal/", nil)
cgrCfg.configSCfg.RootDir = "/usr/share/cgrates/"
req := httptest.NewRequest("GET", "http://127.0.0.1/conf/samples/diamagent_internal/", nil)
w := httptest.NewRecorder()
HandlerConfigS(w, req)

View File

@@ -2,116 +2,26 @@
"general": {
"node_id": "EngineWithConfigSActive",
"log_level": 7,
"reply_timeout": "50s",
},
"listen": {
"rpc_json": ":2012",
"rpc_gob": ":2013",
"http": ":2080",
"rpc_json": ":3012",
"rpc_gob": ":3013",
"http": ":3080",
},
"data_db": { // database used to store runtime data (eg: accounts, cdr stats)
"db_type": "redis", // data_db type: <redis|mongo>
"db_port": 6379, // data_db port to reach the database
"db_name": "10", // data_db database name to connect to
"data_db": {
"db_type": "*internal",
},
"stor_db": {
"db_password": "CGRateS.org",
},
"rals": {
"enabled": true,
"thresholds_conns": ["*internal"],
"max_increments":3000000,
},
"schedulers": {
"enabled": true,
"cdrs_conns": ["*internal"],
},
"cdrs": {
"enabled": true,
"chargers_conns":["*internal"],
},
"attributes": {
"enabled": true,
},
"chargers": {
"enabled": true,
"attributes_conns": ["*internal"],
},
"resources": {
"enabled": true,
"store_interval": "1s",
"thresholds_conns": ["*internal"]
},
"stats": {
"enabled": true,
"store_interval": "1s",
"thresholds_conns": ["*internal"],
},
"thresholds": {
"enabled": true,
"store_interval": "1s",
},
"routes": {
"enabled": true,
"prefix_indexed_fields":["*req.Destination"],
"stats_conns": ["*internal"],
"resources_conns": ["*internal"],
"rals_conns": ["*internal"],
},
"sessions": {
"enabled": true,
"routes_conns": ["*internal"],
"resources_conns": ["*internal"],
"attributes_conns": ["*internal"],
"rals_conns": ["*internal"],
"cdrs_conns": ["*internal"],
"chargers_conns": ["*internal"],
},
"migrator":{
"out_stordb_password": "CGRateS.org",
"users_filters":["Account"],
},
"apiers": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
"rates": {
"enabled": true
},
"filters": {
"apiers_conns": ["*internal"],
"db_type": "*internal"
},

View File

@@ -363,7 +363,7 @@ func StartEngine(cfgPath string, waitEngine int) (*exec.Cmd, error) {
if !connected {
return nil, fmt.Errorf("engine did not open port <%s>", cfg.ListenCfg().RPCJSONListen)
}
time.Sleep(time.Duration(waitEngine) * time.Millisecond) // wait for rater to register all subsistems
time.Sleep(time.Duration(waitEngine) * time.Millisecond) // wait for rater to register all subsystems
return engine, nil
}