|
|
5dc039 |
From 3424464d3e447308f171399302cf76eb573a618f Mon Sep 17 00:00:00 2001
|
|
|
5dc039 |
From: Reid wahl <nrwahl@protonmail.com>
|
|
|
5dc039 |
Date: Fri, 24 Jul 2020 18:22:24 -0700
|
|
|
5dc039 |
Subject: [PATCH] fence_lpar: Fix parse error from long command line
|
|
|
5dc039 |
|
|
|
5dc039 |
When Pacemaker executes `fence_lpar` and the HMC command line is greater
|
|
|
5dc039 |
than 80 characters, a parse error causes agent failure. This can happen
|
|
|
5dc039 |
with a long user name and/or long managed system name. It happens only
|
|
|
5dc039 |
when Pacemaker spawns the `fence_lpar` process; it does not happen when
|
|
|
5dc039 |
`fence_lpar` is run from the CLI.
|
|
|
5dc039 |
|
|
|
5dc039 |
A long command line gets a carriage return ('\r') added at the 80
|
|
|
5dc039 |
character mark and wraps back to the beginning of the line with no line
|
|
|
5dc039 |
feed ('\n'), overwriting the displayed characters. `fence_lpar`'s regex
|
|
|
5dc039 |
matches handle this fine when it's run from the command line.
|
|
|
5dc039 |
|
|
|
5dc039 |
The problem is that when Pacemaker spawns fence_lpar, **for some
|
|
|
5dc039 |
reason** there are backspace characters in the buffer when we hit the
|
|
|
5dc039 |
'\r' character. This seems to overwrite some of the `conn.before`
|
|
|
5dc039 |
string. As a result, the regex doesn't match `conn.before`, and the
|
|
|
5dc039 |
agent fails.
|
|
|
5dc039 |
|
|
|
5dc039 |
This patch works around the `conn.before` weirdness by reading and
|
|
|
5dc039 |
discarding the first received line **before** any regex processing.
|
|
|
5dc039 |
|
|
|
5dc039 |
Resolves: RHBZ#1860544
|
|
|
5dc039 |
Resolves: RHBZ#1860545
|
|
|
5dc039 |
|
|
|
5dc039 |
Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
|
|
|
5dc039 |
---
|
|
|
5dc039 |
agents/lpar/fence_lpar.py | 33 +++++++++++++++++++++++++++------
|
|
|
5dc039 |
1 file changed, 27 insertions(+), 6 deletions(-)
|
|
|
5dc039 |
|
|
|
5dc039 |
diff --git a/agents/lpar/fence_lpar.py b/agents/lpar/fence_lpar.py
|
|
|
5dc039 |
index 270bbe3b..9dfabc43 100644
|
|
|
5dc039 |
--- a/agents/lpar/fence_lpar.py
|
|
|
5dc039 |
+++ b/agents/lpar/fence_lpar.py
|
|
|
5dc039 |
@@ -19,6 +19,9 @@
|
|
|
5dc039 |
def get_power_status(conn, options):
|
|
|
5dc039 |
if options["--hmc-version"] == "3":
|
|
|
5dc039 |
conn.send("lssyscfg -r lpar -m " + options["--managed"] + " -n " + options["--plug"] + " -F name,state\n")
|
|
|
5dc039 |
+
|
|
|
5dc039 |
+ # First line (command) may cause parsing issues if long
|
|
|
5dc039 |
+ conn.readline()
|
|
|
5dc039 |
conn.log_expect(options["--command-prompt"], int(options["--power-timeout"]))
|
|
|
5dc039 |
|
|
|
5dc039 |
try:
|
|
|
5dc039 |
@@ -29,6 +32,9 @@ def get_power_status(conn, options):
|
|
|
5dc039 |
elif options["--hmc-version"] in ["4", "IVM"]:
|
|
|
5dc039 |
conn.send("lssyscfg -r lpar -m "+ options["--managed"] +
|
|
|
5dc039 |
" --filter 'lpar_names=" + options["--plug"] + "'\n")
|
|
|
5dc039 |
+
|
|
|
5dc039 |
+ # First line (command) may cause parsing issues if long
|
|
|
5dc039 |
+ conn.readline()
|
|
|
5dc039 |
conn.log_expect(options["--command-prompt"], int(options["--power-timeout"]))
|
|
|
5dc039 |
|
|
|
5dc039 |
try:
|
|
|
5dc039 |
@@ -49,6 +55,9 @@ def set_power_status(conn, options):
|
|
|
5dc039 |
if options["--hmc-version"] == "3":
|
|
|
5dc039 |
conn.send("chsysstate -o " + options["--action"] + " -r lpar -m " + options["--managed"]
|
|
|
5dc039 |
+ " -n " + options["--plug"] + "\n")
|
|
|
5dc039 |
+
|
|
|
5dc039 |
+ # First line (command) may cause parsing issues if long
|
|
|
5dc039 |
+ conn.readline()
|
|
|
5dc039 |
conn.log_expect(options["--command-prompt"], int(options["--power-timeout"]))
|
|
|
5dc039 |
elif options["--hmc-version"] in ["4", "IVM"]:
|
|
|
5dc039 |
if options["--action"] == "on":
|
|
|
5dc039 |
@@ -60,17 +69,23 @@ def set_power_status(conn, options):
|
|
|
5dc039 |
else:
|
|
|
5dc039 |
conn.send("chsysstate -o shutdown -r lpar --immed" +
|
|
|
5dc039 |
" -m " + options["--managed"] + " -n " + options["--plug"] + "\n")
|
|
|
5dc039 |
+
|
|
|
5dc039 |
+ # First line (command) may cause parsing issues if long
|
|
|
5dc039 |
+ conn.readline()
|
|
|
5dc039 |
conn.log_expect(options["--command-prompt"], int(options["--power-timeout"]))
|
|
|
5dc039 |
|
|
|
5dc039 |
def get_lpar_list(conn, options):
|
|
|
5dc039 |
outlets = {}
|
|
|
5dc039 |
if options["--hmc-version"] == "3":
|
|
|
5dc039 |
conn.send("query_partition_names -m " + options["--managed"] + "\n")
|
|
|
5dc039 |
+
|
|
|
5dc039 |
+ ## We have to remove first line (command)
|
|
|
5dc039 |
+ conn.readline()
|
|
|
5dc039 |
conn.log_expect(options["--command-prompt"], int(options["--power-timeout"]))
|
|
|
5dc039 |
|
|
|
5dc039 |
- ## We have to remove first 3 lines (command + header) and last line (part of new prompt)
|
|
|
5dc039 |
+ ## We have to remove next 2 lines (header) and last line (part of new prompt)
|
|
|
5dc039 |
####
|
|
|
5dc039 |
- res = re.search("^.+?\n(.+?\n){2}(.*)\n.*$", conn.before, re.S)
|
|
|
5dc039 |
+ res = re.search("^(.+?\n){2}(.*)\n.*$", conn.before, re.S)
|
|
|
5dc039 |
|
|
|
5dc039 |
if res == None:
|
|
|
5dc039 |
fail_usage("Unable to parse output of list command")
|
|
|
5dc039 |
@@ -81,11 +96,14 @@ def get_lpar_list(conn, options):
|
|
|
5dc039 |
elif options["--hmc-version"] == "4":
|
|
|
5dc039 |
conn.send("lssyscfg -r lpar -m " + options["--managed"] +
|
|
|
5dc039 |
" -F name:state\n")
|
|
|
5dc039 |
+
|
|
|
5dc039 |
+ ## We have to remove first line (command)
|
|
|
5dc039 |
+ conn.readline()
|
|
|
5dc039 |
conn.log_expect(options["--command-prompt"], int(options["--power-timeout"]))
|
|
|
5dc039 |
|
|
|
5dc039 |
- ## We have to remove first line (command) and last line (part of new prompt)
|
|
|
5dc039 |
+ ## We have to remove last line (part of new prompt)
|
|
|
5dc039 |
####
|
|
|
5dc039 |
- res = re.search("^.+?\n(.*)\n.*$", conn.before, re.S)
|
|
|
5dc039 |
+ res = re.search("^(.*)\n.*$", conn.before, re.S)
|
|
|
5dc039 |
|
|
|
5dc039 |
if res == None:
|
|
|
5dc039 |
fail_usage("Unable to parse output of list command")
|
|
|
5dc039 |
@@ -100,11 +118,14 @@ def get_lpar_list(conn, options):
|
|
|
5dc039 |
elif options["--hmc-version"] == "IVM":
|
|
|
5dc039 |
conn.send("lssyscfg -r lpar -m " + options["--managed"] +
|
|
|
5dc039 |
" -F name,state\n")
|
|
|
5dc039 |
+
|
|
|
5dc039 |
+ ## We have to remove first line (command)
|
|
|
5dc039 |
+ conn.readline()
|
|
|
5dc039 |
conn.log_expect(options["--command-prompt"], int(options["--power-timeout"]))
|
|
|
5dc039 |
|
|
|
5dc039 |
- ## We have to remove first line (command) and last line (part of new prompt)
|
|
|
5dc039 |
+ ## We have to remove last line (part of new prompt)
|
|
|
5dc039 |
####
|
|
|
5dc039 |
- res = re.search("^.+?\n(.*)\n.*$", conn.before, re.S)
|
|
|
5dc039 |
+ res = re.search("^(.*)\n.*$", conn.before, re.S)
|
|
|
5dc039 |
|
|
|
5dc039 |
if res == None:
|
|
|
5dc039 |
fail_usage("Unable to parse output of list command")
|