summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--nova/compute/manager.py10
-rw-r--r--nova/utils.py12
-rw-r--r--nova/virt/xenapi/vmops.py10
3 files changed, 7 insertions, 25 deletions
diff --git a/nova/compute/manager.py b/nova/compute/manager.py
index d915dc069..3a712fd97 100644
--- a/nova/compute/manager.py
+++ b/nova/compute/manager.py
@@ -34,7 +34,6 @@ terminating it.
:func:`nova.utils.import_object`
"""
-import base64
import datetime
import random
import string
@@ -353,15 +352,10 @@ class ComputeManager(manager.Manager):
LOG.warn(_('trying to inject a file into a non-running '
'instance: %(instance_id)s (state: %(instance_state)s '
'expected: %(expected_state)s)') % locals())
- # Files/paths *should* be base64-encoded at this point, but
- # double-check to make sure.
- b64_path = utils.ensure_b64_encoding(path)
- b64_contents = utils.ensure_b64_encoding(file_contents)
- plain_path = base64.b64decode(b64_path)
nm = instance_ref['name']
- msg = _('instance %(nm)s: injecting file to %(plain_path)s') % locals()
+ msg = _('instance %(nm)s: injecting file to %(path)s') % locals()
LOG.audit(msg)
- self.driver.inject_file(instance_ref, b64_path, b64_contents)
+ self.driver.inject_file(instance_ref, path, file_contents)
@exception.wrap_exception
@checks_instance_lock
diff --git a/nova/utils.py b/nova/utils.py
index 0cf91e0cc..02b71900c 100644
--- a/nova/utils.py
+++ b/nova/utils.py
@@ -491,18 +491,6 @@ def loads(s):
return json.loads(s)
-def ensure_b64_encoding(val):
- """Safety method to ensure that values expected to be base64-encoded
- actually are. If they are, the value is returned unchanged. Otherwise,
- the encoded value is returned.
- """
- try:
- dummy = base64.decode(val)
- return val
- except TypeError:
- return base64.b64encode(val)
-
-
def get_from_path(items, path):
""" Returns a list of items matching the specified path. Takes an
XPath-like expression e.g. prop1/prop2/prop3, and for each item in items,
diff --git a/nova/virt/xenapi/vmops.py b/nova/virt/xenapi/vmops.py
index 9ac83efb0..89d58a664 100644
--- a/nova/virt/xenapi/vmops.py
+++ b/nova/virt/xenapi/vmops.py
@@ -19,6 +19,7 @@
Management class for VM-related functions (spawn, reboot, etc).
"""
+import base64
import json
import M2Crypto
import os
@@ -313,17 +314,16 @@ class VMOps(object):
task = self._session.call_xenapi("Async.VM.start", vm, False, False)
self._session.wait_for_task(task, instance.id)
- def inject_file(self, instance, b64_path, b64_contents):
+ def inject_file(self, instance, path, contents):
"""Write a file to the VM instance. The path to which it is to be
written and the contents of the file need to be supplied; both should
be base64-encoded to prevent errors with non-ASCII characters being
transmitted. If the agent does not support file injection, or the user
has disabled it, a NotImplementedError will be raised.
"""
- # Files/paths *should* be base64-encoded at this point, but
- # double-check to make sure.
- b64_path = utils.ensure_b64_encoding(b64_path)
- b64_contents = utils.ensure_b64_encoding(b64_contents)
+ # Files/paths must be base64-encoded for transmission to agent
+ b64_path = base64.b64encode(path)
+ b64_contents = base64.b64encode(contents)
# Need to uniquely identify this request.
transaction_id = str(uuid.uuid4())