mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2024-11-23 18:24:13 +08:00
ci/broadcom: use SNMP to turn on/off devices
So far we were using a telnet-based script to communicate with the PoE Switch to turn on/off the network ports the DUTs are connected. But this script does not seem very reliable because from time to time the switch fails to execute the steps in the script. As the PoE Switch we use is a smart one with support for SNMP protocol, it would be easier to use it to handle it, which allows to turn on/off the ports without going through the nasty telnet steps Acked-by: Michel Dänzer <mdaenzer@redhat.com> Reviewed-by: Jose Maria Casanova Crespo <jmcasanova@igalia.com> Signed-off-by: Juan A. Suarez Romero <jasuarez@igalia.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9954>
This commit is contained in:
parent
3720c6a6f6
commit
515ffe4af4
@ -474,7 +474,7 @@ arm_test:
|
||||
FDO_DISTRIBUTION_EXEC: 'env ARTIFACTS_PREFIX=https://${MINIO_HOST}/mesa-lava ARTIFACTS_SUFFIX=baremetal/${MESA_ROOTFS_TAG}--${MESA_ARM_BUILD_TAG}--${MESA_TEMPLATES_COMMIT} CI_PROJECT_PATH=${CI_PROJECT_PATH} FDO_CI_CONCURRENT=${FDO_CI_CONCURRENT} FDO_UPSTREAM_REPO=${FDO_UPSTREAM_REPO} bash .gitlab-ci/container/${CI_JOB_NAME}.sh'
|
||||
FDO_DISTRIBUTION_TAG: "${MESA_IMAGE_TAG}--${MESA_ROOTFS_TAG}--${MESA_ARM_BUILD_TAG}--${MESA_TEMPLATES_COMMIT}"
|
||||
MESA_ARM_BUILD_TAG: *arm_build
|
||||
MESA_IMAGE_TAG: &arm_test "2021-03-31-unified"
|
||||
MESA_IMAGE_TAG: &arm_test "2021-04-06-snmp"
|
||||
MESA_ROOTFS_TAG: *arm-baremetal
|
||||
|
||||
.use-arm_test:
|
||||
|
@ -1,8 +1,17 @@
|
||||
#!/bin/bash
|
||||
|
||||
if [ -z "$BM_POE_INTERFACE" ]; then
|
||||
echo "Must supply the PoE Interface to power off"
|
||||
echo "Must supply the PoE Interface to power up"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
$CI_PROJECT_DIR/install/bare-metal/poe-set.py $BM_POE_INTERFACE off
|
||||
if [ -z "$BM_POE_ADDRESS" ]; then
|
||||
echo "Must supply the PoE Switch host"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
SNMP_KEY="SNMPv2-SMI::mib-2.105.1.1.1.3.1.`expr 48 + $BM_POE_INTERFACE`"
|
||||
SNMP_ON="i 1"
|
||||
SNMP_OFF="i 2"
|
||||
|
||||
flock /var/run/poe.lock -c "snmpset -v2c -r 3 -t 30 -cmesaci $BM_POE_ADDRESS $SNMP_KEY $SNMP_OFF"
|
||||
|
@ -5,4 +5,15 @@ if [ -z "$BM_POE_INTERFACE" ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
$CI_PROJECT_DIR/install/bare-metal/poe-set.py $BM_POE_INTERFACE reset
|
||||
if [ -z "$BM_POE_ADDRESS" ]; then
|
||||
echo "Must supply the PoE Switch host"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
SNMP_KEY="SNMPv2-SMI::mib-2.105.1.1.1.3.1.`expr 48 + $BM_POE_INTERFACE`"
|
||||
SNMP_ON="i 1"
|
||||
SNMP_OFF="i 2"
|
||||
|
||||
flock /var/run/poe.lock -c "snmpset -v2c -r 3 -t 30 -cmesaci $BM_POE_ADDRESS $SNMP_KEY $SNMP_OFF"
|
||||
sleep 3s
|
||||
flock /var/run/poe.lock -c "snmpset -v2c -r 3 -t 30 -cmesaci $BM_POE_ADDRESS $SNMP_KEY $SNMP_ON"
|
||||
|
@ -1,129 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# Copyright © 2021 Igalia, S.L.
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a
|
||||
# copy of this software and associated documentation files (the "Software"),
|
||||
# to deal in the Software without restriction, including without limitation
|
||||
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
# and/or sell copies of the Software, and to permit persons to whom the
|
||||
# Software is furnished to do so, subject to the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice (including the next
|
||||
# paragraph) shall be included in all copies or substantial portions of the
|
||||
# Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
# IN THE SOFTWARE.
|
||||
|
||||
import argparse
|
||||
import fcntl
|
||||
import os
|
||||
import telnetlib
|
||||
import time
|
||||
|
||||
class Telnet:
|
||||
def __init__(self, args):
|
||||
self.retries = 3
|
||||
self.lock_file = "/var/run/poe.lock"
|
||||
self.debug = args.debug
|
||||
self.lock = None
|
||||
self.tn = None
|
||||
try:
|
||||
self.host = os.environ['BM_POE_ADDRESS']
|
||||
self.username = os.environ['BM_POE_USERNAME'].encode('ascii')
|
||||
self.password = os.environ['BM_POE_PASSWORD'].encode('ascii')
|
||||
except KeyError as k:
|
||||
raise OSError("envvar " + str(k) + " undefined")
|
||||
|
||||
def login(self):
|
||||
# Sometimes login fails; retry 3 times before aborting
|
||||
logged = False
|
||||
for retry in range(self.retries):
|
||||
self.lock = open(self.lock_file, 'w')
|
||||
fcntl.flock(self.lock, fcntl.LOCK_EX)
|
||||
self.tn = telnetlib.Telnet(self.host)
|
||||
self.tn.set_debuglevel(1 if self.debug else 0)
|
||||
self.tn.read_until(b'Password:')
|
||||
self.tn.write(self.username + b'\t' + self.password + b'\r')
|
||||
w = self.tn.read_until(b'Back', 3).decode('ascii')
|
||||
if w.endswith("Back"):
|
||||
logged = True
|
||||
break
|
||||
self.tn.close()
|
||||
self.lock.close()
|
||||
time.sleep(3)
|
||||
|
||||
if not logged:
|
||||
raise OSError("Can not log in")
|
||||
|
||||
self.tn.write(b'\x01')
|
||||
self.tn.read_until(b'>')
|
||||
self.tn.write(b'lcli\r')
|
||||
self.tn.read_until(b'User Name:')
|
||||
self.tn.write(self.username + b'\r')
|
||||
self.tn.read_until(b'Password:')
|
||||
self.tn.write(self.password + b'\r')
|
||||
self.tn.read_until(b'#')
|
||||
|
||||
def logout(self):
|
||||
self.lock.close()
|
||||
self.tn.close()
|
||||
|
||||
def select_port(self, port):
|
||||
self.tn.write(b'configure\r')
|
||||
self.tn.read_until(b'#')
|
||||
|
||||
self.tn.write(b'interface GE ' + str(port).encode('ascii') + b'\r')
|
||||
self.tn.read_until(b'#')
|
||||
|
||||
def poe_on(self):
|
||||
self.tn.write(b'power inline auto\r')
|
||||
self.tn.read_until(b'#')
|
||||
|
||||
def poe_off(self):
|
||||
self.tn.write(b'power inline never\r')
|
||||
self.tn.read_until(b'#')
|
||||
|
||||
def poe_reset(self):
|
||||
self.poe_off()
|
||||
time.sleep(3)
|
||||
self.poe_on()
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description='Powers on/off switch port')
|
||||
parser.add_argument('-d', '--debug',
|
||||
action='store_true',
|
||||
help='Enable debug')
|
||||
parser.add_argument('port',
|
||||
type=int,
|
||||
help='Port to turn on/off')
|
||||
parser.add_argument('operation',
|
||||
choices=['on', 'off', 'reset'],
|
||||
help='Operation to perform')
|
||||
args = parser.parse_args()
|
||||
|
||||
try:
|
||||
telnet = Telnet(args)
|
||||
|
||||
telnet.login()
|
||||
|
||||
telnet.select_port(args.port)
|
||||
if args.operation == "on":
|
||||
telnet.poe_on()
|
||||
elif args.operation == "off":
|
||||
telnet.poe_off()
|
||||
elif args.operation == "reset":
|
||||
telnet.poe_reset()
|
||||
|
||||
telnet.logout()
|
||||
except Exception as e:
|
||||
print("Error! " + str(e))
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
@ -55,7 +55,6 @@ class PoERun:
|
||||
|
||||
if not boot_detected:
|
||||
self.print_error("Something wrong; couldn't detect the boot start up sequence")
|
||||
self.logged_system(self.powerdown)
|
||||
return 2
|
||||
|
||||
for line in self.ser.lines():
|
||||
|
@ -20,7 +20,7 @@ apt-get install -y --no-remove \
|
||||
python3-serial \
|
||||
python3.7 \
|
||||
rsync \
|
||||
telnet \
|
||||
snmp \
|
||||
unzip \
|
||||
wget
|
||||
|
||||
@ -28,5 +28,9 @@ apt-get install -y --no-remove \
|
||||
sed -i '/gzip_/ s/#\ //g' /etc/nginx/nginx.conf
|
||||
cp .gitlab-ci/bare-metal/nginx-default-site /etc/nginx/sites-enabled/default
|
||||
|
||||
# setup SNMPv2 SMI MIB
|
||||
wget https://raw.githubusercontent.com/net-snmp/net-snmp/master/mibs/SNMPv2-SMI.txt \
|
||||
-O /usr/share/snmp/mibs/SNMPv2-SMI.txt
|
||||
|
||||
arch=arm64 . .gitlab-ci/container/baremetal_build.sh
|
||||
arch=armhf . .gitlab-ci/container/baremetal_build.sh
|
||||
|
Loading…
Reference in New Issue
Block a user