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"]
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:
54
mock_cl.assert_called_once_with(logging.DEBUG)
55
mock_c.assert_called_once_with('an-env', "/bin/juju", debug=False,
57
self.assertEqual(mock_bc.call_count, 1)
58
mock_assess.assert_called_once_with(client, 'trusty', '10.0.0.2')
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"
71
class TestAssess(TestCase):
73
def test_update_mongo(self):
75
spec=["juju", "wait_for_started", "deploy", "upgrade_mongo",
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())