Extra cleanup for install partitions (#108)

This commit is contained in:
Itxaka 2023-08-02 19:11:50 +02:00 committed by GitHub
parent f5f3d3f221
commit 8feaf648e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 41 additions and 1 deletions

View File

@ -98,6 +98,11 @@ func (i *InstallSpec) Sanitize() error {
if extraPartsSizeCheck == 1 && i.Partitions.Persistent.Size == 0 { if extraPartsSizeCheck == 1 && i.Partitions.Persistent.Size == 0 {
return fmt.Errorf("both persistent partition and extra partitions have size set to 0. Only one partition can have its size set to 0 which means that it will take all the available disk space in the device") return fmt.Errorf("both persistent partition and extra partitions have size set to 0. Only one partition can have its size set to 0 which means that it will take all the available disk space in the device")
} }
// Set default labels in case the config from cloud/config overrides this values.
// we need them to be on fixed values, otherwise we wont know where to find things on boot, on reset, etc...
i.Partitions.SetDefaultLabels()
return i.Partitions.SetFirmwarePartitions(i.Firmware, i.PartTable) return i.Partitions.SetFirmwarePartitions(i.Firmware, i.PartTable)
} }
@ -271,6 +276,18 @@ func (ep *ElementalPartitions) SetFirmwarePartitions(firmware string, partTable
return nil return nil
} }
// SetDefaultLabels sets the default labels for oem, state, persistent and recovery partitions.
func (ep *ElementalPartitions) SetDefaultLabels() {
ep.OEM.FilesystemLabel = constants.OEMLabel
ep.OEM.Name = constants.OEMPartName
ep.State.FilesystemLabel = constants.StateLabel
ep.State.Name = constants.StatePartName
ep.Persistent.FilesystemLabel = constants.PersistentLabel
ep.Persistent.Name = constants.PersistentPartName
ep.Recovery.FilesystemLabel = constants.RecoveryLabel
ep.Recovery.Name = constants.RecoveryPartName
}
// NewElementalPartitionsFromList fills an ElementalPartitions instance from given // NewElementalPartitionsFromList fills an ElementalPartitions instance from given
// partitions list. First tries to match partitions by partition label, if not, // partitions list. First tries to match partitions by partition label, if not,
// it tries to match partitions by default filesystem label // it tries to match partitions by default filesystem label

View File

@ -239,7 +239,11 @@ var _ = Describe("Types", Label("types", "config"), func() {
Passive: v1.Image{ Passive: v1.Image{
Source: v1.NewEmptySrc(), Source: v1.NewEmptySrc(),
}, },
Partitions: v1.ElementalPartitions{}, Partitions: v1.ElementalPartitions{
OEM: &v1.Partition{},
Recovery: &v1.Partition{},
Persistent: &v1.Partition{},
},
ExtraPartitions: v1.PartitionList{}, ExtraPartitions: v1.PartitionList{},
} }
}) })
@ -276,6 +280,14 @@ var _ = Describe("Types", Label("types", "config"), func() {
Expect(spec.Partitions.EFI).To(BeNil()) Expect(spec.Partitions.EFI).To(BeNil())
Expect(spec.Partitions.BIOS).ToNot(BeNil()) Expect(spec.Partitions.BIOS).ToNot(BeNil())
Expect(spec.Partitions.BIOS.Flags).To(ContainElement("bios_grub")) Expect(spec.Partitions.BIOS.Flags).To(ContainElement("bios_grub"))
Expect(spec.Partitions.OEM.FilesystemLabel).To(Equal(constants.OEMLabel))
Expect(spec.Partitions.OEM.Name).To(Equal(constants.OEMPartName))
Expect(spec.Partitions.Recovery.FilesystemLabel).To(Equal(constants.RecoveryLabel))
Expect(spec.Partitions.Recovery.Name).To(Equal(constants.RecoveryPartName))
Expect(spec.Partitions.Persistent.FilesystemLabel).To(Equal(constants.PersistentLabel))
Expect(spec.Partitions.Persistent.Name).To(Equal(constants.PersistentPartName))
Expect(spec.Partitions.State.FilesystemLabel).To(Equal(constants.StateLabel))
Expect(spec.Partitions.State.Name).To(Equal(constants.StatePartName))
}) })
It("fills the spec with defaults (EFI)", func() { It("fills the spec with defaults (EFI)", func() {
spec.Active.Source = v1.NewFileSrc("/tmp") spec.Active.Source = v1.NewFileSrc("/tmp")
@ -295,6 +307,14 @@ var _ = Describe("Types", Label("types", "config"), func() {
Expect(spec.Partitions.EFI.Size).To(Equal(constants.EfiSize)) Expect(spec.Partitions.EFI.Size).To(Equal(constants.EfiSize))
Expect(spec.Partitions.EFI.FS).To(Equal(constants.EfiFs)) Expect(spec.Partitions.EFI.FS).To(Equal(constants.EfiFs))
Expect(spec.Partitions.EFI.Flags).To(ContainElement("esp")) Expect(spec.Partitions.EFI.Flags).To(ContainElement("esp"))
Expect(spec.Partitions.OEM.FilesystemLabel).To(Equal(constants.OEMLabel))
Expect(spec.Partitions.OEM.Name).To(Equal(constants.OEMPartName))
Expect(spec.Partitions.Recovery.FilesystemLabel).To(Equal(constants.RecoveryLabel))
Expect(spec.Partitions.Recovery.Name).To(Equal(constants.RecoveryPartName))
Expect(spec.Partitions.Persistent.FilesystemLabel).To(Equal(constants.PersistentLabel))
Expect(spec.Partitions.Persistent.Name).To(Equal(constants.PersistentPartName))
Expect(spec.Partitions.State.FilesystemLabel).To(Equal(constants.StateLabel))
Expect(spec.Partitions.State.Name).To(Equal(constants.StatePartName))
}) })
It("Cannot add extra partitions with 0 size + persistent with 0 size", func() { It("Cannot add extra partitions with 0 size + persistent with 0 size", func() {
spec.Active.Source = v1.NewFileSrc("/tmp") spec.Active.Source = v1.NewFileSrc("/tmp")
@ -381,6 +401,9 @@ var _ = Describe("Types", Label("types", "config"), func() {
spec.Partitions.State = &v1.Partition{ spec.Partitions.State = &v1.Partition{
MountPoint: "/tmp", MountPoint: "/tmp",
} }
spec.Partitions.OEM = &v1.Partition{}
spec.Partitions.Recovery = &v1.Partition{}
spec.Partitions.Persistent = &v1.Partition{}
err := spec.Sanitize() err := spec.Sanitize()
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
}) })