py33: unknown encoding: base64 Edit

Python 3 doesn't support str.encode('base64'), we should use the
module "base64" instead.

Close-Bug #1229161

Change-Id: I1432952558f8c5c3cff39761306e91916d80207f
This commit is contained in:
Kui Shi 2013-09-25 06:24:14 +08:00
parent 2ab334435f
commit 8b264fc61d
2 changed files with 6 additions and 3 deletions

View File

@ -360,7 +360,7 @@ class BootingManagerWithFind(ManagerWithFind):
data = file_or_string
personality.append({
'path': filepath,
'contents': data.encode('base64'),
'contents': base64.b64encode(data.encode('utf-8')),
})
if availability_zone:

View File

@ -16,6 +16,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import base64
import datetime
import os
import mock
@ -174,7 +175,8 @@ class ShellTest(utils.TestCase):
def test_boot_user_data(self):
testfile = os.path.join(os.path.dirname(__file__), 'testfile.txt')
expected_file_data = open(testfile).read().encode('base64').strip()
data = open(testfile).read()
expected_file_data = base64.b64encode(data.encode('utf-8'))
self.run_command(
'boot --flavor 1 --image 1 --user_data %s some-server' % testfile)
self.assert_called_anytime(
@ -514,7 +516,8 @@ class ShellTest(utils.TestCase):
def test_boot_files(self):
testfile = os.path.join(os.path.dirname(__file__), 'testfile.txt')
expected_file_data = open(testfile).read().encode('base64')
data = open(testfile).read()
expected_file_data = base64.b64encode(data.encode('utf-8'))
cmd = ('boot some-server --flavor 1 --image 1'
' --file /tmp/foo=%s --file /tmp/bar=%s')