Merge ~teknoraver/snappy-hwe-snaps/+git/captive-redirect:master into ~snappy-hwe-team/snappy-hwe-snaps/+git/captive-redirect:master
- Git
- lp:~teknoraver/snappy-hwe-snaps/+git/captive-redirect
- master
- Merge into master
Status: | Merged |
---|---|
Approved by: | Matteo Croce |
Approved revision: | 48ec1db781397020d8f5d6f464bd474553f08d75 |
Merged at revision: | a10ecc6ddb9439708da44f861325df1c8ce11518 |
Proposed branch: | ~teknoraver/snappy-hwe-snaps/+git/captive-redirect:master |
Merge into: | ~snappy-hwe-team/snappy-hwe-snaps/+git/captive-redirect:master |
Diff against target: |
591 lines (+452/-7) 14 files modified
README.md (+4/-0) cmd/config/main.go (+23/-7) cmd/config/main_test.go (+119/-0) parts/plugins/x-go.py (+44/-0) run-tests.sh (+80/-0) snap/hooks/configure (+24/-0) snapcraft.yaml (+22/-0) spread.yaml (+50/-0) tests/lib/prepare-all.sh (+26/-0) tests/lib/prepare-each.sh (+15/-0) tests/lib/restore-each.sh (+3/-0) tests/main/disable/task.yaml (+8/-0) tests/main/enable-all/task.yaml (+16/-0) tests/main/enable-some/task.yaml (+18/-0) |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Jim Hodapp (community) | Approve | ||
Simon Fels | Approve | ||
System Enablement Bot | continuous-integration | Approve | |
Review via email: mp+315937@code.launchpad.net |
Commit message
Description of the change
Add configure hook
System Enablement Bot (system-enablement-ci-bot) wrote : | # |
Simon Fels (morphis) wrote : | # |
Needs tests and left a comment inline.
Simon Fels (morphis) : | # |
Matteo Croce (teknoraver) : | # |
System Enablement Bot (system-enablement-ci-bot) wrote : | # |
FAILED: Continuous integration, rev:e812ecd15e9
https:/
Executed test runs:
None: https:/
Click here to trigger a rebuild:
https:/
System Enablement Bot (system-enablement-ci-bot) wrote : | # |
FAILED: Continuous integration, rev:e7ade5043fd
https:/
Executed test runs:
None: https:/
Click here to trigger a rebuild:
https:/
System Enablement Bot (system-enablement-ci-bot) wrote : | # |
FAILED: Continuous integration, rev:3beac138976
https:/
Executed test runs:
None: https:/
Click here to trigger a rebuild:
https:/
System Enablement Bot (system-enablement-ci-bot) wrote : | # |
FAILED: Continuous integration, rev:70d5e7a55db
https:/
Executed test runs:
None: https:/
Click here to trigger a rebuild:
https:/
System Enablement Bot (system-enablement-ci-bot) wrote : | # |
FAILED: Continuous integration, rev:70d5e7a55db
https:/
Executed test runs:
None: https:/
Click here to trigger a rebuild:
https:/
Jim Hodapp (jhodapp) : | # |
System Enablement Bot (system-enablement-ci-bot) wrote : | # |
FAILED: Continuous integration, rev:0c77410cd89
https:/
Executed test runs:
None: https:/
Click here to trigger a rebuild:
https:/
System Enablement Bot (system-enablement-ci-bot) wrote : | # |
FAILED: Continuous integration, rev:0c77410cd89
https:/
Executed test runs:
None: https:/
Click here to trigger a rebuild:
https:/
System Enablement Bot (system-enablement-ci-bot) wrote : | # |
FAILED: Continuous integration, rev:18047f44dcb
https:/
Executed test runs:
None: https:/
Click here to trigger a rebuild:
https:/
System Enablement Bot (system-enablement-ci-bot) wrote : | # |
FAILED: Continuous integration, rev:18047f44dcb
https:/
Executed test runs:
None: https:/
Click here to trigger a rebuild:
https:/
Simon Fels (morphis) : | # |
Simon Fels (morphis) wrote : | # |
Still missing spread tests.
System Enablement Bot (system-enablement-ci-bot) wrote : | # |
FAILED: Continuous integration, rev:7de793a5a39
https:/
Executed test runs:
None: https:/
Click here to trigger a rebuild:
https:/
System Enablement Bot (system-enablement-ci-bot) wrote : | # |
FAILED: Continuous integration, rev:7de793a5a39
https:/
Executed test runs:
None: https:/
Click here to trigger a rebuild:
https:/
System Enablement Bot (system-enablement-ci-bot) wrote : | # |
FAILED: Continuous integration, rev:ab50be81a4d
https:/
Executed test runs:
None: https:/
Click here to trigger a rebuild:
https:/
System Enablement Bot (system-enablement-ci-bot) wrote : | # |
PASSED: Continuous integration, rev:f93df22654a
https:/
Executed test runs:
SUCCESS: https:/
None: https:/
Click here to trigger a rebuild:
https:/
System Enablement Bot (system-enablement-ci-bot) wrote : | # |
PASSED: Continuous integration, rev:f93df22654a
https:/
Executed test runs:
SUCCESS: https:/
None: https:/
Click here to trigger a rebuild:
https:/
Jim Hodapp (jhodapp) wrote : | # |
The tests look good, some changes needed...see inline below.
Jim Hodapp (jhodapp) wrote : | # |
I'd also like to see a test that verifies that traffic makes it from the external interface(s) and gets redirected to the portal destination.
Simon Fels (morphis) : | # |
Matteo Croce (teknoraver) : | # |
Matteo Croce (teknoraver) wrote : | # |
> I'd also like to see a test that verifies that traffic makes it from the
> external interface(s) and gets redirected to the portal destination.
That would involve a second VM with the the virtual ethernet bridged to the tested one
System Enablement Bot (system-enablement-ci-bot) wrote : | # |
PASSED: Continuous integration, rev:c2713fe2896
https:/
Executed test runs:
SUCCESS: https:/
None: https:/
Click here to trigger a rebuild:
https:/
System Enablement Bot (system-enablement-ci-bot) wrote : | # |
PASSED: Continuous integration, rev:c2713fe2896
https:/
Executed test runs:
SUCCESS: https:/
None: https:/
Click here to trigger a rebuild:
https:/
System Enablement Bot (system-enablement-ci-bot) wrote : | # |
PASSED: Continuous integration, rev:48ec1db7813
https:/
Executed test runs:
SUCCESS: https:/
None: https:/
Click here to trigger a rebuild:
https:/
System Enablement Bot (system-enablement-ci-bot) wrote : | # |
PASSED: Continuous integration, rev:48ec1db7813
https:/
Executed test runs:
SUCCESS: https:/
None: https:/
Click here to trigger a rebuild:
https:/
System Enablement Bot (system-enablement-ci-bot) wrote : | # |
PASSED: Continuous integration, rev:48ec1db7813
https:/
Executed test runs:
SUCCESS: https:/
None: https:/
Click here to trigger a rebuild:
https:/
Simon Fels (morphis) wrote : | # |
I would like to see still a spread test covering the real functionality of this snap using some kind of network namespace + veth combination but considering we want to get the first part of this finally done approving this now.
Jim Hodapp (jhodapp) wrote : | # |
Agree with Simon's comment, approving.
Preview Diff
1 | diff --git a/README.md b/README.md | |||
2 | index 16ce364..69d3bcc 100644 | |||
3 | --- a/README.md | |||
4 | +++ b/README.md | |||
5 | @@ -19,6 +19,10 @@ You can set multiple configuration options with the config command: | |||
6 | 19 | ``` | 19 | ``` |
7 | 20 | $ captive-portal.config set active=true port=8080 interfaces=eth1 | 20 | $ captive-portal.config set active=true port=8080 interfaces=eth1 |
8 | 21 | ``` | 21 | ``` |
9 | 22 | The configuration options are: | ||
10 | 23 | active=(true,false) activates or deactivates the redirect | ||
11 | 24 | port=(1-65535) port to redirect to | ||
12 | 25 | interfaces=... comma separated value of interface to redirect from, if empty redirects from all | ||
13 | 22 | ## Development | 26 | ## Development |
14 | 23 | 27 | ||
15 | 24 | ``` | 28 | ``` |
16 | diff --git a/cmd/config/main.go b/cmd/config/main.go | |||
17 | index 1c1fd2a..535bc02 100644 | |||
18 | --- a/cmd/config/main.go | |||
19 | +++ b/cmd/config/main.go | |||
20 | @@ -28,7 +28,7 @@ import ( | |||
21 | 28 | "github.com/jessevdk/go-flags" | 28 | "github.com/jessevdk/go-flags" |
22 | 29 | ) | 29 | ) |
23 | 30 | 30 | ||
25 | 31 | var configFile = filepath.Join(os.Getenv("SNAP_DATA"), "config.json") | 31 | var configFile = filepath.Join(os.Getenv("SNAP_COMMON"), "config.json") |
26 | 32 | 32 | ||
27 | 33 | type config struct { | 33 | type config struct { |
28 | 34 | Active bool `json:"active"` | 34 | Active bool `json:"active"` |
29 | @@ -72,11 +72,14 @@ func (c *config) saveConfig(path string) error { | |||
30 | 72 | 72 | ||
31 | 73 | // Convenience function which basically does 'iptables -t nat ...' | 73 | // Convenience function which basically does 'iptables -t nat ...' |
32 | 74 | // to add rules to the nat table | 74 | // to add rules to the nat table |
34 | 75 | func addRule(args ...string) error { | 75 | func run(args ...string) error { |
35 | 76 | cmd := exec.Command("iptables", append([]string{"-t", "nat"}, args...)...) | 76 | cmd := exec.Command("iptables", append([]string{"-t", "nat"}, args...)...) |
36 | 77 | return cmd.Run() | 77 | return cmd.Run() |
37 | 78 | } | 78 | } |
38 | 79 | 79 | ||
39 | 80 | // Override run with a logging function in tests | ||
40 | 81 | var addRule = run | ||
41 | 82 | |||
42 | 80 | func clearRules() { | 83 | func clearRules() { |
43 | 81 | // Flush our custom 'captive' chain and delete it | 84 | // Flush our custom 'captive' chain and delete it |
44 | 82 | addRule("-D", "PREROUTING", "-j", "captive") | 85 | addRule("-D", "PREROUTING", "-j", "captive") |
45 | @@ -134,9 +137,9 @@ func applyRules() error { | |||
46 | 134 | type statusCommand struct{} | 137 | type statusCommand struct{} |
47 | 135 | 138 | ||
48 | 136 | func (cmd *statusCommand) Execute(args []string) error { | 139 | func (cmd *statusCommand) Execute(args []string) error { |
52 | 137 | println("active:", cfg.Active) | 140 | fmt.Println("active:", cfg.Active) |
53 | 138 | println("port:", cfg.Port) | 141 | fmt.Println("port:", cfg.Port) |
54 | 139 | println("interfaces:", strings.Join(cfg.Interfaces, ", ")) | 142 | fmt.Println("interfaces:", strings.Join(cfg.Interfaces, ", ")) |
55 | 140 | 143 | ||
56 | 141 | return nil | 144 | return nil |
57 | 142 | } | 145 | } |
58 | @@ -157,9 +160,22 @@ func (cmd *setCommand) Execute(args []string) error { | |||
59 | 157 | 160 | ||
60 | 158 | switch value := arg[i+1:]; arg[:i] { | 161 | switch value := arg[i+1:]; arg[:i] { |
61 | 159 | case "active": | 162 | case "active": |
63 | 160 | cfg.Active = value == "true" | 163 | switch value { |
64 | 164 | case "true": | ||
65 | 165 | cfg.Active = true | ||
66 | 166 | case "false": | ||
67 | 167 | cfg.Active = false | ||
68 | 168 | default: | ||
69 | 169 | return fmt.Errorf("Invalid active status %s", value) | ||
70 | 170 | } | ||
71 | 161 | case "port": | 171 | case "port": |
73 | 162 | port, _ := strconv.ParseUint(value, 0, 16) | 172 | port, err := strconv.ParseUint(value, 0, 16) |
74 | 173 | if err != nil { | ||
75 | 174 | return err | ||
76 | 175 | } | ||
77 | 176 | if port == 0 { | ||
78 | 177 | return fmt.Errorf("Port can't be 0") | ||
79 | 178 | } | ||
80 | 163 | cfg.Port = uint16(port) | 179 | cfg.Port = uint16(port) |
81 | 164 | case "interfaces": | 180 | case "interfaces": |
82 | 165 | if len(value) > 0 { | 181 | if len(value) > 0 { |
83 | diff --git a/cmd/config/main_test.go b/cmd/config/main_test.go | |||
84 | 166 | new file mode 100644 | 182 | new file mode 100644 |
85 | index 0000000..dc7a1c1 | |||
86 | --- /dev/null | |||
87 | +++ b/cmd/config/main_test.go | |||
88 | @@ -0,0 +1,119 @@ | |||
89 | 1 | // | ||
90 | 2 | // Copyright (C) 2017 Canonical Ltd | ||
91 | 3 | // | ||
92 | 4 | // This program is free software: you can redistribute it and/or modify | ||
93 | 5 | // it under the terms of the GNU General Public License version 3 as | ||
94 | 6 | // published by the Free Software Foundation. | ||
95 | 7 | // | ||
96 | 8 | // This program is distributed in the hope that it will be useful, | ||
97 | 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
98 | 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
99 | 11 | // GNU General Public License for more details. | ||
100 | 12 | // | ||
101 | 13 | // You should have received a copy of the GNU General Public License | ||
102 | 14 | // along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
103 | 15 | |||
104 | 16 | package main | ||
105 | 17 | |||
106 | 18 | import ( | ||
107 | 19 | "os" | ||
108 | 20 | "testing" | ||
109 | 21 | |||
110 | 22 | "gopkg.in/check.v1" | ||
111 | 23 | ) | ||
112 | 24 | |||
113 | 25 | const ( | ||
114 | 26 | configPath = "/tmp/cr-config.json" | ||
115 | 27 | argsfile = "iptables.args" | ||
116 | 28 | ) | ||
117 | 29 | |||
118 | 30 | // gopkg.in/check.v1 stuff | ||
119 | 31 | func Test(t *testing.T) { check.TestingT(t) } | ||
120 | 32 | |||
121 | 33 | type ClientSuite struct{} | ||
122 | 34 | |||
123 | 35 | var _ = check.Suite(&ClientSuite{}) | ||
124 | 36 | |||
125 | 37 | func (s *ClientSuite) TestConfig(c *check.C) { | ||
126 | 38 | |||
127 | 39 | // Prepare two configuration structures | ||
128 | 40 | cfg1 := config{ | ||
129 | 41 | Active: true, | ||
130 | 42 | Port: 8080, | ||
131 | 43 | Interfaces: []string{"eth2", "tun1"}, | ||
132 | 44 | } | ||
133 | 45 | var cfg2 config | ||
134 | 46 | |||
135 | 47 | c.Assert(cfg1.saveConfig(configPath), check.IsNil) | ||
136 | 48 | defer os.Remove(configPath) | ||
137 | 49 | c.Assert(cfg2.loadConfig(configPath), check.IsNil) | ||
138 | 50 | |||
139 | 51 | c.Assert(cfg1, check.DeepEquals, cfg2) | ||
140 | 52 | } | ||
141 | 53 | |||
142 | 54 | var iptablesArgs [][]string | ||
143 | 55 | |||
144 | 56 | func testRun(args ...string) error { | ||
145 | 57 | iptablesArgs = append(iptablesArgs, args) | ||
146 | 58 | return nil | ||
147 | 59 | } | ||
148 | 60 | |||
149 | 61 | func (s *ClientSuite) TestClear(c *check.C) { | ||
150 | 62 | // Mock iptables calls | ||
151 | 63 | iptablesArgs = [][]string{} | ||
152 | 64 | addRule = testRun | ||
153 | 65 | |||
154 | 66 | clearRules() | ||
155 | 67 | |||
156 | 68 | c.Assert(iptablesArgs, check.DeepEquals, [][]string{ | ||
157 | 69 | {"-D", "PREROUTING", "-j", "captive"}, | ||
158 | 70 | {"-F", "captive"}, | ||
159 | 71 | {"-X", "captive"}, | ||
160 | 72 | }) | ||
161 | 73 | } | ||
162 | 74 | |||
163 | 75 | func (s *ClientSuite) TestApplyAll(c *check.C) { | ||
164 | 76 | // Mock iptables calls | ||
165 | 77 | iptablesArgs = [][]string{} | ||
166 | 78 | addRule = testRun | ||
167 | 79 | |||
168 | 80 | cfg = config{ | ||
169 | 81 | Active: true, | ||
170 | 82 | Port: 54239, | ||
171 | 83 | } | ||
172 | 84 | |||
173 | 85 | applyRules() | ||
174 | 86 | |||
175 | 87 | c.Assert(iptablesArgs, check.DeepEquals, [][]string{ | ||
176 | 88 | {"-D", "PREROUTING", "-j", "captive"}, | ||
177 | 89 | {"-F", "captive"}, | ||
178 | 90 | {"-X", "captive"}, | ||
179 | 91 | {"-N", "captive"}, | ||
180 | 92 | {"-I", "PREROUTING", "-j", "captive"}, | ||
181 | 93 | {"-A", "captive", "-p", "tcp", "-m", "multiport", "--dport", "80,443", "-j", "REDIRECT", "--to-ports", "54239"}, | ||
182 | 94 | }) | ||
183 | 95 | } | ||
184 | 96 | |||
185 | 97 | func (s *ClientSuite) TestApplySome(c *check.C) { | ||
186 | 98 | // Mock iptables calls | ||
187 | 99 | iptablesArgs = [][]string{} | ||
188 | 100 | addRule = testRun | ||
189 | 101 | |||
190 | 102 | cfg = config{ | ||
191 | 103 | Active: true, | ||
192 | 104 | Port: 1234, | ||
193 | 105 | Interfaces: []string{"eth4", "ppp2"}, | ||
194 | 106 | } | ||
195 | 107 | |||
196 | 108 | applyRules() | ||
197 | 109 | |||
198 | 110 | c.Assert(iptablesArgs, check.DeepEquals, [][]string{ | ||
199 | 111 | {"-D", "PREROUTING", "-j", "captive"}, | ||
200 | 112 | {"-F", "captive"}, | ||
201 | 113 | {"-X", "captive"}, | ||
202 | 114 | {"-N", "captive"}, | ||
203 | 115 | {"-I", "PREROUTING", "-j", "captive"}, | ||
204 | 116 | {"-A", "captive", "-i", "eth4", "-p", "tcp", "-m", "multiport", "--dport", "80,443", "-j", "REDIRECT", "--to-ports", "1234"}, | ||
205 | 117 | {"-A", "captive", "-i", "ppp2", "-p", "tcp", "-m", "multiport", "--dport", "80,443", "-j", "REDIRECT", "--to-ports", "1234"}, | ||
206 | 118 | }) | ||
207 | 119 | } | ||
208 | diff --git a/parts/plugins/x-go.py b/parts/plugins/x-go.py | |||
209 | 0 | new file mode 100644 | 120 | new file mode 100644 |
210 | index 0000000..2211de7 | |||
211 | --- /dev/null | |||
212 | +++ b/parts/plugins/x-go.py | |||
213 | @@ -0,0 +1,44 @@ | |||
214 | 1 | # -*- Mode:Python; indent-tabs-mode:nil; tab-width:4 -*- | ||
215 | 2 | # | ||
216 | 3 | # Copyright (C) 2015, 2016 Canonical Ltd | ||
217 | 4 | # | ||
218 | 5 | # This program is free software: you can redistribute it and/or modify | ||
219 | 6 | # it under the terms of the GNU General Public License version 3 as | ||
220 | 7 | # published by the Free Software Foundation. | ||
221 | 8 | # | ||
222 | 9 | # This program is distributed in the hope that it will be useful, | ||
223 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
224 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
225 | 12 | # GNU General Public License for more details. | ||
226 | 13 | # | ||
227 | 14 | # You should have received a copy of the GNU General Public License | ||
228 | 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
229 | 16 | |||
230 | 17 | import os | ||
231 | 18 | |||
232 | 19 | import snapcraft | ||
233 | 20 | import snapcraft.plugins.go | ||
234 | 21 | |||
235 | 22 | DEBIAN_GOCODE_SRC_PATH = "/usr/share/gocode/src" | ||
236 | 23 | |||
237 | 24 | class GoPlugin(snapcraft.plugins.go.GoPlugin): | ||
238 | 25 | def pull(self): | ||
239 | 26 | # Skip the pull step from GoPlugin here as it would repeat 90% of what | ||
240 | 27 | # we're doing here and will only conflict. | ||
241 | 28 | snapcraft.BasePlugin.pull(self) | ||
242 | 29 | os.makedirs(self._gopath_src, exist_ok=True) | ||
243 | 30 | |||
244 | 31 | if self.options.source: | ||
245 | 32 | go_package = self._get_local_go_package() | ||
246 | 33 | go_package_path = os.path.join(self._gopath_src, go_package) | ||
247 | 34 | if os.path.islink(go_package_path): | ||
248 | 35 | os.unlink(go_package_path) | ||
249 | 36 | os.makedirs(os.path.dirname(go_package_path), exist_ok=True) | ||
250 | 37 | os.symlink(self.sourcedir, go_package_path) | ||
251 | 38 | # We can't just add the gocode directory to GOPATH as go | ||
252 | 39 | # doesn't like this. Instead we're symlinking the necessary | ||
253 | 40 | # subdirectories from the gocode directory into our already | ||
254 | 41 | # existing GOPATH. | ||
255 | 42 | for dir in os.listdir(DEBIAN_GOCODE_SRC_PATH): | ||
256 | 43 | os.symlink(os.path.join(DEBIAN_GOCODE_SRC_PATH, dir), | ||
257 | 44 | os.path.join(self._gopath_src, dir)) | ||
258 | diff --git a/run-tests.sh b/run-tests.sh | |||
259 | 0 | new file mode 100755 | 45 | new file mode 100755 |
260 | index 0000000..92910b5 | |||
261 | --- /dev/null | |||
262 | +++ b/run-tests.sh | |||
263 | @@ -0,0 +1,80 @@ | |||
264 | 1 | #!/bin/sh | ||
265 | 2 | # | ||
266 | 3 | # Copyright (C) 2016 Canonical Ltd | ||
267 | 4 | # | ||
268 | 5 | # This program is free software: you can redistribute it and/or modify | ||
269 | 6 | # it under the terms of the GNU General Public License version 3 as | ||
270 | 7 | # published by the Free Software Foundation. | ||
271 | 8 | # | ||
272 | 9 | # This program is distributed in the hope that it will be useful, | ||
273 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
274 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
275 | 12 | # GNU General Public License for more details. | ||
276 | 13 | # | ||
277 | 14 | # You should have received a copy of the GNU General Public License | ||
278 | 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
279 | 16 | |||
280 | 17 | set -e | ||
281 | 18 | |||
282 | 19 | TESTS_EXTRAS_URL="https://git.launchpad.net/~snappy-hwe-team/snappy-hwe-snaps/+git/tests-extras" | ||
283 | 20 | TESTS_EXTRAS_PATH=".tests-extras" | ||
284 | 21 | |||
285 | 22 | # Display help. | ||
286 | 23 | # This has to be in sync with the tests-extras/test-runner.sh script | ||
287 | 24 | # functionalities as the parameters to this one are passed directly there | ||
288 | 25 | show_help() { | ||
289 | 26 | exec cat <<'EOF' | ||
290 | 27 | Usage: run-tests.sh [OPTIONS] | ||
291 | 28 | |||
292 | 29 | This is fetch & forget script and what it does is to fetch the | ||
293 | 30 | tests-extras repository and execute the run-tests.sh script from | ||
294 | 31 | there passing arguments as-is. | ||
295 | 32 | |||
296 | 33 | optional arguments: | ||
297 | 34 | --help Show this help message and exit | ||
298 | 35 | --channel Select another channel to build the base image from (default: stable) | ||
299 | 36 | --snap Extra snap to install | ||
300 | 37 | --debug Enable verbose debugging output | ||
301 | 38 | --test-from-channel Pull network-manager snap from the specified channel instead of building it from source | ||
302 | 39 | --force-new-image Force generating a new image used for testing | ||
303 | 40 | EOF | ||
304 | 41 | } | ||
305 | 42 | |||
306 | 43 | # Clone the tests-extras repository | ||
307 | 44 | clone_tests_extras() { | ||
308 | 45 | echo "INFO: Fetching tests-extras scripts into $TESTS_EXTRAS_PATH ..." | ||
309 | 46 | git clone -b master $TESTS_EXTRAS_URL $TESTS_EXTRAS_PATH >/dev/null 2>&1 | ||
310 | 47 | if [ $? -ne 0 ]; then | ||
311 | 48 | echo "ERROR: Failed to fetch the $TESTS_EXTRAS_URL repo, exiting.." | ||
312 | 49 | exit 1 | ||
313 | 50 | fi | ||
314 | 51 | } | ||
315 | 52 | |||
316 | 53 | # Make sure the already cloned tests-extras repository is in a known and update | ||
317 | 54 | # state before it is going to be used. | ||
318 | 55 | restore_and_update_tests_extras() { | ||
319 | 56 | echo "INFO: Restoring and updating $TESTS_EXTRAS_PATH" | ||
320 | 57 | cd $TESTS_EXTRAS_PATH && git reset --hard && git clean -dfx && git pull | ||
321 | 58 | cd - | ||
322 | 59 | } | ||
323 | 60 | |||
324 | 61 | # ============================================================================== | ||
325 | 62 | # This is fetch & forget script and what it does is to fetch the tests-extras | ||
326 | 63 | # repo and execute the run-tests.sh script from there passing arguments as-is. | ||
327 | 64 | # | ||
328 | 65 | # The tests-extras repository ends up checked out in the snap tree but as a | ||
329 | 66 | # hidden directory which is re-used since then. | ||
330 | 67 | |||
331 | 68 | # Display help w/o fetching anything | ||
332 | 69 | if [ "$1" = "--help" ]; then | ||
333 | 70 | show_help | ||
334 | 71 | fi | ||
335 | 72 | |||
336 | 73 | if [ -d "$TESTS_EXTRAS_PATH" ]; then | ||
337 | 74 | restore_and_update_tests_extras | ||
338 | 75 | else | ||
339 | 76 | clone_tests_extras | ||
340 | 77 | fi | ||
341 | 78 | |||
342 | 79 | echo "INFO: Executing tests runner" | ||
343 | 80 | cd $TESTS_EXTRAS_PATH && ./tests-runner.sh "$@" | ||
344 | diff --git a/snap/hooks/configure b/snap/hooks/configure | |||
345 | 0 | new file mode 100755 | 81 | new file mode 100755 |
346 | index 0000000..249f367 | |||
347 | --- /dev/null | |||
348 | +++ b/snap/hooks/configure | |||
349 | @@ -0,0 +1,24 @@ | |||
350 | 1 | #!/bin/sh | ||
351 | 2 | |||
352 | 3 | # Copyright (C) 2017 Canonical Ltd | ||
353 | 4 | # | ||
354 | 5 | # This program is free software: you can redistribute it and/or modify | ||
355 | 6 | # it under the terms of the GNU General Public License version 3 as | ||
356 | 7 | # published by the Free Software Foundation. | ||
357 | 8 | # | ||
358 | 9 | # This program is distributed in the hope that it will be useful, | ||
359 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
360 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
361 | 12 | # GNU General Public License for more details. | ||
362 | 13 | # | ||
363 | 14 | # You should have received a copy of the GNU General Public License | ||
364 | 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
365 | 16 | |||
366 | 17 | active=$(snapctl get active) | ||
367 | 18 | port=$(snapctl get port) | ||
368 | 19 | interfaces=$(snapctl get interfaces) | ||
369 | 20 | |||
370 | 21 | # Exit after fresh installation | ||
371 | 22 | [ -z "$active$port$interfaces" ] && exit 0 | ||
372 | 23 | |||
373 | 24 | exec $SNAP/bin/config set active="$active" port="$port" interfaces="$interfaces" | ||
374 | diff --git a/snapcraft.yaml b/snapcraft.yaml | |||
375 | index 1bb3f5f..7e030be 100644 | |||
376 | --- a/snapcraft.yaml | |||
377 | +++ b/snapcraft.yaml | |||
378 | @@ -1,3 +1,18 @@ | |||
379 | 1 | # | ||
380 | 2 | # Copyright (C) 2017 Canonical Ltd | ||
381 | 3 | # | ||
382 | 4 | # This program is free software: you can redistribute it and/or modify | ||
383 | 5 | # it under the terms of the GNU General Public License version 3 as | ||
384 | 6 | # published by the Free Software Foundation. | ||
385 | 7 | # | ||
386 | 8 | # This program is distributed in the hope that it will be useful, | ||
387 | 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
388 | 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
389 | 11 | # GNU General Public License for more details. | ||
390 | 12 | # | ||
391 | 13 | # You should have received a copy of the GNU General Public License | ||
392 | 14 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
393 | 15 | |||
394 | 1 | name: captive-redirect | 16 | name: captive-redirect |
395 | 2 | version: 1 | 17 | version: 1 |
396 | 3 | confinement: strict | 18 | confinement: strict |
397 | @@ -14,9 +29,16 @@ apps: | |||
398 | 14 | plugs: | 29 | plugs: |
399 | 15 | - firewall-control | 30 | - firewall-control |
400 | 16 | 31 | ||
401 | 32 | hooks: | ||
402 | 33 | configure: | ||
403 | 34 | plugs: | ||
404 | 35 | - firewall-control | ||
405 | 36 | |||
406 | 17 | parts: | 37 | parts: |
407 | 18 | config: | 38 | config: |
408 | 19 | plugin: go | 39 | plugin: go |
409 | 20 | source: cmd/config | 40 | source: cmd/config |
410 | 21 | snap: | 41 | snap: |
411 | 22 | - bin | 42 | - bin |
412 | 43 | build-packages: | ||
413 | 44 | - golang-go-flags-dev | ||
414 | diff --git a/spread.yaml b/spread.yaml | |||
415 | 23 | new file mode 100644 | 45 | new file mode 100644 |
416 | index 0000000..3eefa0a | |||
417 | --- /dev/null | |||
418 | +++ b/spread.yaml | |||
419 | @@ -0,0 +1,50 @@ | |||
420 | 1 | # | ||
421 | 2 | # Copyright (C) 2017 Canonical Ltd | ||
422 | 3 | # | ||
423 | 4 | # This program is free software: you can redistribute it and/or modify | ||
424 | 5 | # it under the terms of the GNU General Public License version 3 as | ||
425 | 6 | # published by the Free Software Foundation. | ||
426 | 7 | # | ||
427 | 8 | # This program is distributed in the hope that it will be useful, | ||
428 | 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
429 | 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
430 | 11 | # GNU General Public License for more details. | ||
431 | 12 | # | ||
432 | 13 | # You should have received a copy of the GNU General Public License | ||
433 | 14 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
434 | 15 | |||
435 | 16 | |||
436 | 17 | project: captive-redirect | ||
437 | 18 | |||
438 | 19 | environment: | ||
439 | 20 | PROJECT_PATH: /home/captive-redirect | ||
440 | 21 | TESTSLIB: $PROJECT_PATH/tests/lib | ||
441 | 22 | SNAP_NAME: captive-redirect | ||
442 | 23 | # Allow the host to pass the channel to use for the test rim | ||
443 | 24 | SNAP_CHANNEL: $(HOST:echo $SNAP_CHANNEL) | ||
444 | 25 | |||
445 | 26 | backends: | ||
446 | 27 | qemu: | ||
447 | 28 | systems: | ||
448 | 29 | - ubuntu-core-16: | ||
449 | 30 | username: test | ||
450 | 31 | password: test | ||
451 | 32 | |||
452 | 33 | # Put this somewhere where we have read-write access | ||
453 | 34 | path: /home/captive-redirect | ||
454 | 35 | |||
455 | 36 | exclude: | ||
456 | 37 | - .git | ||
457 | 38 | |||
458 | 39 | prepare: | | ||
459 | 40 | . $TESTSLIB/prepare-all.sh | ||
460 | 41 | |||
461 | 42 | suites: | ||
462 | 43 | tests/main/: | ||
463 | 44 | summary: Full-system tests for the captive-redirect snap | ||
464 | 45 | systems: | ||
465 | 46 | - ubuntu-core-16 | ||
466 | 47 | prepare-each: | | ||
467 | 48 | . $TESTSLIB/prepare-each.sh | ||
468 | 49 | restore-each: | | ||
469 | 50 | . $TESTSLIB/restore-each.sh | ||
470 | diff --git a/tests/lib/prepare-all.sh b/tests/lib/prepare-all.sh | |||
471 | 0 | new file mode 100755 | 51 | new file mode 100755 |
472 | index 0000000..d47845f | |||
473 | --- /dev/null | |||
474 | +++ b/tests/lib/prepare-all.sh | |||
475 | @@ -0,0 +1,26 @@ | |||
476 | 1 | #!/bin/sh | ||
477 | 2 | |||
478 | 3 | rm -f /home/captive-redirect/captive-redirect_*.snap | ||
479 | 4 | |||
480 | 5 | # Setup classic snap and build the captive-redirect snap in there | ||
481 | 6 | snap install --devmode --beta classic | ||
482 | 7 | cat <<-EOF > /home/test/build-snap.sh | ||
483 | 8 | #!/bin/sh | ||
484 | 9 | set -ex | ||
485 | 10 | apt update | ||
486 | 11 | apt install -y snapcraft git | ||
487 | 12 | cd /home/captive-redirect/ | ||
488 | 13 | snapcraft clean | ||
489 | 14 | snapcraft | ||
490 | 15 | EOF | ||
491 | 16 | chmod +x /home/test/build-snap.sh | ||
492 | 17 | sudo classic /home/test/build-snap.sh | ||
493 | 18 | snap remove classic | ||
494 | 19 | |||
495 | 20 | # Make sure we have a snap binary | ||
496 | 21 | test -e /home/captive-redirect/captive-redirect_*.snap | ||
497 | 22 | |||
498 | 23 | # Snapshot of the current snapd state for a later restore | ||
499 | 24 | systemctl stop snapd.service snapd.socket | ||
500 | 25 | tar czf $SPREAD_PATH/snapd-state.tar.gz /var/lib/snapd | ||
501 | 26 | systemctl start snapd.socket | ||
502 | diff --git a/tests/lib/prepare-each.sh b/tests/lib/prepare-each.sh | |||
503 | 0 | new file mode 100755 | 27 | new file mode 100755 |
504 | index 0000000..d983cef | |||
505 | --- /dev/null | |||
506 | +++ b/tests/lib/prepare-each.sh | |||
507 | @@ -0,0 +1,15 @@ | |||
508 | 1 | #!/bin/sh | ||
509 | 2 | |||
510 | 3 | # Restore snapd state from backup | ||
511 | 4 | systemctl stop snapd.service snapd.socket | ||
512 | 5 | rm -rf /var/lib/snapd/* | ||
513 | 6 | tar xzf $SPREAD_PATH/snapd-state.tar.gz -C / | ||
514 | 7 | rm -rf /root/.snap | ||
515 | 8 | systemctl start snapd.socket | ||
516 | 9 | |||
517 | 10 | # Clean iptables | ||
518 | 11 | iptables -t nat -F | ||
519 | 12 | iptables -t nat -X | ||
520 | 13 | |||
521 | 14 | snap install --dangerous /home/captive-redirect/captive-redirect_*.snap | ||
522 | 15 | snap connect captive-redirect:firewall-control core | ||
523 | diff --git a/tests/lib/restore-each.sh b/tests/lib/restore-each.sh | |||
524 | 0 | new file mode 100755 | 16 | new file mode 100755 |
525 | index 0000000..aa8f65c | |||
526 | --- /dev/null | |||
527 | +++ b/tests/lib/restore-each.sh | |||
528 | @@ -0,0 +1,3 @@ | |||
529 | 1 | #!/bin/sh | ||
530 | 2 | |||
531 | 3 | snap remove captive-redirect | ||
532 | diff --git a/tests/main/disable/task.yaml b/tests/main/disable/task.yaml | |||
533 | 0 | new file mode 100644 | 4 | new file mode 100644 |
534 | index 0000000..ababdb0 | |||
535 | --- /dev/null | |||
536 | +++ b/tests/main/disable/task.yaml | |||
537 | @@ -0,0 +1,8 @@ | |||
538 | 1 | summary: Verify that the redirect can be disabled | ||
539 | 2 | |||
540 | 3 | execute: | | ||
541 | 4 | # Snap is installed, check that it's disabled | ||
542 | 5 | captive-redirect.config status |grep 'active: false' | ||
543 | 6 | |||
544 | 7 | # Check that we have no iptables rules | ||
545 | 8 | ! iptables-save |grep -- -j | ||
546 | diff --git a/tests/main/enable-all/task.yaml b/tests/main/enable-all/task.yaml | |||
547 | 0 | new file mode 100644 | 9 | new file mode 100644 |
548 | index 0000000..4745acb | |||
549 | --- /dev/null | |||
550 | +++ b/tests/main/enable-all/task.yaml | |||
551 | @@ -0,0 +1,16 @@ | |||
552 | 1 | summary: Verify that the redirect can be enabled on all interfaces | ||
553 | 2 | |||
554 | 3 | execute: | | ||
555 | 4 | # Enable the redirect on all interfaces | ||
556 | 5 | captive-redirect.config set active=true port=9000 | ||
557 | 6 | |||
558 | 7 | captive-redirect.config status |grep 'active: true' | ||
559 | 8 | captive-redirect.config status |grep 'port: 9000' | ||
560 | 9 | captive-redirect.config status |grep 'interfaces: $' | ||
561 | 10 | |||
562 | 11 | # Check that we have the iptables rules | ||
563 | 12 | ipt=/tmp/rules.$$ | ||
564 | 13 | iptables-save >$ipt | ||
565 | 14 | |||
566 | 15 | grep -- '-A PREROUTING -j captive' $ipt | ||
567 | 16 | grep -- '-A captive -p tcp -m multiport --dports 80,443 -j REDIRECT --to-ports 9000' $ipt | ||
568 | diff --git a/tests/main/enable-some/task.yaml b/tests/main/enable-some/task.yaml | |||
569 | 0 | new file mode 100644 | 17 | new file mode 100644 |
570 | index 0000000..5bf13f6 | |||
571 | --- /dev/null | |||
572 | +++ b/tests/main/enable-some/task.yaml | |||
573 | @@ -0,0 +1,18 @@ | |||
574 | 1 | summary: Verify that the redirect can be enabled selectively on configured interfaces | ||
575 | 2 | |||
576 | 3 | execute: | | ||
577 | 4 | # Enable the redirect on the configured interfaces | ||
578 | 5 | captive-redirect.config set active=true port=7689 interfaces=eth4,tun2 | ||
579 | 6 | |||
580 | 7 | captive-redirect.config status |grep 'active: true' | ||
581 | 8 | captive-redirect.config status |grep 'port: 7689' | ||
582 | 9 | captive-redirect.config status |grep 'interfaces: .*eth4' | ||
583 | 10 | captive-redirect.config status |grep 'interfaces: .*tun2' | ||
584 | 11 | |||
585 | 12 | # Check that we have the iptables rules | ||
586 | 13 | ipt=/tmp/rules.$$ | ||
587 | 14 | iptables-save >$ipt | ||
588 | 15 | |||
589 | 16 | grep -- '-A PREROUTING -j captive' $ipt | ||
590 | 17 | grep -- '-A captive -i eth4 -p tcp -m multiport --dports 80,443 -j REDIRECT --to-ports 7689' $ipt | ||
591 | 18 | grep -- '-A captive -i tun2 -p tcp -m multiport --dports 80,443 -j REDIRECT --to-ports 7689' $ipt |
FAILED: Continuous integration, rev:f1557bc4ce4 ac4c1ee8ec0b1d6 e409d0ed25abfc /jenkins. canonical. com/system- enablement/ job/generic- build-snap/ 717/ /jenkins. canonical. com/system- enablement/ job/generic- update- snap-mp/ 625/console
https:/
Executed test runs:
None: https:/
Click here to trigger a rebuild: /jenkins. canonical. com/system- enablement/ job/generic- build-snap/ 717/rebuild
https:/