Specify the IP address for cluster communication

Specify the IP address that cluster communication should happen on,
this is derived from the network space being used for the
pacemaker-remote relation.

Depends-On: I92b3f2644c7bee4e55463ffaae2769c33458dd16
Change-Id: I5aa6993ec702f97403d1a659e09a3fb2f5af4202
Closes-Bug: #1824514
This commit is contained in:
Liam Young 2019-04-12 10:41:29 +00:00
parent a443c78cc0
commit fbb67ae2f8
6 changed files with 25 additions and 16 deletions

4
.gitreview Normal file
View File

@ -0,0 +1,4 @@
[gerrit]
host=review.openstack.org
port=29418
project=openstack/charm-pacemaker-remote.git

4
.zuul.yaml Normal file
View File

@ -0,0 +1,4 @@
- project:
templates:
- python35-charm-jobs
- openstack-cover-jobs

View File

@ -1,4 +1,3 @@
# Requirements to build the charm
charm-tools
simplejson
flake8

View File

@ -13,6 +13,7 @@
# limitations under the License.
import shutil
import socket
import os
import charms.reactive as reactive
@ -20,8 +21,6 @@ import charmhelpers.fetch as fetch
import charmhelpers.core.hookenv as hookenv
import charmhelpers.core.host as ch_host
import charmhelpers.contrib.network.ip
COROSYNC_DIR = '/etc/corosync'
SERVICES = ['pacemaker_remote', 'pcsd']
PACKAGES = ['pacemaker-remote', 'pcs', 'resource-agents', 'corosync']
@ -65,8 +64,8 @@ def install():
@reactive.when('endpoint.pacemaker-remote.joined')
def publish_stonith_info():
"""Provide remote hacluster with info for including remote in cluster"""
remote_hostname = charmhelpers.contrib.network.ip.get_hostname(
hookenv.unit_get('private-address'))
remote_ip = hookenv.network_get_primary_address('pacemaker-remote')
remote_hostname = socket.gethostname()
if hookenv.config('enable-stonith'):
stonith_hostname = remote_hostname
else:
@ -75,6 +74,7 @@ def publish_stonith_info():
'endpoint.pacemaker-remote.joined')
remote.publish_info(
remote_hostname=remote_hostname,
remote_ip=remote_ip,
enable_resources=hookenv.config('enable-resources'),
stonith_hostname=stonith_hostname)

View File

@ -3,7 +3,7 @@
# within individual charm repos.
[tox]
skipsdist = True
envlist = pep8,py3
envlist = pep8,py3.5
[testenv]
setenv = VIRTUAL_ENV={envdir}
@ -31,8 +31,8 @@ basepython = python2.7
whitelist_externals = true
commands = true
[testenv:py3]
basepython = python3
[testenv:py3.5]
basepython = python3.5
deps = -r{toxinidir}/test-requirements.txt
commands = stestr run {posargs}

View File

@ -142,13 +142,13 @@ class TestPAcemakerRemoteHandlers(unittest.TestCase):
self.wipe_corosync_state.assert_called_once_with()
def test_publish_stonith_info(self):
self.patch(handlers.charmhelpers.contrib.network.ip, 'get_hostname')
self.patch(handlers.socket, 'gethostname')
self.patch(handlers.hookenv, 'network_get_primary_address')
self.patch(handlers.hookenv, 'status_set')
self.patch(handlers.hookenv, 'config')
self.patch(handlers.hookenv, 'unit_get')
self.patch(handlers.reactive, 'endpoint_from_flag')
self.unit_get.return_value = '10.0.0.10'
self.get_hostname.return_value = 'myhost.maas'
self.gethostname.return_value = 'myhost.maas'
self.network_get_primary_address.return_value = '10.0.0.10'
cfg = {
'enable-stonith': True,
'enable-resources': True}
@ -158,17 +158,18 @@ class TestPAcemakerRemoteHandlers(unittest.TestCase):
handlers.publish_stonith_info()
endpoint_mock.publish_info.assert_called_once_with(
enable_resources=True,
remote_ip='10.0.0.10',
remote_hostname='myhost.maas',
stonith_hostname='myhost.maas')
def test_publish_stonith_info_all_off(self):
self.patch(handlers.charmhelpers.contrib.network.ip, 'get_hostname')
self.patch(handlers.socket, 'gethostname')
self.patch(handlers.hookenv, 'network_get_primary_address')
self.patch(handlers.hookenv, 'status_set')
self.patch(handlers.hookenv, 'config')
self.patch(handlers.hookenv, 'unit_get')
self.patch(handlers.reactive, 'endpoint_from_flag')
self.unit_get.return_value = '10.0.0.10'
self.get_hostname.return_value = 'myhost.maas'
self.gethostname.return_value = 'myhost.maas'
self.network_get_primary_address.return_value = '10.0.0.10'
cfg = {
'enable-stonith': False,
'enable-resources': False}
@ -178,6 +179,7 @@ class TestPAcemakerRemoteHandlers(unittest.TestCase):
handlers.publish_stonith_info()
endpoint_mock.publish_info.assert_called_once_with(
enable_resources=False,
remote_ip='10.0.0.10',
remote_hostname='myhost.maas',
stonith_hostname=None)