Improved Primitive support and better testing
This changeset addresses several issues.
- Improve primitive support so the status and output of an executed
primitive can be retrieved
- Merge latest upstream libjuju (required for new primive features)
- New testing framework
This is the start of a new testing framework with the ability to
create and configure LXD containers with SSH, to use while testing proxy
charms.
- Add support for using ssh keys with proxy charms
See Feature 1429. This uses the per-proxy charm/unit ssh keypair
Signed-off-by: Adam Israel <adam.israel@canonical.com>
diff --git a/modules/libjuju/docs/changelog.rst b/modules/libjuju/docs/changelog.rst
index caf778e..a4a4222 100644
--- a/modules/libjuju/docs/changelog.rst
+++ b/modules/libjuju/docs/changelog.rst
@@ -1,6 +1,60 @@
Changelog
---------
+<<<<<<< HEAD
+=======
+0.9.1
+^^^^^
+Monday July 16 2018
+
+* Update websockets to 6.0 to fix OS X support due to Brew update to Py3.7 (#254)
+
+
+0.9.0
+^^^^^
+Friday June 29 2018
+
+* python3.7 compatibility updates (#251)
+* Handle juju not installed in is_bootstrapped for tests (#250)
+* Add app.reset_config(list). (#249)
+* Implement model.get_action_status (#248)
+* Fix `make client` in Python 3.6 (#247)
+
+
+0.8.0
+^^^^^
+Thursday June 14 2018
+
+* Add support for adding a manual (ssh) machine (#240)
+* Backwards compatibility fixes (#213)
+* Implement model.get_action_output (#242)
+* Fix JSON serialization error for bundle with lxd to unit placement (#243)
+* Fix reference in docs to connect_current (#239)
+* Wrap machine agent status workaround in version check (#238)
+* Convert seconds to nanoseconds for juju.unit.run (#237)
+* Fix spurious intermittent failure in test_machines.py::test_status (#236)
+* Define an unused juju-zfs lxd storage pool for Travis (#235)
+* Add support for Application get_actions (#234)
+
+
+0.7.5
+^^^^^
+Friday May 18 2018
+
+* Surface errors from bundle plan (#233)
+* Always send auth-tag even with macaroon auth (#217)
+* Inline jsonfile credential when sending to controller (#231)
+
+0.7.4
+^^^^^
+Tuesday Apr 24 2018
+
+* Always parse tags and spaces constraints to lists (#228)
+* Doc index improvements (#211)
+* Add doc req to force newer pymacaroons to fix RTD builds
+* Fix dependency conflict for building docs
+
+>>>>>>> 8a2d5bc35a302a970244b3c307a4f47deac0af63
0.7.3
^^^^^
Tuesday Feb 20 2018
@@ -49,6 +103,7 @@
* Make Application.upgrade_charm upgrade resources (#158)
* Expand integration tests to use stable/edge versions of juju (#155)
* Move docs to ReadTheDocs (https://pythonlibjuju.readthedocs.io/en/latest/)
+<<<<<<< HEAD
0.6.1
^^^^^
@@ -60,6 +115,8 @@
* Make Application.upgrade_charm upgrade resources (#158)
* Expand integration tests to use stable/edge versions of juju (#155)
* Move docs to ReadTheDocs (https://pythonlibjuju.readthedocs.io/en/latest/)
+=======
+>>>>>>> 8a2d5bc35a302a970244b3c307a4f47deac0af63
0.6.0
^^^^^
diff --git a/modules/libjuju/docs/narrative/controller.rst b/modules/libjuju/docs/narrative/controller.rst
index 2da0e7b..1d86321 100644
--- a/modules/libjuju/docs/narrative/controller.rst
+++ b/modules/libjuju/docs/narrative/controller.rst
@@ -6,9 +6,9 @@
Connecting to the controller endpoint is useful if you want to programmatically
create a new model. If the model you want to use already exists, you can
-connect directly to it (see :doc:`model`).
+connect directly to it (see py:doc:`model`).
-For api docs, see :class:`juju.controller.Controller`.
+For API docs, see py:class:`juju.controller.Controller`.
Connecting to the Current Controller
@@ -21,7 +21,7 @@
from juju.controller import Controller
controller = Controller()
- await controller.connect_current()
+ await controller.connect()
Connecting to a Named Controller
@@ -33,68 +33,60 @@
from juju.controller import Controller
controller = Controller()
- await controller.connect_controller('mycontroller')
+ await controller.connect('mycontroller')
-Connecting with Username/Password Authentication
-------------------------------------------------
+Connecting with Authentication
+------------------------------
+You can control what user you are connecting with by specifying either a
+username/password pair, or a macaroon or bakery client that can provide
+a macaroon.
+
+
+.. code:: python
+
+ controller = Controller()
+ await controller.connect(username='admin',
+ password='f53f08cfc32a2e257fe5393271d89d62')
+
+ # or with a macaroon
+ await controller.connect(macaroons=[
+ {
+ "Name": "macaroon-218d87053ad19626bcd5a0eef0bc9ba8bd4fbd80a968f52a5fd430b2aa8660df",
+ "Value": "W3siY2F2ZWF0cyI6 ... jBkZiJ9XQ==",
+ "Domain": "10.130.48.27",
+ "Path": "/auth",
+ "Secure": false,
+ "HostOnly": true,
+ "Expires": "2018-03-07T22:07:23Z",
+ },
+ ])
+
+ # or with a bakery client
+ from macaroonbakery.httpbakery import Client
+ from http.cookiejar import FileCookieJar
+
+ bakery_client=Client()
+ bakery_client.cookies = FileCookieJar('cookies.txt')
+ controller = Controller()
+ await controller.connect(bakery_client=bakery_client)
+
+
+
+Connecting with an Explicit Endpoint
+------------------------------------
The most flexible, but also most verbose, way to connect is using the API
-endpoint url and credentials directly. This method does NOT require the Juju
-CLI client to be installed.
+endpoint url and credentials directly. This method does NOT require the
+Juju CLI client to be installed.
.. code:: python
- from juju.controller import Controller
-
controller = Controller()
-
- controller_endpoint = '10.0.4.171:17070'
- username = 'admin'
- password = 'f53f08cfc32a2e257fe5393271d89d62'
-
- # Left out for brevity, but if you have a cert string you should pass it in.
- # You can copy the cert from the output of The `juju show-controller`
- # command.
- cacert = None
-
await controller.connect(
- controller_endpoint,
- username,
- password,
- cacert,
- )
-
-
-Connecting with Macaroon Authentication
----------------------------------------
-To connect to a shared controller, you'll need
-to use macaroon authentication. The simplest example is shown below, and uses
-already-discharged macaroons from the local filesystem. This will work if you
-have the Juju CLI installed.
-
-.. note::
-
- The library does not yet contain support for fetching and discharging
- macaroons. Until it does, if you want to use macaroon auth, you'll need
- to supply already-discharged macaroons yourself.
-
-.. code:: python
-
- from juju.client.connection import get_macaroons()
- from juju.controller import Controller
-
- controller = Controller()
-
- controller_endpoint = '10.0.4.171:17070'
- username = None
- password = None
- cacert = None
- macaroons = get_macaroons()
-
- await controller.connect(
- controller_endpoint,
- username,
- password,
- cacert,
- macaroons,
+ endpoint='10.0.4.171:17070',
+ username='admin',
+ password='f53f08cfc32a2e257fe5393271d89d62',
+ cacert=None, # Left out for brevity, but if you have a cert string you
+ # should pass it in. You can get the cert from the output
+ # of The `juju show-controller` command.
)
diff --git a/modules/libjuju/docs/narrative/model.rst b/modules/libjuju/docs/narrative/model.rst
index 57dbc81..42633a1 100644
--- a/modules/libjuju/docs/narrative/model.rst
+++ b/modules/libjuju/docs/narrative/model.rst
@@ -4,7 +4,7 @@
models. In order to do anything useful with a model, the juju lib must
connect to one of these endpoints. There are several ways to do this.
-For api docs, see :class:`juju.model.Model`.
+For api docs, see py:class:`juju.model.Model`.
Connecting to the Current Model
@@ -14,10 +14,8 @@
.. code:: python
- from juju.model import Model
-
model = Model()
- await model.connect_current()
+ await model.connect()
Connecting to a Named Model
@@ -28,88 +26,74 @@
.. code:: python
- # $ juju switch
- # juju-2.0.1:admin/libjuju
+ model = Model()
+ await model.connect('juju-2.0.1:admin/libjuju')
- from juju.model import Model
+
+Connecting with Authentication
+------------------------------
+You can control what user you are connecting with by specifying either a
+username/password pair, or a macaroon or bakery client that can provide
+a macaroon.
+
+
+.. code:: python
model = Model()
- await model.connect_model('juju-2.0.1:admin/libjuju')
+ await model.connect(username='admin',
+ password='f53f08cfc32a2e257fe5393271d89d62')
+
+ # or with a macaroon
+ await model.connect(macaroons=[
+ {
+ "Name": "macaroon-218d87053ad19626bcd5a0eef0bc9ba8bd4fbd80a968f52a5fd430b2aa8660df",
+ "Value": "W3siY2F2ZWF0cyI6 ... jBkZiJ9XQ==",
+ "Domain": "10.130.48.27",
+ "Path": "/auth",
+ "Secure": false,
+ "HostOnly": true,
+ "Expires": "2018-03-07T22:07:23Z",
+ },
+ ])
+
+ # or with a bakery client
+ from macaroonbakery.httpbakery import Client
+ from http.cookiejar import FileCookieJar
+
+ bakery_client=Client()
+ bakery_client.cookies = FileCookieJar('cookies.txt')
+ model = Model()
+ await model.connect(bakery_client=bakery_client)
+
-Connecting with Username/Password Authentication
-------------------------------------------------
+Connecting with an Explicit Endpoint
+------------------------------------
The most flexible, but also most verbose, way to connect is using the API
-endpoint url and credentials directly. This method does NOT require the Juju
-CLI client to be installed.
+endpoint url, model UUID, and credentials directly. This method does NOT
+require the Juju CLI client to be installed.
.. code:: python
from juju.model import Model
model = Model()
-
- controller_endpoint = '10.0.4.171:17070'
- model_uuid = 'e8399ac7-078c-4817-8e5e-32316d55b083'
- username = 'admin'
- password = 'f53f08cfc32a2e257fe5393271d89d62'
-
- # Left out for brevity, but if you have a cert string you should pass it in.
- # You can copy the cert from the output of The `juju show-controller`
- # command.
- cacert = None
-
await model.connect(
- controller_endpoint,
- model_uuid,
- username,
- password,
- cacert,
- )
-
-
-Connecting with Macaroon Authentication
----------------------------------------
-To connect to a shared model, or a model an a shared controller, you'll need
-to use macaroon authentication. The simplest example is shown below, and uses
-already-discharged macaroons from the local filesystem. This will work if you
-have the Juju CLI installed.
-
-.. note::
-
- The library does not yet contain support for fetching and discharging
- macaroons. Until it does, if you want to use macaroon auth, you'll need
- to supply already-discharged macaroons yourself.
-
-.. code:: python
-
- from juju.client.connection import get_macaroons()
- from juju.model import Model
-
- model = Model()
-
- controller_endpoint = '10.0.4.171:17070'
- model_uuid = 'e8399ac7-078c-4817-8e5e-32316d55b083'
- username = None
- password = None
- cacert = None
- macaroons = get_macaroons()
-
- await model.connect(
- controller_endpoint,
- model_uuid,
- username,
- password,
- cacert,
- macaroons,
+ endpoint='10.0.4.171:17070',
+ uuid='e8399ac7-078c-4817-8e5e-32316d55b083',
+ username='admin',
+ password='f53f08cfc32a2e257fe5393271d89d62',
+ cacert=None, # Left out for brevity, but if you have a cert string you
+ # should pass it in. You can get the cert from the output
+ # of The `juju show-controller` command.
)
Creating and Destroying a Model
-------------------------------
Example of creating a new model and then destroying it. See
-:meth:`juju.controller.Controller.add_model` and
-:meth:`juju.controller.Controller.destroy_model` for more info.
+py:method:`juju.controller.Controller.add_model` and
+py:method:`juju.controller.Controller.destroy_model` for more info.
.. code:: python
@@ -134,8 +118,8 @@
Adding Machines and Containers
------------------------------
To add a machine or container, connect to a model and then call its
-:meth:`~juju.model.Model.add_machine` method. A
-:class:`~juju.machine.Machine` instance is returned. The machine id
+py:method:`~juju.model.Model.add_machine` method. A
+py:class:`~juju.machine.Machine` instance is returned. The machine id
can be used to deploy a charm to a specific machine or container.
.. code:: python
@@ -192,7 +176,7 @@
------------------------------
To watch for and respond to changes in a model, register an observer with the
model. The easiest way to do this is by creating a
-:class:`juju.model.ModelObserver` subclass.
+py:class:`juju.model.ModelObserver` subclass.
.. code:: python
@@ -283,7 +267,7 @@
# specific handler method is not defined.
-Any :class:`juju.model.ModelEntity` object can be observed directly by
+Any py:class:`juju.model.ModelEntity` object can be observed directly by
registering callbacks on the object itself.
.. code:: python
diff --git a/modules/libjuju/docs/readme.rst b/modules/libjuju/docs/readme.rst
index 886550d..87666d0 100644
--- a/modules/libjuju/docs/readme.rst
+++ b/modules/libjuju/docs/readme.rst
@@ -38,10 +38,7 @@
----------
Here's a simple example that shows basic usage of the library. The example
connects to the currently active Juju model, deploys a single unit of the
-ubuntu charm, then exits.
-
-More examples can be found in the `examples/` directory of the source tree,
-and in the documentation.
+ubuntu charm, then exits:
.. code:: python
@@ -95,3 +92,12 @@
if __name__ == '__main__':
main()
+
+
+More examples can be found in the docs, as well as in the ``examples/``
+directory of the source tree which can be run using ``tox``. For
+example, to run ``examples/connect_current_model.py``, use:
+
+.. code:: bash
+
+ tox -e example -- examples/connect_current_model.py
diff --git a/modules/libjuju/docs/upstream-updates/index.rst b/modules/libjuju/docs/upstream-updates/index.rst
index 7082a6e..41f448a 100644
--- a/modules/libjuju/docs/upstream-updates/index.rst
+++ b/modules/libjuju/docs/upstream-updates/index.rst
@@ -48,6 +48,54 @@
which facades were touched.
+Integrating into the Object Layer
+---------------------------------
+
+Once the raw client APIs are synced, you may need to integrate any new or
+changed API calls into the object layer, to provide a clean, Pythonic way
+to interact with the model. This may be as simple as adding an optional
+parameter to an existing model method, tweaking what manipulations, if any
+the model method does to the data before it is sent to the API, or it may
+require adding an entirely new model method to capture the new functionality.
+
+In general, the approach should be to make the interactions with the model
+layer use the same patterns as when you use the CLI, just with Python idioms
+and OO approaches.
+
+When trying to determine what client calls need to be made and what data to
+be sent for a given Juju CLI action, it is very useful to add
+`--debug --logging-config TRACE` to any Juju CLI command to view the full
+conversation between the CLI client and the API server. For example:
+
+```
+[johnsca@murdoch:~] $ juju deploy --debug --logging-config TRACE ./builds/test
+11:51:20 INFO juju.cmd supercommand.go:56 running juju [2.3.5 gc go1.10]
+11:51:20 DEBUG juju.cmd supercommand.go:57 args: []string{"/snap/juju/3884/bin/juju", "deploy", "--debug", "--logging-config", "TRACE", "./builds/test"}
+11:51:20 INFO juju.juju api.go:67 connecting to API addresses: [35.172.119.191:17070 172.31.94.16:17070 252.94.16.1:17070]
+11:51:20 TRACE juju.api certpool.go:49 cert dir "/etc/juju/certs.d" does not exist
+11:51:20 DEBUG juju.api apiclient.go:843 successfully dialed "wss://35.172.119.191:17070/model/a7317969-6dab-4ba4-844b-af3d661c228d/api"
+11:51:20 INFO juju.api apiclient.go:597 connection established to "wss://35.172.119.191:17070/model/a7317969-6dab-4ba4-844b-af3d661c228d/api"
+...
+11:51:20 INFO juju.cmd.juju.application series_selector.go:71 with the configured model default series "xenial"
+11:51:20 DEBUG httpbakery client.go:244 client do POST https://35.172.119.191:17070/model/a7317969-6dab-4ba4-844b-af3d661c228d/charms?revision=0&schema=local&series=xenial {
+11:51:21 DEBUG httpbakery client.go:246 } -> error <nil>
+11:51:21 INFO cmd deploy.go:1096 Deploying charm "local:xenial/test-0".
+11:51:21 TRACE juju.rpc.jsoncodec codec.go:225 -> {"request-id":3,"type":"Charms","version":2,"request":"CharmInfo","params":{"url":"local:xenial/test-0"}}
+11:51:21 TRACE juju.rpc.jsoncodec codec.go:120 <- {"request-id":3,"response":{"revision":0,"url":"local:xenial/test-0","config":{"test":{"type":"string","default":""}},"meta":{"name":"test","summary":"test","description":"test","subordinate":false,"series":["xenial"],"resources":{"dummy":{"name":"dummy","type":"file","path":"dummy.snap","description":"dummy snap"}},"min-juju-version":"0.0.0"},"actions":{}}}
+11:51:21 TRACE juju.rpc.jsoncodec codec.go:225 -> {"request-id":4,"type":"Charms","version":2,"request":"IsMetered","params":{"url":"local:xenial/test-0"}}
+11:51:21 TRACE juju.rpc.jsoncodec codec.go:120 <- {"request-id":4,"response":{"metered":false}}
+11:51:21 TRACE juju.rpc.jsoncodec codec.go:225 -> {"request-id":5,"type":"Resources","version":1,"request":"AddPendingResources","params":{"tag":"application-test","url":"local:xenial/test-0","channel":"","macaroon":null,"resources":[{"name":"dummy","type":"file","path":"dummy.snap","description":"dummy snap","origin":"store","revision":-1,"fingerprint":"","size":0}]}}
+11:51:21 TRACE juju.rpc.jsoncodec codec.go:120 <- {"request-id":5,"response":{"pending-ids":["c0ffdd92-da23-4fb2-8d41-d82d58423447"]}}
+11:51:21 TRACE juju.rpc.jsoncodec codec.go:225 -> {"request-id":6,"type":"Application","version":5,"request":"Deploy","params":{"applications":[{"application":"test","series":"xenial","charm-url":"local:xenial/test-0","channel":"","num-units":1,"config-yaml":"","constraints":{},"resources":{"dummy":"c0ffdd92-da23-4fb2-8d41-d82d58423447"}}]}}
+11:51:21 TRACE juju.rpc.jsoncodec codec.go:120 <- {"request-id":6,"response":{"results":[{}]}}
+11:51:21 TRACE juju.rpc.jsoncodec codec.go:123 <- error: read tcp 192.168.1.102:52168->35.172.119.191:17070: use of closed network connection (closing true)
+11:51:21 DEBUG juju.api monitor.go:35 RPC connection died
+11:51:21 INFO cmd supercommand.go:465 command finished
+```
+
+Note that this will contain login information (which has been removed from the above).
+
+
Overrides
---------