Merge lp:~zyga/checkbox/selftest into lp:checkbox

Proposed by Zygmunt Krynicki
Status: Work in progress
Proposed branch: lp:~zyga/checkbox/selftest
Merge into: lp:checkbox
Diff against target: 784 lines (+738/-0)
9 files modified
.selftest/manage.py (+20/-0)
.selftest/units/coverage.pxu (+11/-0)
.selftest/units/enum.pxu (+66/-0)
.selftest/units/plans.pxu (+12/-0)
.selftest/units/provider.pxu (+59/-0)
.selftest/units/python.pxu (+114/-0)
.selftest/units/smoke.pxu (+11/-0)
.selftest/units/support.pxu (+120/-0)
selftest.sh (+325/-0)
To merge this branch: bzr merge lp:~zyga/checkbox/selftest
Reviewer Review Type Date Requested Status
Maciej Kisielewski Needs Information
Review via email: mp+253478@code.launchpad.net

Description of the change

This branch adds selftest, A standalone script that lets anyone use plainbox to test something.

We're going to use it to test checkbox.

There are some strings attached but I wanted to share it early
 - it doesn't yet handle package installation, it's easy to do, just not something I did yesterday
 - it doesn't build checkbox-gui

What does it do? It's easier to paste the tail of the output:
==================================[ Results ]===================================
 ☑ : Smoke test for selftest
 ☑ : Create a bare virtualenv
 ☑ : Populate virtualenv with additional environment variables
 ☑ : Clone the external-tarballs repository
 ☑ : Install all python dependencies
 ☑ : Meta-job for all bootstrap actions
 ☑ : Enumerate Python Projects
 ☑ : Enumerate Plainbox Providers
 ☑ : Develop Plainbox
 ☑ : Plainbox Integration Tests
 ☑ : Develop Checkbox Support
 ☑ : Develop Checkbox NG
 ☑ : Plainbox Unit Tests
 ☑ : Checkbox Support Unit Tests
 ☑ : Checkbox NG Unit Tests
 ☑ : Build Plainbox Internationalization Catalog
 ☑ : Build Checkbox Support Internationalization Catalog
 ☑ : Build Checkbox NG Internationalization Catalog
 ☑ : Build Plainbox HTML Documentation
 ☑ : Build Checkbox NG HTML Documentation
 ☑ : Build Plainbox Manual Pages
 ☑ : Develop Checkbox Provider for Plainbox
 ☑ : Develop Resource Provider for Plainbox
 ☑ : Develop Ubuntu Touch Provider for Plainbox
 ☑ : Develop Canonical Client Certification Provider for Plainbox
 ☑ : Develop Canonical Server Certification Provider for Plainbox
 ☑ : Validate Resource Provider for Plainbox
 ☑ : Validate Checkbox Provider for Plainbox
 ☑ : Validate Ubuntu Touch Provider for Plainbox
 ☑ : Validate Canonical Client Certification Provider for Plainbox
 ☑ : Validate Canonical Server Certification Provider for Plainbox
 ☑ : Build Checkbox Provider for Plainbox
 ☑ : Build Resource Provider for Plainbox
 ☑ : Build Ubuntu Touch Provider for Plainbox
 ☑ : Build Canonical Client Certification Provider for Plainbox
 ☑ : Build Canonical Server Certification Provider for Plainbox
 ☑ : Build Checkbox Provider for Plainbox Internationalization Catalog
 ☑ : Build Resource Provider for Plainbox Internationalization Catalog
 ☑ : Build Ubuntu Touch Provider for Plainbox Internationalization Catalog
 ☑ : Build Canonical Client Certification Provider for Plainbox Internationalization Catalog
 ☑ : Build Canonical Server Certification Provider for Plainbox Internationalization Catalog

09:54 <@zyga> this has a chance to replace 90% of support/
09:56 <@zyga> spineau: my goal is to get rid of all the testing scripts
09:57 <@zyga> spineau: and all the support/ directory
09:57 <@zyga> spineau: and all the cruft we have all over the tree
09:57 <@zyga> spineau: and put it all in the .selftest/ provider
09:57 <@zyga> spineau: and run it just like './selftest.sh' in any environment
09:57 <@zyga> spineau: native, in vagrant, in lxc, etc
09:57 <@zyga> spineau: and switch tarmac to that as well
09:58 <@spineau> zyga: we can relocate the release stuff if needed
09:58 <@zyga> spineau: no, I mean I don't mind keeping the support/ directory
09:58 <@zyga> spineau: just the explosion of scripts there that one has to understand
09:58 <@spineau> zyga: ok, I see
09:58 <@zyga> spineau: it also replaces mk-venv
09:59 <@zyga> spineau: though it's all incomplete, it does 90% of the work but not 100%
09:59 <@zyga> spineau: I wanted to get feedback from you guys
09:59 <@zyga> spineau: so that travis and tarmac and local testing is identical
09:59 <@zyga> spineau: and stuff like PROVIDERPATH not being set because it's hard to do so won't be a problem again
10:00 <@zyga> spineau: e.g. the new validation thing only fails because we have that issue
10:00 <@zyga> spineau: it's not broken, the test env is not setup correctly
10:00 <@zyga> spineau: I think to fully replace what we use today two more things need to happen
10:00 <@zyga> spineau: one is easy, add a few more jobs to install ppas, packages, and build checkbox-gui
10:00 <@zyga> spineau: that's really easy
10:01 <@zyga> spineau: the bigger thing is to improve plainbox so that plainbox run can be given a session directory and run (or re-run) tests in an existing session
10:01 <@zyga> spineau: the idea behind that is that now each ./selftest.sh run is standalone and cretes a new test session
10:01 <@zyga> spineau: but that's slow
10:01 <@zyga> spineau: for incremental tests we really want to reuse the session, reuse prior tess there that setup PLAINBOX_SESSION_STATE with data
10:02 <@zyga> spineau: e.g. tarballs, venvs, pip packages and more
10:02 <@zyga> spineau: so I'd like to bake it in trunk
10:02 <@zyga> spineau: and to the switch at around 0.22
10:02 <@zyga> spineau: and in the meantime test it in all the ways we can

To post a comment you must log in.
Revision history for this message
Daniel Manrique (roadmr) wrote :

Cool! I tried this inside a container, just ran ./selftest.sh run, and it failed :( because I hadn't installed intltool, which goes to what you mentioned about package installation.

Another thing I noticed is that the exit code was 0 even though some of the tests failed, I wonder if we should have a proper non-success exit code for this.

I'm also thinking about whether it overlaps a bit with tools like tox, which we use in capomastro and hexr.

But in all, this is very nice and allows expressing the rather complicated setup for plainbox tests in a manner that's familiar to a developer who is already working with plainbox. Thanks!

Revision history for this message
Zygmunt Krynicki (zyga) wrote :

Yeah, it doesn't install any packages. I'll make it do that and
re-submit this branch.

The exit code is a plainbox deficiency. I will really start looking at
this so that 0.2{2,3,4} can improve.
As for tox, yes, but it does things that tox cannot do. Tox is like
pip, this is like dpkg. Self-test is a tox super-set.

Thanks for the feedback.
ZK

On Wed, Mar 25, 2015 at 7:14 PM, Daniel Manrique
<email address hidden> wrote:
> Cool! I tried this inside a container, just ran ./selftest.sh run, and it failed :( because I hadn't installed intltool, which goes to what you mentioned about package installation.
>
> Another thing I noticed is that the exit code was 0 even though some of the tests failed, I wonder if we should have a proper non-success exit code for this.
>
> I'm also thinking about whether it overlaps a bit with tools like tox, which we use in capomastro and hexr.
>
> But in all, this is very nice and allows expressing the rather complicated setup for plainbox tests in a manner that's familiar to a developer who is already working with plainbox. Thanks!
> --
> https://code.launchpad.net/~zyga/checkbox/selftest/+merge/253478
> You are the owner of lp:~zyga/checkbox/selftest.

Revision history for this message
Maciej Kisielewski (kissiel) wrote :

Could we run autopilot for CBT as well?

review: Needs Information
Revision history for this message
Zygmunt Krynicki (zyga) wrote :

Yes, sorry, this branch is not done by any means. I'll work on it
after the release. I want to land and replace all the magic with this.

Unmerged revisions

3623. By Zygmunt Krynicki

selftest: add a provider for selftest

Jobs in the selftest provider are dividied into three categories:
 - tests for a given component (e.g. plainbox or checkbox-gui)
 - configuration for a given component (e.g. installing required
   packages and other kinds of dependencies)
 - environment probing jobs that can be used by the earlier two,
   those can be used to restrict certain tests to a specific platform
   (e.g. don't build checkbox-gui on fedora, in travis CI or on precise)

Signed-off-by: Zygmunt Krynicki <email address hidden>

3622. By Zygmunt Krynicki

selftest: add the selftest tool

This patch adds a new tool, selftest.sh, coupld with any provider
(located in .selftest) for self-testing which replaces the ad-hoc
collection of scripts and tiny data files that we used to have for each
of the components. The provider can be invoked using the selftest.sh
shell script.

The script has the following modes of operation:

    selftest.sh run - run all tests
    (run is also implicit so just running the script is good enough)
    selftest.sh bootstrap - setup current environment for testing
    (bootstrap is also performed implicitly if needed)
    selftest.sh manage - run the management script
    selftest.sh shell - spawn a shell where plainbox sees the
                            local self-test provider
    selftest.sh validate - validate the selftest provider
    selftest.sh info - display information about the selftest provider

Signed-off-by: Zygmunt Krynicki <email address hidden>

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added directory '.selftest'
2=== added file '.selftest/manage.py'
3--- .selftest/manage.py 1970-01-01 00:00:00 +0000
4+++ .selftest/manage.py 2015-03-19 08:53:15 +0000
5@@ -0,0 +1,20 @@
6+#!/usr/bin/env python3
7+from plainbox.provider_manager import setup
8+from plainbox.provider_manager import N_
9+
10+# You can inject other stuff here but please don't go overboard.
11+#
12+# In particular, if you need comprehensive compilation support to get
13+# your bin/ populated then please try to discuss that with us in the
14+# upstream project IRC channel #checkbox on irc.freenode.net.
15+
16+# NOTE: one thing that you could do here, that makes a lot of sense,
17+# is to compute version somehow. This may vary depending on the
18+# context of your provider. Future version of PlainBox will offer git,
19+# bzr and mercurial integration using the versiontools library
20+# (optional)
21+
22+setup(
23+ name='2015.com.canonical.checkbox.selftest:selftest', version="1.0",
24+ description=N_("Self-testing provider for lp:checkbox"),
25+)
26
27=== added directory '.selftest/units'
28=== added file '.selftest/units/coverage.pxu'
29--- .selftest/units/coverage.pxu 1970-01-01 00:00:00 +0000
30+++ .selftest/units/coverage.pxu 2015-03-19 08:53:15 +0000
31@@ -0,0 +1,11 @@
32+id: coverage/report
33+_summary: Generate code coverage report
34+_description:
35+ This job creates a simple text coverage report for the entire project.
36+depends: support/virtualenv
37+plugin: shell
38+estimated_duration: 1.0
39+command:
40+ . $PLAINBOX_SESSION_SHARE/virtualenv/bin/activate
41+ coverage report
42+flags: preserve-locale
43
44=== added file '.selftest/units/enum.pxu'
45--- .selftest/units/enum.pxu 1970-01-01 00:00:00 +0000
46+++ .selftest/units/enum.pxu 2015-03-19 08:53:15 +0000
47@@ -0,0 +1,66 @@
48+id: enum/python-projects
49+_summary: Enumerate Python Projects
50+_description:
51+ This job enumerates all of the python projects. It is a resource for a few
52+ templates that simplify testing and maintenance of selftest.
53+plugin: resource
54+command:
55+ echo "path: plainbox"
56+ echo "name: plainbox"
57+ echo "title: Plainbox"
58+ echo "build_i18n: yes"
59+ echo "build_sphinx_html: yes"
60+ echo "build_sphinx_man: yes"
61+ echo "depends:"
62+ echo
63+ echo "path: checkbox-support"
64+ echo "name: checkbox-support"
65+ echo "title: Checkbox Support"
66+ echo "build_i18n: yes"
67+ echo "build_sphinx_html: no"
68+ echo "build_sphinx_man: no"
69+ echo "depends:"
70+ echo
71+ echo "name: checkbox-ng"
72+ echo "path: checkbox-ng"
73+ echo "title: Checkbox NG"
74+ echo "build_i18n: yes"
75+ echo "build_sphinx_html: yes"
76+ echo "build_sphinx_man: no"
77+ echo "depends: test/plainbox/unit-tests, test/checkbox-support/unit-tests"
78+estimated_duration: 1.0
79+flags: preserve-locale
80+
81+id: enum/plainbox-providers
82+_summary: Enumerate Plainbox Providers
83+_description:
84+ This job enumerates all of the plainbox providers. It is a resource for a few
85+ templates that simplify testing and maintenance of selftest.
86+plugin: resource
87+command:
88+ echo "path: providers/plainbox-provider-checkbox"
89+ echo "name: plainbox-provider-checkbox"
90+ echo "title: Checkbox Provider for Plainbox"
91+ echo "depends: test/plainbox-provider-resource/validate"
92+ echo
93+ echo "path: providers/plainbox-provider-resource-generic"
94+ echo "name: plainbox-provider-resource"
95+ echo "title: Resource Provider for Plainbox"
96+ echo "depends:"
97+ echo
98+ echo "path: providers/plainbox-provider-ubuntu-touch"
99+ echo "name: plainbox-provider-ubuntu-touch"
100+ echo "title: Ubuntu Touch Provider for Plainbox"
101+ echo "depends:"
102+ echo
103+ echo "path: providers/plainbox-provider-certification-client"
104+ echo "name: plainbox-provider-certification-client"
105+ echo "title: Canonical Client Certification Provider for Plainbox"
106+ echo "depends: test/plainbox-provider-checkbox/validate"
107+ echo
108+ echo "path: providers/plainbox-provider-certification-server"
109+ echo "name: plainbox-provider-certification-server"
110+ echo "title: Canonical Server Certification Provider for Plainbox"
111+ echo "depends: test/plainbox-provider-checkbox/validate"
112+estimated_duration: 1.0
113+flags: preserve-locale
114
115=== added file '.selftest/units/plans.pxu'
116--- .selftest/units/plans.pxu 1970-01-01 00:00:00 +0000
117+++ .selftest/units/plans.pxu 2015-03-19 08:53:15 +0000
118@@ -0,0 +1,12 @@
119+id: selftest
120+unit: test plan
121+_name: All Tests
122+_description:
123+ This test plan includes all of the self tests for lp:checkbox.
124+ It is the most comprehensive and longest test plan to run.
125+include:
126+ selftest/smoke
127+ meta/bootstrap
128+ enum/.*
129+ test/.*
130+estimated_duration: 1.0
131
132=== added file '.selftest/units/provider.pxu'
133--- .selftest/units/provider.pxu 1970-01-01 00:00:00 +0000
134+++ .selftest/units/provider.pxu 2015-03-19 08:53:15 +0000
135@@ -0,0 +1,59 @@
136+unit: template
137+template-unit: job
138+template-resource:enum/plainbox-providers
139+id: test/{name}/develop
140+_summary: Develop {title}
141+_description:
142+ This job develops the provider {name}.
143+depends: meta/bootstrap, test/plainbox/unit-tests
144+plugin: shell
145+estimated_duration: 1.0
146+command:
147+ . $PLAINBOX_SESSION_SHARE/virtualenv/bin/activate
148+ $SELFTEST_TOP/{path}/manage.py develop -d $PROVIDERPATH -f
149+flags: preserve-locale
150+
151+unit: template
152+template-unit: job
153+template-resource:enum/plainbox-providers
154+id: test/{name}/validate
155+_summary: Validate {title}
156+_description:
157+ This job validates the provider {name}.
158+depends: meta/bootstrap, test/{name}/develop, {depends}
159+plugin: shell
160+estimated_duration: 1.0
161+command:
162+ . $PLAINBOX_SESSION_SHARE/virtualenv/bin/activate
163+ $SELFTEST_TOP/{path}/manage.py validate -N
164+flags: preserve-locale
165+
166+unit: template
167+template-unit: job
168+template-resource:enum/plainbox-providers
169+id: test/{name}/build
170+_summary: Build {title}
171+_description:
172+ This job builds all buildable elements of {name}.
173+depends: meta/bootstrap
174+plugin: shell
175+estimated_duration: 1.0
176+command:
177+ . $PLAINBOX_SESSION_SHARE/virtualenv/bin/activate
178+ $SELFTEST_TOP/{path}/manage.py build
179+flags: preserve-locale
180+
181+unit: template
182+template-unit: job
183+template-resource:enum/plainbox-providers
184+id: test/{name}/build_i18n
185+_summary: Build {title} Internationalization Catalog
186+_description:
187+ This job builds all of the localization catalogs for {name}.
188+depends: meta/bootstrap
189+plugin: shell
190+estimated_duration: 1.0
191+command:
192+ . $PLAINBOX_SESSION_SHARE/virtualenv/bin/activate
193+ $SELFTEST_TOP/{path}/manage.py i18n
194+flags: preserve-locale
195
196=== added file '.selftest/units/python.pxu'
197--- .selftest/units/python.pxu 1970-01-01 00:00:00 +0000
198+++ .selftest/units/python.pxu 2015-03-19 08:53:15 +0000
199@@ -0,0 +1,114 @@
200+unit: template
201+template-unit: job
202+template-resource:enum/python-projects
203+id: test/{name}/develop
204+_summary: Develop {title}
205+_description:
206+ This job runs setup.py develop for {name}.
207+depends: meta/bootstrap
208+plugin: shell
209+estimated_duration: 1.0
210+command:
211+ . $PLAINBOX_SESSION_SHARE/virtualenv/bin/activate
212+ # NOTE: Due to bug in how setup(scripts=[...]) works we need to be in the
213+ # right directory as otherwise setuptools won't find one of the launcher
214+ # scripts.
215+ ( cd $SELFTEST_TOP/{path} && ./setup.py develop )
216+flags: preserve-locale
217+
218+unit: template
219+template-unit: job
220+template-resource:enum/python-projects
221+id: test/{name}/unit-tests
222+_summary: {title} Unit Tests
223+_description:
224+ This job runs all of the unit tests for {name}. The tests are executed with
225+ automatic coverage and branch analysis.
226+depends: meta/bootstrap, test/{name}/develop, {depends}
227+plugin: shell
228+estimated_duration: 1
229+command:
230+ . $PLAINBOX_SESSION_SHARE/virtualenv/bin/activate
231+ export LANGUAGE=en
232+ export LANG=C.UTF-8
233+ export COVERAGE_FILE=$PLAINBOX_SESSION_SHARE/coverage
234+ $SELFTEST_TOP/{path}/setup.py test --quiet
235+flags: preserve-locale
236+
237+unit: template
238+template-unit: job
239+template-resource:enum/python-projects
240+template-filter: project.build_i18n == 'yes'
241+template-imports: from 2015.com.canonical.checkbox.selftest import enum/python-projects as project
242+id: test/{name}/build-i18n
243+_summary: Build {title} Internationalization Catalog
244+_description:
245+ This job builds all of the localization catalogs for {name}.
246+command:
247+ . $PLAINBOX_SESSION_SHARE/virtualenv/bin/activate
248+ $SELFTEST_TOP/{path}/setup.py build_i18n -m
249+depends: meta/bootstrap
250+plugin: shell
251+estimated_duration: 1.0
252+flags: preserve-locale
253+
254+unit: template
255+template-unit: job
256+template-resource:enum/python-projects
257+template-filter: project.build_sphinx_html == 'yes'
258+template-imports: from 2015.com.canonical.checkbox.selftest import enum/python-projects as project
259+id: test/{name}/build-html-docs
260+_summary: Build {title} HTML Documentation
261+_description:
262+ This job builds all of the HTML documentation for {name}.
263+command:
264+ . $PLAINBOX_SESSION_SHARE/virtualenv/bin/activate
265+ # XXX: Due to a bug somewhere we cannot build manual pages from a temporary
266+ # directory. I haven't figure out what is causing this yet.
267+ cd $SELFTEST_TOP/{path}
268+ $SELFTEST_TOP/{path}/setup.py build_sphinx -b html
269+depends: meta/bootstrap
270+plugin: shell
271+estimated_duration: 1.0
272+flags: preserve-locale
273+
274+unit: template
275+template-unit: job
276+template-resource:enum/python-projects
277+template-filter: project.build_sphinx_man == 'yes'
278+template-imports: from 2015.com.canonical.checkbox.selftest import enum/python-projects as project
279+id: test/{name}/build-manpages
280+_summary: Build {title} Manual Pages
281+_description:
282+ This job builds all of the manual pages for {name}.
283+command:
284+ . $PLAINBOX_SESSION_SHARE/virtualenv/bin/activate
285+ . $PLAINBOX_SESSION_SHARE/virtualenv/bin/activate
286+ # XXX: Due to a bug somewhere we cannot build manual pages from a temporary
287+ # directory. I haven't figure out what is causing this yet.
288+ cd $SELFTEST_TOP/{path}
289+ $SELFTEST_TOP/{path}/setup.py build_sphinx -b man
290+depends: meta/bootstrap
291+plugin: shell
292+estimated_duration: 1.0
293+flags: preserve-locale
294+
295+id: test/plainbox/integration-tests
296+_summary: Plainbox Integration Tests
297+_description:
298+ This job runs all of the "integration tests" for plainbox. Integration
299+ tests are really mis-named and should eventually be removed and
300+ transitioned into testing all of the providers that live in this project.
301+ In practice integration tests run a set of automated tests on a small
302+ subset of the "checkbox source" provider.
303+command:
304+ . $PLAINBOX_SESSION_SHARE/virtualenv/bin/activate
305+ export LANGUAGE=en
306+ export LANG=C.UTF-8
307+ export COVERAGE_FILE=$PLAINBOX_SESSION_SHARE/coverage
308+ coverage run --append --branch --module plainbox \
309+ self-test --after-reexec --integration-tests --quiet
310+depends: meta/bootstrap, test/plainbox/develop
311+plugin: shell
312+estimated_duration: 1.0
313+flags: preserve-locale
314
315=== added file '.selftest/units/smoke.pxu'
316--- .selftest/units/smoke.pxu 1970-01-01 00:00:00 +0000
317+++ .selftest/units/smoke.pxu 2015-03-19 08:53:15 +0000
318@@ -0,0 +1,11 @@
319+id: selftest/smoke
320+unit: job
321+_summary: Smoke test for selftest
322+_description:
323+ This smoke test can be used to check if selftest itself can run anything.
324+ This tests simply prints a message and quits successfully.
325+plugin: shell
326+command:
327+ echo "Smoke test successful"
328+flags: preserve-locale
329+estimated_duration: 1.0
330
331=== added file '.selftest/units/support.pxu'
332--- .selftest/units/support.pxu 1970-01-01 00:00:00 +0000
333+++ .selftest/units/support.pxu 2015-03-19 08:53:15 +0000
334@@ -0,0 +1,120 @@
335+id: support/bare-virtualenv
336+_summary: Create a bare virtualenv
337+_description:
338+ This job creates a new virtualenv that is required by other tests. This
339+ virtualenv is created in the $PLAINBOX_SESSION_SHARE/virtualenv directory,
340+ which is a temporary directory unique to each testing session.
341+plugin: shell
342+estimated_duration: 3
343+command:
344+ set -x
345+ virtualenv \
346+ --system-site-packages \
347+ --python=/usr/bin/python3 \
348+ $PLAINBOX_SESSION_SHARE/virtualenv
349+flags: preserve-locale
350+
351+id: support/inject-extra-env
352+_summary: Populate virtualenv with additional environment variables
353+_description:
354+ This job appends a number of checkbox-specific envirionment variables to the
355+ activation script of the virtualenv. Since many other scripts source the same
356+ file it is a simple and handy way to add some globals.
357+ .
358+ The variables are:
359+ - PLAINBOX_LOCALE_DIR - assits in plainbox i18n when uninstalled
360+ - CHECKBOX_NG_LOCALE_DIR - ditto
361+ - CHECKBOX_PROVIDER_LOCALE_DIR - ditto
362+ - PROVIDERPATH - tells plainbox where to look for providers
363+ In addition, the directory specified by PROVIDERPATH is created.
364+plugin: shell
365+estimated_duration: 1
366+depends: support/bare-virtualenv
367+command:
368+ set -e
369+ set -x
370+ echo "export PLAINBOX_LOCALE_DIR=$SELFTEST_TOP/plainbox/build/mo" >> $PLAINBOX_SESSION_SHARE/virtualenv/bin/activate
371+ echo "export CHECKBOX_NG_LOCALE_DIR=$SELFTEST_TOP/checkbox-ng/build/mo" >> $PLAINBOX_SESSION_SHARE/virtualenv/bin/activate
372+ echo "export CHECKBOX_PROVIDER_LOCALE_DIR=$SELFTEST_TOP/providers/plainbox-provider-checkbox/build/mo" >> $PLAINBOX_SESSION_SHARE/virtualenv/bin/activate
373+ # Add PROVIDERPATH to the venv
374+ echo "export PROVIDERPATH=$PLAINBOX_SESSION_SHARE/share/plainbox-providers-1" >> $PLAINBOX_SESSION_SHARE/virtualenv/bin/activate
375+ mkdir -p "$PLAINBOX_SESSION_SHARE/share/plainbox-providers-1"
376+flags: preserve-locale
377+
378+id: support/get-external-tarballs
379+_summary: Clone the external-tarballs repository
380+_description:
381+ This job clones (or updates) the repository with external tarballs. The
382+ revision to switch to is stored in support/external-tarballs-revision.txt
383+plugin: shell
384+estimated_duration: 1
385+command:
386+ set -e
387+ if [ ! -d "$PLAINBOX_SESSION_SHARE/external-tarballs" ]; then
388+ echo "I: cloning external-tarballs repository..."
389+ # Clone the external-tarballs repo
390+ git clone git://github.com/checkbox/external-tarballs \
391+ $PLAINBOX_SESSION_SHARE/external-tarballs
392+ fi
393+ cd $PLAINBOX_SESSION_SHARE/external-tarballs/
394+ # Fetch so that we may have the needed revision
395+ if ! git fetch origin --quiet; then
396+ echo "W: cannot perform fetch, external-tarballs may be out of date"
397+ fi
398+ # Ensure that we are on the correct revision
399+ if ! git checkout $(cat $SELFTEST_TOP/support/external-tarballs-revision.txt); then
400+ echo "E: cannot switch to required commit!"
401+ exit 1
402+ fi
403+flags: preserve-locale
404+
405+id: support/install-pip-dependencies
406+_summary: Install all python dependencies
407+_description:
408+ This job installs all of the dependencis specified by various
409+ requirement/pip-*.txt files into a python virtualenv.
410+plugin: shell
411+estimated_duration: 1
412+depends: support/bare-virtualenv, support/get-external-tarballs
413+command:
414+ set -e
415+ set -x
416+ # Set a http_proxy to the local discard port to prevent setuptools from
417+ # downloading anything.
418+ export http_proxy=http://127.0.0.1:9
419+ # Custom pip executable. Needed because the pip we want is called
420+ # differently in different situations. Inside a virtualenv it is always
421+ # 'pip' but outside it may be pip-3.2 or pip-3.3, depending on python
422+ # version.
423+ CHECKBOX_PIP=${CHECKBOX_PIP:-pip}
424+ echo "I: using $CHECKBOX_PIP to install python packages"
425+ # Construct a list of required python packages.
426+ python_pkg_list="$(find "$SELFTEST_TOP" -path '*/requirements/pip-*.txt' -exec cat "{}" \; | grep -v '^#' | sort | uniq)"
427+ # Install them
428+ echo "I: installing following pip packages:" $python_pkg_list
429+ $CHECKBOX_PIP install --no-index \
430+ "--find-links=file://$PLAINBOX_SESSION_SHARE/external-tarballs/index.html" \
431+ $python_pkg_list
432+flags: preserve-locale
433+
434+id: meta/bootstrap
435+_summary: Meta-job for all bootstrap actions
436+_description:
437+ This metajob depends on all of the bootstrapping jobs
438+plugin: shell
439+estimated_duration: 1
440+depends: support/bare-virtualenv, support/inject-extra-env, support/install-pip-dependencies
441+command: :
442+flags: preserve-locale
443+
444+id: pip-freeze
445+_summary: Run 'pip freeze' in the virtual environment
446+_description:
447+ This metajob depends on all of the bootstrapping jobs
448+plugin: shell
449+estimated_duration: 1
450+depends: support/bare-virtualenv, support/install-pip-dependencies
451+command:
452+ . $PLAINBOX_SESSION_SHARE/virtualenv/bin/activate
453+ pip freeze
454+flags: preserve-locale
455
456=== added file 'selftest.sh'
457--- selftest.sh 1970-01-01 00:00:00 +0000
458+++ selftest.sh 2015-03-19 08:53:15 +0000
459@@ -0,0 +1,325 @@
460+#!/bin/sh
461+# This file is part of Checkbox.
462+#
463+# Copyright 2013-2015 Canonical Ltd.
464+# Written by:
465+# Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
466+#
467+# Checkbox is free software: you can redistribute it and/or modify
468+# it under the terms of the GNU General Public License version 3,
469+# as published by the Free Software Foundation.
470+#
471+# Checkbox is distributed in the hope that it will be useful,
472+# but WITHOUT ANY WARRANTY; without even the implied warranty of
473+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
474+# GNU General Public License for more details.
475+#
476+# You should have received a copy of the GNU General Public License
477+# along with selftest. If not, see <http://www.gnu.org/licenses/>.
478+
479+# Feel free to customize those two lines for your project.
480+SELFTEST_BOOTSTRAP_DIR=/tmp/selftest-bootstrap.venv
481+SELFTEST_RUN_DEFAULT='-T 2015.com.canonical.checkbox.selftest::selftest'
482+
483+# The rest is generic, no need to change it.
484+test -z "$SELFTEST_TOP" -a -d /vagrant && SELFTEST_TOP=/vagrant
485+test -z "$SELFTEST_TOP" && SELFTEST_TOP="$(git rev-parse --show-toplevel 2>/dev/null)"
486+test -z "$SELFTEST_TOP" && SELFTEST_TOP="$(bzr root)"
487+export SELFTEST_TOP
488+SELFTEST_PROVIDERPATH="$SELFTEST_BOOTSTRAP_DIR/share/plainbox-providers-1"
489+SELFTEST_MANAGE="$SELFTEST_TOP/.selftest/manage.py"
490+
491+
492+_selftest__detect_platform() {
493+ echo "I: Detecting platform ..."
494+ PLATFORM=$(
495+ _selftest__load_os_release \
496+ && echo "$ID-$VERSION_ID-$(uname -m | sed -e 's/x86_64/amd64/g')" \
497+ || echo "error-error-error"
498+ )
499+ echo "N: Platform detected: $PLATFORM"
500+}
501+
502+
503+_selftest__load_os_release() {
504+ # Try to guess where we are running
505+ if [ -f /etc/os-release ]; then
506+ # Load /etc/os-release if present
507+ . /etc/os-release
508+ elif [ "$(which lsb_release)" != "" ]; then
509+ # Emulate /etc/os-release for well-known Ubuntu releases that lack it
510+ # Ubuntu ships /etc/os-release starting with 12.04.2 or 12.10
511+ # https://bugs.launchpad.net/ubuntu/+source/base-files/+bug/947236
512+ case "$(lsb_release --short --description)" in
513+ "Ubuntu 12.04 LTS")
514+ NAME="Ubuntu"
515+ VERSION="12.04 LTS, Precise Pangolin"
516+ ID=ubuntu
517+ ID_LIKE=debian
518+ PRETTY_NAME="Ubuntu precise (12.04 LTS)"
519+ VERSION_ID="12.04"
520+ ;;
521+ "Ubuntu 12.04.1 LTS")
522+ NAME="Ubuntu"
523+ VERSION="12.04.1 LTS, Precise Pangolin"
524+ ID=ubuntu
525+ ID_LIKE=debian
526+ PRETTY_NAME="Ubuntu precise (12.04.1 LTS)"
527+ VERSION_ID="12.04"
528+ ;;
529+ *)
530+ NAME=Linux
531+ ;;
532+ esac
533+ fi
534+}
535+
536+
537+
538+_selftest__configure_platform() {
539+ echo "I: Configuring platform ..."
540+ case $PLATFORM in
541+ ubuntu-*)
542+ _selftest__configure_debian
543+ ;;
544+ elementary-*)
545+ _selftest__configure_debian
546+ ;;
547+ debian-*)
548+ _selftest__configure_debian
549+ ;;
550+ fedora-*)
551+ _selftest__configure_fedora
552+ ;;
553+ *)
554+ echo "E: Unable to configure platform $PLATFORM"
555+ echo "E: Patch support/plainbox-selftest-provider/bootstrap"
556+ echo "E: (look for _selftest__configure_platform)"
557+ echo "E: If you think this should work then please report"
558+ echo "E: a bug on https://bugs.launchpad.net/selftest/+filebug"
559+ exit 1
560+ ;;
561+ esac
562+}
563+
564+
565+_selftest__configure_debian() {
566+ export DEBIAN_FRONTEND=noninteractive
567+ if ! sudo apt-get -qqy install python3 python-virtualenv; then
568+ echo "E: Unable to instal core dependencies"
569+ echo "E: Typically this happens when you are offline"
570+ exit 1
571+ fi
572+}
573+
574+
575+_selftest__configure_fedora() {
576+ if ! sudo yum -q install -y python3 python-virtualenv; then
577+ echo "E: Unable to instal core dependencies"
578+ echo "E: Typically this happens when you are offline"
579+ exit 1
580+ fi
581+}
582+
583+
584+_selftest__install_stable_plainbox() {
585+ echo "I: Creating python3 virtual environment"
586+ if ! virtualenv --quiet -p python3 "$SELFTEST_BOOTSTRAP_DIR"; then
587+ echo "E: Unable to create a virtualenv for python 3"
588+ _selftest__bug
589+ fi
590+ _selftest__venv_enter
591+ if ! pip freeze | grep plainbox >/dev/null; then
592+ echo "I: Installing plainbox 0.20"
593+ if ! pip install plainbox==0.20; then
594+ echo "E: Unable to install plainbox 0.20"
595+ echo "E: Typically this happens when you are offline"
596+ exit 1
597+ fi
598+ fi
599+ echo "I: Checking if plainbox is operational ..."
600+ if [ "$(plainbox --version 2>&1 )" != 0.20 ]; then
601+ echo "E: Installed plainbox doesn't work."
602+ _selftest__bug
603+ fi
604+ _selftest__venv_exit
605+}
606+
607+
608+_selftest__develop_selftest_provider() {
609+ echo "I: Developing the self-test provider ..."
610+ _selftest__venv_enter
611+ if ! "$SELFTEST_MANAGE" develop -f -d "$SELFTEST_PROVIDERPATH"; then
612+ echo "E: Unable to develop the self-test provider"
613+ _selftest__bug
614+ fi
615+ _selftest__venv_exit
616+}
617+
618+_selftest__detect_broken_vagrant() {
619+ if [ -d "/vagrant" ] ; then
620+ # Vagrant sanity check, see if /vagrant really works.
621+ #
622+ # On various installations of Ubuntu this is not the case as the cloud images
623+ # we depend on seem to have broken virtualbox tools installation inside. This
624+ # causes the filesystem mounted on /vagrant to crash horribly and kill all
625+ # processes attempting to use it.
626+ echo "I: Checking for broken /vagrant ..."
627+ if ! find /vagrant -mindepth 1 -maxdepth 1 >/dev/null; then
628+ cat <<__EOM__
629+ E: It seems that /vagrant directory is broken
630+ E: This is a known issue.
631+ E: See this link for a workaround if you have recent-enough VirtualBox:
632+ E: https://bugs.launchpad.net/ubuntu/+source/virtualbox/+bug/1252872
633+ E: Alternatively you can use NFS on any version of VirtualBox:
634+ E: http://docs.vagrantup.com/v2/synced-folders/nfs.html
635+__EOM__
636+ exit 1
637+ else
638+ echo "I: It seems that /vagrant is working okay"
639+ fi
640+ fi
641+}
642+
643+
644+_selftest__patch_broken_pkg_resources() {
645+ if sudo patch -p0 /usr/lib/python3/dist-packages/pkg_resources.py << EOF
646+--- pkg_resources.py.orig 2014-05-15 19:39:38.365807720 +0000
647++++ pkg_resources.py 2014-05-15 19:44:50.449807720 +0000
648+@@ -1749,11 +1749,16 @@
649+ for dist in find_distributions(os.path.join(path_item, entry)):
650+ yield dist
651+ elif not only and lower.endswith('.egg-link'):
652+- for line in open(os.path.join(path_item, entry)):
653+- if not line.strip(): continue
654+- for item in find_distributions(os.path.join(path_item,line.rstrip())):
655+- yield item
656+- break
657++ try:
658++ entry_file = open(os.path.join(path_item, entry))
659++ for line in entry_file:
660++ if not line.strip(): continue
661++ for item in find_distributions(os.path.join(path_item,line.rstrip())):
662++ yield item
663++ break
664++ finally:
665++ entry_file.close()
666++
667+ register_finder(ImpWrapper,find_on_path)
668+
669+ _declare_state('dict', _namespace_handlers={})
670+EOF
671+ then
672+ echo "I: Patching pkg_resources.py succeeded"
673+ else
674+ echo "E: Unable to patch pkg_resources.py :-("
675+ _selftest__bug
676+ fi
677+}
678+
679+
680+_selftest__bug() {
681+ echo "E: Please report a bug on https://bugs.launchpad.net/checkbox/+filebug"
682+ exit 1
683+}
684+
685+
686+_selftest__venv_enter() {
687+ . "$SELFTEST_BOOTSTRAP_DIR/bin/activate"
688+}
689+
690+
691+_selftest__venv_exit() {
692+ deactivate
693+}
694+
695+
696+_selftest__bootstrap() {
697+ _selftest__detect_broken_vagrant
698+ _selftest__detect_platform
699+ _selftest__configure_platform
700+ _selftest__install_stable_plainbox
701+ _selftest__develop_selftest_provider
702+}
703+
704+
705+_selftest__maybe_bootstrap() {
706+ if [ ! -e "$SELFTEST_BOOTSTRAP_DIR" ]; then
707+ echo "N: Doing automatic bootstrap ..."
708+ _selftest__bootstrap
709+ fi
710+}
711+
712+
713+_selftest__run() {
714+ _selftest__venv_enter
715+ PROVIDERPATH="$SELFTEST_PROVIDERPATH" plainbox run ${@:-$SELFTEST_RUN_DEFAULT}
716+ retval=$?
717+ _selftest__venv_exit
718+ return $retval
719+}
720+
721+
722+_selftest__manage() {
723+ _selftest__venv_enter
724+ "$SELFTEST_MANAGE" "$@"
725+ _selftest__venv_exit
726+}
727+
728+
729+_selftest__shell() {
730+ _selftest__venv_enter
731+ echo "I: activating interactive selftest shell"
732+ echo "I: type 'exit' to quit"
733+ PROVIDERPATH="$SELFTEST_PROVIDERPATH" debian_chroot="selftest" bash "$@"
734+ _selftest__venv_exit
735+}
736+
737+
738+_selftest__main() {
739+ case "$1" in
740+ '')
741+ _selftest__maybe_bootstrap
742+ _selftest__run "$@"
743+ exit $?
744+ ;;
745+ run)
746+ shift
747+ _selftest__maybe_bootstrap
748+ _selftest__run "$@"
749+ exit $?
750+ ;;
751+ bootstrap)
752+ shift
753+ _selftest__bootstrap
754+ exit $?
755+ ;;
756+ validate)
757+ shift
758+ _selftest__manage validate "$@"
759+ exit $?
760+ ;;
761+ info)
762+ shift
763+ _selftest__manage info "$@"
764+ exit $?
765+ ;;
766+ manage)
767+ shift
768+ _selftest__manage "$@"
769+ exit $?
770+ ;;
771+ shell)
772+ shift
773+ _selftest__shell "$@"
774+ exit $?
775+ ;;
776+ *)
777+ echo "Usage: selftest {boostrap,run,validate,info,manage,shell}"
778+ exit 1
779+ ;;
780+ esac
781+}
782+
783+
784+_selftest__main "$@"

Subscribers

People subscribed via source and target branches