Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Add option to set kernel and post kernel options on provisioning via API #9618

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2895,7 +2895,9 @@ public int provisionVirtualGuest(User loggedInUser, Integer sid, String guestNam
@ApiIgnore(ApiType.HTTP)
public int provisionSystem(User loggedInUser, Integer sid, String profileName)
throws FaultException {
return provisionSystem(loggedInUser, RhnXmlRpcServer.getRequest(), sid, profileName, new Date());
return provisionSystem(
loggedInUser, RhnXmlRpcServer.getRequest(), sid, null, profileName, new Date(), new HashMap<>()
);
}

/**
Expand All @@ -2919,7 +2921,7 @@ public int provisionSystem(User loggedInUser, Integer sid, String profileName)
@ApiIgnore(ApiType.XMLRPC)
public int provisionSystem(User loggedInUser, HttpServletRequest request, Integer sid, String profileName)
throws FaultException {
return provisionSystem(loggedInUser, request, sid, profileName, new Date());
return provisionSystem(loggedInUser, request, sid, null, profileName, new Date(), new HashMap<>());
}

/**
Expand All @@ -2944,7 +2946,9 @@ public int provisionSystem(User loggedInUser, HttpServletRequest request, Intege
@ApiIgnore(ApiType.HTTP)
public int provisionSystem(User loggedInUser, Integer sid, Integer proxy, String profileName)
throws FaultException {
return provisionSystem(loggedInUser, RhnXmlRpcServer.getRequest(), sid, proxy, profileName, new Date());
return provisionSystem(
loggedInUser, RhnXmlRpcServer.getRequest(), sid, proxy, profileName, new Date(), new HashMap<>()
);
}

/**
Expand All @@ -2971,7 +2975,7 @@ public int provisionSystem(User loggedInUser, Integer sid, Integer proxy, String
public int provisionSystem(User loggedInUser, HttpServletRequest request, Integer sid, Integer proxy,
String profileName)
throws FaultException {
return provisionSystem(loggedInUser, request, sid, proxy, profileName, new Date());
return provisionSystem(loggedInUser, request, sid, proxy, profileName, new Date(), new HashMap<>());
}

/**
Expand All @@ -2997,7 +3001,9 @@ public int provisionSystem(User loggedInUser, HttpServletRequest request, Intege
public int provisionSystem(User loggedInUser, Integer sid,
String profileName, Date earliestDate)
throws FaultException {
return provisionSystem(loggedInUser, RhnXmlRpcServer.getRequest(), sid, profileName, earliestDate);
return provisionSystem(
loggedInUser, RhnXmlRpcServer.getRequest(), sid, null, profileName, earliestDate, new HashMap<>()
);
}

/**
Expand All @@ -3024,7 +3030,7 @@ public int provisionSystem(User loggedInUser, Integer sid,
public int provisionSystem(User loggedInUser, HttpServletRequest request, Integer sid,
String profileName, Date earliestDate)
throws FaultException {
return provisionSystem(loggedInUser, request , sid, null, profileName, earliestDate);
return provisionSystem(loggedInUser, request , sid, null, profileName, earliestDate, new HashMap<>());
}

/**
Expand Down Expand Up @@ -3053,8 +3059,9 @@ public int provisionSystem(User loggedInUser, Integer sid,
Integer proxy, String profileName, Date earliestDate)
throws FaultException {
HttpServletRequest request = RhnXmlRpcServer.getRequest();
return provisionSystem(loggedInUser, request, sid, proxy, profileName, earliestDate);
return provisionSystem(loggedInUser, request, sid, proxy, profileName, earliestDate, new HashMap<>());
}

/**
* Provision a system using the specified kickstart/autoinstallation profile at specified time.
*
Expand All @@ -3079,7 +3086,77 @@ public int provisionSystem(User loggedInUser, Integer sid,
*/
@ApiIgnore(ApiType.XMLRPC)
public int provisionSystem(User loggedInUser, HttpServletRequest request, Integer sid,
Integer proxy, String profileName, Date earliestDate)
Integer proxy, String profileName, Date earliestDate)
throws FaultException {
return provisionSystem(loggedInUser, request, sid, proxy, profileName, earliestDate, new HashMap<>());
}

/**
* Provision a system using the specified kickstart/autoinstallation profile at specified time.
*
* @param loggedInUser The current user
* @param sid of the system to be provisioned
* @param proxy ID of the proxy to use
* @param profileName of Profile to be used.
* @param earliestDate when the autoinstallation needs to be scheduled
* @param advancedOptions custom kernel or post kernel options
* @return Returns id of the action if successful, exception otherwise
* @throws FaultException A FaultException is thrown if the server corresponding to
* id cannot be found or profile is not found.
*
* @apidoc.doc Provision a system using the specified kickstart/autoinstallation profile.
* @apidoc.param #session_key()
* @apidoc.param #param_desc("int", "sid", "ID of the system to be provisioned.")
* @apidoc.param #param_desc("int", "proxy", "ID of the proxy to use.")
* @apidoc.param #param_desc("string", "profileName", "Profile to use.")
* @apidoc.param #param("$date", "earliestDate")
* @apidoc.param
* #struct_begin("advancedOptions")
* #prop_desc("string", "kernel_options", "custom kernel options")
* #prop_desc("string", "post_kernel_options", "custom post kernel options")
* #struct_end()
* @apidoc.returntype #param_desc("int", "id", "ID of the action scheduled, otherwise exception thrown
* on error")
*/
@ApiIgnore(ApiType.HTTP)
public int provisionSystem(User loggedInUser, Integer sid, Integer proxy, String profileName,
Date earliestDate, Map<String, String> advancedOptions)
throws FaultException {
HttpServletRequest request = RhnXmlRpcServer.getRequest();
return provisionSystem(loggedInUser, request, sid, proxy, profileName, earliestDate, advancedOptions);
}

/**
* Provision a system using the specified kickstart/autoinstallation profile at specified time.
*
* @param loggedInUser The current user
* @param request the request
* @param sid of the system to be provisioned
* @param proxy ID of the proxy to use
* @param profileName of Profile to be used.
* @param earliestDate when the autoinstallation needs to be scheduled
* @param advancedOptions custom kernel or post kernel options
* @return Returns id of the action if successful, exception otherwise
* @throws FaultException A FaultException is thrown if the server corresponding to
* id cannot be found or profile is not found.
*
* @apidoc.doc Provision a system using the specified kickstart/autoinstallation profile.
* @apidoc.param #session_key()
* @apidoc.param #param_desc("int", "sid", "ID of the system to be provisioned.")
* @apidoc.param #param_desc("int", "proxy", "ID of the proxy to use.")
* @apidoc.param #param_desc("string", "profileName", "Profile to use.")
* @apidoc.param #param("$date", "earliestDate")
* @apidoc.param
* #struct_begin("advancedOptions")
* #prop_desc("string", "kernel_options", "custom kernel options")
* #prop_desc("string", "post_kernel_options", "custom post kernel options")
* #struct_end()
* @apidoc.returntype #param_desc("int", "id", "ID of the action scheduled, otherwise exception thrown
* on error")
*/
@ApiIgnore(ApiType.XMLRPC)
public int provisionSystem(User loggedInUser, HttpServletRequest request, Integer sid,
Integer proxy, String profileName, Date earliestDate, Map<String, String> advancedOptions)
throws FaultException {
log.debug("provisionSystem called.");

Expand All @@ -3104,6 +3181,12 @@ public int provisionSystem(User loggedInUser, HttpServletRequest request, Intege
KickstartScheduleCommand cmd = new KickstartScheduleCommand(
Long.valueOf(sid),
ksdata.getId(), loggedInUser, earliestDate, host);
if (advancedOptions.containsKey("kernel_options")) {
cmd.setKernelOptions(advancedOptions.get("kernel_options"));
}
if (advancedOptions.containsKey("post_kernel_options")) {
cmd.setPostKernelOptions(advancedOptions.get("post_kernel_options"));
}
if (proxy != null) {
Server proxyServer = SystemManager.lookupByIdAndOrg(Long.valueOf(proxy), loggedInUser.getOrg());
if (proxyServer == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.extension.RegisterExtension;

import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

Expand Down Expand Up @@ -134,10 +136,12 @@ public void testProvisionSystem() throws Exception {
"custom", "echo test-command");
k.getKickstartDefaults().getKstree().setChannel(server.getBaseChannel());
String profileName = k.getLabel();
Map<String, String> advancedOptions = Map.of("kernel_options", "console=ttyS0");
RhnMockHttpServletRequest request = new RhnMockHttpServletRequest();

int result = 0;
result = handler.provisionSystem(admin, request, server.getId().intValue(), profileName);
result = handler.provisionSystem(admin, request, server.getId().intValue(), null, profileName,
new Date(), advancedOptions);

// something was scheduled
assertNotEquals(0, result);
Expand All @@ -149,6 +153,7 @@ public void testProvisionSystem() throws Exception {
assertNotNull(ks);
assertEquals(server.getId(), ks.getNewServer().getId());
assertEquals("echo test-command", ks.getKsdata().getCommand("custom").getArguments());
assertEquals("console=ttyS0", ks.getKsdata().getKernelParams());

// Action details to check correct host
List<Action> actions = ActionFactory.listActionsForServer(admin, server);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Add option to set kernel and post kernel options on provisioning via API

Check failure on line 1 in java/spacewalk-java.changes.parlt.provisioning-kernel-options-api

View workflow job for this annotation

GitHub Actions / Changelog tests

Line exceeds 67 characters in file java/spacewalk-java.changes.parlt.provisioning-kernel-options-api#L1
Loading