39
39
40
40
# Maps a Kolla image to a list of containers that use the image.
41
41
IMAGE_TO_CONTAINERS_EXCEPTIONS : Dict [str , List [str ]] = {
42
+ "dnsmasq" : [
43
+ "ironic_dnsmasq" ,
44
+ ],
42
45
"haproxy" : [
43
46
"glance_tls_proxy" ,
47
+ "haproxy" ,
44
48
"neutron_tls_proxy" ,
45
49
],
46
50
"mariadb-server" : [
47
51
"mariadb" ,
48
52
"mariabackup" ,
49
53
],
50
- "neutron-eswitchd" : [
54
+ "neutron-mlnx-agent" : [
55
+ "neutron_eswitchd" ,
51
56
"neutron_mlnx_agent" ,
52
57
],
53
58
"neutron-metadata-agent" : [
58
63
"nova_super_conductor" ,
59
64
"nova_conductor" ,
60
65
],
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
+ ],
61
75
"prometheus-v2-server" : [
62
76
"prometheus_server" ,
63
77
],
@@ -96,6 +110,9 @@ def parse_args() -> argparse.Namespace:
96
110
parser .add_argument ("--base-distros" , default = "," .join (SUPPORTED_BASE_DISTROS ), choices = SUPPORTED_BASE_DISTROS )
97
111
subparsers = parser .add_subparsers (dest = "command" , required = True )
98
112
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
+
99
116
subparser = subparsers .add_parser ("check-hierarchy" , help = "Check tag variable hierarchy against kolla-ansible" )
100
117
subparser .add_argument ("--kolla-ansible-path" , required = True , help = "Path to kolla-ansible repostory checked out to correct branch" )
101
118
@@ -114,7 +131,7 @@ def parse_args() -> argparse.Namespace:
114
131
return parser .parse_args ()
115
132
116
133
117
- def get_abs_path (relative_path : str ) -> str :
134
+ def get_abs_path (relative_path : str ) -> pathlib . Path :
118
135
"""Return the absolute path of a file in SKC."""
119
136
script_path = pathlib .Path (inspect .getfile (inspect .currentframe ()))
120
137
return script_path .parent .parent / relative_path
@@ -277,6 +294,45 @@ def check_tags(base_distros: List[str], kolla_image_tags: KollaImageTags, regist
277
294
sys .exit (1 )
278
295
279
296
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
+
280
336
def check_hierarchy (kolla_ansible_path : str ):
281
337
"""Check the tag variable hierarchy against Kolla Ansible variables."""
282
338
cmd = """git grep -h '^[a-z0-9_]*_tag:' ansible/roles/*/defaults/main.yml"""
@@ -352,7 +408,9 @@ def main():
352
408
353
409
validate (kolla_image_tags )
354
410
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" :
356
414
check_hierarchy (args .kolla_ansible_path )
357
415
elif args .command == "check-tags" :
358
416
check_tags (base_distros , kolla_image_tags , args .registry , args .namespace )
0 commit comments