summaryrefslogtreecommitdiffstats
path: root/func/minion/modules/test.py
blob: a5ba98babcbdc7cf165d799d4e49e1670d833174 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import func_module
import time
import exceptions
from certmaster.config import BaseConfig, Option, IntOption, FloatOption, BoolOption

class Test(func_module.FuncModule):
    version = "11.11.11"
    api_version = "0.0.1"
    description = "Just a very simple example module"

    class Config(BaseConfig):
        example = Option('1')
        string_option = Option('some string here')
        int_option = IntOption(37)
        bool_option = BoolOption(True)
        float_option = FloatOption(3.14159)
        testvalue = 'this is a test. It is only a test'
        

    def add(self, numb1, numb2):
        return numb1 + numb2

    def ping(self):
        return 1

    def sleep(self,t):
        """
        Sleeps for t seconds, and returns time of day.
        Simply a test function for trying out async and threaded voodoo.
        """
        t = int(t)
        time.sleep(t)
        return time.time()


    def explode(self):
        """
        Testing remote exception handling is useful
        """
        raise exceptions.Exception("khhhhhhaaaaaan!!!!!!")


    def explode_no_string(self):
        """
        Testing remote exception handling is useful
        """
        raise exceptions.Exception()


    def echo(self, data):
        """
        Returns whatever was passed into it
        """
        return data

    def bigint(self):
        """
        Returns an integer greater than 2^32-1
        """
        return 2**32


    def configfoo(self):
        """
        Returns the options config
        """
        return self.options

    def config_save(self):
	"""
	Saves the options config
	"""
	self.save_config()
	return self.options

    def config_set(self, key_name, value):
        setattr(self.options,key_name, value)
        self.save_config()
        return self.options

    def config_get(self, key_name):
	return getattr(self.options, key_name)

    def config_get_test(self):
	return self.options.testvalue

    def register_method_args(self):
        """
        Implementing method argument getter
        """

        return {
                'add':{
                    'args':{
                        'numb1':{
                            'type':'int',
                            'optional':False,
                            'description':'An int'
                            },
                        'numb2':{
                            'type':'int',
                            'optional':False,
                            'description':'An int'
                                }

                        },
                    'description':'Gives back the sum of 2 integers'
                    },
                'ping':{
                    'args':{},
                    'description':"Ping the minion"
                    },
                'sleep':{
                    'args':{
                        't':{
                            'type':'int',
                            'optional':False,
                            'description':'Num of sec'
                            }
                        },
                    'description':"Sleep for a while"
                    },
                'explode':{
                    'args':{},
                    'description':"Raises an exception"
                    },
                'echo':{
                    'args':{
                        'data':{
                            'type':'string',
                            'optional':False,
                            'description':"The message to send"
                            }
                        },
                    'description':"Echoes back the sent data "
                    },
                'bigint':{
                    'args':{},
                    'description':"Returns a number greater than 2^32-1"
                    }
                }