~viswesn/juju-ci-tools/aws_boto3

« back to all changes in this revision

Viewing changes to tests/test_scale_out.py

  • Committer: Curtis Hovey
  • Date: 2017-01-25 02:32:29 UTC
  • mfrom: (1855 trunk)
  • mto: This revision was merged to the branch mainline in revision 1865.
  • Revision ID: curtis@canonical.com-20170125023229-g7c6bzt0cqe1j8g3
Merged trunk and resolved conflicts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
from unittest import TestCase
9
9
 
10
10
from jujupy import (
11
 
    EnvJujuClient,
 
11
    ModelClient,
12
12
    JujuData,
13
13
)
14
14
from scale_out import (
20
20
)
21
21
 
22
22
 
23
 
def fake_EnvJujuClient(env, path=None, debug=None):
24
 
    return EnvJujuClient(env=env, version='1.2.3.4', full_path=path)
 
23
def fake_ModelClient(env, path=None, debug=None):
 
24
    return ModelClient(env=env, version='1.2.3.4', full_path=path)
25
25
 
26
26
 
27
27
class TestScaleOut(TestCase):
29
29
    @contextmanager
30
30
    def fake_client_cxt(self):
31
31
        env = JujuData('foo', {})
32
 
        client = fake_EnvJujuClient(env)
 
32
        client = fake_ModelClient(env)
33
33
        bv_cxt = patch('scale_out.client_from_config',
34
34
                       return_value=client)
35
35
        with bv_cxt as bv_mock:
59
59
        self.assertEqual(args, expected)
60
60
 
61
61
    @patch('scale_out.boot_context', autospec=True)
62
 
    @patch('jujupy.EnvJujuClient.add_ssh_machines', autospec=True)
 
62
    @patch('jujupy.ModelClient.add_ssh_machines', autospec=True)
63
63
    def test_scaleout_setup(
64
64
            self,
65
65
            add_ssh_machines_func,
127
127
 
128
128
        with self.fake_client_cxt():
129
129
            with patch('scale_out.boot_context', autospec=True) as bc_mock:
130
 
                with patch('jujupy.EnvJujuClient.add_ssh_machines',
 
130
                with patch('jujupy.ModelClient.add_ssh_machines',
131
131
                           autospec=True):
132
132
                    with scaleout_setup(args) as client:
133
133
                        pass
146
146
 
147
147
    def test_deploy_charms(self):
148
148
        with self.fake_client_cxt() as (client, env, bv_mock):
149
 
            with patch.object(EnvJujuClient, 'deploy') as d_mock:
150
 
                with patch.object(EnvJujuClient,
 
149
            with patch.object(ModelClient, 'deploy') as d_mock:
 
150
                with patch.object(ModelClient,
151
151
                                  'wait_for_started') as wfs_mock:
152
152
                    deploy_charms(client, ['ubuntu', 'mysql'])
153
153
        expected = [call('ubuntu', service='ubuntu'),
157
157
 
158
158
    def test_deploy_charms_local(self):
159
159
        with self.fake_client_cxt() as (client, env, bv_mock):
160
 
            with patch.object(EnvJujuClient, 'deploy') as d_mock:
161
 
                with patch.object(EnvJujuClient,
 
160
            with patch.object(ModelClient, 'deploy') as d_mock:
 
161
                with patch.object(ModelClient,
162
162
                                  'wait_for_started') as wfs_mock:
163
163
                    deploy_charms(client, ['local:foo', 'local:bar'])
164
164
        expected = [call('local:foo', service='foo'),
168
168
 
169
169
    def test_scale_out(self):
170
170
        with self.fake_client_cxt() as (client, env, bv_mock):
171
 
            with patch.object(EnvJujuClient, 'juju') as j_mock:
172
 
                with patch.object(EnvJujuClient,
 
171
            with patch.object(ModelClient, 'juju') as j_mock:
 
172
                with patch.object(ModelClient,
173
173
                                  'wait_for_started') as wfs_mock:
174
174
                    scale_out(client, 'ubuntu')
175
175
        j_mock.assert_called_once_with('add-unit', ('ubuntu', '-n', '5'))