Commit 837fbe41 authored by François Grisez's avatar François Grisez

Add a section 'cluster' to the config file

parent 8fb5bc2f
......@@ -23,7 +23,9 @@ import time
import logging
import argparse
import md5
from test import *
import socket
import errno
import test
def md5sum(string):
......@@ -40,8 +42,19 @@ def generate_password(host, salt):
return md5sum(host + salt)
def find_local_address(nodes):
s = socket.socket(socket.AF_INET)
for node in nodes:
try:
s.bind((node, 0))
return node
except socket.error as e:
if e.errno != errno.EADDRNOTAVAIL:
raise
return None
parser = argparse.ArgumentParser(description="daemon for testing availability of each server of a Flexisip cluster")
parser.add_argument("local_ip", help="IP number of the local host")
parser.add_argument("domain", help="domain handle by the cluster")
parser.add_argument("salt", help="salt used to generate passwords")
parser.add_argument("nodes", nargs='+', help="list of nodes to test")
......@@ -50,10 +63,18 @@ parser.add_argument("--log", help="log file path", dest="log_file", default="./f
parser.add_argument("--port", "-p", help="port to switch off when test fails", dest="port", type=int, default=12345)
args = parser.parse_args()
caller_username = generate_username(args.local_ip)
caller_password = generate_password(args.local_ip, args.salt)
logging.basicConfig(level=logging.INFO, filename=args.log_file)
logging.info("Starting Flexisip monitior")
local_ip = find_local_address(args.nodes)
if local_ip is None:
logging.fatal("No node address matches with any local addresse")
exit(1)
caller_username = generate_username(local_ip)
caller_password = generate_password(local_ip, args.salt)
caller_uid = "sip:{0}:{1}@{2}".format(caller_username, caller_password, args.domain)
caller_proxy = "sip:{0};transport=tcp".format(args.local_ip)
caller_proxy = "sip:{0};transport=tcp".format(local_ip)
caller_config = (caller_uid, caller_proxy)
callee_uris = []
......@@ -62,14 +83,13 @@ for node in args.nodes:
uri = "sip:{0}@{1}".format(username, args.domain)
callee_uris.append(uri)
logging.basicConfig(level=logging.INFO, filename=args.log_file)
logging.info("Starting Flexisip monitior")
try:
test_ = InterCallTest(caller_config, callee_uris)
test_ = test.InterCallTest(caller_config, callee_uris)
except:
logging.fatal("Test initialization failed")
exit(1)
action = TcpPortAction(args.port)
action = test.TcpPortAction(args.port)
test_.listeners.append(action)
try:
......
......@@ -312,7 +312,7 @@ oid Oid::oidFromHashedString(const string &str) {
}
GenericEntry:: GenericEntry(const string &name, GenericValueType type, const string &help,oid oid_index) :
mOid(0),mName(name),mReadOnly(false),mExportToConfigFile(true),mHelp(help),mType(type),mParent(0),mOidLeaf(oid_index){
mOid(NULL),mName(name),mReadOnly(false),mExportToConfigFile(true),mHelp(help),mType(type),mParent(0),mOidLeaf(oid_index){
mConfigListener=NULL;
size_t idx;
for(idx=0;idx<name.size();idx++){
......@@ -725,7 +725,12 @@ GenericManager::GenericManager() : mNeedRestart(false), mDirtyConfig(false),
{ Integer ,"transaction-timeout", "SIP transaction timeout in milliseconds. It is T1*64 (32000 ms) by default.","32000"},
config_item_end
};
static ConfigItemDescriptor cluster_conf[]={
{ Boolean , "enabled" , "Set to 'true' if that node is part of a cluster" , "false" },
{ StringList , "nodes" , "List of IP addresses of all nodes present in the cluster" , "" },
config_item_end
};
GenericStruct *notifObjs=new GenericStruct("notif","Templates for notifications.",1);
......@@ -757,6 +762,10 @@ GenericManager::GenericManager() : mNeedRestart(false), mDirtyConfig(false),
runtimeError->setReadOnly(true);
global->addChild(runtimeError);
GenericStruct *cluster = new GenericStruct("cluster", "Should the server is part of a cluster, this section enable to describe the topology of the cluster.", 0);
mConfigRoot.addChild(cluster);
cluster->addChildrenValues(cluster_conf);
cluster->setReadOnly(true);
}
bool GenericManager::doIsValidNextConfig(const ConfigValue &cv) {
......
......@@ -220,6 +220,20 @@ private:
const char *res=ev->findIncomingSubject(toCheck);
return res;
}
void loadTrustedHosts(const ConfigStringList &trustedHosts) {
mTrustedHosts = trustedHosts.read();
const GenericStruct *clusterSection = GenericManager::get()->getRoot()->get<GenericStruct>("cluster");
bool clusterEnabled = clusterSection->get<ConfigBoolean>("enabled")->read();
if(clusterEnabled) {
list<string> clusterNodes = clusterSection->get<ConfigStringList>("nodes")->read();
for(const string &node : clusterNodes) {
if(find(mTrustedHosts.cbegin(), mTrustedHosts.cend(), node) == mTrustedHosts.cend()) {
mTrustedHosts.push_back(node);
}
}
}
}
public:
StatCounter64 *mCountAsyncRetrieve;
......@@ -331,7 +345,7 @@ public:
}
}
mTrustedHosts=mc->get<ConfigStringList>("trusted-hosts")->read();
loadTrustedHosts(*mc->get<ConfigStringList>("trusted-hosts"));
dbUseHashedPasswords = mc->get<ConfigBoolean>("hashed-passwords")->read();
mImmediateRetrievePassword = mc->get<ConfigBoolean>("immediate-retrieve-password")->read();
mNewAuthOn407 = mc->get<ConfigBoolean>("new-auth-on-407")->read();
......@@ -530,7 +544,7 @@ public:
virtual bool doOnConfigStateChanged(const ConfigValue &conf, ConfigState state) {
if (conf.getName() == "trusted-hosts" && state == ConfigState::Commited) {
mTrustedHosts=((ConfigStringList*)(&conf))->read();
loadTrustedHosts((const ConfigStringList &)conf);
LOGD("Trusted hosts updated");
return true;
} else {
......
......@@ -48,15 +48,14 @@ void Monitor::exec(int socket) {
su_root_t *root = NULL;
shared_ptr<Agent> a = make_shared<Agent>(root);
GenericManager::get()->loadStrict();
GenericStruct *monitorParams = GenericManager::get()->getRoot()->get<GenericStruct>("monitor");
GenericStruct *authParams = GenericManager::get()->getRoot()->get<GenericStruct>("module::Authentication");
GenericStruct *cluster = GenericManager::get()->getRoot()->get<GenericStruct>("cluster");
string interval = monitorParams->get<ConfigValue>("test-interval")->get();
string logfile = monitorParams->get<ConfigString>("logfile")->read();
string port = monitorParams->get<ConfigValue>("switch-port")->get();
string salt = monitorParams->get<ConfigString>("password-salt")->read();
list<string> trustedHosts = authParams->get<ConfigStringList>("trusted-hosts")->read();
trustedHosts.remove_if(isLocalhost);
list<string> nodes = cluster->get<ConfigStringList>("nodes")->read();
string domain;
try {
......@@ -71,12 +70,12 @@ void Monitor::exec(int socket) {
exit(-1);
}
if(trustedHosts.empty()) {
if(nodes.empty()) {
LOGE("Monitor: no nodes declared in module::Registrar::trusted-hosts");
exit(-1);
}
char **args = new char *[10 + trustedHosts.size()];
char **args = new char *[10 + nodes.size()];
args[0] = strdup(PYTHON_INTERPRETOR.c_str());
args[1] = strdup(SCRIPT_PATH.c_str());
args[2] = strdup("--interval");
......@@ -88,7 +87,7 @@ void Monitor::exec(int socket) {
args[8] = strdup(domain.c_str());
args[9] = strdup(salt.c_str());
int i=10;
for(string node : trustedHosts) {
for(string node : nodes) {
args[i] = strdup(node.c_str());
i++;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment