Merge lp:~free.ekanayaka/landscape-charm/use-sample-hashids-for-tests into lp:~landscape/landscape-charm/trunk

Proposed by Free Ekanayaka
Status: Merged
Approved by: Free Ekanayaka
Approved revision: 266
Merged at revision: 270
Proposed branch: lp:~free.ekanayaka/landscape-charm/use-sample-hashids-for-tests
Merge into: lp:~landscape/landscape-charm/trunk
Diff against target: 136 lines (+57/-5)
3 files modified
lib/apt.py (+16/-0)
lib/tests/test_apt.py (+20/-1)
tests/helpers.py (+21/-4)
To merge this branch: bzr merge lp:~free.ekanayaka/landscape-charm/use-sample-hashids-for-tests
Reviewer Review Type Date Requested Status
Fernando Correa Neto (community) Approve
🤖 Landscape Builder test results Approve
Björn Tillenius (community) Approve
Review via email: mp+258771@code.launchpad.net

Commit message

Use the lightweight hashids package when running integration tests.

This branch changes the integration tests code to add a "flag" use-sample-hashids file to the charm directory. If the install hook sees this file it will add an extra PPA that holds a lightweight hashids package.

Description of the change

Use the lightweight hashids package when running integration tests.

This branch changes the integration tests code to add a "flag" use-sample-hashids file to the charm directory. If the install hook sees this file it will add an extra PPA that holds a lightweight hashids package.

The extra PPA is a temporary one, but is good enough for now.

To test it, just run integration tests:

SKIP_SLOW_TESTS=1 make integration-test-trunk

(make sure juju is pointing to a non-bootstrapped environment, with the local provider)

To post a comment you must log in.
Revision history for this message
🤖 Landscape Builder (landscape-builder) wrote :
review: Approve (test results)
265. By Free Ekanayaka

Merge from trunk

Revision history for this message
🤖 Landscape Builder (landscape-builder) wrote :
review: Approve (test results)
Revision history for this message
Björn Tillenius (bjornt) wrote :

Thanks for this, this reduced the deploy time by 30 seconds for me. +1 with some minor comments.

review: Approve
Revision history for this message
Free Ekanayaka (free.ekanayaka) :
266. By Free Ekanayaka

Address review comments

Revision history for this message
🤖 Landscape Builder (landscape-builder) wrote :
review: Approve (test results)
Revision history for this message
Fernando Correa Neto (fcorrea) wrote :

Looks good. +1

Still having 100% of cronjob failures but it seems unrelated to this branch.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/apt.py'
2--- lib/apt.py 2015-04-08 11:28:24 +0000
3+++ lib/apt.py 2015-05-12 10:27:12 +0000
4@@ -13,6 +13,10 @@
5 PACKAGES_DEV = ("dpkg-dev", "pbuilder")
6 TARBALL = "landscape-server_*.tar.gz"
7
8+# XXX Eventually we'll want to use a dedicated PPA, populated by Jenkins.
9+SAMPLE_HASHIDS_PPA = "ppa:landscape/fake-kernel"
10+SAMPLE_HASHIDS_KEY = "4652B4E6"
11+
12 # XXX Default options taken from charmhelpers, there's no way to just
13 # extend them.
14 DEFAULT_INSTALL_OPTIONS = ("--option=Dpkg::Options::=--force-confold",)
15@@ -86,6 +90,9 @@
16
17 self._fetch.add_source(source, config.get("key"))
18
19+ if self._use_sample_hashids():
20+ self._fetch.add_source(SAMPLE_HASHIDS_PPA, SAMPLE_HASHIDS_KEY)
21+
22 return True
23
24 def _set_local_source(self):
25@@ -135,3 +142,12 @@
26 fd.write(digest)
27
28 return True
29+
30+ def _use_sample_hashids(self):
31+ """Whether to use sample hashids instead of the real ones.
32+
33+ This method will check for a 'use-sample-hashids' file in the charm
34+ directory and return True if it finds one.
35+ """
36+ charm_dir = self._hookenv.charm_dir()
37+ return os.path.exists(os.path.join(charm_dir, "use-sample-hashids"))
38
39=== modified file 'lib/tests/test_apt.py'
40--- lib/tests/test_apt.py 2015-03-09 11:56:34 +0000
41+++ lib/tests/test_apt.py 2015-05-12 10:27:12 +0000
42@@ -1,6 +1,8 @@
43 import os
44
45-from lib.apt import Apt, PACKAGES, BUILD_LOCAL_ARCHIVE, DEFAULT_INSTALL_OPTIONS
46+from lib.apt import (
47+ Apt, PACKAGES, BUILD_LOCAL_ARCHIVE, DEFAULT_INSTALL_OPTIONS,
48+ SAMPLE_HASHIDS_PPA, SAMPLE_HASHIDS_KEY)
49 from lib.hook import HookError
50 from lib.tests.stubs import FetchStub, SubprocessStub
51 from lib.tests.helpers import HookenvTest
52@@ -64,6 +66,23 @@
53 self.assertEqual([("ppa:landscape/15.01", None)], self.fetch.sources)
54 self.assertEqual([True], self.fetch.updates)
55
56+ def test_set_sources_sample_hashids(self):
57+ """
58+ The C{set_sources} method adds the sample hashids PPA if a
59+ file named 'use-sample-hashids' is found.
60+ """
61+ self.hookenv.config()["source"] = "ppa:landscape/14.10"
62+ flag_file = os.path.join(
63+ self.hookenv.charm_dir(), "use-sample-hashids")
64+ with open(flag_file, "w") as fd:
65+ fd.write("")
66+ self.apt.set_sources()
67+ self.assertEqual(
68+ [("ppa:landscape/14.10", None),
69+ (SAMPLE_HASHIDS_PPA, SAMPLE_HASHIDS_KEY)],
70+ self.fetch.sources)
71+ self.assertEqual([True], self.fetch.updates)
72+
73 def test_local_tarball(self):
74 """
75 If a Landscape tarball is found, the C{set_sources} method builds local
76
77=== modified file 'tests/helpers.py'
78--- tests/helpers.py 2015-05-11 14:16:10 +0000
79+++ tests/helpers.py 2015-05-12 10:27:12 +0000
80@@ -77,7 +77,7 @@
81 try:
82 self._deployment.setup(timeout=self._timeout)
83 finally:
84- shutil.rmtree(repo_dir)
85+ self._clean_repo_dir(repo_dir)
86 self._deployment.sentry.wait(self._timeout)
87
88 self._stopped_landscape_services = []
89@@ -100,10 +100,17 @@
90 """Start the given Landscape service on the given unit."""
91 self._control_landscape_service("start", service, unit)
92
93+ def _get_charm_dir(self):
94+ """Get the path to the root of the charm directory."""
95+ return os.path.join(os.path.dirname(__file__), "..")
96+
97+ def _get_sample_hashids_path(self):
98+ """Get the path to the flag file for enabling sample hashids."""
99+ return os.path.join(self._get_charm_dir(), "use-sample-hashids")
100+
101 def _get_bundle(self):
102 """Return a dict with the data for the test bundle."""
103- charm_dir = os.path.join(os.path.dirname(__file__), "..")
104- bundles_dir = os.path.join(charm_dir, "bundles")
105+ bundles_dir = os.path.join(self._get_charm_dir(), "bundles")
106 environment = Environment(
107 loader=FileSystemLoader(bundles_dir), trim_blocks=True,
108 lstrip_blocks=True, keep_trailing_newline=True)
109@@ -115,7 +122,7 @@
110 if source == "lds-trunk-ppa":
111 # We want the lds-trunk PPA, let's grab its details from
112 # the secrets directory
113- secrets_dir = os.path.join(charm_dir, "secrets")
114+ secrets_dir = os.path.join(self._get_charm_dir(), "secrets")
115 with open(os.path.join(secrets_dir, "lds-trunk-ppa")) as fd:
116 extra_config = yaml.safe_load(fd.read())
117 else:
118@@ -148,8 +155,18 @@
119 charm_link = os.path.join(series_dir, "landscape-server")
120 os.symlink(branch_dir, charm_link)
121 os.environ["JUJU_REPOSITORY"] = repo_dir
122+
123+ # Enable sample hashids
124+ with open(self._get_sample_hashids_path(), "w") as fd:
125+ fd.write("")
126+
127 return repo_dir
128
129+ def _clean_repo_dir(self, repo_dir):
130+ """Clean up the repository directory and the sample hashids flag."""
131+ shutil.rmtree(repo_dir)
132+ os.unlink(self._get_sample_hashids_path())
133+
134 def _control_landscape_service(self, action, service, unit):
135 """Start or stop the given Landscape service on the given unit."""
136 unit = self._deployment.sentry.unit["landscape-server/%d" % unit]

Subscribers

People subscribed via source and target branches