reubenmiller / go-c8y-cli

go c8y cli tool for interacting with the Cumulocity IoT API
https://goc8ycli.netlify.app/
MIT License
36 stars 8 forks source link

c8y software versions list error on RaspberryPi #104

Closed rafzal1078 closed 2 years ago

rafzal1078 commented 2 years ago

I receive an error when trying to run the 'software versions list --software' command on a RaspberryPi. Here is the script I'm using to set my session and run the command:

#!/bin/bash

start_session(){
    C8Y_HOST=""
    C8Y_TENET=""
    C8Y_USERNAME=""
    C8Y_PASSWORD=""

    echo "Setting go-c8y-cli source"
    source "/etc/go-c8y-cli/shell/c8y.plugin.sh"

    echo "Setting go-c8y-cli session"
    c8y sessions create \
        --host "$C8Y_TENET" \
        --username "$C8Y_USERNAME" \
        --password "$C8Y_PASSWORD" \
        --description "Deploy Testing" \
        --type dev

    echo "Starting go-c8y-cli session"
    set-session

    echo "Setting mode.enableCreate TRUE"
    c8y settings update mode.enableCreate 'true'
}
 install_software(){
     local name="$1"             

     echo "Installing software: $name"
 }

clear_session(){
    c8y sessions clear
}

#
# Main
#
start_session

if [ $1 == P ]; then
    LATEST_VERSION=$( c8y software versions list -n --software asdm_algorithm_stack_P --includeAll --select "*.lastUpdated " -o csv | sort -Vr | head -1 )
elif [ $1 == Q ]; then
    echo "Setting Q software install"
else
    echo "No software release type set"
    exit 1
fi

c8y software versions list --software 740

#install_software "$LATEST_VERSION"
clear_session

This is the command prompt output when running the script:

./c8y_asdm_install.sh Q
Setting go-c8y-cli source
Setting go-c8y-cli session
/home/pi/.cumulocity/secasdm.us.cumulocity.com-rebecca.afzal@schindler.com.json
Starting go-c8y-cli session
---------------------  Cumulocity Session  ---------------------

    path: /home/pi/.cumulocity/secasdm.us.cumulocity.com-rebecca.afzal@schindler.com.json

host         : secasdm.us.cumulocity.com
tenant       : secasdm
username     : rebecca.afzal@schindler.com

Setting mode.enableCreate TRUE
Updated session file /home/pi/.cumulocity/secasdm.us.cumulocity.com-rebecca.afzal@schindler.com.json
Setting Q software install
panic: unaligned 64-bit atomic operation

goroutine 11 [running]:
runtime/internal/atomic.panicUnaligned()
    /opt/hostedtoolcache/go/1.16.13/x64/src/runtime/internal/atomic/unaligned.go:8 +0x24
runtime/internal/atomic.Xadd64(0x27f65f4, 0x1, 0x0, 0x0, 0x0)
    /opt/hostedtoolcache/go/1.16.13/x64/src/runtime/internal/atomic/asm_arm.s:233 +0x14
github.com/reubenmiller/go-c8y-cli/pkg/iterator.(*SliceIterator).GetNext(0x27f65e8, 0x0, 0x0, 0x24648, 0xa6d6dcc8, 0x1c17c, 0x19d44, 0x2884008)
    /home/runner/work/go-c8y-cli/go-c8y-cli/pkg/iterator/slice.go:16 +0x34
github.com/reubenmiller/go-c8y-cli/pkg/c8yfetcher.(*EntityIterator).GetNext(0x280a210, 0x765901, 0x280a210, 0x9105fc, 0x280a210, 0xa6cbf201, 0x0, 0x1c418)
    /home/runner/work/go-c8y-cli/go-c8y-cli/pkg/c8yfetcher/c8yfetcher.go:234 +0x34
github.com/reubenmiller/go-c8y-cli/pkg/flags.(*StringTemplate).Execute(0x27bc570, 0x5e700, 0x0, 0x0, 0x0, 0x245fd18, 0x0, 0x2884000, 0x0, 0x1, ...)
    /home/runner/work/go-c8y-cli/go-c8y-cli/pkg/flags/stringtemplate.go:77 +0x2e8
github.com/reubenmiller/go-c8y-cli/pkg/flags.(*StringTemplate).GetNext(0x27bc570, 0x245fd18, 0x0, 0x0, 0x1, 0x2884000, 0x0, 0x1)
    /home/runner/work/go-c8y-cli/go-c8y-cli/pkg/flags/stringtemplate.go:100 +0x38
github.com/reubenmiller/go-c8y-cli/pkg/requestiterator.(*RequestIterator).GetNext(0x28246c0, 0x7d9a97, 0x19, 0x2432e4c, 0x1, 0x1)
    /home/runner/work/go-c8y-cli/go-c8y-cli/pkg/requestiterator/requestiterator.go:86 +0xc6c
github.com/reubenmiller/go-c8y-cli/pkg/worker.(*Worker).runBatched.func1(0x27454c0, 0x2823110, 0x28102e0, 0x28246c0, 0x0, 0x0, 0x2745500, 0x0, 0x0, 0x1, ...)
    /home/runner/work/go-c8y-cli/go-c8y-cli/pkg/worker/worker.go:223 +0x100
created by github.com/reubenmiller/go-c8y-cli/pkg/worker.(*Worker).runBatched
    /home/runner/work/go-c8y-cli/go-c8y-cli/pkg/worker/worker.go:215 +0x368

I am able to run 'c8y software list' without getting the error.

reubenmiller commented 2 years ago

Hi @rafzal1078, thanks for the issue. This issue looks to be related to running on an ARM cpu running 32bit in golang. I'll continue my research and see if I can come up with a fix shortly.

reubenmiller commented 2 years ago

@rafzal1078 I have published a new release v2.7.1 which should fix it, though I don't have a 32 bit arm device on hand so I won't close the ticket until I have confirmation that it is really fixed.

Also I made a few tweaks to your bash script to show how it could be simplified a bit.

#!/bin/bash

# Check if someone has set a session already
if declare -p C8Y_SESSION >&/dev/null ; then
    # This allows the script to play nicely if you want to run set-session yourself on the console before
    # calling this script

    echo "Session is already set (via C8Y_SESSION env variable)"
    c8y sessions get
else
    echo "Use fixed credentials (set via env variables)"
    #
    # Docs: https://goc8ycli.netlify.app/docs/concepts/sessions/#continuous-integration-usage-environment-variables
    #
    export C8Y_HOST=""
    export C8Y_TENANT=""
    export C8Y_USERNAME=""
    export C8Y_PASSWORD=""
fi

# Disable all prompts and enable create/update/delete. Easier alternative rather than using c8y settings update mode.enableCreate 'true'
# docs: https://goc8ycli.netlify.app/docs/configuration/settings/#ci-boolean
export C8Y_SETTINGS_CI=true

install_software(){
    local software="$1"
    local version="$2"
    local device="$3"

    echo "Installing software: $name=$version on device ($device)"
    echo "$device" | c8y software versions install --software "$software" --version "$version"
}

#
# Main
#

#
# Case statements are a little easier to read then if/else in this situation
#
case "$1" in
    P)
        echo "Setting P software install"
        SOFTWARE="asdm_algorithm_stack_P"
        ;;

    Q)
        echo "Setting Q software install"
        SOFTWARE="asdm_algorithm_stack_Q"
        ;;

    *)
        echo "No software release type set"
        exit 1
        ;;
esac

#
# Select latest version (this relies on version sorting via gnu sort)
#
echo "Finding latest version of '$SOFTWARE'"
LATEST_VERSION=$(
    c8y software versions list \
        --software "$SOFTWARE" \
        --select "c8y_Software.version" \
        --includeAll \
        --output csv \
    | sort -Vr \
    | head -1
)

#
# Check if the latest version is defined, and cancel if not
#
if [ -z "$LATEST_VERSION" ]; then
    echo "Could not find the latest version for software package '$SOFTWARE'"
    exit 2
fi

#
# Update this part to do want you want. I just changed it so the 2nd script argument is the target device...
#
TARGET_DEVICE="$2"
install_software "$SOFTWARE" "$LATEST_VERSION" "$TARGET_DEVICE"
reubenmiller commented 2 years ago

Actually I was able to test it on an armel (arm32) bit and c8y v2.7.1 works now

I verified the bug in v2.7.0

user@device:~/tmp$ ./c8y_2.7.0 software versions list --software python3-c8yda -p 1
panic: unaligned 64-bit atomic operation

goroutine 11 [running]:
runtime/internal/atomic.panicUnaligned()
        /opt/hostedtoolcache/go/1.16.13/x64/src/runtime/internal/atomic/unaligned.go:8 +0x24
runtime/internal/atomic.Xadd64(0x137e504, 0x1, 0x0, 0x0, 0x1c64c)
        /opt/hostedtoolcache/go/1.16.13/x64/src/runtime/internal/atomic/asm_arm.s:233 +0x14
github.com/reubenmiller/go-c8y-cli/pkg/iterator.(*SliceIterator).GetNext(0x137e4f8, 0x8, 0x0, 0x4, 0x1c3b0, 0x19f74, 0x13c8400, 0x8)
        /home/runner/work/go-c8y-cli/go-c8y-cli/pkg/iterator/slice.go:16 +0x34
github.com/reubenmiller/go-c8y-cli/pkg/c8yfetcher.(*EntityIterator).GetNext(0x138e180, 0x775901, 0x138e180, 0x91fad4, 0x138e180, 0x1, 0x0, 0x0)
        /home/runner/work/go-c8y-cli/go-c8y-cli/pkg/c8yfetcher/c8yfetcher.go:234 +0x34
github.com/reubenmiller/go-c8y-cli/pkg/flags.(*StringTemplate).Execute(0x1340430, 0x5fa00, 0x0, 0x0, 0x0, 0x102ad18, 0x0, 0x13c83f8, 0x0, 0x1, ...)
        /home/runner/work/go-c8y-cli/go-c8y-cli/pkg/flags/stringtemplate.go:77 +0x2e8
github.com/reubenmiller/go-c8y-cli/pkg/flags.(*StringTemplate).GetNext(0x1340430, 0x102ad18, 0x0, 0x0, 0x1, 0x13c83f8, 0x0, 0x1)
        /home/runner/work/go-c8y-cli/go-c8y-cli/pkg/flags/stringtemplate.go:100 +0x38
github.com/reubenmiller/go-c8y-cli/pkg/requestiterator.(*RequestIterator).GetNext(0x1327c20, 0x7e9aba, 0x19, 0x102ae4c, 0x1, 0x1)
        /home/runner/work/go-c8y-cli/go-c8y-cli/pkg/requestiterator/requestiterator.go:86 +0xc60
github.com/reubenmiller/go-c8y-cli/pkg/worker.(*Worker).runBatched.func1(0x12db1c0, 0x13a8e78, 0x13961e0, 0x1327c20, 0x0, 0x0, 0x12db200, 0x0, 0x0, 0x1, ...)
        /home/runner/work/go-c8y-cli/go-c8y-cli/pkg/worker/worker.go:223 +0x100
created by github.com/reubenmiller/go-c8y-cli/pkg/worker.(*Worker).runBatched
        /home/runner/work/go-c8y-cli/go-c8y-cli/pkg/worker/worker.go:215 +0x368

And ran the same command in the new v2.7.1

user@device:~/tmp$ ./c8y_2.7.1 software versions list --software python3-c8yda -p 1
| additionParents.references.0.managedObject.additionParents.references | additionParents.references.0.managedObject.additionParents.self                |
|-----------------------------------------------------------------------|--------------------------------------------------------------------------------|
| []                                                                    | https://dummy-value.com/inventory/managedObjects/111111/addi… |
rafzal1078 commented 2 years ago

Thank you for the quick response, and improvements to my script. I will on my setup today.