diff --git a/octane/handlers/backup_restore/__init__.py b/octane/handlers/backup_restore/__init__.py index 68191dfa..5be15c05 100644 --- a/octane/handlers/backup_restore/__init__.py +++ b/octane/handlers/backup_restore/__init__.py @@ -45,7 +45,7 @@ ARCHIVATORS = [ logs.LogsArchivator, version.VersionArchivator, nailgun_plugins.NailgunPluginsArchivator, - # puppet.PuppetApplyHost, + puppet.PuppetApplyTasks, ] REPO_ARCHIVATORS = [ diff --git a/octane/handlers/backup_restore/puppet.py b/octane/handlers/backup_restore/puppet.py index 9815cba1..c3117191 100644 --- a/octane/handlers/backup_restore/puppet.py +++ b/octane/handlers/backup_restore/puppet.py @@ -20,11 +20,11 @@ class PuppetArchivator(base.DirsArchivator): tag = "puppet" -class PuppetApplyHost(base.Base): +class PuppetApplyTasks(base.Base): def backup(self): pass def restore(self): with auth.set_astute_password(self.context): - puppet.apply_host() + puppet.apply_all_tasks() diff --git a/octane/magic_consts.py b/octane/magic_consts.py index 4ab7b51a..3ed8bbf4 100644 --- a/octane/magic_consts.py +++ b/octane/magic_consts.py @@ -24,6 +24,9 @@ NAILGUN_ARCHIVATOR_PATCHES = ( ) BOOTSTRAP_INITRAMFS = "/var/www/nailgun/bootstrap/initramfs.img" +PUPPET_TASKS_DIR = os.path.join(PUPPET_DIR, 'fuel/examples') +PUPPET_APPLY_TASKS_SCRIPT = os.path.join(PUPPET_TASKS_DIR, 'deploy.sh') + SSH_KEYS = ['/root/.ssh/id_rsa', '/root/.ssh/bootstrap.rsa'] OS_SERVICES = ["nova", "keystone", "heat", "neutron", "cinder", "glance"] BRIDGES = ['br-ex', 'br-mgmt'] diff --git a/octane/tests/test_archivators_restore.py b/octane/tests/test_archivators_restore.py index ddf1507a..0bb8b197 100644 --- a/octane/tests/test_archivators_restore.py +++ b/octane/tests/test_archivators_restore.py @@ -525,14 +525,14 @@ def test_release_restore(mocker, mock_open, content, existing_releases, calls): mock_open.assert_called_once_with(magic_consts.OPENSTACK_FIXTURES) -def test_post_restore_puppet_apply_host(mocker): +def test_post_restore_puppet_apply_tasks(mocker): context = backup_restore.NailgunCredentialsContext( user="admin", password="user_pswd") mock_set_astute_password = mocker.patch( "octane.util.auth.set_astute_password") - mock_apply = mocker.patch("octane.util.puppet.apply_host") + mock_apply = mocker.patch("octane.util.puppet.apply_all_tasks") - archivator = puppet.PuppetApplyHost(None, context) + archivator = puppet.PuppetApplyTasks(None, context) archivator.restore() assert mock_apply.called diff --git a/octane/tests/test_util_puppet.py b/octane/tests/test_util_puppet.py index bee06b25..e83a9f53 100644 --- a/octane/tests/test_util_puppet.py +++ b/octane/tests/test_util_puppet.py @@ -34,13 +34,17 @@ def test_apply_task(mock_subprocess, name, returncode, is_error): mock_subprocess.assert_called_once_with(cmd) -def test_apply_host(mock_subprocess): - puppet_util.apply_host() - assert mock_subprocess.call_count == 1 +def test_apply_all_tasks(mock_subprocess): + puppet_util.apply_all_tasks() + expected_filename = "/etc/puppet/modules/fuel/examples/deploy.sh" + mock_subprocess.assert_called_once_with([expected_filename]) -def test_apply_host_error(mock_subprocess): +def test_apply_all_tasks_error(mocker, mock_subprocess): + mock_log = mocker.patch("octane.util.puppet.LOG") exc = subprocess.CalledProcessError(1, 'TEST_PROCESS') mock_subprocess.side_effect = exc - with pytest.raises(type(exc)): - puppet_util.apply_host() + with pytest.raises(subprocess.CalledProcessError): + puppet_util.apply_all_tasks() + mock_log.error.assert_called_once_with( + "Cannot apply Puppet state on host: %s", exc) diff --git a/octane/util/puppet.py b/octane/util/puppet.py index 6f6ce963..bd4f2b2d 100644 --- a/octane/util/puppet.py +++ b/octane/util/puppet.py @@ -21,10 +21,8 @@ LOG = logging.getLogger(__name__) def apply_task(task): - path = os.path.join(magic_consts.PUPPET_DIR, - 'fuel', - 'examples', - '{0}.pp'.format(task)) + filename = '{0}.pp'.format(task) + path = os.path.join(magic_consts.PUPPET_TASKS_DIR, filename) cmd = ['puppet', 'apply', '-d', '-v', "--color", "false", '--detailed-exitcodes', path] try: @@ -44,18 +42,12 @@ def apply_task(task): raise -def apply_host(): - cmd = ['puppet', 'apply', '-d', '-v'] - path = os.path.join(magic_consts.PUPPET_DIR, - 'nailgun', - 'examples', - 'host-only.pp') - cmd.append(path) +def apply_all_tasks(): try: - subprocess.call(cmd) + subprocess.call([magic_consts.PUPPET_APPLY_TASKS_SCRIPT]) except subprocess.CalledProcessError as exc: LOG.error("Cannot apply Puppet state on host: %s", - exc.message) + exc) raise