@@ -201,11 +201,17 @@ func (r *runner) run() (results []testrunner.TestResult, err error) {
201201 logger .Debug ("Running system tests for package" )
202202 }
203203
204+ stackVersion , err := r .options .KibanaClient .Version ()
205+ if err != nil {
206+ return result .WithError (fmt .Errorf ("cannot request Kibana version: %w" , err ))
207+ }
208+
204209 devDeployPath , err := servicedeployer .FindDevDeployPath (servicedeployer.FactoryOptions {
205210 Profile : r .options .Profile ,
206211 PackageRootPath : r .options .PackageRootPath ,
207212 DataStreamRootPath : dataStreamPath ,
208213 DevDeployDir : DevDeployDir ,
214+ StackVersion : stackVersion .Version (),
209215 })
210216 if err != nil {
211217 return result .WithError (fmt .Errorf ("_dev/deploy directory not found: %w" , err ))
@@ -224,7 +230,7 @@ func (r *runner) run() (results []testrunner.TestResult, err error) {
224230 startTesting := time .Now ()
225231 for _ , cfgFile := range cfgFiles {
226232 for _ , variantName := range r .selectVariants (variantsFile ) {
227- partial , err := r .runTestPerVariant (result , locationManager , cfgFile , dataStreamPath , variantName )
233+ partial , err := r .runTestPerVariant (result , locationManager , cfgFile , dataStreamPath , variantName , stackVersion . Version () )
228234 results = append (results , partial ... )
229235 if err != nil {
230236 return results , err
@@ -253,14 +259,15 @@ func (r *runner) run() (results []testrunner.TestResult, err error) {
253259 return results , nil
254260}
255261
256- func (r * runner ) runTestPerVariant (result * testrunner.ResultComposer , locationManager * locations.LocationManager , cfgFile , dataStreamPath , variantName string ) ([]testrunner.TestResult , error ) {
262+ func (r * runner ) runTestPerVariant (result * testrunner.ResultComposer , locationManager * locations.LocationManager , cfgFile , dataStreamPath , variantName , stackVersion string ) ([]testrunner.TestResult , error ) {
257263 serviceOptions := servicedeployer.FactoryOptions {
258264 Profile : r .options .Profile ,
259265 PackageRootPath : r .options .PackageRootPath ,
260266 DataStreamRootPath : dataStreamPath ,
261267 DevDeployDir : DevDeployDir ,
262268 Variant : variantName ,
263269 Type : servicedeployer .TypeTest ,
270+ StackVersion : stackVersion ,
264271 }
265272
266273 var ctxt servicedeployer.ServiceContext
@@ -475,16 +482,11 @@ func (r *runner) runTest(config *testConfig, ctxt servicedeployer.ServiceContext
475482 return result .WithError (fmt .Errorf ("unable to reload system test case configuration: %w" , err ))
476483 }
477484
478- kib , err := stack .NewKibanaClient ()
479- if err != nil {
480- return result .WithError (fmt .Errorf ("can't create Kibana client: %w" , err ))
481- }
482-
483485 // Install the package before creating the policy, so we control exactly what is being
484486 // installed.
485487 logger .Debug ("Installing package..." )
486488 installer , err := installer .NewForPackage (installer.Options {
487- Kibana : kib ,
489+ Kibana : r . options . KibanaClient ,
488490 RootPath : r .options .PackageRootPath ,
489491 SkipValidation : true ,
490492 })
@@ -516,21 +518,21 @@ func (r *runner) runTest(config *testConfig, ctxt servicedeployer.ServiceContext
516518 Description : fmt .Sprintf ("test policy created by elastic-package test system for data stream %s/%s" , r .options .TestFolder .Package , r .options .TestFolder .DataStream ),
517519 Namespace : "ep" ,
518520 }
519- policy , err := kib .CreatePolicy (p )
521+ policy , err := r . options . KibanaClient .CreatePolicy (p )
520522 if err != nil {
521523 return result .WithError (fmt .Errorf ("could not create test policy: %w" , err ))
522524 }
523525 r .deleteTestPolicyHandler = func () error {
524526 logger .Debug ("deleting test policy..." )
525- if err := kib .DeletePolicy (* policy ); err != nil {
527+ if err := r . options . KibanaClient .DeletePolicy (* policy ); err != nil {
526528 return fmt .Errorf ("error cleaning up test policy: %w" , err )
527529 }
528530 return nil
529531 }
530532
531533 logger .Debug ("adding package data stream to test policy..." )
532534 ds := createPackageDatastream (* policy , * pkgManifest , policyTemplate , * dataStreamManifest , * config )
533- if err := kib .AddPackageDataStreamToPolicy (ds ); err != nil {
535+ if err := r . options . KibanaClient .AddPackageDataStreamToPolicy (ds ); err != nil {
534536 return result .WithError (fmt .Errorf ("could not add data stream config to policy: %w" , err ))
535537 }
536538
@@ -576,7 +578,7 @@ func (r *runner) runTest(config *testConfig, ctxt servicedeployer.ServiceContext
576578 return result .WithError (err )
577579 }
578580
579- agents , err := checkEnrolledAgents (kib , ctxt )
581+ agents , err := checkEnrolledAgents (r . options . KibanaClient , ctxt )
580582 if err != nil {
581583 return result .WithError (fmt .Errorf ("can't check enrolled agents: %w" , err ))
582584 }
@@ -589,19 +591,19 @@ func (r *runner) runTest(config *testConfig, ctxt servicedeployer.ServiceContext
589591 // Assign policy to agent
590592 r .resetAgentPolicyHandler = func () error {
591593 logger .Debug ("reassigning original policy back to agent..." )
592- if err := kib .AssignPolicyToAgent (agent , origPolicy ); err != nil {
594+ if err := r . options . KibanaClient .AssignPolicyToAgent (agent , origPolicy ); err != nil {
593595 return fmt .Errorf ("error reassigning original policy to agent: %w" , err )
594596 }
595597 return nil
596598 }
597599
598- policyWithDataStream , err := kib .GetPolicy (policy .ID )
600+ policyWithDataStream , err := r . options . KibanaClient .GetPolicy (policy .ID )
599601 if err != nil {
600602 return result .WithError (fmt .Errorf ("could not read the policy with data stream: %w" , err ))
601603 }
602604
603605 logger .Debug ("assigning package data stream to agent..." )
604- if err := kib .AssignPolicyToAgent (agent , * policyWithDataStream ); err != nil {
606+ if err := r . options . KibanaClient .AssignPolicyToAgent (agent , * policyWithDataStream ); err != nil {
605607 return result .WithError (fmt .Errorf ("could not assign policy to agent: %w" , err ))
606608 }
607609
0 commit comments