From e6fb9e970681391b6cca16deedf21b24407acf8b Mon Sep 17 00:00:00 2001 From: Iker Pedrosa Date: Wed, 28 Aug 2024 10:07:40 +0200 Subject: [PATCH] PreparePamUserDB: implement db conversion Check the databases reported by ScanPamUserDB and convert them to GDBM format. It also includes the component test for the actor. Signed-off-by: Iker Pedrosa --- .../actors/preparepamuserdb/actor.py | 18 ++++++++++++++ .../libraries/preparepamuserdb.py | 19 +++++++++++++++ .../preparepamuserdb/tests/files/db1.db | Bin 0 -> 12288 bytes .../preparepamuserdb/tests/files/db2.db | Bin 0 -> 12288 bytes .../tests/test_preparepamuserdb.py | 23 ++++++++++++++++++ 5 files changed, 60 insertions(+) create mode 100644 repos/system_upgrade/el9toel10/actors/preparepamuserdb/actor.py create mode 100644 repos/system_upgrade/el9toel10/actors/preparepamuserdb/libraries/preparepamuserdb.py create mode 100644 repos/system_upgrade/el9toel10/actors/preparepamuserdb/tests/files/db1.db create mode 100644 repos/system_upgrade/el9toel10/actors/preparepamuserdb/tests/files/db2.db create mode 100644 repos/system_upgrade/el9toel10/actors/preparepamuserdb/tests/test_preparepamuserdb.py diff --git a/repos/system_upgrade/el9toel10/actors/preparepamuserdb/actor.py b/repos/system_upgrade/el9toel10/actors/preparepamuserdb/actor.py new file mode 100644 index 0000000000..9f6c610805 --- /dev/null +++ b/repos/system_upgrade/el9toel10/actors/preparepamuserdb/actor.py @@ -0,0 +1,18 @@ +from leapp.actors import Actor +from leapp.models import PamUserDbLocation +from leapp.tags import RPMUpgradePhaseTag, IPUWorkflowTag +from leapp.libraries.actor import preparepamuserdb + + +class PreparePamUserDb(Actor): + """ + Convert the pam_userdb databases to GDBM + """ + + name = 'prepare_pam_user_db' + consumes = (PamUserDbLocation,) + produces = () + tags = (RPMUpgradePhaseTag, IPUWorkflowTag) + + def process(self): + preparepamuserdb.process() diff --git a/repos/system_upgrade/el9toel10/actors/preparepamuserdb/libraries/preparepamuserdb.py b/repos/system_upgrade/el9toel10/actors/preparepamuserdb/libraries/preparepamuserdb.py new file mode 100644 index 0000000000..500144aeb1 --- /dev/null +++ b/repos/system_upgrade/el9toel10/actors/preparepamuserdb/libraries/preparepamuserdb.py @@ -0,0 +1,19 @@ +import subprocess + +from leapp.models import PamUserDbLocation +from leapp.libraries.stdlib import api + + +def process(): + for msg in api.consume(PamUserDbLocation): + locations = msg.locations + + for location in locations: + cmd = f'db_converter --src {location}.db --dest {location}.gdbm' + try: + subprocess.call(cmd, shell=True) + except subprocess.CalledProcessError as e: + api.current_logger().debug( + f"'{cmd}' returned non-zero exit status: {e.returncode}" + ) + return diff --git a/repos/system_upgrade/el9toel10/actors/preparepamuserdb/tests/files/db1.db b/repos/system_upgrade/el9toel10/actors/preparepamuserdb/tests/files/db1.db new file mode 100644 index 0000000000000000000000000000000000000000..a5f6dcb7cc410f26f7921c9fd962149f035e4954 GIT binary patch literal 12288 zcmeI%Jqp4=5QgDzQ%EdA(s&8G_`?Bb_Jk0(MsJ=VIYjR*LWr>|~e? z3;T4-NK%N)(TxTgx@h7mT}Vaxyyfn44CB}-m)HKhPFp_Xb&fl(`_p!n_q|6TfB*sr zAbS4fjx+?-4XIGja+U(2WdaqgPPf zMRn5+FRh4(qREWqpc5Zi^qcHv5mDZ^r}g~1FFu>j_k4IfZSP0=&7k~SC zCI}E9K!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB=E_3*?Ocan4`HrHbCQYSyQI s`|~UF|GaDd--_7@5FkK+009C72oNAZfWW^C6r*}Pna+yc*J@MW0Dk`#6#xJL literal 0 HcmV?d00001 diff --git a/repos/system_upgrade/el9toel10/actors/preparepamuserdb/tests/test_preparepamuserdb.py b/repos/system_upgrade/el9toel10/actors/preparepamuserdb/tests/test_preparepamuserdb.py new file mode 100644 index 0000000000..b1770be7f1 --- /dev/null +++ b/repos/system_upgrade/el9toel10/actors/preparepamuserdb/tests/test_preparepamuserdb.py @@ -0,0 +1,23 @@ +import os + +import pytest + +from pathlib import Path +from leapp.models import PamUserDbLocation +from leapp.libraries.actor import preparepamuserdb +from leapp.libraries.stdlib import api + +CUR_DIR = os.path.dirname(os.path.abspath(__file__)) + + +def test_process_locations(current_actor_context): + current_actor_context.feed( + PamUserDbLocation( + locations=[f'{CUR_DIR}/files/db1', f'{CUR_DIR}/files/db2'] + ) + ) + current_actor_context.run() + db1 = Path(f'{CUR_DIR}/files/db1.gdbm') + assert db1.is_file() + db2 = Path(f'{CUR_DIR}/files/db2.gdbm') + assert db2.is_file()