From f4390b74e5d2b6d08da13b17fed77ee31ab66bbe Mon Sep 17 00:00:00 2001 From: Maximilien Cuony Date: Tue, 2 Apr 2019 09:48:34 +0200 Subject: [PATCH 1/3] Use tgt_type instead of expr_form (deprecated in 2017.07 - removed in 2019.02) --- pepper/cli.py | 24 ++++++++++++------------ pepper/libpepper.py | 18 +++++++++--------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/pepper/cli.py b/pepper/cli.py index 1446333..8473c88 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", ) @@ -498,7 +498,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 @@ -540,7 +540,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 c5cecf6..60c03db 100644 --- a/pepper/libpepper.py +++ b/pepper/libpepper.py @@ -307,7 +307,7 @@ def low(self, lowstate, path='/'): ''' return self.req(path, lowstate) - def local(self, tgt, fun, arg=None, kwarg=None, expr_form='glob', + def local(self, tgt, fun, arg=None, kwarg=None, tgt_type='glob', timeout=None, ret=None): ''' Run a single command using the ``local`` client @@ -326,8 +326,8 @@ def local(self, tgt, fun, arg=None, kwarg=None, expr_form='glob', if kwarg: low['kwarg'] = kwarg - if expr_form: - low['expr_form'] = expr_form + if tgt_type: + low['tgt_type'] = tgt_type if timeout: low['timeout'] = timeout @@ -337,7 +337,7 @@ 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', + def local_async(self, tgt, fun, arg=None, kwarg=None, tgt_type='glob', timeout=None, ret=None): ''' Run a single command using the ``local_async`` client @@ -356,8 +356,8 @@ def local_async(self, tgt, fun, arg=None, kwarg=None, expr_form='glob', if kwarg: low['kwarg'] = kwarg - if expr_form: - low['expr_form'] = expr_form + if tgt_type: + low['tgt_type'] = tgt_type if timeout: low['timeout'] = timeout @@ -367,7 +367,7 @@ 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', + def local_batch(self, tgt, fun, arg=None, kwarg=None, tgt_type='glob', batch='50%', ret=None): ''' Run a single command using the ``local_batch`` client @@ -386,8 +386,8 @@ def local_batch(self, tgt, fun, arg=None, kwarg=None, expr_form='glob', if kwarg: low['kwarg'] = kwarg - if expr_form: - low['expr_form'] = expr_form + if tgt_type: + low['tgt_type'] = tgt_type if batch: low['batch'] = batch From 37631fe16d9880cfc06d9e82b2109c991d2f2500 Mon Sep 17 00:00:00 2001 From: Maximilien Cuony Date: Mon, 24 Apr 2023 10:11:47 +0200 Subject: [PATCH 2/3] tgt_type vs expr_form: add backward compatilibty, add tests --- pepper/libpepper.py | 9 ++++++++- tests/integration/test_local.py | 10 ++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/pepper/libpepper.py b/pepper/libpepper.py index 46880c3..205b101 100644 --- a/pepper/libpepper.py +++ b/pepper/libpepper.py @@ -308,7 +308,7 @@ def low(self, lowstate, path='/'): return self.req(path, lowstate) def local(self, tgt, fun, arg=None, kwarg=None, tgt_type='glob', - timeout=None, ret=None): + timeout=None, ret=None, expr_form=None): ''' Run a single command using the ``local`` client @@ -329,6 +329,13 @@ def local(self, tgt, fun, arg=None, kwarg=None, tgt_type='glob', if tgt_type: low['tgt_type'] = tgt_type + if expr_form: + + logger.warning('expr_form argument is deprecated in local function, please use tgt_type instead') + + if not tgt_type: + low['tgt_type'] = expr_form + if timeout: low['timeout'] = timeout diff --git a/tests/integration/test_local.py b/tests/integration/test_local.py index ba0c24c..1db97c1 100644 --- a/tests/integration/test_local.py +++ b/tests/integration/test_local.py @@ -3,3 +3,13 @@ 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 pepper_client.local('*', 'test.ping', tgt_type='list')['return'][0][session_minion_id] is False + 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 pepper_client.local('*', 'test.ping', expr_form='list')['return'][0][session_minion_id] is False + assert pepper_client.local(session_minion_id, 'test.ping', expr_form='list')['return'][0][session_minion_id] is True From d368f85766c501b6b3611d1e39b9831c1a30f15f Mon Sep 17 00:00:00 2001 From: Maximilien Cuony Date: Wed, 3 May 2023 11:05:26 +0200 Subject: [PATCH 3/3] tgt_type vs expr_form: fix tests, extra backward compatibility --- pepper/libpepper.py | 17 +++++++++++------ tests/integration/test_local.py | 7 ++++--- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/pepper/libpepper.py b/pepper/libpepper.py index 205b101..78371c2 100644 --- a/pepper/libpepper.py +++ b/pepper/libpepper.py @@ -330,11 +330,8 @@ def local(self, tgt, fun, arg=None, kwarg=None, tgt_type='glob', low['tgt_type'] = tgt_type if expr_form: - logger.warning('expr_form argument is deprecated in local function, please use tgt_type instead') - - if not tgt_type: - low['tgt_type'] = expr_form + low['tgt_type'] = expr_form if timeout: low['timeout'] = timeout @@ -345,7 +342,7 @@ def local(self, tgt, fun, arg=None, kwarg=None, tgt_type='glob', return self.low([low]) def local_async(self, tgt, fun, arg=None, kwarg=None, tgt_type='glob', - timeout=None, ret=None): + timeout=None, ret=None, expr_form=None): ''' Run a single command using the ``local_async`` client @@ -366,6 +363,10 @@ def local_async(self, tgt, fun, arg=None, kwarg=None, tgt_type='glob', if tgt_type: low['tgt_type'] = tgt_type + if 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 @@ -375,7 +376,7 @@ def local_async(self, tgt, fun, arg=None, kwarg=None, tgt_type='glob', return self.low([low]) def local_batch(self, tgt, fun, arg=None, kwarg=None, tgt_type='glob', - batch='50%', ret=None): + batch='50%', ret=None, expr_form=None): ''' Run a single command using the ``local_batch`` client @@ -396,6 +397,10 @@ def local_batch(self, tgt, fun, arg=None, kwarg=None, tgt_type='glob', if tgt_type: low['tgt_type'] = tgt_type + if 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 1db97c1..31d7538 100644 --- a/tests/integration/test_local.py +++ b/tests/integration/test_local.py @@ -6,10 +6,11 @@ def test_local(pepper_client, session_minion_id): def test_local_with_tgt_type(pepper_client, session_minion_id): - assert pepper_client.local('*', 'test.ping', tgt_type='list')['return'][0][session_minion_id] is False + 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 pepper_client.local('*', 'test.ping', expr_form='list')['return'][0][session_minion_id] is False - assert pepper_client.local(session_minion_id, 'test.ping', expr_form='list')['return'][0][session_minion_id] is True + 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