~frankban/juju-quickstart/deploy-changeset

« back to all changes in this revision

Viewing changes to quickstart/tests/test_jujutools.py

  • Committer: Francesco Banconi
  • Date: 2015-02-10 15:19:24 UTC
  • mfrom: (119.2.9 new-auth-api-endpoint)
  • Revision ID: francesco.banconi@canonical.com-20150210151924-m6br1cg2m0gvmctq
Add support for new Juju WebSocket API endpoints.

Recent Juju versions introduced a new API endpoint
path. In essence, instead of the usual 
"wss://<address>:17070", the new 
"wss://<address>:17070/environment/<env-uuid>/api"
is used to connect to the API.
This allows for connecting to a specific environment
in a multi-environment state server scenario.

In this branch the new API endpoint is used if a recent 
Juju version is in use, and if it is possible to retrieve 
the  environment UUID from the jenv file.

Also, when connecting to the GUI server (for creating
the auth token or for deploying bundles), use the new
GUI server API endpoints when possible, i.e. when the
charm is recent enough to support redirecting requests 
to the new Juju endpoints.
Note that this feature is assumed to land in the next
juju-gui charm release (see settings.py). If that's
not the case, we'll need to increase the charm revisions
in settings.MINIMUM_REVISIONS_FOR_NEW_API_ENDPOINT
before releasing the new Quickstart.

Tests: `make check`

QA:
- bootstrap quickstart as usual: `devenv/bin/juju-quickstart`;
- check that, if you are using juju devel (1.22beta), quickstart
  properly connect to the new API endpoint;
- run quickstart again to deploy a bundle, e.g.:
  `devenv/bin/juju-quickstart bundle:mediawiki/single`;
- ensure that the deployment request succeeds;
- if possible, do the above with and older version of Juju, 
  to ensure backward compatibility.

Done, thank you!

R=martin.hilton, jeff.pihach
CC=
https://codereview.appspot.com/199490043

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
from quickstart.tests import helpers
29
29
 
30
30
 
 
31
class TestGetApiUrl(unittest.TestCase):
 
32
 
 
33
    def test_new_url(self):
 
34
        # The new Juju API endpoint is returned if a recent Juju is used.
 
35
        url = jujutools.get_api_url('1.2.3.4:17070', (1, 22, 0), 'env-uuid')
 
36
        self.assertEqual('wss://1.2.3.4:17070/environment/env-uuid/api', url)
 
37
 
 
38
    def test_new_url_with_prefix(self):
 
39
        # The new Juju API endpoint is returned with the given path prefix.
 
40
        url = jujutools.get_api_url(
 
41
            '1.2.3.4:17070', (1, 22, 0), 'env-uuid', prefix='/my/path/')
 
42
        self.assertEqual(
 
43
            'wss://1.2.3.4:17070/my/path/environment/env-uuid/api', url)
 
44
 
 
45
    def test_old_juju(self):
 
46
        # The old Juju API endpoint is returned if the Juju in use is not a
 
47
        # recent version.
 
48
        url = jujutools.get_api_url('1.2.3.4:17070', (1, 21, 7), 'env-uuid')
 
49
        self.assertEqual('wss://1.2.3.4:17070', url)
 
50
 
 
51
    def test_old_juju_with_prefix(self):
 
52
        # The old Juju API endpoint is returned with the given path prefix.
 
53
        url = jujutools.get_api_url(
 
54
            '1.2.3.4:8888', (1, 21, 7), 'env-uuid', 'proxy/')
 
55
        self.assertEqual('wss://1.2.3.4:8888/proxy', url)
 
56
 
 
57
    def test_no_env_uuid(self):
 
58
        # The old Juju API endpoint is returned if the environment unique
 
59
        # identifier is unreachable.
 
60
        url = jujutools.get_api_url('1.2.3.4:17070', (1, 23, 42), None)
 
61
        self.assertEqual('wss://1.2.3.4:17070', url)
 
62
 
 
63
    def test_no_env_uuid_with_prefix(self):
 
64
        # The old Juju API endpoint is returned with the given path prefix.
 
65
        url = jujutools.get_api_url(
 
66
            '1.2.3.4:17070', (1, 23, 42), None, 'my/prefix')
 
67
        self.assertEqual('wss://1.2.3.4:17070/my/prefix', url)
 
68
 
 
69
    def test_new_charm_old_juju(self):
 
70
        # The old Juju API endpoints are used if and old version of Juju is in
 
71
        # use, even if the Juju GUI charm is recent.
 
72
        charm = charms.Charm.from_url('cs:trusty/juju-gui-42')
 
73
        url = jujutools.get_api_url(
 
74
            '1.2.3.4:5678', (1, 21, 7), 'env-uuid', charm=charm)
 
75
        self.assertEqual('wss://1.2.3.4:5678', url)
 
76
 
 
77
    def test_customized_charm_unexpected_name(self):
 
78
        # If a customized Juju GUI charm is used, then we assume it supports
 
79
        # the new Juju Login API endpoint (unexpected charm name).
 
80
        charm = charms.Charm.from_url('cs:trusty/the-amazing-gui-0')
 
81
        url = jujutools.get_api_url(
 
82
            'example.com:17070', (1, 22, 2), 'uuid', charm=charm)
 
83
        self.assertEqual('wss://example.com:17070/environment/uuid/api', url)
 
84
 
 
85
    def test_customized_charm_unexpected_user(self):
 
86
        # If a customized Juju GUI charm is used, then we assume it supports
 
87
        # the new Juju Login API endpoint (unexpected charm user).
 
88
        charm = charms.Charm.from_url('cs:~who/trusty/juju-gui-0')
 
89
        url = jujutools.get_api_url(
 
90
            'example.com:17070', (1, 22, 2), 'uuid', charm=charm)
 
91
        self.assertEqual('wss://example.com:17070/environment/uuid/api', url)
 
92
 
 
93
    def test_customized_charm_unexpected_schema(self):
 
94
        # If a customized Juju GUI charm is used, then we assume it supports
 
95
        # the new Juju Login API endpoint (local charm).
 
96
        charm = charms.Charm.from_url('local:precise/juju-gui-0')
 
97
        url = jujutools.get_api_url(
 
98
            'example.com:17070', (1, 22, 2), 'uuid', prefix='/', charm=charm)
 
99
        self.assertEqual('wss://example.com:17070/environment/uuid/api', url)
 
100
 
 
101
    def test_customized_charm_unexpected_series(self):
 
102
        # If a customized Juju GUI charm is used, then we assume it supports
 
103
        # the new Juju Login API endpoint (unsupported charm series).
 
104
        charm = charms.Charm.from_url('cs:vivid/juju-gui-0')
 
105
        url = jujutools.get_api_url(
 
106
            'example.com:22', (1, 22, 2), 'uuid', prefix='ws', charm=charm)
 
107
        self.assertEqual('wss://example.com:22/ws/environment/uuid/api', url)
 
108
 
 
109
    def test_recent_precise_charm(self):
 
110
        # The new API endpoints are used if a recent precise charm is in use.
 
111
        charm = charms.Charm.from_url('cs:precise/juju-gui-107')
 
112
        url = jujutools.get_api_url(
 
113
            '1.2.3.4:4747', (1, 42, 0), 'env-id', charm=charm)
 
114
        self.assertEqual('wss://1.2.3.4:4747/environment/env-id/api', url)
 
115
 
 
116
    def test_recent_trusty_charm(self):
 
117
        # The new API endpoints are used if a recent trusty charm is in use.
 
118
        charm = charms.Charm.from_url('cs:trusty/juju-gui-19')
 
119
        url = jujutools.get_api_url(
 
120
            '1.2.3.4:4747', (1, 42, 0), 'env-id', charm=charm)
 
121
        self.assertEqual('wss://1.2.3.4:4747/environment/env-id/api', url)
 
122
 
 
123
    def test_old_precise_charm(self):
 
124
        # The old API endpoint is returned if the precise Juju GUI charm in use
 
125
        # is outdated.
 
126
        charm = charms.Charm.from_url('cs:precise/juju-gui-106')
 
127
        url = jujutools.get_api_url(
 
128
            '1.2.3.4:4747', (1, 42, 0), 'env-uuid', charm=charm)
 
129
        self.assertEqual('wss://1.2.3.4:4747', url)
 
130
 
 
131
    def test_old_trusty_charm(self):
 
132
        # The old API endpoint is returned if the trusty Juju GUI charm in use
 
133
        # is outdated.
 
134
        charm = charms.Charm.from_url('cs:trusty/juju-gui-18')
 
135
        url = jujutools.get_api_url(
 
136
            '1.2.3.4:4747', (1, 42, 0), 'env-uuid', prefix='ws', charm=charm)
 
137
        self.assertEqual('wss://1.2.3.4:4747/ws', url)
 
138
 
 
139
    def test_recent_charm_and_prefix(self):
 
140
        # The new API endpoint is returned if a recent charm and a prefix are
 
141
        # both provided. This test exercises the real case in which the GUI
 
142
        # server API endpoint is returned.
 
143
        charm = charms.Charm.from_url('cs:trusty/juju-gui-42')
 
144
        url = jujutools.get_api_url(
 
145
            '1.2.3.4:17070', (1, 22, 0), 'env-id', prefix='ws', charm=charm)
 
146
        self.assertEqual('wss://1.2.3.4:17070/ws/environment/env-id/api', url)
 
147
 
 
148
 
31
149
class TestGetServiceInfo(helpers.WatcherDataTestsMixin, unittest.TestCase):
32
150
 
33
151
    def test_service_and_unit(self):