コード例 #1
0
  def test_start_worker(self):
    flexmock(file_io).should_receive("mkdir").and_return(None)
    flexmock(file_io) \
       .should_receive("read").and_return("192.168.0.1\n129.168.0.2\n184.48.65.89")
    flexmock(monit_app_configuration).should_receive('create_config_file').and_return('')
    flexmock(monit_interface).should_receive('start') \
       .and_return(False)
    flexmock(TaskQueueConfig)\
       .should_receive("load_queues_from_file").and_return()
    flexmock(TaskQueueConfig)\
       .should_receive("create_celery_worker_scripts").and_return()
    flexmock(TaskQueueConfig)\
       .should_receive("create_celery_file").and_return()
   
    dtq = DistributedTaskQueue() 
    json_request = {}
    json_request = json.dumps(json_request)
    self.assertEquals(dtq.start_worker(json_request), 
                 json.dumps({'error': True, 'reason': 'Missing app_id tag'}))

    json_request = "fefwoinfwef=fwf23onr2or3"
    json_response = dtq.start_worker(json_request)
    self.assertEquals(json_response, json.dumps({'error': True, 'reason': 'Badly formed JSON'}))

    json_request = {'app_id':'my-app'}
    json_request = json.dumps(json_request)
    assert 'true' in dtq.start_worker(json_request)

    flexmock(monit_interface).should_receive('start') \
       .and_return(True)
  
    json_request = {'app_id':'my-app'}
    json_request = json.dumps(json_request)
    assert 'false' in dtq.start_worker(json_request)
コード例 #2
0
 def test_stop_worker(self):
   flexmock(os).should_receive("system").and_return(None)
   flexmock(monit_interface).should_receive('stop') \
      .and_return(False)
   flexmock(file_io).should_receive("delete").and_return(None)
   flexmock(file_io).should_receive("mkdir").and_return(None)
   flexmock(file_io) \
      .should_receive("read").and_return("192.168.0.1\n129.168.0.2\n184.48.65.89")
   dtq = DistributedTaskQueue() 
   json_request = {'app_id':'test_app'}
   self.assertEquals(json.loads(dtq.stop_worker(json.dumps(json_request)))['error'],
                     True)
   flexmock(monit_interface).should_receive('stop') \
      .and_return(True)
   self.assertEquals(json.loads(dtq.stop_worker(json.dumps(json_request)))['error'],
                     False)
コード例 #3
0
    def test_fetch_queue_stats(self):
        flexmock(file_io).should_receive("mkdir").and_return(None)
        flexmock(file_io) \
           .should_receive("read").and_return("192.168.0.1")
        flexmock(file_io) \
           .should_receive("write").and_return(None)

        dtq = DistributedTaskQueue()
コード例 #4
0
    def test_modify_task_lease(self):
        flexmock(file_io).should_receive("mkdir").and_return(None)
        flexmock(file_io) \
           .should_receive("read").and_return("192.168.0.1")
        flexmock(file_io) \
           .should_receive("write").and_return(None)

        dtq = DistributedTaskQueue()
コード例 #5
0
    def test_update_storage_limit(self):
        flexmock(file_io).should_receive("mkdir").and_return(None)
        flexmock(file_io) \
           .should_receive("read").and_return("192.168.0.1")
        flexmock(file_io) \
           .should_receive("write").and_return(None)

        dtq = DistributedTaskQueue()
コード例 #6
0
 def test_stop_worker(self):
     flexmock(os).should_receive("system").and_return(None)
     flexmock(god_interface).should_receive('stop') \
        .and_return(False)
     flexmock(file_io).should_receive("delete").and_return(None)
     flexmock(file_io).should_receive("mkdir").and_return(None)
     flexmock(file_io) \
        .should_receive("read").and_return("192.168.0.1\n129.168.0.2\n184.48.65.89")
     dtq = DistributedTaskQueue()
     json_request = {'app_id': 'test_app'}
     self.assertEquals(
         json.loads(dtq.stop_worker(json.dumps(json_request)))['error'],
         True)
     flexmock(god_interface).should_receive('stop') \
        .and_return(True)
     self.assertEquals(
         json.loads(dtq.stop_worker(json.dumps(json_request)))['error'],
         False)
コード例 #7
0
    def test_start_worker(self):
        flexmock(file_io).should_receive("mkdir").and_return(None)
        flexmock(file_io) \
           .should_receive("read").and_return("192.168.0.1\n129.168.0.2\n184.48.65.89")
        flexmock(file_io) \
           .should_receive("write").and_return(None)
        flexmock(TaskQueueConfig)\
           .should_receive("create_celery_file").and_return("/some/file")
        flexmock(TaskQueueConfig)\
           .should_receive("create_celery_worker_scripts").and_return("/some/file")
        flexmock(TaskQueueConfig)\
           .should_receive("load_queues_from_file").and_return()

        dtq = DistributedTaskQueue()
        dtq.start_worker("hi")
        flexmock(urllib2)\
           .should_receive("Request").and_return(FakeConnection('/some/url'))

        results = {'192.168.0.1': {}, '129.168.0.2': {}, '184.46.65.89': {}}
        self.assertEqual(dtq.start_worker("hi"), results)
コード例 #8
0
  def test_start_worker(self):
    flexmock(file_io).should_receive("mkdir").and_return(None)
    flexmock(file_io) \
       .should_receive("read").and_return("192.168.0.1\n129.168.0.2\n184.48.65.89")
    flexmock(file_io) \
       .should_receive("write").and_return(None)
    flexmock(TaskQueueConfig)\
       .should_receive("create_celery_file").and_return("/some/file")
    flexmock(TaskQueueConfig)\
       .should_receive("create_celery_worker_scripts").and_return("/some/file")
    flexmock(TaskQueueConfig)\
       .should_receive("load_queues_from_file").and_return()
 
    dtq = DistributedTaskQueue()
    dtq.start_worker("hi")
    flexmock(urllib2)\
       .should_receive("Request").and_return(FakeConnection('/some/url'))
    
    results =  {'192.168.0.1':{}, '129.168.0.2':{}, '184.46.65.89':{}}
    self.assertEqual(dtq.start_worker("hi"), results)
コード例 #9
0
    def test_start_worker(self):
        flexmock(file_io).should_receive("mkdir").and_return(None)
        flexmock(file_io) \
           .should_receive("read").and_return("192.168.0.1\n129.168.0.2\n184.48.65.89")
        flexmock(god_app_configuration).should_receive(
            'create_config_file').and_return('')
        flexmock(god_interface).should_receive('start') \
           .and_return(False)
        flexmock(TaskQueueConfig)\
           .should_receive("load_queues_from_file").and_return()
        flexmock(TaskQueueConfig)\
           .should_receive("create_celery_worker_scripts").and_return()
        flexmock(TaskQueueConfig)\
           .should_receive("create_celery_file").and_return()

        dtq = DistributedTaskQueue()
        json_request = {}
        json_request = json.dumps(json_request)
        self.assertEquals(
            dtq.start_worker(json_request),
            json.dumps({
                'error': True,
                'reason': 'Missing app_id tag'
            }))

        json_request = "fefwoinfwef=fwf23onr2or3"
        json_response = dtq.start_worker(json_request)
        self.assertEquals(
            json_response,
            json.dumps({
                'error': True,
                'reason': 'Badly formed JSON'
            }))

        json_request = {'app_id': 'my-app'}
        json_request = json.dumps(json_request)
        assert 'true' in dtq.start_worker(json_request)

        flexmock(god_interface).should_receive('start') \
           .and_return(True)

        json_request = {'app_id': 'my-app'}
        json_request = json.dumps(json_request)
        assert 'false' in dtq.start_worker(json_request)
コード例 #10
0
 def test_pause_queue(self):
     mock_file_io()
     dtq = DistributedTaskQueue()
コード例 #11
0
 def test_update_storage_limit(self):
     mock_file_io()
     dtq = DistributedTaskQueue()
コード例 #12
0
 def test_delete_group(self):
     mock_file_io()
     dtq = DistributedTaskQueue()
コード例 #13
0
 def test_force_run(self):
     mock_file_io()
     dtq = DistributedTaskQueue()
コード例 #14
0
 def test_fetch_task(self):
     mock_file_io()
     dtq = DistributedTaskQueue()
コード例 #15
0
 def test_query_tasks(self):
     mock_file_io()
     dtq = DistributedTaskQueue()
コード例 #16
0
 def test_modify_task_lease(self):
     mock_file_io()
     dtq = DistributedTaskQueue()
コード例 #17
0
 def test_bulk_add(self):
     mock_file_io()
     dtq = DistributedTaskQueue()
コード例 #18
0
 def test_fetch_queue_stats(self):
     mock_file_io()
     dtq = DistributedTaskQueue()