~andrewjbeach/juju-ci-tools/make-local-patcher

« back to all changes in this revision

Viewing changes to tests/test_scale_out.py

Handle LoggedException in quickstart_deploy, assess_bootstrap.

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
 
10
10
from jujupy import (
11
11
    EnvJujuClient,
12
 
    JujuData,
 
12
    SimpleEnvironment,
13
13
)
14
14
from scale_out import (
15
15
    deploy_charms,
20
20
)
21
21
 
22
22
 
 
23
def fake_SimpleEnvironment(name):
 
24
    return SimpleEnvironment(name, {})
 
25
 
 
26
 
23
27
def fake_EnvJujuClient(env, path=None, debug=None):
24
28
    return EnvJujuClient(env=env, version='1.2.3.4', full_path=path)
25
29
 
28
32
 
29
33
    @contextmanager
30
34
    def fake_client_cxt(self):
31
 
        env = JujuData('foo', {})
 
35
        env = fake_SimpleEnvironment('foo')
32
36
        client = fake_EnvJujuClient(env)
33
 
        bv_cxt = patch('scale_out.client_from_config',
 
37
        bv_cxt = patch('jujupy.EnvJujuClient.by_version',
34
38
                       return_value=client)
35
 
        with bv_cxt as bv_mock:
36
 
            yield (client, env, bv_mock)
 
39
        fc_cxt = patch('jujupy.SimpleEnvironment.from_config',
 
40
                       return_value=env)
 
41
        with bv_cxt, fc_cxt:
 
42
            yield (client, env)
37
43
 
38
44
    def test_parse_args(self):
39
45
        args = parse_args(
53
59
            series=None,
54
60
            temp_env_name='temp_name',
55
61
            upload_tools=False,
56
 
            verbose=logging.INFO,
57
 
            deadline=None,
 
62
            verbose=logging.INFO
58
63
        )
59
64
        self.assertEqual(args, expected)
60
65
 
61
66
    @patch('scale_out.boot_context', autospec=True)
62
 
    @patch('jujupy.EnvJujuClient.add_ssh_machines', autospec=True)
 
67
    @patch('scale_out.EnvJujuClient.add_ssh_machines', autospec=True)
63
68
    def test_scaleout_setup(
64
69
            self,
65
70
            add_ssh_machines_func,
80
85
            series=None,
81
86
            temp_env_name='temp_name',
82
87
            upload_tools=False,
83
 
            verbose=logging.INFO,
84
 
            deadline=None,
 
88
            verbose=logging.INFO
85
89
        )
86
90
 
87
 
        with self.fake_client_cxt() as (fake_client, fake_env, bv_mock):
 
91
        with self.fake_client_cxt() as (fake_client, fake_env):
88
92
            with scaleout_setup(args) as client:
 
93
                # Get a reference to the by_version function that was patched
 
94
                # in fake_client_cxt()
 
95
                bv_mock = EnvJujuClient.by_version
89
96
                pass
90
97
        boot_context_func.assert_called_once_with(
91
98
            args.temp_env_name,
99
106
            args.keep_env,
100
107
            args.upload_tools,
101
108
            region=args.region)
102
 
        bv_mock.assert_called_once_with('test_env', '/path/juju', False,
103
 
                                        soft_deadline=None)
 
109
        bv_mock.assert_called_once_with(fake_env, '/path/juju', False)
104
110
        add_ssh_machines_func.assert_called_once_with(client, ['0'])
105
111
        self.assertIs(client, fake_client)
106
112
 
121
127
            series='my_series',
122
128
            temp_env_name='temp_name',
123
129
            upload_tools=False,
124
 
            verbose=logging.INFO,
125
 
            deadline=None,
 
130
            verbose=logging.INFO
126
131
        )
127
132
 
128
133
        with self.fake_client_cxt():
129
134
            with patch('scale_out.boot_context', autospec=True) as bc_mock:
130
 
                with patch('jujupy.EnvJujuClient.add_ssh_machines',
 
135
                with patch('scale_out.EnvJujuClient.add_ssh_machines',
131
136
                           autospec=True):
132
137
                    with scaleout_setup(args) as client:
133
138
                        pass
145
150
            region=args.region)
146
151
 
147
152
    def test_deploy_charms(self):
148
 
        with self.fake_client_cxt() as (client, env, bv_mock):
 
153
        with self.fake_client_cxt() as (client, env):
149
154
            with patch.object(EnvJujuClient, 'deploy') as d_mock:
150
155
                with patch.object(EnvJujuClient,
151
156
                                  'wait_for_started') as wfs_mock:
156
161
        wfs_mock.assert_called_once_with()
157
162
 
158
163
    def test_deploy_charms_local(self):
159
 
        with self.fake_client_cxt() as (client, env, bv_mock):
 
164
        with self.fake_client_cxt() as (client, env):
160
165
            with patch.object(EnvJujuClient, 'deploy') as d_mock:
161
166
                with patch.object(EnvJujuClient,
162
167
                                  'wait_for_started') as wfs_mock:
167
172
        wfs_mock.assert_called_once_with()
168
173
 
169
174
    def test_scale_out(self):
170
 
        with self.fake_client_cxt() as (client, env, bv_mock):
 
175
        with self.fake_client_cxt() as (client, env):
171
176
            with patch.object(EnvJujuClient, 'juju') as j_mock:
172
177
                with patch.object(EnvJujuClient,
173
178
                                  'wait_for_started') as wfs_mock: