diff --git a/lib/auto_attach.py b/lib/auto_attach.py index 798bfe9302..6f20cccf11 100644 --- a/lib/auto_attach.py +++ b/lib/auto_attach.py @@ -33,6 +33,11 @@ LOG = logging.getLogger("ubuntupro.lib.auto_attach") +# All known cloud-config keys which provide ubuntu pro configuration directives +CLOUD_INIT_UA_KEYS = set( + ["ubuntu-advantage", "ubuntu_advantage", "ubuntu_pro"] +) + try: import cloudinit.stages as ci_stages # type: ignore except ImportError: @@ -54,10 +59,7 @@ def check_cloudinit_userdata_for_ua_info(): if init is None: return False - if init.cfg and ( - "ubuntu_advantage" in init.cfg.keys() - or "ubuntu-advantage" in init.cfg.keys() - ): + if init.cfg and CLOUD_INIT_UA_KEYS.intersection(init.cfg): return True return False diff --git a/uaclient/tests/test_lib_auto_attach.py b/uaclient/tests/test_lib_auto_attach.py index c529bc70c4..eed9107458 100644 --- a/uaclient/tests/test_lib_auto_attach.py +++ b/uaclient/tests/test_lib_auto_attach.py @@ -41,6 +41,20 @@ def test_check_cloudinit_data_returns_false_if_no_cloudinit( "cloud_config_modules": ["ubuntu-advantage", "test"], }, ), + ( + True, + { + "ubuntu_pro": {"token": "TOKEN"}, + "cloud_config_modules": ["ubuntu-advantage", "test"], + }, + ), + ( + True, + { + "ubuntu-advantage": {"token": "TOKEN"}, + "cloud_config_modules": ["ubuntu-advantage", "test"], + }, + ), ), ) @mock.patch("lib.auto_attach.get_cloudinit_init_stage")