~abentley/juju-ci-tools/client-from-config-4

« back to all changes in this revision

Viewing changes to tests/test_run_deployer.py

  • Committer: Aaron Bentley
  • Date: 2016-03-18 14:47:06 UTC
  • mto: This revision was merged to the branch mainline in revision 1324.
  • Revision ID: aaron.bentley@canonical.com-20160318144706-z7wy9c21m3psi6g5
Introduce set_model_name, update tests, check controller on bootstrap.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
from argparse import Namespace
2
2
import logging
3
3
import os
4
 
import pickle
5
4
import stat
6
5
import subprocess
7
6
from tempfile import NamedTemporaryFile
27
26
    parse_args,
28
27
    )
29
28
import tests
30
 
from tests.test_jujupy import fake_juju_client
 
29
from tests.test_jujupy import FakeJujuClient
31
30
 
32
31
 
33
32
class TestParseArgs(tests.TestCase):
80
79
        args = ['bundles', 'an-env', '/bin/juju', 'logs', 'deployer-env']
81
80
        env = JujuData('an-env')
82
81
        client = EnvJujuClient(env, '1.234-76', None)
83
 
        with patch('run_deployer.client_from_config',
84
 
                   return_value=client) as c_mock:
85
 
            with patch('run_deployer.boot_context'):
86
 
                with patch('run_deployer.assess_deployer') as ad_mock:
87
 
                    main(args)
88
 
        c_mock.assert_called_once_with('an-env', '/bin/juju', debug=False)
89
 
        ad_mock.assert_called_once_with(parse_args(args), client, 1200, 1800)
90
 
 
91
 
    def test_basic_args_native_deploy(self):
92
 
        args = ['mediawiki-scalable.yaml', 'an-env', '/bin/juju', 'logs',
93
 
                'deployer-env', '--allow-native-deploy',
94
 
                '--bundle-verification-script',
95
 
                'verify_mediawiki_bundle.py']
96
 
        env = JujuData('an-env')
97
 
        client = EnvJujuClient(env, '1.234-76', None)
98
 
        with patch('run_deployer.client_from_config',
99
 
                   return_value=client) as c_mock:
100
 
            with patch('run_deployer.boot_context'):
101
 
                with patch('run_deployer.assess_deployer') as ad_mock:
102
 
                    with patch('run_deployer.run_command') as mb_mock:
 
82
        with patch('jujupy.SimpleEnvironment.from_config',
 
83
                   return_value=env) as e_mock:
 
84
            with patch('jujupy.EnvJujuClient.by_version',
 
85
                       return_value=client) as c_mock:
 
86
                with patch('run_deployer.boot_context'):
 
87
                    with patch('run_deployer.assess_deployer') as ad_mock:
103
88
                        main(args)
104
 
        c_mock.assert_called_once_with('an-env', '/bin/juju', debug=False)
105
 
        ad_mock.assert_called_once_with(parse_args(args), client, 1200, 1800)
106
 
        client_ser = pickle.dumps(client)
107
 
        mb_mock.assert_called_once_with(['verify_mediawiki_bundle.py',
108
 
                                         client_ser])
109
 
 
110
 
    def test_basic_args_native_deploy_landscape(self):
111
 
        args = ['cs:~landscape/bundle/landscape-scalable', 'an-env',
112
 
                '/bin/juju', 'logs', 'deployer-env',
113
 
                '--allow-native-deploy',
114
 
                '--bundle-verification-script',
115
 
                'verify_landscape_bundle.py']
116
 
        env = JujuData('an-env')
117
 
        client = EnvJujuClient(env, '1.234-76', None)
118
 
        with patch('run_deployer.client_from_config',
119
 
                   return_value=client) as c_mock:
120
 
            with patch('run_deployer.boot_context'):
121
 
                with patch('run_deployer.assess_deployer') as ad_mock:
122
 
                        with patch('run_deployer.run_command') as rc:
123
 
                            main(args)
124
 
        c_mock.assert_called_once_with('an-env', '/bin/juju', debug=False)
125
 
        ad_mock.assert_called_once_with(parse_args(args), client, 1200, 1800)
126
 
        client_ser = pickle.dumps(client)
127
 
        rc.assert_called_once_with(['verify_landscape_bundle.py',
128
 
                                   client_ser])
 
89
        e_mock.assert_called_once_with('an-env')
 
90
        c_mock.assert_called_once_with(env, '/bin/juju', debug=False)
 
91
        ad_mock.assert_called_once_with(parse_args(args), client, 1200, 1800)
129
92
 
130
93
 
131
94
class TestAssessDeployer(tests.TestCase):
185
148
        self.assertEqual(
186
149
            ch_mock.call_args_list, [call('/tmp/check', 'foo', environ)] * 2)
187
150
 
 
151
    @patch('run_deployer.SimpleEnvironment.from_config')
188
152
    @patch('run_deployer.boot_context', autospec=True)
189
153
    def test_run_deployer_upgrade(self, *args):
190
154
        args = self.make_args(
191
155
            juju_bin='baz/juju', upgrade=True,
192
156
            upgrade_condition=['bla/0:clock_skew', 'foo/1:fill_disk'])
193
 
        client = fake_juju_client()
194
 
        client.bootstrap()
195
 
        with patch('run_deployer.client_from_config', return_value=client):
 
157
        client = FakeJujuClient()
 
158
        with patch('run_deployer.EnvJujuClient.by_version',
 
159
                   return_value=client):
196
160
            with patch('run_deployer.apply_condition') as ac_mock:
197
161
                with patch('run_deployer.assess_upgrade') as au_mock:
198
162
                    assess_deployer(args, client, 600, 1800)
228
192
class TestApplyCondition(tests.TestCase):
229
193
 
230
194
    def test_apply_condition_clock_skew(self):
231
 
        client = fake_juju_client()
 
195
        client = FakeJujuClient()
232
196
        remote = FakeRemote()
233
197
        with patch('run_deployer.remote_from_unit',
234
198
                   return_value=remote, autospec=True) as ru_mock:
237
201
        self.assertEqual(CLOCK_SKEW_SCRIPT, remote.command)
238
202
 
239
203
    def test_apply_condition_raises_ErrUnitCondition(self):
240
 
        client = fake_juju_client()
 
204
        client = FakeJujuClient()
241
205
        remote = FakeRemote()
242
206
        with patch('run_deployer.remote_from_unit',
243
207
                   return_value=remote) as rfu_mock: