-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added nt-discovery.sh to get information about host
Ticket: ENT-12576 Signed-off-by: Victor Moene <victor.moene@northern.tech>
- Loading branch information
Showing
5 changed files
with
193 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#!/bin/bash | ||
|
||
set -o pipefail | ||
|
||
run_command() { | ||
# $1: command to run | ||
# $2: variable name to store in / output | ||
# $3: custom error message (optional) | ||
result="$(bash -c "$1" 2>&1 | sed -e ':a' -e 'N' -e '$!ba' -e 's/\n/\\n/g' | sed -e 's/\"/\\"/g')" | ||
status=$? | ||
if [ "$status" -eq "0" ]; then | ||
echo "NTD_$2=\"$result\"" | ||
else | ||
echo "NTD_$2_CMD=\"$1\"" | ||
# custom output result | ||
if [ "$#" -eq "3" ]; then | ||
echo "NTD_$2_ERROR=\"$3\"" | ||
else | ||
echo "NTD_$2_ERROR=\"$result\"" | ||
fi | ||
fi | ||
} | ||
|
||
run_command "uname" "UNAME" | ||
run_command "uname -m" "ARCH" | ||
run_command "cat /etc/os-release" "OS_RELEASE" | ||
run_command "cat /etc/redhat-release" "REDHAT_RELEASE" | ||
|
||
# cf-agent | ||
|
||
cfagent_path=$(command -v cf-agent) | ||
|
||
if ! [ $? -eq "0" ]; then | ||
cfagent_path=$(command -v /var/cfengine/bin/cf-agent) | ||
|
||
if ! [ $? -eq "0" ]; then | ||
cfagent_path="cf-agent" | ||
fi | ||
fi | ||
|
||
run_command "command -v $cfagent_path" "CFAGENT_PATH" "Cannot find cf-agent" | ||
run_command "$cfagent_path --version" "CFAGENT_VERSION" | ||
run_command "cat /var/cfengine/policy_server.dat" "POLICY_SERVER" | ||
|
||
# packages | ||
|
||
run_command "echo $UID" "UID" | ||
run_command "command -v dpkg" "DPKG" "Cannot find dpkg" | ||
run_command "command -v rpm" "RPM" "Cannot find rpm" | ||
run_command "command -v yum" "YUM" "Cannot find yum" | ||
run_command "command -v apt" "APT" "Cannot find apt" | ||
run_command "command -v pkg" "PKG" "Cannot find pkg" | ||
run_command "command -v zypper" "ZYPPER" "Cannot find zypper" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from cf_remote.utils import has_unescaped_character, parse_envfile | ||
|
||
|
||
def test_parse_envfile(): | ||
data = parse_envfile('NTD_TEST="test"') | ||
assert "NTD_TEST" in data | ||
assert data["NTD_TEST"] == "test" | ||
|
||
data = parse_envfile('NTD_TEST="\\"helloworld\\""') | ||
assert data["NTD_TEST"] == '"helloworld"' | ||
|
||
data = parse_envfile('NTD_TEST=""helloworld""') | ||
assert data is None | ||
|
||
data = parse_envfile('NTD_TEST="\n"') | ||
assert data is None | ||
|
||
data = parse_envfile('NTD_TEST="\\nhello"') | ||
assert data["NTD_TEST"] == "\nhello" | ||
|
||
# 2 lines: | ||
data = parse_envfile('NTD_TEST="test"\nNTD_HELLO="hello"') | ||
assert len(data) == 2 | ||
assert data["NTD_TEST"] == "test" | ||
assert data["NTD_HELLO"] == "hello" | ||
# Empty value is allowed: | ||
data = parse_envfile('NTD_EMPTY=""') | ||
assert data["NTD_EMPTY"] == "" | ||
# Empty key is not allowed: | ||
assert parse_envfile('="value"') is None | ||
# Lowercase key not allowed: | ||
assert parse_envfile('NTD_key="value"') is None | ||
# Various cases of things which are not allowed: | ||
assert parse_envfile('') is None | ||
assert parse_envfile('=') is None | ||
assert parse_envfile('""=""') is None | ||
assert parse_envfile('=""') is None | ||
assert parse_envfile('""=') is None | ||
assert parse_envfile(' ') is None | ||
assert parse_envfile('NTD_TEST="NTD_TEST_TWO="test"\\nhello"') is None | ||
|
||
|
||
def test_has_unescaped_character(): | ||
assert not has_unescaped_character(r"test", '"') | ||
assert not has_unescaped_character(r"\"test\"", '"') | ||
assert has_unescaped_character(r'hello"world', '"') | ||
assert has_unescaped_character(r'hello\""world', '"') |