Bug 1010355 - like operator support is missing in bkr.client
like operator support is missing in bkr.client
Status: CLOSED CURRENTRELEASE
Product: Beaker
Classification: Community
Component: command line (Show other bugs)
0.14
Unspecified Unspecified
medium Severity medium (vote)
: 21.1
: ---
Assigned To: Dan Callaghan
tools-bugs
: FutureFeature, NeedsTestCase, Patch
: 1240974 (view as bug list)
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2013-09-20 11:13 EDT by Miroslav Hradílek
Modified: 2015-10-20 23:25 EDT (History)
10 users (show)

See Also:
Fixed In Version:
Doc Type: Enhancement
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2015-10-20 23:25:22 EDT
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Miroslav Hradílek 2013-09-20 11:13:12 EDT
Description of problem:
Python module bkr.client is lacking support for 'like' operator as described in docs[1][2]. I'd quite need this operator to be supported.

[1] http://beaker-project.org/docs/user-guide/job-xml.html#job-xml
[2] http://beaker-project.org/schema/beaker-job.rng

Version-Release number of selected component (if applicable):
beaker-client-0.14.1-1.fc18.noarch

How reproducible:
100%

Steps to Reproduce:
bkr workflow-tomorrow 6.4 x86_64 Server --dryrun --hostrequire 'devicelikeipmi'

Actual results:
No task selected, just reserving the machine
Using distro rhel-6.4 from the command line
Traceback (most recent call last):
  File "/bin/bkr", line 9, in <module>
    load_entry_point('bkr.client==0.14.1', 'console_scripts', 'bkr')()
  File "/usr/lib/python2.7/site-packages/bkr/client/main.py", line 50, in main
    return cmd.run(*cmd_args, **cmd_opts.__dict__)
  File "/usr/lib/python2.7/site-packages/bkr/client/commands/cmd_workflow_tomorrow.py", line 1829, in run
    cases=[nitrate.TestCase(id) for id in options.cases])
  File "/usr/lib/python2.7/site-packages/bkr/client/commands/cmd_workflow_tomorrow.py", line 1371, in schedule
    self.check_environment()
  File "/usr/lib/python2.7/site-packages/bkr/client/commands/cmd_workflow_tomorrow.py", line 749, in check_environment
    self.create_recipe(distro, variant, arch))
  File "/usr/lib/python2.7/site-packages/bkr/client/commands/cmd_workflow_tomorrow.py", line 1017, in create_recipe
    recipe.addBaseRequires(**kwargs)
  File "/usr/lib/python2.7/site-packages/bkr/client/__init__.py", line 634, in addBaseRequires
    key, op, value = p2.split(require,3)
ValueError: need more than 1 value to unpack

Expected results:
. . .
			<hostRequires>
				<and>
					<device op="like" value="ipmi"/>
				</and>
			</hostRequires>
. . .

Additional info:
The regex p2 obviously does not accept 'like' operator see
/usr/lib/python2.7/site-packages/bkr/client/__init__.py:
. . .
    625         p2 = re.compile(r'([\!=<>]+|&gt;|&lt;)')
    626         for keyvalue in keyvalues:
    627             key, op, value = p2.split(keyvalue,3)
    628             mykeyvalue = self.doc.createElement('key_value')
    629             mykeyvalue.setAttribute('key', '%s' % key)
    630             mykeyvalue.setAttribute('op', '%s' % op)
    631             mykeyvalue.setAttribute('value', '%s' % value)
    632             self.addHostRequires(mykeyvalue)
    633         for require in requires:
    634             key, op, value = p2.split(require,3)
    635             myrequire = self.doc.createElement('%s' % key)
    636             myrequire.setAttribute('op', '%s' % op)
    637             myrequire.setAttribute('value', '%s' % value)
    638             self.addHostRequires(myrequire)
. . .
Comment 2 Dan Callaghan 2015-08-24 01:55:10 EDT
(In reply to Miroslav Hradílek from comment #0)
> Steps to Reproduce:
> bkr workflow-tomorrow 6.4 x86_64 Server --dryrun --hostrequire 'devicelikeipmi'

That looks a bit bizarre. We can split on '\s+like\s+' instead.

bkr workflow-tomorrow 6.4 x86_64 Server --dryrun --hostrequire 'device like ipmi'
Comment 3 Dan Callaghan 2015-08-24 02:44:01 EDT
Note that you can already (since 0.17) pass raw XML to --hostrequire:

bkr workflow-simple --hostrequire '<hostname op="like" value="%.khw.%"/>' ...
Comment 4 Dan Callaghan 2015-08-24 02:44:25 EDT
*** Bug 1240974 has been marked as a duplicate of this bug. ***
Comment 5 Dan Callaghan 2015-08-24 02:45:54 EDT
(In reply to Dan Callaghan from comment #2)
> bkr workflow-tomorrow 6.4 x86_64 Server --dryrun --hostrequire 'device like ipmi'

Actually that won't have any useful effect either. The <device/> host filter is special, it does not actually have a value="" attribute, it has separate XML attributes for each attribute of the device, so you would use it like this:

    <device op="like" description="%IPMI%"/>

There's no way to represent that indirectly using --hostrequire, you can only pass the raw XML:

    --hostrequire '<device op="like" description="%IPMI%"/>'
Comment 6 Dan Callaghan 2015-08-24 02:46:52 EDT
A better example (from bug 1240974) would be:

    --hostrequire 'hostname like %.khw.%'

which will become:

    <hostname op="like" value="%.khw.%"/>
Comment 7 Dan Callaghan 2015-08-24 03:00:13 EDT
http://gerrit.beaker-project.org/4362
Comment 8 Dan Callaghan 2015-08-26 01:47:16 EDT
This bug fix is included in beaker-client-21.1-0.git.3.58733b1 which is currently available for testing here:

https://beaker-project.org/nightlies/release-21/
Comment 10 Dan Callaghan 2015-10-20 23:25:22 EDT
Beaker 21.1 has been released.

Note You need to log in before you can comment on or make changes to this bug.