Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion integration-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# PyPI requirements for cloud-init integration testing
# https://cloudinit.readthedocs.io/en/latest/topics/integration_tests.html
#
pycloudlib @ git+https://github.com/canonical/pycloudlib.git@39805087affaed07b266d64cf0d883be775b5c0f
pycloudlib @ git+https://github.com/canonical/pycloudlib.git@878981e3c7caaf583a8c7c5494dba9d9447acee8
pytest
3 changes: 2 additions & 1 deletion tests/integration_tests/bugs/test_gh570.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,6 @@ def test_nocloud_seedfrom_vendordata(client: IntegrationInstance):
VENDOR_DATA,
)
client.execute('cloud-init clean --logs')
client.restart(raise_on_cloudinit_failure=True)
client.restart()
assert client.execute('cloud-init status').ok
assert 'seeded_vendordata_test_file' in client.execute('ls /var/tmp')
3 changes: 2 additions & 1 deletion tests/integration_tests/bugs/test_lp1900837.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ def test_permissions_unchanged(self, client):
assert "600" == _get_log_perms(client)

# Reboot
client.restart(raise_on_cloudinit_failure=True)
client.restart()
assert client.execute('cloud-init status').ok

# Check that permissions are not reset on reboot
assert "600" == _get_log_perms(client)
14 changes: 4 additions & 10 deletions tests/integration_tests/clouds.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def _perform_launch(self, launch_kwargs):
pycloudlib_instance = self.cloud_instance.launch(**launch_kwargs)
return pycloudlib_instance

def launch(self, user_data=None, launch_kwargs=None, wait=True,
def launch(self, user_data=None, launch_kwargs=None,
settings=integration_settings):
if launch_kwargs is None:
launch_kwargs = {}
Expand All @@ -147,13 +147,9 @@ def launch(self, user_data=None, launch_kwargs=None, wait=True,
self.settings.EXISTING_INSTANCE_ID
)
return
if 'wait' in launch_kwargs:
raise Exception("Specify 'wait' directly to launch, "
"not in 'launch_kwargs'")
kwargs = {
'image_id': self.image_id,
'user_data': user_data,
'wait': False,
}
kwargs.update(launch_kwargs)
log.info(
Expand All @@ -163,11 +159,9 @@ def launch(self, user_data=None, launch_kwargs=None, wait=True,
)

pycloudlib_instance = self._perform_launch(kwargs)
if wait:
pycloudlib_instance.wait(raise_on_cloudinit_failure=False)
log.info('Launched instance: %s', pycloudlib_instance)
instance = self.get_instance(pycloudlib_instance, settings)
if wait:
if kwargs.get('wait', True):
# If we aren't waiting, we can't rely on command execution here
log.info(
'cloud-init version: %s',
Expand Down Expand Up @@ -277,7 +271,7 @@ def _mount_source(instance: LXDInstance):

def _perform_launch(self, launch_kwargs):
launch_kwargs['inst_type'] = launch_kwargs.pop('instance_type', None)
launch_kwargs.pop('wait')
wait = launch_kwargs.pop('wait', True)
release = launch_kwargs.pop('image_id')

try:
Expand All @@ -293,7 +287,7 @@ def _perform_launch(self, launch_kwargs):
)
if self.settings.CLOUD_INIT_SOURCE == 'IN_PLACE':
self._mount_source(pycloudlib_instance)
pycloudlib_instance.start(wait=False)
pycloudlib_instance.start(wait=wait)
return pycloudlib_instance


Expand Down
13 changes: 4 additions & 9 deletions tests/integration_tests/instances.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,13 @@ def __init__(self, cloud: 'IntegrationCloud', instance: BaseInstance,
def destroy(self):
self.instance.delete()

def restart(self, raise_on_cloudinit_failure=False):
def restart(self):
"""Restart this instance (via cloud mechanism) and wait for boot.

This wraps pycloudlib's `BaseInstance.restart` to pass
`raise_on_cloudinit_failure=False` to `BaseInstance.wait`, mirroring
our launch behaviour.
This wraps pycloudlib's `BaseInstance.restart`
"""
self.instance.restart(wait=False)
log.info("Instance restarted; waiting for boot")
self.instance.wait(
raise_on_cloudinit_failure=raise_on_cloudinit_failure
)
log.info("Restarting instance and waiting for boot")
self.instance.restart()

def execute(self, command, *, use_sudo=True) -> Result:
if self.instance.username == 'root' and use_sudo is False:
Expand Down
4 changes: 2 additions & 2 deletions tests/integration_tests/modules/test_power_state_change.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ def _detect_reboot(instance: IntegrationInstance):
# detecting the first boot or second boot, so we also check
# the logs to ensure we've booted twice. If the logs show we've
# only booted once, wait until we've booted twice
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Total aside, but I just noticed that this test could fail (by exiting early) if run on an instance which has booted more than once without cloud-init.log removal: the "first" boot would have multiple entries. Generally for this sort of check, I think we need a "before" count which is expected to increase before we consider the reboot complete (and this is why we should capture this in library code, so every .restart() call DTRT).

Anyway, moving on.

instance.instance.wait(raise_on_cloudinit_failure=False)
instance.instance.wait()
for _ in range(600):
try:
log = instance.read_from_file('/var/log/cloud-init.log')
boot_count = log.count("running 'init-local'")
if boot_count == 1:
instance.instance.wait(raise_on_cloudinit_failure=False)
instance.instance.wait()
elif boot_count > 1:
break
except Exception:
Expand Down
7 changes: 3 additions & 4 deletions tests/integration_tests/test_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,14 @@ def _output_to_compare(instance, file_path, netcfg_path):

def _restart(instance):
# work around pad.lv/1908287
try:
instance.restart(raise_on_cloudinit_failure=True)
except OSError as e:
instance.restart()
if not instance.execute('cloud-init status --wait --long').ok:
for _ in range(10):
time.sleep(5)
result = instance.execute('cloud-init status --wait --long')
if result.ok:
return
raise e
raise Exception("Cloud-init didn't finish starting up")


@pytest.mark.sru_2020_11
Expand Down