Control access to crm in cases when the unit is yet not

having any corosync resource available.

Closes-bug: #1864804
Change-Id: I6eb3b9a816a93c4c7894e17935b1e7c8604592c5
Signed-off-by: José Pekkarinen <jose.pekkarinen@canonical.com>
This commit is contained in:
José Pekkarinen 2020-02-12 12:08:18 +02:00
parent 3fad300b7f
commit 4baae7a0f2
No known key found for this signature in database
GPG Key ID: C5C0F6B04C2B7720
2 changed files with 24 additions and 6 deletions

View File

@ -111,9 +111,11 @@ class HAClusterRequires(RelationBase):
"""
if mcastport is None:
mcastport = 4440
resources = self.get_local('resources')
resources_dict = self.get_local('resources')
self.bind_on(iface=iface, mcastport=mcastport)
self.manage_resources(resources)
if resources_dict:
resources = relations.hacluster.common.CRM(**resources_dict)
self.manage_resources(resources)
def delete_resource(self, resource_name):
resource_dict = self.get_local('resources')

View File

@ -217,20 +217,36 @@ class TestHAClusterRequires(unittest.TestCase):
self.assertFalse(self.set_remote.called)
def test_bind_resources(self):
self.patch_kr('get_local', 'resources')
expected = {
'colocations': {}, 'groups': {},
'clones': {}, 'orders': {},
'resource_params': {}, 'delete_resources': [],
'init_services': [], 'locations': {},
'some': 'resources', 'systemd_services': [],
'resources': {}, 'ms': {}
}
self.patch_kr('get_local', expected)
self.patch_kr('bind_on')
self.patch_kr('manage_resources')
self.cr.bind_resources()
self.bind_on.assert_called_once_with(iface=None, mcastport=4440)
self.manage_resources.assert_called_once_with('resources')
self.manage_resources.assert_called_once_with(expected)
def test_bind_resources_no_defaults(self):
self.patch_kr('get_local', 'resources')
expected = {
'colocations': {}, 'groups': {},
'clones': {}, 'orders': {},
'resource_params': {}, 'delete_resources': [],
'init_services': [], 'locations': {},
'some': 'resources', 'systemd_services': [],
'resources': {}, 'ms': {}
}
self.patch_kr('get_local', expected)
self.patch_kr('bind_on')
self.patch_kr('manage_resources')
self.cr.bind_resources(iface='tr34', mcastport=111)
self.bind_on.assert_called_once_with(iface='tr34', mcastport=111)
self.manage_resources.assert_called_once_with('resources')
self.manage_resources.assert_called_once_with(expected)
def test_delete_resource(self):
existing_data = {