Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new flags to just setup, teardown or run tests only #1250

Merged
merged 112 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
112 commits
Select commit Hold shift + click to select a range
20fbf41
Add Setup method to interface
mrodm May 4, 2023
adad2d6
Add setup for system
mrodm May 4, 2023
d1af618
Add flag for config file
mrodm May 5, 2023
63ecb86
Fix field name
mrodm May 5, 2023
684ee9b
Update runners
mrodm May 5, 2023
628216b
Execute Configure/Setup if it is implemented interface
mrodm Jan 24, 2024
681f8af
Add new flags for setup / teardown
mrodm Jan 26, 2024
da5272a
Add CanRunSetupTeardownIndependent method to the interface
mrodm Jan 29, 2024
2345470
Refactor - add initRun
mrodm Jan 29, 2024
d86240f
Use variables from runner struct
mrodm Jan 29, 2024
cf23c5d
Fix data stream root path
mrodm Jan 29, 2024
5add400
Add specific policy suffix when running setup flag
mrodm Jan 29, 2024
58dde46
Add first PoC for setup and teardown
mrodm Jan 29, 2024
17542ef
Add check about variants
mrodm Jan 30, 2024
84ea79a
Remove prefix from policy - those policies are saved after each setup
mrodm Jan 30, 2024
6ad085f
Do not delete old docs in tear-down - just in the wipe handler
mrodm Jan 30, 2024
2b6027f
If any error in setup, run teardown
mrodm Jan 30, 2024
eb23780
Use constants
mrodm Jan 30, 2024
f0d955c
Ensure two setup commands are run sequentially
mrodm Jan 30, 2024
e0f2b39
Update folder path for service setup files
mrodm Jan 30, 2024
9e0b394
Merge remote upstream/main into add_flag_setup_testrunner
mrodm Jan 30, 2024
029ad0b
Not hide errors from prepare scenario
mrodm Jan 30, 2024
e6e0a7a
Show wait for data timeout in message
mrodm Jan 30, 2024
13f0c97
Review log messages
mrodm Jan 30, 2024
d2f3498
Manage errors about setup service directory for setup and teardown
mrodm Jan 30, 2024
7065d57
Remove commented code
mrodm Jan 30, 2024
87c56f5
Use the expected config file if set
mrodm Jan 30, 2024
3e5cb14
Just create folder and files if setup flag is set
mrodm Jan 30, 2024
efa483e
Reordered clauses
mrodm Jan 30, 2024
cff0dd8
Use r.variants
mrodm Jan 30, 2024
bf38069
Not allow to run tests if the setup service folder exists
mrodm Jan 31, 2024
70cbb3e
Move skip check to runTest
mrodm Jan 31, 2024
53f818d
Refactor - create a new function for context and service options
mrodm Jan 31, 2024
6cc1ad0
Remove unnecessary variables from servicedeployer.FactoryOptions
mrodm Jan 31, 2024
ff62d08
Use option instead of calculating from path
mrodm Jan 31, 2024
af3e334
Rename function and variable about service setup dir
mrodm Jan 31, 2024
deeab20
Show config and variant in the output
mrodm Jan 31, 2024
70ecf7a
Allow to run tests adding --no-provision flag
mrodm Feb 1, 2024
9b75ff8
Add safeguard for no-provision flag
mrodm Feb 1, 2024
3bc39eb
Add first tests for system test flags
mrodm Feb 1, 2024
4868898
Add report flags
mrodm Feb 1, 2024
cf278fc
Add more tests
mrodm Feb 2, 2024
739cfb2
Add silent mode to curl when installing docker-compose
mrodm Feb 2, 2024
ea1a9c7
Fix flag for no-provision test
mrodm Feb 2, 2024
a085cb6
Add specific management of old docs when run tests only mode
mrodm Feb 2, 2024
880ea8f
Add collapsed section in BK output
mrodm Feb 2, 2024
60220ae
Do not check about modes in runTest
mrodm Feb 2, 2024
f4baa17
Add checks for flags in run tests only mode
mrodm Feb 2, 2024
00cd9f8
Fix linting in shell scripts
mrodm Feb 2, 2024
bb2291a
Update docs with a section about running system tests in steps
mrodm Feb 2, 2024
6a8f797
Add language into markdown snippets
mrodm Feb 5, 2024
14cf21a
Remove trailing whitespaces
mrodm Feb 5, 2024
343c52c
Add more info in docs
mrodm Feb 5, 2024
06f7896
Update language for snippet
mrodm Feb 5, 2024
df1821d
Add missing language in markdown snippets
mrodm Feb 5, 2024
6f43c70
Re-phrase system test runs configuration list
mrodm Feb 5, 2024
a9d2b84
Merge remote-tracking branch 'upstream/main' into add_flag_setup_test…
mrodm Feb 7, 2024
9173d9d
WIP
mrodm Feb 7, 2024
273ee15
Handle agent log level
mrodm Feb 7, 2024
0b4bda9
Add checks for config file flag
mrodm Feb 8, 2024
d78212b
Add message about technical preview for these flags
mrodm Feb 8, 2024
c3c9565
Rename variable for consistency
mrodm Feb 8, 2024
d0a36ac
Update errors shown to the user if flags are misused
mrodm Feb 8, 2024
23d8ee1
Fix error message
mrodm Feb 8, 2024
38fb6b6
Retrieve variant from setup dir for tests and tear-down
mrodm Feb 8, 2024
698bd31
update test script with another package
mrodm Feb 8, 2024
08ad913
Update doc with latest changes
mrodm Feb 8, 2024
0dd2696
Check if config file flag exists before getting the value
mrodm Feb 8, 2024
ec10a44
Set container service name for each package
mrodm Feb 8, 2024
d3cea72
Avoid settng config file flag for tear-down and no-provision flags
mrodm Feb 8, 2024
3643519
Update test scripts and docs
mrodm Feb 8, 2024
163e42b
Update files that should be in service_setup folder
mrodm Feb 8, 2024
667ffab
Force to use config-file parameter with setup
mrodm Feb 13, 2024
a3848d5
Use if instead of switch
mrodm Feb 13, 2024
83da2bd
Use optons to create custom agent and compose deployers
mrodm Feb 13, 2024
9c48fee
Run docker-compose up in setup or when the whole test is run
mrodm Feb 13, 2024
fe5745b
Remove leftovers
mrodm Feb 13, 2024
21c645a
Revert change in number format for mode perm
mrodm Feb 13, 2024
bb0b65c
Merge remote upstream/main into add_flag_setup_testrunner
mrodm Feb 13, 2024
0b07787
Refactor and extract function to delete docs and wait
mrodm Feb 14, 2024
3ec81cc
Remove switch
mrodm Feb 14, 2024
5305d55
Create function to write all scenario setup related files
mrodm Feb 14, 2024
6832cab
Connect service to network before checking for healthy
mrodm Feb 14, 2024
0a866ce
Write just one file for service setup data
mrodm Feb 14, 2024
27370bb
Just write the required values from config in file
mrodm Feb 14, 2024
22ff4b0
Create new location manager in cmd/testrunner to get service setup data
mrodm Feb 14, 2024
be3bb0c
Remove method from TestRunner interface
mrodm Feb 14, 2024
252fef2
Check container health in all modes
mrodm Feb 14, 2024
dfe5ba8
Update file name in test script
mrodm Feb 14, 2024
d14daa4
Use less variables in compose and custom_agent deployers
mrodm Feb 14, 2024
db82d2f
Add missing error handling
mrodm Feb 14, 2024
32ae291
Move to function to read config file path string
mrodm Feb 14, 2024
9856557
Change switch by ifs
mrodm Feb 14, 2024
1393831
Add more checks for config-file and data-streams flags
mrodm Feb 14, 2024
7fcad77
Raise error if variant is not defined
mrodm Feb 14, 2024
4934517
Add functions to manage serviceSetupDir
mrodm Feb 14, 2024
e4e5b81
Use function to read setup data
mrodm Feb 14, 2024
827c7d7
Move state file to profile (stack) folder
mrodm Feb 14, 2024
de6acb3
Rename variables to refer to state
mrodm Feb 14, 2024
baad699
Add doc for StateFolderPath
mrodm Feb 14, 2024
90b8e79
Merge remote upstream/main into add_flag_setup_testrunner
mrodm Feb 14, 2024
bd8acba
Update path in test script
mrodm Feb 14, 2024
40c5c87
Update script with packages using custom agents
mrodm Feb 14, 2024
f57a653
Remove state folder field from struct
mrodm Feb 14, 2024
ee91de4
Fix test script with package folder paths
mrodm Feb 14, 2024
14e1e2f
Raise error for unsupported service deployers
mrodm Feb 14, 2024
5264086
Add support for kind service deployer
mrodm Feb 14, 2024
7d4ca6a
Fix function name
mrodm Feb 15, 2024
d7818bd
Install kind and kubectl in system test flags step
mrodm Feb 15, 2024
7c86cf2
Fix function name
mrodm Feb 15, 2024
7c43ec9
Not delete state folder, just service state
mrodm Feb 15, 2024
b22f48a
Add note to comment about variant flag
mrodm Feb 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .buildkite/scripts/integration_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ usage() {
PARALLEL_TARGET="test-check-packages-parallel"
FALSE_POSITIVES_TARGET="test-check-packages-false-positives"
KIND_TARGET="test-check-packages-with-kind"
SYSTEM_TEST_FLAGS_TARGET="test-system-test-flags"
TMP_FOLDER_TEMPLATE="${TMP_FOLDER_TEMPLATE_BASE}.XXXXXXXXX"
GOOGLE_CREDENTIALS_FILENAME="google-cloud-credentials.json"

Expand Down Expand Up @@ -115,7 +116,7 @@ with_docker
echo "--- install docker-compose plugin"
with_docker_compose_plugin

if [[ "${TARGET}" == "${KIND_TARGET}" ]]; then
if [[ "${TARGET}" == "${KIND_TARGET}" || "${TARGET}" == "${SYSTEM_TEST_FLAGS_TARGET}" ]]; then
echo "--- install kubectl & kind"
with_kubernetes
fi
Expand Down
3 changes: 2 additions & 1 deletion docs/howto/system_testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,6 @@ A sample workflow would look like:

### Running system tests without cleanup (technical preview)
jsoriano marked this conversation as resolved.
Show resolved Hide resolved

**Disclaimer**: just tested with service deployer `docker`.

By default, `elastic-package test system` command always performs these steps to run tests for a given package:
1. Setup:
Expand Down Expand Up @@ -634,6 +633,8 @@ This process is repeated for each combination of:
It's possible also to run these steps independently. For that it is required to set which configuration file (`--config-file`)
jsoriano marked this conversation as resolved.
Show resolved Hide resolved
and which variant (`--variant`), if any, is going to be used to start and configure the service for these tests.

**NOTE**: Currently, there is just support for packages using the following service deployers: `docker`, `agent` (custom agents) and `k8s`.

Then, each step can be run using one of these flags:
- Run the setup (`--setup`), after this command is executed:
- Service container will be kept running.
Expand Down
13 changes: 12 additions & 1 deletion internal/servicedeployer/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,15 @@ func Factory(options FactoryOptions) (ServiceDeployer, error) {
switch serviceDeployerName {
case "k8s":
if _, err := os.Stat(serviceDeployerPath); err == nil {
return NewKubernetesServiceDeployer(options.Profile, serviceDeployerPath, options.StackVersion)
opts := KubernetesServiceDeployerOptions{
Profile: options.Profile,
DefinitionsDir: serviceDeployerPath,
StackVersion: options.StackVersion,
RunSetup: options.RunSetup,
RunTestsOnly: options.RunTestsOnly,
RunTearDown: options.RunTearDown,
}
return NewKubernetesServiceDeployer(opts)
}
case "docker":
dockerComposeYMLPath := filepath.Join(serviceDeployerPath, "docker-compose.yml")
Expand Down Expand Up @@ -88,6 +96,9 @@ func Factory(options FactoryOptions) (ServiceDeployer, error) {
}
return NewCustomAgentDeployer(opts)
case "tf":
if options.RunSetup || options.RunTearDown || options.RunTestsOnly {
return nil, errors.New("terraform service deployer not supported to run by steps")
}
Comment on lines +99 to +101
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now, this service deployer is not supported. I'd prefer to just leave this option (test flags) for stacks/services started locally for now.

This the error that is going to be shown to the user:

2024/02/15 09:44:36 DEBUG setting up service...
Error: error running package system tests: could not complete test run: could not create service runner: terraform service deployer not supported to run by steps

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 we can add this later

if _, err := os.Stat(serviceDeployerPath); err == nil {
return NewTerraformServiceDeployer(serviceDeployerPath)
}
Expand Down
53 changes: 40 additions & 13 deletions internal/servicedeployer/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,20 @@ type KubernetesServiceDeployer struct {
profile *profile.Profile
definitionsDir string
stackVersion string

runSetup bool
runTestsOnly bool
runTearDown bool
}

type KubernetesServiceDeployerOptions struct {
Profile *profile.Profile
DefinitionsDir string
StackVersion string

RunSetup bool
RunTestsOnly bool
RunTearDown bool
}

type kubernetesDeployedService struct {
Expand Down Expand Up @@ -75,11 +89,14 @@ func (s *kubernetesDeployedService) SetContext(sc ServiceContext) error {
var _ DeployedService = new(kubernetesDeployedService)

// NewKubernetesServiceDeployer function creates a new instance of KubernetesServiceDeployer.
func NewKubernetesServiceDeployer(profile *profile.Profile, definitionsPath string, stackVersion string) (*KubernetesServiceDeployer, error) {
func NewKubernetesServiceDeployer(opts KubernetesServiceDeployerOptions) (*KubernetesServiceDeployer, error) {
return &KubernetesServiceDeployer{
profile: profile,
definitionsDir: definitionsPath,
stackVersion: stackVersion,
profile: opts.Profile,
definitionsDir: opts.DefinitionsDir,
stackVersion: opts.StackVersion,
runSetup: opts.RunSetup,
runTestsOnly: opts.RunTestsOnly,
runTearDown: opts.RunTearDown,
}, nil
}

Expand All @@ -91,19 +108,29 @@ func (ksd KubernetesServiceDeployer) SetUp(ctxt ServiceContext) (DeployedService
return nil, fmt.Errorf("kind context verification failed: %w", err)
}

err = kind.ConnectToElasticStackNetwork(ksd.profile)
if err != nil {
return nil, fmt.Errorf("can't connect control plane to Elastic stack network: %w", err)
if ksd.runTearDown || ksd.runTestsOnly {
logger.Debug("Skip connect kind to Elastic stack network")
} else {
err = kind.ConnectToElasticStackNetwork(ksd.profile)
if err != nil {
return nil, fmt.Errorf("can't connect control plane to Elastic stack network: %w", err)
}
}

err = installElasticAgentInCluster(ksd.profile, ksd.stackVersion)
if err != nil {
return nil, fmt.Errorf("can't install Elastic-Agent in the Kubernetes cluster: %w", err)
if ksd.runTearDown || ksd.runTestsOnly {
logger.Debug("Skip install Elastic Agent in cluster")
} else {
err = installElasticAgentInCluster(ksd.profile, ksd.stackVersion)
if err != nil {
return nil, fmt.Errorf("can't install Elastic-Agent in the Kubernetes cluster: %w", err)
}
}

err = ksd.installCustomDefinitions()
if err != nil {
return nil, fmt.Errorf("can't install custom definitions in the Kubernetes cluster: %w", err)
if !ksd.runTearDown {
err = ksd.installCustomDefinitions()
if err != nil {
return nil, fmt.Errorf("can't install custom definitions in the Kubernetes cluster: %w", err)
}
}

ctxt.Name = kind.ControlPlaneContainerName
Expand Down
8 changes: 3 additions & 5 deletions internal/testrunner/runners/system/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ type runner struct {
stackVersion kibana.VersionInfo
locationManager *locations.LocationManager
jsoriano marked this conversation as resolved.
Show resolved Hide resolved

serviceStateFolder string
serviceStateFilePath string

// Execution order of following handlers is defined in runner.TearDown() method.
Expand Down Expand Up @@ -365,8 +364,7 @@ func (r *runner) initRun() error {
if err != nil {
return fmt.Errorf("reading service logs directory failed: %w", err)
}
r.serviceStateFolder = testrunner.StateFolderPath(r.options.Profile.ProfilePath)
r.serviceStateFilePath = filepath.Join(r.serviceStateFolder, testrunner.ServiceStateFileName)
r.serviceStateFilePath = filepath.Join(testrunner.StateFolderPath(r.options.Profile.ProfilePath), testrunner.ServiceStateFileName)

r.dataStreamPath, found, err = packages.FindDataStreamRootForPath(r.options.TestFolder.Path)
if err != nil {
Expand Down Expand Up @@ -995,7 +993,7 @@ func (r *runner) prepareScenario(config *testConfig, ctxt servicedeployer.Servic
}

func (r *runner) removeServiceStateDir() error {
dirPath := r.serviceStateFolder
dirPath := filepath.Dir(r.serviceStateFilePath)
err := os.RemoveAll(dirPath)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should remove the file only, in case we use the directory later for other states. Leaving the directory there should not be a problem.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes totally sense.
Update this function to just delete the file, and update the tests accordingly.

if err != nil {
return fmt.Errorf("failed to remove directory %q: %w", dirPath, err)
Expand All @@ -1004,7 +1002,7 @@ func (r *runner) removeServiceStateDir() error {
}

func (r *runner) createServiceStateDir() error {
dirPath := r.serviceStateFolder
dirPath := filepath.Dir(r.serviceStateFilePath)
err := os.MkdirAll(dirPath, 0755)
if err != nil {
return fmt.Errorf("mkdir failed (path: %s): %w", dirPath, err)
Expand Down
Loading