Esempio n. 1
0
    def test(self):
        here = os.getcwd()
        mypid = os.getpid()
        with open("split-test.txt", "w") as f:
            f.write("foobar")
        with splitbrain(self.conn):
            try:
                path = tempfile.mkdtemp()

                import email

                self.assertNotIn("stale", repr(email))

                os.chdir(path)
                hispid = os.getpid()
                self.assertNotEqual(mypid, hispid)
                here2 = os.getcwd()
                self.assertNotEqual(here, here2)
                self.assertFalse(os.path.exists("split-test.txt"))
                with open("split-test.txt", "w") as f:
                    f.write("spam")

                with localbrain():
                    self.assertEqual(os.getpid(), mypid)
                    with open("split-test.txt", "r") as f:
                        self.assertEqual(f.read(), "foobar")

                try:
                    def f():
                        g()
                    def g():
                        h()
                    def h():
                        open("crap.txt", "r")
                    f()
                except IOError:
                    with localbrain():
                        tbtext = "".join(traceback.format_exception(*sys.exc_info()))
                    # pdb.post_mortem(sys.exc_info()[2])
                    self.assertIn("f()", tbtext)
                    self.assertIn("g()", tbtext)
                    self.assertIn("h()", tbtext)
                else:
                    self.fail("This should have raised a IOError")

            finally:
                # we must move away from the tempdir to delete it (at least on windows)
                os.chdir("/")
                shutil.rmtree(path)

        self.assertIn("stale", repr(email))

        self.assertEqual(os.getpid(), mypid)
        self.assertEqual(os.getcwd(), here)

        os.remove("split-test.txt")
Esempio n. 2
0
import rpyc
from rpyc.utils.splitbrain import splitbrain, localbrain
import traceback
import sys

c = rpyc.classic.connect("localhost")
import os
pid1 = os.getpid()

with open("tmp.txt", "w") as f:
    f.write("foobar")

with splitbrain(c):
    pid2 = os.getpid()
    assert pid1 != pid2
    import email
    print(email)
    import os as os2
    pid3 = os2.getpid()
    assert pid2 == pid3

    assert not os.path.exists("tmp.txt")

    with localbrain():
        with open("tmp.txt", "r") as f:
            assert f.read() == "foobar"
        pid4 = os.getpid()
        assert pid4 == pid1

    try:
        open("tmp.txt", "r")
Esempio n. 3
0
import sys
import rpyc
from plumbum import SshMachine
from rpyc.utils.zerodeploy import DeployedServer
from rpyc.utils.splitbrain import splitbrain

mach = SshMachine("192.168.1.117")

print sys.platform

with DeployedServer(mach) as dep:
    conn = dep.classic_connect()
    print conn.modules.sys.platform

    try:
        import posix
    except ImportError as ex:
        print ex

    with splitbrain(conn):
        import posix
        print posix.stat("/boot")

    print posix



Esempio n. 4
0
splitbrain.enable()
server_file = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "bin", "rpyc_classic.py")
proc = subprocess.Popen([sys.executable, server_file, "--mode=oneshot", "--host=localhost", "-p0"], 
    stdin = subprocess.PIPE, stdout = subprocess.PIPE, stderr = subprocess.PIPE)
assert proc.stdout.readline().strip() == six.b("rpyc-oneshot")
host, port = proc.stdout.readline().strip().split(six.b("\t"))
conn = rpyc.classic.connect(host, int(port))

here = os.getcwd()
mypid = os.getpid()

with open("split-test.txt", "w") as f:
    f.write("foobar")

with splitbrain(conn):
    try:
#        path = tempfile.mkdtemp()
#        
#        import email
#        
#        assert "stale" not in repr(email)
#        
#        os.chdir(path)
#        hispid = os.getpid()
#        assert mypid != hispid
#        here2 = os.getcwd()
#        assert here != here2
#        assert not os.path.exists("split-test.txt")
#        with open("split-test.txt", "w") as f:
#            f.write("spam")
Esempio n. 5
0
    def test(self):
        here = os.getcwd()
        mypid = os.getpid()
        with open("split-test.txt", "w") as f:
            f.write("foobar")
        with splitbrain(self.conn):
            try:
                path = tempfile.mkdtemp()

                import email

                self.assertNotIn("stale", repr(email))

                os.chdir(path)
                hispid = os.getpid()
                self.assertNotEqual(mypid, hispid)
                here2 = os.getcwd()
                self.assertNotEqual(here, here2)
                self.assertFalse(os.path.exists("split-test.txt"))
                with open("split-test.txt", "w") as f:
                    f.write("spam")

                with localbrain():
                    self.assertEqual(os.getpid(), mypid)
                    with open("split-test.txt", "r") as f:
                        self.assertEqual(f.read(), "foobar")

                try:

                    def f():
                        g()

                    def g():
                        h()

                    def h():
                        open("crap.txt", "r")

                    f()
                except IOError:
                    with localbrain():
                        tbtext = "".join(
                            traceback.format_exception(*sys.exc_info()))
                    # pdb.post_mortem(sys.exc_info()[2])
                    self.assertIn("f()", tbtext)
                    self.assertIn("g()", tbtext)
                    self.assertIn("h()", tbtext)
                else:
                    self.fail("This should have raised a IOError")

            finally:
                # we must move away from the tempdir to delete it (at least on windows)
                os.chdir("/")
                shutil.rmtree(path)

        self.assertIn("stale", repr(email))

        self.assertEqual(os.getpid(), mypid)
        self.assertEqual(os.getcwd(), here)

        os.remove("split-test.txt")
Esempio n. 6
0
import rpyc
from rpyc.utils.splitbrain import splitbrain, localbrain
import traceback
import sys


c = rpyc.classic.connect("localhost")
import os
pid1 = os.getpid()

with open("tmp.txt", "w") as f:
    f.write("foobar")

with splitbrain(c):
    pid2 = os.getpid()
    assert pid1 != pid2
    import email
    print (email)
    import os as os2
    pid3 = os2.getpid()
    assert pid2 == pid3
    
    assert not os.path.exists("tmp.txt")
    
    with localbrain():
        with open("tmp.txt", "r") as f:
            assert f.read() == "foobar"
        pid4 = os.getpid()
        assert pid4 == pid1
    
    try: