Note: This bug is displayed in read-only format because the product is no longer active in Red Hat Bugzilla.

Bug 1010355

Summary: like operator support is missing in bkr.client
Product: [Retired] Beaker Reporter: Miroslav Hradílek <mhradile>
Component: command lineAssignee: Dan Callaghan <dcallagh>
Status: CLOSED CURRENTRELEASE QA Contact: tools-bugs <tools-bugs>
Severity: medium Docs Contact:
Priority: medium    
Version: 0.14CC: aigao, dcallagh, dowang, ebaak, lzachar, qwan, rjoost, sgao, tools-bugs
Target Milestone: 21.1Keywords: FutureFeature, NeedsTestCase, Patch
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Enhancement
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2015-10-21 03:25:22 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Miroslav Hradílek 2013-09-20 15:13:12 UTC
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 05:55:10 UTC
(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 06:44:01 UTC
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 06:44:25 UTC
*** Bug 1240974 has been marked as a duplicate of this bug. ***

Comment 5 Dan Callaghan 2015-08-24 06:45:54 UTC
(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 06:46:52 UTC
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 07:00:13 UTC
http://gerrit.beaker-project.org/4362

Comment 8 Dan Callaghan 2015-08-26 05:47:16 UTC
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-21 03:25:22 UTC
Beaker 21.1 has been released.