added "--network=host " for docker command if host equals localhost
This commit is contained in:
parent
4025a1f549
commit
7b84cfb9e8
@ -248,10 +248,10 @@ public class DeviceConnectivityControllerTest extends AbstractControllerTest {
|
||||
"-t v1/devices/me/telemetry -u \"%s\" -m \"{temperature:25}\"", credentials.getCredentialsId()));
|
||||
|
||||
JsonNode dockerMqttCommands = commands.get(MQTT).get(DOCKER);
|
||||
assertThat(dockerMqttCommands.get(MQTT).asText()).isEqualTo(String.format("docker run --rm -it thingsboard/mosquitto-clients mosquitto_pub -d -q 1 -h localhost" +
|
||||
assertThat(dockerMqttCommands.get(MQTT).asText()).isEqualTo(String.format("docker run --rm -it --network=host thingsboard/mosquitto-clients mosquitto_pub -d -q 1 -h localhost" +
|
||||
" -p 1883 -t v1/devices/me/telemetry -u \"%s\" -m \"{temperature:25}\"",
|
||||
credentials.getCredentialsId()));
|
||||
assertThat(dockerMqttCommands.get(MQTTS).asText()).isEqualTo(String.format("docker run --rm -it thingsboard/mosquitto-clients " +
|
||||
assertThat(dockerMqttCommands.get(MQTTS).asText()).isEqualTo(String.format("docker run --rm -it --network=host thingsboard/mosquitto-clients " +
|
||||
"/bin/sh -c \"curl -f -S -o ca-root.pem http://localhost:80/api/device-connectivity/mqtts/certificate/download && " +
|
||||
"mosquitto_pub -d -q 1 --cafile ca-root.pem -h localhost -p 8883 -t v1/devices/me/telemetry -u \"%s\" -m \"{temperature:25}\"\"",
|
||||
credentials.getCredentialsId()));
|
||||
@ -286,10 +286,10 @@ public class DeviceConnectivityControllerTest extends AbstractControllerTest {
|
||||
"-t %s -u \"%s\" -m \"{temperature:25}\"", DEVICE_TELEMETRY_TOPIC, credentials.getCredentialsId()));
|
||||
|
||||
JsonNode dockerMqttCommands = commands.get(MQTT).get(DOCKER);
|
||||
assertThat(dockerMqttCommands.get(MQTT).asText()).isEqualTo(String.format("docker run --rm -it thingsboard/mosquitto-clients mosquitto_pub -d -q 1 -h localhost" +
|
||||
assertThat(dockerMqttCommands.get(MQTT).asText()).isEqualTo(String.format("docker run --rm -it --network=host thingsboard/mosquitto-clients mosquitto_pub -d -q 1 -h localhost" +
|
||||
" -p 1883 -t %s -u \"%s\" -m \"{temperature:25}\"",
|
||||
DEVICE_TELEMETRY_TOPIC, credentials.getCredentialsId()));
|
||||
assertThat(dockerMqttCommands.get(MQTTS).asText()).isEqualTo(String.format("docker run --rm -it thingsboard/mosquitto-clients " +
|
||||
assertThat(dockerMqttCommands.get(MQTTS).asText()).isEqualTo(String.format("docker run --rm -it --network=host thingsboard/mosquitto-clients " +
|
||||
"/bin/sh -c \"curl -f -S -o ca-root.pem http://localhost:80/api/device-connectivity/mqtts/certificate/download && " +
|
||||
"mosquitto_pub -d -q 1 --cafile ca-root.pem -h localhost -p 8883 -t %s -u \"%s\" -m \"{temperature:25}\"\"",
|
||||
DEVICE_TELEMETRY_TOPIC, credentials.getCredentialsId()));
|
||||
@ -330,10 +330,10 @@ public class DeviceConnectivityControllerTest extends AbstractControllerTest {
|
||||
"-t %s -i \"%s\" -u \"%s\" -P \"%s\" -m \"{temperature:25}\"", DEVICE_TELEMETRY_TOPIC, clientId, userName, password));
|
||||
|
||||
JsonNode dockerMqttCommands = commands.get(MQTT).get(DOCKER);
|
||||
assertThat(dockerMqttCommands.get(MQTT).asText()).isEqualTo(String.format("docker run --rm -it thingsboard/mosquitto-clients mosquitto_pub -d -q 1 -h localhost" +
|
||||
assertThat(dockerMqttCommands.get(MQTT).asText()).isEqualTo(String.format("docker run --rm -it --network=host thingsboard/mosquitto-clients mosquitto_pub -d -q 1 -h localhost" +
|
||||
" -p 1883 -t %s -i \"%s\" -u \"%s\" -P \"%s\" -m \"{temperature:25}\"",
|
||||
DEVICE_TELEMETRY_TOPIC, clientId, userName, password));
|
||||
assertThat(dockerMqttCommands.get(MQTTS).asText()).isEqualTo(String.format("docker run --rm -it thingsboard/mosquitto-clients " +
|
||||
assertThat(dockerMqttCommands.get(MQTTS).asText()).isEqualTo(String.format("docker run --rm -it --network=host thingsboard/mosquitto-clients " +
|
||||
"/bin/sh -c \"curl -f -S -o ca-root.pem http://localhost:80/api/device-connectivity/mqtts/certificate/download && " +
|
||||
"mosquitto_pub -d -q 1 --cafile ca-root.pem -h localhost -p 8883 -t %s -i \"%s\" -u \"%s\" -P \"%s\" -m \"{temperature:25}\"\"",
|
||||
DEVICE_TELEMETRY_TOPIC, clientId, userName, password));
|
||||
|
||||
@ -135,7 +135,7 @@ public class DeviceConnectivityUtil {
|
||||
}
|
||||
|
||||
StringBuilder mqttDockerCommand = new StringBuilder();
|
||||
mqttDockerCommand.append(DOCKER_RUN).append(MQTT_IMAGE);
|
||||
mqttDockerCommand.append(DOCKER_RUN).append("localhost".equals(host) ? "--network=host ":"").append(MQTT_IMAGE);
|
||||
|
||||
if (MQTTS.equals(protocol)) {
|
||||
mqttDockerCommand.append("/bin/sh -c \"")
|
||||
@ -167,6 +167,6 @@ public class DeviceConnectivityUtil {
|
||||
|
||||
public static String getDockerCoapPublishCommand(String protocol, String host, String port, DeviceCredentials deviceCredentials) {
|
||||
String coapCommand = getCoapPublishCommand(protocol, host, port, deviceCredentials);
|
||||
return coapCommand != null ? String.format("%s%s%s", DOCKER_RUN, COAP_IMAGE, coapCommand) : null;
|
||||
return coapCommand != null ? String.format("%s%s%s", DOCKER_RUN + ("localhost".equals(host) ? "--network=host ":""), COAP_IMAGE, coapCommand) : null;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user