Skip to content

Commit 49c5554

Browse files
johnscaDavid Garcia
andauthored
Switch from Travis to GitHub Actions, fix some issues (#415)
* Switch from Travis to GitHub Actions * Fixes #417 and #419 * Run lint sooner * Fix action result having new values Fixes #421 * Fix failing unit test Co-authored-by: David Garcia <david.garcia@canonical.com>
1 parent 9e1409a commit 49c5554

7 files changed

Lines changed: 76 additions & 68 deletions

File tree

.github/workflows/tox.yaml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Run tests with Tox
2+
3+
on: [push]
4+
5+
jobs:
6+
build:
7+
8+
runs-on: ubuntu-latest
9+
strategy:
10+
matrix:
11+
python: [3.6, 3.7, 3.8]
12+
juju: [stable, edge]
13+
14+
steps:
15+
- uses: actions/checkout@v2
16+
- name: Setup Python
17+
uses: actions/setup-python@v1
18+
with:
19+
python-version: ${{ matrix.python }}
20+
- name: Install Tox and any other packages
21+
run: pip install tox
22+
- name: Run Lint and Unit Tests
23+
run: tox -e lint,py3
24+
- name: Install Snaps
25+
run: |
26+
sudo snap install lxd
27+
sudo snap install juju --classic --channel ${{ matrix.juju }}
28+
sudo snap install juju-wait --classic
29+
- name: Configure LXD
30+
run: |
31+
sudo lxd waitready --timeout 30
32+
sudo chmod 666 /var/snap/lxd/common/lxd/unix.socket
33+
lxd init --auto --network-address='[::]' --network-port=8443 --storage-backend=dir
34+
lxc network set lxdbr0 ipv6.address none
35+
- name: Bootstrap Juju Controller
36+
run: juju bootstrap localhost test --config 'identity-url=https://api.staging.jujucharms.com/identity' --config 'allow-model-access=true' --config 'test-mode=true'
37+
- name: Run Integration Tests
38+
run: tox -e integration,serial
39+
env:
40+
TEST_AGENTS: '{"agents":[{"url":"https://api.staging.jujucharms.com/identity","username":"libjuju-ci@yellow"}],"key":{"private":"88OOCxIHQNguRG7zFg2y2Hx5Ob0SeVKKBRnjyehverc=","public":"fDn20+5FGyN2hYO7z0rFUyoHGUnfrleslUNtoYsjNSs="}}'

.travis.yml

Lines changed: 0 additions & 52 deletions
This file was deleted.

juju/application.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ async def get_actions(self, schema=False):
311311
actions = result.actions
312312
break
313313
if not schema:
314-
actions = {k: v['description'] for k, v in actions.items()}
314+
actions = {k: v.description for k, v in actions.items()}
315315
return actions
316316

317317
async def get_resources(self):

juju/unit.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -279,25 +279,27 @@ async def is_leader_from_status(self):
279279

280280
# Is the application a subordinate? If so change our data variables to
281281
# the parent
282-
if status.applications[app].get('subordinate-to'):
282+
if status.applications[app].subordinate_to:
283283
is_subordinate = True
284-
target_apps = status.applications[app]['subordinate-to']
284+
target_apps = status.applications[app].subordinate_to
285285

286286
for target_app in target_apps:
287287
app_data = status.applications[target_app]
288288

289-
if not app_data.get('units'):
289+
if not app_data.units:
290290
continue
291291

292-
if app_data['units'].get(self.name):
293-
return app_data['units'][self.name].get('leader', False)
292+
if app_data.units.get(self.name):
293+
is_leader = app_data.units[self.name].leader
294+
return is_leader if is_leader else False
294295

295296
if not is_subordinate:
296297
continue
297298

298-
for key, unit in app_data['units'].items():
299-
if unit.get('subordinates') and unit['subordinates'].get(self.name):
300-
return unit['subordinates'][self.name].get('leader', False)
299+
for key, unit in app_data.units.items():
300+
if unit.subordinates and unit.subordinates.get(self.name):
301+
is_leader = unit.subordinates[self.name].leader
302+
return is_leader if is_leader else False
301303

302304
return False
303305

tests/integration/test_unit.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,25 @@ async def run_action(unit):
5757

5858
for unit in app.units:
5959
action = await run_action(unit)
60-
assert action.results == {'dir': '/var/git/myrepo.git'}
60+
assert action.results == {
61+
'Code': '0',
62+
'Stdout': "Adding group `myrepo' (GID 1001) ...\n"
63+
'Done.\n'
64+
'Initialized empty Git repository in '
65+
'/var/git/myrepo.git/\n',
66+
'dir': '/var/git/myrepo.git',
67+
}
6168
out = await model.get_action_output(action.entity_id, wait=5)
62-
assert out == {'dir': '/var/git/myrepo.git'}
63-
status = await model.get_action_status(uuid_or_prefix=action.entity_id)
69+
assert out == {
70+
'Code': '0',
71+
'Stdout': "Adding group `myrepo' (GID 1001) ...\n"
72+
'Done.\n'
73+
'Initialized empty Git repository in '
74+
'/var/git/myrepo.git/\n',
75+
'dir': '/var/git/myrepo.git',
76+
}
77+
status = await model.get_action_status(
78+
uuid_or_prefix=action.entity_id)
6479
assert status[action.entity_id] == 'completed'
6580
break
6681

tests/unit/test_unit.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from juju.model import Model
66
from juju.unit import Unit
7+
from juju.client._definitions import FullStatus
78

89
from .. import base
910

@@ -137,8 +138,7 @@ async def test_unit_is_leader(mock_cf):
137138
model._connector = mock.MagicMock()
138139

139140
for test in tests:
140-
status = mock.Mock()
141-
status.applications = test['applications']
141+
status = FullStatus.from_json(test)
142142
client_facade = mock_cf.from_connection()
143143
client_facade.FullStatus = base.AsyncMock(return_value=status)
144144

tox.ini

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ commands =
3939
py.test --tb native -ra -v -s -n auto -k 'not integration' -m 'not serial' {posargs}
4040

4141
[testenv:lint]
42-
envdir = {toxworkdir}/py3
4342
commands =
4443
flake8 --ignore E501,W504,E402 {posargs} juju tests examples
4544
deps =
@@ -56,7 +55,11 @@ commands =
5655
[testenv:serial]
5756
# tests that can't be run in parallel
5857
envdir = {toxworkdir}/py3
59-
commands = py.test --tb native -ra -v -s {posargs:-m 'serial'}
58+
commands =
59+
# These need to be installed in a specific order
60+
pip install urllib3==1.25.7
61+
pip install pylxd
62+
py.test --tb native -ra -v -s {posargs:-m 'serial'}
6063

6164
[testenv:example]
6265
envdir = {toxworkdir}/py3

0 commit comments

Comments
 (0)