Merge lp:~heber013/ubuntu-system-tests/adding-snap-test into lp:ubuntu-system-tests
- adding-snap-test
- Merge into trunk
Status: | Merged |
---|---|
Merged at revision: | 574 |
Proposed branch: | lp:~heber013/ubuntu-system-tests/adding-snap-test |
Merge into: | lp:ubuntu-system-tests |
Diff against target: |
418 lines (+314/-14) 6 files modified
debian/tests/dependencies.json (+2/-0) ubuntu_system_tests/helpers/snapd/__init__.py (+19/-0) ubuntu_system_tests/helpers/snapd/snapd.py (+206/-0) ubuntu_system_tests/host/target_setup.py (+21/-10) ubuntu_system_tests/host/targets.py (+9/-4) ubuntu_system_tests/tests/test_snapd.py (+57/-0) |
To merge this branch: | bzr merge lp:~heber013/ubuntu-system-tests/adding-snap-test |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
platform-qa-bot | continuous-integration | Approve | |
Heber Parrucci (community) | continuous-integration | Needs Fixing | |
Review via email:
|
Commit message
Add tests for snapd command line: install, find, download a snap.
Description of the change
Add tests for snapd command line: install, find, download a snap.
@run_tests: ubuntu_
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Heber Parrucci (heber013) wrote : | # |
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Heber Parrucci (heber013) wrote : | # |
FAILED: Continuous integration, rev:572
https:/
Executed test runs:
UNSTABLE: https:/
SUCCESS: https:/
None: https:/
SUCCESS: https:/
Click here to trigger a rebuild:
https:/
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Heber Parrucci (heber013) wrote : | # |
PASSED: Continuous integration, rev:572
https:/
Executed test runs:
UNSTABLE: https:/
None: https:/
SUCCESS: https:/
Click here to trigger a rebuild:
https:/
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Heber Parrucci (heber013) wrote : | # |
FAILED: Continuous integration, rev:572
https:/
Executed test runs:
UNSTABLE: https:/
SUCCESS: https:/
None: https:/
SUCCESS: https:/
Click here to trigger a rebuild:
https:/
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Heber Parrucci (heber013) wrote : | # |
PASSED: Continuous integration, rev:572
https:/
Executed test runs:
UNSTABLE: https:/
None: https:/
SUCCESS: https:/
Click here to trigger a rebuild:
https:/
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Heber Parrucci (heber013) wrote : | # |
FAILED: Continuous integration, rev:572
https:/
Executed test runs:
UNSTABLE: https:/
SUCCESS: https:/
None: https:/
SUCCESS: https:/
Click here to trigger a rebuild:
https:/
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Heber Parrucci (heber013) wrote : | # |
FAILED: Continuous integration, rev:572
https:/
Executed test runs:
FAILURE: https:/
None: https:/
SUCCESS: https:/
Click here to trigger a rebuild:
https:/
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Heber Parrucci (heber013) wrote : | # |
PASSED: Continuous integration, rev:572
https:/
Executed test runs:
UNSTABLE: https:/
None: https:/
SUCCESS: https:/
Click here to trigger a rebuild:
https:/
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Heber Parrucci (heber013) wrote : | # |
FAILED: Continuous integration, rev:572
https:/
Executed test runs:
UNSTABLE: https:/
SUCCESS: https:/
None: https:/
SUCCESS: https:/
Click here to trigger a rebuild:
https:/
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Heber Parrucci (heber013) wrote : | # |
FAILED: Continuous integration, rev:572
https:/
Executed test runs:
FAILURE: https:/
None: https:/
SUCCESS: https:/
Click here to trigger a rebuild:
https:/
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Heber Parrucci (heber013) wrote : | # |
PASSED: Continuous integration, rev:572
https:/
Executed test runs:
UNSTABLE: https:/
None: https:/
SUCCESS: https:/
Click here to trigger a rebuild:
https:/
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Heber Parrucci (heber013) wrote : | # |
FAILED: Continuous integration, rev:572
https:/
Executed test runs:
UNSTABLE: https:/
SUCCESS: https:/
None: https:/
SUCCESS: https:/
Click here to trigger a rebuild:
https:/
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Heber Parrucci (heber013) wrote : | # |
PASSED: Continuous integration, rev:572
https:/
Executed test runs:
UNSTABLE: https:/
None: https:/
SUCCESS: https:/
Click here to trigger a rebuild:
https:/
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Heber Parrucci (heber013) wrote : | # |
FAILED: Continuous integration, rev:572
https:/
Executed test runs:
UNSTABLE: https:/
SUCCESS: https:/
None: https:/
SUCCESS: https:/
Click here to trigger a rebuild:
https:/
- 573. By Heber Parrucci
-
merge from trunk
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
platform-qa-bot (platform-qa-bot) wrote : | # |
FAILED: Continuous integration, rev:573
https:/
Executed test runs:
None: https:/
Click here to trigger a rebuild:
https:/
- 574. By Heber Parrucci
-
fixing json format for dependencies.json
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
platform-qa-bot (platform-qa-bot) wrote : | # |
PASSED: Continuous integration, rev:574
https:/
Executed test runs:
SUCCESS: https:/
None: https:/
SUCCESS: https:/
Click here to trigger a rebuild:
https:/
Preview Diff
1 | === modified file 'debian/tests/dependencies.json' | |||
2 | --- debian/tests/dependencies.json 2017-12-22 19:35:15 +0000 | |||
3 | +++ debian/tests/dependencies.json 2018-01-02 13:43:13 +0000 | |||
4 | @@ -12,6 +12,7 @@ | |||
5 | 12 | { "id": "python3-testtools", "version": "", "tmpinstall": "false" }, | 12 | { "id": "python3-testtools", "version": "", "tmpinstall": "false" }, |
6 | 13 | { "id": "python3-warlock", "version": "", "tmpinstall": "false" }, | 13 | { "id": "python3-warlock", "version": "", "tmpinstall": "false" }, |
7 | 14 | { "id": "python3-xlib", "version": "", "tmpinstall": "false" }, | 14 | { "id": "python3-xlib", "version": "", "tmpinstall": "false" }, |
8 | 15 | { "id": "python3-yaml", "version": "", "tmpinstall": "false" }, | ||
9 | 15 | { "id": "subunit", "version": "", "tmpinstall": "false" }, | 16 | { "id": "subunit", "version": "", "tmpinstall": "false" }, |
10 | 16 | { "id": "ubuntu-app-launch-tools", "version": "", "tmpinstall": "false" }, | 17 | { "id": "ubuntu-app-launch-tools", "version": "", "tmpinstall": "false" }, |
11 | 17 | { "id": "ubuntu-system-tests-helpers", "version": "", "tmpinstall": "false", "condition": "installed" }, | 18 | { "id": "ubuntu-system-tests-helpers", "version": "", "tmpinstall": "false", "condition": "installed" }, |
12 | @@ -40,6 +41,7 @@ | |||
13 | 40 | "python3-testtools", | 41 | "python3-testtools", |
14 | 41 | "python3-warlock", | 42 | "python3-warlock", |
15 | 42 | "python3-xlib", | 43 | "python3-xlib", |
16 | 44 | "python3-yaml", | ||
17 | 43 | "subunit", | 45 | "subunit", |
18 | 44 | "ubuntu-app-launch-tools", | 46 | "ubuntu-app-launch-tools", |
19 | 45 | "ubuntu-system-tests-helpers", | 47 | "ubuntu-system-tests-helpers", |
20 | 46 | 48 | ||
21 | === added directory 'ubuntu_system_tests/helpers/snapd' | |||
22 | === added file 'ubuntu_system_tests/helpers/snapd/__init__.py' | |||
23 | --- ubuntu_system_tests/helpers/snapd/__init__.py 1970-01-01 00:00:00 +0000 | |||
24 | +++ ubuntu_system_tests/helpers/snapd/__init__.py 2018-01-02 13:43:13 +0000 | |||
25 | @@ -0,0 +1,19 @@ | |||
26 | 1 | # -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*- | ||
27 | 2 | |||
28 | 3 | # | ||
29 | 4 | # Snappy Ecosystem Tests | ||
30 | 5 | # Copyright (C) 2017 Canonical | ||
31 | 6 | # | ||
32 | 7 | # This program is free software: you can redistribute it and/or modify | ||
33 | 8 | # it under the terms of the GNU General Public License as published by | ||
34 | 9 | # the Free Software Foundation, either version 3 of the License, or | ||
35 | 10 | # (at your option) any later version. | ||
36 | 11 | # | ||
37 | 12 | # This program is distributed in the hope that it will be useful, | ||
38 | 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
39 | 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
40 | 15 | # GNU General Public License for more details. | ||
41 | 16 | # | ||
42 | 17 | # You should have received a copy of the GNU General Public License | ||
43 | 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
44 | 19 | # | ||
45 | 0 | 20 | ||
46 | === added file 'ubuntu_system_tests/helpers/snapd/snapd.py' | |||
47 | --- ubuntu_system_tests/helpers/snapd/snapd.py 1970-01-01 00:00:00 +0000 | |||
48 | +++ ubuntu_system_tests/helpers/snapd/snapd.py 2018-01-02 13:43:13 +0000 | |||
49 | @@ -0,0 +1,206 @@ | |||
50 | 1 | # -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*- | ||
51 | 2 | |||
52 | 3 | # | ||
53 | 4 | # Snappy Ecosystem Tests | ||
54 | 5 | # Copyright (C) 2017 Canonical | ||
55 | 6 | # | ||
56 | 7 | # This program is free software: you can redistribute it and/or modify | ||
57 | 8 | # it under the terms of the GNU General Public License as published by | ||
58 | 9 | # the Free Software Foundation, either version 3 of the License, or | ||
59 | 10 | # (at your option) any later version. | ||
60 | 11 | # | ||
61 | 12 | # This program is distributed in the hope that it will be useful, | ||
62 | 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
63 | 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
64 | 15 | # GNU General Public License for more details. | ||
65 | 16 | # | ||
66 | 17 | # You should have received a copy of the GNU General Public License | ||
67 | 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
68 | 19 | # | ||
69 | 20 | |||
70 | 21 | """Helpers around snapd command-line interface.""" | ||
71 | 22 | |||
72 | 23 | import json | ||
73 | 24 | import logging | ||
74 | 25 | from time import sleep | ||
75 | 26 | |||
76 | 27 | import yaml | ||
77 | 28 | from ubuntu_system_tests.helpers.testbed import run_command_with_sudo, run_command | ||
78 | 29 | |||
79 | 30 | PATH_SNAP = '/usr/bin/snap' | ||
80 | 31 | COMMAND_DOWNLOAD = 'download {snap} --channel={channel}' | ||
81 | 32 | COMMAND_FIND = 'find {search_term}' | ||
82 | 33 | COMMAND_INFO = 'info {snap}' | ||
83 | 34 | COMMAND_INSTALL = 'install {snap} --channel={channel}' | ||
84 | 35 | COMMAND_LIST = 'list' | ||
85 | 36 | COMMAND_LOGIN = 'login {email}' | ||
86 | 37 | COMMAND_LOGOUT = 'logout' | ||
87 | 38 | COMMAND_REFRESH = 'refresh {snap} --channel={channel}' | ||
88 | 39 | COMMAND_REMOVE = 'remove {snap}' | ||
89 | 40 | COMMAND_SIGN = 'sign' | ||
90 | 41 | CHANNEL_STABLE = 'stable' | ||
91 | 42 | COMMAND_LIST_KEYS = 'keys' | ||
92 | 43 | COMMANDS_LOGIN = """\ | ||
93 | 44 | sudo /usr/bin/expect \ | ||
94 | 45 | -c 'spawn snap login {email}' \ | ||
95 | 46 | -c 'expect \"Password*\"' \ | ||
96 | 47 | -c 'send {password}\\r' \ | ||
97 | 48 | -c 'interact'\ | ||
98 | 49 | """ | ||
99 | 50 | |||
100 | 51 | |||
101 | 52 | LOGGER = logging.getLogger(__name__) | ||
102 | 53 | |||
103 | 54 | |||
104 | 55 | class Snapd: | ||
105 | 56 | """Contain Snapd specific functionality to use via command | ||
106 | 57 | line interface""" | ||
107 | 58 | |||
108 | 59 | def run_snapd_command(self, command, cwd='', sudo=False): | ||
109 | 60 | """Run snapd command over ssh. | ||
110 | 61 | |||
111 | 62 | :param command: a string containing parameters for the `snap` command. | ||
112 | 63 | :param cwd: the current working directory on the remote where | ||
113 | 64 | the command should run. | ||
114 | 65 | :param sudo: whether to run the command with sudo privileges | ||
115 | 66 | :returns: stdout of the command | ||
116 | 67 | """ | ||
117 | 68 | if not command.startswith(PATH_SNAP): | ||
118 | 69 | command = '{} {}'.format(PATH_SNAP, command) | ||
119 | 70 | if cwd: | ||
120 | 71 | command = 'cd {};{}'.format(cwd.rstrip(), command) | ||
121 | 72 | if sudo: | ||
122 | 73 | return run_command_with_sudo(command) | ||
123 | 74 | else: | ||
124 | 75 | return run_command(command) | ||
125 | 76 | |||
126 | 77 | def login(self, email, password): | ||
127 | 78 | """Login to snapd. | ||
128 | 79 | |||
129 | 80 | :param email: Ubuntu SSO account email address. | ||
130 | 81 | :param password: Ubuntu SSO account password. | ||
131 | 82 | """ | ||
132 | 83 | run_command(COMMANDS_LOGIN.format(email=email, | ||
133 | 84 | password=password)) | ||
134 | 85 | return self.is_logged_in(email) | ||
135 | 86 | |||
136 | 87 | def is_logged_in(self, email): | ||
137 | 88 | """Return bool representing if the user is logged into snapd.""" | ||
138 | 89 | try: | ||
139 | 90 | return json.loads(run_command('cat ~/.snap/auth.json')).get('email') == email | ||
140 | 91 | except ValueError: | ||
141 | 92 | return False | ||
142 | 93 | |||
143 | 94 | def logout(self, email): | ||
144 | 95 | """Logout snapd current user.""" | ||
145 | 96 | if self.is_logged_in(email): | ||
146 | 97 | self.run_snapd_command(COMMAND_LOGOUT) | ||
147 | 98 | |||
148 | 99 | def download(self, snap, channel=CHANNEL_STABLE): | ||
149 | 100 | """Download the requested snap. | ||
150 | 101 | |||
151 | 102 | :param snap: name of the snap to download. | ||
152 | 103 | :param channel: name of the release channel to download from. | ||
153 | 104 | """ | ||
154 | 105 | command = COMMAND_DOWNLOAD.format(snap=snap, channel=channel) | ||
155 | 106 | _dir = run_command('mktemp -d').rstrip() | ||
156 | 107 | self.run_snapd_command(command, cwd=_dir) | ||
157 | 108 | return _dir | ||
158 | 109 | |||
159 | 110 | def install(self, snap, channel=CHANNEL_STABLE): | ||
160 | 111 | """Install the requested snap.""" | ||
161 | 112 | return self.run_snapd_command(COMMAND_INSTALL.format(snap=snap, | ||
162 | 113 | channel=channel), | ||
163 | 114 | sudo=True) | ||
164 | 115 | |||
165 | 116 | def is_installed(self, snap): | ||
166 | 117 | """Return bool representing whether a snap is installed.""" | ||
167 | 118 | try: | ||
168 | 119 | for installed_snap in Snapd._parse_output( | ||
169 | 120 | self.run_snapd_command(COMMAND_LIST)): | ||
170 | 121 | if installed_snap['name'] == snap: | ||
171 | 122 | return True | ||
172 | 123 | except KeyError: | ||
173 | 124 | return False | ||
174 | 125 | return False | ||
175 | 126 | |||
176 | 127 | def remove(self, snap): | ||
177 | 128 | """Remove a snap, if its already installed.""" | ||
178 | 129 | if self.is_installed(snap): | ||
179 | 130 | self.run_snapd_command(COMMAND_REMOVE.format(snap=snap), sudo=True) | ||
180 | 131 | |||
181 | 132 | def info(self, snap, verbose=False): | ||
182 | 133 | """Query the Ubuntu store of the information about a snap. | ||
183 | 134 | |||
184 | 135 | :param snap: Name of the snap for which the info is required. | ||
185 | 136 | :param verbose: Whether to information should be detailed. | ||
186 | 137 | :return: Return a dictionary containing information about the snap. | ||
187 | 138 | """ | ||
188 | 139 | command = COMMAND_INFO.format(snap=snap) | ||
189 | 140 | if verbose: | ||
190 | 141 | command = ' '.join([command, '--verbose']) | ||
191 | 142 | return yaml.load("""{}""".format(self.run_snapd_command(command))) | ||
192 | 143 | |||
193 | 144 | def refresh(self, snap, channel=CHANNEL_STABLE): | ||
194 | 145 | """Refresh the requested snap.""" | ||
195 | 146 | self.run_snapd_command(COMMAND_REFRESH.format(snap=snap, | ||
196 | 147 | channel=channel)) | ||
197 | 148 | |||
198 | 149 | @staticmethod | ||
199 | 150 | def _parse_output(raw_output): | ||
200 | 151 | """Pretty parse the output from snapd commands like `find` and `list`. | ||
201 | 152 | |||
202 | 153 | :param raw_output: The raw output returned from the command | ||
203 | 154 | :return: A list of dictionaries containing sorted results | ||
204 | 155 | from the output. | ||
205 | 156 | """ | ||
206 | 157 | split_output = raw_output.split('\n') | ||
207 | 158 | headers = [header.lower() for header in split_output.pop(0).split()] | ||
208 | 159 | return [dict(zip(headers, line.split())) for line in split_output] | ||
209 | 160 | |||
210 | 161 | def find(self, keyword): | ||
211 | 162 | """Find snaps based on the provided filters | ||
212 | 163 | |||
213 | 164 | :param keyword: Keyword to use for the query. | ||
214 | 165 | :return: Return a list of dictionaries containing information about | ||
215 | 166 | snaps matching the `keyword`. | ||
216 | 167 | """ | ||
217 | 168 | return Snapd._parse_output( | ||
218 | 169 | self.run_snapd_command(COMMAND_FIND.format( | ||
219 | 170 | search_term=keyword))) | ||
220 | 171 | |||
221 | 172 | def is_published(self, snap_name, revision, channel='stable'): | ||
222 | 173 | """Return bool representing whether a snap is published. | ||
223 | 174 | |||
224 | 175 | :param snap_name: Name of the snap to check. | ||
225 | 176 | :param revision: Revision to check. | ||
226 | 177 | :param channel: Channel to check. | ||
227 | 178 | :return: True if published, False otherwise. | ||
228 | 179 | """ | ||
229 | 180 | try: | ||
230 | 181 | return int(self.info(snap_name)['channels'][channel].split()[1] | ||
231 | 182 | .strip('()')) >= int(revision) | ||
232 | 183 | except (ValueError, KeyError): | ||
233 | 184 | return False | ||
234 | 185 | |||
235 | 186 | def wait_for_publish(self, snap_name, revision, channel='stable', | ||
236 | 187 | retry_attempts=10, retry_interval=1): | ||
237 | 188 | """Waits for the requested snap to publish by checking if its info | ||
238 | 189 | can be retrieved. | ||
239 | 190 | |||
240 | 191 | :param snap_name: Name of the snap to wait for publish. | ||
241 | 192 | :param revision: Snap revision number to check. | ||
242 | 193 | :param channel: Channel to check snap in. | ||
243 | 194 | :param retry_attempts: Number of times to check for the publish. | ||
244 | 195 | :param retry_interval: Time between each attempt. | ||
245 | 196 | :raises ValueError: If the snap is not found published after the | ||
246 | 197 | given time. | ||
247 | 198 | """ | ||
248 | 199 | for _ in range(retry_attempts): | ||
249 | 200 | if self.is_published(snap_name, revision, channel): | ||
250 | 201 | break | ||
251 | 202 | else: | ||
252 | 203 | sleep(retry_interval) | ||
253 | 204 | else: | ||
254 | 205 | raise ValueError('Snap not published, waited {} seconds.'.format( | ||
255 | 206 | retry_attempts * retry_interval)) | ||
256 | 0 | 207 | ||
257 | === modified file 'ubuntu_system_tests/host/target_setup.py' | |||
258 | --- ubuntu_system_tests/host/target_setup.py 2017-09-22 13:51:52 +0000 | |||
259 | +++ ubuntu_system_tests/host/target_setup.py 2018-01-02 13:43:13 +0000 | |||
260 | @@ -65,8 +65,10 @@ | |||
261 | 65 | 65 | ||
262 | 66 | """Class to run setup actions directly on the target device.""" | 66 | """Class to run setup actions directly on the target device.""" |
263 | 67 | 67 | ||
265 | 68 | def __init__(self, config): | 68 | def __init__(self, config, snapd_https_proxy, snapd_http_proxy): |
266 | 69 | self.config = config | 69 | self.config = config |
267 | 70 | self.snapd_https_proxy = snapd_https_proxy | ||
268 | 71 | self.snapd_http_proxy = snapd_http_proxy | ||
269 | 70 | self.series = None | 72 | self.series = None |
270 | 71 | self.release = None | 73 | self.release = None |
271 | 72 | self.core_series = None | 74 | self.core_series = None |
272 | @@ -94,6 +96,7 @@ | |||
273 | 94 | with open("/etc/environment", "r") as environment: | 96 | with open("/etc/environment", "r") as environment: |
274 | 95 | if "QT_LOAD_TESTABILITY" not in environment.read(): | 97 | if "QT_LOAD_TESTABILITY" not in environment.read(): |
275 | 96 | self.enable_testability() | 98 | self.enable_testability() |
276 | 99 | self.setup_snapd_proxy() | ||
277 | 97 | 100 | ||
278 | 98 | def get_release(self): | 101 | def get_release(self): |
279 | 99 | """Return float release number of running system.""" | 102 | """Return float release number of running system.""" |
280 | @@ -258,16 +261,19 @@ | |||
281 | 258 | self.mount_fs_rw() | 261 | self.mount_fs_rw() |
282 | 259 | self._dist_upgrade() | 262 | self._dist_upgrade() |
283 | 260 | 263 | ||
288 | 261 | def setup_snapd_https_proxy(self): | 264 | def setup_snapd_proxy(self): |
289 | 262 | """Setup https proxy for snapd if its defined in config.""" | 265 | """Setup proxy for snapd if it is defined in config.""" |
290 | 263 | proxy = self.config.get('https_proxy') | 266 | if self.snapd_https_proxy or self.snapd_http_proxy: |
287 | 264 | if proxy: | ||
291 | 265 | conf = '/etc/systemd/system/snapd.service.d/proxy.conf' | 267 | conf = '/etc/systemd/system/snapd.service.d/proxy.conf' |
292 | 266 | self._create_folder(os.path.dirname(conf)) | 268 | self._create_folder(os.path.dirname(conf)) |
293 | 269 | content = '[Service]\nEnvironment=SNAPD_DEBUG=1\n' | ||
294 | 270 | if self.snapd_https_proxy: | ||
295 | 271 | content += 'Environment=https_proxy={}\n'.format(self.snapd_https_proxy) | ||
296 | 272 | if self.snapd_http_proxy: | ||
297 | 273 | content += 'Environment=http_proxy={}\n'.format(self.snapd_http_proxy) | ||
298 | 267 | self._create_file( | 274 | self._create_file( |
299 | 268 | conf, | 275 | conf, |
302 | 269 | '[Service]\n' | 276 | content) |
301 | 270 | 'Environment=https_proxy={}\n'.format(proxy)) | ||
303 | 271 | subprocess.check_call(['systemctl', 'daemon-reload']) | 277 | subprocess.check_call(['systemctl', 'daemon-reload']) |
304 | 272 | subprocess.check_call(['systemctl', 'restart', 'snapd.service']) | 278 | subprocess.check_call(['systemctl', 'restart', 'snapd.service']) |
305 | 273 | 279 | ||
306 | @@ -599,10 +605,10 @@ | |||
307 | 599 | ['systemctl', 'enable', service_name]) | 605 | ['systemctl', 'enable', service_name]) |
308 | 600 | 606 | ||
309 | 601 | 607 | ||
311 | 602 | def main(config_path, username): | 608 | def main(config_path, snapd_https_proxy, snapd_http_proxy, username): |
312 | 603 | with open(config_path, 'r') as f: | 609 | with open(config_path, 'r') as f: |
313 | 604 | config_json = json.loads(f.read()) | 610 | config_json = json.loads(f.read()) |
315 | 605 | runner = SetupRunner(config_json) | 611 | runner = SetupRunner(config_json, snapd_https_proxy, snapd_http_proxy) |
316 | 606 | try: | 612 | try: |
317 | 607 | runner.run_setup_commands(username) | 613 | runner.run_setup_commands(username) |
318 | 608 | finally: | 614 | finally: |
319 | @@ -612,7 +618,12 @@ | |||
320 | 612 | if __name__ == '__main__': | 618 | if __name__ == '__main__': |
321 | 613 | PARSER = argparse.ArgumentParser(description='Setup target.') | 619 | PARSER = argparse.ArgumentParser(description='Setup target.') |
322 | 614 | PARSER.add_argument('--config_path', help='target config path') | 620 | PARSER.add_argument('--config_path', help='target config path') |
323 | 621 | PARSER.add_argument('--snapd_https_proxy', help='snapd https proxy', default=None) | ||
324 | 622 | PARSER.add_argument('--snapd_http_proxy', help='snapd http proxy', default=None) | ||
325 | 615 | PARSER.add_argument('--username', | 623 | PARSER.add_argument('--username', |
326 | 616 | help='Username to configure the environment') | 624 | help='Username to configure the environment') |
327 | 617 | ARGS = PARSER.parse_args() | 625 | ARGS = PARSER.parse_args() |
329 | 618 | sys.exit(main(ARGS.config_path, ARGS.username)) | 626 | sys.exit(main(ARGS.config_path, |
330 | 627 | ARGS.snapd_https_proxy, | ||
331 | 628 | ARGS.snapd_http_proxy, | ||
332 | 629 | ARGS.username)) | ||
333 | 619 | 630 | ||
334 | === modified file 'ubuntu_system_tests/host/targets.py' | |||
335 | --- ubuntu_system_tests/host/targets.py 2017-08-10 14:11:03 +0000 | |||
336 | +++ ubuntu_system_tests/host/targets.py 2018-01-02 13:43:13 +0000 | |||
337 | @@ -180,10 +180,15 @@ | |||
338 | 180 | def _run_target_setup(self): | 180 | def _run_target_setup(self): |
339 | 181 | self._push_setup_script() | 181 | self._push_setup_script() |
340 | 182 | self._push_setup_config() | 182 | self._push_setup_config() |
345 | 183 | return self.run_sudo( | 183 | command = '/usr/bin/python3 /tmp/target_setup.py --config_path /tmp/target_config.json ' \ |
346 | 184 | '/usr/bin/python3 /tmp/target_setup.py --config_path /tmp/target_config.json ' | 184 | '--username %s' % self.config_stack.get('device_username') |
347 | 185 | '--username %s' % self.config_stack.get('device_username'), | 185 | snapd_https_proxy = self.config_stack.get('snapd_https_proxy') |
348 | 186 | timeout=TIMEOUT_SETUP) | 186 | snapd_http_proxy = self.config_stack.get('snapd_http_proxy') |
349 | 187 | if snapd_https_proxy: | ||
350 | 188 | command += ' --snapd_https_proxy %s' % snapd_https_proxy | ||
351 | 189 | if snapd_http_proxy: | ||
352 | 190 | command += ' --snapd_http_proxy %s' % snapd_http_proxy | ||
353 | 191 | return self.run_sudo(command, timeout=TIMEOUT_SETUP) | ||
354 | 187 | 192 | ||
355 | 188 | def get_config(self, config_stack, args): | 193 | def get_config(self, config_stack, args): |
356 | 189 | """Select the required config items to pass to the target setup | 194 | """Select the required config items to pass to the target setup |
357 | 190 | 195 | ||
358 | === added file 'ubuntu_system_tests/tests/test_snapd.py' | |||
359 | --- ubuntu_system_tests/tests/test_snapd.py 1970-01-01 00:00:00 +0000 | |||
360 | +++ ubuntu_system_tests/tests/test_snapd.py 2018-01-02 13:43:13 +0000 | |||
361 | @@ -0,0 +1,57 @@ | |||
362 | 1 | # -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*- | ||
363 | 2 | |||
364 | 3 | # | ||
365 | 4 | # Ubuntu System Tests | ||
366 | 5 | # Copyright (C) 2017 Canonical | ||
367 | 6 | # | ||
368 | 7 | # This program is free software: you can redistribute it and/or modify | ||
369 | 8 | # it under the terms of the GNU General Public License as published by | ||
370 | 9 | # the Free Software Foundation, either version 3 of the License, or | ||
371 | 10 | # (at your option) any later version. | ||
372 | 11 | # | ||
373 | 12 | # This program is distributed in the hope that it will be useful, | ||
374 | 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
375 | 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
376 | 15 | # GNU General Public License for more details. | ||
377 | 16 | # | ||
378 | 17 | # You should have received a copy of the GNU General Public License | ||
379 | 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
380 | 19 | # | ||
381 | 20 | import os | ||
382 | 21 | |||
383 | 22 | from testtools import skip | ||
384 | 23 | |||
385 | 24 | from ubuntu_system_tests.helpers.snapd.snapd import Snapd | ||
386 | 25 | from ubuntu_system_tests.tests.base import BaseUbuntuSystemTestCase | ||
387 | 26 | |||
388 | 27 | |||
389 | 28 | class TestSnapd(BaseUbuntuSystemTestCase): | ||
390 | 29 | """Tests for snapd""" | ||
391 | 30 | |||
392 | 31 | def setUp(self): | ||
393 | 32 | super(TestSnapd, self).setUp() | ||
394 | 33 | self.snapd = Snapd() | ||
395 | 34 | self.snap_name = 'hello-world' | ||
396 | 35 | |||
397 | 36 | def test_install_snap(self): | ||
398 | 37 | """Install snap and verify it is installed properly""" | ||
399 | 38 | self.snapd.install(self.snap_name) | ||
400 | 39 | self.assertTrue(self.snapd.is_installed(self.snap_name), | ||
401 | 40 | 'The snap %s is not installed' % self.snap_name) | ||
402 | 41 | |||
403 | 42 | def test_find_snap(self): | ||
404 | 43 | """Find a snap and verify it is returned properly""" | ||
405 | 44 | self.assertTrue(self.snapd.find(self.snap_name), | ||
406 | 45 | 'The snap %s was not returned' % self.snap_name) | ||
407 | 46 | |||
408 | 47 | @skip('Skip until snap download issue is solved in venonat') | ||
409 | 48 | def test_download_snap(self): | ||
410 | 49 | """Download a snap and verify it is downloaded properly""" | ||
411 | 50 | snap_dir = self.snapd.download(self.snap_name) | ||
412 | 51 | self.assertTrue(len(os.listdir(snap_dir)) > 0, | ||
413 | 52 | 'The snap %s was not downloaded' % self.snap_name) | ||
414 | 53 | |||
415 | 54 | def tearDown(self): | ||
416 | 55 | super().tearDown() | ||
417 | 56 | if self.snapd.is_installed(self.snap_name): | ||
418 | 57 | self.snapd.remove(self.snap_name) |
PASSED: Continuous integration, rev:572 /platform- qa-jenkins. ubuntu. com/job/ ubuntu- system- tests-ci/ 1307/ /platform- qa-jenkins. ubuntu. com/job/ ust-ubuntu- bionic- desktop- amd64/192 /platform- qa-jenkins. ubuntu. com/job/ generic- update- mp/2424/ console /platform- qa-jenkins. ubuntu. com/job/ ust-build- image-ubuntu- bionic- desktop- amd64/10
https:/
Executed test runs:
UNSTABLE: https:/
None: https:/
SUCCESS: https:/
Click here to trigger a rebuild: /platform- qa-jenkins. ubuntu. com/job/ ubuntu- system- tests-ci/ 1307/rebuild
https:/