-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test ungraceful node(s) reboot(test part)
- Loading branch information
Showing
9 changed files
with
558 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,39 @@ | ||
package systemtestsparams | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"log" | ||
) | ||
|
||
const ( | ||
// Label represents label that can be used for test cases selection. | ||
Label = "system" | ||
) | ||
|
||
// BMCDetails structure to hold BMC details. | ||
type BMCDetails struct { | ||
Username string `json:"username"` | ||
Password string `json:"password"` | ||
BMCAddress string `json:"bmc"` | ||
} | ||
|
||
// NodesBMCMap holds info about BMC connection for a specific node. | ||
type NodesBMCMap map[string]BMCDetails | ||
|
||
// Decode - method for envconfig package to parse JSON encoded environment variables. | ||
func (nad *NodesBMCMap) Decode(value string) error { | ||
nodesAuthMap := new(map[string]BMCDetails) | ||
|
||
err := json.Unmarshal([]byte(value), nodesAuthMap) | ||
|
||
if err != nil { | ||
log.Printf("Error to parse data %v", err) | ||
|
||
return fmt.Errorf("invalid map json: %w", err) | ||
} | ||
|
||
*nad = *nodesAuthMap | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
package rebootconfig | ||
|
||
import ( | ||
"log" | ||
"os" | ||
"path/filepath" | ||
"runtime" | ||
|
||
"github.com/kelseyhightower/envconfig" | ||
"github.com/openshift-kni/eco-gosystem/tests/internal/config" | ||
systemtestsparams "github.com/openshift-kni/eco-gosystem/tests/internal/params" | ||
"gopkg.in/yaml.v2" | ||
) | ||
|
||
const ( | ||
// PathToDefaultRebootParamsFile path to config file with default ran du parameters. | ||
PathToDefaultRebootParamsFile = "./default.yaml" | ||
) | ||
|
||
// RebootConfig type keeps ran du configuration. | ||
type RebootConfig struct { | ||
*config.GeneralConfig | ||
NodesCredentialsMap systemtestsparams.NodesBMCMap `yaml:"nodes_bmc_map" envconfig:"ECO_SYSTEM_NODES_CREDENTIALS_MAP"` | ||
// | ||
ControlPlaneLabelStr string `yaml:"control_plane_nodes_label" envconfig:"ECO_REBOOT_CONTROL_PLANE_NODES_LABEL"` | ||
MasterNodesLabelStr string `yaml:"master_nodes_label" envconfig:"ECO_REBOOT_MASTER_NODES_LABEL"` | ||
WorkerNodesLabelStr string `yaml:"worker_nodes_label" envconfig:"ECO_REBOOT_WORKER_NODES_LABEL"` | ||
} | ||
|
||
// NewRebootConfig returns instance of RebootConfig config type. | ||
func NewRebootConfig() *RebootConfig { | ||
log.Print("Creating new RebootConfig struct") | ||
|
||
var rebootConf RebootConfig | ||
rebootConf.GeneralConfig = config.NewConfig() | ||
|
||
var confFile string | ||
|
||
if fileFromEnv, exists := os.LookupEnv("ECO_SYSTEM_REBOOT_CONFIG_FILE_PATH"); !exists { | ||
_, filename, _, _ := runtime.Caller(0) | ||
baseDir := filepath.Dir(filename) | ||
confFile = filepath.Join(baseDir, PathToDefaultRebootParamsFile) | ||
} else { | ||
confFile = fileFromEnv | ||
} | ||
|
||
log.Printf("Open config file %s", confFile) | ||
|
||
err := readFile(&rebootConf, confFile) | ||
if err != nil { | ||
log.Printf("Error to read config file %s", confFile) | ||
|
||
return nil | ||
} | ||
|
||
err = readEnv(&rebootConf) | ||
|
||
if err != nil { | ||
log.Print("Error to read environment variables") | ||
|
||
return nil | ||
} | ||
|
||
return &rebootConf | ||
} | ||
|
||
func readFile(rebootConfig *RebootConfig, cfgFile string) error { | ||
openedCfgFile, err := os.Open(cfgFile) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
defer func() { | ||
_ = openedCfgFile.Close() | ||
}() | ||
|
||
decoder := yaml.NewDecoder(openedCfgFile) | ||
err = decoder.Decode(&rebootConfig) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func readEnv(rebootConfig *RebootConfig) error { | ||
err := envconfig.Process("", rebootConfig) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
# default configurations. | ||
verbose_level: 0 | ||
dump_failed_tests: false | ||
reports_dump_dir: "/tmp/reports" | ||
polarion_report: true | ||
dry_run: false | ||
control_plane_nodes_label: "node-role.kubernetes.io/control-plane=''" | ||
master_nodes_label: "node-role.kubernetes.io/master=''" | ||
worker_nodes_label: "node-role.kubernetes.io/worker=''" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package rebootinittools | ||
|
||
import ( | ||
"github.com/openshift-kni/eco-goinfra/pkg/clients" | ||
"github.com/openshift-kni/eco-gosystem/tests/internal/inittools" | ||
"github.com/openshift-kni/eco-gosystem/tests/reboot/internal/rebootconfig" | ||
) | ||
|
||
var ( | ||
// APIClient provides API access to cluster. | ||
APIClient *clients.Settings | ||
// RebootTestConfig provides access to tests configuration parameters. | ||
RebootTestConfig *rebootconfig.RebootConfig | ||
) | ||
|
||
// init loads all variables automatically when this package is imported. Once package is imported a user has full | ||
// access to all vars within init function. It is recommended to import this package using dot import. | ||
func init() { | ||
RebootTestConfig = rebootconfig.NewRebootConfig() | ||
APIClient = inittools.APIClient | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package rebootparams | ||
|
||
const ( | ||
// Label is used for 'reboot' test cases selection. | ||
Label = "reboot" | ||
|
||
// LabelValidateReboot is used to select tests that reboot cluster. | ||
LabelValidateReboot = "validate_reboots" | ||
|
||
// RebootLogLevel configures logging level for reboot related tests. | ||
RebootLogLevel = 90 | ||
) | ||
|
||
// BMCDetails structure to hold BMC details. | ||
type BMCDetails struct { | ||
Username string `json:"username"` | ||
Password string `json:"password"` | ||
BMCAddress string `json:"bmc"` | ||
} | ||
|
||
// NodesBMCMap holds info about BMC connection for a specific node. | ||
type NodesBMCMap map[string]BMCDetails |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package rebootparams | ||
|
||
import ( | ||
systemtestsparams "github.com/openshift-kni/eco-gosystem/tests/internal/params" | ||
"github.com/openshift-kni/k8sreporter" | ||
v1 "k8s.io/api/core/v1" | ||
) | ||
|
||
var ( | ||
// Labels represents the range of labels that can be used for test cases selection. | ||
Labels = []string{systemtestsparams.Label, Label} | ||
|
||
// ReporterNamespacesToDump tells to the reporter from where to collect logs. | ||
ReporterNamespacesToDump = map[string]string{ | ||
"openshift-machine-api": "openshift-machine-api", | ||
} | ||
|
||
// ReporterCRDsToDump tells to the reporter what CRs to dump. | ||
ReporterCRDsToDump = []k8sreporter.CRData{ | ||
{Cr: &v1.PodList{}}, | ||
} | ||
) |
Oops, something went wrong.