func TestNothing(t *testing.T) { if os.Getenv("TRAVIS") == "true" { t.Skip("Unable to run test on Travis") } assert := assert.New(t) mgr := metamgr.NewMetadataManager("rmf5", []string{"127.0.0.1"}) c := cepm.NewCPMd(7902, mgr) go c.Background() // Port number for testing re, err := NewRiakExplorer(7901, "rex@ubuntu.", c) // 998th prime number. assert.Equal(nil, err) re.TearDown() _, err = re.NewRiakExplorerClient().Ping() assert.NotNil(err) procs, err := ps.Processes() if err != nil { t.Fatal("Could not get OS processes") } pid := os.Getpid() for _, proc := range procs { if proc.PPid() == pid { assert.Fail("There are children proccesses leftover") } } }
func TestTeardown(t *testing.T) { go func() { sigs := make(chan os.Signal, 1) signal.Notify(sigs, syscall.SIGQUIT) buf := make([]byte, 1<<20) for { <-sigs runtime.Stack(buf, true) log.Printf("=== received SIGQUIT ===\n*** goroutine dump...\n%s\n*** end\n", buf) } }() assert := assert.New(t) re, err := NewProcessManager(func() { return }, "/bin/sleep", []string{"100"}, func() error { return nil }, nil) assert.Nil(err) re.TearDown() procs, err := ps.Processes() if err != nil { t.Fatal("Could not get OS processes") } pid := os.Getpid() for _, proc := range procs { if proc.PPid() == pid { assert.Fail("There are children proccesses leftover") } } }
// Status prings status of the node and returns error (if any) func Status(args []string) { doc := `Usage: calicoctl node status Options: -h --help Show this screen. Description: Check the status of the Calico node instance. This incudes the status and uptime of the node instance, and BGP peering states. ` parsedArgs, err := docopt.Parse(doc, args, true, "", false, false) if err != nil { fmt.Printf("Invalid option: 'calicoctl %s'. Use flag '--help' to read about a specific subcommand.\n", strings.Join(args, " ")) os.Exit(1) } if len(parsedArgs) == 0 { return } // Must run this command as root to be able to connect to BIRD sockets enforceRoot() // Go through running processes and check if `calico-felix` processes is not running processes, err := gops.Processes() if err != nil { fmt.Println(err) } if !psContains("calico-felix", processes) { // Return and print message if calico-node is not running fmt.Printf("Calico process is not running.\n") os.Exit(1) } fmt.Printf("Calico process is running.\n") // Check if birdv4 process is running, print the BGP peer table if it is, else print a warning if psContains("bird", processes) { printBGPPeers("4") } else { fmt.Printf("\nINFO: BIRDv4 process: 'bird' is not running.\n") } // Check if birdv6 process is running, print the BGP peer table if it is, else print a warning if psContains("bird6", processes) { printBGPPeers("6") } else { fmt.Printf("\nINFO: BIRDv6 process: 'bird6' is not running.\n") } // Have to manually enter an empty line because the table print // library prints the last line, so can't insert a '\n' there fmt.Println() }
func main() { test, err := ps.Processes() if err != nil { fmt.Println(fmt.Sprintf("Error: %v", err.Error())) } for i := range test { if test[i].Executable() != "notepad.exe" { continue } fmt.Println(test[i].Pid(), test[i].Executable()) } }
// TODO: Fix test and decompress trusty into "root" // It needs to manage the root itself func TestREX(t *testing.T) { if os.Getenv("TRAVIS") == "true" { t.Skip("Unable to run test on Travis") } assert := assert.New(t) mgr := metamgr.NewMetadataManager("rmf5", []string{"127.0.0.1"}) c := cepm.NewCPMd(7902, mgr) go c.Background() // Port number for testing dirname, err := ioutil.TempDir("", "root") defer os.RemoveAll(dirname) t.Log("Decompressing into: ", dirname) assert.Nil(err) //defer os.RemoveAll(dirname) f, err := os.Open("../artifacts/data/trusty.tar.gz") assert.Nil(err) assert.Nil(common.ExtractGZ(dirname, f)) f, err = os.Open("../artifacts/data/riak_explorer-bin.tar.gz") assert.Nil(err) assert.Nil(common.ExtractGZ(dirname, f)) re, err := NewRiakExplorer(7901, "rex@ubuntu.", c, dirname, true) // 998th prime number. assert.Equal(nil, err) re.TearDown() _, err = re.NewRiakExplorerClient().Ping() assert.NotNil(err) procs, err := ps.Processes() if err != nil { t.Fatal("Could not get OS processes") } pid := os.Getpid() for _, proc := range procs { if proc.PPid() == pid { assert.Fail("There are children proccesses leftover") } } }
// Get all child process func (p *Process) Children(recursive bool) (cps []Process) { pses, err := mps.Processes() if err != nil { return } pidMap := make(map[int][]mps.Process, 0) for _, p := range pses { pidMap[p.PPid()] = append(pidMap[p.PPid()], p) } var travel func(int) travel = func(pid int) { for _, p := range pidMap[pid] { cps = append(cps, Process{p}) if recursive { travel(p.Pid()) } } } travel(p.Pid()) return }