Merge "Split upgrade_tasks.yaml per step tasks."
This commit is contained in:
commit
3db41939a3
|
@ -205,3 +205,5 @@ DEPLOYMENT_STATUS_FILE = 'deployment_status.yaml'
|
||||||
MISTRAL_WORK_DIR = '/var/lib/mistral'
|
MISTRAL_WORK_DIR = '/var/lib/mistral'
|
||||||
|
|
||||||
EXCLUSIVE_NEUTRON_DRIVERS = ['ovn', 'openvswitch']
|
EXCLUSIVE_NEUTRON_DRIVERS = ['ovn', 'openvswitch']
|
||||||
|
|
||||||
|
UPGRADE_STEPS_MAX = 6
|
||||||
|
|
|
@ -128,34 +128,47 @@ class TestConfig(base.TestCase):
|
||||||
self.tmp_dir = self.useFixture(fixtures.TempDir()).path
|
self.tmp_dir = self.useFixture(fixtures.TempDir()).path
|
||||||
fake_role = [role for role in
|
fake_role = [role for role in
|
||||||
fakes.FAKE_STACK['outputs'][1]['output_value']]
|
fakes.FAKE_STACK['outputs'][1]['output_value']]
|
||||||
expected_tasks = {'FakeController': [{'name': 'Stop fake service',
|
expected_tasks = {'FakeController': {0: [],
|
||||||
'service': 'name=fake '
|
1: [{'name': 'Stop fake service',
|
||||||
'state=stopped',
|
'service': 'name=fake '
|
||||||
'when': 'step|int == 1'}],
|
'state=stopped',
|
||||||
'FakeCompute': [{'name': 'Stop fake service',
|
'when': 'step|int == 1'}],
|
||||||
'service':
|
2: [],
|
||||||
'name=fake state=stopped',
|
3: [],
|
||||||
'when': ['nova_api_enabled.rc == 0',
|
4: [],
|
||||||
'httpd_enabled.rc != 0',
|
5: []},
|
||||||
'step|int == 1']},
|
'FakeCompute': {0: [],
|
||||||
{'name': 'Stop nova-'
|
1: [{'name': 'Stop fake service',
|
||||||
'compute service',
|
'service': 'name=fake '
|
||||||
'service':
|
'state=stopped',
|
||||||
'name=openstack-nova-'
|
'when': ['nova_api_enabled.rc'
|
||||||
'compute state=stopped',
|
' == 0',
|
||||||
'when': [
|
'httpd_enabled.rc'
|
||||||
'nova_compute_enabled.rc == 0',
|
' != 0',
|
||||||
'step|int == 2', 'existing',
|
'step|int == 1']}],
|
||||||
'list']}]}
|
2: [{'name': 'Stop nova-compute '
|
||||||
|
'service',
|
||||||
|
'service': 'name=openstack-'
|
||||||
|
'nova-compute state=stopped',
|
||||||
|
'when': ['nova_compute_'
|
||||||
|
'enabled.rc == 0',
|
||||||
|
'step|int == 2',
|
||||||
|
'existing',
|
||||||
|
'list']}],
|
||||||
|
3: [],
|
||||||
|
4: [],
|
||||||
|
5: []}}
|
||||||
for role in fake_role:
|
for role in fake_role:
|
||||||
filedir = os.path.join(self.tmp_dir, role)
|
filedir = os.path.join(self.tmp_dir, role)
|
||||||
os.makedirs(filedir)
|
os.makedirs(filedir)
|
||||||
filepath = os.path.join(filedir, "upgrade_tasks_playbook.yaml")
|
for step in range(constants.UPGRADE_STEPS_MAX):
|
||||||
playbook_tasks = self.config._write_playbook_get_tasks(
|
filepath = os.path.join(filedir, "upgrade_tasks_step%s.yaml"
|
||||||
fakes.FAKE_STACK['outputs'][1]['output_value'][role]
|
% step)
|
||||||
['upgrade_tasks'], role, filepath)
|
playbook_tasks = self.config._write_tasks_per_step(
|
||||||
self.assertTrue(os.path.isfile(filepath))
|
fakes.FAKE_STACK['outputs'][1]['output_value'][role]
|
||||||
self.assertEqual(expected_tasks[role], playbook_tasks)
|
['upgrade_tasks'], role, filepath, step)
|
||||||
|
self.assertTrue(os.path.isfile(filepath))
|
||||||
|
self.assertEqual(expected_tasks[role][step], playbook_tasks)
|
||||||
|
|
||||||
def test_get_server_names(self):
|
def test_get_server_names(self):
|
||||||
heat = mock.MagicMock()
|
heat = mock.MagicMock()
|
||||||
|
|
|
@ -111,30 +111,30 @@ class Config(object):
|
||||||
return os.fdopen(
|
return os.fdopen(
|
||||||
os.open(path, os.O_WRONLY | os.O_CREAT | os.O_TRUNC, 0o600), 'w')
|
os.open(path, os.O_WRONLY | os.O_CREAT | os.O_TRUNC, 0o600), 'w')
|
||||||
|
|
||||||
def _write_playbook_get_tasks(self, tasks, role, filepath):
|
def _write_tasks_per_step(self, tasks, role, filepath, step):
|
||||||
playbook = []
|
|
||||||
|
|
||||||
def get_key(task):
|
def step_in_task(task, step):
|
||||||
whenexpr = task.get('when', None)
|
whenexpr = task.get('when', None)
|
||||||
if whenexpr is None:
|
if whenexpr is None:
|
||||||
return ''
|
# If no step is defined, it will be executed for all
|
||||||
|
# steps.
|
||||||
|
return True
|
||||||
if not isinstance(whenexpr, list):
|
if not isinstance(whenexpr, list):
|
||||||
whenexpr = [whenexpr]
|
whenexpr = [whenexpr]
|
||||||
for w in whenexpr:
|
for w in whenexpr:
|
||||||
# make \|int optional incase forgotten; use only step digit:
|
# make \|int optional incase forgotten; use only step digit:
|
||||||
match = re.search('step(\|int)? == ([0-9]+)', "%s" % w)
|
match = re.search('step(\|int)? == ([0-9]+)$', "%s" % w)
|
||||||
if match:
|
if match:
|
||||||
matches = len(match.groups())
|
if match.group(2) == str(step):
|
||||||
return match.group(matches)
|
return True
|
||||||
return ''
|
else:
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
sorted_tasks = sorted(tasks, key=get_key)
|
tasks_per_step = [task for task in tasks if step_in_task(task, step)]
|
||||||
playbook.append({'name': '%s playbook' % role,
|
|
||||||
'hosts': role,
|
|
||||||
'tasks': sorted_tasks})
|
|
||||||
with self._open_file(filepath) as conf_file:
|
with self._open_file(filepath) as conf_file:
|
||||||
yaml.safe_dump(playbook, conf_file, default_flow_style=False)
|
yaml.safe_dump(tasks_per_step, conf_file, default_flow_style=False)
|
||||||
return sorted_tasks
|
return tasks_per_step
|
||||||
|
|
||||||
def initialize_git_repo(self, dirname):
|
def initialize_git_repo(self, dirname):
|
||||||
repo = git.Repo.init(dirname)
|
repo = git.Repo.init(dirname)
|
||||||
|
@ -222,23 +222,27 @@ class Config(object):
|
||||||
role_group_vars[role_name] = {}
|
role_group_vars[role_name] = {}
|
||||||
role_group_vars[role_name].update(role[config])
|
role_group_vars[role_name].update(role[config])
|
||||||
else:
|
else:
|
||||||
if 'upgrade_tasks' in config:
|
# NOTE(jfrancoa): Move this upgrade_tasks condition to the
|
||||||
filepath = os.path.join(role_path, '%s_playbook.yaml' %
|
# upper level once THT is adapted. We include it here to
|
||||||
config)
|
# allow the CI to pass until THT changed is not merged.
|
||||||
data = self._write_playbook_get_tasks(
|
if config == 'upgrade_tasks':
|
||||||
role[config], role_name, filepath)
|
for i in range(constants.UPGRADE_STEPS_MAX):
|
||||||
else:
|
filepath = os.path.join(role_path, '%s_step%s.yaml'
|
||||||
try:
|
% (config, i))
|
||||||
data = role[config]
|
self._write_tasks_per_step(role[config], role_name,
|
||||||
except KeyError as e:
|
filepath, i)
|
||||||
message = 'Invalid key: %s, error: %s' % (config,
|
try:
|
||||||
str(e))
|
data = role[config]
|
||||||
raise KeyError(message)
|
except KeyError as e:
|
||||||
|
message = 'Invalid key: %s, error: %s' % (config,
|
||||||
|
str(e))
|
||||||
|
raise KeyError(message)
|
||||||
filepath = os.path.join(role_path, '%s.yaml' % config)
|
filepath = os.path.join(role_path, '%s.yaml' % config)
|
||||||
with self._open_file(filepath) as conf_file:
|
with self._open_file(filepath) as conf_file:
|
||||||
yaml.safe_dump(data,
|
yaml.safe_dump(data,
|
||||||
conf_file,
|
conf_file,
|
||||||
default_flow_style=False)
|
default_flow_style=False)
|
||||||
|
|
||||||
role_config = self.get_role_config()
|
role_config = self.get_role_config()
|
||||||
for config_name, config in six.iteritems(role_config):
|
for config_name, config in six.iteritems(role_config):
|
||||||
conf_path = os.path.join(config_dir, config_name + ".yaml")
|
conf_path = os.path.join(config_dir, config_name + ".yaml")
|
||||||
|
|
Loading…
Reference in New Issue