From 45f11c0ca5ed1a8ceeab883707f8acf122a78f26 Mon Sep 17 00:00:00 2001 From: Pascal Arlt Date: Sat, 15 Feb 2025 12:55:45 +0100 Subject: [PATCH 01/20] Update inotify beacon on control nodes on inventory change Signed-off-by: Pascal Arlt --- .../rhn/manager/system/AnsibleManager.java | 60 ++++++++++++++++++- .../pillar/MinionGeneralPillarGenerator.java | 11 ++++ 2 files changed, 69 insertions(+), 2 deletions(-) diff --git a/java/code/src/com/redhat/rhn/manager/system/AnsibleManager.java b/java/code/src/com/redhat/rhn/manager/system/AnsibleManager.java index c236432b54e0..219eec9033cf 100644 --- a/java/code/src/com/redhat/rhn/manager/system/AnsibleManager.java +++ b/java/code/src/com/redhat/rhn/manager/system/AnsibleManager.java @@ -18,6 +18,7 @@ import static java.util.Optional.empty; import static java.util.Optional.of; +import com.redhat.rhn.GlobalInstanceHolder; import com.redhat.rhn.common.hibernate.LookupException; import com.redhat.rhn.common.validator.ValidatorException; import com.redhat.rhn.common.validator.ValidatorResult; @@ -36,8 +37,10 @@ import com.redhat.rhn.taskomatic.TaskomaticApiException; import com.suse.manager.webui.services.iface.SaltApi; +import com.suse.manager.webui.services.pillar.MinionPillarManager; import com.suse.manager.webui.utils.salt.custom.AnsiblePlaybookSlsResult; import com.suse.salt.netapi.calls.LocalCall; +import com.suse.salt.netapi.datatypes.target.MinionList; import com.suse.salt.netapi.utils.Xor; import com.google.gson.reflect.TypeToken; @@ -46,7 +49,9 @@ import java.nio.file.InvalidPathException; import java.nio.file.Path; +import java.util.ArrayList; import java.util.Date; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Optional; @@ -149,7 +154,16 @@ public static AnsiblePath createAnsiblePath(String typeLabel, long minionServerI ansiblePath.setMinionServer(minionServer); ansiblePath.setPath(Path.of(path)); - return AnsibleFactory.saveAnsiblePath(ansiblePath); + ansiblePath = AnsibleFactory.saveAnsiblePath(ansiblePath); + + // Refresh inotify beacon if a new inventory was added + if (type == AnsiblePath.Type.INVENTORY) { + MinionPillarManager.INSTANCE.generatePillar(minionServer, false, + MinionPillarManager.PillarSubset.GENERAL); + GlobalInstanceHolder.SALT_API.refreshPillar(new MinionList(minionServer.getMinionId())); + } + + return ansiblePath; } /** @@ -167,7 +181,17 @@ public static AnsiblePath updateAnsiblePath(long existingPathId, String newPath, .orElseThrow(() -> new LookupException("Ansible path id " + existingPathId + " not found.")); validateAnsiblePath(newPath, empty(), of(existingPathId), existing.getMinionServer().getId()); existing.setPath(Path.of(newPath)); - return AnsibleFactory.saveAnsiblePath(existing); + + existing = AnsibleFactory.saveAnsiblePath(existing); + + // Refresh inotify beacon if the updated path is an inventory + if (existing.getEntityType() == AnsiblePath.Type.INVENTORY) { + MinionPillarManager.INSTANCE.generatePillar(existing.getMinionServer(), false, + MinionPillarManager.PillarSubset.GENERAL); + GlobalInstanceHolder.SALT_API.refreshPillar(new MinionList(existing.getMinionServer().getMinionId())); + } + + return existing; } private static void validateAnsiblePath(String path, Optional typeLabel, Optional pathId, @@ -228,7 +252,15 @@ private static void validateAnsiblePath(String path, Optional typeLabel, public static void removeAnsiblePath(long pathId, User user) { AnsiblePath path = lookupAnsiblePathById(pathId, user) .orElseThrow(() -> new LookupException("Ansible path id " + pathId + " not found.")); + AnsibleFactory.removeAnsiblePath(path); + + // Refresh inotify beacon if the removed path was an inventory + if (path.getEntityType() == AnsiblePath.Type.INVENTORY) { + MinionPillarManager.INSTANCE.generatePillar(path.getMinionServer(), false, + MinionPillarManager.PillarSubset.GENERAL); + GlobalInstanceHolder.SALT_API.refreshPillar(new MinionList(path.getMinionServer().getMinionId())); + } } /** @@ -374,6 +406,30 @@ public Optional>> introspectInventory(long pathI success -> success)); } + /** + * Generate the inotify beacon for the given ansible control node based on + * the {@link InventoryPath} related to it. + * + * @param minion the minion server + * @return the inotify beacon configuration + */ + public static List> generateBeacon(MinionServer minion) { + List> beacon = new ArrayList<>(); + List inventories = AnsibleFactory.listAnsibleInventoryPaths(minion.getId()); + + if (!inventories.isEmpty()) { + Map files = new HashMap<>(); + inventories.forEach(i -> { + files.put(i.getPath().toString(), Map.of("mask", List.of("modify"))); + }); + beacon.add(Map.of("files", files)); + beacon.add(Map.of("interval", 5)); + beacon.add(Map.of("disable_during_state_run", true)); + } + + return beacon; + } + private static MinionServer lookupAnsibleControlNode(long systemId, User user) { Server controlNode = SystemManager.lookupByIdAndUser(systemId, user); if (controlNode == null) { diff --git a/java/code/src/com/suse/manager/webui/services/pillar/MinionGeneralPillarGenerator.java b/java/code/src/com/suse/manager/webui/services/pillar/MinionGeneralPillarGenerator.java index 6f1999b2b398..a1490d289748 100644 --- a/java/code/src/com/suse/manager/webui/services/pillar/MinionGeneralPillarGenerator.java +++ b/java/code/src/com/suse/manager/webui/services/pillar/MinionGeneralPillarGenerator.java @@ -21,6 +21,8 @@ import com.redhat.rhn.domain.channel.Channel; import com.redhat.rhn.domain.server.MinionServer; import com.redhat.rhn.domain.server.Pillar; +import com.redhat.rhn.manager.entitlement.EntitlementManager; +import com.redhat.rhn.manager.system.AnsibleManager; import com.suse.manager.model.attestation.AttestationFactory; import com.suse.manager.model.attestation.CoCoAttestationStatus; @@ -31,6 +33,7 @@ import org.apache.logging.log4j.Logger; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.Optional; @@ -99,6 +102,14 @@ public Optional generatePillarData(MinionServer minion) { beaconConfig.put("pkgset", PKGSET_BEACON_PROPS); beaconConfig.put("reboot_info", minion.isRedHat() ? REBOOT_INFO_BEACON_PROPS_RH : REBOOT_INFO_BEACON_PROPS); } + // If the minion is an Ansible control node generate an inotify beacon with the managed inventory files + // If there is no inventory path for the minion the beacon will be removed + if (minion.hasEntitlement(EntitlementManager.ANSIBLE_CONTROL_NODE)) { + List> inotifyBeacon = AnsibleManager.generateBeacon(minion); + if (!inotifyBeacon.isEmpty()) { + beaconConfig.put("inotify", inotifyBeacon); + } + } if (!beaconConfig.isEmpty()) { pillar.add("beacons", beaconConfig); } From 39146c34469e664605d5a6b5eacff5488af57035 Mon Sep 17 00:00:00 2001 From: Pascal Arlt Date: Sat, 15 Feb 2025 13:30:36 +0100 Subject: [PATCH 02/20] Refresh pillar data on add/remove Ansible control node entitlement Signed-off-by: Pascal Arlt --- .../redhat/rhn/manager/system/entitling/SystemEntitler.java | 5 +++++ .../rhn/manager/system/entitling/SystemUnentitler.java | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/java/code/src/com/redhat/rhn/manager/system/entitling/SystemEntitler.java b/java/code/src/com/redhat/rhn/manager/system/entitling/SystemEntitler.java index a9027a7e9a67..fc328d655832 100644 --- a/java/code/src/com/redhat/rhn/manager/system/entitling/SystemEntitler.java +++ b/java/code/src/com/redhat/rhn/manager/system/entitling/SystemEntitler.java @@ -29,6 +29,7 @@ import com.suse.manager.webui.services.iface.MonitoringManager; import com.suse.manager.webui.services.iface.SaltApi; import com.suse.manager.webui.services.impl.SaltSSHService; +import com.suse.manager.webui.services.pillar.MinionPillarManager; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -102,6 +103,10 @@ else if (EntitlementManager.OSIMAGE_BUILD_HOST.equals(ent)) { entitleServer(server, ent); server.asMinionServer().ifPresent(minion -> { + if (EntitlementManager.ANSIBLE_CONTROL_NODE.equals(ent)) { + MinionPillarManager.INSTANCE.generatePillar(minion, false, MinionPillarManager.PillarSubset.GENERAL); + } + serverGroupManager.updatePillarAfterGroupUpdateForServers(Arrays.asList(minion)); if (EntitlementManager.MONITORING.equals(ent)) { diff --git a/java/code/src/com/redhat/rhn/manager/system/entitling/SystemUnentitler.java b/java/code/src/com/redhat/rhn/manager/system/entitling/SystemUnentitler.java index 87e33f37152c..59c9af4a7c91 100644 --- a/java/code/src/com/redhat/rhn/manager/system/entitling/SystemUnentitler.java +++ b/java/code/src/com/redhat/rhn/manager/system/entitling/SystemUnentitler.java @@ -24,6 +24,7 @@ import com.redhat.rhn.manager.system.ServerGroupManager; import com.suse.manager.webui.services.iface.MonitoringManager; +import com.suse.manager.webui.services.pillar.MinionPillarManager; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -83,6 +84,9 @@ public void removeServerEntitlement(Server server, Entitlement ent) { } server.asMinionServer().ifPresent(s -> { + if (EntitlementManager.ANSIBLE_CONTROL_NODE.equals(ent)) { + MinionPillarManager.INSTANCE.generatePillar(s, false, MinionPillarManager.PillarSubset.GENERAL); + } serverGroupManager.updatePillarAfterGroupUpdateForServers(Arrays.asList(s)); if (EntitlementManager.MONITORING.equals(ent)) { try { From 7d99a0036e196fb5803e295f1d15e02c52317c0f Mon Sep 17 00:00:00 2001 From: Pascal Arlt Date: Mon, 17 Feb 2025 12:22:45 +0100 Subject: [PATCH 03/20] Move PlaybookAction to action.ansible package Signed-off-by: Pascal Arlt --- java/code/src/com/redhat/rhn/domain/action/ActionFactory.java | 3 ++- .../com/redhat/rhn/domain/action/Action_legacyUser.hbm.xml | 4 ++-- .../rhn/domain/action/{salt => ansible}/PlaybookAction.java | 2 +- .../action/{salt => ansible}/PlaybookActionDetails.hbm.xml | 2 +- .../action/{salt => ansible}/PlaybookActionDetails.java | 2 +- .../rhn/frontend/xmlrpc/ansible/test/AnsibleHandlerTest.java | 4 ++-- .../src/com/redhat/rhn/manager/action/ActionChainManager.java | 4 ++-- .../rhn/manager/action/test/ActionChainManagerTest.java | 4 ++-- .../suse/manager/webui/services/SaltServerActionService.java | 4 ++-- .../webui/services/test/SaltServerActionServiceTest.java | 4 ++-- 10 files changed, 17 insertions(+), 16 deletions(-) rename java/code/src/com/redhat/rhn/domain/action/{salt => ansible}/PlaybookAction.java (96%) rename java/code/src/com/redhat/rhn/domain/action/{salt => ansible}/PlaybookActionDetails.hbm.xml (94%) rename java/code/src/com/redhat/rhn/domain/action/{salt => ansible}/PlaybookActionDetails.java (97%) diff --git a/java/code/src/com/redhat/rhn/domain/action/ActionFactory.java b/java/code/src/com/redhat/rhn/domain/action/ActionFactory.java index c334972b33ec..271d47d5419d 100644 --- a/java/code/src/com/redhat/rhn/domain/action/ActionFactory.java +++ b/java/code/src/com/redhat/rhn/domain/action/ActionFactory.java @@ -24,6 +24,8 @@ import com.redhat.rhn.common.hibernate.HibernateFactory; import com.redhat.rhn.common.hibernate.HibernateRuntimeException; import com.redhat.rhn.common.localization.LocalizationService; +import com.redhat.rhn.domain.action.ansible.InventoryAction; +import com.redhat.rhn.domain.action.ansible.PlaybookAction; import com.redhat.rhn.domain.action.appstream.AppStreamAction; import com.redhat.rhn.domain.action.channel.SubscribeChannelsAction; import com.redhat.rhn.domain.action.config.ConfigAction; @@ -45,7 +47,6 @@ import com.redhat.rhn.domain.action.rhnpackage.PackageActionDetails; import com.redhat.rhn.domain.action.salt.ApplyStatesAction; import com.redhat.rhn.domain.action.salt.ApplyStatesActionDetails; -import com.redhat.rhn.domain.action.salt.PlaybookAction; import com.redhat.rhn.domain.action.salt.build.ImageBuildAction; import com.redhat.rhn.domain.action.salt.inspect.ImageInspectAction; import com.redhat.rhn.domain.action.scap.ScapAction; diff --git a/java/code/src/com/redhat/rhn/domain/action/Action_legacyUser.hbm.xml b/java/code/src/com/redhat/rhn/domain/action/Action_legacyUser.hbm.xml index f34e6e0779ba..c36bfaaaff58 100644 --- a/java/code/src/com/redhat/rhn/domain/action/Action_legacyUser.hbm.xml +++ b/java/code/src/com/redhat/rhn/domain/action/Action_legacyUser.hbm.xml @@ -351,8 +351,8 @@ PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" - - + diff --git a/java/code/src/com/redhat/rhn/domain/action/salt/PlaybookAction.java b/java/code/src/com/redhat/rhn/domain/action/ansible/PlaybookAction.java similarity index 96% rename from java/code/src/com/redhat/rhn/domain/action/salt/PlaybookAction.java rename to java/code/src/com/redhat/rhn/domain/action/ansible/PlaybookAction.java index d0f4d90e6f03..cf4b4ed578b8 100644 --- a/java/code/src/com/redhat/rhn/domain/action/salt/PlaybookAction.java +++ b/java/code/src/com/redhat/rhn/domain/action/ansible/PlaybookAction.java @@ -12,7 +12,7 @@ * granted to use or replicate Red Hat trademarks that are incorporated * in this software or its documentation. */ -package com.redhat.rhn.domain.action.salt; +package com.redhat.rhn.domain.action.ansible; import com.redhat.rhn.domain.action.Action; diff --git a/java/code/src/com/redhat/rhn/domain/action/salt/PlaybookActionDetails.hbm.xml b/java/code/src/com/redhat/rhn/domain/action/ansible/PlaybookActionDetails.hbm.xml similarity index 94% rename from java/code/src/com/redhat/rhn/domain/action/salt/PlaybookActionDetails.hbm.xml rename to java/code/src/com/redhat/rhn/domain/action/ansible/PlaybookActionDetails.hbm.xml index 9510fc5dfa05..58d7f0b43fac 100644 --- a/java/code/src/com/redhat/rhn/domain/action/salt/PlaybookActionDetails.hbm.xml +++ b/java/code/src/com/redhat/rhn/domain/action/ansible/PlaybookActionDetails.hbm.xml @@ -3,7 +3,7 @@ PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> - protected diff --git a/java/code/src/com/redhat/rhn/domain/action/salt/PlaybookActionDetails.java b/java/code/src/com/redhat/rhn/domain/action/ansible/PlaybookActionDetails.java similarity index 97% rename from java/code/src/com/redhat/rhn/domain/action/salt/PlaybookActionDetails.java rename to java/code/src/com/redhat/rhn/domain/action/ansible/PlaybookActionDetails.java index 6ca6bf05221c..6d4b8051e68a 100644 --- a/java/code/src/com/redhat/rhn/domain/action/salt/PlaybookActionDetails.java +++ b/java/code/src/com/redhat/rhn/domain/action/ansible/PlaybookActionDetails.java @@ -12,7 +12,7 @@ * granted to use or replicate Red Hat trademarks that are incorporated * in this software or its documentation. */ -package com.redhat.rhn.domain.action.salt; +package com.redhat.rhn.domain.action.ansible; import com.redhat.rhn.domain.action.ActionChild; diff --git a/java/code/src/com/redhat/rhn/frontend/xmlrpc/ansible/test/AnsibleHandlerTest.java b/java/code/src/com/redhat/rhn/frontend/xmlrpc/ansible/test/AnsibleHandlerTest.java index 27b7e9a0ee64..7db55318a6b9 100644 --- a/java/code/src/com/redhat/rhn/frontend/xmlrpc/ansible/test/AnsibleHandlerTest.java +++ b/java/code/src/com/redhat/rhn/frontend/xmlrpc/ansible/test/AnsibleHandlerTest.java @@ -25,8 +25,8 @@ import com.redhat.rhn.common.db.datasource.DataResult; import com.redhat.rhn.domain.action.Action; import com.redhat.rhn.domain.action.ActionFactory; -import com.redhat.rhn.domain.action.salt.PlaybookAction; -import com.redhat.rhn.domain.action.salt.PlaybookActionDetails; +import com.redhat.rhn.domain.action.ansible.PlaybookAction; +import com.redhat.rhn.domain.action.ansible.PlaybookActionDetails; import com.redhat.rhn.domain.server.MinionServer; import com.redhat.rhn.domain.server.ServerArch; import com.redhat.rhn.domain.server.ServerFactory; diff --git a/java/code/src/com/redhat/rhn/manager/action/ActionChainManager.java b/java/code/src/com/redhat/rhn/manager/action/ActionChainManager.java index e1c17c147cd9..2104b916cedf 100644 --- a/java/code/src/com/redhat/rhn/manager/action/ActionChainManager.java +++ b/java/code/src/com/redhat/rhn/manager/action/ActionChainManager.java @@ -23,6 +23,8 @@ import com.redhat.rhn.domain.action.ActionChainFactory; import com.redhat.rhn.domain.action.ActionFactory; import com.redhat.rhn.domain.action.ActionType; +import com.redhat.rhn.domain.action.ansible.PlaybookAction; +import com.redhat.rhn.domain.action.ansible.PlaybookActionDetails; import com.redhat.rhn.domain.action.appstream.AppStreamAction; import com.redhat.rhn.domain.action.appstream.AppStreamActionDetails; import com.redhat.rhn.domain.action.channel.SubscribeChannelsAction; @@ -31,8 +33,6 @@ import com.redhat.rhn.domain.action.rhnpackage.PackageAction; import com.redhat.rhn.domain.action.salt.ApplyStatesAction; import com.redhat.rhn.domain.action.salt.ApplyStatesActionDetails; -import com.redhat.rhn.domain.action.salt.PlaybookAction; -import com.redhat.rhn.domain.action.salt.PlaybookActionDetails; import com.redhat.rhn.domain.action.salt.build.ImageBuildAction; import com.redhat.rhn.domain.action.salt.build.ImageBuildActionDetails; import com.redhat.rhn.domain.action.script.ScriptActionDetails; diff --git a/java/code/src/com/redhat/rhn/manager/action/test/ActionChainManagerTest.java b/java/code/src/com/redhat/rhn/manager/action/test/ActionChainManagerTest.java index d74d17f43821..9cb918b7aaf1 100644 --- a/java/code/src/com/redhat/rhn/manager/action/test/ActionChainManagerTest.java +++ b/java/code/src/com/redhat/rhn/manager/action/test/ActionChainManagerTest.java @@ -27,8 +27,8 @@ import com.redhat.rhn.domain.action.ActionChain; import com.redhat.rhn.domain.action.ActionChainFactory; import com.redhat.rhn.domain.action.ActionFactory; -import com.redhat.rhn.domain.action.salt.PlaybookAction; -import com.redhat.rhn.domain.action.salt.PlaybookActionDetails; +import com.redhat.rhn.domain.action.ansible.PlaybookAction; +import com.redhat.rhn.domain.action.ansible.PlaybookActionDetails; import com.redhat.rhn.domain.errata.Errata; import com.redhat.rhn.domain.errata.ErrataFactory; import com.redhat.rhn.domain.rhnpackage.Package; diff --git a/java/code/src/com/suse/manager/webui/services/SaltServerActionService.java b/java/code/src/com/suse/manager/webui/services/SaltServerActionService.java index e5cb354b6ef0..8c32092290b9 100644 --- a/java/code/src/com/suse/manager/webui/services/SaltServerActionService.java +++ b/java/code/src/com/suse/manager/webui/services/SaltServerActionService.java @@ -57,8 +57,8 @@ import com.redhat.rhn.domain.action.rhnpackage.PackageUpdateAction; import com.redhat.rhn.domain.action.salt.ApplyStatesAction; import com.redhat.rhn.domain.action.salt.ApplyStatesActionDetails; -import com.redhat.rhn.domain.action.salt.PlaybookAction; -import com.redhat.rhn.domain.action.salt.PlaybookActionDetails; +import com.redhat.rhn.domain.action.ansible.PlaybookAction; +import com.redhat.rhn.domain.action.ansible.PlaybookActionDetails; import com.redhat.rhn.domain.action.salt.build.ImageBuildAction; import com.redhat.rhn.domain.action.salt.build.ImageBuildActionDetails; import com.redhat.rhn.domain.action.salt.inspect.ImageInspectAction; diff --git a/java/code/src/com/suse/manager/webui/services/test/SaltServerActionServiceTest.java b/java/code/src/com/suse/manager/webui/services/test/SaltServerActionServiceTest.java index 10730237c40c..70d570122700 100644 --- a/java/code/src/com/suse/manager/webui/services/test/SaltServerActionServiceTest.java +++ b/java/code/src/com/suse/manager/webui/services/test/SaltServerActionServiceTest.java @@ -30,11 +30,11 @@ import com.redhat.rhn.domain.action.ActionChainFactory; import com.redhat.rhn.domain.action.ActionFactory; import com.redhat.rhn.domain.action.ActionStatus; +import com.redhat.rhn.domain.action.ansible.PlaybookAction; +import com.redhat.rhn.domain.action.ansible.PlaybookActionDetails; import com.redhat.rhn.domain.action.channel.SubscribeChannelsAction; import com.redhat.rhn.domain.action.channel.SubscribeChannelsActionDetails; import com.redhat.rhn.domain.action.config.ConfigAction; -import com.redhat.rhn.domain.action.salt.PlaybookAction; -import com.redhat.rhn.domain.action.salt.PlaybookActionDetails; import com.redhat.rhn.domain.action.script.ScriptActionDetails; import com.redhat.rhn.domain.action.server.ServerAction; import com.redhat.rhn.domain.action.test.ActionFactoryTest; From 1bf80ebe5bcd5b4125f8958a0ae438591a544668 Mon Sep 17 00:00:00 2001 From: Pascal Arlt Date: Mon, 17 Feb 2025 18:42:05 +0100 Subject: [PATCH 04/20] Add InventoryAction to refresh inventories Signed-off-by: Pascal Arlt --- .../rhn/domain/action/ActionFactory.java | 8 +++ .../domain/action/Action_legacyUser.hbm.xml | 6 ++ .../action/ansible/InventoryAction.java | 44 +++++++++++++ .../ansible/InventoryActionDetails.hbm.xml | 21 +++++++ .../ansible/InventoryActionDetails.java | 63 +++++++++++++++++++ .../strings/java/StringResource_en_US.xml | 6 ++ .../rhn/manager/action/ActionManager.java | 56 +++++++++++++++++ .../services/SaltServerActionService.java | 20 +++++- .../spacewalk/common/data/rhnActionType.sql | 2 +- .../common/tables/rhnActionInventory.sql | 32 ++++++++++ 10 files changed, 255 insertions(+), 3 deletions(-) create mode 100644 java/code/src/com/redhat/rhn/domain/action/ansible/InventoryAction.java create mode 100644 java/code/src/com/redhat/rhn/domain/action/ansible/InventoryActionDetails.hbm.xml create mode 100644 java/code/src/com/redhat/rhn/domain/action/ansible/InventoryActionDetails.java create mode 100644 schema/spacewalk/common/tables/rhnActionInventory.sql diff --git a/java/code/src/com/redhat/rhn/domain/action/ActionFactory.java b/java/code/src/com/redhat/rhn/domain/action/ActionFactory.java index 271d47d5419d..a08787f3e60d 100644 --- a/java/code/src/com/redhat/rhn/domain/action/ActionFactory.java +++ b/java/code/src/com/redhat/rhn/domain/action/ActionFactory.java @@ -432,6 +432,9 @@ else if (typeIn.equals(TYPE_SUBSCRIBE_CHANNELS)) { else if (typeIn.equals(TYPE_PLAYBOOK)) { retval = new PlaybookAction(); } + else if (typeIn.equals(TYPE_INVENTORY)) { + retval = new InventoryAction(); + } else if (typeIn.equals(TYPE_COCO_ATTESTATION)) { retval = new CoCoAttestationAction(); } @@ -1244,5 +1247,10 @@ public static void delete(ServerAction serverAction) { * The constant representing appstreams changes action. */ public static final ActionType TYPE_APPSTREAM_CONFIGURE = lookupActionTypeByLabel("appstreams.configure"); + + /** + * The constant representing "Refresh Ansible inventories" [ID:525] + */ + public static final ActionType TYPE_INVENTORY = lookupActionTypeByLabel("ansible.inventory"); } diff --git a/java/code/src/com/redhat/rhn/domain/action/Action_legacyUser.hbm.xml b/java/code/src/com/redhat/rhn/domain/action/Action_legacyUser.hbm.xml index c36bfaaaff58..2613f6a3d999 100644 --- a/java/code/src/com/redhat/rhn/domain/action/Action_legacyUser.hbm.xml +++ b/java/code/src/com/redhat/rhn/domain/action/Action_legacyUser.hbm.xml @@ -370,6 +370,12 @@ PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" + + + + + diff --git a/java/code/src/com/redhat/rhn/domain/action/ansible/InventoryAction.java b/java/code/src/com/redhat/rhn/domain/action/ansible/InventoryAction.java new file mode 100644 index 000000000000..6676fcb15788 --- /dev/null +++ b/java/code/src/com/redhat/rhn/domain/action/ansible/InventoryAction.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2025 SUSE LLC + * + * This software is licensed to you under the GNU General Public License, + * version 2 (GPLv2). There is NO WARRANTY for this software, express or + * implied, including the implied warranties of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 + * along with this software; if not, see + * http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. + * + * Red Hat trademarks are not licensed under GPLv2. No permission is + * granted to use or replicate Red Hat trademarks that are incorporated + * in this software or its documentation. + */ +package com.redhat.rhn.domain.action.ansible; + +import com.redhat.rhn.domain.action.Action; + +/** + * InventoryAction - Action class representing the execution of an Ansible inventory refresh + */ +public class InventoryAction extends Action { + + private InventoryActionDetails details; + + /** + * Return the details. + * @return details + */ + public InventoryActionDetails getDetails() { + return details; + } + + /** + * Set the details. + * @param detailsIn details + */ + public void setDetails(InventoryActionDetails detailsIn) { + if (detailsIn != null) { + detailsIn.setParentAction(this); + } + this.details = detailsIn; + } +} diff --git a/java/code/src/com/redhat/rhn/domain/action/ansible/InventoryActionDetails.hbm.xml b/java/code/src/com/redhat/rhn/domain/action/ansible/InventoryActionDetails.hbm.xml new file mode 100644 index 000000000000..6579aaaada08 --- /dev/null +++ b/java/code/src/com/redhat/rhn/domain/action/ansible/InventoryActionDetails.hbm.xml @@ -0,0 +1,21 @@ + + + + + + protected + + rhn_act_inventory_id_seq + 1 + + + + + + + + diff --git a/java/code/src/com/redhat/rhn/domain/action/ansible/InventoryActionDetails.java b/java/code/src/com/redhat/rhn/domain/action/ansible/InventoryActionDetails.java new file mode 100644 index 000000000000..3da0551ee76a --- /dev/null +++ b/java/code/src/com/redhat/rhn/domain/action/ansible/InventoryActionDetails.java @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2025 SUSE LLC + * + * This software is licensed to you under the GNU General Public License, + * version 2 (GPLv2). There is NO WARRANTY for this software, express or + * implied, including the implied warranties of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 + * along with this software; if not, see + * http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. + * + * Red Hat trademarks are not licensed under GPLv2. No permission is + * granted to use or replicate Red Hat trademarks that are incorporated + * in this software or its documentation. + */ +package com.redhat.rhn.domain.action.ansible; + +import com.redhat.rhn.domain.action.ActionChild; + +/** + * InventoryActionDetails - Class representation of the table rhnActionInventory. + */ +public class InventoryActionDetails extends ActionChild { + + private long id; + private long actionId; + private String inventoryPath; + + /** + * @return the id + */ + public long getId() { + return id; + } + + /** + * @param idIn the id to set + */ + public void setId(long idIn) { + this.id = idIn; + } + + /** + * @return the action id + */ + public long getActionId() { + return actionId; + } + + /** + * @param actionIdIn the action id to set + */ + public void setActionId(long actionIdIn) { + this.actionId = actionIdIn; + } + + public String getInventoryPath() { + return inventoryPath; + } + + public void setInventoryPath(String inventoryPathIn) { + this.inventoryPath = inventoryPathIn; + } +} diff --git a/java/code/src/com/redhat/rhn/frontend/strings/java/StringResource_en_US.xml b/java/code/src/com/redhat/rhn/frontend/strings/java/StringResource_en_US.xml index 1d6ea5f441e0..cba0331afa66 100644 --- a/java/code/src/com/redhat/rhn/frontend/strings/java/StringResource_en_US.xml +++ b/java/code/src/com/redhat/rhn/frontend/strings/java/StringResource_en_US.xml @@ -9289,6 +9289,12 @@ Alternatively, you will want to download <strong>Incremental Channel Conte com.redhat.rhn.domain.action.ActionFormatter.getActionType + + Refresh Ansible inventories + + com.redhat.rhn.domain.action.ActionFormatter.getActionType + + There was a problem assigning the Prometheus Exporters formula. diff --git a/java/code/src/com/redhat/rhn/manager/action/ActionManager.java b/java/code/src/com/redhat/rhn/manager/action/ActionManager.java index ed8224de1214..db2fe4d6cf8c 100644 --- a/java/code/src/com/redhat/rhn/manager/action/ActionManager.java +++ b/java/code/src/com/redhat/rhn/manager/action/ActionManager.java @@ -33,6 +33,8 @@ import com.redhat.rhn.domain.action.Action; import com.redhat.rhn.domain.action.ActionFactory; import com.redhat.rhn.domain.action.ActionType; +import com.redhat.rhn.domain.action.ansible.InventoryAction; +import com.redhat.rhn.domain.action.ansible.InventoryActionDetails; import com.redhat.rhn.domain.action.config.ConfigAction; import com.redhat.rhn.domain.action.config.ConfigUploadAction; import com.redhat.rhn.domain.action.dup.DistUpgradeAction; @@ -2514,4 +2516,58 @@ public static List changeProxy(User loggedInUser, List sysids, Long } return ret; } + + /** + * Schedule an immediate Ansible inventory refresh without a user. + * + * @param server the server + * @param inventoryPath the Ansible inventory + * @return the scheduled InventoryAction + * @throws TaskomaticApiException if there was a Taskomatic error + * (typically: Taskomatic is down) + */ + public static Action scheduleInventoryRefresh(Server server, String inventoryPath) + throws TaskomaticApiException { + Date earliest = new Date(); + return scheduleInventoryRefresh(Optional.empty(), server, inventoryPath, earliest); + } + + /** + * Schedule an Ansible inventory refresh. + * + * @param user the user + * @param server the server + * @param earliest The earliest time this action should be run. + * @param inventoryPath the Ansible inventory + * @return the scheduled InventoryAction + * @throws TaskomaticApiException if there was a Taskomatic error + * (typically: Taskomatic is down) + */ + public static Action scheduleInventoryRefresh(Optional user, Server server, String inventoryPath, + Date earliest) throws TaskomaticApiException { + checkSaltOrManagementEntitlement(server.getId()); + + InventoryAction action = (InventoryAction) ActionFactory.createAction( + ActionFactory.TYPE_INVENTORY); + + InventoryActionDetails details = new InventoryActionDetails(); + details.setInventoryPath(inventoryPath); + + action.setName(ActionFactory.TYPE_INVENTORY.getName()); + action.setOrg(server.getOrg()); + action.setSchedulerUser(user.orElse(null)); + action.setEarliestAction(earliest); + action.setDetails(details); + + ServerAction sa = new ServerAction(); + sa.setStatus(ActionFactory.STATUS_QUEUED); + sa.setRemainingTries(REMAINING_TRIES); + sa.setServerWithCheck(server); + action.addServerAction(sa); + sa.setParentActionWithCheck(action); + + ActionFactory.save(action); + taskomaticApi.scheduleActionExecution(action); + return action; + } } diff --git a/java/code/src/com/suse/manager/webui/services/SaltServerActionService.java b/java/code/src/com/suse/manager/webui/services/SaltServerActionService.java index 8c32092290b9..4398f16778b4 100644 --- a/java/code/src/com/suse/manager/webui/services/SaltServerActionService.java +++ b/java/code/src/com/suse/manager/webui/services/SaltServerActionService.java @@ -19,6 +19,8 @@ import static java.util.Collections.emptyMap; import static java.util.Collections.singletonList; import static java.util.Collections.singletonMap; +import static java.util.Optional.empty; +import static java.util.Optional.of; import static java.util.Optional.ofNullable; import static java.util.stream.Collectors.groupingBy; import static java.util.stream.Collectors.joining; @@ -40,6 +42,10 @@ import com.redhat.rhn.domain.action.ActionFactory; import com.redhat.rhn.domain.action.ActionStatus; import com.redhat.rhn.domain.action.ActionType; +import com.redhat.rhn.domain.action.ansible.InventoryAction; +import com.redhat.rhn.domain.action.ansible.InventoryActionDetails; +import com.redhat.rhn.domain.action.ansible.PlaybookAction; +import com.redhat.rhn.domain.action.ansible.PlaybookActionDetails; import com.redhat.rhn.domain.action.appstream.AppStreamAction; import com.redhat.rhn.domain.action.appstream.AppStreamActionDetails; import com.redhat.rhn.domain.action.channel.SubscribeChannelsAction; @@ -57,8 +63,6 @@ import com.redhat.rhn.domain.action.rhnpackage.PackageUpdateAction; import com.redhat.rhn.domain.action.salt.ApplyStatesAction; import com.redhat.rhn.domain.action.salt.ApplyStatesActionDetails; -import com.redhat.rhn.domain.action.ansible.PlaybookAction; -import com.redhat.rhn.domain.action.ansible.PlaybookActionDetails; import com.redhat.rhn.domain.action.salt.build.ImageBuildAction; import com.redhat.rhn.domain.action.salt.build.ImageBuildActionDetails; import com.redhat.rhn.domain.action.salt.inspect.ImageInspectAction; @@ -212,6 +216,7 @@ public class SaltServerActionService { private static final String SYSTEM_REBOOT = "system.reboot"; private static final String KICKSTART_INITIATE = "bootloader.autoinstall"; private static final String ANSIBLE_RUNPLAYBOOK = "ansible.runplaybook"; + private static final String ANSIBLE_INVENTORIES = "ansible.targets"; private static final String COCOATTEST_REQUESTDATA = "cocoattest.requestdata"; public static final String APPSTREAMS_CONFIGURE = "appstreams.configure"; public static final String PARAM_APPSTREAMS_ENABLE = "param_appstreams_enable"; @@ -351,6 +356,9 @@ else if (ActionFactory.TYPE_KICKSTART_INITIATE.equals(actionType)) { else if (ActionFactory.TYPE_PLAYBOOK.equals(actionType)) { return singletonMap(executePlaybookActionCall((PlaybookAction) actionIn), minions); } + else if (ActionFactory.TYPE_INVENTORY.equals(actionType)) { + return singletonMap(executeInventoryActionCall((InventoryAction) actionIn), minions); + } else if (ActionFactory.TYPE_COCO_ATTESTATION.equals(actionType)) { return cocoAttestationAction(minions); } @@ -1741,6 +1749,14 @@ private LocalCall executePlaybookActionCall(PlaybookAction action) { Optional.of(details.isTestMode())); } + private LocalCall executeInventoryActionCall(InventoryAction action) { + InventoryActionDetails details = action.getDetails(); + String inventoryPath = details.getInventoryPath(); + + return new LocalCall<>("ansible.targets", empty(), of(Map.of("inventory", inventoryPath)), + new TypeToken<>() { }); + } + private Map, List> cocoAttestationAction(List minionSummaries) { return Map.of( State.apply(Collections.singletonList(COCOATTEST_REQUESTDATA), Optional.empty()), diff --git a/schema/spacewalk/common/data/rhnActionType.sql b/schema/spacewalk/common/data/rhnActionType.sql index f21536479c95..682dc356918d 100644 --- a/schema/spacewalk/common/data/rhnActionType.sql +++ b/schema/spacewalk/common/data/rhnActionType.sql @@ -71,4 +71,4 @@ insert into rhnActionType values (521, 'ansible.playbook', 'Execute an Ansible p insert into rhnActionType values (523, 'coco.attestation', 'Confidential Compute Attestation', 'N', 'N', 'N'); insert into rhnActionType values (524, 'appstreams.configure', 'Configure AppStreams in a system', 'N', 'N', 'N'); commit; - +insert into rhnActionType values (525, 'ansible.inventory', 'Refresh Ansible inventories', 'N', 'N', 'N'); diff --git a/schema/spacewalk/common/tables/rhnActionInventory.sql b/schema/spacewalk/common/tables/rhnActionInventory.sql new file mode 100644 index 000000000000..c62428bd948b --- /dev/null +++ b/schema/spacewalk/common/tables/rhnActionInventory.sql @@ -0,0 +1,32 @@ +-- +-- Copyright (c) 2025 SUSE LLC +-- +-- This software is licensed to you under the GNU General Public License, +-- version 2 (GPLv2). There is NO WARRANTY for this software, express or +-- implied, including the implied warranties of MERCHANTABILITY or FITNESS +-- FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 +-- along with this software; if not, see +-- http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. +-- +CREATE TABLE rhnActionInventory +( + id NUMERIC NOT NULL + CONSTRAINT rhn_action_inventory_id_pk + PRIMARY KEY, + action_id NUMERIC NOT NULL + CONSTRAINT rhn_action_inventory_aid_fk + REFERENCES rhnAction (id) + ON DELETE CASCADE, + inventory_path VARCHAR(1024), + created TIMESTAMPTZ + DEFAULT (current_timestamp) NOT NULL, + modified TIMESTAMPTZ + DEFAULT (current_timestamp) NOT NULL +) +; + +CREATE UNIQUE INDEX rhn_act_inventory_aid_uq + ON rhnActionInventory (action_id); + +CREATE SEQUENCE rhn_act_inventory_id_seq; + From 272e87218c086074657620453da1a02d60b6b545 Mon Sep 17 00:00:00 2001 From: Pascal Arlt Date: Mon, 17 Feb 2025 18:42:54 +0100 Subject: [PATCH 05/20] Schedule InventoryAction on inotify event Signed-off-by: Pascal Arlt --- .../src/com/suse/manager/reactor/SaltReactor.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/java/code/src/com/suse/manager/reactor/SaltReactor.java b/java/code/src/com/suse/manager/reactor/SaltReactor.java index 92a4a9a5bb16..bfa9ad160be5 100644 --- a/java/code/src/com/suse/manager/reactor/SaltReactor.java +++ b/java/code/src/com/suse/manager/reactor/SaltReactor.java @@ -294,6 +294,19 @@ else if (beaconEvent.getBeacon().equals("reboot_info")) { } ); } + else if (beaconEvent.getBeacon().equals("inotify")) { + Optional minion = MinionServerFactory.findByMinionId(beaconEvent.getMinionId()); + minion.ifPresent(m -> { + // Schedule retrieval of minions from changed inventory + try { + ActionManager.scheduleInventoryRefresh(m, beaconEvent.getAdditional()); + } + catch (TaskomaticApiException e) { + LOG.error("Could not schedule Ansible inventory refresh for minion: {}", + m.getMinionId(), e); + } + }); + } return empty(); } From 07068a54cfdde666ac43a29ec36c707da6353e83 Mon Sep 17 00:00:00 2001 From: Pascal Arlt Date: Tue, 18 Feb 2025 18:39:45 +0100 Subject: [PATCH 06/20] Move parseInventoryAndGetHostnames to AnsibleManager Signed-off-by: Pascal Arlt --- .../rhn/manager/system/AnsibleManager.java | 26 ++++++++++++++++++ .../webui/controllers/AnsibleController.java | 27 +------------------ .../test/AnsibleControllerTest.java | 5 ++-- 3 files changed, 29 insertions(+), 29 deletions(-) diff --git a/java/code/src/com/redhat/rhn/manager/system/AnsibleManager.java b/java/code/src/com/redhat/rhn/manager/system/AnsibleManager.java index 219eec9033cf..6e41af53dc1d 100644 --- a/java/code/src/com/redhat/rhn/manager/system/AnsibleManager.java +++ b/java/code/src/com/redhat/rhn/manager/system/AnsibleManager.java @@ -45,6 +45,7 @@ import com.google.gson.reflect.TypeToken; +import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; import java.nio.file.InvalidPathException; @@ -52,9 +53,11 @@ import java.util.ArrayList; import java.util.Date; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Optional; +import java.util.Set; public class AnsibleManager extends BaseManager { @@ -406,6 +409,29 @@ public Optional>> introspectInventory(long pathI success -> success)); } + /** + * Parse Ansible Inventory content to look for host names + * + * @param inventoryMap the Ansible Inventory content + * @return the Set of hostnames + */ + public static Set parseInventoryAndGetHostnames(Map> inventoryMap) { + HashSet hostnames = new HashSet<>(); + + for (Map.Entry> entry : inventoryMap.entrySet()) { + String ansibleGroupName = entry.getKey(); + if (!ansibleGroupName.equals("_meta")) { + @SuppressWarnings("unchecked") + List hostList = (List)entry.getValue().get("hosts"); + if (CollectionUtils.isNotEmpty(hostList)) { + hostnames.addAll(hostList); + } + } + } + + return hostnames; + } + /** * Generate the inotify beacon for the given ansible control node based on * the {@link InventoryPath} related to it. diff --git a/java/code/src/com/suse/manager/webui/controllers/AnsibleController.java b/java/code/src/com/suse/manager/webui/controllers/AnsibleController.java index 6c99ab48cccb..7b61b0404993 100644 --- a/java/code/src/com/suse/manager/webui/controllers/AnsibleController.java +++ b/java/code/src/com/suse/manager/webui/controllers/AnsibleController.java @@ -47,7 +47,6 @@ import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; -import org.apache.commons.collections.CollectionUtils; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.yaml.snakeyaml.LoaderOptions; @@ -58,7 +57,6 @@ import java.time.ZoneId; import java.util.Date; import java.util.HashMap; -import java.util.HashSet; import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -349,7 +347,7 @@ public static String introspectInventory(Request req, Response res, User user) { .map(inventory -> { Map data = new HashMap<>(); - Set hostvars = parseInventoryAndGetHostnames(inventory); + Set hostvars = AnsibleManager.parseInventoryAndGetHostnames(inventory); List registeredServers = new LinkedList<>(); List unknownHostNames = new LinkedList<>(); @@ -382,29 +380,6 @@ public static String introspectInventory(Request req, Response res, User user) { } } - /** - * Parse Ansible Inventory content to look for host names - * - * @param inventoryMap the Ansible Inventory content - * @return the Set of hostnames - */ - public static Set parseInventoryAndGetHostnames(Map> inventoryMap) { - HashSet hostnames = new HashSet<>(); - - for (Map.Entry> entry : inventoryMap.entrySet()) { - String ansibleGroupName = entry.getKey(); - if (!ansibleGroupName.equals("_meta")) { - @SuppressWarnings("unchecked") - List hostList = (List)entry.getValue().get("hosts"); - if (CollectionUtils.isNotEmpty(hostList)) { - hostnames.addAll(hostList); - } - } - } - - return hostnames; - } - /** * Discover ansible playbooks * diff --git a/java/code/src/com/suse/manager/webui/controllers/test/AnsibleControllerTest.java b/java/code/src/com/suse/manager/webui/controllers/test/AnsibleControllerTest.java index 09b6938ab77c..4f1fd54a80da 100644 --- a/java/code/src/com/suse/manager/webui/controllers/test/AnsibleControllerTest.java +++ b/java/code/src/com/suse/manager/webui/controllers/test/AnsibleControllerTest.java @@ -17,10 +17,9 @@ import static org.junit.jupiter.api.Assertions.assertEquals; +import com.redhat.rhn.manager.system.AnsibleManager; import com.redhat.rhn.testing.BaseTestCaseWithUser; -import com.suse.manager.webui.controllers.AnsibleController; - import org.junit.jupiter.api.Test; import java.util.List; @@ -150,7 +149,7 @@ private List getTestInventories() { public void testParseInventoryAndGetHostnames() { List testCases = getTestInventories(); testCases.stream().forEach((testCase) -> { - Set gotHostnames = AnsibleController.parseInventoryAndGetHostnames(testCase.getInventory()); + Set gotHostnames = AnsibleManager.parseInventoryAndGetHostnames(testCase.getInventory()); assertEquals(gotHostnames, testCase.getExpectedResult()); }); } From 508810c215bf70213cf44d184a21038893c045ac Mon Sep 17 00:00:00 2001 From: Pascal Arlt Date: Tue, 18 Feb 2025 18:41:39 +0100 Subject: [PATCH 07/20] Create table to store Ansible managed systems per inventory Signed-off-by: Pascal Arlt --- .../domain/server/ansible/InventoryPath.java | 33 +++++++++++++++++++ .../tables/suseAnsibleInventoryServers.sql | 31 +++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 schema/spacewalk/common/tables/suseAnsibleInventoryServers.sql diff --git a/java/code/src/com/redhat/rhn/domain/server/ansible/InventoryPath.java b/java/code/src/com/redhat/rhn/domain/server/ansible/InventoryPath.java index 0ad82c75186b..d607cb6b6317 100644 --- a/java/code/src/com/redhat/rhn/domain/server/ansible/InventoryPath.java +++ b/java/code/src/com/redhat/rhn/domain/server/ansible/InventoryPath.java @@ -16,9 +16,16 @@ package com.redhat.rhn.domain.server.ansible; import com.redhat.rhn.domain.server.MinionServer; +import com.redhat.rhn.domain.server.Server; + +import java.util.Set; import javax.persistence.DiscriminatorValue; import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.JoinColumn; +import javax.persistence.JoinTable; +import javax.persistence.OneToMany; import javax.persistence.Transient; /** @@ -28,6 +35,8 @@ @DiscriminatorValue("inventory") public class InventoryPath extends AnsiblePath { + private Set inventoryServers; + /** * Standard constructor */ @@ -46,4 +55,28 @@ public InventoryPath(MinionServer minionServer) { public Type getEntityType() { return Type.INVENTORY; } + + /** + * Gets the inventory servers + * + * @return the inventory servers + */ + @OneToMany(fetch = FetchType.LAZY) + @JoinTable( + name = "suseAnsibleInventoryServers", + joinColumns = @JoinColumn(name = "inventory_id"), + inverseJoinColumns = @JoinColumn(name = "server_id") + ) + public Set getInventoryServers() { + return inventoryServers; + } + + /** + * Sets the inventory server + * + * @param inventoryServersIn the inventory servers + */ + public void setInventoryServers(Set inventoryServersIn) { + inventoryServers = inventoryServersIn; + } } diff --git a/schema/spacewalk/common/tables/suseAnsibleInventoryServers.sql b/schema/spacewalk/common/tables/suseAnsibleInventoryServers.sql new file mode 100644 index 000000000000..c1801b6bd670 --- /dev/null +++ b/schema/spacewalk/common/tables/suseAnsibleInventoryServers.sql @@ -0,0 +1,31 @@ +-- +-- Copyright (c) 2025 SUSE LLC +-- +-- This software is licensed to you under the GNU General Public License, +-- version 2 (GPLv2). There is NO WARRANTY for this software, express or +-- implied, including the implied warranties of MERCHANTABILITY or FITNESS +-- FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 +-- along with this software; if not, see +-- http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. +-- +CREATE TABLE suseAnsibleInventoryServers( + + inventory_id NUMERIC NOT NULL + CONSTRAINT suse_ansible_inventory_id_fk + REFERENCES suseAnsiblePath(id) + ON DELETE CASCADE, + + server_id NUMERIC NOT NULL + CONSTRAINT suse_ansible_inventory_sid_fk + REFERENCES rhnServer(id) + ON DELETE CASCADE, + + created TIMESTAMPTZ + DEFAULT (current_timestamp) NOT NULL, + + modified TIMESTAMPTZ + DEFAULT (current_timestamp) NOT NULL +); + +CREATE UNIQUE INDEX suse_ansible_inventory_server_uq + ON suseAnsibleInventoryServers(inventory_id, server_id); From 48f1bc49de99fe287e45ba545133d71c407187b9 Mon Sep 17 00:00:00 2001 From: Pascal Arlt Date: Tue, 18 Feb 2025 18:42:53 +0100 Subject: [PATCH 08/20] Store Ansible managed systems on inventory refresh return Signed-off-by: Pascal Arlt --- .../rhn/domain/server/AnsibleFactory.java | 18 ++++++++ .../src/com/suse/manager/utils/SaltUtils.java | 43 +++++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/java/code/src/com/redhat/rhn/domain/server/AnsibleFactory.java b/java/code/src/com/redhat/rhn/domain/server/AnsibleFactory.java index b3e94149a479..f3b85cecd354 100644 --- a/java/code/src/com/redhat/rhn/domain/server/AnsibleFactory.java +++ b/java/code/src/com/redhat/rhn/domain/server/AnsibleFactory.java @@ -16,6 +16,7 @@ package com.redhat.rhn.domain.server; import com.redhat.rhn.common.hibernate.HibernateFactory; +import com.redhat.rhn.common.hibernate.PathConverter; import com.redhat.rhn.domain.server.ansible.AnsiblePath; import com.redhat.rhn.domain.server.ansible.InventoryPath; import com.redhat.rhn.domain.server.ansible.PlaybookPath; @@ -63,6 +64,23 @@ public static Optional lookupAnsiblePathByPathAndMinion(Path path, .uniqueResultOptional(); } + /** + * Lookup {@link InventoryPath} associated with a {@link MinionServer} with given path + * + * @param minionId the id of {@link MinionServer} + * @param inventoryPath the path of the inventory + * @return optional of {@link InventoryPath} + */ + public static Optional lookupAnsibleInventoryPath(long minionId, String inventoryPath) { + return HibernateFactory.getSession() + .createQuery("SELECT p FROM InventoryPath p " + + "WHERE p.minionServer.id = :mid " + + "AND p.path = :inventoryPath") + .setParameter("mid", minionId) + .setParameter("inventoryPath", new PathConverter().convertToEntityAttribute(inventoryPath)) + .uniqueResultOptional(); + } + /** * List {@link AnsiblePath}s associated with a {@link MinionServer} with given id * diff --git a/java/code/src/com/suse/manager/utils/SaltUtils.java b/java/code/src/com/suse/manager/utils/SaltUtils.java index f8015178673d..496ac9b6b5a2 100644 --- a/java/code/src/com/suse/manager/utils/SaltUtils.java +++ b/java/code/src/com/suse/manager/utils/SaltUtils.java @@ -27,6 +27,7 @@ import com.redhat.rhn.domain.action.ActionFactory; import com.redhat.rhn.domain.action.ActionStatus; import com.redhat.rhn.domain.action.ActionType; +import com.redhat.rhn.domain.action.ansible.InventoryAction; import com.redhat.rhn.domain.action.config.ConfigRevisionActionResult; import com.redhat.rhn.domain.action.config.ConfigVerifyAction; import com.redhat.rhn.domain.action.dup.DistUpgradeAction; @@ -64,6 +65,7 @@ import com.redhat.rhn.domain.rhnpackage.PackageFactory; import com.redhat.rhn.domain.rhnpackage.PackageName; import com.redhat.rhn.domain.rhnpackage.PackageType; +import com.redhat.rhn.domain.server.AnsibleFactory; import com.redhat.rhn.domain.server.InstalledPackage; import com.redhat.rhn.domain.server.InstalledProduct; import com.redhat.rhn.domain.server.MinionServer; @@ -71,12 +73,14 @@ import com.redhat.rhn.domain.server.Server; import com.redhat.rhn.domain.server.ServerAppStream; import com.redhat.rhn.domain.server.ServerFactory; +import com.redhat.rhn.domain.server.ansible.InventoryPath; import com.redhat.rhn.domain.user.User; import com.redhat.rhn.frontend.action.common.BadParameterException; import com.redhat.rhn.manager.action.ActionManager; import com.redhat.rhn.manager.audit.ScapManager; import com.redhat.rhn.manager.errata.ErrataManager; import com.redhat.rhn.manager.rhnpackage.PackageManager; +import com.redhat.rhn.manager.system.AnsibleManager; import com.redhat.rhn.manager.system.SystemManager; import com.redhat.rhn.taskomatic.TaskomaticApi; import com.redhat.rhn.taskomatic.TaskomaticApiException; @@ -713,6 +717,14 @@ else if (action.getActionType().equals(ActionFactory.TYPE_SUBSCRIBE_CHANNELS)) { else if (action.getActionType().equals(ActionFactory.TYPE_COCO_ATTESTATION)) { handleCocoAttestationResult(action, serverAction, jsonResult); } + else if (action.getActionType().equals(ActionFactory.TYPE_INVENTORY)) { + if (serverAction.getStatus().equals(ActionFactory.STATUS_COMPLETED)) { + handleInventoryRefresh(action, serverAction, jsonResult); + } + else { + serverAction.setResultMsg(getJsonResultWithPrettyPrint(jsonResult)); + } + } else { serverAction.setResultMsg(getJsonResultWithPrettyPrint(jsonResult)); } @@ -1887,6 +1899,37 @@ private static void handleHardwareProfileUpdate(MinionServer server, } } + private void handleInventoryRefresh(Action action, ServerAction serverAction, JsonElement jsonResult) { + try { + Set hostvars = AnsibleManager.parseInventoryAndGetHostnames( + Json.GSON.fromJson(jsonResult, Map.class)); + InventoryAction inventoryAction = (InventoryAction) action; + Optional inventory = AnsibleFactory.lookupAnsibleInventoryPath( + serverAction.getServerId(), inventoryAction.getDetails().getInventoryPath()); + + if (inventory.isPresent()) { + Set registeredServers = new HashSet<>(); + hostvars.forEach(serverName -> ServerFactory.findByFqdn(serverName).ifPresent(registeredServers::add)); + + inventory.get().setInventoryServers(registeredServers); + AnsibleFactory.saveAnsiblePath(inventory.get()); + } + else { + String message = String.format("Unable to find Ansible inventory: '%s' for system %s", + inventoryAction.getDetails().getInventoryPath(), + serverAction.getServerId()); + LOG.warn(message); + serverAction.setStatus(ActionFactory.STATUS_FAILED); + serverAction.setResultMsg(message); + } + } + catch (JsonSyntaxException e) { + LOG.warn("Unable to parse Ansible inventory from json: {}", e.getMessage()); + return; + } + serverAction.setResultMsg("Successfully refreshed Ansible managed systems"); + } + private static PackageEvr parsePackageEvr(Optional epoch, String version, Optional release, PackageType type) { switch (type) { From 78dd257ec4f9248fb17e394b9372e221b109e9ec Mon Sep 17 00:00:00 2001 From: Pascal Arlt Date: Wed, 19 Feb 2025 13:53:48 +0100 Subject: [PATCH 09/20] Add ansible_managed entitlement schema Signed-off-by: Pascal Arlt --- .../db/datasource/xml/System_queries.xml | 1 + .../common/data/rhnSGTypeBaseAddonCompat.sql | 4 + .../common/data/rhnServerGroupType.sql | 8 + .../data/rhnServerServerGroupArchCompat.sql | 158 ++++++ schema/spacewalk/common/tables/tables.deps | 2 + .../postgres/packages/rhn_entitlements.pkb | 3 + .../postgres/procs/create_new_org.sql | 7 + .../500-ansible_managed_entitlement.sql | 482 ++++++++++++++++++ .../501-rhn_entitlements.pkb.sql | 385 ++++++++++++++ .../502-create_new_org.sql | 244 +++++++++ 10 files changed, 1294 insertions(+) create mode 100644 schema/spacewalk/upgrade/susemanager-schema-5.1.3-to-susemanager-schema-5.1.4/500-ansible_managed_entitlement.sql create mode 100644 schema/spacewalk/upgrade/susemanager-schema-5.1.3-to-susemanager-schema-5.1.4/501-rhn_entitlements.pkb.sql create mode 100644 schema/spacewalk/upgrade/susemanager-schema-5.1.3-to-susemanager-schema-5.1.4/502-create_new_org.sql diff --git a/java/code/src/com/redhat/rhn/common/db/datasource/xml/System_queries.xml b/java/code/src/com/redhat/rhn/common/db/datasource/xml/System_queries.xml index 970aa1752818..7c3d8f61ea91 100644 --- a/java/code/src/com/redhat/rhn/common/db/datasource/xml/System_queries.xml +++ b/java/code/src/com/redhat/rhn/common/db/datasource/xml/System_queries.xml @@ -1478,6 +1478,7 @@ SELECT 1 WHEN 'monitoring_entitled' then 'Monitoring' WHEN 'ansible_control_node' then 'Ansible Control Node' WHEN 'peripheral_server' then 'Peripheral Server' + WHEN 'ansible_managed' then 'Ansible Managed' END) diff --git a/schema/spacewalk/common/data/rhnSGTypeBaseAddonCompat.sql b/schema/spacewalk/common/data/rhnSGTypeBaseAddonCompat.sql index 1870ca0d37fa..931e6f4a4c2f 100644 --- a/schema/spacewalk/common/data/rhnSGTypeBaseAddonCompat.sql +++ b/schema/spacewalk/common/data/rhnSGTypeBaseAddonCompat.sql @@ -45,4 +45,8 @@ insert into rhnSGTypeBaseAddonCompat (base_id, addon_id) values (lookup_sg_type('foreign_entitled'), lookup_sg_type('peripheral_server')); +insert into rhnSGTypeBaseAddonCompat (base_id, addon_id) +values (lookup_sg_type('salt_entitled'), + lookup_sg_type('ansible_managed')); + commit; diff --git a/schema/spacewalk/common/data/rhnServerGroupType.sql b/schema/spacewalk/common/data/rhnServerGroupType.sql index 6a2aa5e28857..8992a691c0f5 100644 --- a/schema/spacewalk/common/data/rhnServerGroupType.sql +++ b/schema/spacewalk/common/data/rhnServerGroupType.sql @@ -97,4 +97,12 @@ insert into rhnServerGroupType ( id, label, name, permanent, is_base) 'N', 'N' ); +-- ansible_managed type ----------------------------------------------------- + +insert into rhnServerGroupType ( id, label, name, permanent, is_base) + values ( sequence_nextval('rhn_servergroup_type_seq'), + 'ansible_managed', 'Ansible Managed Servers', + 'N', 'N' + ); + commit; diff --git a/schema/spacewalk/common/data/rhnServerServerGroupArchCompat.sql b/schema/spacewalk/common/data/rhnServerServerGroupArchCompat.sql index cafa5c1c2a54..5f9faecd3815 100644 --- a/schema/spacewalk/common/data/rhnServerServerGroupArchCompat.sql +++ b/schema/spacewalk/common/data/rhnServerServerGroupArchCompat.sql @@ -937,4 +937,162 @@ insert into rhnServerServerGroupArchCompat ( server_arch_id, server_group_type ) values (lookup_server_arch('amd64-redhat-linux'), lookup_sg_type('peripheral_server')); +-- ansible_managed system entitlement + +insert into rhnServerServerGroupArchCompat ( server_arch_id, server_group_type ) + values (lookup_server_arch('i386-redhat-linux'), + lookup_sg_type('ansible_managed')); + +insert into rhnServerServerGroupArchCompat ( server_arch_id, server_group_type ) + values (lookup_server_arch('i386-debian-linux'), + lookup_sg_type('ansible_managed')); + +insert into rhnServerServerGroupArchCompat ( server_arch_id, server_group_type ) + values (lookup_server_arch('i486-redhat-linux'), + lookup_sg_type('ansible_managed')); + +insert into rhnServerServerGroupArchCompat ( server_arch_id, server_group_type ) + values (lookup_server_arch('i586-redhat-linux'), + lookup_sg_type('ansible_managed')); + +insert into rhnServerServerGroupArchCompat ( server_arch_id, server_group_type ) + values (lookup_server_arch('i686-redhat-linux'), + lookup_sg_type('ansible_managed')); + +insert into rhnServerServerGroupArchCompat ( server_arch_id, server_group_type ) + values (lookup_server_arch('athlon-redhat-linux'), + lookup_sg_type('ansible_managed')); + +insert into rhnServerServerGroupArchCompat ( server_arch_id, server_group_type ) + values (lookup_server_arch('alpha-redhat-linux'), + lookup_sg_type('ansible_managed')); + +insert into rhnServerServerGroupArchCompat ( server_arch_id, server_group_type ) + values (lookup_server_arch('alpha-debian-linux'), + lookup_sg_type('ansible_managed')); + +insert into rhnServerServerGroupArchCompat ( server_arch_id, server_group_type ) + values (lookup_server_arch('alphaev6-redhat-linux'), + lookup_sg_type('ansible_managed')); + +insert into rhnServerServerGroupArchCompat ( server_arch_id, server_group_type ) + values (lookup_server_arch('ia64-redhat-linux'), + lookup_sg_type('ansible_managed')); + +insert into rhnServerServerGroupArchCompat ( server_arch_id, server_group_type ) + values (lookup_server_arch('ia64-debian-linux'), + lookup_sg_type('ansible_managed')); + +insert into rhnServerServerGroupArchCompat ( server_arch_id, server_group_type ) + values (lookup_server_arch('sparc-redhat-linux'), + lookup_sg_type('ansible_managed')); + +insert into rhnServerServerGroupArchCompat ( server_arch_id, server_group_type ) + values (lookup_server_arch('sparc-debian-linux'), + lookup_sg_type('ansible_managed')); + +insert into rhnServerServerGroupArchCompat ( server_arch_id, server_group_type ) + values (lookup_server_arch('sparcv9-redhat-linux'), + lookup_sg_type('ansible_managed')); + +insert into rhnServerServerGroupArchCompat ( server_arch_id, server_group_type ) + values (lookup_server_arch('sparc64-redhat-linux'), + lookup_sg_type('ansible_managed')); + +insert into rhnServerServerGroupArchCompat ( server_arch_id, server_group_type ) + values (lookup_server_arch('s390-redhat-linux'), + lookup_sg_type('ansible_managed')); + +insert into rhnServerServerGroupArchCompat ( server_arch_id, server_group_type ) + values (lookup_server_arch('aarch64-redhat-linux'), + lookup_sg_type('ansible_managed')); + +insert into rhnServerServerGroupArchCompat ( server_arch_id, server_group_type ) + values (lookup_server_arch('armv7l-redhat-linux'), + lookup_sg_type('ansible_managed')); + +insert into rhnServerServerGroupArchCompat ( server_arch_id, server_group_type ) + values (lookup_server_arch('armv5tejl-redhat-linux'), + lookup_sg_type('ansible_managed')); + +insert into rhnServerServerGroupArchCompat ( server_arch_id, server_group_type ) + values (lookup_server_arch('armv6l-redhat-linux'), + lookup_sg_type('ansible_managed')); + +insert into rhnServerServerGroupArchCompat ( server_arch_id, server_group_type ) + values (lookup_server_arch('armv6hl-redhat-linux'), + lookup_sg_type('ansible_managed')); + +insert into rhnServerServerGroupArchCompat ( server_arch_id, server_group_type ) + values (lookup_server_arch('s390-debian-linux'), + lookup_sg_type('ansible_managed')); + +insert into rhnServerServerGroupArchCompat ( server_arch_id, server_group_type ) + values (lookup_server_arch('s390x-redhat-linux'), + lookup_sg_type('ansible_managed')); + +insert into rhnServerServerGroupArchCompat ( server_arch_id, server_group_type ) + values (lookup_server_arch('ppc-redhat-linux'), + lookup_sg_type('ansible_managed')); + +insert into rhnServerServerGroupArchCompat ( server_arch_id, server_group_type ) + values (lookup_server_arch('powerpc-debian-linux'), + lookup_sg_type('ansible_managed')); + +insert into rhnServerServerGroupArchCompat ( server_arch_id, server_group_type ) + values (lookup_server_arch('ppc64-redhat-linux'), + lookup_sg_type('ansible_managed')); + +insert into rhnServerServerGroupArchCompat ( server_arch_id, server_group_type ) + values (lookup_server_arch('ppc64le-redhat-linux'), + lookup_sg_type('ansible_managed')); + +insert into rhnServerServerGroupArchCompat ( server_arch_id, server_group_type ) + values (lookup_server_arch('pSeries-redhat-linux'), + lookup_sg_type('ansible_managed')); + +insert into rhnServerServerGroupArchCompat ( server_arch_id, server_group_type ) + values (lookup_server_arch('iSeries-redhat-linux'), + lookup_sg_type('ansible_managed')); + +insert into rhnServerServerGroupArchCompat ( server_arch_id, server_group_type ) + values (lookup_server_arch('x86_64-redhat-linux'), + lookup_sg_type('ansible_managed')); + +insert into rhnServerServerGroupArchCompat ( server_arch_id, server_group_type ) + values (lookup_server_arch('ia32e-redhat-linux'), + lookup_sg_type('ansible_managed')); + +insert into rhnServerServerGroupArchCompat ( server_arch_id, server_group_type ) + values (lookup_server_arch('amd64-redhat-linux'), + lookup_sg_type('ansible_managed')); + +insert into rhnServerServerGroupArchCompat ( server_arch_id, server_group_type ) + values (lookup_server_arch('amd64-debian-linux'), + lookup_sg_type('ansible_managed')); + +insert into rhnServerServerGroupArchCompat ( server_arch_id, server_group_type ) + values (lookup_server_arch('arm64-debian-linux'), + lookup_sg_type('ansible_managed')); + +insert into rhnServerServerGroupArchCompat ( server_arch_id, server_group_type ) + values (lookup_server_arch('ppc64iseries-redhat-linux'), + lookup_sg_type('ansible_managed')); + +insert into rhnServerServerGroupArchCompat ( server_arch_id, server_group_type ) + values (lookup_server_arch('ppc64pseries-redhat-linux'), + lookup_sg_type('ansible_managed')); + +insert into rhnServerServerGroupArchCompat ( server_arch_id, server_group_type ) + values (lookup_server_arch('arm-debian-linux'), + lookup_sg_type('ansible_managed')); + +insert into rhnServerServerGroupArchCompat ( server_arch_id, server_group_type ) + values (lookup_server_arch('armv6l-debian-linux'), + lookup_sg_type('ansible_managed')); + +insert into rhnServerServerGroupArchCompat ( server_arch_id, server_group_type ) + values (lookup_server_arch('mips-debian-linux'), + lookup_sg_type('ansible_managed')); + commit; diff --git a/schema/spacewalk/common/tables/tables.deps b/schema/spacewalk/common/tables/tables.deps index 8f4be56be0bc..063c30cf7668 100644 --- a/schema/spacewalk/common/tables/tables.deps +++ b/schema/spacewalk/common/tables/tables.deps @@ -304,6 +304,8 @@ suseAppstreamPackage :: suseAppstream rhnPackage suseAppstreamApi :: suseAppstream rhnChannelNewestPackage :: suseAppstream rhnChannel rhnPackageName rhnPackageEVR \ rhnPackageArch +suseAnsibleInventoryServers :: suseAnsiblePath rhnServer +rhnActionInventory :: rhnAction endpoint :: schemas/access namespace :: schemas/access endpointNamespace :: schemas/access endpoint namespace diff --git a/schema/spacewalk/postgres/packages/rhn_entitlements.pkb b/schema/spacewalk/postgres/packages/rhn_entitlements.pkb index 5fb7741c6fa0..7435dafc1999 100644 --- a/schema/spacewalk/postgres/packages/rhn_entitlements.pkb +++ b/schema/spacewalk/postgres/packages/rhn_entitlements.pkb @@ -238,6 +238,7 @@ as $$ when 'monitoring_entitled' then 'Monitoring' when 'ansible_control_node' then 'Ansible' when 'peripheral_server' then 'Peripheral' + when 'ansible_managed' then 'Ansible Managed' end ); perform rhn_server.insert_into_servergroup (server_id_in, sgid); @@ -296,6 +297,7 @@ as $$ when 'osimage_build_host' then 'OS Image' when 'ansible_control_node' then 'Ansible' when 'peripheral_server' then 'Peripheral' + when 'ansible_managed' then 'Ansible Managed' end ); perform rhn_server.delete_from_servergroup(server_id_in, group_id); @@ -339,6 +341,7 @@ as $$ when 'osimage_build_host' then 'OS Image' when 'ansible_control_node' then 'Ansible' when 'peripheral_server' then 'Peripheral' + when 'ansible_managed' then 'Ansible Managed' end ); perform rhn_server.delete_from_servergroup(server_id_in, diff --git a/schema/spacewalk/postgres/procs/create_new_org.sql b/schema/spacewalk/postgres/procs/create_new_org.sql index 1563cb4b28c8..d899dd2b4b73 100644 --- a/schema/spacewalk/postgres/procs/create_new_org.sql +++ b/schema/spacewalk/postgres/procs/create_new_org.sql @@ -233,6 +233,13 @@ begin from rhnServerGroupType sgt where sgt.label = 'peripheral_server'; + insert into rhnServerGroup + ( id, name, description, group_type, org_id ) + select nextval('rhn_server_group_id_seq'), sgt.name, sgt.name, + sgt.id, new_org_id + from rhnServerGroupType sgt + where sgt.label = 'ansible_managed'; + insert into suseImageStore (id, label, uri, store_type_id, org_id) values ( nextval('suse_imgstore_id_seq'), diff --git a/schema/spacewalk/upgrade/susemanager-schema-5.1.3-to-susemanager-schema-5.1.4/500-ansible_managed_entitlement.sql b/schema/spacewalk/upgrade/susemanager-schema-5.1.3-to-susemanager-schema-5.1.4/500-ansible_managed_entitlement.sql new file mode 100644 index 000000000000..80de579f08f1 --- /dev/null +++ b/schema/spacewalk/upgrade/susemanager-schema-5.1.3-to-susemanager-schema-5.1.4/500-ansible_managed_entitlement.sql @@ -0,0 +1,482 @@ +-------------------------------------------------------------------------------- +-- rhnServerGroupType ---------------------------------------------------------- +-------------------------------------------------------------------------------- +INSERT INTO rhnServerGroupType( + id, + label, + name, + permanent, + is_base) +SELECT + sequence_nextval('rhn_servergroup_type_seq'), + 'ansible_managed', + 'Ansible Managed Servers', + 'N', + 'N' +WHERE NOT EXISTS ( + SELECT 1 + FROM rhnServerGroupType + WHERE label = 'ansible_managed' +); + + +-------------------------------------------------------------------------------- +-- rhnSGTypeBaseAddonCompat ---------------------------------------------------- +-------------------------------------------------------------------------------- +INSERT INTO rhnSGTypeBaseAddonCompat( + base_id, + addon_id) +SELECT + lookup_sg_type('salt_entitled'), + lookup_sg_type('ansible_managed') +WHERE NOT EXISTS ( + SELECT 1 + FROM rhnSGTypeBaseAddonCompat + WHERE base_id = lookup_sg_type('salt_entitled') + AND addon_id = lookup_sg_type('ansible_managed') +); + + +-------------------------------------------------------------------------------- +-- rhnServerServerGroupArchCompat ---------------------------------------------- +-------------------------------------------------------------------------------- +INSERT INTO rhnServerServerGroupArchCompat ( server_arch_id, server_group_type ) +SELECT + lookup_server_arch('i386-redhat-linux'), + lookup_sg_type('ansible_managed') +WHERE NOT EXISTS ( + SELECT 1 + FROM rhnServerServerGroupArchCompat + WHERE server_arch_id = lookup_server_arch('i386-redhat-linux') + AND server_group_type = lookup_sg_type('ansible_managed') +); + +INSERT INTO rhnServerServerGroupArchCompat ( server_arch_id, server_group_type ) +SELECT + lookup_server_arch('i386-debian-linux'), + lookup_sg_type('ansible_managed') +WHERE NOT EXISTS ( + SELECT 1 + FROM rhnServerServerGroupArchCompat + WHERE server_arch_id = lookup_server_arch('i386-debian-linux') + AND server_group_type = lookup_sg_type('ansible_managed') +); + +INSERT INTO rhnServerServerGroupArchCompat ( server_arch_id, server_group_type ) +SELECT + lookup_server_arch('i486-redhat-linux'), + lookup_sg_type('ansible_managed') +WHERE NOT EXISTS ( + SELECT 1 + FROM rhnServerServerGroupArchCompat + WHERE server_arch_id = lookup_server_arch('i486-redhat-linux') + AND server_group_type = lookup_sg_type('ansible_managed') +); + +INSERT INTO rhnServerServerGroupArchCompat ( server_arch_id, server_group_type ) +SELECT + lookup_server_arch('i586-redhat-linux'), + lookup_sg_type('ansible_managed') +WHERE NOT EXISTS ( + SELECT 1 + FROM rhnServerServerGroupArchCompat + WHERE server_arch_id = lookup_server_arch('i586-redhat-linux') + AND server_group_type = lookup_sg_type('ansible_managed') +); + +INSERT INTO rhnServerServerGroupArchCompat ( server_arch_id, server_group_type ) +SELECT + lookup_server_arch('i686-redhat-linux'), + lookup_sg_type('ansible_managed') +WHERE NOT EXISTS ( + SELECT 1 + FROM rhnServerServerGroupArchCompat + WHERE server_arch_id = lookup_server_arch('i686-redhat-linux') + AND server_group_type = lookup_sg_type('ansible_managed') +); + +INSERT INTO rhnServerServerGroupArchCompat ( server_arch_id, server_group_type ) +SELECT + lookup_server_arch('athlon-redhat-linux'), + lookup_sg_type('ansible_managed') +WHERE NOT EXISTS ( + SELECT 1 + FROM rhnServerServerGroupArchCompat + WHERE server_arch_id = lookup_server_arch('athlon-redhat-linux') + AND server_group_type = lookup_sg_type('ansible_managed') +); + +INSERT INTO rhnServerServerGroupArchCompat ( server_arch_id, server_group_type ) +SELECT + lookup_server_arch('alpha-redhat-linux'), + lookup_sg_type('ansible_managed') +WHERE NOT EXISTS ( + SELECT 1 + FROM rhnServerServerGroupArchCompat + WHERE server_arch_id = lookup_server_arch('alpha-redhat-linux') + AND server_group_type = lookup_sg_type('ansible_managed') +); + +INSERT INTO rhnServerServerGroupArchCompat ( server_arch_id, server_group_type ) +SELECT + lookup_server_arch('alpha-debian-linux'), + lookup_sg_type('ansible_managed') +WHERE NOT EXISTS ( + SELECT 1 + FROM rhnServerServerGroupArchCompat + WHERE server_arch_id = lookup_server_arch('alpha-debian-linux') + AND server_group_type = lookup_sg_type('ansible_managed') +); + +INSERT INTO rhnServerServerGroupArchCompat ( server_arch_id, server_group_type ) +SELECT + lookup_server_arch('alphaev6-redhat-linux'), + lookup_sg_type('ansible_managed') +WHERE NOT EXISTS ( + SELECT 1 + FROM rhnServerServerGroupArchCompat + WHERE server_arch_id = lookup_server_arch('alphaev6-redhat-linux') + AND server_group_type = lookup_sg_type('ansible_managed') +); + +INSERT INTO rhnServerServerGroupArchCompat ( server_arch_id, server_group_type ) +SELECT + lookup_server_arch('ia64-redhat-linux'), + lookup_sg_type('ansible_managed') +WHERE NOT EXISTS ( + SELECT 1 + FROM rhnServerServerGroupArchCompat + WHERE server_arch_id = lookup_server_arch('ia64-redhat-linux') + AND server_group_type = lookup_sg_type('ansible_managed') +); + +INSERT INTO rhnServerServerGroupArchCompat ( server_arch_id, server_group_type ) +SELECT + lookup_server_arch('ia64-debian-linux'), + lookup_sg_type('ansible_managed') +WHERE NOT EXISTS ( + SELECT 1 + FROM rhnServerServerGroupArchCompat + WHERE server_arch_id = lookup_server_arch('ia64-debian-linux') + AND server_group_type = lookup_sg_type('ansible_managed') +); + +INSERT INTO rhnServerServerGroupArchCompat ( server_arch_id, server_group_type ) +SELECT + lookup_server_arch('sparc-redhat-linux'), + lookup_sg_type('ansible_managed') +WHERE NOT EXISTS ( + SELECT 1 + FROM rhnServerServerGroupArchCompat + WHERE server_arch_id = lookup_server_arch('sparc-redhat-linux') + AND server_group_type = lookup_sg_type('ansible_managed') +); + +INSERT INTO rhnServerServerGroupArchCompat ( server_arch_id, server_group_type ) +SELECT + lookup_server_arch('sparc-debian-linux'), + lookup_sg_type('ansible_managed') +WHERE NOT EXISTS ( + SELECT 1 + FROM rhnServerServerGroupArchCompat + WHERE server_arch_id = lookup_server_arch('sparc-debian-linux') + AND server_group_type = lookup_sg_type('ansible_managed') +); + +INSERT INTO rhnServerServerGroupArchCompat ( server_arch_id, server_group_type ) +SELECT + lookup_server_arch('sparcv9-redhat-linux'), + lookup_sg_type('ansible_managed') +WHERE NOT EXISTS ( + SELECT 1 + FROM rhnServerServerGroupArchCompat + WHERE server_arch_id = lookup_server_arch('sparcv9-redhat-linux') + AND server_group_type = lookup_sg_type('ansible_managed') +); + +INSERT INTO rhnServerServerGroupArchCompat ( server_arch_id, server_group_type ) +SELECT + lookup_server_arch('sparc64-redhat-linux'), + lookup_sg_type('ansible_managed') +WHERE NOT EXISTS ( + SELECT 1 + FROM rhnServerServerGroupArchCompat + WHERE server_arch_id = lookup_server_arch('sparc64-redhat-linux') + AND server_group_type = lookup_sg_type('ansible_managed') +); + +INSERT INTO rhnServerServerGroupArchCompat ( server_arch_id, server_group_type ) +SELECT + lookup_server_arch('s390-redhat-linux'), + lookup_sg_type('ansible_managed') +WHERE NOT EXISTS ( + SELECT 1 + FROM rhnServerServerGroupArchCompat + WHERE server_arch_id = lookup_server_arch('s390-redhat-linux') + AND server_group_type = lookup_sg_type('ansible_managed') +); + +INSERT INTO rhnServerServerGroupArchCompat ( server_arch_id, server_group_type ) +SELECT + lookup_server_arch('aarch64-redhat-linux'), + lookup_sg_type('ansible_managed') +WHERE NOT EXISTS ( + SELECT 1 + FROM rhnServerServerGroupArchCompat + WHERE server_arch_id = lookup_server_arch('aarch64-redhat-linux') + AND server_group_type = lookup_sg_type('ansible_managed') +); + +INSERT INTO rhnServerServerGroupArchCompat ( server_arch_id, server_group_type ) +SELECT + lookup_server_arch('armv7l-redhat-linux'), + lookup_sg_type('ansible_managed') +WHERE NOT EXISTS ( + SELECT 1 + FROM rhnServerServerGroupArchCompat + WHERE server_arch_id = lookup_server_arch('armv7l-redhat-linux') + AND server_group_type = lookup_sg_type('ansible_managed') +); + +INSERT INTO rhnServerServerGroupArchCompat ( server_arch_id, server_group_type ) +SELECT + lookup_server_arch('armv5tejl-redhat-linux'), + lookup_sg_type('ansible_managed') +WHERE NOT EXISTS ( + SELECT 1 + FROM rhnServerServerGroupArchCompat + WHERE server_arch_id = lookup_server_arch('armv5tejl-redhat-linux') + AND server_group_type = lookup_sg_type('ansible_managed') +); + +INSERT INTO rhnServerServerGroupArchCompat ( server_arch_id, server_group_type ) +SELECT + lookup_server_arch('armv6l-redhat-linux'), + lookup_sg_type('ansible_managed') +WHERE NOT EXISTS ( + SELECT 1 + FROM rhnServerServerGroupArchCompat + WHERE server_arch_id = lookup_server_arch('armv6l-redhat-linux') + AND server_group_type = lookup_sg_type('ansible_managed') +); + +INSERT INTO rhnServerServerGroupArchCompat ( server_arch_id, server_group_type ) +SELECT + lookup_server_arch('armv6hl-redhat-linux'), + lookup_sg_type('ansible_managed') +WHERE NOT EXISTS ( + SELECT 1 + FROM rhnServerServerGroupArchCompat + WHERE server_arch_id = lookup_server_arch('armv6hl-redhat-linux') + AND server_group_type = lookup_sg_type('ansible_managed') +); + +INSERT INTO rhnServerServerGroupArchCompat ( server_arch_id, server_group_type ) +SELECT + lookup_server_arch('s390-debian-linux'), + lookup_sg_type('ansible_managed') +WHERE NOT EXISTS ( + SELECT 1 + FROM rhnServerServerGroupArchCompat + WHERE server_arch_id = lookup_server_arch('s390-debian-linux') + AND server_group_type = lookup_sg_type('ansible_managed') +); + +INSERT INTO rhnServerServerGroupArchCompat ( server_arch_id, server_group_type ) +SELECT + lookup_server_arch('s390x-redhat-linux'), + lookup_sg_type('ansible_managed') +WHERE NOT EXISTS ( + SELECT 1 + FROM rhnServerServerGroupArchCompat + WHERE server_arch_id = lookup_server_arch('s390x-redhat-linux') + AND server_group_type = lookup_sg_type('ansible_managed') +); + +INSERT INTO rhnServerServerGroupArchCompat ( server_arch_id, server_group_type ) +SELECT + lookup_server_arch('ppc-redhat-linux'), + lookup_sg_type('ansible_managed') +WHERE NOT EXISTS ( + SELECT 1 + FROM rhnServerServerGroupArchCompat + WHERE server_arch_id = lookup_server_arch('ppc-redhat-linux') + AND server_group_type = lookup_sg_type('ansible_managed') +); + +INSERT INTO rhnServerServerGroupArchCompat ( server_arch_id, server_group_type ) +SELECT + lookup_server_arch('powerpc-debian-linux'), + lookup_sg_type('ansible_managed') +WHERE NOT EXISTS ( + SELECT 1 + FROM rhnServerServerGroupArchCompat + WHERE server_arch_id = lookup_server_arch('powerpc-debian-linux') + AND server_group_type = lookup_sg_type('ansible_managed') +); + +INSERT INTO rhnServerServerGroupArchCompat ( server_arch_id, server_group_type ) +SELECT + lookup_server_arch('ppc64-redhat-linux'), + lookup_sg_type('ansible_managed') +WHERE NOT EXISTS ( + SELECT 1 + FROM rhnServerServerGroupArchCompat + WHERE server_arch_id = lookup_server_arch('ppc64-redhat-linux') + AND server_group_type = lookup_sg_type('ansible_managed') +); + +INSERT INTO rhnServerServerGroupArchCompat ( server_arch_id, server_group_type ) +SELECT + lookup_server_arch('ppc64le-redhat-linux'), + lookup_sg_type('ansible_managed') +WHERE NOT EXISTS ( + SELECT 1 + FROM rhnServerServerGroupArchCompat + WHERE server_arch_id = lookup_server_arch('ppc64le-redhat-linux') + AND server_group_type = lookup_sg_type('ansible_managed') +); + +INSERT INTO rhnServerServerGroupArchCompat ( server_arch_id, server_group_type ) +SELECT + lookup_server_arch('pSeries-redhat-linux'), + lookup_sg_type('ansible_managed') +WHERE NOT EXISTS ( + SELECT 1 + FROM rhnServerServerGroupArchCompat + WHERE server_arch_id = lookup_server_arch('pSeries-redhat-linux') + AND server_group_type = lookup_sg_type('ansible_managed') +); + +INSERT INTO rhnServerServerGroupArchCompat ( server_arch_id, server_group_type ) +SELECT + lookup_server_arch('iSeries-redhat-linux'), + lookup_sg_type('ansible_managed') +WHERE NOT EXISTS ( + SELECT 1 + FROM rhnServerServerGroupArchCompat + WHERE server_arch_id = lookup_server_arch('iSeries-redhat-linux') + AND server_group_type = lookup_sg_type('ansible_managed') +); + +INSERT INTO rhnServerServerGroupArchCompat ( server_arch_id, server_group_type ) +SELECT + lookup_server_arch('x86_64-redhat-linux'), + lookup_sg_type('ansible_managed') +WHERE NOT EXISTS ( + SELECT 1 + FROM rhnServerServerGroupArchCompat + WHERE server_arch_id = lookup_server_arch('x86_64-redhat-linux') + AND server_group_type = lookup_sg_type('ansible_managed') +); + +INSERT INTO rhnServerServerGroupArchCompat ( server_arch_id, server_group_type ) +SELECT + lookup_server_arch('ia32e-redhat-linux'), + lookup_sg_type('ansible_managed') +WHERE NOT EXISTS ( + SELECT 1 + FROM rhnServerServerGroupArchCompat + WHERE server_arch_id = lookup_server_arch('ia32e-redhat-linux') + AND server_group_type = lookup_sg_type('ansible_managed') +); + +INSERT INTO rhnServerServerGroupArchCompat ( server_arch_id, server_group_type ) +SELECT + lookup_server_arch('amd64-redhat-linux'), + lookup_sg_type('ansible_managed') +WHERE NOT EXISTS ( + SELECT 1 + FROM rhnServerServerGroupArchCompat + WHERE server_arch_id = lookup_server_arch('amd64-redhat-linux') + AND server_group_type = lookup_sg_type('ansible_managed') +); + +INSERT INTO rhnServerServerGroupArchCompat ( server_arch_id, server_group_type ) +SELECT + lookup_server_arch('amd64-debian-linux'), + lookup_sg_type('ansible_managed') +WHERE NOT EXISTS ( + SELECT 1 + FROM rhnServerServerGroupArchCompat + WHERE server_arch_id = lookup_server_arch('amd64-debian-linux') + AND server_group_type = lookup_sg_type('ansible_managed') +); + +INSERT INTO rhnServerServerGroupArchCompat ( server_arch_id, server_group_type ) +SELECT + lookup_server_arch('arm64-debian-linux'), + lookup_sg_type('ansible_managed') +WHERE NOT EXISTS ( + SELECT 1 + FROM rhnServerServerGroupArchCompat + WHERE server_arch_id = lookup_server_arch('arm64-debian-linux') + AND server_group_type = lookup_sg_type('ansible_managed') +); + +INSERT INTO rhnServerServerGroupArchCompat ( server_arch_id, server_group_type ) +SELECT + lookup_server_arch('ppc64iseries-redhat-linux'), + lookup_sg_type('ansible_managed') +WHERE NOT EXISTS ( + SELECT 1 + FROM rhnServerServerGroupArchCompat + WHERE server_arch_id = lookup_server_arch('ppc64iseries-redhat-linux') + AND server_group_type = lookup_sg_type('ansible_managed') +); + +INSERT INTO rhnServerServerGroupArchCompat ( server_arch_id, server_group_type ) +SELECT + lookup_server_arch('ppc64pseries-redhat-linux'), + lookup_sg_type('ansible_managed') +WHERE NOT EXISTS ( + SELECT 1 + FROM rhnServerServerGroupArchCompat + WHERE server_arch_id = lookup_server_arch('ppc64pseries-redhat-linux') + AND server_group_type = lookup_sg_type('ansible_managed') +); + +INSERT INTO rhnServerServerGroupArchCompat ( server_arch_id, server_group_type ) +SELECT + lookup_server_arch('arm-debian-linux'), + lookup_sg_type('ansible_managed') +WHERE NOT EXISTS ( + SELECT 1 + FROM rhnServerServerGroupArchCompat + WHERE server_arch_id = lookup_server_arch('arm-debian-linux') + AND server_group_type = lookup_sg_type('ansible_managed') +); + +INSERT INTO rhnServerServerGroupArchCompat ( server_arch_id, server_group_type ) +SELECT + lookup_server_arch('armv6l-debian-linux'), + lookup_sg_type('ansible_managed') +WHERE NOT EXISTS ( + SELECT 1 + FROM rhnServerServerGroupArchCompat + WHERE server_arch_id = lookup_server_arch('armv6l-debian-linux') + AND server_group_type = lookup_sg_type('ansible_managed') +); + +INSERT INTO rhnServerServerGroupArchCompat ( server_arch_id, server_group_type ) +SELECT + lookup_server_arch('mips-debian-linux'), + lookup_sg_type('ansible_managed') +WHERE NOT EXISTS ( + SELECT 1 + FROM rhnServerServerGroupArchCompat + WHERE server_arch_id = lookup_server_arch('mips-debian-linux') + AND server_group_type = lookup_sg_type('ansible_managed') +); + + +-------------------------------------------------------------------------------- +-- existing server groups update ----------------------------------------------- +-------------------------------------------------------------------------------- +INSERT INTO rhnServerGroup ( id, name, description, group_type, org_id ) +SELECT nextval('rhn_server_group_id_seq'), sgt.name, sgt.name, sgt.id, org.id +FROM rhnServerGroupType sgt, web_customer org +WHERE sgt.label = 'ansible_managed' AND org.id NOT IN ( + SELECT sg.org_id from rhnServerGroup sg + WHERE sg.name = 'Ansible Managed Servers' +); diff --git a/schema/spacewalk/upgrade/susemanager-schema-5.1.3-to-susemanager-schema-5.1.4/501-rhn_entitlements.pkb.sql b/schema/spacewalk/upgrade/susemanager-schema-5.1.3-to-susemanager-schema-5.1.4/501-rhn_entitlements.pkb.sql new file mode 100644 index 000000000000..738564710dcf --- /dev/null +++ b/schema/spacewalk/upgrade/susemanager-schema-5.1.3-to-susemanager-schema-5.1.4/501-rhn_entitlements.pkb.sql @@ -0,0 +1,385 @@ +-- +-- Copyright (c) 2008--2015 Red Hat, Inc. +-- +-- This software is licensed to you under the GNU General Public License, +-- version 2 (GPLv2). There is NO WARRANTY for this software, express or +-- implied, including the implied warranties of MERCHANTABILITY or FITNESS +-- FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 +-- along with this software; if not, see +-- http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. +-- +-- Red Hat trademarks are not licensed under GPLv2. No permission is +-- granted to use or replicate Red Hat trademarks that are incorporated +-- in this software or its documentation. +-- + +-- create schema rhn_entitlements; + +-- setup search_path so that these functions are created in appropriate schema. +update pg_settings set setting = 'rhn_entitlements,' || setting where name = 'search_path'; + + create or replace function find_compatible_sg ( + server_id_in in numeric, + type_label_in in varchar + ) + returns numeric +as $$ + declare + servergroups cursor for + select sg.id + from rhnServerGroupType sgt, + rhnServerGroup sg, + rhnServer s, + rhnServerServerGroupArchCompat ssgac + where s.id = server_id_in + and s.org_id = sg.org_id + and sgt.label = type_label_in + and sg.group_type = sgt.id + and ssgac.server_group_type = sgt.id + and ssgac.server_arch_id = s.server_arch_id + and not exists ( + select 1 + from rhnServerGroupMembers sgm + where sgm.server_group_id = sg.id + and sgm.server_id = s.id); + + + begin + for servergroup in servergroups loop + return servergroup.id; + end loop; + + --no servergroup found + return NULL; + end$$ +language plpgsql; + + + create or replace function entitlement_grants_service ( + entitlement_in in varchar, + service_level_in in varchar + ) returns numeric +as $$ + begin + if service_level_in = 'management' then + if entitlement_in = 'enterprise_entitled' or entitlement_in = 'salt_entitled' then + return 1; + else + return 0; + end if; + elsif service_level_in = 'updates' then + return 1; + else + return 0; + end if; + end$$ +language plpgsql; + + create or replace function can_entitle_server ( + server_id_in in numeric, + type_label_in in varchar + ) + returns numeric +as $$ + declare + addon_servergroups cursor (base_label_in varchar, + addon_label_in varchar) for + select + addon_id + from + rhnSGTypeBaseAddonCompat + where base_id = lookup_sg_type (base_label_in) + and addon_id = lookup_sg_type (addon_label_in); + + previous_ent varchar[]; + is_base_in char := 'N'; + is_base_current char := 'N'; + i numeric := 0; + sgid numeric := 0; + + begin + + previous_ent := rhn_entitlements.get_server_entitlement(server_id_in); + RAISE NOTICE 'can_entitle_server - % - % prev ents: %', server_id_in, type_label_in, previous_ent; + + select distinct is_base + into is_base_in + from rhnServerGroupType + where label = type_label_in; + + if array_upper(previous_ent, 1) is null or array_upper(previous_ent, 1) = 0 then + if is_base_in = 'Y' then + sgid := rhn_entitlements.find_compatible_sg (server_id_in, type_label_in); + if sgid is not null then + -- rhn_server.insert_into_servergroup (server_id_in, sgid); + return 1; + else + -- rhn_exception.raise_exception ('invalid_base_entitlement'); + RAISE NOTICE 'invalid_base_entitlement - no compatible server group'; + return 0; + end if; + else + -- rhn_exception.raise_exception ('invalid_base_entitlement'); + RAISE NOTICE 'invalid_base_entitlement - not a base entitlement'; + return 0; + end if; + + -- there are previous ents, first make sure we're not trying to entitle a base ent + elsif is_base_in = 'Y' then + -- rhn_exception.raise_exception ('invalid_addon_entitlement'); + RAISE NOTICE 'invalid_addon_entitlement - found another base'; + return 0; + + -- it must be an addon, so proceed with the entitlement + else + + -- find the servers base ent + is_base_current := 'N'; + i := 0; + while is_base_current = 'N' and i < array_upper(previous_ent, 1) + loop + i := i + 1; + select is_base + into is_base_current + from rhnServerGroupType + where label = previous_ent[i]; + end loop; + + -- never found a base ent, that would be strange + if is_base_current = 'N' then + -- rhn_exception.raise_exception ('invalid_base_entitlement'); + RAISE NOTICE 'invalid_base_entitlement - never found a base'; + return 0; + end if; + + -- this for loop verifies the validity of the addon path + for addon_servergroup in addon_servergroups (previous_ent[i], type_label_in) loop + -- find an appropriate sgid for the addon and entitle the server + sgid := rhn_entitlements.find_compatible_sg (server_id_in, type_label_in); + if sgid is not null then + -- rhn_server.insert_into_servergroup (server_id_in, sgid); + return 1; + else + -- rhn_exception.raise_exception ('invalid_addon_entitlement'); + RAISE NOTICE 'invalid_addon_entitlement - no server group found'; + return 0; + end if; + end loop; + + end if; + RAISE NOTICE 'final error'; + return 0; + + end$$ +language plpgsql; + + create or replace function can_switch_base ( + server_id_in in integer, + type_label_in in varchar + ) + returns numeric +as $$ + declare + type_label_in_is_base char(1); + sgid numeric; + + begin + + select is_base into type_label_in_is_base + from rhnServerGroupType + where label = type_label_in; + + if not found then + perform rhn_exception.raise_exception ( 'invalid_entitlement' ); + end if; + + if type_label_in_is_base = 'N' then + perform rhn_exception.raise_exception ( 'invalid_entitlement' ); + else + sgid := rhn_entitlements.find_compatible_sg ( server_id_in, + type_label_in ); + if sgid is not null then + return 1; + else + return 0; + end if; + end if; + + end$$ +language plpgsql; + + create or replace function entitle_server ( + server_id_in in numeric, + type_label_in in varchar + ) returns void +as $$ + declare + sgid numeric := 0; + + begin + + if rhn_entitlements.can_entitle_server(server_id_in, + type_label_in) = 1 then + sgid := rhn_entitlements.find_compatible_sg (server_id_in, + type_label_in); + if sgid is not null then + insert into rhnServerHistory ( id, server_id, summary, details ) + values ( nextval('rhn_event_id_seq'), server_id_in, + 'added system entitlement ', + case type_label_in + when 'enterprise_entitled' then 'Management' + when 'bootstrap_entitled' then 'Bootstrap' + when 'salt_entitled' then 'Salt' + when 'foreign_entitled' then 'Foreign' + when 'virtualization_host' then 'Virtualization' + when 'container_build_host' then 'Container' + when 'osimage_build_host' then 'OS Image' + when 'monitoring_entitled' then 'Monitoring' + when 'ansible_control_node' then 'Ansible' + when 'peripheral_server' then 'Peripheral' + when 'ansible_managed' then 'Ansible Managed' + end ); + + perform rhn_server.insert_into_servergroup (server_id_in, sgid); + + else + perform rhn_exception.raise_exception ('no_available_server_group'); + end if; + else + perform rhn_exception.raise_exception ('invalid_entitlement'); + end if; + end$$ +language plpgsql; + + create or replace function remove_server_entitlement ( + server_id_in in numeric, + type_label_in in varchar + ) returns void +as $$ + declare + group_id numeric; + type_is_base char; + begin + + select sg.id, sgt.is_base + into group_id, type_is_base + from rhnServerGroupType sgt, + rhnServerGroup sg, + rhnServerGroupMembers sgm, + rhnServer s + where s.id = server_id_in + and s.id = sgm.server_id + and sgm.server_group_id = sg.id + and sg.org_id = s.org_id + and sgt.label = type_label_in + and sgt.id = sg.group_type; + + if not found then + perform rhn_exception.raise_exception('invalid_server_group_member'); + end if; + + if ( type_is_base = 'Y' ) then + -- unentitle_server should handle everything, don't really need to do anything else special here + perform rhn_entitlements.unentitle_server ( server_id_in ); + else + + insert into rhnServerHistory ( id, server_id, summary, details ) + values ( nextval('rhn_event_id_seq'), server_id_in, + 'removed system entitlement ', + case type_label_in + when 'enterprise_entitled' then 'Management' + when 'bootstrap_entitled' then 'Bootstrap' + when 'salt_entitled' then 'Salt' + when 'foreign_entitled' then 'Foreign' + when 'virtualization_host' then 'Virtualization' + when 'container_build_host' then 'Container' + when 'osimage_build_host' then 'OS Image' + when 'ansible_control_node' then 'Ansible' + when 'peripheral_server' then 'Peripheral' + when 'ansible_managed' then 'Ansible Managed' + end ); + + perform rhn_server.delete_from_servergroup(server_id_in, group_id); + + end if; + + end$$ +language plpgsql; + + create or replace function unentitle_server ( + server_id_in in numeric + ) returns void +as $$ + declare + servergroups cursor for + select distinct sgt.label, sg.id server_group_id + from rhnServerGroupType sgt, + rhnServerGroup sg, + rhnServer s, + rhnServerGroupMembers sgm + where s.id = server_id_in + and s.org_id = sg.org_id + and sg.group_type = sgt.id + and sgm.server_group_id = sg.id + and sgm.server_id = s.id; + + begin + + for servergroup in servergroups loop + + insert into rhnServerHistory ( id, server_id, summary, details ) + values ( nextval('rhn_event_id_seq'), server_id_in, + 'removed system entitlement ', + case servergroup.label + when 'enterprise_entitled' then 'Management' + when 'bootstrap_entitled' then 'Bootstrap' + when 'salt_entitled' then 'Salt' + when 'foreign_entitled' then 'Foreign' + when 'virtualization_host' then 'Virtualization' + when 'container_build_host' then 'Container' + when 'osimage_build_host' then 'OS Image' + when 'ansible_control_node' then 'Ansible' + when 'peripheral_server' then 'Peripheral' + when 'ansible_managed' then 'Ansible Managed' + end ); + + perform rhn_server.delete_from_servergroup(server_id_in, + servergroup.server_group_id ); + end loop; + + end$$ +language plpgsql; + + + create or replace function get_server_entitlement ( + server_id_in in numeric + ) returns varchar[] +as $$ + declare + server_groups cursor for + select sgt.label + from rhnServerGroupType sgt, + rhnServerGroup sg, + rhnServerGroupMembers sgm + where 1=1 + and sgm.server_id = server_id_in + and sg.id = sgm.server_group_id + and sgt.id = sg.group_type; + + ent_array varchar[]; + + begin + + ent_array := '{}'; + + for sg in server_groups loop + ent_array := ent_array || sg.label; + end loop; + + return ent_array; + + end$$ +language plpgsql; + +-- restore the original setting +update pg_settings set setting = overlay( setting placing '' from 1 for (length('rhn_entitlements')+1) ) where name = 'search_path'; diff --git a/schema/spacewalk/upgrade/susemanager-schema-5.1.3-to-susemanager-schema-5.1.4/502-create_new_org.sql b/schema/spacewalk/upgrade/susemanager-schema-5.1.3-to-susemanager-schema-5.1.4/502-create_new_org.sql new file mode 100644 index 000000000000..fd9fd64e4ac5 --- /dev/null +++ b/schema/spacewalk/upgrade/susemanager-schema-5.1.3-to-susemanager-schema-5.1.4/502-create_new_org.sql @@ -0,0 +1,244 @@ +create or replace function create_new_org +( + name_in in varchar, + password_in in varchar + --org_id_out out number +) returns numeric +as +$$ +declare + ug_type numeric; + group_val numeric; + new_org_id numeric; + org_id_out numeric; +begin + + select nextval('web_customer_id_seq') into new_org_id from dual; + + insert into web_customer ( + id, name + ) values ( + new_org_id, name_in + ); + + select nextval('rhn_user_group_id_seq') into group_val from dual; + + select id + into ug_type + from rhnUserGroupType + where label = 'org_admin'; + + insert into rhnUserGroup ( + id, name, + description, + max_members, group_type, org_id + ) values ( + group_val, 'Organization Administrators', + 'Organization Administrators for Org ' || name_in, + NULL, ug_type, new_org_id + ); + + select nextval('rhn_user_group_id_seq') into group_val from dual; + + select id + into ug_type + from rhnUserGroupType + where label = 'system_group_admin'; + + insert into rhnUserGroup ( + id, name, + description, + max_members, group_type, org_id + ) values ( + group_val, 'System Group Administrators', + 'System Group Administrators for Org ' || name_in, + NULL, ug_type, new_org_id + ); + + + select nextval('rhn_user_group_id_seq') into group_val from dual; + + select id + into ug_type + from rhnUserGroupType + where label = 'activation_key_admin'; + + insert into rhnUserGroup ( + id, name, + description, + max_members, group_type, org_id + ) values ( + group_val, 'Activation Key Administrators', + 'Activation Key Administrators for Org ' || name_in, + NULL, ug_type, new_org_id + ); + + select nextval('rhn_user_group_id_seq') into group_val from dual; + + select id + into ug_type + from rhnUserGroupType + where label = 'channel_admin'; + + insert into rhnUserGroup ( + id, name, + description, + max_members, group_type, org_id + ) values ( + group_val, 'Channel Administrators', + 'Channel Administrators for Org ' || name_in, + NULL, ug_type, new_org_id + ); + + if new_org_id = 1 then + select nextval('rhn_user_group_id_seq') into group_val from dual; + + select id + into ug_type + from rhnUserGroupType + where label = 'satellite_admin'; + + insert into rhnUserGroup ( + id, name, + description, + max_members, group_type, org_id + ) values ( + group_val, 'SUSE Manager Administrators', + 'SUSE Manager Administrators for Org ' || name_in, + NULL, ug_type, new_org_id + ); + end if; + + select nextval('rhn_user_group_id_seq') into group_val from dual; + + select id + into ug_type + from rhnUserGroupType + where label = 'config_admin'; + + insert into rhnUserGroup ( + id, name, + description, + max_members, group_type, org_id + ) values ( + group_val, 'Configuration Administrators', + 'Configuration Administrators for Org ' || name_in, + NULL, ug_type, new_org_id + ); + + select nextval('rhn_user_group_id_seq') into group_val from dual; + + select id + into ug_type + from rhnUserGroupType + where label = 'image_admin'; + + insert into rhnUserGroup ( + id, name, + description, + max_members, group_type, org_id + ) values ( + group_val, 'Image Administrators', + 'Image Administrators for Org ' || name_in, + NULL, ug_type, new_org_id + ); + + select nextval('rhn_user_group_id_seq') into group_val from dual; + + -- there aren't any users yet, so we don't need to update + -- rhnUserServerPerms + + insert into rhnServerGroup + ( id, name, description, group_type, org_id ) + select nextval('rhn_server_group_id_seq'), sgt.name, sgt.name, + sgt.id, new_org_id + from rhnServerGroupType sgt + where sgt.label = 'bootstrap_entitled'; + + insert into rhnServerGroup + ( id, name, description, group_type, org_id ) + select nextval('rhn_server_group_id_seq'), sgt.name, sgt.name, + sgt.id, new_org_id + from rhnServerGroupType sgt + where sgt.label = 'enterprise_entitled'; + + insert into rhnServerGroup + ( id, name, description, group_type, org_id ) + select nextval('rhn_server_group_id_seq'), sgt.name, sgt.name, + sgt.id, new_org_id + from rhnServerGroupType sgt + where sgt.label = 'salt_entitled'; + + insert into rhnServerGroup + ( id, name, description, group_type, org_id ) + select nextval('rhn_server_group_id_seq'), sgt.name, sgt.name, + sgt.id, new_org_id + from rhnServerGroupType sgt + where sgt.label = 'foreign_entitled'; + + insert into rhnServerGroup + ( id, name, description, group_type, org_id ) + select nextval('rhn_server_group_id_seq'), sgt.name, sgt.name, + sgt.id, new_org_id + from rhnServerGroupType sgt + where sgt.label = 'virtualization_host'; + + insert into rhnServerGroup + ( id, name, description, group_type, org_id ) + select nextval('rhn_server_group_id_seq'), sgt.name, sgt.name, + sgt.id, new_org_id + from rhnServerGroupType sgt + where sgt.label = 'container_build_host'; + + insert into rhnServerGroup + ( id, name, description, group_type, org_id ) + select nextval('rhn_server_group_id_seq'), sgt.name, sgt.name, + sgt.id, new_org_id + from rhnServerGroupType sgt + where sgt.label = 'osimage_build_host'; + + insert into rhnServerGroup + ( id, name, description, group_type, org_id ) + select nextval('rhn_server_group_id_seq'), sgt.name, sgt.name, + sgt.id, new_org_id + from rhnServerGroupType sgt + where sgt.label = 'monitoring_entitled'; + + insert into rhnServerGroup + ( id, name, description, group_type, org_id ) + select nextval('rhn_server_group_id_seq'), sgt.name, sgt.name, + sgt.id, new_org_id + from rhnServerGroupType sgt + where sgt.label = 'ansible_control_node'; + + insert into rhnServerGroup + ( id, name, description, group_type, org_id ) + select nextval('rhn_server_group_id_seq'), sgt.name, sgt.name, + sgt.id, new_org_id + from rhnServerGroupType sgt + where sgt.label = 'peripheral_server'; + + insert into rhnServerGroup + ( id, name, description, group_type, org_id ) + select nextval('rhn_server_group_id_seq'), sgt.name, sgt.name, + sgt.id, new_org_id + from rhnServerGroupType sgt + where sgt.label = 'ansible_managed'; + + insert into suseImageStore (id, label, uri, store_type_id, org_id) + values ( + nextval('suse_imgstore_id_seq'), + 'SUSE Manager OS Image Store', + new_org_id || '/', + (SELECT id FROM suseImageStoreType WHERE label = 'os_image'), + new_org_id + ); + + org_id_out := new_org_id; + + -- Returning the value of OUT parameter + return org_id_out; + +end; +$$ +language plpgsql; From 78efa2b384d588db1bb33b763b36103c60d80d5c Mon Sep 17 00:00:00 2001 From: Pascal Arlt Date: Wed, 19 Feb 2025 17:34:11 +0100 Subject: [PATCH 10/20] Add ansible_managed entitlement java Signed-off-by: Pascal Arlt --- .../AnsibleManagedEntitlement.java | 51 +++++++++++++++++++ .../src/com/redhat/rhn/domain/org/Org.java | 3 ++ .../strings/jsp/StringResource_en_US.xml | 3 ++ .../entitlement/EntitlementManager.java | 7 +++ .../test/EntitlementManagerTest.java | 5 ++ java/code/webapp/WEB-INF/struts-config.xml | 1 + 6 files changed, 70 insertions(+) create mode 100644 java/code/src/com/redhat/rhn/domain/entitlement/AnsibleManagedEntitlement.java diff --git a/java/code/src/com/redhat/rhn/domain/entitlement/AnsibleManagedEntitlement.java b/java/code/src/com/redhat/rhn/domain/entitlement/AnsibleManagedEntitlement.java new file mode 100644 index 000000000000..35398ad7d66f --- /dev/null +++ b/java/code/src/com/redhat/rhn/domain/entitlement/AnsibleManagedEntitlement.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2025 SUSE LLC + * + * This software is licensed to you under the GNU General Public License, + * version 2 (GPLv2). There is NO WARRANTY for this software, express or + * implied, including the implied warranties of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 + * along with this software; if not, see + * http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. + * + * Red Hat trademarks are not licensed under GPLv2. No permission is + * granted to use or replicate Red Hat trademarks that are incorporated + * in this software or its documentation. + */ + +package com.redhat.rhn.domain.entitlement; + +import com.redhat.rhn.domain.server.Server; +import com.redhat.rhn.manager.entitlement.EntitlementManager; + +/** + * Ansible Control Node entitlement + */ +public class AnsibleManagedEntitlement extends Entitlement { + + /** + * Standard constructor + */ + public AnsibleManagedEntitlement() { + super(EntitlementManager.ANSIBLE_MANAGED_ENTITLED); + } + + /** + * Constructs an Entitlement labeled lbl. + * + * @param lbl Entitlement label. + */ + AnsibleManagedEntitlement(String lbl) { + super(lbl); + } + + @Override + public boolean isPermanent() { + return false; + } + + @Override + public boolean isBase() { + return false; + } +} diff --git a/java/code/src/com/redhat/rhn/domain/org/Org.java b/java/code/src/com/redhat/rhn/domain/org/Org.java index 8cf83aaa3c57..f066bb9ed53d 100644 --- a/java/code/src/com/redhat/rhn/domain/org/Org.java +++ b/java/code/src/com/redhat/rhn/domain/org/Org.java @@ -510,6 +510,9 @@ public Set getValidAddOnEntitlementsForOrg() { !Config.get().getBoolean(ConfigDefaults.KIWI_OS_IMAGE_BUILDING_ENABLED)) { continue; } + else if (EntitlementManager.ANSIBLE_MANAGED_ENTITLED.equals(ent.getLabel())) { + continue; + } addonEntitlements.add(ent); } } diff --git a/java/code/src/com/redhat/rhn/frontend/strings/jsp/StringResource_en_US.xml b/java/code/src/com/redhat/rhn/frontend/strings/jsp/StringResource_en_US.xml index e1a2addaa5ab..26c34de13724 100644 --- a/java/code/src/com/redhat/rhn/frontend/strings/jsp/StringResource_en_US.xml +++ b/java/code/src/com/redhat/rhn/frontend/strings/jsp/StringResource_en_US.xml @@ -25148,6 +25148,9 @@ given channel. Peripheral Server + + Ansible Managed + Formulas diff --git a/java/code/src/com/redhat/rhn/manager/entitlement/EntitlementManager.java b/java/code/src/com/redhat/rhn/manager/entitlement/EntitlementManager.java index 49662b19e2f4..1aa101a6313a 100644 --- a/java/code/src/com/redhat/rhn/manager/entitlement/EntitlementManager.java +++ b/java/code/src/com/redhat/rhn/manager/entitlement/EntitlementManager.java @@ -15,6 +15,7 @@ package com.redhat.rhn.manager.entitlement; import com.redhat.rhn.domain.entitlement.AnsibleControlNodeEntitlement; +import com.redhat.rhn.domain.entitlement.AnsibleManagedEntitlement; import com.redhat.rhn.domain.entitlement.BootstrapEntitlement; import com.redhat.rhn.domain.entitlement.ContainerBuildHostEntitlement; import com.redhat.rhn.domain.entitlement.Entitlement; @@ -54,6 +55,7 @@ public class EntitlementManager extends BaseManager { public static final Entitlement MONITORING = new MonitoringEntitlement(); public static final Entitlement ANSIBLE_CONTROL_NODE = new AnsibleControlNodeEntitlement(); public static final Entitlement PERIPHERAL_SERVER = new PeripheralServerEntitlement(); + public static final Entitlement ANSIBLE_MANAGED = new AnsibleManagedEntitlement(); public static final String UNENTITLED = "unentitled"; public static final String ENTERPRISE_ENTITLED = "enterprise_entitled"; @@ -66,6 +68,7 @@ public class EntitlementManager extends BaseManager { public static final String MONITORING_ENTITLED = "monitoring_entitled"; public static final String ANSIBLE_CONTROL_NODE_ENTITLED = "ansible_control_node"; public static final String PERIPHERAL_SERVER_ENTITLED = "peripheral_server"; + public static final String ANSIBLE_MANAGED_ENTITLED = "ansible_managed"; private static final Set ADDON_ENTITLEMENTS; private static final Set BASE_ENTITLEMENTS; @@ -77,6 +80,7 @@ public class EntitlementManager extends BaseManager { ADDON_ENTITLEMENTS.add(MONITORING); ADDON_ENTITLEMENTS.add(ANSIBLE_CONTROL_NODE); ADDON_ENTITLEMENTS.add(PERIPHERAL_SERVER); + ADDON_ENTITLEMENTS.add(ANSIBLE_MANAGED); BASE_ENTITLEMENTS = new LinkedHashSet<>(); BASE_ENTITLEMENTS.add(MANAGEMENT); @@ -121,6 +125,9 @@ else if (ANSIBLE_CONTROL_NODE_ENTITLED.equals(name)) { else if (PERIPHERAL_SERVER_ENTITLED.equals(name)) { return PERIPHERAL_SERVER; } + else if (ANSIBLE_MANAGED_ENTITLED.equals(name)) { + return ANSIBLE_MANAGED; + } LOG.debug("Unknown entitlement: {}", name); return null; } diff --git a/java/code/src/com/redhat/rhn/manager/entitlement/test/EntitlementManagerTest.java b/java/code/src/com/redhat/rhn/manager/entitlement/test/EntitlementManagerTest.java index a2b8d1bd6c34..d4ffe7f0e18d 100644 --- a/java/code/src/com/redhat/rhn/manager/entitlement/test/EntitlementManagerTest.java +++ b/java/code/src/com/redhat/rhn/manager/entitlement/test/EntitlementManagerTest.java @@ -62,5 +62,10 @@ public void testGetEntitlementByName() { EntitlementManager.ANSIBLE_CONTROL_NODE_ENTITLED); assertNotNull(ent); assertEquals(EntitlementManager.ANSIBLE_CONTROL_NODE, ent); + + ent = EntitlementManager.getByName( + EntitlementManager.ANSIBLE_MANAGED_ENTITLED); + assertNotNull(ent); + assertEquals(EntitlementManager.ANSIBLE_MANAGED, ent); } } diff --git a/java/code/webapp/WEB-INF/struts-config.xml b/java/code/webapp/WEB-INF/struts-config.xml index 859e562bfec7..ba55bb7680d9 100644 --- a/java/code/webapp/WEB-INF/struts-config.xml +++ b/java/code/webapp/WEB-INF/struts-config.xml @@ -901,6 +901,7 @@ + From 4067d5c55372fb0a65e16a2091944ee2205ba6b9 Mon Sep 17 00:00:00 2001 From: Pascal Arlt Date: Sat, 22 Feb 2025 14:02:50 +0100 Subject: [PATCH 11/20] Update ansible_managed entitlement on systems on inventory modify Signed-off-by: Pascal Arlt --- .../rhn/domain/server/AnsibleFactory.java | 15 +++++ .../rhn/manager/system/AnsibleManager.java | 48 ++++++++++++++++ .../src/com/suse/manager/utils/SaltUtils.java | 55 +++++++++---------- 3 files changed, 90 insertions(+), 28 deletions(-) diff --git a/java/code/src/com/redhat/rhn/domain/server/AnsibleFactory.java b/java/code/src/com/redhat/rhn/domain/server/AnsibleFactory.java index f3b85cecd354..17f35aec2846 100644 --- a/java/code/src/com/redhat/rhn/domain/server/AnsibleFactory.java +++ b/java/code/src/com/redhat/rhn/domain/server/AnsibleFactory.java @@ -123,6 +123,21 @@ public static List listAnsibleInventoryPaths(long minionId) { .list(); } + /** + * List all {@link Server}s linked to inventories excluding given {@link InventoryPath} + * + * @param path the inventory to exclude + * @return the list of inventory servers + */ + public static List listAnsibleInventoryServersExcludingPath(InventoryPath path) { + return HibernateFactory.getSession().createNativeQuery(""" + SELECT DISTINCT s.*, 0 as clazz_ FROM suseAnsibleInventoryServers ais + JOIN rhnServer s ON ais.server_id = s.id + WHERE ais.inventory_id != :inventory_id""", Server.class) + .setParameter("inventory_id", path.getId()) + .getResultList(); + } + /** * Save an {@link AnsiblePath} * diff --git a/java/code/src/com/redhat/rhn/manager/system/AnsibleManager.java b/java/code/src/com/redhat/rhn/manager/system/AnsibleManager.java index 6e41af53dc1d..213358ea16c4 100644 --- a/java/code/src/com/redhat/rhn/manager/system/AnsibleManager.java +++ b/java/code/src/com/redhat/rhn/manager/system/AnsibleManager.java @@ -34,6 +34,9 @@ import com.redhat.rhn.frontend.xmlrpc.UnsupportedOperationException; import com.redhat.rhn.manager.BaseManager; import com.redhat.rhn.manager.action.ActionChainManager; +import com.redhat.rhn.manager.action.ActionManager; +import com.redhat.rhn.manager.entitlement.EntitlementManager; +import com.redhat.rhn.manager.system.entitling.SystemEntitlementManager; import com.redhat.rhn.taskomatic.TaskomaticApiException; import com.suse.manager.webui.services.iface.SaltApi; @@ -47,6 +50,8 @@ import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import java.nio.file.InvalidPathException; import java.nio.file.Path; @@ -61,6 +66,7 @@ public class AnsibleManager extends BaseManager { + private static Logger log = LogManager.getLogger(AnsibleManager.class); private final SaltApi saltApi; /** @@ -456,6 +462,48 @@ public static List> generateBeacon(MinionServer minion) { return beacon; } + /** + * Handle add or remove ansible_managed entitlement from systems + * + * @param inventory the inventory + * @param systemsToAdd the systems to add + */ + public static void handleInventoryRefresh(InventoryPath inventory, Set systemsToAdd) { + Set systemsToRemove = inventory.getInventoryServers(); + systemsToRemove.removeAll(systemsToAdd); + + // Only remove entitlement from servers if they no longer appear in the list of ansible managed systems + List ansibleManagedSystems = AnsibleFactory.listAnsibleInventoryServersExcludingPath(inventory); + ansibleManagedSystems.removeIf(ansibleManagedSystems::contains); + + updateAnsibleManagedSystems(systemsToAdd, systemsToRemove); + + inventory.setInventoryServers(systemsToAdd); + AnsibleFactory.saveAnsiblePath(inventory); + } + + /** + * Handle add or remove ansible_managed entitlement from systems + * + * @param systemsToAdd the servers to add + * @param systemsToRemove the servers to remove + */ + public static void updateAnsibleManagedSystems(Set systemsToAdd, Set systemsToRemove) { + SystemEntitlementManager systemEntitlementManager = GlobalInstanceHolder.SYSTEM_ENTITLEMENT_MANAGER; + + // Add entitlement to servers + systemsToAdd.forEach(s -> { + if (!s.hasEntitlement(EntitlementManager.ANSIBLE_MANAGED) && + systemEntitlementManager.canEntitleServer(s, EntitlementManager.ANSIBLE_MANAGED)) { + systemEntitlementManager.addEntitlementToServer(s, EntitlementManager.ANSIBLE_MANAGED); + } + }); + // Remove entitlement from servers + systemsToRemove.forEach(s -> + systemEntitlementManager.removeServerEntitlement(s, EntitlementManager.ANSIBLE_MANAGED) + ); + } + private static MinionServer lookupAnsibleControlNode(long systemId, User user) { Server controlNode = SystemManager.lookupByIdAndUser(systemId, user); if (controlNode == null) { diff --git a/java/code/src/com/suse/manager/utils/SaltUtils.java b/java/code/src/com/suse/manager/utils/SaltUtils.java index 496ac9b6b5a2..da7574a37f37 100644 --- a/java/code/src/com/suse/manager/utils/SaltUtils.java +++ b/java/code/src/com/suse/manager/utils/SaltUtils.java @@ -21,6 +21,7 @@ import static com.suse.manager.webui.services.SaltConstants.SUMA_STATE_FILES_ROOT_PATH; import com.redhat.rhn.common.hibernate.HibernateFactory; +import com.redhat.rhn.common.hibernate.LookupException; import com.redhat.rhn.common.localization.LocalizationService; import com.redhat.rhn.common.messaging.MessageQueue; import com.redhat.rhn.domain.action.Action; @@ -718,12 +719,7 @@ else if (action.getActionType().equals(ActionFactory.TYPE_COCO_ATTESTATION)) { handleCocoAttestationResult(action, serverAction, jsonResult); } else if (action.getActionType().equals(ActionFactory.TYPE_INVENTORY)) { - if (serverAction.getStatus().equals(ActionFactory.STATUS_COMPLETED)) { handleInventoryRefresh(action, serverAction, jsonResult); - } - else { - serverAction.setResultMsg(getJsonResultWithPrettyPrint(jsonResult)); - } } else { serverAction.setResultMsg(getJsonResultWithPrettyPrint(jsonResult)); @@ -1900,34 +1896,37 @@ private static void handleHardwareProfileUpdate(MinionServer server, } private void handleInventoryRefresh(Action action, ServerAction serverAction, JsonElement jsonResult) { - try { - Set hostvars = AnsibleManager.parseInventoryAndGetHostnames( - Json.GSON.fromJson(jsonResult, Map.class)); - InventoryAction inventoryAction = (InventoryAction) action; - Optional inventory = AnsibleFactory.lookupAnsibleInventoryPath( - serverAction.getServerId(), inventoryAction.getDetails().getInventoryPath()); - - if (inventory.isPresent()) { - Set registeredServers = new HashSet<>(); - hostvars.forEach(serverName -> ServerFactory.findByFqdn(serverName).ifPresent(registeredServers::add)); - - inventory.get().setInventoryServers(registeredServers); - AnsibleFactory.saveAnsiblePath(inventory.get()); + String inventoryPath = ((InventoryAction) action).getDetails().getInventoryPath(); + if (serverAction.getStatus().equals(ActionFactory.STATUS_COMPLETED)) { + try { + Set inventorySystems = AnsibleManager.parseInventoryAndGetHostnames( + Json.GSON.fromJson(jsonResult, Map.class)); + + InventoryPath inventory = AnsibleFactory.lookupAnsibleInventoryPath( + serverAction.getServerId(), inventoryPath) + .orElseThrow(() -> new LookupException("Unable to find Ansible inventory: " + + inventoryPath + " for system " + serverAction.getServerId())); + + Set systemsToAdd = inventorySystems.stream().map(s -> ServerFactory.findByFqdn(s) + .orElse(null)).filter(Objects::nonNull).collect(Collectors.toSet()); + + AnsibleManager.handleInventoryRefresh(inventory, systemsToAdd); + serverAction.setResultMsg("Refreshed Ansible managed systems of inventory: '" + inventoryPath + "'"); } - else { - String message = String.format("Unable to find Ansible inventory: '%s' for system %s", - inventoryAction.getDetails().getInventoryPath(), - serverAction.getServerId()); - LOG.warn(message); + catch (JsonSyntaxException e) { + LOG.error("Unable to parse Ansible hostnames from json: {}", e.getMessage()); serverAction.setStatus(ActionFactory.STATUS_FAILED); - serverAction.setResultMsg(message); + serverAction.setResultMsg("Unable to parse hostnames from inventory: " + inventoryPath); + } + catch (LookupException e) { + LOG.error(e.getMessage()); + serverAction.setStatus(ActionFactory.STATUS_FAILED); + serverAction.setResultMsg(e.getMessage()); } } - catch (JsonSyntaxException e) { - LOG.warn("Unable to parse Ansible inventory from json: {}", e.getMessage()); - return; + else { + serverAction.setResultMsg(jsonResult.getAsString()); } - serverAction.setResultMsg("Successfully refreshed Ansible managed systems"); } private static PackageEvr parsePackageEvr(Optional epoch, String version, Optional release, From 5720a00d6a355614e18d49ebb5d4595cf9a33180 Mon Sep 17 00:00:00 2001 From: Pascal Arlt Date: Sat, 22 Feb 2025 14:04:08 +0100 Subject: [PATCH 12/20] Update inventory servers and entitlement on inventory create/update/remove Signed-off-by: Pascal Arlt --- .../rhn/manager/system/AnsibleManager.java | 49 +++++++++++++++---- .../src/com/suse/manager/utils/SaltUtils.java | 2 + .../minion/ansible/ansible-control-node.tsx | 4 +- 3 files changed, 43 insertions(+), 12 deletions(-) diff --git a/java/code/src/com/redhat/rhn/manager/system/AnsibleManager.java b/java/code/src/com/redhat/rhn/manager/system/AnsibleManager.java index 213358ea16c4..ba710f57d931 100644 --- a/java/code/src/com/redhat/rhn/manager/system/AnsibleManager.java +++ b/java/code/src/com/redhat/rhn/manager/system/AnsibleManager.java @@ -162,11 +162,19 @@ public static AnsiblePath createAnsiblePath(String typeLabel, long minionServerI ansiblePath.setMinionServer(minionServer); ansiblePath.setPath(Path.of(path)); - ansiblePath = AnsibleFactory.saveAnsiblePath(ansiblePath); - // Refresh inotify beacon if a new inventory was added if (type == AnsiblePath.Type.INVENTORY) { + // Schedule inventory refresh + try { + ActionManager.scheduleInventoryRefresh(ansiblePath.getMinionServer(), ansiblePath.getPath().toString()); + } + catch (TaskomaticApiException e) { + log.error("Could not schedule Ansible inventory refresh for minion: {}", + ansiblePath.getMinionServer().getMinionId(), e); + } + + // Refresh inotify beacon MinionPillarManager.INSTANCE.generatePillar(minionServer, false, MinionPillarManager.PillarSubset.GENERAL); GlobalInstanceHolder.SALT_API.refreshPillar(new MinionList(minionServer.getMinionId())); @@ -188,17 +196,33 @@ public static AnsiblePath createAnsiblePath(String typeLabel, long minionServerI public static AnsiblePath updateAnsiblePath(long existingPathId, String newPath, User user) { AnsiblePath existing = lookupAnsiblePathById(existingPathId, user) .orElseThrow(() -> new LookupException("Ansible path id " + existingPathId + " not found.")); + if (existing.getPath().toString().equals(newPath)) { + // nothing to update + return existing; + } validateAnsiblePath(newPath, empty(), of(existingPathId), existing.getMinionServer().getId()); existing.setPath(Path.of(newPath)); - existing = AnsibleFactory.saveAnsiblePath(existing); - - // Refresh inotify beacon if the updated path is an inventory if (existing.getEntityType() == AnsiblePath.Type.INVENTORY) { + // Remove ansible managed systems from changed inventory and schedule inventory refresh + try { + handleInventoryRefresh((InventoryPath) existing, new HashSet<>()); + AnsibleFactory.saveAnsiblePath(existing); + ActionManager.scheduleInventoryRefresh(existing.getMinionServer(), existing.getPath().toString()); + } + catch (TaskomaticApiException e) { + log.error("Could not schedule Ansible inventory refresh for minion: {}", + existing.getMinionServer().getMinionId(), e); + } + + // Refresh inotify beacon MinionPillarManager.INSTANCE.generatePillar(existing.getMinionServer(), false, MinionPillarManager.PillarSubset.GENERAL); GlobalInstanceHolder.SALT_API.refreshPillar(new MinionList(existing.getMinionServer().getMinionId())); } + else { + AnsibleFactory.saveAnsiblePath(existing); + } return existing; } @@ -262,14 +286,20 @@ public static void removeAnsiblePath(long pathId, User user) { AnsiblePath path = lookupAnsiblePathById(pathId, user) .orElseThrow(() -> new LookupException("Ansible path id " + pathId + " not found.")); - AnsibleFactory.removeAnsiblePath(path); - - // Refresh inotify beacon if the removed path was an inventory if (path.getEntityType() == AnsiblePath.Type.INVENTORY) { + // Remove entitlement from managed servers + handleInventoryRefresh((InventoryPath) path, new HashSet<>()); + AnsibleFactory.removeAnsiblePath(path); + + // Refresh inotify beacon MinionPillarManager.INSTANCE.generatePillar(path.getMinionServer(), false, MinionPillarManager.PillarSubset.GENERAL); GlobalInstanceHolder.SALT_API.refreshPillar(new MinionList(path.getMinionServer().getMinionId())); } + else { + AnsibleFactory.removeAnsiblePath(path); + } + } /** @@ -474,12 +504,11 @@ public static void handleInventoryRefresh(InventoryPath inventory, Set s // Only remove entitlement from servers if they no longer appear in the list of ansible managed systems List ansibleManagedSystems = AnsibleFactory.listAnsibleInventoryServersExcludingPath(inventory); - ansibleManagedSystems.removeIf(ansibleManagedSystems::contains); + systemsToRemove.removeIf(ansibleManagedSystems::contains); updateAnsibleManagedSystems(systemsToAdd, systemsToRemove); inventory.setInventoryServers(systemsToAdd); - AnsibleFactory.saveAnsiblePath(inventory); } /** diff --git a/java/code/src/com/suse/manager/utils/SaltUtils.java b/java/code/src/com/suse/manager/utils/SaltUtils.java index da7574a37f37..c7d45fc2d986 100644 --- a/java/code/src/com/suse/manager/utils/SaltUtils.java +++ b/java/code/src/com/suse/manager/utils/SaltUtils.java @@ -1911,6 +1911,8 @@ private void handleInventoryRefresh(Action action, ServerAction serverAction, Js .orElse(null)).filter(Objects::nonNull).collect(Collectors.toSet()); AnsibleManager.handleInventoryRefresh(inventory, systemsToAdd); + AnsibleFactory.saveAnsiblePath(inventory); + serverAction.setResultMsg("Refreshed Ansible managed systems of inventory: '" + inventoryPath + "'"); } catch (JsonSyntaxException e) { diff --git a/web/html/src/manager/minion/ansible/ansible-control-node.tsx b/web/html/src/manager/minion/ansible/ansible-control-node.tsx index cffd342bbaa5..d95d2167b7b1 100644 --- a/web/html/src/manager/minion/ansible/ansible-control-node.tsx +++ b/web/html/src/manager/minion/ansible/ansible-control-node.tsx @@ -98,7 +98,7 @@ export class AnsibleControlNode extends React.Component { Network.post("/rhn/manager/api/systems/details/ansible/paths/save", { minionServerId: editPath?.minionServerId, type: editPath?.type, - path: editPath?.path, + path: editPath?.path?.trim(), id: editPath?.id, }).then((blob) => { if (blob.success) { @@ -130,7 +130,7 @@ export class AnsibleControlNode extends React.Component { Network.post("/rhn/manager/api/systems/details/ansible/paths/save", { minionServerId: this.state.minionServerId, type: type, - path: newPath, + path: newPath?.trim(), }).then((blob) => { if (blob.success) { const newAnsiblePath = { From ea718605a6f3ec8df10c0a44f30d37269a650df1 Mon Sep 17 00:00:00 2001 From: Pascal Arlt Date: Tue, 25 Feb 2025 10:17:23 +0100 Subject: [PATCH 13/20] Handle ansible managed systems on remove control node and system delete Signed-off-by: Pascal Arlt --- .../rhn/domain/server/AnsibleFactory.java | 32 +++++++++++++++++++ .../rhn/manager/system/AnsibleManager.java | 23 +++++++++++++ .../rhn/manager/system/SystemManager.java | 13 ++++++++ .../system/entitling/SystemUnentitler.java | 4 +-- 4 files changed, 70 insertions(+), 2 deletions(-) diff --git a/java/code/src/com/redhat/rhn/domain/server/AnsibleFactory.java b/java/code/src/com/redhat/rhn/domain/server/AnsibleFactory.java index 17f35aec2846..61221e6e510c 100644 --- a/java/code/src/com/redhat/rhn/domain/server/AnsibleFactory.java +++ b/java/code/src/com/redhat/rhn/domain/server/AnsibleFactory.java @@ -123,6 +123,22 @@ public static List listAnsibleInventoryPaths(long minionId) { .list(); } + /** + * List all ansible managed {@link Server}s linked to given {@link Server} + * + * @param minionId the id of the contorl node + * @return the list of inventory servers + */ + public static List listAnsibleInventoryServersByControlNode(long minionId) { + return HibernateFactory.getSession().createNativeQuery(""" + SELECT DISTINCT s.*, 0 as clazz_ FROM suseAnsiblePath ap + JOIN suseAnsibleInventoryServers ais ON ap.id = ais.inventory_id + JOIN rhnServer s ON ais.server_id = s.id + WHERE ap.server_id = :server_id""", Server.class) + .setParameter("server_id", minionId) + .getResultList(); + } + /** * List all {@link Server}s linked to inventories excluding given {@link InventoryPath} * @@ -138,6 +154,22 @@ public static List listAnsibleInventoryServersExcludingPath(InventoryPat .getResultList(); } + /** + * List all {@link Server}s linked to inventories from control nodes excluding given {@link MinionServer} + * + * @param minionId the id of the control node to exclude + * @return the list of inventory servers + */ + public static List listAnsibleInventoryServersExcludingControlNode(long minionId) { + return HibernateFactory.getSession().createNativeQuery(""" + SELECT DISTINCT s.*, 0 as clazz_ FROM suseAnsiblePath ap + JOIN suseAnsibleInventoryServers ais ON ap.id = ais.inventory_id + JOIN rhnServer s ON ais.server_id = s.id + WHERE ap.server_id != :server_id""", Server.class) + .setParameter("server_id", minionId) + .getResultList(); + } + /** * Save an {@link AnsiblePath} * diff --git a/java/code/src/com/redhat/rhn/manager/system/AnsibleManager.java b/java/code/src/com/redhat/rhn/manager/system/AnsibleManager.java index ba710f57d931..16db16c31f41 100644 --- a/java/code/src/com/redhat/rhn/manager/system/AnsibleManager.java +++ b/java/code/src/com/redhat/rhn/manager/system/AnsibleManager.java @@ -299,7 +299,30 @@ public static void removeAnsiblePath(long pathId, User user) { else { AnsibleFactory.removeAnsiblePath(path); } + } + /** + * Remove all ansible paths for given minion server + * + * @param minionServer the minion server + */ + public static void removeAnsiblePaths(MinionServer minionServer) { + List paths = AnsibleFactory.listAnsiblePaths(minionServer.getId()); + Set systemsToRemove = new HashSet<>(); + paths.forEach(p -> { + if (p.getEntityType() == AnsiblePath.Type.INVENTORY) { + systemsToRemove.addAll(((InventoryPath) p).getInventoryServers()); + } + AnsibleFactory.removeAnsiblePath(p); + }); + if (!systemsToRemove.isEmpty()) { + List ansibleManagedSystems = AnsibleFactory.listAnsibleInventoryServersExcludingControlNode( + minionServer.getId()); + systemsToRemove.removeIf(ansibleManagedSystems::contains); + updateAnsibleManagedSystems(new HashSet<>(), systemsToRemove); + } + MinionPillarManager.INSTANCE.generatePillar(minionServer, false, MinionPillarManager.PillarSubset.GENERAL); + GlobalInstanceHolder.SALT_API.refreshPillar(new MinionList(minionServer.getMinionId())); } /** diff --git a/java/code/src/com/redhat/rhn/manager/system/SystemManager.java b/java/code/src/com/redhat/rhn/manager/system/SystemManager.java index da0d60d4b974..bc67fcafa3a3 100644 --- a/java/code/src/com/redhat/rhn/manager/system/SystemManager.java +++ b/java/code/src/com/redhat/rhn/manager/system/SystemManager.java @@ -57,6 +57,7 @@ import com.redhat.rhn.domain.rhnpackage.PackageFactory; import com.redhat.rhn.domain.rhnpackage.PackageName; import com.redhat.rhn.domain.role.RoleFactory; +import com.redhat.rhn.domain.server.AnsibleFactory; import com.redhat.rhn.domain.server.CPU; import com.redhat.rhn.domain.server.MgrServerInfo; import com.redhat.rhn.domain.server.MinionServer; @@ -720,6 +721,18 @@ public void deleteServer(User user, Long sid, boolean deleteSaltKey) { CobblerSystemRemoveCommand rc = new CobblerSystemRemoveCommand(user, server); rc.store(); + // remove associated Ansible managed systems + if (server.hasEntitlement(EntitlementManager.ANSIBLE_CONTROL_NODE)) { + List managedSystemsToRemove = AnsibleFactory.listAnsibleInventoryServersByControlNode( + server.getId()); + if (!managedSystemsToRemove.isEmpty()) { + List ansibleManagedServers = AnsibleFactory.listAnsibleInventoryServersExcludingControlNode( + server.getId()); + managedSystemsToRemove.removeAll(ansibleManagedServers); + AnsibleManager.updateAnsibleManagedSystems(new HashSet<>(), new HashSet<>(managedSystemsToRemove)); + } + } + // remove associated VirtualInstances Set toRemove = new HashSet<>(); if (server.isVirtualGuest()) { diff --git a/java/code/src/com/redhat/rhn/manager/system/entitling/SystemUnentitler.java b/java/code/src/com/redhat/rhn/manager/system/entitling/SystemUnentitler.java index 59c9af4a7c91..dcbc84c8b560 100644 --- a/java/code/src/com/redhat/rhn/manager/system/entitling/SystemUnentitler.java +++ b/java/code/src/com/redhat/rhn/manager/system/entitling/SystemUnentitler.java @@ -21,10 +21,10 @@ import com.redhat.rhn.domain.server.Server; import com.redhat.rhn.domain.server.ServerFactory; import com.redhat.rhn.manager.entitlement.EntitlementManager; +import com.redhat.rhn.manager.system.AnsibleManager; import com.redhat.rhn.manager.system.ServerGroupManager; import com.suse.manager.webui.services.iface.MonitoringManager; -import com.suse.manager.webui.services.pillar.MinionPillarManager; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -85,7 +85,7 @@ public void removeServerEntitlement(Server server, Entitlement ent) { server.asMinionServer().ifPresent(s -> { if (EntitlementManager.ANSIBLE_CONTROL_NODE.equals(ent)) { - MinionPillarManager.INSTANCE.generatePillar(s, false, MinionPillarManager.PillarSubset.GENERAL); + AnsibleManager.removeAnsiblePaths(s); } serverGroupManager.updatePillarAfterGroupUpdateForServers(Arrays.asList(s)); if (EntitlementManager.MONITORING.equals(ent)) { From d8e6ac1255634900675f83d870e3d026f601597d Mon Sep 17 00:00:00 2001 From: Pascal Arlt Date: Wed, 26 Feb 2025 11:07:53 +0100 Subject: [PATCH 14/20] Allow filtering by ansible managed systems in the system list Signed-off-by: Pascal Arlt --- web/html/src/manager/systems/list-filter.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/web/html/src/manager/systems/list-filter.tsx b/web/html/src/manager/systems/list-filter.tsx index d30e6866dddb..915633c9907a 100644 --- a/web/html/src/manager/systems/list-filter.tsx +++ b/web/html/src/manager/systems/list-filter.tsx @@ -10,6 +10,7 @@ const SYSTEM_KIND_OPTIONS = [ const SYSTEM_TYPE_OPTIONS = [ { value: "ansible_control_node", label: t("Ansible Control Node") }, + { value: "ansible_managed", label: t("Ansible Managed") }, { value: "bootstrap_entitled", label: t("Bootstrap") }, { value: "container_build_host", label: t("Container Build Host") }, { value: "foreign_entitled", label: t("Foreign") }, From 0a3403af857f77ffc1b3fd39abacde7b102b25f6 Mon Sep 17 00:00:00 2001 From: Pascal Arlt Date: Tue, 25 Feb 2025 10:18:15 +0100 Subject: [PATCH 15/20] Create default paths on add control node Signed-off-by: Pascal Arlt --- .../rhn/manager/system/AnsibleManager.java | 39 ++++++++++++++++++- .../system/entitling/SystemEntitler.java | 4 +- 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/java/code/src/com/redhat/rhn/manager/system/AnsibleManager.java b/java/code/src/com/redhat/rhn/manager/system/AnsibleManager.java index 16db16c31f41..29cd4afdc287 100644 --- a/java/code/src/com/redhat/rhn/manager/system/AnsibleManager.java +++ b/java/code/src/com/redhat/rhn/manager/system/AnsibleManager.java @@ -144,8 +144,21 @@ public static List listAnsibleInventoryPaths(long minionId, User */ public static AnsiblePath createAnsiblePath(String typeLabel, long minionServerId, String path, User user) { MinionServer minionServer = lookupAnsibleControlNode(minionServerId, user); + return createAnsiblePath(typeLabel, minionServer, path); + } - validateAnsiblePath(path, of(typeLabel), empty(), minionServerId); + /** + * Create and save a new ansible path + * + * @param typeLabel the type label + * @param minionServer the minion server + * @param path the path + * @return the created and saved AnsiblePath + * @throws LookupException if the user does not have permissions or server not found + * @throws ValidatorException if the validation fails + */ + public static AnsiblePath createAnsiblePath(String typeLabel, MinionServer minionServer, String path) { + validateAnsiblePath(path, of(typeLabel), empty(), minionServer.getId()); AnsiblePath ansiblePath; AnsiblePath.Type type = AnsiblePath.Type.fromLabel(typeLabel); @@ -556,6 +569,30 @@ public static void updateAnsibleManagedSystems(Set systemsToAdd, Set { if (EntitlementManager.ANSIBLE_CONTROL_NODE.equals(ent)) { - MinionPillarManager.INSTANCE.generatePillar(minion, false, MinionPillarManager.PillarSubset.GENERAL); + AnsibleManager.createDefaultPaths(minion); } serverGroupManager.updatePillarAfterGroupUpdateForServers(Arrays.asList(minion)); From 957d5973f46a6d38b0487793980ac0753ac07441 Mon Sep 17 00:00:00 2001 From: Pascal Arlt Date: Tue, 25 Feb 2025 15:35:34 +0100 Subject: [PATCH 16/20] Add missing schema migration files Signed-off-by: Pascal Arlt --- ...503-create-suseAnsibleInventoryServers.sql | 31 +++++++++++++++++++ .../504-create-rhnActionInventory.sql | 31 +++++++++++++++++++ .../505-insert-action-ansible-inventory.sql | 14 +++++++++ 3 files changed, 76 insertions(+) create mode 100644 schema/spacewalk/upgrade/susemanager-schema-5.1.3-to-susemanager-schema-5.1.4/503-create-suseAnsibleInventoryServers.sql create mode 100644 schema/spacewalk/upgrade/susemanager-schema-5.1.3-to-susemanager-schema-5.1.4/504-create-rhnActionInventory.sql create mode 100644 schema/spacewalk/upgrade/susemanager-schema-5.1.3-to-susemanager-schema-5.1.4/505-insert-action-ansible-inventory.sql diff --git a/schema/spacewalk/upgrade/susemanager-schema-5.1.3-to-susemanager-schema-5.1.4/503-create-suseAnsibleInventoryServers.sql b/schema/spacewalk/upgrade/susemanager-schema-5.1.3-to-susemanager-schema-5.1.4/503-create-suseAnsibleInventoryServers.sql new file mode 100644 index 000000000000..9636fd098aa4 --- /dev/null +++ b/schema/spacewalk/upgrade/susemanager-schema-5.1.3-to-susemanager-schema-5.1.4/503-create-suseAnsibleInventoryServers.sql @@ -0,0 +1,31 @@ +-- +-- Copyright (c) 2025 SUSE LLC +-- +-- This software is licensed to you under the GNU General Public License, +-- version 2 (GPLv2). There is NO WARRANTY for this software, express or +-- implied, including the implied warranties of MERCHANTABILITY or FITNESS +-- FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 +-- along with this software; if not, see +-- http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. +-- +CREATE TABLE IF NOT EXISTS suseAnsibleInventoryServers( + + inventory_id NUMERIC NOT NULL + CONSTRAINT suse_ansible_inventory_id_fk + REFERENCES suseAnsiblePath(id) + ON DELETE CASCADE, + + server_id NUMERIC NOT NULL + CONSTRAINT suse_ansible_inventory_sid_fk + REFERENCES rhnServer(id) + ON DELETE CASCADE, + + created TIMESTAMPTZ + DEFAULT (current_timestamp) NOT NULL, + + modified TIMESTAMPTZ + DEFAULT (current_timestamp) NOT NULL +); + +CREATE UNIQUE INDEX IF NOT EXISTS suse_ansible_inventory_server_uq + ON suseAnsibleInventoryServers(inventory_id, server_id); diff --git a/schema/spacewalk/upgrade/susemanager-schema-5.1.3-to-susemanager-schema-5.1.4/504-create-rhnActionInventory.sql b/schema/spacewalk/upgrade/susemanager-schema-5.1.3-to-susemanager-schema-5.1.4/504-create-rhnActionInventory.sql new file mode 100644 index 000000000000..257b9cc608c1 --- /dev/null +++ b/schema/spacewalk/upgrade/susemanager-schema-5.1.3-to-susemanager-schema-5.1.4/504-create-rhnActionInventory.sql @@ -0,0 +1,31 @@ +-- +-- Copyright (c) 2025 SUSE LLC +-- +-- This software is licensed to you under the GNU General Public License, +-- version 2 (GPLv2). There is NO WARRANTY for this software, express or +-- implied, including the implied warranties of MERCHANTABILITY or FITNESS +-- FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 +-- along with this software; if not, see +-- http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. +-- +CREATE TABLE IF NOT EXISTS rhnActionInventory +( + id NUMERIC NOT NULL + CONSTRAINT rhn_action_inventory_id_pk + PRIMARY KEY, + action_id NUMERIC NOT NULL + CONSTRAINT rhn_action_inventory_aid_fk + REFERENCES rhnAction (id) + ON DELETE CASCADE, + inventory_path VARCHAR(1024), + created TIMESTAMPTZ + DEFAULT (current_timestamp) NOT NULL, + modified TIMESTAMPTZ + DEFAULT (current_timestamp) NOT NULL +) +; + +CREATE UNIQUE INDEX IF NOT EXISTS rhn_act_inventory_aid_uq + ON rhnActionInventory (action_id); + +CREATE SEQUENCE IF NOT EXISTS rhn_act_inventory_id_seq; diff --git a/schema/spacewalk/upgrade/susemanager-schema-5.1.3-to-susemanager-schema-5.1.4/505-insert-action-ansible-inventory.sql b/schema/spacewalk/upgrade/susemanager-schema-5.1.3-to-susemanager-schema-5.1.4/505-insert-action-ansible-inventory.sql new file mode 100644 index 000000000000..815a9abf39a6 --- /dev/null +++ b/schema/spacewalk/upgrade/susemanager-schema-5.1.3-to-susemanager-schema-5.1.4/505-insert-action-ansible-inventory.sql @@ -0,0 +1,14 @@ +-- +-- Copyright (c) 2025 SUSE LLC +-- +-- This software is licensed to you under the GNU General Public License, +-- version 2 (GPLv2). There is NO WARRANTY for this software, express or +-- implied, including the implied warranties of MERCHANTABILITY or FITNESS +-- FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 +-- along with this software; if not, see +-- http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. +-- +INSERT INTO rhnActionType + SELECT 525, 'ansible.inventory', 'Refresh Ansible inventories', 'N', 'N', 'N' + WHERE NOT EXISTS (SELECT 1 FROM rhnActionType WHERE id = 525); + From c8658e3a68532358f1526a36e06fdfece6d7b9e5 Mon Sep 17 00:00:00 2001 From: Pascal Arlt Date: Tue, 25 Feb 2025 18:05:05 +0100 Subject: [PATCH 17/20] Refactor System(Un)Entitler constructor to only use SaltApi Signed-off-by: Pascal Arlt --- .../com/redhat/rhn/GlobalInstanceHolder.java | 7 +--- .../common/security/acl/test/AccessTest.java | 8 +--- .../AnsibleManagedEntitlement.java | 1 - .../test/BaseEntitlementTestCase.java | 8 +--- .../ContainerBuildHostEntitlementTest.java | 8 +--- .../test/OSImageBuildHostEntitlementTest.java | 8 +--- .../test/PeripheralServerEntitlementTest.java | 8 +--- .../test/VirtualizationEntitlementTest.java | 8 +--- .../image/test/ImageInfoFactoryTest.java | 8 +--- .../domain/server/test/ServerFactoryTest.java | 6 +-- .../rhn/domain/server/test/ServerTest.java | 8 +--- .../test/VirtualInstanceFactoryTest.java | 8 +--- .../SystemEntitlementsSetupActionTest.java | 8 +--- .../SystemEntitlementsSubmitActionTest.java | 8 +--- .../sdc/test/SystemDetailsEditActionTest.java | 8 +--- .../sdc/test/SystemOverviewActionTest.java | 8 +--- .../test/AdminConfigurationHandlerTest.java | 6 +-- .../ansible/test/AnsibleHandlerTest.java | 8 +--- .../test/ChannelSoftwareHandlerTest.java | 8 +--- .../image/test/ImageInfoHandlerTest.java | 8 +--- .../test/SystemHandlerProvisioningTest.java | 6 +-- .../system/test/SystemHandlerPtfTest.java | 7 +--- .../xmlrpc/system/test/SystemHandlerTest.java | 6 +-- .../action/test/ActionManagerTest.java | 8 +--- .../action/test/MinionActionManagerTest.java | 6 +-- .../org/test/MigrationManagerTest.java | 6 +-- .../rhn/manager/system/SystemManager.java | 7 +--- .../system/entitling/SystemEntitler.java | 12 +++--- .../system/entitling/SystemUnentitler.java | 14 ++++--- .../test/SystemEntitlementManagerTest.java | 9 +--- .../system/test/AnsibleManagerTest.java | 42 ++++++++----------- .../system/test/SystemManagerTest.java | 8 +--- .../test/PaygComputeDimensionsTaskTest.java | 9 +--- .../suse/manager/hub/test/HubManagerTest.java | 8 +--- .../matcher/test/MatcherJsonIOTest.java | 8 +--- .../RegisterMinionEventMessageAction.java | 8 +--- .../test/JobReturnEventMessageActionTest.java | 8 +--- .../test/SystemsControllerTest.java | 8 +--- .../SCCSystemRegistrationManagerTest.java | 18 ++------ 39 files changed, 72 insertions(+), 274 deletions(-) diff --git a/java/code/src/com/redhat/rhn/GlobalInstanceHolder.java b/java/code/src/com/redhat/rhn/GlobalInstanceHolder.java index df780044e7a8..c1464b3e1362 100644 --- a/java/code/src/com/redhat/rhn/GlobalInstanceHolder.java +++ b/java/code/src/com/redhat/rhn/GlobalInstanceHolder.java @@ -20,7 +20,6 @@ import com.redhat.rhn.domain.server.ServerGroupFactory; import com.redhat.rhn.frontend.taglibs.helpers.RenderUtils; import com.redhat.rhn.manager.formula.FormulaManager; -import com.redhat.rhn.manager.formula.FormulaMonitoringManager; import com.redhat.rhn.manager.org.MigrationManager; import com.redhat.rhn.manager.system.ServerGroupManager; import com.redhat.rhn.manager.system.SystemManager; @@ -38,7 +37,6 @@ import com.suse.manager.webui.menu.MenuTree; import com.suse.manager.webui.services.SaltServerActionService; import com.suse.manager.webui.services.ThrottlingService; -import com.suse.manager.webui.services.iface.MonitoringManager; import com.suse.manager.webui.services.iface.SaltApi; import com.suse.manager.webui.services.iface.SystemQuery; import com.suse.manager.webui.services.impl.SaltService; @@ -81,11 +79,8 @@ private GlobalInstanceHolder() { new RegularMinionBootstrapper(SYSTEM_QUERY, SALT_API, PAYG_MANAGER, ATTESTATION_MANAGER); public static final SSHMinionBootstrapper SSH_MINION_BOOTSTRAPPER = new SSHMinionBootstrapper(SYSTEM_QUERY, SALT_API, PAYG_MANAGER, ATTESTATION_MANAGER); - public static final MonitoringManager MONITORING_MANAGER = new FormulaMonitoringManager(SALT_API); public static final SystemEntitlementManager SYSTEM_ENTITLEMENT_MANAGER = new SystemEntitlementManager( - new SystemUnentitler(MONITORING_MANAGER, SERVER_GROUP_MANAGER), - new SystemEntitler(SALT_API, MONITORING_MANAGER, - SERVER_GROUP_MANAGER) + new SystemUnentitler(SALT_API), new SystemEntitler(SALT_API) ); public static final SystemManager SYSTEM_MANAGER = new SystemManager(ServerFactory.SINGLETON, ServerGroupFactory.SINGLETON, SALT_API); diff --git a/java/code/src/com/redhat/rhn/common/security/acl/test/AccessTest.java b/java/code/src/com/redhat/rhn/common/security/acl/test/AccessTest.java index 98f622c5276a..e4cd5d36442d 100644 --- a/java/code/src/com/redhat/rhn/common/security/acl/test/AccessTest.java +++ b/java/code/src/com/redhat/rhn/common/security/acl/test/AccessTest.java @@ -33,8 +33,6 @@ import com.redhat.rhn.domain.user.User; import com.redhat.rhn.domain.user.legacy.UserImpl; import com.redhat.rhn.manager.entitlement.EntitlementManager; -import com.redhat.rhn.manager.formula.FormulaMonitoringManager; -import com.redhat.rhn.manager.system.ServerGroupManager; import com.redhat.rhn.manager.system.SystemManager; import com.redhat.rhn.manager.system.entitling.SystemEntitlementManager; import com.redhat.rhn.manager.system.entitling.SystemEntitler; @@ -45,7 +43,6 @@ import com.redhat.rhn.testing.TestUtils; import com.redhat.rhn.testing.UserTestUtils; -import com.suse.manager.webui.services.iface.MonitoringManager; import com.suse.manager.webui.services.iface.SaltApi; import com.suse.manager.webui.services.test.TestSaltApi; @@ -66,11 +63,8 @@ public class AccessTest extends BaseTestCaseWithUser { private Acl acl; private final SaltApi saltApi = new TestSaltApi(); - private final ServerGroupManager serverGroupManager = new ServerGroupManager(saltApi); - private final MonitoringManager monitoringManager = new FormulaMonitoringManager(saltApi); private final SystemEntitlementManager systemEntitlementManager = new SystemEntitlementManager( - new SystemUnentitler(monitoringManager, serverGroupManager), - new SystemEntitler(saltApi, monitoringManager, serverGroupManager) + new SystemUnentitler(saltApi), new SystemEntitler(saltApi) ); @Override diff --git a/java/code/src/com/redhat/rhn/domain/entitlement/AnsibleManagedEntitlement.java b/java/code/src/com/redhat/rhn/domain/entitlement/AnsibleManagedEntitlement.java index 35398ad7d66f..3520c32b6391 100644 --- a/java/code/src/com/redhat/rhn/domain/entitlement/AnsibleManagedEntitlement.java +++ b/java/code/src/com/redhat/rhn/domain/entitlement/AnsibleManagedEntitlement.java @@ -15,7 +15,6 @@ package com.redhat.rhn.domain.entitlement; -import com.redhat.rhn.domain.server.Server; import com.redhat.rhn.manager.entitlement.EntitlementManager; /** diff --git a/java/code/src/com/redhat/rhn/domain/entitlement/test/BaseEntitlementTestCase.java b/java/code/src/com/redhat/rhn/domain/entitlement/test/BaseEntitlementTestCase.java index 61e1762f4327..d728cad1d20f 100644 --- a/java/code/src/com/redhat/rhn/domain/entitlement/test/BaseEntitlementTestCase.java +++ b/java/code/src/com/redhat/rhn/domain/entitlement/test/BaseEntitlementTestCase.java @@ -21,15 +21,12 @@ import com.redhat.rhn.domain.entitlement.Entitlement; import com.redhat.rhn.domain.server.Server; import com.redhat.rhn.manager.entitlement.EntitlementManager; -import com.redhat.rhn.manager.formula.FormulaMonitoringManager; -import com.redhat.rhn.manager.system.ServerGroupManager; import com.redhat.rhn.manager.system.entitling.SystemEntitlementManager; import com.redhat.rhn.manager.system.entitling.SystemEntitler; import com.redhat.rhn.manager.system.entitling.SystemUnentitler; import com.redhat.rhn.testing.BaseTestCaseWithUser; import com.redhat.rhn.testing.ServerTestUtils; -import com.suse.manager.webui.services.iface.MonitoringManager; import com.suse.manager.webui.services.iface.SaltApi; import com.suse.manager.webui.services.iface.SystemQuery; import com.suse.manager.webui.services.test.TestSaltApi; @@ -47,11 +44,8 @@ public abstract class BaseEntitlementTestCase extends BaseTestCaseWithUser { private final SystemQuery systemQuery = new TestSystemQuery(); private final SaltApi saltApi = new TestSaltApi(); - private final ServerGroupManager serverGroupManager = new ServerGroupManager(saltApi); - private final MonitoringManager monitoringManager = new FormulaMonitoringManager(saltApi); private final SystemEntitlementManager systemEntitlementManager = new SystemEntitlementManager( - new SystemUnentitler(monitoringManager, serverGroupManager), - new SystemEntitler(saltApi, monitoringManager, serverGroupManager) + new SystemUnentitler(saltApi), new SystemEntitler(saltApi) ); @Override diff --git a/java/code/src/com/redhat/rhn/domain/entitlement/test/ContainerBuildHostEntitlementTest.java b/java/code/src/com/redhat/rhn/domain/entitlement/test/ContainerBuildHostEntitlementTest.java index 040bb3c1a291..4a6810b2f56d 100644 --- a/java/code/src/com/redhat/rhn/domain/entitlement/test/ContainerBuildHostEntitlementTest.java +++ b/java/code/src/com/redhat/rhn/domain/entitlement/test/ContainerBuildHostEntitlementTest.java @@ -22,15 +22,12 @@ import com.redhat.rhn.domain.server.Server; import com.redhat.rhn.domain.server.test.MinionServerFactoryTest; import com.redhat.rhn.manager.entitlement.EntitlementManager; -import com.redhat.rhn.manager.formula.FormulaMonitoringManager; -import com.redhat.rhn.manager.system.ServerGroupManager; import com.redhat.rhn.manager.system.entitling.SystemEntitlementManager; import com.redhat.rhn.manager.system.entitling.SystemEntitler; import com.redhat.rhn.manager.system.entitling.SystemUnentitler; import com.redhat.rhn.testing.ServerTestUtils; import com.suse.manager.reactor.utils.ValueMap; -import com.suse.manager.webui.services.iface.MonitoringManager; import com.suse.manager.webui.services.iface.SaltApi; import com.suse.manager.webui.services.test.TestSaltApi; @@ -42,11 +39,8 @@ public class ContainerBuildHostEntitlementTest extends BaseEntitlementTestCase { private final SaltApi saltApi = new TestSaltApi(); - private final ServerGroupManager serverGroupManager = new ServerGroupManager(saltApi); - private final MonitoringManager monitoringManager = new FormulaMonitoringManager(saltApi); private final SystemEntitlementManager systemEntitlementManager = new SystemEntitlementManager( - new SystemUnentitler(monitoringManager, serverGroupManager), - new SystemEntitler(saltApi, monitoringManager, serverGroupManager) + new SystemUnentitler(saltApi), new SystemEntitler(saltApi) ); @Override diff --git a/java/code/src/com/redhat/rhn/domain/entitlement/test/OSImageBuildHostEntitlementTest.java b/java/code/src/com/redhat/rhn/domain/entitlement/test/OSImageBuildHostEntitlementTest.java index edd82898f9d2..16c1919fc9b3 100644 --- a/java/code/src/com/redhat/rhn/domain/entitlement/test/OSImageBuildHostEntitlementTest.java +++ b/java/code/src/com/redhat/rhn/domain/entitlement/test/OSImageBuildHostEntitlementTest.java @@ -23,14 +23,11 @@ import com.redhat.rhn.domain.server.Server; import com.redhat.rhn.domain.server.test.MinionServerFactoryTest; import com.redhat.rhn.manager.entitlement.EntitlementManager; -import com.redhat.rhn.manager.formula.FormulaMonitoringManager; -import com.redhat.rhn.manager.system.ServerGroupManager; import com.redhat.rhn.manager.system.entitling.SystemEntitlementManager; import com.redhat.rhn.manager.system.entitling.SystemEntitler; import com.redhat.rhn.manager.system.entitling.SystemUnentitler; import com.redhat.rhn.testing.ServerTestUtils; -import com.suse.manager.webui.services.iface.MonitoringManager; import com.suse.manager.webui.services.iface.SaltApi; import com.suse.manager.webui.services.iface.SystemQuery; import com.suse.manager.webui.services.test.TestSaltApi; @@ -43,11 +40,8 @@ public class OSImageBuildHostEntitlementTest extends BaseEntitlementTestCase { private final SystemQuery systemQuery = new TestSystemQuery(); private final SaltApi saltApi = new TestSaltApi(); - private final ServerGroupManager serverGroupManager = new ServerGroupManager(saltApi); - private final MonitoringManager monitoringManager = new FormulaMonitoringManager(saltApi); private final SystemEntitlementManager systemEntitlementManager = new SystemEntitlementManager( - new SystemUnentitler(monitoringManager, serverGroupManager), - new SystemEntitler(saltApi, monitoringManager, serverGroupManager) + new SystemUnentitler(saltApi), new SystemEntitler(saltApi) ); @Override diff --git a/java/code/src/com/redhat/rhn/domain/entitlement/test/PeripheralServerEntitlementTest.java b/java/code/src/com/redhat/rhn/domain/entitlement/test/PeripheralServerEntitlementTest.java index edba36a8dfba..9c46ce5c2496 100644 --- a/java/code/src/com/redhat/rhn/domain/entitlement/test/PeripheralServerEntitlementTest.java +++ b/java/code/src/com/redhat/rhn/domain/entitlement/test/PeripheralServerEntitlementTest.java @@ -23,15 +23,12 @@ import com.redhat.rhn.domain.server.ServerFactory; import com.redhat.rhn.domain.server.test.MinionServerFactoryTest; import com.redhat.rhn.manager.entitlement.EntitlementManager; -import com.redhat.rhn.manager.formula.FormulaMonitoringManager; -import com.redhat.rhn.manager.system.ServerGroupManager; import com.redhat.rhn.manager.system.entitling.SystemEntitlementManager; import com.redhat.rhn.manager.system.entitling.SystemEntitler; import com.redhat.rhn.manager.system.entitling.SystemUnentitler; import com.redhat.rhn.testing.ServerTestUtils; import com.redhat.rhn.testing.TestUtils; -import com.suse.manager.webui.services.iface.MonitoringManager; import com.suse.manager.webui.services.iface.SaltApi; import com.suse.manager.webui.services.iface.SystemQuery; import com.suse.manager.webui.services.test.TestSaltApi; @@ -45,11 +42,8 @@ public class PeripheralServerEntitlementTest extends BaseEntitlementTestCase { private final SystemQuery systemQuery = new TestSystemQuery(); private final SaltApi saltApi = new TestSaltApi(); - private final ServerGroupManager serverGroupManager = new ServerGroupManager(saltApi); - private final MonitoringManager monitoringManager = new FormulaMonitoringManager(saltApi); private final SystemEntitlementManager systemEntitlementManager = new SystemEntitlementManager( - new SystemUnentitler(monitoringManager, serverGroupManager), - new SystemEntitler(saltApi, monitoringManager, serverGroupManager) + new SystemUnentitler(saltApi), new SystemEntitler(saltApi) ); @Override diff --git a/java/code/src/com/redhat/rhn/domain/entitlement/test/VirtualizationEntitlementTest.java b/java/code/src/com/redhat/rhn/domain/entitlement/test/VirtualizationEntitlementTest.java index db1b3817a276..d258afedcb1d 100644 --- a/java/code/src/com/redhat/rhn/domain/entitlement/test/VirtualizationEntitlementTest.java +++ b/java/code/src/com/redhat/rhn/domain/entitlement/test/VirtualizationEntitlementTest.java @@ -22,15 +22,12 @@ import com.redhat.rhn.domain.server.Server; import com.redhat.rhn.domain.server.test.MinionServerFactoryTest; import com.redhat.rhn.manager.entitlement.EntitlementManager; -import com.redhat.rhn.manager.formula.FormulaMonitoringManager; -import com.redhat.rhn.manager.system.ServerGroupManager; import com.redhat.rhn.manager.system.entitling.SystemEntitlementManager; import com.redhat.rhn.manager.system.entitling.SystemEntitler; import com.redhat.rhn.manager.system.entitling.SystemUnentitler; import com.redhat.rhn.testing.ServerTestUtils; import com.suse.manager.reactor.utils.ValueMap; -import com.suse.manager.webui.services.iface.MonitoringManager; import com.suse.manager.webui.services.iface.SaltApi; import com.suse.manager.webui.services.iface.SystemQuery; import com.suse.manager.webui.services.test.TestSaltApi; @@ -45,11 +42,8 @@ public class VirtualizationEntitlementTest extends BaseEntitlementTestCase { private final SystemQuery systemQuery = new TestSystemQuery(); private final SaltApi saltApi = new TestSaltApi(); - private final ServerGroupManager serverGroupManager = new ServerGroupManager(saltApi); - private final MonitoringManager monitoringManager = new FormulaMonitoringManager(saltApi); private final SystemEntitlementManager systemEntitlementManager = new SystemEntitlementManager( - new SystemUnentitler(monitoringManager, serverGroupManager), - new SystemEntitler(saltApi, monitoringManager, serverGroupManager) + new SystemUnentitler(saltApi), new SystemEntitler(saltApi) ); @Override diff --git a/java/code/src/com/redhat/rhn/domain/image/test/ImageInfoFactoryTest.java b/java/code/src/com/redhat/rhn/domain/image/test/ImageInfoFactoryTest.java index 783f63e22fb8..9c0b93f61565 100644 --- a/java/code/src/com/redhat/rhn/domain/image/test/ImageInfoFactoryTest.java +++ b/java/code/src/com/redhat/rhn/domain/image/test/ImageInfoFactoryTest.java @@ -54,8 +54,6 @@ import com.redhat.rhn.domain.token.ActivationKey; import com.redhat.rhn.domain.user.User; import com.redhat.rhn.manager.entitlement.EntitlementManager; -import com.redhat.rhn.manager.formula.FormulaMonitoringManager; -import com.redhat.rhn.manager.system.ServerGroupManager; import com.redhat.rhn.manager.system.entitling.SystemEntitlementManager; import com.redhat.rhn.manager.system.entitling.SystemEntitler; import com.redhat.rhn.manager.system.entitling.SystemUnentitler; @@ -66,7 +64,6 @@ import com.redhat.rhn.testing.TestUtils; import com.redhat.rhn.testing.UserTestUtils; -import com.suse.manager.webui.services.iface.MonitoringManager; import com.suse.manager.webui.services.iface.SaltApi; import com.suse.manager.webui.services.iface.SystemQuery; import com.suse.manager.webui.services.test.TestSaltApi; @@ -105,11 +102,8 @@ public class ImageInfoFactoryTest extends BaseTestCaseWithUser { private static SaltApi saltApiMock; private final SystemQuery systemQuery = new TestSystemQuery(); private final SaltApi saltApi = new TestSaltApi(); - private final ServerGroupManager serverGroupManager = new ServerGroupManager(saltApi); - private final MonitoringManager monitoringManager = new FormulaMonitoringManager(saltApi); private final SystemEntitlementManager systemEntitlementManager = new SystemEntitlementManager( - new SystemUnentitler(monitoringManager, serverGroupManager), - new SystemEntitler(saltApi, monitoringManager, serverGroupManager) + new SystemUnentitler(saltApi), new SystemEntitler(saltApi) ); @Override diff --git a/java/code/src/com/redhat/rhn/domain/server/test/ServerFactoryTest.java b/java/code/src/com/redhat/rhn/domain/server/test/ServerFactoryTest.java index 9aed3bdeca62..f427717973d3 100644 --- a/java/code/src/com/redhat/rhn/domain/server/test/ServerFactoryTest.java +++ b/java/code/src/com/redhat/rhn/domain/server/test/ServerFactoryTest.java @@ -85,7 +85,6 @@ import com.redhat.rhn.domain.user.UserFactory; import com.redhat.rhn.frontend.xmlrpc.ServerNotInGroupException; import com.redhat.rhn.manager.entitlement.EntitlementManager; -import com.redhat.rhn.manager.formula.FormulaMonitoringManager; import com.redhat.rhn.manager.rhnset.RhnSetDecl; import com.redhat.rhn.manager.rhnset.RhnSetManager; import com.redhat.rhn.manager.system.ServerGroupManager; @@ -108,7 +107,6 @@ import com.suse.manager.utils.SaltKeyUtils; import com.suse.manager.utils.SaltUtils; import com.suse.manager.webui.services.SaltServerActionService; -import com.suse.manager.webui.services.iface.MonitoringManager; import com.suse.manager.webui.services.iface.SaltApi; import com.suse.manager.webui.services.iface.SystemQuery; import com.suse.manager.webui.services.test.TestSaltApi; @@ -153,10 +151,8 @@ public class ServerFactoryTest extends BaseTestCaseWithUser { SALT_UTILS, SALT_KEY_UTILS ); - private static final MonitoringManager MONITORING_MANAGER = new FormulaMonitoringManager(SALT_API); private static final SystemEntitlementManager SYSTEM_ENTITLEMENT_MANAGER = new SystemEntitlementManager( - new SystemUnentitler(MONITORING_MANAGER, SERVER_GROUP_MANAGER), - new SystemEntitler(SALT_API, MONITORING_MANAGER, SERVER_GROUP_MANAGER) + new SystemUnentitler(SALT_API), new SystemEntitler(SALT_API) ); @Override diff --git a/java/code/src/com/redhat/rhn/domain/server/test/ServerTest.java b/java/code/src/com/redhat/rhn/domain/server/test/ServerTest.java index 0326f6223b8b..6cad6591e621 100644 --- a/java/code/src/com/redhat/rhn/domain/server/test/ServerTest.java +++ b/java/code/src/com/redhat/rhn/domain/server/test/ServerTest.java @@ -36,7 +36,6 @@ import com.redhat.rhn.domain.server.VirtualInstance; import com.redhat.rhn.domain.user.User; import com.redhat.rhn.manager.entitlement.EntitlementManager; -import com.redhat.rhn.manager.formula.FormulaMonitoringManager; import com.redhat.rhn.manager.rhnset.RhnSetDecl; import com.redhat.rhn.manager.system.ServerGroupManager; import com.redhat.rhn.manager.system.SystemManager; @@ -50,7 +49,6 @@ import com.redhat.rhn.testing.TestUtils; import com.redhat.rhn.testing.UserTestUtils; -import com.suse.manager.webui.services.iface.MonitoringManager; import com.suse.manager.webui.services.iface.SaltApi; import com.suse.manager.webui.services.test.TestSaltApi; @@ -69,11 +67,9 @@ public class ServerTest extends BaseTestCaseWithUser { private final SaltApi saltApi = new TestSaltApi(); private final ServerGroupManager serverGroupManager = new ServerGroupManager(saltApi); - private final MonitoringManager monitoringManager = new FormulaMonitoringManager(saltApi); - private final SystemUnentitler systemUnentitler = new SystemUnentitler( - monitoringManager, serverGroupManager); + private final SystemUnentitler systemUnentitler = new SystemUnentitler(saltApi); private final SystemEntitlementManager systemEntitlementManager = new SystemEntitlementManager( - systemUnentitler, new SystemEntitler(saltApi, monitoringManager, serverGroupManager) + systemUnentitler, new SystemEntitler(saltApi) ); @Test diff --git a/java/code/src/com/redhat/rhn/domain/server/test/VirtualInstanceFactoryTest.java b/java/code/src/com/redhat/rhn/domain/server/test/VirtualInstanceFactoryTest.java index 91b86673ce2c..2929d1db50b2 100644 --- a/java/code/src/com/redhat/rhn/domain/server/test/VirtualInstanceFactoryTest.java +++ b/java/code/src/com/redhat/rhn/domain/server/test/VirtualInstanceFactoryTest.java @@ -25,8 +25,6 @@ import com.redhat.rhn.domain.server.VirtualInstance; import com.redhat.rhn.domain.server.VirtualInstanceFactory; import com.redhat.rhn.domain.user.User; -import com.redhat.rhn.manager.formula.FormulaMonitoringManager; -import com.redhat.rhn.manager.system.ServerGroupManager; import com.redhat.rhn.manager.system.entitling.SystemEntitlementManager; import com.redhat.rhn.manager.system.entitling.SystemEntitler; import com.redhat.rhn.manager.system.entitling.SystemUnentitler; @@ -35,7 +33,6 @@ import com.redhat.rhn.testing.TestUtils; import com.redhat.rhn.testing.UserTestUtils; -import com.suse.manager.webui.services.iface.MonitoringManager; import com.suse.manager.webui.services.iface.SaltApi; import com.suse.manager.webui.services.test.TestSaltApi; @@ -69,11 +66,8 @@ public void setUp() { "testOrg" + this.getClass().getSimpleName()); builder = new GuestBuilder(user); SaltApi saltApi = new TestSaltApi(); - ServerGroupManager serverGroupManager = new ServerGroupManager(saltApi); - MonitoringManager monitoringManager = new FormulaMonitoringManager(saltApi); systemEntitlementManager = new SystemEntitlementManager( - new SystemUnentitler(monitoringManager, serverGroupManager), - new SystemEntitler(saltApi, monitoringManager, serverGroupManager) + new SystemUnentitler(saltApi), new SystemEntitler(saltApi) ); } diff --git a/java/code/src/com/redhat/rhn/frontend/action/systems/entitlements/test/SystemEntitlementsSetupActionTest.java b/java/code/src/com/redhat/rhn/frontend/action/systems/entitlements/test/SystemEntitlementsSetupActionTest.java index 02d16ba22f56..619d440ed6a8 100644 --- a/java/code/src/com/redhat/rhn/frontend/action/systems/entitlements/test/SystemEntitlementsSetupActionTest.java +++ b/java/code/src/com/redhat/rhn/frontend/action/systems/entitlements/test/SystemEntitlementsSetupActionTest.java @@ -35,8 +35,6 @@ import com.redhat.rhn.frontend.action.systems.entitlements.SystemEntitlementsSetupAction; import com.redhat.rhn.frontend.struts.RequestContext; import com.redhat.rhn.manager.entitlement.EntitlementManager; -import com.redhat.rhn.manager.formula.FormulaMonitoringManager; -import com.redhat.rhn.manager.system.ServerGroupManager; import com.redhat.rhn.manager.system.SystemManager; import com.redhat.rhn.manager.system.entitling.SystemEntitlementManager; import com.redhat.rhn.manager.system.entitling.SystemEntitler; @@ -46,7 +44,6 @@ import com.redhat.rhn.testing.ServerTestUtils; import com.redhat.rhn.testing.UserTestUtils; -import com.suse.manager.webui.services.iface.MonitoringManager; import com.suse.manager.webui.services.impl.SaltSSHService; import com.suse.manager.webui.services.impl.SaltService; import com.suse.salt.netapi.datatypes.target.MinionList; @@ -78,11 +75,8 @@ public void setUp() throws Exception { Config.get().setBoolean(ConfigDefaults.KIWI_OS_IMAGE_BUILDING_ENABLED, "true"); context.setImposteriser(ByteBuddyClassImposteriser.INSTANCE); saltServiceMock = context.mock(SaltService.class); - ServerGroupManager serverGroupManager = new ServerGroupManager(saltServiceMock); - MonitoringManager monitoringManager = new FormulaMonitoringManager(saltServiceMock); systemEntitlementManager = new SystemEntitlementManager( - new SystemUnentitler(monitoringManager, serverGroupManager), - new SystemEntitler(saltServiceMock, monitoringManager, serverGroupManager) + new SystemUnentitler(saltServiceMock), new SystemEntitler(saltServiceMock) ); context.checking(new Expectations() {{ allowing(saltServiceMock).refreshPillar(with(any(MinionList.class))); diff --git a/java/code/src/com/redhat/rhn/frontend/action/systems/entitlements/test/SystemEntitlementsSubmitActionTest.java b/java/code/src/com/redhat/rhn/frontend/action/systems/entitlements/test/SystemEntitlementsSubmitActionTest.java index fdb4f9b0fb06..996cb4c6a60e 100644 --- a/java/code/src/com/redhat/rhn/frontend/action/systems/entitlements/test/SystemEntitlementsSubmitActionTest.java +++ b/java/code/src/com/redhat/rhn/frontend/action/systems/entitlements/test/SystemEntitlementsSubmitActionTest.java @@ -30,8 +30,6 @@ import com.redhat.rhn.frontend.action.systems.entitlements.SystemEntitlementsSubmitAction; import com.redhat.rhn.frontend.struts.RhnAction; import com.redhat.rhn.manager.entitlement.EntitlementManager; -import com.redhat.rhn.manager.formula.FormulaMonitoringManager; -import com.redhat.rhn.manager.system.ServerGroupManager; import com.redhat.rhn.manager.system.SystemManager; import com.redhat.rhn.manager.system.entitling.SystemEntitlementManager; import com.redhat.rhn.manager.system.entitling.SystemEntitler; @@ -39,7 +37,6 @@ import com.redhat.rhn.testing.RhnPostMockStrutsTestCase; import com.redhat.rhn.testing.ServerTestUtils; -import com.suse.manager.webui.services.iface.MonitoringManager; import com.suse.manager.webui.services.iface.SaltApi; import com.suse.manager.webui.services.iface.SystemQuery; import com.suse.manager.webui.services.test.TestSaltApi; @@ -61,11 +58,8 @@ public class SystemEntitlementsSubmitActionTest extends RhnPostMockStrutsTestCas private final SystemQuery systemQuery = new TestSystemQuery(); private final SaltApi saltApi = new TestSaltApi(); - private final ServerGroupManager serverGroupManager = new ServerGroupManager(saltApi); - private final MonitoringManager monitoringManager = new FormulaMonitoringManager(saltApi); private final SystemEntitlementManager systemEntitlementManager = new SystemEntitlementManager( - new SystemUnentitler(monitoringManager, serverGroupManager), - new SystemEntitler(saltApi, monitoringManager, serverGroupManager) + new SystemUnentitler(saltApi), new SystemEntitler(saltApi) ); diff --git a/java/code/src/com/redhat/rhn/frontend/action/systems/sdc/test/SystemDetailsEditActionTest.java b/java/code/src/com/redhat/rhn/frontend/action/systems/sdc/test/SystemDetailsEditActionTest.java index 1d6ef2c9a6f2..f2ce2d9f3d1f 100644 --- a/java/code/src/com/redhat/rhn/frontend/action/systems/sdc/test/SystemDetailsEditActionTest.java +++ b/java/code/src/com/redhat/rhn/frontend/action/systems/sdc/test/SystemDetailsEditActionTest.java @@ -28,8 +28,6 @@ import com.redhat.rhn.frontend.struts.RhnAction; import com.redhat.rhn.frontend.struts.RhnHelper; import com.redhat.rhn.manager.entitlement.EntitlementManager; -import com.redhat.rhn.manager.formula.FormulaMonitoringManager; -import com.redhat.rhn.manager.system.ServerGroupManager; import com.redhat.rhn.manager.system.entitling.SystemEntitlementManager; import com.redhat.rhn.manager.system.entitling.SystemEntitler; import com.redhat.rhn.manager.system.entitling.SystemUnentitler; @@ -39,7 +37,6 @@ import com.redhat.rhn.testing.TestUtils; import com.redhat.rhn.testing.UserTestUtils; -import com.suse.manager.webui.services.iface.MonitoringManager; import com.suse.manager.webui.services.iface.SaltApi; import com.suse.manager.webui.services.iface.SystemQuery; import com.suse.manager.webui.services.test.TestSaltApi; @@ -62,11 +59,8 @@ public class SystemDetailsEditActionTest extends RhnPostMockStrutsTestCase { protected Server s; private final SystemQuery systemQuery = new TestSystemQuery(); private final SaltApi saltApi = new TestSaltApi(); - private final ServerGroupManager serverGroupManager = new ServerGroupManager(saltApi); - private final MonitoringManager monitoringManager = new FormulaMonitoringManager(saltApi); private final SystemEntitlementManager systemEntitlementManager = new SystemEntitlementManager( - new SystemUnentitler(monitoringManager, serverGroupManager), - new SystemEntitler(saltApi, monitoringManager, serverGroupManager) + new SystemUnentitler(saltApi), new SystemEntitler(saltApi) ); /** diff --git a/java/code/src/com/redhat/rhn/frontend/action/systems/sdc/test/SystemOverviewActionTest.java b/java/code/src/com/redhat/rhn/frontend/action/systems/sdc/test/SystemOverviewActionTest.java index 340abe7f0cef..a01cff351516 100644 --- a/java/code/src/com/redhat/rhn/frontend/action/systems/sdc/test/SystemOverviewActionTest.java +++ b/java/code/src/com/redhat/rhn/frontend/action/systems/sdc/test/SystemOverviewActionTest.java @@ -32,8 +32,6 @@ import com.redhat.rhn.domain.server.test.ServerFactoryTest; import com.redhat.rhn.domain.user.UserFactory; import com.redhat.rhn.manager.errata.cache.ErrataCacheManager; -import com.redhat.rhn.manager.formula.FormulaMonitoringManager; -import com.redhat.rhn.manager.system.ServerGroupManager; import com.redhat.rhn.manager.system.SystemManager; import com.redhat.rhn.manager.system.entitling.SystemEntitlementManager; import com.redhat.rhn.manager.system.entitling.SystemEntitler; @@ -41,7 +39,6 @@ import com.redhat.rhn.testing.RhnMockStrutsTestCase; import com.redhat.rhn.testing.TestUtils; -import com.suse.manager.webui.services.iface.MonitoringManager; import com.suse.manager.webui.services.iface.SaltApi; import com.suse.manager.webui.services.test.TestSaltApi; @@ -59,11 +56,8 @@ public class SystemOverviewActionTest extends RhnMockStrutsTestCase { protected Server s; private final SaltApi saltApi = new TestSaltApi(); - private final ServerGroupManager serverGroupManager = new ServerGroupManager(saltApi); - private final MonitoringManager monitoringManager = new FormulaMonitoringManager(saltApi); private final SystemEntitlementManager systemEntitlementManager = new SystemEntitlementManager( - new SystemUnentitler(monitoringManager, serverGroupManager), - new SystemEntitler(saltApi, monitoringManager, serverGroupManager) + new SystemUnentitler(saltApi), new SystemEntitler(saltApi) ); /** diff --git a/java/code/src/com/redhat/rhn/frontend/xmlrpc/admin/configuration/test/AdminConfigurationHandlerTest.java b/java/code/src/com/redhat/rhn/frontend/xmlrpc/admin/configuration/test/AdminConfigurationHandlerTest.java index 4d5cfe15211a..bdfeccf792c3 100644 --- a/java/code/src/com/redhat/rhn/frontend/xmlrpc/admin/configuration/test/AdminConfigurationHandlerTest.java +++ b/java/code/src/com/redhat/rhn/frontend/xmlrpc/admin/configuration/test/AdminConfigurationHandlerTest.java @@ -51,7 +51,6 @@ import com.redhat.rhn.frontend.xmlrpc.systemgroup.ServerGroupHandler; import com.redhat.rhn.frontend.xmlrpc.test.BaseHandlerTestCase; import com.redhat.rhn.frontend.xmlrpc.user.UserHandler; -import com.redhat.rhn.manager.formula.FormulaMonitoringManager; import com.redhat.rhn.manager.org.MigrationManager; import com.redhat.rhn.manager.system.ServerGroupManager; import com.redhat.rhn.manager.system.SystemManager; @@ -66,7 +65,6 @@ import com.suse.manager.attestation.AttestationManager; import com.suse.manager.webui.controllers.bootstrap.RegularMinionBootstrapper; import com.suse.manager.webui.controllers.bootstrap.SSHMinionBootstrapper; -import com.suse.manager.webui.services.iface.MonitoringManager; import com.suse.manager.webui.services.iface.SaltApi; import com.suse.manager.webui.services.iface.SystemQuery; import com.suse.manager.webui.services.test.TestSaltApi; @@ -106,10 +104,8 @@ public class AdminConfigurationHandlerTest extends BaseHandlerTestCase { regularMinionBootstrapper, sshMinionBootstrapper ); - private final MonitoringManager monitoringManager = new FormulaMonitoringManager(saltApi); private final SystemEntitlementManager systemEntitlementManager = new SystemEntitlementManager( - new SystemUnentitler(monitoringManager, serverGroupManager), - new SystemEntitler(saltApi, monitoringManager, serverGroupManager) + new SystemUnentitler(saltApi), new SystemEntitler(saltApi) ); private SystemManager systemManager = new SystemManager(ServerFactory.SINGLETON, ServerGroupFactory.SINGLETON, saltApi); diff --git a/java/code/src/com/redhat/rhn/frontend/xmlrpc/ansible/test/AnsibleHandlerTest.java b/java/code/src/com/redhat/rhn/frontend/xmlrpc/ansible/test/AnsibleHandlerTest.java index 7db55318a6b9..cdb6e1a51170 100644 --- a/java/code/src/com/redhat/rhn/frontend/xmlrpc/ansible/test/AnsibleHandlerTest.java +++ b/java/code/src/com/redhat/rhn/frontend/xmlrpc/ansible/test/AnsibleHandlerTest.java @@ -42,9 +42,7 @@ import com.redhat.rhn.manager.action.ActionChainManager; import com.redhat.rhn.manager.action.ActionManager; import com.redhat.rhn.manager.entitlement.EntitlementManager; -import com.redhat.rhn.manager.formula.FormulaMonitoringManager; import com.redhat.rhn.manager.system.AnsibleManager; -import com.redhat.rhn.manager.system.ServerGroupManager; import com.redhat.rhn.manager.system.entitling.SystemEntitlementManager; import com.redhat.rhn.manager.system.entitling.SystemEntitler; import com.redhat.rhn.manager.system.entitling.SystemUnentitler; @@ -52,7 +50,6 @@ import com.redhat.rhn.taskomatic.TaskomaticApiException; import com.redhat.rhn.testing.TestUtils; -import com.suse.manager.webui.services.iface.MonitoringManager; import com.suse.manager.webui.services.iface.SaltApi; import com.suse.salt.netapi.calls.LocalCall; import com.suse.salt.netapi.datatypes.target.MinionList; @@ -322,11 +319,8 @@ public void testFetchPlaybookContents() throws Exception { } private MinionServer createAnsibleControlNode(User user) throws Exception { - MonitoringManager monitoringManager = new FormulaMonitoringManager(saltApi); - ServerGroupManager groupManager = new ServerGroupManager(saltApi); SystemEntitlementManager entitlementManager = new SystemEntitlementManager( - new SystemUnentitler(monitoringManager, groupManager), - new SystemEntitler(saltApi, monitoringManager, groupManager) + new SystemUnentitler(saltApi), new SystemEntitler(saltApi) ); context.checking(new Expectations() {{ diff --git a/java/code/src/com/redhat/rhn/frontend/xmlrpc/channel/software/test/ChannelSoftwareHandlerTest.java b/java/code/src/com/redhat/rhn/frontend/xmlrpc/channel/software/test/ChannelSoftwareHandlerTest.java index 1f2b4870a0a4..cf75a2443825 100644 --- a/java/code/src/com/redhat/rhn/frontend/xmlrpc/channel/software/test/ChannelSoftwareHandlerTest.java +++ b/java/code/src/com/redhat/rhn/frontend/xmlrpc/channel/software/test/ChannelSoftwareHandlerTest.java @@ -58,8 +58,6 @@ import com.redhat.rhn.frontend.xmlrpc.system.XmlRpcSystemHelper; import com.redhat.rhn.frontend.xmlrpc.test.BaseHandlerTestCase; import com.redhat.rhn.manager.channel.ChannelManager; -import com.redhat.rhn.manager.formula.FormulaMonitoringManager; -import com.redhat.rhn.manager.system.ServerGroupManager; import com.redhat.rhn.manager.system.SystemManager; import com.redhat.rhn.manager.system.entitling.SystemEntitlementManager; import com.redhat.rhn.manager.system.entitling.SystemEntitler; @@ -73,7 +71,6 @@ import com.suse.manager.attestation.AttestationManager; import com.suse.manager.webui.controllers.bootstrap.RegularMinionBootstrapper; import com.suse.manager.webui.controllers.bootstrap.SSHMinionBootstrapper; -import com.suse.manager.webui.services.iface.MonitoringManager; import com.suse.manager.webui.services.iface.SaltApi; import com.suse.manager.webui.services.iface.SystemQuery; import com.suse.manager.webui.services.test.TestSaltApi; @@ -112,7 +109,6 @@ public class ChannelSoftwareHandlerTest extends BaseHandlerTestCase { private final SaltApi saltApi = new TestSaltApi(); private final CloudPaygManager paygManager = new TestCloudPaygManagerBuilder().build(); private final AttestationManager attestationManager = new AttestationManager(); - private final ServerGroupManager serverGroupManager = new ServerGroupManager(saltApi); private RegularMinionBootstrapper regularMinionBootstrapper = new RegularMinionBootstrapper(systemQuery, saltApi, paygManager, attestationManager); private SSHMinionBootstrapper sshMinionBootstrapper = @@ -121,10 +117,8 @@ public class ChannelSoftwareHandlerTest extends BaseHandlerTestCase { regularMinionBootstrapper, sshMinionBootstrapper ); - private final MonitoringManager monitoringManager = new FormulaMonitoringManager(saltApi); private final SystemEntitlementManager systemEntitlementManager = new SystemEntitlementManager( - new SystemUnentitler(monitoringManager, serverGroupManager), - new SystemEntitler(saltApi, monitoringManager, serverGroupManager) + new SystemUnentitler(saltApi), new SystemEntitler(saltApi) ); private SystemManager systemManager = new SystemManager(ServerFactory.SINGLETON, ServerGroupFactory.SINGLETON, saltApi); diff --git a/java/code/src/com/redhat/rhn/frontend/xmlrpc/image/test/ImageInfoHandlerTest.java b/java/code/src/com/redhat/rhn/frontend/xmlrpc/image/test/ImageInfoHandlerTest.java index 0ab5190374d4..b4319d1bde58 100644 --- a/java/code/src/com/redhat/rhn/frontend/xmlrpc/image/test/ImageInfoHandlerTest.java +++ b/java/code/src/com/redhat/rhn/frontend/xmlrpc/image/test/ImageInfoHandlerTest.java @@ -57,8 +57,6 @@ import com.redhat.rhn.manager.action.ActionManager; import com.redhat.rhn.manager.entitlement.EntitlementManager; import com.redhat.rhn.manager.errata.cache.ErrataCacheManager; -import com.redhat.rhn.manager.formula.FormulaMonitoringManager; -import com.redhat.rhn.manager.system.ServerGroupManager; import com.redhat.rhn.manager.system.entitling.SystemEntitlementManager; import com.redhat.rhn.manager.system.entitling.SystemEntitler; import com.redhat.rhn.manager.system.entitling.SystemUnentitler; @@ -67,7 +65,6 @@ import com.redhat.rhn.testing.ImageTestUtils; import com.redhat.rhn.testing.TestUtils; -import com.suse.manager.webui.services.iface.MonitoringManager; import com.suse.manager.webui.services.impl.SaltSSHService; import com.suse.manager.webui.services.impl.SaltService; import com.suse.manager.webui.services.impl.runner.MgrUtilRunner; @@ -111,11 +108,8 @@ public void setUp() throws Exception { context.setImposteriser(ByteBuddyClassImposteriser.INSTANCE); Config.get().setBoolean(ConfigDefaults.KIWI_OS_IMAGE_BUILDING_ENABLED, "true"); saltServiceMock = context.mock(SaltService.class); - ServerGroupManager serverGroupManager = new ServerGroupManager(saltServiceMock); - MonitoringManager monitoringManager = new FormulaMonitoringManager(saltServiceMock); systemEntitlementManager = new SystemEntitlementManager( - new SystemUnentitler(monitoringManager, serverGroupManager), - new SystemEntitler(saltServiceMock, monitoringManager, serverGroupManager) + new SystemUnentitler(saltServiceMock), new SystemEntitler(saltServiceMock) ); handler = new ImageInfoHandler(saltServiceMock); context.checking(new Expectations() {{ diff --git a/java/code/src/com/redhat/rhn/frontend/xmlrpc/system/test/SystemHandlerProvisioningTest.java b/java/code/src/com/redhat/rhn/frontend/xmlrpc/system/test/SystemHandlerProvisioningTest.java index 1d16c6849b83..7dcf81dc1052 100644 --- a/java/code/src/com/redhat/rhn/frontend/xmlrpc/system/test/SystemHandlerProvisioningTest.java +++ b/java/code/src/com/redhat/rhn/frontend/xmlrpc/system/test/SystemHandlerProvisioningTest.java @@ -37,7 +37,6 @@ import com.redhat.rhn.frontend.xmlrpc.system.XmlRpcSystemHelper; import com.redhat.rhn.frontend.xmlrpc.test.BaseHandlerTestCase; import com.redhat.rhn.manager.entitlement.EntitlementManager; -import com.redhat.rhn.manager.formula.FormulaMonitoringManager; import com.redhat.rhn.manager.kickstart.cobbler.CobblerXMLRPCHelper; import com.redhat.rhn.manager.rhnpackage.test.PackageManagerTest; import com.redhat.rhn.manager.system.ServerGroupManager; @@ -55,7 +54,6 @@ import com.suse.manager.attestation.AttestationManager; import com.suse.manager.webui.controllers.bootstrap.RegularMinionBootstrapper; import com.suse.manager.webui.controllers.bootstrap.SSHMinionBootstrapper; -import com.suse.manager.webui.services.iface.MonitoringManager; import com.suse.manager.webui.services.iface.SaltApi; import com.suse.manager.webui.services.iface.SystemQuery; import com.suse.manager.webui.services.test.TestSaltApi; @@ -94,10 +92,8 @@ public class SystemHandlerProvisioningTest extends BaseHandlerTestCase { sshMinionBootstrapper ); private final ServerGroupManager serverGroupManager = new ServerGroupManager(saltApi); - private final MonitoringManager monitoringManager = new FormulaMonitoringManager(saltApi); private final SystemEntitlementManager systemEntitlementManager = new SystemEntitlementManager( - new SystemUnentitler(monitoringManager, serverGroupManager), - new SystemEntitler(saltApi, monitoringManager, serverGroupManager) + new SystemUnentitler(saltApi), new SystemEntitler(saltApi) ); private final SystemManager systemManager = new SystemManager(ServerFactory.SINGLETON, ServerGroupFactory.SINGLETON, saltApi); diff --git a/java/code/src/com/redhat/rhn/frontend/xmlrpc/system/test/SystemHandlerPtfTest.java b/java/code/src/com/redhat/rhn/frontend/xmlrpc/system/test/SystemHandlerPtfTest.java index 91e7775e0ef0..c3514d9bdafd 100644 --- a/java/code/src/com/redhat/rhn/frontend/xmlrpc/system/test/SystemHandlerPtfTest.java +++ b/java/code/src/com/redhat/rhn/frontend/xmlrpc/system/test/SystemHandlerPtfTest.java @@ -37,7 +37,6 @@ import com.redhat.rhn.frontend.xmlrpc.system.SystemHandler; import com.redhat.rhn.frontend.xmlrpc.system.XmlRpcSystemHelper; import com.redhat.rhn.frontend.xmlrpc.test.BaseHandlerTestCase; -import com.redhat.rhn.manager.formula.FormulaMonitoringManager; import com.redhat.rhn.manager.system.ServerGroupManager; import com.redhat.rhn.manager.system.SystemManager; import com.redhat.rhn.manager.system.entitling.SystemEntitlementManager; @@ -51,7 +50,6 @@ import com.suse.manager.attestation.AttestationManager; import com.suse.manager.webui.controllers.bootstrap.RegularMinionBootstrapper; import com.suse.manager.webui.controllers.bootstrap.SSHMinionBootstrapper; -import com.suse.manager.webui.services.iface.MonitoringManager; import com.suse.manager.webui.services.iface.SaltApi; import com.suse.manager.webui.services.iface.SystemQuery; import com.suse.manager.webui.services.test.TestSaltApi; @@ -114,10 +112,9 @@ public void setUp() throws Exception { XmlRpcSystemHelper xmlRpcHelper = new XmlRpcSystemHelper(regularBootstrapper, sshBootstrapper); ServerGroupManager groupManager = new ServerGroupManager(saltApi); - MonitoringManager monitoringManager = new FormulaMonitoringManager(saltApi); - SystemUnentitler unentitler = new SystemUnentitler(monitoringManager, groupManager); - SystemEntitler entitler = new SystemEntitler(saltApi, monitoringManager, groupManager); + SystemUnentitler unentitler = new SystemUnentitler(saltApi); + SystemEntitler entitler = new SystemEntitler(saltApi); SystemEntitlementManager entitlementManager = new SystemEntitlementManager(unentitler, entitler); SystemManager systemManager = new SystemManager(ServerFactory.SINGLETON, ServerGroupFactory.SINGLETON, saltApi); diff --git a/java/code/src/com/redhat/rhn/frontend/xmlrpc/system/test/SystemHandlerTest.java b/java/code/src/com/redhat/rhn/frontend/xmlrpc/system/test/SystemHandlerTest.java index 90f263aa10d8..9d9a199a5bcd 100644 --- a/java/code/src/com/redhat/rhn/frontend/xmlrpc/system/test/SystemHandlerTest.java +++ b/java/code/src/com/redhat/rhn/frontend/xmlrpc/system/test/SystemHandlerTest.java @@ -139,7 +139,6 @@ import com.redhat.rhn.manager.channel.ChannelManager; import com.redhat.rhn.manager.entitlement.EntitlementManager; import com.redhat.rhn.manager.errata.cache.ErrataCacheManager; -import com.redhat.rhn.manager.formula.FormulaMonitoringManager; import com.redhat.rhn.manager.kickstart.cobbler.CobblerXMLRPCHelper; import com.redhat.rhn.manager.profile.ProfileManager; import com.redhat.rhn.manager.rhnpackage.test.PackageManagerTest; @@ -165,7 +164,6 @@ import com.suse.manager.webui.controllers.bootstrap.RegularMinionBootstrapper; import com.suse.manager.webui.controllers.bootstrap.SSHMinionBootstrapper; import com.suse.manager.webui.services.SaltServerActionService; -import com.suse.manager.webui.services.iface.MonitoringManager; import com.suse.manager.webui.services.iface.SaltApi; import com.suse.manager.webui.services.iface.SystemQuery; import com.suse.manager.webui.services.pillar.MinionCustomInfoPillarGenerator; @@ -218,10 +216,8 @@ public class SystemHandlerTest extends BaseHandlerTestCase { sshMinionBootstrapper ); private final ServerGroupManager serverGroupManager = new ServerGroupManager(saltApi); - private final MonitoringManager monitoringManager = new FormulaMonitoringManager(saltApi); private final SystemEntitlementManager systemEntitlementManager = new SystemEntitlementManager( - new SystemUnentitler(monitoringManager, serverGroupManager), - new SystemEntitler(saltApi, monitoringManager, serverGroupManager) + new SystemUnentitler(saltApi), new SystemEntitler(saltApi) ); private SystemManager systemManager = new SystemManager(ServerFactory.SINGLETON, ServerGroupFactory.SINGLETON, saltApi); diff --git a/java/code/src/com/redhat/rhn/manager/action/test/ActionManagerTest.java b/java/code/src/com/redhat/rhn/manager/action/test/ActionManagerTest.java index 7de076d030a3..0566e4fe0482 100644 --- a/java/code/src/com/redhat/rhn/manager/action/test/ActionManagerTest.java +++ b/java/code/src/com/redhat/rhn/manager/action/test/ActionManagerTest.java @@ -84,13 +84,11 @@ import com.redhat.rhn.manager.action.ActionIsChildException; import com.redhat.rhn.manager.action.ActionManager; import com.redhat.rhn.manager.entitlement.EntitlementManager; -import com.redhat.rhn.manager.formula.FormulaMonitoringManager; import com.redhat.rhn.manager.kickstart.ProvisionVirtualInstanceCommand; import com.redhat.rhn.manager.profile.ProfileManager; import com.redhat.rhn.manager.profile.test.ProfileManagerTest; import com.redhat.rhn.manager.rhnset.RhnSetDecl; import com.redhat.rhn.manager.rhnset.RhnSetManager; -import com.redhat.rhn.manager.system.ServerGroupManager; import com.redhat.rhn.manager.system.SystemManager; import com.redhat.rhn.manager.system.entitling.SystemEntitlementManager; import com.redhat.rhn.manager.system.entitling.SystemEntitler; @@ -103,7 +101,6 @@ import com.redhat.rhn.testing.TestUtils; import com.redhat.rhn.testing.UserTestUtils; -import com.suse.manager.webui.services.iface.MonitoringManager; import com.suse.manager.webui.services.iface.SaltApi; import com.suse.manager.webui.services.iface.SystemQuery; import com.suse.manager.webui.services.test.TestSaltApi; @@ -149,11 +146,8 @@ public class ActionManagerTest extends JMockBaseTestCaseWithUser { private static TaskomaticApi taskomaticApi; private final SystemQuery systemQuery = new TestSystemQuery(); private final SaltApi saltApi = new TestSaltApi(); - private final ServerGroupManager serverGroupManager = new ServerGroupManager(saltApi); - private final MonitoringManager monitoringManager = new FormulaMonitoringManager(saltApi); private final SystemEntitlementManager systemEntitlementManager = new SystemEntitlementManager( - new SystemUnentitler(monitoringManager, serverGroupManager), - new SystemEntitler(saltApi, monitoringManager, serverGroupManager) + new SystemUnentitler(saltApi), new SystemEntitler(saltApi) ); private final SystemManager systemManager = new SystemManager(ServerFactory.SINGLETON, new ServerGroupFactory(), saltApi); diff --git a/java/code/src/com/redhat/rhn/manager/action/test/MinionActionManagerTest.java b/java/code/src/com/redhat/rhn/manager/action/test/MinionActionManagerTest.java index 17c0f647dc86..c349d342c251 100644 --- a/java/code/src/com/redhat/rhn/manager/action/test/MinionActionManagerTest.java +++ b/java/code/src/com/redhat/rhn/manager/action/test/MinionActionManagerTest.java @@ -45,7 +45,6 @@ import com.redhat.rhn.manager.action.MinionActionManager; import com.redhat.rhn.manager.errata.ErrataManager; import com.redhat.rhn.manager.errata.cache.ErrataCacheManager; -import com.redhat.rhn.manager.formula.FormulaMonitoringManager; import com.redhat.rhn.manager.system.ServerGroupManager; import com.redhat.rhn.manager.system.SystemManager; import com.redhat.rhn.manager.system.entitling.SystemEntitlementManager; @@ -60,7 +59,6 @@ import com.suse.manager.attestation.AttestationManager; import com.suse.manager.webui.controllers.bootstrap.RegularMinionBootstrapper; import com.suse.manager.webui.controllers.bootstrap.SSHMinionBootstrapper; -import com.suse.manager.webui.services.iface.MonitoringManager; import com.suse.manager.webui.services.iface.SaltApi; import com.suse.manager.webui.services.iface.SystemQuery; import com.suse.manager.webui.services.test.TestSaltApi; @@ -98,10 +96,8 @@ public class MinionActionManagerTest extends JMockBaseTestCaseWithUser { private final SystemQuery systemQuery = new TestSystemQuery(); private final SaltApi saltApi = new TestSaltApi(); private final ServerGroupManager serverGroupManager = new ServerGroupManager(saltApi); - private final MonitoringManager monitoringManager = new FormulaMonitoringManager(saltApi); private final SystemEntitlementManager systemEntitlementManager = new SystemEntitlementManager( - new SystemUnentitler(monitoringManager, serverGroupManager), - new SystemEntitler(saltApi, monitoringManager, serverGroupManager) + new SystemUnentitler(saltApi), new SystemEntitler(saltApi) ); private final CloudPaygManager paygManager = new TestCloudPaygManagerBuilder().build(); private final AttestationManager attestationManager = new AttestationManager(); diff --git a/java/code/src/com/redhat/rhn/manager/org/test/MigrationManagerTest.java b/java/code/src/com/redhat/rhn/manager/org/test/MigrationManagerTest.java index bc9e8657ae6b..de4fa683045a 100644 --- a/java/code/src/com/redhat/rhn/manager/org/test/MigrationManagerTest.java +++ b/java/code/src/com/redhat/rhn/manager/org/test/MigrationManagerTest.java @@ -36,7 +36,6 @@ import com.redhat.rhn.domain.user.User; import com.redhat.rhn.domain.user.UserFactory; import com.redhat.rhn.manager.entitlement.EntitlementManager; -import com.redhat.rhn.manager.formula.FormulaMonitoringManager; import com.redhat.rhn.manager.org.MigrationManager; import com.redhat.rhn.manager.system.ServerGroupManager; import com.redhat.rhn.manager.system.entitling.SystemEntitlementManager; @@ -47,7 +46,6 @@ import com.redhat.rhn.testing.ServerTestUtils; import com.redhat.rhn.testing.UserTestUtils; -import com.suse.manager.webui.services.iface.MonitoringManager; import com.suse.manager.webui.services.iface.SaltApi; import com.suse.manager.webui.services.test.TestSaltApi; @@ -73,10 +71,8 @@ public class MigrationManagerTest extends BaseTestCaseWithUser { private final SaltApi saltApi = new TestSaltApi(); private final ServerGroupManager serverGroupManager = new ServerGroupManager(saltApi); - private final MonitoringManager monitoringManager = new FormulaMonitoringManager(saltApi); private final SystemEntitlementManager systemEntitlementManager = new SystemEntitlementManager( - new SystemUnentitler(monitoringManager, serverGroupManager), - new SystemEntitler(saltApi, monitoringManager, serverGroupManager) + new SystemUnentitler(saltApi), new SystemEntitler(saltApi) ); private final MigrationManager migrationManager = new MigrationManager(serverGroupManager); diff --git a/java/code/src/com/redhat/rhn/manager/system/SystemManager.java b/java/code/src/com/redhat/rhn/manager/system/SystemManager.java index bc67fcafa3a3..0e0ac2a54285 100644 --- a/java/code/src/com/redhat/rhn/manager/system/SystemManager.java +++ b/java/code/src/com/redhat/rhn/manager/system/SystemManager.java @@ -110,7 +110,6 @@ import com.redhat.rhn.manager.BaseManager; import com.redhat.rhn.manager.channel.ChannelManager; import com.redhat.rhn.manager.entitlement.EntitlementManager; -import com.redhat.rhn.manager.formula.FormulaMonitoringManager; import com.redhat.rhn.manager.kickstart.cobbler.CobblerSystemRemoveCommand; import com.redhat.rhn.manager.rhnset.RhnSetDecl; import com.redhat.rhn.manager.system.entitling.SystemEntitlementManager; @@ -133,7 +132,6 @@ import com.suse.manager.webui.controllers.StatesAPI; import com.suse.manager.webui.services.SaltStateGeneratorService; import com.suse.manager.webui.services.StateRevisionService; -import com.suse.manager.webui.services.iface.MonitoringManager; import com.suse.manager.webui.services.iface.SaltApi; import com.suse.manager.xmlrpc.dto.SystemEventDetailsDto; import com.suse.utils.Opt; @@ -205,11 +203,8 @@ public SystemManager(ServerFactory serverFactoryIn, ServerGroupFactory serverGro this.serverFactory = serverFactoryIn; this.serverGroupFactory = serverGroupFactoryIn; this.saltApi = saltApiIn; - ServerGroupManager serverGroupManager = new ServerGroupManager(saltApiIn); - MonitoringManager monitoringManager = new FormulaMonitoringManager(saltApi); systemEntitlementManager = new SystemEntitlementManager( - new SystemUnentitler(monitoringManager, serverGroupManager), - new SystemEntitler(saltApiIn, monitoringManager, serverGroupManager) + new SystemUnentitler(saltApiIn), new SystemEntitler(saltApiIn) ); } diff --git a/java/code/src/com/redhat/rhn/manager/system/entitling/SystemEntitler.java b/java/code/src/com/redhat/rhn/manager/system/entitling/SystemEntitler.java index 8bc296a702af..07504b3f4e26 100644 --- a/java/code/src/com/redhat/rhn/manager/system/entitling/SystemEntitler.java +++ b/java/code/src/com/redhat/rhn/manager/system/entitling/SystemEntitler.java @@ -24,6 +24,7 @@ import com.redhat.rhn.domain.server.ServerGroup; import com.redhat.rhn.domain.server.ServerGroupFactory; import com.redhat.rhn.manager.entitlement.EntitlementManager; +import com.redhat.rhn.manager.formula.FormulaMonitoringManager; import com.redhat.rhn.manager.system.AnsibleManager; import com.redhat.rhn.manager.system.ServerGroupManager; @@ -46,19 +47,18 @@ public class SystemEntitler { private static final Logger LOG = LogManager.getLogger(SystemEntitler.class); private SaltApi saltApi; + private AnsibleManager ansibleManager; private MonitoringManager monitoringManager; private ServerGroupManager serverGroupManager; /** * @param saltApiIn instance for gathering data from a system. - * @param monitoringManagerIn instance for handling monitoring configuration. - * @param serverGroupManagerIn */ - public SystemEntitler(SaltApi saltApiIn, - MonitoringManager monitoringManagerIn, ServerGroupManager serverGroupManagerIn) { + public SystemEntitler(SaltApi saltApiIn) { this.saltApi = saltApiIn; - this.monitoringManager = monitoringManagerIn; - this.serverGroupManager = serverGroupManagerIn; + this.ansibleManager = new AnsibleManager(saltApiIn); + this.monitoringManager = new FormulaMonitoringManager(saltApiIn); + this.serverGroupManager = new ServerGroupManager(saltApiIn); } /** diff --git a/java/code/src/com/redhat/rhn/manager/system/entitling/SystemUnentitler.java b/java/code/src/com/redhat/rhn/manager/system/entitling/SystemUnentitler.java index dcbc84c8b560..63c37a7cc3cf 100644 --- a/java/code/src/com/redhat/rhn/manager/system/entitling/SystemUnentitler.java +++ b/java/code/src/com/redhat/rhn/manager/system/entitling/SystemUnentitler.java @@ -21,10 +21,12 @@ import com.redhat.rhn.domain.server.Server; import com.redhat.rhn.domain.server.ServerFactory; import com.redhat.rhn.manager.entitlement.EntitlementManager; +import com.redhat.rhn.manager.formula.FormulaMonitoringManager; import com.redhat.rhn.manager.system.AnsibleManager; import com.redhat.rhn.manager.system.ServerGroupManager; import com.suse.manager.webui.services.iface.MonitoringManager; +import com.suse.manager.webui.services.iface.SaltApi; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -40,17 +42,17 @@ public class SystemUnentitler { private static final Logger LOG = LogManager.getLogger(SystemUnentitler.class); + private final AnsibleManager ansibleManager; private final MonitoringManager monitoringManager; private final ServerGroupManager serverGroupManager; /** - * @param monitoringManagerIn instance for handling monitoring configuration. - * @param serverGroupManagerIn + * @param saltApiIn */ - public SystemUnentitler(MonitoringManager monitoringManagerIn, - ServerGroupManager serverGroupManagerIn) { - this.monitoringManager = monitoringManagerIn; - this.serverGroupManager = serverGroupManagerIn; + public SystemUnentitler(SaltApi saltApiIn) { + this.ansibleManager = new AnsibleManager(saltApiIn); + this.monitoringManager = new FormulaMonitoringManager(saltApiIn); + this.serverGroupManager = new ServerGroupManager(saltApiIn); } /** diff --git a/java/code/src/com/redhat/rhn/manager/system/entitling/test/SystemEntitlementManagerTest.java b/java/code/src/com/redhat/rhn/manager/system/entitling/test/SystemEntitlementManagerTest.java index 942a90141802..e04ae1f715fd 100644 --- a/java/code/src/com/redhat/rhn/manager/system/entitling/test/SystemEntitlementManagerTest.java +++ b/java/code/src/com/redhat/rhn/manager/system/entitling/test/SystemEntitlementManagerTest.java @@ -27,8 +27,6 @@ import com.redhat.rhn.domain.server.test.MinionServerFactoryTest; import com.redhat.rhn.domain.user.User; import com.redhat.rhn.manager.entitlement.EntitlementManager; -import com.redhat.rhn.manager.formula.FormulaMonitoringManager; -import com.redhat.rhn.manager.system.ServerGroupManager; import com.redhat.rhn.manager.system.entitling.SystemEntitlementManager; import com.redhat.rhn.manager.system.entitling.SystemEntitler; import com.redhat.rhn.manager.system.entitling.SystemUnentitler; @@ -38,7 +36,6 @@ import com.redhat.rhn.testing.TestUtils; import com.redhat.rhn.testing.UserTestUtils; -import com.suse.manager.webui.services.iface.MonitoringManager; import com.suse.manager.webui.services.impl.SaltSSHService; import com.suse.manager.webui.services.impl.SaltService; import com.suse.salt.netapi.datatypes.target.MinionList; @@ -59,11 +56,9 @@ public void setUp() throws Exception { super.setUp(); setImposteriser(ByteBuddyClassImposteriser.INSTANCE); saltServiceMock = mock(SaltService.class); - ServerGroupManager serverGroupManager = new ServerGroupManager(saltServiceMock); - MonitoringManager monitoringManager = new FormulaMonitoringManager(saltServiceMock); systemEntitlementManager = new SystemEntitlementManager( - new SystemUnentitler(monitoringManager, serverGroupManager), - new SystemEntitler(saltServiceMock, monitoringManager, serverGroupManager) + new SystemUnentitler(saltServiceMock), + new SystemEntitler(saltServiceMock) ); context().checking(new Expectations() {{ allowing(saltServiceMock).refreshPillar(with(any(MinionList.class))); diff --git a/java/code/src/com/redhat/rhn/manager/system/test/AnsibleManagerTest.java b/java/code/src/com/redhat/rhn/manager/system/test/AnsibleManagerTest.java index df9ce3562db5..587f0f7c780d 100644 --- a/java/code/src/com/redhat/rhn/manager/system/test/AnsibleManagerTest.java +++ b/java/code/src/com/redhat/rhn/manager/system/test/AnsibleManagerTest.java @@ -29,9 +29,7 @@ import com.redhat.rhn.domain.server.test.MinionServerFactoryTest; import com.redhat.rhn.domain.user.User; import com.redhat.rhn.manager.entitlement.EntitlementManager; -import com.redhat.rhn.manager.formula.FormulaMonitoringManager; import com.redhat.rhn.manager.system.AnsibleManager; -import com.redhat.rhn.manager.system.ServerGroupManager; import com.redhat.rhn.manager.system.entitling.SystemEntitlementManager; import com.redhat.rhn.manager.system.entitling.SystemEntitler; import com.redhat.rhn.manager.system.entitling.SystemUnentitler; @@ -39,7 +37,6 @@ import com.redhat.rhn.testing.TestUtils; import com.redhat.rhn.testing.UserTestUtils; -import com.suse.manager.webui.services.iface.MonitoringManager; import com.suse.manager.webui.services.iface.SaltApi; import com.suse.manager.webui.utils.salt.custom.AnsiblePlaybookSlsResult; import com.suse.salt.netapi.calls.LocalCall; @@ -89,7 +86,7 @@ public void testSaveAndLookupAnsiblePath() throws Exception { MinionServer minion = createAnsibleControlNode(user); AnsiblePath path = new InventoryPath(minion); path.setPath(Path.of("/tmp/test1")); - path = AnsibleManager.createAnsiblePath("inventory", minion.getId(), "/tmp/test", user); + path = ansibleManager.createAnsiblePath("inventory", minion.getId(), "/tmp/test", user); HibernateFactory.getSession().flush(); HibernateFactory.getSession().evict(path); @@ -110,7 +107,7 @@ public void testSaveAndLookupAnsiblePathNoPerms() throws Exception { path.setPath(Path.of("/tmp/test1")); try { - AnsibleManager.createAnsiblePath("inventory", minion.getId(), "/tmp/test", chuck); + ansibleManager.createAnsiblePath("inventory", minion.getId(), "/tmp/test", chuck); fail("An exception should have been thrown."); } catch (LookupException e) { @@ -118,7 +115,7 @@ public void testSaveAndLookupAnsiblePathNoPerms() throws Exception { } // now save with allowed user - path = AnsibleManager.createAnsiblePath("inventory", minion.getId(), "/tmp/test", user); + path = ansibleManager.createAnsiblePath("inventory", minion.getId(), "/tmp/test", user); try { AnsibleManager.lookupAnsiblePathById(path.getId(), chuck); @@ -143,7 +140,7 @@ public void testSaveAndLookupAnsiblePathNoPerms() throws Exception { @Test public void testUpdateNonExistingAnsiblePath() { try { - AnsibleManager.updateAnsiblePath(-12345, "/tmp/test", user); + ansibleManager.updateAnsiblePath(-12345, "/tmp/test", user); fail("An exception should have been thrown."); } catch (LookupException e) { @@ -159,8 +156,8 @@ public void testUpdateNonExistingAnsiblePath() { @Test public void testUpdateAnsiblePath() throws Exception { MinionServer minion = createAnsibleControlNode(user); - AnsiblePath path = AnsibleManager.createAnsiblePath("inventory", minion.getId(), "/tmp/test", user); - path = AnsibleManager.updateAnsiblePath(path.getId(), "/tmp/test-updated", user); + AnsiblePath path = ansibleManager.createAnsiblePath("inventory", minion.getId(), "/tmp/test", user); + path = ansibleManager.updateAnsiblePath(path.getId(), "/tmp/test-updated", user); HibernateFactory.getSession().flush(); HibernateFactory.getSession().evict(path); AnsiblePath updated = AnsibleManager.lookupAnsiblePathById(path.getId(), user).get(); @@ -172,7 +169,7 @@ public void testCreateAnsiblePathNormalSystem() throws Exception { MinionServer minion = MinionServerFactoryTest.createTestMinionServer(user); try { - AnsibleManager.createAnsiblePath("inventory", minion.getId(), "/tmp/test", user); + ansibleManager.createAnsiblePath("inventory", minion.getId(), "/tmp/test", user); fail("An exception should have been thrown."); } catch (LookupException e) { @@ -189,7 +186,7 @@ public void testCreateAnsiblePathNormalSystem() throws Exception { public void testSaveAnsibleRelativePath() throws Exception { MinionServer minion = createAnsibleControlNode(user); try { - AnsibleManager.createAnsiblePath("inventory", minion.getId(), "relative/path", user); + ansibleManager.createAnsiblePath("inventory", minion.getId(), "relative/path", user); fail("An exception should have been thrown."); } catch (ValidatorException e) { @@ -217,7 +214,7 @@ public void testFetchPlaybookInvalidPath() { @Test public void testFetchPlaybookAbsolutePath() throws Exception { MinionServer controlNode = createAnsibleControlNode(user); - AnsiblePath path = AnsibleManager.createAnsiblePath("playbook", controlNode.getId(), "/root/playbooks", user); + AnsiblePath path = ansibleManager.createAnsiblePath("playbook", controlNode.getId(), "/root/playbooks", user); try { ansibleManager.fetchPlaybookContents(path.getId(), "/absolute", user); @@ -234,7 +231,7 @@ public void testFetchPlaybookAbsolutePath() throws Exception { @Test public void testFetchPlaybook() throws Exception { MinionServer controlNode = createAnsibleControlNode(user); - AnsiblePath path = AnsibleManager.createAnsiblePath("playbook", controlNode.getId(), "/root/playbooks", user); + AnsiblePath path = ansibleManager.createAnsiblePath("playbook", controlNode.getId(), "/root/playbooks", user); context.checking(new Expectations() {{ allowing(saltApi).callSync(with(any(LocalCall.class)), with(controlNode.getMinionId())); @@ -252,7 +249,7 @@ public void testFetchPlaybook() throws Exception { @Test public void testFetchPlaybookSaltNoResult() throws Exception { MinionServer controlNode = createAnsibleControlNode(user); - AnsiblePath path = AnsibleManager.createAnsiblePath("playbook", controlNode.getId(), "/root/playbooks", user); + AnsiblePath path = ansibleManager.createAnsiblePath("playbook", controlNode.getId(), "/root/playbooks", user); context.checking(new Expectations() {{ allowing(saltApi).callSync(with(any(LocalCall.class)), with(controlNode.getMinionId())); @@ -311,7 +308,7 @@ public void testSchedulePlaybookNonexistingMinion() throws Exception { @Test public void testDiscoverPlaybooks() throws Exception { MinionServer controlNode = createAnsibleControlNode(user); - AnsiblePath playbookPath = AnsibleManager.createAnsiblePath("playbook", controlNode.getId(), "/tmp/test", user); + AnsiblePath playbookPath = ansibleManager.createAnsiblePath("playbook", controlNode.getId(), "/tmp/test", user); Map> expected = Map.of("/tmp/test", Map.of("site.yml", new AnsiblePlaybookSlsResult("/tmp/test/site.yml", "/tmp/test/hosts"))); @@ -334,7 +331,7 @@ public void testDiscoverPlaybooks() throws Exception { @Test public void testDiscoverPlaybooksSaltError() throws Exception { MinionServer controlNode = createAnsibleControlNode(user); - AnsiblePath playbookPath = AnsibleManager.createAnsiblePath("playbook", controlNode.getId(), "/tmp/test", user); + AnsiblePath playbookPath = ansibleManager.createAnsiblePath("playbook", controlNode.getId(), "/tmp/test", user); context.checking(new Expectations() {{ allowing(saltApi).callSync(with(any(LocalCall.class)), with(controlNode.getMinionId())); @@ -373,7 +370,7 @@ public void testDiscoverPlaybooksNonExistingPath() { @Test public void testDiscoverPlaybooksInInventory() throws Exception { MinionServer controlNode = createAnsibleControlNode(user); - AnsiblePath inventoryPath = AnsibleManager.createAnsiblePath( + AnsiblePath inventoryPath = ansibleManager.createAnsiblePath( "inventory", controlNode.getId(), "/tmp/test/hosts", user); try { ansibleManager.discoverPlaybooks(inventoryPath.getId(), user); @@ -390,7 +387,7 @@ public void testDiscoverPlaybooksInInventory() throws Exception { @Test public void testIntrospectInventory() throws Exception { MinionServer controlNode = createAnsibleControlNode(user); - AnsiblePath inventoryPath = AnsibleManager.createAnsiblePath( + AnsiblePath inventoryPath = ansibleManager.createAnsiblePath( "inventory", controlNode.getId(), "/tmp/test/hosts", user); Map>>> expected = @@ -412,7 +409,7 @@ public void testIntrospectInventory() throws Exception { @Test public void testIntrospectInventorySaltError() throws Exception { MinionServer controlNode = createAnsibleControlNode(user); - AnsiblePath inventoryPath = AnsibleManager.createAnsiblePath( + AnsiblePath inventoryPath = ansibleManager.createAnsiblePath( "inventory", controlNode.getId(), "/tmp/test/hosts", user); context.checking(new Expectations() {{ @@ -451,7 +448,7 @@ public void testIntrospectInventoryNonExistingPath() { @Test public void testIntrospectInventoryInPlaybook() throws Exception { MinionServer controlNode = createAnsibleControlNode(user); - AnsiblePath playbookPath = AnsibleManager.createAnsiblePath("playbook", controlNode.getId(), "/tmp/test", user); + AnsiblePath playbookPath = ansibleManager.createAnsiblePath("playbook", controlNode.getId(), "/tmp/test", user); try { ansibleManager.introspectInventory(playbookPath.getId(), user); fail("An exception should have been thrown."); @@ -462,11 +459,8 @@ public void testIntrospectInventoryInPlaybook() throws Exception { } private MinionServer createAnsibleControlNode(User user) throws Exception { - MonitoringManager monitoringManager = new FormulaMonitoringManager(saltApi); - ServerGroupManager groupManager = new ServerGroupManager(saltApi); SystemEntitlementManager entitlementManager = new SystemEntitlementManager( - new SystemUnentitler(monitoringManager, groupManager), - new SystemEntitler(saltApi, monitoringManager, groupManager) + new SystemUnentitler(saltApi), new SystemEntitler(saltApi) ); context.checking(new Expectations() {{ diff --git a/java/code/src/com/redhat/rhn/manager/system/test/SystemManagerTest.java b/java/code/src/com/redhat/rhn/manager/system/test/SystemManagerTest.java index 6873def13aef..c9fcb0e9769d 100644 --- a/java/code/src/com/redhat/rhn/manager/system/test/SystemManagerTest.java +++ b/java/code/src/com/redhat/rhn/manager/system/test/SystemManagerTest.java @@ -110,13 +110,11 @@ import com.redhat.rhn.manager.content.MgrSyncUtils; import com.redhat.rhn.manager.entitlement.EntitlementManager; import com.redhat.rhn.manager.errata.cache.ErrataCacheManager; -import com.redhat.rhn.manager.formula.FormulaMonitoringManager; import com.redhat.rhn.manager.kickstart.cobbler.CobblerXMLRPCHelper; import com.redhat.rhn.manager.kickstart.cobbler.test.MockXMLRPCInvoker; import com.redhat.rhn.manager.rhnpackage.test.PackageManagerTest; import com.redhat.rhn.manager.rhnset.RhnSetDecl; import com.redhat.rhn.manager.rhnset.RhnSetManager; -import com.redhat.rhn.manager.system.ServerGroupManager; import com.redhat.rhn.manager.system.SystemManager; import com.redhat.rhn.manager.system.SystemsExistException; import com.redhat.rhn.manager.system.entitling.SystemEntitlementManager; @@ -137,7 +135,6 @@ import com.suse.manager.ssl.SSLCertManager; import com.suse.manager.ssl.SSLCertPair; import com.suse.manager.webui.controllers.utils.ContactMethodUtil; -import com.suse.manager.webui.services.iface.MonitoringManager; import com.suse.manager.webui.services.iface.SaltApi; import com.suse.manager.webui.services.impl.SaltSSHService; import com.suse.manager.webui.services.impl.SaltService; @@ -219,11 +216,8 @@ public void setUp() throws Exception { } }); SaltApi saltApi = new TestSaltApi(); - MonitoringManager monitoringManager = new FormulaMonitoringManager(saltApi); - ServerGroupManager serverGroupManager = new ServerGroupManager(saltApi); systemEntitlementManager = new SystemEntitlementManager( - new SystemUnentitler(monitoringManager, serverGroupManager), - new SystemEntitler(saltApi, monitoringManager, serverGroupManager) + new SystemUnentitler(saltApi), new SystemEntitler(saltApi) ); this.systemManager = new SystemManager(ServerFactory.SINGLETON, ServerGroupFactory.SINGLETON, saltServiceMock); createMetadataFiles(); diff --git a/java/code/src/com/redhat/rhn/taskomatic/task/payg/test/PaygComputeDimensionsTaskTest.java b/java/code/src/com/redhat/rhn/taskomatic/task/payg/test/PaygComputeDimensionsTaskTest.java index 28111beb8852..1f24c4ca10f9 100644 --- a/java/code/src/com/redhat/rhn/taskomatic/task/payg/test/PaygComputeDimensionsTaskTest.java +++ b/java/code/src/com/redhat/rhn/taskomatic/task/payg/test/PaygComputeDimensionsTaskTest.java @@ -27,8 +27,6 @@ import com.redhat.rhn.domain.server.test.MinionServerFactoryTest; import com.redhat.rhn.domain.server.test.ServerFactoryTest; import com.redhat.rhn.manager.entitlement.EntitlementManager; -import com.redhat.rhn.manager.formula.FormulaMonitoringManager; -import com.redhat.rhn.manager.system.ServerGroupManager; import com.redhat.rhn.manager.system.entitling.SystemEntitlementManager; import com.redhat.rhn.manager.system.entitling.SystemEntitler; import com.redhat.rhn.manager.system.entitling.SystemUnentitler; @@ -41,7 +39,6 @@ import com.suse.cloud.domain.PaygDimensionComputation; import com.suse.cloud.domain.PaygDimensionFactory; import com.suse.cloud.test.TestCloudPaygManagerBuilder; -import com.suse.manager.webui.services.iface.MonitoringManager; import com.suse.manager.webui.services.iface.SaltApi; import com.suse.manager.webui.services.test.TestSaltApi; @@ -71,12 +68,8 @@ public void before() { factory = new PaygDimensionFactory(); SaltApi saltApi = new TestSaltApi(); - ServerGroupManager serverGroupManager = new ServerGroupManager(saltApi); - MonitoringManager monitoringManager = new FormulaMonitoringManager(saltApi); - systemEntitlementManager = new SystemEntitlementManager( - new SystemUnentitler(monitoringManager, serverGroupManager), - new SystemEntitler(saltApi, monitoringManager, serverGroupManager) + new SystemUnentitler(saltApi), new SystemEntitler(saltApi) ); } diff --git a/java/code/src/com/suse/manager/hub/test/HubManagerTest.java b/java/code/src/com/suse/manager/hub/test/HubManagerTest.java index f8edd4f592c2..4b4681bef9c7 100644 --- a/java/code/src/com/suse/manager/hub/test/HubManagerTest.java +++ b/java/code/src/com/suse/manager/hub/test/HubManagerTest.java @@ -35,9 +35,7 @@ import com.redhat.rhn.domain.user.User; import com.redhat.rhn.domain.user.UserFactory; import com.redhat.rhn.manager.entitlement.EntitlementManager; -import com.redhat.rhn.manager.formula.FormulaMonitoringManager; import com.redhat.rhn.manager.setup.MirrorCredentialsManager; -import com.redhat.rhn.manager.system.ServerGroupManager; import com.redhat.rhn.manager.system.entitling.SystemEntitlementManager; import com.redhat.rhn.manager.system.entitling.SystemEntitler; import com.redhat.rhn.manager.system.entitling.SystemUnentitler; @@ -58,7 +56,6 @@ import com.suse.manager.model.hub.IssServer; import com.suse.manager.model.hub.ManagerInfoJson; import com.suse.manager.model.hub.TokenType; -import com.suse.manager.webui.services.iface.MonitoringManager; import com.suse.manager.webui.services.iface.SaltApi; import com.suse.manager.webui.services.test.TestSaltApi; import com.suse.manager.webui.utils.token.IssTokenBuilder; @@ -228,11 +225,8 @@ public void setUp() throws Exception { mockTaskomaticApi = new MockTaskomaticApi(); SaltApi saltApi = new TestSaltApi(); - MonitoringManager monitoringManager = new FormulaMonitoringManager(saltApi); - ServerGroupManager serverGroupManager = new ServerGroupManager(saltApi); SystemEntitlementManager sysEntMgr = new SystemEntitlementManager( - new SystemUnentitler(monitoringManager, serverGroupManager), - new SystemEntitler(saltApi, monitoringManager, serverGroupManager) + new SystemUnentitler(saltApi), new SystemEntitler(saltApi) ); hubManager = new HubManager(hubFactory, clientFactoryMock, new MirrorCredentialsManager(), mockTaskomaticApi, diff --git a/java/code/src/com/suse/manager/matcher/test/MatcherJsonIOTest.java b/java/code/src/com/suse/manager/matcher/test/MatcherJsonIOTest.java index bd89402e54b8..64c03c8c5585 100644 --- a/java/code/src/com/suse/manager/matcher/test/MatcherJsonIOTest.java +++ b/java/code/src/com/suse/manager/matcher/test/MatcherJsonIOTest.java @@ -40,8 +40,6 @@ import com.redhat.rhn.manager.action.ActionManager; import com.redhat.rhn.manager.content.ContentSyncManager; import com.redhat.rhn.manager.entitlement.EntitlementManager; -import com.redhat.rhn.manager.formula.FormulaMonitoringManager; -import com.redhat.rhn.manager.system.ServerGroupManager; import com.redhat.rhn.manager.system.entitling.SystemEntitlementManager; import com.redhat.rhn.manager.system.entitling.SystemEntitler; import com.redhat.rhn.manager.system.entitling.SystemUnentitler; @@ -52,7 +50,6 @@ import com.suse.manager.maintenance.BaseProductManager; import com.suse.manager.matcher.MatcherJsonIO; -import com.suse.manager.webui.services.iface.MonitoringManager; import com.suse.manager.webui.services.iface.SaltApi; import com.suse.manager.webui.services.test.TestSaltApi; import com.suse.matcher.json.MatchJson; @@ -108,11 +105,8 @@ public void setUp() throws Exception { setImposteriser(ByteBuddyClassImposteriser.INSTANCE); SaltApi saltApi = new TestSaltApi(); - MonitoringManager monitoringManager = new FormulaMonitoringManager(saltApi); - ServerGroupManager serverGroupManager = new ServerGroupManager(saltApi); systemEntitlementManager = new SystemEntitlementManager( - new SystemUnentitler(monitoringManager, serverGroupManager), - new SystemEntitler(saltApi, monitoringManager, serverGroupManager) + new SystemUnentitler(saltApi), new SystemEntitler(saltApi) ); baseProductManagerMock = mock(BaseProductManager.class); diff --git a/java/code/src/com/suse/manager/reactor/messaging/RegisterMinionEventMessageAction.java b/java/code/src/com/suse/manager/reactor/messaging/RegisterMinionEventMessageAction.java index a2e81f64674f..19942f6470c5 100644 --- a/java/code/src/com/suse/manager/reactor/messaging/RegisterMinionEventMessageAction.java +++ b/java/code/src/com/suse/manager/reactor/messaging/RegisterMinionEventMessageAction.java @@ -47,8 +47,6 @@ import com.redhat.rhn.domain.user.User; import com.redhat.rhn.manager.action.ActionManager; import com.redhat.rhn.manager.entitlement.EntitlementManager; -import com.redhat.rhn.manager.formula.FormulaMonitoringManager; -import com.redhat.rhn.manager.system.ServerGroupManager; import com.redhat.rhn.manager.system.SystemManager; import com.redhat.rhn.manager.system.entitling.SystemEntitlementManager; import com.redhat.rhn.manager.system.entitling.SystemEntitler; @@ -63,7 +61,6 @@ import com.suse.manager.webui.controllers.StatesAPI; import com.suse.manager.webui.services.SaltActionChainGeneratorService; import com.suse.manager.webui.services.SaltStateGeneratorService; -import com.suse.manager.webui.services.iface.MonitoringManager; import com.suse.manager.webui.services.iface.SaltApi; import com.suse.manager.webui.services.iface.SystemQuery; import com.suse.manager.webui.services.impl.MinionPendingRegistrationService; @@ -132,11 +129,8 @@ public RegisterMinionEventMessageAction(SystemQuery systemQueryIn, SaltApi saltA systemQuery = systemQueryIn; cloudPaygManager = paygMgrIn; attestationManager = attMgrIn; - MonitoringManager monitoringManager = new FormulaMonitoringManager(saltApi); - ServerGroupManager groupManager = new ServerGroupManager(saltApi); entitlementManager = new SystemEntitlementManager( - new SystemUnentitler(monitoringManager, groupManager), - new SystemEntitler(saltApi, monitoringManager, groupManager) + new SystemUnentitler(saltApi), new SystemEntitler(saltApi) ); } diff --git a/java/code/src/com/suse/manager/reactor/messaging/test/JobReturnEventMessageActionTest.java b/java/code/src/com/suse/manager/reactor/messaging/test/JobReturnEventMessageActionTest.java index 5c92df31313a..f4e59ef2143f 100644 --- a/java/code/src/com/suse/manager/reactor/messaging/test/JobReturnEventMessageActionTest.java +++ b/java/code/src/com/suse/manager/reactor/messaging/test/JobReturnEventMessageActionTest.java @@ -65,8 +65,6 @@ import com.redhat.rhn.manager.action.ActionChainManager; import com.redhat.rhn.manager.action.ActionManager; import com.redhat.rhn.manager.entitlement.EntitlementManager; -import com.redhat.rhn.manager.formula.FormulaMonitoringManager; -import com.redhat.rhn.manager.system.ServerGroupManager; import com.redhat.rhn.manager.system.SystemManager; import com.redhat.rhn.manager.system.entitling.SystemEntitlementManager; import com.redhat.rhn.manager.system.entitling.SystemEntitler; @@ -85,7 +83,6 @@ import com.suse.manager.utils.SaltKeyUtils; import com.suse.manager.utils.SaltUtils; import com.suse.manager.webui.services.SaltServerActionService; -import com.suse.manager.webui.services.iface.MonitoringManager; import com.suse.manager.webui.services.impl.SaltSSHService; import com.suse.manager.webui.services.impl.SaltService; import com.suse.manager.webui.services.impl.runner.MgrUtilRunner; @@ -157,11 +154,8 @@ public void setUp() throws Exception { Config.get().setString("server.secret_key", DigestUtils.sha256Hex(TestUtils.randomString())); saltServiceMock = context().mock(SaltService.class); - ServerGroupManager serverGroupManager = new ServerGroupManager(saltServiceMock); - MonitoringManager monitoringManager = new FormulaMonitoringManager(saltServiceMock); systemEntitlementManager = new SystemEntitlementManager( - new SystemUnentitler(monitoringManager, serverGroupManager), - new SystemEntitler(saltServiceMock, monitoringManager, serverGroupManager) + new SystemUnentitler(saltServiceMock), new SystemEntitler(saltServiceMock) ); saltUtils = new SaltUtils(saltServiceMock, saltServiceMock); saltServerActionService = new SaltServerActionService(saltServiceMock, saltUtils, diff --git a/java/code/src/com/suse/manager/webui/controllers/test/SystemsControllerTest.java b/java/code/src/com/suse/manager/webui/controllers/test/SystemsControllerTest.java index 18d380115eea..1d08de57a3fc 100644 --- a/java/code/src/com/suse/manager/webui/controllers/test/SystemsControllerTest.java +++ b/java/code/src/com/suse/manager/webui/controllers/test/SystemsControllerTest.java @@ -23,8 +23,6 @@ import com.redhat.rhn.domain.role.RoleFactory; import com.redhat.rhn.domain.server.Server; import com.redhat.rhn.domain.server.VirtualInstance; -import com.redhat.rhn.manager.formula.FormulaMonitoringManager; -import com.redhat.rhn.manager.system.ServerGroupManager; import com.redhat.rhn.manager.system.SystemManager; import com.redhat.rhn.manager.system.entitling.SystemEntitlementManager; import com.redhat.rhn.manager.system.entitling.SystemEntitler; @@ -33,7 +31,6 @@ import com.redhat.rhn.testing.SparkTestUtils; import com.suse.manager.webui.controllers.SystemsController; -import com.suse.manager.webui.services.iface.MonitoringManager; import com.suse.manager.webui.services.iface.SaltApi; import com.suse.manager.webui.services.test.TestSaltApi; @@ -81,11 +78,8 @@ public void setUp() throws Exception { SaltApi saltApi = new TestSaltApi(); systemsController = new SystemsController(saltApi); - MonitoringManager monitoringManager = new FormulaMonitoringManager(saltApi); - ServerGroupManager serverGroupManager = new ServerGroupManager(saltApi); SystemEntitlementManager systemEntitlementManager = new SystemEntitlementManager( - new SystemUnentitler(monitoringManager, serverGroupManager), - new SystemEntitler(new TestSaltApi(), monitoringManager, serverGroupManager) + new SystemUnentitler(saltApi), new SystemEntitler(saltApi) ); serversByHostServerName = new HashMap<>(); diff --git a/java/code/src/com/suse/scc/test/SCCSystemRegistrationManagerTest.java b/java/code/src/com/suse/scc/test/SCCSystemRegistrationManagerTest.java index 0944f635c930..70dedbb834a7 100644 --- a/java/code/src/com/suse/scc/test/SCCSystemRegistrationManagerTest.java +++ b/java/code/src/com/suse/scc/test/SCCSystemRegistrationManagerTest.java @@ -31,8 +31,6 @@ import com.redhat.rhn.domain.server.VirtualInstanceFactory; import com.redhat.rhn.domain.server.test.CPUTest; import com.redhat.rhn.manager.entitlement.EntitlementManager; -import com.redhat.rhn.manager.formula.FormulaMonitoringManager; -import com.redhat.rhn.manager.system.ServerGroupManager; import com.redhat.rhn.manager.system.entitling.SystemEntitlementManager; import com.redhat.rhn.manager.system.entitling.SystemEntitler; import com.redhat.rhn.manager.system.entitling.SystemUnentitler; @@ -40,7 +38,6 @@ import com.redhat.rhn.testing.ServerTestUtils; import com.suse.manager.webui.services.SaltStateGeneratorService; -import com.suse.manager.webui.services.iface.MonitoringManager; import com.suse.manager.webui.services.iface.SaltApi; import com.suse.manager.webui.services.test.TestSaltApi; import com.suse.scc.SCCSystemRegistrationManager; @@ -337,11 +334,8 @@ public void testVirtualInfoLibvirt() throws Exception { SaltStateGeneratorService.INSTANCE.setSkipSetOwner(true); SaltApi saltApi = new TestSaltApi(); - MonitoringManager monitoringManager = new FormulaMonitoringManager(saltApi); - ServerGroupManager serverGroupManager = new ServerGroupManager(saltApi); SystemEntitlementManager sysEntMgr = new SystemEntitlementManager( - new SystemUnentitler(monitoringManager, serverGroupManager), - new SystemEntitler(saltApi, monitoringManager, serverGroupManager) + new SystemUnentitler(saltApi), new SystemEntitler(saltApi) ); Server host = ServerTestUtils.createVirtHostWithGuests(user, 2, true, sysEntMgr); @@ -426,11 +420,8 @@ public void testVirtualInfoVMware() throws Exception { SaltStateGeneratorService.INSTANCE.setSkipSetOwner(true); SaltApi saltApi = new TestSaltApi(); - MonitoringManager monitoringManager = new FormulaMonitoringManager(saltApi); - ServerGroupManager serverGroupManager = new ServerGroupManager(saltApi); SystemEntitlementManager sysEntMgr = new SystemEntitlementManager( - new SystemUnentitler(monitoringManager, serverGroupManager), - new SystemEntitler(saltApi, monitoringManager, serverGroupManager) + new SystemUnentitler(saltApi), new SystemEntitler(saltApi) ); Server host = ServerTestUtils.createVirtHostWithGuests(user, 2, true, sysEntMgr); @@ -524,11 +515,8 @@ public void testVirtualInfoCloud() throws Exception { SaltStateGeneratorService.INSTANCE.setSkipSetOwner(true); SaltApi saltApi = new TestSaltApi(); - MonitoringManager monitoringManager = new FormulaMonitoringManager(saltApi); - ServerGroupManager serverGroupManager = new ServerGroupManager(saltApi); SystemEntitlementManager sysEntMgr = new SystemEntitlementManager( - new SystemUnentitler(monitoringManager, serverGroupManager), - new SystemEntitler(saltApi, monitoringManager, serverGroupManager) + new SystemUnentitler(saltApi), new SystemEntitler(saltApi) ); Server host = ServerTestUtils.createVirtHostWithGuests(user, 2, true, sysEntMgr); From 8c970b9462f75d53b99a35f7096b0b87b36b81bd Mon Sep 17 00:00:00 2001 From: Pascal Arlt Date: Tue, 25 Feb 2025 18:06:12 +0100 Subject: [PATCH 18/20] Make methods using SaltApi non static to allow unit test mocking Signed-off-by: Pascal Arlt --- .../xmlrpc/ansible/AnsibleHandler.java | 6 ++--- .../rhn/manager/system/AnsibleManager.java | 26 +++++++++---------- .../system/entitling/SystemEntitler.java | 2 +- .../system/entitling/SystemUnentitler.java | 2 +- .../webui/controllers/AnsibleController.java | 6 ++--- 5 files changed, 20 insertions(+), 22 deletions(-) diff --git a/java/code/src/com/redhat/rhn/frontend/xmlrpc/ansible/AnsibleHandler.java b/java/code/src/com/redhat/rhn/frontend/xmlrpc/ansible/AnsibleHandler.java index f60e87d0e80f..b6237b950ec2 100644 --- a/java/code/src/com/redhat/rhn/frontend/xmlrpc/ansible/AnsibleHandler.java +++ b/java/code/src/com/redhat/rhn/frontend/xmlrpc/ansible/AnsibleHandler.java @@ -272,7 +272,7 @@ public AnsiblePath createAnsiblePath(User loggedInUser, Map prop String path = getFieldValue(props, "path"); try { - return AnsibleManager.createAnsiblePath(typeLabel, controlNodeId, path, loggedInUser); + return ansibleManager.createAnsiblePath(typeLabel, controlNodeId, path, loggedInUser); } catch (LookupException e) { throw new EntityNotExistsFaultException(controlNodeId); @@ -303,7 +303,7 @@ public AnsiblePath createAnsiblePath(User loggedInUser, Map prop public AnsiblePath updateAnsiblePath(User loggedInUser, Integer pathId, Map props) { try { String newPath = getFieldValue(props, "path"); - return AnsibleManager.updateAnsiblePath(pathId, newPath, loggedInUser); + return ansibleManager.updateAnsiblePath(pathId, newPath, loggedInUser); } catch (LookupException e) { throw new EntityNotExistsFaultException(pathId); @@ -329,7 +329,7 @@ public AnsiblePath updateAnsiblePath(User loggedInUser, Integer pathId, Map listAnsibleInventoryPaths(long minionId, User * @throws LookupException if the user does not have permissions or server not found * @throws ValidatorException if the validation fails */ - public static AnsiblePath createAnsiblePath(String typeLabel, long minionServerId, String path, User user) { + public AnsiblePath createAnsiblePath(String typeLabel, long minionServerId, String path, User user) { MinionServer minionServer = lookupAnsibleControlNode(minionServerId, user); return createAnsiblePath(typeLabel, minionServer, path); } @@ -157,7 +157,7 @@ public static AnsiblePath createAnsiblePath(String typeLabel, long minionServerI * @throws LookupException if the user does not have permissions or server not found * @throws ValidatorException if the validation fails */ - public static AnsiblePath createAnsiblePath(String typeLabel, MinionServer minionServer, String path) { + public AnsiblePath createAnsiblePath(String typeLabel, MinionServer minionServer, String path) { validateAnsiblePath(path, of(typeLabel), empty(), minionServer.getId()); AnsiblePath ansiblePath; @@ -190,7 +190,7 @@ public static AnsiblePath createAnsiblePath(String typeLabel, MinionServer minio // Refresh inotify beacon MinionPillarManager.INSTANCE.generatePillar(minionServer, false, MinionPillarManager.PillarSubset.GENERAL); - GlobalInstanceHolder.SALT_API.refreshPillar(new MinionList(minionServer.getMinionId())); + saltApi.refreshPillar(new MinionList(minionServer.getMinionId())); } return ansiblePath; @@ -206,7 +206,7 @@ public static AnsiblePath createAnsiblePath(String typeLabel, MinionServer minio * @throws LookupException if the user does not have permissions or existing path not found * @throws ValidatorException if the validation fails */ - public static AnsiblePath updateAnsiblePath(long existingPathId, String newPath, User user) { + public AnsiblePath updateAnsiblePath(long existingPathId, String newPath, User user) { AnsiblePath existing = lookupAnsiblePathById(existingPathId, user) .orElseThrow(() -> new LookupException("Ansible path id " + existingPathId + " not found.")); if (existing.getPath().toString().equals(newPath)) { @@ -231,7 +231,7 @@ public static AnsiblePath updateAnsiblePath(long existingPathId, String newPath, // Refresh inotify beacon MinionPillarManager.INSTANCE.generatePillar(existing.getMinionServer(), false, MinionPillarManager.PillarSubset.GENERAL); - GlobalInstanceHolder.SALT_API.refreshPillar(new MinionList(existing.getMinionServer().getMinionId())); + saltApi.refreshPillar(new MinionList(existing.getMinionServer().getMinionId())); } else { AnsibleFactory.saveAnsiblePath(existing); @@ -295,7 +295,7 @@ private static void validateAnsiblePath(String path, Optional typeLabel, * @param user the user performing the action * @throws LookupException if the user does not have permissions or if entity does not exist */ - public static void removeAnsiblePath(long pathId, User user) { + public void removeAnsiblePath(long pathId, User user) { AnsiblePath path = lookupAnsiblePathById(pathId, user) .orElseThrow(() -> new LookupException("Ansible path id " + pathId + " not found.")); @@ -307,7 +307,7 @@ public static void removeAnsiblePath(long pathId, User user) { // Refresh inotify beacon MinionPillarManager.INSTANCE.generatePillar(path.getMinionServer(), false, MinionPillarManager.PillarSubset.GENERAL); - GlobalInstanceHolder.SALT_API.refreshPillar(new MinionList(path.getMinionServer().getMinionId())); + saltApi.refreshPillar(new MinionList(path.getMinionServer().getMinionId())); } else { AnsibleFactory.removeAnsiblePath(path); @@ -319,7 +319,7 @@ public static void removeAnsiblePath(long pathId, User user) { * * @param minionServer the minion server */ - public static void removeAnsiblePaths(MinionServer minionServer) { + public void removeAnsiblePaths(MinionServer minionServer) { List paths = AnsibleFactory.listAnsiblePaths(minionServer.getId()); Set systemsToRemove = new HashSet<>(); paths.forEach(p -> { @@ -335,7 +335,7 @@ public static void removeAnsiblePaths(MinionServer minionServer) { updateAnsibleManagedSystems(new HashSet<>(), systemsToRemove); } MinionPillarManager.INSTANCE.generatePillar(minionServer, false, MinionPillarManager.PillarSubset.GENERAL); - GlobalInstanceHolder.SALT_API.refreshPillar(new MinionList(minionServer.getMinionId())); + saltApi.refreshPillar(new MinionList(minionServer.getMinionId())); } /** @@ -574,19 +574,17 @@ public static void updateAnsibleManagedSystems(Set systemsToAdd, Set { if (EntitlementManager.ANSIBLE_CONTROL_NODE.equals(ent)) { - AnsibleManager.createDefaultPaths(minion); + ansibleManager.createDefaultPaths(minion); } serverGroupManager.updatePillarAfterGroupUpdateForServers(Arrays.asList(minion)); diff --git a/java/code/src/com/redhat/rhn/manager/system/entitling/SystemUnentitler.java b/java/code/src/com/redhat/rhn/manager/system/entitling/SystemUnentitler.java index 63c37a7cc3cf..1e8c8fba3b45 100644 --- a/java/code/src/com/redhat/rhn/manager/system/entitling/SystemUnentitler.java +++ b/java/code/src/com/redhat/rhn/manager/system/entitling/SystemUnentitler.java @@ -87,7 +87,7 @@ public void removeServerEntitlement(Server server, Entitlement ent) { server.asMinionServer().ifPresent(s -> { if (EntitlementManager.ANSIBLE_CONTROL_NODE.equals(ent)) { - AnsibleManager.removeAnsiblePaths(s); + ansibleManager.removeAnsiblePaths(s); } serverGroupManager.updatePillarAfterGroupUpdateForServers(Arrays.asList(s)); if (EntitlementManager.MONITORING.equals(ent)) { diff --git a/java/code/src/com/suse/manager/webui/controllers/AnsibleController.java b/java/code/src/com/suse/manager/webui/controllers/AnsibleController.java index 7b61b0404993..c3016b923440 100644 --- a/java/code/src/com/suse/manager/webui/controllers/AnsibleController.java +++ b/java/code/src/com/suse/manager/webui/controllers/AnsibleController.java @@ -226,13 +226,13 @@ public static String saveAnsiblePath(Request req, Response res, User user) { AnsiblePath currentPath; try { if (json.getId() == null) { - currentPath = AnsibleManager.createAnsiblePath(json.getType(), + currentPath = getAnsibleManager().createAnsiblePath(json.getType(), json.getMinionServerId(), json.getPath(), user); } else { - currentPath = AnsibleManager.updateAnsiblePath(json.getId(), + currentPath = getAnsibleManager().updateAnsiblePath(json.getId(), json.getPath(), user); } @@ -258,7 +258,7 @@ public static String deleteAnsiblePath(Request req, Response res, User user) { Long ansiblePathId = GSON.fromJson(req.body(), Long.class); try { - AnsibleManager.removeAnsiblePath(ansiblePathId, user); + getAnsibleManager().removeAnsiblePath(ansiblePathId, user); } catch (LookupException e) { return result(res, error(LOCAL.getMessage("ansible.entity_not_found")), new TypeToken<>() { }); From f9f860c94661efa40f3273fc7379d6dbe6e77fbf Mon Sep 17 00:00:00 2001 From: Pascal Arlt Date: Wed, 26 Feb 2025 10:15:13 +0100 Subject: [PATCH 19/20] Make unit tests happy Signed-off-by: Pascal Arlt --- .../frontend/xmlrpc/ansible/test/AnsibleHandlerTest.java | 8 ++++---- .../src/com/redhat/rhn/manager/system/AnsibleManager.java | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/java/code/src/com/redhat/rhn/frontend/xmlrpc/ansible/test/AnsibleHandlerTest.java b/java/code/src/com/redhat/rhn/frontend/xmlrpc/ansible/test/AnsibleHandlerTest.java index cdb6e1a51170..8db185e40cc0 100644 --- a/java/code/src/com/redhat/rhn/frontend/xmlrpc/ansible/test/AnsibleHandlerTest.java +++ b/java/code/src/com/redhat/rhn/frontend/xmlrpc/ansible/test/AnsibleHandlerTest.java @@ -159,7 +159,7 @@ public void testCreateAndGetAnsiblePath() throws Exception { Map.of( "type", "inventory", "server_id", controlNode.getId().intValue(), - "path", "/etc/ansible/hosts" + "path", "/etc/ansible/test" )); AnsiblePath playbookPath = handler.createAnsiblePath( @@ -203,7 +203,7 @@ public void testUpdateAnsiblePath() throws Exception { Map.of( "type", "inventory", "server_id", controlNode.getId().intValue(), - "path", "/etc/ansible/hosts" + "path", "/etc/ansible/test" )); handler.updateAnsiblePath(admin, inventoryPath.getId().intValue(), Map.of("path", "/tmp/new-location")); @@ -220,7 +220,7 @@ public void testUpdateInvalidAnsiblePath() throws Exception { Map.of( "type", "inventory", "server_id", controlNode.getId().intValue(), - "path", "/etc/ansible/hosts" + "path", "/etc/ansible/test" )); try { @@ -241,7 +241,7 @@ public void testRemoveAnsiblePath() throws Exception { Map.of( "type", "inventory", "server_id", controlNode.getId().intValue(), - "path", "/etc/ansible/hosts" + "path", "/etc/ansible/test" )); int result = handler.removeAnsiblePath(admin, inventoryPath.getId().intValue()); diff --git a/java/code/src/com/redhat/rhn/manager/system/AnsibleManager.java b/java/code/src/com/redhat/rhn/manager/system/AnsibleManager.java index 3db13c37f7b0..8ff85251a4b0 100644 --- a/java/code/src/com/redhat/rhn/manager/system/AnsibleManager.java +++ b/java/code/src/com/redhat/rhn/manager/system/AnsibleManager.java @@ -165,6 +165,7 @@ public AnsiblePath createAnsiblePath(String typeLabel, MinionServer minionServer switch (type) { case INVENTORY: ansiblePath = new InventoryPath(); + ((InventoryPath) ansiblePath).setInventoryServers(new HashSet<>()); break; case PLAYBOOK: ansiblePath = new PlaybookPath(); From b90dc2eb83dc63a9e163eb9834d2b3525246bf43 Mon Sep 17 00:00:00 2001 From: Pascal Arlt Date: Thu, 27 Feb 2025 09:32:01 +0100 Subject: [PATCH 20/20] Make sonarcloud happy Signed-off-by: Pascal Arlt --- .../action/ansible/InventoryAction.java | 22 ++++++++++++++++++ .../domain/action/ansible/PlaybookAction.java | 22 ++++++++++++++++++ .../src/com/redhat/rhn/domain/org/Org.java | 8 +++---- .../domain/server/ansible/InventoryPath.java | 23 +++++++++++++++++++ .../rhn/manager/system/AnsibleManager.java | 8 +++---- .../src/com/suse/manager/utils/SaltUtils.java | 6 +++++ .../services/SaltServerActionService.java | 2 +- 7 files changed, 80 insertions(+), 11 deletions(-) diff --git a/java/code/src/com/redhat/rhn/domain/action/ansible/InventoryAction.java b/java/code/src/com/redhat/rhn/domain/action/ansible/InventoryAction.java index 6676fcb15788..4c8ea2947803 100644 --- a/java/code/src/com/redhat/rhn/domain/action/ansible/InventoryAction.java +++ b/java/code/src/com/redhat/rhn/domain/action/ansible/InventoryAction.java @@ -16,6 +16,9 @@ import com.redhat.rhn.domain.action.Action; +import org.apache.commons.lang3.builder.EqualsBuilder; +import org.apache.commons.lang3.builder.HashCodeBuilder; + /** * InventoryAction - Action class representing the execution of an Ansible inventory refresh */ @@ -41,4 +44,23 @@ public void setDetails(InventoryActionDetails detailsIn) { } this.details = detailsIn; } + + @Override + public boolean equals(Object oIn) { + if (this == oIn) { + return true; + } + if (!(oIn instanceof InventoryAction that)) { + return false; + } + return new EqualsBuilder().appendSuper(super.equals(oIn)).append(details, that.details).isEquals(); + } + + @Override + public int hashCode() { + return new HashCodeBuilder(17, 37) + .appendSuper(super.hashCode()) + .append(details) + .toHashCode(); + } } diff --git a/java/code/src/com/redhat/rhn/domain/action/ansible/PlaybookAction.java b/java/code/src/com/redhat/rhn/domain/action/ansible/PlaybookAction.java index cf4b4ed578b8..b60140da9b81 100644 --- a/java/code/src/com/redhat/rhn/domain/action/ansible/PlaybookAction.java +++ b/java/code/src/com/redhat/rhn/domain/action/ansible/PlaybookAction.java @@ -16,6 +16,9 @@ import com.redhat.rhn.domain.action.Action; +import org.apache.commons.lang3.builder.EqualsBuilder; +import org.apache.commons.lang3.builder.HashCodeBuilder; + /** * PlaybookAction - Action class representing the execution of an Ansible playbook */ @@ -41,4 +44,23 @@ public void setDetails(PlaybookActionDetails detailsIn) { } this.details = detailsIn; } + + @Override + public boolean equals(Object oIn) { + if (this == oIn) { + return true; + } + if (!(oIn instanceof PlaybookAction that)) { + return false; + } + return new EqualsBuilder().appendSuper(super.equals(oIn)).append(details, that.details).isEquals(); + } + + @Override + public int hashCode() { + return new HashCodeBuilder(17, 37) + .appendSuper(super.hashCode()) + .append(details) + .toHashCode(); + } } diff --git a/java/code/src/com/redhat/rhn/domain/org/Org.java b/java/code/src/com/redhat/rhn/domain/org/Org.java index f066bb9ed53d..e0a688f5d85f 100644 --- a/java/code/src/com/redhat/rhn/domain/org/Org.java +++ b/java/code/src/com/redhat/rhn/domain/org/Org.java @@ -506,11 +506,9 @@ public Set getValidAddOnEntitlementsForOrg() { if (!sgt.isBase()) { Entitlement ent = EntitlementManager.getByName(sgt.getLabel()); if (ent != null) { - if (EntitlementManager.OSIMAGE_BUILD_HOST_ENTITLED.equals(ent.getLabel()) && - !Config.get().getBoolean(ConfigDefaults.KIWI_OS_IMAGE_BUILDING_ENABLED)) { - continue; - } - else if (EntitlementManager.ANSIBLE_MANAGED_ENTITLED.equals(ent.getLabel())) { + if ((EntitlementManager.OSIMAGE_BUILD_HOST_ENTITLED.equals(ent.getLabel()) && + !Config.get().getBoolean(ConfigDefaults.KIWI_OS_IMAGE_BUILDING_ENABLED)) || + EntitlementManager.ANSIBLE_MANAGED_ENTITLED.equals(ent.getLabel())) { continue; } addonEntitlements.add(ent); diff --git a/java/code/src/com/redhat/rhn/domain/server/ansible/InventoryPath.java b/java/code/src/com/redhat/rhn/domain/server/ansible/InventoryPath.java index d607cb6b6317..a6acc8efef84 100644 --- a/java/code/src/com/redhat/rhn/domain/server/ansible/InventoryPath.java +++ b/java/code/src/com/redhat/rhn/domain/server/ansible/InventoryPath.java @@ -18,6 +18,9 @@ import com.redhat.rhn.domain.server.MinionServer; import com.redhat.rhn.domain.server.Server; +import org.apache.commons.lang3.builder.EqualsBuilder; +import org.apache.commons.lang3.builder.HashCodeBuilder; + import java.util.Set; import javax.persistence.DiscriminatorValue; @@ -79,4 +82,24 @@ public Set getInventoryServers() { public void setInventoryServers(Set inventoryServersIn) { inventoryServers = inventoryServersIn; } + + @Override + public boolean equals(Object oIn) { + if (this == oIn) { + return true; + } + if (!(oIn instanceof InventoryPath that)) { + return false; + } + return new EqualsBuilder().appendSuper(super.equals(oIn)) + .append(inventoryServers, that.inventoryServers).isEquals(); + } + + @Override + public int hashCode() { + return new HashCodeBuilder(17, 37) + .appendSuper(super.hashCode()) + .append(inventoryServers) + .toHashCode(); + } } diff --git a/java/code/src/com/redhat/rhn/manager/system/AnsibleManager.java b/java/code/src/com/redhat/rhn/manager/system/AnsibleManager.java index 8ff85251a4b0..f7d904288208 100644 --- a/java/code/src/com/redhat/rhn/manager/system/AnsibleManager.java +++ b/java/code/src/com/redhat/rhn/manager/system/AnsibleManager.java @@ -518,9 +518,7 @@ public static List> generateBeacon(MinionServer minion) { if (!inventories.isEmpty()) { Map files = new HashMap<>(); - inventories.forEach(i -> { - files.put(i.getPath().toString(), Map.of("mask", List.of("modify"))); - }); + inventories.forEach(i -> files.put(i.getPath().toString(), Map.of("mask", List.of("modify")))); beacon.add(Map.of("files", files)); beacon.add(Map.of("interval", 5)); beacon.add(Map.of("disable_during_state_run", true)); @@ -582,13 +580,13 @@ public void createDefaultPaths(MinionServer minionServer) { createAnsiblePath(AnsiblePath.Type.INVENTORY.getLabel(), minionServer, inventory); } catch (ValidatorException e) { - log.info("Inventory path: '" + inventory + "' already exists. Skipping..."); + log.info(String.format("Inventory path: '%s' already exists. Skipping...", inventory)); } try { createAnsiblePath(AnsiblePath.Type.PLAYBOOK.getLabel(), minionServer, playbook); } catch (ValidatorException e) { - log.info("Playbook path: '" + playbook + "' already exists. Skipping..."); + log.info(String.format("Playbook path: '%s' already exists. Skipping...", playbook)); } } diff --git a/java/code/src/com/suse/manager/utils/SaltUtils.java b/java/code/src/com/suse/manager/utils/SaltUtils.java index c7d45fc2d986..98cdc1c36fdd 100644 --- a/java/code/src/com/suse/manager/utils/SaltUtils.java +++ b/java/code/src/com/suse/manager/utils/SaltUtils.java @@ -1896,6 +1896,12 @@ private static void handleHardwareProfileUpdate(MinionServer server, } private void handleInventoryRefresh(Action action, ServerAction serverAction, JsonElement jsonResult) { + if (jsonResult == null) { + serverAction.setStatus(ActionFactory.STATUS_FAILED); + serverAction.setResultMsg( + "Error while requesting inventory data from target system: Got no result from system"); + return; + } String inventoryPath = ((InventoryAction) action).getDetails().getInventoryPath(); if (serverAction.getStatus().equals(ActionFactory.STATUS_COMPLETED)) { try { diff --git a/java/code/src/com/suse/manager/webui/services/SaltServerActionService.java b/java/code/src/com/suse/manager/webui/services/SaltServerActionService.java index 4398f16778b4..5f4bb49c3d05 100644 --- a/java/code/src/com/suse/manager/webui/services/SaltServerActionService.java +++ b/java/code/src/com/suse/manager/webui/services/SaltServerActionService.java @@ -1753,7 +1753,7 @@ private LocalCall executeInventoryActionCall(InventoryAction action) { InventoryActionDetails details = action.getDetails(); String inventoryPath = details.getInventoryPath(); - return new LocalCall<>("ansible.targets", empty(), of(Map.of("inventory", inventoryPath)), + return new LocalCall<>(ANSIBLE_INVENTORIES, empty(), of(Map.of("inventory", inventoryPath)), new TypeToken<>() { }); }