Ejemplo n.º 1
0
def settings_create(ctx):
    """Create a settings file."""
    # Choose where and whether to save the configuration file.
    path = ctx.obj['load_path']
    if path:
        click.confirm(
            'A settings file already exists. Continuing will override it. '
            'Do you want to continue?',
            abort=True,
        )
    else:
        path = ctx.obj['save_path']

    # Get information about Pulp.
    pulp_config = {'pulp': _get_pulp_properties()}
    pulp_config['hosts'] = [
        _get_host_properties(pulp_config['pulp']['version'])
    ]
    pulp_config['pulp']['version'] = str(pulp_config['pulp']['version'])
    try:
        config.validate_config(pulp_config)  # This should NEVER fail!
    except exceptions.ConfigValidationError:
        print(
            'An internal error has occurred. Please report this to the Pulp '
            'Smash developers at https://github.com/PulpQE/pulp-smash/issues',
            file=sys.stderr,
        )
        raise

    # Write the config to disk.
    with open(path, 'w') as handler:
        handler.write(json.dumps(pulp_config, indent=2, sort_keys=True))
    click.echo('Settings written to {}.'.format(path))
Ejemplo n.º 2
0
 def test_invalid_config(self):
     """An invalid config raises an exception."""
     config_dict = json.loads(PULP_SMASH_CONFIG)
     config_dict["pulp"]["auth"] = []
     config_dict["hosts"][0]["hostname"] = ""
     with self.assertRaises(exceptions.ConfigValidationError):
         config.validate_config(config_dict)
Ejemplo n.º 3
0
def settings_validate(ctx):
    """Validate the settings file."""
    path = ctx.obj['cfg_path']
    if not path:
        _raise_settings_not_found()

    with open(path) as handle:
        config_dict = json.load(handle)
    if 'systems' not in config_dict and 'pulp' in config_dict:
        message = ('the settings file at {} appears to be following the old '
                   'configuration file format, please update it like below:\n'.
                   format(path))
        message += json.dumps(config.convert_old_config(config_dict), indent=2)
        result = click.ClickException(message)
        result.exit_code = -1
        raise result
    try:
        config.validate_config(config_dict)
    except exceptions.ConfigValidationError as err:
        message = ('invalid settings file {}\n'.format(path))
        for error_message in err.error_messages:
            message += error_message
        result = click.ClickException(message)
        result.exit_code = -1
        raise result
Ejemplo n.º 4
0
def settings_create(ctx):
    """Create a settings file."""
    # Choose where and whether to save the configuration file.
    path = ctx.obj["load_path"]
    if path:
        click.confirm(
            "A settings file already exists. Continuing will override it. "
            "Do you want to continue?",
            abort=True,
        )
    else:
        path = ctx.obj["save_path"]

    # Get information about Pulp.
    pulp_config = {"pulp": _get_pulp_properties()}
    pulp_config["general"] = _get_task_timeout()
    pulp_config["hosts"] = [
        _get_host_properties(pulp_config["pulp"]["version"])
    ]
    pulp_config["pulp"]["version"] = str(pulp_config["pulp"]["version"])
    try:
        config.validate_config(pulp_config)  # This should NEVER fail!
    except exceptions.ConfigValidationError:
        print(
            "An internal error has occurred. Please report this to the Pulp "
            "Smash developers at https://github.com/PulpQE/pulp-smash/issues",
            file=sys.stderr,
        )
        raise

    # Write the config to disk.
    with open(path, "w") as handler:
        handler.write(json.dumps(pulp_config, indent=2, sort_keys=True))
    click.echo("Settings written to {}.".format(path))
Ejemplo n.º 5
0
def settings_create(ctx):
    """Create a settings file."""
    # Choose where and whether to save the configuration file.
    path = ctx.obj['load_path']
    if path:
        click.confirm(
            'A settings file already exists. Continuing will override it. '
            'Do you want to continue?',
            abort=True,
        )
    else:
        path = ctx.obj['save_path']

    # Get information about Pulp.
    pulp_config = {'pulp': _get_pulp_properties()}
    pulp_config['hosts'] = [
        _get_host_properties(pulp_config['pulp']['version'])
    ]
    pulp_config['pulp']['version'] = str(pulp_config['pulp']['version'])
    try:
        config.validate_config(pulp_config)  # This should NEVER fail!
    except exceptions.ConfigValidationError:
        print(
            'An internal error has occurred. Please report this to the Pulp '
            'Smash developers at https://github.com/PulpQE/pulp-smash/issues',
            file=sys.stderr,
        )
        raise

    # Write the config to disk.
    with open(path, 'w') as handler:
        handler.write(json.dumps(pulp_config, indent=2, sort_keys=True))
    click.echo('Settings written to {}.'.format(path))
Ejemplo n.º 6
0
 def test_invalid_config(self):
     """An invalid config raises an exception."""
     config_dict = json.loads(PULP_SMASH_CONFIG)
     config_dict['pulp']['auth'] = []
     config_dict['hosts'][0]['hostname'] = ''
     with self.assertRaises(exceptions.ConfigValidationError):
         config.validate_config(config_dict)
Ejemplo n.º 7
0
 def test_invalid_config(self):
     """An invalid config raises an exception."""
     config_dict = json.loads(PULP_SMASH_CONFIG)
     config_dict['pulp']['auth'] = []
     config_dict['hosts'][0]['hostname'] = ''
     with self.assertRaises(exceptions.ConfigValidationError):
         config.validate_config(config_dict)
Ejemplo n.º 8
0
 def test_config_missing_roles(self):
     """Missing required roles in config raises an exception."""
     config_dict = json.loads(PULP_SMASH_CONFIG)
     for system in config_dict['systems']:
         system['roles'].pop('api', None)
         system['roles'].pop('pulp workers', None)
     with self.assertRaises(exceptions.ConfigValidationError) as err:
         config.validate_config(config_dict)
     self.assertEqual(
         err.exception.error_messages,
         ['The following roles are missing: api, pulp workers'])
Ejemplo n.º 9
0
def settings_validate(ctx):
    """Validate the settings file."""
    path = ctx.obj['load_path']
    if not path:
        _raise_settings_not_found()
    with open(path) as handle:
        config_dict = json.load(handle)
    try:
        config.validate_config(config_dict)
    except exceptions.ConfigValidationError as err:
        raise click.ClickException('{} is invalid: '.format(path) +
                                   err.message) from err
Ejemplo n.º 10
0
 def test_config_missing_roles(self):
     """Missing required roles in config raises an exception."""
     config_dict = json.loads(PULP_SMASH_CONFIG)
     for host in config_dict["hosts"]:
         host["roles"].pop("api", None)
         host["roles"].pop("pulp workers", None)
     with self.assertRaises(exceptions.ConfigValidationError) as err:
         config.validate_config(config_dict)
     self.assertEqual(
         err.exception.message,
         "The following roles are not fulfilled by any hosts: api, pulp workers",
     )
Ejemplo n.º 11
0
def settings_validate(ctx):
    """Validate the settings file."""
    path = ctx.obj['load_path']
    if not path:
        _raise_settings_not_found()
    with open(path) as handle:
        config_dict = json.load(handle)
    try:
        config.validate_config(config_dict)
    except exceptions.ConfigValidationError as err:
        raise click.ClickException(
            '{} is invalid: '.format(path) + err.message
        ) from err
Ejemplo n.º 12
0
 def test_config_missing_roles(self):
     """Missing required roles in config raises an exception."""
     config_dict = json.loads(PULP_SMASH_CONFIG)
     for host in config_dict['hosts']:
         host['roles'].pop('api', None)
         host['roles'].pop('pulp workers', None)
     with self.assertRaises(exceptions.ConfigValidationError) as err:
         config.validate_config(config_dict)
     self.assertEqual(
         err.exception.message,
         'The following roles are not fulfilled by any hosts: api, pulp '
         'workers',
     )
Ejemplo n.º 13
0
 def test_invalid_config(self):
     """An invalid config raises an exception."""
     config_dict = json.loads(PULP_SMASH_CONFIG)
     config_dict['pulp']['auth'] = []
     config_dict['systems'][0]['hostname'] = ''
     with self.assertRaises(exceptions.ConfigValidationError) as err:
         config.validate_config(config_dict)
     self.assertEqual(
         sorted(err.exception.error_messages),
         sorted([
             'Failed to validate config[\'pulp\'][\'auth\'] because [] is too '
             'short.',
             'Failed to validate config[\'systems\'][0][\'hostname\'] because '
             '\'\' is not a \'hostname\'.',
         ]))
Ejemplo n.º 14
0
 def test_valid_config(self):
     """A valid config does not raise an exception."""
     self.assertIsNone(config.validate_config(
         json.loads(PULP_SMASH_CONFIG)))
Ejemplo n.º 15
0
 def test_valid_config(self):
     """A valid config does not raise an exception."""
     self.assertIsNone(
         config.validate_config(json.loads(PULP_SMASH_CONFIG)))