Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Ansible] Ansible Managed entitlement and default playbook/inventory paths #9812

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
45f11c0
Update inotify beacon on control nodes on inventory change
parlt91 Feb 15, 2025
39146c3
Refresh pillar data on add/remove Ansible control node entitlement
parlt91 Feb 15, 2025
7d99a00
Move PlaybookAction to action.ansible package
parlt91 Feb 17, 2025
1bf80eb
Add InventoryAction to refresh inventories
parlt91 Feb 17, 2025
272e872
Schedule InventoryAction on inotify event
parlt91 Feb 17, 2025
07068a5
Move parseInventoryAndGetHostnames to AnsibleManager
parlt91 Feb 18, 2025
508810c
Create table to store Ansible managed systems per inventory
parlt91 Feb 18, 2025
48f1bc4
Store Ansible managed systems on inventory refresh return
parlt91 Feb 18, 2025
78dd257
Add ansible_managed entitlement schema
parlt91 Feb 19, 2025
78efa2b
Add ansible_managed entitlement java
parlt91 Feb 19, 2025
4067d5c
Update ansible_managed entitlement on systems on inventory modify
parlt91 Feb 22, 2025
5720a00
Update inventory servers and entitlement on inventory
parlt91 Feb 22, 2025
ea71860
Handle ansible managed systems on remove control node and system delete
parlt91 Feb 25, 2025
d8e6ac1
Allow filtering by ansible managed systems in the system list
parlt91 Feb 26, 2025
0a3403a
Create default paths on add control node
parlt91 Feb 25, 2025
957d597
Add missing schema migration files
parlt91 Feb 25, 2025
c8658e3
Refactor System(Un)Entitler constructor to only use SaltApi
parlt91 Feb 25, 2025
8c970b9
Make methods using SaltApi non static to allow unit test mocking
parlt91 Feb 25, 2025
f9f860c
Make unit tests happy
parlt91 Feb 26, 2025
b90dc2e
Make sonarcloud happy
parlt91 Feb 27, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions java/code/src/com/redhat/rhn/GlobalInstanceHolder.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
</query>
</write-mode>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -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
Expand Down
11 changes: 10 additions & 1 deletion java/code/src/com/redhat/rhn/domain/action/ActionFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -431,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();
}
Expand Down Expand Up @@ -1243,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");
}

Original file line number Diff line number Diff line change
Expand Up @@ -351,8 +351,8 @@ PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
</subclass>

<!-- Ansible playbook action -->
<subclass name="com.redhat.rhn.domain.action.salt.PlaybookAction" lazy="true" discriminator-value="521">
<one-to-one name="details" class="com.redhat.rhn.domain.action.salt.PlaybookActionDetails"
<subclass name="com.redhat.rhn.domain.action.ansible.PlaybookAction" lazy="true" discriminator-value="521">
<one-to-one name="details" class="com.redhat.rhn.domain.action.ansible.PlaybookActionDetails"
outer-join="false" cascade="all" property-ref="parentAction"/>
</subclass>

Expand All @@ -370,6 +370,12 @@ PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
</set>
</subclass>

<!-- Ansible inventory action -->
<subclass name="com.redhat.rhn.domain.action.ansible.InventoryAction" lazy="true" discriminator-value="525">
<one-to-one name="details" class="com.redhat.rhn.domain.action.ansible.InventoryActionDetails"
outer-join="false" cascade="all" property-ref="parentAction"/>
</subclass>

</class>
<query name="Action.findByIdandOrgId">
<![CDATA[from com.redhat.rhn.domain.action.Action as a where a.id = :aid and org_id = :orgId]]>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* 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;

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
*/
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;
}

@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();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.redhat.rhn.domain.action.ansible.InventoryActionDetails"
table="rhnActionInventory">
<id name="id" type="long" column="id">
<meta attribute="scope-set">protected</meta>
<generator class="org.hibernate.id.enhanced.SequenceStyleGenerator">
<param name="sequence_name">rhn_act_inventory_id_seq</param>
<param name="increment_size">1</param>
</generator>
</id>
<property name="inventoryPath" column="inventory_path" type="string" />
<property name="created" type="timestamp" insert="false" update="false" />
<property name="modified" type="timestamp" insert="false" update="false" />
<many-to-one name="parentAction" column="action_id" class="com.redhat.rhn.domain.action.Action"
outer-join="true" not-null="true" update="false"/>
</class>
</hibernate-mapping>
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@
* 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;

import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;

/**
* PlaybookAction - Action class representing the execution of an Ansible playbook
*/
Expand All @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.redhat.rhn.domain.action.salt.PlaybookActionDetails"
<class name="com.redhat.rhn.domain.action.ansible.PlaybookActionDetails"
table="rhnActionPlaybook">
<id name="id" type="long" column="id">
<meta attribute="scope-set">protected</meta>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* 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.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 <code>lbl</code>.
*
* @param lbl Entitlement label.
*/
AnsibleManagedEntitlement(String lbl) {
super(lbl);
}

@Override
public boolean isPermanent() {
return false;
}

@Override
public boolean isBase() {
return false;
}
}
Loading
Loading