~darkmuggle-deactivatedaccount/ubuntu/trusty/cloudinit/lp1316475-1303986

« back to all changes in this revision

Viewing changes to tests/unittests/test_datasource/test_opennebula.py

  • Committer: Scott Moser
  • Date: 2014-04-01 18:38:24 UTC
  • mfrom: (1.4.17)
  • Revision ID: smoser@ubuntu.com-20140401183824-hjtco4p3wes92rl3
* New upstream release.
  * support base64 encoded user-data in OpenNebula, required
    to allow arbitrary content in user-data (LP: #1300941)
  * pep8 and pylint fixes

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
from mocker import MockerTestCase
5
5
from tests.unittests.helpers import populate_dir
6
6
 
 
7
from base64 import b64encode
7
8
import os
8
9
import pwd
9
10
 
164
165
 
165
166
            public_keys.append(SSH_KEY % (c + 1,))
166
167
 
167
 
    def test_user_data(self):
168
 
        for k in ('USER_DATA', 'USERDATA'):
169
 
            my_d = os.path.join(self.tmp, k)
170
 
            populate_context_dir(my_d, {k: USER_DATA})
 
168
    def test_user_data_plain(self):
 
169
        for k in ('USER_DATA', 'USERDATA'):
 
170
            my_d = os.path.join(self.tmp, k)
 
171
            populate_context_dir(my_d, {k: USER_DATA,
 
172
                                        'USERDATA_ENCODING': ''})
 
173
            results = ds.read_context_disk_dir(my_d)
 
174
 
 
175
            self.assertTrue('userdata' in results)
 
176
            self.assertEqual(USER_DATA, results['userdata'])
 
177
 
 
178
    def test_user_data_encoding_required_for_decode(self):
 
179
        b64userdata = b64encode(USER_DATA)
 
180
        for k in ('USER_DATA', 'USERDATA'):
 
181
            my_d = os.path.join(self.tmp, k)
 
182
            populate_context_dir(my_d, {k: b64userdata})
 
183
            results = ds.read_context_disk_dir(my_d)
 
184
 
 
185
            self.assertTrue('userdata' in results)
 
186
            self.assertEqual(b64userdata, results['userdata'])
 
187
 
 
188
    def test_user_data_base64_encoding(self):
 
189
        for k in ('USER_DATA', 'USERDATA'):
 
190
            my_d = os.path.join(self.tmp, k)
 
191
            populate_context_dir(my_d, {k: b64encode(USER_DATA),
 
192
                                        'USERDATA_ENCODING': 'base64'})
171
193
            results = ds.read_context_disk_dir(my_d)
172
194
 
173
195
            self.assertTrue('userdata' in results)