Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXavier Coulon2016-09-07 10:13:07 +0000
committerJeff Johnston2016-09-07 18:48:30 +0000
commitf9077113558c7a0ca294de67baaa13384e2704f8 (patch)
tree670a1b2e45f0f136b5de6f7893b2980e94457e26
parent9dfb2da94d14d3ede0e06ae0feaeba4779c59566 (diff)
downloadorg.eclipse.linuxtools-f9077113558c7a0ca294de67baaa13384e2704f8.tar.gz
org.eclipse.linuxtools-f9077113558c7a0ca294de67baaa13384e2704f8.tar.xz
org.eclipse.linuxtools-f9077113558c7a0ca294de67baaa13384e2704f8.zip
Bug 500973 - Push image to local registry fails
The problem came from the concatenation of ':' with the port number which resulted in 'localhost5058' instead of 'localhost:5000' because the ':' was interpreted as a number and not a Character (':' is 58 in the ASCII table) Added a JUnit test and improved SWTBot tests. Change-Id: I466405fd172647e81ca64fb4a12df7bdac45046d Signed-off-by: Xavier Coulon <xcoulon@redhat.com> Reviewed-on: https://git.eclipse.org/r/80572 Tested-by: Hudson CI Reviewed-by: Jeff Johnston <jjohnstn@redhat.com> (cherry picked from commit b3c3184784192846d4864bd8c6b9da21c3d1665f) Reviewed-on: https://git.eclipse.org/r/80619
-rw-r--r--containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerClientFactory.java20
-rw-r--r--containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/RegistryInfo.java6
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/docker/core/RegistryInfoTest.java53
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImagePushSWTBotTests.java22
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/PushImageCommandHandler.java3
5 files changed, 91 insertions, 13 deletions
diff --git a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerClientFactory.java b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerClientFactory.java
index e399903e55..48619098b6 100644
--- a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerClientFactory.java
+++ b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerClientFactory.java
@@ -95,15 +95,17 @@ public class DockerClientFactory {
return builder.build();
}
- private AuthConfig buildAuthentication(IRegistryAccount info) {
- final AuthConfig authAccount = AuthConfig.builder()
- .serverAddress(info.getServerAddress())
- .username(info.getUsername())
- .email(info.getEmail())
- .password(info.getPassword() != null
- ? new String(info.getPassword()) : null)
- .build();
- return authAccount;
+ private AuthConfig buildAuthentication(final IRegistryAccount info) {
+ if (info.getUsername() != null && !info.getUsername().isEmpty()) {
+ final AuthConfig authAccount = AuthConfig.builder()
+ .serverAddress(info.getServerAddress())
+ .username(info.getUsername()).email(info.getEmail())
+ .password(info.getPassword() != null
+ ? new String(info.getPassword()) : null)
+ .build();
+ return authAccount;
+ }
+ return null;
}
}
diff --git a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/RegistryInfo.java b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/RegistryInfo.java
index 5276ee74d0..8beec033bd 100644
--- a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/RegistryInfo.java
+++ b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/RegistryInfo.java
@@ -38,8 +38,10 @@ public class RegistryInfo extends AbstractRegistry {
public String getServerHost() {
try {
final URL serverAddress = new URL(getServerAddress());
- return serverAddress.getHost() + (serverAddress.getPort() != -1
- ? ':' + serverAddress.getPort() : ""); //$NON-NLS-1$
+ final String serverHost = serverAddress.getHost()
+ + (serverAddress.getPort() != -1
+ ? ":" + serverAddress.getPort() : ""); //$NON-NLS-1$
+ return serverHost;
} catch (MalformedURLException e) {
// assume there was no scheme, so just use the plain
// server address
diff --git a/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/docker/core/RegistryInfoTest.java b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/docker/core/RegistryInfoTest.java
new file mode 100644
index 0000000000..2cb110664f
--- /dev/null
+++ b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/docker/core/RegistryInfoTest.java
@@ -0,0 +1,53 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Red Hat.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat - Initial Contribution
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.docker.core;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.eclipse.linuxtools.internal.docker.core.RegistryAccountInfo;
+import org.eclipse.linuxtools.internal.docker.core.RegistryInfo;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameter;
+import org.junit.runners.Parameterized.Parameters;
+
+/**
+ * Testing the {@link RegistryInfo} class
+ */
+@RunWith(Parameterized.class)
+public class RegistryInfoTest {
+
+ @Parameters
+ public static Object[][] getData() {
+ final Object[][] data = new Object[][] {
+ new Object[] { new RegistryInfo("http://localhost", false), "localhost" },
+ new Object[] { new RegistryInfo("http://localhost:5000", false), "localhost:5000" },
+ new Object[] { new RegistryAccountInfo("http://localhost:5000", "user", "user@foo.com",
+ "secret".toCharArray(), false), "localhost:5000" }, };
+ return data;
+ }
+
+ @Parameter(0)
+ public RegistryInfo registryInfo;
+
+ @Parameter(1)
+ public String expectedServerAddress;
+
+ @Test
+ public void shouldGetServerHost() {
+ // when
+ final String serverAddress = registryInfo.getServerHost();
+ // then
+ assertThat(serverAddress).isEqualTo(expectedServerAddress);
+ }
+}
diff --git a/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImagePushSWTBotTests.java b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImagePushSWTBotTests.java
index beff20e7f8..aa0ea25b2d 100644
--- a/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImagePushSWTBotTests.java
+++ b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImagePushSWTBotTests.java
@@ -130,7 +130,7 @@ public class ImagePushSWTBotTests {
// then the 'push()' method on the client should have been called
SWTUtils.wait(1, TimeUnit.SECONDS);
Mockito.verify(client, Mockito.times(1)).tag("foo/bar:latest", "foo.com/foo/bar:latest", false);
- Mockito.verify(client, Mockito.times(1)).push(Matchers.any(), Matchers.any());
+ Mockito.verify(client, Mockito.times(1)).push(Matchers.eq("foo.com/foo/bar:latest"), Matchers.any());
Mockito.verify(client, Mockito.times(1)).removeImage("foo.com/foo/bar:latest", false, false);
}
@@ -144,12 +144,30 @@ public class ImagePushSWTBotTests {
// then the 'push()' method on the client should have been called
SWTUtils.wait(1, TimeUnit.SECONDS);
Mockito.verify(client, Mockito.never()).tag(Matchers.anyString(), Matchers.anyString(), Matchers.anyBoolean());
- Mockito.verify(client, Mockito.times(1)).push(Matchers.any(), Matchers.any());
+ Mockito.verify(client, Mockito.times(1)).push(Matchers.eq("foo/bar:latest"), Matchers.any());
Mockito.verify(client, Mockito.never()).removeImage(Matchers.anyString(), Matchers.anyBoolean(),
Matchers.anyBoolean());
}
@Test
+ public void shouldPushImageToLocalRegistry() throws DockerException, InterruptedException {
+ // when
+ MockRegistryAccountManagerFactory
+ .registryAccount(new RegistryAccountInfo("http://localhost:5000", null, null, null, false)).build();
+ openPushWizard();
+ // when selecting other registry
+ bot.comboBox(0).setSelection(1);
+ // when click on Finish
+ bot.button("Finish").click();
+ // wait for the push job to complete
+ // then the 'push()' method on the client should have been called
+ SWTUtils.wait(1, TimeUnit.SECONDS);
+ Mockito.verify(client, Mockito.times(1)).tag("foo/bar:latest", "localhost:5000/foo/bar:latest", false);
+ Mockito.verify(client, Mockito.times(1)).push(Matchers.eq("localhost:5000/foo/bar:latest"), Matchers.any());
+ Mockito.verify(client, Mockito.times(1)).removeImage("localhost:5000/foo/bar:latest", false, false);
+ }
+
+ @Test
public void shouldPushImageWithForceTagging() throws DockerException, InterruptedException {
// given
MockRegistryAccountManagerFactory
diff --git a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/PushImageCommandHandler.java b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/PushImageCommandHandler.java
index 35f3f7525c..d5a7dc9323 100644
--- a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/PushImageCommandHandler.java
+++ b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/PushImageCommandHandler.java
@@ -22,6 +22,7 @@ import org.eclipse.linuxtools.docker.core.DockerException;
import org.eclipse.linuxtools.docker.core.IDockerConnection;
import org.eclipse.linuxtools.docker.core.IDockerImage;
import org.eclipse.linuxtools.docker.core.IRegistryAccount;
+import org.eclipse.linuxtools.docker.ui.Activator;
import org.eclipse.linuxtools.internal.docker.core.DefaultImagePushProgressHandler;
import org.eclipse.linuxtools.internal.docker.core.DockerConnection;
import org.eclipse.linuxtools.internal.docker.ui.views.DVMessages;
@@ -124,6 +125,8 @@ public class PushImageCommandHandler extends AbstractHandler {
DVMessages.getFormattedString(ERROR_PUSHING_IMAGE,
defaultImageNameTag),
e.getMessage()));
+ Activator.logErrorMessage(DVMessages.getFormattedString(
+ ERROR_PUSHING_IMAGE, defaultImageNameTag), e);
// for now
} catch (InterruptedException e) {
// do nothing

Back to the top