Skip to content

Commit

Permalink
Add new flag '--fun'. If set, the 'yes', 'no' in the compliant column…
Browse files Browse the repository at this point in the history
… of 'saptune note verify' is replaced by a smiley.

(jsc#SAPSOL-236)
  • Loading branch information
angelabriel committed Aug 19, 2024
1 parent a9f9802 commit 0499871
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 14 deletions.
4 changes: 2 additions & 2 deletions actions/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,13 +303,13 @@ Daemon control:
Tune system according to SAP and SUSE notes:
saptune [--format FORMAT] [--force-color] note ( list | verify | revertall | enabled | applied )
saptune [--format FORMAT] [--force-color] note ( apply | simulate | customise | create | edit | revert | show | delete ) NOTEID
saptune [--format FORMAT] [--force-color] note verify [--colorscheme SCHEME] [--show-non-compliant] [NOTEID|applied]
saptune [--format FORMAT] [--force-color] [--fun] note verify [--colorscheme SCHEME] [--show-non-compliant] [NOTEID|applied]
saptune [--format FORMAT] [--force-color] note rename NOTEID NEWNOTEID
Tune system for all notes applicable to your SAP solution:
saptune [--format FORMAT] [--force-color] solution ( list | verify | enabled | applied )
saptune [--format FORMAT] [--force-color] solution ( apply | simulate | customise | create | edit | revert | show | delete ) SOLUTIONNAME
saptune [--format FORMAT] [--force-color] solution change [--force] SOLUTIONNAME
saptune [--format FORMAT] [--force-color] solution verify [--colorscheme SCHEME] [--show-non-compliant] [SOLUTIONNAME]
saptune [--format FORMAT] [--force-color] [--fun] solution verify [--colorscheme SCHEME] [--show-non-compliant] [SOLUTIONNAME]
saptune [--format FORMAT] [--force-color] solution rename SOLUTIONNAME NEWSOLUTIONNAME
Staging control:
saptune [--format FORMAT] [--force-color] staging ( status | enable | disable | is-enabled | list )
Expand Down
29 changes: 27 additions & 2 deletions actions/actionsMatchtxt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,42 @@ staged Notes:
staged Solutions:
sapconf.service: not available
tuned.service: disabled/active (profile: '%s')
tuned.service: disabled/active (profile: 'balanced')
systemd system state: running
virtualization: %s
tuning: not tuned
Remember: if you wish to automatically activate the note's and solution's tuning options after a reboot, you must enable saptune.service by running:
'saptune service enable'.
`, "balanced", system.GetVirtStatus())
`, system.GetVirtStatus())

var saptuneStatMatchText = fmt.Sprintf(`
saptune.service: disabled/active
saptune package: 'undef'
configured version: '3'
enabled Solution: sol1 (simpleNote)
applied Solution:
additional enabled Notes: 900929
enabled Notes: 900929
applied Notes:
orphaned Overrides:
staging: disabled
staged Notes:
staged Solutions:
sapconf.service: not available
tuned.service: disabled/active (profile: '')
systemd system state: running
virtualization: %s
tuning: not tuned
Remember: if you wish to automatically activate the note's and solution's tuning options after a reboot, you must enable saptune.service by running:
'saptune service enable'.
`, system.GetVirtStatus())

var saptuneStat2MatchText = fmt.Sprintf(`
saptune.service: disabled/inactive
saptune package: 'undef'
configured version: '3'
Expand Down
6 changes: 5 additions & 1 deletion actions/serviceacts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,11 @@ func TestServiceActions(t *testing.T) {
tstwriter = &errExitbuffer
ServiceActionStatus(&buffer, sApp, saptuneVersion)
txt := buffer.String()
checkOut(t, txt, saptuneStatusMatchText)
if txt != saptuneStatusMatchText {
checkOut(t, txt, saptuneStatMatchText)
} else {
checkOut(t, txt, saptuneStatusMatchText)
}
errExOut := errExitbuffer.String()
if errExOut != "" {
t.Errorf("wrong text returned by ErrorExit: '%v' instead of ''\n", errExOut)
Expand Down
25 changes: 23 additions & 2 deletions actions/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ import (
"strings"
)

// define smiley for 'yes' and 'no' in 'verify'
var smileYes = '\U0001F60E'
var smileNo = '\U0001F61F'
var smileDash = '\U0001F611'

// define max column width
var fmtmax = 30

Expand Down Expand Up @@ -444,6 +449,9 @@ func colorPrint(format, compliant, colorScheme string) (string, string) {
if colCompl == "" {
colCompl = compliant
}
if system.IsFlagSet("fun") {
colCompl = funPrint(colCompl)
}
return colFormat, colCompl
}

Expand All @@ -470,6 +478,17 @@ func colorFormating(colCmpl, colNonCmpl, txt, compliant string) string {
return colFormat
}

// funPrint prints emojis instead of text in the 'compliant' column of 'verify'
func funPrint(txt string) string {
if strings.Contains(txt, "yes") {
txt = strings.Replace(txt, "yes", " "+string(smileYes), 1)
}
if strings.Contains(txt, "no") {
txt = strings.Replace(txt, "no ", " "+string(smileNo), 1)
}
return txt
}

// printTableRow prints one row of the table
// If needed the lines of the override column, the expected column and the
// actual column will be wrapped after 'fmtmax' characters
Expand Down Expand Up @@ -546,12 +565,13 @@ func printWrappedRow(writer io.Writer, wrappedElem map[string][]string, rowEleme
// printRow prints now the row of the table
func printRow(writer io.Writer, twist bool, cols []string, rowElements map[string]string) {
if rowElements["type"] == "verify" {
printVerifiedRow(twist, writer, rowElements, cols)
printVerifyRow(twist, writer, rowElements, cols)
} else {
printSimulateRow(twist, writer, rowElements, cols)
}
}

// printSimulateRow prints the 'simulate' row
func printSimulateRow(twist bool, writer io.Writer, rowElements map[string]string, cols []string) {
if twist {
fmt.Fprintf(writer, rowElements["colFormat"], rowElements["parameter"], cols[0], cols[1], cols[2], rowElements["comment"])
Expand All @@ -560,7 +580,8 @@ func printSimulateRow(twist bool, writer io.Writer, rowElements map[string]strin
}
}

func printVerifiedRow(twist bool, writer io.Writer, rowElements map[string]string, cols []string) {
// printVerifyRow prints the 'verify' row
func printVerifyRow(twist bool, writer io.Writer, rowElements map[string]string, cols []string) {
if twist {
fmt.Fprintf(writer, rowElements["colFormat"], rowElements["note"], rowElements["parameter"], cols[1], cols[2], cols[0], rowElements["compliant"])
} else {
Expand Down
4 changes: 2 additions & 2 deletions ospackage/usr/lib/supportconfig/plugins/saptune
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ set -u

function display_package_info() {
echo -e "\n#==[ Command ]======================================#"
echo -e "# rpm -q ${1}"
rpm -q "${1}"
echo -e "# rpm -qi ${1}"
rpm -qi "${1}"

echo -e "\n#==[ Command ]======================================#"
echo -e "# rpm -V ${1}"
Expand Down
15 changes: 10 additions & 5 deletions system/argsAndFlags.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func GetFlagVal(flag string) string {
func ParseCliArgs() ([]string, map[string]string) {
stArgs := []string{}
// supported flags
stFlags := map[string]string{"force": "false", "dryrun": "false", "help": "false", "version": "false", "show-non-compliant": "false", "format": "", "colorscheme": "", "non-compliance-check": "false", "notSupported": "", "force-color": "false"}
stFlags := map[string]string{"force": "false", "dryrun": "false", "help": "false", "version": "false", "show-non-compliant": "false", "format": "", "colorscheme": "", "non-compliance-check": "false", "notSupported": "", "force-color": "false", "fun": "false"}
skip := false
for i, arg := range os.Args {
if skip {
Expand Down Expand Up @@ -127,6 +127,8 @@ func handleSimpleFlags(arg string, flags map[string]string) {
flags["non-compliance-check"] = "true"
case "--force-color", "-force-color":
flags["force-color"] = "true"
case "--fun", "-fun":
flags["fun"] = "true"
default:
setUnsupportedFlag(arg, flags)
}
Expand Down Expand Up @@ -208,7 +210,8 @@ func chkGlobalSyntax(cmdLinePos map[string]int) bool {

// chkGlobalOpts checks for global options
// saptune --format FORMAT [--version|--help]
// saptune --force-color [--version|--help]
// saptune --force-color
// saptune --fun
// saptune --version or saptune --help
func chkGlobalOpts(cmdLinePos map[string]int) bool {
stArgs := os.Args
Expand Down Expand Up @@ -245,11 +248,13 @@ func chkGlobalOpts(cmdLinePos map[string]int) bool {
}

// check for '--version' or '-version'
ret, globOpt = chkGlobalFlag("version", stArgs[globPos], ret, globOpt)
// check for '--help' or '-help'
ret, globOpt = chkGlobalFlag("help", stArgs[globPos], ret, globOpt)
// check for '--force-color' or '-force-color'
ret, globOpt = chkGlobalFlag("force-color", stArgs[globPos], ret, globOpt)
// check for '--fun' or '-fun'
globalFlags := []string{"version", "help", "force-color", "fun"}
for _, gflag := range globalFlags {
ret, globOpt = chkGlobalFlag(gflag, stArgs[globPos], ret, globOpt)
}

if globOpt {
cmdLinePos["realm"] = cmdLinePos["realm"] + 1
Expand Down

0 comments on commit 0499871

Please sign in to comment.