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

« back to all changes in this revision

Viewing changes to tests/test_assess_update_mongo.py

  • Committer: John George
  • Date: 2015-01-14 22:03:47 UTC
  • mto: This revision was merged to the branch mainline in revision 798.
  • Revision ID: john.george@canonical.com-20150114220347-e8q5wezs1qg9a00u
Added support for setting the juju path, series and agent_url.

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
 
        env = object()
45
 
        client = Mock(spec=["is_jes_enabled"])
46
 
        with patch("assess_update_mongo.configure_logging",
47
 
                   autospec=True) as mock_cl:
48
 
            with patch("assess_update_mongo.BootstrapManager.booted_context",
49
 
                       autospec=True) as mock_bc:
50
 
                with patch("jujupy.SimpleEnvironment.from_config",
51
 
                           return_value=env) as mock_e:
52
 
                    with patch("jujupy.EnvJujuClient.by_version",
53
 
                               return_value=client) as mock_c:
54
 
                        with patch("assess_update_mongo.assess_update_mongo",
55
 
                                   autospec=True) as mock_assess:
56
 
                            main(argv)
57
 
        mock_cl.assert_called_once_with(logging.DEBUG)
58
 
        mock_e.assert_called_once_with("an-env")
59
 
        mock_c.assert_called_once_with(env, "/bin/juju", debug=False)
60
 
        self.assertEqual(mock_bc.call_count, 1)
61
 
        mock_assess.assert_called_once_with(client, 'trusty', '10.0.0.2')
62
 
 
63
 
 
64
 
EG_MONGO3_PROC = (
65
 
    "4709 ?        Ssl    0:11 /usr/lib/juju/mongo3/bin/mongod "
66
 
    "--dbpath /var/lib/juju/db --sslOnNormalPorts "
67
 
    "--sslPEMKeyFile /var/lib/juju/server.pem --sslPEMKeyPassword xxxxxxx "
68
 
    "--port 37017 --syslog --journal --replSet juju --ipv6 --quiet "
69
 
    "--oplogSize 512 --auth --keyFile /var/lib/juju/shared-secret "
70
 
    "--noprealloc --smallfiles"
71
 
)
72
 
 
73
 
 
74
 
class TestAssess(TestCase):
75
 
 
76
 
    def test_update_mongo(self):
77
 
        mock_client = Mock(
78
 
            spec=["juju", "wait_for_started", "deploy", "upgrade_mongo",
79
 
                  "show_status"])
80
 
        mock_client.version = '2.0.0'
81
 
        mock_remote = Mock(spec=['run'])
82
 
        mock_remote.run.side_effect = ('', EG_MONGO3_PROC)
83
 
        with patch('assess_update_mongo.remote_from_address',
84
 
                   autospec=True, return_value=mock_remote) as r_mock:
85
 
            assess_update_mongo(mock_client, 'trusty', '10.0.0.2')
86
 
        mock_client.deploy.assert_called_once_with('ubuntu', series='trusty')
87
 
        mock_client.wait_for_started.assert_called_once_with()
88
 
        mock_client.upgrade_mongo.assert_called_once_with()
89
 
        r_mock.assert_called_once_with('10.0.0.2', series='trusty')
90
 
        mock_remote.run.assert_any_call(DEP_SCRIPT)
91
 
        mock_remote.run.assert_any_call(VERIFY_SCRIPT)
92
 
        self.assertNotIn("TODO", self.log_stream.getvalue())