Merge lp:~free.ekanayaka/landscape-charm/faster-hashids-test into lp:~landscape/landscape-charm/trunk

Proposed by Free Ekanayaka
Status: Merged
Approved by: Free Ekanayaka
Approved revision: 293
Merged at revision: 294
Proposed branch: lp:~free.ekanayaka/landscape-charm/faster-hashids-test
Merge into: lp:~landscape/landscape-charm/trunk
Diff against target: 185 lines (+71/-10)
6 files modified
Makefile (+1/-1)
lib/apt.py (+12/-1)
lib/paths.py (+1/-0)
lib/tests/rootdir.py (+1/-1)
lib/tests/test_apt.py (+56/-1)
tests/basic/test_service.py (+0/-6)
To merge this branch: bzr merge lp:~free.ekanayaka/landscape-charm/faster-hashids-test
Reviewer Review Type Date Requested Status
Chad Smith Approve
Adam Collard (community) Approve
🤖 Landscape Builder test results Approve
Review via email: mp+260474@code.launchpad.net

Commit message

Use the sample hash-id-databases configuration in order to make the test_hash_id_databases_cron test run faster.

Description of the change

Use the sample hash-id-databases configuration in order to make the test_hash_id_databases_cron test run faster.

To post a comment you must log in.
Revision history for this message
🤖 Landscape Builder (landscape-builder) wrote :

Command: make ci-test
Result: Success
Revno: 291
Branch: lp:~free.ekanayaka/landscape-charm/faster-hashids-test
Jenkins: https://ci.lscape.net/job/latch-test/1072/

review: Approve (test results)
Revision history for this message
Chad Smith (chad.smith) wrote :

Marking Needs Fixing to see how you intend to resolve the current error.

review: Needs Fixing
Revision history for this message
Free Ekanayaka (free.ekanayaka) :
292. By Free Ekanayaka

Address review comments

293. By Free Ekanayaka

Merge from trunk, fix conflicts

Revision history for this message
🤖 Landscape Builder (landscape-builder) wrote :

Command: make ci-test
Result: Success
Revno: 293
Branch: lp:~free.ekanayaka/landscape-charm/faster-hashids-test
Jenkins: https://ci.lscape.net/job/latch-test/1114/

review: Approve (test results)
Revision history for this message
Adam Collard (adam-collard) wrote :

+1.

Sorry this took so long, I fell in the usual traps for integration tests on charms.

1) don't run make integration-test; run make integration-test-trunk
2) don't use a MAAS provider that you're not pointing DNS at

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

> +1.
>
> Sorry this took so long, I fell in the usual traps for integration tests on
> charms.
>
> 1) don't run make integration-test; run make integration-test-trunk
> 2) don't use a MAAS provider that you're not pointing DNS at

Errata corrige:

2) don't use a MAAS provider, use a local provider

Revision history for this message
Chad Smith (chad.smith) wrote :

Yes my failing was regarding running make integration-test (which fails with 100% of the time with this branch) and not make integration-test-trunk.

I'm not sure we need backwards compatibility for make integration-test in landscape-charm/trunk with landscape-charm/stable as this charm branch will eventually be stable when we are trying to run make integration-test in jenkins.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Makefile'
2--- Makefile 2015-05-26 12:57:37 +0000
3+++ Makefile 2015-05-29 09:32:29 +0000
4@@ -41,7 +41,7 @@
5 fi
6
7 integration-test: test-depends
8- juju test --set-e -p SKIP_SLOW_TESTS,LS_CHARM_SOURCE,JUJU_HOME,JUJU_ENV,PG_MANUAL_TUNING -v --timeout 3000s
9+ juju test --set-e -p LS_CHARM_SOURCE,JUJU_HOME,JUJU_ENV,PG_MANUAL_TUNING -v --timeout 3000s
10
11 integration-test-dense-maas:
12 DEPLOYER_TARGET=landscape-dense-maas $(MAKE) integration-test
13
14=== modified file 'lib/apt.py'
15--- lib/apt.py 2015-05-26 07:23:02 +0000
16+++ lib/apt.py 2015-05-29 09:32:29 +0000
17@@ -8,6 +8,7 @@
18 from charmhelpers.core import hookenv
19
20 from lib.hook import HookError
21+from lib.paths import default_paths
22
23 PACKAGES = ("landscape-server",)
24 PACKAGES_DEV = ("dpkg-dev", "pbuilder")
25@@ -45,10 +46,12 @@
26 tarball.
27 """
28
29- def __init__(self, hookenv=hookenv, fetch=fetch, subprocess=subprocess):
30+ def __init__(self, hookenv=hookenv, fetch=fetch, subprocess=subprocess,
31+ paths=default_paths):
32 self._hookenv = hookenv
33 self._fetch = fetch
34 self._subprocess = subprocess
35+ self._paths = paths
36
37 def set_sources(self):
38 """Configure the extra APT sources to use."""
39@@ -70,6 +73,14 @@
40 packages = self._fetch.filter_installed_packages(PACKAGES)
41 self._fetch.apt_install(packages, options=options, fatal=True)
42
43+ if self._use_sample_hashids():
44+ config_dir = self._paths.config_dir()
45+ real = os.path.join(config_dir, "hash-id-databases.conf")
46+ sample = os.path.join(config_dir, "hash-id-databases-sample.conf")
47+ if not os.path.exists(real + ".orig"):
48+ os.rename(real, real + ".orig")
49+ shutil.copy(sample, real)
50+
51 def _set_remote_source(self):
52 """Set the remote APT repository to use, if new or changed."""
53 config = self._hookenv.config()
54
55=== modified file 'lib/paths.py'
56--- lib/paths.py 2015-05-21 07:31:32 +0000
57+++ lib/paths.py 2015-05-29 09:32:29 +0000
58@@ -8,6 +8,7 @@
59 INSTALL_DIR = "/opt/canonical/landscape"
60 CONFIG_DIR = INSTALL_DIR + "/configs/standalone"
61 OFFLINE_DIR = INSTALL_DIR + "/canonical/landscape/offline"
62+
63 SCHEMA_SCRIPT = "/usr/bin/landscape-schema"
64
65 LICENSE_FILE = "/etc/landscape/license.txt"
66
67=== modified file 'lib/tests/rootdir.py'
68--- lib/tests/rootdir.py 2015-04-29 15:53:55 +0000
69+++ lib/tests/rootdir.py 2015-05-29 09:32:29 +0000
70@@ -16,7 +16,7 @@
71 def setUp(self):
72 super(RootDir, self).setUp()
73 self.paths = Paths(self.path)
74- os.makedirs(os.path.dirname(self.paths.config_dir()))
75+ os.makedirs(self.paths.config_dir())
76 os.makedirs(os.path.dirname(self.paths.ssl_certificate()))
77 os.makedirs(self.paths.offline_dir())
78 for path in ERRORFILES_MAP.itervalues():
79
80=== modified file 'lib/tests/test_apt.py'
81--- lib/tests/test_apt.py 2015-05-29 07:05:34 +0000
82+++ lib/tests/test_apt.py 2015-05-29 09:32:29 +0000
83@@ -9,6 +9,7 @@
84 from lib.hook import HookError
85 from lib.tests.stubs import FetchStub, SubprocessStub
86 from lib.tests.helpers import HookenvTest
87+from lib.tests.rootdir import RootDir
88
89
90 class AptTest(HookenvTest):
91@@ -17,11 +18,14 @@
92 super(AptTest, self).setUp()
93 self.fetch = FetchStub()
94 self.subprocess = SubprocessStub()
95+ self.root_dir = self.useFixture(RootDir())
96+ self.paths = self.root_dir.paths
97 self.subprocess.add_fake_executable("add-apt-repository")
98 self.subprocess.add_fake_executable(
99 "/usr/lib/pbuilder/pbuilder-satisfydepends")
100 self.apt = Apt(
101- hookenv=self.hookenv, fetch=self.fetch, subprocess=self.subprocess)
102+ hookenv=self.hookenv, fetch=self.fetch, subprocess=self.subprocess,
103+ paths=self.paths)
104
105 def _create_local_tarball(self, name, version):
106 """Create a local minimal source package tarball that can be built.
107@@ -173,3 +177,54 @@
108 self.apt.install_packages()
109 options = list(DEFAULT_INSTALL_OPTIONS) + ["--allow-unauthenticated"]
110 self.assertEqual([(PACKAGES, options, True)], self.fetch.installed)
111+
112+ def test_install_sample_hashids(self):
113+ """
114+ If a file named 'use-sample-hashids' is found the install() method
115+ replaces the real hash-id-databases config file with the sample one.
116+ """
117+ self.hookenv.config()["source"] = "ppa:landscape/14.10"
118+ charm_dir = self.hookenv.charm_dir()
119+ config_dir = self.paths.config_dir()
120+ flag_file = os.path.join(charm_dir, "use-sample-hashids")
121+ real = os.path.join(config_dir, "hash-id-databases.conf")
122+ sample = os.path.join(config_dir, "hash-id-databases-sample.conf")
123+ with open(flag_file, "w") as fd:
124+ fd.write("")
125+ with open(real, "w") as fd:
126+ fd.write("real")
127+ with open(sample, "w") as fd:
128+ fd.write("sample")
129+ self.apt.install_packages()
130+
131+ with open(real + ".orig") as fd:
132+ self.assertEqual("real", fd.read())
133+
134+ with open(real) as fd:
135+ self.assertEqual("sample", fd.read())
136+
137+ def test_install_sample_hashids_idempotent(self):
138+ """
139+ The real hash-id-databases configuration file is not renamed again
140+ if was already.
141+ """
142+ self.hookenv.config()["source"] = "ppa:landscape/14.10"
143+ charm_dir = self.hookenv.charm_dir()
144+ config_dir = self.paths.config_dir()
145+ flag_file = os.path.join(charm_dir, "use-sample-hashids")
146+ real = os.path.join(config_dir, "hash-id-databases.conf")
147+ sample = os.path.join(config_dir, "hash-id-databases-sample.conf")
148+ with open(flag_file, "w") as fd:
149+ fd.write("")
150+ with open(real, "w") as fd:
151+ fd.write("real")
152+ with open(sample, "w") as fd:
153+ fd.write("sample")
154+ self.apt.install_packages()
155+ self.apt.install_packages()
156+
157+ with open(real + ".orig") as fd:
158+ self.assertEqual("real", fd.read())
159+
160+ with open(real) as fd:
161+ self.assertEqual("sample", fd.read())
162
163=== modified file 'tests/basic/test_service.py'
164--- tests/basic/test_service.py 2015-05-22 09:15:39 +0000
165+++ tests/basic/test_service.py 2015-05-29 09:32:29 +0000
166@@ -4,10 +4,6 @@
167 FIXME: revert to using ssh -q, stderr=STDOUT instead of 2>&1, stderr=PIPE once
168 lp:1281577 is addressed.
169 """
170-
171-import unittest
172-
173-from os import getenv
174 from subprocess import check_output, CalledProcessError, PIPE
175
176 from helpers import IntegrationTest
177@@ -234,8 +230,6 @@
178 self.assertEqual(output, "")
179 self.assertEqual(status, 0)
180
181- @unittest.skipIf(getenv("SKIP_SLOW_TESTS", None),
182- "Requested to skip slow tests.")
183 def test_hash_id_databases_cron(self):
184 """Verify that the hash_id_databases cron job runs without errors."""
185 script = "/opt/canonical/landscape/scripts/hash_id_databases.sh"

Subscribers

People subscribed via source and target branches