示例#1
0
def test_yaml_encoded_cases(fpath):
    with open(fpath) as stream:
        loaded_yaml = yaml.safe_load(stream)
        assert 'files' in loaded_yaml
        assert 'expected' in loaded_yaml
        fs = filesystems.DictBackedFilesystem(loaded_yaml['files'])
        expected = model.OperatingSystem(
            model.distro_for(loaded_yaml['expected']['distro']),
            model.Version(loaded_yaml['expected']['major'],
                          loaded_yaml['expected']['minor']))

    inspector = inspection._linux_inspector(fs)
    actual = inspector.inspect()
    assert expected == actual
示例#2
0
 def match(
     self, fs: boot_inspect.system.filesystems.Filesystem
 ) -> model.OperatingSystem:
     """Returns the OperatingSystem that is identified."""
     etc_os_rel = {}
     if fs.is_file('/etc/os-release'):
         etc_os_rel = _parse_config_file(fs.read_utf8('/etc/os-release'))
     if 'ID' in etc_os_rel:
         matches = self._name_matcher.fullmatch(
             etc_os_rel['ID']) is not None
     else:
         matches = self._legacy and self._legacy.matches(fs)
     if matches:
         return model.OperatingSystem(
             distro=self.distro,
             version=self._get_version(etc_os_rel, fs),
         )
示例#3
0
def _from_nt_version(variant: str, major_nt: int, minor_nt: int,
                     product_name: str) -> model.OperatingSystem:
    major, minor = None, None
    nt_version = major_nt, minor_nt
    if _client_pattern.search(variant):
        major, minor = _client_versions.get(nt_version, (None, None))
    elif _server_pattern.search(variant):
        if nt_version in _server_versions:
            major, minor = _server_versions.get(nt_version, (None, None))
        elif nt_version == (10, 0):
            if '2016' in product_name:
                major, minor = '2016', ''
            elif '2019' in product_name:
                major, minor = '2019', ''

    if major is not None and minor is not None:
        return model.OperatingSystem(model.Distro.WINDOWS,
                                     model.Version(major, minor))
示例#4
0
  def test_allow_empty_minor_version(self):
    inspection_results = model.InspectionResults(
      device="/dev/sdb",
      os=model.OperatingSystem(
        distro=model.Distro.UBUNTU,
        version=model.Version(major="14", ),
      ),
      architecture=model.Architecture.x64,
    )

    expected = {
      "device": "/dev/sdb",
      "os": {
        "distro": "ubuntu",
        "version": {
          "major": "14",
          "minor": "",
        }
      },
      "architecture": "x64",
    }
    actual = json.dumps(inspection_results, cls=model.ModelJSONEncoder)
    assert expected == json.loads(actual)
示例#5
0
  def test_happy_case(self):
    inspection_results = model.InspectionResults(
      device="/dev/sdb",
      os=model.OperatingSystem(
        distro=model.Distro.WINDOWS,
        version=model.Version(major="8", minor="1"),
      ),
      architecture=model.Architecture.x86,
    )

    expected = {
      "device": "/dev/sdb",
      "os": {
        "distro": "windows",
        "version": {
          "major": "8",
          "minor": "1",
        }
      },
      "architecture": "x86",
    }
    actual = json.dumps(inspection_results, cls=model.ModelJSONEncoder)
    assert expected == json.loads(actual)
示例#6
0
 def inspect(self) -> model.OperatingSystem:
   if self._is_windows():
     return model.OperatingSystem(
       model.Distro.WINDOWS,
       self._get_version(),
     )
示例#7
0
def windows(major, minor=''):
    return model.OperatingSystem(distro=model.Distro.WINDOWS,
                                 version=model.Version(major, minor))