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

adding "udmi validate" tool #561

Merged
merged 17 commits into from
Jan 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .gencode_hash.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ b35646a2f3d7c30fd34e3ea6ab6a1070b39c469fd1de49cab1093ff32faaf06d gencode/docs/c
64bafb080b454189b7b64a95e049c3427fd1cca70cf0809a31150610f40e9525 gencode/docs/config.html
73b3beb740f5bc3ff26d173c356b2d3bf3b9892be83a704d3eeee7c9ff030230 gencode/docs/config_mapping.html
cc4bb19794042f88f3a72b197b4d21736e5cebf6ec47ffac560430e9f580181f gencode/docs/configuration_endpoint.html
b7ca70e3176f997f254c32bd8d53dff1462ac8a71c0e166aaa85193d67bff60b gencode/docs/configuration_execution.html
eee42c93923612ad84086c2768fbdc1f1b617c67eb3665e85758a158d988ede5 gencode/docs/configuration_execution.html
fa89df05f3db9b27f96b65d89d3fef4aa3c8ad8e758fcfc123627f88bf600d00 gencode/docs/configuration_pubber.html
0f0355e343cb8197dfbae1481c0eca3a0566d73181bc968e33fd469a1c94d1e6 gencode/docs/envelope.html
92da453dec3e27493216f8c3672b6203be9eb9b3086741c22fda9432c22504b7 gencode/docs/event.html
Expand All @@ -23,7 +23,7 @@ f46367beaab5886ef87ce70b542611134c3565daa53e367de4f49dab51214f12 gencode/docs/r
7ed934930aee763e0beebc349725ba3909115e8d346bb762f28bcbe745bb163a gencode/docs/schema_extras.js
63cd94346f634ca2945982c147546cb1103fcfea4c42eac04b065ca838f5217f gencode/docs/state.html
f10172c9b4cd350cae1f673077b07b1362168599b966a78d4ec4ef19b7bbf441 gencode/docs/state_mapping.html
552f85739f547960d2c1b96c99152ff831a036ce4d19908a5361b35a2d5f2132 gencode/docs/state_validation.html
e8c57cbcea8328957e5fbf2d73fd15bd43cf783380f31deda9e8f96f6f7e6475 gencode/docs/state_validation.html
d39d7fe37a41c74a40080af7b0a429d201ab1fdff7444428c4b98eb7b38c332b gencode/java/udmi/schema/Asset.java
b405ce628f7819b46b19950aeaba89ee938fea54261000616bc534b9f81bd59c gencode/java/udmi/schema/Auth_provider.java
0825a5cec83003bb0a6488c4ed7010a04ae0d3848ef36fe01bb4e6718ba7b96d gencode/java/udmi/schema/Aux.java
Expand Down Expand Up @@ -51,7 +51,7 @@ dd2eb479a8e93a851c535c8b40fbd62e152bd60e0473f3b23800ec61f798bed0 gencode/java/u
06758aca1e0043ddf343b504030f47bb19260e99a82e2d66f12e86092a2434ca gencode/java/udmi/schema/Enumerate.java
017f8e237efa959b81d72f3dd2e78b915856198ceef02c041c657b30df93b7c2 gencode/java/udmi/schema/Envelope.java
e9f5c77be81486b6b8c6d88f70f2d50583d8c3fafa2ac09ead80f44b8d5e751e gencode/java/udmi/schema/Event.java
69c3c12ce057b6ab8e27ab8cab6fb009bfd1c997652214b49e6f2a26a58f302c gencode/java/udmi/schema/ExecutionConfiguration.java
80708e2b4ee30deaf41806a80d006706b7d4bc0589e088c5c0bab0c28e772380 gencode/java/udmi/schema/ExecutionConfiguration.java
2e77a29988e6c17875d3f781be931e3b835bb310639f60d3bb28f24405a86bed gencode/java/udmi/schema/FamilyDiscoveryConfig.java
ae4a645f199c8e24b3303463d428ca17af7603ae9ae9238397a6a82e752ab454 gencode/java/udmi/schema/FamilyDiscoveryEvent.java
5ad9bf328fa1500250ff8bc75f2044b3815c5c11cb368e1cc228ac8ca16639c2 gencode/java/udmi/schema/FamilyDiscoveryState.java
Expand Down Expand Up @@ -105,7 +105,7 @@ ceacfb4a1d0a4b4f4110b0e0717e57f2bbfd80ef18599d24fab19ddf497f399e gencode/java/u
d3968b92497e83a63f18cc0e74484a9807f1bb92db0c92d556ec2caaa143d645 gencode/java/udmi/schema/TestingModel.java
7793d6d76a430dc7acf668d92d2df5f8e0625d6228207731f96e220f3b90e659 gencode/java/udmi/schema/TestingSystemConfig.java
ac6f8fd87c8986cce01e872460c15ff6fe71e3816f9bde610acfe25f7d38c8d4 gencode/java/udmi/schema/ValidationEvent.java
f7d117dc8b9764acf0c95a13a2bfdfbdf31d1a8ec83a707448aa4d7391ef07e2 gencode/java/udmi/schema/ValidationState.java
960c3a9ec9e309cd0dbd23c49a722a64e3b360c8771d8e6a4463ee21a44f94a6 gencode/java/udmi/schema/ValidationState.java
e007ddd1ceeae3603c85110c33e1bb4a418ff9c7a791ca0df25b7ea3caeafd36 gencode/java/udmi/schema/ValidationSummary.java
b77d953fd22e655c0f10ae32deeaa222769d971f8c38b3379eba45720fb910cc gencode/java/udmi/schema/VirtualEquipmentLinks.java
67553fdfe44896f487a7d4cf8161537e2595d48a96f8e44a1f9bac4a6d71591a gencode/python/udmi/schema/__init__.py
Expand All @@ -129,7 +129,7 @@ ac3facbd96f7cb2f7e387e7497d6a36af379a2687329571f250c5670f9933244 gencode/python
7da3bdb37f338260d5f3829fa5fcbb9bbf9f146b514a68319c314a96c6b8ac12 gencode/python/udmi/schema/config_system.py
cce623b34fd694880039a1c080214c33e00acaef5bc72276cf11a3bb2de40000 gencode/python/udmi/schema/config_system_testing.py
bbaa2d9322d0c92282116c4a28edbb363d01681dc093e6463999f127aa108f51 gencode/python/udmi/schema/configuration_endpoint.py
e8a1574074554b6144b178d2adedc76a1c7be5ae911b253deff4460d8d82c6ee gencode/python/udmi/schema/configuration_execution.py
264f42c1455c4d0311b3f1cf925214f159d4728d82b3153d2b407588fb7b682c gencode/python/udmi/schema/configuration_execution.py
7f4f8c1a6ead34bf72b9134b97a39001752eb0f9647fafaac82ced4bb2f46b88 gencode/python/udmi/schema/configuration_pubber.py
998ce105f88686f27b85f3630a396ed04b106f830c133a684ea5c505ca95b1c3 gencode/python/udmi/schema/envelope.py
ed8ace0196c5e99d20778cb4210aa88cfe44a5e4539af98a1e194b9a71fa538e gencode/python/udmi/schema/equipment_translation.py
Expand Down Expand Up @@ -176,5 +176,5 @@ f2a76b32a5568d87a8c9ca8b32dc8a129bc7386f9522c5399d32db433be4cb70 gencode/python
8a601de0130081eec02724fd554749b7bd96d02874b0a3557d461cced41bd09b gencode/python/udmi/schema/state_system.py
8a0bf4294fb70533a056322a6bfc6f13a963381d2100d1468d8b6de757cd72e9 gencode/python/udmi/schema/state_system_hardware.py
37c55dce0e38dddad3cebb3d40270128a4dbb7b586657d1746bb96dac90e2ac1 gencode/python/udmi/schema/state_system_operation.py
231479e4dd7d961d59149580aba6a99cd466cea553400f338e9da2bf3ffbe78c gencode/python/udmi/schema/state_validation.py
b4ed0fc3cafb48d4dfb5fb54f5b1d48df2d57ac85a5c36591ca12ed97ca8e687 gencode/python/udmi/schema/state_validation.py
83a57db63df10d43b1789c3f115a515c23bb7bc7a8cc8c2accdc17d0cbac89fe gencode/python/udmi/schema/virtual_links.py
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ credentials.json
/validator/.idea/libraries/
/pubber/build/
/pubber/out/
/pubber/pubber/out/
/pubber/.idea/libraries/
/sites/
/attributes.json
Expand Down
46 changes: 37 additions & 9 deletions bin/test_locate
Original file line number Diff line number Diff line change
@@ -1,19 +1,34 @@
#!/bin/bash -e

function locate_help {
echo To clean config directories and stop-at-first-failure, use:
echo
echo $0 trial
echo
false
}


ROOT=$(realpath $(dirname $0)/..)
cd $ROOT

trial_run=
if [[ $1 == trial ]]; then
trial_run=true
shift
fi

failures=$(mktemp)
working=$(mktemp)

function test_locate {
udmi locate $2 > $working
udmi locate $2 > $working 2>&1 || true
profile=$(echo $(fgrep profile: $working | cut -d: -f2))
site_model=$(echo $(fgrep site_model: $working | cut -d: -f2))
if [[ -n $4 ]]; then
if [[ -n $4 && $4 != null ]]; then
expected_site=$(realpath --relative-base $PWD $ROOT/$4)
else
expected_site=
expected_site=$4
fi
if [[ $profile == $3 && $site_model == $expected_site ]]; then
result=PASS
Expand All @@ -27,6 +42,14 @@ function test_locate {
echo " site_model expected:" $expected_site was $site_model >> $failures
fi
echo $result $1
if [[ -n $trial_run && $result != PASS ]]; then
echo ======================
cat $working
echo ======================
cat $failures
echo ======================
return 1
fi
}

# Make sure udmi is in the path.
Expand All @@ -42,9 +65,14 @@ cat <<EOF > $PROFILE_TEMPLATE
}
EOF

if [[ -n $trial_run ]]; then
echo Cleaning config directories...
rm -rf $HOME/.udmi $ROOT/$SITE_PATH/.udmi
fi

[[ ! -d $ROOT/$SITE_PATH ]] && (echo $ROOT/$SITE_PATH not found, check your setup. && false)
[[ -d $HOME/.udmi ]] && (echo $HOME/.udmi exists, remove before testing && false)
[[ -d $ROOT/$SITE_PATH/.udmi ]] && (echo $ROOT/$SITE_PATH/.udmi exists, remove before testing && false)
[[ -d $HOME/.udmi ]] && (echo $HOME/.udmi exists; locate_help)
[[ -d $ROOT/$SITE_PATH/.udmi ]] && (echo $ROOT/$SITE_PATH/.udmi exists; locate_help)

rm -rf $HOME/.udmi $ROOT/$SITE_PATH/.udmi
mkdir -p $HOME/.udmi $ROOT/$SITE_PATH/.udmi
Expand All @@ -62,12 +90,12 @@ test_locate user_missing bar "" ""
echo Remove user default profile...
rm -f $HOME/.udmi/default_profile.json

test_locate default_missing "" "" ""
test_locate default_missing "" .udmi/default_profile.json null

echo Create empty user default profile...
echo {} > $HOME/.udmi/default_profile.json

test_locate default_empty "" .udmi/default_profile.json ""
test_locate default_empty "" .udmi/default_profile.json null

cd $ROOT/$SITE_PATH
echo Testing from $PWD
Expand All @@ -77,9 +105,9 @@ cp $PROFILE_TEMPLATE .udmi/
cp $PROFILE_TEMPLATE .udmi/profile_bar.json

test_locate site_default "" .udmi/default_profile.json $SITE_PATH
test_locate site_missing foo "" $SITE_PATH
test_locate site_missing foo $HOME/.udmi/profile_foo.json $SITE_PATH
test_locate site_profile bar .udmi/profile_bar.json $SITE_PATH
test_locate site_nothing baz "" $SITE_PATH
test_locate site_nothing baz "" ""

echo Cleanup .udmi directories...
rm -rf $HOME/.udmi $ROOT/$SITE_PATH/.udmi
Expand Down
3 changes: 3 additions & 0 deletions bin/test_trace
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ trace_in=validator/traces/${trace_name}.in
site_model=sites/udmi_site_model
site_out=$site_model/out

# Use a static/constant value to make output stable.
export UDMI_TOOLS=test_trace

rm -rf $site_out
validator/bin/validate -- schema trace $trace_in $site_model

Expand Down
2 changes: 1 addition & 1 deletion bin/test_validator
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ bin/reset_config $site_path $project_id $device_id
bin/reset_config $site_path $project_id $proxy_id

echo Starting validator, output in $VALIDATOR_OUT
bin/validator $site_path $project_id > $VALIDATOR_OUT 2>&1 &
udmi validate -s $site_path -p $project_id > $VALIDATOR_OUT 2>&1 &
vpid=$!
echo Started validator pid $vpid

Expand Down
8 changes: 2 additions & 6 deletions bin/udmi-locate
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
#!/bin/bash -e

UDMI_ROOT=$(realpath $(dirname $(readlink -f $0))/..)

source $UDMI_ROOT/etc/shell_common.sh

source $UDMI_ROOT/etc/find_udmi_profile.sh
source $(realpath $(dirname $(readlink -f $0))/..)/etc/udmi_preamble.sh
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly all this source'ing makes me nervous. Is there some other way we can accomplish this?

If we just want to put configuration data into shell scripts that's one thing, and carefully pull the values out. But at the point that we are building multiple source (with sourceing them) shell scripts I think we might need a different approach.

WDYT?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know how else to do it other than with "source" -- if you have a specific suggestion on "some other way" that's more appropriate then I'm all ears... but -- if you want/need to do something like define "common functions" I'm not sure how else to do it...

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think if you are sourcing shell scripts you need to move to a different language.


echo profile: ${udmi_profile}
echo site_model: ${site_model}
echo site_model: ${udmi_site}
22 changes: 8 additions & 14 deletions bin/udmi-pubber
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
#!/bin/bash -e

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there some reason these aren't named same_as_the_others instead of using - ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was basing it off of the git extension format, e.g. the file "git-utility" would map to the command-line "git utility " -- as a way to provide transparent extensions. So, "udmi-validate" maps to "udmi validate". The snake_case ones are generally things then that should be run directly (bin/test_sequencer). So, that was the reason (consistency with git extension naming)...

UDMI_ROOT=$(realpath $(dirname $(readlink -f $0))/..)
source $(realpath $(dirname $(readlink -f $0))/..)/etc/udmi_preamble.sh

cd $UDMI_ROOT
[[ $udmi_site != null ]] || udmi_help site_model not defined
[[ $udmi_project != null ]] || udmi_help project_id not defined
[[ $udmi_device != null ]] || udmi_help device_id not defined
[[ $udmi_serial != null ]] || udmi_help serial_id not defined

source etc/shell_common.sh

source etc/find_udmi_profile.sh

source etc/extract_parameters.sh

[[ $udmi_project != null ]] || (echo project_id not defined && false)
[[ $udmi_device != null ]] || (echo device_id not defined && false)
[[ $udmi_serial != null ]] || (echo serial_id not defined && false)

echo $UDMI_ROOT/bin/pubber $site_model $udmi_project $udmi_device $udmi_serial $*
$UDMI_ROOT/bin/pubber $site_model $udmi_project $udmi_device $udmi_serial $*
cmd="$UDMI_ROOT/bin/pubber $udmi_site $udmi_project $udmi_device $udmi_serial $*"
echo $cmd
$cmd
60 changes: 60 additions & 0 deletions bin/udmi-validate
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/bin/bash -e

source $(realpath $(dirname $(readlink -f $0))/..)/etc/udmi_preamble.sh

CONFIG_FILE=/tmp/validator_config.json

echo $udmi_site
[[ $udmi_site != null ]] || udmi_help site_model not defined
[[ $udmi_project != null ]] || udmi_help project_id not defined

[[ $udmi_feed != null ]] || udmi_feed=

SUMMARY_FILE=out/validation_report.json
rm -f $SUMMARY_FILE

$UDMI_ROOT/validator/bin/build

echo Writing config to $CONFIG_FILE
cat <<EOF > $CONFIG_FILE
{
"project_id": "$udmi_project",
"site_model": "$udmi_site",
"log_level": "$udmi_loglevel",
"udmi_root": "$UDMI_ROOT",
"feed_name": "$udmi_feed",
"udmi_version": "$udmi_version",
"key_file": "$site_path/validator/rsa_private.pkcs8"
}
EOF

JAVA_CMD="java -cp $UDMI_JAR com.google.daq.mqtt.validator.Validator"

cmd="$JAVA_CMD $CONFIG_FILE"
if [[ $udmi_runsec != null ]]; then
cmd="timeout ${udmi_runsec}s $cmd"
fi

echo $cmd
result=0
$cmd || result=$?

if [[ $result != 124 ]]; then
echo abnormal termination not due to timeout.
false
fi

[[ -f $SUMMARY_FILE ]] || (echo missing summary file $SUMMARY_FILE && false)

mkdir -p out/devices

error_files=$(find out/devices/ -name \*.out)
echo
if [[ -n $error_files ]]; then
echo Device validation error files:
find out/devices/ -name \*.out
else
echo No device validation errors found.
fi
echo
echo Report summary in $SUMMARY_FILE
40 changes: 35 additions & 5 deletions etc/extract_parameters.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,53 @@ fi
udmi_device=$(jq -r .device_id $udmi_profile)
udmi_project=$(jq -r .project_id $udmi_profile)
udmi_serial=$(jq -r .serial_no $udmi_profile)
udmi_runsec=$(jq -r .run_sec $udmi_profile)
udmi_keyfile=$(jq -r .key_file $udmi_profile)
udmi_feed=$(jq -r .feed_name $udmi_profile)

while getopts "d:p:x:" opt; do
while getopts "p:d:x:l:s:k:f:" opt; do
case $opt in
d)
udmi_device=${OPTARG}
;;
p)
udmi_project=${OPTARG}
;;
s)
udmi_site=${OPTARG}
;;
d)
udmi_device=${OPTARG}
;;
x)
udmi_serial=${OPTARG}
;;
l)
udmi_runsec=${OPTARG}
;;
k)
udmi_keyfile=${OPTARG}
;;
f)
udmi_feed=${OPTARG}
;;
\?)
echo "Usage: [-d device] [-p project] [-x serial]"
echo "Usage: [-p project] [-s site] [-d device] [-x serial] [-l length] [-k key_file] [-f feed_name]"
false
;;
esac
done

shift $((OPTIND-1))

function udmi_help {
echo
echo $*
echo
echo 'Common udmi profile paramaeters (or command line option):'
echo ' project_id (-p): the cloud project id'
echo ' site_model (-s): the udmi site model'
echo ' device_id (-d): the device id to test/validate'
echo ' serial_no (-x): the device serial number for test'
echo ' run_sec (-l): the test run length in seconds'
echo ' key_file (-k): reflector device private key file'
echo ' feed_name (-f): PubSub cloud feed subscription name'
false
}
Loading