Пример #1
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
        }
    })
Пример #2
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
            }
        }
    })
Пример #3
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
        }
    })
Пример #4
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
        }
    })
Пример #5
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
            }
        }
    })
Пример #6
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',
    })
Пример #7
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',
    })
Пример #8
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',
    })
Пример #9
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',
    })
Пример #10
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',
    })
Пример #11
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',
    })
Пример #12
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',
    })
Пример #13
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',
    })
Пример #14
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',
    })
Пример #15
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',
    })
Пример #16
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',
    })
Пример #17
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',
    })
Пример #18
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',
    })
Пример #19
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',
    })
Пример #20
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',
    })
Пример #21
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',
    })
Пример #22
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',
    })
Пример #23
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',
    })
Пример #24
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',
    })
Пример #25
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',
    })
Пример #26
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',
    })
Пример #27
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',
    })
Пример #28
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',
    })
Пример #29
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',
    })
Пример #30
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',
    })
Пример #31
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',
    })
Пример #32
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
        }
    })
Пример #33
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
        }
    })
Пример #34
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
        }
    })
Пример #35
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
        }
    })
Пример #36
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
        }
    })
Пример #37
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
        }
    })
Пример #38
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'})
Пример #39
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
            }
        }
    })
Пример #40
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
            }
        }
    })
Пример #41
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
            }
        }
    })
Пример #42
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
            }
        }
    })
Пример #43
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
        }
    })
Пример #44
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
        }
    })
Пример #45
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
        }
    })
Пример #46
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
        }
    })
Пример #47
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
        }
    })
Пример #48
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
        }
    })
Пример #49
0
def test_unreserve_resources(mocker):
    operator = mocker.Mock()
    master = mocker.Mock()
    driver = MesosOperatorMasterDriver(master, operator)
    driver._send = mocker.Mock()
    agent_id = str(uuid.uuid4())
    resources = [
        {
            'type': 'SCALAR',
            'name': 'cpus',
            'reservation': {
                'principal': 'my-principal'
            },
            'role': 'role',
            'scalar': {
                'value': random.uniform(0, 1024.0)
            }
        },
        {
            'type': 'SCALAR',
            'name': 'mem',
            'reservation': {
                'principal': 'my-principal'
            },
            'role': 'role',
            'scalar': {
                'value': random.uniform(0, 1024.0)
            }
        }
    ]
    driver.unreserveResources(agent_id, resources)
    driver._send.assert_called_once_with({
        'type': 'UNRESERVE_RESOURCES',
        'unreserve_resources': {
            'agent_id': {
                'value': agent_id
            },
            'resources': resources
        }
    })
Пример #50
0
def test_unreserve_resources(mocker):
    operator = mocker.Mock()
    master = mocker.Mock()
    driver = MesosOperatorMasterDriver(master, operator)
    driver._send = mocker.Mock()
    agent_id = str(uuid.uuid4())
    resources = [
        {
            'type': 'SCALAR',
            'name': 'cpus',
            'reservation': {
                'principal': 'my-principal'
            },
            'role': 'role',
            'scalar': {
                'value': random.uniform(0, 1024.0)
            }
        },
        {
            'type': 'SCALAR',
            'name': 'mem',
            'reservation': {
                'principal': 'my-principal'
            },
            'role': 'role',
            'scalar': {
                'value': random.uniform(0, 1024.0)
            }
        }
    ]
    driver.unreserveResources(agent_id, resources)
    driver._send.assert_called_once_with({
        'type': 'UNRESERVE_RESOURCES',
        'unreserve_resources': {
            'agent_id': {
                'value': agent_id
            },
            'resources': resources
        }
    })
Пример #51
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'
        }
    )
Пример #52
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
        }
    })