~raharper/curtin/trunk.snappy-dd

« back to all changes in this revision

Viewing changes to tests/unittests/test_curthooks.py

  • Committer: Ryan Harper
  • Date: 2017-03-22 01:54:52 UTC
  • Revision ID: ryan.harper@canonical.com-20170322015452-el8sasyuq7yqt9cu
Rename Snappy->UbuntuCore; Add UbuntuCore curthooks unittets

Show diffs side-by-side

added added

removed removed

Lines of Context:
175
175
        self.assertEqual([], self.mock_install_packages.call_args_list)
176
176
 
177
177
 
 
178
class TestUbuntuCoreHooks(CurthooksBase):
 
179
    def setUp(self):
 
180
        super(TestUbuntuCoreHooks, self).setUp()
 
181
        self.target = None
 
182
 
 
183
    def tearDown(self):
 
184
        if self.target:
 
185
            shutil.rmtree(self.target)
 
186
 
 
187
    def test_target_is_ubuntu_core(self):
 
188
        self.target = tempfile.mkdtemp()
 
189
        ubuntu_core_path = os.path.join(self.target, 'system-data')
 
190
        util.ensure_dir(ubuntu_core_path)
 
191
        self.assertTrue(os.path.isdir(ubuntu_core_path))
 
192
        is_core = curthooks.target_is_ubuntu_core(self.target)
 
193
        self.assertTrue(is_core)
 
194
 
 
195
    def test_target_is_ubuntu_core_no_target(self):
 
196
        is_core = curthooks.target_is_ubuntu_core(self.target)
 
197
        self.assertFalse(is_core)
 
198
 
 
199
    def test_target_is_ubuntu_core_noncore_target(self):
 
200
        self.target = tempfile.mkdtemp()
 
201
        non_core_path = os.path.join(self.target, 'curtin')
 
202
        util.ensure_dir(non_core_path)
 
203
        self.assertTrue(os.path.isdir(non_core_path))
 
204
        is_core = curthooks.target_is_ubuntu_core(self.target)
 
205
        self.assertFalse(is_core)
 
206
 
 
207
    @patch('curtin.util.write_file')
 
208
    @patch('curtin.util.del_file')
 
209
    @patch('curtin.commands.curthooks.handle_cloudconfig')
 
210
    def test_curthooks_no_config(self, mock_handle_cc, mock_del_file,
 
211
                                 mock_write_file):
 
212
        self.target = tempfile.mkdtemp()
 
213
        config = {}
 
214
        curthooks.ubuntu_core_curthooks(config, target=self.target)
 
215
        self.assertEqual(len(mock_handle_cc.call_args_list), 0)
 
216
        self.assertEqual(len(mock_del_file.call_args_list), 0)
 
217
        self.assertEqual(len(mock_write_file.call_args_list), 0)
 
218
 
 
219
    @patch('curtin.util.write_file')
 
220
    @patch('curtin.util.del_file')
 
221
    @patch('curtin.commands.curthooks.handle_cloudconfig')
 
222
    def test_curthooks_cloud_config(self, mock_handle_cc, mock_del_file,
 
223
                                    mock_write_file):
 
224
        self.target = tempfile.mkdtemp()
 
225
        config = {
 
226
            'cloudconfig': {
 
227
                'file1': {
 
228
                    'content': "Hello World!\n",
 
229
                }
 
230
            }
 
231
        }
 
232
        curthooks.ubuntu_core_curthooks(config, target=self.target)
 
233
 
 
234
        self.assertEqual(len(mock_del_file.call_args_list), 0)
 
235
        cc_path = os.path.join(self.target,
 
236
                               'system-data/etc/cloud/cloud.cfg.d')
 
237
        mock_handle_cc.assert_called_with(config.get('cloudconfig'),
 
238
                                          target=cc_path)
 
239
        self.assertEqual(len(mock_write_file.call_args_list), 0)
 
240
 
 
241
 
178
242
# vi: ts=4 expandtab syntax=python