cloud-init-dev team mailing list archive
-
cloud-init-dev team
-
Mailing list archive
-
Message #04315
Re: [Merge] ~chad.smith/cloud-init:feature/snap-module into cloud-init:master
Diff comments:
> diff --git a/tests/cloud_tests/testcases/modules/snap.py b/tests/cloud_tests/testcases/modules/snap.py
> new file mode 100644
> index 0000000..7120e3f
> --- /dev/null
> +++ b/tests/cloud_tests/testcases/modules/snap.py
> @@ -0,0 +1,132 @@
> +# This file is part of cloud-init. See LICENSE file for license information.
> +
> +"""cloud-init Integration Test Verify Script"""
> +import json
> +import re
> +
> +from tests.cloud_tests.testcases import base
> +
> +
> +class TestSnap(base.CloudTestCase):
> + """Test snap module"""
> +
> + def test_snappy_version(self):
> + """Expect hello-world and core snaps are installed."""
> + out = self.get_data_file('snaplist')
> + self.assertIn('core', out)
> + self.assertIn('hello-world', out)
> +
> + def test_instance_data_json_ec2(self):
> + """Validate instance-data.json content by ec2 platform.
> +
> + This content is sourced by snapd when determining snapstore endpoints.
> + We validate expected values per cloud type to ensure we don't break
> + snapd.
> + """
> + if self.platform != 'ec2':
@Josh and @Scott, I'd like you guys specifically to look at how I've decided to extend the integration tests to Skip based on platform or os_name to see if that jives with how we'd like to use things. The problem I was trying to solve was that I need an integration test needs a bit vibility into its platform(cloud) or distro os_name as the assertions may be different in different cases.
Data gets passing into this test class instance in /tests/cloud_tests/verify.py which has the os_name & platform context
> + raise base.SkipTest(
> + 'Skipping ec2 instance-data.json on %s' % self.platform)
> + out = self.get_data_file('instance-data.json')
> + if not out:
> + if self.os_name == 'bionic':
> + raise AssertionError('No instance-data.json found on bionic')
> + raise base.SkipTest(
> + 'Skipping instance-data.json test. OS: %s not bionic' %
> + self.os_name)
> + instance_data = json.loads(out)
> + self.assertEqual(
> + ['ds/user-data'], instance_data['base64-encoded-keys'])
> + ds = instance_data.get('ds', {})
> + macs = ds.get('network', {}).get('interfaces', {}).get('macs', {})
> + if not macs:
> + raise AssertionError('No network data from EC2 meta-data')
> + # Check meta-data items we depend on
> + expected_net_keys = [
> + 'public-ipv4s', 'ipv4-associations', 'local-hostname',
> + 'public-hostname']
> + for mac, mac_data in macs.items():
> + for key in expected_net_keys:
> + self.assertIn(key, mac_data)
> + self.assertIsNotNone(
> + ds.get('placement', {}).get('availability-zone'),
> + 'Could not determine EC2 Availability zone placement')
> + ds = instance_data.get('ds', {})
> + v1_data = instance_data.get('v1', {})
> + self.assertIsNotNone(
> + v1_data['availability-zone'], 'expected ec2 availability-zone')
> + self.assertEqual('aws', v1_data['cloud-name'])
> + self.assertIn('i-', v1_data['instance-id'])
> + self.assertIn('ip-', v1_data['local-hostname'])
> + self.assertIsNotNone(v1_data['region'], 'expected ec2 region')
> +
> + def test_instance_data_json_lxd(self):
> + """Validate instance-data.json content by lxd platform.
> +
> + This content is sourced by snapd when determining snapstore endpoints.
> + We validate expected values per cloud type to ensure we don't break
> + snapd.
> + """
> + if self.platform != 'lxd':
> + raise base.SkipTest(
> + 'Skipping lxd instance-data.json on %s' % self.platform)
> + out = self.get_data_file('instance-data.json')
> + if not out:
> + if self.os_name == 'bionic':
> + raise AssertionError('No instance-data.json found on bionic')
> + raise base.SkipTest(
> + 'Skipping instance-data.json test. OS: %s not bionic' %
> + self.os_name)
> + instance_data = json.loads(out)
> + v1_data = instance_data.get('v1', {})
> + self.assertEqual(
> + ['ds/user-data', 'ds/vendor-data'],
> + instance_data['base64-encoded-keys'])
> + self.assertEqual('nocloud', v1_data['cloud-name'])
> + self.assertIsNone(
> + v1_data['availability-zone'],
> + 'found unexpected lxd availability-zone %s' %
> + v1_data['availability-zone'])
> + self.assertIn('cloud-test', v1_data['instance-id'])
> + self.assertIn('cloud-test', v1_data['local-hostname'])
> + self.assertIsNone(
> + v1_data['region'],
> + 'found unexpected lxd region %s' % v1_data['region'])
> +
> + def test_instance_data_json_kvm(self):
> + """Validate instance-data.json content by nocloud-kvm platform.
> +
> + This content is sourced by snapd when determining snapstore endpoints.
> + We validate expected values per cloud type to ensure we don't break
> + snapd.
> + """
> + if self.platform != 'nocloud-kvm':
> + raise base.SkipTest(
> + 'Skipping nocloud-kvm instance-data.json on %s' %
> + self.platform)
> + out = self.get_data_file('instance-data.json')
> + if not out:
> + if self.os_name == 'bionic':
> + raise AssertionError('No instance-data.json found on bionic')
> + raise base.SkipTest(
> + 'Skipping instance-data.json test. OS: %s not bionic' %
> + self.os_name)
> + instance_data = json.loads(out)
> + v1_data = instance_data.get('v1', {})
> + self.assertEqual(
> + ['ds/user-data'], instance_data['base64-encoded-keys'])
> + self.assertEqual('nocloud', v1_data['cloud-name'])
> + self.assertIsNone(
> + v1_data['availability-zone'],
> + 'found unexpected kvm availability-zone %s' %
> + v1_data['availability-zone'])
> + self.assertIsNotNone(
> + re.match('[\da-f]{8}(-[\da-f]{4}){3}-[\da-f]{12}',
> + v1_data['instance-id']),
> + 'kvm instance-id is not a UUID: %s' % v1_data['instance-id'])
> + self.assertIn('ubuntu', v1_data['local-hostname'])
> + self.assertIsNone(
> + v1_data['region'],
> + 'found unexpected lxd region %s' % v1_data['region'])
> +
> +
> +# vi: ts=4 expandtab
--
https://code.launchpad.net/~chad.smith/cloud-init/+git/cloud-init/+merge/338366
Your team cloud-init commiters is requested to review the proposed merge of ~chad.smith/cloud-init:feature/snap-module into cloud-init:master.