def test_list_cli(): _install_helloworld() stdout = file_json( 'tests/data/package/json/test_list_helloworld.json', 4) _list(args=['--json'], stdout=stdout) _uninstall_helloworld() stderr = ( b'This is a Community service. ' b'Community services are not tested ' b'for production environments. ' b'There may be bugs, incomplete features, ' b'incorrect documentation, or other discrepancies.\n' b'By Deploying, you agree to the Terms ' b'and Conditions https://mesosphere.com/' b'catalog-terms-conditions/#community-services\n' b'Installing CLI subcommand for package [helloworld] ' b'version [0.1.0]\n' b'New commands available: http\n' ) _install_helloworld(args=['--cli', '--yes'], stderr=stderr) stdout = file_json( 'tests/data/package/json/test_list_helloworld_cli.json', 4) _list(args=['--json'], stdout=stdout) _uninstall_cli_helloworld()
def test_list(): with _helloworld(): expected_output = file_json( 'tests/data/package/json/test_list_helloworld.json', 4) _list(args=['--json'], stdout=expected_output) _list(args=['--json', 'helloworld'], stdout=expected_output) _list(args=['--json', '--app-id=/helloworld'], stdout=expected_output)
def test_package_metadata(): _install_helloworld() # test marathon labels expected_source = bytes( UNIVERSE_TEST_REPOS['helloworld-universe'], 'utf-8' ) expected_labels = { 'DCOS_PACKAGE_NAME': b'helloworld', 'DCOS_PACKAGE_VERSION': b'0.1.0', 'DCOS_PACKAGE_SOURCE': expected_source, } app_labels = _get_app_labels('helloworld') for label, value in expected_labels.items(): assert value == six.b(app_labels.get(label)) # test local package.json package = file_json( 'tests/data/package/json/test_package_metadata.json') package = json.loads(package.decode("UTF-8")) cmd = subcommand.InstalledSubcommand("dcos-http") # test local package.json assert cmd.package_json()['marathon'] == package['marathon'] # uninstall helloworld _uninstall_helloworld() # TODO(janisz): Remove after DCOS_OSS-5619 assert_command(['dcos', 'plugin', 'remove', 'dcos-http'])
def test_describe_options(): stdout = file_json( 'tests/data/package/json/test_describe_app_options.json') stdout = json.loads(stdout.decode('utf-8')) expected_labels = stdout.pop("labels", None) with util.temptext(b'{"name": "hallo", "port": 80}') as options: returncode, stdout_, stderr = exec_command( ['dcos', 'package', 'describe', '--app', '--options', options[1], 'helloworld']) stdout_ = json.loads(stdout_.decode('utf-8')) actual_labels = stdout_.pop("labels", None) for label, value in expected_labels.items(): if label in ["DCOS_PACKAGE_METADATA", "DCOS_PACKAGE_OPTIONS"]: # We covert the metadata into a dictionary # so that failures in equality are more descriptive assert base64_to_dict(value) == \ base64_to_dict(actual_labels.get(label)) else: assert value == actual_labels.get(label) assert stdout == stdout_ assert stderr == b'' assert returncode == 0
def test_package_metadata(): _install_helloworld() # test marathon labels expected_source = bytes(UNIVERSE_TEST_REPOS['helloworld-universe'], 'utf-8') expected_labels = { 'DCOS_PACKAGE_NAME': b'helloworld', 'DCOS_PACKAGE_VERSION': b'0.1.0', 'DCOS_PACKAGE_SOURCE': expected_source, } app_labels = _get_app_labels('helloworld') for label, value in expected_labels.items(): assert value == six.b(app_labels.get(label)) # test local package.json package = file_json('tests/data/package/json/test_package_metadata.json') package = json.loads(package.decode("UTF-8")) helloworld_subcommand = subcommand.InstalledSubcommand("helloworld") # test local package.json assert helloworld_subcommand.package_json() == package # uninstall helloworld _uninstall_helloworld()
def test_cli_global(): helloworld_path = 'tests/data/package/json/test_list_helloworld_cli.json' helloworld_json = file_json(helloworld_path) with _helloworld_cli(global_=True): assert os.path.exists(subcommand.global_package_dir("helloworld")) assert_command(cmd=['dcos', 'package', 'list', '--json', '--cli'], stdout=helloworld_json)
def test_package_describe(): stdout = file_json('tests/data/package/json/test_describe_helloworld.json') returncode_, stdout_, stderr_ = exec_command( ['dcos', 'package', 'describe', 'helloworld']) assert returncode_ == 0 output = json.loads(stdout_.decode('utf-8')) assert output == json.loads(stdout.decode('utf-8')) assert stderr_ == b''
def test_list_cli(): _install_helloworld() stdout = file_json('tests/data/package/json/test_list_helloworld.json') _list(args=['--json'], stdout=stdout) _uninstall_helloworld() stdout = (b'By Deploying, you agree to the Terms ' b'and Conditions https://mesosphere.com/' b'catalog-terms-conditions/#community-services\n' b"Installing CLI subcommand for package [helloworld] " + b"version [0.1.0]\n" b"New command available: dcos " + _executable_name(b'helloworld') + b"\n") _install_helloworld(args=['--cli', '--yes'], stdout=stdout) stdout = file_json('tests/data/package/json/test_list_helloworld_cli.json') _list(args=['--json'], stdout=stdout) _uninstall_cli_helloworld()
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'])
def test_describe(command_to_run, expected_output_file): stdout = file_json('tests/data/package/json/' + expected_output_file) expected_stdout = json.loads(stdout.decode('utf-8')) returncode, stdout, stderr = exec_command( ['dcos', 'package', 'describe'] + command_to_run.split(' '), ) assert returncode == 0 assert stderr == b'' actual_stdout = json.loads(stdout.decode('utf-8')) assert expected_stdout == actual_stdout
def test_package_metadata(): _install_helloworld() # test marathon labels expected_metadata = { 'maintainer': '*****@*****.**', 'framework': False, 'name': 'helloworld', 'version': '0.1.0', 'packagingVersion': '3.0', 'preInstallNotes': 'A sample pre-installation message', 'selected': False, 'website': 'https://github.com/mesosphere/dcos-helloworld', 'description': 'Example DCOS application package', 'tags': ['mesosphere', 'example', 'subcommand'], 'postInstallNotes': 'A sample post-installation message' } expected_source = bytes( UNIVERSE_TEST_REPOS['helloworld-universe'], 'utf-8' ) expected_labels = { 'DCOS_PACKAGE_NAME': b'helloworld', 'DCOS_PACKAGE_VERSION': b'0.1.0', 'DCOS_PACKAGE_SOURCE': expected_source, } app_labels = _get_app_labels('helloworld') for label, value in expected_labels.items(): assert value == six.b(app_labels.get(label)) assert expected_metadata == base64_to_dict(six.b( app_labels.get('DCOS_PACKAGE_METADATA'))) # test local package.json package = file_json( 'tests/data/package/json/test_package_metadata.json') package = json.loads(package.decode("UTF-8")) helloworld_subcommand = subcommand.InstalledSubcommand("helloworld") # test local package.json assert helloworld_subcommand.package_json() == package # uninstall helloworld _uninstall_helloworld()
def test_list(zk_znode): empty = b'[]\n' _list(args=['--json'], stdout=empty) _list(args=['xyzzy', '--json'], stdout=empty) _list(args=['--app-id=/xyzzy', '--json'], stdout=empty) with _helloworld(): expected_output = file_json( 'tests/data/package/json/test_list_helloworld.json') _list(args=['--json'], stdout=expected_output) _list(args=['--json', 'helloworld'], stdout=expected_output) _list(args=['--json', '--app-id=/helloworld'], stdout=expected_output) le_package = 'ceci-nest-pas-une-package' _list(args=['--json', le_package], stdout=empty) _list(args=['--json', '--app-id=/' + le_package], stdout=empty)
def test_list_cli_only(env): helloworld_path = 'tests/data/package/json/test_list_helloworld_cli.json' helloworld_json = file_json(helloworld_path) with _helloworld_cli(), \ update_config('package.cosmos_url', 'http://nohost', env): assert_command( cmd=['dcos', 'package', 'list', '--json', '--cli'], stdout=helloworld_json) assert_command( cmd=['dcos', 'package', 'list', '--json', '--cli', '--app-id=/helloworld'], stdout=b'[]\n') assert_command( cmd=['dcos', 'package', 'list', '--json', '--cli', 'helloworld'], stdout=helloworld_json)
def test_describe_render(): stdout = file_json( 'tests/data/package/json/test_describe_helloworld_app_render.json') stdout = json.loads(stdout.decode('utf-8')) expected_labels = stdout.pop("labels", None) returncode, stdout_, stderr = exec_command( ['dcos', 'package', 'describe', 'helloworld', '--app', '--render']) stdout_ = json.loads(stdout_.decode('utf-8')) actual_labels = stdout_.pop("labels", None) for label, value in expected_labels.items(): assert value == actual_labels.get(label) assert stdout == stdout_ assert stderr == b'' assert returncode == 0
def test_describe_render(): stdout = file_json( 'tests/data/package/json/test_describe_helloworld_app_render.json') stdout = json.loads(stdout.decode('utf-8')) expected_labels = stdout.pop("labels", None) returncode, stdout_, stderr = exec_command( ['dcos', 'package', 'describe', 'helloworld', '--app', '--render']) stdout_ = json.loads(stdout_.decode('utf-8')) actual_labels = stdout_.pop("labels", None) for label, value in expected_labels.items(): if label == "DCOS_PACKAGE_METADATA": # We covert the metadata into a dictionary # so that failures in equality are more descriptive assert base64_to_dict(value) == \ base64_to_dict(actual_labels.get(label)) else: assert value == actual_labels.get(label) assert stdout == stdout_ assert stderr == b'' assert returncode == 0
def test_repo_list(): repo_list = file_json('tests/data/package/json/test_repo_list.json') assert_command(['dcos', 'package', 'repo', 'list', '--json'], stdout=repo_list)
def test_describe_config(): stdout = file_json( 'tests/data/package/json/test_describe_helloworld_config.json') assert_command(['dcos', 'package', 'describe', 'helloworld', '--config'], stdout=stdout)