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

« back to all changes in this revision

Viewing changes to tests/test_assess_update_mongo.py

  • Committer: Curtis Hovey
  • Date: 2015-06-16 20:18:37 UTC
  • mto: This revision was merged to the branch mainline in revision 995.
  • Revision ID: curtis@canonical.com-20150616201837-l44eyp22o501g6ee
Ensure the env name is in the config.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
"""Tests for assess_update_mongo module."""
2
 
 
3
 
import logging
4
 
from mock import Mock, patch
5
 
import StringIO
6
 
 
7
 
from assess_update_mongo import (
8
 
    assess_update_mongo,
9
 
    DEP_SCRIPT,
10
 
    parse_args,
11
 
    main,
12
 
    VERIFY_SCRIPT,
13
 
)
14
 
from tests import (
15
 
    parse_error,
16
 
    TestCase,
17
 
)
18
 
 
19
 
 
20
 
class TestParseArgs(TestCase):
21
 
 
22
 
    def test_common_args(self):
23
 
        args = parse_args(["an-env", "/bin/juju", "/tmp/logs", "an-env-mod"])
24
 
        self.assertEqual("an-env", args.env)
25
 
        self.assertEqual("/bin/juju", args.juju_bin)
26
 
        self.assertEqual("/tmp/logs", args.logs)
27
 
        self.assertEqual("an-env-mod", args.temp_env_name)
28
 
        self.assertEqual(False, args.debug)
29
 
 
30
 
    def test_help(self):
31
 
        fake_stdout = StringIO.StringIO()
32
 
        with parse_error(self) as fake_stderr:
33
 
            with patch("sys.stdout", fake_stdout):
34
 
                parse_args(["--help"])
35
 
        self.assertEqual("", fake_stderr.getvalue())
36
 
        self.assertNotIn("TODO", fake_stdout.getvalue())
37
 
 
38
 
 
39
 
class TestMain(TestCase):
40
 
 
41
 
    def test_main(self):
42
 
        argv = ["an-env", "/bin/juju", "/tmp/logs", "an-env-mod", "--verbose",
43
 
                "--series", "trusty", "--bootstrap-host", "10.0.0.2"]
44
 
        client = Mock(spec=["is_jes_enabled"])
45
 
        with patch("assess_update_mongo.configure_logging",
46
 
                   autospec=True) as mock_cl:
47
 
            with patch("assess_update_mongo.BootstrapManager.booted_context",
48
 
                       autospec=True) as mock_bc:
49
 
                with patch("deploy_stack.client_from_config",
50
 
                           return_value=client) as mock_c:
51
 
                    with patch("assess_update_mongo.assess_update_mongo",
52
 
                               autospec=True) as mock_assess:
53
 
                        main(argv)
54
 
        mock_cl.assert_called_once_with(logging.DEBUG)
55
 
        mock_c.assert_called_once_with('an-env', "/bin/juju", debug=False,
56
 
                                       soft_deadline=None)
57
 
        self.assertEqual(mock_bc.call_count, 1)
58
 
        mock_assess.assert_called_once_with(client, 'trusty', '10.0.0.2')
59
 
 
60
 
 
61
 
EG_MONGO3_PROC = (
62
 
    "4709 ?        Ssl    0:11 /usr/lib/juju/mongo3/bin/mongod "
63
 
    "--dbpath /var/lib/juju/db --sslOnNormalPorts "
64
 
    "--sslPEMKeyFile /var/lib/juju/server.pem --sslPEMKeyPassword xxxxxxx "
65
 
    "--port 37017 --syslog --journal --replSet juju --ipv6 --quiet "
66
 
    "--oplogSize 512 --auth --keyFile /var/lib/juju/shared-secret "
67
 
    "--noprealloc --smallfiles"
68
 
)
69
 
 
70
 
 
71
 
class TestAssess(TestCase):
72
 
 
73
 
    def test_update_mongo(self):
74
 
        mock_client = Mock(
75
 
            spec=["juju", "wait_for_started", "deploy", "upgrade_mongo",
76
 
                  "show_status"])
77
 
        mock_client.version = '2.0.0'
78
 
        mock_remote = Mock(spec=['run'])
79
 
        mock_remote.run.side_effect = ('', EG_MONGO3_PROC)
80
 
        with patch('assess_update_mongo.remote_from_address',
81
 
                   autospec=True, return_value=mock_remote) as r_mock:
82
 
            assess_update_mongo(mock_client, 'trusty', '10.0.0.2')
83
 
        mock_client.deploy.assert_called_once_with('ubuntu', series='trusty')
84
 
        mock_client.wait_for_started.assert_called_once_with()
85
 
        mock_client.upgrade_mongo.assert_called_once_with()
86
 
        r_mock.assert_called_once_with('10.0.0.2', series='trusty')
87
 
        mock_remote.run.assert_any_call(DEP_SCRIPT)
88
 
        mock_remote.run.assert_any_call(VERIFY_SCRIPT)
89
 
        self.assertNotIn("TODO", self.log_stream.getvalue())