Bug 20933 - add get_int() for univention.config_registry.ConfigRegistry
add get_int() for univention.config_registry.ConfigRegistry
Status: CLOSED FIXED
Product: UCS
Classification: Unclassified
Component: UCR
UCS 5.0
Other Linux
: P5 enhancement (vote)
: UCS 5.0-1-errata
Assigned To: Ildefonso González Sánchez
Arvid Requate
https://git.knut.univention.de/univen...
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2010-12-09 13:49 CET by Hendrik Mangels
Modified: 2022-01-26 17:21 CET (History)
2 users (show)

See Also:
What kind of report is it?: Development Internal
What type of bug is this?: ---
Who will be affected by this bug?: ---
How will those affected feel about the bug?: ---
User Pain:
Enterprise Customer affected?:
School Customer affected?:
ISV affected?:
Waiting Support:
Flags outvoted (downgraded) after PO Review:
Ticket number:
Bug group (optional): bitesize
Max CVSS v3 score:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Hendrik Mangels univentionstaff 2010-12-09 13:49:40 CET
Falls eine Zahl erwartet wird, aber eine Zeichenkette in einer UCR-Variablen gespeichert ist, wirft der folgende Code eine ValueError-Exception:

cfgRegistry = ucr.ConfigRegistry()
cfgRegistry.load()
my_int = int( cfgRegistry.get( var, default ))

Es sollte eine Funktion "get_int" geben, welche sicher eine Zahl oder den angegebenen "default" zurück gibt.
Comment 1 Stefan Gohmann univentionstaff 2016-04-25 07:52:18 CEST
This issue has been filed against UCS 2.4.

UCS 2.4 is out of maintenance and many UCS components have vastly changed in
later releases. Thus, this issue is now being closed.

If this issue still occurs in newer UCS versions, please use "Clone this bug".
In this case please provide detailed information on how this issue is affecting
you.
Comment 2 Florian Best univentionstaff 2021-10-27 19:24:47 CEST
We still need a simple:
def get_int(self, key, default=None):
    try:
        return int(self[key])
    except (KeyError, ValueError):
        return default
Comment 3 Arvid Requate univentionstaff 2021-12-30 11:58:13 CET
We should also implement a unit test for this, probably in
base/univention-config-registry/tests/test_backend.py
Comment 4 Ildefonso González Sánchez univentionstaff 2021-12-30 18:24:26 CET
https://git.knut.univention.de/univention/ucs/-/merge_requests/221
Comment 5 Arvid Requate univentionstaff 2022-01-05 18:25:28 CET
Reopen: The merge request is not merged yet and the package not built.
Comment 7 Arvid Requate univentionstaff 2022-01-26 11:49:46 CET
Verified:
* Code review: Ok
* Package update: Ok
* Functional test (python REPL): Ok
* Test coverage:

/var/univention/buildsystem2/logs/ucs_5.0-0-errata5.0-1/univention-config-registry_15.0.7-16A~5.0.0.202201260941.log.bz2 shows:

tests/test_backend.py::TestConfigRegistry::test_get_int PASSED           [  3%]
tests/test_backend.py::TestConfigRegistry::test_get_int_string[10-None-10] PASSED [  3%]
tests/test_backend.py::TestConfigRegistry::test_get_int_string[10-20-100] PASSED [  3%]
tests/test_backend.py::TestConfigRegistry::test_get_int_string[10-string-10] PASSED [  3%]
tests/test_backend.py::TestConfigRegistry::test_get_int_string[string-10-100] PASSED [  3%]
tests/test_backend.py::TestConfigRegistry::test_get_int_string[10-20-101] PASSED [  4%]
tests/test_backend.py::TestConfigRegistry::test_get_int_string[string-None-None] PASSED [  4%]
tests/test_backend.py::TestConfigRegistry::test_get_int_string[string-10-101] PASSED [  4%]

* Advisory: Ok
Comment 8 Arvid Requate univentionstaff 2022-01-26 11:55:47 CET
A run of https://jenkins.knut.univention.de:8181/job/UCS-5.0/job/UCS-5.0-1/job/ErrataValidation/ confirmed that advisory and metadata are consistent and the errata update can be released.