From 5877315c7fd20f603a35d1ff79a3b2c1407a54fc Mon Sep 17 00:00:00 2001 From: Georgy Kibardin Date: Mon, 26 Sep 2016 17:10:53 +0300 Subject: [PATCH] Configure mcollective identity in startup scripts As a part of handing over control over mcollective from nailgun agent to startup scripts lets get rid of of nodiscover file flag and perform mcollective configuration and start Change-Id: Ia2f984570b38642b1090f6483ed3fa78958550c5 Partial-Bug: #1585671 --- cloud-init-templates/cloud_config_ubuntu.jinja2 | 1 - contrib/fuel_bootstrap/files/xenial/etc/rc.local | 3 --- .../files/xenial/usr/bin/fix-configs-on-startup | 8 ++++++-- fuel_agent/tests/test_build_utils.py | 11 ++++++----- fuel_agent/utils/build.py | 8 +++++--- 5 files changed, 17 insertions(+), 14 deletions(-) diff --git a/cloud-init-templates/cloud_config_ubuntu.jinja2 b/cloud-init-templates/cloud_config_ubuntu.jinja2 index 403583f0..c9d732e5 100644 --- a/cloud-init-templates/cloud_config_ubuntu.jinja2 +++ b/cloud-init-templates/cloud_config_ubuntu.jinja2 @@ -131,7 +131,6 @@ runcmd: - fi {% else %} - if [ -x /bin/systemctl ]; then - - /bin/systemctl unmask mcollective - /bin/systemctl enable mcollective # TODO(dteselkin) rework start sequence when bug # https://bugs.launchpad.net/fuel/+bug/1543063 is fixed diff --git a/contrib/fuel_bootstrap/files/xenial/etc/rc.local b/contrib/fuel_bootstrap/files/xenial/etc/rc.local index 73a2922e..9712ba74 100755 --- a/contrib/fuel_bootstrap/files/xenial/etc/rc.local +++ b/contrib/fuel_bootstrap/files/xenial/etc/rc.local @@ -2,6 +2,3 @@ # Perform fuel bootstrap configuration /usr/bin/fix-configs-on-startup || /bin/true - -# Unlocking nailgun-agent for discovering -/bin/rm -f /etc/nailgun-agent/nodiscover diff --git a/contrib/fuel_bootstrap/files/xenial/usr/bin/fix-configs-on-startup b/contrib/fuel_bootstrap/files/xenial/usr/bin/fix-configs-on-startup index e4e5bb72..216c7133 100755 --- a/contrib/fuel_bootstrap/files/xenial/usr/bin/fix-configs-on-startup +++ b/contrib/fuel_bootstrap/files/xenial/usr/bin/fix-configs-on-startup @@ -61,8 +61,12 @@ systemctl restart ntp # # Update mcollective config # +while true; do + sleep 5 + grep --line-regexp "[[:digit:]]\+" /etc/nailgun_uid && break +done sed -i "s/^plugin.rabbitmq.pool.1.host\b.*$/plugin.rabbitmq.pool.1.host = $masternode_ip/" /etc/mcollective/server.cfg sed -i "s/^plugin.rabbitmq.pool.1.user\b.*$/plugin.rabbitmq.pool.1.user = $mco_user/" /etc/mcollective/server.cfg sed -i "s/^plugin.rabbitmq.pool.1.password\b.*$/plugin.rabbitmq.pool.1.password= $mco_pass/" /etc/mcollective/server.cfg -systemctl unmask mcollective -systemctl start mcollective +echo "identity = $(head -n 1 /etc/nailgun_uid)" >> /etc/mcollective/server.cfg +service mcollective restart diff --git a/fuel_agent/tests/test_build_utils.py b/fuel_agent/tests/test_build_utils.py index 010fedbe..5d15e286 100644 --- a/fuel_agent/tests/test_build_utils.py +++ b/fuel_agent/tests/test_build_utils.py @@ -189,7 +189,7 @@ class BuildUtilsTestCase(unittest2.TestCase): 'cloud_config_modules': ['runcmd', 'write-files'] }, mock.ANY, encoding='utf-8', default_flow_style=False) - @mock.patch('fuel_agent.utils.build.os.symlink') + @mock.patch('fuel_agent.utils.build.os.unlink') @mock.patch('fuel_agent.utils.build.os.mkdir') @mock.patch('fuel_agent.utils.build.open', create=True, new_callable=mock.mock_open) @@ -201,7 +201,7 @@ class BuildUtilsTestCase(unittest2.TestCase): @mock.patch('fuel_agent.utils.build.yaml.safe_load') def test_do_post_inst(self, mock_yaml_load, mock_yaml_dump, mock_exec, mock_files, mock_clean, mock_path, - mock_open, mock_mkdir, mock_symlink): + mock_open, mock_mkdir, mock_unlink): mock_path.join.return_value = 'fake_path' mock_path.exists.return_value = True @@ -241,8 +241,9 @@ class BuildUtilsTestCase(unittest2.TestCase): mock.call('chroot', 'etc/shadow'), mock.call('chroot', 'etc/init.d/puppet'), mock.call('chroot', 'etc/init/mcollective.override'), - mock.call('chroot', 'etc/systemd/system'), - mock.call('chroot', 'etc/systemd/system/mcollective.service'), + mock.call('chroot', + 'etc/systemd/system' + '/multi-user.target.wants/mcollective.service'), mock.call('chroot', 'etc/cloud/cloud.cfg.d/'), mock.call('chroot', 'etc/cloud/cloud.cfg.d/99-disable-network-config.cfg'), @@ -250,7 +251,7 @@ class BuildUtilsTestCase(unittest2.TestCase): mock.call('/', bu.GRUB2_DMRAID_SETTINGS)] self.assertEqual(mock_path_join_expected_calls, mock_path.join.call_args_list) - mock_symlink.assert_called_once_with('/dev/null', 'fake_path') + mock_unlink.assert_called_once_with('fake_path') mock_yaml_dump.assert_called_with(mock.ANY, mock.ANY, encoding='utf-8', diff --git a/fuel_agent/utils/build.py b/fuel_agent/utils/build.py index 3ee05326..eb8cbd30 100644 --- a/fuel_agent/utils/build.py +++ b/fuel_agent/utils/build.py @@ -211,9 +211,11 @@ def do_post_inst(chroot, hashed_root_password, # to prevent confusing messages in its log (regarding connection errors). with open(os.path.join(chroot, 'etc/init/mcollective.override'), 'w') as f: f.write("manual\n") - if os.path.exists(os.path.join(chroot, 'etc/systemd/system')): - os.symlink('/dev/null', os.path.join(chroot, - 'etc/systemd/system/mcollective.service')) + service_link = os.path.join( + chroot, + 'etc/systemd/system/multi-user.target.wants/mcollective.service') + if os.path.exists(service_link): + os.unlink(service_link) cloud_cfg = os.path.join(chroot, 'etc/cloud/cloud.cfg.d/') utils.makedirs_if_not_exists(os.path.dirname(cloud_cfg)) with open(os.path.join(