Merge lp:~canonical-platform-qa/ubuntu-system-tests/temp_config_files into lp:ubuntu-system-tests

Proposed by Sergio Cazzolato
Status: Work in progress
Proposed branch: lp:~canonical-platform-qa/ubuntu-system-tests/temp_config_files
Merge into: lp:ubuntu-system-tests
Diff against target: 358 lines (+103/-49)
8 files modified
README.rst (+9/-7)
debian/tests/control (+2/-2)
debian/tests/systemtests (+2/-0)
ubuntu_system_tests/command_line.py (+4/-5)
ubuntu_system_tests/config.py (+75/-26)
ubuntu_system_tests/selftests/test_command_line.py (+6/-5)
ubuntu_system_tests/selftests/test_config.py (+3/-3)
ubuntu_system_tests/systemtests.py (+2/-1)
To merge this branch: bzr merge lp:~canonical-platform-qa/ubuntu-system-tests/temp_config_files
Reviewer Review Type Date Requested Status
platform-qa-bot continuous-integration Needs Fixing
Christopher Lee (community) Needs Fixing
Max Brustkern (community) Approve
PS Jenkins bot continuous-integration Approve
prod-platform-qa continuous-integration Pending
Sergio Cazzolato Pending
Review via email: mp+268839@code.launchpad.net

Commit message

Fix to make possible to use temp config file for regular config data

To post a comment you must log in.
Revision history for this message
Sergio Cazzolato (sergio-j-cazzolato) wrote :

Still missing to fix the tests

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
155. By Sergio Cazzolato

Fixing unit tests

156. By Sergio Cazzolato

Fix leak and add documentation to readme.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Max Brustkern (nuclearbob) wrote :

Running without human interaction is my main use case. As an aside, the idea of the test runner altering it's config file every run is fairly concerning to me anyway; it seems like it could introduce race conditions when more than one instance runs simultaneously. Maybe this needs to be a bigger change discussed with more of the team?

Revision history for this message
Sergio Cazzolato (sergio-j-cazzolato) wrote :

Currently you are able to pass a config file as parameter for the tests execution.

What do you think about of pre-create all the config files that you need and then invoque the tests using the config file that you need?

Another alternative is that the test runner creates on the fly the config file and pass it as parameter to the test.

Revision history for this message
Max Brustkern (nuclearbob) wrote :

I think this should work well.

review: Approve
Revision history for this message
Christopher Lee (veebers) wrote :

Just a couple of minor things I came across when I was poking around.

review: Needs Fixing
Revision history for this message
platform-qa-bot (platform-qa-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
platform-qa-bot (platform-qa-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
platform-qa-bot (platform-qa-bot) wrote :
review: Needs Fixing (continuous-integration)

Unmerged revisions

156. By Sergio Cazzolato

Fix leak and add documentation to readme.

155. By Sergio Cazzolato

Fixing unit tests

154. By Sergio Cazzolato

Fix to make possible to use temp config file for regular config data

153. By Sergio Cazzolato

Adding fix to delete the config files just when these are temporal

152. By Max Brustkern

Don't delete config path

151. By Max Brustkern

Cleaning up temp files

150. By Max Brustkern

Remove remaining use of hardcoded /tmp file on host

149. By Max Brustkern

Added non-static config file on host

148. By Max Brustkern

Separate host and device config file paths

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'README.rst'
2--- README.rst 2015-07-08 10:43:02 +0000
3+++ README.rst 2015-08-23 04:04:32 +0000
4@@ -82,14 +82,16 @@
5 test.option1=test value 1
6 test.option2=test value 2
7
8-The default file is *~/.config/ubuntu-system-tests.conf*, but you can use a
9-different file by passing it to the run command. See the `Run` section for more
10-details.
11+By default, if the file *~/.config/ubuntu-system-tests.conf* is created, it
12+will be used, but you can use a different file by passing it to the run
13+command. See the `Run` section for more details.
14
15-If you don't have that file created the first time you run the tests, you will
16-be prompted to enter values for all the options defined as mandatory. The
17-values you provide in this interactive wizard will be saved to the conf file
18-so they are kept for the following runs.
19+If you don't have the config file created, a temporary config file will be
20+used to run the tests (allowing to run more than once test execution in
21+parallel fron the host machine). You will be prompted to enter values for all
22+the options defined as mandatory. The values you provide in this interactive
23+wizard will be used to run the current execution but won't be saved to any
24+conf file.
25
26 Copy data files to test server
27 ------------------------------
28
29=== modified file 'debian/tests/control'
30--- debian/tests/control 2015-08-18 16:20:29 +0000
31+++ debian/tests/control 2015-08-23 04:04:32 +0000
32@@ -7,7 +7,7 @@
33 gallery-app-autopilot,
34 mediaplayer-app-autopilot,
35 messaging-app-autopilot,
36- oxideqt-chromedriver,
37+ #oxideqt-chromedriver,
38 python3-autopilot,
39 python3-dbus,
40 python3-debian,
41@@ -15,7 +15,7 @@
42 python3-paramiko,
43 python3-requests,
44 python3-retrying,
45- python3-selenium,
46+ #python3-selenium,
47 python3-testtools,
48 python3-warlock,
49 subunit,
50
51=== modified file 'debian/tests/systemtests'
52--- debian/tests/systemtests 2015-07-01 05:13:40 +0000
53+++ debian/tests/systemtests 2015-08-23 04:04:32 +0000
54@@ -20,6 +20,8 @@
55
56 import sys
57
58+sys.path.append('.')
59+
60 from ubuntu_system_tests import systemtests
61
62
63
64=== modified file 'ubuntu_system_tests/command_line.py'
65--- ubuntu_system_tests/command_line.py 2015-08-11 09:26:08 +0000
66+++ ubuntu_system_tests/command_line.py 2015-08-23 04:04:32 +0000
67@@ -53,7 +53,7 @@
68 parser = ArgumentParser('Run system tests for Ubuntu Touch.')
69 parser.add_argument('--config', '-c',
70 help='The config file to use for this run.',
71- default='ubuntu-system-tests.conf')
72+ default=None)
73 parser.add_argument(
74 '--update-apt', '-u', action='store_true',
75 help='Update apt lists before installing the dependencies',
76@@ -86,7 +86,6 @@
77
78 enable_autopilot_introspection(config_stack)
79 return_code = run_autopkg_test(config_stack, update_apt, network_ready)
80- config.delete_temporal_config_file()
81
82 if return_code <= 6:
83 # Return codes higher than 6 mean that there was a problem with adt or
84@@ -135,7 +134,7 @@
85 """
86 config.register_test_options()
87
88- config_stack = config.UbuntuSystemTestsStack(conf_name)
89+ config_stack = config.get_host_config_stack(conf_name)
90
91 # We set the values passed from the command line to send them from the host
92 # to the testbed.
93@@ -280,9 +279,9 @@
94
95 def _add_copy_to_temp_config_file(run_cmd):
96 """ Add the copy parameter for the temp config file to the command line"""
97- if os.path.isfile(config.get_device_config_temp_file_path()):
98+ if os.path.isfile(config.get_host_config_temp_file_path()):
99 run_cmd.extend(['--copy', '{src}:{dest}'.format(
100- src=config.get_device_config_temp_file_path(),
101+ src=config.get_host_config_temp_file_path(),
102 dest=config.get_device_config_temp_file_path())])
103
104
105
106=== modified file 'ubuntu_system_tests/config.py'
107--- ubuntu_system_tests/config.py 2015-08-11 15:25:10 +0000
108+++ ubuntu_system_tests/config.py 2015-08-23 04:04:32 +0000
109@@ -21,6 +21,8 @@
110 import logging
111 import os
112
113+from tempfile import mkstemp
114+
115 from uciconfig import (
116 options,
117 stacks,
118@@ -126,33 +128,46 @@
119 return '/tmp/ubuntu-system-tests.conf'
120
121
122+def get_host_config_temp_file_path():
123+ """Return the path of the config file with temporal data copied to the
124+ device."""
125+ global config_stack
126+ if not config_stack:
127+ return ''
128+ return get_host_config_stack().host_temp_config_file
129+
130+
131 def get_device_config_temp_file_path():
132 """Return the path of the config file with temporal data copied to the
133 device."""
134 return '/tmp/ubuntu-system-tests-temp.conf'
135
136
137-def get_config_stack_from_file(file_path):
138- """Return config stack from specified file path."""
139- return UbuntuSystemTestsStack(file_path)
140-
141-
142 def get_device_config_stack():
143- """Return the config stack variable"""
144+ """Return the config stack variable in the device"""
145 global config_stack
146 if not config_stack:
147- config_stack = get_config_stack_from_file(
148- get_device_config_file_path())
149+ config_stack = \
150+ UbuntuSystemTestsStack(get_device_config_file_path(),
151+ get_device_config_temp_file_path())
152 _add_temp_values_to_config_stack(config_stack)
153 return config_stack
154
155
156+def get_host_config_stack(config_name=None, temp_path=None):
157+ """Return the config stack variable in the host machine"""
158+ global config_stack
159+ if not config_stack:
160+ config_stack = UbuntuSystemTestsStack(config_name, temp_path)
161+ return config_stack
162+
163+
164 def _add_temp_values_to_config_stack(stack):
165 """ Add the temporal data to the config stack. The temporal data is
166 retrieved from the temporal config file which is deleted after the values
167 are read
168 """
169- tmp_tuples = _get_temp_config_values()
170+ tmp_tuples = _get_temp_config_values(stack.host_temp_config_file)
171
172 try:
173 for pair in tmp_tuples:
174@@ -162,12 +177,12 @@
175 logger.error("Incorrect format for temporal variables.")
176
177
178-def _get_temp_config_values(delete=True):
179+def _get_temp_config_values(temp_path):
180 """ Read the the temporal config values and delete the temp file if it is
181 requested.
182 """
183- if os.path.isfile(get_device_config_temp_file_path()):
184- with open(get_device_config_temp_file_path(), 'r') as f:
185+ if os.path.isfile(temp_path):
186+ with open(temp_path, 'r') as f:
187 data = f.read()
188
189 return data.split(',')
190@@ -180,38 +195,72 @@
191 the test execution
192 :param temp_items: A dict with the items to store
193 """
194- delete_temporal_config_file()
195-
196- with open(get_device_config_temp_file_path(), 'w') as file:
197+ with open(get_host_config_temp_file_path(), 'w') as file:
198 for item, value in temp_items.items():
199 file.write('{item}={value}'.format(item=item, value=value))
200
201
202-def delete_temporal_config_file():
203- """Delete the temporal config stack file"""
204- if os.path.isfile(get_device_config_temp_file_path()):
205- os.remove(get_device_config_temp_file_path())
206-
207-
208 def get_test_config_values(config_stack):
209 """Returns a string containing the comma separated key=value options.
210 The list includes the cofig values and the temporal ones as well"""
211 values = config_stack.get_autopilot_config_string()
212- tmp_vars = _get_temp_config_values()
213+ tmp_vars = _get_temp_config_values(config_stack.host_temp_config_file)
214
215 return '{values},{temp}'.format(values=values, temp=tmp_vars)
216
217
218 class UbuntuSystemTestsStack(stacks.Stack):
219
220- def __init__(self, conf_name='ubuntu-system-tests.conf'):
221- config_path = os.path.join(
222- get_user_config_dir(), conf_name)
223- user_store = self.get_shared_store(UbuntuSystemTestsStore(config_path))
224+ DEFAULT_CONFIG = 'ubuntu-system-tests.conf'
225+
226+ def __init__(self, config_name=None, temp_path=None):
227+
228+ # If either an specific config name hs been requested or the default
229+ # config file already exists, set it as config file
230+ self.host_config_path = self._get_predefined_config_path(config_name)
231+ if not self.host_config_path:
232+ self.host_config_path = mkstemp()[1]
233+
234+ # Initialize the super
235+ user_store = self.get_shared_store(UbuntuSystemTestsStore(
236+ self.host_config_path))
237 super().__init__(
238 [stacks.NameMatcher(user_store, None).get_sections],
239 user_store, mutable_section_id=None)
240+
241+ # Create the stack and config file for temporal data
242 self.temp_stack = dict()
243+ if temp_path:
244+ self.host_temp_config_file = temp_path
245+ else:
246+ self.host_temp_config_file = mkstemp()[1]
247+
248+ def __del__(self):
249+ # just temporal files created with mkstemp will be deleted.
250+ self._del_config_file(self.host_temp_config_file)
251+ self._del_config_file(self.host_config_path)
252+
253+ def _del_config_file(self, config_path):
254+ """ Delete the config file when it is not created in the default
255+ config dir
256+ """
257+ if os.path.exists(config_path) and \
258+ os.path.dirname(config_path) != get_user_config_dir():
259+ os.unlink(config_path)
260+
261+ def _get_predefined_config_path(self, config_name):
262+ """ Get the config file path in the default dir """
263+
264+ # When the config name is set, the config will be stored in there.
265+ if config_name:
266+ return os.path.join(get_user_config_dir(), config_name)
267+
268+ # If the default file is created, this will be used
269+ elif os.path.exists(os.path.join(get_user_config_dir(),
270+ self.DEFAULT_CONFIG)):
271+ return os.path.join(get_user_config_dir(), self.DEFAULT_CONFIG)
272+
273+ return None
274
275 def get_missing_options_from_stdin(self):
276 """Ask the user for the values of the missing options.
277
278=== modified file 'ubuntu_system_tests/selftests/test_command_line.py'
279--- ubuntu_system_tests/selftests/test_command_line.py 2015-06-30 11:21:23 +0000
280+++ ubuntu_system_tests/selftests/test_command_line.py 2015-08-23 04:04:32 +0000
281@@ -172,16 +172,16 @@
282 self.set_config_values(device_serial='')
283
284 config_stack = command_line._get_config_stack(
285- 'ubuntu-system-tests.conf', tests_to_run=[])
286+ self.config_stack.host_config_path, tests_to_run=[])
287
288 self.assertEqual('', config_stack.get('tests_to_run'))
289
290 def test_get_config_stack_with_tests_to_run(self):
291 self.set_config_values(device_serial='')
292
293- config_stack = command_line._get_config_stack(
294- 'ubuntu-system-tests.conf',
295- tests_to_run=['test1', 'test2', 'test3'])
296+ config_stack = command_line.\
297+ _get_config_stack(self.config_stack.host_config_path,
298+ tests_to_run=['test1', 'test2', 'test3'])
299
300 self.assertEqual(
301 'test1 test2 test3', config_stack.get('tests_to_run'))
302@@ -252,6 +252,7 @@
303 temp_control = command_line._create_temp_control_file(
304 ['dep4', 'dep5'], control.name
305 )
306+ self.addCleanup(os.remove, temp_control)
307 with open(temp_control) as temp:
308 tmp_control_content = temp.read()
309 expected_content = """Tests: systemtests
310@@ -320,7 +321,7 @@
311
312 class MainPassingCommandLineArgumentsTestCase(testscenarios.TestWithScenarios):
313
314- DEFAULT_CONFIG_FILE = 'ubuntu-system-tests.conf'
315+ DEFAULT_CONFIG_FILE = None
316 RUN_ALL_TESTS = []
317 DO_APT_UPDATE = True
318 DONT_APT_UPDATE = False
319
320=== modified file 'ubuntu_system_tests/selftests/test_config.py'
321--- ubuntu_system_tests/selftests/test_config.py 2015-05-21 18:15:40 +0000
322+++ ubuntu_system_tests/selftests/test_config.py 2015-08-23 04:04:32 +0000
323@@ -33,7 +33,7 @@
324 from ubuntu_system_tests.helpers.autopilot import override_proxy_timeout
325
326
327-class HelpersTestCase(selftests.ConfigBaseTestCase):
328+class HelpersTest7Case(selftests.ConfigBaseTestCase):
329
330 def get_mock_proxy(self):
331 """Returns a rubbish proxy object that doesn't actually do anything."""
332@@ -112,10 +112,10 @@
333 class UbuntuSystemTestsStackTestCase(selftests.ConfigBaseTestCase):
334
335 def test_store_location(self):
336- config_stack = config.UbuntuSystemTestsStack()
337+ config_stack = config.UbuntuSystemTestsStack('tests.conf')
338
339 expected_config_path = os.path.join(
340- os.environ.get('HOME'), '.config', 'ubuntu-system-tests.conf')
341+ os.environ.get('HOME'), '.config', 'tests.conf')
342 self.assertEqual(expected_config_path, config_stack.store.path)
343
344 def test_get_autopilot_config_string(self):
345
346=== modified file 'ubuntu_system_tests/systemtests.py'
347--- ubuntu_system_tests/systemtests.py 2015-07-15 17:03:36 +0000
348+++ ubuntu_system_tests/systemtests.py 2015-08-23 04:04:32 +0000
349@@ -103,7 +103,8 @@
350
351 def ensure_temp_stack_deleted():
352 """Delete the temporal config file after the tests are executed"""
353- config.delete_temporal_config_file()
354+ if os.path.exists(config.get_device_config_temp_file_path()):
355+ os.remove(config.get_device_config_temp_file_path())
356
357
358 if __name__ == '__main__':

Subscribers

People subscribed via source and target branches

to all changes: