Automatic starting daemons out of sample configs in localtests, /tmp as output folder to work in non-root mode

This commit is contained in:
DanB
2014-03-02 17:34:03 +01:00
parent 755ab02d55
commit 62ccb5b9df
3 changed files with 40 additions and 10 deletions

View File

@@ -25,6 +25,7 @@ import (
"net/rpc"
"net/rpc/jsonrpc"
"net/url"
"os"
"os/exec"
"path"
"reflect"
@@ -53,6 +54,7 @@ README:
* Execute remote Apis and test their replies(follow prepaid1cent scenario so we can test load in dataDb also).
*/
var cfgPath string
var cfg *config.CGRConfig
var rater *rpc.Client
@@ -62,10 +64,24 @@ var storDbType = flag.String("stordb_type", "mysql", "The type of the storDb dat
var waitRater = flag.Int("wait_rater", 300, "Number of miliseconds to wait for rater to start and cache")
func init() {
cfgPath := path.Join(*dataDir, "conf", "cgrates.cfg")
cfgPath = path.Join(*dataDir, "conf", "samples", "apier_local_test.cfg")
cfg, _ = config.NewCGRConfig(&cfgPath)
}
func TestCreateDirs(t *testing.T) {
if !*testLocal {
return
}
for _, pathDir := range []string{cfg.CdreDir, cfg.CdrcCdrInDir, cfg.CdrcCdrOutDir, cfg.HistoryDir} {
if err := os.RemoveAll(pathDir); err != nil {
t.Fatal("Error removing folder: ", pathDir, err)
}
if err := os.MkdirAll(pathDir, 0755); err != nil {
t.Fatal("Error creating folder: ", pathDir, err)
}
}
}
// Empty tables before using them
func TestCreateTables(t *testing.T) {
if !*testLocal {
@@ -124,7 +140,7 @@ func TestStartEngine(t *testing.T) {
t.Fatal("Cannot find cgr-engine executable")
}
exec.Command("pkill", "cgr-engine").Run() // Just to make sure another one is not running, bit brutal maybe we can fine tune it
engine := exec.Command(enginePath, "-rater", "-scheduler", "-cdrs", "-mediator", "-config", path.Join(*dataDir, "conf", "cgrates.cfg"))
engine := exec.Command(enginePath, "-config", cfgPath)
if err := engine.Start(); err != nil {
t.Fatal("Cannot start cgr-engine: ", err.Error())
}
@@ -137,8 +153,7 @@ func TestRpcConn(t *testing.T) {
return
}
var err error
rater, err = jsonrpc.Dial("tcp", fscsvCfg.RPCJSONListen)
//rater, err = rpc.Dial("tcp", "127.0.0.1:2013") //ToDo: Fix with automatic config
rater, err = jsonrpc.Dial("tcp", fscsvCfg.RPCJSONListen) // We connect over JSON so we can also troubleshoot if needed
if err != nil {
t.Fatal("Could not connect to rater: ", err.Error())
}

View File

@@ -21,6 +21,7 @@ package apier
import (
"fmt"
"net/rpc/jsonrpc"
"os"
"os/exec"
"path"
"reflect"
@@ -32,13 +33,28 @@ import (
"github.com/cgrates/cgrates/utils"
)
var fscsvCfgPath string
var fscsvCfg *config.CGRConfig
func init() {
fscsvCfgPath := path.Join(*dataDir, "tutorials", "fs_csv", "cgrates", "etc", "cgrates", "cgrates.cfg")
fscsvCfgPath = path.Join(*dataDir, "tutorials", "fs_csv", "cgrates", "etc", "cgrates", "cgrates.cfg")
fscsvCfg, _ = config.NewCGRConfig(&fscsvCfgPath)
}
func TestFsCsvCreateDirs(t *testing.T) {
if !*testLocal {
return
}
for _, pathDir := range []string{cfg.CdreDir, cfg.CdrcCdrInDir, cfg.CdrcCdrOutDir, cfg.HistoryDir} {
if err := os.RemoveAll(pathDir); err != nil {
t.Fatal("Error removing folder: ", pathDir, err)
}
if err := os.MkdirAll(pathDir, 0755); err != nil {
t.Fatal("Error creating folder: ", pathDir, err)
}
}
}
// Empty tables before using them
func TestFsCsvCreateTables(t *testing.T) {
if !*testLocal {
@@ -95,10 +111,9 @@ func TestFsCsvStartEngine(t *testing.T) {
if err != nil {
t.Fatal("Cannot find cgr-engine executable")
}
fmt.Println(path.Join(*dataDir, "tutorials", "fs_csv", "cgrates", "etc", "cgrates", "cgrates.cfg"))
exec.Command("pkill", "cgr-engine").Run() // Just to make sure another one is not running, bit brutal maybe we can fine tune it
go func() {
eng := exec.Command(enginePath, "-config", path.Join(*dataDir, "tutorials", "fs_csv", "cgrates", "etc", "cgrates", "cgrates.cfg"))
eng := exec.Command(enginePath, "-config", fscsvCfgPath)
out, _ := eng.CombinedOutput()
engine.Logger.Info(fmt.Sprintf("CgrEngine-TestFsCsv: %s", out))
}()

View File

@@ -61,8 +61,8 @@ enabled = true # Enable CDR client functionality
# cdrs_method = http_cgr # Mechanism to use when posting CDRs on server <http_cgr>
# run_delay = 0 # Sleep interval in seconds between consecutive runs, 0 to use automation via inotify
cdr_type = freeswitch_csv # CDR file format <csv>.
cdr_in_dir = /var/log/cgrates/cdr/cdrc/in # Absolute path towards the directory where the CDRs are stored.
cdr_out_dir = /tmp # Absolute path towards the directory where processed CDRs will be moved.
cdr_in_dir = /tmp/cgrates/cdr/cdrc/in # Absolute path towards the directory where the CDRs are stored.
cdr_out_dir = /tmp/cgrates/cdr/cdrc/out # Absolute path towards the directory where processed CDRs will be moved.
cdr_source_id = freeswitch_csv # Free form field, tag identifying the source of the CDRs within CGRS database.
accid_field = 10 # Accounting id field identifier. Use index number in case of .csv cdrs.
reqtype_field = 16 # Request type field identifier. Use index number in case of .csv cdrs.
@@ -105,7 +105,7 @@ enabled = true # Starts SessionManager service: <true|false>.
[history_server]
enabled = true # Starts History service: <true|false>.
history_dir = /tmp/cgr_history # Location on disk where to store history files.
history_dir = /tmp/cgrates/history # Location on disk where to store history files.
# save_interval = 1s # Interval to save changed cache into .git archive
[history_agent]