How to use waitRebootAndSSH method of isolated Package

Best Syzkaller code snippet using isolated.waitRebootAndSSH

isolated.go

Source:isolated.go Github

copy

Full Screen

...171// log.Logf(0, "ssh returned")172// }173// return nil174// }175// func (inst *instance) waitRebootAndSSH(rebootTimeout int, sshTimeout time.Duration) error {176// if err := inst.waitForReboot(rebootTimeout); err != nil {177// log.Logf(2, "isolated: machine did not reboot")178// return err179// }180// log.Logf(2, "isolated: rebooted wait for comeback")181// if err := inst.waitForSSH(sshTimeout); err != nil {182// log.Logf(2, "isolated: machine did not comeback")183// return err184// }185// log.Logf(2, "isolated: reboot succeeded")186// return nil187// }188// func (inst *instance) repair() error {189// log.Logf(2, "isolated: trying to ssh")190// if err := inst.waitForSSH(30 * time.Minute); err != nil {191// log.Logf(2, "isolated: ssh failed")192// return fmt.Errorf("SSH failed")193// }194// if inst.cfg.TargetReboot {195// if len(inst.cfg.USBDevNums) > 0 {196// log.Logf(2, "isolated: trying to reboot by USB authorization")197// usbAuth := fmt.Sprintf("%s%s%s", "/sys/bus/usb/devices/", inst.cfg.USBDevNums[inst.index], "/authorized")198// if err := ioutil.WriteFile(usbAuth, []byte("0"), 0); err != nil {199// log.Logf(2, "isolated: failed to turn off the device")200// return err201// }202// if err := ioutil.WriteFile(usbAuth, []byte("1"), 0); err != nil {203// log.Logf(2, "isolated: failed to turn on the device")204// return err205// }206// } else {207// log.Logf(2, "isolated: ssh succeeded, trying to reboot by ssh")208// inst.ssh("reboot") // reboot will return an error, ignore it209// if err := inst.waitRebootAndSSH(5*60, 30*time.Minute); err != nil {210// return fmt.Errorf("waitRebootAndSSH failed: %v", err)211// }212// }213// }214// if inst.cfg.StartupScript != "" {215// log.Logf(2, "isolated: executing startup_script")216// // Execute the contents of the StartupScript on the DUT.217// contents, err := ioutil.ReadFile(inst.cfg.StartupScript)218// if err != nil {219// return fmt.Errorf("unable to read startup_script: %v", err)220// }221// c := string(contents)222// if err := inst.ssh(fmt.Sprintf("bash -c \"%v\"", vmimpl.EscapeDoubleQuotes(c))); err != nil {223// return fmt.Errorf("failed to execute startup_script: %v", err)224// }225// log.Logf(2, "isolated: done executing startup_script")226// }227// return nil228// }229func (inst *instance) waitForSSH(timeout time.Duration) error {230 return vmimpl.WaitForSSH(inst.debug, timeout, inst.targetAddr, inst.sshKey, inst.sshUser,231 inst.os, inst.targetPort, nil)232}233// func (inst *instance) waitForReboot(timeout int) error {234// var err error235// start := time.Now()236// for {237// if !vmimpl.SleepInterruptible(time.Second) {238// return fmt.Errorf("shutdown in progress")239// }240// // If it fails, then the reboot started.241// if err = inst.ssh("pwd"); err != nil {242// return nil243// }244// if time.Since(start).Seconds() > float64(timeout) {245// break246// }247// }248// return fmt.Errorf("isolated: the machine did not reboot on repair")249// }250func (inst *instance) Close() {251 close(inst.closed)252}253// func (inst *instance) Copy(hostSrc string) (string, error) {254// baseName := filepath.Base(hostSrc)255// vmDst := filepath.Join(inst.cfg.TargetDir, baseName)256// inst.ssh("pkill -9 '" + baseName + "'; rm -f '" + vmDst + "'")257// args := append(vmimpl.SCPArgs(inst.debug, inst.sshKey, inst.targetPort),258// hostSrc, inst.sshUser+"@"+inst.targetAddr+":"+vmDst)259// cmd := osutil.Command("scp", args...)260// if inst.debug {261// log.Logf(0, "running command: scp %#v", args)262// cmd.Stdout = os.Stdout263// cmd.Stderr = os.Stdout264// }265// if err := cmd.Start(); err != nil {266// return "", err267// }268// done := make(chan bool)269// go func() {270// select {271// case <-time.After(3 * time.Minute):272// cmd.Process.Kill()273// case <-done:274// }275// }()276// err := cmd.Wait()277// close(done)278// if err != nil {279// return "", err280// }281// return vmDst, nil282// }283// func (inst *instance) Run(timeout time.Duration, stop <-chan bool, command string) (284// <-chan []byte, <-chan error, error) {285// args := append(vmimpl.SSHArgs(inst.debug, inst.sshKey, inst.targetPort), inst.sshUser+"@"+inst.targetAddr)286// dmesg, err := vmimpl.OpenRemoteConsole("ssh", args...)287// if err != nil {288// return nil, nil, err289// }290// rpipe, wpipe, err := osutil.LongPipe()291// if err != nil {292// dmesg.Close()293// return nil, nil, err294// }295// args = vmimpl.SSHArgsForward(inst.debug, inst.sshKey, inst.targetPort, inst.forwardPort)296// if inst.cfg.Pstore {297// args = append(args, "-o", "ServerAliveInterval=6")298// args = append(args, "-o", "ServerAliveCountMax=5")299// }300// args = append(args, inst.sshUser+"@"+inst.targetAddr, "cd "+inst.cfg.TargetDir+" && exec "+command)301// if inst.debug {302// log.Logf(0, "running command: ssh %#v", args)303// }304// cmd := osutil.Command("ssh", args...)305// cmd.Stdout = wpipe306// cmd.Stderr = wpipe307// if err := cmd.Start(); err != nil {308// dmesg.Close()309// rpipe.Close()310// wpipe.Close()311// return nil, nil, err312// }313// wpipe.Close()314// var tee io.Writer315// if inst.debug {316// tee = os.Stdout317// }318// merger := vmimpl.NewOutputMerger(tee)319// merger.Add("dmesg", dmesg)320// merger.Add("ssh", rpipe)321// return vmimpl.Multiplex(cmd, merger, dmesg, timeout, stop, inst.closed, inst.debug)322// }323func (inst *instance) readPstoreContents() ([]byte, error) {324 log.Logf(0, "reading pstore contents")325 args := append(vmimpl.SSHArgs(inst.debug, inst.sshKey, inst.targetPort),326 inst.sshUser+"@"+inst.targetAddr, "cat "+pstoreConsoleFile+" && rm "+pstoreConsoleFile)327 if inst.debug {328 log.Logf(0, "running command: ssh %#v", args)329 }330 var stdout, stderr bytes.Buffer331 cmd := osutil.Command("ssh", args...)332 cmd.Stdout = &stdout333 cmd.Stderr = &stderr334 if err := cmd.Run(); err != nil {335 return nil, fmt.Errorf("unable to read pstore file: %v: %v", err, stderr.String())336 }337 return stdout.Bytes(), nil338}339// func (inst *instance) Diagnose(rep *report.Report) ([]byte, bool) {340// if !inst.cfg.Pstore {341// return nil, false342// }343// // TODO: kernel may not reboot after some errors.344// // E.g. if panic_on_warn is not set, or some errors don't trigger reboot at all (e.g. LOCKDEP overflows).345// log.Logf(2, "waiting for crashed DUT to come back up")346// if err := inst.waitRebootAndSSH(5*60, 30*time.Minute); err != nil {347// return []byte(fmt.Sprintf("unable to SSH into DUT after reboot: %v", err)), false348// }349// log.Logf(2, "reading contents of pstore")350// contents, err := inst.readPstoreContents()351// if err != nil {352// return []byte(fmt.Sprintf("Diagnose failed: %v\n", err)), false353// }354// return contents, false355// }356func splitTargetPort(addr string) (string, int, error) {357 target := addr358 port := 22359 if colonPos := strings.Index(addr, ":"); colonPos != -1 {360 p, err := strconv.ParseUint(addr[colonPos+1:], 10, 16)...

Full Screen

Full Screen

waitRebootAndSSH

Using AI Code Generation

copy

Full Screen

1import (2 "github.com/GoogleCloudPlatform/compute-image-tools/cli_tools/gce_ovf_import/domain"3 "github.com/GoogleCloudPlatform/compute-image-tools/cli_tools/gce_ovf_import/ovf_utils"4 "github.com/GoogleCloudPlatform/compute-image-tools/cli_tools/gce_ovf_import/ovf_importer"5 "github.com/GoogleCloudPlatform/compute-image-tools/cli_tools/gce_ovf_import/gce_utils"6 "github.com/GoogleCloudPlatform/compute-image-tools/cli_tools/gce_ovf_import/ovf_import_params"7 "github.com/GoogleCloudPlatform/compute-image-tools/cli_tools/gce_ovf_import/params"8 "github.com/GoogleCloudPlatform/compute-image-tools/cli_tools/gce_ovf_import/ovf_importer/ovf_importer_utils"9 "github.com/GoogleCloudPlatform/compute-image-tools/cli_tools/gce_ovf_import/ovf_importer/ovf_importer_test"10 "github.com/GoogleCloudPlatform/compute-image-tools/cli_tools/gce_ovf_import/ovf_importer/ovf_importer_mock"

Full Screen

Full Screen

waitRebootAndSSH

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 ctx := context.Background()4 testSuite := junitxml.NewTestSuite("Test Suite")5 testSetup := junitxml.NewTestCase(testSuite, "TestSetup")6 defer testSuite.Write(os.Stdout)7 logger := logging.NewToolLogger("INFO")8 computeClient, err := compute.NewService(ctx, option.WithCredentialsFile("C:\\Users\\shashank\\Desktop\\shashank\\credentials.json"))9 if err != nil {10 log.Fatalf("Error creating compute client: %v", err)11 }12 testSetup.Logf("Creating test image")13 testSetup.Logf("Image under test %q", imageName)14 testCase := junitxml.NewTestCase(testSuite, "Test Case")15 testCase.Logf("Running test case")16 testCase.Logf("Creating instance")17 instanceName := path.RandString(5)18 _, err = utils.CreateInstance(testCase, logger, computeClient, testProjectConfig.TestProjectID, testProjectConfig.TestZone, instanceName, testProjectConfig.TestImageConfig.image, testProjectConfig.TestImageConfig.imageFamily, testProjectConfig.TestImageConfig.imageProject, machineType, testProjectConfig.TestStartupScriptURL, testProjectConfig.TestMetadata, testProjectConfig.TestLabels, testProjectConfig.TestNetwork, testProjectConfig.TestSubnet,

Full Screen

Full Screen

waitRebootAndSSH

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 logger := logging.NewStdoutLogger(service.NewLogger("2.go"))4 isolated := isolation.NewIsolated(logger, "C:\\Users\\user\\go\\src\\github.com\\GoogleCloudPlatform\\compute-image-tools\\cli_tools\\common\\utils\\isolation\\test_data\\2.go")5 isolated.WaitRebootAndSSH(func() error {6 logger.Log("message 2")7 })8}

Full Screen

Full Screen

waitRebootAndSSH

Using AI Code Generation

copy

Full Screen

1import (2type Isolated struct {3}4func (i *Isolated) waitRebootAndSSH() error {5 if err := i.ssh.Reboot(); err != nil {6 }7 if err := i.ssh.WaitSSH(); err != nil {8 }9}10func main() {11 wg.Add(1)12 go func() {13 defer wg.Done()14 i := &Isolated{ssh: &SSH{}}15 if err := i.waitRebootAndSSH(); err != nil {16 log.Fatal(err)17 }18 fmt.Println("done")19 }()20 wg.Wait()21}22import (23type Isolated struct {24}25func (i *Isolated) waitRebootAndSSH() error {26 if err := i.ssh.Reboot(); err != nil {27 }28 if err := i.ssh.WaitSSH(); err != nil {29 }30}31func main() {32 wg.Add(1)33 go func() {34 defer wg.Done()35 i := &Isolated{ssh: &SSH{}}36 if err := i.waitRebootAndSSH(); err != nil {37 log.Fatal(err)38 }39 fmt.Println("done")40 }()41 wg.Wait()42}43import (44type Isolated struct {45}46func (i *Isolated) waitRebootAndSSH() error {47 if err := i.ssh.Reboot(); err != nil

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Syzkaller automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful