Can't deploy local charm via API

Bug #1616574 reported by Tim Van Steenburgh
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
python-jujuclient
Triaged
Critical
Tim Van Steenburgh

Bug Description

The steps used to deploy a local charm via the api under juju1 no longer work on juju2 (beta15).

Here's a python script to repro. You'll need the latest lp:python-jujuclient, which you can install from source or from ppa:tvansteenburgh/ppa.

tvansteenburgh@xenial-vm:~/python-jujuclient⟫ cat deploy_test.py
#!/usr/bin/env python3

import logging
import ssl

from jujuclient.juju2.environment import Environment

log = logging.getLogger(__name__)

# Constants, change these for your environment
API_SERVER = '10.0.4.52'
USER = 'user-admin'
PASSWORD = 'd7247825e7df512140005cb2b6aab925'
CHARM_DIR = '/home/tvansteenburgh/src/charms/trusty/ubuntu'

if __name__ == "__main__":
    logging.basicConfig(level=logging.DEBUG)

    # Login to controller
    endpoint = 'wss://%s:17070' % (API_SERVER)
    controller = Environment(endpoint)
    controller.login(PASSWORD, user=USER)

    # Login to default model
    models = controller.models.list()
    for m in models['user-models']:
        if m['model']['name'] == 'default':
            model_endpoint = '{}/model/{}/api'.format(
                endpoint, m['model']['uuid'])
            model = Environment(model_endpoint)
            model.login(PASSWORD, user=USER)

    # Workaround for certificatge failure (hack)
    ssl._create_default_https_context = ssl._create_unverified_context

    # Upload a local charm to the model
    res = model.add_local_charm_dir(CHARM_DIR, "trusty")
    log.debug("Added local charm: %s", res)

    # Turn on rpc debugging so we can see raw api calls
    model._debug = True

    # Deploy the uploaded charm
    res = model.deploy('mycharm', res['charm-url'])
    log.debug("Deploy response: %s", res)

And here's the output of running it. As you can see, the local charm is uploaded successfully and we get a charm-url back, but then when we try to deploy the charm using that url, it doesn't work:

tvansteenburgh@xenial-vm:~/python-jujuclient⟫ .tox/py27/bin/python deploy_test.py
DEBUG:__main__:Added local charm: {u'charm-url': u'local:trusty/ubuntu-3'}
DEBUG:jujuclient.rpc:rpc request:
{
  "params": {
    "applications": [
      {
        "placement": [],
        "num-units": 1,
        "application": "mycharm",
        "charm-url": "local:trusty/ubuntu-3",
        "config": {},
        "constraints": {}
      }
    ]
  },
  "request-id": 2,
  "version": 1,
  "request": "Deploy",
  "type": "Application"
}
DEBUG:jujuclient.rpc:rpc response:
{
  "request-id": 2,
  "response": {
    "results": [
      {
        "error": {
          "message": "charm \"local:trusty/ubuntu-3\" not found",
          "code": "not found"
        }
      }
    ]
  }
}
DEBUG:__main__:Deploy response: {u'results': [{u'error': {u'message': u'charm "local:trusty/ubuntu-3" not found', u'code': u'not found'}}]}

Changed in juju:
status: New → Triaged
importance: Undecided → High
milestone: none → 2.0-beta17
Marco Ceppi (marcoceppi)
Changed in juju:
importance: High → Critical
Changed in juju:
assignee: nobody → Katherine Cox-Buday (cox-katherine-e)
affects: juju → python-jujuclient
Changed in python-jujuclient:
milestone: 2.0-beta17 → none
Revision history for this message
Tim Van Steenburgh (tvansteenburgh) wrote :

Turns out that model.uuid is None since the Environment is instantiated with a bare IP endpoint, and the model uuid is not passed in. The effect is the the charm is uploaded to the controller instead of the model. So it gets a valid charm-url back, but it's from the controller, not the model, so when you try to deploy that charm in the model, it's not found.

Totally not a bug in juju.

@katco, I'm sorry for wasting your time. Thanks for your patience and helpfulness.

Changed in python-jujuclient:
assignee: Katherine Cox-Buday (cox-katherine-e) → Tim Van Steenburgh (tvansteenburgh)
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.