k8s.io/kubernetes@v1.29.3/test/e2e_node/remote/ssh_runner.go (about)

     1  /*
     2  Copyright 2023 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package remote
    18  
    19  import (
    20  	"fmt"
    21  )
    22  
    23  var _ Runner = (*SSHRunner)(nil)
    24  
    25  type SSHRunner struct {
    26  	cfg Config
    27  }
    28  
    29  func (s *SSHRunner) StartTests(suite TestSuite, archivePath string, results chan *TestResult) (numTests int) {
    30  	for _, host := range s.cfg.Hosts {
    31  		fmt.Printf("Initializing e2e tests using host %s.\n", host)
    32  		numTests++
    33  		go func(host string, junitFileName string) {
    34  			output, exitOk, err := RunRemote(RunRemoteConfig{
    35  				Suite:          suite,
    36  				Archive:        archivePath,
    37  				Host:           host,
    38  				Cleanup:        s.cfg.Cleanup,
    39  				ImageDesc:      "",
    40  				JunitFileName:  junitFileName,
    41  				TestArgs:       s.cfg.TestArgs,
    42  				GinkgoArgs:     s.cfg.GinkgoFlags,
    43  				SystemSpecName: s.cfg.SystemSpecName,
    44  				ExtraEnvs:      s.cfg.ExtraEnvs,
    45  				RuntimeConfig:  s.cfg.RuntimeConfig,
    46  			})
    47  			results <- &TestResult{
    48  				Output: output,
    49  				Err:    err,
    50  				Host:   host,
    51  				ExitOK: exitOk,
    52  			}
    53  		}(host, host)
    54  	}
    55  	return
    56  }
    57  
    58  func NewSSHRunner(cfg Config) Runner {
    59  	return &SSHRunner{
    60  		cfg: cfg,
    61  	}
    62  }
    63  
    64  func (s *SSHRunner) Validate() error {
    65  	if len(s.cfg.Hosts) == 0 {
    66  		return fmt.Errorf("must specify --hosts when running ssh")
    67  	}
    68  	if s.cfg.ImageConfigFile != "" {
    69  		return fmt.Errorf("must not specify --image-config-file when running ssh")
    70  	}
    71  	if len(s.cfg.Images) > 0 {
    72  		return fmt.Errorf("must not specify --images when running ssh")
    73  	}
    74  	return nil
    75  }