Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JUJU-1457] Merge 3.0 compatibility branch onto master #692

Merged
merged 41 commits into from
Jul 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
15bed75
Add schema and the new clients
cderici Jul 12, 2022
067d60d
Update the facade versions
cderici Jul 12, 2022
d42f7e6
Move get_info into the controller
cderici Jul 15, 2022
0ec285d
Use GetModelConstraints from ModelConfigFacade
cderici Jul 15, 2022
33f175b
Use MachineManager facade for destroying machines
cderici Jul 15, 2022
f7eccd1
Temporarily disable subordinate check with CharmHub at deploy
cderici Jul 15, 2022
b80ea7e
Point to the correct schema
cderici Jul 15, 2022
d1c31bd
ClientFacade->ModelConfigFacade for SetModelConstraints
cderici Jul 15, 2022
83e4f8e
Fix deploy_local_bundle_dir
cderici Jul 15, 2022
40b2ab0
Update the base64 test bundle to use charmhub
cderici Jul 15, 2022
a874649
ClientFacade->MachineManagerFacade for ProvisioningScript
cderici Jul 15, 2022
fdbffa8
Fix _connect_direct to pass model_uuid to get_model_info
cderici Jul 15, 2022
49b81d1
Update the unit tests to use the correct facades
cderici Jul 18, 2022
8b7e7b8
Merge pull request #689 from cderici/3.0-compat
jujubot Jul 19, 2022
94454b4
Fix upgrade charm to use the CharmsFacade
cderici Jul 18, 2022
74f3570
Fix set/unset ApplicationConfig
cderici Jul 19, 2022
eae718e
Allow time in test for actions to be registered
cderici Jul 20, 2022
392b630
Fix CharmHub stuff and bring back subordinate check
cderici Jul 20, 2022
8cf5414
Fix unit test
cderici Jul 20, 2022
42ba24f
GetCharmURL -> GetCharmURLOrigin
cderici Jul 20, 2022
cdf624e
Fix GetConsumeDetails args OfferURLs
cderici Jul 20, 2022
274e90e
Fix the ActionFacade.Run
cderici Jul 20, 2022
08fb01c
Merge pull request #691 from cderici/more-test-fixes-for-3.0-compat
jujubot Jul 21, 2022
3a7922e
Turn client module into a dynamic binding registry
cderici Jul 22, 2022
8f05333
Generate code to use _2_9_clients along with _clients
cderici Jul 22, 2022
f45389f
Exclude the old_clients from lint
cderici Jul 22, 2022
54567a1
Correct facade switch for GetModelConstraints
cderici Jul 22, 2022
9852c13
Lazily import classes in test_model.py
cderici Jul 22, 2022
e210cce
Disable pre-check for new_client value
cderici Jul 22, 2022
cc2dbee
Defer importing client bindings only when needed
cderici Jul 22, 2022
5e6a338
Correct facade switch for ProvisioningScript
cderici Jul 22, 2022
8f230c8
Add the actual old clients for 2.9 and missing schemas for completeness
cderici Jul 22, 2022
9bc9370
Use correct _definitions in old_clients/_client
cderici Jul 22, 2022
f6ef0e7
Remove redundant code in client codegen in facade.py
cderici Jul 22, 2022
a16716c
Fix unit test mocks to include server-version
cderici Jul 22, 2022
7716314
Correct facade switch for destroying machines in 2.9
cderici Jul 22, 2022
c5f2bac
Introduce a way on the connection to check the client version
cderici Jul 22, 2022
a1c4f20
Correct result field switch for 2.9
cderici Jul 22, 2022
2887fce
Use the nicer way to check if using old client
cderici Jul 22, 2022
4a41e04
Improve charmhub api request code with retries
cderici Jul 22, 2022
e516285
Keep only the relevant schemas in hand
cderici Jul 22, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions juju/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,10 +431,9 @@ async def get_actions(self, schema=False):
:return dict: The charms actions, empty dict if none are defined.
"""
actions = {}
entity = [{"tag": self.tag}]
entity = {"tag": self.tag}
action_facade = client.ActionFacade.from_connection(self.connection)
results = (
await action_facade.ApplicationsCharmsActions(entities=entity)).results
results = (await action_facade.ApplicationsCharmsActions(entities=[entity])).results
for result in results:
if result.application_tag == self.tag and result.actions:
actions = result.actions
Expand Down Expand Up @@ -563,7 +562,10 @@ async def set_config(self, config):
else:
raise JujuApplicationConfigError(config, [k, v])

await app_facade.Set(application=self.name, options=str_config)
return await app_facade.SetConfigs(args=[{
"application": self.name,
"config": str_config,
}])

async def reset_config(self, to_default):
"""
Expand All @@ -577,7 +579,10 @@ async def reset_config(self, to_default):
log.debug(
'Restoring default config for %s: %s', self.name, to_default)

return await app_facade.Unset(application=self.name, options=to_default)
return await app_facade.UnsetApplicationsConfig(args=[{
"application": self.name,
"options": to_default,
}])

async def set_constraints(self, constraints):
"""Set machine constraints for this application.
Expand Down Expand Up @@ -619,7 +624,7 @@ async def refresh(
if switch is not None and revision is not None:
raise ValueError("switch and revision are mutually exclusive")

client_facade = client.ClientFacade.from_connection(self.connection)
charms_facade = client.CharmsFacade.from_connection(self.connection)
resources_facade = client.ResourcesFacade.from_connection(
self.connection)
app_facade = self._facade()
Expand All @@ -644,11 +649,15 @@ async def refresh(
if charm_url == self.data['charm-url']:
raise JujuError('already running charm "%s"' % charm_url)

# TODO (caner) : this needs to be revisited and updated with the charmhub stuff
origin = client.CharmOrigin(source="charm-store",
risk=channel,
)
# Update charm
await client_facade.AddCharm(
await charms_facade.AddCharm(
url=charm_url,
force=force,
channel=channel
charm_origin=origin,
)

# Update resources
Expand Down
12 changes: 6 additions & 6 deletions juju/bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ def __init__(self, model, trusted=False, forced=False):
model.connection())
self.ann_facade = client.AnnotationsFacade.from_connection(
model.connection())
self.machine_manager_facade = client.MachineManagerFacade.from_connection(
model.connection())

# Feature detect if we have the new charms facade, otherwise fallback
# to the client facade, when making calls.
Expand Down Expand Up @@ -617,10 +619,8 @@ async def run(self, context):
self.application, charm, overrides=self.resources)
elif Schema.CHARM_HUB.matches(url.schema):
c_hub = charmhub.CharmHub(context.model)
info = await c_hub.info(url.name, channel=self.channel)
if info.errors.error_list.code:
raise JujuError("unable to resolve the charm {} with channel {}".format(url.name, channel))
origin.id_ = info.result.id_
id_, _ = c_hub.get_charm_id(url.name)
origin.id_ = id_
resources = await context.model._add_charmhub_resources(
self.application, charm, origin, overrides=self.resources)
else:
Expand Down Expand Up @@ -726,7 +726,7 @@ async def run(self, context):
if Schema.CHARM_STORE.matches(url.schema):
entity_id = await context.charmstore.entityId(self.charm, channel=self.channel)
log.debug('Adding %s', entity_id)
await context.client_facade.AddCharm(channel=self.channel, url=entity_id, force=False)
await context.charms_facade.AddCharm(channel=self.channel, url=entity_id, force=False)
identifier = entity_id
origin = client.CharmOrigin(source="charm-store", risk="stable")

Expand Down Expand Up @@ -837,7 +837,7 @@ async def run(self, context):

# Submit the request.
params = client.AddMachineParams(**params)
results = await context.client_facade.AddMachines(params=[params])
results = await context.machine_manager_facade.AddMachines(params=[params])
error = results.machines[0].error
if error:
raise ValueError("Error adding machine: %s" % error.message)
Expand Down
31 changes: 31 additions & 0 deletions juju/charmhub.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,42 @@
from .client import client
from .errors import JujuError
from juju import jasyncio

import requests
import json


class CharmHub:
def __init__(self, model):
self.model = model

def request_charmhub_with_retry(self, url, retries):
for attempt in range(retries):
_response = requests.get(url)
if _response.status_code == 200:
return _response
jasyncio.sleep(5)
raise JujuError("Got {} from {}".format(_response.status_code, url))

def get_charm_id(self, charm_name):
conn, headers, path_prefix = self.model.connection().https_connection()

url = "http://api.snapcraft.io/v2/charms/info/{}".format(charm_name)
_response = self.request_charmhub_with_retry(url, 5)
response = json.loads(_response.text)
return response['id'], response['name']

def is_subordinate(self, charm_name):
conn, headers, path_prefix = self.model.connection().https_connection()

url = "http://api.snapcraft.io/v2/charms/info/{}?fields=default-release.revision.subordinate".format(charm_name)
_response = self.request_charmhub_with_retry(url, 5)
response = json.loads(_response.text)
return 'subordinate' in response['default-release']['revision']

# TODO (caner) : we should be able to recreate the channel-map through the
# api call without needing the CharmHub facade

async def info(self, name, channel=None):
"""info displays detailed information about a CharmHub charm. The charm
can be specified by the exact name.
Expand Down
12 changes: 8 additions & 4 deletions juju/client/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

from juju.client._definitions import *

from juju.client import _client2, _client1, _client3, _client4, _client5, _client8, _client7, _client9, _client10, _client6, _client12, _client11, _client13, _client15, _client16, _client17, _client18

from juju.client import _client2, _client1, _client3, _client4, _client5, _client8, _client7, _client9, _client10, _client6, _client12, _client11, _client13, _client15, _client16, _client17, _client18, _client14


CLIENTS = {
Expand All @@ -23,11 +24,11 @@
"15": _client15,
"16": _client16,
"17": _client17,
"18": _client18
"18": _client18,
"14": _client14
}



def lookup_facade(name, version):
"""
Given a facade name and version, attempt to pull that facade out
Expand All @@ -45,7 +46,6 @@ def lookup_facade(name, version):
"{}".format(name))



class TypeFactory:
@classmethod
def from_connection(cls, connection):
Expand Down Expand Up @@ -259,6 +259,10 @@ class EntityWatcherFacade(TypeFactory):
pass


class EnvironUpgraderFacade(TypeFactory):
pass


class ExternalControllerUpdaterFacade(TypeFactory):
pass

Expand Down
Loading