~ankatare/juju-ci-tools/juju-aws-add-credential

« back to all changes in this revision

Viewing changes to tests/test_chaos.py

  • Committer: ankatare at hotmail
  • Date: 2017-01-31 03:53:09 UTC
  • mfrom: (1837.1.30 trunk)
  • Revision ID: ankatare@hotmail.com-20170131035309-8dmn8d86opr9yorl
merge trunck

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
    MonkeyRunner,
19
19
    )
20
20
from jujupy import (
21
 
    EnvJujuClient,
 
21
    ModelClient,
22
22
    JujuData,
23
23
    )
24
24
from remote import SSHRemote
31
31
class TestBackgroundChaos(FakeHomeTestCase):
32
32
 
33
33
    def test_background_chaos(self):
34
 
        client = EnvJujuClient(JujuData('foo', {}), None, '/foo/juju')
 
34
        client = ModelClient(JujuData('foo', {}), None, '/foo/juju')
35
35
        with patch('chaos.MonkeyRunner.deploy_chaos_monkey',
36
36
                   autospec=True) as d_mock:
37
37
            with patch('chaos.MonkeyRunner.unleash_once',
55
55
                         w_mock.mock_calls[1][2])
56
56
 
57
57
    def test_background_chaos_exits(self):
58
 
        client = EnvJujuClient(JujuData('foo', {}), None, '/foo/juju')
 
58
        client = ModelClient(JujuData('foo', {}), None, '/foo/juju')
59
59
        with patch('chaos.MonkeyRunner.deploy_chaos_monkey',
60
60
                   autospec=True):
61
61
            with patch('chaos.MonkeyRunner.unleash_once',
102
102
                ('show-status', '--format', 'yaml'): status,
103
103
                }
104
104
            return output[args]
105
 
        client = EnvJujuClient(JujuData('foo', {}), '1.25.0', '/foo/juju')
 
105
        client = ModelClient(JujuData('foo', {}), '1.25.0', '/foo/juju')
106
106
        with patch.object(client, 'get_juju_output', side_effect=output,
107
107
                          autospec=True) as gjo_mock:
108
108
            with patch('subprocess.check_call', autospec=True) as cc_mock:
109
109
                monkey_runner = MonkeyRunner('foo', client, service='ser1')
110
 
                with patch('jujupy.GroupReporter._write', autospec=True):
 
110
                with patch('jujupy.client.GroupReporter._write',
 
111
                           autospec=True):
111
112
                    monkey_runner.deploy_chaos_monkey()
112
113
        assert_juju_call(
113
114
            self,
150
151
                ('show-status', '--format', 'yaml'): status,
151
152
                }
152
153
            return output[args]
153
 
        client = EnvJujuClient(JujuData('foo', {}), None, '/foo/juju')
 
154
        client = ModelClient(JujuData('foo', {}), None, '/foo/juju')
154
155
        runner = MonkeyRunner('foo', client, service='jenkins')
155
156
        with patch.object(client, 'get_juju_output', side_effect=output,
156
157
                          autospec=True):
203
204
                ('config', 'chaos-monkey'): charm_config,
204
205
                }
205
206
            return output[args]
206
 
        client = EnvJujuClient(JujuData('foo', {}), None, '/foo')
 
207
        client = ModelClient(JujuData('foo', {}), None, '/foo')
207
208
        monkey_runner = MonkeyRunner('foo', client, service='jenkins')
208
209
        monkey_runner.monkey_ids = {
209
210
            'chaos-monkey/0': 'workspace0',
315
316
                     'abcdabcdabcdabcdabcdabcdabcdabcdabcd'),
316
317
                }
317
318
            return output[args]
318
 
        client = EnvJujuClient(JujuData('foo', {}), None, '/foo/juju')
 
319
        client = ModelClient(JujuData('foo', {}), None, '/foo/juju')
319
320
        monkey_runner = MonkeyRunner('foo', client, service='jenkins')
320
321
        with patch.object(client, 'get_juju_output', side_effect=output,
321
322
                          autospec=True) as gjo_mock:
384
385
                 ): 'Action fail',
385
386
                }
386
387
            return output[args]
387
 
        client = EnvJujuClient(JujuData('foo', {}), None, '/foo/juju')
 
388
        client = ModelClient(JujuData('foo', {}), None, '/foo/juju')
388
389
        monkey_runner = MonkeyRunner('foo', client, service='jenkins')
389
390
        with patch.object(client, 'get_juju_output', side_effect=output,
390
391
                          autospec=True):
397
398
 
398
399
    def test_is_healthy(self):
399
400
        SCRIPT = """#!/bin/bash\necho -n 'PASS'\nexit 0"""
400
 
        client = EnvJujuClient(JujuData('foo', {}), None, '/foo/juju')
 
401
        client = ModelClient(JujuData('foo', {}), None, '/foo/juju')
401
402
        with NamedTemporaryFile(delete=False) as health_script:
402
403
            health_script.write(SCRIPT)
403
404
            os.fchmod(health_script.fileno(), stat.S_IEXEC | stat.S_IREAD)
413
414
 
414
415
    def test_is_healthy_fail(self):
415
416
        SCRIPT = """#!/bin/bash\necho -n 'FAIL'\nexit 1"""
416
 
        client = EnvJujuClient(JujuData('foo', {}), None, '/foo/juju')
 
417
        client = ModelClient(JujuData('foo', {}), None, '/foo/juju')
417
418
        with NamedTemporaryFile(delete=False) as health_script:
418
419
            health_script.write(SCRIPT)
419
420
            os.fchmod(health_script.fileno(), stat.S_IEXEC | stat.S_IREAD)
428
429
 
429
430
    def test_is_healthy_with_no_execute_perms(self):
430
431
        SCRIPT = """#!/bin/bash\nexit 0"""
431
 
        client = EnvJujuClient(JujuData('foo', {}), None, '/foo/juju')
 
432
        client = ModelClient(JujuData('foo', {}), None, '/foo/juju')
432
433
        with NamedTemporaryFile(delete=False) as health_script:
433
434
            health_script.write(SCRIPT)
434
435
            os.fchmod(health_script.fileno(), stat.S_IREAD)
447
448
class TestWaitForChaos(FakeHomeTestCase):
448
449
 
449
450
    def test_wait_for_chaos_complete(self):
450
 
        client = EnvJujuClient(JujuData('foo', {}), None, '/foo')
 
451
        client = ModelClient(JujuData('foo', {}), None, '/foo')
451
452
        runner = MonkeyRunner('foo', client)
452
453
        units = [('blib', 'blab')]
453
454
        with patch.object(runner, 'iter_chaos_monkey_units', autospec=True,
460
461
        self.assertEqual(us_mock.call_count, 1)
461
462
 
462
463
    def test_wait_for_chaos_complete_timesout(self):
463
 
        client = EnvJujuClient(JujuData('foo', {}), None, '/foo')
 
464
        client = ModelClient(JujuData('foo', {}), None, '/foo')
464
465
        runner = MonkeyRunner('foo', client)
465
466
        with self.assertRaisesRegexp(
466
467
                Exception, 'Chaos operations did not complete.'):
467
468
            runner.wait_for_chaos(timeout=0)
468
469
 
469
470
    def test_wait_for_chaos_started(self):
470
 
        client = EnvJujuClient(JujuData('foo', {}), None, '/foo')
 
471
        client = ModelClient(JujuData('foo', {}), None, '/foo')
471
472
        runner = MonkeyRunner('foo', client)
472
473
        units = [('blib', 'blab')]
473
474
        with patch.object(runner, 'iter_chaos_monkey_units', autospec=True,
481
482
        self.assertEqual(us_mock.call_count, 1)
482
483
 
483
484
    def test_wait_for_chaos_unexpected_state(self):
484
 
        client = EnvJujuClient(JujuData('foo', {}), None, '/foo')
 
485
        client = ModelClient(JujuData('foo', {}), None, '/foo')
485
486
        runner = MonkeyRunner('foo', client)
486
487
        with self.assertRaisesRegexp(
487
488
                Exception, 'Unexpected state value: foo'):