def check_host(host, port, timeout=5, check_with_session=False):
    """
    Checks if a given host/port is up and running (i.e., it is open).
    If ``check_with_session`` is ``True`` then it is assumed that the
    host/port combination corresponds to a Node Manager and the check is
    performed by attempting to create and delete a session.
    """
    if not check_with_session:
        return utils.portIsOpen(host, port, timeout)

    try:
        session_id = str(uuid.uuid4())
        with NodeManagerClient(host, port, timeout=timeout) as c:
            c.create_session(session_id)
            c.destroy_session(session_id)
        return True
    except:
        return False
Exemple #2
0
    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)
Exemple #3
0
    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)
Exemple #4
0
 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)
Exemple #5
0
 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"])