Skip to content

Commit

Permalink
Merge pull request #93 from angelabriel/master
Browse files Browse the repository at this point in the history
Fix problems found by the test
  • Loading branch information
angelabriel authored Aug 9, 2022
2 parents 1dcfece + 40e0dcb commit 9cf9161
Show file tree
Hide file tree
Showing 95 changed files with 3,056 additions and 575 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/saptune-ut.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ name: saptuneUnittst
on:
# Triggers the workflow on pull request events but only for the master and sle-12 branch
push:
branches: [ saptune_test ]
branches: [ master, saptune_test ]
pull_request:
branches: [ master ]

Expand Down Expand Up @@ -54,7 +54,7 @@ jobs:

- name: Code Climate report coverage
run: ./cc-test-reporter after-build --debug --prefix ${{ env.CC_PREFIX }} --exit-code $?
if: github.event_name != 'pull_request'
if: ${{ env.CC_TEST_REPORTER_ID }}

- name: Stop and remove Docker Image
run: |
Expand Down
22 changes: 17 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

[![Build Status](https://travis-ci.org/SUSE/saptune.svg?branch=master)](https://travis-ci.org/SUSE/saptune)
[![Build Status](https://github.com/SUSE/saptune/actions/workflows/saptune-ut.yml/badge.svg)](https://github.com/SUSE/saptune/actions/workflows/saptune-ut.yml/badge.svg)
[![Test Coverage](https://api.codeclimate.com/v1/badges/5375e2ca293dd0e8b322/test_coverage)](https://codeclimate.com/github/SUSE/saptune/test_coverage)
[![Maintainability](https://api.codeclimate.com/v1/badges/5375e2ca293dd0e8b322/maintainability)](https://codeclimate.com/github/SUSE/saptune/maintainability)

Expand Down Expand Up @@ -47,7 +47,7 @@ They give our administrators and our partners a simple way to implement their ow

# Migration:

Guide to help you migrate to the new saptune\
Guide to help you migrate from saptune running version <b>1</b> to the saptune version 2 or 3\
Migration? Isn’t a simple package update enough?

Not in every case.
Expand All @@ -57,8 +57,18 @@ If the update discovers applied saptune SAP notes or solutions, saptune will con
The switch to version 2 has to be done deliberately.\
To help you, we will provide a step-by-step guide. Just plan your switch when you are ready, no rush!

We will support saptune version 1 until end of the lifetime of SLES 12 / SLES 15 SP1, which should give enough time to move. Although please bear in mind that since saptune version 1 will be deprecated, we will only do bug fixing. New features, new SAP notes or new parameters will only be done for version 2!
We will support saptune version 1 until end of the lifetime of SLES 12 / SLES 15 SP1, which should give enough time to move. Although please bear in mind that since saptune version 1 will be deprecated, we will only do bug fixing. New features, new SAP notes or new parameters will only be done for future versions of saptune!

With saptune version 3 the support for version 1 is <b>abandoned</b>.
If the migration from version 1 to version 2 or 3 was not done before the package update, saptune will not work and that's expected.
But all needed files for the migration are still available, so following the procedure described in the man page saptune-migrate(7) will bring you back to a working saptune.

For the update from version 2 to version 3 <b>NO</b> migration is needed.

But as we discontinued the use of tuned to get the tuning started during boot and instead use our own systemd service <b>saptune.service</b> we will need to stop the tuning of the system during the package update for a short timeframe to avoid tuned error messages.

If you are used to start saptune using tuned directly in the past, please move to <b>'saptune service start'</b> instead.
If you use <b>'saptune daemon start'</b>, you will now get a 'deprecated' warning, but the command will still continue to work.

# Where to find documentation?

Expand All @@ -68,12 +78,14 @@ When the technical blog series about the details of saptune and how to do a migr
For now:\
<https://www.suse.com/c/a-new-saptune-is-knocking-on-your-door/>\
<https://www.suse.com/c/a-new-saptune-is-here/>\
<https://www.suse.com/c/saptune-a-deep-dive/>
<https://www.suse.com/c/saptune-a-deep-dive/>\
<https://www.suse.com/c/saptune-3-is-on-the-horizon/>\
<https://www.suse.com/c/saptune-3-is-here/>


# Feedback

Supporters, contributors, colleagues, customers and partners are welcome to approach us with ideas and suggestions. If you miss something or you think something should be done better, then don’t hesitate to contact us. You are welcome to give further feedback via email at SapAlliance@suse.com, create an issue in this repository, carrier pigeon etc. and tell us your needs.\
Supporters, contributors, colleagues, customers and partners are welcome to approach us with ideas and suggestions. If you miss something or you think something should be done better, then don’t hesitate to contact us. You are welcome to give further feedback via email at sapalliance@suse.com, create an issue in this repository, carrier pigeon etc. and tell us your needs.\
With each new version of saptune we implement many of them, but the journey will continue and you can expect further enhancements in the future.


Expand Down
23 changes: 14 additions & 9 deletions actions/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ var dfltColorScheme = "full-red-noncmpl"

// SelectAction selects the chosen action depending on the first command line
// argument
func SelectAction(stApp *app.App, saptuneVers string) {
func SelectAction(writer io.Writer, stApp *app.App, saptuneVers string) {
// switch off color and highlighting, if Stdout is not a terminal
switchOffColor()
system.JnotSupportedYet()
Expand All @@ -86,21 +86,21 @@ func SelectAction(stApp *app.App, saptuneVers string) {

switch system.CliArg(1) {
case "daemon":
DaemonAction(os.Stdout, system.CliArg(2), saptuneVers, stApp)
DaemonAction(writer, system.CliArg(2), saptuneVers, stApp)
case "service":
ServiceAction(system.CliArg(2), saptuneVers, stApp)
ServiceAction(writer, system.CliArg(2), saptuneVers, stApp)
case "note":
NoteAction(system.CliArg(2), system.CliArg(3), system.CliArg(4), stApp)
NoteAction(writer, system.CliArg(2), system.CliArg(3), system.CliArg(4), stApp)
case "solution":
SolutionAction(system.CliArg(2), system.CliArg(3), system.CliArg(4), stApp)
SolutionAction(writer, system.CliArg(2), system.CliArg(3), system.CliArg(4), stApp)
case "revert":
RevertAction(os.Stdout, system.CliArg(2), stApp)
RevertAction(writer, system.CliArg(2), stApp)
case "staging":
StagingAction(system.CliArg(2), system.CliArgs(3), stApp)
case "status":
ServiceAction("status", saptuneVers, stApp)
ServiceAction(writer, "status", saptuneVers, stApp)
default:
PrintHelpAndExit(os.Stdout, 1)
PrintHelpAndExit(writer, 1)
}
}

Expand Down Expand Up @@ -139,15 +139,20 @@ func rememberMessage(writer io.Writer) {

// VerifyAllParameters Verify that all system parameters do not deviate from any of the enabled solutions/notes.
func VerifyAllParameters(writer io.Writer, tuneApp *app.App) {
result := system.JPNotes{}
if len(tuneApp.NoteApplyOrder) == 0 {
fmt.Fprintf(writer, "No notes or solutions enabled, nothing to verify.\n")
} else {
unsatisfiedNotes, comparisons, err := tuneApp.VerifyAll()
if err != nil {
system.ErrorExit("Failed to inspect the current system: %v", err)
}
PrintNoteFields(writer, "NONE", comparisons, true)
PrintNoteFields(writer, "NONE", comparisons, true, &result)
tuneApp.PrintNoteApplyOrder(writer)
result.NotesOrder = tuneApp.NoteApplyOrder
sysComp := len(unsatisfiedNotes) == 0
result.SysCompliance = &sysComp
system.Jcollect(result)
if len(unsatisfiedNotes) == 0 {
fmt.Fprintf(writer, "%s%sThe running system is currently well-tuned according to all of the enabled notes.%s%s\n", setGreenText, setBoldText, resetBoldText, resetTextColor)
} else {
Expand Down
112 changes: 112 additions & 0 deletions actions/actionsMatchtxt_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
package actions

import (
"fmt"
"github.com/SUSE/saptune/system"
)

var noteListMatchText = `
All notes (+ denotes manually enabled notes, * denotes notes enabled by solutions, - denotes notes enabled by solutions but reverted manually later, O denotes override file exists for note, C denotes custom note):
900929 Linux: STORAGE_PARAMETERS_WRONG_SET and 'mmap() failed'
Version 7 from 31.07.2017
https://launchpad.support.sap.com/#/notes/900929
NEWSOL2NOTE
extraNote Configuration drop in for extra tests
Version 0 from 04.06.2019
oldFile Name_syntax
simpleNote Configuration drop in for simple tests
Version 1 from 09.07.2019
wrongFileNamesyntax
Remember: if you wish to automatically activate the solution's tuning options after a reboot, you must enable and start saptune.service by running:
saptune service enablestart
`

var solutionListMatchText = `
All solutions (* denotes enabled solution, O denotes override file exists for solution, C denotes custom solutions, D denotes deprecated solutions):
BWA - SAP_BWA
HANA - 941735 1771258 1980196 1984787 2205917 2382421 2534844
MAXDB - 941735 1771258 1984787
NETW - 941735 1771258 1980196 1984787 2534844
Remember: if you wish to automatically activate the solution's tuning options after a reboot, you must enable and start saptune.service by running:
saptune service enablestart
`

var saptuneStatusMatchText = fmt.Sprintf(`
saptune.service: disabled/active
saptune package: 'undef'
configured version: '3'
enabled Solution: sol1 (simpleNote)
applied Solution:
additional enabled Notes: 2205917
enabled Notes: 2205917
applied Notes:
staging: disabled
staged Notes:
staged Solutions:
sapconf.service: not available
tuned.service: disabled/active (profile: '%s')
system state: running
virtualization: %s
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.GetTunedAdmProfile(), system.GetVirtStatus())

var saptuneStatMatchText = fmt.Sprintf(`
saptune.service: disabled/inactive
saptune package: 'undef'
configured version: '3'
enabled Solution:
applied Solution:
additional enabled Notes:
enabled Notes:
applied Notes:
staging: disabled
staged Notes:
staged Solutions:
sapconf.service: not available
tuned.service: disabled/active (profile: '%s')
system state: running
virtualization: %s
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 enablestart'.
Your system has not yet been tuned. Please visit `+"`"+`saptune note`+"`"+` and `+"`"+`saptune solution`+"`"+` to start tuning.
`, system.GetTunedAdmProfile(), system.GetVirtStatus())

var PrintHelpAndExitMatchText = `saptune: Comprehensive system optimisation management for SAP solutions.
Daemon control:
saptune daemon [ start | status | stop ] ATTENTION: deprecated
saptune service [ start | status | stop | restart | takeover | enable | disable | enablestart | disablestop ]
Tune system according to SAP and SUSE notes:
saptune note [ list | revertall | enabled | applied ]
saptune note [ apply | simulate | customise | create | edit | revert | show | delete ] NoteID
saptune note verify [--colorscheme=<color scheme>] [--show-non-compliant] [NoteID]
saptune note rename NoteID newNoteID
Tune system for all notes applicable to your SAP solution:
saptune solution [ list | verify | enabled | applied ]
saptune solution [ apply | simulate | verify | customise | create | edit | revert | show | delete ] SolutionName
saptune solution rename SolutionName newSolutionName
Staging control:
saptune staging [ status | enable | disable | is-enabled | list | diff | analysis | release ]
saptune staging [ analysis | diff ] [ NoteID... | SolutionID... | all ]
saptune staging release [--force|--dry-run] [ NoteID... | SolutionID... | all ]
Revert all parameters tuned by the SAP notes or solutions:
saptune revert all
Remove the pending lock file from a former saptune call
saptune lock remove
Call external script '/usr/sbin/saptune_check'
saptune check
Print current saptune status:
saptune status
Print current saptune version:
saptune version
Print this message:
saptune help
`
84 changes: 19 additions & 65 deletions actions/actions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ import (

var SolutionSheetsInGOPATH = path.Join(os.Getenv("GOPATH"), "/src/github.com/SUSE/saptune/testdata/sol/sols") + "/"
var ExtraFilesInGOPATH = path.Join(os.Getenv("GOPATH"), "/src/github.com/SUSE/saptune/testdata/extra") + "/"
var ExtraTstFilesInGOPATH = path.Join(os.Getenv("GOPATH"), "/src/github.com/SUSE/saptune/testdata/etc/saptune/extra") + "/"
var OverTstFilesInGOPATH = path.Join(os.Getenv("GOPATH"), "/src/github.com/SUSE/saptune/testdata/etc/saptune/override") + "/"
var DeprecFilesInGOPATH = path.Join(os.Getenv("GOPATH"), "/src/github.com/SUSE/saptune/testdata/sol/deprecated") + "/"
var TstFilesInGOPATH = path.Join(os.Getenv("GOPATH"), "/src/github.com/SUSE/saptune/testdata/")
var TstFilesInGOPATH = path.Join(os.Getenv("GOPATH"), "/src/github.com/SUSE/saptune/testdata") + "/"

var AllTestSolutions = map[string]solution.Solution{
"sol1": {"simpleNote"},
Expand All @@ -40,6 +41,18 @@ var tstErrorExitOut = func(str string, out ...interface{}) error {
return fmt.Errorf(str+"\n", out...)
}

var switchOnColor = func(t *testing.T) {
setGreenText = "\033[32m"
setRedText = "\033[31m"
setYellowText = "\033[33m"
setBlueText = "\033[34m"
setBoldText = "\033[1m"
resetBoldText = "\033[22m"
setStrikeText = "\033[9m"
resetTextColor = "\033[0m"
dfltColorScheme = "full-red-noncmpl"
}

var checkOut = func(t *testing.T, got, want string) {
t.Helper()
if got != want {
Expand Down Expand Up @@ -118,39 +131,9 @@ Parameters tuned by the notes and solutions have been successfully reverted.
// this errExitMatchText differs from the 'real' text by the last 2 lines
// because of test situation, the 'exit 1' in PrintHelpAndExit is not
// executed (as designed for testing)
errExitMatchText := fmt.Sprintf(`saptune: Comprehensive system optimisation management for SAP solutions.
Daemon control:
saptune daemon [ start | status | stop ] ATTENTION: deprecated
saptune service [ start | status | stop | restart | takeover | enable | disable | enablestart | disablestop ]
Tune system according to SAP and SUSE notes:
saptune note [ list | revertall | enabled | applied ]
saptune note [ apply | simulate | customise | create | edit | revert | show | delete ] NoteID
saptune note verify [--colorscheme=<color scheme>] [--show-non-compliant] [NoteID]
saptune note rename NoteID newNoteID
Tune system for all notes applicable to your SAP solution:
saptune solution [ list | verify | enabled | applied ]
saptune solution [ apply | simulate | verify | customise | create | edit | revert | show | delete ] SolutionName
saptune solution rename SolutionName newSolutionName
Staging control:
saptune staging [ status | enable | disable | is-enabled | list | diff | analysis | release ]
saptune staging [ analysis | diff ] [ NoteID... | SolutionID... | all ]
saptune staging release [--force|--dry-run] [ NoteID... | SolutionID... | all ]
Revert all parameters tuned by the SAP notes or solutions:
saptune revert all
Remove the pending lock file from a former saptune call
saptune lock remove
Call external script '/usr/sbin/saptune_check'
saptune check
Print current saptune status:
saptune status
Print current saptune version:
saptune version
Print this message:
saptune help
Reverting all notes and solutions, this may take some time...
errExitMatchText := PrintHelpAndExitMatchText + `Reverting all notes and solutions, this may take some time...
Parameters tuned by the notes and solutions have been successfully reverted.
`)

`
buffer.Reset()
// reset tApp variables, which were deleted by 'revert all'
tearDown(t)
Expand Down Expand Up @@ -206,7 +189,7 @@ func TestGetFileName(t *testing.T) {
// test with non-existing extra note
nID = "hugo"
getFnameMatchText := fmt.Sprintf("ERROR: Note %s not found in %s or %s.\n", nID, "", ExtraFilesInGOPATH)
fname, extra = getFileName(nID, "", ExtraFilesInGOPATH)
_, _ = getFileName(nID, "", ExtraFilesInGOPATH)
if tstRetErrorExit != 1 {
t.Errorf("error exit should be '1' and NOT '%v'\n", tstRetErrorExit)
}
Expand All @@ -215,7 +198,7 @@ func TestGetFileName(t *testing.T) {
}

func TestReadYesNo(t *testing.T) {
yesnoMatchText := fmt.Sprintf("Answer is [y/n]: ")
yesnoMatchText := "Answer is [y/n]: "
buffer := bytes.Buffer{}
input := "yes\n"
if !readYesNo("Answer is", strings.NewReader(input), &buffer) {
Expand All @@ -242,36 +225,7 @@ func TestPrintHelpAndExit(t *testing.T) {
defer func() { system.ErrorExitOut = oldErrorExitOut }()
system.ErrorExitOut = tstErrorExitOut

errExitMatchText := fmt.Sprintf(`saptune: Comprehensive system optimisation management for SAP solutions.
Daemon control:
saptune daemon [ start | status | stop ] ATTENTION: deprecated
saptune service [ start | status | stop | restart | takeover | enable | disable | enablestart | disablestop ]
Tune system according to SAP and SUSE notes:
saptune note [ list | revertall | enabled | applied ]
saptune note [ apply | simulate | customise | create | edit | revert | show | delete ] NoteID
saptune note verify [--colorscheme=<color scheme>] [--show-non-compliant] [NoteID]
saptune note rename NoteID newNoteID
Tune system for all notes applicable to your SAP solution:
saptune solution [ list | verify | enabled | applied ]
saptune solution [ apply | simulate | verify | customise | create | edit | revert | show | delete ] SolutionName
saptune solution rename SolutionName newSolutionName
Staging control:
saptune staging [ status | enable | disable | is-enabled | list | diff | analysis | release ]
saptune staging [ analysis | diff ] [ NoteID... | SolutionID... | all ]
saptune staging release [--force|--dry-run] [ NoteID... | SolutionID... | all ]
Revert all parameters tuned by the SAP notes or solutions:
saptune revert all
Remove the pending lock file from a former saptune call
saptune lock remove
Call external script '/usr/sbin/saptune_check'
saptune check
Print current saptune status:
saptune status
Print current saptune version:
saptune version
Print this message:
saptune help
`)
errExitMatchText := PrintHelpAndExitMatchText
errExitbuffer := bytes.Buffer{}
tstwriter = &errExitbuffer
buffer := bytes.Buffer{}
Expand Down
7 changes: 5 additions & 2 deletions actions/footnote.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@ func setUsNa(actVal, compliant, comment string, footnote []string) (string, stri
compliant = compliant + " [16]"
compliant = strings.Replace(compliant, "no ", " - ", 1)
comment = comment + " [16]"
footnote[15] = footnote16
if !system.IsFlagSet("show-non-compliant") {
footnote[15] = footnote16
}
}
return compliant, comment, footnote
}
Expand Down Expand Up @@ -165,7 +167,8 @@ func setSecBoot(mapKey, compliant, comment string, footnote []string) (string, s
// setFLdiffs sets footnote for diffs in force_latency parameter
func setFLdiffs(mapKey, compliant, comment, info string, footnote []string) (string, string, []string) {
if mapKey == "force_latency" && info == "hasDiffs" {
compliant = "no [4]"
compliant = compliant + " [4]"
compliant = strings.Replace(compliant, " - ", "no ", 1)
comment = comment + " [4]"
footnote[3] = footnote4
}
Expand Down
Loading

0 comments on commit 9cf9161

Please sign in to comment.