Skip to content

Commit

Permalink
Ensure node names are FQDNs when configuring pacemaker (#74)
Browse files Browse the repository at this point in the history
* Ensure node names are FQDNs when configuring pacemaker

This can happen if corosync ring0 was configured via IP instead of FQDN

Signed-off-by: Nathaniel Clark <[email protected]>

* Fixup test cases

Signed-off-by: Nathaniel Clark <[email protected]>

* Fix typo

Signed-off-by: Nathaniel Clark <[email protected]>

* Update VERSION to 4.1.4-2

Ensure this is used over base

Signed-off-by: Nathaniel Clark <[email protected]>

* Pass optional fqdn to configure_corosync2_stage_1

If FQDN is passed, set hostname to this.

Signed-off-by: Nathaniel Clark <[email protected]>

* Add Tests for optional set-hostname in corosync2_stage1

Signed-off-by: Nathaniel Clark <[email protected]>

* Don't need to import socket anymore

* Version Bump to 4.1.5

Signed-off-by: Nathaniel Clark <[email protected]>

* fix copr makefile

Support docker build in /build or in . for normal copr builds

Signed-off-by: Nathaniel Clark <[email protected]>

* Catch no nodes configured in pacemaker when is_dc() called

Signed-off-by: Nathaniel Clark <[email protected]>

* Also catch StopIteration

Signed-off-by: Nathaniel Clark <[email protected]>
  • Loading branch information
utopiabound authored and jgrund committed Apr 9, 2019
1 parent b39ccff commit 3df1d2f
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 19 deletions.
24 changes: 14 additions & 10 deletions .copr/Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
BUILDROOT:=$(shell [ -d "/build" ] && echo "/build" || echo ".")
TMPDIR:=$(shell mktemp -d)

srpm:
rm -rf /tmp/_topdir
rm -rf /tmp/scratch
mkdir -p /tmp/_topdir/SOURCES
mkdir -p /tmp/scratch
rm -rf /build/_topdir
cp -r /build/* /tmp/scratch
cd /tmp/scratch; \
python setup.py sdist -d /tmp/_topdir/SOURCES/
python --version || dnf -y install python2-setuptools
mkdir -p ${TMPDIR}/_topdir/SOURCES
mkdir -p ${TMPDIR}/scratch
rm -rf ${BUILDROOT}/_topdir
cp -r ${BUILDROOT}/* ${TMPDIR}/scratch
cd ${TMPDIR}/scratch; \
python setup.py sdist -d ${TMPDIR}/_topdir/SOURCES/

rpmbuild -bs -D "_topdir ${TMPDIR}/_topdir" ${TMPDIR}/scratch/python-iml-agent.spec
cp -r ${TMPDIR}/_topdir/SRPMS/* $(outdir)
rm -rf ${TMPDIR}

rpmbuild -bs -D "_topdir /tmp/_topdir" /tmp/scratch/python-iml-agent.spec
cp -r /tmp/_topdir/SRPMS/* $(outdir)
1 change: 1 addition & 0 deletions chroma_agent/action_plugins/agent_updates.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def configure_repo(filename, file_contents):
full_filename = os.path.join(REPO_PATH, filename)
temp_full_filename = full_filename + ".tmp"

# this format needs to match create_repo() in manager agent-bootstrap-script
file_contents = file_contents.format(
crypto.AUTHORITY_FILE, crypto.PRIVATE_KEY_FILE, crypto.CERTIFICATE_FILE
)
Expand Down
8 changes: 7 additions & 1 deletion chroma_agent/action_plugins/manage_corosync2.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,20 @@ def stop_corosync2():
return agent_ok_or_error(corosync_service.stop())


def configure_corosync2_stage_1(mcast_port, pcs_password):
def configure_corosync2_stage_1(mcast_port, pcs_password, fqdn=None):
# need to use user "hacluster" which is created on install of "pcs" package,
# WARNING: clear text password
set_password_command = [
"bash",
"-c",
"echo %s | passwd --stdin %s" % (pcs_password, PCS_USER),
]
if fqdn is not None:
error = AgentShell.run_canned_error_message(
["hostnamectl", "set-hostname", fqdn]
)
if error:
return agent_error(error)

return agent_ok_or_error(
AgentShell.run_canned_error_message(set_password_command)
Expand Down
5 changes: 4 additions & 1 deletion chroma_agent/lib/pacemaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,10 @@ def get_node(self, node_name):

@property
def is_dc(self):
return self.dc == self.get_node(socket.gethostname()).name
try:
return self.dc == self.get_node(socket.gethostname()).name
except (IndexError, StopIteration) as _:
return False

@property
def configured(self):
Expand Down
2 changes: 1 addition & 1 deletion chroma_agent/version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
PACKAGE_VERSION = "4.1.4"
PACKAGE_VERSION = "4.1.5"
VERSION = "{}-1".format(PACKAGE_VERSION)
4 changes: 2 additions & 2 deletions python-iml-agent.spec
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ BuildRequires: systemd
%define unit_name chroma-agent.service

%global pypi_name iml-agent
%{?!version: %global version 4.1.4}
%{?!version: %global version 4.1.5}
%{?!python_sitelib: %global python_sitelib %(%{__python} -c "from distutils.sysconfig import get_python_lib; import sys; sys.stdout.write(get_python_lib())")}

%{?dist_version: %global source https://github.com/whamcloud/%{pypi_name}/archive/%{dist_version}.tar.gz}
Expand All @@ -13,7 +13,7 @@ BuildRequires: systemd
%{?!dist_version: %global archive_version %{version}}

Name: python-%{pypi_name}
Version: 4.1.4
Version: 4.1.5
# Release Start
Release: 1%{?dist}
# Release End
Expand Down
29 changes: 25 additions & 4 deletions tests/test_corosync_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,8 @@ def test_manual_ring1_config(self):
self.mock_add_port.assert_has_calls([mock.call(new_mcast_port, "udp")])
self.mock_corosync_service.enable.assert_called_once_with()

def test_manual_ring1_config_corosync2(self):
def _test_manual_ring1_config_corosync2(self, fqdn=False):
import socket
from chroma_agent.action_plugins.manage_corosync2 import (
configure_corosync2_stage_1,
)
Expand Down Expand Up @@ -302,6 +303,13 @@ def test_manual_ring1_config_corosync2(self):
ring1_name,
)
),
)
if fqdn:
self.add_commands(
CommandCaptureCommand(("hostnamectl", "set-hostname", new_node_fqdn))
)

self.add_commands(
CommandCaptureCommand(
("bash", "-c", "echo bondJAMESbond | passwd --stdin hacluster")
),
Expand Down Expand Up @@ -366,9 +374,16 @@ def test_manual_ring1_config_corosync2(self):
)

# ...then corosync / pcsd
self.assertEqual(
agent_result_ok, configure_corosync2_stage_1(mcast_port, pcs_password)
)
if fqdn:
self.assertEqual(
agent_result_ok,
configure_corosync2_stage_1(mcast_port, pcs_password, new_node_fqdn),
)
else:
self.assertEqual(
agent_result_ok, configure_corosync2_stage_1(mcast_port, pcs_password)
)

self.assertEqual(
agent_result_ok,
configure_corosync2_stage_2(
Expand Down Expand Up @@ -415,6 +430,12 @@ def test_manual_ring1_config_corosync2(self):

self.assertRanAllCommandsInOrder()

def test_manual_ring1_config_corosync2(self):
self._test_manual_ring1_config_corosync2(False)

def test_manual_ring1_config_corosync2_fqdn(self):
self._test_manual_ring1_config_corosync2(True)

def test_unconfigure_corosync2(self):
from chroma_agent.action_plugins.manage_corosync2 import unconfigure_corosync2
from chroma_agent.action_plugins.manage_corosync2 import PCS_TCP_PORT
Expand Down

0 comments on commit 3df1d2f

Please sign in to comment.