Changeset 441a022 in nscp


Ignore:
Timestamp:
01/18/12 22:47:06 (16 months ago)
Author:
Michael Medin <michael@…>
Branches:
master, 0.4.0, 0.4.1, 0.4.2
Children:
2ec2eb6
Parents:
ffa6a59
Message:
  • Fixed error state propagation
  • Added unit tests to cmake (ie make test will now run unit tests)
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • CMakeLists.txt

    r2b2e9b8 r441a022  
    476476  ${BUILD_TARGET_EXE_PATH}/config.py 
    477477) 
     478 
     479ENABLE_TESTING() 
     480 
     481add_nscp_py_test(nsca test_nsca) 
     482add_nscp_py_test(nrpe test_nrpe) 
     483add_nscp_py_test(python test_python) 
     484IF(WIN32) 
     485  add_nscp_py_test(eventlog test_eventlog) 
     486  add_nscp_py_test(w32_system test_w32_system) 
     487ENDIF(WIN32) 
  • build/cmake/functions.cmake

    r7ec3dd1 r441a022  
    4141ENDMACRO(copy_single_file) 
    4242 
     43MACRO(add_nscp_py_test name script) 
     44  ADD_TEST("${name}" 
     45    nscp  
     46      py  
     47      --settings dummy  
     48      --exec run  
     49      --script ${script} 
     50      --query py_unittest 
     51    ) 
     52ENDMACRO(add_nscp_py_test) 
     53 
  • changelog

    rffa6a59 r441a022  
    1111 * Improved the syntax and output of running unit tests 
    1212 * Refactored unit tests to be slightly nicer 
     13 * Fixed error state propagation 
     14 * Added unit tests to cmake (ie make test will now run unit tests) 
    1315   
    14162012-01-16 MickeM 
  • helpers/installer-dlls/main_dll/main_dll.cpp

    r16198e3 r441a022  
    228228    h.setPropertyAndOld(_T("CONF_NRPE"), has_key(modpath, _T("NRPEServer"))); 
    229229    h.setPropertyAndOld(_T("CONF_SCHEDULER"), has_key(modpath, _T("Scheduler"))); 
    230     h.setPropertyAndOld(_T("CONF_NSCA"), has_key(modpath, _T("NSCAAgent"))); 
     230    h.setPropertyAndOld(_T("CONF_NSCA"), has_key(modpath, _T("NSCAClient"))); 
    231231    h.setPropertyAndOld(_T("CONF_NSCLIENT"), has_key(modpath, _T("NSClientServer"))); 
    232232    h.setPropertyAndOld(_T("CONF_WMI"), has_key(modpath, _T("CheckWMI"))); 
     
    300300    write_changed_key(h, data, _T("CONF_NRPE"), modpath, _T("NRPEServer"), modval); 
    301301    write_changed_key(h, data, _T("CONF_SCHEDULER"), modpath, _T("Scheduler"), modval); 
    302     write_changed_key(h, data, _T("CONF_NSCA"), modpath, _T("NSCAAgent"), modval); 
     302    write_changed_key(h, data, _T("CONF_NSCA"), modpath, _T("NSCAClient"), modval); 
    303303    write_changed_key(h, data, _T("CONF_NSCLIENT"), modpath, _T("NSClientServer"), modval); 
    304304    write_changed_key(h, data, _T("CONF_WMI"), modpath, _T("CheckWMI"), modval); 
  • modules/PythonScript/PythonScript.cpp

    rba63b95 r441a022  
    120120  callFunction("shutdown"); 
    121121} 
    122 void python_script::callFunction(const std::string& functionName) { 
     122bool python_script::callFunction(const std::string& functionName) { 
    123123  try { 
    124124    script_wrapper::thread_locker locker; 
     
    127127      if( scriptFunction ) 
    128128        scriptFunction(); 
     129      return true; 
    129130    } catch( error_already_set e) { 
    130131      script_wrapper::log_exception(); 
     132      return false; 
    131133    } 
    132134  } catch (...) { 
    133135    NSC_LOG_ERROR(_T("Unknown exception")); 
    134   } 
    135 } 
    136 void python_script::callFunction(const std::string& functionName, unsigned int i1, const std::string &s1, const std::string &s2){ 
     136    return false; 
     137  } 
     138} 
     139bool python_script::callFunction(const std::string& functionName, unsigned int i1, const std::string &s1, const std::string &s2){ 
    137140  try { 
    138141    script_wrapper::thread_locker locker; 
     
    141144      if(scriptFunction) 
    142145        scriptFunction(i1, s1, s2); 
     146      return true; 
    143147    } catch(error_already_set e) { 
    144148      script_wrapper::log_exception(); 
     149      return false; 
    145150    } 
    146151  } catch (...) { 
    147152    NSC_LOG_ERROR(_T("Unknown exception")); 
     153    return false; 
    148154  } 
    149155} 
     
    165171      path /= _T("python"); 
    166172      path /= _T("lib"); 
     173      NSC_DEBUG_MSG(_T("Lib path: ") + path.string()); 
    167174      PyRun_SimpleString(("sys.path.append('" + utf8::cvt<std::string>(path.string()) + "')").c_str()); 
    168175 
     
    293300    script_container sc(*ofile); 
    294301    python_script script(get_id(), "", sc); 
    295     script.callFunction("__main__"); 
     302    if (!script.callFunction("__main__")) { 
     303      message = _T("Failed to execute script: __main__"); 
     304      return NSCAPI::returnUNKNOWN; 
     305    } 
    296306    message = _T("Script execute successfully..."); 
    297307    return NSCAPI::returnOK; 
  • modules/PythonScript/PythonScript.h

    r9c06054 r441a022  
    3939  python_script(unsigned int plugin_id, const std::string alias, const script_container& script); 
    4040  ~python_script(); 
    41   void callFunction(const std::string& functionName); 
    42   void callFunction(const std::string& functionName, unsigned int i1, const std::string &s1, const std::string &s2); 
     41  bool callFunction(const std::string& functionName); 
     42  bool callFunction(const std::string& functionName, unsigned int i1, const std::string &s1, const std::string &s2); 
    4343  void _exec(const std::string &scriptfile); 
    4444}; 
  • scripts/CMakeLists.txt

    r4b1e6fe r441a022  
    55FILE (GLOB scripts_PS1 "*.ps1") 
    66FILE (GLOB scripts_LIB "lib/*.vbs") 
    7 IF(WIN32) 
     7#IF(WIN32) 
    88FILE (GLOB_RECURSE scripts_PYT "python/*.py") 
    9 ELSE(WIN32) 
    10 FILE (GLOB scripts_PYT "python/*.py" "python/lib/*.py") 
    11 ENDIF(WIN32) 
     9#ELSE(WIN32) 
     10#FILE (GLOB scripts_PYT "python/*.py" "python/lib/*.py") 
     11#ENDIF(WIN32) 
    1212FILE (GLOB scripts_LUA "lua/*.lua") 
    1313 
  • scripts/python/lib/test_helper.py

    rffa6a59 r441a022  
    221221      return 'OK: %s'%self.title 
    222222    else: 
    223       (total, ok) = c.count() 
     223      (total, ok) = self.count() 
    224224      return 'ERROR: %s (%d/%d)'%(self.title, ok, total) 
    225225 
  • scripts/python/test_all.py

    rffa6a59 r441a022  
    33 
    44from sys import path 
    5 from os import getcwd 
    6 path.append(getcwd() + '/scripts/python') 
     5import os 
     6path.append(os.getcwd() + '/scripts/python') 
    77 
    88from test_nsca import NSCAServerTest 
    99from test_nrpe import NRPEServerTest 
    1010#from test_pb import NSCAServerTest 
    11 from test_eventlog import EventLogTest 
    1211from test_python import PythonTest 
    13 from test_w32_system import Win32SystemTest 
    1412 
    15 all_tests = [NSCAServerTest, NRPEServerTest, EventLogTest, PythonTest, Win32SystemTest] 
     13#  
     14all_tests = [NSCAServerTest, PythonTest, NRPEServerTest] 
     15if os.name == 'nt': 
     16  from test_eventlog import EventLogTest 
     17  from test_w32_system import Win32SystemTest 
     18  all_tests.extend([EventLogTest, Win32SystemTest]) 
    1619 
    1720def __main__(): 
  • scripts/python/test_nrpe.py

    r89838be r441a022  
    11from NSCP import Settings, Registry, Core, log, status, log_error, sleep 
     2import sys 
     3log('==>%s'%sys.path) 
     4 
    25from test_helper import BasicTest, TestResult, Callable, setup_singleton, install_testcases, init_testcases, shutdown_testcases 
    36import plugin_pb2 
  • scripts/python/test_nsca.py

    rba63b95 r441a022  
    165165    (result_code, err) = core.submit('nsca_test_outbox', message.SerializeToString()) 
    166166 
    167     result = TestResult() 
     167    result = TestResult('Testing payload: %s'%tag) 
    168168    result.add_message(len(err) == 0, 'Testing to send message using %s/sbp'%tag, err) 
    169169    found = self.wait_and_validate(uid, result, msg, perf, '%s/spb'%tag) 
     
    192192    found = self.wait_and_validate(uid, result, msg, perf, '%s/exec'%tag) 
    193193    if retry and not found: 
    194       return self.submit_via_exec(encryption, source, status, msg, perf, tag, False) 
     194      return self.submit_via_exec(encryption, source, status, msg, perf, '%s (retry)'%tag, False) 
    195195    return result 
    196196 
  • scripts/python/test_python.py

    r89838be r441a022  
    44from time import time 
    55 
    6 install_checks = 1000 
     6install_checks = 100 
     7time_to_run = 30 
     8 
     9core = Core.get() 
    710 
    811class PythonTest(BasicTest): 
     
    3639    self.reg.simple_function('py_stress_noop', PythonTest.noop_handler, 'This is a simple noop command') 
    3740    self.reg.simple_subscription('py_stress_test', PythonTest.stress_handler) 
     41    conf = Settings.get() 
     42    conf.set_string('/settings/test_scheduler', 'threads', '50') 
     43    core.reload('test_scheduler') 
     44     
    3845 
    3946  def teardown(self): 
     47    conf = Settings.get() 
     48    conf.set_string('/settings/test_scheduler', 'threads', '0') 
     49    core.reload('test_scheduler') 
    4050    None 
    4151 
     
    4353    result = TestResult() 
    4454    start = time() 
    45     while self.stress_count < install_checks*10: 
    46       log('Waiting for %d: %d/%d'%(install_checks*10, self.stress_count, self.noop_count)) 
     55    total_count = install_checks*time_to_run/5 
     56    while self.stress_count < total_count: 
     57      log('Waiting for %d: %d/%d'%(total_count, self.stress_count, self.noop_count)) 
    4758      old_stress_count = self.stress_count 
    4859      old_noop_count = self.noop_count 
     
    6374     
    6475    base_path = '/settings/test_scheduler' 
    65     conf.set_string(base_path, 'threads', '50') 
     76    conf.set_string(base_path, 'threads', '0') 
    6677 
    6778    default_path = '%s/default'%base_path 
  • service/NSClient++.cpp

    r89838be r441a022  
    254254  } 
    255255  delete [] wargv; 
     256  return ret; 
    256257} 
    257258#endif 
     
    12571258  } 
    12581259  std::string response; 
    1259   NSCAPI::nagiosReturn c = plugin->handleCommand(command.c_str(), request, response); 
     1260  ret = plugin->handleCommand(command.c_str(), request, response); 
    12601261  try { 
    12611262    std::wstring msg, perf; 
  • service/cli_parser.hpp

    r89838be r441a022  
    432432          mainClient.simple_exec(module, _T("help"), arguments, resp); 
    433433        } else if (mode == combined) { 
    434           mainClient.reload(_T("service")); 
    435           ret = mainClient.simple_query(module, combined_query, arguments, resp); 
     434          if (ret == NSCAPI::returnOK) { 
     435            mainClient.reload(_T("service")); 
     436            ret = mainClient.simple_query(module, combined_query, arguments, resp); 
     437          } else { 
     438            std::wcerr << _T("Failed to execute command, will not attempt query") << std::endl; 
     439          } 
    436440        } 
    437441      } else if (mode == submit) { 
  • version.hpp

    r89838be r441a022  
    11#ifndef VERSION_HPP 
    22#define VERSION_HPP 
    3 #define PRODUCTVER     0,4,0,123 
    4 #define STRPRODUCTVER  "0,4,0,123" 
    5 #define STRPRODUCTDATE "2012-01-16" 
     3#define PRODUCTVER     0,4,0,125 
     4#define STRPRODUCTVER  "0,4,0,125" 
     5#define STRPRODUCTDATE "2012-01-18" 
    66#endif // VERSION_HPP 
  • version.txt

    r89838be r441a022  
    11version=0.4.0 
    2 build=123 
    3 date=2012-01-16 
     2build=125 
     3date=2012-01-18 
Note: See TracChangeset for help on using the changeset viewer.