Merge lp:~mvo/snappy/15.04-config-cleanup into lp:~snappy-dev/snappy/15.04-deprecated

Proposed by Michael Vogt
Status: Merged
Approved by: Michael Vogt
Approved revision: 475
Merged at revision: 479
Proposed branch: lp:~mvo/snappy/15.04-config-cleanup
Merge into: lp:~snappy-dev/snappy/15.04-deprecated
Prerequisite: lp:~mvo/snappy/15.04-fix-off-by-one
Diff against target: 237 lines (+51/-46)
2 files modified
coreconfig/config.go (+34/-29)
coreconfig/config_test.go (+17/-17)
To merge this branch: bzr merge lp:~mvo/snappy/15.04-config-cleanup
Reviewer Review Type Date Requested Status
Michael Vogt (community) Approve
Sergio Schvezov Approve
Review via email: mp+270629@code.launchpad.net

Commit message

reorganizes the ubuntu-core network config

Description of the change

This branch reorganizes the ubuntu-core network config so that there is:
 ubuntu-core.network.{interfaces,ppp}
instead of
 ubuntu-core.{ppp,network}
which looks a bit less organized.

To post a comment you must log in.
Revision history for this message
Sergio Schvezov (sergiusens) :
review: Approve
Revision history for this message
Snappy Tarmac (snappydevtarmac) wrote :

Attempt to merge into lp:snappy/15.04 failed due to conflicts:

text conflict in coreconfig/config.go

Revision history for this message
Sergio Schvezov (sergiusens) wrote :

ah, this didn't get the pump for the var string change

Revision history for this message
Michael Vogt (mvo) :
review: Approve
Revision history for this message
Snappy Tarmac (snappydevtarmac) wrote :

There are additional revisions which have not been approved in review. Please seek review and approval of these new revisions.

Revision history for this message
Michael Vogt (mvo) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'coreconfig/config.go'
2--- coreconfig/config.go 2015-09-11 18:32:41 +0000
3+++ coreconfig/config.go 2015-09-11 19:51:15 +0000
4@@ -43,7 +43,7 @@
5
6 var (
7 modprobePath = "/etc/modprobe.d/ubuntu-core.conf"
8- networkRoot = "/etc/network/interfaces.d/"
9+ interfacesRoot = "/etc/network/interfaces.d/"
10 pppRoot = "/etc/ppp/"
11 watchdogConfigPath = "/etc/watchdog.conf"
12 watchdogStartupPath = "/etc/default/watchdog"
13@@ -54,13 +54,17 @@
14 var ErrInvalidUnitStatus = errors.New("invalid unit status")
15
16 type systemConfig struct {
17- Autopilot *bool `yaml:"autopilot,omitempty"`
18- Timezone *string `yaml:"timezone,omitempty"`
19- Hostname *string `yaml:"hostname,omitempty"`
20- Modprobe *string `yaml:"modprobe,omitempty"`
21- Network []passthroughConfig `yaml:"network,omitempty"`
22- PPP []passthroughConfig `yaml:"ppp,omitempty"`
23- Watchdog *watchdogConfig `yaml:"watchdog,omitempty"`
24+ Autopilot *bool `yaml:"autopilot,omitempty"`
25+ Timezone *string `yaml:"timezone,omitempty"`
26+ Hostname *string `yaml:"hostname,omitempty"`
27+ Modprobe *string `yaml:"modprobe,omitempty"`
28+ Network *networkConfig `yaml:"network,omitempty"`
29+ Watchdog *watchdogConfig `yaml:"watchdog,omitempty"`
30+}
31+
32+type networkConfig struct {
33+ Interfaces []passthroughConfig `yaml:"interfaces"`
34+ PPP []passthroughConfig `yaml:"ppp"`
35 }
36
37 type passthroughConfig struct {
38@@ -100,7 +104,7 @@
39 if err != nil {
40 return nil, err
41 }
42- network, err := getNetwork()
43+ interfaces, err := getInterfaces()
44 if err != nil {
45 return nil, err
46 }
47@@ -113,13 +117,20 @@
48 return nil, err
49 }
50
51+ var network *networkConfig
52+ if len(interfaces) > 0 || len(ppp) > 0 {
53+ network = &networkConfig{
54+ Interfaces: interfaces,
55+ PPP: ppp,
56+ }
57+ }
58+
59 config := &systemConfig{
60 Autopilot: &autopilot,
61 Timezone: &tz,
62 Hostname: &hostname,
63 Modprobe: &modprobe,
64 Network: network,
65- PPP: ppp,
66 Watchdog: watchdog,
67 }
68
69@@ -216,20 +227,15 @@
70 return "", err
71 }
72 case "Network":
73- if passthroughEqual(oldConfig.Network, newConfig.Network) {
74- continue
75- }
76-
77- if err := setNetwork(newConfig.Network); err != nil {
78- return "", err
79- }
80- case "PPP":
81- if passthroughEqual(oldConfig.PPP, newConfig.PPP) {
82- continue
83- }
84-
85- if err := setPPP(newConfig.PPP); err != nil {
86- return "", err
87+ if oldConfig.Network == nil || !passthroughEqual(oldConfig.Network.Interfaces, newConfig.Network.Interfaces) {
88+ if err := setInterfaces(newConfig.Network.Interfaces); err != nil {
89+ return "", err
90+ }
91+ }
92+ if oldConfig.Network == nil || !passthroughEqual(oldConfig.Network.PPP, newConfig.Network.PPP) {
93+ if err := setPPP(newConfig.Network.PPP); err != nil {
94+ return "", err
95+ }
96 }
97 case "Watchdog":
98 if oldConfig.Watchdog != nil && *oldConfig.Watchdog == *newConfig.Watchdog {
99@@ -298,7 +304,6 @@
100 os.Remove(path)
101 continue
102 }
103-
104 if err := ioutil.WriteFile(path, []byte(c.Content), 0644); err != nil {
105 return err
106 }
107@@ -307,12 +312,12 @@
108 return nil
109 }
110
111-var getNetwork = func() (pc []passthroughConfig, err error) {
112- return getPassthrough(networkRoot)
113+var getInterfaces = func() (pc []passthroughConfig, err error) {
114+ return getPassthrough(interfacesRoot)
115 }
116
117-var setNetwork = func(pc []passthroughConfig) error {
118- return setPassthrough(networkRoot, pc)
119+var setInterfaces = func(pc []passthroughConfig) error {
120+ return setPassthrough(interfacesRoot, pc)
121 }
122
123 var getPPP = func() (pc []passthroughConfig, err error) {
124
125=== modified file 'coreconfig/config_test.go'
126--- coreconfig/config_test.go 2015-09-09 16:16:39 +0000
127+++ coreconfig/config_test.go 2015-09-11 19:51:15 +0000
128@@ -48,7 +48,7 @@
129 originalCmdSystemctl = cmdSystemctl
130 originalHostnamePath = hostnamePath
131 originalModprobePath = modprobePath
132- originalNetworkRoot = networkRoot
133+ originalInterfacesRoot = interfacesRoot
134 originalPppRoot = pppRoot
135 originalWatchdogStartupPath = watchdogStartupPath
136 originalWatchdogConfigPath = watchdogConfigPath
137@@ -79,7 +79,7 @@
138 return nil
139 }
140
141- networkRoot = c.MkDir() + "/"
142+ interfacesRoot = c.MkDir() + "/"
143 pppRoot = c.MkDir() + "/"
144 watchdogConfigPath = filepath.Join(c.MkDir(), "watchdog-config")
145 watchdogStartupPath = filepath.Join(c.MkDir(), "watchdog-startup")
146@@ -102,7 +102,7 @@
147 cmdAutopilotEnabled = originalCmdAutopilotEnabled
148 cmdSystemctl = originalCmdSystemctl
149 modprobePath = originalModprobePath
150- networkRoot = originalNetworkRoot
151+ interfacesRoot = originalInterfacesRoot
152 pppRoot = originalPppRoot
153 watchdogStartupPath = originalWatchdogStartupPath
154 watchdogConfigPath = originalWatchdogConfigPath
155@@ -456,12 +456,12 @@
156 }
157
158 func (cts *ConfigTestSuite) TestNetworkGet(c *C) {
159- path := filepath.Join(networkRoot, "eth0")
160+ path := filepath.Join(interfacesRoot, "eth0")
161 content := "auto eth0"
162 err := ioutil.WriteFile(path, []byte(content), 0644)
163 c.Assert(err, IsNil)
164
165- nc, err := getNetwork()
166+ nc, err := getInterfaces()
167 c.Assert(err, IsNil)
168 c.Assert(nc, DeepEquals, []passthroughConfig{
169 {Name: "eth0", Content: "auto eth0"},
170@@ -472,8 +472,8 @@
171 nc := []passthroughConfig{
172 {Name: "eth0", Content: "auto eth0"},
173 }
174- path := filepath.Join(networkRoot, nc[0].Name)
175- err := setNetwork(nc)
176+ path := filepath.Join(interfacesRoot, nc[0].Name)
177+ err := setInterfaces(nc)
178 c.Assert(err, IsNil)
179 content, err := ioutil.ReadFile(path)
180 c.Assert(err, IsNil)
181@@ -481,7 +481,7 @@
182 }
183
184 func (cts *ConfigTestSuite) TestNetworkSetEmptyRemoves(c *C) {
185- path := filepath.Join(networkRoot, "eth0")
186+ path := filepath.Join(interfacesRoot, "eth0")
187 content := "auto eth0"
188 err := ioutil.WriteFile(path, []byte(content), 0644)
189 c.Assert(err, IsNil)
190@@ -490,7 +490,7 @@
191 nc := []passthroughConfig{
192 {Name: "eth0", Content: ""},
193 }
194- err = setNetwork(nc)
195+ err = setInterfaces(nc)
196 c.Assert(err, IsNil)
197 _, err = ioutil.ReadFile(path)
198 c.Assert(helpers.FileExists(path), Equals, false)
199@@ -522,20 +522,19 @@
200 }
201
202 func (cts *ConfigTestSuite) TestNetworkSetViaYaml(c *C) {
203- modprobePath = filepath.Join(c.MkDir(), "test.conf")
204-
205 input := `
206 config:
207 ubuntu-core:
208 network:
209- - name: eth0
210- content: auto dhcp
211+ interfaces:
212+ - name: eth0
213+ content: auto dhcp
214 `
215 _, err := Set(input)
216 c.Assert(err, IsNil)
217
218 // ensure its really there
219- content, err := ioutil.ReadFile(filepath.Join(networkRoot, "eth0"))
220+ content, err := ioutil.ReadFile(filepath.Join(interfacesRoot, "eth0"))
221 c.Assert(err, IsNil)
222 c.Assert(string(content), Equals, "auto dhcp")
223 }
224@@ -546,9 +545,10 @@
225 input := `
226 config:
227 ubuntu-core:
228- ppp:
229- - name: chap-secret
230- content: password
231+ network:
232+ ppp:
233+ - name: chap-secret
234+ content: password
235 `
236 _, err := Set(input)
237 c.Assert(err, IsNil)

Subscribers

People subscribed via source and target branches