コード例 #1
0
 def test_reload_session(self):
     self.sess.add(_PStruct(a=1, b='foo'))
     self.sess.add(_PStruct(a=2, b='bar'))
     self.sess.add(_PStruct(a=3, b='baz'))
     if hasattr(self, 'extra_args'):
         sess2 = Session(self.sess.path, **self.extra_args)
     else:
         sess2 = Session(self.sess.path)
     assert len(sess2) == 3
     for task_id in sess2.tasks.iterkeys():
         task = sess2.store.load(task_id)
         assert task == sess2.tasks[task_id]
     for task2_id, task1_id in zip(sorted(sess2.tasks.keys()),
                                   sorted(self.sess.tasks.keys())):
         assert (self.sess.tasks[task1_id] == sess2.tasks[task2_id])
コード例 #2
0
 def test_load_session_reads_session_start_time(self):
     """Check if session reads the creation time from the `created` file"""
     session2 = Session(self.sess.path)
     start_file = os.path.join(self.sess.path,
                               self.sess.TIMESTAMP_FILES['start'])
     assert os.stat(start_file).st_mtime == self.sess.created
     assert os.stat(start_file).st_mtime == session2.created
コード例 #3
0
 def test_incomplete_session_dir(self):
     tmpdir = tempfile.mktemp(dir='.')
     os.mkdir(tmpdir)
     incomplete_sess = Session(tmpdir)
     assert os.path.exists(os.path.join(tmpdir, Session.INDEX_FILENAME))
     assert os.path.exists(os.path.join(tmpdir, Session.STORE_URL_FILENAME))
     incomplete_sess.destroy()
コード例 #4
0
    def setUp(self):
        tmpdir = tempfile.mktemp(dir='.')
        self.tmpdir = tmpdir
        self.sess = Session(tmpdir)
        self.extra_args = {}

        yield

        self.sess.destroy()
コード例 #5
0
    def test_empty_lines_in_index_file(self):
        """Check that the index file is read correctly even when there
        are empty lines.

        Because of a bug, in some cases Session used to create invalid
        job ids equals to ''
        """
        self.sess.add(_PStruct(a=1, b='foo'), flush=True)
        fd_job_ids = open(
            os.path.join(self.sess.path, self.sess.INDEX_FILENAME), 'a')
        fd_job_ids.write('\n\n\n')
        if hasattr(self, 'extra_args'):
            self.sess = Session(self.sess.path, **self.extra_args)
        else:
            self.sess = Session(self.sess.path)
        ids = self.sess.list_ids()
        assert len(ids) == 1
        assert ids == [str(i) for i in self.sess.tasks]
コード例 #6
0
def test_create():
    tmpdir = tempfile.mktemp(dir='.')
    try:
        sess = Session(tmpdir)
        assert os.path.isdir(sess.path)
        sess.destroy()
    except:
        if os.path.exists(tmpdir):
            shutil.rmtree(tmpdir)
        raise
コード例 #7
0
ファイル: test_session.py プロジェクト: ryantaylor-cu/gc3pie
    def _with_tmp_session(self):
        tmpdir = tempfile.mktemp(
            prefix=(os.path.basename(__file__) + '.'),
            suffix='.d')
        self.tmpdir = tmpdir
        self.sess = Session(tmpdir)
        self.extra_args = {}

        yield

        self.sess.destroy()
コード例 #8
0
ファイル: test_session.py プロジェクト: ryantaylor-cu/gc3pie
 def test_incomplete_session_dir(self):
     tmpdir = tempfile.mktemp(
         prefix=(os.path.basename(__file__) + '.'),
         suffix='.d')
     os.mkdir(tmpdir)
     incomplete_sess = Session(tmpdir)
     assert os.path.exists(os.path.join(tmpdir,
                                             Session.INDEX_FILENAME))
     assert os.path.exists(os.path.join(tmpdir,
                                             Session.STORE_URL_FILENAME))
     incomplete_sess.destroy()
コード例 #9
0
ファイル: test_session.py プロジェクト: ryantaylor-cu/gc3pie
def test_create():
    tmpdir = tempfile.mktemp(
        prefix=(os.path.basename(__file__) + '.'),
        suffix='.d')
    try:
        sess = Session(tmpdir)
        assert os.path.isdir(sess.path)
        sess.destroy()
    except:
        if os.path.exists(tmpdir):
            shutil.rmtree(tmpdir)
        raise
コード例 #10
0
    def setUp(self):
        self.tmpdir = os.path.abspath(tempfile.mktemp(dir=os.getcwd()))
        #import pdb; pdb.set_trace()  ### DEBUG
        self.sess = Session(self.tmpdir,
                            create=True,
                            store_or_url="sqlite:///{0}/store.db".format(
                                self.tmpdir))

        yield

        if os.path.exists(self.tmpdir):
            shutil.rmtree(self.tmpdir)
コード例 #11
0
 def setUp(self):
     tmpdir = tempfile.mktemp(dir='.')
     self.tmpdir = os.path.basename(tmpdir)
     try:
         self.extra_args = {'table_name': self.tmpdir}
         self.sess = Session(
             tmpdir,
             store_url="mysql://*****:*****@localhost/gc3",
             **self.extra_args)
     except sqlalchemy.exc.OperationalError:
         if os.path.exists(tmpdir):
             shutil.rmtree(tmpdir)
         raise SkipTest("Cannot connect to MySQL database.")
コード例 #12
0
def test_destroy():
    tmpdir = tempfile.mktemp(dir='.')
    try:
        sess = Session(tmpdir)
        tid = sess.add(_PStruct(a=1, b='foo'))
        sess.destroy()
        # destroy should kill all traces of the sessiondir
        assert_false(os.path.exists(sess.path))
        # in particular, no task can be loaded
        sess.load(tid)
    except:
        if os.path.exists(tmpdir):
            shutil.rmtree(tmpdir)
        raise
コード例 #13
0
ファイル: test_session.py プロジェクト: ryantaylor-cu/gc3pie
    def _with_tmp_session(self):
        self.tmpdir = os.path.abspath(
            tempfile.mktemp(
                prefix=(os.path.basename(__file__) + '.'),
                suffix='.d'))
        self.sess = Session(
            self.tmpdir,
            create=True,
            store_or_url="sqlite:///{0}/store.db".format(self.tmpdir))
        self.extra_args = {}

        yield

        if os.path.exists(self.tmpdir):
            shutil.rmtree(self.tmpdir)
コード例 #14
0
 def _make_session(self, session_uri, store_url):
     # We rule out "simulated" sessions (the `TemporarySession`
     # class from `gc3libs.session`) because in that case there's
     # no index so *all* jobs will be loaded, which in even
     # moderate TM usage leads to out-of-memory errors soon.
     assert session_uri.scheme == 'file', (
         "tm_jobdaemon can only manage directory-based sessions!")
     self.log.info("Creating session at %s, storing tasks at %s ...",
                   session_uri, store_url)
     return Session(
         session_uri.path,
         create=True,
         store_or_url=store_url,
         extra_fields=get_gc3pie_store_extra_fields(),
         idfactory=idfactory,
     )
コード例 #15
0
ファイル: test_session.py プロジェクト: ryantaylor-cu/gc3pie
def test_destroy():
    tmpdir = tempfile.mktemp(
        prefix=(os.path.basename(__file__) + '.'),
        suffix='.d')
    try:
        sess = Session(tmpdir)
        tid = sess.add(_PStruct(a=1, b='foo'))
        sess.destroy()
        # destroy should kill all traces of the sessiondir
        assert not os.path.exists(sess.path)
        # in particular, no task can be loaded
        with pytest.raises(gc3libs.exceptions.LoadError):
            sess.load(tid)
    except:
        if os.path.exists(tmpdir):
            shutil.rmtree(tmpdir)
        raise
コード例 #16
0
ファイル: utils.py プロジェクト: TissueMAPS/TmLibrary
def create_gc3pie_session(location, store):
    '''Creates a `Session` instance for job persistence in the PostgresSQL table

    Parameters
    ----------
    location: str
        path to a directory on disk for the file system representation of the
        store
    store: gc3libs.persistence.store.Store
        store instance

    Returns
    -------
    gc3libs.persistence.session.Session
        `GC3Pie` session
    '''
    logger.debug('create GC3Pie session')
    return Session(location, store=store)
コード例 #17
0
ファイル: test_session.py プロジェクト: ryantaylor-cu/gc3pie
    def test_empty_lines_in_index_file(self):
        """
        Check that the index file is read correctly even when there
        are empty lines.

        Because of a bug, in some cases the
        `gc3libs.session.Session`:class: used to create invalid job
        ids (equal to ``''``).
        """
        self.sess.add(_PStruct(a=1, b='foo'), flush=True)
        with open(os.path.join(self.sess.path,
                               self.sess.INDEX_FILENAME), 'a') as fp:
            fp.write('\n\n\n')
            fp.flush()
        self.sess = Session(self.sess.path, **self.extra_args)
        ids = self.sess.list_ids()
        assert len(ids) == 1
        assert ids == [str(task_id) for task_id in self.sess.tasks]
コード例 #18
0
    def setUp(self):
        tmpdir = tempfile.mktemp(dir='.')
        self.tmpdir = os.path.basename(tmpdir)
        try:
            self.extra_args = {'table_name': self.tmpdir}
            self.sess = Session(
                tmpdir,
                store_url="mysql://*****:*****@localhost/gc3",
                **self.extra_args)
        except sqlalchemy.exc.OperationalError:
            if os.path.exists(tmpdir):
                shutil.rmtree(tmpdir)
            pytest.mark.skip("Cannot connect to MySQL database.")

        yield

        self.sess.destroy()
        conn = self.sess.store._engine.connect()
        conn.execute("drop table `%s`" % self.tmpdir)
コード例 #19
0
 def setUp(self):
     tmpdir = tempfile.mktemp(dir='.')
     self.tmpdir = os.path.basename(tmpdir)
     self.sess = Session(tmpdir,
                         store_url="sqlite:///%s/store.db" %
                         os.path.abspath(self.tmpdir))