def test_calculate_overprovision(self):
        '''When calculated space is higher than available space, raise an exception.'''
        vg_size = 20 * 10**6  # 20 mb drive
        vg_available = 10  # 10 bytes available
        size_str = '80%'

        vg = VolumeGroup(None, size=vg_size, available_size=vg_available)

        with pytest.raises(error.NotEnoughStorage):
            ApplyNodeStorage.calculate_bytes(size_str=size_str, context=vg)
    def test_calculate_G_label(self):
        '''Convert gigabyte labels to x * 10^9 bytes.'''
        size_str = '15G'
        drive_size = 20 * 10**9
        drive = BlockDevice(None, size=drive_size, available_size=drive_size)

        calc_size = ApplyNodeStorage.calculate_bytes(
            size_str=size_str, context=drive)

        assert calc_size == 15 * 10**9
    def test_calculate_TiB_label(self):
        '''Convert tebibyte labels to x * 2^40 bytes.'''
        size_str = '15TiB'
        drive_size = 20 * 2**40
        drive = BlockDevice(None, size=drive_size, available_size=drive_size)

        calc_size = ApplyNodeStorage.calculate_bytes(
            size_str=size_str, context=drive)

        assert calc_size == 15 * 2**40
    def test_calculate_TB_label(self):
        '''Convert terabyte labels to x * 10^12 bytes.'''
        size_str = '15TB'
        drive_size = 20 * 1000 * 1000 * 1000 * 1000
        drive = BlockDevice(None, size=drive_size, available_size=drive_size)

        calc_size = ApplyNodeStorage.calculate_bytes(size_str=size_str,
                                                     context=drive)

        assert calc_size == 15 * 1000 * 1000 * 1000 * 1000
    def test_calculate_min_label(self):
        '''Adding the min marker '>' should provision all available space.'''
        vg_size = 20 * 10**6  # 20 mb drive
        vg_available = 15 * 10**6
        size_str = '>10%'

        vg = VolumeGroup(None, size=vg_size, available_size=vg_available)

        calc_size = ApplyNodeStorage.calculate_bytes(
            size_str=size_str, context=vg)

        assert calc_size == vg_available - ApplyNodeStorage.PART_TABLE_RESERVATION
    def test_calculate_percent_vg(self):
        '''Convert a percent of total blockdev space to explicit byte count.'''
        vg_size = 20 * 10**6  # 20 mb drive
        lv_size = math.floor(.2 * vg_size)  # calculate 20% of drive size
        size_str = '20%'

        vg = VolumeGroup(None, size=vg_size, available_size=vg_size)

        calc_size = ApplyNodeStorage.calculate_bytes(
            size_str=size_str, context=vg)

        assert calc_size == lv_size
    def test_calculate_percent_blockdev(self):
        '''Convert a percent of total blockdev space to explicit byte count.'''
        drive_size = 20 * 10**6  # 20 mb drive
        part_size = math.floor(.2 * drive_size)  # calculate 20% of drive size
        size_str = '20%'

        drive = BlockDevice(None, size=drive_size, available_size=drive_size)

        calc_size = ApplyNodeStorage.calculate_bytes(
            size_str=size_str, context=drive)

        assert calc_size == part_size