当前位置: 首页>>代码示例>>Python>>正文


Python Scheduler.get_scheduling_period方法代码示例

本文整理汇总了Python中scheduler.Scheduler.get_scheduling_period方法的典型用法代码示例。如果您正苦于以下问题:Python Scheduler.get_scheduling_period方法的具体用法?Python Scheduler.get_scheduling_period怎么用?Python Scheduler.get_scheduling_period使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在scheduler.Scheduler的用法示例。


在下文中一共展示了Scheduler.get_scheduling_period方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TimingTestCase

# 需要导入模块: from scheduler import Scheduler [as 别名]
# 或者: from scheduler.Scheduler import get_scheduling_period [as 别名]
class TimingTestCase(unittest.TestCase):
    sch = None

    def __init__(self, *args, **kwargs):
        super(TimingTestCase, self).__init__(*args, **kwargs)

        if self.sch is None:
            configuration.select('marvinctld',
                                 preset={'inventory': {'sync': False},
                                         'database': TEMP_DB,
                                         'log': {'level': 50,
                                                 'file': TEMP_LOG}})

            from scheduler import Scheduler
            self.sch = Scheduler(refresh=True)
            self.assertIsNotNone(self.sch.db())

            self.assertTrue(os.path.isfile(TEMP_DB))

            userid, error = self.sch.create_user('admin', 'admin', 'admin')
            self.assertIsNotNone(userid)

            c = self.sch.db().cursor()
            nodes = self.sch.get_nodes()
            if nodes is None or len(nodes) < 25:
                print "creating 25 nodes...",
                for nodeid in xrange(1,25):
                    c.execute("INSERT OR IGNORE INTO nodes VALUES (?, ?, ?, ?)",
                              (nodeid, 'test %i' % nodeid, 'active', 0))
                    self.sch.db().commit()
                    self.sch.set_node_types(nodeid, 'status:test')
                print "done."

    def test_01_lots_of_recurring(self):
        userid = self.sch.get_users()[0]['id']
        now = time.time()
        until = self.sch.get_scheduling_period()[1]
        print
        print "creating 25x2 recurring experiments ..."
        for nodeid in xrange(1,25):
            before = time.time()
            r = self.sch.allocate(userid, 'test', now + 500, 60, 1,
                                  'status:test', '...',
                                  {'recurrence': 'simple',
                                   'period': 3600,
                                   'until': until})
            print r
            self.assertEqual(r[2]['nodecount'], 1)
            self.assertEqual(r[2]['intervals'], 744)
            r = self.sch.allocate(userid, 'test', now + 750, 60, 1, 'status:test', '...',
                                  {'recurrence': 'simple',
                                   'period': 3600,
                                   'until': until})
            self.assertEqual(r[2]['nodecount'], 1)
            self.assertEqual(r[2]['intervals'], 744)
            after = time.time()
            print nodeid * 2, after-before, "seconds."
            self.assertLess(after-before, 10)  # completes in 10 seconds or less
        print "completed in %f seconds." % (after-now)

    def test_02_find_slot(self):
        before = time.time()
        r = self.sch.find_slot(1)
        self.assertEqual(r[0][0]['nodecount'], 1)
        r = self.sch.find_slot(1, nodetypes='status:fail')
        self.assertIsNone(r[0])
        r = self.sch.find_slot(1, duration=500, nodes=['1'],
                               nodetypes='status:test,-status:foo')
        self.assertIsNotNone(r[0])
        self.assertEqual(r[0][0]['nodecount'], 1)
        r = self.sch.find_slot(1, duration=500, nodes=['500', '600'])
        self.assertIsNone(r[0])
        after = time.time()
        print "completed in %f seconds - " % (after-before),
        self.assertLess(after-before, 3)  # completes in 3 seconds or less

    def test_99_cleanup(self):
        os.unlink(TEMP_DB)
开发者ID:MONROE-PROJECT,项目名称:Scheduler,代码行数:80,代码来源:test_timing.py

示例2: SchedulerTestCase

# 需要导入模块: from scheduler import Scheduler [as 别名]
# 或者: from scheduler.Scheduler import get_scheduling_period [as 别名]
class SchedulerTestCase(unittest.TestCase):
    sch = None

    def __init__(self, *args, **kwargs):
        super(SchedulerTestCase, self).__init__(*args, **kwargs)

        if self.sch is None:
            configuration.select('marvinctld',
                                 preset={'inventory': {'sync': False},
                                         'database': TEMP_DB,
                                         'repository': {
                                                 'deployment':'server.xyz'},
                                         'log': {'level': 50,
                                                 'file': TEMP_LOG}})

            from scheduler import Scheduler
            self.sch = Scheduler()

            c = self.sch.db().cursor()
            now = int(time.time())
            c.execute("INSERT OR IGNORE INTO nodes VALUES (?, ?, ?, ?)",
                  ('1', 'test-node', 'active', now))
            c.execute("INSERT OR IGNORE INTO nodes VALUES (?, ?, ?, ?)",
                  ('2', 'test-node 2', 'active', now))
            c.execute("INSERT OR REPLACE INTO node_interface "
                  "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
                  ('1', 'a', 'ab', 'abc', 'abcd', 0, 0, 0, 0, 0, 0))
            c.execute("INSERT OR REPLACE INTO node_interface "
                  "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
                  ('2', 'a', 'ab', 'abc', 'abcd', 0, 0, 0, 0, 0, 0))
            self.sch.db().commit()
            self.sch.set_node_types(1, 'status:test')

    def test_00_db_exists(self):
        self.assertTrue(os.path.isfile(TEMP_DB))
        self.assertIsNotNone(self.sch.db())

    def test_01_create_user(self):
        userid, error = self.sch.create_user('admin', 'admin', 'admin')
        self.assertIsNotNone(userid)
        user = self.sch.get_users(ssl='admin')
        self.assertIsNotNone(user)
        self.assertEqual(user[0].get('id', None), 1)
        self.assertGreater(user[0].get('quota_time', 0), 0)
        self.assertGreater(user[0].get('quota_data', 0), 0)
        self.assertGreater(user[0].get('quota_storage', 0), 0)
        role = self.sch.get_role(ssl='admin')
        self.assertEqual(role, 'admin')
        # not an user
        user = self.sch.get_users(userid=5)
        self.assertIsNone(user)

    def test_02_created_node(self):
        result = self.sch.get_nodes(nodetype='status:test')
        self.assertEqual(result[0].get('id', None), 1)

    def test_03_delete_user(self):
        userid, error = self.sch.create_user('foo', 'foo', 'foo')
        self.assertIsNotNone(userid)
        ok = self.sch.delete_user(userid)
        self.assertTrue(ok)

    def test_04_get_empty_schedule(self):
        self.assertEqual(self.sch.get_schedule(), [])

    def test_05_get_empty_experiments(self):
        self.assertIsNone(self.sch.get_experiments())

    def test_06_get_scheduling_period(self):
        p = self.sch.get_scheduling_period()
        self.assertGreater(p[1]-p[0], 0)

    def test_10_allocate(self):
        now = int(time.time())
        # basic a few minutes into the future
        r = self.sch.allocate(1,'test', now + 500, 500, 1, 'status:test,-status:foo,-status:bar', '...', {})
        self.assertEqual(r[2]['nodecount'], 1)
        # not available
        r = self.sch.allocate(1,'test', now + 500, 500, 1, 'status:test', '...', {})
        self.assertEqual(r[2]['available'], 0)
        # too soon
        r = self.sch.allocate(1,'test', now, 500, 1, 'status:test', '...', {})
        self.assertIsNone(r[0])
        # too soon after the previous experiment
        r = self.sch.allocate(1,'test', now + 1000, 500, 1, 'status:test', '...', {})
        self.assertIsNone(r[0])
        # too short
        r = self.sch.allocate(1,'test', now + 1500, 1, 1, 'status:test', '...', {})
        self.assertIsNone(r[0])
        # zero node count
        r = self.sch.allocate(1,'test', now + 1500, 500, 0, 'status:test', '...', {})
        self.assertIsNone(r[0])
        # too many nodes
        r = self.sch.allocate(1,'test', now + 1500, 500, 2, 'status:test', '...', {})
        self.assertEqual(r[2]['available'], 1)
        # too much storage requested
        r = self.sch.allocate(1,'test', now + 1500, 500, 1, 'status:test', '...',
                              {'storage': 501 * 1000000000})
        self.assertEqual(r[2]['requested'], 501 * 1000000000)

#.........这里部分代码省略.........
开发者ID:MONROE-PROJECT,项目名称:Scheduler,代码行数:103,代码来源:test_scheduler.py


注:本文中的scheduler.Scheduler.get_scheduling_period方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。