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.
This commit is contained in:
Liam Young 2020-04-29 05:43:29 +00:00
parent 39db5bfb9e
commit a2455bbe5a
3 changed files with 53 additions and 22 deletions

@ -1 +1 @@
Subproject commit 04cb347938b87776638fdeaa48f6c5c0f115346d
Subproject commit 60c43f81e36139ab4044c185247eb27fe389bce6

View File

@ -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'})

View File

@ -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)