예제 #1
0
    def test_get_partition_number_primary(self, _get_cached_partitions,
                                          _get_cached_info):
        _get_cached_info.return_value = {"partition table": "msdos"}
        _get_cached_partitions.return_value = {}

        partition_data = ("/dev/sda", "primary", "0s", "10s")
        self.assertEqual(partitioned._get_partition_number(*partition_data),
                         "1")

        _get_cached_partitions.return_value = {
            "1": {
                "number": "1",
                "type": "primary",
                "size": "10s",
                "start": "0s",
                "end": "10s",
            }
        }
        self.assertEqual(partitioned._get_partition_number(*partition_data),
                         "1")

        partition_data = ("/dev/sda", "primary", "0s", "10s")
        self.assertEqual(partitioned._get_partition_number(*partition_data),
                         "1")

        _get_cached_partitions.return_value = {
            "1": {
                "number": "1",
                "type": "primary",
                "start": "0s",
                "end": "10s"
            },
            "2": {
                "number": "2",
                "type": "primary",
                "start": "11s",
                "end": "20s"
            },
            "3": {
                "number": "3",
                "type": "primary",
                "start": "21s",
                "end": "30s"
            },
            "4": {
                "number": "4",
                "type": "primary",
                "start": "31s",
                "end": "40s"
            },
        }

        partition_data = ("/dev/sda", "primary", "41s", "50s")
        self.assertRaises(partitioned.EnumerateException,
                          partitioned._get_partition_number, *partition_data)

        _get_cached_info.return_value = {"partition table": "gpt"}
        partition_data = ("/dev/sda", "primary", "41s", "50s")
        self.assertEqual(partitioned._get_partition_number(*partition_data),
                         "5")
예제 #2
0
    def test_get_partition_number_primary(self, _get_cached_partitions,
                                          _get_cached_info):
        _get_cached_info.return_value = {'partition table': 'msdos'}
        _get_cached_partitions.return_value = {}

        partition_data = ('/dev/sda', 'primary', '0s', '10s')
        self.assertEqual(partitioned._get_partition_number(*partition_data),
                         '1')

        _get_cached_partitions.return_value = {
            '1': {
                'number': '1',
                'type': 'primary',
                'size': '10s',
                'start': '0s',
                'end': '10s',
            }
        }
        self.assertEqual(partitioned._get_partition_number(*partition_data),
                         '1')

        partition_data = ('/dev/sda', 'primary', '0s', '10s')
        self.assertEqual(partitioned._get_partition_number(*partition_data),
                         '1')

        _get_cached_partitions.return_value = {
            '1': {
                'number': '1',
                'type': 'primary',
                'start': '0s',
                'end': '10s',
            },
            '2': {
                'number': '2',
                'type': 'primary',
                'start': '11s',
                'end': '20s',
            },
            '3': {
                'number': '3',
                'type': 'primary',
                'start': '21s',
                'end': '30s',
            },
            '4': {
                'number': '4',
                'type': 'primary',
                'start': '31s',
                'end': '40s',
            },
        }

        partition_data = ('/dev/sda', 'primary', '41s', '50s')
        self.assertRaises(partitioned.EnumerateException,
                          partitioned._get_partition_number, *partition_data)

        _get_cached_info.return_value = {'partition table': 'gpt'}
        partition_data = ('/dev/sda', 'primary', '41s', '50s')
        self.assertEqual(partitioned._get_partition_number(*partition_data),
                         '5')
예제 #3
0
    def test_get_partition_number_logial(self, _get_cached_partitions,
                                         _get_cached_info):
        _get_cached_info.return_value = {"partition table": "msdos"}
        _get_cached_partitions.return_value = {}
        partition_data = ("/dev/sda", "logical", "0s", "10s")
        self.assertRaises(partitioned.EnumerateException,
                          partitioned._get_partition_number, *partition_data)

        _get_cached_partitions.return_value = {
            "1": {
                "number": "1",
                "type": "primary",
                "start": "0s",
                "end": "10s"
            },
        }
        partition_data = ("/dev/sda", "logical", "12s", "15s")
        self.assertRaises(partitioned.EnumerateException,
                          partitioned._get_partition_number, *partition_data)

        _get_cached_partitions.return_value = {
            "1": {
                "number": "1",
                "type": "primary",
                "start": "0s",
                "end": "10s"
            },
            "2": {
                "number": "2",
                "type": "extended",
                "start": "11s",
                "end": "20s"
            },
        }
        self.assertEqual(partitioned._get_partition_number(*partition_data),
                         "5")

        _get_cached_partitions.return_value = {
            "1": {
                "number": "1",
                "type": "primary",
                "start": "0s",
                "end": "10s"
            },
            "2": {
                "number": "2",
                "type": "extended",
                "start": "11s",
                "end": "20s"
            },
            "5": {
                "number": "5",
                "type": "logical",
                "start": "12s",
                "end": "15s"
            },
        }
        self.assertEqual(partitioned._get_partition_number(*partition_data),
                         "5")

        partition_data = ("/dev/sda", "logical", "16s", "19s")
        self.assertEqual(partitioned._get_partition_number(*partition_data),
                         "6")
예제 #4
0
    def test_get_partition_number_logial(self, _get_cached_partitions,
                                         _get_cached_info):
        _get_cached_info.return_value = {'partition table': 'msdos'}
        _get_cached_partitions.return_value = {}
        partition_data = ('/dev/sda', 'logical', '0s', '10s')
        self.assertRaises(partitioned.EnumerateException,
                          partitioned._get_partition_number, *partition_data)

        _get_cached_partitions.return_value = {
            '1': {
                'number': '1',
                'type': 'primary',
                'start': '0s',
                'end': '10s',
            },
        }
        partition_data = ('/dev/sda', 'logical', '12s', '15s')
        self.assertRaises(partitioned.EnumerateException,
                          partitioned._get_partition_number, *partition_data)

        _get_cached_partitions.return_value = {
            '1': {
                'number': '1',
                'type': 'primary',
                'start': '0s',
                'end': '10s',
            },
            '2': {
                'number': '2',
                'type': 'extended',
                'start': '11s',
                'end': '20s',
            },
        }
        self.assertEqual(partitioned._get_partition_number(*partition_data),
                         '5')

        _get_cached_partitions.return_value = {
            '1': {
                'number': '1',
                'type': 'primary',
                'start': '0s',
                'end': '10s',
            },
            '2': {
                'number': '2',
                'type': 'extended',
                'start': '11s',
                'end': '20s',
            },
            '5': {
                'number': '5',
                'type': 'logical',
                'start': '12s',
                'end': '15s',
            },
        }
        self.assertEqual(partitioned._get_partition_number(*partition_data),
                         '5')

        partition_data = ('/dev/sda', 'logical', '16s', '19s')
        self.assertEqual(partitioned._get_partition_number(*partition_data),
                         '6')