From ed486dde9bf173393b1700a96762c3fd15f6a0f7 Mon Sep 17 00:00:00 2001
From: jaiszeen <116672962+jaiszeen@users.noreply.github.com>
Date: Wed, 7 Dec 2022 15:25:47 -0600
Subject: [PATCH 01/22] feat: comman-connectivity-steps
---
.../pom.xml | 12 +-
.../testing/platform/NetworkUtils.java | 26 ++++
.../greengrass/testing/platform/Platform.java | 6 +
.../testing/platform/linux/LinuxPlatform.java | 6 +
.../platform/linux/NetworkUtilsLinux.java | 138 ++++++++++++++++++
.../pom.xml | 2 +-
6 files changed, 188 insertions(+), 2 deletions(-)
create mode 100644 aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/src/main/java/com/aws/greengrass/testing/platform/NetworkUtils.java
create mode 100644 aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/src/main/java/com/aws/greengrass/testing/platform/linux/NetworkUtilsLinux.java
diff --git a/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/pom.xml b/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/pom.xml
index 88441f84..05bfafdd 100644
--- a/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/pom.xml
+++ b/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/pom.xml
@@ -99,7 +99,7 @@
com.google.guava
guava
- 31.1-jre
+ 23.0
org.immutables
@@ -142,6 +142,16 @@
2.13.0
test
+
+ software.amazon.awssdk
+ utils
+
+
+ org.projectlombok
+ lombok
+ 1.18.22
+ compile
+
\ No newline at end of file
diff --git a/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/src/main/java/com/aws/greengrass/testing/platform/NetworkUtils.java b/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/src/main/java/com/aws/greengrass/testing/platform/NetworkUtils.java
new file mode 100644
index 00000000..840e9d4b
--- /dev/null
+++ b/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/src/main/java/com/aws/greengrass/testing/platform/NetworkUtils.java
@@ -0,0 +1,26 @@
+/*
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+package com.aws.greengrass.testing.platform;
+
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.util.ArrayList;
+import java.util.List;
+
+public abstract class NetworkUtils {
+ protected static final String[] MQTT_PORTS = {"8883", "443"};
+ // 8888 and 8889 are used by the squid proxy which runs on a remote DUT
+ // and need to disable access to test offline proxy scenarios
+ protected static final String[] NETWORK_PORTS = {"443", "8888", "8889"};
+ protected static final int[] GG_UPSTREAM_PORTS = {8883, 8443, 443};
+ protected static final int SSH_PORT = 22;
+ protected final List blockedPorts = new ArrayList<>();
+
+ public abstract void disconnectNetwork() throws InterruptedException, IOException;
+
+ public abstract void recoverNetwork() throws InterruptedException, IOException;
+
+}
diff --git a/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/src/main/java/com/aws/greengrass/testing/platform/Platform.java b/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/src/main/java/com/aws/greengrass/testing/platform/Platform.java
index 7eb5a0cd..c3f4c022 100644
--- a/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/src/main/java/com/aws/greengrass/testing/platform/Platform.java
+++ b/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/src/main/java/com/aws/greengrass/testing/platform/Platform.java
@@ -9,4 +9,10 @@ public interface Platform {
Commands commands();
PlatformFiles files();
+
+ default NetworkUtils getNetworkUtils() {
+ return null;
+ }
+
}
+
diff --git a/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/src/main/java/com/aws/greengrass/testing/platform/linux/LinuxPlatform.java b/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/src/main/java/com/aws/greengrass/testing/platform/linux/LinuxPlatform.java
index 19db0728..d1772cf1 100644
--- a/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/src/main/java/com/aws/greengrass/testing/platform/linux/LinuxPlatform.java
+++ b/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/src/main/java/com/aws/greengrass/testing/platform/linux/LinuxPlatform.java
@@ -8,6 +8,7 @@
import com.aws.greengrass.testing.api.device.Device;
import com.aws.greengrass.testing.api.model.PillboxContext;
import com.aws.greengrass.testing.platform.AbstractPlatform;
+import com.aws.greengrass.testing.platform.NetworkUtils;
public class LinuxPlatform extends AbstractPlatform {
public LinuxPlatform(final Device device, final PillboxContext pillboxContext) {
@@ -18,4 +19,9 @@ public LinuxPlatform(final Device device, final PillboxContext pillboxContext) {
public LinuxCommands commands() {
return new LinuxCommands(device, pillboxContext);
}
+
+ @Override
+ public NetworkUtils getNetworkUtils() {
+ return new NetworkUtilsLinux();
+ }
}
diff --git a/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/src/main/java/com/aws/greengrass/testing/platform/linux/NetworkUtilsLinux.java b/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/src/main/java/com/aws/greengrass/testing/platform/linux/NetworkUtilsLinux.java
new file mode 100644
index 00000000..eaa5c4a7
--- /dev/null
+++ b/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/src/main/java/com/aws/greengrass/testing/platform/linux/NetworkUtilsLinux.java
@@ -0,0 +1,138 @@
+/*
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+package com.aws.greengrass.testing.platform.linux;
+
+import com.aws.greengrass.testing.platform.NetworkUtils;
+import lombok.AllArgsConstructor;
+import software.amazon.awssdk.utils.IoUtils;
+
+import java.io.IOException;
+import java.net.NetworkInterface;
+import java.nio.charset.StandardCharsets;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+@AllArgsConstructor
+public class NetworkUtilsLinux extends NetworkUtils {
+ private static final String ENABLE_OPTION = "--insert";
+ private static final String DISABLE_OPTION = "--delete";
+ private static final String APPEND_OPTION = "-A";
+ private static final String IPTABLE_COMMAND_BLOCK_INGRESS_STR =
+ "sudo iptables %s INPUT -p tcp --sport %s -j REJECT";
+ private static final String IPTABLE_COMMAND_STR = "sudo iptables %s OUTPUT -p tcp --dport %s -j REJECT && "
+ + "sudo iptables %s INPUT -p tcp --sport %s -j REJECT";
+ private static final String IPTABLES_DROP_DPORT_EXTERNAL_ONLY_COMMAND_STR =
+ "sudo iptables %s INPUT -p tcp -s localhost --dport %s -j ACCEPT && "
+ +
+ "sudo iptables %s INPUT -p tcp --dport %s -j DROP && "
+ +
+ "sudo iptables %s OUTPUT -p tcp -d localhost --dport %s -j ACCEPT && "
+ +
+ "sudo iptables %s OUTPUT -p tcp --dport %s -j DROP";
+ private static final String IPTABLE_SAFELIST_COMMAND_STR
+ = "sudo iptables %s OUTPUT -p tcp -d %s --dport %d -j ACCEPT && "
+ +
+ "sudo iptables %s INPUT -p tcp -s %s --sport %d -j ACCEPT";
+ private static final String GET_IPTABLES_RULES = "sudo iptables -S";
+
+ // The string we are looking for to verify that there is an iptables rule to reject a port
+ // We only need to look for sport because sport only gets created if dport is successful
+ private static final String IPTABLES_RULE = "-m tcp --sport %s -j REJECT";
+
+ private static final AtomicBoolean bandwidthSetup = new AtomicBoolean(false);
+
+
+ private void modifyMqttConnection(String action) throws IOException, InterruptedException {
+ for (String port : MQTT_PORTS) {
+ new ProcessBuilder().command(
+ "sh", "-c", String.format(IPTABLES_DROP_DPORT_EXTERNAL_ONLY_COMMAND_STR,
+ action, port, action, port, action, port, action, port)
+ ).start().waitFor(2, TimeUnit.SECONDS);
+ }
+ }
+
+
+ private void filterPortOnInterface(String iface, int port) throws IOException, InterruptedException {
+ // Filtering SSH traffic impacts test execution, so we explicitly disallow it
+ if (port == SSH_PORT) {
+ return;
+ }
+ List filterSourcePortCommand = Stream.of("sudo", "tc", "filter", "add", "dev",
+ iface, "parent", "1:", "protocol", "ip", "prio", "1", "u32", "match",
+ "ip", "sport", Integer.toString(port), "0xffff", "flowid", "1:2").collect(Collectors.toList());
+ executeCommand(filterSourcePortCommand);
+
+ List filterDestPortCommand = Stream.of("sudo", "tc", "filter", "add", "dev", iface,
+ "parent", "1:", "protocol", "ip", "prio", "1", "u32", "match",
+ "ip", "dport", Integer.toString(port), "0xffff", "flowid", "1:2").collect(Collectors.toList());
+ executeCommand(filterDestPortCommand);
+ }
+
+ private void deleteRootNetemQdiscOnInterface() throws InterruptedException, IOException {
+ Enumeration nets = NetworkInterface.getNetworkInterfaces();
+ for (NetworkInterface netint : Collections.list(nets)) {
+ if (netint.isPointToPoint() || netint.isLoopback()) {
+ continue;
+ }
+ executeCommand(Stream.of("sudo", "tc", "qdisc", "del", "dev", netint.getName(), "root")
+ .collect(Collectors.toList()));
+ }
+ }
+
+ private void createRootNetemQdiscOnInterface(String iface, int netemRateKbps)
+ throws InterruptedException, IOException {
+ // TODO: Add support for setting packet loss and delay
+ int netemDelayMs = 750;
+ List addQdiscCommand = Stream.of("sudo", "tc", "qdisc", "add", "dev", iface, "root", "handle",
+ "1:", "prio", "bands", "2", "priomap", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0",
+ "0", "0", "0", "0", "0").collect(Collectors.toList());
+ executeCommand(addQdiscCommand);
+
+ List netemCommand =
+ Stream.of("sudo", "tc", "qdisc", "add", "dev", iface, "parent", "1:2", "netem", "delay",
+ String.format("%dms", netemDelayMs), "rate", String.format("%dkbit", netemRateKbps))
+ .collect(Collectors.toList());
+ executeCommand(netemCommand);
+ }
+
+ private String executeCommand(List command) throws IOException, InterruptedException {
+ Process proc = new ProcessBuilder().command(command).start();
+ proc.waitFor(2, TimeUnit.SECONDS);
+ if (proc.exitValue() != 0) {
+ throw new IOException("CLI command " + command + " failed with error "
+ + new String(IoUtils.toByteArray(proc.getErrorStream()), StandardCharsets.UTF_8));
+ }
+ return new String(IoUtils.toByteArray(proc.getInputStream()), StandardCharsets.UTF_8);
+ }
+
+ @Override
+ public void disconnectNetwork() throws InterruptedException, IOException {
+ interfacepolicy(IPTABLE_COMMAND_STR, ENABLE_OPTION, "connection-loss", NETWORK_PORTS);
+ }
+
+ @Override
+ public void recoverNetwork() throws InterruptedException, IOException {
+ interfacepolicy(IPTABLE_COMMAND_STR, DISABLE_OPTION, "connection-recover", NETWORK_PORTS);
+ if (bandwidthSetup.get()) {
+ deleteRootNetemQdiscOnInterface();
+ bandwidthSetup.set(false);
+ }
+ }
+
+ private void interfacepolicy(String iptableCommandString, String option, String eventName, String... ports)
+ throws InterruptedException,
+ IOException {
+ for (String port : ports) {
+ new ProcessBuilder().command("sh", "-c", String.format(iptableCommandString, option, port, option, port))
+ .start().waitFor(2, TimeUnit.SECONDS);
+ }
+ }
+}
diff --git a/aws-greengrass-testing-platform/aws-greengrass-testing-platform-pillbox/pom.xml b/aws-greengrass-testing-platform/aws-greengrass-testing-platform-pillbox/pom.xml
index 62c30d7c..d65a46fd 100644
--- a/aws-greengrass-testing-platform/aws-greengrass-testing-platform-pillbox/pom.xml
+++ b/aws-greengrass-testing-platform/aws-greengrass-testing-platform-pillbox/pom.xml
@@ -124,7 +124,7 @@
com.google.guava
guava
- 31.1-jre
+ 23.0
org.immutables
From 2ba72d0eff3ef2b721eddb8b2065a40b8b2e544e Mon Sep 17 00:00:00 2001
From: jaiszeen <116672962+jaiszeen@users.noreply.github.com>
Date: Thu, 8 Dec 2022 09:28:14 -0600
Subject: [PATCH 02/22] fix: pr comment
---
.../main/java/com/aws/greengrass/testing/platform/Platform.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/src/main/java/com/aws/greengrass/testing/platform/Platform.java b/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/src/main/java/com/aws/greengrass/testing/platform/Platform.java
index c3f4c022..43416391 100644
--- a/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/src/main/java/com/aws/greengrass/testing/platform/Platform.java
+++ b/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/src/main/java/com/aws/greengrass/testing/platform/Platform.java
@@ -11,7 +11,7 @@ public interface Platform {
PlatformFiles files();
default NetworkUtils getNetworkUtils() {
- return null;
+ throw new UnsupportedOperationException();
}
}
From a243a740a2dc402d6797ee116113e534efde0c5d Mon Sep 17 00:00:00 2001
From: jaiszeen <116672962+jaiszeen@users.noreply.github.com>
Date: Thu, 8 Dec 2022 15:40:36 -0600
Subject: [PATCH 03/22] feat: connectivitystep
---
.../features/CommanConnectivitySteps.java | 51 +++++++++++++++++++
.../pom.xml | 14 +++--
.../greengrass/testing/platform/Platform.java | 2 +-
.../testing/platform/PlatformResolver.java | 4 ++
.../platform/linux/NetworkUtilsLinux.java | 3 +-
5 files changed, 67 insertions(+), 7 deletions(-)
create mode 100644 aws-greengrass-testing-features/aws-greengrass-testing-features-api/src/main/java/com/aws/greengrass/testing/features/CommanConnectivitySteps.java
diff --git a/aws-greengrass-testing-features/aws-greengrass-testing-features-api/src/main/java/com/aws/greengrass/testing/features/CommanConnectivitySteps.java b/aws-greengrass-testing-features/aws-greengrass-testing-features-api/src/main/java/com/aws/greengrass/testing/features/CommanConnectivitySteps.java
new file mode 100644
index 00000000..f9c45e82
--- /dev/null
+++ b/aws-greengrass-testing-features/aws-greengrass-testing-features-api/src/main/java/com/aws/greengrass/testing/features/CommanConnectivitySteps.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+package com.aws.greengrass.testing.features;
+
+import com.aws.greengrass.testing.platform.PlatformResolver;
+import io.cucumber.guice.ScenarioScoped;
+import io.cucumber.java.en.Given;
+import io.cucumber.java.en.When;
+
+import java.io.IOException;
+import javax.inject.Inject;
+
+/**
+ * Checks the connectivity for platfroms.
+ *
+ * @throws IOException {throws IOException}
+ * @throws InterruptedException {throws IInterruptedException}
+ *
+ */
+@ScenarioScoped
+public class CommanConnectivitySteps {
+ private final PlatformResolver platformResolver;
+
+ @Inject
+ @SuppressWarnings("MissingJavadocMethod")
+ public CommanConnectivitySteps(PlatformResolver platformResolver) {
+ this.platformResolver = platformResolver;
+ }
+
+ /**
+ * Checks the connectivity for platfroms.
+ *
+ * @throws IOException {throws IOException}
+ * @throws InterruptedException {throws IInterruptedException}
+ * @param connectivity checks platfrom connectivity
+ *
+ */
+ @Given("device network connectivity is {word}")
+ @When("I set device network connectivity to {word}")
+ public void setDeviceNetwork(final String connectivity) throws IOException, InterruptedException {
+ if ("offline".equalsIgnoreCase(connectivity)) {
+ platformResolver.resolve().getNetworkUtils().disconnectNetwork();
+ } else {
+ platformResolver.resolve().getNetworkUtils().recoverNetwork();
+ }
+ }
+}
+
diff --git a/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/pom.xml b/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/pom.xml
index 05bfafdd..452fc2c4 100644
--- a/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/pom.xml
+++ b/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/pom.xml
@@ -99,7 +99,7 @@
com.google.guava
guava
- 23.0
+ 31.1-jre
org.immutables
@@ -147,9 +147,15 @@
utils
- org.projectlombok
- lombok
- 1.18.22
+ javax.inject
+ javax.inject
+ 1
+ compile
+
+
+ io.cucumber
+ cucumber-guice
+ 5.7.0
compile
diff --git a/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/src/main/java/com/aws/greengrass/testing/platform/Platform.java b/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/src/main/java/com/aws/greengrass/testing/platform/Platform.java
index 43416391..04e2a7fd 100644
--- a/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/src/main/java/com/aws/greengrass/testing/platform/Platform.java
+++ b/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/src/main/java/com/aws/greengrass/testing/platform/Platform.java
@@ -11,7 +11,7 @@ public interface Platform {
PlatformFiles files();
default NetworkUtils getNetworkUtils() {
- throw new UnsupportedOperationException();
+ throw new UnsupportedOperationException("Not yet implemented");
}
}
diff --git a/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/src/main/java/com/aws/greengrass/testing/platform/PlatformResolver.java b/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/src/main/java/com/aws/greengrass/testing/platform/PlatformResolver.java
index ae85193f..64b91c42 100644
--- a/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/src/main/java/com/aws/greengrass/testing/platform/PlatformResolver.java
+++ b/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/src/main/java/com/aws/greengrass/testing/platform/PlatformResolver.java
@@ -13,6 +13,7 @@
import com.aws.greengrass.testing.platform.macos.MacosPlatform;
import com.aws.greengrass.testing.platform.windows.WindowsPlatform;
import com.google.common.annotations.VisibleForTesting;
+import io.cucumber.guice.ScenarioScoped;
import java.util.Collections;
import java.util.HashMap;
@@ -20,7 +21,9 @@
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
+import javax.inject.Inject;
+@ScenarioScoped
public class PlatformResolver {
private static final Set SUPPORTED_PLATFORMS = Collections.unmodifiableSet(Stream.of(
"all", "any", "unix", "posix", "linux", "debian", "windows", "fedora", "ubuntu", "macos",
@@ -29,6 +32,7 @@ public class PlatformResolver {
private final Device device;
private final PillboxContext pillboxContext;
+ @Inject
public PlatformResolver(final Device device, final PillboxContext pillboxContext) {
this.device = device;
this.pillboxContext = pillboxContext;
diff --git a/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/src/main/java/com/aws/greengrass/testing/platform/linux/NetworkUtilsLinux.java b/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/src/main/java/com/aws/greengrass/testing/platform/linux/NetworkUtilsLinux.java
index eaa5c4a7..5e0c528e 100644
--- a/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/src/main/java/com/aws/greengrass/testing/platform/linux/NetworkUtilsLinux.java
+++ b/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/src/main/java/com/aws/greengrass/testing/platform/linux/NetworkUtilsLinux.java
@@ -6,7 +6,6 @@
package com.aws.greengrass.testing.platform.linux;
import com.aws.greengrass.testing.platform.NetworkUtils;
-import lombok.AllArgsConstructor;
import software.amazon.awssdk.utils.IoUtils;
import java.io.IOException;
@@ -20,7 +19,7 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;
-@AllArgsConstructor
+
public class NetworkUtilsLinux extends NetworkUtils {
private static final String ENABLE_OPTION = "--insert";
private static final String DISABLE_OPTION = "--delete";
From eac15c61a22f26e6bf37abbc8406e728ea252966 Mon Sep 17 00:00:00 2001
From: jaiszeen <116672962+jaiszeen@users.noreply.github.com>
Date: Fri, 9 Dec 2022 12:57:57 -0600
Subject: [PATCH 04/22] fix: connectivitystep
---
.../features/CommanConnectivitySteps.java | 19 ++++++++++---------
.../testing/platform/PlatformResolver.java | 12 +++++++++++-
2 files changed, 21 insertions(+), 10 deletions(-)
diff --git a/aws-greengrass-testing-features/aws-greengrass-testing-features-api/src/main/java/com/aws/greengrass/testing/features/CommanConnectivitySteps.java b/aws-greengrass-testing-features/aws-greengrass-testing-features-api/src/main/java/com/aws/greengrass/testing/features/CommanConnectivitySteps.java
index f9c45e82..355110b0 100644
--- a/aws-greengrass-testing-features/aws-greengrass-testing-features-api/src/main/java/com/aws/greengrass/testing/features/CommanConnectivitySteps.java
+++ b/aws-greengrass-testing-features/aws-greengrass-testing-features-api/src/main/java/com/aws/greengrass/testing/features/CommanConnectivitySteps.java
@@ -5,6 +5,9 @@
package com.aws.greengrass.testing.features;
+import com.aws.greengrass.testing.api.device.Device;
+import com.aws.greengrass.testing.api.model.PillboxContext;
+import com.aws.greengrass.testing.platform.Platform;
import com.aws.greengrass.testing.platform.PlatformResolver;
import io.cucumber.guice.ScenarioScoped;
import io.cucumber.java.en.Given;
@@ -18,33 +21,31 @@
*
* @throws IOException {throws IOException}
* @throws InterruptedException {throws IInterruptedException}
- *
*/
@ScenarioScoped
public class CommanConnectivitySteps {
- private final PlatformResolver platformResolver;
+ private final Platform platform;
@Inject
@SuppressWarnings("MissingJavadocMethod")
- public CommanConnectivitySteps(PlatformResolver platformResolver) {
- this.platformResolver = platformResolver;
+ public CommanConnectivitySteps(Platform platform) {
+ this.platform = platform;
}
/**
* Checks the connectivity for platfroms.
*
- * @throws IOException {throws IOException}
- * @throws InterruptedException {throws IInterruptedException}
* @param connectivity checks platfrom connectivity
- *
+ * @throws IOException {throws IOException}
+ * @throws InterruptedException {throws IInterruptedException}
*/
@Given("device network connectivity is {word}")
@When("I set device network connectivity to {word}")
public void setDeviceNetwork(final String connectivity) throws IOException, InterruptedException {
if ("offline".equalsIgnoreCase(connectivity)) {
- platformResolver.resolve().getNetworkUtils().disconnectNetwork();
+ platform.getNetworkUtils().disconnectNetwork();
} else {
- platformResolver.resolve().getNetworkUtils().recoverNetwork();
+ platform.getNetworkUtils().recoverNetwork();
}
}
}
diff --git a/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/src/main/java/com/aws/greengrass/testing/platform/PlatformResolver.java b/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/src/main/java/com/aws/greengrass/testing/platform/PlatformResolver.java
index 64b91c42..a1d66e25 100644
--- a/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/src/main/java/com/aws/greengrass/testing/platform/PlatformResolver.java
+++ b/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/src/main/java/com/aws/greengrass/testing/platform/PlatformResolver.java
@@ -24,7 +24,7 @@
import javax.inject.Inject;
@ScenarioScoped
-public class PlatformResolver {
+public class PlatformResolver implements Platform {
private static final Set SUPPORTED_PLATFORMS = Collections.unmodifiableSet(Stream.of(
"all", "any", "unix", "posix", "linux", "debian", "windows", "fedora", "ubuntu", "macos",
"raspbian", "qnx", "cygwin", "freebsd", "solaris", "sunos").collect(Collectors.toSet()));
@@ -107,4 +107,14 @@ Map createRanks() {
}
return ranks;
}
+
+ @Override
+ public Commands commands() {
+ return null;
+ }
+
+ @Override
+ public PlatformFiles files() {
+ return null;
+ }
}
From eccbd3a654b9d4dc1991687fc47e22b3acae9da0 Mon Sep 17 00:00:00 2001
From: jaiszeen <116672962+jaiszeen@users.noreply.github.com>
Date: Mon, 12 Dec 2022 09:05:11 -0600
Subject: [PATCH 05/22] fix: pr comments
---
.../aws-greengrass-testing-platform-api/pom.xml | 12 ------------
.../testing/platform/PlatformResolver.java | 16 +---------------
2 files changed, 1 insertion(+), 27 deletions(-)
diff --git a/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/pom.xml b/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/pom.xml
index 452fc2c4..90fb8c4d 100644
--- a/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/pom.xml
+++ b/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/pom.xml
@@ -146,18 +146,6 @@
software.amazon.awssdk
utils
-
- javax.inject
- javax.inject
- 1
- compile
-
-
- io.cucumber
- cucumber-guice
- 5.7.0
- compile
-
\ No newline at end of file
diff --git a/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/src/main/java/com/aws/greengrass/testing/platform/PlatformResolver.java b/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/src/main/java/com/aws/greengrass/testing/platform/PlatformResolver.java
index a1d66e25..ae85193f 100644
--- a/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/src/main/java/com/aws/greengrass/testing/platform/PlatformResolver.java
+++ b/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/src/main/java/com/aws/greengrass/testing/platform/PlatformResolver.java
@@ -13,7 +13,6 @@
import com.aws.greengrass.testing.platform.macos.MacosPlatform;
import com.aws.greengrass.testing.platform.windows.WindowsPlatform;
import com.google.common.annotations.VisibleForTesting;
-import io.cucumber.guice.ScenarioScoped;
import java.util.Collections;
import java.util.HashMap;
@@ -21,10 +20,8 @@
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
-import javax.inject.Inject;
-@ScenarioScoped
-public class PlatformResolver implements Platform {
+public class PlatformResolver {
private static final Set SUPPORTED_PLATFORMS = Collections.unmodifiableSet(Stream.of(
"all", "any", "unix", "posix", "linux", "debian", "windows", "fedora", "ubuntu", "macos",
"raspbian", "qnx", "cygwin", "freebsd", "solaris", "sunos").collect(Collectors.toSet()));
@@ -32,7 +29,6 @@ public class PlatformResolver implements Platform {
private final Device device;
private final PillboxContext pillboxContext;
- @Inject
public PlatformResolver(final Device device, final PillboxContext pillboxContext) {
this.device = device;
this.pillboxContext = pillboxContext;
@@ -107,14 +103,4 @@ Map createRanks() {
}
return ranks;
}
-
- @Override
- public Commands commands() {
- return null;
- }
-
- @Override
- public PlatformFiles files() {
- return null;
- }
}
From f39d33ae9f9fc951d67e1dc566af44a835e07f7e Mon Sep 17 00:00:00 2001
From: jaiszeen <116672962+jaiszeen@users.noreply.github.com>
Date: Wed, 7 Dec 2022 15:25:47 -0600
Subject: [PATCH 06/22] feat: comman-connectivity-steps
---
.../pom.xml | 12 +-
.../testing/platform/NetworkUtils.java | 26 ++++
.../greengrass/testing/platform/Platform.java | 6 +
.../testing/platform/linux/LinuxPlatform.java | 6 +
.../platform/linux/NetworkUtilsLinux.java | 138 ++++++++++++++++++
.../pom.xml | 2 +-
6 files changed, 188 insertions(+), 2 deletions(-)
create mode 100644 aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/src/main/java/com/aws/greengrass/testing/platform/NetworkUtils.java
create mode 100644 aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/src/main/java/com/aws/greengrass/testing/platform/linux/NetworkUtilsLinux.java
diff --git a/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/pom.xml b/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/pom.xml
index 88441f84..05bfafdd 100644
--- a/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/pom.xml
+++ b/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/pom.xml
@@ -99,7 +99,7 @@
com.google.guava
guava
- 31.1-jre
+ 23.0
org.immutables
@@ -142,6 +142,16 @@
2.13.0
test
+
+ software.amazon.awssdk
+ utils
+
+
+ org.projectlombok
+ lombok
+ 1.18.22
+ compile
+
\ No newline at end of file
diff --git a/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/src/main/java/com/aws/greengrass/testing/platform/NetworkUtils.java b/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/src/main/java/com/aws/greengrass/testing/platform/NetworkUtils.java
new file mode 100644
index 00000000..840e9d4b
--- /dev/null
+++ b/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/src/main/java/com/aws/greengrass/testing/platform/NetworkUtils.java
@@ -0,0 +1,26 @@
+/*
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+package com.aws.greengrass.testing.platform;
+
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.util.ArrayList;
+import java.util.List;
+
+public abstract class NetworkUtils {
+ protected static final String[] MQTT_PORTS = {"8883", "443"};
+ // 8888 and 8889 are used by the squid proxy which runs on a remote DUT
+ // and need to disable access to test offline proxy scenarios
+ protected static final String[] NETWORK_PORTS = {"443", "8888", "8889"};
+ protected static final int[] GG_UPSTREAM_PORTS = {8883, 8443, 443};
+ protected static final int SSH_PORT = 22;
+ protected final List blockedPorts = new ArrayList<>();
+
+ public abstract void disconnectNetwork() throws InterruptedException, IOException;
+
+ public abstract void recoverNetwork() throws InterruptedException, IOException;
+
+}
diff --git a/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/src/main/java/com/aws/greengrass/testing/platform/Platform.java b/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/src/main/java/com/aws/greengrass/testing/platform/Platform.java
index 7eb5a0cd..c3f4c022 100644
--- a/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/src/main/java/com/aws/greengrass/testing/platform/Platform.java
+++ b/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/src/main/java/com/aws/greengrass/testing/platform/Platform.java
@@ -9,4 +9,10 @@ public interface Platform {
Commands commands();
PlatformFiles files();
+
+ default NetworkUtils getNetworkUtils() {
+ return null;
+ }
+
}
+
diff --git a/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/src/main/java/com/aws/greengrass/testing/platform/linux/LinuxPlatform.java b/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/src/main/java/com/aws/greengrass/testing/platform/linux/LinuxPlatform.java
index 19db0728..d1772cf1 100644
--- a/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/src/main/java/com/aws/greengrass/testing/platform/linux/LinuxPlatform.java
+++ b/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/src/main/java/com/aws/greengrass/testing/platform/linux/LinuxPlatform.java
@@ -8,6 +8,7 @@
import com.aws.greengrass.testing.api.device.Device;
import com.aws.greengrass.testing.api.model.PillboxContext;
import com.aws.greengrass.testing.platform.AbstractPlatform;
+import com.aws.greengrass.testing.platform.NetworkUtils;
public class LinuxPlatform extends AbstractPlatform {
public LinuxPlatform(final Device device, final PillboxContext pillboxContext) {
@@ -18,4 +19,9 @@ public LinuxPlatform(final Device device, final PillboxContext pillboxContext) {
public LinuxCommands commands() {
return new LinuxCommands(device, pillboxContext);
}
+
+ @Override
+ public NetworkUtils getNetworkUtils() {
+ return new NetworkUtilsLinux();
+ }
}
diff --git a/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/src/main/java/com/aws/greengrass/testing/platform/linux/NetworkUtilsLinux.java b/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/src/main/java/com/aws/greengrass/testing/platform/linux/NetworkUtilsLinux.java
new file mode 100644
index 00000000..eaa5c4a7
--- /dev/null
+++ b/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/src/main/java/com/aws/greengrass/testing/platform/linux/NetworkUtilsLinux.java
@@ -0,0 +1,138 @@
+/*
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+package com.aws.greengrass.testing.platform.linux;
+
+import com.aws.greengrass.testing.platform.NetworkUtils;
+import lombok.AllArgsConstructor;
+import software.amazon.awssdk.utils.IoUtils;
+
+import java.io.IOException;
+import java.net.NetworkInterface;
+import java.nio.charset.StandardCharsets;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+@AllArgsConstructor
+public class NetworkUtilsLinux extends NetworkUtils {
+ private static final String ENABLE_OPTION = "--insert";
+ private static final String DISABLE_OPTION = "--delete";
+ private static final String APPEND_OPTION = "-A";
+ private static final String IPTABLE_COMMAND_BLOCK_INGRESS_STR =
+ "sudo iptables %s INPUT -p tcp --sport %s -j REJECT";
+ private static final String IPTABLE_COMMAND_STR = "sudo iptables %s OUTPUT -p tcp --dport %s -j REJECT && "
+ + "sudo iptables %s INPUT -p tcp --sport %s -j REJECT";
+ private static final String IPTABLES_DROP_DPORT_EXTERNAL_ONLY_COMMAND_STR =
+ "sudo iptables %s INPUT -p tcp -s localhost --dport %s -j ACCEPT && "
+ +
+ "sudo iptables %s INPUT -p tcp --dport %s -j DROP && "
+ +
+ "sudo iptables %s OUTPUT -p tcp -d localhost --dport %s -j ACCEPT && "
+ +
+ "sudo iptables %s OUTPUT -p tcp --dport %s -j DROP";
+ private static final String IPTABLE_SAFELIST_COMMAND_STR
+ = "sudo iptables %s OUTPUT -p tcp -d %s --dport %d -j ACCEPT && "
+ +
+ "sudo iptables %s INPUT -p tcp -s %s --sport %d -j ACCEPT";
+ private static final String GET_IPTABLES_RULES = "sudo iptables -S";
+
+ // The string we are looking for to verify that there is an iptables rule to reject a port
+ // We only need to look for sport because sport only gets created if dport is successful
+ private static final String IPTABLES_RULE = "-m tcp --sport %s -j REJECT";
+
+ private static final AtomicBoolean bandwidthSetup = new AtomicBoolean(false);
+
+
+ private void modifyMqttConnection(String action) throws IOException, InterruptedException {
+ for (String port : MQTT_PORTS) {
+ new ProcessBuilder().command(
+ "sh", "-c", String.format(IPTABLES_DROP_DPORT_EXTERNAL_ONLY_COMMAND_STR,
+ action, port, action, port, action, port, action, port)
+ ).start().waitFor(2, TimeUnit.SECONDS);
+ }
+ }
+
+
+ private void filterPortOnInterface(String iface, int port) throws IOException, InterruptedException {
+ // Filtering SSH traffic impacts test execution, so we explicitly disallow it
+ if (port == SSH_PORT) {
+ return;
+ }
+ List filterSourcePortCommand = Stream.of("sudo", "tc", "filter", "add", "dev",
+ iface, "parent", "1:", "protocol", "ip", "prio", "1", "u32", "match",
+ "ip", "sport", Integer.toString(port), "0xffff", "flowid", "1:2").collect(Collectors.toList());
+ executeCommand(filterSourcePortCommand);
+
+ List filterDestPortCommand = Stream.of("sudo", "tc", "filter", "add", "dev", iface,
+ "parent", "1:", "protocol", "ip", "prio", "1", "u32", "match",
+ "ip", "dport", Integer.toString(port), "0xffff", "flowid", "1:2").collect(Collectors.toList());
+ executeCommand(filterDestPortCommand);
+ }
+
+ private void deleteRootNetemQdiscOnInterface() throws InterruptedException, IOException {
+ Enumeration nets = NetworkInterface.getNetworkInterfaces();
+ for (NetworkInterface netint : Collections.list(nets)) {
+ if (netint.isPointToPoint() || netint.isLoopback()) {
+ continue;
+ }
+ executeCommand(Stream.of("sudo", "tc", "qdisc", "del", "dev", netint.getName(), "root")
+ .collect(Collectors.toList()));
+ }
+ }
+
+ private void createRootNetemQdiscOnInterface(String iface, int netemRateKbps)
+ throws InterruptedException, IOException {
+ // TODO: Add support for setting packet loss and delay
+ int netemDelayMs = 750;
+ List addQdiscCommand = Stream.of("sudo", "tc", "qdisc", "add", "dev", iface, "root", "handle",
+ "1:", "prio", "bands", "2", "priomap", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0",
+ "0", "0", "0", "0", "0").collect(Collectors.toList());
+ executeCommand(addQdiscCommand);
+
+ List netemCommand =
+ Stream.of("sudo", "tc", "qdisc", "add", "dev", iface, "parent", "1:2", "netem", "delay",
+ String.format("%dms", netemDelayMs), "rate", String.format("%dkbit", netemRateKbps))
+ .collect(Collectors.toList());
+ executeCommand(netemCommand);
+ }
+
+ private String executeCommand(List command) throws IOException, InterruptedException {
+ Process proc = new ProcessBuilder().command(command).start();
+ proc.waitFor(2, TimeUnit.SECONDS);
+ if (proc.exitValue() != 0) {
+ throw new IOException("CLI command " + command + " failed with error "
+ + new String(IoUtils.toByteArray(proc.getErrorStream()), StandardCharsets.UTF_8));
+ }
+ return new String(IoUtils.toByteArray(proc.getInputStream()), StandardCharsets.UTF_8);
+ }
+
+ @Override
+ public void disconnectNetwork() throws InterruptedException, IOException {
+ interfacepolicy(IPTABLE_COMMAND_STR, ENABLE_OPTION, "connection-loss", NETWORK_PORTS);
+ }
+
+ @Override
+ public void recoverNetwork() throws InterruptedException, IOException {
+ interfacepolicy(IPTABLE_COMMAND_STR, DISABLE_OPTION, "connection-recover", NETWORK_PORTS);
+ if (bandwidthSetup.get()) {
+ deleteRootNetemQdiscOnInterface();
+ bandwidthSetup.set(false);
+ }
+ }
+
+ private void interfacepolicy(String iptableCommandString, String option, String eventName, String... ports)
+ throws InterruptedException,
+ IOException {
+ for (String port : ports) {
+ new ProcessBuilder().command("sh", "-c", String.format(iptableCommandString, option, port, option, port))
+ .start().waitFor(2, TimeUnit.SECONDS);
+ }
+ }
+}
diff --git a/aws-greengrass-testing-platform/aws-greengrass-testing-platform-pillbox/pom.xml b/aws-greengrass-testing-platform/aws-greengrass-testing-platform-pillbox/pom.xml
index 62c30d7c..d65a46fd 100644
--- a/aws-greengrass-testing-platform/aws-greengrass-testing-platform-pillbox/pom.xml
+++ b/aws-greengrass-testing-platform/aws-greengrass-testing-platform-pillbox/pom.xml
@@ -124,7 +124,7 @@
com.google.guava
guava
- 31.1-jre
+ 23.0
org.immutables
From 434e0775be871563c939f23fa7c984eaf91024b8 Mon Sep 17 00:00:00 2001
From: jaiszeen <116672962+jaiszeen@users.noreply.github.com>
Date: Thu, 8 Dec 2022 09:28:14 -0600
Subject: [PATCH 07/22] fix: pr comment
---
.../main/java/com/aws/greengrass/testing/platform/Platform.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/src/main/java/com/aws/greengrass/testing/platform/Platform.java b/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/src/main/java/com/aws/greengrass/testing/platform/Platform.java
index c3f4c022..43416391 100644
--- a/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/src/main/java/com/aws/greengrass/testing/platform/Platform.java
+++ b/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/src/main/java/com/aws/greengrass/testing/platform/Platform.java
@@ -11,7 +11,7 @@ public interface Platform {
PlatformFiles files();
default NetworkUtils getNetworkUtils() {
- return null;
+ throw new UnsupportedOperationException();
}
}
From 011b09a9ada03758a9d94a9701d5aa0c2b5ccf7d Mon Sep 17 00:00:00 2001
From: jaiszeen <116672962+jaiszeen@users.noreply.github.com>
Date: Thu, 8 Dec 2022 15:40:36 -0600
Subject: [PATCH 08/22] feat: connectivitystep
---
.../features/CommanConnectivitySteps.java | 51 +++++++++++++++++++
.../pom.xml | 14 +++--
.../greengrass/testing/platform/Platform.java | 2 +-
.../testing/platform/PlatformResolver.java | 4 ++
.../platform/linux/NetworkUtilsLinux.java | 3 +-
5 files changed, 67 insertions(+), 7 deletions(-)
create mode 100644 aws-greengrass-testing-features/aws-greengrass-testing-features-api/src/main/java/com/aws/greengrass/testing/features/CommanConnectivitySteps.java
diff --git a/aws-greengrass-testing-features/aws-greengrass-testing-features-api/src/main/java/com/aws/greengrass/testing/features/CommanConnectivitySteps.java b/aws-greengrass-testing-features/aws-greengrass-testing-features-api/src/main/java/com/aws/greengrass/testing/features/CommanConnectivitySteps.java
new file mode 100644
index 00000000..f9c45e82
--- /dev/null
+++ b/aws-greengrass-testing-features/aws-greengrass-testing-features-api/src/main/java/com/aws/greengrass/testing/features/CommanConnectivitySteps.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+package com.aws.greengrass.testing.features;
+
+import com.aws.greengrass.testing.platform.PlatformResolver;
+import io.cucumber.guice.ScenarioScoped;
+import io.cucumber.java.en.Given;
+import io.cucumber.java.en.When;
+
+import java.io.IOException;
+import javax.inject.Inject;
+
+/**
+ * Checks the connectivity for platfroms.
+ *
+ * @throws IOException {throws IOException}
+ * @throws InterruptedException {throws IInterruptedException}
+ *
+ */
+@ScenarioScoped
+public class CommanConnectivitySteps {
+ private final PlatformResolver platformResolver;
+
+ @Inject
+ @SuppressWarnings("MissingJavadocMethod")
+ public CommanConnectivitySteps(PlatformResolver platformResolver) {
+ this.platformResolver = platformResolver;
+ }
+
+ /**
+ * Checks the connectivity for platfroms.
+ *
+ * @throws IOException {throws IOException}
+ * @throws InterruptedException {throws IInterruptedException}
+ * @param connectivity checks platfrom connectivity
+ *
+ */
+ @Given("device network connectivity is {word}")
+ @When("I set device network connectivity to {word}")
+ public void setDeviceNetwork(final String connectivity) throws IOException, InterruptedException {
+ if ("offline".equalsIgnoreCase(connectivity)) {
+ platformResolver.resolve().getNetworkUtils().disconnectNetwork();
+ } else {
+ platformResolver.resolve().getNetworkUtils().recoverNetwork();
+ }
+ }
+}
+
diff --git a/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/pom.xml b/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/pom.xml
index 05bfafdd..452fc2c4 100644
--- a/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/pom.xml
+++ b/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/pom.xml
@@ -99,7 +99,7 @@
com.google.guava
guava
- 23.0
+ 31.1-jre
org.immutables
@@ -147,9 +147,15 @@
utils
- org.projectlombok
- lombok
- 1.18.22
+ javax.inject
+ javax.inject
+ 1
+ compile
+
+
+ io.cucumber
+ cucumber-guice
+ 5.7.0
compile
diff --git a/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/src/main/java/com/aws/greengrass/testing/platform/Platform.java b/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/src/main/java/com/aws/greengrass/testing/platform/Platform.java
index 43416391..04e2a7fd 100644
--- a/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/src/main/java/com/aws/greengrass/testing/platform/Platform.java
+++ b/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/src/main/java/com/aws/greengrass/testing/platform/Platform.java
@@ -11,7 +11,7 @@ public interface Platform {
PlatformFiles files();
default NetworkUtils getNetworkUtils() {
- throw new UnsupportedOperationException();
+ throw new UnsupportedOperationException("Not yet implemented");
}
}
diff --git a/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/src/main/java/com/aws/greengrass/testing/platform/PlatformResolver.java b/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/src/main/java/com/aws/greengrass/testing/platform/PlatformResolver.java
index ae85193f..64b91c42 100644
--- a/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/src/main/java/com/aws/greengrass/testing/platform/PlatformResolver.java
+++ b/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/src/main/java/com/aws/greengrass/testing/platform/PlatformResolver.java
@@ -13,6 +13,7 @@
import com.aws.greengrass.testing.platform.macos.MacosPlatform;
import com.aws.greengrass.testing.platform.windows.WindowsPlatform;
import com.google.common.annotations.VisibleForTesting;
+import io.cucumber.guice.ScenarioScoped;
import java.util.Collections;
import java.util.HashMap;
@@ -20,7 +21,9 @@
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
+import javax.inject.Inject;
+@ScenarioScoped
public class PlatformResolver {
private static final Set SUPPORTED_PLATFORMS = Collections.unmodifiableSet(Stream.of(
"all", "any", "unix", "posix", "linux", "debian", "windows", "fedora", "ubuntu", "macos",
@@ -29,6 +32,7 @@ public class PlatformResolver {
private final Device device;
private final PillboxContext pillboxContext;
+ @Inject
public PlatformResolver(final Device device, final PillboxContext pillboxContext) {
this.device = device;
this.pillboxContext = pillboxContext;
diff --git a/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/src/main/java/com/aws/greengrass/testing/platform/linux/NetworkUtilsLinux.java b/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/src/main/java/com/aws/greengrass/testing/platform/linux/NetworkUtilsLinux.java
index eaa5c4a7..5e0c528e 100644
--- a/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/src/main/java/com/aws/greengrass/testing/platform/linux/NetworkUtilsLinux.java
+++ b/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/src/main/java/com/aws/greengrass/testing/platform/linux/NetworkUtilsLinux.java
@@ -6,7 +6,6 @@
package com.aws.greengrass.testing.platform.linux;
import com.aws.greengrass.testing.platform.NetworkUtils;
-import lombok.AllArgsConstructor;
import software.amazon.awssdk.utils.IoUtils;
import java.io.IOException;
@@ -20,7 +19,7 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;
-@AllArgsConstructor
+
public class NetworkUtilsLinux extends NetworkUtils {
private static final String ENABLE_OPTION = "--insert";
private static final String DISABLE_OPTION = "--delete";
From f88cece7cef095ed058c154477df2d36b7e02865 Mon Sep 17 00:00:00 2001
From: jaiszeen <116672962+jaiszeen@users.noreply.github.com>
Date: Fri, 9 Dec 2022 12:57:57 -0600
Subject: [PATCH 09/22] fix: connectivitystep
---
.../features/CommanConnectivitySteps.java | 19 ++++++++++---------
.../testing/platform/PlatformResolver.java | 12 +++++++++++-
2 files changed, 21 insertions(+), 10 deletions(-)
diff --git a/aws-greengrass-testing-features/aws-greengrass-testing-features-api/src/main/java/com/aws/greengrass/testing/features/CommanConnectivitySteps.java b/aws-greengrass-testing-features/aws-greengrass-testing-features-api/src/main/java/com/aws/greengrass/testing/features/CommanConnectivitySteps.java
index f9c45e82..355110b0 100644
--- a/aws-greengrass-testing-features/aws-greengrass-testing-features-api/src/main/java/com/aws/greengrass/testing/features/CommanConnectivitySteps.java
+++ b/aws-greengrass-testing-features/aws-greengrass-testing-features-api/src/main/java/com/aws/greengrass/testing/features/CommanConnectivitySteps.java
@@ -5,6 +5,9 @@
package com.aws.greengrass.testing.features;
+import com.aws.greengrass.testing.api.device.Device;
+import com.aws.greengrass.testing.api.model.PillboxContext;
+import com.aws.greengrass.testing.platform.Platform;
import com.aws.greengrass.testing.platform.PlatformResolver;
import io.cucumber.guice.ScenarioScoped;
import io.cucumber.java.en.Given;
@@ -18,33 +21,31 @@
*
* @throws IOException {throws IOException}
* @throws InterruptedException {throws IInterruptedException}
- *
*/
@ScenarioScoped
public class CommanConnectivitySteps {
- private final PlatformResolver platformResolver;
+ private final Platform platform;
@Inject
@SuppressWarnings("MissingJavadocMethod")
- public CommanConnectivitySteps(PlatformResolver platformResolver) {
- this.platformResolver = platformResolver;
+ public CommanConnectivitySteps(Platform platform) {
+ this.platform = platform;
}
/**
* Checks the connectivity for platfroms.
*
- * @throws IOException {throws IOException}
- * @throws InterruptedException {throws IInterruptedException}
* @param connectivity checks platfrom connectivity
- *
+ * @throws IOException {throws IOException}
+ * @throws InterruptedException {throws IInterruptedException}
*/
@Given("device network connectivity is {word}")
@When("I set device network connectivity to {word}")
public void setDeviceNetwork(final String connectivity) throws IOException, InterruptedException {
if ("offline".equalsIgnoreCase(connectivity)) {
- platformResolver.resolve().getNetworkUtils().disconnectNetwork();
+ platform.getNetworkUtils().disconnectNetwork();
} else {
- platformResolver.resolve().getNetworkUtils().recoverNetwork();
+ platform.getNetworkUtils().recoverNetwork();
}
}
}
diff --git a/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/src/main/java/com/aws/greengrass/testing/platform/PlatformResolver.java b/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/src/main/java/com/aws/greengrass/testing/platform/PlatformResolver.java
index 64b91c42..a1d66e25 100644
--- a/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/src/main/java/com/aws/greengrass/testing/platform/PlatformResolver.java
+++ b/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/src/main/java/com/aws/greengrass/testing/platform/PlatformResolver.java
@@ -24,7 +24,7 @@
import javax.inject.Inject;
@ScenarioScoped
-public class PlatformResolver {
+public class PlatformResolver implements Platform {
private static final Set SUPPORTED_PLATFORMS = Collections.unmodifiableSet(Stream.of(
"all", "any", "unix", "posix", "linux", "debian", "windows", "fedora", "ubuntu", "macos",
"raspbian", "qnx", "cygwin", "freebsd", "solaris", "sunos").collect(Collectors.toSet()));
@@ -107,4 +107,14 @@ Map createRanks() {
}
return ranks;
}
+
+ @Override
+ public Commands commands() {
+ return null;
+ }
+
+ @Override
+ public PlatformFiles files() {
+ return null;
+ }
}
From 7ccc866aafc3c42e5f54065ac0e4a76c1769d251 Mon Sep 17 00:00:00 2001
From: jaiszeen <116672962+jaiszeen@users.noreply.github.com>
Date: Mon, 12 Dec 2022 09:05:11 -0600
Subject: [PATCH 10/22] fix: pr comments
---
.../aws-greengrass-testing-platform-api/pom.xml | 12 ------------
.../testing/platform/PlatformResolver.java | 16 +---------------
2 files changed, 1 insertion(+), 27 deletions(-)
diff --git a/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/pom.xml b/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/pom.xml
index 452fc2c4..90fb8c4d 100644
--- a/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/pom.xml
+++ b/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/pom.xml
@@ -146,18 +146,6 @@
software.amazon.awssdk
utils
-
- javax.inject
- javax.inject
- 1
- compile
-
-
- io.cucumber
- cucumber-guice
- 5.7.0
- compile
-
\ No newline at end of file
diff --git a/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/src/main/java/com/aws/greengrass/testing/platform/PlatformResolver.java b/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/src/main/java/com/aws/greengrass/testing/platform/PlatformResolver.java
index a1d66e25..ae85193f 100644
--- a/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/src/main/java/com/aws/greengrass/testing/platform/PlatformResolver.java
+++ b/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/src/main/java/com/aws/greengrass/testing/platform/PlatformResolver.java
@@ -13,7 +13,6 @@
import com.aws.greengrass.testing.platform.macos.MacosPlatform;
import com.aws.greengrass.testing.platform.windows.WindowsPlatform;
import com.google.common.annotations.VisibleForTesting;
-import io.cucumber.guice.ScenarioScoped;
import java.util.Collections;
import java.util.HashMap;
@@ -21,10 +20,8 @@
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
-import javax.inject.Inject;
-@ScenarioScoped
-public class PlatformResolver implements Platform {
+public class PlatformResolver {
private static final Set SUPPORTED_PLATFORMS = Collections.unmodifiableSet(Stream.of(
"all", "any", "unix", "posix", "linux", "debian", "windows", "fedora", "ubuntu", "macos",
"raspbian", "qnx", "cygwin", "freebsd", "solaris", "sunos").collect(Collectors.toSet()));
@@ -32,7 +29,6 @@ public class PlatformResolver implements Platform {
private final Device device;
private final PillboxContext pillboxContext;
- @Inject
public PlatformResolver(final Device device, final PillboxContext pillboxContext) {
this.device = device;
this.pillboxContext = pillboxContext;
@@ -107,14 +103,4 @@ Map createRanks() {
}
return ranks;
}
-
- @Override
- public Commands commands() {
- return null;
- }
-
- @Override
- public PlatformFiles files() {
- return null;
- }
}
From b539e9e18e7177b7a07f1a3646963018807fe931 Mon Sep 17 00:00:00 2001
From: jaiszeen <116672962+jaiszeen@users.noreply.github.com>
Date: Tue, 13 Dec 2022 08:59:17 -0600
Subject: [PATCH 11/22] fix: comments
---
.../aws-greengrass-testing-features-api/pom.xml | 5 -----
...vitySteps.java => CommonConnectivitySteps.java} | 14 +++++++++-----
2 files changed, 9 insertions(+), 10 deletions(-)
rename aws-greengrass-testing-features/aws-greengrass-testing-features-api/src/main/java/com/aws/greengrass/testing/features/{CommanConnectivitySteps.java => CommonConnectivitySteps.java} (83%)
diff --git a/aws-greengrass-testing-features/aws-greengrass-testing-features-api/pom.xml b/aws-greengrass-testing-features/aws-greengrass-testing-features-api/pom.xml
index 7aefcbdb..e47ad1fe 100644
--- a/aws-greengrass-testing-features/aws-greengrass-testing-features-api/pom.xml
+++ b/aws-greengrass-testing-features/aws-greengrass-testing-features-api/pom.xml
@@ -194,11 +194,6 @@
${auto.service.version}
provided
-
- com.google.inject
- guice
- ${guice.version}
-
org.immutables
value
diff --git a/aws-greengrass-testing-features/aws-greengrass-testing-features-api/src/main/java/com/aws/greengrass/testing/features/CommanConnectivitySteps.java b/aws-greengrass-testing-features/aws-greengrass-testing-features-api/src/main/java/com/aws/greengrass/testing/features/CommonConnectivitySteps.java
similarity index 83%
rename from aws-greengrass-testing-features/aws-greengrass-testing-features-api/src/main/java/com/aws/greengrass/testing/features/CommanConnectivitySteps.java
rename to aws-greengrass-testing-features/aws-greengrass-testing-features-api/src/main/java/com/aws/greengrass/testing/features/CommonConnectivitySteps.java
index 355110b0..7af75d2c 100644
--- a/aws-greengrass-testing-features/aws-greengrass-testing-features-api/src/main/java/com/aws/greengrass/testing/features/CommanConnectivitySteps.java
+++ b/aws-greengrass-testing-features/aws-greengrass-testing-features-api/src/main/java/com/aws/greengrass/testing/features/CommonConnectivitySteps.java
@@ -5,11 +5,9 @@
package com.aws.greengrass.testing.features;
-import com.aws.greengrass.testing.api.device.Device;
-import com.aws.greengrass.testing.api.model.PillboxContext;
import com.aws.greengrass.testing.platform.Platform;
-import com.aws.greengrass.testing.platform.PlatformResolver;
import io.cucumber.guice.ScenarioScoped;
+import io.cucumber.java.After;
import io.cucumber.java.en.Given;
import io.cucumber.java.en.When;
@@ -23,12 +21,12 @@
* @throws InterruptedException {throws IInterruptedException}
*/
@ScenarioScoped
-public class CommanConnectivitySteps {
+public class CommonConnectivitySteps {
private final Platform platform;
@Inject
@SuppressWarnings("MissingJavadocMethod")
- public CommanConnectivitySteps(Platform platform) {
+ public CommonConnectivitySteps(Platform platform) {
this.platform = platform;
}
@@ -48,5 +46,11 @@ public void setDeviceNetwork(final String connectivity) throws IOException, Inte
platform.getNetworkUtils().recoverNetwork();
}
}
+
+ @After
+ public void afterEachScenario()throws IOException, InterruptedException {
+ platform.getNetworkUtils().recoverNetwork();
+ }
+
}
From 12ea59f3d5f67464ce90ea5120d34d5329e97fc2 Mon Sep 17 00:00:00 2001
From: jaiszeen <116672962+jaiszeen@users.noreply.github.com>
Date: Tue, 13 Dec 2022 09:40:24 -0600
Subject: [PATCH 12/22] fix: pr comments
---
.../features/CommanConnectivitySteps.java | 52 -------------------
.../features/CommonConnectivitySteps.java | 19 ++++---
.../testing/features/DeploymentSteps.java | 1 +
.../testing/platform/linux/LinuxPlatform.java | 5 +-
.../pom.xml | 2 +-
5 files changed, 17 insertions(+), 62 deletions(-)
delete mode 100644 aws-greengrass-testing-features/aws-greengrass-testing-features-api/src/main/java/com/aws/greengrass/testing/features/CommanConnectivitySteps.java
diff --git a/aws-greengrass-testing-features/aws-greengrass-testing-features-api/src/main/java/com/aws/greengrass/testing/features/CommanConnectivitySteps.java b/aws-greengrass-testing-features/aws-greengrass-testing-features-api/src/main/java/com/aws/greengrass/testing/features/CommanConnectivitySteps.java
deleted file mode 100644
index 355110b0..00000000
--- a/aws-greengrass-testing-features/aws-greengrass-testing-features-api/src/main/java/com/aws/greengrass/testing/features/CommanConnectivitySteps.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
- * SPDX-License-Identifier: Apache-2.0
- */
-
-package com.aws.greengrass.testing.features;
-
-import com.aws.greengrass.testing.api.device.Device;
-import com.aws.greengrass.testing.api.model.PillboxContext;
-import com.aws.greengrass.testing.platform.Platform;
-import com.aws.greengrass.testing.platform.PlatformResolver;
-import io.cucumber.guice.ScenarioScoped;
-import io.cucumber.java.en.Given;
-import io.cucumber.java.en.When;
-
-import java.io.IOException;
-import javax.inject.Inject;
-
-/**
- * Checks the connectivity for platfroms.
- *
- * @throws IOException {throws IOException}
- * @throws InterruptedException {throws IInterruptedException}
- */
-@ScenarioScoped
-public class CommanConnectivitySteps {
- private final Platform platform;
-
- @Inject
- @SuppressWarnings("MissingJavadocMethod")
- public CommanConnectivitySteps(Platform platform) {
- this.platform = platform;
- }
-
- /**
- * Checks the connectivity for platfroms.
- *
- * @param connectivity checks platfrom connectivity
- * @throws IOException {throws IOException}
- * @throws InterruptedException {throws IInterruptedException}
- */
- @Given("device network connectivity is {word}")
- @When("I set device network connectivity to {word}")
- public void setDeviceNetwork(final String connectivity) throws IOException, InterruptedException {
- if ("offline".equalsIgnoreCase(connectivity)) {
- platform.getNetworkUtils().disconnectNetwork();
- } else {
- platform.getNetworkUtils().recoverNetwork();
- }
- }
-}
-
diff --git a/aws-greengrass-testing-features/aws-greengrass-testing-features-api/src/main/java/com/aws/greengrass/testing/features/CommonConnectivitySteps.java b/aws-greengrass-testing-features/aws-greengrass-testing-features-api/src/main/java/com/aws/greengrass/testing/features/CommonConnectivitySteps.java
index 7af75d2c..4e8ad1dc 100644
--- a/aws-greengrass-testing-features/aws-greengrass-testing-features-api/src/main/java/com/aws/greengrass/testing/features/CommonConnectivitySteps.java
+++ b/aws-greengrass-testing-features/aws-greengrass-testing-features-api/src/main/java/com/aws/greengrass/testing/features/CommonConnectivitySteps.java
@@ -23,6 +23,7 @@
@ScenarioScoped
public class CommonConnectivitySteps {
private final Platform platform;
+ private boolean offline;
@Inject
@SuppressWarnings("MissingJavadocMethod")
@@ -31,26 +32,28 @@ public CommonConnectivitySteps(Platform platform) {
}
/**
- * Checks the connectivity for platfroms.
+ * Checks the connectivity for platforms.
*
- * @param connectivity checks platfrom connectivity
+ * @param connectivity checks platform connectivity
* @throws IOException {throws IOException}
* @throws InterruptedException {throws IInterruptedException}
*/
- @Given("device network connectivity is {word}")
- @When("I set device network connectivity to {word}")
+
+ @When("device network connectivity is {word}")
public void setDeviceNetwork(final String connectivity) throws IOException, InterruptedException {
if ("offline".equalsIgnoreCase(connectivity)) {
platform.getNetworkUtils().disconnectNetwork();
+ offline=true;
} else {
platform.getNetworkUtils().recoverNetwork();
}
}
-
@After
- public void afterEachScenario()throws IOException, InterruptedException {
- platform.getNetworkUtils().recoverNetwork();
+ public void teardown() throws IOException, InterruptedException {
+ if (offline) {
+ platform.getNetworkUtils().recoverNetwork();
+ offline=false;
+ }
}
-
}
diff --git a/aws-greengrass-testing-features/aws-greengrass-testing-features-api/src/main/java/com/aws/greengrass/testing/features/DeploymentSteps.java b/aws-greengrass-testing-features/aws-greengrass-testing-features-api/src/main/java/com/aws/greengrass/testing/features/DeploymentSteps.java
index fbf47d4b..546e1165 100644
--- a/aws-greengrass-testing-features/aws-greengrass-testing-features-api/src/main/java/com/aws/greengrass/testing/features/DeploymentSteps.java
+++ b/aws-greengrass-testing-features/aws-greengrass-testing-features-api/src/main/java/com/aws/greengrass/testing/features/DeploymentSteps.java
@@ -397,4 +397,5 @@ void checkADeploymentReachesCompleted(GreengrassV2Lifecycle ggv2, String deploym
Thread.currentThread().interrupt();
}
}
+
}
diff --git a/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/src/main/java/com/aws/greengrass/testing/platform/linux/LinuxPlatform.java b/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/src/main/java/com/aws/greengrass/testing/platform/linux/LinuxPlatform.java
index d1772cf1..cd03f900 100644
--- a/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/src/main/java/com/aws/greengrass/testing/platform/linux/LinuxPlatform.java
+++ b/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/src/main/java/com/aws/greengrass/testing/platform/linux/LinuxPlatform.java
@@ -11,8 +11,11 @@
import com.aws.greengrass.testing.platform.NetworkUtils;
public class LinuxPlatform extends AbstractPlatform {
+
+ NetworkUtilsLinux networkUtilsLinux= null;
public LinuxPlatform(final Device device, final PillboxContext pillboxContext) {
super(device, pillboxContext);
+ networkUtilsLinux = new NetworkUtilsLinux();
}
@Override
@@ -22,6 +25,6 @@ public LinuxCommands commands() {
@Override
public NetworkUtils getNetworkUtils() {
- return new NetworkUtilsLinux();
+ return this.networkUtilsLinux;
}
}
diff --git a/aws-greengrass-testing-platform/aws-greengrass-testing-platform-pillbox/pom.xml b/aws-greengrass-testing-platform/aws-greengrass-testing-platform-pillbox/pom.xml
index d65a46fd..62c30d7c 100644
--- a/aws-greengrass-testing-platform/aws-greengrass-testing-platform-pillbox/pom.xml
+++ b/aws-greengrass-testing-platform/aws-greengrass-testing-platform-pillbox/pom.xml
@@ -124,7 +124,7 @@
com.google.guava
guava
- 23.0
+ 31.1-jre
org.immutables
From 47ddba615f3e0f061574e0d452c5baef7d99780e Mon Sep 17 00:00:00 2001
From: jaiszeen <116672962+jaiszeen@users.noreply.github.com>
Date: Tue, 13 Dec 2022 11:09:49 -0600
Subject: [PATCH 13/22] fix: comments
---
.../features/CommonConnectivitySteps.java | 59 ----------------
.../testing/features/ConnectivitySteps.java | 69 +++++++++++++++++++
.../testing/platform/linux/LinuxPlatform.java | 3 +-
.../pom.xml | 2 +-
4 files changed, 72 insertions(+), 61 deletions(-)
delete mode 100644 aws-greengrass-testing-features/aws-greengrass-testing-features-api/src/main/java/com/aws/greengrass/testing/features/CommonConnectivitySteps.java
create mode 100644 aws-greengrass-testing-features/aws-greengrass-testing-features-api/src/main/java/com/aws/greengrass/testing/features/ConnectivitySteps.java
diff --git a/aws-greengrass-testing-features/aws-greengrass-testing-features-api/src/main/java/com/aws/greengrass/testing/features/CommonConnectivitySteps.java b/aws-greengrass-testing-features/aws-greengrass-testing-features-api/src/main/java/com/aws/greengrass/testing/features/CommonConnectivitySteps.java
deleted file mode 100644
index 4e8ad1dc..00000000
--- a/aws-greengrass-testing-features/aws-greengrass-testing-features-api/src/main/java/com/aws/greengrass/testing/features/CommonConnectivitySteps.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
- * SPDX-License-Identifier: Apache-2.0
- */
-
-package com.aws.greengrass.testing.features;
-
-import com.aws.greengrass.testing.platform.Platform;
-import io.cucumber.guice.ScenarioScoped;
-import io.cucumber.java.After;
-import io.cucumber.java.en.Given;
-import io.cucumber.java.en.When;
-
-import java.io.IOException;
-import javax.inject.Inject;
-
-/**
- * Checks the connectivity for platfroms.
- *
- * @throws IOException {throws IOException}
- * @throws InterruptedException {throws IInterruptedException}
- */
-@ScenarioScoped
-public class CommonConnectivitySteps {
- private final Platform platform;
- private boolean offline;
-
- @Inject
- @SuppressWarnings("MissingJavadocMethod")
- public CommonConnectivitySteps(Platform platform) {
- this.platform = platform;
- }
-
- /**
- * Checks the connectivity for platforms.
- *
- * @param connectivity checks platform connectivity
- * @throws IOException {throws IOException}
- * @throws InterruptedException {throws IInterruptedException}
- */
-
- @When("device network connectivity is {word}")
- public void setDeviceNetwork(final String connectivity) throws IOException, InterruptedException {
- if ("offline".equalsIgnoreCase(connectivity)) {
- platform.getNetworkUtils().disconnectNetwork();
- offline=true;
- } else {
- platform.getNetworkUtils().recoverNetwork();
- }
- }
- @After
- public void teardown() throws IOException, InterruptedException {
- if (offline) {
- platform.getNetworkUtils().recoverNetwork();
- offline=false;
- }
- }
-}
-
diff --git a/aws-greengrass-testing-features/aws-greengrass-testing-features-api/src/main/java/com/aws/greengrass/testing/features/ConnectivitySteps.java b/aws-greengrass-testing-features/aws-greengrass-testing-features-api/src/main/java/com/aws/greengrass/testing/features/ConnectivitySteps.java
new file mode 100644
index 00000000..188c4ce0
--- /dev/null
+++ b/aws-greengrass-testing-features/aws-greengrass-testing-features-api/src/main/java/com/aws/greengrass/testing/features/ConnectivitySteps.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+package com.aws.greengrass.testing.features;
+
+import com.aws.greengrass.testing.platform.Platform;
+import io.cucumber.guice.ScenarioScoped;
+import io.cucumber.java.After;
+import io.cucumber.java.en.When;
+
+import java.io.IOException;
+import javax.inject.Inject;
+
+/**
+ * Blocks the traffic port (IP ports) on ports 443,8888,8889 and back online it.
+ * Re-enables them to simulate Network Connectivity.
+ */
+@ScenarioScoped
+public class ConnectivitySteps {
+ private final Platform platform;
+ private boolean offline = false;
+
+ @Inject
+ @SuppressWarnings("MissingJavadocMethod")
+ public ConnectivitySteps(Platform platform) {
+ this.platform = platform;
+ }
+
+ /**
+ * Blocks the traffic port (IP ports) on ports 443,8888,8889 and back online it.
+ * Re-enables them to simulate Network Connectivity.
+ *
+ * @param connectivity checks platform connectivity
+ * @throws IOException {throws IOException}
+ * @throws InterruptedException {throws IInterruptedException}
+ * @throws UnsupportedOperationException {throws UnsupportedOperationException}
+ */
+ @When("the device network connectivity is {word}")
+ public void setDeviceNetwork(final String connectivity) throws IOException, InterruptedException {
+ switch (connectivity) {
+ case "offline":
+ platform.getNetworkUtils().disconnectNetwork();
+ break;
+ case "online":
+ platform.getNetworkUtils().recoverNetwork();
+ break;
+ default:
+ throw new UnsupportedOperationException("Connectivity " + connectivity + " is not supported ");
+ }
+
+ offline = connectivity.equalsIgnoreCase("offline");
+ }
+
+ /**
+ * After Each scenario if there is any failure it will make the device go online.
+ * Re-enables them to simulate Network Connectivity.
+ * @throws IOException {IOException}
+ * @throws InterruptedException {InterruptedException}
+ */
+ @After
+ public void teardown() throws IOException, InterruptedException {
+ if (offline) {
+ platform.getNetworkUtils().recoverNetwork();
+ }
+ }
+}
+
diff --git a/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/src/main/java/com/aws/greengrass/testing/platform/linux/LinuxPlatform.java b/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/src/main/java/com/aws/greengrass/testing/platform/linux/LinuxPlatform.java
index cd03f900..1cf4ddb9 100644
--- a/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/src/main/java/com/aws/greengrass/testing/platform/linux/LinuxPlatform.java
+++ b/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/src/main/java/com/aws/greengrass/testing/platform/linux/LinuxPlatform.java
@@ -12,7 +12,8 @@
public class LinuxPlatform extends AbstractPlatform {
- NetworkUtilsLinux networkUtilsLinux= null;
+ private final NetworkUtilsLinux networkUtilsLinux;
+
public LinuxPlatform(final Device device, final PillboxContext pillboxContext) {
super(device, pillboxContext);
networkUtilsLinux = new NetworkUtilsLinux();
diff --git a/aws-greengrass-testing-platform/aws-greengrass-testing-platform-pillbox/pom.xml b/aws-greengrass-testing-platform/aws-greengrass-testing-platform-pillbox/pom.xml
index 62c30d7c..d65a46fd 100644
--- a/aws-greengrass-testing-platform/aws-greengrass-testing-platform-pillbox/pom.xml
+++ b/aws-greengrass-testing-platform/aws-greengrass-testing-platform-pillbox/pom.xml
@@ -124,7 +124,7 @@
com.google.guava
guava
- 31.1-jre
+ 23.0
org.immutables
From 43a1dfcfb3dab5997504de85a04f78b1db1d51fb Mon Sep 17 00:00:00 2001
From: jaiszeen <116672962+jaiszeen@users.noreply.github.com>
Date: Tue, 13 Dec 2022 11:54:06 -0600
Subject: [PATCH 14/22] fix: comments
---
.../testing/features/ConnectivitySteps.java | 20 +++++--------------
.../pom.xml | 5 +++++
.../platform/linux/NetworkUtilsLinux.java | 5 ++---
3 files changed, 12 insertions(+), 18 deletions(-)
diff --git a/aws-greengrass-testing-features/aws-greengrass-testing-features-api/src/main/java/com/aws/greengrass/testing/features/ConnectivitySteps.java b/aws-greengrass-testing-features/aws-greengrass-testing-features-api/src/main/java/com/aws/greengrass/testing/features/ConnectivitySteps.java
index 188c4ce0..ec25f290 100644
--- a/aws-greengrass-testing-features/aws-greengrass-testing-features-api/src/main/java/com/aws/greengrass/testing/features/ConnectivitySteps.java
+++ b/aws-greengrass-testing-features/aws-greengrass-testing-features-api/src/main/java/com/aws/greengrass/testing/features/ConnectivitySteps.java
@@ -13,10 +13,6 @@
import java.io.IOException;
import javax.inject.Inject;
-/**
- * Blocks the traffic port (IP ports) on ports 443,8888,8889 and back online it.
- * Re-enables them to simulate Network Connectivity.
- */
@ScenarioScoped
public class ConnectivitySteps {
private final Platform platform;
@@ -29,10 +25,10 @@ public ConnectivitySteps(Platform platform) {
}
/**
- * Blocks the traffic port (IP ports) on ports 443,8888,8889 and back online it.
- * Re-enables them to simulate Network Connectivity.
+ * Blocks the traffic port (IP ports) on ports 443,8888,8889 and when the connectivity parameter is "offline" and.
+ * re-enables traffic on the ports when it is "online".
*
- * @param connectivity checks platform connectivity
+ * @param connectivity desired connectivity status ("offline", "online")
* @throws IOException {throws IOException}
* @throws InterruptedException {throws IInterruptedException}
* @throws UnsupportedOperationException {throws UnsupportedOperationException}
@@ -47,20 +43,14 @@ public void setDeviceNetwork(final String connectivity) throws IOException, Inte
platform.getNetworkUtils().recoverNetwork();
break;
default:
- throw new UnsupportedOperationException("Connectivity " + connectivity + " is not supported ");
+ throw new UnsupportedOperationException("Connectivity " + connectivity + " is not supported");
}
offline = connectivity.equalsIgnoreCase("offline");
}
- /**
- * After Each scenario if there is any failure it will make the device go online.
- * Re-enables them to simulate Network Connectivity.
- * @throws IOException {IOException}
- * @throws InterruptedException {InterruptedException}
- */
@After
- public void teardown() throws IOException, InterruptedException {
+ private void teardown() throws IOException, InterruptedException {
if (offline) {
platform.getNetworkUtils().recoverNetwork();
}
diff --git a/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/pom.xml b/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/pom.xml
index 90fb8c4d..fcab25fa 100644
--- a/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/pom.xml
+++ b/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/pom.xml
@@ -146,6 +146,11 @@
software.amazon.awssdk
utils
+
+ com.google.inject
+ guice
+ ${guice.version}
+
\ No newline at end of file
diff --git a/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/src/main/java/com/aws/greengrass/testing/platform/linux/NetworkUtilsLinux.java b/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/src/main/java/com/aws/greengrass/testing/platform/linux/NetworkUtilsLinux.java
index 5e0c528e..a805cc01 100644
--- a/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/src/main/java/com/aws/greengrass/testing/platform/linux/NetworkUtilsLinux.java
+++ b/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/src/main/java/com/aws/greengrass/testing/platform/linux/NetworkUtilsLinux.java
@@ -58,7 +58,6 @@ private void modifyMqttConnection(String action) throws IOException, Interrupted
}
}
-
private void filterPortOnInterface(String iface, int port) throws IOException, InterruptedException {
// Filtering SSH traffic impacts test execution, so we explicitly disallow it
if (port == SSH_PORT) {
@@ -120,6 +119,7 @@ public void disconnectNetwork() throws InterruptedException, IOException {
@Override
public void recoverNetwork() throws InterruptedException, IOException {
interfacepolicy(IPTABLE_COMMAND_STR, DISABLE_OPTION, "connection-recover", NETWORK_PORTS);
+
if (bandwidthSetup.get()) {
deleteRootNetemQdiscOnInterface();
bandwidthSetup.set(false);
@@ -127,8 +127,7 @@ public void recoverNetwork() throws InterruptedException, IOException {
}
private void interfacepolicy(String iptableCommandString, String option, String eventName, String... ports)
- throws InterruptedException,
- IOException {
+ throws InterruptedException, IOException {
for (String port : ports) {
new ProcessBuilder().command("sh", "-c", String.format(iptableCommandString, option, port, option, port))
.start().waitFor(2, TimeUnit.SECONDS);
From bdb94d613bcf3b84ea6d90ddb9f658458c69b68a Mon Sep 17 00:00:00 2001
From: jaiszeen <116672962+jaiszeen@users.noreply.github.com>
Date: Tue, 13 Dec 2022 12:33:12 -0600
Subject: [PATCH 15/22] fix: comments
---
.../com/aws/greengrass/testing/features/ConnectivitySteps.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/aws-greengrass-testing-features/aws-greengrass-testing-features-api/src/main/java/com/aws/greengrass/testing/features/ConnectivitySteps.java b/aws-greengrass-testing-features/aws-greengrass-testing-features-api/src/main/java/com/aws/greengrass/testing/features/ConnectivitySteps.java
index ec25f290..feea15df 100644
--- a/aws-greengrass-testing-features/aws-greengrass-testing-features-api/src/main/java/com/aws/greengrass/testing/features/ConnectivitySteps.java
+++ b/aws-greengrass-testing-features/aws-greengrass-testing-features-api/src/main/java/com/aws/greengrass/testing/features/ConnectivitySteps.java
@@ -25,7 +25,7 @@ public ConnectivitySteps(Platform platform) {
}
/**
- * Blocks the traffic port (IP ports) on ports 443,8888,8889 and when the connectivity parameter is "offline" and.
+ * Blocks the traffic port (IP ports) on ports 443,8888,8889 and when the connectivity parameter is "offline" and
* re-enables traffic on the ports when it is "online".
*
* @param connectivity desired connectivity status ("offline", "online")
From bc552b66d9a8cabadc7629d7936c6b2d75ef5361 Mon Sep 17 00:00:00 2001
From: jaiszeen <116672962+jaiszeen@users.noreply.github.com>
Date: Tue, 13 Dec 2022 12:37:31 -0600
Subject: [PATCH 16/22] fix: dependency
---
.../aws-greengrass-testing-platform-api/pom.xml | 5 -----
1 file changed, 5 deletions(-)
diff --git a/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/pom.xml b/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/pom.xml
index fcab25fa..90fb8c4d 100644
--- a/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/pom.xml
+++ b/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/pom.xml
@@ -146,11 +146,6 @@
software.amazon.awssdk
utils
-
- com.google.inject
- guice
- ${guice.version}
-
\ No newline at end of file
From ba75c37b6db293f21233366e8971fc2c740135c6 Mon Sep 17 00:00:00 2001
From: jaiszeen <116672962+jaiszeen@users.noreply.github.com>
Date: Tue, 13 Dec 2022 12:57:05 -0600
Subject: [PATCH 17/22] fix: dependency
---
.../aws-greengrass-testing-platform-api/pom.xml | 5 +++++
.../aws-greengrass-testing-platform-pillbox/pom.xml | 2 +-
2 files changed, 6 insertions(+), 1 deletion(-)
diff --git a/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/pom.xml b/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/pom.xml
index 90fb8c4d..fcab25fa 100644
--- a/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/pom.xml
+++ b/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/pom.xml
@@ -146,6 +146,11 @@
software.amazon.awssdk
utils
+
+ com.google.inject
+ guice
+ ${guice.version}
+
\ No newline at end of file
diff --git a/aws-greengrass-testing-platform/aws-greengrass-testing-platform-pillbox/pom.xml b/aws-greengrass-testing-platform/aws-greengrass-testing-platform-pillbox/pom.xml
index d65a46fd..62c30d7c 100644
--- a/aws-greengrass-testing-platform/aws-greengrass-testing-platform-pillbox/pom.xml
+++ b/aws-greengrass-testing-platform/aws-greengrass-testing-platform-pillbox/pom.xml
@@ -124,7 +124,7 @@
com.google.guava
guava
- 23.0
+ 31.1-jre
org.immutables
From 74f72035fa28a2b3ed919f9d41b3bff8f275912e Mon Sep 17 00:00:00 2001
From: jaiszeen <116672962+jaiszeen@users.noreply.github.com>
Date: Tue, 13 Dec 2022 13:28:07 -0600
Subject: [PATCH 18/22] fix: dependency
---
.../aws-greengrass-testing-features-api/pom.xml | 5 +++++
.../aws-greengrass-testing-platform-api/pom.xml | 5 -----
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/aws-greengrass-testing-features/aws-greengrass-testing-features-api/pom.xml b/aws-greengrass-testing-features/aws-greengrass-testing-features-api/pom.xml
index e47ad1fe..7f040dcf 100644
--- a/aws-greengrass-testing-features/aws-greengrass-testing-features-api/pom.xml
+++ b/aws-greengrass-testing-features/aws-greengrass-testing-features-api/pom.xml
@@ -236,5 +236,10 @@
2.13.0
test
+
+ com.google.inject
+ guice
+ ${guice.version}
+
\ No newline at end of file
diff --git a/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/pom.xml b/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/pom.xml
index fcab25fa..90fb8c4d 100644
--- a/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/pom.xml
+++ b/aws-greengrass-testing-platform/aws-greengrass-testing-platform-api/pom.xml
@@ -146,11 +146,6 @@
software.amazon.awssdk
utils
-
- com.google.inject
- guice
- ${guice.version}
-
\ No newline at end of file
From b00884abbc6279576127cc4e2ab6d263e29b79d5 Mon Sep 17 00:00:00 2001
From: jaiszeen <116672962+jaiszeen@users.noreply.github.com>
Date: Tue, 13 Dec 2022 14:26:22 -0600
Subject: [PATCH 19/22] fix: dependency
---
.../aws-greengrass-testing-features-api/pom.xml | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/aws-greengrass-testing-features/aws-greengrass-testing-features-api/pom.xml b/aws-greengrass-testing-features/aws-greengrass-testing-features-api/pom.xml
index 7f040dcf..7aefcbdb 100644
--- a/aws-greengrass-testing-features/aws-greengrass-testing-features-api/pom.xml
+++ b/aws-greengrass-testing-features/aws-greengrass-testing-features-api/pom.xml
@@ -194,6 +194,11 @@
${auto.service.version}
provided
+
+ com.google.inject
+ guice
+ ${guice.version}
+
org.immutables
value
@@ -236,10 +241,5 @@
2.13.0
test
-
- com.google.inject
- guice
- ${guice.version}
-
\ No newline at end of file
From b5155b33914cfbcd7c72f791574062834fce3c5d Mon Sep 17 00:00:00 2001
From: jaiszeen <116672962+jaiszeen@users.noreply.github.com>
Date: Tue, 13 Dec 2022 16:36:49 -0600
Subject: [PATCH 20/22] fix: comments
---
.../aws/greengrass/testing/features/ConnectivitySteps.java | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/aws-greengrass-testing-features/aws-greengrass-testing-features-api/src/main/java/com/aws/greengrass/testing/features/ConnectivitySteps.java b/aws-greengrass-testing-features/aws-greengrass-testing-features-api/src/main/java/com/aws/greengrass/testing/features/ConnectivitySteps.java
index feea15df..cc648789 100644
--- a/aws-greengrass-testing-features/aws-greengrass-testing-features-api/src/main/java/com/aws/greengrass/testing/features/ConnectivitySteps.java
+++ b/aws-greengrass-testing-features/aws-greengrass-testing-features-api/src/main/java/com/aws/greengrass/testing/features/ConnectivitySteps.java
@@ -35,7 +35,7 @@ public ConnectivitySteps(Platform platform) {
*/
@When("the device network connectivity is {word}")
public void setDeviceNetwork(final String connectivity) throws IOException, InterruptedException {
- switch (connectivity) {
+ switch (connectivity.toLowerCase()) {
case "offline":
platform.getNetworkUtils().disconnectNetwork();
break;
@@ -46,7 +46,7 @@ public void setDeviceNetwork(final String connectivity) throws IOException, Inte
throw new UnsupportedOperationException("Connectivity " + connectivity + " is not supported");
}
- offline = connectivity.equalsIgnoreCase("offline");
+ "offline".equalsIgnoreCase(connectivity);
}
@After
From 7159dcc0e856606bfb5b8707a3c2fe4f48b93ade Mon Sep 17 00:00:00 2001
From: jaiszeen <116672962+jaiszeen@users.noreply.github.com>
Date: Tue, 13 Dec 2022 16:51:13 -0600
Subject: [PATCH 21/22] fix: comments
---
.../com/aws/greengrass/testing/features/ConnectivitySteps.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/aws-greengrass-testing-features/aws-greengrass-testing-features-api/src/main/java/com/aws/greengrass/testing/features/ConnectivitySteps.java b/aws-greengrass-testing-features/aws-greengrass-testing-features-api/src/main/java/com/aws/greengrass/testing/features/ConnectivitySteps.java
index cc648789..2345895e 100644
--- a/aws-greengrass-testing-features/aws-greengrass-testing-features-api/src/main/java/com/aws/greengrass/testing/features/ConnectivitySteps.java
+++ b/aws-greengrass-testing-features/aws-greengrass-testing-features-api/src/main/java/com/aws/greengrass/testing/features/ConnectivitySteps.java
@@ -46,7 +46,7 @@ public void setDeviceNetwork(final String connectivity) throws IOException, Inte
throw new UnsupportedOperationException("Connectivity " + connectivity + " is not supported");
}
- "offline".equalsIgnoreCase(connectivity);
+ offline = "offline".equalsIgnoreCase(connectivity);
}
@After
From 52a765cdf5e913a9add2a5de74b87d0e4f65493c Mon Sep 17 00:00:00 2001
From: Nelson Ochoa
Date: Tue, 13 Dec 2022 15:53:19 -0700
Subject: [PATCH 22/22] fix: method documentation
---
.../com/aws/greengrass/testing/features/ConnectivitySteps.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/aws-greengrass-testing-features/aws-greengrass-testing-features-api/src/main/java/com/aws/greengrass/testing/features/ConnectivitySteps.java b/aws-greengrass-testing-features/aws-greengrass-testing-features-api/src/main/java/com/aws/greengrass/testing/features/ConnectivitySteps.java
index 2345895e..c0b675e0 100644
--- a/aws-greengrass-testing-features/aws-greengrass-testing-features-api/src/main/java/com/aws/greengrass/testing/features/ConnectivitySteps.java
+++ b/aws-greengrass-testing-features/aws-greengrass-testing-features-api/src/main/java/com/aws/greengrass/testing/features/ConnectivitySteps.java
@@ -25,7 +25,7 @@ public ConnectivitySteps(Platform platform) {
}
/**
- * Blocks the traffic port (IP ports) on ports 443,8888,8889 and when the connectivity parameter is "offline" and
+ * Blocks the traffic on ports 443, 8888, 8889 when the connectivity parameter is "offline" and
* re-enables traffic on the ports when it is "online".
*
* @param connectivity desired connectivity status ("offline", "online")