示例#1
0
 def test_blkid_no_cache_uses_no_cache(self, m_subp):
     """blkid should turn off cache if disable_cache is true."""
     m_subp.return_value = (self.blkid_out.format(**self.ids), "")
     self.assertEqual(self._get_expected(), util.blkid(disable_cache=True))
     m_subp.assert_called_with(["blkid", "-o", "full", "-c", "/dev/null"],
                               capture=True,
                               decode="replace")
示例#2
0
def get_md():
    rbx_data = None
    devices = [
        dev
        for dev, bdata in util.blkid().items()
        if bdata.get('LABEL', '').upper() == 'CLOUDMD'
    ]
    for device in devices:
        try:
            rbx_data = util.mount_cb(
                device=device,
                callback=read_user_data_callback,
                mtype=['vfat', 'fat']
            )
            if rbx_data:
                break
        except OSError as err:
            if err.errno != errno.ENOENT:
                raise
        except util.MountFailedError:
            util.logexc(LOG, "Failed to mount %s when looking for user "
                             "data", device)
    if not rbx_data:
        util.logexc(LOG, "Failed to load metadata and userdata")
        return False
    return rbx_data
示例#3
0
 def test_blkid_no_cache_uses_no_cache(self, m_subp):
     """blkid should turn off cache if disable_cache is true."""
     m_subp.return_value = (
         self.blkid_out.format(**self.ids), "")
     self.assertEqual(self._get_expected(),
                      util.blkid(disable_cache=True))
     m_subp.assert_called_with(["blkid", "-o", "full", "-c", "/dev/null"],
                               capture=True, decode="replace")
示例#4
0
def get_ibm_platform():
    """Return a tuple (Platform, path)

    If this is Not IBM cloud, then the return value is (None, None).
    An instance in provisioning mode is considered running on IBM cloud."""
    label_mdata = "METADATA"
    label_cfg2 = "CONFIG-2"
    not_found = (None, None)

    if not _is_xen():
        return not_found

    # fslabels contains only the first entry with a given label.
    fslabels = {}
    try:
        devs = util.blkid()
    except subp.ProcessExecutionError as e:
        LOG.warning("Failed to run blkid: %s", e)
        return (None, None)

    for dev in sorted(devs.keys()):
        data = devs[dev]
        label = data.get("LABEL", "").upper()
        uuid = data.get("UUID", "").upper()
        if label not in (label_mdata, label_cfg2):
            continue
        if label in fslabels:
            LOG.warning(
                "Duplicate fslabel '%s'. existing=%s current=%s",
                label,
                fslabels[label],
                data,
            )
            continue
        if label == label_cfg2 and uuid != IBM_CONFIG_UUID:
            LOG.debug(
                "Skipping %s with LABEL=%s due to uuid != %s: %s",
                dev,
                label,
                uuid,
                data,
            )
            continue
        fslabels[label] = data

    metadata_path = fslabels.get(label_mdata, {}).get("DEVNAME")
    cfg2_path = fslabels.get(label_cfg2, {}).get("DEVNAME")

    if cfg2_path:
        return (Platforms.OS_CODE, cfg2_path)
    elif metadata_path:
        if _is_ibm_provisioning():
            return (Platforms.TEMPLATE_PROVISIONING_METADATA, metadata_path)
        else:
            return (Platforms.TEMPLATE_LIVE_METADATA, metadata_path)
    elif _is_ibm_provisioning():
        return (Platforms.TEMPLATE_PROVISIONING_NODATA, None)
    return not_found
示例#5
0
 def test_functional_blkid(self, m_subp):
     m_subp.return_value = (self.blkid_out.format(**self.ids), "")
     self.assertEqual(self._get_expected(), util.blkid())
     m_subp.assert_called_with(["blkid", "-o", "full"],
                               capture=True,
                               decode="replace")
示例#6
0
 def test_functional_blkid(self, m_subp):
     m_subp.return_value = (
         self.blkid_out.format(**self.ids), "")
     self.assertEqual(self._get_expected(), util.blkid())
     m_subp.assert_called_with(["blkid", "-o", "full"], capture=True,
                               decode="replace")