Skip to content

Commit 3032e69

Browse files
committed
many: simplify changes
1 parent 838d03f commit 3032e69

6 files changed

Lines changed: 9 additions & 48 deletions

File tree

boot/assets.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -509,8 +509,6 @@ type TrustedAssetsUpdateObserver struct {
509509
modeenvLocked bool
510510
}
511511

512-
var _ gadget.ContentUpdateObserver = (*TrustedAssetsUpdateObserver)(nil)
513-
514512
func doUpdateBootEntry(efiBl bootloader.UefiBootloader, updatedAssets []string) error {
515513
description, assetPath, optionalData, err := efiBl.ParametersForEfiLoadOption(updatedAssets)
516514
if err != nil {
@@ -541,10 +539,6 @@ func (o *TrustedAssetsUpdateObserver) UpdateBootEntry() error {
541539
return doUpdateBootEntry(efiBl, updatedAssets)
542540
}
543541

544-
func (o *TrustedAssetsUpdateObserver) UpdateApplied() error {
545-
return o.UpdateBootEntry()
546-
}
547-
548542
// Done must be called when done with the observer if any of the
549543
// gadget.ContenUpdateObserver methods might have been called.
550544
func (o *TrustedAssetsUpdateObserver) Done() {

gadget/mountedfilesystem_test.go

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -969,21 +969,6 @@ func (m *mockContentUpdateObserver) Observe(op gadget.ContentOperation, partRole
969969
return gadget.ChangeApply, nil
970970
}
971971

972-
func (m *mockContentUpdateObserver) BeforeWrite() error {
973-
return nil
974-
}
975-
976-
func (m *mockContentUpdateObserver) Canceled() error {
977-
return nil
978-
}
979-
980-
func (m *mockContentUpdateObserver) UpdateApplied() error {
981-
return nil
982-
}
983-
984-
func (m *mockContentUpdateObserver) Done() {
985-
}
986-
987972
func (s *mountedfilesystemTestSuite) TestMountedUpdaterBackupSimple(c *C) {
988973
// some data for the gadget
989974
gdWritten := []gadgetData{

gadget/update.go

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,6 @@ type ContentUpdateObserver interface {
124124
// Canceled is called when the update has been canceled, or if changes
125125
// were written and the update has been reverted.
126126
Canceled() error
127-
// UpdateApplied is called after a successful update has been written to
128-
// disk and before the update is considered complete.
129-
UpdateApplied() error
130-
// Done is called when the observer is no longer needed.
131-
Done()
132127
}
133128

134129
// searchVolumeWithTraitsAndMatchParts searches for a disk matching the given
@@ -1790,9 +1785,6 @@ func updateLocationForStructure(structureLocations map[string]map[int]StructureL
17901785

17911786
func applyUpdates(structureLocations map[string]map[int]StructureLocation, new GadgetData, updates []updatePair, rollbackDir string, observer ContentUpdateObserver) error {
17921787
updaters := make([]Updater, len(updates))
1793-
if observer != nil {
1794-
defer observer.Done()
1795-
}
17961788

17971789
for i, one := range updates {
17981790
loc, err := updateLocationForStructure(structureLocations, one.to)
@@ -1850,15 +1842,8 @@ func applyUpdates(structureLocations map[string]map[int]StructureLocation, new G
18501842
}
18511843

18521844
if updateErr == nil {
1853-
if observer == nil {
1854-
// all good, updates applied successfully
1855-
return nil
1856-
}
1857-
if err := observer.UpdateApplied(); err == nil {
1858-
return nil
1859-
} else {
1860-
updateErr = fmt.Errorf("cannot observe applied update: %v", err)
1861-
}
1845+
// all good, updates applied successfully
1846+
return nil
18621847
}
18631848

18641849
logger.Noticef("cannot update gadget: %v", updateErr)

gadget/update_test.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -694,13 +694,6 @@ func (m *mockUpdateProcessObserver) Canceled() error {
694694
return m.canceledErr
695695
}
696696

697-
func (m *mockUpdateProcessObserver) UpdateApplied() error {
698-
return nil
699-
}
700-
701-
func (m *mockUpdateProcessObserver) Done() {
702-
}
703-
704697
func (u *updateTestSuite) TestUpdateApplyHappy(c *C) {
705698
oldData, newData, rollbackDir := u.updateDataSet(c)
706699
// update two structs

overlord/devicestate/devicestate_gadget_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,6 @@ func (s *deviceMgrGadgetSuite) testUpdateGadgetSimple(c *C, grade string, encryp
325325
c.Check(observer, IsNil)
326326
} else {
327327
c.Check(observer, NotNil)
328-
defer observer.Done()
329328
// expecting a very specific observer
330329
trustedUpdateObserver, ok := observer.(*boot.TrustedAssetsUpdateObserver)
331330
c.Assert(ok, Equals, true, Commentf("unexpected type: %T", observer))
@@ -348,7 +347,6 @@ func (s *deviceMgrGadgetSuite) testUpdateGadgetSimple(c *C, grade string, encryp
348347
c.Assert(m.CurrentTrustedRecoveryBootAssets, NotNil)
349348
c.Check(m.CurrentTrustedRecoveryBootAssets["trusted-asset"], DeepEquals,
350349
[]string{"88478d8afe6925b348b9cd00085f3535959fde7029a64d7841b031acc39415c690796757afab1852a9e09da913a0151b"})
351-
c.Assert(observer.UpdateApplied(), IsNil)
352350
}
353351
return nil
354352
})

overlord/devicestate/handlers_gadget.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ func (m *DeviceManager) doUpdateGadgetAssets(t *state.Task, _ *tomb.Tomb) error
198198
}
199199
if err == nil {
200200
updateObserver = observeTrustedBootAssets
201+
defer observeTrustedBootAssets.Done()
201202
}
202203

203204
// do not release the state lock, the update observer may
@@ -208,12 +209,17 @@ func (m *DeviceManager) doUpdateGadgetAssets(t *state.Task, _ *tomb.Tomb) error
208209
return err
209210
}
210211

212+
// After a gadget-update, some bootloaders may need to reconfigure values.
211213
if updated, err := boot.ReconfigureRuntimeBootConfig(groundDeviceCtx); err != nil {
212214
return fmt.Errorf("cannot reconfigure runtime boot config: %v", err)
213215
} else if updated {
214216
t.Logf("reconfigured runtime boot config")
215217
}
216-
return nil
218+
219+
if updateObserver == nil {
220+
return nil
221+
}
222+
return observeTrustedBootAssets.UpdateBootEntry()
217223
}()
218224
if err != nil {
219225
if err == gadget.ErrNoUpdate {

0 commit comments

Comments
 (0)