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

Initial version of udmi tool wrapper #552

Merged
merged 67 commits into from
Dec 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
65b21fb
Basic udmi tool framework
grafnu Oct 15, 2022
75d241a
Additional shell functionality
grafnu Oct 15, 2022
e302826
udmi locate
grafnu Oct 18, 2022
1a2532e
Fixing things
grafnu Oct 18, 2022
6980462
Updating logs output path
grafnu Oct 20, 2022
9932faf
Merge remote-tracking branch 'faucet/master'
grafnu Oct 22, 2022
60184fe
Merge branch 'master' into gittools
grafnu Oct 22, 2022
85d960e
Add test locate
grafnu Oct 22, 2022
b1e3220
Incremental
grafnu Oct 22, 2022
934cc19
Merge remote-tracking branch 'faucet/master'
grafnu Oct 26, 2022
148128d
Merge branch 'master' into gittools
grafnu Oct 26, 2022
527d778
Merge branch 'master' into gittools
grafnu Nov 7, 2022
aacf05c
Merge branch 'master' into gittools
grafnu Nov 9, 2022
b686620
Merge branch 'master' into gittools
grafnu Nov 10, 2022
3f2cefc
Merge branch 'master' into gittools
grafnu Nov 21, 2022
bc65999
Merge branch 'master' into gittools
grafnu Nov 23, 2022
164b555
Merge branch 'master' into gittools
grafnu Nov 28, 2022
accf0a3
Merge branch 'master' into gittools
grafnu Nov 30, 2022
1acfb33
Merge branch 'master' into gittools
grafnu Dec 2, 2022
58ca910
Start to weak for validator errors
grafnu Dec 5, 2022
5a727cd
Merge branch 'master' into gittools
grafnu Dec 5, 2022
bd460b9
Add locate diagnostics
grafnu Dec 6, 2022
d4ad5bc
Try sudo
grafnu Dec 6, 2022
cce212f
Install udmi link
grafnu Dec 6, 2022
194237d
Sqash commit to only cron change
grafnu Dec 7, 2022
d2159fb
Merge branch 'master' into gittools
grafnu Dec 7, 2022
17721c5
Merge remote-tracking branch 'faucet/master'
grafnu Dec 7, 2022
c50e088
Merge branch 'master' into gittools
grafnu Dec 7, 2022
5c6f0b8
Merge remote-tracking branch 'faucet/master'
grafnu Dec 7, 2022
cfba3b5
Merge remote-tracking branch 'faucet/master'
grafnu Dec 9, 2022
8a4b099
Merge branch 'master' into gittools
grafnu Dec 9, 2022
2db6c48
Merge branch 'master' into gittools
grafnu Dec 12, 2022
9a3ee01
Adding oftencron
grafnu Dec 13, 2022
1525544
Merge remote-tracking branch 'faucet/master'
grafnu Dec 14, 2022
07bdeb1
Adding concurrency
grafnu Dec 14, 2022
e8b0b9b
Empty Commit
grafnu Dec 14, 2022
d727a0b
Merge branch 'master' into gittools
grafnu Dec 14, 2022
b63f12b
adding cancel-in-progress
grafnu Dec 14, 2022
df4a6bf
Merge branch 'master' into gittools
grafnu Dec 14, 2022
801172a
Merge remote-tracking branch 'faucet/master'
grafnu Dec 14, 2022
882916d
Merge branch 'master' into gittools
grafnu Dec 14, 2022
e1c3974
Remove redundant concurrency
grafnu Dec 14, 2022
fe29ac9
Merge branch 'master' into gittools
grafnu Dec 15, 2022
967e326
Cleanup cron
grafnu Dec 15, 2022
c48ed8c
Merge branch 'master' into gittools
grafnu Dec 16, 2022
bced84d
Basic pubber command
grafnu Dec 21, 2022
5c7e148
Tweaking tools
grafnu Dec 21, 2022
a6afc37
Fix locate tests
grafnu Dec 21, 2022
32df4c5
Create missing out directory
grafnu Dec 21, 2022
4aa4f76
Merge branch 'master' into gittools
grafnu Dec 21, 2022
cc313b9
Add debugging
grafnu Dec 22, 2022
a966c4c
Fix testing site root
grafnu Dec 22, 2022
e7e166b
make sure udmi-locate is on path
grafnu Dec 22, 2022
1405301
Fix find path
grafnu Dec 22, 2022
5bb894e
Add debugging
grafnu Dec 22, 2022
7728089
Add debugging
grafnu Dec 22, 2022
f125b7a
Calculate relative path for site_model
grafnu Dec 22, 2022
a1f585a
Cleanup site_model path
grafnu Dec 22, 2022
f0fc137
Adding debugging
grafnu Dec 22, 2022
a15cbf0
Use dynamic expected path
grafnu Dec 22, 2022
0e5dc4f
FIx path checks
grafnu Dec 22, 2022
5954277
Add udmi to path
grafnu Dec 22, 2022
6b844d3
Update site-path
grafnu Dec 22, 2022
bc46a79
Merge remote-tracking branch 'faucet/master' into gittools
grafnu Dec 22, 2022
1961120
Whitespace cleanup
grafnu Dec 22, 2022
80b51ce
Merge branch 'master' into gittools
grafnu Dec 23, 2022
b5456f6
Add udmi to dependency install
grafnu Dec 24, 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
6 changes: 3 additions & 3 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
python-version: '3.10'
- name: Checkout source
uses: actions/checkout@v2.3.4
- name: Install dependencies
- name: bin/run_tests install_dependencies
run: bin/run_tests install_dependencies
- name: code checks
if: ${{ always() }}
Expand Down Expand Up @@ -130,8 +130,8 @@ jobs:
if: "${{ env.GCP_TARGET_PROJECT != '' }}"
run: |
bin/test_itemized $GCP_TARGET_PROJECT
more /tmp/test_itemized.out
diff -u /tmp/test_itemized.out etc/test_itemized.out
more out/test_itemized.out
diff -u out/test_itemized.out etc/test_itemized.out
- name: output logs
if: ${{ always() }}
run: |
Expand Down
2 changes: 2 additions & 0 deletions bin/run_tests
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ case "$1" in
install_dependencies)
bin/setup_base
bin/clone_model
sudo ln -fs $PWD/bin/udmi /usr/local/bin/
;;
code_checks)
bin/gencode check
pubber/bin/build check
validator/bin/build check
bin/test_pylint
bin/test_locate
;;
schema_conformance_tests)
bin/test_schema -p
Expand Down
30 changes: 20 additions & 10 deletions bin/test_itemized
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,26 @@ fi
PROJECT_ID=$1
shift 1

udmi_profile=out/pubber_profile.json
SITE_PATH=sites/udmi_site_model
DEVICE_ID=AHU-1

PUBBER_OUT=pubber.out
SEQUENCER_OUT=sequencer.out
RESULTS_OUT=/tmp/test_itemized.out
PUBBER_OUT=out/pubber.out
SEQUENCER_OUT=out/sequencer.out
RESULTS_OUT=out/test_itemized.out
GOLDEN_FILE=etc/test_itemized.out

rm -f $RESULTS_OUT $SEQUENCER_OUT $PUBBER_OUT
touch $RESULTS_OUT $SEQUENCER_OUT $PUBBER_OUT
rm -f $RESULTS_OUT $SEQUENCER_OUT $PUBBER_OUT
touch $RESULTS_OUT $SEQUENCER_OUT $PUBBER_OUT
mkdir -p out

cat <<EOF > $udmi_profile
{
"site_model": "$PWD/$SITE_PATH",
"device_id": "$DEVICE_ID",
"project_id": "$PROJECT_ID"
}
EOF

while read -u 7 action test_name remainder; do
if [[ $action != TEST ]]; then
Expand All @@ -29,10 +39,10 @@ while read -u 7 action test_name remainder; do

echo -n "TEST $test_name $pubber_opts" >> $RESULTS_OUT
echo "TEST $test_name $pubber_opts"

serial_no=sequencer-$RANDOM
bin/pubber $SITE_PATH $PROJECT_ID $DEVICE_ID $serial_no $pubber_opts > $PUBBER_OUT 2>&1 &
WAITING=60
udmi pubber $udmi_profile -x $serial_no $pubber_opts > $PUBBER_OUT 2>&1 &
WAITING=20
for i in `seq 1 $WAITING`; do
if [[ -n $(fgrep "Connection complete" $PUBBER_OUT) ]]; then
break
Expand All @@ -46,8 +56,8 @@ while read -u 7 action test_name remainder; do
false
fi

bin/sequencer $SITE_PATH $PROJECT_ID $DEVICE_ID $serial_no $test_name 2>&1 | tee $SEQUENCER_OUT
bin/sequencer $SITE_PATH $PROJECT_ID $DEVICE_ID $serial_no $test_name 2>&1 | tee $SEQUENCER_OUT

kill $(ps ax | fgrep pubber | fgrep java | awk '{print $1}')

result=$(grep -E -m 1 "RESULT [a-z]+ $test_name " $SEQUENCER_OUT)
Expand Down
94 changes: 94 additions & 0 deletions bin/test_locate
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#!/bin/bash -e

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

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

function test_locate {
udmi locate $2 > $working
profile=$(echo $(fgrep profile: $working | cut -d: -f2))
site_model=$(echo $(fgrep site_model: $working | cut -d: -f2))
if [[ -n $4 ]]; then
expected_site=$(realpath --relative-base $PWD $ROOT/$4)
else
expected_site=
fi
if [[ $profile == $3 && $site_model == $expected_site ]]; then
result=PASS
else
result=FAIL
config_files=$(cd $ROOT; find $HOME/.udmi $ROOT/sites/udmi_site_model/.udmi -name \*.json 2>/dev/null)
echo "$1: udmi locate $2" >> $failures
echo " working directory: " $PWD >> $failures
echo " config files:" $config_files >> $failures
echo " profile expected:" $3 was $profile >> $failures
echo " site_model expected:" $expected_site was $site_model >> $failures
fi
echo $result $1
}

# Make sure udmi is in the path.
export PATH=$ROOT/bin:$PATH

SITE_PATH=sites/udmi_site_model
USER_DEFAULT=$HOME/.udmi/default_profile.json
PROFILE_TEMPLATE=$ROOT/out/default_profile.json
mkdir -p ${PROFILE_TEMPLATE%/*.json}
cat <<EOF > $PROFILE_TEMPLATE
{
"site_model": "$ROOT/$SITE_PATH"
}
EOF

[[ ! -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)

rm -rf $HOME/.udmi $ROOT/$SITE_PATH/.udmi
mkdir -p $HOME/.udmi $ROOT/$SITE_PATH/.udmi

cp $PROFILE_TEMPLATE $USER_DEFAULT
cp $PROFILE_TEMPLATE $HOME/.udmi/profile_foo.json

cd $HOME
echo Testing from $PWD

test_locate default_site "" .udmi/default_profile.json $SITE_PATH
test_locate user_profile foo .udmi/profile_foo.json $SITE_PATH
test_locate user_missing bar "" ""

echo Remove user default profile...
rm -f $HOME/.udmi/default_profile.json

test_locate default_missing "" "" ""

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

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

cd $ROOT/$SITE_PATH
echo Testing from $PWD

echo Copying profiles to .udmi/
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_profile bar .udmi/profile_bar.json $SITE_PATH
test_locate site_nothing baz "" $SITE_PATH

echo Cleanup .udmi directories...
rm -rf $HOME/.udmi $ROOT/$SITE_PATH/.udmi

if [[ -n $(cat $failures) ]]; then
echo Test failures:
cat $failures
false
fi

echo Done with locate tests.
rm -f $failures
25 changes: 25 additions & 0 deletions bin/udmi
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash -e

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

commands=$(cd $UDMI_ROOT/bin; ls udmi-*)
commands=$(echo ${commands//udmi-/})

function show_help {
echo udmi sub-command [options]
echo " sub-command is (usually) something like: $commands"
}
if [[ -z $1 ]]; then
show_help
false
fi

subcmd=udmi-$1
shift

pathcmd=$(which $subcmd || true)
if [[ -z $pathcmd ]]; then
pathcmd=$UDMI_ROOT/bin/$subcmd
fi

$pathcmd "$@"
10 changes: 10 additions & 0 deletions bin/udmi-locate
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/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

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

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

cd $UDMI_ROOT

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 $*
33 changes: 33 additions & 0 deletions etc/extract_parameters.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#
# Assuming the profile has been previously extracted/defined, this script will parse out the common
# profile parameters and process any common command-line arguments.
#

if [[ -z $udmi_profile ]]; then
echo udmi_profile not defined.
false
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)

while getopts "d:p:x:" opt; do
case $opt in
d)
udmi_device=${OPTARG}
;;
p)
udmi_project=${OPTARG}
;;
x)
udmi_serial=${OPTARG}
;;
\?)
echo "Usage: [-d device] [-p project] [-x serial]"
false
;;
esac
done

shift $((OPTIND-1))
84 changes: 84 additions & 0 deletions etc/find_udmi_profile.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#
# Look through and find the site and profile to use for tools.
# This is not a function somewhere because it needs to manipulate the argument stack.
#
# A few configuration cases are supported:
# 1. No argument, or first argument starts with -
# a. Look for working site_model directory and use ${site_mode}/.udmi/defailt_profile.json
# b. Look in ~/.udmi/default_profile.json
# 2. Specific profile specified as file wiht .json extension
# a. Site defined in profile
# a. Site derived from working path (parent with .udmi directory)
# 3. Semantic profile specificed (no .json)
# a. Working site derived from current working directory, look in ${site_mode}/.udmi/profile_${profile}.json
# b. Look in ~/.udmi/profile_${profile}.json
#

function find_or_extract {
if [[ -f $1 ]]; then
site_model=$(jq -r .site_model < $1)
profile_dir=$(dirname $1)
if [[ -z ${site_model} ]]; then
site_model=$(cd ${profile_dir}; find_site_model_root)
elif [[ ${site_model} == "null" ]]; then
site_model=
elif [[ ${site_model} =~ ^/ ]]; then
true # model is absolue, so don't munge.
else
site_model=$(realpath --relative-base ${PWD} ${profile_dir}/${site_model})
fi
echo ${site_model}
fi
}

udmi_profile=
if [[ -z $1 || $1 =~ ^- ]]; then
# No argument specified
site_model=$(find_site_model_root)
if [[ -d ${site_model}/.udmi ]]; then
echo Using working site model $site_model
udmi_profile=${site_model}/.udmi/default_profile.json
echo Using site model default udmi profile $udmi_profile
else
udmi_profile=~/.udmi/default_profile.json
echo Using user default udmi profile $udmi_profile
site_model=$(find_or_extract $udmi_profile)
echo Extracted site model $site_model
fi
elif [[ $1 =~ .json$ ]]; then
# Explicit .json file
udmi_profile=$1
shift
site_model=$(find_or_extract $udmi_profile)
else
# Semantic profile (no .json suffix)
profile_name=$1
shift
site_model=$(find_site_model_root)
if [[ ! -f ${site_model}/cloud_iot_config.json ]]; then
site_model=
fi
if [[ -n ${site_model} ]]; then
udmi_profile=${site_model}/.udmi/profile_${profile_name}.json
else
udmi_profile=~/.udmi/profile_${profile_name}.json
site_model=$(find_or_extract $udmi_profile)
fi
if [[ -z ${site_model} ]]; then
udmi_profile=
fi
fi

if [[ ! -f ${udmi_profile} ]]; then
echo Invalid/empty udmi_profile ${udmi_profile}
udmi_profile=
else
udmi_profile=$(realpath --relative-base $PWD ${udmi_profile})
fi

if [[ ! -f ${site_model}/cloud_iot_config.json ]]; then
echo Invalid/empty site_model ${site_model}
site_model=
else
site_model=$(realpath --relative-base $PWD ${site_model})
fi
16 changes: 16 additions & 0 deletions etc/shell_common.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#
# General utility functions for working with UDMI scripts. Will be source'd by
# executing scripts.
#


#
# Walk up the directory tree looking for the cloud_iot_config.json site model marker.
# If not found, just return empty.
#
function find_site_model_root {
while [ $PWD != "/" ]; do
test -f cloud_iot_config.json && { pwd; break; }
cd ..
done
}