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
=== added directory '.selftest'
=== added file '.selftest/manage.py'
--- .selftest/manage.py 1970-01-01 00:00:00 +0000
+++ .selftest/manage.py 2015-03-19 08:53:15 +0000
@@ -0,0 +1,20 @@
1#!/usr/bin/env python3
2from plainbox.provider_manager import setup
3from plainbox.provider_manager import N_
4
5# You can inject other stuff here but please don't go overboard.
6#
7# In particular, if you need comprehensive compilation support to get
8# your bin/ populated then please try to discuss that with us in the
9# upstream project IRC channel #checkbox on irc.freenode.net.
10
11# NOTE: one thing that you could do here, that makes a lot of sense,
12# is to compute version somehow. This may vary depending on the
13# context of your provider. Future version of PlainBox will offer git,
14# bzr and mercurial integration using the versiontools library
15# (optional)
16
17setup(
18 name='2015.com.canonical.checkbox.selftest:selftest', version="1.0",
19 description=N_("Self-testing provider for lp:checkbox"),
20)
021
=== added directory '.selftest/units'
=== added file '.selftest/units/coverage.pxu'
--- .selftest/units/coverage.pxu 1970-01-01 00:00:00 +0000
+++ .selftest/units/coverage.pxu 2015-03-19 08:53:15 +0000
@@ -0,0 +1,11 @@
1id: coverage/report
2_summary: Generate code coverage report
3_description:
4 This job creates a simple text coverage report for the entire project.
5depends: support/virtualenv
6plugin: shell
7estimated_duration: 1.0
8command:
9 . $PLAINBOX_SESSION_SHARE/virtualenv/bin/activate
10 coverage report
11flags: preserve-locale
012
=== added file '.selftest/units/enum.pxu'
--- .selftest/units/enum.pxu 1970-01-01 00:00:00 +0000
+++ .selftest/units/enum.pxu 2015-03-19 08:53:15 +0000
@@ -0,0 +1,66 @@
1id: enum/python-projects
2_summary: Enumerate Python Projects
3_description:
4 This job enumerates all of the python projects. It is a resource for a few
5 templates that simplify testing and maintenance of selftest.
6plugin: resource
7command:
8 echo "path: plainbox"
9 echo "name: plainbox"
10 echo "title: Plainbox"
11 echo "build_i18n: yes"
12 echo "build_sphinx_html: yes"
13 echo "build_sphinx_man: yes"
14 echo "depends:"
15 echo
16 echo "path: checkbox-support"
17 echo "name: checkbox-support"
18 echo "title: Checkbox Support"
19 echo "build_i18n: yes"
20 echo "build_sphinx_html: no"
21 echo "build_sphinx_man: no"
22 echo "depends:"
23 echo
24 echo "name: checkbox-ng"
25 echo "path: checkbox-ng"
26 echo "title: Checkbox NG"
27 echo "build_i18n: yes"
28 echo "build_sphinx_html: yes"
29 echo "build_sphinx_man: no"
30 echo "depends: test/plainbox/unit-tests, test/checkbox-support/unit-tests"
31estimated_duration: 1.0
32flags: preserve-locale
33
34id: enum/plainbox-providers
35_summary: Enumerate Plainbox Providers
36_description:
37 This job enumerates all of the plainbox providers. It is a resource for a few
38 templates that simplify testing and maintenance of selftest.
39plugin: resource
40command:
41 echo "path: providers/plainbox-provider-checkbox"
42 echo "name: plainbox-provider-checkbox"
43 echo "title: Checkbox Provider for Plainbox"
44 echo "depends: test/plainbox-provider-resource/validate"
45 echo
46 echo "path: providers/plainbox-provider-resource-generic"
47 echo "name: plainbox-provider-resource"
48 echo "title: Resource Provider for Plainbox"
49 echo "depends:"
50 echo
51 echo "path: providers/plainbox-provider-ubuntu-touch"
52 echo "name: plainbox-provider-ubuntu-touch"
53 echo "title: Ubuntu Touch Provider for Plainbox"
54 echo "depends:"
55 echo
56 echo "path: providers/plainbox-provider-certification-client"
57 echo "name: plainbox-provider-certification-client"
58 echo "title: Canonical Client Certification Provider for Plainbox"
59 echo "depends: test/plainbox-provider-checkbox/validate"
60 echo
61 echo "path: providers/plainbox-provider-certification-server"
62 echo "name: plainbox-provider-certification-server"
63 echo "title: Canonical Server Certification Provider for Plainbox"
64 echo "depends: test/plainbox-provider-checkbox/validate"
65estimated_duration: 1.0
66flags: preserve-locale
067
=== added file '.selftest/units/plans.pxu'
--- .selftest/units/plans.pxu 1970-01-01 00:00:00 +0000
+++ .selftest/units/plans.pxu 2015-03-19 08:53:15 +0000
@@ -0,0 +1,12 @@
1id: selftest
2unit: test plan
3_name: All Tests
4_description:
5 This test plan includes all of the self tests for lp:checkbox.
6 It is the most comprehensive and longest test plan to run.
7include:
8 selftest/smoke
9 meta/bootstrap
10 enum/.*
11 test/.*
12estimated_duration: 1.0
013
=== added file '.selftest/units/provider.pxu'
--- .selftest/units/provider.pxu 1970-01-01 00:00:00 +0000
+++ .selftest/units/provider.pxu 2015-03-19 08:53:15 +0000
@@ -0,0 +1,59 @@
1unit: template
2template-unit: job
3template-resource:enum/plainbox-providers
4id: test/{name}/develop
5_summary: Develop {title}
6_description:
7 This job develops the provider {name}.
8depends: meta/bootstrap, test/plainbox/unit-tests
9plugin: shell
10estimated_duration: 1.0
11command:
12 . $PLAINBOX_SESSION_SHARE/virtualenv/bin/activate
13 $SELFTEST_TOP/{path}/manage.py develop -d $PROVIDERPATH -f
14flags: preserve-locale
15
16unit: template
17template-unit: job
18template-resource:enum/plainbox-providers
19id: test/{name}/validate
20_summary: Validate {title}
21_description:
22 This job validates the provider {name}.
23depends: meta/bootstrap, test/{name}/develop, {depends}
24plugin: shell
25estimated_duration: 1.0
26command:
27 . $PLAINBOX_SESSION_SHARE/virtualenv/bin/activate
28 $SELFTEST_TOP/{path}/manage.py validate -N
29flags: preserve-locale
30
31unit: template
32template-unit: job
33template-resource:enum/plainbox-providers
34id: test/{name}/build
35_summary: Build {title}
36_description:
37 This job builds all buildable elements of {name}.
38depends: meta/bootstrap
39plugin: shell
40estimated_duration: 1.0
41command:
42 . $PLAINBOX_SESSION_SHARE/virtualenv/bin/activate
43 $SELFTEST_TOP/{path}/manage.py build
44flags: preserve-locale
45
46unit: template
47template-unit: job
48template-resource:enum/plainbox-providers
49id: test/{name}/build_i18n
50_summary: Build {title} Internationalization Catalog
51_description:
52 This job builds all of the localization catalogs for {name}.
53depends: meta/bootstrap
54plugin: shell
55estimated_duration: 1.0
56command:
57 . $PLAINBOX_SESSION_SHARE/virtualenv/bin/activate
58 $SELFTEST_TOP/{path}/manage.py i18n
59flags: preserve-locale
060
=== added file '.selftest/units/python.pxu'
--- .selftest/units/python.pxu 1970-01-01 00:00:00 +0000
+++ .selftest/units/python.pxu 2015-03-19 08:53:15 +0000
@@ -0,0 +1,114 @@
1unit: template
2template-unit: job
3template-resource:enum/python-projects
4id: test/{name}/develop
5_summary: Develop {title}
6_description:
7 This job runs setup.py develop for {name}.
8depends: meta/bootstrap
9plugin: shell
10estimated_duration: 1.0
11command:
12 . $PLAINBOX_SESSION_SHARE/virtualenv/bin/activate
13 # NOTE: Due to bug in how setup(scripts=[...]) works we need to be in the
14 # right directory as otherwise setuptools won't find one of the launcher
15 # scripts.
16 ( cd $SELFTEST_TOP/{path} && ./setup.py develop )
17flags: preserve-locale
18
19unit: template
20template-unit: job
21template-resource:enum/python-projects
22id: test/{name}/unit-tests
23_summary: {title} Unit Tests
24_description:
25 This job runs all of the unit tests for {name}. The tests are executed with
26 automatic coverage and branch analysis.
27depends: meta/bootstrap, test/{name}/develop, {depends}
28plugin: shell
29estimated_duration: 1
30command:
31 . $PLAINBOX_SESSION_SHARE/virtualenv/bin/activate
32 export LANGUAGE=en
33 export LANG=C.UTF-8
34 export COVERAGE_FILE=$PLAINBOX_SESSION_SHARE/coverage
35 $SELFTEST_TOP/{path}/setup.py test --quiet
36flags: preserve-locale
37
38unit: template
39template-unit: job
40template-resource:enum/python-projects
41template-filter: project.build_i18n == 'yes'
42template-imports: from 2015.com.canonical.checkbox.selftest import enum/python-projects as project
43id: test/{name}/build-i18n
44_summary: Build {title} Internationalization Catalog
45_description:
46 This job builds all of the localization catalogs for {name}.
47command:
48 . $PLAINBOX_SESSION_SHARE/virtualenv/bin/activate
49 $SELFTEST_TOP/{path}/setup.py build_i18n -m
50depends: meta/bootstrap
51plugin: shell
52estimated_duration: 1.0
53flags: preserve-locale
54
55unit: template
56template-unit: job
57template-resource:enum/python-projects
58template-filter: project.build_sphinx_html == 'yes'
59template-imports: from 2015.com.canonical.checkbox.selftest import enum/python-projects as project
60id: test/{name}/build-html-docs
61_summary: Build {title} HTML Documentation
62_description:
63 This job builds all of the HTML documentation for {name}.
64command:
65 . $PLAINBOX_SESSION_SHARE/virtualenv/bin/activate
66 # XXX: Due to a bug somewhere we cannot build manual pages from a temporary
67 # directory. I haven't figure out what is causing this yet.
68 cd $SELFTEST_TOP/{path}
69 $SELFTEST_TOP/{path}/setup.py build_sphinx -b html
70depends: meta/bootstrap
71plugin: shell
72estimated_duration: 1.0
73flags: preserve-locale
74
75unit: template
76template-unit: job
77template-resource:enum/python-projects
78template-filter: project.build_sphinx_man == 'yes'
79template-imports: from 2015.com.canonical.checkbox.selftest import enum/python-projects as project
80id: test/{name}/build-manpages
81_summary: Build {title} Manual Pages
82_description:
83 This job builds all of the manual pages for {name}.
84command:
85 . $PLAINBOX_SESSION_SHARE/virtualenv/bin/activate
86 . $PLAINBOX_SESSION_SHARE/virtualenv/bin/activate
87 # XXX: Due to a bug somewhere we cannot build manual pages from a temporary
88 # directory. I haven't figure out what is causing this yet.
89 cd $SELFTEST_TOP/{path}
90 $SELFTEST_TOP/{path}/setup.py build_sphinx -b man
91depends: meta/bootstrap
92plugin: shell
93estimated_duration: 1.0
94flags: preserve-locale
95
96id: test/plainbox/integration-tests
97_summary: Plainbox Integration Tests
98_description:
99 This job runs all of the "integration tests" for plainbox. Integration
100 tests are really mis-named and should eventually be removed and
101 transitioned into testing all of the providers that live in this project.
102 In practice integration tests run a set of automated tests on a small
103 subset of the "checkbox source" provider.
104command:
105 . $PLAINBOX_SESSION_SHARE/virtualenv/bin/activate
106 export LANGUAGE=en
107 export LANG=C.UTF-8
108 export COVERAGE_FILE=$PLAINBOX_SESSION_SHARE/coverage
109 coverage run --append --branch --module plainbox \
110 self-test --after-reexec --integration-tests --quiet
111depends: meta/bootstrap, test/plainbox/develop
112plugin: shell
113estimated_duration: 1.0
114flags: preserve-locale
0115
=== added file '.selftest/units/smoke.pxu'
--- .selftest/units/smoke.pxu 1970-01-01 00:00:00 +0000
+++ .selftest/units/smoke.pxu 2015-03-19 08:53:15 +0000
@@ -0,0 +1,11 @@
1id: selftest/smoke
2unit: job
3_summary: Smoke test for selftest
4_description:
5 This smoke test can be used to check if selftest itself can run anything.
6 This tests simply prints a message and quits successfully.
7plugin: shell
8command:
9 echo "Smoke test successful"
10flags: preserve-locale
11estimated_duration: 1.0
012
=== added file '.selftest/units/support.pxu'
--- .selftest/units/support.pxu 1970-01-01 00:00:00 +0000
+++ .selftest/units/support.pxu 2015-03-19 08:53:15 +0000
@@ -0,0 +1,120 @@
1id: support/bare-virtualenv
2_summary: Create a bare virtualenv
3_description:
4 This job creates a new virtualenv that is required by other tests. This
5 virtualenv is created in the $PLAINBOX_SESSION_SHARE/virtualenv directory,
6 which is a temporary directory unique to each testing session.
7plugin: shell
8estimated_duration: 3
9command:
10 set -x
11 virtualenv \
12 --system-site-packages \
13 --python=/usr/bin/python3 \
14 $PLAINBOX_SESSION_SHARE/virtualenv
15flags: preserve-locale
16
17id: support/inject-extra-env
18_summary: Populate virtualenv with additional environment variables
19_description:
20 This job appends a number of checkbox-specific envirionment variables to the
21 activation script of the virtualenv. Since many other scripts source the same
22 file it is a simple and handy way to add some globals.
23 .
24 The variables are:
25 - PLAINBOX_LOCALE_DIR - assits in plainbox i18n when uninstalled
26 - CHECKBOX_NG_LOCALE_DIR - ditto
27 - CHECKBOX_PROVIDER_LOCALE_DIR - ditto
28 - PROVIDERPATH - tells plainbox where to look for providers
29 In addition, the directory specified by PROVIDERPATH is created.
30plugin: shell
31estimated_duration: 1
32depends: support/bare-virtualenv
33command:
34 set -e
35 set -x
36 echo "export PLAINBOX_LOCALE_DIR=$SELFTEST_TOP/plainbox/build/mo" >> $PLAINBOX_SESSION_SHARE/virtualenv/bin/activate
37 echo "export CHECKBOX_NG_LOCALE_DIR=$SELFTEST_TOP/checkbox-ng/build/mo" >> $PLAINBOX_SESSION_SHARE/virtualenv/bin/activate
38 echo "export CHECKBOX_PROVIDER_LOCALE_DIR=$SELFTEST_TOP/providers/plainbox-provider-checkbox/build/mo" >> $PLAINBOX_SESSION_SHARE/virtualenv/bin/activate
39 # Add PROVIDERPATH to the venv
40 echo "export PROVIDERPATH=$PLAINBOX_SESSION_SHARE/share/plainbox-providers-1" >> $PLAINBOX_SESSION_SHARE/virtualenv/bin/activate
41 mkdir -p "$PLAINBOX_SESSION_SHARE/share/plainbox-providers-1"
42flags: preserve-locale
43
44id: support/get-external-tarballs
45_summary: Clone the external-tarballs repository
46_description:
47 This job clones (or updates) the repository with external tarballs. The
48 revision to switch to is stored in support/external-tarballs-revision.txt
49plugin: shell
50estimated_duration: 1
51command:
52 set -e
53 if [ ! -d "$PLAINBOX_SESSION_SHARE/external-tarballs" ]; then
54 echo "I: cloning external-tarballs repository..."
55 # Clone the external-tarballs repo
56 git clone git://github.com/checkbox/external-tarballs \
57 $PLAINBOX_SESSION_SHARE/external-tarballs
58 fi
59 cd $PLAINBOX_SESSION_SHARE/external-tarballs/
60 # Fetch so that we may have the needed revision
61 if ! git fetch origin --quiet; then
62 echo "W: cannot perform fetch, external-tarballs may be out of date"
63 fi
64 # Ensure that we are on the correct revision
65 if ! git checkout $(cat $SELFTEST_TOP/support/external-tarballs-revision.txt); then
66 echo "E: cannot switch to required commit!"
67 exit 1
68 fi
69flags: preserve-locale
70
71id: support/install-pip-dependencies
72_summary: Install all python dependencies
73_description:
74 This job installs all of the dependencis specified by various
75 requirement/pip-*.txt files into a python virtualenv.
76plugin: shell
77estimated_duration: 1
78depends: support/bare-virtualenv, support/get-external-tarballs
79command:
80 set -e
81 set -x
82 # Set a http_proxy to the local discard port to prevent setuptools from
83 # downloading anything.
84 export http_proxy=http://127.0.0.1:9
85 # Custom pip executable. Needed because the pip we want is called
86 # differently in different situations. Inside a virtualenv it is always
87 # 'pip' but outside it may be pip-3.2 or pip-3.3, depending on python
88 # version.
89 CHECKBOX_PIP=${CHECKBOX_PIP:-pip}
90 echo "I: using $CHECKBOX_PIP to install python packages"
91 # Construct a list of required python packages.
92 python_pkg_list="$(find "$SELFTEST_TOP" -path '*/requirements/pip-*.txt' -exec cat "{}" \; | grep -v '^#' | sort | uniq)"
93 # Install them
94 echo "I: installing following pip packages:" $python_pkg_list
95 $CHECKBOX_PIP install --no-index \
96 "--find-links=file://$PLAINBOX_SESSION_SHARE/external-tarballs/index.html" \
97 $python_pkg_list
98flags: preserve-locale
99
100id: meta/bootstrap
101_summary: Meta-job for all bootstrap actions
102_description:
103 This metajob depends on all of the bootstrapping jobs
104plugin: shell
105estimated_duration: 1
106depends: support/bare-virtualenv, support/inject-extra-env, support/install-pip-dependencies
107command: :
108flags: preserve-locale
109
110id: pip-freeze
111_summary: Run 'pip freeze' in the virtual environment
112_description:
113 This metajob depends on all of the bootstrapping jobs
114plugin: shell
115estimated_duration: 1
116depends: support/bare-virtualenv, support/install-pip-dependencies
117command:
118 . $PLAINBOX_SESSION_SHARE/virtualenv/bin/activate
119 pip freeze
120flags: preserve-locale
0121
=== added file 'selftest.sh'
--- selftest.sh 1970-01-01 00:00:00 +0000
+++ selftest.sh 2015-03-19 08:53:15 +0000
@@ -0,0 +1,325 @@
1#!/bin/sh
2# This file is part of Checkbox.
3#
4# Copyright 2013-2015 Canonical Ltd.
5# Written by:
6# Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
7#
8# Checkbox is free software: you can redistribute it and/or modify
9# it under the terms of the GNU General Public License version 3,
10# as published by the Free Software Foundation.
11#
12# Checkbox is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with selftest. If not, see <http://www.gnu.org/licenses/>.
19
20# Feel free to customize those two lines for your project.
21SELFTEST_BOOTSTRAP_DIR=/tmp/selftest-bootstrap.venv
22SELFTEST_RUN_DEFAULT='-T 2015.com.canonical.checkbox.selftest::selftest'
23
24# The rest is generic, no need to change it.
25test -z "$SELFTEST_TOP" -a -d /vagrant && SELFTEST_TOP=/vagrant
26test -z "$SELFTEST_TOP" && SELFTEST_TOP="$(git rev-parse --show-toplevel 2>/dev/null)"
27test -z "$SELFTEST_TOP" && SELFTEST_TOP="$(bzr root)"
28export SELFTEST_TOP
29SELFTEST_PROVIDERPATH="$SELFTEST_BOOTSTRAP_DIR/share/plainbox-providers-1"
30SELFTEST_MANAGE="$SELFTEST_TOP/.selftest/manage.py"
31
32
33_selftest__detect_platform() {
34 echo "I: Detecting platform ..."
35 PLATFORM=$(
36 _selftest__load_os_release \
37 && echo "$ID-$VERSION_ID-$(uname -m | sed -e 's/x86_64/amd64/g')" \
38 || echo "error-error-error"
39 )
40 echo "N: Platform detected: $PLATFORM"
41}
42
43
44_selftest__load_os_release() {
45 # Try to guess where we are running
46 if [ -f /etc/os-release ]; then
47 # Load /etc/os-release if present
48 . /etc/os-release
49 elif [ "$(which lsb_release)" != "" ]; then
50 # Emulate /etc/os-release for well-known Ubuntu releases that lack it
51 # Ubuntu ships /etc/os-release starting with 12.04.2 or 12.10
52 # https://bugs.launchpad.net/ubuntu/+source/base-files/+bug/947236
53 case "$(lsb_release --short --description)" in
54 "Ubuntu 12.04 LTS")
55 NAME="Ubuntu"
56 VERSION="12.04 LTS, Precise Pangolin"
57 ID=ubuntu
58 ID_LIKE=debian
59 PRETTY_NAME="Ubuntu precise (12.04 LTS)"
60 VERSION_ID="12.04"
61 ;;
62 "Ubuntu 12.04.1 LTS")
63 NAME="Ubuntu"
64 VERSION="12.04.1 LTS, Precise Pangolin"
65 ID=ubuntu
66 ID_LIKE=debian
67 PRETTY_NAME="Ubuntu precise (12.04.1 LTS)"
68 VERSION_ID="12.04"
69 ;;
70 *)
71 NAME=Linux
72 ;;
73 esac
74 fi
75}
76
77
78
79_selftest__configure_platform() {
80 echo "I: Configuring platform ..."
81 case $PLATFORM in
82 ubuntu-*)
83 _selftest__configure_debian
84 ;;
85 elementary-*)
86 _selftest__configure_debian
87 ;;
88 debian-*)
89 _selftest__configure_debian
90 ;;
91 fedora-*)
92 _selftest__configure_fedora
93 ;;
94 *)
95 echo "E: Unable to configure platform $PLATFORM"
96 echo "E: Patch support/plainbox-selftest-provider/bootstrap"
97 echo "E: (look for _selftest__configure_platform)"
98 echo "E: If you think this should work then please report"
99 echo "E: a bug on https://bugs.launchpad.net/selftest/+filebug"
100 exit 1
101 ;;
102 esac
103}
104
105
106_selftest__configure_debian() {
107 export DEBIAN_FRONTEND=noninteractive
108 if ! sudo apt-get -qqy install python3 python-virtualenv; then
109 echo "E: Unable to instal core dependencies"
110 echo "E: Typically this happens when you are offline"
111 exit 1
112 fi
113}
114
115
116_selftest__configure_fedora() {
117 if ! sudo yum -q install -y python3 python-virtualenv; then
118 echo "E: Unable to instal core dependencies"
119 echo "E: Typically this happens when you are offline"
120 exit 1
121 fi
122}
123
124
125_selftest__install_stable_plainbox() {
126 echo "I: Creating python3 virtual environment"
127 if ! virtualenv --quiet -p python3 "$SELFTEST_BOOTSTRAP_DIR"; then
128 echo "E: Unable to create a virtualenv for python 3"
129 _selftest__bug
130 fi
131 _selftest__venv_enter
132 if ! pip freeze | grep plainbox >/dev/null; then
133 echo "I: Installing plainbox 0.20"
134 if ! pip install plainbox==0.20; then
135 echo "E: Unable to install plainbox 0.20"
136 echo "E: Typically this happens when you are offline"
137 exit 1
138 fi
139 fi
140 echo "I: Checking if plainbox is operational ..."
141 if [ "$(plainbox --version 2>&1 )" != 0.20 ]; then
142 echo "E: Installed plainbox doesn't work."
143 _selftest__bug
144 fi
145 _selftest__venv_exit
146}
147
148
149_selftest__develop_selftest_provider() {
150 echo "I: Developing the self-test provider ..."
151 _selftest__venv_enter
152 if ! "$SELFTEST_MANAGE" develop -f -d "$SELFTEST_PROVIDERPATH"; then
153 echo "E: Unable to develop the self-test provider"
154 _selftest__bug
155 fi
156 _selftest__venv_exit
157}
158
159_selftest__detect_broken_vagrant() {
160 if [ -d "/vagrant" ] ; then
161 # Vagrant sanity check, see if /vagrant really works.
162 #
163 # On various installations of Ubuntu this is not the case as the cloud images
164 # we depend on seem to have broken virtualbox tools installation inside. This
165 # causes the filesystem mounted on /vagrant to crash horribly and kill all
166 # processes attempting to use it.
167 echo "I: Checking for broken /vagrant ..."
168 if ! find /vagrant -mindepth 1 -maxdepth 1 >/dev/null; then
169 cat <<__EOM__
170 E: It seems that /vagrant directory is broken
171 E: This is a known issue.
172 E: See this link for a workaround if you have recent-enough VirtualBox:
173 E: https://bugs.launchpad.net/ubuntu/+source/virtualbox/+bug/1252872
174 E: Alternatively you can use NFS on any version of VirtualBox:
175 E: http://docs.vagrantup.com/v2/synced-folders/nfs.html
176__EOM__
177 exit 1
178 else
179 echo "I: It seems that /vagrant is working okay"
180 fi
181 fi
182}
183
184
185_selftest__patch_broken_pkg_resources() {
186 if sudo patch -p0 /usr/lib/python3/dist-packages/pkg_resources.py << EOF
187--- pkg_resources.py.orig 2014-05-15 19:39:38.365807720 +0000
188+++ pkg_resources.py 2014-05-15 19:44:50.449807720 +0000
189@@ -1749,11 +1749,16 @@
190 for dist in find_distributions(os.path.join(path_item, entry)):
191 yield dist
192 elif not only and lower.endswith('.egg-link'):
193- for line in open(os.path.join(path_item, entry)):
194- if not line.strip(): continue
195- for item in find_distributions(os.path.join(path_item,line.rstrip())):
196- yield item
197- break
198+ try:
199+ entry_file = open(os.path.join(path_item, entry))
200+ for line in entry_file:
201+ if not line.strip(): continue
202+ for item in find_distributions(os.path.join(path_item,line.rstrip())):
203+ yield item
204+ break
205+ finally:
206+ entry_file.close()
207+
208 register_finder(ImpWrapper,find_on_path)
209
210 _declare_state('dict', _namespace_handlers={})
211EOF
212 then
213 echo "I: Patching pkg_resources.py succeeded"
214 else
215 echo "E: Unable to patch pkg_resources.py :-("
216 _selftest__bug
217 fi
218}
219
220
221_selftest__bug() {
222 echo "E: Please report a bug on https://bugs.launchpad.net/checkbox/+filebug"
223 exit 1
224}
225
226
227_selftest__venv_enter() {
228 . "$SELFTEST_BOOTSTRAP_DIR/bin/activate"
229}
230
231
232_selftest__venv_exit() {
233 deactivate
234}
235
236
237_selftest__bootstrap() {
238 _selftest__detect_broken_vagrant
239 _selftest__detect_platform
240 _selftest__configure_platform
241 _selftest__install_stable_plainbox
242 _selftest__develop_selftest_provider
243}
244
245
246_selftest__maybe_bootstrap() {
247 if [ ! -e "$SELFTEST_BOOTSTRAP_DIR" ]; then
248 echo "N: Doing automatic bootstrap ..."
249 _selftest__bootstrap
250 fi
251}
252
253
254_selftest__run() {
255 _selftest__venv_enter
256 PROVIDERPATH="$SELFTEST_PROVIDERPATH" plainbox run ${@:-$SELFTEST_RUN_DEFAULT}
257 retval=$?
258 _selftest__venv_exit
259 return $retval
260}
261
262
263_selftest__manage() {
264 _selftest__venv_enter
265 "$SELFTEST_MANAGE" "$@"
266 _selftest__venv_exit
267}
268
269
270_selftest__shell() {
271 _selftest__venv_enter
272 echo "I: activating interactive selftest shell"
273 echo "I: type 'exit' to quit"
274 PROVIDERPATH="$SELFTEST_PROVIDERPATH" debian_chroot="selftest" bash "$@"
275 _selftest__venv_exit
276}
277
278
279_selftest__main() {
280 case "$1" in
281 '')
282 _selftest__maybe_bootstrap
283 _selftest__run "$@"
284 exit $?
285 ;;
286 run)
287 shift
288 _selftest__maybe_bootstrap
289 _selftest__run "$@"
290 exit $?
291 ;;
292 bootstrap)
293 shift
294 _selftest__bootstrap
295 exit $?
296 ;;
297 validate)
298 shift
299 _selftest__manage validate "$@"
300 exit $?
301 ;;
302 info)
303 shift
304 _selftest__manage info "$@"
305 exit $?
306 ;;
307 manage)
308 shift
309 _selftest__manage "$@"
310 exit $?
311 ;;
312 shell)
313 shift
314 _selftest__shell "$@"
315 exit $?
316 ;;
317 *)
318 echo "Usage: selftest {boostrap,run,validate,info,manage,shell}"
319 exit 1
320 ;;
321 esac
322}
323
324
325_selftest__main "$@"

Subscribers

People subscribed via source and target branches