Add re-initialization of the master node

PuppetApplyHost is renamed to PuppetApplyTasks to perform full
re-initialization of the master node by applying all puppet tasks.

Change-Id: I52a02fd4e72c1fd6367f91f088beacc0e9715969
This commit is contained in:
Ilya Kharin 2016-04-20 11:08:08 +03:00
parent 3ca668f9df
commit ccbe6604ba
6 changed files with 24 additions and 25 deletions

View File

@ -45,7 +45,7 @@ ARCHIVATORS = [
logs.LogsArchivator,
version.VersionArchivator,
nailgun_plugins.NailgunPluginsArchivator,
# puppet.PuppetApplyHost,
puppet.PuppetApplyTasks,
]
REPO_ARCHIVATORS = [

View File

@ -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()

View File

@ -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']

View File

@ -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

View File

@ -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)

View File

@ -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