3939
4040# Maps a Kolla image to a list of containers that use the image.
4141IMAGE_TO_CONTAINERS_EXCEPTIONS : Dict [str , List [str ]] = {
42+ "dnsmasq" : [
43+ "ironic_dnsmasq" ,
44+ ],
4245 "haproxy" : [
4346 "glance_tls_proxy" ,
47+ "haproxy" ,
4448 "neutron_tls_proxy" ,
4549 ],
4650 "mariadb-server" : [
4751 "mariadb" ,
4852 "mariabackup" ,
4953 ],
50- "neutron-eswitchd" : [
54+ "neutron-mlnx-agent" : [
55+ "neutron_eswitchd" ,
5156 "neutron_mlnx_agent" ,
5257 ],
5358 "neutron-metadata-agent" : [
5863 "nova_super_conductor" ,
5964 "nova_conductor" ,
6065 ],
66+ "openvswitch-db-server" : [
67+ "openvswitch_db" ,
68+ ],
69+ "ovn-nb-db-server" : [
70+ "ovn_nb_db" ,
71+ ],
72+ "ovn-sb-db-server" : [
73+ "ovn_sb_db" ,
74+ ],
6175 "prometheus-v2-server" : [
6276 "prometheus_server" ,
6377 ],
@@ -96,6 +110,9 @@ def parse_args() -> argparse.Namespace:
96110 parser .add_argument ("--base-distros" , default = "," .join (SUPPORTED_BASE_DISTROS ), choices = SUPPORTED_BASE_DISTROS )
97111 subparsers = parser .add_subparsers (dest = "command" , required = True )
98112
113+ subparser = subparsers .add_parser ("check-image-map" , help = "Check image mapping against kolla-ansible" )
114+ subparser .add_argument ("--kolla-ansible-path" , required = True , help = "Path to kolla-ansible repostory checked out to correct branch" )
115+
99116 subparser = subparsers .add_parser ("check-hierarchy" , help = "Check tag variable hierarchy against kolla-ansible" )
100117 subparser .add_argument ("--kolla-ansible-path" , required = True , help = "Path to kolla-ansible repostory checked out to correct branch" )
101118
@@ -114,7 +131,7 @@ def parse_args() -> argparse.Namespace:
114131 return parser .parse_args ()
115132
116133
117- def get_abs_path (relative_path : str ) -> str :
134+ def get_abs_path (relative_path : str ) -> pathlib . Path :
118135 """Return the absolute path of a file in SKC."""
119136 script_path = pathlib .Path (inspect .getfile (inspect .currentframe ()))
120137 return script_path .parent .parent / relative_path
@@ -277,6 +294,45 @@ def check_tags(base_distros: List[str], kolla_image_tags: KollaImageTags, regist
277294 sys .exit (1 )
278295
279296
297+ def check_image_map (kolla_ansible_path : str ):
298+ """Check the image mapping against Kolla Ansible variables.
299+
300+ The *_image variables in Kolla Ansible define the mapping between
301+ containers and images. Ensure that the mapping defined in this script
302+ matches the one in Kolla Ansible.
303+ """
304+ supported_images = read_images ("etc/kayobe/pulp.yml" )
305+ assert supported_images
306+ # Build a map from container to image name.
307+ cmd = """git grep -h '^[a-z0-9_]*_image:' ansible/roles/*/defaults/main.yml"""
308+ image_map_str = subprocess .check_output (cmd , shell = True , cwd = os .path .realpath (kolla_ansible_path ))
309+ image_map = yaml .safe_load (image_map_str )
310+ image_var_re = re .compile (r"^([a-z0-9_]+)_image$" )
311+ image_map = {
312+ image_var_re .match (image_var ).group (1 ): image .split ("/" )[- 1 ]
313+ for image_var , image in image_map .items ()
314+ }
315+ # Filter out unsupported images.
316+ image_map = {
317+ container : image
318+ for container , image in image_map .items ()
319+ if image in supported_images
320+ }
321+ assert image_map
322+ errors = []
323+ # Check that our mapping is correct.
324+ for container , image in image_map .items ():
325+ containers = get_containers (image )
326+ if container not in containers :
327+ errors .append ((container , image ))
328+ if errors :
329+ print ("Errors:" )
330+ for tag_var , image in errors :
331+ print (f"Expected { tag_var } container to use { image } image" )
332+ if errors :
333+ sys .exit (1 )
334+
335+
280336def check_hierarchy (kolla_ansible_path : str ):
281337 """Check the tag variable hierarchy against Kolla Ansible variables."""
282338 cmd = """git grep -h '^[a-z0-9_]*_tag:' ansible/roles/*/defaults/main.yml"""
@@ -352,7 +408,9 @@ def main():
352408
353409 validate (kolla_image_tags )
354410
355- if args .command == "check-hierarchy" :
411+ if args .command == "check-image-map" :
412+ check_image_map (args .kolla_ansible_path )
413+ elif args .command == "check-hierarchy" :
356414 check_hierarchy (args .kolla_ansible_path )
357415 elif args .command == "check-tags" :
358416 check_tags (base_distros , kolla_image_tags , args .registry , args .namespace )
0 commit comments