示例#1
0
    def test_create(self):

        environment = Environment(True, ProbeMode_NONE, TargetMode_DIRECT)
        s = Storage(environment)

        devicegraph = Devicegraph(s)

        sda = Disk.create(devicegraph, "/dev/sda")
        sda.set_region(Region(0, 1000000, 512))

        gpt = sda.create_partition_table(PtType_GPT)
        sda1 = gpt.create_partition("/dev/sda1", Region(2048, 4096, 512),
                                    PartitionType_PRIMARY)
        ext4 = sda1.create_filesystem(FsType_EXT4)

        self.assertEqual(devicegraph.empty(), False)
        self.assertEqual(devicegraph.num_devices(), 4)

        sda.set_size(2**64 - 512)
        self.assertEqual(sda.get_size(), 2**64 - 512)

        sda1.set_region(Region(2048, 4096, 512))
        self.assertEqual(sda1.get_region().get_start(), 2048)
        self.assertEqual(sda1.get_region().get_length(), 4096)
        self.assertEqual(sda1.get_region().get_block_size(), 512)
        self.assertEqual(sda1.get_region(), Region(2048, 4096, 512))

        ext4.set_label("test-label")
        self.assertEqual(ext4.get_label(), "test-label")

        ext4.add_mountpoint("/test1")
        self.assertEqual(ext4.get_mountpoints().size(), 1)
        self.assertEqual(ext4.get_mountpoints()[0], "/test1")
示例#2
0
    def test_create(self):

        environment = Environment(True, ProbeMode_NONE, TargetMode_DIRECT)
        s = Storage(environment)

        devicegraph = Devicegraph(s)

        sda = Disk.create(devicegraph, "/dev/sda")
        gpt = sda.create_partition_table(PtType_GPT)
        sda1 = gpt.create_partition("/dev/sda1", Region(1, 2, 262144), PartitionType_PRIMARY)
        ext4 = sda1.create_filesystem(FsType_EXT4)

        self.assertEqual(devicegraph.empty(), False)
        self.assertEqual(devicegraph.num_devices(), 4)

        sda.set_size_k(2**64 - 1)
        self.assertEqual(sda.get_size_k(), 2**64 - 1)

        sda1.set_region(Region(1, 2, 262144))
        self.assertEqual(sda1.get_region().get_start(), 1)
        self.assertEqual(sda1.get_region().get_length(), 2)
        self.assertEqual(sda1.get_region().get_block_size(), 262144)
        self.assertEqual(sda1.get_region(), Region(1, 2, 262144))

        ext4.set_label("test-label")
        self.assertEqual(ext4.get_label(), "test-label")

        ext4.add_mountpoint("/test1")
        self.assertEqual(ext4.get_mountpoints().size(), 1)
        self.assertEqual(ext4.get_mountpoints()[0], "/test1")
示例#3
0
    def test_str(self):

        environment = Environment(True, ProbeMode_NONE, TargetMode_DIRECT)
        s = Storage(environment)

        devicegraph = Devicegraph(s)
        sda = Disk.create(devicegraph, "/dev/sda")
        gpt = sda.create_partition_table(PtType_GPT)

        self.assertEqual(str(sda)[:32], "Disk sid:42 displayname:/dev/sda")
        self.assertEqual(sda.get_displayname(), "/dev/sda")

        self.assertEqual(str(gpt)[:26], "Gpt sid:43 displayname:gpt")
        self.assertEqual(gpt.get_displayname(), "gpt")
示例#4
0
    def test_str(self):

        environment = Environment(True, ProbeMode_NONE, TargetMode_DIRECT)
        s = Storage(environment)

        devicegraph = Devicegraph(s)
        sda = Disk.create(devicegraph, "/dev/sda")
        gpt = sda.create_partition_table(PtType_GPT)

        self.assertEqual(str(sda)[:32], "Disk sid:42 displayname:/dev/sda")
        self.assertEqual(sda.get_displayname(), "/dev/sda")

        self.assertEqual(str(gpt)[:26], "Gpt sid:43 displayname:gpt")
        self.assertEqual(gpt.get_displayname(), "gpt")
示例#5
0
    def test_create(self):

        environment = Environment(True, ProbeMode_NONE, TargetMode_DIRECT)
        s = Storage(environment)

        devicegraph = Devicegraph(s)

        sda = Disk.create(devicegraph, "/dev/sda")

        gpt = sda.create_partition_table(PtType_GPT)

        sda1 = gpt.create_partition("/dev/sda1", PRIMARY)
        sda2 = gpt.create_partition("/dev/sda2", PRIMARY)

        ext4 = sda1.create_filesystem(EXT4)
        swap = sda2.create_filesystem(SWAP)

        self.assertEqual(devicegraph.num_devices(), 6)
        self.assertEqual(devicegraph.num_holders(), 5)
示例#6
0
    def test_sid(self):

        environment = Environment(True, ProbeMode_NONE, TargetMode_DIRECT)
        s = Storage(environment)

        devicegraph = Devicegraph(s)
        sda = Disk.create(devicegraph, "/dev/sda")
        gpt = sda.create_partition_table(PtType_GPT)

        self.assertEqual(sda.get_sid(), 42)
        self.assertEqual(gpt.get_sid(), 43)

        self.assertEqual(devicegraph.find_device(42).get_sid(), 42)

        self.assertRaises(DeviceNotFound, lambda: devicegraph.find_device(99))

        self.assertEqual(devicegraph.find_holder(42, 43).get_source_sid(), 42)
        self.assertEqual(devicegraph.find_holder(42, 43).get_target_sid(), 43)

        self.assertRaises(HolderNotFound, lambda: devicegraph.find_holder(99, 99))
示例#7
0
    def test_sid(self):

        environment = Environment(True, ProbeMode_NONE, TargetMode_DIRECT)
        s = Storage(environment)

        devicegraph = Devicegraph(s)
        sda = Disk.create(devicegraph, "/dev/sda")
        gpt = sda.create_partition_table(PtType_GPT)

        self.assertEqual(sda.get_sid(), 42)
        self.assertEqual(gpt.get_sid(), 43)

        self.assertEqual(devicegraph.find_device(42).get_sid(), 42)

        self.assertRaises(DeviceNotFound, lambda: devicegraph.find_device(99))

        self.assertEqual(devicegraph.find_holder(42, 43).get_source_sid(), 42)
        self.assertEqual(devicegraph.find_holder(42, 43).get_target_sid(), 43)

        self.assertRaises(HolderNotFound, lambda: devicegraph.find_holder(99, 99))
示例#8
0
    def test_create(self):

        environment = Environment(True, ProbeMode_NONE, TargetMode_DIRECT)
        s = Storage(environment)

        devicegraph = Devicegraph(s)

        sda = Disk.create(devicegraph, "/dev/sda")

        gpt = sda.create_partition_table(PtType_GPT)

        sda1 = gpt.create_partition("/dev/sda1", Region(0, 100, 262144),
                                    PartitionType_PRIMARY)
        sda2 = gpt.create_partition("/dev/sda2", Region(100, 100, 262144),
                                    PartitionType_PRIMARY)

        ext4 = sda1.create_filesystem(FsType_EXT4)
        swap = sda2.create_filesystem(FsType_SWAP)

        self.assertEqual(devicegraph.num_devices(), 6)
        self.assertEqual(devicegraph.num_holders(), 5)
示例#9
0
    def test_create(self):

        environment = Environment(True, ProbeMode_NONE, TargetMode_DIRECT)
        s = Storage(environment)

        devicegraph = Devicegraph(s)

        sda = Disk.create(devicegraph, "/dev/sda")
        sda.set_region(Region(0, 1000000, 512))

        gpt = sda.create_partition_table(PtType_GPT)
        sda1 = gpt.create_partition("/dev/sda1", Region(2048, 4096, 512),
                                    PartitionType_PRIMARY)
        ext4 = sda1.create_blk_filesystem(FsType_EXT4)
        mount_point = ext4.create_mount_point("/test")
        mount_point.set_mount_options(VectorString(["ro"]))

        self.assertEqual(devicegraph.empty(), False)
        self.assertEqual(devicegraph.num_devices(), 5)

        sda.set_size(2**64 - 512)
        self.assertEqual(sda.get_size(), 2**64 - 512)

        sda1.set_region(Region(2048, 4096, 512))
        self.assertEqual(sda1.get_region().get_start(), 2048)
        self.assertEqual(sda1.get_region().get_length(), 4096)
        self.assertEqual(sda1.get_region().get_block_size(), 512)
        self.assertEqual(sda1.get_region(), Region(2048, 4096, 512))

        ext4.set_label("test-label")
        self.assertEqual(ext4.get_label(), "test-label")

        self.assertEqual(mount_point.get_mount_options().size(), 1)
        self.assertEqual(mount_point.get_mount_options()[0], "ro")

        self.assertTrue(devicegraph.used_features() & UF_EXT4)
        self.assertFalse(devicegraph.used_features() & UF_BTRFS)

        self.assertTrue(LIBSTORAGE_NG_VERSION_STRING)
示例#10
0
    def test_create(self):

        environment = Environment(True, ProbeMode_NONE, TargetMode_DIRECT)
        s = Storage(environment)

        devicegraph = Devicegraph(s)

        sda = Disk.create(devicegraph, "/dev/sda")
        sda.set_region(Region(0, 1000000, 512))

        gpt = sda.create_partition_table(PtType_GPT)
        sda1 = gpt.create_partition("/dev/sda1", Region(2048, 4096, 512), PartitionType_PRIMARY)
        ext4 = sda1.create_blk_filesystem(FsType_EXT4)

        self.assertEqual(devicegraph.empty(), False)
        self.assertEqual(devicegraph.num_devices(), 4)

        sda.set_size(2**64 - 512)
        self.assertEqual(sda.get_size(), 2**64 - 512)

        sda1.set_region(Region(2048, 4096, 512))
        self.assertEqual(sda1.get_region().get_start(), 2048)
        self.assertEqual(sda1.get_region().get_length(), 4096)
        self.assertEqual(sda1.get_region().get_block_size(), 512)
        self.assertEqual(sda1.get_region(), Region(2048, 4096, 512))

        ext4.set_label("test-label")
        self.assertEqual(ext4.get_label(), "test-label")

        ext4.add_mountpoint("/test1")
        self.assertEqual(ext4.get_mountpoints().size(), 1)
        self.assertEqual(ext4.get_mountpoints()[0], "/test1")

        self.assertTrue(devicegraph.used_features() & UF_EXT4)
        self.assertFalse(devicegraph.used_features() & UF_BTRFS)

        self.assertTrue(LIBSTORAGE_NG_VERSION_STRING)
示例#11
0
#!/usr/bin/python

from storage import Devicegraph, Disk, BlkDevice, GPT, EXT4, SWAP


devicegraph = Devicegraph()

sda = Disk.create(devicegraph, "/dev/sda")

gpt = sda.create_partition_table(GPT)

sda1 = gpt.create_partition("/dev/sda1")
sda2 = gpt.create_partition("/dev/sda2")

ext4 = sda1.create_filesystem(EXT4)
swap = sda2.create_filesystem(SWAP)

print devicegraph


print "partitions on gpt:"
for partition in gpt.get_partitions():
  print "  %s %s" % (partition, partition.get_number())
print


print "descendants of sda:"
for device in sda.get_descendants(False):
  print "  %s" % device
print
示例#12
0
#!/usr/bin/python

from storage import Devicegraph, Disk, BlkDevice, Region, PtType_GPT, EXT4, SWAP, PRIMARY


devicegraph = Devicegraph()

sda = Disk.create(devicegraph, "/dev/sda")

gpt = sda.create_partition_table(PtType_GPT)

sda1 = gpt.create_partition("/dev/sda1", Region(0, 1000, 512), PRIMARY)
sda2 = gpt.create_partition("/dev/sda2", Region(1000, 1000, 512), PRIMARY)

ext4 = sda1.create_filesystem(EXT4)
swap = sda2.create_filesystem(SWAP)

print devicegraph


print "partitions on gpt:"
for partition in gpt.get_partitions():
  print "  %s %s" % (partition, partition.get_number())
print


print "descendants of sda:"
for device in sda.get_descendants(False):
  print "  %s" % device
print