Skip to content

Commit 4ce4905

Browse files
committed
TMP: Hardlink sfdisk to iterate against failing tests
1 parent e910d63 commit 4ce4905

File tree

1 file changed

+33
-33
lines changed

1 file changed

+33
-33
lines changed

internal/exec/stages/disks/partitions.go

+33-33
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ import (
3434
"github.com/coreos/ignition/v2/config/v3_5_experimental/types"
3535
"github.com/coreos/ignition/v2/internal/distro"
3636
"github.com/coreos/ignition/v2/internal/exec/util"
37-
"github.com/coreos/ignition/v2/internal/sgdisk"
37+
"github.com/coreos/ignition/v2/internal/sfdisk"
3838
iutil "github.com/coreos/ignition/v2/internal/util"
3939
)
4040

4141
var (
42-
ErrBadSgdiskOutput = errors.New("sgdisk had unexpected output")
42+
ErrBadsfdiskOutput = errors.New("sfdisk had unexpected output")
4343
)
4444

4545
// createPartitions creates the partitions described in config.Storage.Disks.
@@ -75,7 +75,7 @@ func (s stage) createPartitions(config types.Config) error {
7575

7676
// partitionMatches determines if the existing partition matches the spec given. See doc/operator notes for what
7777
// what it means for an existing partition to match the spec. spec must have non-zero Start and Size.
78-
func partitionMatches(existing util.PartitionInfo, spec sgdisk.Partition) error {
78+
func partitionMatches(existing util.PartitionInfo, spec sfdisk.Partition) error {
7979
if err := partitionMatchesCommon(existing, spec); err != nil {
8080
return err
8181
}
@@ -87,13 +87,13 @@ func partitionMatches(existing util.PartitionInfo, spec sgdisk.Partition) error
8787

8888
// partitionMatchesResize returns if the existing partition should be resized by evaluating if
8989
// `resize`field is true and partition matches in all respects except size.
90-
func partitionMatchesResize(existing util.PartitionInfo, spec sgdisk.Partition) bool {
90+
func partitionMatchesResize(existing util.PartitionInfo, spec sfdisk.Partition) bool {
9191
return cutil.IsTrue(spec.Resize) && partitionMatchesCommon(existing, spec) == nil
9292
}
9393

9494
// partitionMatchesCommon handles the common tests (excluding the partition size) to determine
9595
// if the existing partition matches the spec given.
96-
func partitionMatchesCommon(existing util.PartitionInfo, spec sgdisk.Partition) error {
96+
func partitionMatchesCommon(existing util.PartitionInfo, spec sfdisk.Partition) error {
9797
if spec.Number != existing.Number {
9898
return fmt.Errorf("partition numbers did not match (specified %d, got %d). This should not happen, please file a bug.", spec.Number, existing.Number)
9999
}
@@ -113,7 +113,7 @@ func partitionMatchesCommon(existing util.PartitionInfo, spec sgdisk.Partition)
113113
}
114114

115115
// partitionShouldBeInspected returns if the partition has zeroes that need to be resolved to sectors.
116-
func partitionShouldBeInspected(part sgdisk.Partition) bool {
116+
func partitionShouldBeInspected(part sfdisk.Partition) bool {
117117
if part.Number == 0 {
118118
return false
119119
}
@@ -131,19 +131,19 @@ func convertMiBToSectors(mib *int, sectorSize int) *int64 {
131131
}
132132

133133
// getRealStartAndSize returns a map of partition numbers to a struct that contains what their real start
134-
// and end sector should be. It runs sgdisk --pretend to determine what the partitions would look like if
134+
// and end sector should be. It runs sfdisk --pretend to determine what the partitions would look like if
135135
// everything specified were to be (re)created.
136-
func (s stage) getRealStartAndSize(dev types.Disk, devAlias string, diskInfo util.DiskInfo) ([]sgdisk.Partition, error) {
137-
partitions := []sgdisk.Partition{}
136+
func (s stage) getRealStartAndSize(dev types.Disk, devAlias string, diskInfo util.DiskInfo) ([]sfdisk.Partition, error) {
137+
partitions := []sfdisk.Partition{}
138138
for _, cpart := range dev.Partitions {
139-
partitions = append(partitions, sgdisk.Partition{
139+
partitions = append(partitions, sfdisk.Partition{
140140
Partition: cpart,
141141
StartSector: convertMiBToSectors(cpart.StartMiB, diskInfo.LogicalSectorSize),
142142
SizeInSectors: convertMiBToSectors(cpart.SizeMiB, diskInfo.LogicalSectorSize),
143143
})
144144
}
145145

146-
op := sgdisk.Begin(s.Logger, devAlias)
146+
op := sfdisk.Begin(s.Logger, devAlias)
147147
for _, part := range partitions {
148148
if info, exists := diskInfo.GetPartition(part.Number); exists {
149149
// delete all existing partitions
@@ -157,7 +157,7 @@ func (s stage) getRealStartAndSize(dev types.Disk, devAlias string, diskInfo uti
157157
}
158158
}
159159
if partitionShouldExist(part) {
160-
// Clear the label. sgdisk doesn't escape control characters. This makes parsing easier
160+
// Clear the label. sfdisk doesn't escape control characters. This makes parsing easier
161161
part.Label = nil
162162
op.CreatePartition(part)
163163
}
@@ -177,12 +177,12 @@ func (s stage) getRealStartAndSize(dev types.Disk, devAlias string, diskInfo uti
177177
return nil, err
178178
}
179179

180-
realDimensions, err := parseSgdiskPretend(output, partitionsToInspect)
180+
realDimensions, err := parsesfdiskPretend(output, partitionsToInspect)
181181
if err != nil {
182182
return nil, err
183183
}
184184

185-
result := []sgdisk.Partition{}
185+
result := []sfdisk.Partition{}
186186
for _, part := range partitions {
187187
if dims, ok := realDimensions[part.Number]; ok {
188188
if part.StartSector != nil {
@@ -197,7 +197,7 @@ func (s stage) getRealStartAndSize(dev types.Disk, devAlias string, diskInfo uti
197197
return result, nil
198198
}
199199

200-
type sgdiskOutput struct {
200+
type sfdiskOutput struct {
201201
start int64
202202
size int64
203203
}
@@ -213,17 +213,17 @@ func parseLine(r *regexp.Regexp, line string) (int64, error) {
213213
case 2:
214214
return strconv.ParseInt(matches[1], 10, 64)
215215
default:
216-
return 0, ErrBadSgdiskOutput
216+
return 0, ErrBadsfdiskOutput
217217
}
218218
}
219219

220-
// parseSgdiskPretend parses the output of running sgdisk pretend with --info specified for each partition
221-
// number specified in partitionNumbers. E.g. if paritionNumbers is [1,4,5], it is expected that the sgdisk
222-
// output was from running `sgdisk --pretend <commands> --info=1 --info=4 --info=5`. It assumes the the
220+
// parsesfdiskPretend parses the output of running sfdisk pretend with --info specified for each partition
221+
// number specified in partitionNumbers. E.g. if paritionNumbers is [1,4,5], it is expected that the sfdisk
222+
// output was from running `sfdisk --pretend <commands> --info=1 --info=4 --info=5`. It assumes the the
223223
// partition labels are well behaved (i.e. contain no control characters). It returns a list of partitions
224-
// matching the partition numbers specified, but with the start and size information as determined by sgdisk.
225-
// The partition numbers need to passed in because sgdisk includes them in its output.
226-
func parseSgdiskPretend(sgdiskOut string, partitionNumbers []int) (map[int]sgdiskOutput, error) {
224+
// matching the partition numbers specified, but with the start and size information as determined by sfdisk.
225+
// The partition numbers need to passed in because sfdisk includes them in its output.
226+
func parsesfdiskPretend(sfdiskOut string, partitionNumbers []int) (map[int]sfdiskOutput, error) {
227227
if len(partitionNumbers) == 0 {
228228
return nil, nil
229229
}
@@ -235,12 +235,12 @@ func parseSgdiskPretend(sgdiskOut string, partitionNumbers []int) (map[int]sgdis
235235
FAIL_ON_START_END = iota
236236
)
237237

238-
output := map[int]sgdiskOutput{}
238+
output := map[int]sfdiskOutput{}
239239
state := START
240-
current := sgdiskOutput{}
240+
current := sfdiskOutput{}
241241
i := 0
242242

243-
lines := strings.Split(sgdiskOut, "\n")
243+
lines := strings.Split(sfdiskOut, "\n")
244244
for _, line := range lines {
245245
switch state {
246246
case START:
@@ -264,29 +264,29 @@ func parseSgdiskPretend(sgdiskOut string, partitionNumbers []int) (map[int]sgdis
264264
if i == len(partitionNumbers) {
265265
state = FAIL_ON_START_END
266266
} else {
267-
current = sgdiskOutput{}
267+
current = sfdiskOutput{}
268268
state = START
269269
}
270270
}
271271
case FAIL_ON_START_END:
272272
if len(startRegex.FindStringSubmatch(line)) != 0 ||
273273
len(endRegex.FindStringSubmatch(line)) != 0 {
274-
return nil, ErrBadSgdiskOutput
274+
return nil, ErrBadsfdiskOutput
275275
}
276276
}
277277
}
278278

279279
if state != FAIL_ON_START_END {
280280
// We stopped parsing in the middle of a info block. Something is wrong
281-
return nil, ErrBadSgdiskOutput
281+
return nil, ErrBadsfdiskOutput
282282
}
283283

284284
return output, nil
285285
}
286286

287287
// partitionShouldExist returns whether a bool is indicating if a partition should exist or not.
288288
// nil (unspecified in json) is treated the same as true.
289-
func partitionShouldExist(part sgdisk.Partition) bool {
289+
func partitionShouldExist(part sfdisk.Partition) bool {
290290
return !cutil.IsFalse(part.ShouldExist)
291291
}
292292

@@ -438,14 +438,14 @@ func (s stage) partitionDisk(dev types.Disk, devAlias string) error {
438438
return fmt.Errorf("refusing to operate on directly active disk %q", devAlias)
439439
}
440440
if cutil.IsTrue(dev.WipeTable) {
441-
op := sgdisk.Begin(s.Logger, devAlias)
441+
op := sfdisk.Begin(s.Logger, devAlias)
442442
s.Logger.Info("wiping partition table requested on %q", devAlias)
443443
if len(activeParts) > 0 {
444444
return fmt.Errorf("refusing to wipe active disk %q", devAlias)
445445
}
446446
op.WipeTable(true)
447447
if err := op.Commit(); err != nil {
448-
// `sgdisk --zap-all` will exit code 2 if the table was corrupted; retry it
448+
// `sfdisk --zap-all` will exit code 2 if the table was corrupted; retry it
449449
// https://github.com/coreos/fedora-coreos-tracker/issues/1596
450450
s.Logger.Info("potential error encountered while wiping table... retrying")
451451
if err := op.Commit(); err != nil {
@@ -457,7 +457,7 @@ func (s stage) partitionDisk(dev types.Disk, devAlias string) error {
457457
// Ensure all partitions with number 0 are last
458458
sort.Stable(PartitionList(dev.Partitions))
459459

460-
op := sgdisk.Begin(s.Logger, devAlias)
460+
op := sfdisk.Begin(s.Logger, devAlias)
461461

462462
diskInfo, err := s.getPartitionMap(devAlias)
463463
if err != nil {
@@ -542,7 +542,7 @@ func (s stage) partitionDisk(dev types.Disk, devAlias string) error {
542542
return fmt.Errorf("commit failure: %v", err)
543543
}
544544

545-
// In contrast to similar tools, sgdisk does not trigger the update of the
545+
// In contrast to similar tools, sfdisk does not trigger the update of the
546546
// kernel partition table with BLKPG but only uses BLKRRPART which fails
547547
// as soon as one partition of the disk is mounted
548548
if len(activeParts) > 0 {

0 commit comments

Comments
 (0)