Move deployed dir from /var/run to /var/lib
Deployments should not be run again when a server is rebooted because heat will likely not be listening for the deployment signals. This change moves the deployed directory from /var/run/heat-config/deployed to /var/lib/heat-config/deployed so that deployed state is persisted across reboots. There is migration logic to move the existing files from the old to the new location, this will only be run on the first run of 55-heat-config after its package is updated. Change-Id: I3d305a4ac5b68c29037760682d37e5b9a530828e Closes-Bug: #1513220
This commit is contained in:
parent
f939f38514
commit
c002854fa4
@ -15,6 +15,7 @@
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
@ -25,7 +26,9 @@ HOOKS_DIR = os.environ.get('HEAT_CONFIG_HOOKS',
|
||||
CONF_FILE = os.environ.get('HEAT_SHELL_CONFIG',
|
||||
'/var/run/heat-config/heat-config')
|
||||
DEPLOYED_DIR = os.environ.get('HEAT_CONFIG_DEPLOYED',
|
||||
'/var/run/heat-config/deployed')
|
||||
'/var/lib/heat-config/deployed')
|
||||
OLD_DEPLOYED_DIR = os.environ.get('HEAT_CONFIG_DEPLOYED_OLD',
|
||||
'/var/run/heat-config/deployed')
|
||||
HEAT_CONFIG_NOTIFY = os.environ.get('HEAT_CONFIG_NOTIFY',
|
||||
'heat-config-notify')
|
||||
|
||||
@ -44,7 +47,12 @@ def main(argv=sys.argv):
|
||||
return 1
|
||||
|
||||
if not os.path.isdir(DEPLOYED_DIR):
|
||||
os.makedirs(DEPLOYED_DIR, 0o700)
|
||||
if DEPLOYED_DIR != OLD_DEPLOYED_DIR and os.path.isdir(OLD_DEPLOYED_DIR):
|
||||
log.debug('Migrating deployed state from %s to %s' %
|
||||
(OLD_DEPLOYED_DIR, DEPLOYED_DIR))
|
||||
shutil.move(OLD_DEPLOYED_DIR, DEPLOYED_DIR)
|
||||
else:
|
||||
os.makedirs(DEPLOYED_DIR, 0o700)
|
||||
|
||||
try:
|
||||
configs = json.load(open(CONF_FILE))
|
||||
|
@ -14,6 +14,7 @@
|
||||
import copy
|
||||
import json
|
||||
import os
|
||||
import shutil
|
||||
import tempfile
|
||||
|
||||
import fixtures
|
||||
@ -123,6 +124,7 @@ class HeatConfigTest(common.RunScriptTest):
|
||||
f.write(fake_hook)
|
||||
f.flush()
|
||||
os.chmod(hook_name, 0o755)
|
||||
self.env = os.environ.copy()
|
||||
|
||||
def write_config_file(self, data):
|
||||
config_file = tempfile.NamedTemporaryFile()
|
||||
@ -133,14 +135,13 @@ class HeatConfigTest(common.RunScriptTest):
|
||||
def run_heat_config(self, data):
|
||||
with self.write_config_file(data) as config_file:
|
||||
|
||||
env = os.environ.copy()
|
||||
env.update({
|
||||
self.env.update({
|
||||
'HEAT_CONFIG_HOOKS': self.hooks_dir.join(),
|
||||
'HEAT_CONFIG_DEPLOYED': self.deployed_dir.join(),
|
||||
'HEAT_SHELL_CONFIG': config_file.name
|
||||
})
|
||||
returncode, stdout, stderr = self.run_cmd(
|
||||
[self.heat_config_path], env)
|
||||
[self.heat_config_path], self.env)
|
||||
|
||||
self.assertEqual(0, returncode, stderr)
|
||||
|
||||
@ -219,3 +220,22 @@ class HeatConfigTest(common.RunScriptTest):
|
||||
stdin_path, matchers.Not(matchers.FileExists()))
|
||||
self.assertThat(
|
||||
stdout_path, matchers.Not(matchers.FileExists()))
|
||||
|
||||
# run again with a different deployed_dir
|
||||
old_deployed_dir = self.deployed_dir
|
||||
self.env['HEAT_CONFIG_DEPLOYED_OLD'] = old_deployed_dir.join()
|
||||
self.deployed_dir = self.useFixture(fixtures.TempDir())
|
||||
# make sure the new deployed_dir doesn't exist to trigger the migration
|
||||
shutil.rmtree(self.deployed_dir.join())
|
||||
|
||||
self.run_heat_config(data)
|
||||
for config in self.data:
|
||||
hook = config['group']
|
||||
if hook == 'no-such-hook':
|
||||
continue
|
||||
deployed_file = self.deployed_dir.join('%s.json' % config['id'])
|
||||
old_deployed_file = old_deployed_dir.join('%s.json' % config['id'])
|
||||
self.assertEqual(config,
|
||||
self.json_from_file(deployed_file))
|
||||
self.assertThat(
|
||||
old_deployed_file, matchers.Not(matchers.FileExists()))
|
||||
|
Loading…
x
Reference in New Issue
Block a user