def test_uninstall_multiple_frameworknames(): retcode, _, _ = exec_command([ 'dcos', 'package', 'install', 'helloworld', '--yes', '--options=tests/data/package/helloworld-1.json' ]) assert retcode == 0 retcode, _, _ = exec_command([ 'dcos', 'package', 'install', 'helloworld', '--yes', '--options=tests/data/package/helloworld-2.json' ]) assert retcode == 0 watch_all_deployments() retcode, _, _ = exec_command([ 'dcos', 'package', 'uninstall', 'helloworld', '--yes', '--app-id=hello-1' ]) assert retcode == 0 retcode, _, _ = exec_command([ 'dcos', 'package', 'uninstall', 'helloworld', '--yes', '--app-id=hello-2' ]) assert retcode == 0 watch_all_deployments()
def _chronos_package( args=['--yes'], returncode=0, stdout=b'Installing Marathon app for package [chronos] ' b'version [2.5.0-1]\n', stderr=b'', pre_install_notes=(b'By Deploying, you agree to the Terms ' b'and Conditions https://mesosphere.com/' b'catalog-terms-conditions/#certified-services\n' b'We recommend a minimum of one node with at least ' b'1 CPU and 2GB of RAM available for the ' b'Chronos Service.\n'), post_install_notes=b'Chronos DCOS Service has been successfully ' b'installed!\n\n' b'\tDocumentation: http://mesos.github.io/' b'chronos\n' b'\tIssues: https://github.com/mesos/chronos/' b'issues\n', stdin=None): _install_chronos(args, returncode, stdout, stderr, pre_install_notes, post_install_notes, stdin) try: yield finally: _uninstall_chronos() delete_zk_node('chronos') watch_all_deployments()
def test_stop_unknown_task_wipe(): with _zero_instance_app(): start_app('zero-instance-app') watch_all_deployments() task_id = 'unknown-task-id' _stop_task(task_id, '--wipe', expect_success=False)
def test_kill_unknown_task(): with _zero_instance_app(): start_app('zero-instance-app') watch_all_deployments() task_id = ['unknown-task-id'] _kill_task(task_id, expect_success=False)
def test_killing_with_host_app(): with _zero_instance_app(): start_app('zero-instance-app', 3) watch_all_deployments() existing_tasks = _list_tasks(3, 'zero-instance-app') task_hosts = set([task['host'] for task in existing_tasks]) if len(task_hosts) <= 1: pytest.skip('test needs 2 or more agents to succeed, ' 'only {} agents available'.format(len(task_hosts))) assert len(task_hosts) > 1 kill_host = list(task_hosts)[0] expected_to_be_killed = set([ task['id'] for task in existing_tasks if task['host'] == kill_host ]) not_to_be_killed = set([ task['id'] for task in existing_tasks if task['host'] != kill_host ]) assert len(not_to_be_killed) > 0 assert len(expected_to_be_killed) > 0 command = [ 'dcos', 'marathon', 'app', 'kill', '--host', kill_host, 'zero-instance-app' ] returncode, stdout, stderr = exec_command(command) assert stdout.decode().startswith('Killed tasks: ') assert stderr == b'' new_tasks = set([task['id'] for task in _list_tasks()]) assert not_to_be_killed.intersection(new_tasks) == not_to_be_killed assert len(expected_to_be_killed.intersection(new_tasks)) == 0
def test_kill_task_wipe(): with _zero_instance_app(): start_app('zero-instance-app', 1) watch_all_deployments() task_list = _list_tasks(1, 'zero-instance-app') task_id = [task_list[0]['id']] _kill_task(task_id, wipe=True)
def test_stop_task_wipe(): with _zero_instance_app(): start_app('zero-instance-app', 1) watch_all_deployments() task_list = _list_tasks(1, 'zero-instance-app') task_id = task_list[0]['id'] _stop_task(task_id, '--wipe')
def test_kill_two_tasks(): with _zero_instance_app(): start_app('zero-instance-app', 2) watch_all_deployments() task_list = _list_tasks(2, 'zero-instance-app') task_ids = [task['id'] for task in task_list] _kill_task(task_ids)
def test_install(): with package('chronos', deploy=True, args=[]): watch_all_deployments() wait_for_service('chronos') services = get_services(args=['--inactive']) assert len( [service for service in services if service['name'] == 'chronos']) == 0
def _pod_add_from_stdin(file_path): cmd = _POD_ADD_CMD with open(file_path) as fd: returncode, stdout, stderr = exec_command(cmd, stdin=fd) assert returncode == 0 assert re.fullmatch(r'Created deployment \S+\n', stdout.decode('utf-8')) assert stderr == b'' watch_all_deployments()
def _add_group_by_stdin(file_path): with open(file_path) as fd: cmd = ['dcos', 'marathon', 'group', 'add'] returncode, stdout, stderr = exec_command(cmd, stdin=fd) assert returncode == 0 assert re.fullmatch('Created deployment \S+\n', stdout.decode('utf-8')) assert stderr == b'' # Let's make sure that we don't return until the deployment has finished watch_all_deployments()
def test_kill_and_scale_task(): with _zero_instance_app(): start_app('zero-instance-app', 2) watch_all_deployments() task_list = _list_tasks(2, 'zero-instance-app') task_id = [task_list[0]['id']] _kill_task(task_id, scale=True) task_list = _list_tasks(1, 'zero-instance-app')
def test_stop_app(): with _zero_instance_app(): start_app('zero-instance-app', 3) watch_all_deployments() returncode, stdout, stderr = exec_command( ['dcos', 'marathon', 'app', 'stop', 'zero-instance-app']) assert returncode == 0 assert stdout.decode().startswith('Created deployment ') assert stderr == b''
def _update_group(group_id, file_path): with open(file_path) as fd: returncode, stdout, stderr = exec_command( ['dcos', 'marathon', 'group', 'update', group_id], stdin=fd) assert returncode == 0 assert stdout.decode().startswith('Created deployment ') assert stderr == b'' # Let's make sure that we don't return until the deployment has finished watch_all_deployments()
def test_restarting_app(): app_id = 'zero-instance-app' with app(_ZERO_INSTANCE_APP, app_id): start_app(app_id, 3) watch_all_deployments() returncode, stdout, stderr = exec_command( ['dcos', 'marathon', 'app', 'restart', app_id]) assert returncode == 0 assert stdout.decode().startswith('Created deployment ') assert stderr == b''
def test_scale_group_not_exist(): returncode, stdout, stderr = exec_command( ['dcos', 'marathon', 'group', 'scale', 'scale-group', '2']) assert stderr == b'' watch_all_deployments() returncode, stdout, stderr = exec_command( ['dcos', 'marathon', 'group', 'show', 'scale-group']) res = json.loads(stdout.decode('utf-8')) assert len(res['apps']) == 0 remove_group('scale-group')
def test_pod_update_from_stdin(): with pod(GOOD_POD_FILE_PATH, GOOD_POD_ID): # The deployment will never complete _assert_pod_update_from_stdin(extra_args=[], pod_json_file_path=UNGOOD_POD_FILE_PATH) # Override above failed deployment _assert_pod_update_from_stdin( extra_args=['--force'], pod_json_file_path=UPDATED_GOOD_POD_FILE_PATH) watch_all_deployments()
def test_scale_group(): with group(SCALE_GROUP, 'scale-group'): returncode, stdout, stderr = exec_command( ['dcos', 'marathon', 'group', 'scale', 'scale-group', '2']) assert stderr == b'' assert returncode == 0 watch_all_deployments() returncode, stdout, stderr = exec_command( ['dcos', 'marathon', 'group', 'show', 'scale-group']) res = json.loads(stdout.decode('utf-8')) assert res['groups'][0]['apps'][0]['instances'] == 2
def test_killing_app(): with _zero_instance_app(): start_app('zero-instance-app', 3) watch_all_deployments() returncode, stdout, stderr = exec_command( ['dcos', 'marathon', 'app', 'kill', 'zero-instance-app']) assert returncode == 0 assert stderr == b'' out = stdout.decode() assert out.startswith('Killed tasks: ') out = out.strip('Killed tasks: ') dictout = ast.literal_eval(out) assert len(dictout) == 3
def _uninstall_helloworld( args=[], stdout=b'', stderr=b'', returncode=0, uninstalled=b'Uninstalled package [helloworld] version [0.1.0]\n'): assert_command(['dcos', 'package', 'uninstall', 'helloworld', '--yes'] + args, stdout=stdout, stderr=uninstalled+stderr, returncode=returncode) watch_all_deployments()
def test_show_task(): with _zero_instance_app(): start_app('zero-instance-app', 3) watch_all_deployments() result = _list_tasks(3, 'zero-instance-app') returncode, stdout, stderr = exec_command( ['dcos', 'marathon', 'task', 'show', result[0]['id']]) result = json.loads(stdout.decode('utf-8')) assert returncode == 0 assert result['appId'] == '/zero-instance-app' assert stderr == b''
def test_images_in_metadata(): package_install('cassandra') labels = _get_app_labels('/cassandra') dcos_package_metadata = labels.get("DCOS_PACKAGE_METADATA") images = json.loads( base64.b64decode(dcos_package_metadata).decode('utf-8'))["images"] assert images.get("icon-small") is not None assert images.get("icon-medium") is not None assert images.get("icon-large") is not None package_uninstall('cassandra') delete_zk_node('dcos-service-cassandra') watch_all_deployments()
def test_update_group(): group_app = 'tests/data/marathon/groups/good.json' with group(group_app, 'test-group'): newapp = json.dumps([{"id": "appadded", "cmd": "sleep 0"}]) appjson = "apps={}".format(newapp) returncode, stdout, stderr = exec_command([ 'dcos', 'marathon', 'group', 'update', 'test-group/sleep', appjson ]) assert returncode == 0 assert stdout.decode().startswith('Created deployment ') assert stderr == b'' watch_all_deployments() show_app('test-group/sleep/appadded')
def test_killing_scaling_app(): with _zero_instance_app(): start_app('zero-instance-app', 3) watch_all_deployments() _list_tasks(3) command = ['dcos', 'marathon', 'app', 'kill', '--scale', 'zero-instance-app'] returncode, stdout, stderr = exec_command(command) assert returncode == 0 assert stdout.decode().startswith('Started deployment: ') assert stdout.decode().find('version') > -1 assert stdout.decode().find('deploymentId') > -1 assert stderr == b'' watch_all_deployments() _list_tasks(0)
def test_killing_app(): with _zero_instance_app(): start_app('zero-instance-app', 3) watch_all_deployments() task_set_1 = set( [task['id'] for task in _list_tasks(3, 'zero-instance-app')]) returncode, stdout, stderr = exec_command( ['dcos', 'marathon', 'app', 'kill', 'zero-instance-app']) assert returncode == 0 assert stdout.decode().startswith('Killed tasks: ') assert stderr == b'' watch_all_deployments() task_set_2 = set( [task['id'] for task in _list_tasks(app_id='zero-instance-app')]) assert len(task_set_1.intersection(task_set_2)) == 0
def _package(name, args, stdout=b'', stderr=b'', uninstall_confirmation=True, uninstall_app_id='', uninstall_stderr=b''): """Context manager that installs a package on entrance, and uninstalls it on exit. :param name: package name :type name: str :param args: extra CLI args :type args: [str] :param stdout: Expected stdout :param stderr: Expected stderr :type stdout: bytes :param uninstall_app_id: App id for uninstallation :type uninstall_app_id: string :param uninstall_stderr: Expected stderr :type uninstall_stderr: bytes :rtype: None """ command = ['dcos', 'package', 'install', name] + args installed = False timeout = http.DEFAULT_READ_TIMEOUT try: returncode_, stdout_, stderr_ = exec_command(command, timeout=timeout) installed = (returncode_ == 0) assert stderr_ == stderr assert installed assert stdout_ == stdout yield finally: if installed: command = ['dcos', 'package', 'uninstall', name] if uninstall_confirmation: command.append('--yes') if uninstall_app_id: command.append('--app-id='+uninstall_app_id) assert_command(command, stderr=uninstall_stderr) watch_all_deployments()
def test_rollback_deployment(): with _zero_instance_app(): start_app('zero-instance-app', _ZERO_INSTANCE_APP_INSTANCES) result = list_deployments(1, 'zero-instance-app') returncode, stdout, stderr = exec_command( ['dcos', 'marathon', 'deployment', 'rollback', result[0]['id']]) result = json.loads(stdout.decode('utf-8')) assert returncode == 0 assert 'deploymentId' in result assert 'version' in result assert stderr == b'' watch_all_deployments() list_deployments(0)
def _helloworld_cli(): args = ['--yes', '--cli'] command = ['dcos', 'package', 'install', 'helloworld'] + args installed = False timeout = http.DEFAULT_READ_TIMEOUT try: returncode_, _, _ = exec_command(command, timeout=timeout) installed = (returncode_ == 0) assert installed yield finally: if installed: # TODO(janisz): Cahnge back to package uninstall after DCOS_OSS-5619 command = ['dcos', 'plugin', 'remove', 'dcos-http'] assert_command(command) watch_all_deployments()
def test_uninstall_multiple_frameworknames(zk_znode): retcode, _, _ = exec_command([ 'dcos', 'package', 'install', 'chronos', '--yes', '--options=tests/data/package/chronos-1.json']) assert retcode == 0 retcode, _, _ = exec_command([ 'dcos', 'package', 'install', 'chronos', '--yes', '--options=tests/data/package/chronos-2.json']) assert retcode == 0 watch_all_deployments() _uninstall_chronos(args=['--app-id=chronos-user-1'], returncode=1) _uninstall_chronos(args=['--app-id=chronos-user-2'], returncode=1) for framework in get_services(args=['--inactive']): if framework['name'] == 'chronos-user': service_shutdown(framework['id'])
def test_uninstall_multiple_frameworknames(zk_znode): _install_chronos( args=['--yes', '--options=tests/data/package/chronos-1.json']) _install_chronos( args=['--yes', '--options=tests/data/package/chronos-2.json']) watch_all_deployments() expected_output = file_json( 'tests/data/package/json/test_list_chronos_two_users.json') _list(args=['--json'], stdout=expected_output) _list(args=['--json', 'chronos'], stdout=expected_output) _list(args=['--json', '--app-id=/chronos-user-1'], stdout=file_json( 'tests/data/package/json/test_list_chronos_user_1.json')) _list(args=['--json', '--app-id=/chronos-user-2'], stdout=file_json( 'tests/data/package/json/test_list_chronos_user_2.json')) _uninstall_chronos( args=['--app-id=chronos-user-1'], returncode=1, stderr='Uninstalled package [chronos] version [2.5.0-1]\n' 'Unable to shutdown [chronos] service framework with name ' '[chronos-user] because there are multiple framework ids ' 'matching this name: ') _uninstall_chronos( args=['--app-id=chronos-user-2'], returncode=1, stderr='Uninstalled package [chronos] version [2.5.0-1]\n' 'Unable to shutdown [chronos] service framework with name ' '[chronos-user] because there are multiple framework ids ' 'matching this name: ') for framework in get_services(args=['--inactive']): if framework['name'] == 'chronos-user': service_shutdown(framework['id'])