diff --git a/java/code/src/com/redhat/rhn/GlobalInstanceHolder.java b/java/code/src/com/redhat/rhn/GlobalInstanceHolder.java index 5668a18adb79..df780044e7a8 100644 --- a/java/code/src/com/redhat/rhn/GlobalInstanceHolder.java +++ b/java/code/src/com/redhat/rhn/GlobalInstanceHolder.java @@ -33,7 +33,6 @@ import com.suse.manager.kubernetes.KubernetesManager; import com.suse.manager.utils.SaltKeyUtils; import com.suse.manager.utils.SaltUtils; -import com.suse.manager.virtualization.VirtManagerSalt; import com.suse.manager.webui.controllers.bootstrap.RegularMinionBootstrapper; import com.suse.manager.webui.controllers.bootstrap.SSHMinionBootstrapper; import com.suse.manager.webui.menu.MenuTree; @@ -42,7 +41,6 @@ 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.iface.VirtManager; import com.suse.manager.webui.services.impl.SaltService; import com.suse.manager.webui.utils.MinionActionUtils; import com.suse.manager.webui.utils.UserPreferenceUtils; @@ -79,15 +77,14 @@ private GlobalInstanceHolder() { public static final RenderUtils RENDER_UTILS = new RenderUtils(ACL_FACTORY); public static final MinionActionUtils MINION_ACTION_UTILS = new MinionActionUtils(SALT_API, SALT_UTILS); public static final KubernetesManager KUBERNETES_MANAGER = new KubernetesManager(SALT_API); - public static final VirtManager VIRT_MANAGER = new VirtManagerSalt(SALT_API); public static final RegularMinionBootstrapper REGULAR_MINION_BOOTSTRAPPER = 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(VIRT_MANAGER, MONITORING_MANAGER, SERVER_GROUP_MANAGER), - new SystemEntitler(SALT_API, VIRT_MANAGER, MONITORING_MANAGER, + new SystemUnentitler(MONITORING_MANAGER, SERVER_GROUP_MANAGER), + new SystemEntitler(SALT_API, MONITORING_MANAGER, SERVER_GROUP_MANAGER) ); public static final SystemManager SYSTEM_MANAGER = new SystemManager(ServerFactory.SINGLETON, 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 a6167a3598ab..98f622c5276a 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 @@ -45,10 +45,8 @@ import com.redhat.rhn.testing.TestUtils; import com.redhat.rhn.testing.UserTestUtils; -import com.suse.manager.virtualization.VirtManagerSalt; import com.suse.manager.webui.services.iface.MonitoringManager; import com.suse.manager.webui.services.iface.SaltApi; -import com.suse.manager.webui.services.iface.VirtManager; import com.suse.manager.webui.services.test.TestSaltApi; import org.junit.jupiter.api.BeforeEach; @@ -69,11 +67,10 @@ public class AccessTest extends BaseTestCaseWithUser { private Acl acl; private final SaltApi saltApi = new TestSaltApi(); private final ServerGroupManager serverGroupManager = new ServerGroupManager(saltApi); - private final VirtManager virtManager = new VirtManagerSalt(saltApi); private final MonitoringManager monitoringManager = new FormulaMonitoringManager(saltApi); private final SystemEntitlementManager systemEntitlementManager = new SystemEntitlementManager( - new SystemUnentitler(virtManager, monitoringManager, serverGroupManager), - new SystemEntitler(saltApi, virtManager, monitoringManager, serverGroupManager) + new SystemUnentitler(monitoringManager, serverGroupManager), + new SystemEntitler(saltApi, monitoringManager, serverGroupManager) ); @Override 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 2e173986d807..234fc9ef4a83 100644 --- a/java/code/src/com/redhat/rhn/domain/action/ActionFactory.java +++ b/java/code/src/com/redhat/rhn/domain/action/ActionFactory.java @@ -52,26 +52,6 @@ import com.redhat.rhn.domain.action.script.ScriptActionDetails; import com.redhat.rhn.domain.action.script.ScriptRunAction; import com.redhat.rhn.domain.action.server.ServerAction; -import com.redhat.rhn.domain.action.virtualization.BaseVirtualizationVolumeAction; -import com.redhat.rhn.domain.action.virtualization.VirtualizationCreateGuestAction; -import com.redhat.rhn.domain.action.virtualization.VirtualizationDeleteGuestAction; -import com.redhat.rhn.domain.action.virtualization.VirtualizationDestroyGuestAction; -import com.redhat.rhn.domain.action.virtualization.VirtualizationMigrateGuestAction; -import com.redhat.rhn.domain.action.virtualization.VirtualizationNetworkCreateAction; -import com.redhat.rhn.domain.action.virtualization.VirtualizationNetworkStateChangeAction; -import com.redhat.rhn.domain.action.virtualization.VirtualizationPoolCreateAction; -import com.redhat.rhn.domain.action.virtualization.VirtualizationPoolDeleteAction; -import com.redhat.rhn.domain.action.virtualization.VirtualizationPoolRefreshAction; -import com.redhat.rhn.domain.action.virtualization.VirtualizationPoolStartAction; -import com.redhat.rhn.domain.action.virtualization.VirtualizationPoolStopAction; -import com.redhat.rhn.domain.action.virtualization.VirtualizationRebootGuestAction; -import com.redhat.rhn.domain.action.virtualization.VirtualizationResumeGuestAction; -import com.redhat.rhn.domain.action.virtualization.VirtualizationSchedulePollerAction; -import com.redhat.rhn.domain.action.virtualization.VirtualizationSetMemoryGuestAction; -import com.redhat.rhn.domain.action.virtualization.VirtualizationSetVcpusGuestAction; -import com.redhat.rhn.domain.action.virtualization.VirtualizationShutdownGuestAction; -import com.redhat.rhn.domain.action.virtualization.VirtualizationStartGuestAction; -import com.redhat.rhn.domain.action.virtualization.VirtualizationSuspendGuestAction; import com.redhat.rhn.domain.config.ConfigRevision; import com.redhat.rhn.domain.rhnpackage.PackageEvr; import com.redhat.rhn.domain.rhnpackage.PackageEvrFactory; @@ -419,72 +399,12 @@ else if (typeIn.equals(TYPE_KICKSTART_INITIATE_GUEST)) { else if (typeIn.equals(TYPE_DAEMON_CONFIG)) { retval = new DaemonConfigAction(); } - else if (typeIn.equals(TYPE_VIRTUALIZATION_SHUTDOWN)) { - retval = new VirtualizationShutdownGuestAction(); - } - else if (typeIn.equals(TYPE_VIRTUALIZATION_START)) { - retval = new VirtualizationStartGuestAction(); - } - else if (typeIn.equals(TYPE_VIRTUALIZATION_SUSPEND)) { - retval = new VirtualizationSuspendGuestAction(); - } - else if (typeIn.equals(TYPE_VIRTUALIZATION_RESUME)) { - retval = new VirtualizationResumeGuestAction(); - } - else if (typeIn.equals(TYPE_VIRTUALIZATION_REBOOT)) { - retval = new VirtualizationRebootGuestAction(); - } - else if (typeIn.equals(TYPE_VIRTUALIZATION_DESTROY)) { - retval = new VirtualizationDestroyGuestAction(); - } - else if (typeIn.equals(TYPE_VIRTUALIZATION_DELETE)) { - retval = new VirtualizationDeleteGuestAction(); - } - else if (typeIn.equals(TYPE_VIRTUALIZATION_SET_MEMORY)) { - retval = new VirtualizationSetMemoryGuestAction(); - } - else if (typeIn.equals(TYPE_VIRTUALIZATION_SET_VCPUS)) { - retval = new VirtualizationSetVcpusGuestAction(); - } - else if (typeIn.equals(TYPE_VIRTUALIZATION_GUEST_MIGRATE)) { - retval = new VirtualizationMigrateGuestAction(); - } - else if (typeIn.equals(TYPE_VIRTUALIZATION_SCHEDULE_POLLER)) { - retval = new VirtualizationSchedulePollerAction(); - } else if (typeIn.equals(TYPE_VIRTIZATION_HOST_SUBSCRIBE_TO_TOOLS_CHANNEL)) { retval = new KickstartHostToolsChannelSubscriptionAction(); } else if (typeIn.equals(TYPE_VIRTUALIZATION_GUEST_SUBSCRIBE_TO_TOOLS_CHANNEL)) { retval = new KickstartGuestToolsChannelSubscriptionAction(); } - else if (typeIn.equals(TYPE_VIRTUALIZATION_CREATE)) { - retval = new VirtualizationCreateGuestAction(); - } - else if (typeIn.equals(TYPE_VIRTUALIZATION_POOL_REFRESH)) { - retval = new VirtualizationPoolRefreshAction(); - } - else if (typeIn.equals(TYPE_VIRTUALIZATION_POOL_START)) { - retval = new VirtualizationPoolStartAction(); - } - else if (typeIn.equals(TYPE_VIRTUALIZATION_POOL_STOP)) { - retval = new VirtualizationPoolStopAction(); - } - else if (typeIn.equals(TYPE_VIRTUALIZATION_POOL_DELETE)) { - retval = new VirtualizationPoolDeleteAction(); - } - else if (typeIn.equals(TYPE_VIRTUALIZATION_POOL_CREATE)) { - retval = new VirtualizationPoolCreateAction(); - } - else if (typeIn.equals(TYPE_VIRTUALIZATION_VOLUME_DELETE)) { - retval = new BaseVirtualizationVolumeAction(); - } - else if (typeIn.equals(TYPE_VIRTUALIZATION_NETWORK_STATE_CHANGE)) { - retval = new VirtualizationNetworkStateChangeAction(); - } - else if (typeIn.equals(TYPE_VIRTUALIZATION_NETWORK_CREATE)) { - retval = new VirtualizationNetworkCreateAction(); - } else if (typeIn.equals(TYPE_SCAP_XCCDF_EVAL)) { retval = new ScapAction(); } @@ -1008,33 +928,6 @@ public static void delete(ServerAction serverAction) { singleton.removeObject(serverAction); } - /** - * Return whether an action type is a virtualization one. - * - * @param actionType type to check - * @return true if it is a virtualization action type - */ - public static boolean isVirtualizationActionType(ActionType actionType) { - return actionType.equals(TYPE_VIRTUALIZATION_CREATE) || - actionType.equals(TYPE_VIRTUALIZATION_DELETE) || - actionType.equals(TYPE_VIRTUALIZATION_DESTROY) || - actionType.equals(TYPE_VIRTUALIZATION_REBOOT) || - actionType.equals(TYPE_VIRTUALIZATION_RESUME) || - actionType.equals(TYPE_VIRTUALIZATION_SET_MEMORY) || - actionType.equals(TYPE_VIRTUALIZATION_SET_VCPUS) || - actionType.equals(TYPE_VIRTUALIZATION_SHUTDOWN) || - actionType.equals(TYPE_VIRTUALIZATION_START) || - actionType.equals(TYPE_VIRTUALIZATION_SUSPEND) || - actionType.equals(TYPE_VIRTUALIZATION_GUEST_MIGRATE) || - actionType.equals(TYPE_VIRTUALIZATION_POOL_CREATE) || - actionType.equals(TYPE_VIRTUALIZATION_POOL_DELETE) || - actionType.equals(TYPE_VIRTUALIZATION_POOL_REFRESH) || - actionType.equals(TYPE_VIRTUALIZATION_POOL_START) || - actionType.equals(TYPE_VIRTUALIZATION_POOL_STOP) || - actionType.equals(TYPE_VIRTUALIZATION_NETWORK_STATE_CHANGE) || - actionType.equals(TYPE_VIRTUALIZATION_NETWORK_CREATE); - } - /** * The constant representing the Action Status QUEUED */ @@ -1243,60 +1136,6 @@ public static boolean isVirtualizationActionType(ActionType actionType) { public static final ActionType TYPE_ROLLBACK_ROLLBACK = lookupActionTypeByLabel("rollback.rollback"); - /** - * The constant representing "Shuts down a Xen domain." [ID:36] - */ - public static final ActionType TYPE_VIRTUALIZATION_SHUTDOWN = - lookupActionTypeByLabel("virt.shutdown"); - - /** - * The constant representing "Starts up a Xen domain." [ID:37] - */ - public static final ActionType TYPE_VIRTUALIZATION_START = - lookupActionTypeByLabel("virt.start"); - - /** - * The constant representing "Suspends a Xen domain." [ID:38] - */ - public static final ActionType TYPE_VIRTUALIZATION_SUSPEND = - lookupActionTypeByLabel("virt.suspend"); - - /** - * The constant representing "Resumes a Xen domain." [ID:39] - */ - public static final ActionType TYPE_VIRTUALIZATION_RESUME = - lookupActionTypeByLabel("virt.resume"); - - /** - * The constant representing "Reboots a Xen domain." [ID:40] - */ - public static final ActionType TYPE_VIRTUALIZATION_REBOOT = - lookupActionTypeByLabel("virt.reboot"); - - /** - * The constant representing "Destroys a Xen Domain." [ID:41] - */ - public static final ActionType TYPE_VIRTUALIZATION_DESTROY = - lookupActionTypeByLabel("virt.destroy"); - - /** - * The constant representing "Sets the maximum memory usage for a Xen domain." [ID:42] - */ - public static final ActionType TYPE_VIRTUALIZATION_SET_MEMORY = - lookupActionTypeByLabel("virt.setMemory"); - - /** - * The constant representing "Sets the Vcpu usage for a Xen domain." [ID:48] - */ - public static final ActionType TYPE_VIRTUALIZATION_SET_VCPUS = - lookupActionTypeByLabel("virt.setVCPUs"); - - /** - * The constant representing "Sets when the poller should run." [ID:43] - */ - public static final ActionType TYPE_VIRTUALIZATION_SCHEDULE_POLLER = - lookupActionTypeByLabel("virt.schedulePoller"); - /** * The constant representing "Schedule a package install of host specific * functionality." [ID:44] @@ -1370,77 +1209,11 @@ public static boolean isVirtualizationActionType(ActionType actionType) { public static final ActionType TYPE_SUBSCRIBE_CHANNELS = lookupActionTypeByLabel("channels.subscribe"); - /** - * The constant representing "Deletes a virtual domain." [ID:507] - */ - public static final ActionType TYPE_VIRTUALIZATION_DELETE = - lookupActionTypeByLabel("virt.delete"); - - /** - * The constant representing "Creates a virtual domain." [ID:508] - */ - public static final ActionType TYPE_VIRTUALIZATION_CREATE = - lookupActionTypeByLabel("virt.create"); - - /** - * The constant representing "Refresh a virtual storage pool." [ID:509] - */ - public static final ActionType TYPE_VIRTUALIZATION_POOL_REFRESH = - lookupActionTypeByLabel("virt.pool_refresh"); - - /** - * The constant representing "Start a virtual storage pool." [ID:510] - */ - public static final ActionType TYPE_VIRTUALIZATION_POOL_START = - lookupActionTypeByLabel("virt.pool_start"); - - /** - * The constant representing "Stops a virtual storage pool." [ID:511] - */ - public static final ActionType TYPE_VIRTUALIZATION_POOL_STOP = - lookupActionTypeByLabel("virt.pool_stop"); - - /** - * The constant representing "Deletes a virtual storage pool." [ID:512] - */ - public static final ActionType TYPE_VIRTUALIZATION_POOL_DELETE = - lookupActionTypeByLabel("virt.pool_delete"); - - /** - * The constant representing "Creates a virtual storage pool." [ID:513] - */ - public static final ActionType TYPE_VIRTUALIZATION_POOL_CREATE = - lookupActionTypeByLabel("virt.pool_create"); - - /** - * The constant representing "Deletes a virtual storage volume" [ID:514] - */ - public static final ActionType TYPE_VIRTUALIZATION_VOLUME_DELETE = - lookupActionTypeByLabel("virt.volume_delete"); - - /** - * The constant representing "Change a virtual network state" [ID:519] - */ - public static final ActionType TYPE_VIRTUALIZATION_NETWORK_STATE_CHANGE = - lookupActionTypeByLabel("virt.network_state"); - - /** - * The constant representing "Creates a virtual network" [ID:520] - */ - public static final ActionType TYPE_VIRTUALIZATION_NETWORK_CREATE = - lookupActionTypeByLabel("virt.network_create"); - /** * The constant representing "Execute an Ansible playbook" [ID:521] */ public static final ActionType TYPE_PLAYBOOK = lookupActionTypeByLabel("ansible.playbook"); - /** - * The constant representing "Migrate a virtual domain" [ID:522] - */ - public static final ActionType TYPE_VIRTUALIZATION_GUEST_MIGRATE = - lookupActionTypeByLabel("virt.guest_migrate"); - /** * The constant representing "Confidential Compute Attestation" [ID:523] */ 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 dab9696b70bc..f34e6e0779ba 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 @@ -253,89 +253,6 @@ PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -348,83 +265,6 @@ PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" discriminator-value="51" lazy="true"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - () { }.getType()); - } - - @Override - public String getWebSocketActionId() { - return String.format("new-%s", getId()); - } -} diff --git a/java/code/src/com/redhat/rhn/domain/action/virtualization/VirtualizationNetworkStateChangeAction.java b/java/code/src/com/redhat/rhn/domain/action/virtualization/VirtualizationNetworkStateChangeAction.java deleted file mode 100644 index b6c2f7b5648e..000000000000 --- a/java/code/src/com/redhat/rhn/domain/action/virtualization/VirtualizationNetworkStateChangeAction.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2020 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.virtualization; - -/** - * Represents the virtual network actions like start, stop and delete - */ -public class VirtualizationNetworkStateChangeAction extends BaseVirtualizationNetworkAction { - private String state; - - /** - * @return the state to change the networks to - */ - public String getState() { - return state; - } - - /** - * @param stateIn the state to change the networks to - */ - public void setState(String stateIn) { - state = stateIn; - } -} diff --git a/java/code/src/com/redhat/rhn/domain/action/virtualization/VirtualizationPoolCreateAction.java b/java/code/src/com/redhat/rhn/domain/action/virtualization/VirtualizationPoolCreateAction.java deleted file mode 100644 index f0425506fde9..000000000000 --- a/java/code/src/com/redhat/rhn/domain/action/virtualization/VirtualizationPoolCreateAction.java +++ /dev/null @@ -1,201 +0,0 @@ -/* - * Copyright (c) 2020 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.virtualization; - -/** - * Represents a virtual storage creation action. - */ -public class VirtualizationPoolCreateAction extends BaseVirtualizationPoolAction { - - private String uuid; - private String type; - private String target; - private boolean autostart = false; - - // Permissions properties - private String mode; - private String owner; - private String group; - private String seclabel; - - private VirtualizationPoolCreateActionSource source; - - - /** - * @return Returns the uuid. - */ - public String getUuid() { - return uuid; - } - - - /** - * @param uuidIn The uuid to set. - */ - public void setUuid(String uuidIn) { - uuid = uuidIn; - } - - /** - * @return Returns the pool type. - */ - public String getType() { - return type; - } - - /** - * @param typeIn The pool type to set. - */ - public void setType(String typeIn) { - type = typeIn; - } - - /** - * @return Returns the target. - */ - public String getTarget() { - return target; - } - - /** - * @param targetIn The target to set. - */ - public void setTarget(String targetIn) { - target = targetIn; - } - - /** - * @return Returns whether to autostart the pool. - */ - public boolean isAutostart() { - return autostart; - } - - /** - * @param autostartIn True if the pool needs to be automatically started. - */ - public void setAutostart(boolean autostartIn) { - autostart = autostartIn; - } - - /** - * @return Returns the permission mode. - */ - public String getMode() { - return mode; - } - - /** - * @param modeIn The permission mode to set. - */ - public void setMode(String modeIn) { - mode = modeIn; - } - - /** - * @return Returns the owner user. - */ - public String getOwner() { - return owner; - } - - /** - * @param ownerIn The owner user to set. - */ - public void setOwner(String ownerIn) { - owner = ownerIn; - } - - - /** - * @return Returns the group. - */ - public String getGroup() { - return group; - } - - /** - * @param groupIn The group to set. - */ - public void setGroup(String groupIn) { - group = groupIn; - } - - /** - * @return Returns the SE Linux label. - */ - public String getSeclabel() { - return seclabel; - } - - /** - * @param seclabelIn The SE Linux label to set. - */ - public void setSeclabel(String seclabelIn) { - seclabel = seclabelIn; - } - - /** - * @return Returns the source. - */ - public VirtualizationPoolCreateActionSource getSource() { - return source; - } - - /** - * @return the source serialized into a String. - * - * This function should only be used by hibernate. - */ - public String getSourceAsString() { - String string = null; - if (source != null) { - string = source.toString(); - } - return string; - } - - /** - * @param sourceIn The source to set. - */ - public void setSource(VirtualizationPoolCreateActionSource sourceIn) { - source = sourceIn; - } - - /** - * Set the source from its Serialized value. - * - * @param sourceString serialized value. - * - * This function should only be used by hibernate. - */ - public void setSourceAsString(String sourceString) { - if (sourceString != null) { - source = VirtualizationPoolCreateActionSource.parse(sourceString); - } - else { - source = null; - } - } - - @Override - public String getWebSocketActionId() { - String id = super.getWebSocketActionId(); - if (getUuid() == null) { - id = String.format("new-%s", getId()); - } - return id; - } -} diff --git a/java/code/src/com/redhat/rhn/domain/action/virtualization/VirtualizationPoolCreateActionSource.java b/java/code/src/com/redhat/rhn/domain/action/virtualization/VirtualizationPoolCreateActionSource.java deleted file mode 100644 index a43f3a59b7f8..000000000000 --- a/java/code/src/com/redhat/rhn/domain/action/virtualization/VirtualizationPoolCreateActionSource.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2020 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.virtualization; - -import com.suse.manager.reactor.utils.OptionalTypeAdapterFactory; -import com.suse.manager.virtualization.PoolSource; - -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.google.gson.reflect.TypeToken; - -/** - * Represents the virtual storage source parameters for the storage pool creation action. - * Note that to save database fields this is stored as a json string in the database. - */ -public class VirtualizationPoolCreateActionSource extends PoolSource { - - private static final Gson GSON = new GsonBuilder() - .registerTypeAdapterFactory(new OptionalTypeAdapterFactory()) - .create(); - - /** - * Create from a serialized string. - * - * @param json the serialized string as output by toString() - * @return the parsed object - */ - public static VirtualizationPoolCreateActionSource parse(String json) { - return GSON.fromJson(json, new TypeToken() { }.getType()); - } - - /** - * Serializes into a json string - * {@inheritDoc} - */ - @Override - public String toString() { - return GSON.toJson(this); - } -} diff --git a/java/code/src/com/redhat/rhn/domain/action/virtualization/VirtualizationPoolDeleteAction.java b/java/code/src/com/redhat/rhn/domain/action/virtualization/VirtualizationPoolDeleteAction.java deleted file mode 100644 index e81ecda45699..000000000000 --- a/java/code/src/com/redhat/rhn/domain/action/virtualization/VirtualizationPoolDeleteAction.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2020 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.virtualization; - -/** - * Represents a virtual storage removal action. - */ -public class VirtualizationPoolDeleteAction extends BaseVirtualizationPoolAction { - - private boolean purge = false; - - /** - * Set whether the delete operation needs to also delete the data. - * - * @param purgeIn true to delete the pool and volumes, false otherwise - */ - public void setPurge(boolean purgeIn) { - purge = purgeIn; - } - - /** - * @return whether the delete operation needs to also delete the data. - * Defaults to false. - */ - public boolean isPurge() { - return purge; - } -} diff --git a/java/code/src/com/redhat/rhn/domain/action/virtualization/VirtualizationPoolRefreshAction.java b/java/code/src/com/redhat/rhn/domain/action/virtualization/VirtualizationPoolRefreshAction.java deleted file mode 100644 index bebd48118b59..000000000000 --- a/java/code/src/com/redhat/rhn/domain/action/virtualization/VirtualizationPoolRefreshAction.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (c) 2020 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.virtualization; - -/** - * Represents a virtual storage refresh action. - */ -public class VirtualizationPoolRefreshAction extends BaseVirtualizationPoolAction { - -} diff --git a/java/code/src/com/redhat/rhn/domain/action/virtualization/VirtualizationPoolStartAction.java b/java/code/src/com/redhat/rhn/domain/action/virtualization/VirtualizationPoolStartAction.java deleted file mode 100644 index 2be1a30414fe..000000000000 --- a/java/code/src/com/redhat/rhn/domain/action/virtualization/VirtualizationPoolStartAction.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (c) 2020 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.virtualization; - - -/** - * Represents a virtual storage start action. - */ -public class VirtualizationPoolStartAction extends BaseVirtualizationPoolAction { - -} diff --git a/java/code/src/com/redhat/rhn/domain/action/virtualization/VirtualizationPoolStopAction.java b/java/code/src/com/redhat/rhn/domain/action/virtualization/VirtualizationPoolStopAction.java deleted file mode 100644 index 8204db6e2f5d..000000000000 --- a/java/code/src/com/redhat/rhn/domain/action/virtualization/VirtualizationPoolStopAction.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (c) 2020 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.virtualization; - - -/** - * Represents a virtual storage stop action. - */ -public class VirtualizationPoolStopAction extends BaseVirtualizationPoolAction { - -} diff --git a/java/code/src/com/redhat/rhn/domain/action/virtualization/VirtualizationRebootGuestAction.java b/java/code/src/com/redhat/rhn/domain/action/virtualization/VirtualizationRebootGuestAction.java deleted file mode 100644 index 03a9ad018132..000000000000 --- a/java/code/src/com/redhat/rhn/domain/action/virtualization/VirtualizationRebootGuestAction.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2009--2010 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. - */ -package com.redhat.rhn.domain.action.virtualization; - -/** - * Class representing TYPE_VIRTUALIZATION_REBOOT - */ -public class VirtualizationRebootGuestAction extends BaseVirtualizationGuestAction { - - private boolean force = false; - - /** - * @return Returns whether to force off rather than cleanly shutting down. - */ - public boolean isForce() { - return force; - } - - /** - * @param forceIn whether to force off rather than cleanly shutting down. - */ - public void setForce(boolean forceIn) { - force = forceIn; - } -} diff --git a/java/code/src/com/redhat/rhn/domain/action/virtualization/VirtualizationResumeGuestAction.java b/java/code/src/com/redhat/rhn/domain/action/virtualization/VirtualizationResumeGuestAction.java deleted file mode 100644 index 4328ada7f834..000000000000 --- a/java/code/src/com/redhat/rhn/domain/action/virtualization/VirtualizationResumeGuestAction.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (c) 2009--2010 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. - */ -package com.redhat.rhn.domain.action.virtualization; - -/** - * Class representing TYPE_VIRTUALIZATION_RESUME - */ -public class VirtualizationResumeGuestAction extends BaseVirtualizationGuestAction { - -} diff --git a/java/code/src/com/redhat/rhn/domain/action/virtualization/VirtualizationSchedulePollerAction.java b/java/code/src/com/redhat/rhn/domain/action/virtualization/VirtualizationSchedulePollerAction.java deleted file mode 100644 index 8ba59439e650..000000000000 --- a/java/code/src/com/redhat/rhn/domain/action/virtualization/VirtualizationSchedulePollerAction.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2009--2010 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. - */ -package com.redhat.rhn.domain.action.virtualization; - -import com.redhat.rhn.domain.action.Action; - -/** - * VirtualizationSchedulePollerAction - Class representing - * TYPE_VIRTUALIZATION_SCHEDULE_POLLER - * - */ -public class VirtualizationSchedulePollerAction extends Action { - -} diff --git a/java/code/src/com/redhat/rhn/domain/action/virtualization/VirtualizationSetMemoryGuestAction.java b/java/code/src/com/redhat/rhn/domain/action/virtualization/VirtualizationSetMemoryGuestAction.java deleted file mode 100644 index 44ec45f2acd3..000000000000 --- a/java/code/src/com/redhat/rhn/domain/action/virtualization/VirtualizationSetMemoryGuestAction.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2009--2010 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. - */ -package com.redhat.rhn.domain.action.virtualization; - -/** - * Class representing TYPE_VIRTUALIZATION_SET_MEMORY. - * Make sure the 'memory' field is in kilobytes. - */ -public class VirtualizationSetMemoryGuestAction extends BaseVirtualizationGuestAction { - - private Integer memory; - - /** - * Set the memory to be appied to the guest. This is KILOBYTES - * @param memoryIn New setting for guest memory. - */ - public void setMemory(Integer memoryIn) { - memory = memoryIn; - } - - /** - * Guest the guest memory. KILOBYTES - * @return The guest memory setting. - */ - public Integer getMemory() { - return memory; - } -} diff --git a/java/code/src/com/redhat/rhn/domain/action/virtualization/VirtualizationSetVcpusGuestAction.java b/java/code/src/com/redhat/rhn/domain/action/virtualization/VirtualizationSetVcpusGuestAction.java deleted file mode 100644 index 0a21d3546a1a..000000000000 --- a/java/code/src/com/redhat/rhn/domain/action/virtualization/VirtualizationSetVcpusGuestAction.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2009--2010 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. - */ -package com.redhat.rhn.domain.action.virtualization; - -/** - * Class representing TYPE_VIRTUALIZATION_SET_VCPUS - */ -public class VirtualizationSetVcpusGuestAction extends BaseVirtualizationGuestAction { - - private Integer vcpu; - - /** - * Set the vcpus to be appied to the guest. - * @param vcpuIn New setting for guest vcpus. - */ - public void setVcpu(Integer vcpuIn) { - vcpu = vcpuIn; - } - - /** - * Guest the guest vcpus. - * @return The guest vcpu setting. - */ - public Integer getVcpu() { - return vcpu; - } -} - diff --git a/java/code/src/com/redhat/rhn/domain/action/virtualization/VirtualizationShutdownGuestAction.java b/java/code/src/com/redhat/rhn/domain/action/virtualization/VirtualizationShutdownGuestAction.java deleted file mode 100644 index 293140622b95..000000000000 --- a/java/code/src/com/redhat/rhn/domain/action/virtualization/VirtualizationShutdownGuestAction.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2009--2010 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. - */ -package com.redhat.rhn.domain.action.virtualization; - -/** - * Class representing TYPE_VIRTUALIZATION_SHUTDOWN - */ -public class VirtualizationShutdownGuestAction extends BaseVirtualizationGuestAction { - - private boolean force = false; - - /** - * @return Returns whether to force off rather than cleanly shutting down. - */ - public boolean isForce() { - return force; - } - - /** - * @param forceIn whether to force off rather than cleanly shutting down. - */ - public void setForce(boolean forceIn) { - force = forceIn; - } -} diff --git a/java/code/src/com/redhat/rhn/domain/action/virtualization/VirtualizationStartGuestAction.java b/java/code/src/com/redhat/rhn/domain/action/virtualization/VirtualizationStartGuestAction.java deleted file mode 100644 index b43b57ae4b52..000000000000 --- a/java/code/src/com/redhat/rhn/domain/action/virtualization/VirtualizationStartGuestAction.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (c) 2009--2010 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. - */ -package com.redhat.rhn.domain.action.virtualization; - -/** - * Class representing TYPE_VIRTUALIZATION_SHUTDOWN - */ -public class VirtualizationStartGuestAction extends BaseVirtualizationGuestAction { - -} diff --git a/java/code/src/com/redhat/rhn/domain/action/virtualization/VirtualizationSuspendGuestAction.java b/java/code/src/com/redhat/rhn/domain/action/virtualization/VirtualizationSuspendGuestAction.java deleted file mode 100644 index a0b8bf27e91a..000000000000 --- a/java/code/src/com/redhat/rhn/domain/action/virtualization/VirtualizationSuspendGuestAction.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (c) 2009--2010 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. - */ -package com.redhat.rhn.domain.action.virtualization; - -/** - * Class representing TYPE_VIRTUALIZATION_SUSPEND - */ -public class VirtualizationSuspendGuestAction extends BaseVirtualizationGuestAction { - -} diff --git a/java/code/src/com/redhat/rhn/domain/action/virtualization/test/VirtualizationActionsTest.java b/java/code/src/com/redhat/rhn/domain/action/virtualization/test/VirtualizationActionsTest.java deleted file mode 100644 index e424bb7879eb..000000000000 --- a/java/code/src/com/redhat/rhn/domain/action/virtualization/test/VirtualizationActionsTest.java +++ /dev/null @@ -1,257 +0,0 @@ -/* - * Copyright (c) 2009--2010 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. - */ -package com.redhat.rhn.domain.action.virtualization.test; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; - -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.test.ActionFactoryTest; -import com.redhat.rhn.domain.action.virtualization.BaseVirtualizationGuestAction; -import com.redhat.rhn.domain.action.virtualization.VirtualizationCreateGuestAction; -import com.redhat.rhn.domain.action.virtualization.VirtualizationDeleteGuestAction; -import com.redhat.rhn.domain.action.virtualization.VirtualizationGuestPackageInstall; -import com.redhat.rhn.domain.action.virtualization.VirtualizationHostPackageInstall; -import com.redhat.rhn.domain.action.virtualization.VirtualizationPoolCreateAction; -import com.redhat.rhn.domain.action.virtualization.VirtualizationPoolCreateActionSource; -import com.redhat.rhn.domain.action.virtualization.VirtualizationRebootGuestAction; -import com.redhat.rhn.domain.action.virtualization.VirtualizationResumeGuestAction; -import com.redhat.rhn.domain.action.virtualization.VirtualizationSetMemoryGuestAction; -import com.redhat.rhn.domain.action.virtualization.VirtualizationSetVcpusGuestAction; -import com.redhat.rhn.domain.action.virtualization.VirtualizationShutdownGuestAction; -import com.redhat.rhn.domain.action.virtualization.VirtualizationStartGuestAction; -import com.redhat.rhn.domain.action.virtualization.VirtualizationSuspendGuestAction; -import com.redhat.rhn.frontend.context.Context; -import com.redhat.rhn.testing.BaseTestCaseWithUser; - -import com.suse.manager.virtualization.GuestCreateDetails; -import com.suse.manager.virtualization.PoolSourceAuthentication; -import com.suse.manager.virtualization.PoolSourceDevice; -import com.suse.manager.webui.controllers.virtualization.gson.VirtualGuestsUpdateActionJson; - -import org.junit.jupiter.api.Test; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map.Entry; -import java.util.TimeZone; -import java.util.stream.Collectors; - -public class VirtualizationActionsTest extends BaseTestCaseWithUser { - - @Test - public void testPackageInstall() throws Exception { - Action a1 = ActionFactoryTest.createAction(user, - ActionFactory.TYPE_VIRTUALIZATION_GUEST_PACKAGE_INSTALL); - - flushAndEvict(a1); - Long id = a1.getId(); - Action a = ActionFactory.lookupById(id); - - assertNotNull(a); - assertTrue(a instanceof VirtualizationGuestPackageInstall); - - Action a2 = ActionFactoryTest.createAction(user, - ActionFactory.TYPE_VIRTUALIZATION_HOST_PACKAGE_INSTALL); - flushAndEvict(a2); - id = a2.getId(); - - a = ActionFactory.lookupById(id); - assertNotNull(a); - assertTrue(a instanceof VirtualizationHostPackageInstall); - - } - - @Test - public void testDomainLifecycleActions() throws Exception { - HashMap> types = new HashMap<>(); - types.put(ActionFactory.TYPE_VIRTUALIZATION_DELETE, VirtualizationDeleteGuestAction.class); - types.put(ActionFactory.TYPE_VIRTUALIZATION_REBOOT, VirtualizationRebootGuestAction.class); - types.put(ActionFactory.TYPE_VIRTUALIZATION_RESUME, VirtualizationResumeGuestAction.class); - types.put(ActionFactory.TYPE_VIRTUALIZATION_SHUTDOWN, VirtualizationShutdownGuestAction.class); - types.put(ActionFactory.TYPE_VIRTUALIZATION_START, VirtualizationStartGuestAction.class); - types.put(ActionFactory.TYPE_VIRTUALIZATION_SUSPEND, VirtualizationSuspendGuestAction.class); - - for (Entry> entry : types.entrySet()) { - Action a = ActionFactoryTest.createAction(user, entry.getKey()); - flushAndEvict(a); - - Action a1 = ActionFactory.lookupById(a.getId()); - assertNotNull(a1); - - assertTrue(entry.getValue().isInstance(a1)); - } - } - - @Test - public void testDomainForceoff() throws Exception { - Action a = ActionFactoryTest.createAction(user, ActionFactory.TYPE_VIRTUALIZATION_SHUTDOWN); - VirtualizationShutdownGuestAction va = (VirtualizationShutdownGuestAction)a; - va.setForce(true); - flushAndEvict(va); - - Action a1 = ActionFactory.lookupById(a.getId()); - assertNotNull(a1); - - assertTrue(a1 instanceof VirtualizationShutdownGuestAction); - VirtualizationShutdownGuestAction rebootAction = (VirtualizationShutdownGuestAction)a1; - assertTrue(rebootAction.isForce()); - } - - @Test - public void testDomainReset() throws Exception { - Action a = ActionFactoryTest.createAction(user, ActionFactory.TYPE_VIRTUALIZATION_REBOOT); - VirtualizationRebootGuestAction va = (VirtualizationRebootGuestAction)a; - va.setForce(true); - flushAndEvict(va); - - Action a1 = ActionFactory.lookupById(a.getId()); - assertNotNull(a1); - - assertTrue(a1 instanceof VirtualizationRebootGuestAction); - VirtualizationRebootGuestAction rebootAction = (VirtualizationRebootGuestAction)a1; - assertTrue(rebootAction.isForce()); - } - - @Test - public void testSetMemory() throws Exception { - Action a = ActionFactoryTest.createAction(user, ActionFactory.TYPE_VIRTUALIZATION_SET_MEMORY); - flushAndEvict(a); - - Action a1 = ActionFactory.lookupById(a.getId()); - assertNotNull(a1); - - VirtualizationSetMemoryGuestAction va = (VirtualizationSetMemoryGuestAction)a1; - assertEquals(Integer.valueOf(1234), va.getMemory()); - } - - @Test - public void testSetVcpus() throws Exception { - Action a = ActionFactoryTest.createAction(user, ActionFactory.TYPE_VIRTUALIZATION_SET_VCPUS); - flushAndEvict(a); - - Action a1 = ActionFactory.lookupById(a.getId()); - assertNotNull(a1); - - VirtualizationSetVcpusGuestAction va = (VirtualizationSetVcpusGuestAction)a1; - assertEquals(Integer.valueOf(12), va.getVcpu()); - } - - /** - * Test that virtualization creation actions are properly persisted and looked up - * - * @throws Exception something bad happened - */ - @Test - public void testCreateLookup() throws Exception { - Context.getCurrentContext().setTimezone(TimeZone.getDefault()); - - VirtualizationCreateGuestAction a1 = (VirtualizationCreateGuestAction)ActionFactoryTest - .createAction(user, ActionFactory.TYPE_VIRTUALIZATION_CREATE); - a1.setDetails(new GuestCreateDetails()); - a1.getDetails().setType("kvm"); - a1.getDetails().setName("guest0"); - a1.getDetails().setArch("x86_64"); - a1.getDetails().setMemory(1024L); - a1.getDetails().setVcpu(2L); - a1.getDetails().setOsType("hvm"); - a1.getDetails().setKernelOptions("kernelopts"); - a1.getDetails().setCobblerSystem("cobbler:system:id"); - a1.getDetails().setKickstartHost("https://cobbler.host.local"); - - List disks = new ArrayList<>(); - VirtualGuestsUpdateActionJson.DiskData disk0 = a1.getDetails().new DiskData(); - disk0.setTemplate("templateimage.qcow2"); - disk0.setBus("virtio"); - disk0.setPool("default"); - disks.add(disk0); - a1.getDetails().setDisks(disks); - - List nets = Arrays.asList("net0", "net1"); - a1.getDetails().setInterfaces( - nets.stream().map(net -> { - VirtualGuestsUpdateActionJson.InterfaceData detail = a1.getDetails().new InterfaceData(); - detail.setSource(net); - return detail; - }).collect(Collectors.toList())); - - flushAndEvict(a1); - - Action a = ActionFactory.lookupById(a1.getId()); - - assertNotNull(a); - assertTrue(a instanceof VirtualizationCreateGuestAction); - VirtualizationCreateGuestAction actual = (VirtualizationCreateGuestAction)a; - assertEquals("kvm", actual.getDetails().getType()); - assertEquals("guest0", actual.getDetails().getName()); - assertEquals("x86_64", actual.getDetails().getArch()); - assertEquals(Long.valueOf(1024), actual.getDetails().getMemory()); - assertEquals(Long.valueOf(2), actual.getDetails().getVcpu()); - assertEquals("hvm", actual.getDetails().getOsType()); - assertEquals("kernelopts", actual.getDetails().getKernelOptions()); - assertEquals("cobbler:system:id", actual.getDetails().getCobblerSystem()); - assertEquals("https://cobbler.host.local", actual.getDetails().getKickstartHost()); - - assertEquals(1, actual.getDetails().getDisks().size()); - assertEquals("templateimage.qcow2", actual.getDetails().getDisks().get(0).getTemplate()); - assertEquals("virtio", actual.getDetails().getDisks().get(0).getBus()); - assertEquals("default", actual.getDetails().getDisks().get(0).getPool()); - assertEquals(2, actual.getDetails().getInterfaces().size()); - assertEquals("net0", actual.getDetails().getInterfaces().get(0).getSource()); - assertEquals("net1", actual.getDetails().getInterfaces().get(1).getSource()); - } - - @Test - public void testPoolCreate() throws Exception { - VirtualizationPoolCreateAction a1 = (VirtualizationPoolCreateAction)ActionFactoryTest - .createAction(user, ActionFactory.TYPE_VIRTUALIZATION_POOL_CREATE); - a1.setName("pool0"); - a1.setType("iscsi"); - a1.setTarget("/dev/disk/by-path"); - VirtualizationPoolCreateActionSource src = new VirtualizationPoolCreateActionSource(); - src.setAuth(new PoolSourceAuthentication("myuser", "mysecret")); - src.setHosts(Arrays.asList("iscsi.example.com")); - src.setDevices(Arrays.asList(new PoolSourceDevice("iqn.2013-06.com.example:iscsi-pool"))); - a1.setSource(src); - a1.setMode("0744"); - a1.setOwner("107"); - a1.setGroup("108"); - a1.setSeclabel("virt_image_t"); - - flushAndEvict(a1); - - Action a = ActionFactory.lookupById(a1.getId()); - - assertNotNull(a); - assertTrue(a instanceof VirtualizationPoolCreateAction); - VirtualizationPoolCreateAction actual = (VirtualizationPoolCreateAction)a; - assertEquals("pool0", actual.getName()); - assertEquals("iscsi", actual.getType()); - assertEquals("/dev/disk/by-path", actual.getTarget()); - assertEquals("0744", actual.getMode()); - assertEquals("107", actual.getOwner()); - assertEquals("108", actual.getGroup()); - assertEquals("virt_image_t", actual.getSeclabel()); - assertEquals("myuser", actual.getSource().getAuth().getUsername()); - assertEquals("mysecret", actual.getSource().getAuth().getPassword()); - assertEquals("iscsi.example.com", actual.getSource().getHosts().get(0)); - assertEquals("iqn.2013-06.com.example:iscsi-pool", actual.getSource().getDevices().get(0).getPath()); - } -} diff --git a/java/code/src/com/redhat/rhn/domain/action/virtualization/test/VirtualizationPoolCreateActionSourceTest.java b/java/code/src/com/redhat/rhn/domain/action/virtualization/test/VirtualizationPoolCreateActionSourceTest.java deleted file mode 100644 index 7721eca2de46..000000000000 --- a/java/code/src/com/redhat/rhn/domain/action/virtualization/test/VirtualizationPoolCreateActionSourceTest.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (c) 2020--2021 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.virtualization.test; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import com.redhat.rhn.domain.action.virtualization.VirtualizationPoolCreateActionSource; - -import com.suse.manager.virtualization.PoolSourceDevice; - -import org.junit.jupiter.api.Test; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Optional; - -public class VirtualizationPoolCreateActionSourceTest { - - @Test - public void testNfsDir() { - VirtualizationPoolCreateActionSource src = new VirtualizationPoolCreateActionSource(); - src.setDir("/var/lib/libvirt/images"); - src.setFormat("nfs"); - src.setHosts(Arrays.asList("localhost")); - - String serialized = src.toString(); - assertEquals( - "{\"dir\":\"/var/lib/libvirt/images\"," + - "\"hosts\":[\"localhost\"]," + - "\"format\":\"nfs\"" + - "}", serialized); - - VirtualizationPoolCreateActionSource src2 = VirtualizationPoolCreateActionSource.parse(serialized); - assertEquals(src.getDir(), src2.getDir()); - assertEquals(src.getFormat(), src2.getFormat()); - assertEquals("localhost", src2.getHosts().get(0)); - } - - @Test - public void testDevice() { - VirtualizationPoolCreateActionSource src = new VirtualizationPoolCreateActionSource(); - List devices = new ArrayList<>(); - devices.add(new PoolSourceDevice("/dev/mapper/dev0")); - devices.add(new PoolSourceDevice("/dev/mapper/dev1", Optional.of(true))); - src.setDevices(devices); - - String serialized = src.toString(); - assertEquals("{\"devices\":[" + - "{\"path\":\"/dev/mapper/dev0\"}," + - "{\"path\":\"/dev/mapper/dev1\",\"separator\":true}]}", serialized); - } -} 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 64b3cb69a3ea..61e1762f4327 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 @@ -29,11 +29,9 @@ import com.redhat.rhn.testing.BaseTestCaseWithUser; import com.redhat.rhn.testing.ServerTestUtils; -import com.suse.manager.virtualization.VirtManagerSalt; 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.iface.VirtManager; import com.suse.manager.webui.services.test.TestSaltApi; import com.suse.manager.webui.services.test.TestSystemQuery; @@ -50,11 +48,10 @@ 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 VirtManager virtManager = new VirtManagerSalt(saltApi); private final MonitoringManager monitoringManager = new FormulaMonitoringManager(saltApi); private final SystemEntitlementManager systemEntitlementManager = new SystemEntitlementManager( - new SystemUnentitler(virtManager, monitoringManager, serverGroupManager), - new SystemEntitler(saltApi, virtManager, monitoringManager, serverGroupManager) + new SystemUnentitler(monitoringManager, serverGroupManager), + new SystemEntitler(saltApi, monitoringManager, serverGroupManager) ); @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 25afec026a8a..040bb3c1a291 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 @@ -30,10 +30,8 @@ import com.redhat.rhn.testing.ServerTestUtils; import com.suse.manager.reactor.utils.ValueMap; -import com.suse.manager.virtualization.VirtManagerSalt; import com.suse.manager.webui.services.iface.MonitoringManager; import com.suse.manager.webui.services.iface.SaltApi; -import com.suse.manager.webui.services.iface.VirtManager; import com.suse.manager.webui.services.test.TestSaltApi; import org.junit.jupiter.api.Test; @@ -45,11 +43,10 @@ public class ContainerBuildHostEntitlementTest extends BaseEntitlementTestCase { private final SaltApi saltApi = new TestSaltApi(); private final ServerGroupManager serverGroupManager = new ServerGroupManager(saltApi); - private final VirtManager virtManager = new VirtManagerSalt(saltApi); private final MonitoringManager monitoringManager = new FormulaMonitoringManager(saltApi); private final SystemEntitlementManager systemEntitlementManager = new SystemEntitlementManager( - new SystemUnentitler(virtManager, monitoringManager, serverGroupManager), - new SystemEntitler(saltApi, virtManager, monitoringManager, serverGroupManager) + new SystemUnentitler(monitoringManager, serverGroupManager), + new SystemEntitler(saltApi, monitoringManager, serverGroupManager) ); @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 9fc76729ad15..edd82898f9d2 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 @@ -30,11 +30,9 @@ import com.redhat.rhn.manager.system.entitling.SystemUnentitler; import com.redhat.rhn.testing.ServerTestUtils; -import com.suse.manager.virtualization.VirtManagerSalt; 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.iface.VirtManager; import com.suse.manager.webui.services.test.TestSaltApi; import com.suse.manager.webui.services.test.TestSystemQuery; @@ -46,11 +44,10 @@ 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 VirtManager virtManager = new VirtManagerSalt(saltApi); private final MonitoringManager monitoringManager = new FormulaMonitoringManager(saltApi); private final SystemEntitlementManager systemEntitlementManager = new SystemEntitlementManager( - new SystemUnentitler(virtManager, monitoringManager, serverGroupManager), - new SystemEntitler(saltApi, virtManager, monitoringManager, serverGroupManager) + new SystemUnentitler(monitoringManager, serverGroupManager), + new SystemEntitler(saltApi, monitoringManager, serverGroupManager) ); @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 c8d2c59d46ad..edba36a8dfba 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 @@ -31,11 +31,9 @@ import com.redhat.rhn.testing.ServerTestUtils; import com.redhat.rhn.testing.TestUtils; -import com.suse.manager.virtualization.VirtManagerSalt; 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.iface.VirtManager; import com.suse.manager.webui.services.test.TestSaltApi; import com.suse.manager.webui.services.test.TestSystemQuery; @@ -48,11 +46,10 @@ 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 VirtManager virtManager = new VirtManagerSalt(saltApi); private final MonitoringManager monitoringManager = new FormulaMonitoringManager(saltApi); private final SystemEntitlementManager systemEntitlementManager = new SystemEntitlementManager( - new SystemUnentitler(virtManager, monitoringManager, serverGroupManager), - new SystemEntitler(saltApi, virtManager, monitoringManager, serverGroupManager) + new SystemUnentitler(monitoringManager, serverGroupManager), + new SystemEntitler(saltApi, monitoringManager, serverGroupManager) ); @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 115bc3f4d548..db1b3817a276 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 @@ -30,11 +30,9 @@ import com.redhat.rhn.testing.ServerTestUtils; import com.suse.manager.reactor.utils.ValueMap; -import com.suse.manager.virtualization.VirtManagerSalt; 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.iface.VirtManager; import com.suse.manager.webui.services.test.TestSaltApi; import com.suse.manager.webui.services.test.TestSystemQuery; @@ -48,11 +46,10 @@ 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 VirtManager virtManager = new VirtManagerSalt(saltApi); private final MonitoringManager monitoringManager = new FormulaMonitoringManager(saltApi); private final SystemEntitlementManager systemEntitlementManager = new SystemEntitlementManager( - new SystemUnentitler(virtManager, monitoringManager, serverGroupManager), - new SystemEntitler(saltApi, virtManager, monitoringManager, serverGroupManager) + new SystemUnentitler(monitoringManager, serverGroupManager), + new SystemEntitler(saltApi, monitoringManager, serverGroupManager) ); @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 ee28ee6bfe6c..783f63e22fb8 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 @@ -66,11 +66,9 @@ import com.redhat.rhn.testing.TestUtils; import com.redhat.rhn.testing.UserTestUtils; -import com.suse.manager.virtualization.VirtManagerSalt; 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.iface.VirtManager; import com.suse.manager.webui.services.test.TestSaltApi; import com.suse.manager.webui.services.test.TestSystemQuery; import com.suse.manager.webui.utils.salt.custom.ImageChecksum; @@ -108,11 +106,10 @@ public class ImageInfoFactoryTest extends BaseTestCaseWithUser { private final SystemQuery systemQuery = new TestSystemQuery(); private final SaltApi saltApi = new TestSaltApi(); private final ServerGroupManager serverGroupManager = new ServerGroupManager(saltApi); - private final VirtManager virtManager = new VirtManagerSalt(saltApi); private final MonitoringManager monitoringManager = new FormulaMonitoringManager(saltApi); private final SystemEntitlementManager systemEntitlementManager = new SystemEntitlementManager( - new SystemUnentitler(virtManager, monitoringManager, serverGroupManager), - new SystemEntitler(saltApi, virtManager, monitoringManager, serverGroupManager) + new SystemUnentitler(monitoringManager, serverGroupManager), + new SystemEntitler(saltApi, monitoringManager, serverGroupManager) ); @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 beaf3544d653..980044fa75f1 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 @@ -107,12 +107,10 @@ import com.suse.manager.model.maintenance.MaintenanceSchedule; import com.suse.manager.utils.SaltKeyUtils; import com.suse.manager.utils.SaltUtils; -import com.suse.manager.virtualization.VirtManagerSalt; 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.iface.VirtManager; import com.suse.manager.webui.services.test.TestSaltApi; import com.suse.manager.webui.services.test.TestSystemQuery; import com.suse.salt.netapi.calls.LocalCall; @@ -155,11 +153,10 @@ public class ServerFactoryTest extends BaseTestCaseWithUser { SALT_UTILS, SALT_KEY_UTILS ); - private static final VirtManager VIRT_MANAGER = new VirtManagerSalt(SALT_API); private static final MonitoringManager MONITORING_MANAGER = new FormulaMonitoringManager(SALT_API); private static final SystemEntitlementManager SYSTEM_ENTITLEMENT_MANAGER = new SystemEntitlementManager( - new SystemUnentitler(VIRT_MANAGER, MONITORING_MANAGER, SERVER_GROUP_MANAGER), - new SystemEntitler(SALT_API, VIRT_MANAGER, MONITORING_MANAGER, SERVER_GROUP_MANAGER) + new SystemUnentitler(MONITORING_MANAGER, SERVER_GROUP_MANAGER), + new SystemEntitler(SALT_API, MONITORING_MANAGER, SERVER_GROUP_MANAGER) ); @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 6bcacfbc8c5e..0326f6223b8b 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 @@ -50,10 +50,8 @@ import com.redhat.rhn.testing.TestUtils; import com.redhat.rhn.testing.UserTestUtils; -import com.suse.manager.virtualization.VirtManagerSalt; import com.suse.manager.webui.services.iface.MonitoringManager; import com.suse.manager.webui.services.iface.SaltApi; -import com.suse.manager.webui.services.iface.VirtManager; import com.suse.manager.webui.services.test.TestSaltApi; import org.junit.jupiter.api.Test; @@ -71,13 +69,11 @@ public class ServerTest extends BaseTestCaseWithUser { private final SaltApi saltApi = new TestSaltApi(); private final ServerGroupManager serverGroupManager = new ServerGroupManager(saltApi); - private final VirtManager virtManager = new VirtManagerSalt(saltApi); private final MonitoringManager monitoringManager = new FormulaMonitoringManager(saltApi); private final SystemUnentitler systemUnentitler = new SystemUnentitler( - virtManager, monitoringManager, serverGroupManager); + monitoringManager, serverGroupManager); private final SystemEntitlementManager systemEntitlementManager = new SystemEntitlementManager( - systemUnentitler, - new SystemEntitler(saltApi, virtManager, monitoringManager, serverGroupManager) + systemUnentitler, new SystemEntitler(saltApi, monitoringManager, serverGroupManager) ); @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 0a495363ae87..f04f0c1b0746 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 @@ -35,10 +35,8 @@ import com.redhat.rhn.testing.TestUtils; import com.redhat.rhn.testing.UserTestUtils; -import com.suse.manager.virtualization.test.TestVirtManager; import com.suse.manager.webui.services.iface.MonitoringManager; import com.suse.manager.webui.services.iface.SaltApi; -import com.suse.manager.webui.services.iface.VirtManager; import com.suse.manager.webui.services.test.TestSaltApi; import org.apache.commons.collections.CollectionUtils; @@ -70,11 +68,10 @@ public void setUp() { builder = new GuestBuilder(user); SaltApi saltApi = new TestSaltApi(); ServerGroupManager serverGroupManager = new ServerGroupManager(saltApi); - VirtManager virtManager = new TestVirtManager(); MonitoringManager monitoringManager = new FormulaMonitoringManager(saltApi); systemEntitlementManager = new SystemEntitlementManager( - new SystemUnentitler(virtManager, monitoringManager, serverGroupManager), - new SystemEntitler(saltApi, virtManager, monitoringManager, serverGroupManager) + new SystemUnentitler(monitoringManager, serverGroupManager), + new SystemEntitler(saltApi, monitoringManager, serverGroupManager) ); } 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 c1f66dca045e..02d16ba22f56 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 @@ -46,9 +46,7 @@ import com.redhat.rhn.testing.ServerTestUtils; import com.redhat.rhn.testing.UserTestUtils; -import com.suse.manager.virtualization.VirtManagerSalt; import com.suse.manager.webui.services.iface.MonitoringManager; -import com.suse.manager.webui.services.iface.VirtManager; import com.suse.manager.webui.services.impl.SaltSSHService; import com.suse.manager.webui.services.impl.SaltService; import com.suse.salt.netapi.datatypes.target.MinionList; @@ -81,11 +79,10 @@ public void setUp() throws Exception { context.setImposteriser(ByteBuddyClassImposteriser.INSTANCE); saltServiceMock = context.mock(SaltService.class); ServerGroupManager serverGroupManager = new ServerGroupManager(saltServiceMock); - VirtManager virtManager = new VirtManagerSalt(saltServiceMock); MonitoringManager monitoringManager = new FormulaMonitoringManager(saltServiceMock); systemEntitlementManager = new SystemEntitlementManager( - new SystemUnentitler(virtManager, monitoringManager, serverGroupManager), - new SystemEntitler(saltServiceMock, virtManager, monitoringManager, serverGroupManager) + new SystemUnentitler(monitoringManager, serverGroupManager), + new SystemEntitler(saltServiceMock, monitoringManager, serverGroupManager) ); 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 fdc0b8c84004..fdb4f9b0fb06 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 @@ -39,11 +39,9 @@ import com.redhat.rhn.testing.RhnPostMockStrutsTestCase; import com.redhat.rhn.testing.ServerTestUtils; -import com.suse.manager.virtualization.VirtManagerSalt; 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.iface.VirtManager; import com.suse.manager.webui.services.test.TestSaltApi; import com.suse.manager.webui.services.test.TestSystemQuery; @@ -64,11 +62,10 @@ 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 VirtManager virtManager = new VirtManagerSalt(saltApi); private final MonitoringManager monitoringManager = new FormulaMonitoringManager(saltApi); private final SystemEntitlementManager systemEntitlementManager = new SystemEntitlementManager( - new SystemUnentitler(virtManager, monitoringManager, serverGroupManager), - new SystemEntitler(saltApi, virtManager, monitoringManager, serverGroupManager) + new SystemUnentitler(monitoringManager, serverGroupManager), + new SystemEntitler(saltApi, monitoringManager, serverGroupManager) ); diff --git a/java/code/src/com/redhat/rhn/frontend/action/systems/images/ScheduleImageDeploymentAction.java b/java/code/src/com/redhat/rhn/frontend/action/systems/images/ScheduleImageDeploymentAction.java deleted file mode 100644 index a4531460e0cc..000000000000 --- a/java/code/src/com/redhat/rhn/frontend/action/systems/images/ScheduleImageDeploymentAction.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright (c) 2012 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.frontend.action.systems.images; - -import com.redhat.rhn.domain.action.Action; -import com.redhat.rhn.domain.image.ProxyConfig; -import com.redhat.rhn.domain.server.Server; -import com.redhat.rhn.domain.user.User; -import com.redhat.rhn.frontend.struts.RequestContext; -import com.redhat.rhn.frontend.struts.RhnAction; -import com.redhat.rhn.frontend.struts.RhnHelper; -import com.redhat.rhn.manager.action.ActionManager; -import com.redhat.rhn.manager.system.SystemManager; - -import org.apache.commons.lang3.StringUtils; -import org.apache.struts.action.ActionForm; -import org.apache.struts.action.ActionForward; -import org.apache.struts.action.ActionMapping; -import org.apache.struts.action.DynaActionForm; - -import java.util.Map; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -/** - * This action will schedule image deployment for an image given by URL. - */ -public class ScheduleImageDeploymentAction extends RhnAction { - - private static final String SUCCESS_KEY = "images.message.success.scheduled"; - - /** {@inheritDoc} */ - @Override - public ActionForward execute(ActionMapping actionMapping, - ActionForm actionForm, HttpServletRequest request, - HttpServletResponse response) { - - // Get the current user - RequestContext ctx = new RequestContext(request); - User user = ctx.getCurrentUser(); - - // Put the server object to the request (for system header) - Long sid = Long.valueOf(request.getParameter(RequestContext.SID)); - Server server = SystemManager.lookupByIdAndUser(sid, user); - request.setAttribute("system", server); - - ActionForward forward; - if (request.getParameter(RequestContext.DISPATCH) != null) { - // Read the form parameters - DynaActionForm form = (DynaActionForm) actionForm; - Long vcpus = (Long) form.get("vcpus"); - Long memkb = (Long) form.get("mem_mb") * 1024; - String bridge = form.getString("bridge"); - String proxyServer = form.getString("proxy_server"); - String proxyUser = form.getString("proxy_user"); - String proxyPass = form.getString("proxy_pass"); - - // Set up the proxy configuration - ProxyConfig proxy = null; - if (StringUtils.isNotEmpty(proxyServer)) { - proxy = new ProxyConfig(proxyServer, proxyUser, proxyPass); - } - - // Put defaults for deployment parameters - if (vcpus <= 0) { - vcpus = 1L; - } - if (memkb <= 0) { - memkb = 524288L; - } - - // Create the action and store it - String imageUrl = form.getString("image_url"); - - if (StringUtils.isEmpty(imageUrl)) { - createErrorMessage(request, "images.jsp.error.noimage", null); - forward = actionMapping.findForward(RhnHelper.DEFAULT_FORWARD); - } - else { - Action action = ActionManager.createDeployImageAction(user, imageUrl, - vcpus, memkb, bridge, proxy); - ActionManager.addServerToAction(sid, action); - ActionManager.storeAction(action); - createSuccessMessage(request, SUCCESS_KEY, imageUrl); - - // Forward the sid as a request parameter - Map forwardParams = makeParamMap(request); - forwardParams.put(RequestContext.SID, sid); - forward = getStrutsDelegate().forwardParams( - actionMapping.findForward("submitted"), forwardParams); - } - } - else { - forward = actionMapping.findForward(RhnHelper.DEFAULT_FORWARD); - } - return forward; - } -} 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 6119ec3083ff..1d6ef2c9a6f2 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 @@ -39,11 +39,9 @@ import com.redhat.rhn.testing.TestUtils; import com.redhat.rhn.testing.UserTestUtils; -import com.suse.manager.virtualization.VirtManagerSalt; 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.iface.VirtManager; import com.suse.manager.webui.services.test.TestSaltApi; import com.suse.manager.webui.services.test.TestSystemQuery; @@ -65,11 +63,10 @@ public class SystemDetailsEditActionTest extends RhnPostMockStrutsTestCase { private final SystemQuery systemQuery = new TestSystemQuery(); private final SaltApi saltApi = new TestSaltApi(); private final ServerGroupManager serverGroupManager = new ServerGroupManager(saltApi); - private final VirtManager virtManager = new VirtManagerSalt(saltApi); private final MonitoringManager monitoringManager = new FormulaMonitoringManager(saltApi); private final SystemEntitlementManager systemEntitlementManager = new SystemEntitlementManager( - new SystemUnentitler(virtManager, monitoringManager, serverGroupManager), - new SystemEntitler(saltApi, virtManager, monitoringManager, serverGroupManager) + new SystemUnentitler(monitoringManager, serverGroupManager), + new SystemEntitler(saltApi, monitoringManager, serverGroupManager) ); /** 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 d485f0c56866..340abe7f0cef 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 @@ -41,10 +41,8 @@ import com.redhat.rhn.testing.RhnMockStrutsTestCase; import com.redhat.rhn.testing.TestUtils; -import com.suse.manager.virtualization.VirtManagerSalt; import com.suse.manager.webui.services.iface.MonitoringManager; import com.suse.manager.webui.services.iface.SaltApi; -import com.suse.manager.webui.services.iface.VirtManager; import com.suse.manager.webui.services.test.TestSaltApi; import org.junit.jupiter.api.BeforeEach; @@ -62,11 +60,10 @@ public class SystemOverviewActionTest extends RhnMockStrutsTestCase { protected Server s; private final SaltApi saltApi = new TestSaltApi(); private final ServerGroupManager serverGroupManager = new ServerGroupManager(saltApi); - private final VirtManager virtManager = new VirtManagerSalt(saltApi); private final MonitoringManager monitoringManager = new FormulaMonitoringManager(saltApi); private final SystemEntitlementManager systemEntitlementManager = new SystemEntitlementManager( - new SystemUnentitler(virtManager, monitoringManager, serverGroupManager), - new SystemEntitler(saltApi, virtManager, monitoringManager, serverGroupManager) + new SystemUnentitler(monitoringManager, serverGroupManager), + new SystemEntitler(saltApi, monitoringManager, serverGroupManager) ); /** diff --git a/java/code/src/com/redhat/rhn/frontend/action/systems/virtualization/ProvisionVirtualizationWizardAction.java b/java/code/src/com/redhat/rhn/frontend/action/systems/virtualization/ProvisionVirtualizationWizardAction.java deleted file mode 100644 index ede873cf57f7..000000000000 --- a/java/code/src/com/redhat/rhn/frontend/action/systems/virtualization/ProvisionVirtualizationWizardAction.java +++ /dev/null @@ -1,370 +0,0 @@ -/* - * Copyright (c) 2009--2014 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. - */ -package com.redhat.rhn.frontend.action.systems.virtualization; - -import com.redhat.rhn.common.localization.LocalizationService; -import com.redhat.rhn.common.util.DatePicker; -import com.redhat.rhn.common.validator.ValidatorError; -import com.redhat.rhn.domain.kickstart.KickstartData; -import com.redhat.rhn.domain.kickstart.KickstartFactory; -import com.redhat.rhn.domain.server.Server; -import com.redhat.rhn.domain.user.User; -import com.redhat.rhn.frontend.action.kickstart.KickstartHelper; -import com.redhat.rhn.frontend.action.kickstart.ScheduleKickstartWizardAction; -import com.redhat.rhn.frontend.struts.RequestContext; -import com.redhat.rhn.frontend.struts.RhnValidationHelper; -import com.redhat.rhn.frontend.struts.wizard.WizardStep; -import com.redhat.rhn.manager.kickstart.KickstartScheduleCommand; -import com.redhat.rhn.manager.kickstart.ProvisionVirtualInstanceCommand; -import com.redhat.rhn.manager.kickstart.cobbler.CobblerXMLRPCHelper; -import com.redhat.rhn.manager.system.SystemManager; - -import org.apache.commons.lang3.StringUtils; -import org.apache.struts.action.ActionErrors; -import org.apache.struts.action.ActionForward; -import org.apache.struts.action.ActionMapping; -import org.apache.struts.action.ActionMessage; -import org.apache.struts.action.ActionMessages; -import org.apache.struts.action.DynaActionForm; -import org.cobbler.Profile; - -import java.util.Date; -import java.util.HashMap; -import java.util.Map; -import java.util.regex.Pattern; - -import javax.servlet.http.HttpServletResponse; -/** - * ProvisionVirtualizationWizardAction extends ScheduleKickstartWizardAction - */ -public class ProvisionVirtualizationWizardAction extends ScheduleKickstartWizardAction { - - public static final String MEMORY_ALLOCATION = "memoryAllocation"; - public static final String VIRTUAL_CPUS = "virtualCpus"; - public static final String VIRTUAL_BRIDGE = "virtBridge"; - public static final String VIRTUAL_FILE_PATH = "diskPath"; - public static final String LOCAL_STORAGE_GB = "localStorageGigabytes"; - public static final String MAC_ADDRESS = "macAddress"; - public static final String PROFILE = "cobbler_profile"; - - public static final String GUEST_NAME = "guestName"; - - /** - * {@inheritDoc} - */ - @Override - public ActionForward runFirst(ActionMapping mapping, DynaActionForm form, - RequestContext ctx, HttpServletResponse response, - WizardStep step) throws Exception { - Long sid = (Long) form.get(RequestContext.SID); - User user = ctx.getCurrentUser(); - Server system = SystemManager.lookupByIdAndUser(sid, user); - - if (StringUtils.isEmpty(form.getString(MEMORY_ALLOCATION))) { - form.set(MEMORY_ALLOCATION, ""); - } - - if (StringUtils.isEmpty(form.getString(VIRTUAL_CPUS))) { - form.set(VIRTUAL_CPUS, ""); - } - - if (StringUtils.isEmpty(form.getString(LOCAL_STORAGE_GB))) { - form.set(LOCAL_STORAGE_GB, ""); - } - - if (StringUtils.isEmpty(form.getString(MAC_ADDRESS))) { - form.set(MAC_ADDRESS, ""); - } - - return super.runFirst(mapping, form, ctx, response, step); - } - - /** - * {@inheritDoc} - */ - @Override - public ActionForward runSecond(ActionMapping mapping, DynaActionForm form, - RequestContext ctx, HttpServletResponse response, - WizardStep step) throws Exception { - if (!validateFirstSelections(form, ctx)) { - return runFirst(mapping, form, ctx, response, step); - } - ActionErrors errors = validateInput(form); - if (!errors.isEmpty()) { - addErrors(ctx.getRequest(), errors); - //saveMessages(ctx.getRequest(), errors); - return runFirst(mapping, form, ctx, response, step); - } - ActionForward forward = super.runSecond(mapping, form, ctx, response, step); - - Profile pf = getCobblerProfile(ctx); - KickstartData ksdata = ctx.lookupAndBindKickstartData(); - if (StringUtils.isEmpty(form.getString(VIRTUAL_FILE_PATH))) { - form.set(VIRTUAL_FILE_PATH, ProvisionVirtualInstanceCommand. - makeDefaultVirtPath(form.getString(GUEST_NAME), - ksdata.getKickstartDefaults().getVirtualizationType())); - } - if (StringUtils.isEmpty(form.getString(MEMORY_ALLOCATION))) { - form.set(MEMORY_ALLOCATION, String.valueOf(pf.getVirtRam())); - } - - if (StringUtils.isEmpty(form.getString(VIRTUAL_CPUS))) { - form.set(VIRTUAL_CPUS, String.valueOf(pf.getVirtCpus())); - } - - if (StringUtils.isEmpty(form.getString(LOCAL_STORAGE_GB))) { - form.set(LOCAL_STORAGE_GB, String.valueOf(pf.getVirtFileSize())); - } - - if (StringUtils.isEmpty(form.getString(VIRTUAL_BRIDGE))) { - form.set(VIRTUAL_BRIDGE, String.valueOf(pf.getVirtBridge())); - } - - if (StringUtils.isEmpty(form.getString(TARGET_PROFILE_TYPE))) { - form.set(TARGET_PROFILE_TYPE, - KickstartScheduleCommand.TARGET_PROFILE_TYPE_NONE); - } - return forward; - } - - /** - * {@inheritDoc} - */ - @Override - public ActionForward runThird(ActionMapping mapping, DynaActionForm form, - RequestContext ctx, HttpServletResponse response, - WizardStep step) throws Exception { - if (!validateFirstSelections(form, ctx)) { - return runFirst(mapping, form, ctx, response, step); - } - - ActionErrors errors = validateInput(form); - if (!errors.isEmpty()) { - addErrors(ctx.getRequest(), errors); - //saveMessages(ctx.getRequest(), errors); - return runFirst(mapping, form, ctx, response, step); - } - - String scheduleAsap = form.getString("scheduleAsap"); - Date scheduleTime = null; - if (scheduleAsap != null && scheduleAsap.equals("false")) { - scheduleTime = getStrutsDelegate().readScheduleDate(form, "date", - DatePicker.YEAR_RANGE_POSITIVE); - } - else { - scheduleTime = new Date(); - } - KickstartHelper helper = new KickstartHelper(ctx.getRequest()); - - ProvisionVirtualInstanceCommand cmd = getScheduleCommand(form, - ctx, scheduleTime, helper.getKickstartHost()); - - cmd.setKernelOptions(form.getString(KERNEL_PARAMS)); - - cmd.setProfileType(form.getString("targetProfileType")); - cmd.setServerProfileId((Long) form.get("targetServerProfile")); - cmd.setProfileId((Long) form.get("targetProfile")); - - cmd.setGuestName(form.getString(GUEST_NAME)); - - - //If the virt options are overridden use them, otherwise use - // The profile's values - if (!StringUtils.isEmpty(form.getString(MEMORY_ALLOCATION))) { - cmd.setMemoryAllocation(Long.valueOf(form.getString(MEMORY_ALLOCATION))); - } - else { - cmd.setMemoryAllocation((long) this.getCobblerProfile(ctx).getVirtRam().get()); - } - - if (!StringUtils.isEmpty(form.getString(VIRTUAL_CPUS))) { - cmd.setVirtualCpus(Long.valueOf(form.getString(VIRTUAL_CPUS))); - } - else { - cmd.setVirtualCpus((long) this.getCobblerProfile(ctx).getVirtCpus().get()); - } - - if (!StringUtils.isEmpty(form.getString(LOCAL_STORAGE_GB))) { - cmd.setLocalStorageSize(Long.valueOf(form.getString(LOCAL_STORAGE_GB))); - } - else { - cmd.setLocalStorageSize(this.getCobblerProfile(ctx).getVirtFileSize().get().longValue()); - } - - if (!StringUtils.isEmpty(form.getString(VIRTUAL_BRIDGE))) { - cmd.setVirtBridge(form.getString(VIRTUAL_BRIDGE)); - } - else { - cmd.setVirtBridge(this.getCobblerProfile(ctx).getVirtBridge().get()); - } - if (!StringUtils.isEmpty(form.getString(MAC_ADDRESS))) { - String macAddress = form.getString(MAC_ADDRESS); - macAddress = macAddress.replace(":", ""); - macAddress = macAddress.toLowerCase(); - macAddress = macAddress.substring(0, 2) + ":" + - macAddress.substring(2, 4) + ":" + - macAddress.substring(4, 6) + ":" + - macAddress.substring(6, 8) + ":" + - macAddress.substring(8, 10) + ":" + - macAddress.substring(10); - cmd.setMacAddress(macAddress); - } - cmd.setFilePath(form.getString(VIRTUAL_FILE_PATH)); - storeProxyInfo(form, ctx, cmd); - // Store the new KickstartSession to the DB. - ValidatorError ve = cmd.store(); - if (ve != null) { - errors = RhnValidationHelper.validatorErrorToActionErrors(ve); - if (!errors.isEmpty()) { - getStrutsDelegate().saveMessages(ctx.getRequest(), errors); - return runFirst(mapping, form, ctx, response, step); - } - } - - createSuccessMessage(ctx.getRequest(), "kickstart.schedule.success", - LocalizationService.getInstance().formatDate(scheduleTime)); - Map params = new HashMap<>(); - params.put(RequestContext.SID, form.get(RequestContext.SID)); - - return getStrutsDelegate().forwardParams(mapping.findForward("success"), params); - } - @Override - protected KickstartScheduleCommand getKickstartScheduleCommand(Long sid, - User currentUser) { - return new ProvisionVirtualInstanceCommand(sid, currentUser); - } - - - private ActionErrors validateInput(DynaActionForm form) { - ActionErrors errors = new ActionErrors(); - String name = form.getString(GUEST_NAME); - - if (name.length() < ProvisionVirtualInstanceCommand.MIN_NAME_SIZE) { - errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage( - "frontend.actions.systems.virt.invalidguestnamelength", - (ProvisionVirtualInstanceCommand.MIN_NAME_SIZE))); - } - - Pattern pattern = Pattern.compile( - ProvisionVirtualInstanceCommand.GUEST_NAME_REGEXP, - Pattern.CASE_INSENSITIVE); - if (!pattern.matcher(name).matches()) { - errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage( - "frontend.actions.systems.virt.invalidregexp")); - } - - if (!StringUtils.isEmpty(form.getString(MEMORY_ALLOCATION))) { - try { - Long memory = Long.parseLong(form.getString(MEMORY_ALLOCATION)); - if (memory <= 0) { - throw new NumberFormatException(); - } - } - catch (NumberFormatException e) { - errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage( - "frontend.actions.systems.virt.invalidmemvalue")); - } - } - - if (!StringUtils.isEmpty(form.getString(VIRTUAL_CPUS))) { - try { - Long cpus = Long.parseLong(form.getString(VIRTUAL_CPUS)); - if (cpus <= 0 || cpus > ProvisionVirtualInstanceCommand.MAX_CPU) { - throw new NumberFormatException(); - } - } - catch (NumberFormatException e) { - errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage( - "frontend.actions.systems.virt.invalidcpuvalue", - (ProvisionVirtualInstanceCommand.MAX_CPU + 1))); - } - } - - if (!StringUtils.isEmpty(form.getString(LOCAL_STORAGE_GB))) { - try { - Long storage = Long.parseLong(form.getString(LOCAL_STORAGE_GB)); - if (storage <= 0) { - throw new NumberFormatException(); - } - } - catch (NumberFormatException e) { - errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage( - "frontend.actions.systems.virt.invalidstoragevalue")); - form.set(LOCAL_STORAGE_GB, ""); - } - } - - if (!StringUtils.isEmpty(form.getString(MAC_ADDRESS))) { - try { - String macAddress = form.getString(MAC_ADDRESS); - macAddress = macAddress.replace(":", ""); - if (macAddress.length() != 12 || - !macAddress.matches("^[0-9a-fA-F]+$")) { - throw new NumberFormatException(); - } - } - catch (NumberFormatException e) { - errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage( - "frontend.actions.systems.virt.invalidmacaddressvalue")); - form.set(MAC_ADDRESS, ""); - } - } - - return errors; - } - - /** - * Get the cobbler profile - * @param context the request context - * @return the cobbler profile - */ - private Profile getCobblerProfile(RequestContext context) { - if (context.getRequest().getAttribute(PROFILE) == null) { - String cobblerId = (String) context.getRequest().getAttribute( - RequestContext.COBBLER_ID); - User user = context.getCurrentUser(); - Profile cobblerProfile = Profile.lookupById( - CobblerXMLRPCHelper.getConnection(user), cobblerId); - context.getRequest().setAttribute(PROFILE, cobblerProfile); - } - return (Profile) context.getRequest().getAttribute(PROFILE); - } - - @Override - protected ProvisionVirtualInstanceCommand getScheduleCommand(DynaActionForm form, - RequestContext ctx, Date scheduleTime, String host) { - Profile cobblerProfile = getCobblerProfile(ctx); - User user = ctx.getCurrentUser(); - ProvisionVirtualInstanceCommand cmd; - KickstartData data = KickstartFactory. - lookupKickstartDataByCobblerIdAndOrg(user.getOrg(), cobblerProfile.getId()); - - if (data != null) { - cmd = - new ProvisionVirtualInstanceCommand( - (Long) form.get(RequestContext.SID), - data, - ctx.getCurrentUser(), - scheduleTime, - host); - } - else { - cmd = ProvisionVirtualInstanceCommand.createCobblerScheduleCommand((Long) - form.get(RequestContext.SID), cobblerProfile.getName(), - user, scheduleTime, host); - } - return cmd; - } -} diff --git a/java/code/src/com/redhat/rhn/frontend/action/systems/virtualization/test/ProvisionVirtualizationWizardActionTest.java b/java/code/src/com/redhat/rhn/frontend/action/systems/virtualization/test/ProvisionVirtualizationWizardActionTest.java deleted file mode 100644 index 615928bf6135..000000000000 --- a/java/code/src/com/redhat/rhn/frontend/action/systems/virtualization/test/ProvisionVirtualizationWizardActionTest.java +++ /dev/null @@ -1,238 +0,0 @@ -/* - * Copyright (c) 2009--2014 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. - */ -package com.redhat.rhn.frontend.action.systems.virtualization.test; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; - -import com.redhat.rhn.common.conf.ConfigDefaults; -import com.redhat.rhn.common.db.datasource.Row; -import com.redhat.rhn.domain.channel.Channel; -import com.redhat.rhn.domain.channel.test.ChannelFactoryTest; -import com.redhat.rhn.domain.kickstart.KickstartData; -import com.redhat.rhn.domain.kickstart.KickstartFactory; -import com.redhat.rhn.domain.kickstart.KickstartSession; -import com.redhat.rhn.domain.kickstart.test.KickstartDataTest; -import com.redhat.rhn.domain.role.RoleFactory; -import com.redhat.rhn.domain.server.EntitlementServerGroup; -import com.redhat.rhn.domain.server.Server; -import com.redhat.rhn.domain.server.ServerConstants; -import com.redhat.rhn.domain.server.ServerFactory; -import com.redhat.rhn.domain.server.test.ServerFactoryTest; -import com.redhat.rhn.domain.token.ActivationKey; -import com.redhat.rhn.domain.token.ActivationKeyFactory; -import com.redhat.rhn.domain.token.Token; -import com.redhat.rhn.domain.token.TokenFactory; -import com.redhat.rhn.frontend.action.kickstart.ScheduleKickstartWizardAction; -import com.redhat.rhn.frontend.action.kickstart.test.ScheduleKickstartWizardTest; -import com.redhat.rhn.frontend.action.systems.virtualization.ProvisionVirtualizationWizardAction; -import com.redhat.rhn.frontend.dto.ProfileDto; -import com.redhat.rhn.frontend.struts.RequestContext; -import com.redhat.rhn.manager.formula.FormulaMonitoringManager; -import com.redhat.rhn.manager.kickstart.KickstartScheduleCommand; -import com.redhat.rhn.manager.profile.test.ProfileManagerTest; -import com.redhat.rhn.manager.rhnpackage.test.PackageManagerTest; -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.RhnMockStrutsTestCase; -import com.redhat.rhn.testing.ServerGroupTestUtils; -import com.redhat.rhn.testing.TestUtils; - -import com.suse.manager.virtualization.VirtManagerSalt; -import com.suse.manager.webui.services.iface.MonitoringManager; -import com.suse.manager.webui.services.iface.SaltApi; -import com.suse.manager.webui.services.iface.VirtManager; -import com.suse.manager.webui.services.test.TestSaltApi; - -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import java.util.HashSet; -import java.util.Set; - - -/** - * ProvisionVirtualizationWizardActionTest - */ -public class ProvisionVirtualizationWizardActionTest extends RhnMockStrutsTestCase { - - private Server s; - private final SaltApi saltApi = new TestSaltApi(); - private final ServerGroupManager serverGroupManager = new ServerGroupManager(saltApi); - private final VirtManager virtManager = new VirtManagerSalt(saltApi); - private final MonitoringManager monitoringManager = new FormulaMonitoringManager(saltApi); - private final SystemEntitlementManager systemEntitlementManager = new SystemEntitlementManager( - new SystemUnentitler(virtManager, monitoringManager, serverGroupManager), - new SystemEntitler(saltApi, virtManager, monitoringManager, serverGroupManager) - ); - - /** - * {@inheritDoc} - */ - @Override - @BeforeEach - public void setUp() throws Exception { - super.setUp(); - setRequestPathInfo("/systems/details/virtualization/ProvisionVirtualizationWizard"); - user.addPermanentRole(RoleFactory.ORG_ADMIN); - s = ServerFactoryTest.createTestServer(user, true, - ServerConstants.getServerGroupTypeEnterpriseEntitled()); - s.addChannel(ChannelFactoryTest.createBaseChannel(user)); - EntitlementServerGroup sg = ServerGroupTestUtils.createEntitled(user.getOrg(), - ServerFactory.lookupServerGroupTypeByLabel("enterprise_entitled")); - systemEntitlementManager.addEntitlementToServer(s, sg.getGroupType().getAssociatedEntitlement()); - Channel c = ChannelFactoryTest.createTestChannel(user); - // Required so the Server has a base channel - // otherwise we cant ks. - s.addChannel(c); - - PackageManagerTest.addPackageToSystemAndChannel( - ConfigDefaults.get().getKickstartPackageNames().get(0), s, c); - TestUtils.saveAndFlush(s); - TestUtils.saveAndFlush(c); - - PackageManagerTest. - addUp2dateToSystemAndChannel(user, s, - KickstartScheduleCommand.UP2DATE_VERSION, c); - - TestUtils.flushAndEvict(s); - TestUtils.flushAndEvict(c); - addRequestParameter(RequestContext.SID, s.getId().toString()); - } - - @Test - public void testStepOne() { - actionPerform(); - verifyNoActionErrors(); - } - - @Test - public void testStepTwo() throws Exception { - KickstartData k = KickstartDataTest.createKickstartWithProfile(user); - ProfileManagerTest.createProfileWithServer(user); - - ActivationKey key = ActivationKeyFactory.createNewKey(user, "some key"); - ActivationKeyFactory.save(key); - key = TestUtils.reload(key); - Token t = TokenFactory.lookupById(key.getId()); - Set tokens = new HashSet<>(); - tokens.add(t); - k.setDefaultRegTokens(tokens); - - - // Step Two - addRequestParameter(RequestContext.SID, s.getId().toString()); - addRequestParameter("wizardStep", "second"); - addRequestParameter("items_selected", k.getCobblerId().toString()); - addRequestParameter("scheduleAsap", "false"); - addRequestParameter("date_month", "2"); - addRequestParameter("date_day", "16"); - addRequestParameter("date_year", "2006"); - addRequestParameter("date_hour", "8"); - addRequestParameter("date_minute", "0"); - addRequestParameter("date_am_pm", "1"); - addRequestParameter(ProvisionVirtualizationWizardAction.GUEST_NAME, "testName"); - addRequestParameter(RequestContext.COBBLER_ID, k.getCobblerId()); - actionPerform(); - verifyNoActionErrors(); - assertNotNull(request.getAttribute(RequestContext.KICKSTART)); - assertNotNull(request.getAttribute(RequestContext.SYSTEM)); - verifyFormList(ScheduleKickstartWizardAction.SYNCH_PACKAGES, - ProfileDto.class); - verifyFormList(ScheduleKickstartWizardAction.SYNCH_SYSTEMS, - Row.class); - - } - - public void executeStepThree(boolean addProxy) throws Exception { - // Perform step 1 - actionPerform(); - verifyNoActionErrors(); - try { - verifyActionMessage("kickstart.schedule.noprofiles"); - } - catch (AssertionError e) { - verifyActionMessages(new String[] {"kickstart.schedule.noprofiles"}); - } - assertNotNull(request.getAttribute(RequestContext.SYSTEM)); - clearRequestParameters(); - - // Perform step2 - KickstartData k = KickstartDataTest.createKickstartWithProfile(user); - // Required so the server and profile match base channels - k.getKickstartDefaults().getKstree().setChannel(s.getBaseChannel()); - - // Create other server to sync - Server otherServer = ServerFactoryTest.createTestServer(user, true, - ServerConstants.getServerGroupTypeEnterpriseEntitled()); - otherServer.addChannel(ChannelFactoryTest.createTestChannel(user)); - - addRequestParameter(RequestContext.SID, s.getId().toString()); - addRequestParameter("targetProfileType", - KickstartScheduleCommand.TARGET_PROFILE_TYPE_SYSTEM); - addRequestParameter("targetServerProfile", otherServer.getId().toString()); - addRequestParameter("wizardStep", "third"); - addRequestParameter("items_selected", k.getCobblerId().toString()); - addRequestParameter("scheduleAsap", "false"); - addRequestParameter("date_month", "2"); - addRequestParameter("date_day", "16"); - addRequestParameter("date_year", "2006"); - addRequestParameter("date_hour", "8"); - addRequestParameter("date_minute", "0"); - addRequestParameter("date_am_pm", "1"); - addRequestParameter(ProvisionVirtualizationWizardAction.GUEST_NAME, "testName"); - addRequestParameter(RequestContext.COBBLER_ID, k.getCobblerId()); - Server proxy = null; - if (addProxy) { - proxy = ScheduleKickstartWizardTest.addProxy(user, s); - assertNotNull(proxy.getHostname()); - /** Assign a proxy host, this would be the case - * When user selects a proxy entry from the proxies combo - */ - addRequestParameter(ScheduleKickstartWizardAction.PROXY_HOST, - proxy.getId().toString()); - } - - actionPerform(); - verifyNoActionErrors(); - - verifyActionMessage("kickstart.schedule.success"); - assertEquals(getActualForward(), - "/systems/details/kickstart/SessionStatus.do?sid=" + s.getId()); - - assertNotNull(KickstartFactory.lookupKickstartSessionByServer(s.getId())); - if (addProxy && proxy != null) { - verifyFormValue(ScheduleKickstartWizardAction.PROXY_HOST, - proxy.getId().toString()); - KickstartSession session = KickstartFactory. - lookupKickstartSessionByServer(s.getId()); - assertNotNull(session.getSystemRhnHost()); - assertEquals(proxy.getHostname(), session.getSystemRhnHost()); - } - } - - - @Test - public void testStepThreeWithProxy() throws Exception { - executeStepThree(true); - } - - @Test - public void testStepThreeNoProxy() throws Exception { - executeStepThree(false); - } -} 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 31fa55deddf1..4d5cfe15211a 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 @@ -64,13 +64,11 @@ import com.suse.cloud.CloudPaygManager; import com.suse.cloud.test.TestCloudPaygManagerBuilder; import com.suse.manager.attestation.AttestationManager; -import com.suse.manager.virtualization.VirtManagerSalt; 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.iface.VirtManager; import com.suse.manager.webui.services.test.TestSaltApi; import com.suse.manager.webui.services.test.TestSystemQuery; @@ -108,11 +106,10 @@ public class AdminConfigurationHandlerTest extends BaseHandlerTestCase { regularMinionBootstrapper, sshMinionBootstrapper ); - private final VirtManager virtManager = new VirtManagerSalt(saltApi); private final MonitoringManager monitoringManager = new FormulaMonitoringManager(saltApi); private final SystemEntitlementManager systemEntitlementManager = new SystemEntitlementManager( - new SystemUnentitler(virtManager, monitoringManager, serverGroupManager), - new SystemEntitler(saltApi, virtManager, monitoringManager, serverGroupManager) + new SystemUnentitler(monitoringManager, serverGroupManager), + new SystemEntitler(saltApi, monitoringManager, serverGroupManager) ); 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 5b2f2f73da3f..27b7e9a0ee64 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 @@ -52,10 +52,8 @@ import com.redhat.rhn.taskomatic.TaskomaticApiException; import com.redhat.rhn.testing.TestUtils; -import com.suse.manager.virtualization.VirtManagerSalt; import com.suse.manager.webui.services.iface.MonitoringManager; import com.suse.manager.webui.services.iface.SaltApi; -import com.suse.manager.webui.services.iface.VirtManager; import com.suse.salt.netapi.calls.LocalCall; import com.suse.salt.netapi.datatypes.target.MinionList; import com.suse.salt.netapi.utils.Xor; @@ -324,12 +322,11 @@ public void testFetchPlaybookContents() throws Exception { } private MinionServer createAnsibleControlNode(User user) throws Exception { - VirtManager virtManager = new VirtManagerSalt(saltApi); MonitoringManager monitoringManager = new FormulaMonitoringManager(saltApi); ServerGroupManager groupManager = new ServerGroupManager(saltApi); SystemEntitlementManager entitlementManager = new SystemEntitlementManager( - new SystemUnentitler(virtManager, monitoringManager, groupManager), - new SystemEntitler(saltApi, virtManager, monitoringManager, groupManager) + new SystemUnentitler(monitoringManager, groupManager), + new SystemEntitler(saltApi, monitoringManager, groupManager) ); 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 23aeef849f5d..7ae2ae42cf82 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 @@ -75,13 +75,11 @@ import com.suse.cloud.CloudPaygManager; import com.suse.cloud.test.TestCloudPaygManagerBuilder; import com.suse.manager.attestation.AttestationManager; -import com.suse.manager.virtualization.VirtManagerSalt; 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.iface.VirtManager; import com.suse.manager.webui.services.test.TestSaltApi; import com.suse.manager.webui.services.test.TestSystemQuery; @@ -127,11 +125,10 @@ public class ChannelSoftwareHandlerTest extends BaseHandlerTestCase { regularMinionBootstrapper, sshMinionBootstrapper ); - private final VirtManager virtManager = new VirtManagerSalt(saltApi); private final MonitoringManager monitoringManager = new FormulaMonitoringManager(saltApi); private final SystemEntitlementManager systemEntitlementManager = new SystemEntitlementManager( - new SystemUnentitler(virtManager, monitoringManager, serverGroupManager), - new SystemEntitler(saltApi, virtManager, monitoringManager, serverGroupManager) + new SystemUnentitler(monitoringManager, serverGroupManager), + new SystemEntitler(saltApi, monitoringManager, serverGroupManager) ); 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 a6a43c3f1e6a..0ab5190374d4 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 @@ -67,9 +67,7 @@ import com.redhat.rhn.testing.ImageTestUtils; import com.redhat.rhn.testing.TestUtils; -import com.suse.manager.virtualization.VirtManagerSalt; import com.suse.manager.webui.services.iface.MonitoringManager; -import com.suse.manager.webui.services.iface.VirtManager; 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; @@ -114,11 +112,10 @@ public void setUp() throws Exception { Config.get().setBoolean(ConfigDefaults.KIWI_OS_IMAGE_BUILDING_ENABLED, "true"); saltServiceMock = context.mock(SaltService.class); ServerGroupManager serverGroupManager = new ServerGroupManager(saltServiceMock); - VirtManager virtManager = new VirtManagerSalt(saltServiceMock); MonitoringManager monitoringManager = new FormulaMonitoringManager(saltServiceMock); systemEntitlementManager = new SystemEntitlementManager( - new SystemUnentitler(virtManager, monitoringManager, serverGroupManager), - new SystemEntitler(saltServiceMock, virtManager, monitoringManager, serverGroupManager) + new SystemUnentitler(monitoringManager, serverGroupManager), + new SystemEntitler(saltServiceMock, monitoringManager, serverGroupManager) ); handler = new ImageInfoHandler(saltServiceMock); context.checking(new Expectations() {{ diff --git a/java/code/src/com/redhat/rhn/frontend/xmlrpc/system/SystemHandler.java b/java/code/src/com/redhat/rhn/frontend/xmlrpc/system/SystemHandler.java index e063cd464f24..693acdecbd2c 100644 --- a/java/code/src/com/redhat/rhn/frontend/xmlrpc/system/SystemHandler.java +++ b/java/code/src/com/redhat/rhn/frontend/xmlrpc/system/SystemHandler.java @@ -45,8 +45,6 @@ import com.redhat.rhn.domain.action.script.ScriptResult; import com.redhat.rhn.domain.action.script.ScriptRunAction; import com.redhat.rhn.domain.action.server.ServerAction; -import com.redhat.rhn.domain.action.virtualization.VirtualizationSetMemoryGuestAction; -import com.redhat.rhn.domain.action.virtualization.VirtualizationSetVcpusGuestAction; import com.redhat.rhn.domain.channel.Channel; import com.redhat.rhn.domain.channel.ChannelArch; import com.redhat.rhn.domain.channel.ChannelFactory; @@ -101,7 +99,6 @@ import com.redhat.rhn.domain.token.ActivationKeyFactory; import com.redhat.rhn.domain.user.User; import com.redhat.rhn.frontend.action.kickstart.KickstartHelper; -import com.redhat.rhn.frontend.context.Context; import com.redhat.rhn.frontend.dto.ActivationKeyDto; import com.redhat.rhn.frontend.dto.ErrataOverview; import com.redhat.rhn.frontend.dto.EssentialChannelDto; @@ -198,9 +195,6 @@ import com.suse.manager.model.attestation.CoCoEnvironmentType; import com.suse.manager.model.attestation.ServerCoCoAttestationConfig; import com.suse.manager.model.attestation.ServerCoCoAttestationReport; -import com.suse.manager.virtualization.VirtualizationActionHelper; -import com.suse.manager.webui.controllers.virtualization.gson.VirtualGuestSetterActionJson; -import com.suse.manager.webui.controllers.virtualization.gson.VirtualGuestsBaseActionJson; import com.suse.manager.webui.services.pillar.MinionPillarManager; import com.suse.manager.webui.utils.gson.BootstrapParameters; import com.suse.manager.xmlrpc.NoSuchHistoryEventException; @@ -216,8 +210,6 @@ import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; -import java.time.LocalDateTime; -import java.time.ZoneId; import java.util.ArrayList; import java.util.Arrays; import java.util.Calendar; @@ -6431,173 +6423,6 @@ public List listVirtualGuests(User loggedInUser, return result; } - /** - * Schedules an action to set the guests memory usage - * @param loggedInUser The current user - * @param sid the server ID of the guest - * @param memory the amount of memory to set the guest to use - * @return the action id of the scheduled action - * - * @apidoc.doc Schedule an action of a guest's host, to set that guest's memory - * allocation - * @apidoc.param #session_key() - * @apidoc.param #param_desc("int", "sid", "The guest's system id") - * @apidoc.param #param_desc("int", "memory", "The amount of memory to - * allocate to the guest") - * @apidoc.returntype #param_desc("int", "actionID", "the action Id for the schedule action - * on the host system") - * - */ - public int setGuestMemory(User loggedInUser, Integer sid, Integer memory) { - VirtualInstance vi = VirtualInstanceFactory.getInstance().lookupByGuestId( - loggedInUser.getOrg(), sid.longValue()); - - try { - return VirtualizationActionHelper.scheduleAction( - vi.getUuid(), - loggedInUser, - vi.getHostSystem(), - VirtualizationActionHelper.getGuestSetterActionCreator( - ActionFactory.TYPE_VIRTUALIZATION_SET_MEMORY, - (data) -> memory * 1024, - (action, value) -> ((VirtualizationSetMemoryGuestAction)action).setMemory(value), - Map.of(vi.getUuid(), vi.getGuestSystem().getName()) - ), - new VirtualGuestSetterActionJson()); - } - catch (com.redhat.rhn.taskomatic.TaskomaticApiException e) { - throw new TaskomaticApiException(e.getMessage()); - } - } - - - /** - * Schedules an actino to set the guests CPU allocation - * @param loggedInUser The current user - * @param sid the server ID of the guest - * @param numOfCpus the num of cpus to set - * @return the action id of the scheduled action - * - * @apidoc.doc Schedule an action of a guest's host, to set that guest's CPU - * allocation - * @apidoc.param #session_key() - * @apidoc.param #param_desc("int", "sid", "The guest's system id") - * @apidoc.param #param_desc("int", "numOfCpus", "The number of virtual cpus to - * allocate to the guest") - * @apidoc.returntype #param_desc("int", "actionID", "the action Id for the schedule action - * on the host system") - * - */ - public int setGuestCpus(User loggedInUser, Integer sid, Integer numOfCpus) { - VirtualInstance vi = VirtualInstanceFactory.getInstance().lookupByGuestId( - loggedInUser.getOrg(), sid.longValue()); - - try { - return VirtualizationActionHelper.scheduleAction( - vi.getUuid(), - loggedInUser, - vi.getHostSystem(), - VirtualizationActionHelper.getGuestSetterActionCreator( - ActionFactory.TYPE_VIRTUALIZATION_SET_VCPUS, - (data) -> numOfCpus, - (action, value) -> ((VirtualizationSetVcpusGuestAction)action).setVcpu(value), - Map.of(vi.getUuid(), vi.getGuestSystem().getName()) - ), - new VirtualGuestSetterActionJson()); - } - catch (com.redhat.rhn.taskomatic.TaskomaticApiException e) { - throw new TaskomaticApiException(e.getMessage()); - } - } - - /** - * schedules the specified action on the guest - * @param loggedInUser The current user - * @param sid the id of the system - * @param state one of the following: 'start', 'suspend', 'resume', 'restart', - * 'shutdown' - * @param date the date to schedule it - * @return action ID - * - * @apidoc.doc Schedules a guest action for the specified virtual guest for a given - * date/time. - * @apidoc.param #session_key() - * @apidoc.param #param_desc("int", "sid", "the system Id of the guest") - * @apidoc.param #param_desc("string", "state", "One of the following actions 'start', - * 'suspend', 'resume', 'restart', 'shutdown'.") - * @apidoc.param #param_desc($date, "date", "the time/date to schedule the action") - * @apidoc.returntype #param_desc("int", "actionId", "The action id of the scheduled action") - */ - public int scheduleGuestAction(User loggedInUser, Integer sid, String state, - Date date) { - VirtualInstance vi = VirtualInstanceFactory.getInstance().lookupByGuestId( - loggedInUser.getOrg(), sid.longValue()); - - ActionType action; - if (state.equals("start")) { - action = ActionFactory.TYPE_VIRTUALIZATION_START; - } - else if (state.equals("suspend")) { - action = ActionFactory.TYPE_VIRTUALIZATION_SUSPEND; - } - else if (state.equals("resume")) { - action = ActionFactory.TYPE_VIRTUALIZATION_RESUME; - } - else if (state.equals("restart")) { - action = ActionFactory.TYPE_VIRTUALIZATION_REBOOT; - } - else if (state.equals("shutdown")) { - action = ActionFactory.TYPE_VIRTUALIZATION_SHUTDOWN; - } - else { - throw new InvalidActionTypeException(); - } - - try { - VirtualGuestsBaseActionJson data = new VirtualGuestsBaseActionJson(); - data.setUuids(List.of(vi.getUuid())); - data.setForce(false); - data.setEarliest( - Optional.ofNullable(date).map((localDate) -> { - ZoneId zoneId = Optional.ofNullable(Context.getCurrentContext().getTimezone()) - .orElse(TimeZone.getDefault()).toZoneId(); - return LocalDateTime.ofInstant(localDate.toInstant(), zoneId); - }) - ); - return VirtualizationActionHelper.scheduleAction( - vi.getUuid(), - loggedInUser, - vi.getHostSystem(), - VirtualizationActionHelper.getGuestActionCreator( - action, - Map.of(vi.getUuid(), vi.getGuestSystem().getName())), - data); - } - catch (com.redhat.rhn.taskomatic.TaskomaticApiException e) { - throw new TaskomaticApiException(e.getMessage()); - } - } - - /** - * schedules the specified action on the guest - * @param loggedInUser The current user - * @param sid the id of the system - * @param state one of the following: 'start', 'suspend', 'resume', 'restart', - * 'shutdown' - * @return action ID - * - * @apidoc.doc Schedules a guest action for the specified virtual guest for the - * current time. - * @apidoc.param #session_key() - * @apidoc.param #param_desc("int", "sid", "the system Id of the guest") - * @apidoc.param #param_desc("string", "state", "One of the following actions 'start', - * 'suspend', 'resume', 'restart', 'shutdown'.") - * @apidoc.returntype #param_desc("int", "actionId", "The action id of the scheduled action") - */ - public int scheduleGuestAction(User loggedInUser, Integer sid, String state) { - return scheduleGuestAction(loggedInUser, sid, state, null); - } - /** * List the activation keys the system was registered with. * @param loggedInUser The current user 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 220d742ad6d6..8071f2acca84 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 @@ -49,13 +49,11 @@ import com.suse.cloud.CloudPaygManager; import com.suse.cloud.test.TestCloudPaygManagerBuilder; import com.suse.manager.attestation.AttestationManager; -import com.suse.manager.virtualization.VirtManagerSalt; 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.iface.VirtManager; import com.suse.manager.webui.services.test.TestSaltApi; import com.suse.manager.webui.services.test.TestSystemQuery; @@ -116,11 +114,10 @@ public void setUp() throws Exception { XmlRpcSystemHelper xmlRpcHelper = new XmlRpcSystemHelper(regularBootstrapper, sshBootstrapper); ServerGroupManager groupManager = new ServerGroupManager(saltApi); - VirtManager virtManager = new VirtManagerSalt(saltApi); MonitoringManager monitoringManager = new FormulaMonitoringManager(saltApi); - SystemUnentitler unentitler = new SystemUnentitler(virtManager, monitoringManager, groupManager); - SystemEntitler entitler = new SystemEntitler(saltApi, virtManager, monitoringManager, groupManager); + SystemUnentitler unentitler = new SystemUnentitler(monitoringManager, groupManager); + SystemEntitler entitler = new SystemEntitler(saltApi, monitoringManager, groupManager); 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 ca80165730ea..fdc9fe0264de 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 @@ -44,8 +44,6 @@ import com.redhat.rhn.domain.action.script.ScriptRunAction; import com.redhat.rhn.domain.action.server.ServerAction; import com.redhat.rhn.domain.action.server.test.ServerActionTest; -import com.redhat.rhn.domain.action.virtualization.VirtualizationSetMemoryGuestAction; -import com.redhat.rhn.domain.action.virtualization.VirtualizationSetVcpusGuestAction; import com.redhat.rhn.domain.channel.Channel; import com.redhat.rhn.domain.channel.ChannelFactory; import com.redhat.rhn.domain.channel.ChannelFamily; @@ -90,10 +88,7 @@ import com.redhat.rhn.domain.server.ServerGroup; import com.redhat.rhn.domain.server.ServerGroupFactory; import com.redhat.rhn.domain.server.ServerHistoryEvent; -import com.redhat.rhn.domain.server.VirtualInstance; -import com.redhat.rhn.domain.server.VirtualInstanceFactory; import com.redhat.rhn.domain.server.test.CPUTest; -import com.redhat.rhn.domain.server.test.GuestBuilder; import com.redhat.rhn.domain.server.test.MinionServerFactoryTest; import com.redhat.rhn.domain.server.test.NetworkInterfaceTest; import com.redhat.rhn.domain.server.test.ServerFactoryTest; @@ -106,7 +101,6 @@ import com.redhat.rhn.domain.token.test.ActivationKeyTest; import com.redhat.rhn.domain.user.User; import com.redhat.rhn.domain.user.UserFactory; -import com.redhat.rhn.frontend.context.Context; import com.redhat.rhn.frontend.dto.ErrataOverview; import com.redhat.rhn.frontend.dto.HistoryEvent; import com.redhat.rhn.frontend.dto.OperationDetailsDto; @@ -166,13 +160,11 @@ import com.suse.cloud.CloudPaygManager; import com.suse.cloud.test.TestCloudPaygManagerBuilder; import com.suse.manager.attestation.AttestationManager; -import com.suse.manager.virtualization.VirtManagerSalt; 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.iface.VirtManager; import com.suse.manager.webui.services.pillar.MinionCustomInfoPillarGenerator; import com.suse.manager.webui.services.test.TestSaltApi; import com.suse.manager.webui.services.test.TestSystemQuery; @@ -203,7 +195,6 @@ import java.util.Map; import java.util.Optional; import java.util.Set; -import java.util.TimeZone; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Collectors; @@ -225,11 +216,10 @@ public class SystemHandlerTest extends BaseHandlerTestCase { sshMinionBootstrapper ); private final ServerGroupManager serverGroupManager = new ServerGroupManager(saltApi); - private final VirtManager virtManager = new VirtManagerSalt(saltApi); private final MonitoringManager monitoringManager = new FormulaMonitoringManager(saltApi); private final SystemEntitlementManager systemEntitlementManager = new SystemEntitlementManager( - new SystemUnentitler(virtManager, monitoringManager, serverGroupManager), - new SystemEntitler(saltApi, virtManager, monitoringManager, serverGroupManager) + new SystemUnentitler(monitoringManager, serverGroupManager), + new SystemEntitler(saltApi, monitoringManager, serverGroupManager) ); private SystemManager systemManager = new SystemManager(ServerFactory.SINGLETON, ServerGroupFactory.SINGLETON, saltApi); @@ -2538,90 +2528,6 @@ public void testListSystemsWithPackage() { } - @Test - public void testScheduleGuestAction() throws Exception { - Context.getCurrentContext().setTimezone(TimeZone.getTimeZone("UTC")); - Server host = ServerFactoryTest.createTestServer(admin, true); - GuestBuilder build = new GuestBuilder(admin); - VirtualInstance guest = build.createGuest().withVirtHost().build(); - guest.setHostSystem(host); - - VirtualInstanceFactory.getInstance().saveVirtualInstance(guest); - - int id = handler.scheduleGuestAction(admin, - guest.getGuestSystem().getId().intValue(), "restart"); - - List actions = ActionFactory.listActionsForServer(admin, host); - - boolean contains = false; - for (Action act : actions) { - if (act.getId() == id) { - contains = true; - assertEquals(act.getActionType(), ActionFactory.TYPE_VIRTUALIZATION_REBOOT); - } - } - assertTrue(contains); - } - - @Test - public void testSetGuestMemory() throws Exception { - Context.getCurrentContext().setTimezone(TimeZone.getTimeZone("UTC")); - Server host = ServerFactoryTest.createTestServer(admin, true); - GuestBuilder build = new GuestBuilder(admin); - VirtualInstance guest = build.createGuest().withVirtHost().build(); - guest.setHostSystem(host); - - VirtualInstanceFactory.getInstance().saveVirtualInstance(guest); - - int id = handler.setGuestMemory(admin, - guest.getGuestSystem().getId().intValue(), 512); - - List actions = ActionFactory.listActionsForServer(admin, host); - - boolean contains = false; - for (Action act : actions) { - if (act.getId() == id) { - contains = true; - assertEquals(act.getActionType(), - ActionFactory.TYPE_VIRTUALIZATION_SET_MEMORY); - VirtualizationSetMemoryGuestAction action = HibernateFactory.getSession().load( - VirtualizationSetMemoryGuestAction.class, (long) id); - assertEquals(action.getMemory(), Integer.valueOf(512 * 1024)); - } - } - assertTrue(contains); - } - - - @Test - public void testSetGuestCpus() throws Exception { - Context.getCurrentContext().setTimezone(TimeZone.getTimeZone("UTC")); - Server host = ServerFactoryTest.createTestServer(admin, true); - GuestBuilder build = new GuestBuilder(admin); - VirtualInstance guest = build.createGuest().withVirtHost().build(); - guest.setHostSystem(host); - - VirtualInstanceFactory.getInstance().saveVirtualInstance(guest); - - int id = handler.setGuestCpus(admin, - guest.getGuestSystem().getId().intValue(), 3); - - List actions = ActionFactory.listActionsForServer(admin, host); - - boolean contains = false; - for (Action act : actions) { - if (act.getId() == id) { - contains = true; - assertEquals(act.getActionType(), - ActionFactory.TYPE_VIRTUALIZATION_SET_VCPUS); - VirtualizationSetVcpusGuestAction action = HibernateFactory.getSession().load( - VirtualizationSetVcpusGuestAction.class, (long) id); - assertEquals(action.getVcpu(), Integer.valueOf(3)); - } - } - assertTrue(contains); - } - @Test public void testListActivationKeys() throws Exception { Server server = ServerFactoryTest.createTestServer(admin, true); 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 0c8c333787be..3e5d7fb0aeb7 100644 --- a/java/code/src/com/redhat/rhn/manager/action/ActionManager.java +++ b/java/code/src/com/redhat/rhn/manager/action/ActionManager.java @@ -38,8 +38,6 @@ import com.redhat.rhn.domain.action.dup.DistUpgradeAction; import com.redhat.rhn.domain.action.dup.DistUpgradeActionDetails; import com.redhat.rhn.domain.action.errata.ErrataAction; -import com.redhat.rhn.domain.action.image.DeployImageAction; -import com.redhat.rhn.domain.action.image.DeployImageActionDetails; import com.redhat.rhn.domain.action.kickstart.KickstartAction; import com.redhat.rhn.domain.action.kickstart.KickstartActionDetails; import com.redhat.rhn.domain.action.kickstart.KickstartGuestAction; @@ -64,7 +62,6 @@ import com.redhat.rhn.domain.errata.Errata; import com.redhat.rhn.domain.image.ImageProfile; import com.redhat.rhn.domain.image.ImageStore; -import com.redhat.rhn.domain.image.ProxyConfig; import com.redhat.rhn.domain.kickstart.KickstartData; import com.redhat.rhn.domain.kickstart.KickstartFactory; import com.redhat.rhn.domain.org.Org; @@ -105,7 +102,6 @@ import com.suse.manager.webui.controllers.utils.ContactMethodUtil; import com.suse.manager.webui.services.pillar.MinionPillarManager; -import org.apache.commons.codec.binary.Base64; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.tuple.ImmutablePair; import org.apache.commons.lang3.tuple.Pair; @@ -718,43 +714,6 @@ public static Action createConfigAction(User user, Collection revisions, return createConfigActionForServers(user, revisions, servers, type, earliest); } - /** - * Schedule deployment of an image to a vhost. - * - * @return The created action - * @param user The user scheduling image deployment - * @param imageUrl The URL of the image to be deployed - * @param vcpus number of vcpus - * @param memkb memory in Kb - * @param bridge device - * @param proxy proxy configuration - */ - public static Action createDeployImageAction(User user, String imageUrl, - Long vcpus, Long memkb, String bridge, ProxyConfig proxy) { - DeployImageAction a = (DeployImageAction) ActionFactory - .createAction(ActionFactory.TYPE_DEPLOY_IMAGE); - if (user != null) { - a.setSchedulerUser(user); - a.setOrg(user.getOrg()); - } - - DeployImageActionDetails details = new DeployImageActionDetails(); - details.setParentAction(a); - details.setVcpus(vcpus); - details.setMemKb(memkb); - details.setBridgeDevice(bridge); - details.setDownloadUrl(imageUrl); - if (proxy != null) { - details.setProxyServer(proxy.getServer()); - details.setProxyUser(proxy.getUser()); - details.setProxyPass(new String(Base64.encodeBase64( - proxy.getPass().getBytes()))); - } - a.setDetails(details); - a.setName("Image Deployment: " + imageUrl); - return a; - } - /** * * @param user The user scheduling the action 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 c50637cf2bc5..52288a6be758 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 @@ -102,11 +102,9 @@ import com.redhat.rhn.testing.TestUtils; import com.redhat.rhn.testing.UserTestUtils; -import com.suse.manager.virtualization.VirtManagerSalt; 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.iface.VirtManager; import com.suse.manager.webui.services.test.TestSaltApi; import com.suse.manager.webui.services.test.TestSystemQuery; import com.suse.salt.netapi.calls.modules.Schedule; @@ -151,11 +149,10 @@ public class ActionManagerTest extends JMockBaseTestCaseWithUser { private final SystemQuery systemQuery = new TestSystemQuery(); private final SaltApi saltApi = new TestSaltApi(); private final ServerGroupManager serverGroupManager = new ServerGroupManager(saltApi); - private final VirtManager virtManager = new VirtManagerSalt(saltApi); private final MonitoringManager monitoringManager = new FormulaMonitoringManager(saltApi); private final SystemEntitlementManager systemEntitlementManager = new SystemEntitlementManager( - new SystemUnentitler(virtManager, monitoringManager, serverGroupManager), - new SystemEntitler(saltApi, virtManager, monitoringManager, serverGroupManager) + new SystemUnentitler(monitoringManager, serverGroupManager), + new SystemEntitler(saltApi, monitoringManager, serverGroupManager) ); 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 abd887c63e21..e538fc00aac9 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 @@ -58,13 +58,11 @@ import com.suse.cloud.CloudPaygManager; import com.suse.cloud.test.TestCloudPaygManagerBuilder; import com.suse.manager.attestation.AttestationManager; -import com.suse.manager.virtualization.VirtManagerSalt; 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.iface.VirtManager; import com.suse.manager.webui.services.test.TestSaltApi; import com.suse.manager.webui.services.test.TestSystemQuery; @@ -101,11 +99,10 @@ 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 VirtManager virtManager = new VirtManagerSalt(saltApi); private final MonitoringManager monitoringManager = new FormulaMonitoringManager(saltApi); private final SystemEntitlementManager systemEntitlementManager = new SystemEntitlementManager( - new SystemUnentitler(virtManager, monitoringManager, serverGroupManager), - new SystemEntitler(saltApi, virtManager, monitoringManager, serverGroupManager) + new SystemUnentitler(monitoringManager, serverGroupManager), + new SystemEntitler(saltApi, monitoringManager, serverGroupManager) ); 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 00c375be999a..bc9e8657ae6b 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 @@ -47,10 +47,8 @@ import com.redhat.rhn.testing.ServerTestUtils; import com.redhat.rhn.testing.UserTestUtils; -import com.suse.manager.virtualization.VirtManagerSalt; import com.suse.manager.webui.services.iface.MonitoringManager; import com.suse.manager.webui.services.iface.SaltApi; -import com.suse.manager.webui.services.iface.VirtManager; import com.suse.manager.webui.services.test.TestSaltApi; import org.junit.jupiter.api.BeforeEach; @@ -75,11 +73,10 @@ public class MigrationManagerTest extends BaseTestCaseWithUser { private final SaltApi saltApi = new TestSaltApi(); private final ServerGroupManager serverGroupManager = new ServerGroupManager(saltApi); - private final VirtManager virtManager = new VirtManagerSalt(saltApi); private final MonitoringManager monitoringManager = new FormulaMonitoringManager(saltApi); private final SystemEntitlementManager systemEntitlementManager = new SystemEntitlementManager( - new SystemUnentitler(virtManager, monitoringManager, serverGroupManager), - new SystemEntitler(saltApi, virtManager, monitoringManager, serverGroupManager) + new SystemUnentitler(monitoringManager, serverGroupManager), + new SystemEntitler(saltApi, monitoringManager, serverGroupManager) ); 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 fa6f2a6c7335..8e704444856a 100644 --- a/java/code/src/com/redhat/rhn/manager/system/SystemManager.java +++ b/java/code/src/com/redhat/rhn/manager/system/SystemManager.java @@ -131,13 +131,11 @@ import com.suse.manager.ssl.SSLCertManager; import com.suse.manager.ssl.SSLCertPair; import com.suse.manager.utils.PagedSqlQueryBuilder; -import com.suse.manager.virtualization.VirtManagerSalt; 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.webui.services.iface.VirtManager; import com.suse.manager.webui.services.impl.SaltSSHService; import com.suse.manager.webui.services.impl.runner.MgrUtilRunner; import com.suse.manager.webui.utils.YamlHelper; @@ -218,11 +216,10 @@ public SystemManager(ServerFactory serverFactoryIn, ServerGroupFactory serverGro this.serverGroupFactory = serverGroupFactoryIn; this.saltApi = saltApiIn; ServerGroupManager serverGroupManager = new ServerGroupManager(saltApiIn); - VirtManager virtManager = new VirtManagerSalt(saltApi); MonitoringManager monitoringManager = new FormulaMonitoringManager(saltApi); systemEntitlementManager = new SystemEntitlementManager( - new SystemUnentitler(virtManager, monitoringManager, serverGroupManager), - new SystemEntitler(saltApiIn, virtManager, monitoringManager, serverGroupManager) + new SystemUnentitler(monitoringManager, serverGroupManager), + new SystemEntitler(saltApiIn, monitoringManager, serverGroupManager) ); } diff --git a/java/code/src/com/redhat/rhn/manager/system/VirtualInstanceManager.java b/java/code/src/com/redhat/rhn/manager/system/VirtualInstanceManager.java index debd9100e1a8..f1423cc080b8 100644 --- a/java/code/src/com/redhat/rhn/manager/system/VirtualInstanceManager.java +++ b/java/code/src/com/redhat/rhn/manager/system/VirtualInstanceManager.java @@ -24,7 +24,6 @@ import com.suse.manager.utils.SaltUtils; import com.suse.manager.webui.utils.salt.custom.VmInfo; -import com.suse.manager.webui.websocket.VirtNotifications; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -194,7 +193,6 @@ public static void deleteGuestVirtualInstance(VirtualInstance virtualInstance) { else { VirtualInstanceFactory.getInstance().deleteVirtualInstanceOnly(virtualInstance); } - VirtNotifications.spreadRefresh("guest"); } /** @@ -266,8 +264,6 @@ public static void addGuestVirtualInstance(String vmGuid, String name, VirtualInstanceFactory.getInstance() .saveVirtualInstance(virtualInstance); - - VirtNotifications.spreadRefresh("guest"); } else { log.warn("Preventing creation of a duplicated VirtualInstance for 'uuid': {}", vmGuid); @@ -345,8 +341,6 @@ public static void updateGuestVirtualInstanceProperties(VirtualInstance virtualI virtualInstance.setNumberOfCPUs(vCpus); virtualInstance.setTotalMemory(memory); VirtualInstanceFactory.getInstance().saveVirtualInstance(virtualInstance); - - VirtNotifications.spreadRefresh("guest"); } /** 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 e51f8da78843..a9027a7e9a67 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 @@ -19,21 +19,16 @@ import com.redhat.rhn.common.validator.ValidatorException; import com.redhat.rhn.common.validator.ValidatorResult; import com.redhat.rhn.domain.entitlement.Entitlement; -import com.redhat.rhn.domain.server.MinionServer; import com.redhat.rhn.domain.server.Server; import com.redhat.rhn.domain.server.ServerFactory; import com.redhat.rhn.domain.server.ServerGroup; import com.redhat.rhn.domain.server.ServerGroupFactory; -import com.redhat.rhn.domain.server.VirtualInstanceFactory; import com.redhat.rhn.manager.entitlement.EntitlementManager; import com.redhat.rhn.manager.system.ServerGroupManager; -import com.redhat.rhn.manager.system.VirtualInstanceManager; import com.suse.manager.webui.services.iface.MonitoringManager; import com.suse.manager.webui.services.iface.SaltApi; -import com.suse.manager.webui.services.iface.VirtManager; 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; @@ -50,20 +45,17 @@ public class SystemEntitler { private static final Logger LOG = LogManager.getLogger(SystemEntitler.class); private SaltApi saltApi; - private VirtManager virtManager; private MonitoringManager monitoringManager; private ServerGroupManager serverGroupManager; /** * @param saltApiIn instance for gathering data from a system. - * @param virtManagerIn instance for managing virtual machines. * @param monitoringManagerIn instance for handling monitoring configuration. * @param serverGroupManagerIn */ - public SystemEntitler(SaltApi saltApiIn, VirtManager virtManagerIn, + public SystemEntitler(SaltApi saltApiIn, MonitoringManager monitoringManagerIn, ServerGroupManager serverGroupManagerIn) { this.saltApi = saltApiIn; - this.virtManager = virtManagerIn; this.monitoringManager = monitoringManagerIn; this.serverGroupManager = serverGroupManagerIn; } @@ -96,7 +88,6 @@ public ValidatorResult addEntitlementToServer(Server server, Entitlement ent) { return result; } - boolean wasVirtEntitled = server.hasEntitlement(EntitlementManager.VIRTUALIZATION); if (EntitlementManager.VIRTUALIZATION.equals(ent)) { if (server.isVirtualGuest()) { result.addError(new ValidatorError("system.entitle.guestcantvirt")); @@ -113,13 +104,6 @@ else if (EntitlementManager.OSIMAGE_BUILD_HOST.equals(ent)) { server.asMinionServer().ifPresent(minion -> { serverGroupManager.updatePillarAfterGroupUpdateForServers(Arrays.asList(minion)); - if (wasVirtEntitled && !EntitlementManager.VIRTUALIZATION.equals(ent) || - !wasVirtEntitled && EntitlementManager.VIRTUALIZATION.equals(ent)) { - this.updateLibvirtEngine(minion); - MinionPillarManager.INSTANCE.generatePillar(minion, false, - MinionPillarManager.PillarSubset.VIRTUALIZATION); - } - if (EntitlementManager.MONITORING.equals(ent)) { try { monitoringManager.enableMonitoring(minion); @@ -192,10 +176,4 @@ private Optional findServerGroupToEntitleAnEntitledServer(Server se } return serverGroup; } - - private void updateLibvirtEngine(MinionServer minion) { - VirtualInstanceManager.updateHostVirtualInstance(minion, - VirtualInstanceFactory.getInstance().getFullyVirtType()); - virtManager.updateLibvirtEngine(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 1386165c21b0..87e33f37152c 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,8 +24,6 @@ import com.redhat.rhn.manager.system.ServerGroupManager; import com.suse.manager.webui.services.iface.MonitoringManager; -import com.suse.manager.webui.services.iface.VirtManager; -import com.suse.manager.webui.services.pillar.MinionPillarManager; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -42,17 +40,14 @@ public class SystemUnentitler { private static final Logger LOG = LogManager.getLogger(SystemUnentitler.class); private final MonitoringManager monitoringManager; - private final VirtManager virtManager; private final ServerGroupManager serverGroupManager; /** - * @param virtManagerIn instance for managing virtual machines. * @param monitoringManagerIn instance for handling monitoring configuration. * @param serverGroupManagerIn */ - public SystemUnentitler(VirtManager virtManagerIn, MonitoringManager monitoringManagerIn, + public SystemUnentitler(MonitoringManager monitoringManagerIn, ServerGroupManager serverGroupManagerIn) { - this.virtManager = virtManagerIn; this.monitoringManager = monitoringManagerIn; this.serverGroupManager = serverGroupManagerIn; } @@ -97,12 +92,6 @@ public void removeServerEntitlement(Server server, Entitlement ent) { LOG.warn("Error disabling monitoring: {}", e.getMessage()); } } - - if (EntitlementManager.VIRTUALIZATION.equals(ent)) { - virtManager.updateLibvirtEngine(s); - MinionPillarManager.INSTANCE.generatePillar(s, false, - MinionPillarManager.PillarSubset.VIRTUALIZATION); - } }); } 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 e93ed630dad7..942a90141802 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 @@ -38,9 +38,7 @@ import com.redhat.rhn.testing.TestUtils; import com.redhat.rhn.testing.UserTestUtils; -import com.suse.manager.virtualization.VirtManagerSalt; import com.suse.manager.webui.services.iface.MonitoringManager; -import com.suse.manager.webui.services.iface.VirtManager; import com.suse.manager.webui.services.impl.SaltSSHService; import com.suse.manager.webui.services.impl.SaltService; import com.suse.salt.netapi.datatypes.target.MinionList; @@ -62,11 +60,10 @@ public void setUp() throws Exception { setImposteriser(ByteBuddyClassImposteriser.INSTANCE); saltServiceMock = mock(SaltService.class); ServerGroupManager serverGroupManager = new ServerGroupManager(saltServiceMock); - VirtManager virtManager = new VirtManagerSalt(saltServiceMock); MonitoringManager monitoringManager = new FormulaMonitoringManager(saltServiceMock); systemEntitlementManager = new SystemEntitlementManager( - new SystemUnentitler(virtManager, monitoringManager, serverGroupManager), - new SystemEntitler(saltServiceMock, virtManager, monitoringManager, serverGroupManager) + new SystemUnentitler(monitoringManager, serverGroupManager), + new SystemEntitler(saltServiceMock, monitoringManager, serverGroupManager) ); 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 57cf112651c7..df9ce3562db5 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 @@ -39,10 +39,8 @@ import com.redhat.rhn.testing.TestUtils; import com.redhat.rhn.testing.UserTestUtils; -import com.suse.manager.virtualization.VirtManagerSalt; import com.suse.manager.webui.services.iface.MonitoringManager; import com.suse.manager.webui.services.iface.SaltApi; -import com.suse.manager.webui.services.iface.VirtManager; import com.suse.manager.webui.utils.salt.custom.AnsiblePlaybookSlsResult; import com.suse.salt.netapi.calls.LocalCall; import com.suse.salt.netapi.datatypes.target.MinionList; @@ -464,12 +462,11 @@ public void testIntrospectInventoryInPlaybook() throws Exception { } private MinionServer createAnsibleControlNode(User user) throws Exception { - VirtManager virtManager = new VirtManagerSalt(saltApi); MonitoringManager monitoringManager = new FormulaMonitoringManager(saltApi); ServerGroupManager groupManager = new ServerGroupManager(saltApi); SystemEntitlementManager entitlementManager = new SystemEntitlementManager( - new SystemUnentitler(virtManager, monitoringManager, groupManager), - new SystemEntitler(saltApi, virtManager, monitoringManager, groupManager) + new SystemUnentitler(monitoringManager, groupManager), + new SystemEntitler(saltApi, monitoringManager, groupManager) ); 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 d3c3c3fd0929..b73b309b6b35 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 @@ -132,11 +132,9 @@ import com.suse.manager.metrics.SystemsCollector; import com.suse.manager.ssl.SSLCertManager; import com.suse.manager.ssl.SSLCertPair; -import com.suse.manager.virtualization.test.TestVirtManager; 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.iface.VirtManager; 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; @@ -216,12 +214,11 @@ public void setUp() throws Exception { } }); SaltApi saltApi = new TestSaltApi(); - VirtManager virtManager = new TestVirtManager(); MonitoringManager monitoringManager = new FormulaMonitoringManager(saltApi); ServerGroupManager serverGroupManager = new ServerGroupManager(saltApi); systemEntitlementManager = new SystemEntitlementManager( - new SystemUnentitler(virtManager, monitoringManager, serverGroupManager), - new SystemEntitler(saltApi, virtManager, monitoringManager, serverGroupManager) + new SystemUnentitler(monitoringManager, serverGroupManager), + new SystemEntitler(saltApi, monitoringManager, serverGroupManager) ); 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 6aaa13e88e96..28111beb8852 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 @@ -41,10 +41,8 @@ import com.suse.cloud.domain.PaygDimensionComputation; import com.suse.cloud.domain.PaygDimensionFactory; import com.suse.cloud.test.TestCloudPaygManagerBuilder; -import com.suse.manager.virtualization.VirtManagerSalt; import com.suse.manager.webui.services.iface.MonitoringManager; import com.suse.manager.webui.services.iface.SaltApi; -import com.suse.manager.webui.services.iface.VirtManager; import com.suse.manager.webui.services.test.TestSaltApi; import org.junit.jupiter.api.BeforeEach; @@ -74,12 +72,11 @@ public void before() { SaltApi saltApi = new TestSaltApi(); ServerGroupManager serverGroupManager = new ServerGroupManager(saltApi); - VirtManager virtManager = new VirtManagerSalt(saltApi); MonitoringManager monitoringManager = new FormulaMonitoringManager(saltApi); systemEntitlementManager = new SystemEntitlementManager( - new SystemUnentitler(virtManager, monitoringManager, serverGroupManager), - new SystemEntitler(saltApi, virtManager, monitoringManager, serverGroupManager) + new SystemUnentitler(monitoringManager, serverGroupManager), + new SystemEntitler(saltApi, monitoringManager, serverGroupManager) ); } diff --git a/java/code/src/com/suse/manager/maintenance/test/MaintenanceManagerTest.java b/java/code/src/com/suse/manager/maintenance/test/MaintenanceManagerTest.java index 190e74b0d024..ff4de57957d8 100644 --- a/java/code/src/com/suse/manager/maintenance/test/MaintenanceManagerTest.java +++ b/java/code/src/com/suse/manager/maintenance/test/MaintenanceManagerTest.java @@ -295,7 +295,7 @@ public void testAssignScheduleToSystemWithPendingActions() throws Exception { // assign an action not tied to maintenance mode Action allowedAction = MaintenanceTestUtils.createActionForServerAt( - user, ActionFactory.TYPE_VIRTUALIZATION_START, sys1, "2020-04-13T08:15:00+02:00"); + user, ActionFactory.TYPE_HARDWARE_REFRESH_LIST, sys1, "2020-04-13T08:15:00+02:00"); assertEquals(1, mm.assignScheduleToSystems(user, schedule, Set.of(sys1.getId()), false)); // assign maintenance window affected action inside a maintenance window @@ -426,13 +426,13 @@ public void testScheduleChangeMultiWithCancel() throws Exception { Action sapAction1 = MaintenanceTestUtils.createActionForServerAt( user, ActionFactory.TYPE_ERRATA, sapServer, "2020-04-13T08:15:00+02:00"); //moved Action sapActionEx = MaintenanceTestUtils.createActionForServerAt( - user, ActionFactory.TYPE_VIRTUALIZATION_START, sapServer, "2020-04-13T08:15:00+02:00"); //moved + user, ActionFactory.TYPE_HARDWARE_REFRESH_LIST, sapServer, "2020-04-13T08:15:00+02:00"); //moved Action sapAction2 = MaintenanceTestUtils.createActionForServerAt( user, ActionFactory.TYPE_ERRATA, sapServer, "2020-04-27T08:15:00+02:00"); //stay Action coreAction1 = MaintenanceTestUtils.createActionForServerAt( user, ActionFactory.TYPE_ERRATA, coreServer, "2020-04-30T09:15:00+02:00"); //stay Action coreActionEx = MaintenanceTestUtils.createActionForServerAt( - user, ActionFactory.TYPE_VIRTUALIZATION_START, coreServer, "2020-05-21T09:15:00+02:00"); //moved + user, ActionFactory.TYPE_HARDWARE_REFRESH_LIST, coreServer, "2020-05-21T09:15:00+02:00"); //moved Action coreAction2 = MaintenanceTestUtils.createActionForServerAt( user, ActionFactory.TYPE_ERRATA, coreServer, "2020-05-21T09:15:00+02:00"); //moved @@ -507,7 +507,7 @@ public void testScheduleChangeMultiWithActionChain() throws Exception { // Action Chain which start with an action not tied to a maintenance window // Expected Result: Cancel all Actions Action sapAction3 = MaintenanceTestUtils.createActionForServerAt( - user, ActionFactory.TYPE_VIRTUALIZATION_START, sapServer, "2020-04-13T09:59:00+02:00"); //moved + user, ActionFactory.TYPE_HARDWARE_REFRESH_LIST, sapServer, "2020-04-13T09:59:00+02:00"); //moved Action sapAction4 = MaintenanceTestUtils.createActionForServerAt( user, ActionFactory.TYPE_ERRATA, sapServer, "2020-04-13T08:10:02+02:00", sapAction3); //moved @@ -524,7 +524,7 @@ public void testScheduleChangeMultiWithActionChain() throws Exception { // Action Chain which start with an action not tied to a maintenance window // Expected Result: No change Action coreAction3 = MaintenanceTestUtils.createActionForServerAt( - user, ActionFactory.TYPE_VIRTUALIZATION_START, coreServer, "2020-04-30T11:59:30+02:00"); //stay + user, ActionFactory.TYPE_HARDWARE_REFRESH_LIST, coreServer, "2020-04-30T11:59:30+02:00"); //stay Action coreAction4 = MaintenanceTestUtils.createActionForServerAt( user, ActionFactory.TYPE_ERRATA, coreServer, "2020-04-30T13:01:00+02:00", coreAction3); //stay @@ -581,7 +581,7 @@ else if (r.getScheduleName().equals("Core Server Window")) { } else if (r.getScheduleName().equals("Core Server Window")) { r.getActionsServers().keySet().forEach(a -> { - assertEquals(ActionFactory.TYPE_VIRTUALIZATION_START, a.getActionType()); + assertEquals(ActionFactory.TYPE_HARDWARE_REFRESH_LIST, a.getActionType()); assertEquals(coreAction3, a); r.getActionsServers().get(a).forEach(s -> assertEquals(coreServer.getId(), s.getId())); }); 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 1d75e0fe7197..bd89402e54b8 100644 --- a/java/code/src/com/suse/manager/matcher/test/MatcherJsonIOTest.java +++ b/java/code/src/com/suse/manager/matcher/test/MatcherJsonIOTest.java @@ -31,7 +31,6 @@ import com.redhat.rhn.domain.rhnpackage.PackageFactory; import com.redhat.rhn.domain.server.CPU; import com.redhat.rhn.domain.server.InstalledProduct; -import com.redhat.rhn.domain.server.MinionServer; import com.redhat.rhn.domain.server.PinnedSubscription; import com.redhat.rhn.domain.server.Server; import com.redhat.rhn.domain.server.ServerFactory; @@ -53,10 +52,8 @@ import com.suse.manager.maintenance.BaseProductManager; import com.suse.manager.matcher.MatcherJsonIO; -import com.suse.manager.virtualization.test.TestVirtManager; import com.suse.manager.webui.services.iface.MonitoringManager; import com.suse.manager.webui.services.iface.SaltApi; -import com.suse.manager.webui.services.iface.VirtManager; import com.suse.manager.webui.services.test.TestSaltApi; import com.suse.matcher.json.MatchJson; import com.suse.matcher.json.ProductJson; @@ -110,17 +107,12 @@ public void setUp() throws Exception { super.setUp(); setImposteriser(ByteBuddyClassImposteriser.INSTANCE); - VirtManager virtManager = new TestVirtManager() { - @Override - public void updateLibvirtEngine(MinionServer minion) { - } - }; SaltApi saltApi = new TestSaltApi(); MonitoringManager monitoringManager = new FormulaMonitoringManager(saltApi); ServerGroupManager serverGroupManager = new ServerGroupManager(saltApi); systemEntitlementManager = new SystemEntitlementManager( - new SystemUnentitler(virtManager, monitoringManager, serverGroupManager), - new SystemEntitler(saltApi, virtManager, monitoringManager, serverGroupManager) + new SystemUnentitler(monitoringManager, serverGroupManager), + new SystemEntitler(saltApi, monitoringManager, serverGroupManager) ); baseProductManagerMock = mock(BaseProductManager.class); diff --git a/java/code/src/com/suse/manager/reactor/SaltReactor.java b/java/code/src/com/suse/manager/reactor/SaltReactor.java index da14cd785180..92a4a9a5bb16 100644 --- a/java/code/src/com/suse/manager/reactor/SaltReactor.java +++ b/java/code/src/com/suse/manager/reactor/SaltReactor.java @@ -27,7 +27,6 @@ import com.suse.cloud.CloudPaygManager; import com.suse.manager.attestation.AttestationManager; -import com.suse.manager.reactor.messaging.AbstractLibvirtEngineMessage; import com.suse.manager.reactor.messaging.ApplyStatesEventMessage; import com.suse.manager.reactor.messaging.ApplyStatesEventMessageAction; import com.suse.manager.reactor.messaging.BatchStartedEventMessage; @@ -38,13 +37,6 @@ import com.suse.manager.reactor.messaging.ImageSyncedEventMessageAction; import com.suse.manager.reactor.messaging.JobReturnEventMessage; import com.suse.manager.reactor.messaging.JobReturnEventMessageAction; -import com.suse.manager.reactor.messaging.LibvirtEngineDomainLifecycleMessage; -import com.suse.manager.reactor.messaging.LibvirtEngineDomainLifecycleMessageAction; -import com.suse.manager.reactor.messaging.LibvirtEngineNetworkLifecycleMessage; -import com.suse.manager.reactor.messaging.LibvirtEngineNetworkMessageAction; -import com.suse.manager.reactor.messaging.LibvirtEnginePoolLifecycleMessage; -import com.suse.manager.reactor.messaging.LibvirtEnginePoolMessageAction; -import com.suse.manager.reactor.messaging.LibvirtEnginePoolRefreshMessage; import com.suse.manager.reactor.messaging.RefreshGeneratedSaltFilesEventMessage; import com.suse.manager.reactor.messaging.RefreshGeneratedSaltFilesEventMessageAction; import com.suse.manager.reactor.messaging.RegisterMinionEventMessage; @@ -57,11 +49,9 @@ import com.suse.manager.saltboot.PXEEventMessage; import com.suse.manager.saltboot.PXEEventMessageAction; import com.suse.manager.utils.SaltUtils; -import com.suse.manager.virtualization.VirtManagerSalt; import com.suse.manager.webui.services.SaltServerActionService; import com.suse.manager.webui.services.iface.SaltApi; import com.suse.manager.webui.services.iface.SystemQuery; -import com.suse.manager.webui.services.iface.VirtManager; import com.suse.manager.webui.utils.salt.custom.ImageDeployedEvent; import com.suse.manager.webui.utils.salt.custom.ImageSyncedEvent; import com.suse.manager.webui.utils.salt.custom.MinionStartupGrains; @@ -69,7 +59,6 @@ import com.suse.salt.netapi.datatypes.Event; import com.suse.salt.netapi.event.BatchStartedEvent; import com.suse.salt.netapi.event.BeaconEvent; -import com.suse.salt.netapi.event.EngineEvent; import com.suse.salt.netapi.event.EventStream; import com.suse.salt.netapi.event.JobReturnEvent; import com.suse.salt.netapi.event.MinionStartEvent; @@ -128,8 +117,6 @@ public SaltReactor(SaltApi saltApiIn, SystemQuery systemQueryIn, SaltServerActio * Start the salt reactor. */ public void start() { - VirtManager virtManager = new VirtManagerSalt(saltApi); - // Configure message queue to handle minion registrations MessageQueue.registerAction(new RegisterMinionEventMessageAction(systemQuery, saltApi, paygMgr, attestationMgr), RegisterMinionEventMessage.class); @@ -145,14 +132,6 @@ public void start() { SystemIdGenerateEventMessage.class); MessageQueue.registerAction(new ImageDeployedEventMessageAction(systemQuery), ImageDeployedEventMessage.class); - MessageQueue.registerAction(new LibvirtEngineDomainLifecycleMessageAction(virtManager), - LibvirtEngineDomainLifecycleMessage.class); - MessageQueue.registerAction(new LibvirtEnginePoolMessageAction(), - LibvirtEnginePoolLifecycleMessage.class); - MessageQueue.registerAction(new LibvirtEnginePoolMessageAction(), - LibvirtEnginePoolRefreshMessage.class); - MessageQueue.registerAction(new LibvirtEngineNetworkMessageAction(), - LibvirtEngineNetworkLifecycleMessage.class); MessageQueue.registerAction(new BatchStartedEventMessageAction(), BatchStartedEventMessage.class); MessageQueue.registerAction(new ImageSyncedEventMessageAction(), @@ -204,10 +183,9 @@ private Stream eventToMessages(Event event) { ImageDeployedEvent.parse(event).map(this::eventToMessages).orElseGet(() -> ImageSyncedEvent.parse(event).map(this::eventToMessages).orElseGet(() -> PXEEvent.parse(event).map(this::eventToMessages).orElseGet(() -> - EngineEvent.parse(event).map(this::eventToMessages).orElseGet(() -> BeaconEvent.parse(event).map(this::eventToMessages).orElse( empty() - ))))))))); + )))))))); } /** @@ -270,30 +248,6 @@ private Stream eventToMessages(MinionStartEvent minionStartEvent) ); } - /** - * Trigger handling of engine events - * - * @param engineEvent engine event - * @return event handler runnable - */ - private Stream eventToMessages(EngineEvent engineEvent) { - if ("libvirt_events".equals(engineEvent.getEngine())) { - try { - AbstractLibvirtEngineMessage message = AbstractLibvirtEngineMessage.create(engineEvent); - if (message != null) { - return of(message); - } - else { - LOG.debug("Unhandled libvirt engine event:{}", engineEvent.getAdditional()); - } - } - catch (IllegalArgumentException e) { - LOG.warn("Invalid libvirt engine event: {}", engineEvent.getAdditional()); - } - } - return empty(); - } - /** * Trigger handling of job return events. * diff --git a/java/code/src/com/suse/manager/reactor/messaging/AbstractLibvirtEngineMessage.java b/java/code/src/com/suse/manager/reactor/messaging/AbstractLibvirtEngineMessage.java deleted file mode 100644 index ac2227728bce..000000000000 --- a/java/code/src/com/suse/manager/reactor/messaging/AbstractLibvirtEngineMessage.java +++ /dev/null @@ -1,133 +0,0 @@ -/* - * Copyright (c) 2018 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.suse.manager.reactor.messaging; - -import com.redhat.rhn.common.hibernate.HibernateFactory; -import com.redhat.rhn.common.messaging.EventDatabaseMessage; -import com.redhat.rhn.common.messaging.EventMessage; - -import com.suse.salt.netapi.event.EngineEvent; - -import com.google.gson.JsonElement; - -import org.hibernate.Transaction; - -import java.util.Arrays; -import java.util.List; -import java.util.Optional; - -/** - * Libvirt_events engine message to handle - */ -public abstract class AbstractLibvirtEngineMessage implements EventMessage, EventDatabaseMessage { - - private static final int LIBVIRT_EVENTS_ADDITIONAL_PARTS_COUNT = 3; - - private String connection; - private Optional minionId; - private String timestamp; - private Transaction txn; - - /** - * Parse the engine event if it is a libvirt_events one. - * - * @param engineEvent the event to parse - * @return the corresponding event message or null if not handled - * - * @throws IllegalArgumentException if the event is invalid - */ - public static AbstractLibvirtEngineMessage create(EngineEvent engineEvent) throws IllegalArgumentException { - List additionalParts = Arrays.asList(engineEvent.getAdditional().split("/")); - if (additionalParts.size() < LIBVIRT_EVENTS_ADDITIONAL_PARTS_COUNT) { - throw new IllegalArgumentException("Invalid libvirt engine event: " + engineEvent.getAdditional()); - } - String eventType = additionalParts.get(additionalParts.size() - 1); - String objectType = additionalParts.get(additionalParts.size() - 2); - String connection = String.join("/", additionalParts.subList(0, additionalParts.size() - 2)); - - if ("domain".equals(objectType)) { - return LibvirtEngineDomainMessage.createDomainMessage(connection, - eventType, engineEvent.getMinionId(), engineEvent.getTimestamp(), - engineEvent.getData(JsonElement.class)); - } - else if ("pool".equals(objectType)) { - return LibvirtEnginePoolMessage.createPoolMessage(connection, - eventType, engineEvent.getMinionId(), engineEvent.getTimestamp(), - engineEvent.getData(JsonElement.class)); - } - else if ("network".equals(objectType)) { - return LibvirtEngineNetworkMessage.createNetworkMessage(connection, - eventType, engineEvent.getMinionId(), engineEvent.getTimestamp(), - engineEvent.getData(JsonElement.class)); - } - return null; - } - - /** - * @return the libvirt connection of the event (not in an URI format) - */ - public String getConnection() { - return connection; - } - - /** - * @return the ID of the minion that generated the message or empty if - * the message was generated by the master - */ - public Optional getMinionId() { - return minionId; - } - - /** - * @return the timestamp of the event - */ - public String getTimestamp() { - return timestamp; - } - - @Override - public Long getUserId() { - return null; - } - - /** - * - * {@inheritDoc} - */ - @Override - public Transaction getTransaction() { - return txn; - } - - @Override - public String toText() { - return toString(); - } - - @Override - public String toString() { - String origin = minionId.orElse("master"); - return this.getClass().getName() + "[" + origin + "]"; - } - - protected AbstractLibvirtEngineMessage(String connectIn, Optional minionIdIn, - String timestampIn) { - this.connection = connectIn; - this.minionId = minionIdIn; - this.timestamp = timestampIn; - - this.txn = HibernateFactory.getSession().getTransaction(); - } -} diff --git a/java/code/src/com/suse/manager/reactor/messaging/LibvirtEngineDomainLifecycleMessage.java b/java/code/src/com/suse/manager/reactor/messaging/LibvirtEngineDomainLifecycleMessage.java deleted file mode 100644 index ca63ba18747e..000000000000 --- a/java/code/src/com/suse/manager/reactor/messaging/LibvirtEngineDomainLifecycleMessage.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (c) 2018 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.suse.manager.reactor.messaging; - -import com.google.gson.JsonElement; - -import java.util.Optional; - -/** - * - * LibvirtEngineDomainLifecycleMessage - */ -public class LibvirtEngineDomainLifecycleMessage extends LibvirtEngineDomainMessage { - - private String event; - private String detail; - - /** - * @return the domain lifecycle event type (start, destroy, etc) - */ - public String getEvent() { - return event; - } - - /** - * @return the domain lifecycle event detail, mostly indicating the - * reason of the event - */ - public String getDetail() { - return detail; - } - - @Override - public String toString() { - return super.toString() + "[" + event + "]"; - } - - protected LibvirtEngineDomainLifecycleMessage(String connection, - Optional minionId, String timestamp, JsonElement data) { - super(connection, minionId, timestamp, data); - - this.event = data.getAsJsonObject().get("event").getAsString(); - this.detail = data.getAsJsonObject().get("detail").getAsString(); - } -} diff --git a/java/code/src/com/suse/manager/reactor/messaging/LibvirtEngineDomainLifecycleMessageAction.java b/java/code/src/com/suse/manager/reactor/messaging/LibvirtEngineDomainLifecycleMessageAction.java deleted file mode 100644 index ee28e711ea71..000000000000 --- a/java/code/src/com/suse/manager/reactor/messaging/LibvirtEngineDomainLifecycleMessageAction.java +++ /dev/null @@ -1,202 +0,0 @@ -/* - * Copyright (c) 2018 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.suse.manager.reactor.messaging; - -import com.redhat.rhn.common.messaging.EventMessage; -import com.redhat.rhn.common.messaging.MessageAction; -import com.redhat.rhn.domain.server.MinionServerFactory; -import com.redhat.rhn.domain.server.VirtualInstance; -import com.redhat.rhn.domain.server.VirtualInstanceFactory; -import com.redhat.rhn.domain.server.VirtualInstanceState; -import com.redhat.rhn.manager.system.VirtualInstanceManager; - -import com.suse.manager.virtualization.GuestDefinition; -import com.suse.manager.webui.services.iface.VirtManager; -import com.suse.manager.webui.websocket.VirtNotifications; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; - -/** - * Virt Engine Domain Lifecycle Event Action Handler - */ -public class LibvirtEngineDomainLifecycleMessageAction implements MessageAction { - - private static final Logger LOG = LogManager.getLogger(LibvirtEngineDomainLifecycleMessageAction.class); - - private final VirtManager virtManager; - private final List toRestart = new ArrayList<>(); - - /** - * @param virtManagerIn instance to manage virtualization - */ - public LibvirtEngineDomainLifecycleMessageAction(VirtManager virtManagerIn) { - this.virtManager = virtManagerIn; - } - - @Override - public void execute(EventMessage msg) { - LibvirtEngineDomainLifecycleMessage message = (LibvirtEngineDomainLifecycleMessage)msg; - - if (message.getMinionId().isPresent()) { - String minionId = message.getMinionId().get(); - String event = message.getEvent(); - - MinionServerFactory.findByMinionId(minionId).ifPresent(minion -> { - LOG.debug("Processing {}/{} on minion {}", message.getEvent(), message.getDetail(), minionId); - VirtualInstanceManager.updateHostVirtualInstance(minion, - VirtualInstanceFactory.getInstance().getFullyVirtType()); - - final String guid = VirtualInstanceManager.fixUuidIfSwappedUuidExists( - message.getDomainUUID().replaceAll("-", "")); - - VirtNotifications.spreadGuestEvent(minion.getId(), guid, event, message.getDetail()); - - List vms = VirtualInstanceFactory.getInstance().lookupVirtualInstanceByUuid(guid); - if (vms.isEmpty()) { - // We got a machine created from outside SUMA, - // ask Salt for details on it to create it - Optional result = virtManager.getGuestDefinition( - minionId, message.getDomainUUID()); - - result.ifPresent(def -> { - VirtualInstanceState state = VirtualInstanceFactory.getInstance().getStoppedState(); - if (Arrays.asList("started", "resumed").contains(event)) { - state = VirtualInstanceFactory.getInstance().getRunningState(); - } - - LOG.debug("Adding VM {} with state to {}", def.getName(), state.getLabel()); - VirtualInstanceManager.addGuestVirtualInstance(def.getUuid().replaceAll("-", ""), - def.getName(), def.getVirtualInstanceType(), state, minion, null, - def.getVcpu().getMax(), def.getMaxMemory() / 1024); - - // Check if the defined VM will require a manual restart - if (def.isRequiresRestart()) { - watchVirtualMachine(minionId, message.getDomainName()); - } - }); - } - else if (vms.size() == 1) { - // There shouldn't be two VMs with the same UUID across the world - VirtualInstance vm = vms.get(0); - List stoppedEvents = Arrays.asList("defined", "stopped", "shutdown"); - List runningEvents = Arrays.asList("started", "resumed"); - List pausedEvents = Arrays.asList("suspended", "pmsuspended"); - List crashedEvents = Collections.singletonList("crashed"); - - Map, VirtualInstanceState> statesMap = new HashMap<>(); - statesMap.put(stoppedEvents, VirtualInstanceFactory.getInstance().getStoppedState()); - statesMap.put(runningEvents, VirtualInstanceFactory.getInstance().getRunningState()); - statesMap.put(pausedEvents, VirtualInstanceFactory.getInstance().getPausedState()); - statesMap.put(crashedEvents, VirtualInstanceFactory.getInstance().getCrashedState()); - - VirtualInstanceState state = statesMap.entrySet().stream() - .filter(entry -> entry.getKey().contains(event)) - .map(Map.Entry::getValue) - .findFirst().orElse(vms.get(0).getState()); - - LOG.debug("Changing VM {} state to {}", vm, state.getLabel()); - - // At the end of a migration we get a stopped/migrated event from the source host - // and a resumed/migrated event from the target host. - // Skip the stopped event since we will update the virtual host in the resumed one. - boolean migrated = message.getDetail().equals("migrated"); - if (migrated && event.equals("stopped")) { - return; - } - - // We need to check if the VM is still defined and delete it if needed - if (!migrated && Arrays.asList("undefined", "stopped", "shutdown", "crashed").contains(event) && - virtManager.getGuestDefinition(minionId, message.getDomainUUID()).isEmpty()) { - // Ensure the state is updated since this could be shown for stopped cluster VMs - if (vm.isRegisteredGuest()) { - VirtualInstanceManager.updateGuestVirtualInstance(vm, vm.getName(), state, null, - vm.getGuestSystem(), vm.getNumberOfCPUs(), vm.getTotalMemory()); - } - VirtualInstanceManager.deleteGuestVirtualInstance(vm); - unwatchVirtualMachine(minionId, message.getDomainName()); - } - else { - // Update the host when getting the event of the end of a live migration - // or if the server doesn't our record. This could happen if the hypervisor has been fenced - // and the VM moved to another hypervisor in the cluster. - boolean changedHost = event.equals("started") && !message.getDetail().equals("migrated") && - (vm.getHostSystem() == null || !vm.getHostSystem().getId().equals(minion.getId())); - if (migrated && event.equals("resumed") || changedHost) { - VirtualInstanceManager.updateGuestVirtualInstance(vm, vm.getName(), state, - minion, vm.getGuestSystem(), vm.getNumberOfCPUs(), vm.getTotalMemory()); - return; - } - final Optional updatedDef = message.getDetail().equals("updated") ? - virtManager.getGuestDefinition(minionId, message.getDomainUUID()) : - Optional.empty(); - - // Check if we need to restart the VM now - if (event.equals("stopped")) { - checkForRestart(minionId, message.getDomainName()); - } - - String name = updatedDef.isPresent() ? updatedDef.get().getName() : vm.getName(); - Integer cpuCount = updatedDef.map(guestDefinitionIn -> guestDefinitionIn.getVcpu().getMax()) - .orElseGet(vm::getNumberOfCPUs); - Long memory = updatedDef.map(guestDefinitionIn -> guestDefinitionIn.getMaxMemory() / 1024) - .orElseGet(vm::getTotalMemory); - VirtualInstanceManager.updateGuestVirtualInstanceProperties( - vm, name, "updated".equals(message.getDetail()) ? vm.getState() : state, - cpuCount, memory); - } - } - else { - LOG.error(String.format("More than one virtual machine with UUID %s: skipping data update", guid)); - } - }); - } - VirtNotifications.spreadRefresh("guest"); - } - - private void unwatchVirtualMachine(String minionId, String vmName) { - synchronized (toRestart) { - toRestart.remove(computeName(minionId, vmName)); - } - } - - private void watchVirtualMachine(String minionId, String vmName) { - synchronized (toRestart) { - toRestart.add(computeName(minionId, vmName)); - } - } - - private void checkForRestart(String minionId, String vmName) { - String name = computeName(minionId, vmName); - synchronized (toRestart) { - if (toRestart.contains(name)) { - virtManager.startGuest(minionId, vmName); - toRestart.remove(name); - } - } - } - - private String computeName(String minionId, String vmName) { - return minionId + "-" + vmName; - } -} diff --git a/java/code/src/com/suse/manager/reactor/messaging/LibvirtEngineDomainMessage.java b/java/code/src/com/suse/manager/reactor/messaging/LibvirtEngineDomainMessage.java deleted file mode 100644 index 4a7dc2ca0790..000000000000 --- a/java/code/src/com/suse/manager/reactor/messaging/LibvirtEngineDomainMessage.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright (c) 2018 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.suse.manager.reactor.messaging; - -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; - -import java.util.Optional; - -/** - * Libvirt_events engine domain message to handle - */ -public abstract class LibvirtEngineDomainMessage extends AbstractLibvirtEngineMessage { - - private String domainName; - private String domainId; - private String domainUUID; - - /** - * Create a domain message corresponding to the event type - * - * @param connection libvirt connection - * @param eventType libvirt event type (lifecycle, refresh, etc) - * @param minionId the minion ID or empty if the message comes from the master - * @param timestamp the event time stamp - * @param data the JSon data of the event - * - * @return a specialized object matching the event - */ - public static AbstractLibvirtEngineMessage createDomainMessage(String connection, - String eventType, Optional minionId, String timestamp, - JsonElement data) { - if (eventType.equals("lifecycle")) { - return new LibvirtEngineDomainLifecycleMessage(connection, minionId, - timestamp, data); - } - return null; - } - - /** - * @return name of the domain related to the event - */ - public String getDomainName() { - return domainName; - } - - /** - * @return id of the domain related to the event - */ - public String getDomainId() { - return domainId; - } - - /** - * @return uuid of the domain related to the event - */ - public String getDomainUUID() { - return domainUUID; - } - - @Override - public String toString() { - return super.toString() + "[" + domainName + "]"; - } - - protected LibvirtEngineDomainMessage(String connection, Optional minionId, - String timestamp, JsonElement data) { - super(connection, minionId, timestamp); - - JsonObject domain = data.getAsJsonObject().get("domain").getAsJsonObject(); - this.domainName = domain.get("name").getAsString(); - this.domainId = domain.get("id").getAsString(); - this.domainUUID = domain.get("uuid").getAsString(); - } -} diff --git a/java/code/src/com/suse/manager/reactor/messaging/LibvirtEngineNetworkLifecycleMessage.java b/java/code/src/com/suse/manager/reactor/messaging/LibvirtEngineNetworkLifecycleMessage.java deleted file mode 100644 index 4acadf83da4c..000000000000 --- a/java/code/src/com/suse/manager/reactor/messaging/LibvirtEngineNetworkLifecycleMessage.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (c) 2020 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.suse.manager.reactor.messaging; - -import com.google.gson.JsonElement; - -import java.util.Optional; - -/** - * Class representing a Salt virtual network Lifecycle event - */ -public class LibvirtEngineNetworkLifecycleMessage extends LibvirtEngineNetworkMessage { - - private String event; - private String detail; - - /** - * @return the lifecycle event type (start, destroy, etc) - */ - public String getEvent() { - return event; - } - - /** - * @return the lifecycle event detail, mostly indicating the - * reason of the event - */ - public String getDetail() { - return detail; - } - - @Override - public String toString() { - return super.toString() + "[" + event + "]"; - } - - protected LibvirtEngineNetworkLifecycleMessage(String connection, Optional minionId, - String timestamp, JsonElement data) { - super(connection, minionId, timestamp, data); - - event = data.getAsJsonObject().get("event").getAsString(); - detail = data.getAsJsonObject().get("detail").getAsString(); - } -} diff --git a/java/code/src/com/suse/manager/reactor/messaging/LibvirtEngineNetworkMessage.java b/java/code/src/com/suse/manager/reactor/messaging/LibvirtEngineNetworkMessage.java deleted file mode 100644 index 989c2936199b..000000000000 --- a/java/code/src/com/suse/manager/reactor/messaging/LibvirtEngineNetworkMessage.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (c) 2020 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.suse.manager.reactor.messaging; - -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; - -import java.util.Optional; - -/** - * Libvirt_events engine network message to handle - */ -public class LibvirtEngineNetworkMessage extends AbstractLibvirtEngineMessage { - private String netName; - private String netUUID; - - /** - * Create a network message corresponding to the event type - * - * @param connection libvirt connection - * @param eventType libvirt event type (lifecycle...) - * @param minionId the minion ID or empty if the message comes from the master - * @param timestamp the event time stamp - * @param data the JSon data of the event - * - * @return a specialized object matching the event - */ - public static AbstractLibvirtEngineMessage createNetworkMessage(String connection, String eventType, - Optional minionId, String timestamp, - JsonElement data) { - if (eventType.equals("lifecycle")) { - return new LibvirtEngineNetworkLifecycleMessage(connection, minionId, - timestamp, data); - } - return null; - } - - /** - * @return name of the network related to the event - */ - public String getNetworkName() { - return netName; - } - - /** - * @return uuid of the pool related to the event - */ - public String getNetworkUUID() { - return netUUID; - } - - @Override - public String toString() { - return super.toString() + "[" + netName + "]"; - } - - protected LibvirtEngineNetworkMessage(String connection, Optional minionId, - String timestamp, JsonElement data) { - super(connection, minionId, timestamp); - - JsonObject net = data.getAsJsonObject().get("network").getAsJsonObject(); - this.netName = net.get("name").getAsString(); - this.netUUID = net.get("uuid").getAsString(); - } -} diff --git a/java/code/src/com/suse/manager/reactor/messaging/LibvirtEngineNetworkMessageAction.java b/java/code/src/com/suse/manager/reactor/messaging/LibvirtEngineNetworkMessageAction.java deleted file mode 100644 index 4b184ef6a532..000000000000 --- a/java/code/src/com/suse/manager/reactor/messaging/LibvirtEngineNetworkMessageAction.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2020 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.suse.manager.reactor.messaging; - -import com.redhat.rhn.common.messaging.EventMessage; -import com.redhat.rhn.common.messaging.MessageAction; - -import com.suse.manager.webui.websocket.VirtNotifications; - -/** - * Virt engine virtual network lifecycle event action handler - */ -public class LibvirtEngineNetworkMessageAction implements MessageAction { - @Override - public void execute(EventMessage msg) { - // Notify that there was a pool change - VirtNotifications.spreadRefresh("network"); - } -} diff --git a/java/code/src/com/suse/manager/reactor/messaging/LibvirtEnginePoolLifecycleMessage.java b/java/code/src/com/suse/manager/reactor/messaging/LibvirtEnginePoolLifecycleMessage.java deleted file mode 100644 index 55fa57190e04..000000000000 --- a/java/code/src/com/suse/manager/reactor/messaging/LibvirtEnginePoolLifecycleMessage.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (c) 2020 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.suse.manager.reactor.messaging; - -import com.google.gson.JsonElement; - -import java.util.Optional; - -/** - * Class representing a Salt Pool Lifecycle event - */ -public class LibvirtEnginePoolLifecycleMessage extends LibvirtEnginePoolMessage { - - private String event; - private String detail; - - /** - * @return the lifecycle event type (start, destroy, etc) - */ - public String getEvent() { - return event; - } - - /** - * @return the lifecycle event detail, mostly indicating the - * reason of the event - */ - public String getDetail() { - return detail; - } - - @Override - public String toString() { - return super.toString() + "[" + event + "]"; - } - - protected LibvirtEnginePoolLifecycleMessage(String connection, Optional minionId, - String timestamp, JsonElement data) { - super(connection, minionId, timestamp, data); - - event = data.getAsJsonObject().get("event").getAsString(); - detail = data.getAsJsonObject().get("detail").getAsString(); - } -} diff --git a/java/code/src/com/suse/manager/reactor/messaging/LibvirtEnginePoolMessage.java b/java/code/src/com/suse/manager/reactor/messaging/LibvirtEnginePoolMessage.java deleted file mode 100644 index 76b87dd6738e..000000000000 --- a/java/code/src/com/suse/manager/reactor/messaging/LibvirtEnginePoolMessage.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright (c) 2020 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.suse.manager.reactor.messaging; - -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; - -import java.util.Optional; - -/** - * Libvirt_events engine pool message to handle - */ -public class LibvirtEnginePoolMessage extends AbstractLibvirtEngineMessage { - private String poolName; - private String poolUUID; - - /** - * Create a pool message corresponding to the event type - * - * @param connection libvirt connection - * @param eventType libvirt event type (lifecycle, refresh) - * @param minionId the minion ID or empty if the message comes from the master - * @param timestamp the event time stamp - * @param data the JSon data of the event - * - * @return a specialized object matching the event - */ - public static AbstractLibvirtEngineMessage createPoolMessage(String connection, String eventType, - Optional minionId, String timestamp, - JsonElement data) { - if (eventType.equals("lifecycle")) { - return new LibvirtEnginePoolLifecycleMessage(connection, minionId, - timestamp, data); - } - else if (eventType.equals("refresh")) { - return new LibvirtEnginePoolRefreshMessage(connection, minionId, - timestamp, data); - } - return null; - } - - /** - * @return name of the pool related to the event - */ - public String getPoolName() { - return poolName; - } - - /** - * @return uuid of the pool related to the event - */ - public String getPoolUUID() { - return poolUUID; - } - - @Override - public String toString() { - return super.toString() + "[" + poolName + "]"; - } - - protected LibvirtEnginePoolMessage(String connection, Optional minionId, - String timestamp, JsonElement data) { - super(connection, minionId, timestamp); - - JsonObject pool = data.getAsJsonObject().get("pool").getAsJsonObject(); - this.poolName = pool.get("name").getAsString(); - this.poolUUID = pool.get("uuid").getAsString(); - } -} diff --git a/java/code/src/com/suse/manager/reactor/messaging/LibvirtEnginePoolMessageAction.java b/java/code/src/com/suse/manager/reactor/messaging/LibvirtEnginePoolMessageAction.java deleted file mode 100644 index e1fa91bf0eff..000000000000 --- a/java/code/src/com/suse/manager/reactor/messaging/LibvirtEnginePoolMessageAction.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2020 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.suse.manager.reactor.messaging; - -import com.redhat.rhn.common.messaging.EventMessage; -import com.redhat.rhn.common.messaging.MessageAction; - -import com.suse.manager.webui.websocket.VirtNotifications; - -/** - * Virt Engine Storage Pool Lifecycle Event Action Handler - */ -public class LibvirtEnginePoolMessageAction implements MessageAction { - @Override - public void execute(EventMessage msg) { - // Notify that there was a pool change - VirtNotifications.spreadRefresh("pool"); - } -} diff --git a/java/code/src/com/suse/manager/reactor/messaging/LibvirtEnginePoolRefreshMessage.java b/java/code/src/com/suse/manager/reactor/messaging/LibvirtEnginePoolRefreshMessage.java deleted file mode 100644 index e8528548f58c..000000000000 --- a/java/code/src/com/suse/manager/reactor/messaging/LibvirtEnginePoolRefreshMessage.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2020 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.suse.manager.reactor.messaging; - -import com.google.gson.JsonElement; - -import java.util.Optional; - -/** - * Class representing a Salt Pool refresh event - */ -public class LibvirtEnginePoolRefreshMessage extends LibvirtEnginePoolMessage { - private String event; - - /** - * @return the domain lifecycle event type (start, destroy, etc) - */ - public String getEvent() { - return event; - } - - @Override - public String toString() { - return super.toString() + "[" + event + "]"; - } - - protected LibvirtEnginePoolRefreshMessage(String connection, Optional minionId, - String timestamp, JsonElement data) { - super(connection, minionId, timestamp, data); - - event = data.getAsJsonObject().get("event").getAsString(); - } -} 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 c597189045a7..73f559f268c9 100644 --- a/java/code/src/com/suse/manager/reactor/messaging/RegisterMinionEventMessageAction.java +++ b/java/code/src/com/suse/manager/reactor/messaging/RegisterMinionEventMessageAction.java @@ -66,14 +66,12 @@ import com.suse.manager.model.attestation.ServerCoCoAttestationConfig; import com.suse.manager.reactor.utils.ValueMap; import com.suse.manager.utils.SaltUtils; -import com.suse.manager.virtualization.VirtManagerSalt; 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.iface.VirtManager; import com.suse.manager.webui.services.impl.MinionPendingRegistrationService; import com.suse.manager.webui.services.impl.SaltSSHService; import com.suse.manager.webui.services.pillar.MinionPillarManager; @@ -145,12 +143,11 @@ public RegisterMinionEventMessageAction(SystemQuery systemQueryIn, SaltApi saltA systemQuery = systemQueryIn; cloudPaygManager = paygMgrIn; attestationManager = attMgrIn; - VirtManager virtManager = new VirtManagerSalt(saltApi); MonitoringManager monitoringManager = new FormulaMonitoringManager(saltApi); ServerGroupManager groupManager = new ServerGroupManager(saltApi); entitlementManager = new SystemEntitlementManager( - new SystemUnentitler(virtManager, monitoringManager, groupManager), - new SystemEntitler(saltApi, virtManager, monitoringManager, groupManager) + new SystemUnentitler(monitoringManager, groupManager), + new SystemEntitler(saltApi, monitoringManager, groupManager) ); } 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 a40985023e3c..472905c16aff 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 @@ -84,10 +84,8 @@ import com.suse.manager.reactor.utils.test.RhelUtilsTest; import com.suse.manager.utils.SaltKeyUtils; import com.suse.manager.utils.SaltUtils; -import com.suse.manager.virtualization.VirtManagerSalt; import com.suse.manager.webui.services.SaltServerActionService; import com.suse.manager.webui.services.iface.MonitoringManager; -import com.suse.manager.webui.services.iface.VirtManager; 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; @@ -160,11 +158,10 @@ public void setUp() throws Exception { DigestUtils.sha256Hex(TestUtils.randomString())); saltServiceMock = context().mock(SaltService.class); ServerGroupManager serverGroupManager = new ServerGroupManager(saltServiceMock); - VirtManager virtManager = new VirtManagerSalt(saltServiceMock); MonitoringManager monitoringManager = new FormulaMonitoringManager(saltServiceMock); systemEntitlementManager = new SystemEntitlementManager( - new SystemUnentitler(virtManager, monitoringManager, serverGroupManager), - new SystemEntitler(saltServiceMock, virtManager, monitoringManager, serverGroupManager) + new SystemUnentitler(monitoringManager, serverGroupManager), + new SystemEntitler(saltServiceMock, monitoringManager, serverGroupManager) ); saltUtils = new SaltUtils(saltServiceMock, saltServiceMock); saltServerActionService = new SaltServerActionService(saltServiceMock, saltUtils, @@ -2212,34 +2209,6 @@ public void testFailDependentServerActions() throws Exception { assertEquals("Prerequisite failed", runScriptSeverAction.getResultMsg()); } - @Test - public void testStateErrorResponse() throws Exception { - MinionServer minion = MinionServerFactoryTest.createTestMinionServer(user); - minion.setMinionId("demo-kvm1.tf.local"); - Action action = ActionFactoryTest.createAction(user, ActionFactory.TYPE_VIRTUALIZATION_CREATE); - - action.addServerAction(ActionFactoryTest.createServerAction(minion, action)); - - // Setup an event message from file contents - Optional event = JobReturnEvent.parse( - getJobReturnEvent("virtcreate.failure.json", action.getId())); - JobReturnEventMessage message = new JobReturnEventMessage(event.get()); - - // Process the event message - JobReturnEventMessageAction messageAction = new JobReturnEventMessageAction(saltServerActionService, saltUtils); - messageAction.execute(message); - - // Verify the action status - assertEquals(ActionFactory.STATUS_FAILED, action.getServerActions().stream() - .filter(serverAction -> serverAction.getServer().equals(minion)) - .findAny().get().getStatus()); - - // Verify the action message - assertTrue(action.getServerActions().stream() - .filter(serverAction -> serverAction.getServer().equals(minion)) - .findAny().get().getResultMsg().contains("default-broken pool is not defined")); - } - @Test public void testActionChainResponse() throws Exception { TaskomaticApi taskomaticMock = mock(TaskomaticApi.class); diff --git a/java/code/src/com/suse/manager/reactor/messaging/test/LibvirtEngineDomainLifecycleMessageActionTest.java b/java/code/src/com/suse/manager/reactor/messaging/test/LibvirtEngineDomainLifecycleMessageActionTest.java deleted file mode 100644 index 0a90936e9ea9..000000000000 --- a/java/code/src/com/suse/manager/reactor/messaging/test/LibvirtEngineDomainLifecycleMessageActionTest.java +++ /dev/null @@ -1,304 +0,0 @@ -/* - * Copyright (c) 2018 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.suse.manager.reactor.messaging.test; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import com.redhat.rhn.common.db.datasource.DataResult; -import com.redhat.rhn.domain.role.RoleFactory; -import com.redhat.rhn.domain.server.MinionServer; -import com.redhat.rhn.domain.server.Server; -import com.redhat.rhn.domain.server.VirtualInstanceFactory; -import com.redhat.rhn.frontend.dto.VirtualSystemOverview; -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; -import com.redhat.rhn.manager.system.entitling.SystemUnentitler; -import com.redhat.rhn.testing.JMockBaseTestCaseWithUser; -import com.redhat.rhn.testing.ServerTestUtils; -import com.redhat.rhn.testing.TestUtils; - -import com.suse.manager.reactor.messaging.AbstractLibvirtEngineMessage; -import com.suse.manager.reactor.messaging.LibvirtEngineDomainLifecycleMessageAction; -import com.suse.manager.virtualization.GuestDefinition; -import com.suse.manager.webui.services.iface.MonitoringManager; -import com.suse.manager.webui.services.iface.SaltApi; -import com.suse.manager.webui.services.iface.VirtManager; -import com.suse.manager.webui.services.test.TestSaltApi; -import com.suse.salt.netapi.datatypes.Event; -import com.suse.salt.netapi.event.EngineEvent; -import com.suse.salt.netapi.parser.JsonParser; - -import com.google.gson.JsonElement; -import com.google.gson.reflect.TypeToken; - -import org.apache.commons.lang3.StringUtils; -import org.jmock.Expectations; -import org.jmock.States; -import org.jmock.imposters.ByteBuddyClassImposteriser; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import java.io.File; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.stream.Collectors; - -/** - * Test for {@link LibvirtEngineDomainLifecycleMessageAction} - */ -public class LibvirtEngineDomainLifecycleMessageActionTest extends JMockBaseTestCaseWithUser { - - private Server host; - private VirtManager virtManager; - private String guid = "b99a81764f40498d8e612f6ade654fe2"; - private String uuid = "b99a8176-4f40-498d-8e61-2f6ade654fe2"; - - // JsonParser for parsing events from files - public static final JsonParser EVENTS = - new JsonParser<>(new TypeToken<>() { - }); - - @Override - @BeforeEach - public void setUp() throws Exception { - super.setUp(); - user.addPermanentRole(RoleFactory.ORG_ADMIN); - setImposteriser(ByteBuddyClassImposteriser.INSTANCE); - - virtManager = mock(VirtManager.class); - context().checking(new Expectations() { { - allowing(virtManager).getCapabilities("testminion.local"); - will(returnValue( - SaltTestUtils.getSaltResponse( - "/com/suse/manager/webui/controllers/virtualization/test/virt.guest.allcaps.json", null, - new TypeToken>() { }) - )); - allowing(virtManager).updateLibvirtEngine(with(any(MinionServer.class))); - }}); - - SaltApi saltApi = new TestSaltApi(); - MonitoringManager monitoringManager = new FormulaMonitoringManager(saltApi); - ServerGroupManager serverGroupManager = new ServerGroupManager(saltApi); - SystemEntitlementManager systemEntitlementManager = new SystemEntitlementManager( - new SystemUnentitler(virtManager, monitoringManager, serverGroupManager), - new SystemEntitler(new TestSaltApi(), virtManager, monitoringManager, serverGroupManager) - ); - - host = ServerTestUtils.createVirtHostWithGuests(user, 1, true, systemEntitlementManager); - host.getGuests().iterator().next().setUuid(guid); - host.getGuests().iterator().next().setName("sles12sp2"); - host.asMinionServer().get().setMinionId("testminion.local"); - } - - @Test - public void testNewGuestNoRestart() throws Exception { - Map placeholders = new HashMap<>(); - placeholders.put("sles12sp2", "sles12sp2-new"); - placeholders.put(uuid, "98eef4f7-eb7f-4be8-859d-11658506c496"); - expectGuestDefinition("98eef4f7-eb7f-4be8-859d-11658506c496", - "/com/suse/manager/reactor/messaging/test/virt.guest.definition.xml", placeholders); - Optional startEvent = EngineEvent.parse(getEngineEvent("virtevents.guest.started.json", null)); - AbstractLibvirtEngineMessage startMessage = AbstractLibvirtEngineMessage.create(startEvent.get()); - - // Start event - LibvirtEngineDomainLifecycleMessageAction action = new LibvirtEngineDomainLifecycleMessageAction(virtManager); - action.execute(startMessage); - - DataResult guests = SystemManager.virtualGuestsForHostList(user, host.getId(), null); - List newGuests = guests.stream().filter(vso -> vso.getName().equals("sles12sp2-new")) - .collect(Collectors.toList()); - - assertEquals(VirtualInstanceFactory.getInstance().getRunningState().getLabel(), - newGuests.get(0).getStateLabel()); - - // Shutdown event - context().checking(new Expectations() {{ - never(virtManager).startGuest(host.getMinionId(), "sles12sp2-new"); - }}); - Optional stopEvent = EngineEvent.parse( - getEngineEvent("virtevents.guest.shutdown.json", placeholders)); - AbstractLibvirtEngineMessage stopMessage = AbstractLibvirtEngineMessage.create(stopEvent.get()); - - action.execute(stopMessage); - } - - @Test - public void testNewGuestFirstReboot() throws Exception { - Map placeholders = new HashMap<>(); - placeholders.put("sles12sp2", "sles12sp2-new"); - placeholders.put(uuid, "98eef4f7-eb7f-4be8-859d-11658506c496"); - placeholders.put("restart", "destroy"); - expectGuestDefinition("98eef4f7-eb7f-4be8-859d-11658506c496", - "/com/suse/manager/reactor/messaging/test/virt.guest.definition.xml", placeholders); - - // Start event - Optional startEvent = EngineEvent.parse(getEngineEvent("virtevents.guest.started.json", null)); - AbstractLibvirtEngineMessage startMessage = AbstractLibvirtEngineMessage.create(startEvent.get()); - - LibvirtEngineDomainLifecycleMessageAction action = new LibvirtEngineDomainLifecycleMessageAction(virtManager); - action.execute(startMessage); - - // Shutdown event - context().checking(new Expectations() {{ - oneOf(virtManager).startGuest(host.getMinionId(), "sles12sp2-new"); - }}); - Optional stopEvent = EngineEvent.parse( - getEngineEvent("virtevents.guest.shutdown.json", placeholders)); - AbstractLibvirtEngineMessage stopMessage = AbstractLibvirtEngineMessage.create(stopEvent.get()); - - action.execute(stopMessage); - } - - @Test - public void testNewGuestFirstRebootAborted() throws Exception { - States vmState = context().states("vm").startsAs("started"); - - Map placeholders = new HashMap<>(); - placeholders.put("sles12sp2", "sles12sp2-new"); - placeholders.put(uuid, "98eef4f7-eb7f-4be8-859d-11658506c496"); - placeholders.put("restart", "destroy"); - expectGuestDefinition("98eef4f7-eb7f-4be8-859d-11658506c496", - "/com/suse/manager/reactor/messaging/test/virt.guest.definition.xml", placeholders, - vmState, "started"); - expectGuestDefinition("98eef4f7-eb7f-4be8-859d-11658506c496", "virt.noguest.txt", null, - vmState, "deleted"); - - // Start event - Optional startEvent = EngineEvent.parse(getEngineEvent("virtevents.guest.started.json", null)); - AbstractLibvirtEngineMessage startMessage = AbstractLibvirtEngineMessage.create(startEvent.get()); - - LibvirtEngineDomainLifecycleMessageAction action = new LibvirtEngineDomainLifecycleMessageAction(virtManager); - action.execute(startMessage); - - // Shutdown event - vmState.become("deleted"); - - context().checking(new Expectations() { { - never(virtManager).startGuest(host.getMinionId(), "sles12sp2-new"); - } }); - Optional stopEvent = EngineEvent.parse( - getEngineEvent("virtevents.guest.shutdown.json", placeholders)); - AbstractLibvirtEngineMessage stopMessage = AbstractLibvirtEngineMessage.create(stopEvent.get()); - - action.execute(stopMessage); - } - - @Test - public void testShutdownPersistent() throws Exception { - expectGuestDefinition(uuid, - "/com/suse/manager/reactor/messaging/test/virt.guest.definition.xml", null); - context().checking(new Expectations() {{ - never(virtManager).startGuest(host.getMinionId(), "sles12sp2"); - }}); - Optional event = EngineEvent.parse( - getEngineEvent("virtevents.guest.shutdown.json", Collections.emptyMap())); - AbstractLibvirtEngineMessage message = AbstractLibvirtEngineMessage.create(event.get()); - - new LibvirtEngineDomainLifecycleMessageAction(virtManager).execute(message); - - DataResult guests = SystemManager.virtualGuestsForHostList(user, host.getId(), null); - List matchingGuests = guests.stream().filter(vso -> vso.getUuid().equals(guid)) - .collect(Collectors.toList()); - assertEquals(VirtualInstanceFactory.getInstance().getStoppedState().getLabel(), - matchingGuests.get(0).getStateLabel()); - } - - @Test - public void testShutdownTransient() throws Exception { - expectGuestDefinition(uuid, null, null); - context().checking(new Expectations() {{ - never(virtManager).startGuest(host.getMinionId(), "sles12sp2"); - }}); - Optional event = EngineEvent.parse( - getEngineEvent("virtevents.guest.shutdown.json", Collections.emptyMap())); - AbstractLibvirtEngineMessage message = AbstractLibvirtEngineMessage.create(event.get()); - - new LibvirtEngineDomainLifecycleMessageAction(virtManager).execute(message); - - DataResult guests = SystemManager.virtualGuestsForHostList(user, host.getId(), null); - List matchingGuests = guests.stream().filter(vso -> vso.getUuid().equals(guid)) - .collect(Collectors.toList()); - - assertEquals(0, matchingGuests.size()); - } - - @Test - public void testUpdate() throws Exception { - expectGuestDefinition(uuid, - "/com/suse/manager/reactor/messaging/test/virt.guest.definition.xml", null); - Optional event = EngineEvent.parse( - getEngineEvent("virtevents.guest.updated.json", Collections.emptyMap())); - AbstractLibvirtEngineMessage message = AbstractLibvirtEngineMessage.create(event.get()); - - new LibvirtEngineDomainLifecycleMessageAction(virtManager).execute(message); - - DataResult guests = SystemManager.virtualGuestsForHostList(user, host.getId(), null); - List matchingGuests = guests.stream().filter(vso -> vso.getUuid().equals(guid)) - .collect(Collectors.toList()); - - - assertEquals(Long.valueOf(2), matchingGuests.get(0).getVcpus()); - assertEquals(Long.valueOf(1024), matchingGuests.get(0).getMemory()); - } - - protected Optional getSaltResponse(String filename, Map placeholders) { - return SaltTestUtils.getSaltResponse("/com/suse/manager/reactor/messaging/test/" + filename, - placeholders, null); - } - - private Event getEngineEvent(String filename, Map placeholders) throws Exception { - Path path = new File(TestUtils.findTestData( - "/com/suse/manager/reactor/messaging/test/" + filename).getPath()).toPath(); - String eventString = Files.lines(path).collect(Collectors.joining("\n")); - - if (placeholders != null) { - for (Map.Entry entry : placeholders.entrySet()) { - eventString = StringUtils.replace(eventString, entry.getKey(), entry.getValue()); - } - } - return EVENTS.parse(eventString); - } - - private void expectGuestDefinition(String uuidIn, String file, - Map placeholders) { - expectGuestDefinition(uuidIn, file, placeholders, null, null); - } - - private void expectGuestDefinition(String uuidIn, String file, - Map placeholders, - States state, String expectedState) { - context().checking(new Expectations() {{ - allowing(virtManager).getGuestDefinition("testminion.local", uuidIn); - will(returnValue( - file == null ? - Optional.empty() : - SaltTestUtils - .getSaltResponse(file, placeholders, null) - .map(xml -> GuestDefinition.parse(xml, Optional.empty())) - )); - if (state != null && expectedState != null) { - when(state.is(expectedState)); - } - }}); - } -} diff --git a/java/code/src/com/suse/manager/reactor/messaging/test/virt.guest.definition.xml b/java/code/src/com/suse/manager/reactor/messaging/test/virt.guest.definition.xml deleted file mode 100644 index 6330a065dab3..000000000000 --- a/java/code/src/com/suse/manager/reactor/messaging/test/virt.guest.definition.xml +++ /dev/null @@ -1,170 +0,0 @@ - - sles12sp2 - b99a8176-4f40-498d-8e61-2f6ade654fe2 - 1048576 - 1048576 - 2 - - /machine - - - hvm - - - - - - - - - Nehalem - - - - - - - destroy - restart - restart - - - - - - /usr/bin/qemu-kvm - - - - - - -
- - - - - - - -
- - - - - - - - - - - -
- - - - - - - - - - - - - -
- - - - -
- - - - -
- - - - -
- - - - - - -
- - - -
- - - - - - - -
- - - - - - - - - - - - - - - -
- - - - -
- - - - - - - - - - - - - - - -
- -