コード例 #1
0
ファイル: test_dim.py プロジェクト: Zylatis/daliuge
class LocalDimStarter(ManagerStarter):
    def setUp(self):
        super(LocalDimStarter, self).setUp()
        self.nm_info = self.start_nm_in_thread()
        self.dm = self.nm_info.manager
        self.dim = DataIslandManager([hostname])

    def tearDown(self):
        self.nm_info.stop()
        self.dim.shutdown()
        super(LocalDimStarter, self).tearDown()
コード例 #2
0
ファイル: test_rest.py プロジェクト: Zylatis/daliuge
    def setUp(self):
        unittest.TestCase.setUp(self)
        self.dm = NodeManager(False)
        self._dm_server = NMRestServer(self.dm)
        self._dm_t = threading.Thread(target=self._dm_server.start,
                                      args=(hostname,
                                            constants.NODE_DEFAULT_REST_PORT))
        self._dm_t.start()

        self.dim = DataIslandManager(dmHosts=[hostname])
        self._dim_server = CompositeManagerRestServer(self.dim)
        self._dim_t = threading.Thread(
            target=self._dim_server.start,
            args=(hostname, constants.ISLAND_DEFAULT_REST_PORT))
        self._dim_t.start()
コード例 #3
0
ファイル: test_rest.py プロジェクト: Zylatis/daliuge
class TestRest(unittest.TestCase):
    def setUp(self):
        unittest.TestCase.setUp(self)
        self.dm = NodeManager(False)
        self._dm_server = NMRestServer(self.dm)
        self._dm_t = threading.Thread(target=self._dm_server.start,
                                      args=(hostname,
                                            constants.NODE_DEFAULT_REST_PORT))
        self._dm_t.start()

        self.dim = DataIslandManager(dmHosts=[hostname])
        self._dim_server = CompositeManagerRestServer(self.dim)
        self._dim_t = threading.Thread(
            target=self._dim_server.start,
            args=(hostname, constants.ISLAND_DEFAULT_REST_PORT))
        self._dim_t.start()

    def tearDown(self):
        unittest.TestCase.tearDown(self)
        self._dm_server.stop()
        self._dm_t.join()
        self.dm.shutdown()
        self.assertFalse(self._dm_t.is_alive())

        self._dim_server.stop()
        self._dim_t.join()
        self.dim.shutdown()
        self.assertFalse(self._dim_t.is_alive())

    def test_index(self):
        # Just check that the HTML pages load properly
        with RestClient(hostname, constants.NODE_DEFAULT_REST_PORT, 10) as c:
            c._GET('/')
            c._GET('/session')

    def test_errtype(self):

        sid = 'lala'
        c = NodeManagerClient(hostname)
        c.createSession(sid)

        # already exists
        self.assertRaises(exceptions.SessionAlreadyExistsException,
                          c.createSession, sid)

        # different session
        self.assertRaises(exceptions.NoSessionException, c.addGraphSpec,
                          sid + "x", [{}])

        # invalid dropspec, it has no oid/type (is completely empty actually)
        self.assertRaises(exceptions.InvalidGraphException, c.addGraphSpec,
                          sid, [{}])

        # invalid dropspec, app doesn't exist
        self.assertRaises(exceptions.InvalidGraphException, c.addGraphSpec,
                          sid, [{
                              'oid': 'a',
                              'type': 'app',
                              'app': 'doesnt.exist'
                          }])

        # invalid state, the graph status is only queried when the session is running
        self.assertRaises(exceptions.InvalidSessionState, c.getGraphStatus,
                          sid)

        # valid dropspec, but the socket listener app doesn't allow inputs
        c.addGraphSpec(sid, [{
            'type': 'socket',
            'oid': 'a',
            'inputs': ['b']
        }, {
            'oid': 'b',
            'type': 'plain',
            'storage': Categories.MEMORY
        }])
        self.assertRaises(exceptions.InvalidRelationshipException,
                          c.deploySession, sid)

        # And here we point to an unexisting file, making an invalid drop
        c.destroySession(sid)
        c.createSession(sid)
        fname = tempfile.mktemp()
        c.addGraphSpec(sid, [{
            'type': 'plain',
            'storage': Categories.FILE,
            'oid': 'a',
            'filepath': fname,
            'check_filepath_exists': True
        }])
        self.assertRaises(exceptions.InvalidDropException, c.deploySession,
                          sid)

    def test_recursive(self):

        sid = 'lala'
        c = DataIslandManagerClient(hostname)
        c.createSession(sid)

        # invalid dropspec, app doesn't exist
        # This is not checked at the DIM level but only at the NM level
        # The exception should still pass through though
        with self.assertRaises(exceptions.SubManagerException) as cm:
            c.addGraphSpec(sid, [{
                'oid': 'a',
                'type': 'app',
                'app': 'doesnt.exist',
                'node': hostname
            }])
        ex = cm.exception
        self.assertTrue(hostname in ex.args[0])
        self.assertTrue(isinstance(ex.args[0][hostname],
                                   InvalidGraphException))
コード例 #4
0
ファイル: test_rest.py プロジェクト: ICRAR/daliuge
class TestRest(unittest.TestCase):
    def setUp(self):
        unittest.TestCase.setUp(self)
        self.dm = NodeManager(False)
        self._dm_server = NMRestServer(self.dm)
        self._dm_t = threading.Thread(
            target=self._dm_server.start,
            args=(hostname, constants.NODE_DEFAULT_REST_PORT),
        )
        self._dm_t.start()

        self.dim = DataIslandManager(dmHosts=[hostname])
        self._dim_server = CompositeManagerRestServer(self.dim)
        self._dim_t = threading.Thread(
            target=self._dim_server.start,
            args=(hostname, constants.ISLAND_DEFAULT_REST_PORT),
        )
        self._dim_t.start()

    def tearDown(self):
        unittest.TestCase.tearDown(self)
        self._dm_server.stop()
        self._dm_t.join()
        self.dm.shutdown()
        self.assertFalse(self._dm_t.is_alive())

        self._dim_server.stop()
        self._dim_t.join()
        self.dim.shutdown()
        self.assertFalse(self._dim_t.is_alive())

    def test_index(self):
        # Just check that the HTML pages load properly
        with RestClient(hostname, constants.NODE_DEFAULT_REST_PORT, timeout=10) as c:
            c._GET("/")
            c._GET("/session")

    def test_errtype(self):
        sid = "lala"
        c = NodeManagerClient(hostname)
        c.createSession(sid)
        gempty = [{}]
        add_test_reprodata(gempty)
        # already exists
        self.assertRaises(
            exceptions.SessionAlreadyExistsException, c.createSession, sid
        )

        # different session
        self.assertRaises(
            exceptions.NoSessionException, c.addGraphSpec, sid + "x", [{}]
        )

        # invalid dropspec, it has no oid/type (is completely empty actually)
        self.assertRaises(exceptions.InvalidGraphException, c.addGraphSpec, sid, gempty)

        # invalid dropspec, app doesn't exist
        self.assertRaises(
            exceptions.InvalidGraphException,
            c.addGraphSpec,
            sid,
            [
                {
                    "oid": "a",
                    "type": "app",
                    "app": "doesnt.exist",
                    "reprodata": default_repro.copy(),
                },
                default_graph_repro.copy(),
            ],
        )

        # invalid state, the graph status is only queried when the session is running
        self.assertRaises(exceptions.InvalidSessionState, c.getGraphStatus, sid)

        # valid dropspec, but the socket listener app doesn't allow inputs
        c.addGraphSpec(
            sid,
            [
                {
                    "type": "socket",
                    "oid": "a",
                    "inputs": ["b"],
                    "reprodata": default_repro.copy(),
                },
                {
                    "oid": "b",
                    "type": "plain",
                    "storage": Categories.MEMORY,
                    "reprodata": default_repro.copy(),
                },
                default_graph_repro.copy(),
            ],
        )
        self.assertRaises(exceptions.InvalidRelationshipException, c.deploySession, sid)

        # And here we point to an unexisting file, making an invalid drop
        c.destroySession(sid)
        c.createSession(sid)
        fname = tempfile.mktemp()
        c.addGraphSpec(
            sid,
            [
                {
                    "type": "plain",
                    "storage": Categories.FILE,
                    "oid": "a",
                    "filepath": fname,
                    "check_filepath_exists": True,
                    "reprodata": default_repro.copy(),
                },
                default_graph_repro.copy(),
            ],
        )
        self.assertRaises(exceptions.InvalidDropException, c.deploySession, sid)

    def test_recursive(self):
        sid = "lala"
        c = DataIslandManagerClient(hostname)
        c.createSession(sid)

        # invalid dropspec, app doesn't exist
        # This is not checked at the DIM level but only at the NM level
        # The exception should still pass through though
        with self.assertRaises(exceptions.SubManagerException) as cm:
            c.addGraphSpec(
                sid,
                [
                    {
                        "oid": "a",
                        "type": "app",
                        "app": "doesnt.exist",
                        "node": hostname,
                        "reprodata": default_repro.copy(),
                    },
                    default_graph_repro.copy(),
                ],
            )
        ex = cm.exception
        self.assertTrue(hostname in ex.args[0])
        self.assertTrue(isinstance(ex.args[0][hostname], InvalidGraphException))

    def test_reprodata_get(self):
        """
        Tests deploying an incredibly basic graph with and without reprodata
        Then querying the manager for that reprodata.
        """
        sid = "1234"
        c = NodeManagerClient(hostname)
        graph_spec = [
            {
                "type": "plain",
                "storage": Categories.MEMORY,
                "oid": "a",
                "reprodata": default_repro.copy(),
            },
            default_graph_repro.copy(),
        ]
        # Test with reprodata
        c.createSession(sid)
        c.addGraphSpec(sid, graph_spec)
        c.deploySession(sid, completed_uids=["a"])
        response = c.session_repro_data(sid)
        self.assertIsNotNone(response["graph"]["a"]["reprodata"]["rg_blockhash"])
        self.assertIsNotNone(response["reprodata"])
        c.destroySession(sid)
        # Test without reprodata
        graph_spec = graph_spec[0:1]
        graph_spec[0].pop("reprodata")
        c.createSession(sid)
        c.addGraphSpec(sid, graph_spec)
        c.deploySession(sid, completed_uids=["a"])
        response = c.session_repro_data(sid)
        self.assertEqual(
            {"a": {"oid": "a", "storage": "Memory", "type": "plain"}}, response["graph"]
        )
        self.assertEqual({}, response["reprodata"])

    def test_reprostatus_get(self):
        # Test with reprodata
        sid = "1234"
        c = NodeManagerClient(hostname)
        graph_spec = [
            {
                "type": "plain",
                "storage": Categories.MEMORY,
                "oid": "a",
                "reprodata": default_repro.copy(),
            },
            default_graph_repro.copy(),
        ]
        c.createSession(sid)
        c.addGraphSpec(sid, graph_spec)
        c.deploySession(sid, completed_uids=["a"])
        response = c.session_repro_status(sid)
        self.assertTrue(response)
        c.destroySession(sid)
        # Test without reprodata
        graph_spec = graph_spec[0:1]
        graph_spec[0].pop("reprodata")
        c.createSession(sid)
        c.addGraphSpec(sid, graph_spec)
        c.deploySession(sid, completed_uids=["a"])
        response = c.session_repro_status(sid)
        self.assertTrue(response)
        c.destroySession(sid)
コード例 #5
0
ファイル: test_dim.py プロジェクト: Zylatis/daliuge
 def setUp(self):
     super(LocalDimStarter, self).setUp()
     self.nm_info = self.start_nm_in_thread()
     self.dm = self.nm_info.manager
     self.dim = DataIslandManager([hostname])