Comment 3 for bug 1611514

Revision history for this message
Tim Van Steenburgh (tvansteenburgh) wrote :

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'}}]}