示例#1
0
 def test_from_device_file_no_device_file(self, context, tmpdir):
     filename = tmpdir.join("test")
     filename.ensure(file=True)
     with pytest.raises(ValueError) as excinfo:
         Device.from_device_file(context, str(filename))
     message = "not a device file: {0!r}".format(str(filename))
     assert str(excinfo.value) == message
示例#2
0
 def test_from_device_file_no_device_file(self, context, tmpdir):
     filename = tmpdir.join('test')
     filename.ensure(file=True)
     with pytest.raises(ValueError) as excinfo:
         Device.from_device_file(context, str(filename))
     message = 'not a device file: {0!r}'.format(str(filename))
     assert str(excinfo.value) == message
示例#3
0
    def _hp_ld_to_lsm_vol(hp_ld, pool_id, sys_id, ctrl_num, array_num, hp_ld_name):
        """
        raises DeviceNotFoundError
        """
        ld_num = hp_ld_name[len("Logical Drive: ") :]
        vpd83 = hp_ld["Unique Identifier"].lower()
        # No document or command output indicate block size
        # of volume. So we try to read from linux kernel, if failed
        # try 512 and roughly calculate the sector count.
        device = Device.from_device_file(_CONTEXT, hp_ld["Disk Name"])
        vol_name = "%s: /dev/%s" % (hp_ld_name, device.sys_name)
        attributes = device.attributes
        try:
            block_size = attributes.asint("queue/logical_block_size")
            num_of_blocks = attributes.asint("size")
        except (KeyError, UnicodeDecodeError, ValueError):
            block_size = 512
            num_of_blocks = int(_hp_size_to_lsm(hp_ld["Size"]) / block_size)

        if "Failed" in hp_ld["Status"]:
            admin_status = Volume.ADMIN_STATE_DISABLED
        else:
            admin_status = Volume.ADMIN_STATE_ENABLED
        plugin_data = "%s:%s:%s" % (ctrl_num, array_num, ld_num)

        # HP SmartArray does not allow disabling volume.
        return Volume(vpd83, vol_name, vpd83, block_size, num_of_blocks, admin_status, sys_id, pool_id, plugin_data)
示例#4
0
    def _arcconf_ld_to_lsm_vol(arcconf_ld, pool_id, sys_id, ctrl_num,
                               array_num, arcconf_ld_name):
        """
        raises DeviceNotFoundError
        """
        ld_num = arcconf_ld['logicalDriveID']
        vpd83 = str(arcconf_ld['volumeUniqueID']).lower()

        block_size = arcconf_ld['BlockSize']
        num_of_blocks = int(arcconf_ld['dataSpace']) / int(block_size)
        vol_name = arcconf_ld_name

        if len(vpd83) > 0:
            blk_paths = LocalDisk.vpd83_search(vpd83)
            if len(blk_paths) > 0:
                blk_path = blk_paths[0]
                vol_name += ": %s" % " ".join(blk_paths)
                device = Device.from_device_file(_CONTEXT, blk_path)
                attributes = device.attributes
                try:
                    block_size = attributes.asint("BlockSize")
                    num_of_blocks = attributes.asint("dataSpace")
                except (KeyError, UnicodeDecodeError, ValueError):
                    pass

        if int(arcconf_ld['state']) > 2:
            admin_status = Volume.ADMIN_STATE_DISABLED
        else:
            admin_status = Volume.ADMIN_STATE_ENABLED
        plugin_data = "%s:%s:%s" % (ctrl_num, array_num, ld_num)

        volume_id = array_num
        return Volume(volume_id, vol_name, vpd83, block_size, num_of_blocks,
                      admin_status, sys_id, pool_id, plugin_data)
示例#5
0
 def test_from_device_file_links(self, context, device_data):
     if not device_data.device_links:
         pytest.skip("no device links")
     for link in device_data.device_links:
         link = os.path.join(context.device_path, link)
         device = Device.from_device_file(context, link)
         assert device.device_path == device_data.device_path
         assert link in device.device_links
示例#6
0
 def test_from_device_file_links(self, context, device_data):
     if not device_data.device_links:
         pytest.skip('no device links')
     for link in device_data.device_links:
         link = os.path.join(context.device_path, link)
         device = Device.from_device_file(context, link)
         assert device.device_path == device_data.device_path
         assert link in device.device_links
示例#7
0
    def _hp_ld_to_lsm_vol(hp_ld, pool_id, sys_id, ctrl_num, array_num,
                          hp_ld_name):
        """
        raises DeviceNotFoundError
        """
        ld_num = hp_ld_name[len("Logical Drive: "):]
        vpd83 = hp_ld['Unique Identifier'].lower()
        # No document or command output indicate block size
        # of volume. So we try to read from linux kernel, if failed
        # try 512 and roughly calculate the sector count.
        block_size = 512
        num_of_blocks = int(_hp_size_to_lsm(hp_ld['Size']) / block_size)
        vol_name = hp_ld_name

        if len(vpd83) > 0:
            blk_paths = LocalDisk.vpd83_search(vpd83)
            if len(blk_paths) > 0:
                blk_path = blk_paths[0]
                vol_name += ": %s" % " ".join(blk_paths)
                device = Device.from_device_file(_CONTEXT, blk_path)
                attributes = device.attributes
                try:
                    block_size = attributes.asint("queue/logical_block_size")
                    num_of_blocks = attributes.asint("size")
                except (KeyError, UnicodeDecodeError, ValueError):
                    pass

        if 'Failed' in hp_ld['Status']:
            admin_status = Volume.ADMIN_STATE_DISABLED
        else:
            admin_status = Volume.ADMIN_STATE_ENABLED
        plugin_data = "%s:%s:%s" % (ctrl_num, array_num, ld_num)

        # HP SmartArray does not allow disabling volume.
        return Volume(
            vpd83, vol_name, vpd83, block_size, num_of_blocks,
            admin_status, sys_id, pool_id, plugin_data)
示例#8
0
 def test_from_device_file_non_existing(self, context, tmpdir):
     filename = tmpdir.join("test")
     assert not tmpdir.check(file=True)
     with pytest.raises(EnvironmentError) as excinfo:
         Device.from_device_file(context, str(filename))
     pytest.assert_env_error(excinfo.value, errno.ENOENT, str(filename))
示例#9
0
 def test_from_device_file(self, context, device_data):
     if not device_data.device_node:
         pytest.skip("no device file")
     device = Device.from_device_file(context, device_data.device_node)
     assert device.device_node == device_data.device_node
     assert device.device_path == device_data.device_path
示例#10
0
 def test_from_device_file_non_existing(self, context, tmpdir):
     filename = tmpdir.join('test')
     assert not tmpdir.check(file=True)
     with pytest.raises(EnvironmentError) as excinfo:
         Device.from_device_file(context, str(filename))
     pytest.assert_env_error(excinfo.value, errno.ENOENT, str(filename))
示例#11
0
 def test_from_device_file(self, context, device_data):
     if not device_data.device_node:
         pytest.skip('no device file')
     device = Device.from_device_file(context, device_data.device_node)
     assert device.device_node == device_data.device_node
     assert device.device_path == device_data.device_path