Merge "Add role_net_map to expand roles output"

This commit is contained in:
Zuul 2021-01-05 19:05:37 +00:00 committed by Gerrit Code Review
commit 88c515cfad
3 changed files with 29 additions and 22 deletions

View File

@ -170,8 +170,10 @@ def expand(roles, stack_name, expand_provisioned=True, default_image=None,
instances = []
hostname_map = {}
parameter_defaults = {'HostnameMap': hostname_map}
role_net_map = {}
for role in roles:
name = role['name']
role_net_map.setdefault(name, set())
hostname_format = build_hostname_format(
role.get('hostname_format'), name)
count = role.get('count', 1)
@ -260,6 +262,9 @@ def expand(roles, stack_name, expand_provisioned=True, default_image=None,
if provisioned == expand_provisioned:
instances.append(inst)
role_net_map[name].update(
[x['network'] for x in inst.get('networks', [])])
parameter_defaults['%sCount' % name] = (
provisioned_count)
@ -268,7 +273,7 @@ def expand(roles, stack_name, expand_provisioned=True, default_image=None,
env = {'parameter_defaults': parameter_defaults}
else:
env = {}
return instances, env
return instances, env, role_net_map
def merge_networks_defaults(defaults, instance):

View File

@ -216,7 +216,7 @@ def main():
try:
if state in ('present', 'all'):
present, env = bd.expand(
present, env, role_net_map = bd.expand(
roles=module.params['baremetal_deployment'],
stack_name=module.params['stack_name'],
expand_provisioned=True,
@ -226,13 +226,14 @@ def main():
ssh_public_keys=module.params['ssh_public_keys'],
)
if state in ('absent', 'all'):
absent, _ = bd.expand(
absent, _, _ = bd.expand(
roles=module.params['baremetal_deployment'],
stack_name=module.params['stack_name'],
expand_provisioned=False,
default_image=module.params['default_image'],
)
env = {}
role_net_map = {}
if state == 'present':
instances = present
elif state == 'absent':
@ -244,7 +245,8 @@ def main():
changed=True,
msg='Expanded to %d instances' % len(instances),
instances=instances,
environment=env
environment=env,
role_net_map=role_net_map
)
except Exception as e:
module.fail_json(msg=str(e))

View File

@ -102,7 +102,7 @@ class TestExpandRoles(base.TestCase):
{'name': 'Compute'},
{'name': 'Controller'},
]
instances, environment = bd.expand(
instances, environment, role_net_map = bd.expand(
roles, 'overcloud', True, self.default_image
)
@ -134,7 +134,7 @@ class TestExpandRoles(base.TestCase):
{'name': 'Compute'},
{'name': 'Controller'},
]
instances, environment = bd.expand(
instances, environment, role_net_map = bd.expand(
roles, 'overcloud', True, self.default_image, self.default_network
)
self.assertEqual(
@ -165,7 +165,7 @@ class TestExpandRoles(base.TestCase):
]}
},
]
instances, environment = bd.expand(
instances, environment, role_net_map = bd.expand(
roles, 'overcloud', True, self.default_image, None
)
self.assertEqual(
@ -196,7 +196,7 @@ class TestExpandRoles(base.TestCase):
]}
},
]
instances, environment = bd.expand(
instances, environment, role_net_map = bd.expand(
roles, 'overcloud', True, self.default_image, self.default_network
)
self.assertEqual(
@ -229,7 +229,7 @@ class TestExpandRoles(base.TestCase):
]}
},
]
instances, environment = bd.expand(
instances, environment, role_net_map = bd.expand(
roles, 'overcloud', True, self.default_image, self.default_network
)
self.assertEqual(
@ -289,7 +289,7 @@ class TestExpandRoles(base.TestCase):
'hostname': 'overcloud-controller-1',
}]
}]
instances, environment = bd.expand(
instances, environment, role_net_map = bd.expand(
roles, 'overcloud', True, self.default_image
)
self.assertEqual(
@ -321,7 +321,7 @@ class TestExpandRoles(base.TestCase):
},
'hostname_format': 'controller-%index%.example.com'
}]
instances, environment = bd.expand(
instances, environment, role_net_map = bd.expand(
roles, 'overcloud', True, self.default_image,
user_name='heat-admin', ssh_public_keys='aaaa'
)
@ -397,7 +397,7 @@ class TestExpandRoles(base.TestCase):
'vif': True}]},
]},
]
instances, environment = bd.expand(
instances, environment, role_net_map = bd.expand(
roles, 'overcloud', True, self.default_image
)
self.assertEqual(
@ -464,7 +464,7 @@ class TestExpandRoles(base.TestCase):
'nics': [{'subnet': 'leaf-2'}]},
]},
]
instances, environment = bd.expand(
instances, environment, role_net_map = bd.expand(
roles, 'overcloud', True, self.default_image
)
self.assertEqual([
@ -524,7 +524,7 @@ class TestExpandRoles(base.TestCase):
'provisioned': False
}]
}]
instances, environment = bd.expand(
instances, environment, role_net_map = bd.expand(
roles, 'overcloud', True, self.default_image
)
self.assertEqual([
@ -553,7 +553,7 @@ class TestExpandRoles(base.TestCase):
},
environment['parameter_defaults'])
instances, environment = bd.expand(
instances, environment, role_net_map = bd.expand(
roles, 'overcloud', False, self.default_image
)
self.assertEqual([
@ -584,7 +584,7 @@ class TestExpandRoles(base.TestCase):
'provisioned': False
}]
}]
instances, environment = bd.expand(
instances, environment, role_net_map = bd.expand(
roles, 'overcloud', True, self.default_image
)
self.assertEqual([
@ -623,7 +623,7 @@ class TestExpandRoles(base.TestCase):
},
environment['parameter_defaults'])
instances, environment = bd.expand(
instances, environment, role_net_map = bd.expand(
roles, 'overcloud', False, self.default_image
)
self.assertEqual([
@ -663,7 +663,7 @@ class TestExpandRoles(base.TestCase):
'provisioned': True
}]
}]
instances, environment = bd.expand(
instances, environment, role_net_map = bd.expand(
roles, 'overcloud', True, self.default_image
)
self.assertEqual([
@ -694,7 +694,7 @@ class TestExpandRoles(base.TestCase):
},
environment['parameter_defaults'])
instances, environment = bd.expand(
instances, environment, role_net_map = bd.expand(
roles, 'overcloud', False, self.default_image
)
self.assertEqual([
@ -732,7 +732,7 @@ class TestExpandRoles(base.TestCase):
'provisioned': True
}]
}]
instances, environment = bd.expand(
instances, environment, role_net_map = bd.expand(
roles, 'overcloud', True, self.default_image
)
self.assertEqual([
@ -763,7 +763,7 @@ class TestExpandRoles(base.TestCase):
},
environment['parameter_defaults'])
instances, environment = bd.expand(
instances, environment, role_net_map = bd.expand(
roles, 'overcloud', False, self.default_image
)
self.assertEqual([
@ -836,7 +836,7 @@ class TestExpandRoles(base.TestCase):
'nics': [{'subnet': 'leaf-2'}]},
]},
]
instances, environment = bd.expand(
instances, environment, role_net_map = bd.expand(
roles, 'overcloud', True, self.default_image
)
self.assertEqual(