From fd78cbaf22650c3061368684859925f58c005620 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 27 May 2008 10:12:07 +0300 Subject: First commit in gsoc,reusing public method validation in func_module --- func/minion/modules/func_module.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'func/minion') diff --git a/func/minion/modules/func_module.py b/func/minion/modules/func_module.py index 7d476dc..693d808 100644 --- a/func/minion/modules/func_module.py +++ b/func/minion/modules/func_module.py @@ -58,8 +58,7 @@ class FuncModule(object): """ handlers = {} for attr in dir(self): - if inspect.ismethod(getattr(self, attr)) and attr[0] != '_' and \ - attr != 'register_rpc': + if self.__is_public_valid_method(attr): handlers[attr] = getattr(self, attr) return handlers @@ -74,3 +73,10 @@ class FuncModule(object): def __module_description(self): return self.description + + def __is_public_valid_method(self,attr): + if inspect.ismethod(getattr(self, attr)) and attr[0] != '_' and\ + attr != 'register_rpc': + return True + return False + -- cgit From 5ee76c4ff83c18d9dfbcd677a6e9eb5d9c02d254 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 27 May 2008 10:50:09 +0300 Subject: im a real git lame :) the creation of the new method for arg gettter --- func/minion/modules/func_module.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'func/minion') diff --git a/func/minion/modules/func_module.py b/func/minion/modules/func_module.py index 693d808..16f6681 100644 --- a/func/minion/modules/func_module.py +++ b/func/minion/modules/func_module.py @@ -79,4 +79,13 @@ class FuncModule(object): attr != 'register_rpc': return True return False - + + def __get_method_args(self,meth_name): + """ + Gives a list of arguments for particular given + method_name + + @param meth_name: the name of the method + @retun : list or None + """ + pass -- cgit From fa76ae6a01f8740f831c400cccbb3cc744bfca40 Mon Sep 17 00:00:00 2001 From: makkalot Date: Tue, 27 May 2008 11:00:43 +0300 Subject: thanks god we dont use svn everyone would see what silly things im doing :) --- func/minion/modules/func_module.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'func/minion') diff --git a/func/minion/modules/func_module.py b/func/minion/modules/func_module.py index 16f6681..203b321 100644 --- a/func/minion/modules/func_module.py +++ b/func/minion/modules/func_module.py @@ -88,4 +88,4 @@ class FuncModule(object): @param meth_name: the name of the method @retun : list or None """ - pass + return None -- cgit From 7b9276ccd4958dc98099421a52278ccdaccbadb7 Mon Sep 17 00:00:00 2001 From: makkalot Date: Tue, 27 May 2008 13:22:06 +0300 Subject: adding get_method_args for the minion part --- func/minion/modules/func_module.py | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'func/minion') diff --git a/func/minion/modules/func_module.py b/func/minion/modules/func_module.py index 203b321..fd592c7 100644 --- a/func/minion/modules/func_module.py +++ b/func/minion/modules/func_module.py @@ -34,7 +34,8 @@ class FuncModule(object): "module_version" : self.__module_version, "module_api_version" : self.__module_api_version, "module_description" : self.__module_description, - "list_methods" : self.__list_methods + "list_methods" : self.__list_methods, + "get_method_args" : self.__get_method_args, } def __init_log(self): @@ -88,4 +89,24 @@ class FuncModule(object): @param meth_name: the name of the method @retun : list or None """ - return None + if not self.__is_public_valid_method(name): + return {} + + arg_names = inspect.getargspec(getattr(self,name)) + #arg_names[0] is argument names + #arg_names[1] is *arg + #arg_names[2] is **kwarg + #arg_names[3] are defaults + + name_dict =[other_args for other_args in arg_names[1:3] if other_args] + arg_names = arg_names[0] or [] + + #if we have self lets remove it + for rem in arg_names: + if rem=="self": + arg_names.remove(rem) + break + + final_dict={} + final_dict[name]=arg_names+name_dict + return final_dict -- cgit From 2c4817f1ee0f80ad4aae080099994fcec41a529b Mon Sep 17 00:00:00 2001 From: makkalot Date: Tue, 27 May 2008 13:38:12 +0300 Subject: does the arg comes with in a tuple --- func/minion/modules/func_module.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'func/minion') diff --git a/func/minion/modules/func_module.py b/func/minion/modules/func_module.py index fd592c7..98d7266 100644 --- a/func/minion/modules/func_module.py +++ b/func/minion/modules/func_module.py @@ -89,6 +89,9 @@ class FuncModule(object): @param meth_name: the name of the method @retun : list or None """ + #is it a tuple ? + meth_name = method_name[0] + if not self.__is_public_valid_method(name): return {} -- cgit From 6bb831d276d22649ca80a0fb46f272596f8f81dc Mon Sep 17 00:00:00 2001 From: makkalot Date: Tue, 27 May 2008 14:19:21 +0300 Subject: testing ... --- func/minion/modules/func_module.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'func/minion') diff --git a/func/minion/modules/func_module.py b/func/minion/modules/func_module.py index 98d7266..14fdbfe 100644 --- a/func/minion/modules/func_module.py +++ b/func/minion/modules/func_module.py @@ -90,7 +90,7 @@ class FuncModule(object): @retun : list or None """ #is it a tuple ? - meth_name = method_name[0] + #meth_name = meth_name[0] if not self.__is_public_valid_method(name): return {} -- cgit From d50ecd9085106d753232ceb54ba41155775cdd67 Mon Sep 17 00:00:00 2001 From: makkalot Date: Tue, 27 May 2008 14:23:46 +0300 Subject: i should take a break --- func/minion/modules/func_module.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'func/minion') diff --git a/func/minion/modules/func_module.py b/func/minion/modules/func_module.py index 14fdbfe..56fd171 100644 --- a/func/minion/modules/func_module.py +++ b/func/minion/modules/func_module.py @@ -81,16 +81,15 @@ class FuncModule(object): return True return False - def __get_method_args(self,meth_name): + def __get_method_args(self,name): """ Gives a list of arguments for particular given method_name - @param meth_name: the name of the method + @param name: the name of the method @retun : list or None """ #is it a tuple ? - #meth_name = meth_name[0] if not self.__is_public_valid_method(name): return {} -- cgit From e3c15b13bf30494451170fd69bfc227272f8eab1 Mon Sep 17 00:00:00 2001 From: makkalot Date: Tue, 27 May 2008 14:39:12 +0300 Subject: we dont need the base one actually (self.__base_methods) --- func/minion/modules/func_module.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'func/minion') diff --git a/func/minion/modules/func_module.py b/func/minion/modules/func_module.py index 56fd171..d05af66 100644 --- a/func/minion/modules/func_module.py +++ b/func/minion/modules/func_module.py @@ -87,13 +87,16 @@ class FuncModule(object): method_name @param name: the name of the method - @retun : list or None + @retun : dict(name:[arg1,arg2...]) or {} """ - #is it a tuple ? - + if not self.__is_public_valid_method(name): return {} + #we dont need them actually + if name in self.__base_methods.keys(): + return {} + arg_names = inspect.getargspec(getattr(self,name)) #arg_names[0] is argument names #arg_names[1] is *arg -- cgit From ce08177132f46d8ae0fa636feaa19f157482afa5 Mon Sep 17 00:00:00 2001 From: makkalot Date: Tue, 27 May 2008 14:47:14 +0300 Subject: sometimes fails if there is no attr like that fixed --- func/minion/modules/func_module.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'func/minion') diff --git a/func/minion/modules/func_module.py b/func/minion/modules/func_module.py index d05af66..b13d3ac 100644 --- a/func/minion/modules/func_module.py +++ b/func/minion/modules/func_module.py @@ -89,12 +89,15 @@ class FuncModule(object): @param name: the name of the method @retun : dict(name:[arg1,arg2...]) or {} """ + #we dont need them actually + if name in self.__base_methods.keys(): + return {} - if not self.__is_public_valid_method(name): + #tests showed that sometimes happens + if not hasattr(self,name): return {} - #we dont need them actually - if name in self.__base_methods.keys(): + if not self.__is_public_valid_method(name): return {} arg_names = inspect.getargspec(getattr(self,name)) -- cgit From e9d4417179b6c164257794b89ec5da6d853f7d45 Mon Sep 17 00:00:00 2001 From: makkalot Date: Tue, 27 May 2008 15:45:07 +0300 Subject: the unittest for get_method_args it passes the system module test hacky like other members like it we should implement them ... --- func/minion/modules/func_module.py | 1 + 1 file changed, 1 insertion(+) (limited to 'func/minion') diff --git a/func/minion/modules/func_module.py b/func/minion/modules/func_module.py index b13d3ac..21ec3ea 100644 --- a/func/minion/modules/func_module.py +++ b/func/minion/modules/func_module.py @@ -90,6 +90,7 @@ class FuncModule(object): @retun : dict(name:[arg1,arg2...]) or {} """ #we dont need them actually + if name in self.__base_methods.keys(): return {} -- cgit From 7159496b5ded2459669fb73744bb3d397c06461e Mon Sep 17 00:00:00 2001 From: makkalot Date: Fri, 30 May 2008 22:57:21 +0300 Subject: new branch new life creating new branch until i merge my stuff to master to no mess with other ready code --- func/minion/modules/func_arg.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 func/minion/modules/func_arg.py (limited to 'func/minion') diff --git a/func/minion/modules/func_arg.py b/func/minion/modules/func_arg.py new file mode 100644 index 0000000..e69de29 -- cgit From 4357afa7740a407f035e824cfd3bea61a06cefa7 Mon Sep 17 00:00:00 2001 From: makkalot Date: Fri, 30 May 2008 23:56:49 +0300 Subject: add the minion_arg_validator module to code base it is kind fo API what can be assigned and etc --- func/minion/modules/func_arg.py | 140 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 140 insertions(+) (limited to 'func/minion') diff --git a/func/minion/modules/func_arg.py b/func/minion/modules/func_arg.py index e69de29..ae6db16 100644 --- a/func/minion/modules/func_arg.py +++ b/func/minion/modules/func_arg.py @@ -0,0 +1,140 @@ +## +## Copyright 2007, Red Hat, Inc +## see AUTHORS +## +## This software may be freely redistributed under the terms of the GNU +## general public license. +## +## You should have received a copy of the GNU General Public License +## along with this program; if not, write to the Free Software +## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +## + +class ArgCompatibility(object): + """ + That class is going to test if the module that was created by module + writer if he/she obeys to the rules we put before + """ + + #these are the common options can be used with all types + __common_options = ('optional','default','description') + + #basic types has types also + __basic_types={ + 'range':(), + 'min':0, + 'max':0, + 'optional':False, + 'description':'', + 'options':(), + 'min_length':0, + 'max_length':0, + 'validator':'', + 'type':'', + 'default':None #its type is unknown + } + + def __init__(self,get_args_result): + """ + The constructor initilized by the get_method_args() + @param : get_args_result : The dict with all method related info + """ + self.__args_to_check = get_args_result + + #what options does each of the basic_types have : + self.__valid_args={ + 'int':('range','min','max'), + 'string':('options','min_length','max_length','validator'), + 'boolean':(), + 'float':(), + 'hash':('validator'), + 'iterable':('validator'), + } + + + def _is_type_options_compatible(self,argument_dict): + """ + Checks the argument_dict's options and looks inside + self.__valid_args to see if the used option is there + + @param : argument_dict : current argument to check + @return : True of raises IncompatibleTypesException + + """ + #did module writer add a key 'type' + if not argument_dict.has_key('type') or not self.__valid_args.has_key(argument_dict['type']): + raise IncompatibleTypesException("%s is not in valid options"%argument_dict['type']) + + # we will use it everytime so not make lookups + the_type = argument_dict['type'] + from itertools import chain + + for key,value in argument_dict.iteritems(): + + if key == "type": + continue + if key not in chain(self.__valid_args[the_type],self.__common_options): + raise IncompatibleTypesException("There is no option like %s in %s"%(key,the_type)) + + return True + + + def _is_basic_types_compatible(self,type_dict): + """ + Validates that if the types that were submitted with + get_method_args were compatible with our format above + in __basic_types + + @param : type_dict : The type to examine + @return : True or raise IncompatibleTypesException Exception + """ + for key,value in type_dict.iteritems(): + + #do we have that type + if not self.__basic_types.has_key(key): + raise IncompatibleTypesException("%s not in the basic_types"%key) + + #if type matches and dont match default + if key!='default' and type(value)!=type(self.__basic_types[key]): + raise IncompatibleTypesException("%s should be %s"%(key,self.__basic_types[key])) + + return True + + + def validate_all(self): + """ + Validates the output for minion module's + get_method_args method + + @return : True or raise IncompatibleTypesException Exception + """ + + for method in self.__args_to_check.iterkeys(): + for argument in self.__args_to_check[method].itervalues(): + self._is_basic_types_compatible(argument) + self._is_type_options_compatible(argument) + + +###The Exception classes here + + +class IncompatibleTypesException(Exception): + """ + Raised when we assign some values that breaksour rules + @see ArgCompatibility class for allowe situations + """ + def __init__(self, value=None): + Exception.__init__(self) + self.value = value + def __str__(self): + return "%s" %(self.value,) + +class NonExistingMethodRegistered(IncompatibleTypesException): + """ + That Exception is raised when a non existent module is + tried to be registerd we shouldnt allow that + """ + pass + + + -- cgit From 9f5f7cc9357f975c2415b3b0826eeee54be74c05 Mon Sep 17 00:00:00 2001 From: makkalot Date: Sat, 31 May 2008 01:15:18 +0300 Subject: the actual test unit test but doesnt work properly continue tomorrow --- func/minion/modules/func_arg.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'func/minion') diff --git a/func/minion/modules/func_arg.py b/func/minion/modules/func_arg.py index ae6db16..4d87e06 100644 --- a/func/minion/modules/func_arg.py +++ b/func/minion/modules/func_arg.py @@ -67,7 +67,7 @@ class ArgCompatibility(object): # we will use it everytime so not make lookups the_type = argument_dict['type'] - from itertools import chain + from itertools import chain #may i use chain ? for key,value in argument_dict.iteritems(): @@ -114,6 +114,8 @@ class ArgCompatibility(object): self._is_basic_types_compatible(argument) self._is_type_options_compatible(argument) + return True + ###The Exception classes here -- cgit From 12706048cee60b7d39c03104a8b288e5fa6368ee Mon Sep 17 00:00:00 2001 From: makkalot Date: Sun, 1 Jun 2008 12:16:57 +0300 Subject: minor changes in arg module, discovered in unittests ,testing is cool :) --- func/minion/modules/func_arg.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'func/minion') diff --git a/func/minion/modules/func_arg.py b/func/minion/modules/func_arg.py index 4d87e06..95cc000 100644 --- a/func/minion/modules/func_arg.py +++ b/func/minion/modules/func_arg.py @@ -13,7 +13,7 @@ class ArgCompatibility(object): """ That class is going to test if the module that was created by module - writer if he/she obeys to the rules we put before + writer if he/she obeys to the rules we put here """ #these are the common options can be used with all types @@ -36,19 +36,19 @@ class ArgCompatibility(object): def __init__(self,get_args_result): """ - The constructor initilized by the get_method_args() + The constructor initilized by the get_method_args()(the dict to test) @param : get_args_result : The dict with all method related info """ self.__args_to_check = get_args_result #what options does each of the basic_types have : self.__valid_args={ - 'int':('range','min','max'), - 'string':('options','min_length','max_length','validator'), + 'int':('range','min','max',), + 'string':('options','min_length','max_length','validator',), 'boolean':(), 'float':(), - 'hash':('validator'), - 'iterable':('validator'), + 'hash':('validator',), + 'iterable':('validator',), } @@ -123,7 +123,7 @@ class ArgCompatibility(object): class IncompatibleTypesException(Exception): """ Raised when we assign some values that breaksour rules - @see ArgCompatibility class for allowe situations + @see ArgCompatibility class for allowed situations """ def __init__(self, value=None): Exception.__init__(self) -- cgit From aeb784f6958b39d16e4ae879a68e35962b053a76 Mon Sep 17 00:00:00 2001 From: makkalot Date: Sun, 1 Jun 2008 13:07:16 +0300 Subject: reorganizing the func_arg to be able to get method arguments, small pushes are cool --- func/minion/modules/func_arg.py | 8 ++++++++ func/minion/modules/func_module.py | 24 +++++++++++++++++------- 2 files changed, 25 insertions(+), 7 deletions(-) (limited to 'func/minion') diff --git a/func/minion/modules/func_arg.py b/func/minion/modules/func_arg.py index 95cc000..27beb93 100644 --- a/func/minion/modules/func_arg.py +++ b/func/minion/modules/func_arg.py @@ -138,5 +138,13 @@ class NonExistingMethodRegistered(IncompatibleTypesException): """ pass +class UnregisteredMethodArgument(IncompatibleTypesException): + """ + That exception is to try to remove the errors that user may + do during method registration process. If a argument is missed + to be registerted in the method that exception is Raised! + """ + pass + diff --git a/func/minion/modules/func_module.py b/func/minion/modules/func_module.py index 21ec3ea..edb554c 100644 --- a/func/minion/modules/func_module.py +++ b/func/minion/modules/func_module.py @@ -15,7 +15,7 @@ import inspect from func import logger from func.config import read_config from func.commonconfig import FuncdConfig - +from func.minion.modules.func_arg import * #the arg getter stuff class FuncModule(object): @@ -81,16 +81,26 @@ class FuncModule(object): return True return False - def __get_method_args(self,name): + def get_method_args(self,name): """ - Gives a list of arguments for particular given - method_name + Gets arguments with their formats according to ArgCompatibility + class' rules. - @param name: the name of the method + @param :name The name of the method + @return : dict with args or Raise Exception if something wrong + happens + """ + pass + + def __is_all_args_registered(self,name): + """ + Checks if module writer has made some mistakes about + argument registering + + @param name: the name of the method with arguments registered in it @retun : dict(name:[arg1,arg2...]) or {} """ - #we dont need them actually - + #FIXME tobe rewritten if name in self.__base_methods.keys(): return {} -- cgit From 4a274173556d7366604160abbfeb57b51b4eb53b Mon Sep 17 00:00:00 2001 From: makkalot Date: Sun, 1 Jun 2008 13:37:51 +0300 Subject: get_method args implemented also has backward support --- func/minion/modules/func_module.py | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) (limited to 'func/minion') diff --git a/func/minion/modules/func_module.py b/func/minion/modules/func_module.py index edb554c..e2a47c3 100644 --- a/func/minion/modules/func_module.py +++ b/func/minion/modules/func_module.py @@ -81,16 +81,45 @@ class FuncModule(object): return True return False - def get_method_args(self,name): + def __get_method_args(self): """ Gets arguments with their formats according to ArgCompatibility class' rules. - @param :name The name of the method @return : dict with args or Raise Exception if something wrong happens """ - pass + tmp_arg_dict = self.__register_method_args() + + #if it is not implemeted then return empty stuff + if not tmp_arg_dict: + return {} + + #or go ahead + #see if user tried to register an not implemented method :) + for method in tmp_arg_dict.keys(): + if not hasattr(self,method): + raise NonExistingMethodRegistered("%s is not in %s "%(method,self.__class__.__name__)) + + #create argument validation instance + self.arg_comp = ArgCompatibility(tmp_arg_dict) + #see if the options that were used are OK.. + self.arg_comp.validate_all() + + return tmp_arg_dict + + def __register_method_args(self): + """ + That is the method where users should override in their + modules according to be able to send their method arguments + to the Overlord. If they dont have it nothing breaks + just that one in the base class is called + + @return : empty {} + """ + + # to know they didnt implement it + return {} def __is_all_args_registered(self,name): """ -- cgit From e8f7ed14ea4c1f82869253735cb861ac319ca4df Mon Sep 17 00:00:00 2001 From: makkalot Date: Sun, 1 Jun 2008 19:05:03 +0300 Subject: some testing commits --- func/minion/modules/func_module.py | 1 - 1 file changed, 1 deletion(-) (limited to 'func/minion') diff --git a/func/minion/modules/func_module.py b/func/minion/modules/func_module.py index e2a47c3..813dcf2 100644 --- a/func/minion/modules/func_module.py +++ b/func/minion/modules/func_module.py @@ -95,7 +95,6 @@ class FuncModule(object): if not tmp_arg_dict: return {} - #or go ahead #see if user tried to register an not implemented method :) for method in tmp_arg_dict.keys(): if not hasattr(self,method): -- cgit From 7b339cfc592e4243e84a1ecd3f5673021d2b73a0 Mon Sep 17 00:00:00 2001 From: makkalot Date: Sun, 1 Jun 2008 19:13:27 +0300 Subject: a dummy test --- func/minion/modules/func_module.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'func/minion') diff --git a/func/minion/modules/func_module.py b/func/minion/modules/func_module.py index 813dcf2..cb2970c 100644 --- a/func/minion/modules/func_module.py +++ b/func/minion/modules/func_module.py @@ -118,7 +118,7 @@ class FuncModule(object): """ # to know they didnt implement it - return {} + return {'hey':'how'} def __is_all_args_registered(self,name): """ -- cgit From a5b1aac806dad3691a191fe9e13ba07d3f888b2f Mon Sep 17 00:00:00 2001 From: makkalot Date: Sun, 1 Jun 2008 19:17:33 +0300 Subject: move file to parent dir --- func/minion/func_arg.py | 150 ++++++++++++++++++++++++++++++++++++++++ func/minion/modules/func_arg.py | 150 ---------------------------------------- 2 files changed, 150 insertions(+), 150 deletions(-) create mode 100644 func/minion/func_arg.py delete mode 100644 func/minion/modules/func_arg.py (limited to 'func/minion') diff --git a/func/minion/func_arg.py b/func/minion/func_arg.py new file mode 100644 index 0000000..27beb93 --- /dev/null +++ b/func/minion/func_arg.py @@ -0,0 +1,150 @@ +## +## Copyright 2007, Red Hat, Inc +## see AUTHORS +## +## This software may be freely redistributed under the terms of the GNU +## general public license. +## +## You should have received a copy of the GNU General Public License +## along with this program; if not, write to the Free Software +## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +## + +class ArgCompatibility(object): + """ + That class is going to test if the module that was created by module + writer if he/she obeys to the rules we put here + """ + + #these are the common options can be used with all types + __common_options = ('optional','default','description') + + #basic types has types also + __basic_types={ + 'range':(), + 'min':0, + 'max':0, + 'optional':False, + 'description':'', + 'options':(), + 'min_length':0, + 'max_length':0, + 'validator':'', + 'type':'', + 'default':None #its type is unknown + } + + def __init__(self,get_args_result): + """ + The constructor initilized by the get_method_args()(the dict to test) + @param : get_args_result : The dict with all method related info + """ + self.__args_to_check = get_args_result + + #what options does each of the basic_types have : + self.__valid_args={ + 'int':('range','min','max',), + 'string':('options','min_length','max_length','validator',), + 'boolean':(), + 'float':(), + 'hash':('validator',), + 'iterable':('validator',), + } + + + def _is_type_options_compatible(self,argument_dict): + """ + Checks the argument_dict's options and looks inside + self.__valid_args to see if the used option is there + + @param : argument_dict : current argument to check + @return : True of raises IncompatibleTypesException + + """ + #did module writer add a key 'type' + if not argument_dict.has_key('type') or not self.__valid_args.has_key(argument_dict['type']): + raise IncompatibleTypesException("%s is not in valid options"%argument_dict['type']) + + # we will use it everytime so not make lookups + the_type = argument_dict['type'] + from itertools import chain #may i use chain ? + + for key,value in argument_dict.iteritems(): + + if key == "type": + continue + if key not in chain(self.__valid_args[the_type],self.__common_options): + raise IncompatibleTypesException("There is no option like %s in %s"%(key,the_type)) + + return True + + + def _is_basic_types_compatible(self,type_dict): + """ + Validates that if the types that were submitted with + get_method_args were compatible with our format above + in __basic_types + + @param : type_dict : The type to examine + @return : True or raise IncompatibleTypesException Exception + """ + for key,value in type_dict.iteritems(): + + #do we have that type + if not self.__basic_types.has_key(key): + raise IncompatibleTypesException("%s not in the basic_types"%key) + + #if type matches and dont match default + if key!='default' and type(value)!=type(self.__basic_types[key]): + raise IncompatibleTypesException("%s should be %s"%(key,self.__basic_types[key])) + + return True + + + def validate_all(self): + """ + Validates the output for minion module's + get_method_args method + + @return : True or raise IncompatibleTypesException Exception + """ + + for method in self.__args_to_check.iterkeys(): + for argument in self.__args_to_check[method].itervalues(): + self._is_basic_types_compatible(argument) + self._is_type_options_compatible(argument) + + return True + + +###The Exception classes here + + +class IncompatibleTypesException(Exception): + """ + Raised when we assign some values that breaksour rules + @see ArgCompatibility class for allowed situations + """ + def __init__(self, value=None): + Exception.__init__(self) + self.value = value + def __str__(self): + return "%s" %(self.value,) + +class NonExistingMethodRegistered(IncompatibleTypesException): + """ + That Exception is raised when a non existent module is + tried to be registerd we shouldnt allow that + """ + pass + +class UnregisteredMethodArgument(IncompatibleTypesException): + """ + That exception is to try to remove the errors that user may + do during method registration process. If a argument is missed + to be registerted in the method that exception is Raised! + """ + pass + + + diff --git a/func/minion/modules/func_arg.py b/func/minion/modules/func_arg.py deleted file mode 100644 index 27beb93..0000000 --- a/func/minion/modules/func_arg.py +++ /dev/null @@ -1,150 +0,0 @@ -## -## Copyright 2007, Red Hat, Inc -## see AUTHORS -## -## This software may be freely redistributed under the terms of the GNU -## general public license. -## -## You should have received a copy of the GNU General Public License -## along with this program; if not, write to the Free Software -## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -## - -class ArgCompatibility(object): - """ - That class is going to test if the module that was created by module - writer if he/she obeys to the rules we put here - """ - - #these are the common options can be used with all types - __common_options = ('optional','default','description') - - #basic types has types also - __basic_types={ - 'range':(), - 'min':0, - 'max':0, - 'optional':False, - 'description':'', - 'options':(), - 'min_length':0, - 'max_length':0, - 'validator':'', - 'type':'', - 'default':None #its type is unknown - } - - def __init__(self,get_args_result): - """ - The constructor initilized by the get_method_args()(the dict to test) - @param : get_args_result : The dict with all method related info - """ - self.__args_to_check = get_args_result - - #what options does each of the basic_types have : - self.__valid_args={ - 'int':('range','min','max',), - 'string':('options','min_length','max_length','validator',), - 'boolean':(), - 'float':(), - 'hash':('validator',), - 'iterable':('validator',), - } - - - def _is_type_options_compatible(self,argument_dict): - """ - Checks the argument_dict's options and looks inside - self.__valid_args to see if the used option is there - - @param : argument_dict : current argument to check - @return : True of raises IncompatibleTypesException - - """ - #did module writer add a key 'type' - if not argument_dict.has_key('type') or not self.__valid_args.has_key(argument_dict['type']): - raise IncompatibleTypesException("%s is not in valid options"%argument_dict['type']) - - # we will use it everytime so not make lookups - the_type = argument_dict['type'] - from itertools import chain #may i use chain ? - - for key,value in argument_dict.iteritems(): - - if key == "type": - continue - if key not in chain(self.__valid_args[the_type],self.__common_options): - raise IncompatibleTypesException("There is no option like %s in %s"%(key,the_type)) - - return True - - - def _is_basic_types_compatible(self,type_dict): - """ - Validates that if the types that were submitted with - get_method_args were compatible with our format above - in __basic_types - - @param : type_dict : The type to examine - @return : True or raise IncompatibleTypesException Exception - """ - for key,value in type_dict.iteritems(): - - #do we have that type - if not self.__basic_types.has_key(key): - raise IncompatibleTypesException("%s not in the basic_types"%key) - - #if type matches and dont match default - if key!='default' and type(value)!=type(self.__basic_types[key]): - raise IncompatibleTypesException("%s should be %s"%(key,self.__basic_types[key])) - - return True - - - def validate_all(self): - """ - Validates the output for minion module's - get_method_args method - - @return : True or raise IncompatibleTypesException Exception - """ - - for method in self.__args_to_check.iterkeys(): - for argument in self.__args_to_check[method].itervalues(): - self._is_basic_types_compatible(argument) - self._is_type_options_compatible(argument) - - return True - - -###The Exception classes here - - -class IncompatibleTypesException(Exception): - """ - Raised when we assign some values that breaksour rules - @see ArgCompatibility class for allowed situations - """ - def __init__(self, value=None): - Exception.__init__(self) - self.value = value - def __str__(self): - return "%s" %(self.value,) - -class NonExistingMethodRegistered(IncompatibleTypesException): - """ - That Exception is raised when a non existent module is - tried to be registerd we shouldnt allow that - """ - pass - -class UnregisteredMethodArgument(IncompatibleTypesException): - """ - That exception is to try to remove the errors that user may - do during method registration process. If a argument is missed - to be registerted in the method that exception is Raised! - """ - pass - - - -- cgit From 5ff04c7b52d9f273bb307aa03346e05466d5e5b4 Mon Sep 17 00:00:00 2001 From: makkalot Date: Sun, 1 Jun 2008 19:19:10 +0300 Subject: fix the import not to fail --- func/minion/modules/func_module.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'func/minion') diff --git a/func/minion/modules/func_module.py b/func/minion/modules/func_module.py index cb2970c..07b5443 100644 --- a/func/minion/modules/func_module.py +++ b/func/minion/modules/func_module.py @@ -15,7 +15,7 @@ import inspect from func import logger from func.config import read_config from func.commonconfig import FuncdConfig -from func.minion.modules.func_arg import * #the arg getter stuff +from func.minion.func_arg import * #the arg getter stuff class FuncModule(object): -- cgit From c1caf860b5bcf68ac3bd542f792626b115324566 Mon Sep 17 00:00:00 2001 From: makkalot Date: Sun, 1 Jun 2008 20:42:48 +0300 Subject: remove that dummy line im a complete git lame really --- func/minion/modules/func_module.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'func/minion') diff --git a/func/minion/modules/func_module.py b/func/minion/modules/func_module.py index 07b5443..5c9eb03 100644 --- a/func/minion/modules/func_module.py +++ b/func/minion/modules/func_module.py @@ -118,7 +118,7 @@ class FuncModule(object): """ # to know they didnt implement it - return {'hey':'how'} + return {} def __is_all_args_registered(self,name): """ -- cgit From 7388fc3e74711c5a9a788e96a02d7daa063ba9d4 Mon Sep 17 00:00:00 2001 From: makkalot Date: Mon, 2 Jun 2008 19:29:23 +0300 Subject: remove the old version of the get_method_arguments --- func/minion/modules/func_module.py | 37 ------------------------------------- 1 file changed, 37 deletions(-) (limited to 'func/minion') diff --git a/func/minion/modules/func_module.py b/func/minion/modules/func_module.py index 5c9eb03..cfd7438 100644 --- a/func/minion/modules/func_module.py +++ b/func/minion/modules/func_module.py @@ -120,40 +120,3 @@ class FuncModule(object): # to know they didnt implement it return {} - def __is_all_args_registered(self,name): - """ - Checks if module writer has made some mistakes about - argument registering - - @param name: the name of the method with arguments registered in it - @retun : dict(name:[arg1,arg2...]) or {} - """ - #FIXME tobe rewritten - if name in self.__base_methods.keys(): - return {} - - #tests showed that sometimes happens - if not hasattr(self,name): - return {} - - if not self.__is_public_valid_method(name): - return {} - - arg_names = inspect.getargspec(getattr(self,name)) - #arg_names[0] is argument names - #arg_names[1] is *arg - #arg_names[2] is **kwarg - #arg_names[3] are defaults - - name_dict =[other_args for other_args in arg_names[1:3] if other_args] - arg_names = arg_names[0] or [] - - #if we have self lets remove it - for rem in arg_names: - if rem=="self": - arg_names.remove(rem) - break - - final_dict={} - final_dict[name]=arg_names+name_dict - return final_dict -- cgit From 871aae17edf1f0e45ad8075016bde1ba5f68e969 Mon Sep 17 00:00:00 2001 From: makkalot Date: Mon, 2 Jun 2008 19:30:12 +0300 Subject: implement the current options for service module to see if it works --- func/minion/modules/service.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'func/minion') diff --git a/func/minion/modules/service.py b/func/minion/modules/service.py index 062aea5..a4e8bea 100644 --- a/func/minion/modules/service.py +++ b/func/minion/modules/service.py @@ -86,3 +86,29 @@ class Service(func_module.FuncModule): tokens = line.split() results.append((tokens[0], tokens[-1].replace("...",""))) return results + + def __register_method_args(self): + """ + Implementing the argument getter + """ + + #service_name options they are same so use only one + service_name = { + 'type':'string', + 'description':'The name of the running services', + 'validator':'^[a-z]+$'} + + return { + 'get_running':{}, + 'get_enabled':{}, + 'inventory':{}, + 'status':{ + 'service_name':service_name, + }, + 'reload':{'service_name':service_name}, + 'restart':{'service_name':service_name}, + 'stop':{'service_name':service_name}, + 'start':{'service_name':service_name}, + + + } -- cgit From 1b4b73ed260c72ebeb0168c4a649e4f02eeb8dde Mon Sep 17 00:00:00 2001 From: makkalot Date: Mon, 2 Jun 2008 19:56:48 +0300 Subject: arghh we can not use private methods so make public that register thing --- func/minion/modules/func_module.py | 6 +++--- func/minion/modules/service.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'func/minion') diff --git a/func/minion/modules/func_module.py b/func/minion/modules/func_module.py index cfd7438..724a27b 100644 --- a/func/minion/modules/func_module.py +++ b/func/minion/modules/func_module.py @@ -77,7 +77,7 @@ class FuncModule(object): def __is_public_valid_method(self,attr): if inspect.ismethod(getattr(self, attr)) and attr[0] != '_' and\ - attr != 'register_rpc': + attr != 'register_rpc' and attr!='register_method_args': return True return False @@ -89,7 +89,7 @@ class FuncModule(object): @return : dict with args or Raise Exception if something wrong happens """ - tmp_arg_dict = self.__register_method_args() + tmp_arg_dict = self.register_method_args() #if it is not implemeted then return empty stuff if not tmp_arg_dict: @@ -107,7 +107,7 @@ class FuncModule(object): return tmp_arg_dict - def __register_method_args(self): + def register_method_args(self): """ That is the method where users should override in their modules according to be able to send their method arguments diff --git a/func/minion/modules/service.py b/func/minion/modules/service.py index a4e8bea..e615e1b 100644 --- a/func/minion/modules/service.py +++ b/func/minion/modules/service.py @@ -87,7 +87,7 @@ class Service(func_module.FuncModule): results.append((tokens[0], tokens[-1].replace("...",""))) return results - def __register_method_args(self): + def register_method_args(self): """ Implementing the argument getter """ -- cgit From 18a872de604eaeefff7603fd889a8f7baf8fc94e Mon Sep 17 00:00:00 2001 From: makkalot Date: Sun, 8 Jun 2008 15:03:24 +0300 Subject: adding method_name:{args:{},description:..} structure to get_method_args and fixing some stupid bugs --- func/minion/func_arg.py | 42 +++++++++++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 11 deletions(-) (limited to 'func/minion') diff --git a/func/minion/func_arg.py b/func/minion/func_arg.py index 27beb93..b8a01fa 100644 --- a/func/minion/func_arg.py +++ b/func/minion/func_arg.py @@ -18,15 +18,16 @@ class ArgCompatibility(object): #these are the common options can be used with all types __common_options = ('optional','default','description') + __method_options = ('description','args') #making method declarations more generic like method_name:{'args':{...},'description':"bla bla"} #basic types has types also __basic_types={ - 'range':(), + 'range':[1,], 'min':0, 'max':0, 'optional':False, 'description':'', - 'options':(), + 'options':[1,], 'min_length':0, 'max_length':0, 'validator':'', @@ -54,7 +55,7 @@ class ArgCompatibility(object): def _is_type_options_compatible(self,argument_dict): """ - Checks the argument_dict's options and looks inside + Checks the method's argument_dict's options and looks inside self.__valid_args to see if the used option is there @param : argument_dict : current argument to check @@ -63,7 +64,7 @@ class ArgCompatibility(object): """ #did module writer add a key 'type' if not argument_dict.has_key('type') or not self.__valid_args.has_key(argument_dict['type']): - raise IncompatibleTypesException("%s is not in valid options"%argument_dict['type']) + raise IncompatibleTypesException("%s is not in valid options,possible ones are :%s"%(argument_dict['type'],str(self.__valid_args))) # we will use it everytime so not make lookups the_type = argument_dict['type'] @@ -88,6 +89,7 @@ class ArgCompatibility(object): @param : type_dict : The type to examine @return : True or raise IncompatibleTypesException Exception """ + #print "The structure we got is %s:"%(type_dict) for key,value in type_dict.iteritems(): #do we have that type @@ -95,24 +97,42 @@ class ArgCompatibility(object): raise IncompatibleTypesException("%s not in the basic_types"%key) #if type matches and dont match default + #print "The key: %s its value %s and type %s"%(key,value,type(value)) if key!='default' and type(value)!=type(self.__basic_types[key]): - raise IncompatibleTypesException("%s should be %s"%(key,self.__basic_types[key])) + raise IncompatibleTypesException("The %s keyword should be in that type %s"%(key,type(self.__basic_types[key]))) - return True + return True def validate_all(self): """ Validates the output for minion module's get_method_args method - + + The structure that is going to be validated is in that format : + + { + method_name1 : {'args':{...}, + 'description':"wowo"}, + method_name12 : {...} + } + @return : True or raise IncompatibleTypesException Exception """ - + for method in self.__args_to_check.iterkeys(): - for argument in self.__args_to_check[method].itervalues(): - self._is_basic_types_compatible(argument) - self._is_type_options_compatible(argument) + #here we got args or description part + #check if user did submit something not in the __method_options + + for method_option in self.__args_to_check[method].iterkeys(): + if method_option not in self.__method_options: + raise IncompatibleTypesException("There is no option for method_name like %s,possible ones are : %s"%(method_option,str(self.__method_options))) + #check what is inside the args + if method_option == "args": + for argument in self.__args_to_check[method][method_option].itervalues(): + #print argument + self._is_basic_types_compatible(argument) + self._is_type_options_compatible(argument) return True -- cgit From 00d991fc56a21460ff4989d1b50fbb28788fe3e3 Mon Sep 17 00:00:00 2001 From: makkalot Date: Sun, 8 Jun 2008 15:23:54 +0300 Subject: update the service module according to new stuff --- func/minion/modules/service.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'func/minion') diff --git a/func/minion/modules/service.py b/func/minion/modules/service.py index e615e1b..5052615 100644 --- a/func/minion/modules/service.py +++ b/func/minion/modules/service.py @@ -99,16 +99,18 @@ class Service(func_module.FuncModule): 'validator':'^[a-z]+$'} return { - 'get_running':{}, - 'get_enabled':{}, - 'inventory':{}, - 'status':{ + 'get_running':{'args':{}}, + 'get_enabled':{'args':{}}, + 'inventory':{'args':{}}, + 'status':{'args':{ 'service_name':service_name, }, - 'reload':{'service_name':service_name}, - 'restart':{'service_name':service_name}, - 'stop':{'service_name':service_name}, - 'start':{'service_name':service_name}, + 'description':'Getting the status of the service_name' + }, + 'reload':{'args':{'service_name':service_name}}, + 'restart':{'args':{'service_name':service_name}}, + 'stop':{'args':{'service_name':service_name}}, + 'start':{'args':{'service_name':service_name}}, } -- cgit From e05caff42e95b4926411071200da422aa19e5605 Mon Sep 17 00:00:00 2001 From: makkalot Date: Mon, 9 Jun 2008 01:00:06 +0300 Subject: change name iterable to list to prevent confusions --- func/minion/func_arg.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'func/minion') diff --git a/func/minion/func_arg.py b/func/minion/func_arg.py index b8a01fa..4a5ed7e 100644 --- a/func/minion/func_arg.py +++ b/func/minion/func_arg.py @@ -47,9 +47,9 @@ class ArgCompatibility(object): 'int':('range','min','max',), 'string':('options','min_length','max_length','validator',), 'boolean':(), - 'float':(), + 'float':('range','min','max'), 'hash':('validator',), - 'iterable':('validator',), + 'list':('validator',), } -- cgit From c06d90260d9e6b2d0862ebe0a7f432329daefe94 Mon Sep 17 00:00:00 2001 From: makkalot Date: Sun, 15 Jun 2008 16:49:28 +0300 Subject: i think we need to know which argument is in which order so added to validator part to add it returning data srtucure with method_arguments --- func/minion/func_arg.py | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) (limited to 'func/minion') diff --git a/func/minion/func_arg.py b/func/minion/func_arg.py index 4a5ed7e..8ca460a 100644 --- a/func/minion/func_arg.py +++ b/func/minion/func_arg.py @@ -103,6 +103,28 @@ class ArgCompatibility(object): return True + def is_all_arguments_registered(self,cls,method_name,arguments): + """ + Method inspects the method arguments and checks if the user + has registered all the arguments succesfully and also adds a + 'order' keyword to method arguments to + """ + import inspect + from itertools import chain + #get the arguments from real object we have [args],*arg,**kwarg,[defaults] + tmp_arguments=inspect.getargspec(getattr(cls,method_name)) + check_args=[arg for arg in chain(tmp_arguments[0],tmp_arguments[1:3]) if arg and arg!='self'] + print "The arguments taken from the inspect are :",check_args + #the size may change of the hash so should a copy of it + copy_arguments = arguments.copy() + for compare_arg in copy_arguments.iterkeys(): + if not compare_arg in check_args: + raise ArgumentRegistrationError("The argument %s is not in the %s"%(compare_arg,method_name)) + else: + #should set its ordering thing + arguments[compare_arg]['order']=check_args.index(compare_arg) + + return True def validate_all(self): """ @@ -123,7 +145,6 @@ class ArgCompatibility(object): for method in self.__args_to_check.iterkeys(): #here we got args or description part #check if user did submit something not in the __method_options - for method_option in self.__args_to_check[method].iterkeys(): if method_option not in self.__method_options: raise IncompatibleTypesException("There is no option for method_name like %s,possible ones are : %s"%(method_option,str(self.__method_options))) @@ -131,13 +152,15 @@ class ArgCompatibility(object): if method_option == "args": for argument in self.__args_to_check[method][method_option].itervalues(): #print argument + #check if user registered all the args and add to them ordering option! self._is_basic_types_compatible(argument) self._is_type_options_compatible(argument) return True -###The Exception classes here +###The Exception classes here they will be raised during the validation part +###If a module passes all the tests it is ready tobe registered class IncompatibleTypesException(Exception): @@ -167,4 +190,16 @@ class UnregisteredMethodArgument(IncompatibleTypesException): pass +class NonExistingMethodRegistered(IncompatibleTypesException): + """ + Raised when module writer registers a method that doesnt + exist in his/her module class (probably by mistake) + """ + pass +class ArgumentRegistrationError(IncompatibleTypesException): + """ + When user forgets to register soem of the arguments in the list + or adds some argument that is not there + """ + pass -- cgit From f835390c4362d95e6d9084577e662332b82e2a20 Mon Sep 17 00:00:00 2001 From: makkalot Date: Sun, 15 Jun 2008 16:50:08 +0300 Subject: validating if all arguments are registered --- func/minion/modules/func_module.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'func/minion') diff --git a/func/minion/modules/func_module.py b/func/minion/modules/func_module.py index 724a27b..e66f410 100644 --- a/func/minion/modules/func_module.py +++ b/func/minion/modules/func_module.py @@ -96,12 +96,15 @@ class FuncModule(object): return {} #see if user tried to register an not implemented method :) - for method in tmp_arg_dict.keys(): + for method in tmp_arg_dict.iterkeys(): if not hasattr(self,method): raise NonExistingMethodRegistered("%s is not in %s "%(method,self.__class__.__name__)) #create argument validation instance self.arg_comp = ArgCompatibility(tmp_arg_dict) + #see if all registered arguments are there + for method in tmp_arg_dict.iterkeys(): + self.is_all_arguments_registered(self,method,tmp_arg_dict[method]['args']) #see if the options that were used are OK.. self.arg_comp.validate_all() -- cgit From 9419566c1968db33b1d9d50ba02921c5bbe98c16 Mon Sep 17 00:00:00 2001 From: makkalot Date: Sun, 15 Jun 2008 18:25:53 +0300 Subject: export iptables method arguments --- func/minion/modules/iptables/port.py | 85 ++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) (limited to 'func/minion') diff --git a/func/minion/modules/iptables/port.py b/func/minion/modules/iptables/port.py index 370123b..3d3902b 100644 --- a/func/minion/modules/iptables/port.py +++ b/func/minion/modules/iptables/port.py @@ -128,6 +128,91 @@ class Port(func_module.FuncModule): clear_all("-D OUTPUT -p %s --%sport %s -d %s -j REJECT" % (prot, dir, port, ip) ) return call_if_policy("OUTPUT", "DROP", "-I OUTPUT -p %s --%sport %s -d %s -j ACCEPT" % (prot, dir, port, ip) ) + def register_method_args(self): + """ + Export the methods and their definitons + """ + #they are all same so just declare here + port={ + 'type':'string', + 'optional':False, + + } + ip={ + 'type':'string', + 'optional':False, + 'default':'0.0.0.0' + } + prot={ + 'type':'string', + 'options':['tcp','udp','icmp','sctp'], + 'default':'tcp', + 'optional':False + } + dir={ + 'type':'string', + 'default':'dst', + 'options':['src','dst'], + 'optional':False + } + + return { + 'drop_from':{'args': + { + 'ip':ip, + 'prot':prot, + 'dir':dir, + 'port':port + } + }, + 'reject_from':{'args': + { + 'ip':ip, + 'prot':prot, + 'dir':dir, + 'port':port + + } + }, + 'accept_from':{'args': + { + 'ip':ip, + 'prot':prot, + 'dir':dir, + 'port':port + + } + }, + 'drop_to':{'args': + { + 'ip':ip, + 'prot':prot, + 'dir':dir, + 'port':port + + } + }, + 'reject_to':{'args': + { + 'ip':ip, + 'prot':prot, + 'dir':dir, + 'port':port + + } + }, + 'accept_to':{'args': + { + 'ip':ip, + 'prot':prot, + 'dir':dir, + 'port':port + + } + }, + + } + def parse_dir(dir): if (dir == "dst"): return "d" -- cgit From 3bbc0f1d9a588ea0416dce9acb07de77efab51c0 Mon Sep 17 00:00:00 2001 From: makkalot Date: Sun, 15 Jun 2008 19:05:09 +0300 Subject: fixing a silly mistake --- func/minion/modules/func_module.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'func/minion') diff --git a/func/minion/modules/func_module.py b/func/minion/modules/func_module.py index e66f410..53fd66b 100644 --- a/func/minion/modules/func_module.py +++ b/func/minion/modules/func_module.py @@ -104,7 +104,7 @@ class FuncModule(object): self.arg_comp = ArgCompatibility(tmp_arg_dict) #see if all registered arguments are there for method in tmp_arg_dict.iterkeys(): - self.is_all_arguments_registered(self,method,tmp_arg_dict[method]['args']) + self.arg_comp.is_all_arguments_registered(self,method,tmp_arg_dict[method]['args']) #see if the options that were used are OK.. self.arg_comp.validate_all() -- cgit From a041a0d7eb7848825512ce8a6ae8243710356dfb Mon Sep 17 00:00:00 2001 From: makkalot Date: Sun, 15 Jun 2008 19:15:59 +0300 Subject: forgot to add order keyword to basic allowed types so couldnt pass the tests :) --- func/minion/func_arg.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'func/minion') diff --git a/func/minion/func_arg.py b/func/minion/func_arg.py index 8ca460a..bf07f1e 100644 --- a/func/minion/func_arg.py +++ b/func/minion/func_arg.py @@ -32,7 +32,8 @@ class ArgCompatibility(object): 'max_length':0, 'validator':'', 'type':'', - 'default':None #its type is unknown + 'default':None, #its type is unknown, + 'order':0 } def __init__(self,get_args_result): -- cgit From 207dea025323340aeb72c61cf499f348828f393f Mon Sep 17 00:00:00 2001 From: makkalot Date: Sun, 15 Jun 2008 19:28:28 +0300 Subject: haah i can not pass my unittests --- func/minion/func_arg.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'func/minion') diff --git a/func/minion/func_arg.py b/func/minion/func_arg.py index bf07f1e..bde5388 100644 --- a/func/minion/func_arg.py +++ b/func/minion/func_arg.py @@ -17,7 +17,7 @@ class ArgCompatibility(object): """ #these are the common options can be used with all types - __common_options = ('optional','default','description') + __common_options = ('optional','default','description','order') __method_options = ('description','args') #making method declarations more generic like method_name:{'args':{...},'description':"bla bla"} #basic types has types also -- cgit From 5556eb2c218931dcb6f8c5a004eb9b9902cc10e8 Mon Sep 17 00:00:00 2001 From: makkalot Date: Fri, 20 Jun 2008 00:02:18 +0300 Subject: if there is a options keyword in args the others should be there there is no sense --- func/minion/func_arg.py | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'func/minion') diff --git a/func/minion/func_arg.py b/func/minion/func_arg.py index bde5388..6ff7a35 100644 --- a/func/minion/func_arg.py +++ b/func/minion/func_arg.py @@ -66,6 +66,15 @@ class ArgCompatibility(object): #did module writer add a key 'type' if not argument_dict.has_key('type') or not self.__valid_args.has_key(argument_dict['type']): raise IncompatibleTypesException("%s is not in valid options,possible ones are :%s"%(argument_dict['type'],str(self.__valid_args))) + + #we need some specialization about if user has defined options + #there is no need for using validator,min_lenght,max_length + if argument_dict.has_key('options'): + for arg_option in argument_dict.keys(): + if arg_option!='options' and arg_option in self.__valid_args['string']: + raise IncompatibleTypesException('The options keyword should be used alone in a string cant be used with min_length,max_length,validator together') + + #will add here a new for integers # we will use it everytime so not make lookups the_type = argument_dict['type'] -- cgit From c92df80d5e48cb56056bbe37c0982391cf376388 Mon Sep 17 00:00:00 2001 From: makkalot Date: Fri, 20 Jun 2008 14:49:41 +0300 Subject: adding extra validation for range option in integers --- func/minion/func_arg.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'func/minion') diff --git a/func/minion/func_arg.py b/func/minion/func_arg.py index 6ff7a35..6c416e4 100644 --- a/func/minion/func_arg.py +++ b/func/minion/func_arg.py @@ -74,7 +74,17 @@ class ArgCompatibility(object): if arg_option!='options' and arg_option in self.__valid_args['string']: raise IncompatibleTypesException('The options keyword should be used alone in a string cant be used with min_length,max_length,validator together') - #will add here a new for integers + #if range keyword is used into a int argument the others shouldnt be there + if argument_dict.has_key('range'): + if len(argument_dict['range'])!=2: + raise IncompatibleTypesException('The range option should have 2 members [min,max]') + if not argument_dict['range'][0] < argument_dict['range'][1]: + raise IncompatibleTypesException('In the range option first member should be smaller than second [min,max]') + #check if another option was used there ... + for arg_option in argument_dict.keys(): + if arg_option!='range' and arg_option in self.__valid_args['int']: + raise IncompatibleTypesException('The options range should be used alone into a int argument') + # we will use it everytime so not make lookups the_type = argument_dict['type'] -- cgit From 2cf7e75d505b9db2724d6d063db3aaee5c799de7 Mon Sep 17 00:00:00 2001 From: makkalot Date: Sun, 22 Jun 2008 16:13:58 +0300 Subject: the ugly print message that fills all the screen :) --- func/minion/func_arg.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'func/minion') diff --git a/func/minion/func_arg.py b/func/minion/func_arg.py index 6c416e4..5025e17 100644 --- a/func/minion/func_arg.py +++ b/func/minion/func_arg.py @@ -134,7 +134,7 @@ class ArgCompatibility(object): #get the arguments from real object we have [args],*arg,**kwarg,[defaults] tmp_arguments=inspect.getargspec(getattr(cls,method_name)) check_args=[arg for arg in chain(tmp_arguments[0],tmp_arguments[1:3]) if arg and arg!='self'] - print "The arguments taken from the inspect are :",check_args + #print "The arguments taken from the inspect are :",check_args #the size may change of the hash so should a copy of it copy_arguments = arguments.copy() for compare_arg in copy_arguments.iterkeys(): -- cgit From 5d54662be9245bf654ab7e628ea286b6d87605b9 Mon Sep 17 00:00:00 2001 From: makkalot Date: Sun, 22 Jun 2008 16:14:32 +0300 Subject: better validation in server side for services --- func/minion/modules/service.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'func/minion') diff --git a/func/minion/modules/service.py b/func/minion/modules/service.py index 5052615..25acea3 100644 --- a/func/minion/modules/service.py +++ b/func/minion/modules/service.py @@ -95,8 +95,9 @@ class Service(func_module.FuncModule): #service_name options they are same so use only one service_name = { 'type':'string', + 'optional':False, 'description':'The name of the running services', - 'validator':'^[a-z]+$'} + 'validator':'^[a-z\-\_0-9]+$'} return { 'get_running':{'args':{}}, -- cgit