def test_set_perms_failure(self): self.mox.StubOutWithMock(openvz_conn.utils, 'execute') openvz_conn.utils.execute('chmod', 755, TEMPFILE, run_as_root=True)\ .AndRaise(exception.ProcessExecutionError) self.mox.ReplayAll() fh = openvz_conn.OVZFile(TEMPFILE) self.assertRaises(exception.Error, fh.set_permissions, 755)
def test_make_directory_failure(self): self.mox.StubOutWithMock(openvz_conn.utils, 'execute') openvz_conn.utils.execute('mkdir', '-p', TEMPFILE, run_as_root=True)\ .AndRaise(exception.ProcessExecutionError) self.mox.ReplayAll() fh = openvz_conn.OVZFile(TEMPFILE) self.assertRaises(exception.Error, fh.make_dir, TEMPFILE)
def test_set_perms_success(self): self.mox.StubOutWithMock(openvz_conn.utils, 'execute') openvz_conn.utils.execute('chmod', 755, TEMPFILE, run_as_root=True)\ .AndReturn(('', '')) self.mox.ReplayAll() fh = openvz_conn.OVZFile(TEMPFILE) fh.set_permissions(755)
def test_make_directory_success(self): self.mox.StubOutWithMock(openvz_conn.utils, 'execute') openvz_conn.utils.execute('mkdir', '-p', TEMPFILE, run_as_root=True) \ .AndReturn(('', '')) self.mox.ReplayAll() fh = openvz_conn.OVZFile(TEMPFILE) fh.make_dir(TEMPFILE)
def test_touch_file_failure(self): fh = openvz_conn.OVZFile(TEMPFILE) self.mox.StubOutWithMock(fh, 'make_path') fh.make_path() self.mox.StubOutWithMock(openvz_conn.utils, 'execute') openvz_conn.utils.execute('touch', TEMPFILE, run_as_root=True)\ .AndRaise(exception.ProcessExecutionError) self.mox.ReplayAll() self.assertRaises(exception.Error, fh.touch)
def test_touch_file_success(self): fh = openvz_conn.OVZFile(TEMPFILE) self.mox.StubOutWithMock(fh, 'make_path') fh.make_path() self.mox.StubOutWithMock(openvz_conn.utils, 'execute') openvz_conn.utils.execute('touch', TEMPFILE, run_as_root=True)\ .AndReturn(('', '')) self.mox.ReplayAll() fh.touch()
def test_write_to_file_failure(self): self.mox.StubOutWithMock(__builtin__, 'open') __builtin__.open(mox.IgnoreArg(), 'w').AndRaise(exception.Error) self.mox.ReplayAll() fh = openvz_conn.OVZFile(TEMPFILE) self.assertRaises(exception.Error, fh.write)
def test_write_to_file_success(self): self.mox.StubOutWithMock(__builtin__, 'open') __builtin__.open(mox.IgnoreArg(), 'w').AndReturn(self.fake_file) self.mox.ReplayAll() fh = openvz_conn.OVZFile(TEMPFILE) fh.write()