Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use tgt_type instead of expr_form #186

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions pepper/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
30 changes: 21 additions & 9 deletions pepper/libpepper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
the-glu marked this conversation as resolved.
Show resolved Hide resolved
timeout=None, ret=None, expr_form=None):
'''
Run a single command using the ``local`` client

Expand All @@ -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
Expand All @@ -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

Expand All @@ -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
Expand All @@ -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

Expand All @@ -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
Expand Down
11 changes: 11 additions & 0 deletions tests/integration/test_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading