Exemplo n.º 1
0
class Command:
    """Command is a class designed to assist implmentation of CLI programs.
    Expacted to be inherited.
    """

    cf = None
    logger = None

    def __init__(self):
        if os.environ.has_key('PYSILHOUETTE_CONF') is False:
            print >>sys.stderr, '[Error] "PYSILHOUETTE_CONF" did not exist in the environment.'
            sys.exit(1)
            
        self.cf = pysilhouette.prep.readconf(os.environ['PYSILHOUETTE_CONF'])
        if self.logger is None:
            pysilhouette.log.reload_conf(self.cf["env.sys.log.conf.path"])
            self.logger = logging.getLogger('pysilhouette.command') 

        try:
            self.db = Database(self.cf['database.url'],
                          encoding="utf-8",
                          convert_unicode=True,
                          #assert_unicode='warn', # DEBUG
                          echo = False,
                          echo_pool = False,
                          )

            reload_mappers(self.db.get_metadata())
            self.session = self.db.get_session()
        except Exception, e:
            print >>sys.stderr, '[Error] Initializing a database error - %s' % str(e.args)
            self.logger.error('Initializing a database error - %s' % str(e.args))
            t_logger = logging.getLogger('pysilhouette_traceback')
            t_logger.error(traceback.format_exc())
            sys.exit(1)
Exemplo n.º 2
0
    def __init__(self):
        if os.environ.has_key('PYSILHOUETTE_CONF') is False:
            print >> sys.stderr, '[Error] "PYSILHOUETTE_CONF" did not exist in the environment.'
            sys.exit(1)

        self.cf = pysilhouette.prep.readconf(os.environ['PYSILHOUETTE_CONF'])
        if self.logger is None:
            pysilhouette.log.reload_conf(self.cf["env.sys.log.conf.path"])
            self.logger = logging.getLogger('pysilhouette.command')

        try:
            self.db = Database(
                self.cf['database.url'],
                encoding="utf-8",
                convert_unicode=True,
                #assert_unicode='warn', # DEBUG
                echo=False,
                echo_pool=False,
            )

            reload_mappers(self.db.get_metadata())
            self.session = self.db.get_session()
        except Exception, e:
            print >> sys.stderr, '[Error] Initializing a database error - %s' % str(
                e.args)
            self.logger.error('Initializing a database error - %s' %
                              str(e.args))
            t_logger = logging.getLogger('pysilhouette_traceback')
            t_logger.error(traceback.format_exc())
            sys.exit(1)
Exemplo n.º 3
0
    def setUp(self):
        # O/R mapping
        self._db = Database(cf['database.url'],
                            encoding="utf-8",
                            convert_unicode=True,
                            echo=True)
        reload_mappers(self._db.get_metadata())

        # database init
        self._db.get_metadata().drop_all()
        self._db.get_metadata().create_all()  # create table
        pass
Exemplo n.º 4
0
    def setUp(self):
        # O/R mapping
        self._db = Database(cf['database.url'], encoding="utf-8", convert_unicode=True, echo=True)
        reload_mappers(self._db.get_metadata())

        # database init
        self._db.get_metadata().drop_all()
        self._db.get_metadata().create_all() # create table
        pass
Exemplo n.º 5
0
def main():
    (opts, args) = getopts()
    if chkopts(opts) is True:
        return 1
    
    try:
        input_db = Database(opts.input,
                      encoding="utf-8",
                      convert_unicode=True,
                      assert_unicode=DEBUG,
                      echo=DEBUG,
                      echo_pool=DEBUG
                      )

        reload_mappers(input_db.get_metadata())

        output_db = Database(opts.output,
                      encoding="utf-8",
                      convert_unicode=True,
                      assert_unicode=DEBUG,
                      echo=DEBUG,
                      echo_pool=DEBUG
                      )

        reload_mappers(output_db.get_metadata())

    except Exception, e:
        print >>sys.stderr, 'Initializing a database error'
        raise
Exemplo n.º 6
0
def get_engine():
    """<comment-ja>
    Databaseを返却します。(Optimistic Singleton)
    </comment-ja>
    <comment-en>
    TODO: English Comment
    </comment-en>
    """
    global __db
    if __db is None:
        logger = logging.getLogger("karesansui.pysilhouette.db.engine")
        echo = True
        echo_pool = True

        if karesansui.sheconf['database.url'][:6].strip() == 'sqlite':
            __db = Database(karesansui.sheconf['database.url'],
                          encoding="utf-8",
                          convert_unicode=True,
                          #assert_unicode='warn', # DEBUG
                          echo = echo,
                          echo_pool = echo_pool,
                          )
        else:
            if int(karesansui.sheconf['database.pool.status']) == 0:
                __db = Database(karesansui.sheconf['database.url'],
                              encoding="utf-8",
                              convert_unicode=True,
                              #assert_unicode='warn', # DEBUG
                              poolclass=SingletonThreadPool,
                              #echo = opts.verbose,
                              #echo_pool = opts.verbose,
                              echo=echo,
                              echo_pool=echo_pool
                              )
            else:
                __db = Database(karesansui.sheconf['database.url'],
                              encoding="utf-8",
                              convert_unicode=True,
                              #assert_unicode='warn', # DEBUG
                              poolclass=QueuePool,
                              pool_size=int(karesansui.sheconf['database.pool.size']),
                              max_overflow=int(karesansui.sheconf['database.pool.max.overflow']),
                              #echo = opts.verbose,
                              #echo_pool = opts.verbose,
                              echo=echo,
                              echo_pool=echo_pool
                              )

        __engine = __db.get_engine()

        # mapper!!
        mapper(__db.get_metadata())

        logger.debug('[pysilhouette] engine.name=%s - pool=%s' % (__engine.name, __engine.pool.__class__))
    return __db.get_engine()
Exemplo n.º 7
0
def test_setup(cf):
    # --
    db = Database(cf['database.url'], encoding='utf-8', convert_unicode=True)
    reload_mappers(db.get_metadata())

    db.get_metadata().drop_all()
    db.get_metadata().create_all()

    f_cmd = (
        u'python /root/repository/pysilhouette_svn/pysilhouette/job/sendmail.py'
        u' --from="root@localhost"'
        u' --to="root@localhost"'
        u' --subject="test"'
        u' --hostname="localhost"'
        u' --port="25"'
        u' --msg="%s"'
        u' --charset="utf-8"')

    session = db.get_session()
    jg1 = JobGroup(u'get date', '172.16.0.123')
    jg1.finish_command = f_cmd % jg1.name
    jb1 = Job(u'get date', '0', u'/bin/date error')
    jb1.rollback_command = u'/bin/date'
    jg1.jobs.append(jb1)
    jg2 = JobGroup(u'get route', '172.16.0.123')
    jg2.finish_command = f_cmd % jg2.name
    jg2.jobs.append(Job(u'get route', '1', u'/sbin/route'))
    jg3 = JobGroup(u'print string', '172.16.0.123')
    jg3.finish_command = f_cmd % jg3.name
    jg3.jobs.append(Job(u'print string', '2', u'/bin/echo test'))
    session.add_all([jg1, jg2, jg3])
    #session.add(jg1)
    session.commit()

    from pysilhouette.db.access import jobgroup_findbystatus
    _m_jgs = jobgroup_findbystatus(session)
    return db, session, _m_jgs
Exemplo n.º 8
0
def test_setup(cf):
    # --
    db = Database(cf['database.url'], encoding='utf-8', convert_unicode=True)
    reload_mappers(db.get_metadata())

    db.get_metadata().drop_all()
    db.get_metadata().create_all()

    f_cmd = (u'python /root/repository/pysilhouette_svn/pysilhouette/job/sendmail.py'
             u' --from="root@localhost"'
             u' --to="root@localhost"'
             u' --subject="test"'
             u' --hostname="localhost"'
             u' --port="25"'
             u' --msg="%s"'
             u' --charset="utf-8"')

    session = db.get_session()
    jg1 = JobGroup(u'get date', '172.16.0.123')
    jg1.finish_command = f_cmd % jg1.name
    jb1 = Job(u'get date','0',u'/bin/date error')
    jb1.rollback_command = u'/bin/date'
    jg1.jobs.append(jb1)
    jg2 = JobGroup(u'get route', '172.16.0.123')
    jg2.finish_command = f_cmd % jg2.name
    jg2.jobs.append(Job(u'get route','1', u'/sbin/route'))
    jg3 = JobGroup(u'print string', '172.16.0.123')
    jg3.finish_command = f_cmd % jg3.name
    jg3.jobs.append(Job(u'print string','2', u'/bin/echo test'))
    session.add_all([jg1,jg2,jg3])
    #session.add(jg1)
    session.commit()

    from pysilhouette.db.access import jobgroup_findbystatus
    _m_jgs = jobgroup_findbystatus(session)
    return db, session, _m_jgs
Exemplo n.º 9
0
class TestWorker(unittest.TestCase):
    """
    """
    _db = None

    def setUp(self):
        # O/R mapping
        self._db = Database(cf['database.url'], encoding="utf-8", convert_unicode=True, echo=True)
        reload_mappers(self._db.get_metadata())

        # database init
        self._db.get_metadata().drop_all()
        self._db.get_metadata().create_all() # create table
        pass

    def tearDown(self):
        sqlalchemy.orm.clear_mappers()
        pass

    def set_job(self, session, jg_name, uniqkey, 
                job=(True, True, True), rollback=None, mail=None):
        jg1 = JobGroup(jg_name.decode('utf-8'), uniqkey)

        if job[0] is True:
            j1 = Job(u'file create','0','/bin/touch /tmp/test_case1.txt')
        else:
            j1 = Job(u'file create','0','/bin/touch_dummy /tmp/test_case1.txt')

        if job[1] is True:
            j2 = Job(u'file copy', '1', '/bin/cp /tmp/test_case1.txt /tmp/test_case1_rename.txt')
        else:
            j2 = Job(u'file copy', '1', '/bin/cp_dummy /tmp/test_case1.txt /tmp/test_case1_rename.txt')

        if job[2] is True:
            j3 = Job(u'file delete','2','/bin/rm /tmp/test_case1.txt')
        else:
            j3 = Job(u'file delete','2','/bin/rm_dummy /tmp/test_case1.txt')

        jg1.jobs.append(j1)
        jg1.jobs.append(j2)
        jg1.jobs.append(j3)

        if rollback is True:
            j1.rollback_command = u'/bin/echo JOB1 rollback'
            j2.rollback_command = u'/bin/echo JOB2 rollback'
            j3.rollback_command = u'/bin/echo JOB3 rollback'
        elif rollback is False:
            j1.rollback_command = u'/bin/echo_dummy JOB1 rollback'
            j2.rollback_command = u'/bin/echo_dummy JOB2 rollback'
            j3.rollback_command = u'/bin/echo_dummy JOB3 rollback'
        elif rollback is None:
            pass

        if mail is True:
            jg1.finish_command = ok_f_cmd % (jg1.name, jg1.name)
        elif mail is False:
            jg1.finish_command = ng_f_cmd % (jg1.name, jg1.name)
        elif mail is None:
            pass

        session.add_all([jg1])
        session.commit()

    def run_job(self, sess):
        _m_jgs = jobgroup_findbystatus(sess)
        for _m_jg in _m_jgs:
            _w = Worker(self._db, _m_jg.id)
            _w.process()
            worker_debug(self._db, _m_jg.id)
        sess.close()
        
    def check_job(self, sess, jg=RES_NORMAL_END, 
                  job=(RES_NORMAL_END, RES_NORMAL_END, RES_NORMAL_END)):
        sess = self._db.get_session()
        _m_jg1 = jobgroup_findbyid(sess, 1)
        self.assertEqual(int(_m_jg1.status), int(jg))

        _m_jobs = job_findbyjobgroup_id(sess, 1, False)
        self.assertEqual(int(_m_jobs[0].status), int(job[0]))
        self.assertEqual(int(_m_jobs[1].status), int(job[1]))
        self.assertEqual(int(_m_jobs[2].status), int(job[2]))

        sess.close()
        

    def test_case1(self):
        """Test Case 1
          - Job Group : Normal end
          - Job : All Normal end
          - Rollback: Normal end
          - Send Mail : Normal end
        """
        sess = self._db.get_session()
        self.set_job(sess, 'Test Case 1', 'b942f21c-4039-e6e9-09dc-9685985a1b84',
                     job=(True, True, True), rollback=True, mail=True)

        self.run_job(sess)

        self.check_job(sess, jg=RES_NORMAL_END, 
              job=(RES_NORMAL_END, RES_NORMAL_END, RES_NORMAL_END))


    def test_case2(self):
        """Test Case 2
          - Job Group : Normal end
          - Job : All Normal end
          - Rollback: Abnormal termination
          - Send Mail : Normal end
        """
        sess = self._db.get_session()
        self.set_job(sess, 'Test Case 2', 'b942f21c-4039-e6e9-09dc-9685985a1b84',
                     job=(True, True, True), rollback=False, mail=True)

        self.run_job(sess)

        self.check_job(sess, jg=RES_NORMAL_END, 
              job=(RES_NORMAL_END, RES_NORMAL_END, RES_NORMAL_END))

        sess.close()


    def test_case3(self):
        """Test Case 3
          - Job Group : Normal end
          - Job : All Normal end
          - Rollback: None
          - Send Mail : Normal end
        """
        sess = self._db.get_session()
        self.set_job(sess, 'Test Case 3', 'b942f21c-4039-e6e9-09dc-9685985a1b84',
                     job=(True, True, True), rollback=None, mail=True)

        self.run_job(sess)

        self.check_job(sess, jg=RES_NORMAL_END, 
              job=(RES_NORMAL_END, RES_NORMAL_END, RES_NORMAL_END))

        sess.close()

    def test_case4(self):
        """Test Case 4
          - Job Group : Normal end
          - Job : All Normal end
          - Rollback: Normal end
          - Send Mail : Abnormal termination
        """
        sess = self._db.get_session()
        self.set_job(sess, 'Test Case 4', 'b942f21c-4039-e6e9-09dc-9685985a1b84',
                     job=(True, True, True), rollback=None, mail=False)

        self.run_job(sess)

        self.check_job(sess, jg=RES_NORMAL_END, 
              job=(RES_NORMAL_END, RES_NORMAL_END, RES_NORMAL_END))

        sess.close()


    def test_case5(self):
        """Test Case 5
          - Job Group : Normal end
          - Job : All Normal end
          - Rollback: None
          - Send Mail : None
        """
        sess = self._db.get_session()
        self.set_job(sess, 'Test Case 5', 'b942f21c-4039-e6e9-09dc-9685985a1b84',
                     job=(True, True, True), rollback=None, mail=None)

        self.run_job(sess)

        self.check_job(sess, jg=RES_NORMAL_END, 
              job=(RES_NORMAL_END, RES_NORMAL_END, RES_NORMAL_END))

        sess.close()

    def test_case6(self):
        """Test Case 6
          - Job Group : Abnormal termination
          - Job : First Job Abnormal termination
          - Rollback: Normal end
          - Send Mail : Normal end
        """
        sess = self._db.get_session()
        self.set_job(sess, 'Test Case 6', 'b942f21c-4039-e6e9-09dc-9685985a1b84',
                     job=(False, True, True), rollback=True, mail=True)

        self.run_job(sess)

        self.check_job(sess, jg=RES_ABNORMAL_TERMINATION,
                       job=(RES_ROLLBACK_SUCCESSFUL_COMPLETION, 
                            RES_PENDING,
                            RES_PENDING))
        sess.close()

    def test_case7(self):
        """Test Case 7
          - Job Group : Abnormal termination
          - Job : First Job Abnormal termination
          - Rollback: Abnormal termination
          - Send Mail : Normal end
        """
        sess = self._db.get_session()
        self.set_job(sess, 'Test Case 7', 'b942f21c-4039-e6e9-09dc-9685985a1b84',
                     job=(False, True, True), rollback=False, mail=True)

        self.run_job(sess)

        self.check_job(sess, jg=RES_ABNORMAL_TERMINATION,
                       job=(RES_ROLLBACK_ABEND, RES_PENDING, RES_PENDING))

        sess.close()


    def test_case8(self):
        """Test Case 8
          - Job Group : Abnormal termination
          - Job : First Job Abnormal termination
          - Rollback: None
          - Send Mail : Normal end
        """
        sess = self._db.get_session()
        self.set_job(sess, 'Test Case 8', 'b942f21c-4039-e6e9-09dc-9685985a1b84',
                     job=(False, True, True), rollback=None, mail=True)

        self.run_job(sess)

        self.check_job(sess, jg=RES_ABNORMAL_TERMINATION, 
              job=(RES_ABNORMAL_TERMINATION, RES_PENDING, RES_PENDING))

        sess.close()

    def test_case9(self):
        """Test Case 9
          - Job Group : Abnormal termination
          - Job : First Job Abnormal termination
          - Rollback: Normal end
          - Send Mail : Abnormal termination
        """
        sess = self._db.get_session()
        self.set_job(sess, 'Test Case 9', 'b942f21c-4039-e6e9-09dc-9685985a1b84',
                     job=(False, True, True), rollback=True, mail=False)

        self.run_job(sess)

        self.check_job(sess, jg=RES_ABNORMAL_TERMINATION, 
                       job=(RES_ROLLBACK_SUCCESSFUL_COMPLETION,
                            RES_PENDING,
                            RES_PENDING))

        sess.close()

    def test_case10(self):
        """Test Case 10
          - Job Group : Abnormal termination
          - Job : First Job Abnormal termination
          - Rollback: Abnormal termination
          - Send Mail : Abnormal termination
        """
        sess = self._db.get_session()
        self.set_job(sess, 'Test Case 10', 'b942f21c-4039-e6e9-09dc-9685985a1b84',
                     job=(False, True, True), rollback=False, mail=False)

        self.run_job(sess)

        self.check_job(sess, jg=RES_ABNORMAL_TERMINATION, 
                       job=(RES_ROLLBACK_ABEND, RES_PENDING, RES_PENDING))

        sess.close()


    def test_case11(self):
        """Test Case 11
          - Job Group : Abnormal termination
          - Job : First Job Abnormal termination
          - Rollback : None
          - Send Mail : Abnormal termination
        """
        sess = self._db.get_session()
        self.set_job(sess, 'Test Case 11', 'b942f21c-4039-e6e9-09dc-9685985a1b84',
                     job=(False, True, True), rollback=None, mail=False)

        self.run_job(sess)

        self.check_job(sess, jg=RES_ABNORMAL_TERMINATION, 
                       job=(RES_ABNORMAL_TERMINATION, RES_PENDING, RES_PENDING))

        sess.close()


    def test_case12(self):
        """Test Case 12
          - Job Group : Abnormal termination
          - Job : First Job Abnormal termination
          - Rollback: Normal end
          - Send Mail : None
        """
        sess = self._db.get_session()
        self.set_job(sess, 'Test Case 12', 'b942f21c-4039-e6e9-09dc-9685985a1b84',
                     job=(False, True, True), rollback=True, mail=None)

        self.run_job(sess)

        self.check_job(sess, jg=RES_ABNORMAL_TERMINATION, 
                       job=(RES_ROLLBACK_SUCCESSFUL_COMPLETION,
                            RES_PENDING,
                            RES_PENDING))

        sess.close()

    def test_case13(self):
        """Test Case 13
          - Job Group : Abnormal termination
          - Job : First Job Abnormal termination
          - Rollback: Abnormal termination
          - Send Mail : None
        """
        sess = self._db.get_session()
        self.set_job(sess, 'Test Case 13', 'b942f21c-4039-e6e9-09dc-9685985a1b84',
                     job=(False, True, True), rollback=False, mail=None)

        self.run_job(sess)

        self.check_job(sess, jg=RES_ABNORMAL_TERMINATION, 
                       job=(RES_ROLLBACK_ABEND, RES_PENDING, RES_PENDING))

        sess.close()

    def test_case14(self):
        """Test Case 14
          - Job Group : Abnormal termination
          - Job : First Job Abnormal termination
          - Rollback: None
          - Send Mail : None
        """
        sess = self._db.get_session()
        self.set_job(sess, 'Test Case 14', 'b942f21c-4039-e6e9-09dc-9685985a1b84',
                     job=(False, True, True), rollback=None, mail=None)

        self.run_job(sess)

        self.check_job(sess, jg=RES_ABNORMAL_TERMINATION, 
                       job=(RES_ABNORMAL_TERMINATION, RES_PENDING, RES_PENDING))

        sess.close()

    def test_case15(self):
        """Test Case 15
          - Job Group : Abnormal termination
          - Job : Second Job Abnormal termination
          - Rollback: Normal end
          - Send Mail : Normal end
        """
        sess = self._db.get_session()
        self.set_job(sess, 'Test Case 15', 'b942f21c-4039-e6e9-09dc-9685985a1b84',
                     job=(True, False, True), rollback=True, mail=True)

        self.run_job(sess)

        self.check_job(sess, jg=RES_ABNORMAL_TERMINATION,
                       job=(RES_ROLLBACK_SUCCESSFUL_COMPLETION, 
                            RES_ROLLBACK_SUCCESSFUL_COMPLETION, 
                            RES_PENDING))
        sess.close()

    def test_case16(self):
        """Test Case 16
          - Job Group : Abnormal termination
          - Job : Second Job Abnormal termination
          - Rollback: Abnormal termination
          - Send Mail : Normal end
        """
        sess = self._db.get_session()
        self.set_job(sess, 'Test Case 16', 'b942f21c-4039-e6e9-09dc-9685985a1b84',
                     job=(True, False, True), rollback=False, mail=True)

        self.run_job(sess)

        self.check_job(sess, jg=RES_ABNORMAL_TERMINATION,
                       job=(RES_ROLLBACK_ABEND, RES_ROLLBACK_ABEND, RES_PENDING))

        sess.close()


    def test_case17(self):
        """Test Case 17
          - Job Group : Abnormal termination
          - Job : Second Job Abnormal termination
          - Rollback: None
          - Send Mail : Normal end
        """
        sess = self._db.get_session()
        self.set_job(sess, 'Test Case 17', 'b942f21c-4039-e6e9-09dc-9685985a1b84',
                     job=(True, False, True), rollback=None, mail=True)

        self.run_job(sess)

        self.check_job(sess, jg=RES_ABNORMAL_TERMINATION, 
              job=(RES_NORMAL_END, RES_ABNORMAL_TERMINATION, RES_PENDING))

        sess.close()

    def test_case18(self):
        """Test Case 9
          - Job Group : Abnormal termination
          - Job : Second Job Abnormal termination
          - Rollback: Normal end
          - Send Mail : Abnormal termination
        """
        sess = self._db.get_session()
        self.set_job(sess, 'Test Case 18', 'b942f21c-4039-e6e9-09dc-9685985a1b84',
                     job=(True, False, True), rollback=True, mail=False)

        self.run_job(sess)

        self.check_job(sess, jg=RES_ABNORMAL_TERMINATION, 
                       job=(RES_ROLLBACK_SUCCESSFUL_COMPLETION,
                            RES_ROLLBACK_SUCCESSFUL_COMPLETION,
                            RES_PENDING))

        sess.close()

    def test_case19(self):
        """Test Case 19
          - Job Group : Abnormal termination
          - Job : Second Job Abnormal termination
          - Rollback: Abnormal termination
          - Send Mail : Abnormal termination
        """
        sess = self._db.get_session()
        self.set_job(sess, 'Test Case 19', 'b942f21c-4039-e6e9-09dc-9685985a1b84',
                     job=(True, False, True), rollback=False, mail=False)

        self.run_job(sess)

        self.check_job(sess, jg=RES_ABNORMAL_TERMINATION, 
                       job=(RES_ROLLBACK_ABEND, RES_ROLLBACK_ABEND, RES_PENDING))

        sess.close()


    def test_case20(self):
        """Test Case 11
          - Job Group : Abnormal termination
          - Job : Second Job Abnormal termination
          - Rollback : None
          - Send Mail : Abnormal termination
        """
        sess = self._db.get_session()
        self.set_job(sess, 'Test Case 20', 'b942f21c-4039-e6e9-09dc-9685985a1b84',
                     job=(True, False, True), rollback=None, mail=False)

        self.run_job(sess)

        self.check_job(sess, jg=RES_ABNORMAL_TERMINATION, 
                       job=(RES_NORMAL_END,
                            RES_ABNORMAL_TERMINATION,
                            RES_PENDING))

        sess.close()


    def test_case21(self):
        """Test Case 21
          - Job Group : Abnormal termination
          - Job : Second Job Abnormal termination
          - Rollback: Normal end
          - Send Mail : None
        """
        sess = self._db.get_session()
        self.set_job(sess, 'Test Case 21', 'b942f21c-4039-e6e9-09dc-9685985a1b84',
                     job=(True, False, True), rollback=True, mail=None)

        self.run_job(sess)

        self.check_job(sess, jg=RES_ABNORMAL_TERMINATION, 
                       job=(RES_ROLLBACK_SUCCESSFUL_COMPLETION,
                            RES_ROLLBACK_SUCCESSFUL_COMPLETION,
                            RES_PENDING))

        sess.close()

    def test_case22(self):
        """Test Case 22
          - Job Group : Abnormal termination
          - Job : Second Job Abnormal termination
          - Rollback: Abnormal termination
          - Send Mail : None
        """
        sess = self._db.get_session()
        self.set_job(sess, 'Test Case ス22', 'b942f21c-4039-e6e9-09dc-9685985a1b84',
                     job=(True, False, True), rollback=False, mail=None)

        self.run_job(sess)

        self.check_job(sess, jg=RES_ABNORMAL_TERMINATION, 
                       job=(RES_ROLLBACK_ABEND, RES_ROLLBACK_ABEND, RES_PENDING))

        sess.close()

    def test_case23(self):
        """Test Case 23
          - Job Group : Abnormal termination
          - Job : Second Job Abnormal termination
          - Rollback: None
          - Send Mail : None
        """
        sess = self._db.get_session()
        self.set_job(sess, 'テストケース23', 'b942f21c-4039-e6e9-09dc-9685985a1b84',
                     job=(True, False, True), rollback=None, mail=None)

        self.run_job(sess)

        self.check_job(sess, jg=RES_ABNORMAL_TERMINATION, 
                       job=(RES_NORMAL_END, 
                            RES_ABNORMAL_TERMINATION,
                            RES_PENDING))

        sess.close()

    def test_case24(self):
        """Test Case 24
          - Job Group : Abnormal termination
          - Job : Third Job Abnormal termination
          - Rollback: Normal end
          - Send Mail : Normal end
        """
        sess = self._db.get_session()
        self.set_job(sess, 'Test Case 24', 'b942f21c-4039-e6e9-09dc-9685985a1b84',
                     job=(True, True, False), rollback=True, mail=True)

        self.run_job(sess)

        self.check_job(sess, jg=RES_ABNORMAL_TERMINATION,
                       job=(RES_ROLLBACK_SUCCESSFUL_COMPLETION, 
                            RES_ROLLBACK_SUCCESSFUL_COMPLETION, 
                            RES_ROLLBACK_SUCCESSFUL_COMPLETION))
        sess.close()

    def test_case25(self):
        """Test Case 25
          - Job Group : Abnormal termination
          - Job : Third Job Abnormal termination
          - Rollback: Abnormal termination
          - Send Mail : Normal end
        """
        sess = self._db.get_session()
        self.set_job(sess, 'Test Case 25', 'b942f21c-4039-e6e9-09dc-9685985a1b84',
                     job=(True, True, False), rollback=False, mail=True)

        self.run_job(sess)

        self.check_job(sess, jg=RES_ABNORMAL_TERMINATION,
                       job=(RES_ROLLBACK_ABEND, 
                            RES_ROLLBACK_ABEND,
                            RES_ROLLBACK_ABEND))

        sess.close()


    def test_case26(self):
        """Test Case 26
          - Job Group : Abnormal termination
          - Job : Second Job Abnormal termination
          - Rollback: None
          - Send Mail : Normal end
        """
        sess = self._db.get_session()
        self.set_job(sess, 'Test Case 26', 'b942f21c-4039-e6e9-09dc-9685985a1b84',
                     job=(True, True, False), rollback=None, mail=True)

        self.run_job(sess)

        self.check_job(sess, jg=RES_ABNORMAL_TERMINATION, 
              job=(RES_NORMAL_END, RES_NORMAL_END, RES_ABNORMAL_TERMINATION))

        sess.close()

    def test_case27(self):
        """Test Case 27
          - Job Group : Abnormal termination
          - Job : Third Job Abnormal termination
          - Rollback: Normal end
          - Send Mail : Abnormal termination
        """
        sess = self._db.get_session()
        self.set_job(sess, 'Test Case 27', 'b942f21c-4039-e6e9-09dc-9685985a1b84',
                     job=(True, True, False), rollback=True, mail=False)

        self.run_job(sess)

        self.check_job(sess, jg=RES_ABNORMAL_TERMINATION, 
                       job=(RES_ROLLBACK_SUCCESSFUL_COMPLETION,
                            RES_ROLLBACK_SUCCESSFUL_COMPLETION,
                            RES_ROLLBACK_SUCCESSFUL_COMPLETION))

        sess.close()

    def test_case28(self):
        """Test Case 28
          - Job Group : Abnormal termination
          - Job : Third Job Abnormal termination
          - Rollback: Abnormal termination
          - Send Mail : Abnormal termination
        """
        sess = self._db.get_session()
        self.set_job(sess, 'Test Case 28', 'b942f21c-4039-e6e9-09dc-9685985a1b84',
                     job=(True, True, False), rollback=False, mail=False)

        self.run_job(sess)

        self.check_job(sess, jg=RES_ABNORMAL_TERMINATION, 
                       job=(RES_ROLLBACK_ABEND, RES_ROLLBACK_ABEND, RES_ROLLBACK_ABEND))

        sess.close()


    def test_case29(self):
        """Test Case 29
          - Job Group : Abnormal termination
          - Job : Second Job Abnormal termination
          - Rollback : None
          - Send Mail : Abnormal termination
        """
        sess = self._db.get_session()
        self.set_job(sess, 'Test Case 29', 'b942f21c-4039-e6e9-09dc-9685985a1b84',
                     job=(True, True, False), rollback=None, mail=False)

        self.run_job(sess)

        self.check_job(sess, jg=RES_ABNORMAL_TERMINATION, 
                       job=(RES_NORMAL_END,
                            RES_NORMAL_END,
                            RES_ABNORMAL_TERMINATION))

        sess.close()


    def test_case30(self):
        """Test Case 30
          - Job Group : Abnormal termination
          - Job : Third Job Abnormal termination
          - Rollback: Normal end
          - Send Mail : None
        """
        sess = self._db.get_session()
        self.set_job(sess, 'Test Case 30', 'b942f21c-4039-e6e9-09dc-9685985a1b84',
                     job=(True, True, False), rollback=True, mail=None)

        self.run_job(sess)

        self.check_job(sess, jg=RES_ABNORMAL_TERMINATION, 
                       job=(RES_ROLLBACK_SUCCESSFUL_COMPLETION,
                            RES_ROLLBACK_SUCCESSFUL_COMPLETION,
                            RES_ROLLBACK_SUCCESSFUL_COMPLETION))

        sess.close()

    def test_case31(self):
        """Test Case 31
          - Job Group : Abnormal termination
          - Job : Third Job Abnormal termination
          - Rollback: Abnormal termination
          - Send Mail : None
        """
        sess = self._db.get_session()
        self.set_job(sess, 'Test Case 31', 'b942f21c-4039-e6e9-09dc-9685985a1b84',
                     job=(True, True, False), rollback=False, mail=None)

        self.run_job(sess)

        self.check_job(sess, jg=RES_ABNORMAL_TERMINATION, 
                       job=(RES_ROLLBACK_ABEND, 
                            RES_ROLLBACK_ABEND, 
                            RES_ROLLBACK_ABEND))

        sess.close()

    def test_case32(self):
        """Test Case 32
          - Job Group : Abnormal termination
          - Job : Third Job Abnormal termination
          - Rollback: None
          - Send Mail : None
        """
        sess = self._db.get_session()
        self.set_job(sess, 'Test Case 32', 'b942f21c-4039-e6e9-09dc-9685985a1b84',
                     job=(True, True, False), rollback=None, mail=None)

        self.run_job(sess)

        self.check_job(sess, jg=RES_ABNORMAL_TERMINATION, 
                       job=(RES_NORMAL_END, 
                            RES_NORMAL_END,
                            RES_ABNORMAL_TERMINATION))

        sess.close()
Exemplo n.º 10
0
class TestWorker(unittest.TestCase):
    """
    """
    _db = None

    def setUp(self):
        # O/R mapping
        self._db = Database(cf['database.url'],
                            encoding="utf-8",
                            convert_unicode=True,
                            echo=True)
        reload_mappers(self._db.get_metadata())

        # database init
        self._db.get_metadata().drop_all()
        self._db.get_metadata().create_all()  # create table
        pass

    def tearDown(self):
        sqlalchemy.orm.clear_mappers()
        pass

    def set_job(self,
                session,
                jg_name,
                uniqkey,
                job=(True, True, True),
                rollback=None,
                mail=None):
        jg1 = JobGroup(jg_name.decode('utf-8'), uniqkey)

        if job[0] is True:
            j1 = Job(u'file create', '0', '/bin/touch /tmp/test_case1.txt')
        else:
            j1 = Job(u'file create', '0',
                     '/bin/touch_dummy /tmp/test_case1.txt')

        if job[1] is True:
            j2 = Job(u'file copy', '1',
                     '/bin/cp /tmp/test_case1.txt /tmp/test_case1_rename.txt')
        else:
            j2 = Job(
                u'file copy', '1',
                '/bin/cp_dummy /tmp/test_case1.txt /tmp/test_case1_rename.txt')

        if job[2] is True:
            j3 = Job(u'file delete', '2', '/bin/rm /tmp/test_case1.txt')
        else:
            j3 = Job(u'file delete', '2', '/bin/rm_dummy /tmp/test_case1.txt')

        jg1.jobs.append(j1)
        jg1.jobs.append(j2)
        jg1.jobs.append(j3)

        if rollback is True:
            j1.rollback_command = u'/bin/echo JOB1 rollback'
            j2.rollback_command = u'/bin/echo JOB2 rollback'
            j3.rollback_command = u'/bin/echo JOB3 rollback'
        elif rollback is False:
            j1.rollback_command = u'/bin/echo_dummy JOB1 rollback'
            j2.rollback_command = u'/bin/echo_dummy JOB2 rollback'
            j3.rollback_command = u'/bin/echo_dummy JOB3 rollback'
        elif rollback is None:
            pass

        if mail is True:
            jg1.finish_command = ok_f_cmd % (jg1.name, jg1.name)
        elif mail is False:
            jg1.finish_command = ng_f_cmd % (jg1.name, jg1.name)
        elif mail is None:
            pass

        session.add_all([jg1])
        session.commit()

    def run_job(self, sess):
        _m_jgs = jobgroup_findbystatus(sess)
        for _m_jg in _m_jgs:
            _w = Worker(self._db, _m_jg.id)
            _w.process()
            worker_debug(self._db, _m_jg.id)
        sess.close()

    def check_job(self,
                  sess,
                  jg=RES_NORMAL_END,
                  job=(RES_NORMAL_END, RES_NORMAL_END, RES_NORMAL_END)):
        sess = self._db.get_session()
        _m_jg1 = jobgroup_findbyid(sess, 1)
        self.assertEqual(int(_m_jg1.status), int(jg))

        _m_jobs = job_findbyjobgroup_id(sess, 1, False)
        self.assertEqual(int(_m_jobs[0].status), int(job[0]))
        self.assertEqual(int(_m_jobs[1].status), int(job[1]))
        self.assertEqual(int(_m_jobs[2].status), int(job[2]))

        sess.close()

    def test_case1(self):
        """Test Case 1
          - Job Group : Normal end
          - Job : All Normal end
          - Rollback: Normal end
          - Send Mail : Normal end
        """
        sess = self._db.get_session()
        self.set_job(sess,
                     'Test Case 1',
                     'b942f21c-4039-e6e9-09dc-9685985a1b84',
                     job=(True, True, True),
                     rollback=True,
                     mail=True)

        self.run_job(sess)

        self.check_job(sess,
                       jg=RES_NORMAL_END,
                       job=(RES_NORMAL_END, RES_NORMAL_END, RES_NORMAL_END))

    def test_case2(self):
        """Test Case 2
          - Job Group : Normal end
          - Job : All Normal end
          - Rollback: Abnormal termination
          - Send Mail : Normal end
        """
        sess = self._db.get_session()
        self.set_job(sess,
                     'Test Case 2',
                     'b942f21c-4039-e6e9-09dc-9685985a1b84',
                     job=(True, True, True),
                     rollback=False,
                     mail=True)

        self.run_job(sess)

        self.check_job(sess,
                       jg=RES_NORMAL_END,
                       job=(RES_NORMAL_END, RES_NORMAL_END, RES_NORMAL_END))

        sess.close()

    def test_case3(self):
        """Test Case 3
          - Job Group : Normal end
          - Job : All Normal end
          - Rollback: None
          - Send Mail : Normal end
        """
        sess = self._db.get_session()
        self.set_job(sess,
                     'Test Case 3',
                     'b942f21c-4039-e6e9-09dc-9685985a1b84',
                     job=(True, True, True),
                     rollback=None,
                     mail=True)

        self.run_job(sess)

        self.check_job(sess,
                       jg=RES_NORMAL_END,
                       job=(RES_NORMAL_END, RES_NORMAL_END, RES_NORMAL_END))

        sess.close()

    def test_case4(self):
        """Test Case 4
          - Job Group : Normal end
          - Job : All Normal end
          - Rollback: Normal end
          - Send Mail : Abnormal termination
        """
        sess = self._db.get_session()
        self.set_job(sess,
                     'Test Case 4',
                     'b942f21c-4039-e6e9-09dc-9685985a1b84',
                     job=(True, True, True),
                     rollback=None,
                     mail=False)

        self.run_job(sess)

        self.check_job(sess,
                       jg=RES_NORMAL_END,
                       job=(RES_NORMAL_END, RES_NORMAL_END, RES_NORMAL_END))

        sess.close()

    def test_case5(self):
        """Test Case 5
          - Job Group : Normal end
          - Job : All Normal end
          - Rollback: None
          - Send Mail : None
        """
        sess = self._db.get_session()
        self.set_job(sess,
                     'Test Case 5',
                     'b942f21c-4039-e6e9-09dc-9685985a1b84',
                     job=(True, True, True),
                     rollback=None,
                     mail=None)

        self.run_job(sess)

        self.check_job(sess,
                       jg=RES_NORMAL_END,
                       job=(RES_NORMAL_END, RES_NORMAL_END, RES_NORMAL_END))

        sess.close()

    def test_case6(self):
        """Test Case 6
          - Job Group : Abnormal termination
          - Job : First Job Abnormal termination
          - Rollback: Normal end
          - Send Mail : Normal end
        """
        sess = self._db.get_session()
        self.set_job(sess,
                     'Test Case 6',
                     'b942f21c-4039-e6e9-09dc-9685985a1b84',
                     job=(False, True, True),
                     rollback=True,
                     mail=True)

        self.run_job(sess)

        self.check_job(sess,
                       jg=RES_ABNORMAL_TERMINATION,
                       job=(RES_ROLLBACK_SUCCESSFUL_COMPLETION, RES_PENDING,
                            RES_PENDING))
        sess.close()

    def test_case7(self):
        """Test Case 7
          - Job Group : Abnormal termination
          - Job : First Job Abnormal termination
          - Rollback: Abnormal termination
          - Send Mail : Normal end
        """
        sess = self._db.get_session()
        self.set_job(sess,
                     'Test Case 7',
                     'b942f21c-4039-e6e9-09dc-9685985a1b84',
                     job=(False, True, True),
                     rollback=False,
                     mail=True)

        self.run_job(sess)

        self.check_job(sess,
                       jg=RES_ABNORMAL_TERMINATION,
                       job=(RES_ROLLBACK_ABEND, RES_PENDING, RES_PENDING))

        sess.close()

    def test_case8(self):
        """Test Case 8
          - Job Group : Abnormal termination
          - Job : First Job Abnormal termination
          - Rollback: None
          - Send Mail : Normal end
        """
        sess = self._db.get_session()
        self.set_job(sess,
                     'Test Case 8',
                     'b942f21c-4039-e6e9-09dc-9685985a1b84',
                     job=(False, True, True),
                     rollback=None,
                     mail=True)

        self.run_job(sess)

        self.check_job(sess,
                       jg=RES_ABNORMAL_TERMINATION,
                       job=(RES_ABNORMAL_TERMINATION, RES_PENDING,
                            RES_PENDING))

        sess.close()

    def test_case9(self):
        """Test Case 9
          - Job Group : Abnormal termination
          - Job : First Job Abnormal termination
          - Rollback: Normal end
          - Send Mail : Abnormal termination
        """
        sess = self._db.get_session()
        self.set_job(sess,
                     'Test Case 9',
                     'b942f21c-4039-e6e9-09dc-9685985a1b84',
                     job=(False, True, True),
                     rollback=True,
                     mail=False)

        self.run_job(sess)

        self.check_job(sess,
                       jg=RES_ABNORMAL_TERMINATION,
                       job=(RES_ROLLBACK_SUCCESSFUL_COMPLETION, RES_PENDING,
                            RES_PENDING))

        sess.close()

    def test_case10(self):
        """Test Case 10
          - Job Group : Abnormal termination
          - Job : First Job Abnormal termination
          - Rollback: Abnormal termination
          - Send Mail : Abnormal termination
        """
        sess = self._db.get_session()
        self.set_job(sess,
                     'Test Case 10',
                     'b942f21c-4039-e6e9-09dc-9685985a1b84',
                     job=(False, True, True),
                     rollback=False,
                     mail=False)

        self.run_job(sess)

        self.check_job(sess,
                       jg=RES_ABNORMAL_TERMINATION,
                       job=(RES_ROLLBACK_ABEND, RES_PENDING, RES_PENDING))

        sess.close()

    def test_case11(self):
        """Test Case 11
          - Job Group : Abnormal termination
          - Job : First Job Abnormal termination
          - Rollback : None
          - Send Mail : Abnormal termination
        """
        sess = self._db.get_session()
        self.set_job(sess,
                     'Test Case 11',
                     'b942f21c-4039-e6e9-09dc-9685985a1b84',
                     job=(False, True, True),
                     rollback=None,
                     mail=False)

        self.run_job(sess)

        self.check_job(sess,
                       jg=RES_ABNORMAL_TERMINATION,
                       job=(RES_ABNORMAL_TERMINATION, RES_PENDING,
                            RES_PENDING))

        sess.close()

    def test_case12(self):
        """Test Case 12
          - Job Group : Abnormal termination
          - Job : First Job Abnormal termination
          - Rollback: Normal end
          - Send Mail : None
        """
        sess = self._db.get_session()
        self.set_job(sess,
                     'Test Case 12',
                     'b942f21c-4039-e6e9-09dc-9685985a1b84',
                     job=(False, True, True),
                     rollback=True,
                     mail=None)

        self.run_job(sess)

        self.check_job(sess,
                       jg=RES_ABNORMAL_TERMINATION,
                       job=(RES_ROLLBACK_SUCCESSFUL_COMPLETION, RES_PENDING,
                            RES_PENDING))

        sess.close()

    def test_case13(self):
        """Test Case 13
          - Job Group : Abnormal termination
          - Job : First Job Abnormal termination
          - Rollback: Abnormal termination
          - Send Mail : None
        """
        sess = self._db.get_session()
        self.set_job(sess,
                     'Test Case 13',
                     'b942f21c-4039-e6e9-09dc-9685985a1b84',
                     job=(False, True, True),
                     rollback=False,
                     mail=None)

        self.run_job(sess)

        self.check_job(sess,
                       jg=RES_ABNORMAL_TERMINATION,
                       job=(RES_ROLLBACK_ABEND, RES_PENDING, RES_PENDING))

        sess.close()

    def test_case14(self):
        """Test Case 14
          - Job Group : Abnormal termination
          - Job : First Job Abnormal termination
          - Rollback: None
          - Send Mail : None
        """
        sess = self._db.get_session()
        self.set_job(sess,
                     'Test Case 14',
                     'b942f21c-4039-e6e9-09dc-9685985a1b84',
                     job=(False, True, True),
                     rollback=None,
                     mail=None)

        self.run_job(sess)

        self.check_job(sess,
                       jg=RES_ABNORMAL_TERMINATION,
                       job=(RES_ABNORMAL_TERMINATION, RES_PENDING,
                            RES_PENDING))

        sess.close()

    def test_case15(self):
        """Test Case 15
          - Job Group : Abnormal termination
          - Job : Second Job Abnormal termination
          - Rollback: Normal end
          - Send Mail : Normal end
        """
        sess = self._db.get_session()
        self.set_job(sess,
                     'Test Case 15',
                     'b942f21c-4039-e6e9-09dc-9685985a1b84',
                     job=(True, False, True),
                     rollback=True,
                     mail=True)

        self.run_job(sess)

        self.check_job(sess,
                       jg=RES_ABNORMAL_TERMINATION,
                       job=(RES_ROLLBACK_SUCCESSFUL_COMPLETION,
                            RES_ROLLBACK_SUCCESSFUL_COMPLETION, RES_PENDING))
        sess.close()

    def test_case16(self):
        """Test Case 16
          - Job Group : Abnormal termination
          - Job : Second Job Abnormal termination
          - Rollback: Abnormal termination
          - Send Mail : Normal end
        """
        sess = self._db.get_session()
        self.set_job(sess,
                     'Test Case 16',
                     'b942f21c-4039-e6e9-09dc-9685985a1b84',
                     job=(True, False, True),
                     rollback=False,
                     mail=True)

        self.run_job(sess)

        self.check_job(sess,
                       jg=RES_ABNORMAL_TERMINATION,
                       job=(RES_ROLLBACK_ABEND, RES_ROLLBACK_ABEND,
                            RES_PENDING))

        sess.close()

    def test_case17(self):
        """Test Case 17
          - Job Group : Abnormal termination
          - Job : Second Job Abnormal termination
          - Rollback: None
          - Send Mail : Normal end
        """
        sess = self._db.get_session()
        self.set_job(sess,
                     'Test Case 17',
                     'b942f21c-4039-e6e9-09dc-9685985a1b84',
                     job=(True, False, True),
                     rollback=None,
                     mail=True)

        self.run_job(sess)

        self.check_job(sess,
                       jg=RES_ABNORMAL_TERMINATION,
                       job=(RES_NORMAL_END, RES_ABNORMAL_TERMINATION,
                            RES_PENDING))

        sess.close()

    def test_case18(self):
        """Test Case 9
          - Job Group : Abnormal termination
          - Job : Second Job Abnormal termination
          - Rollback: Normal end
          - Send Mail : Abnormal termination
        """
        sess = self._db.get_session()
        self.set_job(sess,
                     'Test Case 18',
                     'b942f21c-4039-e6e9-09dc-9685985a1b84',
                     job=(True, False, True),
                     rollback=True,
                     mail=False)

        self.run_job(sess)

        self.check_job(sess,
                       jg=RES_ABNORMAL_TERMINATION,
                       job=(RES_ROLLBACK_SUCCESSFUL_COMPLETION,
                            RES_ROLLBACK_SUCCESSFUL_COMPLETION, RES_PENDING))

        sess.close()

    def test_case19(self):
        """Test Case 19
          - Job Group : Abnormal termination
          - Job : Second Job Abnormal termination
          - Rollback: Abnormal termination
          - Send Mail : Abnormal termination
        """
        sess = self._db.get_session()
        self.set_job(sess,
                     'Test Case 19',
                     'b942f21c-4039-e6e9-09dc-9685985a1b84',
                     job=(True, False, True),
                     rollback=False,
                     mail=False)

        self.run_job(sess)

        self.check_job(sess,
                       jg=RES_ABNORMAL_TERMINATION,
                       job=(RES_ROLLBACK_ABEND, RES_ROLLBACK_ABEND,
                            RES_PENDING))

        sess.close()

    def test_case20(self):
        """Test Case 11
          - Job Group : Abnormal termination
          - Job : Second Job Abnormal termination
          - Rollback : None
          - Send Mail : Abnormal termination
        """
        sess = self._db.get_session()
        self.set_job(sess,
                     'Test Case 20',
                     'b942f21c-4039-e6e9-09dc-9685985a1b84',
                     job=(True, False, True),
                     rollback=None,
                     mail=False)

        self.run_job(sess)

        self.check_job(sess,
                       jg=RES_ABNORMAL_TERMINATION,
                       job=(RES_NORMAL_END, RES_ABNORMAL_TERMINATION,
                            RES_PENDING))

        sess.close()

    def test_case21(self):
        """Test Case 21
          - Job Group : Abnormal termination
          - Job : Second Job Abnormal termination
          - Rollback: Normal end
          - Send Mail : None
        """
        sess = self._db.get_session()
        self.set_job(sess,
                     'Test Case 21',
                     'b942f21c-4039-e6e9-09dc-9685985a1b84',
                     job=(True, False, True),
                     rollback=True,
                     mail=None)

        self.run_job(sess)

        self.check_job(sess,
                       jg=RES_ABNORMAL_TERMINATION,
                       job=(RES_ROLLBACK_SUCCESSFUL_COMPLETION,
                            RES_ROLLBACK_SUCCESSFUL_COMPLETION, RES_PENDING))

        sess.close()

    def test_case22(self):
        """Test Case 22
          - Job Group : Abnormal termination
          - Job : Second Job Abnormal termination
          - Rollback: Abnormal termination
          - Send Mail : None
        """
        sess = self._db.get_session()
        self.set_job(sess,
                     'Test Case ス22',
                     'b942f21c-4039-e6e9-09dc-9685985a1b84',
                     job=(True, False, True),
                     rollback=False,
                     mail=None)

        self.run_job(sess)

        self.check_job(sess,
                       jg=RES_ABNORMAL_TERMINATION,
                       job=(RES_ROLLBACK_ABEND, RES_ROLLBACK_ABEND,
                            RES_PENDING))

        sess.close()

    def test_case23(self):
        """Test Case 23
          - Job Group : Abnormal termination
          - Job : Second Job Abnormal termination
          - Rollback: None
          - Send Mail : None
        """
        sess = self._db.get_session()
        self.set_job(sess,
                     'テストケース23',
                     'b942f21c-4039-e6e9-09dc-9685985a1b84',
                     job=(True, False, True),
                     rollback=None,
                     mail=None)

        self.run_job(sess)

        self.check_job(sess,
                       jg=RES_ABNORMAL_TERMINATION,
                       job=(RES_NORMAL_END, RES_ABNORMAL_TERMINATION,
                            RES_PENDING))

        sess.close()

    def test_case24(self):
        """Test Case 24
          - Job Group : Abnormal termination
          - Job : Third Job Abnormal termination
          - Rollback: Normal end
          - Send Mail : Normal end
        """
        sess = self._db.get_session()
        self.set_job(sess,
                     'Test Case 24',
                     'b942f21c-4039-e6e9-09dc-9685985a1b84',
                     job=(True, True, False),
                     rollback=True,
                     mail=True)

        self.run_job(sess)

        self.check_job(sess,
                       jg=RES_ABNORMAL_TERMINATION,
                       job=(RES_ROLLBACK_SUCCESSFUL_COMPLETION,
                            RES_ROLLBACK_SUCCESSFUL_COMPLETION,
                            RES_ROLLBACK_SUCCESSFUL_COMPLETION))
        sess.close()

    def test_case25(self):
        """Test Case 25
          - Job Group : Abnormal termination
          - Job : Third Job Abnormal termination
          - Rollback: Abnormal termination
          - Send Mail : Normal end
        """
        sess = self._db.get_session()
        self.set_job(sess,
                     'Test Case 25',
                     'b942f21c-4039-e6e9-09dc-9685985a1b84',
                     job=(True, True, False),
                     rollback=False,
                     mail=True)

        self.run_job(sess)

        self.check_job(sess,
                       jg=RES_ABNORMAL_TERMINATION,
                       job=(RES_ROLLBACK_ABEND, RES_ROLLBACK_ABEND,
                            RES_ROLLBACK_ABEND))

        sess.close()

    def test_case26(self):
        """Test Case 26
          - Job Group : Abnormal termination
          - Job : Second Job Abnormal termination
          - Rollback: None
          - Send Mail : Normal end
        """
        sess = self._db.get_session()
        self.set_job(sess,
                     'Test Case 26',
                     'b942f21c-4039-e6e9-09dc-9685985a1b84',
                     job=(True, True, False),
                     rollback=None,
                     mail=True)

        self.run_job(sess)

        self.check_job(sess,
                       jg=RES_ABNORMAL_TERMINATION,
                       job=(RES_NORMAL_END, RES_NORMAL_END,
                            RES_ABNORMAL_TERMINATION))

        sess.close()

    def test_case27(self):
        """Test Case 27
          - Job Group : Abnormal termination
          - Job : Third Job Abnormal termination
          - Rollback: Normal end
          - Send Mail : Abnormal termination
        """
        sess = self._db.get_session()
        self.set_job(sess,
                     'Test Case 27',
                     'b942f21c-4039-e6e9-09dc-9685985a1b84',
                     job=(True, True, False),
                     rollback=True,
                     mail=False)

        self.run_job(sess)

        self.check_job(sess,
                       jg=RES_ABNORMAL_TERMINATION,
                       job=(RES_ROLLBACK_SUCCESSFUL_COMPLETION,
                            RES_ROLLBACK_SUCCESSFUL_COMPLETION,
                            RES_ROLLBACK_SUCCESSFUL_COMPLETION))

        sess.close()

    def test_case28(self):
        """Test Case 28
          - Job Group : Abnormal termination
          - Job : Third Job Abnormal termination
          - Rollback: Abnormal termination
          - Send Mail : Abnormal termination
        """
        sess = self._db.get_session()
        self.set_job(sess,
                     'Test Case 28',
                     'b942f21c-4039-e6e9-09dc-9685985a1b84',
                     job=(True, True, False),
                     rollback=False,
                     mail=False)

        self.run_job(sess)

        self.check_job(sess,
                       jg=RES_ABNORMAL_TERMINATION,
                       job=(RES_ROLLBACK_ABEND, RES_ROLLBACK_ABEND,
                            RES_ROLLBACK_ABEND))

        sess.close()

    def test_case29(self):
        """Test Case 29
          - Job Group : Abnormal termination
          - Job : Second Job Abnormal termination
          - Rollback : None
          - Send Mail : Abnormal termination
        """
        sess = self._db.get_session()
        self.set_job(sess,
                     'Test Case 29',
                     'b942f21c-4039-e6e9-09dc-9685985a1b84',
                     job=(True, True, False),
                     rollback=None,
                     mail=False)

        self.run_job(sess)

        self.check_job(sess,
                       jg=RES_ABNORMAL_TERMINATION,
                       job=(RES_NORMAL_END, RES_NORMAL_END,
                            RES_ABNORMAL_TERMINATION))

        sess.close()

    def test_case30(self):
        """Test Case 30
          - Job Group : Abnormal termination
          - Job : Third Job Abnormal termination
          - Rollback: Normal end
          - Send Mail : None
        """
        sess = self._db.get_session()
        self.set_job(sess,
                     'Test Case 30',
                     'b942f21c-4039-e6e9-09dc-9685985a1b84',
                     job=(True, True, False),
                     rollback=True,
                     mail=None)

        self.run_job(sess)

        self.check_job(sess,
                       jg=RES_ABNORMAL_TERMINATION,
                       job=(RES_ROLLBACK_SUCCESSFUL_COMPLETION,
                            RES_ROLLBACK_SUCCESSFUL_COMPLETION,
                            RES_ROLLBACK_SUCCESSFUL_COMPLETION))

        sess.close()

    def test_case31(self):
        """Test Case 31
          - Job Group : Abnormal termination
          - Job : Third Job Abnormal termination
          - Rollback: Abnormal termination
          - Send Mail : None
        """
        sess = self._db.get_session()
        self.set_job(sess,
                     'Test Case 31',
                     'b942f21c-4039-e6e9-09dc-9685985a1b84',
                     job=(True, True, False),
                     rollback=False,
                     mail=None)

        self.run_job(sess)

        self.check_job(sess,
                       jg=RES_ABNORMAL_TERMINATION,
                       job=(RES_ROLLBACK_ABEND, RES_ROLLBACK_ABEND,
                            RES_ROLLBACK_ABEND))

        sess.close()

    def test_case32(self):
        """Test Case 32
          - Job Group : Abnormal termination
          - Job : Third Job Abnormal termination
          - Rollback: None
          - Send Mail : None
        """
        sess = self._db.get_session()
        self.set_job(sess,
                     'Test Case 32',
                     'b942f21c-4039-e6e9-09dc-9685985a1b84',
                     job=(True, True, False),
                     rollback=None,
                     mail=None)

        self.run_job(sess)

        self.check_job(sess,
                       jg=RES_ABNORMAL_TERMINATION,
                       job=(RES_NORMAL_END, RES_NORMAL_END,
                            RES_ABNORMAL_TERMINATION))

        sess.close()