Skip to content

Commit

Permalink
[sonic-netns-exec]: use "$@" to reflects all positional parameters as…
Browse files Browse the repository at this point in the history
… they were set initially (#4375)

sonic-netns-exec fails to execute below command in swss.sh:

    sonic-netns-exec "$NET_NS" sonic-db-cli $1 EVAL "
    local tables = {$2}
    for i = 1, table.getn(tables) do
        local matches = redis.call('KEYS', tables[i])
        for j,name in ipairs(matches) do
            redis.call('DEL', name)
        end
    end" 0

This command fails with error " redis.exceptions.ResponseError: value is not an integer or out of range" .

Root cause:

When sonic-netns-exec executes the above function, argument passed to sonic-db-cli is NOT executed as a single script.

The argument is passed as separate keywords to sonic-db-cli, as below:

['EVAL', 'local', 'tables', '=', "{'PORT_TABLE*'}", 'for', 'i', '=', '1,', 'table.getn(tables)', 'do', 'local', 'matches', '=', "redis.call('KEYS',", 'tables[i])', 'for', 'j,name', 'in', 'ipairs(matches)', 'do', "redis.call('DEL',", 'name)', 'end', 'end', '0']

- How I did it
To make sure that the parameters are passed as they were set initially, fix sonic-netns-exec to use double quoted "$@", where "$@" is "$1" "$2" "$3" ... "${N}"

After fix, the argument passed to sonic-db-cli is as below:

Argument passed to sonic-db-cli:

['EVAL', "\n    local tables = {'PORT_TABLE*'}\n    for i = 1, table.getn(tables) do\n        local matches = redis.call('KEYS', tables[i])\n        for j,name in ipairs(matches) do\n            redis.call('DEL', name)\n        end\n    end", '0']

Signed-off-by: SuvarnaMeenakshi <sumeenak@microsoft.com>
  • Loading branch information
SuvarnaMeenakshi authored Apr 7, 2020
1 parent 7bc8f12 commit 2a59551
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions files/scripts/sonic-netns-exec
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
# sonic-netns-exec <namespace name> <command to be executed>
NS="$1"
shift
if [ "$NS" != "" ]; then
ip netns exec $NS $@
if [ ! -z "$NS" ]; then
ip netns exec $NS "$@"
else
$@
"$@"
fi

0 comments on commit 2a59551

Please sign in to comment.