示例#1
0
class DialogModel(Model):
    topic = DialogTopic

    answerfile_sections = fields.JSON()
    actor = fields.String()
    details = fields.Nullable(fields.String())
    key = fields.Nullable(fields.String())
def test_not_required_field_types():
    fields.Nullable(fields.String())._validate_model_value(None, 'test-value')
    fields.Nullable(fields.String())._validate_model_value(None, 'test-value')
    fields.Nullable(fields.String())._validate_builtin_value(
        None, 'test-value')
    fields.Nullable(fields.String())._validate_builtin_value(
        None, 'test-value')
示例#3
0
class RestrictedPCIDevice(Model):
    """
    Model to represent known restrictions of the given PCI devices.


    pci_id - unsupported pci_ids. It has the following
        structure: {Vendor}:{Device}:{SVendor}:{SDevice}, where all these 4
        parameters are numeric ids (see shell command spci -vmmkn). If SVendor
        and SDevice fields do not exist, then pci_id has the following structure:
        {Vendor}:{Device}.
    driver_name - the name of restricted driver
    device_name - the name of restricted device
    supported_{rhel_version} - 1 is supported on the given RHEL, 0 - not
        supported
    available_{rhel_version} - 1 is available on the given RHEL, 0 - not
        available. it could be the driver is available, but not supported
    comments - the field for comments
    """
    topic = SystemInfoTopic

    pci_id = fields.Nullable(fields.String())
    driver_name = fields.Nullable(fields.String())
    device_name = fields.Nullable(fields.String())
    available_rhel7 = fields.Integer()
    supported_rhel7 = fields.Integer()
    available_rhel8 = fields.Integer()
    supported_rhel8 = fields.Integer()
    available_rhel9 = fields.Integer()
    supported_rhel9 = fields.Integer()
    comment = fields.Nullable(fields.String())
示例#4
0
class OpenSshConfig(Model):
    """
    OpenSSH server configuration.

    This model contains the first effective configuration option specified
    in the configuration file or a list of all the options specified
    in all the conditional blocks used throughout the file.
    """
    topic = SystemInfoTopic

    permit_root_login = fields.List(fields.Model(OpenSshPermitRootLogin))
    """ All PermitRootLogin directives. """
    use_privilege_separation = fields.Nullable(fields.StringEnum(['sandbox',
                                                                  'yes',
                                                                  'no']))
    """ Value of the UsePrivilegeSeparation directive, if present. Removed in RHEL 8. """
    protocol = fields.Nullable(fields.String())
    """ Value of the Protocols directive, if present. Removed in RHEL 8. """
    ciphers = fields.Nullable(fields.String())
    """ Value of the Ciphers directive, if present. Ciphers separated by comma. """
    macs = fields.Nullable(fields.String())
    """ Value of the MACs directive, if present. """
    modified = fields.Boolean(default=False)
    """ True if the configuration file was modified. """
    deprecated_directives = fields.List(fields.String())
    """ Configuration directives that were deprecated in the new version of openssh. """
def test_list_field():
    with pytest.raises(fields.ModelViolationError):
        fields.List(fields.String())._validate_builtin_value(
            'something', 'test-value')

    with pytest.raises(fields.ModelViolationError):
        fields.List(fields.String())._convert_to_model(None, 'test-value')

    fields.Nullable(fields.List(fields.String()))._convert_to_model(
        None, 'test-value')

    with pytest.raises(fields.ModelViolationError):
        fields.List(fields.String())._convert_from_model(None, 'test-value')

    fields.Nullable(fields.List(fields.String()))._convert_from_model(
        None, 'test-value')

    with pytest.raises(fields.ModelViolationError):
        fields.Nullable(fields.List(
            fields.Integer(), minimum=1))._validate_builtin_value([],
                                                                  'test-value')

    with pytest.raises(fields.ModelViolationError):
        fields.Nullable(fields.List(
            fields.Integer(), minimum=1))._validate_model_value([],
                                                                'test-value')

    fields.List(fields.Integer(),
                minimum=1)._validate_builtin_value([1], 'test-value')
    fields.List(fields.Integer(),
                minimum=1)._validate_builtin_value([1, 2], 'test-value')
    fields.List(fields.Integer(),
                minimum=1)._validate_model_value([1], 'test-value')
    fields.List(fields.Integer(),
                minimum=1)._validate_model_value([1, 2], 'test-value')

    with pytest.raises(fields.ModelViolationError):
        fields.List(fields.Integer(), minimum=1,
                    maximum=1)._validate_builtin_value([1, 2], 'test-value')

    with pytest.raises(fields.ModelViolationError):
        fields.List(fields.Integer(), minimum=1,
                    maximum=1)._validate_model_value([1, 2], 'test-value')

    fields.List(fields.Integer(),
                maximum=2)._validate_builtin_value([1], 'test-value')
    fields.List(fields.Integer(),
                maximum=2)._validate_builtin_value([1, 2], 'test-value')

    fields.List(fields.Integer(),
                maximum=2)._validate_model_value([1], 'test-value')
    fields.List(fields.Integer(),
                maximum=2)._validate_model_value([1, 2], 'test-value')

    with pytest.raises(fields.ModelViolationError):
        fields.List(fields.Integer(),
                    maximum=3)._validate_builtin_value([1, 2, 3, 4],
                                                       'test-value')
示例#6
0
class RepositoryData(Model):
    topic = SystemInfoTopic

    name = fields.String()
    baseurl = fields.Nullable(fields.String())
    metalink = fields.Nullable(fields.String())
    mirrorlist = fields.Nullable(fields.String())
    enabled = fields.Boolean(default=True)
    additional_fields = fields.Nullable(fields.String())
示例#7
0
class OSRelease(Model):
    topic = SystemInfoTopic

    release_id = fields.String()
    name = fields.String()
    pretty_name = fields.String()
    version = fields.String()
    version_id = fields.String()
    variant = fields.Nullable(fields.String())  # isn't specified on some systems
    variant_id = fields.Nullable(fields.String())  # same as above
示例#8
0
class PCIDevice(Model):
    topic = SystemInfoTopic

    slot = fields.String()
    dev_cls = fields.String()
    vendor = fields.String()
    name = fields.String()
    subsystem_vendor = fields.String()
    subsystem_name = fields.String()
    rev = fields.Nullable(fields.String())
    progif = fields.Nullable(fields.String())
示例#9
0
class RPM(Model):
    topic = SystemInfoTopic
    name = fields.String()
    epoch = fields.String()
    packager = fields.String()
    version = fields.String()
    release = fields.String()
    arch = fields.String()
    pgpsig = fields.String()
    repository = fields.Nullable(fields.String())
    module = fields.Nullable(fields.String())
    stream = fields.Nullable(fields.String())
def test_datetime_field():
    with pytest.raises(fields.ModelViolationError):
        fields.DateTime()._convert_to_model('something', 'test-value')

    with pytest.raises(fields.ModelViolationError):
        fields.DateTime()._convert_to_model(None, 'test-value')

    fields.Nullable(fields.DateTime())._convert_to_model(None, 'test-value')

    with pytest.raises(fields.ModelViolationError):
        fields.DateTime()._convert_from_model(None, 'test-value')

    fields.Nullable(fields.DateTime())._convert_from_model(None, 'test-value')
def test_nested_field():
    with pytest.raises(fields.ModelViolationError):
        fields.Model(BasicModel)._convert_to_model('something', 'test-value')
    with pytest.raises(fields.ModelViolationError):
        fields.Model(BasicModel)._convert_to_model(None, 'test-value')
    fields.Nullable(fields.Model(BasicModel))._convert_to_model(
        None, 'test-value')
示例#12
0
class RootSubdirectory(Model):
    """
    Representation of a single root subdirectory. Can be expanded as needed.
    """
    topic = SystemFactsTopic
    name = fields.String()
    target = fields.Nullable(fields.String())  # if it's a link
示例#13
0
class VsftpdFacts(Model):
    topic = SystemInfoTopic

    default_config_hash = fields.Nullable(fields.String())
    """SHA1 hash of the /etc/vsftpd/vsftpd.conf file, if it exists, None otherwise"""
    configs = fields.List(fields.Model(VsftpdConfig))
    """List of vsftpd configuration files"""
示例#14
0
class PCIDevice(Model):
    """
    Model to represent a PCI Device.

    There is the following match between model parameters and
    the fields of the output of a shell command `lspci -vmmk`

    slot - 'Slot',
    dev_cls - 'Class',
    vendor - 'Vendor',
    name - 'Device',
    subsystem_vendor - 'SVendor',
    subsystem_name - 'SDevice',
    physical_slot - 'PhySlot',
    rev - 'Rev',
    progif - 'ProgIf',
    driver - 'Driver',
    modules - 'Module',
    numa_node - 'NUMANode',

    pci_id - represents the numeric identification of the device, formed as
        string concatenating of the numeric device identifiers for fields
        Vendor, Device, SVendor, SDevice (output
        of a shell command `lspci -vmmkn`) with the `:` delimiter.
        For example:
        one device from output of `lspci -vmmkn` is:

        ```
        Slot:	04:00.0
        Class:	0880
        Vendor:	8086
        Device:	15bf
        SVendor:	17aa
        SDevice:	2279
        Rev:	01
        Driver:	thunderbolt
        Module:	thunderbolt
        ```

        then
        pci_id == "8086:15bf:17aa:2279"
    """
    topic = SystemInfoTopic

    slot = fields.String()
    dev_cls = fields.String()
    vendor = fields.String()
    name = fields.String()
    subsystem_vendor = fields.Nullable(fields.String())
    subsystem_name = fields.Nullable(fields.String())
    physical_slot = fields.Nullable(fields.String())
    rev = fields.Nullable(fields.String())
    progif = fields.Nullable(fields.String())
    driver = fields.Nullable(fields.String())
    modules = fields.Nullable(fields.List(fields.String()))
    numa_node = fields.Nullable(fields.String())
    pci_id = fields.String()
示例#15
0
class OpenSshPermitRootLogin(Model):
    topic = SystemInfoTopic

    value = fields.StringEnum(['yes', 'prohibit-password',
                               'forced-commands-only', 'no'])
    """ Value of a PermitRootLogin directive. """
    in_match = fields.Nullable(fields.List(fields.String()))
    """ Criteria of Match blocks the PermitRootLogin directive occured in, if any. """
class SpamassassinFacts(Model):
    topic = SystemInfoTopic

    spamc_ssl_argument = fields.Nullable(fields.String())
    """
    SSL version specified by the --ssl option in the spamc config file, or None
    if no value is given.
    """

    spamd_ssl_version = fields.Nullable(fields.String())
    """
    SSL version specified by the --ssl-version in the spamassassin sysconfig file,
    or None if no value is given.
    """

    service_overriden = fields.Boolean()
    """
示例#17
0
class ErrorModel(Model):
    topic = ErrorTopic

    message = fields.String()
    severity = fields.StringEnum(choices=ErrorSeverity.ALLOWED_VALUES, default=ErrorSeverity.ERROR)
    details = fields.Nullable(fields.String())
    actor = fields.String()
    time = fields.DateTime()
示例#18
0
class MemoryInfo(Model):
    """
    Represents information about available memory (KiB)
    """

    topic = SystemFactsTopic

    mem_total = fields.Nullable(fields.Integer())
    """
示例#19
0
class SELinuxFacts(Model):
    topic = SystemFactsTopic

    runtime_mode = fields.Nullable(
        fields.StringEnum(['enforcing', 'permissive']))
    static_mode = fields.StringEnum(['enforcing', 'permissive', 'disabled'])
    enabled = fields.Boolean()
    policy = fields.StringEnum(['targeted', 'minimum', 'mls'])
    mls_enabled = fields.Boolean()
示例#20
0
class VsftpdConfig(Model):
    """
    Model representing some aspects of a vsftpd configuration file.

    The attributes representing the state of configuration options are nullable, so that
    they can represent the real state of the option in the file: if an option is set to "YES"
    in the configuration file, the corresponding attribute is set to True; if the option
    is set to NO, the attribute is set to False; if the option is not present in the config
    file at all, the attribute is set to None.
    """
    topic = SystemInfoTopic

    path = fields.String()
    """Path to the vsftpd configuration file"""
    strict_ssl_read_eof = fields.Nullable(fields.Boolean())
    """Represents the state of the strict_ssl_read_eof option in the config file"""
    tcp_wrappers = fields.Nullable(fields.Boolean())
    """Represents the state of the tcp_wrappers option in the config file"""
class KernelCmdlineArg(Model):
    """
    Single kernel command line parameter with/without a value

    When produced alone, represents a parameter to include in RHEL-8 kernel cmdline.
    """
    topic = SystemInfoTopic

    key = fields.String()
    value = fields.Nullable(fields.String())
示例#22
0
class OpenSshConfig(Model):
    """
    OpenSSH server configuration.

    This model contains the first effective configuration option specified
    in the configuration file or a list of all the options specified
    in all the conditional blocks used throughout the file.
    """
    topic = SystemInfoTopic

    permit_root_login = fields.List(fields.Model(OpenSshPermitRootLogin))
    use_privilege_separation = fields.Nullable(fields.StringEnum(['sandbox',
                                                                  'yes',
                                                                  'no']))
    protocol = fields.Nullable(fields.String())
    ciphers = fields.Nullable(fields.String())
    macs = fields.Nullable(fields.String())

    modified = fields.Nullable(fields.Boolean())
示例#23
0
class PkgManagerInfo(Model):
    """
    Package manager (yum/dnf) related info

    We expect to have only one single message of this kind produced
    """
    topic = SystemInfoTopic

    etc_releasever = fields.Nullable(fields.String())
    """
示例#24
0
class Report(Model):
    topic = SystemInfoTopic

    severity = fields.StringEnum(choices=['Info', 'Warning', 'Error'])

    result = fields.StringEnum(
        choices=['Not Applicable', 'Fixed', 'Pass', 'Fail'])

    summary = fields.String()
    details = fields.String()
    solutions = fields.Nullable(fields.String())
示例#25
0
class SELinux(Model):
    topic = SystemInfoTopic

    # FIXME: fixme properly regarding the issue:
    # # https://github.com/oamg/leapp-repository/issues/20
    runtime_mode = fields.Nullable(
        fields.StringEnum(['enforcing', 'permissive']))
    static_mode = fields.StringEnum(['enforcing', 'permissive', 'disabled'])
    enabled = fields.Boolean()
    policy = fields.String()
    mls_enabled = fields.Boolean()
示例#26
0
class UpgradeDracutModule(Model):
    """
    This model is used to influence the leapp upgrade initram disk generation by allowing to
    include dracut modules specified by this message.
    """
    topic = BootPrepTopic

    name = fields.String()
    """ Name of the dracut module that should be added (--add option of dracut) """

    module_path = fields.Nullable(fields.String(default=None))
    """
示例#27
0
class PCIDevice(Model):
    topic = SystemInfoTopic

    slot = fields.String()
    dev_cls = fields.String()
    vendor = fields.String()
    name = fields.String()
    subsystem_vendor = fields.Nullable(fields.String())
    subsystem_name = fields.Nullable(fields.String())
    physical_slot = fields.Nullable(fields.String())
    rev = fields.Nullable(fields.String())
    progif = fields.Nullable(fields.String())
    driver = fields.Nullable(fields.String())
    modules = fields.Nullable(fields.List(fields.String()))
    numa_node = fields.Nullable(fields.String())
class CopyFile(Model):
    """
    Specify a file that should be copied from the host to the target userspace
    container
    """
    topic = TransactionTopic

    src = fields.String()
    """
    Cannonical path to the file (on the host) that should be copied
    """

    dst = fields.Nullable(fields.String())
    """
示例#29
0
class RHSMInfo(Model):
    """
    Subscription-manager details required for the inplace upgrade.
    """
    topic = RHSMTopic

    release = fields.Nullable(fields.String())
    """ Release the subscription-manager is set to. """
    attached_skus = fields.List(fields.String(), default=[])
    """ SKUs the current system is attached to. """
    available_repos = fields.List(fields.String(), default=[])
    """ Repositories that are available to the current system through the subscription-manager. """
    enabled_repos = fields.List(fields.String(), default=[])
    """ Repositories that are enabled on the current system through the subscription-manager. """
    existing_product_certificates = fields.List(fields.String(), default=[])
    """ Product certificates that are currently installed on the system. """
示例#30
0
class CPUInfo(Model):
    """
    The model represents information about CPUs.

    The model currently doesn't represent all information about cpus could
    provide on the machine. Just part of them, in case any other attributes
    will be neded, the model can be extended.

    The provided info is aggregated - like from lscpu command. Expecting all
    CPUs are same on the machine (at least for now).
    """

    topic = SystemFactsTopic

    machine_type = fields.Nullable(fields.Integer())
    """