示例#1
0
    def test___eq__(self, mock_yaml):
        topology1 = TopologyConfiguration("mykafka", "/etc/kafka_discovery")
        topology2 = TopologyConfiguration("mykafka", "/etc/kafka_discovery")
        assert topology1 == topology2

        topology1 = TopologyConfiguration("mykafka")
        topology2 = TopologyConfiguration("mykafka")
        assert topology1 == topology2
示例#2
0
    def test_get_cluster_by_name_error(self, mock_yaml):
        topology = TopologyConfiguration(
            cluster_type='mykafka',
            kafka_topology_path=TEST_BASE_KAFKA,
        )

        with pytest.raises(ConfigurationError):
            topology.get_cluster_by_name('does-not-exist')
示例#3
0
    def test_get_cluster_by_name_error(self, mock_yaml):
        topology = TopologyConfiguration(
            cluster_type='mykafka',
            kafka_topology_path=TEST_BASE_KAFKA,
        )

        with pytest.raises(ConfigurationError):
            topology.get_cluster_by_name('does-not-exist')
示例#4
0
    def test___ne__(self, mock_yaml):
        topology1 = TopologyConfiguration("mykafka", "/etc/kafka_discovery")
        topology2 = TopologyConfiguration("somethingelse",
                                          "/etc/kafka_discovery")
        assert topology1 != topology2

        topology1 = TopologyConfiguration("mykafka")
        topology2 = TopologyConfiguration("somethingelse")
        assert topology1 != topology2
示例#5
0
 def test_get_cluster_by_name(self, mock_yaml):
     topology = TopologyConfiguration(
         cluster_type='mykafka',
         kafka_topology_path=TEST_BASE_KAFKA,
     )
     actual_cluster = topology.get_cluster_by_name('cluster1')
     expected_cluster = ClusterConfig('mykafka', 'cluster1',
                                      ["mybrokerhost1:9092"],
                                      "0.1.2.3,0.2.3.4/kafka")
     assert expected_cluster == actual_cluster
示例#6
0
 def test_get_cluster_by_name(self, mock_yaml):
     topology = TopologyConfiguration(
         cluster_type='mykafka',
         kafka_topology_path=TEST_BASE_KAFKA,
     )
     actual_cluster = topology.get_cluster_by_name('cluster1')
     expected_cluster = ClusterConfig(
         'mykafka', 'cluster1', ["mybrokerhost1:9092"], "0.1.2.3,0.2.3.4/kafka"
     )
     assert expected_cluster == actual_cluster
示例#7
0
 def test_get_all_clusters(self, mock_yaml):
     topology = TopologyConfiguration(
         cluster_type='mykafka',
         kafka_topology_path=TEST_BASE_KAFKA,
     )
     actual_clusters = topology.get_all_clusters()
     expected_clusters = [
         ClusterConfig('mykafka', 'cluster1', ["mybrokerhost1:9092"],
                       "0.1.2.3,0.2.3.4/kafka"),
         ClusterConfig('mykafka', 'cluster2', ["mybrokerhost2:9092"],
                       "0.3.4.5,0.4.5.6/kafka")
     ]
     assert sorted(expected_clusters) == sorted(actual_clusters)
示例#8
0
 def test_get_local_cluster(self, mock_yaml):
     topology = TopologyConfiguration(
         cluster_type='mykafka',
         kafka_topology_path=TEST_BASE_KAFKA,
     )
     mock_yaml.assert_called_once_with('/base/kafka_discovery/mykafka.yaml')
     actual_cluster = topology.get_local_cluster()
     expected_cluster = ClusterConfig(
         'mykafka',
         'cluster1',
         ['mybrokerhost1:9092'],
         '0.1.2.3,0.2.3.4/kafka',
     )
     assert actual_cluster == expected_cluster
示例#9
0
 def test_get_local_cluster(self, mock_yaml):
     topology = TopologyConfiguration(
         cluster_type='mykafka',
         kafka_topology_path=TEST_BASE_KAFKA,
     )
     mock_yaml.assert_called_once_with('/base/kafka_discovery/mykafka.yaml')
     actual_cluster = topology.get_local_cluster()
     expected_cluster = ClusterConfig(
         'mykafka',
         'cluster1',
         ['mybrokerhost1:9092'],
         '0.1.2.3,0.2.3.4/kafka',
     )
     assert actual_cluster == expected_cluster
示例#10
0
 def test_get_all_clusters(self, mock_yaml):
     topology = TopologyConfiguration(
         cluster_type='mykafka',
         kafka_topology_path=TEST_BASE_KAFKA,
     )
     actual_clusters = topology.get_all_clusters()
     expected_clusters = [
         ClusterConfig(
             'mykafka', 'cluster1', ["mybrokerhost1:9092"], "0.1.2.3,0.2.3.4/kafka"
         ),
         ClusterConfig(
             'mykafka', 'cluster2', ["mybrokerhost2:9092"], "0.3.4.5,0.4.5.6/kafka"
         )
     ]
     assert sorted(expected_clusters) == sorted(actual_clusters)
示例#11
0
 def test_get_log_cluster_missing(self, mock_yaml):
     # Should raise ConfigurationError if a cluster is in region but not in
     # the cluster list
     mock_yaml.side_effect = None
     mock_yaml.return_value = {
         'clusters': {
             'cluster1': {
                 'broker_list': ['mybroker'],
                 'zookeeper': '0.1.2.3,0.2.3.4/kafka'
             },
         },
     }
     # The configuration is valid, but there is no local cluster.
     topology = TopologyConfiguration(
         cluster_type='mykafka',
         kafka_topology_path=TEST_BASE_KAFKA,
     )
     # Raise ConfigurationError because there is no local cluster
     with pytest.raises(ConfigurationError):
         topology.get_local_cluster()
示例#12
0
 def test_get_log_cluster_missing(self, mock_yaml):
     # Should raise ConfigurationError if a cluster is in region but not in
     # the cluster list
     mock_yaml.side_effect = None
     mock_yaml.return_value = {
         'clusters': {
             'cluster1': {
                 'broker_list': ['mybroker'],
                 'zookeeper': '0.1.2.3,0.2.3.4/kafka'
             },
         },
     }
     # The configuration is valid, but there is no local cluster.
     topology = TopologyConfiguration(
         cluster_type='mykafka',
         kafka_topology_path=TEST_BASE_KAFKA,
     )
     # Raise ConfigurationError because there is no local cluster
     with pytest.raises(ConfigurationError):
         topology.get_local_cluster()
示例#13
0
 def test_missing_cluster(self):
     with pytest.raises(ConfigurationError):
         with mock.patch("os.path.isfile", return_value=False):
             TopologyConfiguration(cluster_type="wrong_cluster",
                                   kafka_topology_path=TEST_BASE_KAFKA)