From: Alfredo Deza Date: Thu, 15 Aug 2013 20:40:09 +0000 (-0400) Subject: all tests refactored and passing X-Git-Tag: v1.2.1~1^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=410d17a71381b91a10abb20ce8e9ae922d00c57f;p=ceph-deploy.git all tests refactored and passing Signed-off-by: Alfredo Deza --- diff --git a/ceph_deploy/tests/test_cli.py b/ceph_deploy/tests/test_cli.py index 6312ae3..9829ee5 100644 --- a/ceph_deploy/tests/test_cli.py +++ b/ceph_deploy/tests/test_cli.py @@ -9,7 +9,6 @@ def test_help(tmpdir, cli): ) as p: result = p.stdout.read() assert 'usage: ceph-deploy' in result - assert 'Deploy Ceph' in result assert 'optional arguments:' in result assert 'commands:' in result diff --git a/ceph_deploy/tests/test_cli_mon.py b/ceph_deploy/tests/test_cli_mon.py index 81aa045..769e34e 100644 --- a/ceph_deploy/tests/test_cli_mon.py +++ b/ceph_deploy/tests/test_cli_mon.py @@ -70,8 +70,6 @@ mon initial members = host1 secret = get_monitor_secret() assert secret == MON_SECRET - mock_compiled[mon.create_mon].side_effect = _create_mon - try: with mock.patch('ceph_deploy.new.socket.gethostbyname'): with mock.patch('socket.getaddrinfo', fake_getaddrinfo): diff --git a/ceph_deploy/tests/unit/test_mon.py b/ceph_deploy/tests/unit/test_mon.py index 7685aee..2ff735f 100644 --- a/ceph_deploy/tests/unit/test_mon.py +++ b/ceph_deploy/tests/unit/test_mon.py @@ -1,5 +1,7 @@ +import sys from mock import Mock, MagicMock, patch, call from ceph_deploy import mon +from ceph_deploy.hosts.common import mon_create def path_exists(target_paths=None): @@ -42,73 +44,78 @@ class TestCreateMon(object): self.socket.gethostname.return_value = 'hostname' self.fake_write = Mock(name='fake_write') self.fake_file = mock_open(data=self.fake_write) - self.os = Mock() + self.fake_file.readline.return_value = self.fake_file + self.fake_file.readline.lstrip.return_value = '' + self.distro = Mock() self.sprocess = Mock() self.paths = Mock() self.paths.mon.path = Mock(return_value='/cluster-hostname') + self.logger = Mock() + self.logger.info = self.logger.debug = lambda x: sys.stdout.write(str(x) + "\n") def test_create_mon_tmp_path_if_nonexistent(self): - self.os.path.exists = Mock( + self.distro.sudo_conn.modules.os.path.exists = Mock( side_effect=path_exists(['/cluster-hostname'])) self.paths.mon.constants.tmp_path = '/var/lib/ceph/tmp' - with patch('__builtin__.file', self.fake_file): - mon.create_mon( - 'cluster', '1234', 'initd', - paths=self.paths, os=self.os, subprocess=self.sprocess, - socket=self.socket) + args = Mock(return_value=['cluster', '1234', 'initd']) + args.cluster = 'cluster' + with patch('ceph_deploy.hosts.common.conf.load'): + mon_create(self.distro, self.logger, args, Mock(), 'hostname') - result = self.os.makedirs.call_args_list[0] + result = self.distro.sudo_conn.modules.os.makedirs.call_args_list[-1] assert result == call('/var/lib/ceph/tmp') def test_create_mon_path_if_nonexistent(self): - self.os.path.exists = Mock( + self.distro.sudo_conn.modules.os.path.exists = Mock( side_effect=path_exists(['/'])) - with patch('__builtin__.file', self.fake_file): - mon.create_mon( - 'cluster', '1234', 'initd', - paths=self.paths, os=self.os, subprocess=self.sprocess, - socket=self.socket) + args = Mock(return_value=['cluster', '1234', 'initd']) + args.cluster = 'cluster' + with patch('ceph_deploy.hosts.common.conf.load'): + mon_create(self.distro, self.logger, args, Mock(), 'hostname') - result = self.os.makedirs.call_args_list[0] - assert result == call('/cluster-hostname') + result = self.distro.sudo_conn.modules.os.makedirs.call_args_list[0] + assert result == call('/var/lib/ceph/mon/cluster-hostname') def test_write_keyring(self): - self.os.path.exists = Mock( + self.distro.sudo_conn.modules.os.path.exists = Mock( side_effect=path_exists(['/'])) - with patch('__builtin__.file', self.fake_file): - mon.create_mon( - 'cluster', '1234', 'initd', - paths=self.paths, os=self.os, subprocess=self.sprocess, - socket=self.socket) + args = Mock(return_value=['cluster', '1234', 'initd']) + args.cluster = 'cluster' + with patch('ceph_deploy.hosts.common.conf.load'): + with patch('ceph_deploy.hosts.common.remote') as fake_remote: + mon_create(self.distro, self.logger, args, Mock(), 'hostname') - result = self.fake_write.write.call_args_list[0] - assert result == call('1234') + # the second argument to `remote()` should be the write func + result = fake_remote.call_args_list[1][0][-1].__name__ + assert result == 'write_monitor_keyring' def test_write_done_path(self): - self.paths.mon.done = Mock(return_value='/cluster-hostname/done') - self.os.path.exists = Mock( + self.distro.sudo_conn.modules.os.path.exists = Mock( side_effect=path_exists(['/'])) - with patch('__builtin__.file', self.fake_file): - mon.create_mon( - 'cluster', '1234', 'initd', - paths=self.paths, os=self.os, subprocess=self.sprocess, - socket=self.socket) + args = Mock(return_value=['cluster', '1234', 'initd']) + args.cluster = 'cluster' - result = self.fake_file.call_args_list[1] - assert result == call('/cluster-hostname/done', 'w') + with patch('ceph_deploy.hosts.common.conf.load'): + with patch('ceph_deploy.hosts.common.remote') as fake_remote: + mon_create(self.distro, self.logger, args, Mock(), 'hostname') + + # the second to last argument to `remote()` should be the done path + # write + result = fake_remote.call_args_list[-2][0][-1].__name__ + assert result == 'create_done_path' def test_write_init_path(self): - self.paths.mon.init = Mock(return_value='/cluster-hostname/init') - self.os.path.exists = Mock( + self.distro.sudo_conn.modules.os.path.exists = Mock( side_effect=path_exists(['/'])) - with patch('__builtin__.file', self.fake_file): - mon.create_mon( - 'cluster', '1234', 'initd', - paths=self.paths, os=self.os, subprocess=self.sprocess, - socket=self.socket) - - result = self.fake_file.call_args_list[2] - assert result == call('/cluster-hostname/init', 'w') + args = Mock(return_value=['cluster', '1234', 'initd']) + args.cluster = 'cluster' + + with patch('ceph_deploy.hosts.common.conf.load'): + with patch('ceph_deploy.hosts.common.remote') as fake_remote: + mon_create(self.distro, self.logger, args, Mock(), 'hostname') + + result = fake_remote.call_args_list[-1][0][-1].__name__ + assert result == 'create_init_path' class TestIsRunning(object):