Bug 1777806

Summary: When Service weight is set as 0 for server in IPA location "IPA Error 903: InternalError" is displayed
Product: Red Hat Enterprise Linux 8 Reporter: Sudhir Menon <sumenon>
Component: ipaAssignee: François Cami <fcami>
Status: CLOSED ERRATA QA Contact: ipa-qe <ipa-qe>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 8.2CC: fcami, ksiddiqu, pasik, pcech, rcritten, tscherf, twoerner
Target Milestone: rcKeywords: TestCaseProvided
Target Release: 8.0   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: ipa-4.8.7-1.el8 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2020-11-04 02:50:15 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 Sudhir Menon 2019-11-28 11:08:25 UTC
Description of problem: When Service weight is set as 0 for server in IPA location "IPA Error 903: InternalError" is displayed

Version-Release number of selected component (if applicable):
ipa-server-4.8.2-2.module+el8.2.0+4736+360582ce.x86_64


How reproducible: Always


Steps to Reproduce:
1. Install IPA server with 2 locations
2. Setup replica.rhel82.test in one location1 with Service weight 10
3. Setup replica2.rhel82.test in another location2 with Service weight 0

Actual results:
2. Server replica.rhel82.test is added to the location1 with Service weight 10
3. Although not sure if weight of 0 is correct, but when replica2.rhel82.test is added to location2 with Service weight 0 an error is displayed on the UI 'Error 903: Internal error is occured'


httpd error_log
  1 [Thu Nov 28 16:02:26.740769 2019] [wsgi:error] [pid 8648:tid 140034638186240] [remote :49950] ipa: ERROR: non-public: ZeroDivisionError: float division by zero
  2 [Thu Nov 28 16:02:26.740801 2019] [wsgi:error] [pid 8648:tid 140034638186240] [remote :49950] Traceback (most recent call last):
  3 [Thu Nov 28 16:02:26.740805 2019] [wsgi:error] [pid 8648:tid 140034638186240] [remote :49950]   File "/usr/lib/python3.6/site-packages/ipaserver/rpcserver.py", line 368, in wsgi_execute 
  4 [Thu Nov 28 16:02:26.740809 2019] [wsgi:error] [pid 8648:tid 140034638186240] [remote :49950]     result = command(*args, **options)
  5 [Thu Nov 28 16:02:26.740812 2019] [wsgi:error] [pid 8648:tid 140034638186240] [remote :49950]   File "/usr/lib/python3.6/site-packages/ipalib/frontend.py", line 450, in __call__
  6 [Thu Nov 28 16:02:26.740815 2019] [wsgi:error] [pid 8648:tid 140034638186240] [remote :49950]     return self.__do_call(*args, **options)
  7 [Thu Nov 28 16:02:26.740818 2019] [wsgi:error] [pid 8648:tid 140034638186240] [remote :49950]   File "/usr/lib/python3.6/site-packages/ipalib/frontend.py", line 478, in __do_call 
  8 [Thu Nov 28 16:02:26.740821 2019] [wsgi:error] [pid 8648:tid 140034638186240] [remote :49950]     ret = self.run(*args, **options)
  9 [Thu Nov 28 16:02:26.740824 2019] [wsgi:error] [pid 8648:tid 140034638186240] [remote :49950]   File "/usr/lib/python3.6/site-packages/ipalib/frontend.py", line 800, in run
 10 [Thu Nov 28 16:02:26.740827 2019] [wsgi:error] [pid 8648:tid 140034638186240] [remote :49950]     return self.execute(*args, **options)
 11 [Thu Nov 28 16:02:26.740831 2019] [wsgi:error] [pid 8648:tid 140034638186240] [remote :49950]   File "/usr/lib/python3.6/site-packages/ipaserver/plugins/location.py", line 230, in execute
 12 [Thu Nov 28 16:02:26.740834 2019] [wsgi:error] [pid 8648:tid 140034638186240] [remote :49950]     int(server['ipaserviceweight'][0])*100.0/weight_sum)
 13 [Thu Nov 28 16:02:26.740838 2019] [wsgi:error] [pid 8648:tid 140034638186240] [remote :49950] ZeroDivisionError: float division by zero
 14 [Thu Nov 28 16:02:26.740853 2019] [wsgi:error] [pid 8648:tid 140034638186240] [remote :49950]
~                                                                                                      

Expected results: 
Fix the error "IPA Error 903: InternalError" 

Additional info:

Comment 1 François Cami 2019-12-02 08:40:36 UTC
Taking for investigation.

Quoting https://tools.ietf.org/html/rfc2782

Weight
        A server selection mechanism.  The weight field specifies a
        relative weight for entries with the same priority. Larger
        weights SHOULD be given a proportionately higher probability of
        being selected. The range of this number is 0-65535.  This is a
        16 bit unsigned integer in network byte order.  Domain
        administrators SHOULD use Weight 0 when there isn't any server
        selection to do, to make the RR easier to read for humans (less
        noisy).  In the presence of records containing weights greater
        than 0, records with weight 0 should have a very small chance of
        being selected.

Comment 2 François Cami 2019-12-02 11:58:48 UTC
The RFC states that weight=0 is a valid use-case.

If all servers in a location have weight=0, the sum of their weights is still 0:

            for server in servers:
                weight = int(server.get('ipaserviceweight', [100])[0])
                weight_sum += weight

leading to a division by zero later on:

            for server in servers_additional_info.values():
                server['service_relative_weight'] = [
                    u'{:.1f}%'.format(
                        int(server['ipaserviceweight'][0])*100.0/weight_sum)
                ]

Comment 3 François Cami 2019-12-02 12:40:30 UTC
Upstream ticket:
https://pagure.io/freeipa/issue/8135

Comment 10 errata-xmlrpc 2020-11-04 02:50:15 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (Moderate: idm:DL1 and idm:client security, bug fix, and enhancement update), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHSA-2020:4670