Check for uids before yielding tasks in CopyKeys hook

CopyKeys task won't be yielded if get_uids returns empty list.

Change-Id: I44c088b79bfb392d88174f8101e38a60ac6a6c67
Closes-Bug: 1541256
This commit is contained in:
Maciej Kwiek 2016-02-04 12:16:51 +01:00
parent 4c685d1eec
commit 2a806db751
2 changed files with 17 additions and 3 deletions

View File

@ -225,9 +225,7 @@ class CopyKeys(GenericRolesHook):
for file_path in self.task['parameters']['files']:
file_path['src'] = file_path['src'].format(
CLUSTER_ID=self.cluster.id)
uids = self.get_uids()
yield templates.make_generic_task(
uids, self.task)
return super(CopyKeys, self).serialize()
class GenerateCephKeys(GenerateKeys):

View File

@ -363,6 +363,22 @@ class TestHooksSerializers(BaseTaskSerializationTest):
self.assertItemsEqual(
files, serialized['parameters']['files'])
def test_copy_keys_no_nodes(self):
task_config = {
'id': 'copy_keys',
'type': 'copy_files',
'role': '*',
'parameters': {
'files': [{
'src': '/var/www/nailgun/keys/{CLUSTER_ID}/nova.key',
'dst': '/var/lib/astute/nova.key'}],
'permissions': '0600',
'dir_permissions': '0700'}}
task = tasks_serializer.CopyKeys(
task_config, self.cluster, [])
with self.assertRaises(StopIteration):
next(task.serialize())
def test_generate_keys(self):
task_config = {
'id': 'generate_keys',