Skip to content

Commit 81d22c1

Browse files
Start fixing the integration tests
The integration tests do work when run as a file, but fail when attempting to run the whole thing as one. In order to get some tests starting to pass green I think the best way would be to run each on and see if that helps.
1 parent 62517e9 commit 81d22c1

8 files changed

Lines changed: 47 additions & 10 deletions

File tree

juju/bundle.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ def resolve(self, reference):
307307

308308

309309
def is_local_charm(charm_url):
310-
return charm_url.startswith('.') or charm_url.startswith('local:')
310+
return charm_url.startswith('.') or charm_url.startswith('local:') or os.path.isabs(charm_url)
311311

312312

313313
def get_charm_series(path):
@@ -476,7 +476,7 @@ async def run(self, context):
476476
if self.channel is not None and self.channel != "":
477477
channel = Channel.parse(self.channel).normalize()
478478

479-
origin = context.origins[str(url)][str(channel)]
479+
origin = context.origins.get(str(url), {}).get(str(channel), None)
480480
if origin is None:
481481
raise JujuError("expected origin to be valid for application {} and charm {}".format(self.application, self.charm))
482482

@@ -570,6 +570,8 @@ async def run(self, context):
570570
ch = None
571571
identifier = None
572572
if Schema.LOCAL.matches(url.schema):
573+
origin = client.CharmOrigin(source="local", risk="stable")
574+
context.origins[self.charm] = {str(None): origin}
573575
return self.charm
574576

575577
elif Schema.CHARM_STORE.matches(url.schema):

juju/client/connection.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,14 +314,21 @@ async def connect(
314314
self.proxy.connect()
315315

316316
_endpoints = [(endpoint, cacert)] if isinstance(endpoint, str) else [(e, cacert) for e in endpoint]
317+
lastError = None
317318
for _ep in _endpoints:
318319
try:
319320
await self._connect_with_redirect([_ep])
320321
return self
322+
except ssl.SSLError as e:
323+
lastError = e
324+
continue
321325
except OSError as e:
322326
logging.debug(
323327
"Cannot access endpoint {}: {}".format(_ep, e.strerror))
328+
lastError = e
324329
continue
330+
if lastError is not None:
331+
raise lastError
325332
raise Exception("Unable to connect to websocket")
326333

327334
@property

juju/model.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
from . import provisioner, tag, utils
2222
from .annotationhelper import _get_annotations, _set_annotations
23-
from .bundle import BundleHandler, get_charm_series
23+
from .bundle import BundleHandler, get_charm_series, is_local_charm
2424
from .charmhub import CharmHub
2525
from .charmstore import CharmStore
2626
from .client import client, connector
@@ -1428,6 +1428,11 @@ async def deploy(
14281428
origin = None
14291429
result = None
14301430

1431+
# Ensure what we pass in, is a string.
1432+
entity_url = str(entity_url)
1433+
if is_local_charm(entity_url) and not entity_url.startswith("local:"):
1434+
entity_url = "local:{}".format(entity_url)
1435+
print("!!!", entity_url)
14311436
url = URL.parse(str(entity_url))
14321437
architecture = await self._resolve_architecture(url)
14331438

@@ -1441,6 +1446,7 @@ async def deploy(
14411446
if not (entity_path.is_dir() or entity_path.is_file()):
14421447
raise JujuError('{} path not found'.format(entity_url))
14431448

1449+
is_local = True
14441450
is_bundle = (
14451451
(entity_url.endswith(".yaml") and entity_path.exists()) or
14461452
bundle_path.exists()
@@ -1475,13 +1481,13 @@ async def deploy(
14751481
raise JujuError('unknown charm or bundle {}'.format(entity_url))
14761482

14771483
if not application_name:
1478-
if Schema.LOCAL.matches(url.schema) and Schema.CHARM_STORE.matches(url.schema):
1479-
application_name = result['Meta']['charm-metadata']['Name']
1480-
else:
1484+
if Schema.CHARM_HUB.matches(url.schema):
14811485
# For charmhub charms, we don't have the metadata and we're not
14821486
# going to get it, so fallback to the url and use that one if a
14831487
# user didn't specify it.
14841488
application_name = url.name
1489+
elif result is not None and not is_bundle:
1490+
application_name = result['Meta']['charm-metadata']['Name']
14851491

14861492
if is_bundle:
14871493
handler = BundleHandler(self, trusted=trust, forced=force)

juju/url.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def parse(s):
4141
raise JujuError("charm or bundle URL {} has unrecognized parts".format(u))
4242

4343
if Schema.LOCAL.matches(u.scheme):
44-
c = parse_v1_url(Schema.LOCAL, u, s)
44+
c = URL(Schema.LOCAL, name=u.path)
4545
elif Schema.CHARM_STORE.matches(u.scheme):
4646
c = parse_v1_url(Schema.CHARM_STORE, u, s)
4747
else:

tests/integration/test_application.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,26 @@ async def test_add_units(event_loop):
9393
assert isinstance(unit, Unit)
9494

9595

96+
@base.bootstrapped
97+
@pytest.mark.asyncio
98+
async def test_deploy_charmstore_charm(event_loop):
99+
async with base.CleanModel() as model:
100+
app = await model.deploy('cs:ubuntu-0')
101+
await model.block_until(lambda: (len(app.units) > 0 and
102+
app.units[0].machine))
103+
assert app.data['charm-url'] == 'cs:ubuntu-0'
104+
105+
106+
@base.bootstrapped
107+
@pytest.mark.asyncio
108+
async def test_deploy_charmhub_charm(event_loop):
109+
async with base.CleanModel() as model:
110+
app = await model.deploy('hello-juju')
111+
await model.block_until(lambda: (len(app.units) > 0 and
112+
app.units[0].machine))
113+
assert 'hello-juju' in app.data['charm-url']
114+
115+
96116
@base.bootstrapped
97117
@pytest.mark.asyncio
98118
async def test_upgrade_charm(event_loop):
@@ -135,7 +155,7 @@ async def test_upgrade_charm_revision(event_loop):
135155
@pytest.mark.asyncio
136156
async def test_upgrade_charm_switch(event_loop):
137157
async with base.CleanModel() as model:
138-
app = await model.deploy('ubuntu-0')
158+
app = await model.deploy('cs:ubuntu-0')
139159
await model.block_until(lambda: (len(app.units) > 0 and
140160
app.units[0].machine))
141161
assert app.data['charm-url'] == 'cs:ubuntu-0'

tests/integration/test_connection.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,8 @@ async def test_verify_controller_cert(event_loop):
270270
-----END CERTIFICATE-----
271271
"""
272272

273+
print(endpoint)
274+
273275
try:
274276
connection = await Connection.connect(
275277
endpoint=endpoint,

tests/integration/test_model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ async def test_wait_local_charm_waiting_timeout(event_loop):
137137
@pytest.mark.asyncio
138138
async def test_deploy_bundle(event_loop):
139139
async with base.CleanModel() as model:
140-
await model.deploy('bundle/wiki-simple')
140+
await model.deploy('cs:bundle/wiki-simple')
141141

142142
for app in ('wiki', 'mysql'):
143143
assert app in model.applications

tests/integration/test_unit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ async def test_run(event_loop):
1313

1414
async with base.CleanModel() as model:
1515
app = await model.deploy(
16-
'ubuntu-0',
16+
'cs:ubuntu-0',
1717
application_name='ubuntu',
1818
series='trusty',
1919
channel='stable',

0 commit comments

Comments
 (0)