Exemplo n.º 1
0
    def test_clientServer(self):
        """
        A client-server duo. The server outputs the data it receives to its
        output DROP, which in turn is the data held in its input DROP. The graph
        looks like this:

        A --|--> B(client) --|--> D
            |--> C(server) --|

        C is a server application which B connects to. Therefore C must be
        started before B, so B knows C's IP address and connects successfully.
        Although the real writing is done by C, B in this example is also
        treated as a publisher of D. This way D waits for both applications to
        finish before proceeding.
        """

        a = FileDROP('a', 'a')
        b = DockerApp('b', 'b', image='ubuntu:14.04', command='cat %i0 > /dev/tcp/%containerIp[c]%/8000')
        c = DockerApp('c', 'c', image='ubuntu:14.04', command='nc -l 8000 > %o0')
        d = FileDROP('d', 'd')

        b.addInput(a)
        b.addOutput(d)
        c.addInput(a)
        c.addOutput(d)

        # Let 'b' handle its interest in c
        b.handleInterest(c)

        data = os.urandom(10)
        with DROPWaiterCtx(self, d, 100):
            a.write(data)
            a.setCompleted()

        self.assertEqual(data, droputils.allDropContents(d))
Exemplo n.º 2
0
    def test_simpleCopy(self):
        """
        Simple test for a dockerized application. It copies the contents of one
        file into another via the command-line cp utility. It then checks that
        the contents of the target DROP are correct, and that the target file is
        actually owned by our process.
        """

        a = FileDROP("a", "a")
        b = DockerApp("b", "b", image="ubuntu:14.04", command="cp %i0 %o0")
        c = FileDROP("c", "c")

        b.addInput(a)
        b.addOutput(c)

        # Random data so we always check different contents
        data = os.urandom(10)
        with DROPWaiterCtx(self, c, 100):
            a.write(data)
            a.setCompleted()

        self.assertEqual(data, droputils.allDropContents(c))

        # We own the file, not root
        uid = os.getuid()
        self.assertEqual(uid, os.stat(c.path).st_uid)
Exemplo n.º 3
0
    def test_additional_bindings(self):

        # Some additional stuff to bind into docker
        tempDir = tempfile.mkdtemp()
        tempFile = tempfile.mktemp()
        with open(tempFile, "w") as f:
            f.write("data")

        # One binding specifies the target path in the container, the other doesn't
        # so it defaults to the same path
        a = DockerApp(
            "a",
            "a",
            image="ubuntu:14.04",
            command="cp /opt/file %s" % (tempDir, ),
            additionalBindings=[tempDir,
                                "%s:/opt/file" % (tempFile, )],
        )
        a.execute()

        # We copied the file into the directory, but since in the container the
        # file was called "file" we'll see it with that name in tempDir
        self.assertEqual(1, len(os.listdir(tempDir)))
        with open(os.path.join(tempDir, "file")) as f:
            data = f.read()
        self.assertEqual("data", data)

        # Cleanup
        os.unlink(tempFile)
        shutil.rmtree(tempDir)
Exemplo n.º 4
0
 def assertMsgIsCorrect(msg, command):
     a = DockerApp("a", "a", image="ubuntu:14.04", command=command)
     b = FileDROP("b", "b")
     a.addOutput(b)
     with DROPWaiterCtx(self, b, 100):
         a.execute()
     self.assertEqual(msg.encode("utf8"), droputils.allDropContents(b))
Exemplo n.º 5
0
 def assertMsgIsCorrect(msg, command):
     a = DockerApp('a', 'a', image='ubuntu:14.04', command=command)
     b = FileDROP('b', 'b')
     a.addOutput(b)
     with DROPWaiterCtx(self, b, 100):
         a.execute()
     self.assertEqual(six.b(msg), droputils.allDropContents(b))
Exemplo n.º 6
0
 def _ngas_and_fs_io(self, command):
     a = NgasDROP('a', 'a')  # not a filesystem-related DROP, we can reference its URL in the command-line
     b = DockerApp('b', 'b', image="ubuntu:14.04", command=command)
     c = FileDROP('c', 'c')
     b.addInput(a)
     b.addOutput(c)
     with DROPWaiterCtx(self, c, 100):
         a.setCompleted()
     self.assertEqual(six.b(a.dataURL), droputils.allDropContents(c))
Exemplo n.º 7
0
 def _ngas_and_fs_io(self, command):
     a = NgasDROP(
         "HelloWorld.txt", "HelloWorld.txt"
     )  # not a filesystem-related DROP, we can reference its URL in the command-line
     a.ngasSrv = "ngas.ddns.net"
     b = DockerApp("b", "b", image="ubuntu:14.04", command=command)
     c = FileDROP("c", "c")
     b.addInput(a)
     b.addOutput(c)
     with DROPWaiterCtx(self, c, 100):
         a.setCompleted()
     self.assertEqual(a.dataURL.encode("utf8"),
                      droputils.allDropContents(c))
Exemplo n.º 8
0
 def _test_working_dir(self, ensureUserAndSwitch):
     # the sleep is required to make sure that the docker container exists long enough for
     # DALiuGE to get the required information (2 lines of Python code after starting the container!)
     a = DockerApp(
         "a",
         "a",
         workingDir="/mydir",
         image="ubuntu:14.04",
         command="pwd > %o0 && sleep 0.05",
         ensureUserAndSwitch=ensureUserAndSwitch,
     )
     b = FileDROP("b", "b")
     a.addOutput(b)
     with DROPWaiterCtx(self, b, 10):
         a.execute()
     self.assertEqual(b"/mydir", droputils.allDropContents(b).strip())