38
38
)
39
39
from cluster import NotReadyError , RemoveRaftMemberFailedError
40
40
from constants import PEER , POSTGRESQL_SNAP_NAME , SECRET_INTERNAL_LABEL , SNAP_PACKAGES
41
- from tests .helpers import patch_network_get
42
41
43
42
CREATE_CLUSTER_CONF_PATH = "/etc/postgresql-common/createcluster.d/pgcharm.conf"
44
43
@@ -57,7 +56,6 @@ def harness():
57
56
harness .cleanup ()
58
57
59
58
60
- @patch_network_get (private_address = "1.1.1.1" )
61
59
def test_on_install (harness ):
62
60
with patch ("charm.subprocess.check_call" ) as _check_call , patch (
63
61
"charm.snap.SnapCache"
@@ -91,7 +89,6 @@ def test_on_install(harness):
91
89
assert isinstance (harness .model .unit .status , WaitingStatus )
92
90
93
91
94
- @patch_network_get (private_address = "1.1.1.1" )
95
92
def test_on_install_failed_to_create_home (harness ):
96
93
with patch ("charm.subprocess.check_call" ) as _check_call , patch (
97
94
"charm.snap.SnapCache"
@@ -123,7 +120,6 @@ def test_on_install_failed_to_create_home(harness):
123
120
assert isinstance (harness .model .unit .status , WaitingStatus )
124
121
125
122
126
- @patch_network_get (private_address = "1.1.1.1" )
127
123
def test_on_install_snap_failure (harness ):
128
124
with patch (
129
125
"charm.PostgresqlOperatorCharm._install_snap_packages"
@@ -139,21 +135,19 @@ def test_on_install_snap_failure(harness):
139
135
assert isinstance (harness .model .unit .status , BlockedStatus )
140
136
141
137
142
- @patch_network_get (private_address = "1.1.1.1" )
143
138
def test_patroni_scrape_config_no_tls (harness ):
144
139
result = harness .charm .patroni_scrape_config ()
145
140
146
141
assert result == [
147
142
{
148
143
"metrics_path" : "/metrics" ,
149
144
"scheme" : "http" ,
150
- "static_configs" : [{"targets" : ["1.1.1.1 :8008" ]}],
145
+ "static_configs" : [{"targets" : ["192.0.2.0 :8008" ]}],
151
146
"tls_config" : {"insecure_skip_verify" : True },
152
147
},
153
148
]
154
149
155
150
156
- @patch_network_get (private_address = "1.1.1.1" )
157
151
def test_patroni_scrape_config_tls (harness ):
158
152
with patch (
159
153
"charm.PostgresqlOperatorCharm.is_tls_enabled" ,
@@ -166,7 +160,7 @@ def test_patroni_scrape_config_tls(harness):
166
160
{
167
161
"metrics_path" : "/metrics" ,
168
162
"scheme" : "https" ,
169
- "static_configs" : [{"targets" : ["1.1.1.1 :8008" ]}],
163
+ "static_configs" : [{"targets" : ["192.0.2.0 :8008" ]}],
170
164
"tls_config" : {"insecure_skip_verify" : True },
171
165
},
172
166
]
@@ -206,7 +200,6 @@ def test_primary_endpoint_no_peers(harness):
206
200
assert not _patroni .return_value .get_primary .called
207
201
208
202
209
- @patch_network_get (private_address = "1.1.1.1" )
210
203
def test_on_leader_elected (harness ):
211
204
with patch (
212
205
"charm.PostgresqlOperatorCharm._update_relation_endpoints" , new_callable = PropertyMock
@@ -570,7 +563,6 @@ def test_enable_disable_extensions(harness, caplog):
570
563
assert isinstance (harness .charm .unit .status , ActiveStatus )
571
564
572
565
573
- @patch_network_get (private_address = "1.1.1.1" )
574
566
def test_on_start (harness ):
575
567
with (
576
568
patch (
@@ -669,7 +661,6 @@ def test_on_start(harness):
669
661
_restart_services_after_reboot .assert_called_once ()
670
662
671
663
672
- @patch_network_get (private_address = "1.1.1.1" )
673
664
def test_on_start_replica (harness ):
674
665
with (
675
666
patch ("charm.snap.SnapCache" ) as _snap_cache ,
@@ -734,7 +725,6 @@ def test_on_start_replica(harness):
734
725
assert isinstance (harness .model .unit .status , WaitingStatus )
735
726
736
727
737
- @patch_network_get (private_address = "1.1.1.1" )
738
728
def test_on_start_no_patroni_member (harness ):
739
729
with (
740
730
patch ("subprocess.check_output" , return_value = b"C" ),
@@ -785,7 +775,6 @@ def test_on_start_after_blocked_state(harness):
785
775
assert harness .model .unit .status == initial_status
786
776
787
777
788
- @patch_network_get (private_address = "1.1.1.1" )
789
778
def test_on_get_password (harness ):
790
779
with patch ("charm.PostgresqlOperatorCharm.update_config" ):
791
780
rel_id = harness .model .get_relation (PEER ).id
@@ -820,7 +809,6 @@ def test_on_get_password(harness):
820
809
mock_event .set_results .assert_called_once_with ({"password" : "replication-test-password" })
821
810
822
811
823
- @patch_network_get (private_address = "1.1.1.1" )
824
812
def test_on_set_password (harness ):
825
813
with (
826
814
patch ("charm.PostgresqlOperatorCharm.update_config" ),
@@ -883,7 +871,6 @@ def test_on_set_password(harness):
883
871
)
884
872
885
873
886
- @patch_network_get (private_address = "1.1.1.1" )
887
874
def test_on_update_status (harness ):
888
875
with (
889
876
patch ("charm.ClusterTopologyObserver.start_observer" ) as _start_observer ,
@@ -992,7 +979,6 @@ def test_on_update_status(harness):
992
979
_start_observer .assert_called_once ()
993
980
994
981
995
- @patch_network_get (private_address = "1.1.1.1" )
996
982
def test_on_update_status_after_restore_operation (harness ):
997
983
with (
998
984
patch ("charm.ClusterTopologyObserver.start_observer" ),
@@ -1218,7 +1204,6 @@ def test_reboot_on_detached_storage(harness):
1218
1204
_check_call .assert_called_once_with (["systemctl" , "reboot" ])
1219
1205
1220
1206
1221
- @patch_network_get (private_address = "1.1.1.1" )
1222
1207
def test_restart (harness ):
1223
1208
with (
1224
1209
patch ("charm.Patroni.restart_postgresql" ) as _restart_postgresql ,
@@ -1246,7 +1231,6 @@ def test_restart(harness):
1246
1231
mock_event .defer .assert_not_called ()
1247
1232
1248
1233
1249
- @patch_network_get (private_address = "1.1.1.1" )
1250
1234
def test_update_config (harness ):
1251
1235
with (
1252
1236
patch ("subprocess.check_output" , return_value = b"C" ),
@@ -1457,7 +1441,6 @@ def test_validate_config_options(harness):
1457
1441
assert str (e .value ).startswith (message )
1458
1442
1459
1443
1460
- @patch_network_get (private_address = "1.1.1.1" )
1461
1444
def test_on_peer_relation_changed (harness ):
1462
1445
with (
1463
1446
patch ("charm.snap.SnapCache" ),
@@ -1501,7 +1484,7 @@ def test_on_peer_relation_changed(harness):
1501
1484
harness .update_relation_data (
1502
1485
rel_id ,
1503
1486
harness .charm .app .name ,
1504
- {"cluster_initialised" : "True" , "members_ips" : '["1.1.1.1 "]' },
1487
+ {"cluster_initialised" : "True" , "members_ips" : '["192.0.2.0 "]' },
1505
1488
)
1506
1489
harness .set_leader ()
1507
1490
_reconfigure_cluster .return_value = False
@@ -1515,7 +1498,7 @@ def test_on_peer_relation_changed(harness):
1515
1498
_reconfigure_cluster .return_value = True
1516
1499
_update_member_ip .return_value = False
1517
1500
_member_started .return_value = True
1518
- _primary_endpoint .return_value = "1.1.1.1 "
1501
+ _primary_endpoint .return_value = "192.0.2.0 "
1519
1502
harness .model .unit .status = WaitingStatus ("awaiting for cluster to start" )
1520
1503
harness .charm ._on_peer_relation_changed (mock_event )
1521
1504
mock_event .defer .assert_not_called ()
@@ -1600,7 +1583,6 @@ def test_on_peer_relation_changed(harness):
1600
1583
_check_stanza .assert_called_once ()
1601
1584
1602
1585
1603
- @patch_network_get (private_address = "1.1.1.1" )
1604
1586
def test_reconfigure_cluster (harness ):
1605
1587
with (
1606
1588
patch ("charm.PostgresqlOperatorCharm._add_members" ) as _add_members ,
@@ -1684,7 +1666,6 @@ def test_update_certificate(harness):
1684
1666
assert harness .charm .get_secret ("unit" , "private-key" ) == private_key
1685
1667
1686
1668
1687
- @patch_network_get (private_address = "1.1.1.1" )
1688
1669
def test_update_member_ip (harness ):
1689
1670
with (
1690
1671
patch ("charm.PostgresqlOperatorCharm._update_certificate" ) as _update_certificate ,
@@ -1697,7 +1678,7 @@ def test_update_member_ip(harness):
1697
1678
rel_id ,
1698
1679
harness .charm .unit .name ,
1699
1680
{
1700
- "ip" : "1.1.1.1 " ,
1681
+ "ip" : "192.0.2.0 " ,
1701
1682
},
1702
1683
)
1703
1684
assert not (harness .charm ._update_member_ip ())
@@ -1717,13 +1698,12 @@ def test_update_member_ip(harness):
1717
1698
)
1718
1699
assert harness .charm ._update_member_ip ()
1719
1700
relation_data = harness .get_relation_data (rel_id , harness .charm .unit .name )
1720
- assert relation_data .get ("ip" ) == "1.1.1.1 "
1701
+ assert relation_data .get ("ip" ) == "192.0.2.0 "
1721
1702
assert relation_data .get ("ip-to-remove" ) == "2.2.2.2"
1722
1703
_stop_patroni .assert_called_once ()
1723
1704
_update_certificate .assert_called_once ()
1724
1705
1725
1706
1726
- @patch_network_get (private_address = "1.1.1.1" )
1727
1707
def test_push_tls_files_to_workload (harness ):
1728
1708
with (
1729
1709
patch ("charm.PostgresqlOperatorCharm.update_config" ) as _update_config ,
@@ -1874,7 +1854,6 @@ def test_scope_obj(harness):
1874
1854
assert harness .charm ._scope_obj ("test" ) is None
1875
1855
1876
1856
1877
- @patch_network_get (private_address = "1.1.1.1" )
1878
1857
def test_get_secret_from_databag (harness ):
1879
1858
"""Asserts that get_secret method can read secrets from databag.
1880
1859
@@ -1901,7 +1880,6 @@ def test_get_secret_from_databag(harness):
1901
1880
assert harness .charm .get_secret ("unit" , "operator_password" ) == "test-password"
1902
1881
1903
1882
1904
- @patch_network_get (private_address = "1.1.1.1" )
1905
1883
def test_on_get_password_secrets (harness ):
1906
1884
with (
1907
1885
patch ("charm.PostgresqlOperatorCharm._on_leader_elected" ),
@@ -1932,7 +1910,6 @@ def test_on_get_password_secrets(harness):
1932
1910
1933
1911
1934
1912
@pytest .mark .parametrize ("scope,field" , [("app" , "operator-password" ), ("unit" , "csr" )])
1935
- @patch_network_get (private_address = "1.1.1.1" )
1936
1913
def test_get_secret_secrets (harness , scope , field ):
1937
1914
with (
1938
1915
patch ("charm.PostgresqlOperatorCharm._on_leader_elected" ),
@@ -1944,7 +1921,6 @@ def test_get_secret_secrets(harness, scope, field):
1944
1921
assert harness .charm .get_secret (scope , field ) == "test"
1945
1922
1946
1923
1947
- @patch_network_get (private_address = "1.1.1.1" )
1948
1924
def test_set_secret_in_databag (harness , only_without_juju_secrets ):
1949
1925
"""Asserts that set_secret method writes to relation databag.
1950
1926
@@ -1979,7 +1955,6 @@ def test_set_secret_in_databag(harness, only_without_juju_secrets):
1979
1955
1980
1956
1981
1957
@pytest .mark .parametrize ("scope,is_leader" , [("app" , True ), ("unit" , True ), ("unit" , False )])
1982
- @patch_network_get (private_address = "1.1.1.1" )
1983
1958
def test_set_reset_new_secret (harness , scope , is_leader ):
1984
1959
with (
1985
1960
patch ("charm.PostgresqlOperatorCharm._on_leader_elected" ),
@@ -2001,7 +1976,6 @@ def test_set_reset_new_secret(harness, scope, is_leader):
2001
1976
2002
1977
2003
1978
@pytest .mark .parametrize ("scope,is_leader" , [("app" , True ), ("unit" , True ), ("unit" , False )])
2004
- @patch_network_get (private_address = "1.1.1.1" )
2005
1979
def test_invalid_secret (harness , scope , is_leader ):
2006
1980
with (
2007
1981
patch ("charm.PostgresqlOperatorCharm._on_leader_elected" ),
@@ -2016,7 +1990,6 @@ def test_invalid_secret(harness, scope, is_leader):
2016
1990
assert harness .charm .get_secret (scope , "somekey" ) is None
2017
1991
2018
1992
2019
- @patch_network_get (private_address = "1.1.1.1" )
2020
1993
def test_delete_password (harness , _has_secrets , caplog ):
2021
1994
with (
2022
1995
patch ("charm.PostgresqlOperatorCharm._on_leader_elected" ),
@@ -2063,7 +2036,6 @@ def test_delete_password(harness, _has_secrets, caplog):
2063
2036
2064
2037
2065
2038
@pytest .mark .parametrize ("scope,is_leader" , [("app" , True ), ("unit" , True ), ("unit" , False )])
2066
- @patch_network_get (private_address = "1.1.1.1" )
2067
2039
def test_migration_from_databag (harness , only_with_juju_secrets , scope , is_leader ):
2068
2040
"""Check if we're moving on to use secrets when live upgrade from databag to Secrets usage.
2069
2041
@@ -2091,7 +2063,6 @@ def test_migration_from_databag(harness, only_with_juju_secrets, scope, is_leade
2091
2063
2092
2064
2093
2065
@pytest .mark .parametrize ("scope,is_leader" , [("app" , True ), ("unit" , True ), ("unit" , False )])
2094
- @patch_network_get (private_address = "1.1.1.1" )
2095
2066
def test_migration_from_single_secret (harness , only_with_juju_secrets , scope , is_leader ):
2096
2067
"""Check if we're moving on to use secrets when live upgrade from databag to Secrets usage.
2097
2068
0 commit comments