Beispiel #1
0
def _lvm_conf_configured():
    """
    Return True if lvm local conf is using the correct version or is private,
    otherwise return False.
    """
    try:
        cur_conf = confmeta.read_metadata(_LVMLOCAL_CUR)
    except EnvironmentError as e:
        if e.errno != errno.ENOENT:
            raise
        return False

    if cur_conf.revision is None:
        # LVM installs a default lvmlocal.conf with documention for the "local"
        # section. We backup this file and replace it with vdsm version.
        _log(
            "WARNING: LVM local configuration: %s is not based on vdsm "
            "configuration", _LVMLOCAL_CUR)
        return False

    vdsm_conf = confmeta.read_metadata(_LVMLOCAL_VDSM)
    if cur_conf.private:
        # Using private configuration is ok
        _log("Using private lvm local configuration: %s", _LVMLOCAL_CUR)
        if cur_conf.revision < vdsm_conf.revision:
            # But using outated configuration is not. The admin should update
            # the file revision to avoid this warning.
            _log(
                "WARNING: Installed lvm local configuration: %s was based "
                "on an older revision. Please update the file form vdsm "
                "configuration: %s", _LVMLOCAL_CUR, _LVMLOCAL_VDSM)
        return True

    return vdsm_conf.revision == cur_conf.revision
Beispiel #2
0
Datei: lvm.py Projekt: EdDev/vdsm
def _lvm_conf_configured():
    """
    Return True if lvm local conf is using the correct version or is private,
    otherwise return False.
    """
    try:
        cur_conf = confmeta.read_metadata(_LVMLOCAL_CUR)
    except EnvironmentError as e:
        if e.errno != errno.ENOENT:
            raise
        return False

    if cur_conf.revision is None:
        # LVM installs a default lvmlocal.conf with documention for the "local"
        # section. We backup this file and replace it with vdsm version.
        _log("WARNING: LVM local configuration: %s is not based on vdsm "
             "configuration", _LVMLOCAL_CUR)
        return False

    vdsm_conf = confmeta.read_metadata(_LVMLOCAL_VDSM)
    if cur_conf.private:
        # Using private configuration is ok
        _log("Using private lvm local configuration: %s", _LVMLOCAL_CUR)
        if cur_conf.revision < vdsm_conf.revision:
            # But using outated configuration is not. The admin should update
            # the file revision to avoid this warning.
            _log("WARNING: Installed lvm local configuration: %s was based "
                 "on an older revision. Please update the file form vdsm "
                 "configuration: %s", _LVMLOCAL_CUR, _LVMLOCAL_VDSM)
        return True

    return vdsm_conf.revision == cur_conf.revision
 def test_must_start_with_metadata(self):
     data = (b"There is no metadata here\n"
             b"#REVISION: 1\n"
             b"#PRIVATE: YES\n")
     with temporaryPath(data=data) as path:
         md = confmeta.read_metadata(path)
         self.assertEqual(md.revision, None)
         self.assertEqual(md.private, False)
 def test_ignore_file_body(self):
     data = (b"#REVISION: 1\n"
             b"#PRIVATE: YES\n"
             b"REVISION: 2\n"
             b"PRIVATE: NO\n")
     with temporaryPath(data=data) as path:
         md = confmeta.read_metadata(path)
         self.assertEqual(md.revision, 1)
         self.assertEqual(md.private, True)
 def test_order_does_not_matter(self):
     data = (b"# A comment\n"
             b"#PRIVATE: NO\n"
             b"# Another comment\n"
             b"#REVISION: 1\n"
             b"# Last comment\n"
             b"Actual file data...")
     with temporaryPath(data=data) as path:
         md = confmeta.read_metadata(path)
         self.assertEqual(md.revision, 1)
         self.assertEqual(md.private, False)
 def test_no_metadata(self):
     data = (b"# There is no metadata here\n" b"Actual file data...\n")
     with temporaryPath(data=data) as path:
         md = confmeta.read_metadata(path)
         self.assertEqual(md.revision, None)
         self.assertEqual(md.private, False)
 def test_empty(self):
     data = b""
     with temporaryPath(data=data) as path:
         md = confmeta.read_metadata(path)
         self.assertEqual(md.revision, None)
         self.assertEqual(md.private, False)
 def test_no_revision_owned_by_sysadmin(self):
     data = b"#PRIVATE: YES\n"
     with temporaryPath(data=data) as path:
         md = confmeta.read_metadata(path)
         self.assertEqual(md.revision, None)
         self.assertEqual(md.private, True)
 def test_no_revision(self):
     data = b"#PRIVATE: NO\n"
     with temporaryPath(data=data) as path:
         md = confmeta.read_metadata(path)
         self.assertEqual(md.revision, None)
         self.assertEqual(md.private, False)
 def test_owned_by_sysadmin(self):
     data = (b"#REVISION: 1\n" b"#PRIVATE: YES\n")
     with temporaryPath(data=data) as path:
         md = confmeta.read_metadata(path)
         self.assertEqual(md.revision, 1)
         self.assertEqual(md.private, True)
 def test_owned_by_vdsm_by_default(self):
     data = b"#REVISION: 1\n"
     with temporaryPath(data=data) as path:
         md = confmeta.read_metadata(path)
         self.assertEqual(md.revision, 1)
         self.assertEqual(md.private, False)
 def test_invalid_private(self):
     data = (b"#REVISION: 1\n" b"#PRIVATE:\n")
     with temporaryPath(data=data) as path:
         with self.assertRaises(ValueError):
             confmeta.read_metadata(path)
 def test_invalid_revision(self):
     data = (b"#REVISION: invalid\n")
     with temporaryPath(data=data) as path:
         with self.assertRaises(ValueError):
             confmeta.read_metadata(path)
 def test_extra_whitespace(self):
     data = (b"#REVISION:  1   \n" b"#PRIVATE:   NO  \n")
     with temporaryPath(data=data) as path:
         md = confmeta.read_metadata(path)
         self.assertEqual(md.revision, 1)
         self.assertEqual(md.private, False)
 def test_last_value_win(self):
     data = (b"#REVISION: 4\n" b"#REVISION: 3\n" b"#PRIVATE: YES\n")
     with temporaryPath(data=data) as path:
         md = confmeta.read_metadata(path)
         self.assertEqual(md.revision, 3)
         self.assertEqual(md.private, True)
 def test_ignore_unknonwn_tags(self):
     data = (b"#UNKNOWN: VALUE\n" b"#REVISION: 1\n" b"#PRIVATE: YES\n")
     with temporaryPath(data=data) as path:
         md = confmeta.read_metadata(path)
         self.assertEqual(md.revision, 1)
         self.assertEqual(md.private, True)