ntp unit tests broken if no package program available in test environment

Bug #1721573 reported by Scott Moser
14
This bug affects 2 people
Affects Status Importance Assigned to Milestone
cloud-init
Expired
Low
Unassigned

Bug Description

apply this diff to show the error, just make 'ntp_installable' not
find a package installer. At minimum, we just need to mock that out.

$ git diff
diff --git a/cloudinit/config/cc_ntp.py b/cloudinit/config/cc_ntp.py
index 15ae1ecd..5ebdd461 100644
--- a/cloudinit/config/cc_ntp.py
+++ b/cloudinit/config/cc_ntp.py
@@ -147,6 +147,7 @@ def ntp_installable():
     if util.system_is_snappy():
         return False

+ return False
     if any(map(util.which, ['apt-get', 'dnf', 'yum', 'zypper'])):
         return True

$ tox-venv py3 python3 -m nose tests/unittests/test_handler/test_handler_ntp.py:TestNtp
...EEEEEE............
======================================================================
ERROR: Test ntp handler renders the shipped distro ntp.conf templates.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/smoser-public/src/cloud-init/cloud-init/tests/unittests/test_handler/test_handler_ntp.py", line 272, in test_ntp_handler_real_distro_templates
    cc_ntp.handle('notimportant', cfg, mycloud, None, None)
  File "/home/smoser-public/src/cloud-init/cloud-init/cloudinit/config/cc_ntp.py", line 128, in handle
    write_ntp_config_template(ntp_cfg, cloud, confpath, template=template_name)
  File "/home/smoser-public/src/cloud-init/cloud-init/cloudinit/config/cc_ntp.py", line 204, in write_ntp_config_template
    "not rendering %s"), path)
RuntimeError: ('No template found, not rendering %s', '/etc/systemd/timesyncd.conf.d/cloud-init.conf')

======================================================================
ERROR: Ntp schema validation allows for an empty ntp: configuration.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/smoser-public/src/cloud-init/cloud-init/tests/unittests/test_handler/test_handler_ntp.py", line 305, in test_ntp_handler_schema_validation_allows_empty_ntp_config
    with open(ntp_conf) as stream:
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/ci-TestNtp.nmgu_ja4/ntp.conf'

======================================================================
ERROR: Ntp schema validation warns of invalid keys present in ntp config.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/smoser-public/src/cloud-init/cloud-init/tests/unittests/test_handler/test_handler_ntp.py", line 374, in test_ntp_handler_schema_validation_warns_invalid_key_present
    with open(ntp_conf) as stream:
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/ci-TestNtp.zj7sj7n8/ntp.conf'

======================================================================
ERROR: Ntp schema validation warns of non-strings in pools or servers.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/smoser-public/src/cloud-init/cloud-init/tests/unittests/test_handler/test_handler_ntp.py", line 331, in test_ntp_handler_schema_validation_warns_non_string_item_type
    with open(ntp_conf) as stream:
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/ci-TestNtp.agut528j/ntp.conf'

======================================================================
ERROR: Ntp schema validation warns of duplicates in servers or pools.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/smoser-public/src/cloud-init/cloud-init/tests/unittests/test_handler/test_handler_ntp.py", line 400, in test_ntp_handler_schema_validation_warns_of_duplicates
    with open(ntp_conf) as stream:
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/ci-TestNtp.ykjfhbx7/ntp.conf'

======================================================================
ERROR: Ntp schema validation warns of non-array pools or servers types.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/smoser-public/src/cloud-init/cloud-init/tests/unittests/test_handler/test_handler_ntp.py", line 352, in test_ntp_handler_schema_validation_warns_of_non_array_type
    with open(ntp_conf) as stream:
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/ci-TestNtp.4f3ycmp1/ntp.conf'

----------------------------------------------------------------------
Ran 21 tests in 0.085s

FAILED (errors=6)

Scott Moser (smoser)
Changed in cloud-init:
status: New → Confirmed
importance: Undecided → Low
Revision history for this message
James Falcon (falcojr) wrote :
Changed in cloud-init:
status: Confirmed → Expired
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Duplicates of this bug

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.