Ubuntu Pastebin

Paste from smoser at Wed, 6 Dec 2017 17:28:01 +0000

Download as text
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
diff --git a/tests/cloud_tests/__init__.py b/tests/cloud_tests/__init__.py
index 98c1d6c7..dd436989 100644
--- a/tests/cloud_tests/__init__.py
+++ b/tests/cloud_tests/__init__.py
@@ -10,6 +10,12 @@ TESTCASES_DIR = os.path.join(BASE_DIR, 'testcases')
 TEST_CONF_DIR = os.path.join(BASE_DIR, 'testcases')
 TREE_BASE = os.sep.join(BASE_DIR.split(os.sep)[:-2])
 
+# This domain contains reverse lookups for hostnames that are used.
+# The primary reason is so sudo will return quickly when it attempts
+# to look up the hostname.  i9n is just short for 'integration'.
+# see also bug 1730744 for why we had to do this.
+CI_DOMAIN = "i9n.cloud-init.io"
+
 
 def _initialize_logging():
     """Configure logging for cloud_tests."""
diff --git a/tests/cloud_tests/bddeb.py b/tests/cloud_tests/bddeb.py
index c259dfea..8681a5a3 100644
--- a/tests/cloud_tests/bddeb.py
+++ b/tests/cloud_tests/bddeb.py
@@ -8,7 +8,7 @@ import tempfile
 
 from cloudinit import util as c_util
 from tests.cloud_tests import (config, LOG)
-from tests.cloud_tests.platforms import (platforms, images, snapshots,
+from tests.cloud_tests import (platforms, images, snapshots,
                                          instances)
 from tests.cloud_tests.stage import (PlatformComponent, run_stage, run_single)
 
diff --git a/tests/cloud_tests/collect.py b/tests/cloud_tests/collect.py
index db5ee99f..4805cea1 100644
--- a/tests/cloud_tests/collect.py
+++ b/tests/cloud_tests/collect.py
@@ -64,9 +64,9 @@ def collect_test_data(args, snapshot, os_name, test_name):
     # skip the testcase with a warning
     req_features = test_config.get('required_features', [])
     if any(feature not in snapshot.features for feature in req_features):
-        LOG.warn('test config %s requires features not supported by image, '
-                 'skipping.\nrequired features: %s\nsupported features: %s',
-                 test_name, req_features, snapshot.features)
+        LOG.warning('test config %s requires features not supported by image, '
+                    'skipping.\nrequired features: %s\nsupported features: %s',
+                    test_name, req_features, snapshot.features)
         return ({}, 0)
 
     # if there are user data overrides required for this test case, apply them
diff --git a/tests/cloud_tests/config.py b/tests/cloud_tests/config.py
index 52fc2bda..8bd569fd 100644
--- a/tests/cloud_tests/config.py
+++ b/tests/cloud_tests/config.py
@@ -92,7 +92,7 @@ def load_platform_config(platform_name, require_enabled=False):
 
 
 def load_os_config(platform_name, os_name, require_enabled=False,
-                   feature_overrides={}):
+                   feature_overrides=None):
     """Load configuration for os.
 
     @param platform_name: platform name to load os config for
@@ -101,6 +101,8 @@ def load_os_config(platform_name, os_name, require_enabled=False,
     @param feature_overrides: feature flag overrides to merge with features
     @return_value: config dict
     """
+    if feature_overrides is None:
+        feature_overrides = {}
     main_conf = c_util.read_conf(RELEASES_CONF)
     default = main_conf['default_release_config']
     image = main_conf['releases'][os_name]
diff --git a/tests/cloud_tests/platforms/nocloudkvm/instance.py b/tests/cloud_tests/platforms/nocloudkvm/instance.py
index a87d76a6..df2f4c3f 100644
--- a/tests/cloud_tests/platforms/nocloudkvm/instance.py
+++ b/tests/cloud_tests/platforms/nocloudkvm/instance.py
@@ -2,21 +2,18 @@
 
 """Base NoCloud KVM instance."""
 
+import copy
 import os
 import paramiko
 import socket
 import subprocess
 import time
+import uuid
 
 from ..instances import Instance
+from cloudinit.atomic_helper import write_json
 from cloudinit import util as c_util
-from tests.cloud_tests import util
-
-# This domain contains reverse lookups for hostnames that are used.
-# The primary reason is so sudo will return quickly when it attempts
-# to look up the hostname.  i9n is just short for 'integration'.
-# see also bug 1730744 for why we had to do this.
-CI_DOMAIN = "i9n.cloud-init.io"
+from tests.cloud_tests import CI_DOMAIN, util
 
 
 class NoCloudKVMInstance(Instance):
@@ -37,14 +34,38 @@ class NoCloudKVMInstance(Instance):
         @param features: dictionary of supported feature flags
         """
         self.user_data = user_data
-        self.meta_data = meta_data
-        self.ssh_key_file = os.path.join(platform.config['data_dir'],
-                                         platform.config['private_key'])
+        if meta_data:
+            meta_data = copy.deepcopy(meta_data)
+        else:
+            meta_data = {}
+
+        if 'instance-id' in meta_data:
+            iid = meta_data['instance-id']
+        else:
+            iid = str(uuid.uuid1())
+            meta_data['instance-id'] = iid
+
+        self.instance_id = iid
+        self.ssh_key_file = os.path.join(
+            platform.config['data_dir'], platform.config['private_key'])
+        self.ssh_pubkey_file = os.path.join(
+            platform.config['data_dir'], platform.config['public_key'])
+
+        self.ssh_pubkey = None
+        if self.ssh_pubkey_file:
+            with open(self.ssh_pubkey_file, "r") as fp:
+                self.ssh_pubkey = fp.read().rstrip('\n')
+
+            if not meta_data.get('public-keys'):
+                meta_data['public-keys'] = []
+            meta_data['public-keys'].append(self.ssh_pubkey)
+
         self.ssh_port = None
         self.pid = None
         self.pid_file = None
         self.console_file = None
         self.disk = image_path
+        self.meta_data = meta_data
 
         super(NoCloudKVMInstance, self).__init__(
             platform, name, properties, config, features)
@@ -78,11 +99,15 @@ class NoCloudKVMInstance(Instance):
         """Generate nocloud seed from user-data"""
         seed_file = os.path.join(tmpdir, '%s_seed.img' % self.name)
         user_data_file = os.path.join(tmpdir, '%s_user_data' % self.name)
+        meta_data_file = os.path.join(tmpdir, '%s_meta_data' % self.name)
 
         with open(user_data_file, "w") as ud_file:
             ud_file.write(self.user_data)
 
-        c_util.subp(['cloud-localds', seed_file, user_data_file])
+        # meta-data can be yaml, but more easily pretty printed with json
+        write_json(meta_data_file, self.meta_data)
+        c_util.subp(['cloud-localds', seed_file, user_data_file,
+                     meta_data_file])
 
         return seed_file
 
diff --git a/tests/cloud_tests/platforms/nocloudkvm/snapshot.py b/tests/cloud_tests/platforms/nocloudkvm/snapshot.py
index 0005e1f2..2dae3590 100644
--- a/tests/cloud_tests/platforms/nocloudkvm/snapshot.py
+++ b/tests/cloud_tests/platforms/nocloudkvm/snapshot.py
@@ -41,10 +41,6 @@ class NoCloudKVMSnapshot(Snapshot):
         @param use_desc: description of snapshot instance use
         @return_value: an Instance
         """
-        key_file = os.path.join(self.platform.config['data_dir'],
-                                self.platform.config['public_key'])
-        user_data = self.inject_ssh_key(user_data, key_file)
-
         instance = self.platform.create_instance(
             self.properties, self.config, self.features,
             self._image_path, image_desc=str(self), use_desc=use_desc,
@@ -55,22 +51,6 @@ class NoCloudKVMSnapshot(Snapshot):
 
         return instance
 
-    def inject_ssh_key(self, user_data, key_file):
-        """Inject the authorized key into the user_data."""
-        with open(key_file) as f:
-            value = f.read()
-
-        key = 'ssh_authorized_keys:'
-        value = '  - %s' % value.strip()
-        user_data = user_data.split('\n')
-        if key in user_data:
-            user_data.insert(user_data.index(key) + 1, '%s' % value)
-        else:
-            user_data.insert(-1, '%s' % key)
-            user_data.insert(-1, '%s' % value)
-
-        return '\n'.join(user_data)
-
     def destroy(self):
         """Clean up snapshot data."""
         shutil.rmtree(self._workd)
diff --git a/tests/cloud_tests/testcases/base.py b/tests/cloud_tests/testcases/base.py
index 1706f59b..aec49eb6 100644
--- a/tests/cloud_tests/testcases/base.py
+++ b/tests/cloud_tests/testcases/base.py
@@ -12,7 +12,8 @@ from cloudinit import util as c_util
 class CloudTestCase(unittest.TestCase):
     """Base test class for verifiers."""
 
-    data = None
+    # data gets popuulated in get_suite.setUpClass
+    data = {}
     conf = None
     _cloud_config = None
 
@@ -31,6 +32,7 @@ class CloudTestCase(unittest.TestCase):
 
     def get_data_file(self, name):
         """Get data file failing test if it is not present."""
+        import ipdb; ipdb.set_trace()
         if name not in self.data:
             raise AssertionError('File "{}" missing from collect data'
                                  .format(name))
diff --git a/tests/cloud_tests/testcases/modules/set_hostname_fqdn.py b/tests/cloud_tests/testcases/modules/set_hostname_fqdn.py
index eb6f0650..a405b30b 100644
--- a/tests/cloud_tests/testcases/modules/set_hostname_fqdn.py
+++ b/tests/cloud_tests/testcases/modules/set_hostname_fqdn.py
@@ -1,7 +1,7 @@
 # This file is part of cloud-init. See LICENSE file for license information.
 
 """cloud-init Integration Test Verify Script."""
-from tests.cloud_tests.instances.nocloudkvm import CI_DOMAIN
+from tests.cloud_tests import CI_DOMAIN
 from tests.cloud_tests.testcases import base
 
 
diff --git a/tox.ini b/tox.ini
index 92232201..a8cba179 100644
--- a/tox.ini
+++ b/tox.ini
@@ -26,7 +26,7 @@ deps =
     pylint==1.7.1
     # test-requirements because unit tests are now present in cloudinit tree
     -r{toxinidir}/test-requirements.txt
-commands = {envpython} -m pylint {posargs:cloudinit}
+commands = {envpython} -m pylint {posargs:cloudinit tests/ tools/}
 
 [testenv:py3]
 basepython = python3
@@ -119,7 +119,7 @@ commands = {envpython} -m pyflakes {posargs:cloudinit/ tests/ tools/}
 deps = pyflakes
 
 [testenv:tip-pylint]
-commands = {envpython} -m pylint {posargs:cloudinit}
+commands = {envpython} -m pylint {posargs:cloudinit tests/ tools/}
 deps =
     # requirements
     pylint
Download as text