From: Alfredo Deza Date: Wed, 27 Aug 2014 17:03:13 +0000 (-0400) Subject: This is absolutely TERRIBLE X-Git-Tag: v1.5.13~7 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=d6f004931019cf0507b10bcb3d123fc073d5b09f;p=ceph-deploy.git This is absolutely TERRIBLE we have to now patch like mad people all these methods. These old tests should burn in the fire of the parent suns of the galaxy. Signed-off-by: Alfredo Deza --- diff --git a/ceph_deploy/tests/test_cli_mon.py b/ceph_deploy/tests/test_cli_mon.py index 8077888..1ea80d2 100644 --- a/ceph_deploy/tests/test_cli_mon.py +++ b/ceph_deploy/tests/test_cli_mon.py @@ -45,6 +45,17 @@ def test_bad_no_mon(tmpdir, cli): assert err.value.status == 2 +from mock import Mock, patch + + +def make_fake_connection(platform_information=None): + get_connection = Mock() + get_connection.return_value = get_connection + get_connection.remote_module.platform_information = Mock( + return_value=platform_information) + return get_connection + + def test_simple(tmpdir, capsys): with tmpdir.join('ceph.conf').open('w') as f: f.write("""\ @@ -67,18 +78,21 @@ mon initial members = host1 secret = get_monitor_secret() assert secret == MON_SECRET + fake_ip_addresses = lambda x: ['10.0.0.1'] try: - with mock.patch('ceph_deploy.new.net.get_nonlocal_ip', lambda x, subnet: '10.0.0.1'): - with mock.patch('ceph_deploy.new.arg_validators.Hostname', lambda: lambda x: x): - with directory(str(tmpdir)): - main( - args=['-v', 'new', 'host1'], - namespace=ns, - ) - main( - args=['-v', 'mon', 'create', 'host1'], - namespace=ns, - ) + with patch('ceph_deploy.new.net.ip_addresses', fake_ip_addresses): + with mock.patch('ceph_deploy.new.net.get_nonlocal_ip', lambda x: '10.0.0.1'): + with mock.patch('ceph_deploy.new.arg_validators.Hostname', lambda: lambda x: x): + with mock.patch('ceph_deploy.new.hosts'): + with directory(str(tmpdir)): + main( + args=['-v', 'new', '--no-ssh-copykey', 'host1'], + namespace=ns, + ) + main( + args=['-v', 'mon', 'create', 'host1'], + namespace=ns, + ) except SystemExit as e: raise AssertionError('Unexpected exit: %s', e) out, err = capsys.readouterr() diff --git a/ceph_deploy/tests/test_cli_new.py b/ceph_deploy/tests/test_cli_new.py index 0251f42..478bee9 100644 --- a/ceph_deploy/tests/test_cli_new.py +++ b/ceph_deploy/tests/test_cli_new.py @@ -20,10 +20,14 @@ def test_help(tmpdir, cli): def test_write_global_conf_section(tmpdir, cli): - with patch('ceph_deploy.new.net.get_nonlocal_ip', lambda x, subnet: '10.0.0.1'): - with patch('ceph_deploy.new.arg_validators.Hostname', lambda: lambda x: x): - with directory(str(tmpdir)): - main(args=['new', 'host1']) + fake_ip_addresses = lambda x: ['10.0.0.1'] + + with patch('ceph_deploy.new.hosts'): + with patch('ceph_deploy.new.net.ip_addresses', fake_ip_addresses): + with patch('ceph_deploy.new.net.get_nonlocal_ip', lambda x: '10.0.0.1'): + with patch('ceph_deploy.new.arg_validators.Hostname', lambda: lambda x: x): + with directory(str(tmpdir)): + main(args=['new', 'host1']) with tmpdir.join('ceph.conf').open() as f: cfg = conf.ceph.parse(f) assert cfg.sections() == ['global'] @@ -31,15 +35,18 @@ def test_write_global_conf_section(tmpdir, cli): def pytest_funcarg__newcfg(request): tmpdir = request.getfuncargvalue('tmpdir') + fake_ip_addresses = lambda x: ['10.0.0.1'] def new(*args): - with patch('ceph_deploy.new.net.get_nonlocal_ip', lambda x, subnet: '10.0.0.1'): - with patch('ceph_deploy.new.arg_validators.Hostname', lambda: lambda x: x): - with directory(str(tmpdir)): - main(args=['new'] + list(args)) - with tmpdir.join('ceph.conf').open() as f: - cfg = conf.ceph.parse(f) - return cfg + with patch('ceph_deploy.new.net.ip_addresses', fake_ip_addresses): + with patch('ceph_deploy.new.hosts'): + with patch('ceph_deploy.new.net.get_nonlocal_ip', lambda x: '10.0.0.1'): + with patch('ceph_deploy.new.arg_validators.Hostname', lambda: lambda x: x): + with directory(str(tmpdir)): + main(args=['new'] + list(args)) + with tmpdir.join('ceph.conf').open() as f: + cfg = conf.ceph.parse(f) + return cfg return new