コード例 #1
0
def test_update_maintenance_schedule(mocker):
    operator = mocker.Mock()
    master = mocker.Mock()
    driver = MesosOperatorMasterDriver(master, operator)
    driver._send = mocker.Mock()
    windows = [{
        'machine_ids': [{
            'hostname': 'myhost'
        }, {
            'ip': '0.0.0.2'
        }],
        'unavailability': {
            'start': {
                'nanoseconds': 1470820233192017920
            }
        }
    }]
    driver.updateMaintenanceSchedule(windows)
    driver._send.assert_called_once_with({
        'type': 'UPDATE_MAINTENANCE_SCHEDULE',
        'update_maintenance_schedule': {
            'schedule': {
                'windows': windows
            }
        }
    })
コード例 #2
0
ファイル: test_operator.py プロジェクト: douban/pymesos
def test_on_task_updated(mocker):
    operator = mocker.Mock()
    master = mocker.Mock()
    driver = MesosOperatorMasterDriver(master, operator)
    driver._started = True
    task_info = {
        'task_id': {
            'value': str(uuid.uuid4())
        },
        'framework_id': {
            'value': str(uuid.uuid4())
        },
        'agent_id': {
            'value': str(uuid.uuid4())
        },
        'executor_id': {
            'value': str(uuid.uuid4())
        },
        'state': 'TASK_RUNNING'
    }
    event = {
        'type': 'TASK_UPDATED',
        'task_updated': task_info
    }
    driver.on_event(event)
    operator.taskUpdated.assert_called_once_with(task_info)
    operator.taskAdded.assert_not_called()
コード例 #3
0
def test_gen_request(mocker):
    mock_addr = 'mock_addr:1234'
    operator = mocker.Mock()
    master = mocker.Mock()
    driver = MesosOperatorMasterDriver(master, operator)
    driver._master = mock_addr
    req = driver.gen_request()
    parser = HttpParser(0)
    assert len(req) == parser.execute(req, len(req))
    assert parser.is_headers_complete()
    assert parser.get_method() == 'POST'
    assert parser.get_url() == '/api/v1/operator'

    assert parser.is_partial_body()
    body = parser.recv_body()
    result = json.loads(body.decode('utf-8'))
    assert result['type'] == 'SUBSCRIBE'

    headers = {k.upper(): v for k, v in parser.get_headers().items()}
    assert headers == {
        'HOST': mock_addr,
        'CONTENT-TYPE': 'application/json',
        'ACCEPT': 'application/json',
        'CONNECTION': 'close',
        'CONTENT-LENGTH': str(len(body))
    }

    assert parser.is_message_complete()
コード例 #4
0
ファイル: test_operator.py プロジェクト: douban/pymesos
def test_gen_request(mocker):
    mock_addr = 'mock_addr:1234'
    operator = mocker.Mock()
    master = mocker.Mock()
    driver = MesosOperatorMasterDriver(master, operator)
    driver._master = mock_addr
    req = driver.gen_request()
    parser = HttpParser(0)
    assert len(req) == parser.execute(req, len(req))
    assert parser.is_headers_complete()
    assert parser.get_method() == 'POST'
    assert parser.get_url() == '/api/v1/operator'

    assert parser.is_partial_body()
    body = parser.recv_body()
    result = json.loads(body.decode('utf-8'))
    assert result['type'] == 'SUBSCRIBE'

    headers = {k.upper(): v for k, v in parser.get_headers().items()}
    assert headers == {
        'HOST': mock_addr,
        'CONTENT-TYPE': 'application/json',
        'ACCEPT': 'application/json',
        'CONNECTION': 'close',
        'CONTENT-LENGTH': str(len(body))
    }

    assert parser.is_message_complete()
コード例 #5
0
ファイル: test_operator.py プロジェクト: douban/pymesos
def test_set_quota(mocker):
    operator = mocker.Mock()
    master = mocker.Mock()
    driver = MesosOperatorMasterDriver(master, operator)
    driver._send = mocker.Mock()
    quota_request = {
        'force': 'true',
        'guarantee': [
            {
                'name': 'cpus',
                'role': '*',
                'scalar': {
                    'value': random.uniform(0, 1024.0)
                },
                'type': 'SCALAR'
            },
            {
                'name': 'mem',
                'role': '*',
                'scalar': {
                    'value': random.uniform(0, 1024.0)
                },
                'type': 'SCALAR'
            }
        ],
        'role': 'role1'
    }
    driver.setQuota(quota_request)
    driver._send.assert_called_once_with({
        'type': 'SET_QUOTA',
        'set_quota': {
            'quota_request': quota_request
        }
    })
コード例 #6
0
def test_on_framework_removed(mocker):
    operator = mocker.Mock()
    master = mocker.Mock()
    driver = MesosOperatorMasterDriver(master, operator)
    driver._started = True
    framework_info = {
        'capabilities': [{
            'type': 'RESERVATION_REFINEMENT'
        }],
        'checkpoint': 'true',
        'failover_timeout': 0,
        'id': {
            'value': str(uuid.uuid4())
        },
        'name': 'inverse-offer-example-framework',
        'role': '*',
        'user': '******'
    }
    event = {
        'type': 'FRAMEWORK_REMOVED',
        'framework_removed': {
            'framework_info': framework_info
        }
    }
    driver.on_event(event)
    operator.frameworkRemoved.assert_called_once_with(framework_info)
コード例 #7
0
def test_set_quota(mocker):
    operator = mocker.Mock()
    master = mocker.Mock()
    driver = MesosOperatorMasterDriver(master, operator)
    driver._send = mocker.Mock()
    quota_request = {
        'force':
        'true',
        'guarantee': [{
            'name': 'cpus',
            'role': '*',
            'scalar': {
                'value': random.uniform(0, 1024.0)
            },
            'type': 'SCALAR'
        }, {
            'name': 'mem',
            'role': '*',
            'scalar': {
                'value': random.uniform(0, 1024.0)
            },
            'type': 'SCALAR'
        }],
        'role':
        'role1'
    }
    driver.setQuota(quota_request)
    driver._send.assert_called_once_with({
        'type': 'SET_QUOTA',
        'set_quota': {
            'quota_request': quota_request
        }
    })
コード例 #8
0
def test_on_task_updated(mocker):
    operator = mocker.Mock()
    master = mocker.Mock()
    driver = MesosOperatorMasterDriver(master, operator)
    driver._started = True
    task_info = {
        'task_id': {
            'value': str(uuid.uuid4())
        },
        'framework_id': {
            'value': str(uuid.uuid4())
        },
        'agent_id': {
            'value': str(uuid.uuid4())
        },
        'executor_id': {
            'value': str(uuid.uuid4())
        },
        'state': 'TASK_RUNNING'
    }
    event = {
        'type': 'TASK_UPDATED',
        'task_updated': task_info
    }
    driver.on_event(event)
    operator.taskUpdated.assert_called_once_with(task_info)
    operator.taskAdded.assert_not_called()
コード例 #9
0
ファイル: test_operator.py プロジェクト: douban/pymesos
def test_on_framework_removed(mocker):
    operator = mocker.Mock()
    master = mocker.Mock()
    driver = MesosOperatorMasterDriver(master, operator)
    driver._started = True
    framework_info = {
        'capabilities': [
            {
                'type': 'RESERVATION_REFINEMENT'
            }
        ],
        'checkpoint': 'true',
        'failover_timeout': 0,
        'id': {
            'value': str(uuid.uuid4())
        },
        'name': 'inverse-offer-example-framework',
        'role': '*',
        'user': '******'
    }
    event = {
        'type': 'FRAMEWORK_REMOVED',
        'framework_removed': {
            'framework_info': framework_info
        }
    }
    driver.on_event(event)
    operator.frameworkRemoved.assert_called_once_with(framework_info)
コード例 #10
0
ファイル: test_operator.py プロジェクト: douban/pymesos
def test_update_maintenance_schedule(mocker):
    operator = mocker.Mock()
    master = mocker.Mock()
    driver = MesosOperatorMasterDriver(master, operator)
    driver._send = mocker.Mock()
    windows = [
        {
            'machine_ids': [
                {
                    'hostname': 'myhost'
                },
                {
                    'ip': '0.0.0.2'
                }
            ],
            'unavailability': {
                'start': {
                    'nanoseconds': 1470820233192017920
                }
            }
        }
    ]
    driver.updateMaintenanceSchedule(windows)
    driver._send.assert_called_once_with({
        'type': 'UPDATE_MAINTENANCE_SCHEDULE',
        'update_maintenance_schedule': {
            'schedule': {
                'windows': windows
            }
        }
    })
コード例 #11
0
def test_destroy_volumes(mocker):
    operator = mocker.Mock()
    master = mocker.Mock()
    driver = MesosOperatorMasterDriver(master, operator)
    driver._send = mocker.Mock()
    agent_id = str(uuid.uuid4())
    volumes = [{
        'disk': {
            'persistence': {
                'id': 'id1',
                'principal': 'my-principal'
            },
            'volume': {
                'container_path': 'path1',
                'mode': 'RW'
            }
        },
        'name': 'disk',
        'role': 'role1',
        'scalar': {
            'value': random.uniform(0, 1024.0)
        },
        'type': 'SCALAR'
    }]
    driver.destroyVolumes(agent_id, volumes)
    driver._send.assert_called_once_with({
        'type': 'DESTROY_VOLUMES',
        'destroy_volumes': {
            'agent_id': {
                'value': agent_id
            },
            'volumes': volumes
        }
    })
コード例 #12
0
def test_get_state(mocker):
    operator = mocker.Mock()
    master = mocker.Mock()
    driver = MesosOperatorMasterDriver(master, operator)
    driver._send = mocker.Mock()
    driver.getState()
    driver._send.assert_called_once_with({
        'type': 'GET_STATE',
    })
コード例 #13
0
ファイル: test_operator.py プロジェクト: douban/pymesos
def test_get_master(mocker):
    operator = mocker.Mock()
    master = mocker.Mock()
    driver = MesosOperatorMasterDriver(master, operator)
    driver._send = mocker.Mock()
    driver.getMaster()
    driver._send.assert_called_once_with({
        'type': 'GET_MASTER',
    })
コード例 #14
0
ファイル: test_operator.py プロジェクト: douban/pymesos
def test_get_health(mocker):
    operator = mocker.Mock()
    master = mocker.Mock()
    driver = MesosOperatorMasterDriver(master, operator)
    driver._send = mocker.Mock()
    driver.getHealth()
    driver._send.assert_called_once_with({
        'type': 'GET_HEALTH',
    })
コード例 #15
0
def test_get_maintenance_status(mocker):
    operator = mocker.Mock()
    master = mocker.Mock()
    driver = MesosOperatorMasterDriver(master, operator)
    driver._send = mocker.Mock()
    driver.getMaintenanceStatus()
    driver._send.assert_called_once_with({
        'type': 'GET_MAINTENANCE_STATUS',
    })
コード例 #16
0
ファイル: test_operator.py プロジェクト: douban/pymesos
def test_get_frameworks(mocker):
    operator = mocker.Mock()
    master = mocker.Mock()
    driver = MesosOperatorMasterDriver(master, operator)
    driver._send = mocker.Mock()
    driver.getFrameworks()
    driver._send.assert_called_once_with({
        'type': 'GET_FRAMEWORKS',
    })
コード例 #17
0
ファイル: test_operator.py プロジェクト: douban/pymesos
def test_get_state(mocker):
    operator = mocker.Mock()
    master = mocker.Mock()
    driver = MesosOperatorMasterDriver(master, operator)
    driver._send = mocker.Mock()
    driver.getState()
    driver._send.assert_called_once_with({
        'type': 'GET_STATE',
    })
コード例 #18
0
def test_get_master(mocker):
    operator = mocker.Mock()
    master = mocker.Mock()
    driver = MesosOperatorMasterDriver(master, operator)
    driver._send = mocker.Mock()
    driver.getMaster()
    driver._send.assert_called_once_with({
        'type': 'GET_MASTER',
    })
コード例 #19
0
ファイル: test_operator.py プロジェクト: douban/pymesos
def test_get_logging_level(mocker):
    operator = mocker.Mock()
    master = mocker.Mock()
    driver = MesosOperatorMasterDriver(master, operator)
    driver._send = mocker.Mock()
    driver.getLoggingLevel()
    driver._send.assert_called_once_with({
        'type': 'GET_LOGGING_LEVEL',
    })
コード例 #20
0
ファイル: test_operator.py プロジェクト: douban/pymesos
def test_get_maintenance_schedule(mocker):
    operator = mocker.Mock()
    master = mocker.Mock()
    driver = MesosOperatorMasterDriver(master, operator)
    driver._send = mocker.Mock()
    driver.getMaintenanceSchedule()
    driver._send.assert_called_once_with({
        'type': 'GET_MAINTENANCE_SCHEDULE',
    })
コード例 #21
0
ファイル: test_operator.py プロジェクト: douban/pymesos
def test_get_quota(mocker):
    operator = mocker.Mock()
    master = mocker.Mock()
    driver = MesosOperatorMasterDriver(master, operator)
    driver._send = mocker.Mock()
    driver.getQuota()
    driver._send.assert_called_once_with({
        'type': 'GET_QUOTA',
    })
コード例 #22
0
ファイル: test_operator.py プロジェクト: douban/pymesos
def test_get_executors(mocker):
    operator = mocker.Mock()
    master = mocker.Mock()
    driver = MesosOperatorMasterDriver(master, operator)
    driver._send = mocker.Mock()
    driver.getExecutors()
    driver._send.assert_called_once_with({
        'type': 'GET_EXECUTORS',
    })
コード例 #23
0
ファイル: test_operator.py プロジェクト: douban/pymesos
def test_get_version(mocker):
    operator = mocker.Mock()
    master = mocker.Mock()
    driver = MesosOperatorMasterDriver(master, operator)
    driver._send = mocker.Mock()
    driver.getVersion()
    driver._send.assert_called_once_with({
        'type': 'GET_VERSION',
    })
コード例 #24
0
def test_get_quota(mocker):
    operator = mocker.Mock()
    master = mocker.Mock()
    driver = MesosOperatorMasterDriver(master, operator)
    driver._send = mocker.Mock()
    driver.getQuota()
    driver._send.assert_called_once_with({
        'type': 'GET_QUOTA',
    })
コード例 #25
0
def test_get_weights(mocker):
    operator = mocker.Mock()
    master = mocker.Mock()
    driver = MesosOperatorMasterDriver(master, operator)
    driver._send = mocker.Mock()
    driver.getWeights()
    driver._send.assert_called_once_with({
        'type': 'GET_WEIGHTS',
    })
コード例 #26
0
ファイル: test_operator.py プロジェクト: douban/pymesos
def test_get_roles(mocker):
    operator = mocker.Mock()
    master = mocker.Mock()
    driver = MesosOperatorMasterDriver(master, operator)
    driver._send = mocker.Mock()
    driver.getRoles()
    driver._send.assert_called_once_with({
        'type': 'GET_ROLES',
    })
コード例 #27
0
ファイル: test_operator.py プロジェクト: douban/pymesos
def test_get_weights(mocker):
    operator = mocker.Mock()
    master = mocker.Mock()
    driver = MesosOperatorMasterDriver(master, operator)
    driver._send = mocker.Mock()
    driver.getWeights()
    driver._send.assert_called_once_with({
        'type': 'GET_WEIGHTS',
    })
コード例 #28
0
ファイル: test_operator.py プロジェクト: douban/pymesos
def test_get_agents(mocker):
    operator = mocker.Mock()
    master = mocker.Mock()
    driver = MesosOperatorMasterDriver(master, operator)
    driver._send = mocker.Mock()
    driver.getAgents()
    driver._send.assert_called_once_with({
        'type': 'GET_AGENTS',
    })
コード例 #29
0
def test_get_maintenance_schedule(mocker):
    operator = mocker.Mock()
    master = mocker.Mock()
    driver = MesosOperatorMasterDriver(master, operator)
    driver._send = mocker.Mock()
    driver.getMaintenanceSchedule()
    driver._send.assert_called_once_with({
        'type': 'GET_MAINTENANCE_SCHEDULE',
    })
コード例 #30
0
def test_get_frameworks(mocker):
    operator = mocker.Mock()
    master = mocker.Mock()
    driver = MesosOperatorMasterDriver(master, operator)
    driver._send = mocker.Mock()
    driver.getFrameworks()
    driver._send.assert_called_once_with({
        'type': 'GET_FRAMEWORKS',
    })
コード例 #31
0
def test_get_logging_level(mocker):
    operator = mocker.Mock()
    master = mocker.Mock()
    driver = MesosOperatorMasterDriver(master, operator)
    driver._send = mocker.Mock()
    driver.getLoggingLevel()
    driver._send.assert_called_once_with({
        'type': 'GET_LOGGING_LEVEL',
    })
コード例 #32
0
ファイル: test_operator.py プロジェクト: douban/pymesos
def test_get_maintenance_status(mocker):
    operator = mocker.Mock()
    master = mocker.Mock()
    driver = MesosOperatorMasterDriver(master, operator)
    driver._send = mocker.Mock()
    driver.getMaintenanceStatus()
    driver._send.assert_called_once_with({
        'type': 'GET_MAINTENANCE_STATUS',
    })
コード例 #33
0
def test_get_executors(mocker):
    operator = mocker.Mock()
    master = mocker.Mock()
    driver = MesosOperatorMasterDriver(master, operator)
    driver._send = mocker.Mock()
    driver.getExecutors()
    driver._send.assert_called_once_with({
        'type': 'GET_EXECUTORS',
    })
コード例 #34
0
def test_get_version(mocker):
    operator = mocker.Mock()
    master = mocker.Mock()
    driver = MesosOperatorMasterDriver(master, operator)
    driver._send = mocker.Mock()
    driver.getVersion()
    driver._send.assert_called_once_with({
        'type': 'GET_VERSION',
    })
コード例 #35
0
def test_get_agents(mocker):
    operator = mocker.Mock()
    master = mocker.Mock()
    driver = MesosOperatorMasterDriver(master, operator)
    driver._send = mocker.Mock()
    driver.getAgents()
    driver._send.assert_called_once_with({
        'type': 'GET_AGENTS',
    })
コード例 #36
0
def test_get_health(mocker):
    operator = mocker.Mock()
    master = mocker.Mock()
    driver = MesosOperatorMasterDriver(master, operator)
    driver._send = mocker.Mock()
    driver.getHealth()
    driver._send.assert_called_once_with({
        'type': 'GET_HEALTH',
    })
コード例 #37
0
def test_get_roles(mocker):
    operator = mocker.Mock()
    master = mocker.Mock()
    driver = MesosOperatorMasterDriver(master, operator)
    driver._send = mocker.Mock()
    driver.getRoles()
    driver._send.assert_called_once_with({
        'type': 'GET_ROLES',
    })
コード例 #38
0
def test_list_files(mocker):
    operator = mocker.Mock()
    master = mocker.Mock()
    driver = MesosOperatorMasterDriver(master, operator)
    driver._send = mocker.Mock()
    path = 'one/'
    driver.listFiles(path)
    driver._send.assert_called_once_with({
        'type': 'LIST_FILES',
        'list_files': {
            'path': path
        }
    })
コード例 #39
0
ファイル: test_operator.py プロジェクト: douban/pymesos
def test_list_files(mocker):
    operator = mocker.Mock()
    master = mocker.Mock()
    driver = MesosOperatorMasterDriver(master, operator)
    driver._send = mocker.Mock()
    path = 'one/'
    driver.listFiles(path)
    driver._send.assert_called_once_with({
        'type': 'LIST_FILES',
        'list_files': {
            'path': path
        }
    })
コード例 #40
0
def test_remove_quota(mocker):
    operator = mocker.Mock()
    master = mocker.Mock()
    driver = MesosOperatorMasterDriver(master, operator)
    driver._send = mocker.Mock()
    role = 'role1'
    driver.removeQuota(role)
    driver._send.assert_called_once_with({
        'type': 'REMOVE_QUOTA',
        'remove_quota': {
            'role': role
        }
    })
コード例 #41
0
def test_stop_maintenance(mocker):
    operator = mocker.Mock()
    master = mocker.Mock()
    driver = MesosOperatorMasterDriver(master, operator)
    driver._send = mocker.Mock()
    machines = [{'hostname': 'myhost', 'ip': '0.0.0.3'}]
    driver.stopMaintenance(machines)
    driver._send.assert_called_once_with({
        'type': 'STOP_MAINTENANCE',
        'stop_maintenance': {
            'machines': machines
        }
    })
コード例 #42
0
ファイル: test_operator.py プロジェクト: douban/pymesos
def test_remove_quota(mocker):
    operator = mocker.Mock()
    master = mocker.Mock()
    driver = MesosOperatorMasterDriver(master, operator)
    driver._send = mocker.Mock()
    role = 'role1'
    driver.removeQuota(role)
    driver._send.assert_called_once_with({
        'type': 'REMOVE_QUOTA',
        'remove_quota': {
            'role': role
        }
    })
コード例 #43
0
def test_update_weights(mocker):
    operator = mocker.Mock()
    master = mocker.Mock()
    driver = MesosOperatorMasterDriver(master, operator)
    driver._send = mocker.Mock()
    weight_infos = [{'role': 'role', 'weight': random.uniform(0, 10)}]
    driver.updateWeights(weight_infos)
    driver._send.assert_called_once_with({
        'type': 'UPDATE_WEIGHTS',
        'update_weights': {
            'weight_infos': weight_infos
        }
    })
コード例 #44
0
def test_send(mocker):
    operator = mocker.Mock()
    master = mocker.Mock()
    driver = MesosOperatorMasterDriver(master, operator)
    resp = mocker.Mock(status=200, read=mocker.Mock(return_value='{}'))
    conn = mocker.Mock(getresponse=mocker.Mock(return_value=resp))
    driver._get_conn = mocker.Mock(return_value=conn)
    assert driver._send({}) == {}
    driver._get_conn.assert_called_once_with()
    conn.request.assert_called_once_with(
        'POST',
        '/api/v1/operator',
        body=json.dumps({}).encode('utf-8'),
        headers={'Content-Type': 'application/json'})
コード例 #45
0
def test_mark_agent_gone(mocker):
    operator = mocker.Mock()
    master = mocker.Mock()
    driver = MesosOperatorMasterDriver(master, operator)
    driver._send = mocker.Mock()
    agent_id = str(uuid.uuid4())
    driver.markAgentGone(agent_id)
    driver._send.assert_called_once_with({
        'type': 'MARK_AGENT_GONE',
        'mark_agent_gone': {
            'agent_id': {
                'value': agent_id
            }
        }
    })
コード例 #46
0
ファイル: test_operator.py プロジェクト: douban/pymesos
def test_get_metrics(mocker):
    operator = mocker.Mock()
    master = mocker.Mock()
    driver = MesosOperatorMasterDriver(master, operator)
    driver._send = mocker.Mock()
    timeout = random.randint(0, 10) * 1000000000
    driver.getMetrics(timeout)
    driver._send.assert_called_once_with({
        'type': 'GET_METRICS',
        'get_metrics': {
            'timeout': {
                'nanoseconds': timeout
            }
        }
    })
コード例 #47
0
ファイル: test_operator.py プロジェクト: douban/pymesos
def test_mark_agent_gone(mocker):
    operator = mocker.Mock()
    master = mocker.Mock()
    driver = MesosOperatorMasterDriver(master, operator)
    driver._send = mocker.Mock()
    agent_id = str(uuid.uuid4())
    driver.markAgentGone(agent_id)
    driver._send.assert_called_once_with({
        'type': 'MARK_AGENT_GONE',
        'mark_agent_gone': {
            'agent_id': {
                'value': agent_id
            }
        }
    })
コード例 #48
0
def test_get_metrics(mocker):
    operator = mocker.Mock()
    master = mocker.Mock()
    driver = MesosOperatorMasterDriver(master, operator)
    driver._send = mocker.Mock()
    timeout = random.randint(0, 10) * 1000000000
    driver.getMetrics(timeout)
    driver._send.assert_called_once_with({
        'type': 'GET_METRICS',
        'get_metrics': {
            'timeout': {
                'nanoseconds': timeout
            }
        }
    })
コード例 #49
0
ファイル: test_operator.py プロジェクト: douban/pymesos
def test_on_agent_removed(mocker):
    operator = mocker.Mock()
    master = mocker.Mock()
    driver = MesosOperatorMasterDriver(master, operator)
    driver._started = True
    agent_id = str(uuid.uuid4())
    event = {
        'type': 'AGENT_REMOVED',
        'agent_removed': {
            'agent_id': {
                'value': agent_id
            }
        }
    }
    driver.on_event(event)
    operator.agentRemoved.assert_called_once_with(agent_id)
コード例 #50
0
def test_on_agent_removed(mocker):
    operator = mocker.Mock()
    master = mocker.Mock()
    driver = MesosOperatorMasterDriver(master, operator)
    driver._started = True
    agent_id = str(uuid.uuid4())
    event = {
        'type': 'AGENT_REMOVED',
        'agent_removed': {
            'agent_id': {
                'value': agent_id
            }
        }
    }
    driver.on_event(event)
    operator.agentRemoved.assert_called_once_with(agent_id)
コード例 #51
0
ファイル: test_operator.py プロジェクト: douban/pymesos
def test_on_agent_added(mocker):
    operator = mocker.Mock()
    master = mocker.Mock()
    driver = MesosOperatorMasterDriver(master, operator)
    driver._started = True
    agent_info = {
        'active': 'true',
        'agent_info': {
            'hostname': '172.31.2.24',
            'id': {
                'value': str(uuid.uuid4())
            },
            'port': 5051,
            'resources': [],
        },
        'allocated_resources': [],
        'capabilities': [
            {
                'type': 'MULTI_ROLE'
            },
            {
                'type': 'HIERARCHICAL_ROLE'
            },
            {
                'type': 'RESERVATION_REFINEMENT'
            }
        ],
        'offered_resources': [],
        'pid': 'slave(1)@172.31.2.24:5051',
        'registered_time': {
            'nanoseconds': 1500993262264135000
        },
        'reregistered_time': {
            'nanoseconds': 1500993263019321000
        },
        'total_resources': [],
        'version': '1.4.0'
    }
    event = {
        'type': 'AGENT_ADDED',
        'agent_added': {
            'agent': agent_info
        }
    }
    driver.on_event(event)
    operator.agentAdded.assert_called_once_with(agent_info)
コード例 #52
0
ファイル: test_operator.py プロジェクト: douban/pymesos
def test_set_logging_level(mocker):
    operator = mocker.Mock()
    master = mocker.Mock()
    driver = MesosOperatorMasterDriver(master, operator)
    driver._send = mocker.Mock()
    duration = random.randint(0, 10) * 1000000000
    level = random.randint(0, 3)
    driver.setLoggingLevel(level, duration)
    driver._send.assert_called_once_with({
        'type': 'SET_LOGGING_LEVEL',
        'set_logging_level': {
            'duration': {
                'nanoseconds': duration
            },
            'level': level
        }
    })
コード例 #53
0
ファイル: test_operator.py プロジェクト: douban/pymesos
def test_read_file(mocker):
    operator = mocker.Mock()
    master = mocker.Mock()
    driver = MesosOperatorMasterDriver(master, operator)
    driver._send = mocker.Mock()
    path = 'myname'
    length = random.randint(0, 10)
    offset = random.randint(0, length)
    driver.readFile(path, length, offset)
    driver._send.assert_called_once_with({
        'type': 'READ_FILE',
        'read_file': {
            'length': length,
            'offset': offset,
            'path': path
        }
    })
コード例 #54
0
def test_set_logging_level(mocker):
    operator = mocker.Mock()
    master = mocker.Mock()
    driver = MesosOperatorMasterDriver(master, operator)
    driver._send = mocker.Mock()
    duration = random.randint(0, 10) * 1000000000
    level = random.randint(0, 3)
    driver.setLoggingLevel(level, duration)
    driver._send.assert_called_once_with({
        'type': 'SET_LOGGING_LEVEL',
        'set_logging_level': {
            'duration': {
                'nanoseconds': duration
            },
            'level': level
        }
    })
コード例 #55
0
def test_read_file(mocker):
    operator = mocker.Mock()
    master = mocker.Mock()
    driver = MesosOperatorMasterDriver(master, operator)
    driver._send = mocker.Mock()
    path = 'myname'
    length = random.randint(0, 10)
    offset = random.randint(0, length)
    driver.readFile(path, length, offset)
    driver._send.assert_called_once_with({
        'type': 'READ_FILE',
        'read_file': {
            'length': length,
            'offset': offset,
            'path': path
        }
    })
コード例 #56
0
def test_on_agent_added(mocker):
    operator = mocker.Mock()
    master = mocker.Mock()
    driver = MesosOperatorMasterDriver(master, operator)
    driver._started = True
    agent_info = {
        'active': 'true',
        'agent_info': {
            'hostname': '172.31.2.24',
            'id': {
                'value': str(uuid.uuid4())
            },
            'port': 5051,
            'resources': [],
        },
        'allocated_resources': [],
        'capabilities': [
            {
                'type': 'MULTI_ROLE'
            },
            {
                'type': 'HIERARCHICAL_ROLE'
            },
            {
                'type': 'RESERVATION_REFINEMENT'
            }
        ],
        'offered_resources': [],
        'pid': 'slave(1)@172.31.2.24:5051',
        'registered_time': {
            'nanoseconds': 1500993262264135000
        },
        'reregistered_time': {
            'nanoseconds': 1500993263019321000
        },
        'total_resources': [],
        'version': '1.4.0'
    }
    event = {
        'type': 'AGENT_ADDED',
        'agent_added': {
            'agent': agent_info
        }
    }
    driver.on_event(event)
    operator.agentAdded.assert_called_once_with(agent_info)
コード例 #57
0
ファイル: test_operator.py プロジェクト: douban/pymesos
def test_update_weights(mocker):
    operator = mocker.Mock()
    master = mocker.Mock()
    driver = MesosOperatorMasterDriver(master, operator)
    driver._send = mocker.Mock()
    weight_infos = [
        {
            'role': 'role',
            'weight': random.uniform(0, 10)
        }
    ]
    driver.updateWeights(weight_infos)
    driver._send.assert_called_once_with({
        'type': 'UPDATE_WEIGHTS',
        'update_weights': {
            'weight_infos': weight_infos
        }
    })
コード例 #58
0
ファイル: test_operator.py プロジェクト: douban/pymesos
def test_stop_maintenance(mocker):
    operator = mocker.Mock()
    master = mocker.Mock()
    driver = MesosOperatorMasterDriver(master, operator)
    driver._send = mocker.Mock()
    machines = [
        {
            'hostname': 'myhost',
            'ip': '0.0.0.3'
        }
    ]
    driver.stopMaintenance(machines)
    driver._send.assert_called_once_with({
        'type': 'STOP_MAINTENANCE',
        'stop_maintenance': {
            'machines': machines
        }
    })
コード例 #59
0
ファイル: test_operator.py プロジェクト: douban/pymesos
def test_on_framework_updated(mocker):
    operator = mocker.Mock()
    master = mocker.Mock()
    driver = MesosOperatorMasterDriver(master, operator)
    driver._started = True
    framework_info = {
        'active': 'true',
        'allocated_resources': [],
        'connected': 'true',
        'framework_info': {
            'capabilities': [
                {
                    'type': 'RESERVATION_REFINEMENT'
                }
            ],
            'checkpoint': 'true',
            'failover_timeout': 0,
            'id': {
                'value': str(uuid.uuid4())
            },
            'name': 'inverse-offer-example-framework',
            'role': '*',
            'user': '******'
        },
        'inverse_offers': [],
        'recovered': 'false',
        'registered_time': {
            'nanoseconds': 1501191957829317120
        },
        'reregistered_time': {
            'nanoseconds': 1501191957829317120
        }
    }
    event = {
        'type': 'FRAMEWORK_UPDATED',
        'framework_updated': {
            'framework': framework_info
        }
    }
    driver.on_event(event)
    operator.frameworkUpdated.assert_called_once_with(framework_info)
    operator.frameworkAdded.assert_not_called()
コード例 #60
0
ファイル: test_operator.py プロジェクト: douban/pymesos
def test_on_task_added(mocker):
    operator = mocker.Mock()
    master = mocker.Mock()
    driver = MesosOperatorMasterDriver(master, operator)
    driver._started = True
    task_info = {
        'name': 'dummy-task',
        'task_id': {'value': str(uuid.uuid4())},
        'agent_id': {'value': str(uuid.uuid4())},
        'command': {'value': 'sleep', 'arguments': ['100'], }
    }
    event = {
        'type': 'TASK_ADDED',
        'task_added': {
            'task': task_info
        }
    }
    driver.on_event(event)
    operator.taskAdded.assert_called_once_with(task_info)
    operator.taskUpdated.assert_not_called()