Skip to content

Commit 687ae73

Browse files
committed
Dev: unittests: Add unit test for previous commits
1 parent c087e5b commit 687ae73

File tree

2 files changed

+2
-136
lines changed

2 files changed

+2
-136
lines changed

test/unittests/test_bootstrap.py

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1275,25 +1275,17 @@ def test_remove_qdevice_reload(self, mock_qdevice_configured, mock_confirm, mock
12751275
mock_remove_db.assert_called_once_with()
12761276

12771277
@mock.patch('crmsh.service_manager.ServiceManager.start_service')
1278-
@mock.patch('crmsh.qdevice.QDevice')
1279-
@mock.patch('crmsh.corosync.get_value')
1280-
@mock.patch('crmsh.utils.is_qdevice_tls_on')
1278+
@mock.patch('crmsh.bootstrap.retrieve_data')
12811279
@mock.patch('crmsh.bootstrap.invoke')
12821280
@mock.patch('crmsh.bootstrap.sync_file')
12831281
@mock.patch('crmsh.corosync.conf')
12841282
@mock.patch('crmsh.corosync.add_nodelist_from_cmaptool')
12851283
@mock.patch('crmsh.corosync.is_unicast')
12861284
@mock.patch('crmsh.log.LoggerUtils.status_long')
12871285
def test_start_qdevice_on_join_node(self, mock_status_long, mock_is_unicast, mock_add_nodelist,
1288-
mock_conf, mock_csync2_update, mock_invoke, mock_qdevice_tls,
1289-
mock_get_value, mock_qdevice, mock_start_service):
1286+
mock_conf, mock_csync2_update, mock_invoke, mock_retrieve_data, mock_start_service):
12901287
mock_is_unicast.return_value = False
1291-
mock_qdevice_tls.return_value = True
12921288
mock_conf.return_value = "corosync.conf"
1293-
mock_get_value.return_value = "10.10.10.123"
1294-
mock_qdevice_inst = mock.Mock()
1295-
mock_qdevice.return_value = mock_qdevice_inst
1296-
mock_qdevice_inst.certificate_process_on_join = mock.Mock()
12971289

12981290
bootstrap.start_qdevice_on_join_node("node2")
12991291

@@ -1303,10 +1295,6 @@ def test_start_qdevice_on_join_node(self, mock_status_long, mock_is_unicast, moc
13031295
mock_conf.assert_called_once_with()
13041296
mock_csync2_update.assert_called_once_with("corosync.conf")
13051297
mock_invoke.assert_called_once_with("crm corosync reload")
1306-
mock_qdevice_tls.assert_called_once_with()
1307-
mock_get_value.assert_called_once_with("quorum.device.net.host")
1308-
mock_qdevice.assert_called_once_with("10.10.10.123", cluster_node="node2")
1309-
mock_qdevice_inst.certificate_process_on_join.assert_called_once_with()
13101298
mock_start_service.assert_called_once_with("corosync-qdevice.service", enable=True)
13111299

13121300
@mock.patch('crmsh.sh.ShellUtils.get_stdout_stderr')

test/unittests/test_qdevice.py

Lines changed: 0 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,6 @@ def setUp(self):
154154
self.qdevice_with_hostname = qdevice.QDevice("node.qnetd")
155155
self.qdevice_with_invalid_port = qdevice.QDevice("10.10.10.123", port=100)
156156
self.qdevice_with_invalid_tie_breaker = qdevice.QDevice("10.10.10.123", tie_breaker="wrong")
157-
self.qdevice_with_ip_cluster_node = qdevice.QDevice("10.10.10.123", cluster_node="node1.com")
158157
self.qdevice_with_invalid_cmds_relative_path = qdevice.QDevice("10.10.10.123", cmds="ls")
159158
self.qdevice_with_invalid_cmds_not_exist = qdevice.QDevice("10.10.10.123", cmds="/not_exist")
160159
self.qdevice_with_cluster_name = qdevice.QDevice("10.10.10.123", cluster_name="hacluster1")
@@ -175,10 +174,6 @@ def test_qnetd_cacert_on_local(self):
175174
res = self.qdevice_with_ip.qnetd_cacert_on_local
176175
self.assertEqual(res, "/etc/corosync/qdevice/net/10.10.10.123/qnetd-cacert.crt")
177176

178-
def test_qnetd_cacert_on_cluster(self):
179-
res = self.qdevice_with_ip_cluster_node.qnetd_cacert_on_cluster
180-
self.assertEqual(res, "/etc/corosync/qdevice/net/node1.com/qnetd-cacert.crt")
181-
182177
def test_qdevice_crq_on_qnetd(self):
183178
res = self.qdevice_with_cluster_name.qdevice_crq_on_qnetd
184179
self.assertEqual(res, "/etc/corosync/qnetd/nssdb/qdevice-net-node.crq.hacluster1")
@@ -203,10 +198,6 @@ def test_qdevice_p12_on_local(self):
203198
res = self.qdevice_with_ip.qdevice_p12_on_local
204199
self.assertEqual(res, "/etc/corosync/qdevice/net/nssdb/qdevice-net-node.p12")
205200

206-
def test_qdevice_p12_on_cluster(self):
207-
res = self.qdevice_with_ip_cluster_node.qdevice_p12_on_cluster
208-
self.assertEqual(res, "/etc/corosync/qdevice/net/node1.com/qdevice-net-node.p12")
209-
210201
@mock.patch('crmsh.utils.InterfacesInfo.ip_in_local')
211202
@mock.patch('crmsh.utils.node_reachable_check')
212203
@mock.patch('socket.getaddrinfo')
@@ -629,119 +620,6 @@ def test_certificate_process_on_init(self, mock_fetch_qnetd_crt_from_qnetd,
629620
mock_copy_p12_to_cluster.assert_called_once()
630621
mock_import_p12_on_cluster.assert_called_once()
631622

632-
@mock.patch("crmsh.qdevice.QDevice.log_only_to_file")
633-
@mock.patch("os.path.exists")
634-
@mock.patch("crmsh.qdevice.QDevice.qnetd_cacert_on_cluster", new_callable=mock.PropertyMock)
635-
@mock.patch("crmsh.qdevice.QDevice.qnetd_cacert_on_local", new_callable=mock.PropertyMock)
636-
@mock.patch("crmsh.parallax.parallax_slurp")
637-
def test_fetch_qnetd_crt_from_cluster_exist(self, mock_parallax_slurp, mock_qnetd_cacert_local,
638-
mock_qnetd_cacert_cluster, mock_exists, mock_log):
639-
mock_exists.return_value = True
640-
mock_qnetd_cacert_cluster.return_value = "/etc/corosync/qdevice/net/node1.com/qnetd-cacert.crt"
641-
642-
self.qdevice_with_ip_cluster_node.fetch_qnetd_crt_from_cluster()
643-
644-
mock_log.assert_not_called()
645-
mock_exists.assert_called_once_with(mock_qnetd_cacert_cluster.return_value)
646-
mock_qnetd_cacert_cluster.assert_called_once_with()
647-
mock_qnetd_cacert_local.assert_not_called()
648-
mock_parallax_slurp.assert_not_called()
649-
650-
@mock.patch("crmsh.qdevice.QDevice.log_only_to_file")
651-
@mock.patch("os.path.exists")
652-
@mock.patch("crmsh.qdevice.QDevice.qnetd_cacert_on_cluster", new_callable=mock.PropertyMock)
653-
@mock.patch("crmsh.qdevice.QDevice.qnetd_cacert_on_local", new_callable=mock.PropertyMock)
654-
@mock.patch("crmsh.parallax.parallax_slurp")
655-
def test_fetch_qnetd_crt_from_cluster(self, mock_parallax_slurp, mock_qnetd_cacert_local,
656-
mock_qnetd_cacert_cluster, mock_exists, mock_log):
657-
mock_exists.return_value = False
658-
mock_qnetd_cacert_cluster.return_value = "/etc/corosync/qdevice/net/node1.com/qnetd-cacert.crt"
659-
mock_qnetd_cacert_local.return_value = "/etc/corosync/qdevice/net/10.10.10.123/qnetd-cacert.crt"
660-
661-
self.qdevice_with_ip_cluster_node.fetch_qnetd_crt_from_cluster()
662-
663-
mock_log.assert_called_once_with("Step 1: Fetch qnetd-cacert.crt from node1.com")
664-
mock_exists.assert_called_once_with(mock_qnetd_cacert_cluster.return_value)
665-
mock_qnetd_cacert_cluster.assert_called_once_with()
666-
mock_qnetd_cacert_local.assert_called_once_with()
667-
mock_parallax_slurp.assert_called_once_with(["node1.com"], "/etc/corosync/qdevice/net", mock_qnetd_cacert_local.return_value)
668-
669-
@mock.patch("crmsh.qdevice.QDevice.log_only_to_file")
670-
@mock.patch("crmsh.sh.ClusterShell.get_stdout_or_raise_error")
671-
@mock.patch("crmsh.qdevice.QDevice.qnetd_cacert_on_cluster", new_callable=mock.PropertyMock)
672-
def test_init_db_on_local(self, mock_qnetd_cacert_cluster, mock_stdout_stderr, mock_log):
673-
mock_qnetd_cacert_cluster.return_value = "/etc/corosync/qdevice/net/node1.com/qnetd-cacert.crt"
674-
mock_stdout_stderr.return_value = (0, None, None)
675-
676-
self.qdevice_with_ip_cluster_node.init_db_on_local()
677-
678-
mock_log.assert_called_once_with("Step 2: Initialize database on local",
679-
'corosync-qdevice-net-certutil -i -c /etc/corosync/qdevice/net/node1.com/qnetd-cacert.crt')
680-
mock_qnetd_cacert_cluster.assert_called_once_with()
681-
mock_stdout_stderr.assert_called_once_with("corosync-qdevice-net-certutil -i -c {}".format(mock_qnetd_cacert_cluster.return_value))
682-
683-
@mock.patch("crmsh.qdevice.QDevice.log_only_to_file")
684-
@mock.patch("os.path.exists")
685-
@mock.patch("crmsh.qdevice.QDevice.qdevice_p12_on_cluster", new_callable=mock.PropertyMock)
686-
@mock.patch("crmsh.qdevice.QDevice.qdevice_p12_on_local", new_callable=mock.PropertyMock)
687-
@mock.patch("crmsh.parallax.parallax_slurp")
688-
def test_fetch_p12_from_cluster_exist(self, mock_parallax_slurp, mock_p12_on_local,
689-
mock_p12_on_cluster, mock_exists, mock_log):
690-
mock_exists.return_value = True
691-
mock_p12_on_cluster.return_value = "/etc/corosync/qdevice/net/node1.com/qdevice-net-node.p12"
692-
693-
self.qdevice_with_ip_cluster_node.fetch_p12_from_cluster()
694-
695-
mock_log.assert_not_called()
696-
mock_exists.assert_called_once_with(mock_p12_on_cluster.return_value)
697-
mock_p12_on_cluster.assert_called_once_with()
698-
mock_p12_on_local.assert_not_called()
699-
mock_parallax_slurp.assert_not_called()
700-
701-
@mock.patch("crmsh.qdevice.QDevice.log_only_to_file")
702-
@mock.patch("os.path.exists")
703-
@mock.patch("crmsh.qdevice.QDevice.qdevice_p12_on_cluster", new_callable=mock.PropertyMock)
704-
@mock.patch("crmsh.qdevice.QDevice.qdevice_p12_on_local", new_callable=mock.PropertyMock)
705-
@mock.patch("crmsh.parallax.parallax_slurp")
706-
def test_fetch_p12_from_cluster(self, mock_parallax_slurp, mock_p12_on_local,
707-
mock_p12_on_cluster, mock_exists, mock_log):
708-
mock_exists.return_value = False
709-
mock_p12_on_cluster.return_value = "/etc/corosync/qdevice/net/node1.com/qdevice-net-node.p12"
710-
mock_p12_on_local.return_value = "/etc/corosync/qdevice/net/nssdb/qdevice-net-node.p12"
711-
712-
self.qdevice_with_ip_cluster_node.fetch_p12_from_cluster()
713-
714-
mock_log.assert_called_once_with("Step 3: Fetch qdevice-net-node.p12 from node1.com")
715-
mock_exists.assert_called_once_with(mock_p12_on_cluster.return_value)
716-
mock_p12_on_cluster.assert_called_once_with()
717-
mock_p12_on_local.assert_called_once_with()
718-
mock_parallax_slurp.assert_called_once_with(["node1.com"], '/etc/corosync/qdevice/net', mock_p12_on_local.return_value)
719-
720-
@mock.patch("crmsh.qdevice.QDevice.log_only_to_file")
721-
@mock.patch("crmsh.sh.ClusterShell.get_stdout_or_raise_error")
722-
@mock.patch("crmsh.qdevice.QDevice.qdevice_p12_on_cluster", new_callable=mock.PropertyMock)
723-
def test_import_p12_on_local(self, mock_p12_on_cluster, mock_stdout_stderr, mock_log):
724-
mock_p12_on_cluster.return_value = "/etc/corosync/qdevice/net/node1.com/qdevice-net-node.p12"
725-
726-
self.qdevice_with_ip_cluster_node.import_p12_on_local()
727-
728-
mock_log.assert_called_once_with("Step 4: Import cluster certificate and key",
729-
'corosync-qdevice-net-certutil -m -c /etc/corosync/qdevice/net/node1.com/qdevice-net-node.p12')
730-
mock_p12_on_cluster.assert_called_once_with()
731-
mock_stdout_stderr.assert_called_once_with("corosync-qdevice-net-certutil -m -c {}".format(mock_p12_on_cluster.return_value))
732-
733-
@mock.patch("crmsh.qdevice.QDevice.import_p12_on_local")
734-
@mock.patch("crmsh.qdevice.QDevice.fetch_p12_from_cluster")
735-
@mock.patch("crmsh.qdevice.QDevice.init_db_on_local")
736-
@mock.patch("crmsh.qdevice.QDevice.fetch_qnetd_crt_from_cluster")
737-
def test_certificate_process_on_join(self, mock_fetch_qnetd_crt_from_cluster, mock_init_db_on_local,
738-
mock_fetch_p12_from_cluster, mock_import_p12_on_local):
739-
self.qdevice_with_ip.certificate_process_on_join()
740-
mock_fetch_qnetd_crt_from_cluster.assert_called_once_with()
741-
mock_init_db_on_local.assert_called_once_with()
742-
mock_fetch_p12_from_cluster.assert_called_once_with()
743-
mock_import_p12_on_local.assert_called_once_with()
744-
745623
@mock.patch("crmsh.utils.str2file")
746624
@mock.patch("crmsh.corosync.make_section")
747625
@mock.patch("crmsh.corosync.Parser")

0 commit comments

Comments
 (0)