From a2455bbe5ae73849ee8e1e713985c9b3091c60f7 Mon Sep 17 00:00:00 2001 From: Liam Young Date: Wed, 29 Apr 2020 05:43:29 +0000 Subject: [PATCH] Unit test fixes * Fixed typo in test_ceph_iscsi_charm.py file name * Replaced artifical emit in test_on_has_peers with by adding relation data later in the test. * Updated calls to `add_relation_unit` as the `remote_unit_data` arg has been removed. --- mod/operator | 2 +- ...scsi_charm.py => test_ceph_iscsi_charm.py} | 37 ++++++++++++++----- unit_tests/test_interface_ceph_iscsi_peer.py | 36 ++++++++++++------ 3 files changed, 53 insertions(+), 22 deletions(-) rename unit_tests/{test_cepch_iscsi_charm.py => test_ceph_iscsi_charm.py} (92%) diff --git a/mod/operator b/mod/operator index 04cb347..60c43f8 160000 --- a/mod/operator +++ b/mod/operator @@ -1 +1 @@ -Subproject commit 04cb347938b87776638fdeaa48f6c5c0f115346d +Subproject commit 60c43f81e36139ab4044c185247eb27fe389bce6 diff --git a/unit_tests/test_cepch_iscsi_charm.py b/unit_tests/test_ceph_iscsi_charm.py similarity index 92% rename from unit_tests/test_cepch_iscsi_charm.py rename to unit_tests/test_ceph_iscsi_charm.py index 8cc2bad..b3352d0 100644 --- a/unit_tests/test_cepch_iscsi_charm.py +++ b/unit_tests/test_ceph_iscsi_charm.py @@ -109,14 +109,16 @@ class TestCephISCSIGatewayCharmBase(CharmTestCase): def add_cluster_relation(self): rel_id = self.harness.add_relation('cluster', 'ceph-iscsi') self.harness.add_relation_unit( + rel_id, + 'ceph-iscsi/1') + self.harness.update_relation_data( rel_id, 'ceph-iscsi/1', { 'ingress-address': '10.0.0.2', 'gateway_ready': 'True', 'gateway_fqdn': 'ceph-iscsi-1.example' - } - ) + }) return rel_id @patch('socket.getfqdn') @@ -165,13 +167,23 @@ class TestCephISCSIGatewayCharmBase(CharmTestCase): @patch.object(charm.secrets, 'choice') def test_on_has_peers(self, _choice): + rel_id = self.harness.add_relation('cluster', 'ceph-iscsi') _choice.return_value = 'r' - self.add_cluster_relation() self.harness.begin() + self.harness.add_relation_unit( + rel_id, + 'ceph-iscsi/1') self.assertIsNone( self.harness.charm.peers.admin_password) self.harness.set_leader() - self.harness.charm.peers.on.has_peers.emit() + self.harness.update_relation_data( + rel_id, + 'ceph-iscsi/1', + { + 'ingress-address': '10.0.0.2', + 'gateway_ready': 'True', + 'gateway_fqdn': 'ceph-iscsi-1.example' + }) self.assertEqual( self.harness.charm.peers.admin_password, 'rrrrrrrr') @@ -204,10 +216,12 @@ class TestCephISCSIGatewayCharmBase(CharmTestCase): key_values={'rbd-metadata-pool': 'iscsi-pool'}) self.harness.begin() self.harness.add_relation_unit( + rel_id, + 'ceph-mon/0') + self.harness.update_relation_data( rel_id, 'ceph-mon/0', - {'ingress-address': '10.0.0.3'}, - ) + {'ingress-address': '10.0.0.3'}) rel_data = self.harness.get_relation_data(rel_id, 'ceph-iscsi/0') req_osd_settings = json.loads(rel_data['osd-settings']) self.assertEqual( @@ -263,10 +277,12 @@ class TestCephISCSIGatewayCharmBase(CharmTestCase): rel_id = self.harness.add_relation('certificates', 'vault') self.harness.begin() self.harness.add_relation_unit( + rel_id, + 'vault/0') + self.harness.update_relation_data( rel_id, 'vault/0', - {'ingress-address': '10.0.0.3'}, - ) + {'ingress-address': '10.0.0.3'}) rel_data = self.harness.get_relation_data(rel_id, 'ceph-iscsi/0') self.assertEqual( rel_data['application_cert_requests'], @@ -281,9 +297,12 @@ class TestCephISCSIGatewayCharmBase(CharmTestCase): self.harness.begin() with patch('builtins.open', unittest.mock.mock_open()) as _open: self.harness.add_relation_unit( + rel_id, + 'vault/0') + self.harness.update_relation_data( rel_id, 'vault/0', - remote_unit_data={ + { 'ceph-iscsi_0.processed_application_requests': '{"app_data": {"cert": "appcert", "key": "appkey"}}', 'ca': 'ca'}) diff --git a/unit_tests/test_interface_ceph_iscsi_peer.py b/unit_tests/test_interface_ceph_iscsi_peer.py index 12f2770..f57b8b4 100644 --- a/unit_tests/test_interface_ceph_iscsi_peer.py +++ b/unit_tests/test_interface_ceph_iscsi_peer.py @@ -55,14 +55,16 @@ class TestCephISCSIGatewayPeers(unittest.TestCase): receiver) relation_id = self.harness.add_relation('cluster', 'ceph-iscsi') self.harness.add_relation_unit( + relation_id, + 'ceph-iscsi/1') + self.harness.update_relation_data( relation_id, 'ceph-iscsi/1', { 'ingress-address': '192.0.2.2', 'gateway_ready': 'True', 'gateway_fqdn': 'ceph-iscsi-1.example' - } - ) + }) self.assertEqual(len(receiver.observed_events), 1) self.assertIsInstance(receiver.observed_events[0], ReadyPeersEvent) @@ -106,28 +108,34 @@ class TestCephISCSIGatewayPeers(unittest.TestCase): relation_id = self.harness.add_relation('cluster', 'ceph-iscsi') self.harness.add_relation_unit( + relation_id, + 'ceph-iscsi/1') + self.harness.update_relation_data( relation_id, 'ceph-iscsi/1', { 'ingress-address': '192.0.2.2', 'gateway_ready': 'True', 'gateway_fqdn': 'ceph-iscsi-1.example' - } - ) + }) self.harness.add_relation_unit( + relation_id, + 'ceph-iscsi/2') + self.harness.update_relation_data( relation_id, 'ceph-iscsi/2', { 'ingress-address': '192.0.2.3', 'gateway_ready': 'True', 'gateway_fqdn': 'ceph-iscsi-2.example', - } - ) + }) self.harness.add_relation_unit( + relation_id, + 'ceph-iscsi/3') + self.harness.update_relation_data( relation_id, 'ceph-iscsi/3', - {'ingress-address': '192.0.2.4'} - ) + {'ingress-address': '192.0.2.4'}) self.peers.ready_peer_details @@ -143,23 +151,27 @@ class TestCephISCSIGatewayPeers(unittest.TestCase): relation_id = self.harness.add_relation('cluster', 'ceph-iscsi') self.harness.add_relation_unit( + relation_id, + 'ceph-iscsi/1') + self.harness.update_relation_data( relation_id, 'ceph-iscsi/1', { 'ingress-address': '192.0.2.2', 'gateway_ready': 'True', 'gateway_fqdn': 'ceph-iscsi-1.example' - } - ) + }) self.harness.add_relation_unit( + relation_id, + 'ceph-iscsi/2') + self.harness.update_relation_data( relation_id, 'ceph-iscsi/2', { 'ingress-address': '192.0.2.3', 'gateway_ready': 'True', 'gateway_fqdn': 'ceph-iscsi-2.example', - } - ) + }) self.assertEqual(['192.0.2.1', '192.0.2.2', '192.0.2.3'], self.peers.peer_addresses)