Merge lp:~canonical-platform-qa/snappy-ecosystem-tests/fix-trunk-again into lp:snappy-ecosystem-tests

Proposed by Omer Akram
Status: Merged
Approved by: Santiago Baldassin
Approved revision: 44
Merged at revision: 37
Proposed branch: lp:~canonical-platform-qa/snappy-ecosystem-tests/fix-trunk-again
Merge into: lp:snappy-ecosystem-tests
Diff against target: 196 lines (+50/-23)
5 files modified
snappy_ecosystem_tests/environment/containers/lxd.py (+42/-14)
snappy_ecosystem_tests/environment/managers.py (+1/-1)
snappy_ecosystem_tests/environment/setup.py (+1/-4)
snappy_ecosystem_tests/helpers/snapd/snapd.py (+4/-2)
snappy_ecosystem_tests/utils/user.py (+2/-2)
To merge this branch: bzr merge lp:~canonical-platform-qa/snappy-ecosystem-tests/fix-trunk-again
Reviewer Review Type Date Requested Status
Santiago Baldassin (community) Approve
Heber Parrucci (community) Approve
platform-qa-bot continuous-integration Approve
Review via email: mp+319404@code.launchpad.net

Commit message

Fixes trunk by moving the get_ip into the manager. Also adds error reporting in case a command failed to run inside the container.

Description of the change

Fixes trunk by moving the get_ip into the manager. Also adds error reporting in case a command failed to run inside the container.

To post a comment you must log in.
Revision history for this message
platform-qa-bot (platform-qa-bot) wrote :
review: Approve (continuous-integration)
41. By Omer Akram

fix snap commands to actually run

42. By Omer Akram

fix snapd logout

Revision history for this message
platform-qa-bot (platform-qa-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
platform-qa-bot (platform-qa-bot) wrote :
review: Approve (continuous-integration)
43. By Omer Akram

move back get_ip() into the driver

Revision history for this message
platform-qa-bot (platform-qa-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Santiago Baldassin (sbaldassin) wrote :

Code looks good. Minor comment inline

review: Needs Information
44. By Omer Akram

change static methods to members

Revision history for this message
Omer Akram (om26er) wrote :

replied.

Revision history for this message
platform-qa-bot (platform-qa-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Heber Parrucci (heber013) wrote :

LGTM

review: Approve
Revision history for this message
Santiago Baldassin (sbaldassin) wrote :

Code looks good to me

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/containers/lxd.py'
2--- snappy_ecosystem_tests/environment/containers/lxd.py 2017-03-08 17:30:28 +0000
3+++ snappy_ecosystem_tests/environment/containers/lxd.py 2017-03-09 12:41:23 +0000
4@@ -21,8 +21,8 @@
5
6 import os
7 import shlex
8-
9 import logging
10+import time
11
12 from pylxd import Client
13 from pylxd.exceptions import LXDAPIException, NotFound
14@@ -48,7 +48,6 @@
15 """Launch a container"""
16 created_containers = []
17 for cont in containers:
18-
19 if self.client.containers.exists(cont):
20 container = self.client.containers.get(cont)
21 try:
22@@ -62,7 +61,6 @@
23 # not raise an exception:
24 # https://github.com/lxc/pylxd/issues/221
25 pass
26-
27 container_config = DEFAULT_CONTAINER_CONFIG.copy()
28 container_config['source']['alias'] = containers[cont]['release']
29 container_config['name'] = cont
30@@ -72,6 +70,21 @@
31 return created_containers
32
33 @staticmethod
34+ def _execute_command(container, command_string):
35+ """Execute the given string as a command inside the provided container.
36+
37+ :param container: container instance to call command on.
38+ :param command_string: a string containing the command to run.
39+ :return: stdout of the command.
40+ :raises ValueError: If command exists with a non-zero code.
41+ """
42+ response = container.execute(shlex.split(command_string))
43+ if response.exit_code == 0:
44+ LOGGER.info(response.stdout.strip())
45+ return response.stdout.strip()
46+ raise ValueError(response.stderr.strip())
47+
48+ @staticmethod
49 def start(containers):
50 """start all containers received as parameter"""
51 for cont in containers:
52@@ -81,12 +94,12 @@
53 @staticmethod
54 def install(container, packages, channel=None):
55 """Install packages"""
56- container.execute(shlex.split('apt-get update'))
57+ LXDDriver._execute_command(container, 'apt-get update')
58 install_command = 'apt-get install {} -y'.format(
59 ' '.join(packages))
60 if channel:
61 install_command += ' -t {}'.format(channel)
62- container.execute(shlex.split(install_command))
63+ LXDDriver._execute_command(container, install_command)
64
65 @staticmethod
66 @retry(stop_max_attempt_number=5, wait_fixed=3000,
67@@ -98,11 +111,10 @@
68 os.path.expanduser('~') + '/.ssh/id_rsa.pub').read().strip('\n')
69 container.files.put('/home/ubuntu/.ssh/authorized_keys', pub_key)
70
71- @staticmethod
72- def get_ip(container):
73+ def get_ip(self, container_name):
74 """Gets the ip address for a given container"""
75+ container = self.client.containers.get(container_name)
76 networks = container.state().network['eth0']['addresses']
77-
78 for network in networks:
79 if network['address']:
80 return network['address']
81@@ -110,10 +122,26 @@
82 "The container {} does not have an IPV4 connection".format(
83 container.name))
84
85- @staticmethod
86- def export_environment_variables(container,
87- environment_variables):
88+ def export_environment_variables(self, container, environment_variables):
89 """Allow export of environment variables over ssh."""
90- container.execute(shlex.split(COMMAND_ALLOW_ENV_VARS.format(
91- ' '.join(environment_variables))))
92- container.execute(shlex.split('service ssh restart'))
93+ self._execute_command(
94+ container,
95+ COMMAND_ALLOW_ENV_VARS.format(' '.join(environment_variables)))
96+ self._execute_command(container, 'service ssh restart')
97+
98+ def wait_for_internet(self, container, attempts_count=10,
99+ attempt_interval=1, ping_domain=DOMAIN_PING):
100+ """Wait for internet connectivity in the container."""
101+ for _ in range(attempts_count):
102+ try:
103+ self._execute_command(
104+ container, 'ping -c 1 {}'.format(ping_domain))
105+ break
106+ except ValueError:
107+ LOGGER.info('Sleeping for %s second(s)', attempt_interval)
108+ time.sleep(attempt_interval)
109+ else:
110+ raise ValueError(
111+ 'Failed to get internet access in container {} after {} '
112+ 'seconds'.format(container.name,
113+ attempts_count * attempt_interval))
114
115=== modified file 'snappy_ecosystem_tests/environment/managers.py'
116--- snappy_ecosystem_tests/environment/managers.py 2017-03-08 17:30:28 +0000
117+++ snappy_ecosystem_tests/environment/managers.py 2017-03-09 12:41:23 +0000
118@@ -42,8 +42,8 @@
119 def setup(self, profile):
120 """setup the container based on the profile"""
121 containers = self.driver.launch(CONTAINERS)
122-
123 for cont in containers:
124+ self.driver.wait_for_internet(cont)
125 deps = DEPENDENCIES[cont.name] + DEPENDENCIES["shared"]
126 self.driver.install(cont, packages=deps)
127 self.driver.install(
128
129=== modified file 'snappy_ecosystem_tests/environment/setup.py'
130--- snappy_ecosystem_tests/environment/setup.py 2017-03-08 17:30:28 +0000
131+++ snappy_ecosystem_tests/environment/setup.py 2017-03-09 12:41:23 +0000
132@@ -36,10 +36,8 @@
133
134 def get_manager(mode):
135 """Get the manager for the given mode"""
136-
137 try:
138- manager = SUPPORTED_MODULES[mode]
139- return manager()
140+ return SUPPORTED_MODULES[mode]()
141 except KeyError:
142 raise RuntimeError("Mode: {} is not supported".format(mode))
143
144@@ -58,5 +56,4 @@
145 PARSER.add_argument('--profile', default="staging",
146 help='Profile to configure the environment')
147 ARGS = PARSER.parse_args()
148-
149 main(ARGS.mode, ARGS.profile)
150
151=== modified file 'snappy_ecosystem_tests/helpers/snapd/snapd.py'
152--- snappy_ecosystem_tests/helpers/snapd/snapd.py 2017-03-08 17:37:52 +0000
153+++ snappy_ecosystem_tests/helpers/snapd/snapd.py 2017-03-09 12:41:23 +0000
154@@ -69,8 +69,10 @@
155 the command should run.
156 :returns: stdout of the command
157 """
158+ if not command.startswith(PATH_SNAP):
159+ command = '{} {}'.format(PATH_SNAP, command)
160 if cwd:
161- command = '{};{}'.format(cwd, command)
162+ command = '{}; {}'.format(cwd, command)
163 return self.ssh.exec_command(command)
164
165 def login(self, email, password):
166@@ -95,7 +97,7 @@
167 def logout(self, email):
168 """Logout snapd current user."""
169 if self.is_logged_in(email):
170- self.ssh.exec_command(COMMAND_LOGOUT)
171+ self.run_snapd_command_ssh(COMMAND_LOGOUT)
172
173 def download(self, snap, channel=CHANNEL_STABLE):
174 """Download the requested snap.
175
176=== modified file 'snappy_ecosystem_tests/utils/user.py'
177--- snappy_ecosystem_tests/utils/user.py 2017-03-06 17:09:46 +0000
178+++ snappy_ecosystem_tests/utils/user.py 2017-03-09 12:41:23 +0000
179@@ -30,7 +30,7 @@
180
181 def get_snapd_remote_host_credentials():
182 """Return credentials for snapd remote machine, to run commands on."""
183- _ip = MANAGER.get_ip(USER_CONFIG_STACK.get(
184+ _ip = MANAGER.driver.get_ip(USER_CONFIG_STACK.get(
185 'user', 'snapd_hostname_remote',
186 default=os.environ.get('snapd_hostname_remote')))
187 return (_ip,
188@@ -44,7 +44,7 @@
189
190 def get_snapcraft_remote_host_credentials():
191 """Return credentials for snapcraft remote machine, to run commands on."""
192- _ip = MANAGER.get_ip(USER_CONFIG_STACK.get(
193+ _ip = MANAGER.driver.get_ip(USER_CONFIG_STACK.get(
194 'user', 'snapcraft_hostname_remote',
195 default=os.environ.get('snapcraft_snapcraft_remote')))
196 return (_ip,

Subscribers

People subscribed via source and target branches