summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuan A. Suarez Romero <jasuarez@igalia.com>2021-01-07 10:33:03 +0100
committerMarge Bot <eric+marge@anholt.net>2021-01-23 05:35:24 +0000
commit8588fb65d65879791f747aa1b00895491caa80d3 (patch)
tree048820551d05e0b7a4b33d6c6100ade0dbd9c068
parent64fd191d8a88977067011d3727e32439e801d433 (diff)
vc4/ci: Replace expect script by python script
Replace the expect-based script to turn on/off the Raspberry Pi devices using a python-based script. v2: - Fix small nitpicks (Juan) - Limit line length (Andres) v3: - Bump image tags (Eric, Andres) v4: - Bump image tags (Eric) Signed-off-by: Juan A. Suarez Romero <jasuarez@igalia.com> Acked-by: Andres Gomez <agomez@igalia.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8362>
-rw-r--r--.gitlab-ci.yml6
-rwxr-xr-x.gitlab-ci/bare-metal/poe-off2
-rwxr-xr-x.gitlab-ci/bare-metal/poe-on2
-rwxr-xr-x.gitlab-ci/bare-metal/poe-set42
-rwxr-xr-x.gitlab-ci/bare-metal/poe-set.py129
-rw-r--r--.gitlab-ci/container/arm_test-base.sh1
6 files changed, 134 insertions, 48 deletions
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 6ebb88b0654..827d54c0492 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -391,7 +391,7 @@ arm_test-base:
- .fdo.container-build@debian
- .container
variables:
- MESA_IMAGE_TAG: &arm_test-base "2020-12-03-expect"
+ MESA_IMAGE_TAG: &arm_test-base "2021-01-21-noexpect"
.use-arm_test-base:
extends:
@@ -408,7 +408,7 @@ arm64_test:
extends:
- .use-arm_test-base
variables:
- MESA_IMAGE_TAG: &arm64_test "2020-01-13-piglit"
+ MESA_IMAGE_TAG: &arm64_test "2021-01-21-noexpect"
.use-arm64_test:
variables:
@@ -422,7 +422,7 @@ armhf_test:
extends:
- .use-arm_test-base
variables:
- MESA_IMAGE_TAG: &armhf_test "2020-01-13-piglit"
+ MESA_IMAGE_TAG: &armhf_test "2021-01-21-noexpect"
.use-armhf_test:
variables:
diff --git a/.gitlab-ci/bare-metal/poe-off b/.gitlab-ci/bare-metal/poe-off
index 88540f6cc7e..be6e2de78df 100755
--- a/.gitlab-ci/bare-metal/poe-off
+++ b/.gitlab-ci/bare-metal/poe-off
@@ -5,4 +5,4 @@ if [ -z "$BM_POE_INTERFACE" ]; then
exit 1
fi
-flock /var/run/poe.lock -c "$CI_PROJECT_DIR/install/bare-metal/poe-set $BM_POE_INTERFACE off"
+$CI_PROJECT_DIR/install/bare-metal/poe-set.py $BM_POE_INTERFACE off
diff --git a/.gitlab-ci/bare-metal/poe-on b/.gitlab-ci/bare-metal/poe-on
index d6f5c295349..380c3f2fcd1 100755
--- a/.gitlab-ci/bare-metal/poe-on
+++ b/.gitlab-ci/bare-metal/poe-on
@@ -5,4 +5,4 @@ if [ -z "$BM_POE_INTERFACE" ]; then
exit 1
fi
-flock /var/run/poe.lock -c "$CI_PROJECT_DIR/install/bare-metal/poe-set $BM_POE_INTERFACE reset"
+$CI_PROJECT_DIR/install/bare-metal/poe-set.py $BM_POE_INTERFACE reset
diff --git a/.gitlab-ci/bare-metal/poe-set b/.gitlab-ci/bare-metal/poe-set
deleted file mode 100755
index 627d7be493b..00000000000
--- a/.gitlab-ci/bare-metal/poe-set
+++ /dev/null
@@ -1,42 +0,0 @@
-#!/usr/bin/expect -f
-set SWITCHSERVER $env(BM_POE_ADDRESS)
-set USERNAME $env(BM_POE_USERNAME)
-set PASSWORD $env(BM_POE_PASSWORD)
-
-set PORTNUMBER [lindex $argv 0]
-set POESTATUS [lindex $argv 1]
-
-log_user 0
-
-spawn telnet $SWITCHSERVER
-expect "Login"
-sleep 1
-send "$USERNAME\t$PASSWORD\r"
-expect "Menu"
-send "\x01"
-expect ">"
-send "lcli\r"
-expect "Name:"
-send "$USERNAME\r"
-expect "Password:"
-send "$PASSWORD\r"
-expect "#"
-send "configure\r"
-expect "(config)#"
-send "interface GE $PORTNUMBER\r"
-expect "(config-if)#"
-if { "$POESTATUS" == "off" } {
- send "power inline never\r"
-} elseif { "$POESTATUS" == "on" } {
- send "power inline auto\r"
-} elseif { "$POESTATUS" == "reset" } {
- send "power inline never\r"
- send "power inline auto\r"
-}
-expect "(config-if)#"
-send "exit\r"
-expect "(config)#"
-send "exit\r"
-expect "$#"
-send "exit\r"
-expect eof
diff --git a/.gitlab-ci/bare-metal/poe-set.py b/.gitlab-ci/bare-metal/poe-set.py
new file mode 100755
index 00000000000..77e5d74d51c
--- /dev/null
+++ b/.gitlab-ci/bare-metal/poe-set.py
@@ -0,0 +1,129 @@
+#!/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()
diff --git a/.gitlab-ci/container/arm_test-base.sh b/.gitlab-ci/container/arm_test-base.sh
index 1d37a48f836..e7abafda44d 100644
--- a/.gitlab-ci/container/arm_test-base.sh
+++ b/.gitlab-ci/container/arm_test-base.sh
@@ -19,7 +19,6 @@ apt-get install -y --no-remove \
cmake \
cpio \
debootstrap \
- expect \
fastboot \
flex \
g++ \