Ejemplo n.º 1
0
    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())
Ejemplo n.º 2
0
    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
Ejemplo n.º 3
0
    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
Ejemplo n.º 4
0
    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
Ejemplo n.º 5
0
 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')
Ejemplo n.º 6
0
 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'')
Ejemplo n.º 7
0
 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'')
Ejemplo n.º 8
0
 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'')
Ejemplo n.º 9
0
 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
Ejemplo n.º 10
0
 def test_short_failure(self):
     rc, _, _ = exec_cmd(['./py-watch', '0.2', 'false'])
     assert rc == 1
Ejemplo n.º 11
0
 def test_short_success(self):
     rc, _, _ = exec_cmd(['./py-watch', '0.2', 'true'])
     assert rc == 0
Ejemplo n.º 12
0
 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
Ejemplo n.º 13
0
 def test_short_failure(self):
     rc, _, _ = exec_cmd(['./py-watch', '0.2', 'false'])
     assert rc == 1
Ejemplo n.º 14
0
 def test_short_success(self):
     rc, _, _ = exec_cmd(['./py-watch', '0.2', 'true'])
     assert rc == 0