def test_passes_correct_endpoints(self): """Test that passes correct endpoints by default.""" expected_endpoints = "https://test0.local.host:2379" mock_run_sync = _get_mock_run_sync(return_value=b"") controller = EtcdctlController(remote_host=RemoteHosts( config=mock.MagicMock(specset=Config), hosts=NodeSet("test0.local.host")), ) with mock.patch.object(RemoteHosts, "run_sync", mock_run_sync): controller.get_cluster_info() _assert_called_with_single_param( param=f"--endpoints {expected_endpoints}", mock_obj=mock_run_sync, )
def test_passes_correct_key_file(self): """Test that passes correct key file by default.""" expected_key_file = "/etc/etcd/ssl/test0.local.host.priv" mock_run_sync = _get_mock_run_sync(return_value=b"") controller = EtcdctlController(remote_host=RemoteHosts( config=mock.MagicMock(specset=Config), hosts=NodeSet("test0.local.host")), ) with mock.patch.object(RemoteHosts, "run_sync", mock_run_sync): controller.get_cluster_info() _assert_called_with_single_param( param=f"--key-file {expected_key_file}", mock_obj=mock_run_sync, )
def test_raises_when_getting_member_without_id(self): """Test that raises when getting member without id.""" mock_run_sync = _get_mock_run_sync(return_value=b""" 415090d15def9053: name=toolsbeta-test-k8s-etcd-9.toolsbeta.eqiad1.wikimedia.cloud peerURLs=https://toolsbeta-test-k8s-etcd-9.toolsbeta.eqiad1.wikimedia.cloud:2380 clientURLs=https://toolsbeta-test-k8s-etcd-9.toolsbeta.eqiad1.wikimedia.cloud:2379 isLeader=true peerURLs=https://idontexist.localhost:1234 """ # noqa: E501 ) controller = EtcdctlController(remote_host=RemoteHosts( config=mock.MagicMock(specset=Config), hosts=NodeSet("test0.local.host")), ) with self.assertRaises(UnableToParseOutput): with mock.patch.object(RemoteHosts, "run_sync", mock_run_sync): controller.get_cluster_info()
def test_parses_result_with_one_member(self): """Test that parses result with one member.""" expected_node = { "member_id": "415090d15def9053", "name": "toolsbeta-test-k8s-etcd-9.toolsbeta.eqiad1.wikimedia.cloud", "status": "up", "isLeader": True, "peerURLs": "https://toolsbeta-test-k8s-etcd-9.toolsbeta.eqiad1.wikimedia.cloud:2380", "clientURLs": "https://toolsbeta-test-k8s-etcd-9.toolsbeta.eqiad1.wikimedia.cloud:2379", } mock_run_sync = _get_mock_run_sync( return_value=b""" 415090d15def9053: name=toolsbeta-test-k8s-etcd-9.toolsbeta.eqiad1.wikimedia.cloud peerURLs=https://toolsbeta-test-k8s-etcd-9.toolsbeta.eqiad1.wikimedia.cloud:2380 clientURLs=https://toolsbeta-test-k8s-etcd-9.toolsbeta.eqiad1.wikimedia.cloud:2379 isLeader=true """, # noqa: E501 ) controller = EtcdctlController(remote_host=RemoteHosts( config=mock.MagicMock(specset=Config), hosts=NodeSet("test0.local.host")), ) with mock.patch.object(RemoteHosts, "run_sync", mock_run_sync): gotten_result = controller.get_cluster_info() mock_run_sync.assert_called_once() assert len(gotten_result) == 1 assert expected_node["member_id"] in gotten_result assert gotten_result[expected_node["member_id"]] == expected_node
def test_parses_result_with_member_down(self): """Test that parses result with member down.""" expected_result = { "415090d15def9053": { "member_id": "415090d15def9053", "name": "toolsbeta-test-k8s-etcd-9.toolsbeta.eqiad1.wikimedia.cloud", "status": "up", "isLeader": True, "peerURLs": "https://toolsbeta-test-k8s-etcd-9.toolsbeta.eqiad1.wikimedia.cloud:2380", "clientURLs": "https://toolsbeta-test-k8s-etcd-9.toolsbeta.eqiad1.wikimedia.cloud:2379", }, "cf612c785df58f6a": { "member_id": "cf612c785df58f6a", "peerURLs": "https://idontexist.localhost:1234", "status": "unstarted", }, } mock_run_sync = _get_mock_run_sync(return_value=b""" 415090d15def9053: name=toolsbeta-test-k8s-etcd-9.toolsbeta.eqiad1.wikimedia.cloud peerURLs=https://toolsbeta-test-k8s-etcd-9.toolsbeta.eqiad1.wikimedia.cloud:2380 clientURLs=https://toolsbeta-test-k8s-etcd-9.toolsbeta.eqiad1.wikimedia.cloud:2379 isLeader=true cf612c785df58f6a[unstarted]: peerURLs=https://idontexist.localhost:1234 """ # noqa: E501 ) controller = EtcdctlController(remote_host=RemoteHosts( config=mock.MagicMock(specset=Config), hosts=NodeSet("test0.local.host")), ) with mock.patch.object(RemoteHosts, "run_sync", mock_run_sync): gotten_result = controller.get_cluster_info() mock_run_sync.assert_called_once() assert expected_result == gotten_result