1
"""Tests for assess_update_mongo module."""
4
from mock import Mock, patch
7
from assess_update_mongo import (
20
class TestParseArgs(TestCase):
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)
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())
39
class TestMain(TestCase):
42
argv = ["an-env", "/bin/juju", "/tmp/logs", "an-env-mod", "--verbose",
43
"--series", "trusty", "--bootstrap-host", "10.0.0.2"]
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:
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')
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"
74
class TestAssess(TestCase):
76
def test_update_mongo(self):
78
spec=["juju", "wait_for_started", "deploy", "upgrade_mongo",
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())