Bug 1539878 - spacecmd ssm_intersect does not save to cache like ssm_add does
Summary: spacecmd ssm_intersect does not save to cache like ssm_add does
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: Spacewalk
Classification: Community
Component: API
Version: 2.6
Hardware: All
OS: Linux
unspecified
low
Target Milestone: ---
Assignee: Jan Dobes
QA Contact: Red Hat Satellite QA List
URL:
Whiteboard:
Depends On:
Blocks: space28
TreeView+ depends on / blocked
 
Reported: 2018-01-29 19:13 UTC by Thomas Blanchard
Modified: 2018-04-20 12:31 UTC (History)
2 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2018-04-20 12:31:33 UTC
Embargoed:


Attachments (Terms of Use)

Description Thomas Blanchard 2018-01-29 19:13:13 UTC
Description of problem:
spacecmd ssm_intersect does not save to cache like ssm_add or ssm_clear does

Version-Release number of selected component (if applicable):
spacecmd-2.6.16-1.el6.noarch
Note that the issue is not corrected in the github repo.

How reproducible:
Consistently reproducible.

Steps to Reproduce from bash using spacecmd one off commands and sessions
1. Login to spacecmd
spacecmd -s server -- login
2. Clear the ssm cache and ensure no systems are in the cache.
spacecmd -s server -- ssm_clear
spacecmd -s server -- ssm_list | wc -l
3. Add systems to the ssm cache and confirm they are cached between sessions:
spacecmd -q  -- ssm_add 'channel:some_channel_name'
spacecmd -- ssm_list | wc -l
4. Intersect systems with the ssm_intersect command and notice that they intersection is not stored in the cache
spacecmd -q  -- ssm_intersect group:"sub_group_name"
spacecmd -- ssm_list | wc -l

Steps to Reproduce within Spacecmd shell:
1. Login to spacecmd
spacecmd -s server --

2. Run the same set of commands as above and notice that the ssm_intersect is applied properly: 
spacecmd {SSM:0}> ssm_clear
spacecmd {SSM:0}> ssm_list
[...]
spacecmd {SSM:0}> ssm_add 'channel:some_channel_name'
spacecmd {SSM:59}> ssm_intersect group:"sub_group_name"
spacecmd {SSM:59}> ssm_list
[...]
spacecmd {SSM:7}> ssm_list
[...]
spacecmd {SSM:7}> exit

3. Exit then re-enter the spacecmd shell, notice that the ssm cache is loaded from the result of the ssh_add but not from the last known memory cache (59 systems instead of 7 in SSM)
spacecmd -s server --
spacecmd {SSM:59}> ssm_list
[...]


Actual results:
The cache contains the systems resulting from the ssh_add.

Expected results:
The cache should contain the systems resulting from the ssh_add and ssh_intersect, similarly to the Web UI features.

Additional info:
When using the spacecmd shell, one can operate on the memory cache properly with ssm_intersect but not among sessions.

Comment 1 Thomas Blanchard 2018-01-29 19:16:04 UTC
The fix is to add the following code at line 137 (copied from line 93-94):
https://github.com/spacewalkproject/spacewalk/blob/master/spacecmd/src/lib/ssm.py#L137

    # save the SSM for use between sessions
    save_cache(self.ssm_cache_file, self.ssm)

Comment 2 Thomas Blanchard 2018-01-29 19:43:24 UTC
To work around this issue, one can pass all the commands at once to spacecmd: 

This sequence of commands applies the system_setbasechannel to all systems matching 'channel:some_channel_name':
$ spacecmd -s server -- ssm_clear
$ spacecmd -s server -- ssm_add 'channel:some_channel_name'
$ spacecmd -s server -- ssm_intersect group:"sub_group_name"
$ spacecmd -s server -- system_setbasechannel ssm "new_base_channel"

To apply the setbasechannel command to the result of ssm add+intersect, run them as follow (in effect bypassing the ssm session file cache):
$ echo -e 'ssm_clear
ssm_add "channel:some_channel_name"
ssm_intersect group:"sub_group_name"
system_setbasechannel ssm "new_base_channel" | spacecmd -s server --

Comment 3 Thomas Blanchard 2018-01-29 19:47:10 UTC
I created the following pull request: 
https://github.com/spacewalkproject/spacewalk/pull/621

Thomas

Comment 4 Jiří Dostál 2018-03-26 14:24:22 UTC
spacewalk fb2acef1860be38b52aa27c4b3056db4757cad22

Comment 5 Jiří Dostál 2018-04-20 12:31:33 UTC
Spacewalk 2.8 has been released.
https://github.com/spacewalkproject/spacewalk/wiki/ReleaseNotes28


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