def testV2VOutput(self): cmd = [FAKE_VIRT_V2V.cmd, '-v', '-x', '-ic', self.vpx_url, '-o', 'vdsm', '-of', 'raw', '-oa', 'sparse', '--vdsm-image-uuid', self.image_id_a, '--vdsm-vol-uuid', self.volume_id_a, '--vdsm-image-uuid', self.image_id_b, '--vdsm-vol-uuid', self.volume_id_b, '--password-file', '/tmp/mypass', '--vdsm-vm-uuid', self.job_id, '--vdsm-ovf-output', '/usr/local/var/run/vdsm/v2v', '--machine-readable', '-os', '/rhev/data-center/%s/%s' % (self.pool_id, self.domain_id), self.vm_name] rc, output, error = exec_cmd(cmd) self.assertEqual(rc, 0) with io.open('fake-virt-v2v.out', 'rb') as f: self.assertEqual(output, f.read()) with io.open('fake-virt-v2v.err', 'rb') as f: self.assertEqual(error, f.read())
def test_kill_grandkids(self): # watch a bash process that starts a grandchild bash process. # The grandkid bash echoes its pid and sleeps a lot. # on timeout, py-watch should kill the process session spawned by it. rc, out, err = exec_cmd([ './py-watch', '0.2', 'bash', '-c', 'bash -c "readlink /proc/self; sleep 10"']) # assert that the internal bash no longer exist grandkid_pid = int(out.splitlines()[0]) with pytest.raises(OSError) as excinfo: assert os.kill(grandkid_pid, 0) assert excinfo.value.errno == errno.ESRCH
def test_timeout_backtrace(self): script = ''' import time def outer(): inner() def inner(): time.sleep(10) outer() ''' rc, out, err = exec_cmd(['./py-watch', '0.1', 'python', '-c', script]) assert b'in inner ()' in out assert b'in outer ()' in out
def test_exec_cmd_with_env(self): rc, out, err = cmdutils.exec_cmd( ('sh', '-c', 'echo $XXX'), env={'XXX': 'hello'}) self.assertEqual(rc, 0) self.assertEqual(out, b'hello\n')
def test_exec_cmd_with_error_output(self): rc, out, err = cmdutils.exec_cmd(('ls', 'no such prog')) self.assertNotEqual(rc, 0) self.assertIn(b'No such file or directory', err) self.assertEqual(out, b'')
def test_exec_cmd_with_success_output(self): rc, out, err = cmdutils.exec_cmd(('echo', 'hello world')) self.assertEqual(rc, 0, err) self.assertEqual(out, b'hello world\n') self.assertEqual(err, b'')
def test_exec_cmd_with_no_output(self): rc, out, err = cmdutils.exec_cmd(('true',)) self.assertEqual(rc, 0) self.assertEqual(out, b'') self.assertEqual(err, b'')
def test_timeout_output(self): rc, out, err = exec_cmd(['./py-watch', '0.1', 'sleep', '10']) assert b'Watched process timed out' in out assert b'Terminating watched process' in out assert rc == 128 + signal.SIGTERM
def test_short_failure(self): rc, _, _ = exec_cmd(['./py-watch', '0.2', 'false']) assert rc == 1
def test_short_success(self): rc, _, _ = exec_cmd(['./py-watch', '0.2', 'true']) assert rc == 0