Bug 885715 - Spacecmd exits with error if there is duplicats in sattelite server
Summary: Spacecmd exits with error if there is duplicats in sattelite server
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Spacewalk
Classification: Community
Component: Clients
Version: 1.8
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: Aron Parsons
QA Contact: Red Hat Satellite QA List
URL:
Whiteboard:
Depends On:
Blocks: space27
TreeView+ depends on / blocked
 
Reported: 2012-12-10 13:16 UTC by Bo Wiberg
Modified: 2017-09-28 17:56 UTC (History)
5 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2013-03-03 23:38:05 UTC
Embargoed:


Attachments (Terms of Use)

Description Bo Wiberg 2012-12-10 13:16:48 UTC
Description of problem: If there is duoplicates in the satelit server the spacecmd exits with a warning
spacecmd -s rhnsat -u user   system_listinstalledpackages search:name:foo | grep -E  "System|redhat-release"
Spacewalk Password:
INFO: Connected to https://rhnsat/rpc/api as user
WARNING: Duplicate system profile names found
WARNING: You can delete duplicates with 'system_delete'
WARNING: foobar = 1000026123, 1000027424


Version-Release number of selected component (if applicable): spacecmd.noarch 1.8.15-1.fc16


How reproducible:
Have one hostname with two ID in rhss and run spacecmd against that hostname

Steps to Reproduce:
1.
2.
3.
  
Actual results:
Error, even though spacecmd tells me it is a warning

Expected results: spacecmd should tell me about the duplicates as a warning, but should generate correct output.


Additional info:

Comment 1 Miroslav Suchý 2012-12-10 14:03:01 UTC
Forwarding to upstream.

Comment 2 Jan Pazdziora 2012-12-10 15:56:37 UTC
Looking at the spacecmd codebase, there are three typical contexts in which the get_system_id calls appear:

        system_id = self.get_system_id(system)
        if not system_id: return

(this is in do_system_listinstalledpackages), then

        system_id = self.get_system_id(system)
        if not system_id: continue

and as

        system_id = self.get_system_id(system)
        variable = self.client.system.someAPICall(self.session, system_id)

all of them being within some

        for system in sorted(systems):

loop.

Obviously, the return terminates the loop and causes the potential warning to appear as exit, the continue skips the problematic system profile name, and using the zero system_id in API call ... well, will it fail?

We probably should come up with unified way of handling nondeterministic profile names and fix all occurrences.

Steven, do you have any guidance?

Comment 3 Steven Hardy 2012-12-10 16:20:08 UTC
So yes, it looks to me like we should probably replace all of the "if not system_id: return" statements with the continue version - the only risk I see with this is it makes it a bit less obvious that we failed to uniquely look-up a system (if it's one of many systems or a search as above).

As you point out, we should also check the return value before the API call in the third example (pretty sure the API call will fail, but it's not going to be a very elegant failure-mode I guess)

Agree that coming up with some abstraction to tidy this up would be good.

Comment 4 Milan Zázrivec 2013-01-04 09:34:30 UTC
Assigning to Steven, current spacecmd maintainer.

Comment 5 Steven Hardy 2013-02-21 11:50:38 UTC
Reassigning to Aron Parsons, spacecmd maintainer

Comment 6 Aron Parsons 2013-03-03 23:38:05 UTC
commits:
007bb1a9968a7dd082a35e08b9d19f8d9b044e6f
3a815ffb55f2413dd68d8978802b431e0eaba645
7324513b0df53d51000c9bb39ee7235ca608266b

The behavior you're seeing is the intended behavior.  spacecmd does not know which system you're trying to interact with and chooses to not return bad information.    If you intend to have duplicate profile names in your Spacewalk instance, you're going to have to refer to systems by ID, in which case spacecmd will behave as expected.

As discussed by Jan and Steven, I standardized the behavior for when get_system_id does not return a valid system ID (continue instead of return when inside a loop).  I have also changed the error message to be clearer about what's going on when duplicate systems are detected.

Comment 7 Eric Herget 2017-09-28 17:56:37 UTC
This BZ closed some time during 2.5, 2.6 or 2.7.  Adding to 2.7 tracking bug.


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