source: nscp/scripts/python/test.py @ 04ef932

0.4.00.4.10.4.2
Last change on this file since 04ef932 was 04ef932, checked in by Michael Medin <michael@…>, 22 months ago

2011-08-10

  • Fixed so it builds and runs on linux (but parser had issues so disabled som grammar rules whichneeds to be enabled again)
  • Added a lot of freatures and cleand up the PythonScript module
  • Started to merge som features from PythonScript back to Lua script


2011-08-07

  • Fixed a lot of issues with PythonScript module adding suport for alias and "raw command processing"
  • Fixed issue with loading plugins and aliases as well as duplicate plugin detection


2011-08-01

  • Property mode set to 100644
File size: 2.3 KB
Line 
1from NSCP import Settings, Functions, Core, log, status
2
3core = Core.get()
4
5def test(arguments):
6        log('inside test')
7        for a in arguments:
8                log('Got argument: %s'%a)
9        (retcode, msg, perf) = core.simple_query("normal", [])
10        if msg != "ok got: ":
11                return (status.CRITICAL, "Test failed")
12        (retcode, msg, perf) = core.simple_query("normal", ["hello"])
13        if msg != "ok got: hello":
14                return (status.CRITICAL, "Test failed")
15        (retcode, msg, perf) = core.simple_query("normal", ["hello", "world"])
16        if perf != "'args'=2":
17                return (status.CRITICAL, "Test failed: -%s-"%perf)
18        return (status.OK, 'Tests ok')
19
20def normal(arguments):
21        log('inside normal')
22        for a in arguments:
23                log(' | Got argument: %s'%a)
24        if arguments:
25                return (status.OK, 'ok got: %s'%arguments[0], "args=%d; "%len(arguments))
26        return (status.OK, 'ok got: ', "args=%d; "%len(arguments))
27       
28def no_perf(arguments):
29        log('inside no_perf')
30        for a in arguments:
31                log('Got argument: %s'%a)
32        return (status.WARNING, 'I am ok')
33
34def no_msg(arguments):
35        log('inside no_perf')
36        for a in arguments:
37                log('Got argument: %s'%a)
38        return (1)
39
40def no_ret(arguments):
41        log('inside no_perf')
42        for a in arguments:
43                log('Got argument: %s'%a)
44       
45def init(alias):
46        prefix = 'py_'
47        if alias:
48                prefix = '%s_'%alias
49
50        log('Hello World')
51
52        conf = Settings.get()
53        val = conf.get_string('/modules', 'PythonScript', 'foo')
54
55        log('Got it: %s'%val)
56       
57        log('Testing to register a function')
58        fun = Functions.get()
59        fun.register_simple('%stest'%prefix, test, 'This is a sample command')
60        fun.register_simple('%snormal'%prefix, normal, 'This is a sample command')
61        fun.register_simple('%snop'%prefix, no_perf, 'No performance data')
62        fun.register_simple('%snom'%prefix, no_msg, 'No performance data')
63        fun.register_simple('%snor'%prefix, no_ret, 'No performance data')
64
65        log('Testing to register settings keys')
66        conf.register_path('hello', 'PYTHON SETTINGS', 'This is stuff for python')
67        conf.register_key('hello', 'python', 'int', 'KEY', 'This is a key', '42')
68
69        log('Testing to get key (nonexistant): %d' % conf.get_int('hello', 'python', -1))
70        conf.set_int('hello', 'python', 4)
71        log('Testing to get it (after setting it): %d' % conf.get_int('hello', 'python', -1))
72
73        log('Saving configuration...')
74        conf.save()
75
76def shutdown():
77        log('Unloading script...')
Note: See TracBrowser for help on using the repository browser.