Skip to content

Commit ef6581e

Browse files
Project Collection Build Service (msazure)Project Collection Build Service (msazure)
authored andcommitted
Merge PR 6794666
2 parents 74ee252 + 5e57da6 commit ef6581e

File tree

7 files changed

+139
-11
lines changed

7 files changed

+139
-11
lines changed

.azure-pipelines/docker-sonic-slave-template.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ jobs:
3838
- job: Build_${{ parameters.dist }}_${{ parameters.march }}${{ parameters.arch }}
3939
timeoutInMinutes: 360
4040
variables:
41-
- template: .azure-pipelines/template-variables.yml@buildimage
42-
- template: .azure-pipelines/azure-pipelines-repd-build-variables.yml@buildimage
41+
- template: /.azure-pipelines/template-variables.yml@buildimage
42+
- template: /.azure-pipelines/azure-pipelines-repd-build-variables.yml@buildimage
4343
pool: ${{ parameters.pool }}
4444
steps:
4545
- template: cleanup.yml
46-
- template: .azure-pipelines/template-clean-sonic-slave.yml@buildimage
46+
- template: /.azure-pipelines/template-clean-sonic-slave.yml@buildimage
4747
- checkout: self
4848
clean: true
4949
submodules: recursive
@@ -62,7 +62,7 @@ jobs:
6262
exit 0
6363
fi
6464
65-
DOCKER_DATA_ROOT_FOR_MULTIARCH=/data/march/docker make configure PLATFORM=generic PLATFORM_ARCH=${{ parameters.arch }} $args || docker image ls $image_tag
65+
DOCKER_DATA_ROOT_FOR_MULTIARCH=/data/march/docker BLDENV=${{ parameters.dist }} make -f Makefile.work configure PLATFORM=generic PLATFORM_ARCH=${{ parameters.arch }} $args || docker image ls $image_tag
6666
if [[ "$(Build.Reason)" == "PullRequest" ]];then
6767
exit 0
6868
fi

build_debian.sh

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -480,10 +480,16 @@ rm /files/etc/ssh/sshd_config/ClientAliveInterval
480480
rm /files/etc/ssh/sshd_config/ClientAliveCountMax
481481
touch /files/etc/ssh/sshd_config/EmptyLineHack
482482
rename /files/etc/ssh/sshd_config/EmptyLineHack ""
483-
set /files/etc/ssh/sshd_config/ClientAliveInterval 900
483+
set /files/etc/ssh/sshd_config/ClientAliveInterval 300
484484
set /files/etc/ssh/sshd_config/ClientAliveCountMax 1
485485
ins #comment before /files/etc/ssh/sshd_config/ClientAliveInterval
486-
set /files/etc/ssh/sshd_config/#comment[following-sibling::*[1][self::ClientAliveInterval]] "Close inactive client sessions after 15 minutes"
486+
set /files/etc/ssh/sshd_config/#comment[following-sibling::*[1][self::ClientAliveInterval]] "Close inactive client sessions after 5 minutes"
487+
rm /files/etc/ssh/sshd_config/MaxAuthTries
488+
set /files/etc/ssh/sshd_config/MaxAuthTries 3
489+
rm /files/etc/ssh/sshd_config/LogLevel
490+
set /files/etc/ssh/sshd_config/LogLevel VERBOSE
491+
rm /files/etc/ssh/sshd_config/Banner
492+
set /files/etc/ssh/sshd_config/Banner /etc/issue
487493
save
488494
quit
489495
EOF

build_image.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ elif [ "$IMAGE_TYPE" = "aboot" ]; then
191191
zip -g $ABOOT_BOOT_IMAGE .imagehash
192192
rm .imagehash
193193
echo "SWI_VERSION=42.0.0" > version
194+
echo "BUILD_DATE=$(date -d "${build_date}" -u +%Y%m%dT%H%M%SZ)" >> version
194195
echo "SWI_MAX_HWEPOCH=2" >> version
195196
echo "SWI_VARIANT=US" >> version
196197
zip -g $OUTPUT_ABOOT_IMAGE version

platform/broadcom/sonic-platform-modules-cel/debian/platform-modules-haliburton.init

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,26 @@
1111
# Short-Description: Setup Haliburton board.
1212
### END INIT INFO
1313

14+
setup_swap () {
15+
SWAPFILE=/host/myswapfile
16+
17+
if [ ! -f $SWAPFILE ]; then
18+
availspace=`df -h --output=avail /host | sed '1d;s/\s//g;s/[^0-9].*//g'`
19+
diff=$(( availspace - 2*$1 ))
20+
if [ $diff -gt 0 ]; then
21+
fallocate -l ${1}G $SWAPFILE
22+
chmod 600 $SWAPFILE
23+
echo "swap file created successfully"
24+
else
25+
echo "not enough disk space to turn on swap."
26+
return
27+
fi
28+
fi
29+
mkswap $SWAPFILE
30+
swapon $SWAPFILE
31+
echo "swap on successfully"
32+
}
33+
1434
case "$1" in
1535
start)
1636
echo -n "Setting up board... "
@@ -74,6 +94,8 @@ start)
7494

7595
/bin/sh /usr/local/bin/platform_api_mgnt.sh init
7696

97+
setup_swap 2
98+
7799
echo "done."
78100
;;
79101

src/sonic-py-common/sonic_py_common/general.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import sys
2+
from subprocess import Popen, STDOUT, PIPE, CalledProcessError, check_output
23

34

45
def load_module_from_source(module_name, file_path):
@@ -23,3 +24,70 @@ def load_module_from_source(module_name, file_path):
2324
sys.modules[module_name] = module
2425

2526
return module
27+
28+
29+
def getstatusoutput_noshell(cmd):
30+
"""
31+
This function implements getstatusoutput API from subprocess module
32+
but using shell=False to prevent shell injection.
33+
Ref: https://github.com/python/cpython/blob/3.10/Lib/subprocess.py#L602
34+
"""
35+
try:
36+
output = check_output(cmd, universal_newlines=True, stderr=STDOUT)
37+
exitcode = 0
38+
except CalledProcessError as ex:
39+
output = ex.output
40+
exitcode = ex.returncode
41+
if output[-1:] == '\n':
42+
output = output[:-1]
43+
return exitcode, output
44+
45+
46+
def getstatusoutput_noshell_pipe(cmd0, *args):
47+
"""
48+
This function implements getstatusoutput API from subprocess module
49+
but using shell=False to prevent shell injection. Input command
50+
includes two or more commands connected by shell pipe(s).
51+
"""
52+
popens = [Popen(cmd0, stdout=PIPE, universal_newlines=True)]
53+
i = 0
54+
while i < len(args):
55+
popens.append(Popen(args[i], stdin=popens[i].stdout, stdout=PIPE, universal_newlines=True))
56+
popens[i].stdout.close()
57+
i += 1
58+
output = popens[-1].communicate()[0]
59+
if output[-1:] == '\n':
60+
output = output[:-1]
61+
62+
exitcodes = [0] * len(popens)
63+
while popens:
64+
last = popens.pop(-1)
65+
exitcodes[len(popens)] = last.wait()
66+
67+
return (exitcodes, output)
68+
69+
70+
def check_output_pipe(cmd0, *args):
71+
"""
72+
This function implements check_output API from subprocess module.
73+
Input command includes two or more commands connected by shell pipe(s)
74+
"""
75+
popens = [Popen(cmd0, stdout=PIPE, universal_newlines=True)]
76+
i = 0
77+
while i < len(args):
78+
popens.append(Popen(args[i], stdin=popens[i].stdout, stdout=PIPE, universal_newlines=True))
79+
popens[i].stdout.close()
80+
i += 1
81+
output = popens[-1].communicate()[0]
82+
83+
i = 0
84+
args_list = [cmd0] + list(args)
85+
while popens:
86+
current = popens.pop(0)
87+
exitcode = current.wait()
88+
if exitcode != 0:
89+
raise CalledProcessError(returncode=exitcode, cmd=args_list[i], output=current.stdout)
90+
i += 1
91+
92+
return output
93+
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import sys
2+
import pytest
3+
import subprocess
4+
from sonic_py_common.general import getstatusoutput_noshell, getstatusoutput_noshell_pipe, check_output_pipe
5+
6+
7+
def test_getstatusoutput_noshell(tmp_path):
8+
exitcode, output = getstatusoutput_noshell(['echo', 'sonic'])
9+
assert (exitcode, output) == (0, 'sonic')
10+
11+
exitcode, output = getstatusoutput_noshell([sys.executable, "-c", "import sys; sys.exit(6)"])
12+
assert exitcode != 0
13+
14+
def test_getstatusoutput_noshell_pipe():
15+
exitcode, output = getstatusoutput_noshell_pipe(['echo', 'sonic'], ['awk', '{print $1}'])
16+
assert (exitcode, output) == ([0, 0], 'sonic')
17+
18+
exitcode, output = getstatusoutput_noshell_pipe([sys.executable, "-c", "import sys; sys.exit(6)"], [sys.executable, "-c", "import sys; sys.exit(8)"])
19+
assert exitcode == [6, 8]
20+
21+
def test_check_output_pipe():
22+
output = check_output_pipe(['echo', 'sonic'], ['awk', '{print $1}'])
23+
assert output == 'sonic\n'
24+
25+
with pytest.raises(subprocess.CalledProcessError) as e:
26+
check_output_pipe([sys.executable, "-c", "import sys; sys.exit(6)"], [sys.executable, "-c", "import sys; sys.exit(0)"])
27+
assert e.returncode == [6, 0]
28+
29+
with pytest.raises(subprocess.CalledProcessError) as e:
30+
check_output_pipe([sys.executable, "-c", "import sys; sys.exit(0)"], [sys.executable, "-c", "import sys; sys.exit(6)"])
31+
assert e.returncode == [0, 6]

src/system-health/health_checker/service_checker.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,11 @@ def get_critical_process_list_from_file(self, container, critical_processes_file
127127
self.bad_containers.add(container)
128128
logger.log_error('Invalid syntax in critical_processes file of {}'.format(container))
129129
continue
130-
131-
identifier_key = match.group(2).strip()
132-
identifier_value = match.group(3).strip()
133-
if identifier_key == "program" and identifier_value:
134-
critical_process_list.append(identifier_value)
130+
if match.group(1) is not None:
131+
identifier_key = match.group(2).strip()
132+
identifier_value = match.group(3).strip()
133+
if identifier_key == "program" and identifier_value:
134+
critical_process_list.append(identifier_value)
135135

136136
return critical_process_list
137137

0 commit comments

Comments
 (0)