Merge lp:~jamesodhunt/snappy/show-upgrade-details into lp:~snappy-dev/snappy/snappy-moved-to-github

Proposed by James Hunt
Status: Work in progress
Proposed branch: lp:~jamesodhunt/snappy/show-upgrade-details
Merge into: lp:~snappy-dev/snappy/snappy-moved-to-github
Diff against target: 114 lines (+76/-0)
1 file modified
snappy/systemimage.go (+76/-0)
To merge this branch: bzr merge lp:~jamesodhunt/snappy/show-upgrade-details
Reviewer Review Type Date Requested Status
Michael Vogt (community) Needs Fixing
Review via email: mp+249053@code.launchpad.net

Description of the change

There will be a follow-on MP to perform additional checks in the upgrader, but given the issues we've had in this area, I think there is value in adding this basic runtime safety check.

* snappy/systemimage.go:
  - showUpgradeDetails(): Display basic debug showing planned upgrade details
    (displayed if SNAPPY_DEBUG=1).
  - checkUpgrade(): Basic test run unconditionally to ensure the upgrade
    revision applied is as expected.

To post a comment you must log in.
Revision history for this message
Michael Vogt (mvo) wrote :

Thanks for this branch.

I added some inline comments. I also get a test failure when I run this branch.

review: Needs Fixing
Revision history for this message
Michael Vogt (mvo) wrote :

I was thinking a little bit about this and I wonder if we could move the verification into cmd_update.go and essentially just verify that for all parts we install. It seems like if we want to verify, why be specific only to the "SystemImagePart". The other benefit this has is that we don't need to create a "SystemImageRepository" inside the "SystemImagePart" (which makes me a bit uneasy and feels like a layering violation). Just a idea.

Revision history for this message
James Hunt (jamesodhunt) :
Revision history for this message
Michael Vogt (mvo) :

Unmerged revisions

154. By James Hunt

* snappy/systemimage.go:
  - showUpgradeDetails(): Display basic debug showing planned upgrade details
    (displayed if SNAPPY_DEBUG=1).
  - checkUpgrade(): Basic test run unconditionally to ensure the upgrade
    revision applied is as expected.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'snappy/systemimage.go'
2--- snappy/systemimage.go 2015-02-06 13:39:24 +0000
3+++ snappy/systemimage.go 2015-02-09 11:02:22 +0000
4@@ -93,6 +93,7 @@
5 }
6
7 func (s *SystemImagePart) Install(pb ProgressMeter) (err error) {
8+
9 var updateProgress *SensibleWatch
10 if pb != nil {
11 updateProgress, err = s.proxy.makeWatcher("UpdateProgress")
12@@ -125,11 +126,18 @@
13 return err
14 }
15
16+ // Display details of the current system and the planned upgrade
17+ // before the upgrade is actually started.
18+ s.showUpgradeDetails()
19+
20 err = s.proxy.DownloadUpdate()
21 if err != nil {
22 return err
23 }
24
25+ // Check that the final system state is as expected.
26+ s.checkUpgrade()
27+
28 // FIXME: switch s-i daemon back to current partition
29 err = s.partition.UpdateBootloader()
30
31@@ -137,9 +145,76 @@
32 pb.Finished()
33 updateProgress.Cancel()
34 }
35+
36 return err
37 }
38
39+// Show upgrade details if SNAPPY_DEBUG environment variable set
40+func (s *SystemImagePart) showUpgradeDetails() {
41+ if os.Getenv("SNAPPY_DEBUG") == "" {
42+ return
43+ }
44+
45+ // The object we're being called from represents the *future*
46+ // part we're about to install. Since we wish to compare current
47+ // with new, query the existing part too.
48+ repo := NewSystemImageRepository()
49+
50+ currentPart := repo.currentPart()
51+ otherPart := repo.otherPart()
52+
53+ fmt.Printf("current rootfs image:\n")
54+ fmt.Printf(" name : %q\n", currentPart.Name())
55+ fmt.Printf(" version : %q\n", currentPart.Version())
56+ fmt.Printf(" installed : %t\n", currentPart.IsInstalled())
57+ fmt.Printf(" active : %t\n", currentPart.IsActive())
58+
59+ if otherPart != nil {
60+ fmt.Printf("other rootfs image:\n")
61+ fmt.Printf(" name : %q\n", otherPart.Name())
62+ fmt.Printf(" version : %q\n", otherPart.Version())
63+ fmt.Printf(" installed : %t\n", otherPart.IsInstalled())
64+ fmt.Printf(" active : %t\n", otherPart.IsActive())
65+ } else {
66+ fmt.Printf("other rootfs image: none\n")
67+ }
68+
69+ fmt.Printf("upgrade target:\n")
70+ fmt.Printf(" version : %q\n", s.version)
71+ fmt.Printf(" details : %q\n", s.versionDetails)
72+ fmt.Printf(" channel : %q\n", s.channelName)
73+ fmt.Printf(" installed : %t\n", s.isInstalled)
74+ fmt.Printf(" active : %t\n", s.isActive)
75+}
76+
77+// Ensure the expected version update was applied to the expected partition.
78+func (s *SystemImagePart) checkUpgrade() {
79+ // The upgrade has now been applied, so check that the expected
80+ // update was applied by comparing "self" (which is the newest
81+ // system-image revision with that installed on the other
82+ // partition.
83+
84+ repo := NewSystemImageRepository()
85+
86+ // Determine the latest installed part.
87+ latestPart := repo.otherPart()
88+ if latestPart == nil {
89+ // If there is no other part, this system must be a
90+ // single rootfs one, so re-query current to find the
91+ // latest installed part.
92+ latestPart = repo.currentPart()
93+ }
94+
95+ if latestPart == nil {
96+ panic("ERROR: could not find latest installed partition")
97+ }
98+
99+ if s.version != latestPart.Version() {
100+ panic(fmt.Sprintf("ERROR: found latest installed version %q (expected %q)",
101+ latestPart.Version(), s.version))
102+ }
103+}
104+
105 func (s *SystemImagePart) Uninstall() (err error) {
106 return errors.New("Uninstall of a core snap is not possible")
107 }
108@@ -330,6 +405,7 @@
109 return errors.New("updateFailed")
110 break
111 }
112+
113 return nil
114 }
115

Subscribers

People subscribed via source and target branches