Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Fix semantic string generated output for endpoint connection sequence #474

Merged
merged 45 commits into from
Sep 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
8d7800a
x
johnrandolph Sep 20, 2022
77e9eb9
x
johnrandolph Sep 20, 2022
e783a86
x
johnrandolph Sep 20, 2022
61d29b0
x
johnrandolph Sep 21, 2022
1330e4a
x
johnrandolph Sep 22, 2022
bcb4924
x
johnrandolph Sep 22, 2022
7ca5093
x
johnrandolph Sep 22, 2022
73f66bc
x
johnrandolph Sep 22, 2022
12dec20
x
johnrandolph Sep 22, 2022
0692917
x
johnrandolph Sep 22, 2022
775d0be
x
johnrandolph Sep 22, 2022
a62d8b7
x
johnrandolph Sep 22, 2022
e70d7b9
x
johnrandolph Sep 22, 2022
dd0c6f5
x
johnrandolph Sep 22, 2022
6a6397f
x
johnrandolph Sep 22, 2022
f4a8529
x
johnrandolph Sep 22, 2022
7798943
Merge branch 'faucetsdn:master' into master
johnrandolph Sep 22, 2022
e2cf911
x
johnrandolph Sep 23, 2022
cffdfd1
Merge branch 'master' of github.com:johnrandolph/udmi
johnrandolph Sep 23, 2022
a38377d
x
johnrandolph Sep 23, 2022
56386c6
x
johnrandolph Sep 23, 2022
8f68600
Merge branch 'faucetsdn:master' into master
johnrandolph Sep 23, 2022
409c696
x
johnrandolph Sep 23, 2022
99ff7ec
x
johnrandolph Sep 26, 2022
ecd72cb
x
johnrandolph Sep 26, 2022
a53ebda
x
johnrandolph Sep 27, 2022
b880e09
x
johnrandolph Sep 27, 2022
32781f0
x
johnrandolph Sep 27, 2022
fd566a0
x
johnrandolph Sep 27, 2022
fc4a100
x
johnrandolph Sep 27, 2022
11b8a14
empty
johnrandolph Sep 27, 2022
7f9eedc
empty
johnrandolph Sep 27, 2022
c51c0a0
x
johnrandolph Sep 27, 2022
b251bd9
Reverting generated.md
grafnu Sep 27, 2022
9eb0f90
Add semantic string for payload
grafnu Sep 28, 2022
95199c0
Adding semantic nonce
grafnu Sep 28, 2022
ef32462
Actualize semantic string
grafnu Sep 28, 2022
718fefe
Adding generated.md
grafnu Sep 28, 2022
5015d8d
Try different method ordering
grafnu Sep 28, 2022
59f6b61
Merge remote-tracking branch 'faucet/master' into johntest
grafnu Sep 28, 2022
2bf02d2
Adding semantic sequences
grafnu Sep 28, 2022
51efe87
Add underscores to nonce
grafnu Sep 28, 2022
281d856
Fix expected out
grafnu Sep 28, 2022
5211a7c
Adding underscores
grafnu Sep 28, 2022
ff40f40
Expand regex
grafnu Sep 28, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/clone_model
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ fi
cd $MODEL_DIR

git fetch $MODEL_REPO $MODEL_VER
git checkout $MODEL_VER 2> /dev/null
git checkout $MODEL_VER
git log -n 1

mkdir -p validator
Expand Down
2 changes: 2 additions & 0 deletions bin/test_sequencer
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ if [[ -n $pids ]]; then
kill $pids
fi

bin/clone_model # Clone, and check that version is correct.

bin/reset_config $site_path $project_id $device_id

pubber/bin/build
Expand Down
113 changes: 78 additions & 35 deletions docs/specs/sequences/generated.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Some caveats:
* [broken_config](#broken_config): Check that the device correctly handles a broken (non-json) config message.
* [device_config_acked](#device_config_acked): Check that the device MQTT-acknowledges a sent config.
* [endpoint_config_connection_error](#endpoint_config_connection_error): Push endpoint config message to device that results in a connection error.
* [endpoint_config_connection_success](#endpoint_config_connection_success): Push endpoint config message to device that results in success.
* [endpoint_config_connection_success_reconnect](#endpoint_config_connection_success_reconnect): Push endpoint config message to device that results in successful reconnect to the same endpoint.
* [extra_config](#extra_config): Check that the device correctly handles an extra out-of-schema field
* [periodic_scan](#periodic_scan)
* [self_enumeration](#self_enumeration)
Expand All @@ -44,82 +44,125 @@ Some caveats:

Check that the device correctly handles a broken (non-json) config message.

1. Test failed: There were 2 errors:
java.lang.RuntimeException(While updating config block system)
java.lang.RuntimeException(While updating config block system)
1. Update config:
* Set `system.min_loglevel` = `100`
1. Wait for no interesting status
1. Wait for clean config/state synced
1. Wait for state synchronized
1. Check that initial stable_config matches last_config
1. Wait for log category `system.config.receive` level `DEBUG`
1. Wait for has interesting status
1. Wait for log category `system.config.parse` level `ERROR`
1. Check has not logged category `system.config.apply` level `NOTICE` (**incomplete!**)
1. Force reset config
1. Wait for log category `system.config.receive` level `DEBUG`
1. Wait for no interesting status
1. Wait for last_config updated
1. Wait for log category `system.config.apply` level `NOTICE`
1. Wait for log category `system.config.parse` level `DEBUG`

## device_config_acked

Check that the device MQTT-acknowledges a sent config.

1. Test failed: There were 2 errors:
java.lang.RuntimeException(While updating config block system)
java.lang.RuntimeException(While updating config block system)
1. Wait for config acked

## endpoint_config_connection_error

Push endpoint config message to device that results in a connection error.

1. Update config:
* Add `blobset` = { "blobs": { "_iot_endpoint_config": { "phase": `final`, "content_type": `application/json`, "base64": `eyAgICJwcm90b2NvbCI6ICJtcXR0IiwKICAiY2xpZW50X2lkIjogInByb2plY3RzLyVzL2xvY2F0aW9ucy8lcy9yZWdpc3RyaWVzLyVzL2RldmljZXMvJXMiLAogICJob3N0bmFtZSI6ICJsb2NhbGhvc3QiCn0=` } } }
* Add `blobset` = { "blobs": { "_iot_endpoint_config": { "phase": `final`, "content_type": `application/json`, "base64": _endpoint_base64_payload_ } } }
1. Wait for blobset entry config status is error

## endpoint_config_connection_success
## endpoint_config_connection_success_reconnect

Push endpoint config message to device that results in success.
Push endpoint config message to device that results in successful reconnect to the same endpoint.

1. Test failed: There were 2 errors:
java.lang.RuntimeException(Trying to receive message from inactive client)
java.lang.RuntimeException(While updating config block system)
1. Update config:
* Add `blobset` = { "blobs": { "_iot_endpoint_config": { "phase": `final`, "content_type": `application/json`, "base64": _endpoint_base64_payload_, "nonce": _endpoint_nonce_ } } }
1. Wait for blobset entry config status is success

## extra_config

Check that the device correctly handles an extra out-of-schema field

1. Test failed: There were 2 errors:
java.lang.RuntimeException(While updating config block system)
java.lang.RuntimeException(While updating config block system)
1. Update config:
* Set `system.min_loglevel` = `100`
1. Wait for last_config not null
1. Wait for system operational
1. Wait for no interesting status
1. Wait for log category `system.config.receive` level `DEBUG`
1. Wait for last_config updated
1. Wait for system operational
1. Wait for no interesting status
1. Wait for log category `system.config.parse` level `DEBUG`
1. Wait for log category `system.config.apply` level `NOTICE`
1. Wait for log category `system.config.receive` level `DEBUG`
1. Wait for last_config updated again
1. Wait for system operational
1. Wait for no interesting status
1. Wait for log category `system.config.parse` level `DEBUG`
1. Wait for log category `system.config.apply` level `NOTICE`

## periodic_scan

1. Test failed: There were 2 errors:
java.lang.RuntimeException(While updating config block system)
java.lang.RuntimeException(While updating config block system)
1. Update config:
* Add `discovery` = { "families": { } }
1. Wait for all scans not active
1. Update config:
* Add `discovery.families.virtual` = { "generation": _family generation_, "scan_interval_sec": `10`, "enumerate": `true` }
1. Wait for scan iterations

## self_enumeration

1. Test failed: There were 2 errors:
java.lang.RuntimeException(While updating config block system)
java.lang.RuntimeException(While updating config block system)
1. Wait for enumeration not active
1. Update config to discovery generation:
* Add `discovery` = { "enumeration": { "generation": _generation start time_ } }
1. Wait for enumeration generation
1. Wait for enumeration still not active

## single_scan

1. Test failed: There were 2 errors:
java.lang.RuntimeException(While updating config block system)
java.lang.RuntimeException(While updating config block system)
1. Update config:
* Add `discovery` = { "families": { } }
1. Wait for all scans not active
1. Update config:
* Add `discovery.families.virtual` = { "generation": _family generation_, "enumerate": `true` }
1. Wait for scheduled scan start
1. Wait for scan activation
1. Wait for scan completed

## system_last_update

Check that last_update state is correctly set in response to a config update.

1. Test failed: There were 2 errors:
java.lang.RuntimeException(While updating config block system)
java.lang.RuntimeException(While updating config block system)
1. Wait for state last_config matches config timestamp

## system_min_loglevel

Check that the min log-level config is honored by the device.

1. Test failed: There were 2 errors:
java.lang.RuntimeException(While updating config block system)
java.lang.RuntimeException(While updating config block system)
1. Check has not logged category `system.config.apply` level `NOTICE` (**incomplete!**)
1. Update config:
* Set `system.min_loglevel` = `400`
1. Update config:
* Set `system.min_loglevel` = `200`
1. Wait for log category `system.config.apply` level `NOTICE`

## valid_serial_no

1. Test failed: There were 2 errors:
java.lang.RuntimeException(While updating config block system)
java.lang.RuntimeException(While updating config block system)
1. Check that received serial no matches

## writeback_states

1. Test failed: Missing 'invalid' target specification
1. Wait for point filter_differential_pressure_sensor to have value_state default (null)
1. Wait for point filter_alarm_pressure_status to have value_state default (null)
1. Wait for point filter_differential_pressure_setpoint to have value_state default (null)
1. Update config:
* Add `pointset.points.filter_alarm_pressure_status.set_value` = `false`
* Set `pointset.points.filter_differential_pressure_setpoint.set_value` = `60`
* Add `pointset.points.filter_differential_pressure_sensor.set_value` = `15`
1. Wait for point filter_differential_pressure_sensor to have value_state invalid
1. Wait for point filter_alarm_pressure_status to have value_state failure
1. Wait for point filter_differential_pressure_setpoint to have value_state applied
1 change: 1 addition & 0 deletions etc/sequencer.out
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
RESULT pass broken_config Sequence complete
RESULT pass device_config_acked Sequence complete
RESULT pass endpoint_config_connection_error Sequence complete
RESULT pass endpoint_config_connection_success_reconnect Sequence complete
RESULT pass extra_config Sequence complete
RESULT pass periodic_scan Sequence complete
RESULT pass self_enumeration Sequence complete
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
Push endpoint config message to device that results in a connection error.

1. Update config:
* Add `blobset` = { "blobs": { "_iot_endpoint_config": { "phase": `final`, "content_type": `application/json`, "base64": `eyAgICJwcm90b2NvbCI6ICJtcXR0IiwKICAiY2xpZW50X2lkIjogInRlc3RfcHJvamVjdC9kZXZpY2UiLAogICJob3N0bmFtZSI6ICJsb2NhbGhvc3QiCn0=` } } }
* Add `blobset` = { "blobs": { "_iot_endpoint_config": { "phase": `final`, "content_type": `application/json`, "base64": _endpoint_base64_payload_ } } }
1. Wait for blobset entry config status is error
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

## endpoint_config_connection_success_reconnect

Push endpoint config message to device that results in successful reconnect to the same endpoint.

1. Update config:
* Add `blobset` = { "blobs": { "_iot_endpoint_config": { "phase": `final`, "content_type": `application/json`, "base64": _endpoint_base64_payload_, "nonce": _endpoint_nonce_ } } }
1. Wait for blobset entry config status is success
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.google.daq.mqtt.sequencer;

import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.daq.mqtt.sequencer.semantic.SemanticValue.actualize;
import static com.google.daq.mqtt.util.JsonUtil.stringify;
import static java.util.Optional.ofNullable;

Expand Down Expand Up @@ -608,7 +609,7 @@ private void updateConfig(SubFolder subBlock, Object data) {
boolean updated = !messageData.equals(sentBlockConfig);
if (updated) {
final Object tracedObject = augmentTrace(data);
String augmentedMessage = stringify(tracedObject);
String augmentedMessage = actualize(stringify(tracedObject));
String topic = subBlock + "/config";
client.publish(deviceId, topic, augmentedMessage);
debug(String.format("update %s_%s", "config", subBlock));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ public interface SemanticValue {

String BEFORE_MARKER = "@@@";
String AFTER_MARKER = "###";
String STRING_PREFIX = "\"";
String SEMANTIC_REGEX = STRING_PREFIX + BEFORE_MARKER + "[-_.0-9a-zA-Z ]+" + AFTER_MARKER;

static boolean isSemanticValue(Object other) {
boolean semanticString = other instanceof String && ((String) other).startsWith(BEFORE_MARKER);
Expand Down Expand Up @@ -49,4 +51,15 @@ static String getDescription(Object target) {
* @return object description
*/
String getDescription();

/**
* Remove the description tag from any embedded strings, returning the actual string to be used
* (w/o semantic descriptions).
*
* @param string input string to actualize
* @return actual string
*/
static String actualize(String string) {
return string.replaceAll(SEMANTIC_REGEX, STRING_PREFIX);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static udmi.schema.Category.SYSTEM_CONFIG_APPLY;

import com.google.daq.mqtt.sequencer.SequenceBase;
import com.google.daq.mqtt.sequencer.semantic.SemanticValue;
import java.security.SecureRandom;
import java.util.Base64;
import java.util.HashMap;
Expand Down Expand Up @@ -44,13 +45,15 @@ private String generateEndpointConfigClientId() {
private String generateEndpointConfigBase64Payload(String hostname) {
String payload = String.format(
ENDPOINT_CONFIG_HOSTNAME_PAYLOAD, ENDPOINT_CONFIG_CLIENT_ID, hostname);
return Base64.getEncoder().encodeToString(payload.getBytes());
String base64Payload = Base64.getEncoder().encodeToString(payload.getBytes());
return SemanticValue.describe("endpoint_base64_payload", base64Payload);
}

private String generateNonce() {
byte[] nonce = new byte[32];
new SecureRandom().nextBytes(nonce);
return Base64.getEncoder().encodeToString(nonce);
String base64Nonce = Base64.getEncoder().encodeToString(nonce);
return SemanticValue.describe("endpoint_nonce", base64Nonce);
}

@Test
Expand Down