The problem is that when I create a process and execute the command, the process doesn't terminate. I have to set a time limit but this is a problem since even if the process I create takes only 1 sec, it will last until this time limit pass because the process doesnt terminate.
Code: Select all
#Connect to the current guest VM and return guestSession object on success or -1 on fail
def _connectToGuest(self, machine):
guest = self.session.console.guest
#Creating session with the guest VM
guestSession = ""
if (machine == cons.ATTACKER):
guestSession = guest.createSession(self.attackerUser, self.attackerPass, "", "")
elif (machine == cons.DEFENDER):
guestSession = guest.createSession(self.defenderUser, self.defenderPass, "", "")
result = guestSession.waitFor(1, cons.GuestSessionConnectionTimeout)
if (result != 1):
print result
self._printFail("Connecting to guest VM...")
return -1
else:
self._printSuccess("Connecting to guest VM...")
return guestSession
#Lock the given machine to the current session
def _lockMachine (self, machine, mode):
if (machine == cons.DEFENDER):
self.defenderMachine = self.vbox.findMachine(self.defenderMachineName)
self.defenderMachine.lockMachine(self.session, mode)
elif (machine == cons.ATTACKER):
self.attackerMachine = self.vbox.findMachine(self.attackerMachineName)
self.attackerMachine.lockMachine(self.session, mode)
else:
self._printFail("Locking machine...")
return -1
return 0
def runScript(self, machine, scriptURL, args):
#Lock given machine to the current session
lock = self._lockMachine(machine, cons.LockType_Shared)
if (lock == 0):
guestSession = self._connectToGuest(machine)
if (guestSession != -1):
guestProcess = guestSession.processCreate("/bin/sh", [scriptURL, args[0], args[1]], [], [5], 0)
result = guestProcess.waitFor(2, 3000)
data = guestProcess.read(1, 1000000, 100000)
result = guestProcess.waitFor(2, 3000)
print data
print guestProcess.status
print result
#Close guest session
guestSession.close()
#Unlock machine
self.session.unlockMachine()
else:
#Unlock machine
self.session.unlockMachine()