diff --git a/pepper/cli.py b/pepper/cli.py index 68901d9..0a6a02a 100644 --- a/pepper/cli.py +++ b/pepper/cli.py @@ -200,50 +200,50 @@ def add_tgtopts(self): ''' optgroup = optparse.OptionGroup(self.parser, "Targeting Options", "Target which minions to run commands on") - optgroup.defaults.update({'expr_form': 'glob'}) + optgroup.defaults.update({'tgt_type': 'glob'}) optgroup.add_option( - '-E', '--pcre', dest='expr_form', action='store_const', const='pcre', + '-E', '--pcre', dest='tgt_type', action='store_const', const='pcre', help="Target hostnames using PCRE regular expressions", ) optgroup.add_option( - '-L', '--list', dest='expr_form', action='store_const', const='list', + '-L', '--list', dest='tgt_type', action='store_const', const='list', help="Specify a comma delimited list of hostnames", ) optgroup.add_option( - '-G', '--grain', dest='expr_form', action='store_const', const='grain', + '-G', '--grain', dest='tgt_type', action='store_const', const='grain', help="Target based on system properties", ) optgroup.add_option( - '--grain-pcre', dest='expr_form', action='store_const', const='grain_pcre', + '--grain-pcre', dest='tgt_type', action='store_const', const='grain_pcre', help="Target based on PCRE matches on system properties", ) optgroup.add_option( - '-I', '--pillar', dest='expr_form', action='store_const', const='pillar', + '-I', '--pillar', dest='tgt_type', action='store_const', const='pillar', help="Target based on pillar values", ) optgroup.add_option( - '--pillar-pcre', dest='expr_form', action='store_const', const='pillar_pcre', + '--pillar-pcre', dest='tgt_type', action='store_const', const='pillar_pcre', help="Target based on PCRE matches on pillar values" ) optgroup.add_option( - '-R', '--range', dest='expr_form', action='store_const', const='range', + '-R', '--range', dest='tgt_type', action='store_const', const='range', help="Target based on range expression", ) optgroup.add_option( - '-C', '--compound', dest='expr_form', action='store_const', const='compound', + '-C', '--compound', dest='tgt_type', action='store_const', const='compound', help="Target based on compound expression", ) optgroup.add_option( - '-N', '--nodegroup', dest='expr_form', action='store_const', const='nodegroup', + '-N', '--nodegroup', dest='tgt_type', action='store_const', const='nodegroup', help="Target based on a named nodegroup", ) @@ -500,7 +500,7 @@ def parse_cmd(self, api): if len(args) < 2: self.parser.error("Command or target not specified") - low['tgt_type'] = self.options.expr_form + low['tgt_type'] = self.options.tgt_type low['tgt'] = args.pop(0) low['fun'] = args.pop(0) low['batch'] = self.options.batch @@ -542,7 +542,7 @@ def parse_cmd(self, api): if len(args) < 2: self.parser.error("Command or target not specified") - low['tgt_type'] = self.options.expr_form + low['tgt_type'] = self.options.tgt_type low['tgt'] = args.pop(0) low['fun'] = args.pop(0) low['batch'] = self.options.batch diff --git a/pepper/libpepper.py b/pepper/libpepper.py index c9ab461..78371c2 100644 --- a/pepper/libpepper.py +++ b/pepper/libpepper.py @@ -307,8 +307,8 @@ def low(self, lowstate, path='/'): ''' return self.req(path, lowstate) - def local(self, tgt, fun, arg=None, kwarg=None, expr_form='glob', - timeout=None, ret=None): + def local(self, tgt, fun, arg=None, kwarg=None, tgt_type='glob', + timeout=None, ret=None, expr_form=None): ''' Run a single command using the ``local`` client @@ -326,8 +326,12 @@ def local(self, tgt, fun, arg=None, kwarg=None, expr_form='glob', if kwarg: low['kwarg'] = kwarg + if tgt_type: + low['tgt_type'] = tgt_type + if expr_form: - low['expr_form'] = expr_form + logger.warning('expr_form argument is deprecated in local function, please use tgt_type instead') + low['tgt_type'] = expr_form if timeout: low['timeout'] = timeout @@ -337,8 +341,8 @@ def local(self, tgt, fun, arg=None, kwarg=None, expr_form='glob', return self.low([low]) - def local_async(self, tgt, fun, arg=None, kwarg=None, expr_form='glob', - timeout=None, ret=None): + def local_async(self, tgt, fun, arg=None, kwarg=None, tgt_type='glob', + timeout=None, ret=None, expr_form=None): ''' Run a single command using the ``local_async`` client @@ -356,8 +360,12 @@ def local_async(self, tgt, fun, arg=None, kwarg=None, expr_form='glob', if kwarg: low['kwarg'] = kwarg + if tgt_type: + low['tgt_type'] = tgt_type + if expr_form: - low['expr_form'] = expr_form + logger.warning('expr_form argument is deprecated in local function, please use tgt_type instead') + low['tgt_type'] = expr_form if timeout: low['timeout'] = timeout @@ -367,8 +375,8 @@ def local_async(self, tgt, fun, arg=None, kwarg=None, expr_form='glob', return self.low([low]) - def local_batch(self, tgt, fun, arg=None, kwarg=None, expr_form='glob', - batch='50%', ret=None): + def local_batch(self, tgt, fun, arg=None, kwarg=None, tgt_type='glob', + batch='50%', ret=None, expr_form=None): ''' Run a single command using the ``local_batch`` client @@ -386,8 +394,12 @@ def local_batch(self, tgt, fun, arg=None, kwarg=None, expr_form='glob', if kwarg: low['kwarg'] = kwarg + if tgt_type: + low['tgt_type'] = tgt_type + if expr_form: - low['expr_form'] = expr_form + logger.warning('expr_form argument is deprecated in local function, please use tgt_type instead') + low['tgt_type'] = expr_form if batch: low['batch'] = batch diff --git a/tests/integration/test_local.py b/tests/integration/test_local.py index ba0c24c..31d7538 100644 --- a/tests/integration/test_local.py +++ b/tests/integration/test_local.py @@ -3,3 +3,14 @@ def test_local(pepper_client, session_minion_id): assert pepper_client.local('*', 'test.ping')['return'][0][session_minion_id] is True + + +def test_local_with_tgt_type(pepper_client, session_minion_id): + assert session_minion_id not in pepper_client.local('*', 'test.ping', tgt_type='list')['return'][0] + assert pepper_client.local(session_minion_id, 'test.ping', tgt_type='list')['return'][0][session_minion_id] is True + + +def test_local_with_deprecated_expr_form(pepper_client, session_minion_id): + assert session_minion_id not in pepper_client.local('*', 'test.ping', expr_form='list')['return'][0] + r = pepper_client.local(session_minion_id, 'test.ping', expr_form='list')['return'][0][session_minion_id] + assert r is True