Esempio n. 1
0
def test_launch_nested_container(mocker):
    agent = mocker.Mock()
    driver = MesosOperatorAgentDriver(agent)
    driver._send = mocker.Mock()
    launch_nested_container = {
        'container_id': {
            'parent': {
                'parent': {
                    'value': str(uuid.uuid4())
                },
                'value': str(uuid.uuid4())
            },
            'value': str(uuid.uuid4())
        },
        'command': {
            'environment': {
                'variables': [{
                    'name': 'ENV_VAR_KEY',
                    'type': 'VALUE',
                    'value': 'env_var_value'
                }]
            },
            'shell': 'true',
            'value': 'exit 0'
        }
    }
    driver.launchNestedContainer(launch_nested_container)
    driver._send.assert_called_once_with({
        'type':
        'LAUNCH_NESTED_CONTAINER',
        'launch_nested_container':
        launch_nested_container,
    })
Esempio n. 2
0
def test_launch_nested_container_session(mocker):
    agent = mocker.Mock()
    driver = MesosOperatorAgentDriver(agent)
    driver._send = mocker.Mock()
    launch_nested_container_session = {
        'container_id': {
            'parent': {
                'parent': {
                    'value': str(uuid.uuid4())
                },
                'value': str(uuid.uuid4())
            },
            'value': str(uuid.uuid4())
        },
        'command': {
            'environment': {
                'variables': [{
                    'name': 'ENV_VAR_KEY',
                    'type': 'VALUE',
                    'value': 'env_var_value'
                }]
            },
            'shell': 'true',
            'value': 'while [ true ]; do echo $(date); sleep 1; done'
        }
    }
    driver.launchNestedContainerSession(launch_nested_container_session)
    driver._send.assert_called_once_with(
        {
            'type': 'LAUNCH_NESTED_CONTAINER_SESSION',
            'launch_nested_container_session': launch_nested_container_session,
        },
        headers={'Accept': 'application/recordio'})
Esempio n. 3
0
def test_get_containers(mocker):
    agent = mocker.Mock()
    driver = MesosOperatorAgentDriver(agent)
    driver._send = mocker.Mock()
    driver.getContainers()
    driver._send.assert_called_once_with({
        'type': 'GET_CONTAINERS',
    })
Esempio n. 4
0
def test_update_resource_provider_config(mocker):
    agent = mocker.Mock()
    driver = MesosOperatorAgentDriver(agent)
    driver._send = mocker.Mock()
    info = {
        'type': 'org.apache.mesos.rp.local.storage',
        'name': 'test_slrp',
        'default_reservations': [{
            'type': 'DYNAMIC',
            'role': 'test-role'
        }],
        'storage': {
            'plugin': {
                'type':
                'org.apache.mesos.csi.test',
                'name':
                'test_plugin',
                'containers': [{
                    'services': ['CONTROLLER_SERVICE', 'NODE_SERVICE'],
                    'command': {
                        'shell':
                        'true',
                        'value':
                        './test-csi-plugin --available_capacity=\
                            2GB --work_dir=workdir',
                        'uris': [{
                            'value': '/PATH/TO/test-csi-plugin',
                            'executable': 'true'
                        }]
                    },
                    'resources': [{
                        'name': 'cpus',
                        'type': 'SCALAR',
                        'scalar': {
                            'value': random.uniform(0, 200)
                        }
                    }, {
                        'name': 'mem',
                        'type': 'SCALAR',
                        'scalar': {
                            'value': random.uniform(0, 200)
                        }
                    }]
                }]
            }
        }
    }
    driver.updateResourceProviderConfig(info)
    driver._send.assert_called_once_with({
        'type': 'UPDATE_RESOURCE_PROVIDER_CONFIG',
        'update_resource_provider_config': {
            'info': info,
        },
    })
Esempio n. 5
0
def test_prune_images(mocker):
    agent = mocker.Mock()
    driver = MesosOperatorAgentDriver(agent)
    driver._send = mocker.Mock()
    excluded_images = [{'type': 'DOCKER', 'docker': {'name': 'mysql:latest'}}]
    driver.pruneImages(excluded_images)
    driver._send.assert_called_once_with({
        'type': 'PRUNE_IMAGES',
        'prune_images': {
            'excluded_images': excluded_images,
        },
    })
Esempio n. 6
0
def test_get_containers(mocker):
    agent = mocker.Mock()
    driver = MesosOperatorAgentDriver(agent)
    driver._send = mocker.Mock()
    driver.getContainers(show_nested=True)
    driver._send.assert_called_once_with({
        'type': 'GET_CONTAINERS',
        'get_containers': {
            'show_nested': True,
            'show_standalone': False,
        }
    })
Esempio n. 7
0
def test_remove_resource_provider_config(mocker):
    agent = mocker.Mock()
    driver = MesosOperatorAgentDriver(agent)
    driver._send = mocker.Mock()
    type = 'org.apache.mesos.rp.local.storage'
    name = 'test_slrp'
    driver.removeResourceProviderConfig(type, name)
    driver._send.assert_called_once_with({
        'type': 'REMOVE_RESOURCE_PROVIDER_CONFIG',
        'remove_resource_provider_config': {
            'type': type,
            'name': name,
        },
    })
Esempio n. 8
0
def test_attach_container_output(mocker):
    agent = mocker.Mock()
    driver = MesosOperatorAgentDriver(agent)
    driver._send = mocker.Mock()
    container_id = str(uuid.uuid4())
    driver.attachContainerOutput(container_id)
    driver._send.assert_called_once_with({
        'type': 'ATTACH_CONTAINER_OUTPUT',
        'attach_container_output': {
            'container_id': {
                'value': container_id,
            },
        },
    }, headers={'Accept': 'application/recordio',
                'Message-Accept': 'application/json'})
Esempio n. 9
0
def test_remove_nested_container(mocker):
    agent = mocker.Mock()
    driver = MesosOperatorAgentDriver(agent)
    driver._send = mocker.Mock()
    container_id = str(uuid.uuid4())
    parent_id = str(uuid.uuid4())
    driver.removeNestedContainer(container_id, parent_id)
    driver._send.assert_called_once_with({
        'type': 'REMOVE_NESTED_CONTAINER',
        'remove_nested_container': {
            'container_id': {
                'parent': {
                    'value': parent_id,
                },
                'value': container_id
            },
        },
    })
Esempio n. 10
0
def test_attach_container_input(mocker):
    agent = mocker.Mock()
    driver = MesosOperatorAgentDriver(agent)
    driver._send = mocker.Mock()
    container_id = 'da737efb-a9d4-4622-84ef-f55eb07b861a'
    process_ios = [
        {
            'type': 'DATA',
            'data': {
                'type': 'STDIN',
                'data': 'dGVzdAo='
            }
        },
        {
            'type': 'CONTROL',
            'control': {
                'type': 'HEARTBEAT',
                'heartbeat': {
                    'interval': {
                        'nanoseconds': 30000000000
                    }
                }
            }
        }
    ]
    driver.attachContainerInput(container_id, process_ios)
    awaited_result = '153\n{"attach_container_input": {"container_id": ' \
                     '{"value": "da737efb-a9d4-4622-84ef-f55eb07b861a"}, ' \
                     '"type": "CONTAINER_ID"}, "type": ' \
                     '"ATTACH_CONTAINER_INPUT"}163\n' \
                     '{"attach_container_input": {"process_io": {"data": ' \
                     '{"data": "dGVzdAo=", "type": "STDIN"}, "type": ' \
                     '"DATA"}, "type": "PROCESS_IO"}, "type": ' \
                     '"ATTACH_CONTAINER_INPUT"}210\n' \
                     '{"attach_container_input": {"process_io": {"control": ' \
                     '{"heartbeat": {"interval": {"nanoseconds": ' \
                     '30000000000}}, "type": "HEARTBEAT"}, "type": ' \
                     '"CONTROL"}, "type": "PROCESS_IO"}, "type": ' \
                     '"ATTACH_CONTAINER_INPUT"}'
    driver._send.assert_called_once_with(awaited_result, headers={
        'Accept': 'application/recordio'})