def test_pool_nodes(): """Test that pool command is called correctly.""" mocked_remote_hosts = mock.Mock(spec_set=RemoteHosts) mocked_remote_hosts.run_sync = mock.Mock(return_value=iter(())) elastic_hosts = ec.ElasticsearchHosts(mocked_remote_hosts, None) elastic_hosts.pool_nodes() mocked_remote_hosts.run_sync.assert_called_with("pool")
def test_get_remote_hosts(): """Test that RemoteHosts instance is returned.""" mocked_remote_hosts = mock.Mock(spec_set=RemoteHosts) mocked_remote_hosts.hosts = NodeSet("el[1-2]") elastic_hosts = ec.ElasticsearchHosts(mocked_remote_hosts, None) result = elastic_hosts.get_remote_hosts() assert isinstance(result, RemoteHosts)
def test_restart_elasticsearch(): """Test that restart elasticsearch service is called correctly.""" mocked_remote_hosts = mock.Mock(spec_set=RemoteHosts) mocked_remote_hosts.run_sync = mock.Mock(return_value=iter(())) elastic_hosts = ec.ElasticsearchHosts(mocked_remote_hosts, None) elastic_hosts.restart_elasticsearch() mocked_remote_hosts.run_sync.assert_called_with( "cat /etc/elasticsearch/instances | xargs systemctl restart")
def test_wait_for_elasticsearch_does_no_check_when_in_dry_run(): """In dry run we expect to always return that all nodes are up.""" node_group = mock.Mock(spec_set=NodesGroup) node_group.check_all_nodes_up = mock.Mock() remote_hosts = mock.Mock(spec_set=RemoteHosts) hosts = ec.ElasticsearchHosts(remote_hosts, [node_group], dry_run=True) hosts.wait_for_elasticsearch_up() assert not node_group.check_all_nodes_up.called
def test_wait_for_elasticsearch_up_retries_on_failures(mocked_sleep): """Test that elasticsearch instance is called when wait for instance to come up.""" node_group = mock.Mock(spec_set=NodesGroup) node_group.check_all_nodes_up = mock.Mock( side_effect=ec.ElasticsearchClusterCheckError()) remote_hosts = mock.Mock(spec_set=RemoteHosts) hosts = ec.ElasticsearchHosts(remote_hosts, [node_group], dry_run=False) with pytest.raises(ec.ElasticsearchClusterCheckError): hosts.wait_for_elasticsearch_up(timedelta(minutes=1)) assert node_group.check_all_nodes_up.call_count == 12 assert mocked_sleep.called
def test_wait_for_elasticsearch_up_delegates_to_all_nodes_groups(): """Test that elasticsearch instance is called when wait for instance to come up.""" node_group1 = mock.Mock(spec_set=NodesGroup) node_group1.check_all_nodes_up = mock.Mock() node_group2 = mock.Mock(spec_set=NodesGroup) node_group2.check_all_nodes_up = mock.Mock() remote_hosts = mock.Mock(spec_set=RemoteHosts) hosts = ec.ElasticsearchHosts(remote_hosts, [node_group1, node_group2], dry_run=False) hosts.wait_for_elasticsearch_up() assert node_group1.check_all_nodes_up.called assert node_group2.check_all_nodes_up.called