def test_rings_consumer_changed(self, relation_get, fetch_swift_rings_and_builders, broadcast_rings_available, get_swift_hash): rel_data = {'rings_url': 'http://some-url:999', 'swift_hash': 'swhash'} relation_get.side_effect = lambda x: rel_data.get(x) get_swift_hash.return_value = 'swhash' swift_hooks.rings_consumer_changed() fetch_swift_rings_and_builders.assert_called_once_with( 'http://some-url:999') broadcast_rings_available.assert_called_once_with()
def test_rings_consumer_changed_empty_str(self, relation_get, fetch_swift_rings_and_builders, broadcast_rings_available, get_swift_hash, log): rel_data = {'rings_url': '', 'swift_hash': 'swhash'} relation_get.side_effect = lambda x: rel_data.get(x) swift_hooks.rings_consumer_changed() self.assertFalse(fetch_swift_rings_and_builders.called) self.assertFalse(broadcast_rings_available.called) log.assert_called_once_with( 'rings_consumer_relation_changed: Peer not ready?')
def test_rings_consumer_changed_hash_miss(self, relation_get, fetch_swift_rings_and_builders, broadcast_rings_available, get_swift_hash, status_set): rel_data = {'rings_url': 'http://some-url:999', 'swift_hash': 'swhash'} relation_get.side_effect = lambda x: rel_data.get(x) get_swift_hash.return_value = 'mismatch' with self.assertRaises(lib.swift_utils.SwiftProxyCharmException): swift_hooks.rings_consumer_changed() self.assertFalse(fetch_swift_rings_and_builders.called) self.assertFalse(broadcast_rings_available.called) status_set.assert_called_once_with( 'blocked', 'Swift hash has to be unique in multi-region setup')
def test_rings_consumer_changed_fetch_fail(self, relation_get, fetch_swift_rings_and_builders, broadcast_rings_available, get_swift_hash, log): rel_data = {'rings_url': 'http://some-url:999', 'swift_hash': 'swhash'} relation_get.side_effect = lambda x: rel_data.get(x) get_swift_hash.return_value = 'swhash' def _fetch(url): raise subprocess.CalledProcessError('cmd', 1) fetch_swift_rings_and_builders.side_effect = _fetch swift_hooks.rings_consumer_changed() fetch_swift_rings_and_builders.assert_called_once_with( 'http://some-url:999') log.assert_called_once_with( ('Failed to sync rings from http://some-url:999 - no longer ' 'available from that unit?'), level='WARNING') broadcast_rings_available.assert_called_once_with()