Merge lp:~canonical-platform-qa/snappy-ecosystem-tests/spring-cleanup into lp:snappy-ecosystem-tests
- spring-cleanup
- Merge into trunk
Proposed by
Omer Akram
Status: | Merged |
---|---|
Approved by: | Santiago Baldassin |
Approved revision: | 39 |
Merged at revision: | 38 |
Proposed branch: | lp:~canonical-platform-qa/snappy-ecosystem-tests/spring-cleanup |
Merge into: | lp:snappy-ecosystem-tests |
Diff against target: |
337 lines (+1/-296) 4 files modified
snappy_ecosystem_tests/environment/data/snapd.py (+0/-65) snappy_ecosystem_tests/helpers/snapd/staging_builder.py (+0/-97) snappy_ecosystem_tests/utils/lxd.py (+0/-125) snappy_ecosystem_tests/utils/ssh.py (+1/-9) |
To merge this branch: | bzr merge lp:~canonical-platform-qa/snappy-ecosystem-tests/spring-cleanup |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Santiago Baldassin (community) | Approve | ||
platform-qa-bot | continuous-integration | Approve | |
Review via email: mp+319475@code.launchpad.net |
Commit message
Remove unused lxd related code.
Description of the change
Remove unused lxd related code.
To post a comment you must log in.
Revision history for this message
platform-qa-bot (platform-qa-bot) wrote : | # |
review:
Approve
(continuous-integration)
- 39. By Omer Akram
-
More unused code removals
Revision history for this message
platform-qa-bot (platform-qa-bot) wrote : | # |
PASSED: Continuous integration, rev:39
https:/
Executed test runs:
None: https:/
Click here to trigger a rebuild:
https:/
review:
Approve
(continuous-integration)
Revision history for this message
Omer Akram (om26er) wrote : | # |
Note, I have removed the code that was trying to do set environment variables over ssh as those variables were not really doing anything. Snapd decides during runtime based on environment variable in /etc/environment if it should enable staging servers or not.
snapd only reads SNAPPY_
Revision history for this message
Santiago Baldassin (sbaldassin) wrote : | # |
Looks good
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'snappy_ecosystem_tests/environment/data/snapd.py' |
2 | --- snappy_ecosystem_tests/environment/data/snapd.py 2017-03-06 17:09:46 +0000 |
3 | +++ snappy_ecosystem_tests/environment/data/snapd.py 2017-03-09 17:27:27 +0000 |
4 | @@ -20,71 +20,6 @@ |
5 | """snapd data""" |
6 | SNAPD_CONTAINER_NAME = 'snapd' |
7 | |
8 | -CONTAINER_HOME = '/root' |
9 | -DIRECTORY_CLONE = '{}/src/github.com/snapcore/snapd'.format(CONTAINER_HOME) |
10 | -DOMAIN_PING = 'ubuntu.com' |
11 | -ENV_STORE_API_ROOT = 'UBUNTU_STORE_API_ROOT_URL' |
12 | -ENV_STORE_SEARCH_ROOT = 'UBUNTU_STORE_SEARCH_ROOT_URL' |
13 | -ENV_STORE_UPLOAD_ROOT = 'UBUNTU_STORE_UPLOAD_ROOT_URL' |
14 | -ENV_SSO_API_ROOT = 'UBUNTU_SSO_API_ROOT_URL' |
15 | -PACKAGES_SNAPD = ['snapd', 'snap-confine', 'ubuntu-core-launcher'] |
16 | -COMMAND_REMOVE_SNAPD = 'apt purge -y {}'.format(' '.join(PACKAGES_SNAPD)) |
17 | -COMMAND_APT_BUILD_DEP = 'apt build-dep -y ./' |
18 | -COMMAND_APT_INSTALL = 'apt install -y {}' |
19 | -COMMAND_APT_INSTALL_STAGING_DEBS = COMMAND_APT_INSTALL.format( |
20 | - ' '.join(['../{}*.deb'.format(pkg) for pkg in PACKAGES_SNAPD])) |
21 | -COMMAND_APT_UPDATE = 'apt update' |
22 | -COMMAND_APT_UPGRADE = 'apt dist-upgrade -y' |
23 | -COMMAND_BUILD_SNAPD = 'DEB_BUILD_OPTIONS="nocheck testkeys" ' \ |
24 | - 'dpkg-buildpackage -tc -b' |
25 | -COMMAND_EXPORT_STAGING_STORE_VAR = 'echo SNAPPY_USE_STAGING_STORE=1 >> ' \ |
26 | - '/etc/environment' |
27 | -COMMAND_GET_GOVENDOR = 'go get -v github.com/kardianos/govendor' |
28 | -COMMAND_GIT_CLONE = 'git clone {} {}' |
29 | -COMMAND_GOVENDOR_SYNC = 'govendor sync' |
30 | -REPOSITORY_GIT = 'https://github.com/snapcore/snapd' |
31 | -URL_API_ROOT = 'https://myapps.developer.staging.ubuntu.com/dev/api/' |
32 | -URL_SEARCH_ROOT = 'https://search.apps.staging.ubuntu.com/' |
33 | -URL_UPLOAD_ROOT = 'https://upload.apps.staging.ubuntu.com/' |
34 | -URL_SSO_API_ROOT = 'https://login.staging.ubuntu.com/api/v2/' |
35 | - |
36 | -CONTAINER_SETUP = [ |
37 | - COMMAND_REMOVE_SNAPD, |
38 | - COMMAND_APT_UPDATE, |
39 | - # Hold open-iscsi which is causing apt upgrade errors while running |
40 | - # inside container. |
41 | - 'apt-mark hold open-iscsi', |
42 | - COMMAND_APT_UPGRADE, |
43 | - # Needed for snaps to work inside a lxd container |
44 | - # ref: https://stgraber.org/2016/12/07/running-snaps-in-lxd-containers/ |
45 | - COMMAND_APT_INSTALL.format('squashfuse'), |
46 | - COMMAND_GIT_CLONE.format(REPOSITORY_GIT, DIRECTORY_CLONE), |
47 | - {'command': COMMAND_APT_BUILD_DEP, 'cwd': DIRECTORY_CLONE}, |
48 | - {'command': COMMAND_GET_GOVENDOR, 'cwd': DIRECTORY_CLONE}, |
49 | - {'command': COMMAND_GOVENDOR_SYNC, 'cwd': DIRECTORY_CLONE}, |
50 | - {'command': COMMAND_BUILD_SNAPD, 'cwd': DIRECTORY_CLONE}, |
51 | - COMMAND_EXPORT_STAGING_STORE_VAR, |
52 | - {'command': COMMAND_APT_INSTALL_STAGING_DEBS, 'cwd': DIRECTORY_CLONE} |
53 | -] |
54 | - |
55 | -SNAPCRAFT_STAGING_VARIABLES = { |
56 | - ENV_STORE_API_ROOT: URL_API_ROOT, |
57 | - ENV_STORE_SEARCH_ROOT: URL_SEARCH_ROOT, |
58 | - ENV_STORE_UPLOAD_ROOT: URL_UPLOAD_ROOT, |
59 | - ENV_SSO_API_ROOT: URL_SSO_API_ROOT, |
60 | -} |
61 | - |
62 | -SNAPD_STAGING_VARIABLES = { |
63 | - 'SNAPPY_USE_STAGING_STORE': '1' |
64 | -} |
65 | - |
66 | -STAGING_VARIABLES = dict( |
67 | - SNAPCRAFT_STAGING_VARIABLES, **SNAPD_STAGING_VARIABLES) |
68 | - |
69 | -CONTAINER_ENV_VARS = { |
70 | - 'GOPATH': CONTAINER_HOME, |
71 | -} |
72 | - |
73 | DEFAULT_CONTAINER_CONFIG = { |
74 | "name": "snapd", |
75 | "source": { |
76 | |
77 | === removed file 'snappy_ecosystem_tests/helpers/snapd/staging_builder.py' |
78 | --- snappy_ecosystem_tests/helpers/snapd/staging_builder.py 2017-03-02 10:51:37 +0000 |
79 | +++ snappy_ecosystem_tests/helpers/snapd/staging_builder.py 1970-01-01 00:00:00 +0000 |
80 | @@ -1,97 +0,0 @@ |
81 | -# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*- |
82 | - |
83 | -# |
84 | -# Snappy Ecosystem Tests |
85 | -# Copyright (C) 2017 Canonical |
86 | -# |
87 | -# This program is free software: you can redistribute it and/or modify |
88 | -# it under the terms of the GNU General Public License as published by |
89 | -# the Free Software Foundation, either version 3 of the License, or |
90 | -# (at your option) any later version. |
91 | -# |
92 | -# This program is distributed in the hope that it will be useful, |
93 | -# but WITHOUT ANY WARRANTY; without even the implied warranty of |
94 | -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
95 | -# GNU General Public License for more details. |
96 | -# |
97 | -# You should have received a copy of the GNU General Public License |
98 | -# along with this program. If not, see <http://www.gnu.org/licenses/>. |
99 | -# |
100 | - |
101 | -"""Module to enable staging environment for snapd.""" |
102 | - |
103 | -import logging |
104 | -import sys |
105 | -from time import sleep |
106 | - |
107 | -from snappy_ecosystem_tests.environment.data.snapd import ( |
108 | - CONTAINER_HOME, CONTAINER_ENV_VARS, CONTAINER_SETUP) |
109 | -from snappy_ecosystem_tests.utils.lxd import Container, launch_container |
110 | - |
111 | -LOGGER = logging.getLogger(__name__) |
112 | - |
113 | - |
114 | -class StagingBuilder: |
115 | - """Class to build and activate snapd staging environment.""" |
116 | - def __init__(self, container): |
117 | - if not isinstance(container, Container): |
118 | - raise RuntimeError( |
119 | - '`container` must be an instance of ' |
120 | - 'snappy_ecosystem_tests.utils.lxd.Container') |
121 | - self.container = container |
122 | - |
123 | - def _setup_staging(self): |
124 | - """Export environment variables required to enable snapd/snapcraft |
125 | - staging.""" |
126 | - LOGGER.info('Exporting staging environment variables') |
127 | - updated_path = '{}/bin:{}'.format( |
128 | - CONTAINER_HOME, self.container.execute('echo $PATH')) |
129 | - CONTAINER_ENV_VARS['PATH'] = updated_path |
130 | - for key, value in CONTAINER_ENV_VARS.items(): |
131 | - self.container.set_environment_variable(key, value, save=False) |
132 | - self.container.save(wait=True) |
133 | - LOGGER.info('Exported staging environment variables') |
134 | - |
135 | - def _wait_for_internet(self, attempts_count=10, attempt_interval=1): |
136 | - """Wait for internet connectivity in the container.""" |
137 | - for _ in range(attempts_count): |
138 | - if self.container.is_internet_working(): |
139 | - break |
140 | - else: |
141 | - LOGGER.info('Sleeping for %s second(s)', attempt_interval) |
142 | - sleep(attempt_interval) |
143 | - else: |
144 | - LOGGER.error( |
145 | - 'Failed to get internet access in container %s after %s ' |
146 | - 'seconds', self.container.name, |
147 | - attempts_count * attempt_interval) |
148 | - sys.exit(1) |
149 | - |
150 | - def _setup_and_build(self): |
151 | - """Setup the container, pulls and builds snapd with staging enabled. |
152 | - """ |
153 | - for command in CONTAINER_SETUP: |
154 | - if isinstance(command, dict): |
155 | - self.container.execute(**command) |
156 | - else: |
157 | - self.container.execute(command) |
158 | - |
159 | - def build(self): |
160 | - """Setup lxd container environment for snapd staging enabled builds.""" |
161 | - self._setup_staging() |
162 | - self._wait_for_internet() |
163 | - self._setup_and_build() |
164 | - |
165 | - |
166 | -if __name__ == '__main__': |
167 | - # TODO remove local import |
168 | - import argparse |
169 | - logging.basicConfig(level=logging.INFO) |
170 | - PARSER = argparse.ArgumentParser( |
171 | - description='Builder for snapd staging environment.') |
172 | - PARSER.add_argument('container_name', help='name for the new container.') |
173 | - PARSER.add_argument( |
174 | - 'ubuntu_release', help='Ubuntu release version for the container.') |
175 | - ARGS = PARSER.parse_args() |
176 | - StagingBuilder(launch_container(name=ARGS.container_name, |
177 | - release=ARGS.ubuntu_release)).build() |
178 | |
179 | === removed file 'snappy_ecosystem_tests/utils/lxd.py' |
180 | --- snappy_ecosystem_tests/utils/lxd.py 2017-02-21 13:46:08 +0000 |
181 | +++ snappy_ecosystem_tests/utils/lxd.py 1970-01-01 00:00:00 +0000 |
182 | @@ -1,125 +0,0 @@ |
183 | -# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*- |
184 | - |
185 | -# |
186 | -# Snappy Ecosystem Tests |
187 | -# Copyright (C) 2017 Canonical |
188 | -# |
189 | -# This program is free software: you can redistribute it and/or modify |
190 | -# it under the terms of the GNU General Public License as published by |
191 | -# the Free Software Foundation, either version 3 of the License, or |
192 | -# (at your option) any later version. |
193 | -# |
194 | -# This program is distributed in the hope that it will be useful, |
195 | -# but WITHOUT ANY WARRANTY; without even the implied warranty of |
196 | -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
197 | -# GNU General Public License for more details. |
198 | -# |
199 | -# You should have received a copy of the GNU General Public License |
200 | -# along with this program. If not, see <http://www.gnu.org/licenses/>. |
201 | -# |
202 | - |
203 | -"""Module to manipulate lxd containers.""" |
204 | - |
205 | -import logging |
206 | -import shlex |
207 | - |
208 | -import pylxd |
209 | -from pylxd import models |
210 | - |
211 | -DEFAULT_CONTAINER_CONFIG = { |
212 | - 'name': 'snapd', |
213 | - 'source': { |
214 | - 'type': 'image', |
215 | - 'protocol': 'simplestreams', |
216 | - 'server': 'https://cloud-images.ubuntu.com/daily', |
217 | - 'alias': '16.04' |
218 | - } |
219 | -} |
220 | -DOMAIN_PING = 'ubuntu.com' |
221 | -LOGGER = logging.getLogger(__name__) |
222 | - |
223 | - |
224 | -def launch_container(name, release, delete_existing=True): |
225 | - """Launch a lxd container of the requested name and release and return |
226 | - its object.""" |
227 | - lxd_client = pylxd.Client() |
228 | - if delete_existing and lxd_client.containers.exists(name): |
229 | - Container(lxd_client.containers.get(name)).delete() |
230 | - container_config = DEFAULT_CONTAINER_CONFIG.copy() |
231 | - container_config['source']['alias'] = release |
232 | - container_config['name'] = name |
233 | - container = Container( |
234 | - lxd_client.containers.create(container_config, wait=True)) |
235 | - container.start(wait=True) |
236 | - return container |
237 | - |
238 | - |
239 | -class Container: |
240 | - """A Class representing a lxd container. |
241 | - |
242 | - Extends and overrides some functionalities of pylxd.models.Container |
243 | - instance through delegation since that class does not support inheritance. |
244 | - """ |
245 | - def __init__(self, container_instance): |
246 | - # TODO: move to inheritance once upstream supports it. |
247 | - if not isinstance(container_instance, models.Container): |
248 | - raise RuntimeError( |
249 | - '`container_instance` must be an instance of ' |
250 | - 'pylxd.models.Container' |
251 | - ) |
252 | - #TODO: Remove this as the StageBuilder class already has an |
253 | - # instance of the container |
254 | - self._delegate = container_instance |
255 | - |
256 | - def __getattr__(self, name): |
257 | - """Set the container instance as delegate.""" |
258 | - return getattr(self._delegate, name) |
259 | - |
260 | - @staticmethod |
261 | - def _assemble_container_commands(command, cwd=''): |
262 | - """Format and split the requested command to be container friendly.""" |
263 | - exec_command_base = 'sh -c \'{}\'' |
264 | - if cwd: |
265 | - command = 'cd {}; {}'.format(cwd, command) |
266 | - LOGGER.info('Run command: %s', command) |
267 | - return shlex.split(exec_command_base.format(command)) |
268 | - |
269 | - #TODO move the following methods to another place which does not require |
270 | - # a container class |
271 | - def execute(self, command, environment=None, cwd=''): |
272 | - """Execute command in the container.""" |
273 | - response = self._delegate.execute( |
274 | - self._assemble_container_commands(command, cwd=cwd), |
275 | - environment=environment or {} |
276 | - ) |
277 | - if response.exit_code == 0: |
278 | - LOGGER.info(response.stdout) |
279 | - return response.stdout.strip() |
280 | - raise ValueError(response.stderr) |
281 | - |
282 | - def set_environment_variable(self, key, value, save=True): |
283 | - """Exports environment variable to be available to |
284 | - Container.execute().""" |
285 | - self._delegate.config.update({'environment.{}'.format(key): value}) |
286 | - if save: |
287 | - self._delegate.save(wait=True) |
288 | - |
289 | - def is_running(self): |
290 | - """Returns bool representing whether the container is running.""" |
291 | - return self._delegate.status == 'Running' |
292 | - |
293 | - def delete(self, stop=True, wait=True): |
294 | - """Stops and deletes the container.""" |
295 | - if stop and self.is_running(): |
296 | - self._delegate.stop(wait=True) |
297 | - LOGGER.info('Deleting container %s', self.name) |
298 | - self._delegate.delete(wait=wait) |
299 | - LOGGER.info('Deleted container %s', self.name) |
300 | - |
301 | - def is_internet_working(self, ping_domain=DOMAIN_PING): |
302 | - """Return bool representing if the container have internet access.""" |
303 | - try: |
304 | - self.execute('ping -c 1 {}'.format(ping_domain)) |
305 | - return True |
306 | - except ValueError: |
307 | - return False |
308 | |
309 | === modified file 'snappy_ecosystem_tests/utils/ssh.py' |
310 | --- snappy_ecosystem_tests/utils/ssh.py 2017-03-07 13:53:31 +0000 |
311 | +++ snappy_ecosystem_tests/utils/ssh.py 2017-03-09 17:27:27 +0000 |
312 | @@ -24,9 +24,6 @@ |
313 | |
314 | import paramiko |
315 | |
316 | -from snappy_ecosystem_tests.utils.storeconfig import get_current_store |
317 | -from snappy_ecosystem_tests.environment.data.snapd import STAGING_VARIABLES |
318 | - |
319 | LOGGER = logging.getLogger(__name__) |
320 | |
321 | |
322 | @@ -36,14 +33,9 @@ |
323 | def exec_command(self, command, bufsize=-1, timeout=None, get_pty=False, |
324 | environment=None): |
325 | """Execute the given command over ssh.""" |
326 | - if environment is None: |
327 | - # FIXME: get environment variables dinamically |
328 | - if get_current_store() == 'staging': |
329 | - environment = STAGING_VARIABLES |
330 | _, stdout, stderr = super().exec_command( |
331 | command, bufsize, timeout, |
332 | - get_pty, |
333 | - environment=environment) |
334 | + get_pty, environment=environment) |
335 | if stdout.channel.recv_exit_status() != 0: |
336 | raise ValueError(stderr.read().decode().strip()) |
337 | response = stdout.read().decode().strip() |
PASSED: Continuous integration, rev:38 /platform- qa-jenkins. ubuntu. com/job/ snappy- ecosystem- tests-ci/ 272/ /platform- qa-jenkins. ubuntu. com/job/ generic- update- mp/2094/ console
https:/
Executed test runs:
None: https:/
Click here to trigger a rebuild: /platform- qa-jenkins. ubuntu. com/job/ snappy- ecosystem- tests-ci/ 272/rebuild
https:/