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

[JENKINS-60551] Copy constructor test should check all fields #668

Merged
merged 2 commits into from
Dec 20, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -3,6 +3,7 @@
import static org.apache.commons.lang.StringUtils.isEmpty;

import java.io.IOException;
import java.io.StringReader;
import java.net.ConnectException;
import java.net.MalformedURLException;
import java.net.SocketTimeoutException;
Expand All @@ -28,6 +29,7 @@
import javax.annotation.Nonnull;
import javax.servlet.ServletException;

import hudson.util.XStream2;
import io.fabric8.openshift.client.OpenShiftClient;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang.StringUtils;
Expand Down Expand Up @@ -153,27 +155,11 @@ public KubernetesCloud(String name) {
*/
public KubernetesCloud(@NonNull String name, @NonNull KubernetesCloud source) {
super(name);
this.defaultsProviderTemplate = source.defaultsProviderTemplate;
XStream2 xs = new XStream2();
xs.omitField(Cloud.class, "name");
xs.omitField(KubernetesCloud.class, "templates"); // TODO PodTemplate and fields needs to implement equals
xs.unmarshal(XStream2.getDefaultDriver().createReader(new StringReader(xs.toXML(source))), this);
this.templates.addAll(source.templates);
this.serverUrl = source.serverUrl;
this.serverCertificate = source.serverCertificate;
this.skipTlsVerify = source.skipTlsVerify;
this.addMasterProxyEnvVars = source.addMasterProxyEnvVars;
this.namespace = source.namespace;
this.directConnection = source.directConnection;
this.jenkinsUrl = source.jenkinsUrl;
this.jenkinsTunnel = source.jenkinsTunnel;
this.credentialsId = source.credentialsId;
this.containerCap = source.containerCap;
this.retentionTimeout = source.retentionTimeout;
this.connectTimeout = source.connectTimeout;
this.readTimeout = source.readTimeout;
this.usageRestricted = source.usageRestricted;
this.maxRequestsPerHost = source.maxRequestsPerHost;
this.podRetention = source.podRetention;
this.waitForPodSec = source.waitForPodSec;
this.capOnlyOnAlivePods = source.capOnlyOnAlivePods;
setPodLabels(source.podLabels);
}

@Deprecated
Expand Down Expand Up @@ -824,12 +810,25 @@ public ListBoxModel doFillCredentialsIdItems(@QueryParameter String serverUrl) {
@RequirePOST
@SuppressWarnings("unused") // used by jelly
public FormValidation doCheckMaxRequestsPerHostStr(@QueryParameter String value) throws IOException, ServletException {
try {
Integer.parseInt(value);
return FormValidation.ok();
} catch (NumberFormatException e) {
return FormValidation.error("Please supply an integer");
}
return FormValidation.validatePositiveInteger(value);
}

@RequirePOST
@SuppressWarnings("unused") // used by jelly
public FormValidation doCheckConnectTimeout(@QueryParameter String value) {
return FormValidation.validateIntegerInRange(value, DEFAULT_CONNECT_TIMEOUT_SECONDS, Integer.MAX_VALUE);
}

@RequirePOST
@SuppressWarnings("unused") // used by jelly
public FormValidation doCheckReadTimeout(@QueryParameter String value) {
return FormValidation.validateIntegerInRange(value, DEFAULT_READ_TIMEOUT_SECONDS, Integer.MAX_VALUE);
}

@RequirePOST
@SuppressWarnings("unused") // used by jelly
public FormValidation doCheckRetentionTimeout(@QueryParameter String value) {
return FormValidation.validateIntegerInRange(value, DEFAULT_RETENTION_TIMEOUT_MINUTES, Integer.MAX_VALUE);
}

@SuppressWarnings("unused") // used by jelly
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@
</f:entry>

<f:entry title="${%Connection Timeout (seconds)}" field="connectTimeout">
<f:textbox default="${descriptor.defaultConnectTimeout}"/>
<f:number min="${descriptor.defaultConnectTimeout}" default="${descriptor.defaultConnectTimeout}" checkMethod="post"/>
Vlatombe marked this conversation as resolved.
Show resolved Hide resolved
</f:entry>

<f:entry title="${%Read Timeout (seconds)}" field="readTimeout">
<f:textbox default="${descriptor.defaultReadTimeout}"/>
<f:number min="${descriptor.defaultReadTimeout}" default="${descriptor.defaultReadTimeout}" checkMethod="post"/>
</f:entry>

<f:entry title="${%Concurrency Limit}" field="containerCapStr">
<f:textbox default="10"/>
<f:number default="10"/>
</f:entry>

<f:entry title="${%Pod Labels}" field="podLabels">
Expand All @@ -60,7 +60,7 @@
descriptors="${descriptor.allowedPodRetentions}" default="${descriptor.defaultPodRetention}" />

<f:entry title="${%Max connections to Kubernetes API}" field="maxRequestsPerHostStr">
<f:textbox default="32" checkMethod="post"/>
<f:number default="32" checkMethod="post"/>
</f:entry>

<f:entry title="Seconds to wait for pod to be running" field="waitForPodSec">
Expand All @@ -69,7 +69,7 @@

<f:advanced>
<f:entry title="${%Container Cleanup Timeout (minutes)}" field="retentionTimeout">
<f:textbox default="${descriptor.defaultRetentionTimeout}"/>
<f:number min="${descriptor.defaultRetentionTimeout}" default="${descriptor.defaultRetentionTimeout}" checkMethod="post"/>
</f:entry>

<f:entry title="${%Transfer proxy related environment variables from master to agent}" field="addMasterProxyEnvVars">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<div>
The connection timeout in seconds for connections to Kubernetes API. A value of 0 means no timeout.
</div>
The connection timeout in seconds for connections to Kubernetes API. Minimum value is 5.
</div>
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<div>
The read timeout in seconds for connections to Kubernetes API. A value of 0 means no timeout.
</div>
The read timeout in seconds for connections to Kubernetes API. Minimum value is 15.
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ public void copyConstructor() throws Exception {
pt.setName("podTemplate");

KubernetesCloud cloud = new KubernetesCloud("name");
ArrayList<String> objectProperties = Lists.newArrayList("templates", "podRetention", "podLabels", "labels");
ArrayList<String> objectProperties = Lists.newArrayList("templates", "podRetention", "podLabels", "labels", "serverCertificate");
for (String property: PropertyUtils.describe(cloud).keySet()) {
if (PropertyUtils.isWriteable(cloud, property)) {
Class<?> propertyType = PropertyUtils.getPropertyType(cloud, property);
Expand All @@ -307,13 +307,14 @@ public void copyConstructor() throws Exception {
}
}
}
cloud.setServerCertificate("-----BEGIN CERTIFICATE-----");
cloud.setTemplates(Collections.singletonList(pt));
cloud.setPodRetention(new Always());
cloud.setPodLabels(PodLabel.listOf("foo", "bar", "cat", "dog"));
cloud.setLabels(ImmutableMap.of("foo", "bar"));

KubernetesCloud copy = new KubernetesCloud("copy", cloud);

assertEquals("copy", copy.name);
assertEquals("Expected cloud from copy constructor to be equal to the source except for name", cloud, copy);
}

Expand Down