RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
Bug 1816859 - lib389 - Replace exec() with setattr()
Summary: lib389 - Replace exec() with setattr()
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 8
Classification: Red Hat
Component: 389-ds-base
Version: 8.2
Hardware: Unspecified
OS: Unspecified
unspecified
medium
Target Milestone: rc
: 8.0
Assignee: mreynolds
QA Contact: RHDS QE
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2020-03-24 21:59 UTC by mreynolds
Modified: 2020-11-04 03:08 UTC (History)
4 users (show)

Fixed In Version: 389-ds-base-1.4.3.8-2.module+el8.3.0+6591+ebfc9766
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2020-11-04 03:07:44 UTC
Type: Bug
Target Upstream Version:
Embargoed:
mreynolds: mirror+


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Github 389ds 389-ds-base issues 3396 0 None None None 2020-09-13 22:20:05 UTC
Red Hat Product Errata RHEA-2020:4695 0 None None None 2020-11-04 03:07:59 UTC

Description mreynolds 2020-03-24 21:59:07 UTC
Description of problem:


I noticed that https://pagure.io/389-ds-base/blob/master/f/src/lib389/lib389/_constants.py uses exec() a lot to define module global variables. That's rather slow and not very elegant. You can get the current module object with sys.modules[__name__] and then use setattr() instead:

import sys

# current module object
mod = sys.modules[__name__]

setattr(mod, "HOST_STANDALONE{0}".format(N), "LOCALHOST")


Upstream ticket:

https://pagure.io/389-ds-base/issue/50337

Comment 3 Viktor Ashirov 2020-06-02 12:19:22 UTC
# grep setattr /usr/lib/python3.6/site-packages/lib389/_constants.py 
    setattr(mod, "HOST_STANDALONE{0}".format(N), "LOCALHOST")
    setattr(mod, "PORT_STANDALONE{0}".format(N), i)
    setattr(mod, "SECUREPORT_STANDALONE{0}".format(N), i + 24700)
    setattr(mod, "SERVERID_STANDALONE{0}".format(N), "standalone{0}".format(N))
    setattr(mod, "REPLICAID_STANDALONE_{0}".format(N), 65535)
    setattr(mod, "HOST_MASTER_{0}".format(N), "LOCALHOST")
    setattr(mod, "PORT_MASTER_{0}".format(N), i)
    setattr(mod, "SECUREPORT_MASTER_{0}".format(N), i + 24700)
    setattr(mod, "SERVERID_MASTER_{0}".format(N), "master{0}".format(N))
    setattr(mod, "REPLICAID_MASTER_{0}".format(N), N)
    setattr(mod, "HOST_HUB_{0}".format(N), "LOCALHOST")
    setattr(mod, "PORT_HUB_{0}".format(N), i)
    setattr(mod, "SECUREPORT_HUB_{0}".format(N), i + 24700)
    setattr(mod, "SERVERID_HUB_{0}".format(N), "hub{0}".format(N))
    setattr(mod, "REPLICAID_HUB_{0}".format(N), 65535)
    setattr(mod, "HOST_CONSUMER_{0}".format(N), "LOCALHOST")
    setattr(mod, "PORT_CONSUMER_{0}".format(N), i)
    setattr(mod, "SECUREPORT_CONSUMER_{0}".format(N), i + 24700)
    setattr(mod, "SERVERID_CONSUMER_{0}".format(N), "consumer{0}".format(N))

Test that uses these constant passes:
============================================================================ test session starts ============================================================================
platform linux -- Python 3.6.8, pytest-5.4.2, py-1.8.1, pluggy-0.13.1 -- /usr/bin/python3.6
cachedir: .pytest_cache
389-ds-base: 1.4.3.8-2.module+el8.3.0+6591+ebfc9766
nss: 3.44.0-15.el8
nspr: 4.21.0-2.el8_0
openldap: 2.4.46-11.el8_1
cyrus-sasl: not installed
FIPS: disabled
rootdir: /workspace/ds/dirsrvtests, inifile: pytest.ini
collected 1 item                                                                                                                                                            

dirsrvtests/tests/suites/acl/repeated_ldap_add_test.py::test_repeated_ldap_add PASSED                                                                                 [100%]

====================================================================== 1 passed, 47 warnings in 46.72s ======================================================================

Marking as VERIFIED.

Comment 6 errata-xmlrpc 2020-11-04 03:07:44 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 (389-ds:1.4 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/RHEA-2020:4695


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