Merge ~hloeung/jenkins-agent-charm:cleanup into jenkins-agent-charm:master

Proposed by Haw Loeung
Status: Superseded
Proposed branch: ~hloeung/jenkins-agent-charm:cleanup
Merge into: jenkins-agent-charm:master
Diff against target: 292 lines (+49/-81)
11 files modified
Makefile (+1/-1)
dev/null (+0/-50)
reactive/jenkins_slave.py (+1/-10)
tests/bundles (+1/-0)
tests/functional/bundles/base-bionic.yaml (+22/-0)
tests/functional/bundles/overlays/local-charm-overlay.yaml.j2 (+3/-0)
tests/functional/requirements.txt (+1/-6)
tests/functional/tests.yaml (+14/-0)
tests/tests.yaml (+1/-0)
tests/unit/test_jenkins_slave.py (+3/-9)
tox.ini (+2/-5)
Reviewer Review Type Date Requested Status
Jenkins CI Charmers Pending
Review via email: mp+370978@code.launchpad.net

This proposal has been superseded by a proposal from 2019-08-06.

Commit message

Fixed stuck on blocked state discovered from functional testing

To post a comment you must log in.

Unmerged commits

63b6101... by Haw Loeung

Fixed stuck on blocked state discovered from functional testing

34fc4c7... by Haw Loeung

Ignore more deprecated warnings

5cde3e0... by Haw Loeung

Fixed to handle jenkins' non-ready status and deploy nrpe

d96d5f6... by Haw Loeung

Deployable functional test

241b827... by Haw Loeung

Work around not being able to specify location to bundles and tests.yaml

2fdb42b... by Haw Loeung

Initial work replacing functional tests with zaza

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/Makefile b/Makefile
2index e592bf7..43470ed 100644
3--- a/Makefile
4+++ b/Makefile
5@@ -13,7 +13,7 @@ lint:
6 @echo "Running flake8"
7 @tox -e lint
8
9-test: unittest functionaltest lint
10+test: lint unittest functionaltest
11
12 unittest:
13 @tox -e unit
14diff --git a/reactive/jenkins_slave.py b/reactive/jenkins_slave.py
15index ac888a4..68421be 100755
16--- a/reactive/jenkins_slave.py
17+++ b/reactive/jenkins_slave.py
18@@ -65,7 +65,6 @@ def install():
19 host.service('enable', 'jenkins-slave')
20
21 status.maintenance('Installing jenkins-slave... done.')
22- reactive.clear_flag('jenkins-slave.blocked')
23 reactive.clear_flag('jenkins-slave.configured')
24 reactive.set_flag('jenkins-slave.installed')
25
26@@ -73,14 +72,12 @@ def install():
27 @reactive.when('config.changed')
28 def config_changed():
29 status.maintenance('Configuration changed')
30- reactive.clear_flag('jenkins-slave.blocked')
31 reactive.clear_flag('jenkins-slave.configured')
32 reactive.clear_flag('nagios-nrpe.configured')
33
34
35 @reactive.when('jenkins-slave.installed')
36 @reactive.when_not('jenkins-slave.configured')
37-@reactive.when_not('jenkins-slave.blocked')
38 def configure_jenkins_slave():
39 status.maintenance('configuring jenkins-slave')
40 reactive.clear_flag('jenkins-slave.active')
41@@ -97,7 +94,7 @@ def configure_jenkins_slave():
42 else:
43 status.maintenance("No 'master_url' set; not configuring slave at this time.")
44 status.blocked("requires either slave relation or 'master_url'")
45- reactive.set_flag('jenkins-slave.blocked')
46+ reactive.clear_flag('jenkins-slave.active')
47 return
48
49 file_to_units('files/jenkins-slave-sudoers', '/etc/sudoers.d/jenkins', perms=0o440)
50@@ -106,11 +103,6 @@ def configure_jenkins_slave():
51 reactive.set_flag('jenkins-slave.configured')
52
53
54-@reactive.when('jenkins-slave.blocked')
55-def blocked_on_jenkins_url():
56- reactive.clear_flag('jenkins-slave.active')
57-
58-
59 @reactive.when('jenkins-slave.configured')
60 @reactive.when('jenkins-slave.active')
61 @reactive.when('nrpe-external-master.available')
62@@ -151,7 +143,6 @@ def set_active():
63 @reactive.hook('slave-relation-joined', 'slave-relation-changed')
64 def slave_relation_changed():
65 reactive.set_flag('slave-relation.available')
66- reactive.clear_flag('jenkins-slave.blocked')
67 reactive.clear_flag('jenkins-slave.configured')
68 reactive.clear_flag('slave-relation.configured')
69
70diff --git a/requirements.txt b/requirements.txt
71deleted file mode 100644
72index 8462291..0000000
73--- a/requirements.txt
74+++ /dev/null
75@@ -1 +0,0 @@
76-# Include python requirements here
77diff --git a/tests/bundles b/tests/bundles
78new file mode 120000
79index 0000000..dbd0feb
80--- /dev/null
81+++ b/tests/bundles
82@@ -0,0 +1 @@
83+functional/bundles
84\ No newline at end of file
85diff --git a/tests/functional/bundles/base-bionic.yaml b/tests/functional/bundles/base-bionic.yaml
86new file mode 100644
87index 0000000..cb92d23
88--- /dev/null
89+++ b/tests/functional/bundles/base-bionic.yaml
90@@ -0,0 +1,22 @@
91+series: bionic
92+
93+applications:
94+ jenkins:
95+ charm: cs:jenkins
96+ num_units: 1
97+ options:
98+ username: admin
99+ password: admin
100+ expose: true
101+
102+ jenkins-slave:
103+ num_units: 1
104+
105+ nrpe:
106+ charm: cs:nrpe
107+
108+relations:
109+ - - jenkins
110+ - jenkins-slave
111+ - - jenkins-slave
112+ - nrpe
113diff --git a/tests/functional/bundles/overlays/local-charm-overlay.yaml.j2 b/tests/functional/bundles/overlays/local-charm-overlay.yaml.j2
114new file mode 100644
115index 0000000..1adcb54
116--- /dev/null
117+++ b/tests/functional/bundles/overlays/local-charm-overlay.yaml.j2
118@@ -0,0 +1,3 @@
119+applications:
120+ jenkins-slave:
121+ charm: /tmp/charm-builds/jenkins-slave
122diff --git a/tests/functional/requirements.txt b/tests/functional/requirements.txt
123index f76bfbb..b7c9112 100644
124--- a/tests/functional/requirements.txt
125+++ b/tests/functional/requirements.txt
126@@ -1,6 +1 @@
127-flake8
128-juju
129-mock
130-pytest
131-pytest-asyncio
132-requests
133+git+https://github.com/openstack-charmers/zaza.git#egg=zaza
134diff --git a/tests/functional/test_jenkins_slave.py b/tests/functional/test_jenkins_slave.py
135deleted file mode 100644
136index e5051ac..0000000
137--- a/tests/functional/test_jenkins_slave.py
138+++ /dev/null
139@@ -1,50 +0,0 @@
140-import os
141-import pytest
142-from juju.model import Model
143-
144-# Treat tests as coroutines
145-pytestmark = pytest.mark.asyncio
146-
147-series = ['bionic']
148-juju_repository = os.getenv('JUJU_REPOSITORY', '.').rstrip('/')
149-
150-
151-@pytest.fixture
152-async def model():
153- model = Model()
154- await model.connect_current()
155- yield model
156- await model.disconnect()
157-
158-
159-@pytest.fixture
160-async def apps(model):
161- apps = []
162- for entry in series:
163- app = model.applications['jenkins-slave-{}'.format(entry)]
164- apps.append(app)
165- return apps
166-
167-
168-@pytest.fixture
169-async def units(apps):
170- units = []
171- for app in apps:
172- units.extend(app.units)
173- return units
174-
175-
176-@pytest.mark.parametrize('series', series)
177-async def test_jenkins_slave_deploy(model, series):
178- # Starts a deploy for each series
179- await model.deploy('{}/builds/jenkins-slave'.format(juju_repository),
180- series=series,
181- application_name='jenkins-slave-{}'.format(series))
182- assert True
183-
184-
185-async def test_jenkins_slave_status(apps, model):
186- # Verifies status for all deployed series of the charm
187- for app in apps:
188- await model.block_until(lambda: app.status == 'active')
189- assert True
190diff --git a/tests/functional/tests.yaml b/tests/functional/tests.yaml
191new file mode 100644
192index 0000000..757a6ea
193--- /dev/null
194+++ b/tests/functional/tests.yaml
195@@ -0,0 +1,14 @@
196+charm_name: jenkins-slave
197+tests:
198+ - zaza.charm_tests.noop.tests.NoopTest
199+configure:
200+ - zaza.charm_tests.noop.setup.basic_setup
201+gate_bundles:
202+ - base-bionic
203+dev_bundles:
204+ - base-bionic
205+smoke_bundles:
206+ - base-bionic
207+target_deploy_status:
208+ jenkins:
209+ workload-status-message: Jenkins is running
210diff --git a/tests/tests.yaml b/tests/tests.yaml
211new file mode 120000
212index 0000000..19e19a7
213--- /dev/null
214+++ b/tests/tests.yaml
215@@ -0,0 +1 @@
216+functional/tests.yaml
217\ No newline at end of file
218diff --git a/tests/unit/test_jenkins_slave.py b/tests/unit/test_jenkins_slave.py
219index a09c457..efcdb7f 100644
220--- a/tests/unit/test_jenkins_slave.py
221+++ b/tests/unit/test_jenkins_slave.py
222@@ -81,6 +81,7 @@ class TestSetDefaultConf(unittest.TestCase):
223
224 apt.reset_mock()
225 status.active.reset_mock()
226+ status.blocked.reset_mock()
227 status.maintenance.reset_mock()
228
229 @mock.patch('charms.reactive.clear_flag')
230@@ -98,8 +99,7 @@ class TestSetDefaultConf(unittest.TestCase):
231 '''Test correct flags are set via config-changed charm hook'''
232 jenkins_slave.config_changed()
233 self.assertFalse(status.maintenance.assert_called())
234- expected = [mock.call('jenkins-slave.blocked'),
235- mock.call('jenkins-slave.configured'),
236+ expected = [mock.call('jenkins-slave.configured'),
237 mock.call('nagios-nrpe.configured')]
238 self.assertFalse(clear_flag.assert_has_calls(expected, any_order=True))
239
240@@ -174,7 +174,7 @@ class TestSetDefaultConf(unittest.TestCase):
241 unitdata_kv.return_value = {}
242 jenkins_slave.configure_jenkins_slave()
243 self.assertFalse(write_default_conf.assert_not_called())
244- self.assertFalse(set_flag.assert_has_calls([mock.call('jenkins-slave.blocked')], any_order=True))
245+ self.assertFalse(status.blocked.assert_called())
246 self.assertFalse(clear_flag.assert_has_calls([mock.call('jenkins-slave.active')], any_order=True))
247
248 @mock.patch('charms.reactive.clear_flag')
249@@ -209,11 +209,6 @@ class TestSetDefaultConf(unittest.TestCase):
250 expected = [mock.call('jenkins-slave.active'), mock.call('nagios-nrpe.configured')]
251 self.assertFalse(clear_flag.assert_has_calls(expected, any_order=True))
252
253- @mock.patch('charms.reactive.clear_flag')
254- def test_blocked_on_jenkins_url(self, clear_flag):
255- jenkins_slave.blocked_on_jenkins_url()
256- self.assertFalse(clear_flag.assert_has_calls([mock.call('jenkins-slave.active')], any_order=True))
257-
258 @mock.patch('charmhelpers.core.host.service_running')
259 @mock.patch('charmhelpers.core.host.service_restart')
260 @mock.patch('charmhelpers.core.host.service_start')
261@@ -241,7 +236,6 @@ class TestSetDefaultConf(unittest.TestCase):
262 def test_hook_slave_relation_changed_flags(self, set_flag, clear_flag):
263 jenkins_slave.slave_relation_changed()
264 expected = [
265- mock.call('jenkins-slave.blocked'),
266 mock.call('jenkins-slave.configured'),
267 mock.call('slave-relation.configured'),
268 ]
269diff --git a/tox.ini b/tox.ini
270index d6b7675..99078b2 100644
271--- a/tox.ini
272+++ b/tox.ini
273@@ -11,17 +11,14 @@ setenv =
274 [testenv:unit]
275 commands = pytest -v --ignore {toxinidir}/tests/functional --cov=lib --cov=reactive --cov=actions --cov-report=term-missing --cov-branch
276 deps = -r{toxinidir}/tests/unit/requirements.txt
277- -r{toxinidir}/requirements.txt
278 setenv = PYTHONPATH={toxinidir}/lib
279
280 [testenv:functional]
281 passenv =
282 HOME
283- JUJU_REPOSITORY
284- PATH
285-commands = pytest -v --ignore {toxinidir}/tests/unit
286+basepython = python3
287+commands = functest-run-suite --keep-model
288 deps = -r{toxinidir}/tests/functional/requirements.txt
289- -r{toxinidir}/requirements.txt
290
291 [testenv:lint]
292 commands = flake8

Subscribers

People subscribed via source and target branches