-
Notifications
You must be signed in to change notification settings - Fork 875
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
testing: port remaining cloud tests to integration testing framework (SC-191) #955
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3ed9918
bugs/lp1511485.py , bugs/lp1628337.py , and examples/alter_completion…
TheRealFalcon 6ea0477
Added tests for apt defaults, byobu, locale, output, ntp pools, and n…
TheRealFalcon 925b1fd
rest of the ntp server tests
TheRealFalcon 494be8e
The metadata stuff from base.py
TheRealFalcon adcc7da
some small formatting things
TheRealFalcon 169ca3d
Merge branch 'main' into cloud-tests
blackboxsw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,175 @@ | ||
# This file is part of cloud-init. See LICENSE file for license information. | ||
"""A set of somewhat unrelated tests that can be combined into a single | ||
instance launch. Generally tests should only be added here if a failure | ||
of the test would be unlikely to affect the running of another test using | ||
the same instance launch. Most independent module coherence tests can go | ||
here. | ||
""" | ||
import json | ||
import pytest | ||
import re | ||
from datetime import date | ||
|
||
from tests.integration_tests.clouds import ImageSpecification | ||
from tests.integration_tests.instances import IntegrationInstance | ||
from tests.integration_tests.util import verify_ordered_items_in_text | ||
|
||
USER_DATA = """\ | ||
#cloud-config | ||
apt: | ||
primary: | ||
- arches: [default] | ||
uri: http://us.archive.ubuntu.com/ubuntu/ | ||
byobu_by_default: enable | ||
final_message: | | ||
This is my final message! | ||
$version | ||
$timestamp | ||
$datasource | ||
$uptime | ||
locale: en_GB.UTF-8 | ||
locale_configfile: /etc/default/locale | ||
ntp: | ||
servers: ['ntp.ubuntu.com'] | ||
""" | ||
|
||
|
||
@pytest.mark.ci | ||
@pytest.mark.user_data(USER_DATA) | ||
class TestCombined: | ||
def test_final_message(self, class_client: IntegrationInstance): | ||
"""Test that final_message module works as expected. | ||
|
||
Also tests LP 1511485: final_message is silent | ||
""" | ||
client = class_client | ||
log = client.read_from_file('/var/log/cloud-init.log') | ||
today = date.today().strftime('%a, %d %b %Y') | ||
expected = ( | ||
'This is my final message!\n' | ||
r'\d+\.\d+.*\n' | ||
'{}.*\n' | ||
'DataSource.*\n' | ||
r'\d+\.\d+' | ||
).format(today) | ||
|
||
assert re.search(expected, log) | ||
|
||
def test_ntp_with_apt(self, class_client: IntegrationInstance): | ||
"""LP #1628337. | ||
|
||
cloud-init tries to install NTP before even | ||
configuring the archives. | ||
""" | ||
client = class_client | ||
log = client.read_from_file('/var/log/cloud-init.log') | ||
assert 'W: Failed to fetch' not in log | ||
assert 'W: Some index files failed to download' not in log | ||
assert 'E: Unable to locate package ntp' not in log | ||
|
||
def test_byobu(self, class_client: IntegrationInstance): | ||
"""Test byobu configured as enabled by default.""" | ||
client = class_client | ||
assert client.execute('test -e "/etc/byobu/autolaunch"').ok | ||
|
||
def test_configured_locale(self, class_client: IntegrationInstance): | ||
"""Test locale can be configured correctly.""" | ||
client = class_client | ||
default_locale = client.read_from_file('/etc/default/locale') | ||
assert 'LANG=en_GB.UTF-8' in default_locale | ||
|
||
locale_a = client.execute('locale -a') | ||
verify_ordered_items_in_text([ | ||
'en_GB.utf8', | ||
'en_US.utf8' | ||
], locale_a) | ||
|
||
locale_gen = client.execute( | ||
"cat /etc/locale.gen | grep -v '^#' | uniq" | ||
) | ||
verify_ordered_items_in_text([ | ||
'en_GB.UTF-8', | ||
'en_US.UTF-8' | ||
], locale_gen) | ||
|
||
def test_no_problems(self, class_client: IntegrationInstance): | ||
"""Test no errors, warnings, or tracebacks""" | ||
client = class_client | ||
status_file = client.read_from_file('/run/cloud-init/status.json') | ||
status_json = json.loads(status_file)['v1'] | ||
for stage in ('init', 'init-local', 'modules-config', 'modules-final'): | ||
assert status_json[stage]['errors'] == [] | ||
result_file = client.read_from_file('/run/cloud-init/result.json') | ||
result_json = json.loads(result_file)['v1'] | ||
assert result_json['errors'] == [] | ||
|
||
log = client.read_from_file('/var/log/cloud-init.log') | ||
assert 'WARN' not in log | ||
assert 'Traceback' not in log | ||
|
||
def _check_common_metadata(self, data): | ||
assert data['base64_encoded_keys'] == [] | ||
assert data['merged_cfg'] == 'redacted for non-root user' | ||
|
||
image_spec = ImageSpecification.from_os_image() | ||
assert data['sys_info']['dist'][0] == image_spec.os | ||
|
||
v1_data = data['v1'] | ||
assert re.match(r'\d\.\d+\.\d+-\d+', v1_data['kernel_release']) | ||
assert v1_data['variant'] == image_spec.os | ||
assert v1_data['distro'] == image_spec.os | ||
assert v1_data['distro_release'] == image_spec.release | ||
assert v1_data['machine'] == 'x86_64' | ||
assert re.match(r'3.\d\.\d', v1_data['python_version']) | ||
|
||
@pytest.mark.lxd_container | ||
def test_instance_json_lxd(self, class_client: IntegrationInstance): | ||
client = class_client | ||
instance_json_file = client.read_from_file( | ||
'/run/cloud-init/instance-data.json') | ||
|
||
data = json.loads(instance_json_file) | ||
self._check_common_metadata(data) | ||
v1_data = data['v1'] | ||
assert v1_data['cloud_name'] == 'unknown' | ||
assert v1_data['platform'] == 'lxd' | ||
assert v1_data['subplatform'] == ( | ||
'seed-dir (/var/lib/cloud/seed/nocloud-net)') | ||
assert v1_data['availability_zone'] is None | ||
assert v1_data['instance_id'] == client.instance.name | ||
assert v1_data['local_hostname'] == client.instance.name | ||
assert v1_data['region'] is None | ||
|
||
@pytest.mark.lxd_vm | ||
def test_instance_json_lxd_vm(self, class_client: IntegrationInstance): | ||
client = class_client | ||
instance_json_file = client.read_from_file( | ||
'/run/cloud-init/instance-data.json') | ||
|
||
data = json.loads(instance_json_file) | ||
self._check_common_metadata(data) | ||
v1_data = data['v1'] | ||
assert v1_data['cloud_name'] == 'unknown' | ||
assert v1_data['platform'] == 'lxd' | ||
assert v1_data['subplatform'] == ( | ||
'seed-dir (/var/lib/cloud/seed/nocloud-net)') | ||
assert v1_data['availability_zone'] is None | ||
assert v1_data['instance_id'] == client.instance.name | ||
assert v1_data['local_hostname'] == client.instance.name | ||
assert v1_data['region'] is None | ||
|
||
@pytest.mark.ec2 | ||
def test_instance_json_ec2(self, class_client: IntegrationInstance): | ||
client = class_client | ||
instance_json_file = client.read_from_file( | ||
'/run/cloud-init/instance-data.json') | ||
data = json.loads(instance_json_file) | ||
v1_data = data['v1'] | ||
assert v1_data['cloud_name'] == 'aws' | ||
assert v1_data['platform'] == 'ec2' | ||
assert v1_data['subplatform'].startswith('metadata') | ||
assert v1_data[ | ||
'availability_zone'] == client.instance.availability_zone | ||
assert v1_data['instance_id'] == client.instance.name | ||
assert v1_data['local_hostname'].startswith('ip-') | ||
assert v1_data['region'] == client.cloud.cloud_instance.region |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
"""Integration test for output redirection. | ||
|
||
This test redirects the output of a command to a file and then checks the file. | ||
|
||
(This is ported from | ||
``tests/cloud_tests/testcases/main/command_output_simple.yaml``.)""" | ||
import pytest | ||
|
||
from tests.integration_tests.instances import IntegrationInstance | ||
|
||
|
||
USER_DATA = """\ | ||
#cloud-config | ||
output: { all: "| tee -a /var/log/cloud-init-test-output" } | ||
final_message: "should be last line in cloud-init-test-output file" | ||
""" | ||
|
||
|
||
@pytest.mark.ci | ||
@pytest.mark.user_data(USER_DATA) | ||
def test_runcmd(client: IntegrationInstance): | ||
log = client.read_from_file('/var/log/cloud-init-test-output') | ||
assert 'should be last line in cloud-init-test-output file' in log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 on consolidation here of completely unrelated tests. If we find that the interaction of such tests cost us much in terms of lost signal or unexpected cross-module interaction we can separate them in the future. Our integration tests are expensive to setup and to run as far as time. so it's good to be as broad as possible with our tests.