Uploaded image for project: 'Libcloud'
  1. Libcloud
  2. LIBCLOUD-321

libcloud.test.compute.test_deployment.DeploymentTests.test_script_file_deployment() fails with Python 3.3

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 0.13.0
    • Component/s: None
    • Labels:
      None

      Description

      Libcloud-0.12.4 introduced libcloud.test.compute.test_deployment.DeploymentTests.test_script_file_deployment(), which fails with Python 3.3.

      ======================================================================
      ERROR: test_script_file_deployment (libcloud.test.compute.test_deployment.DeploymentTests)
      ----------------------------------------------------------------------
      Traceback (most recent call last):
        File "/tmp/apache-libcloud-0.12.4/libcloud/test/compute/test_deployment.py", line 126, in test_script_file_deployment
          sfd1 = ScriptFileDeployment(script_file=file_path)
        File "/tmp/apache-libcloud-0.12.4/libcloud/compute/deployment.py", line 193, in __init__
          delete=delete)
        File "/tmp/apache-libcloud-0.12.4/libcloud/compute/deployment.py", line 133, in __init__
          argument_value=script)
        File "/tmp/apache-libcloud-0.12.4/libcloud/compute/deployment.py", line 52, in _get_string_value
          'object' % (argument_name))
      TypeError: script argument must be a string or a file-like object
      
      ----------------------------------------------------------------------
      

      libcloud.utils.py3.basestring is defined as str for Python 3.
      Deployment._get_string_value() accepts argument_value, which is libcloud.utils.py3.basestring (i.e. str), but ScriptFileDeployment.__init__() opens a file in binary mode, so the result of reading is bytes, not str.

      Potential fix:

      --- libcloud/compute/deployment.py
      +++ libcloud/compute/deployment.py
      @@ -185,7 +185,7 @@
               @type delete: C{bool}
               @keyword delete: Whether to delete the script on completion.
               """
      -        with open(script_file, 'rb') as fp:
      +        with open(script_file, 'r') as fp:
                   content = fp.read()
       
               super(ScriptFileDeployment, self).__init__(script=content,
      --- libcloud/test/compute/test_deployment.py
      +++ libcloud/test/compute/test_deployment.py
      @@ -115,12 +115,8 @@
                               client=MockClient(hostname='localhost')))
       
           def test_script_file_deployment(self):
      -        # TODO: Fix 3.2 compatibility
      -        if PY32:
      -            return
      -
               file_path = os.path.abspath(__file__)
      -        with open(file_path, 'rb') as fp:
      +        with open(file_path, 'r') as fp:
                   content = fp.read()
       
               sfd1 = ScriptFileDeployment(script_file=file_path)
      

      Alternative fix would be to open file in binary mode and (only when running with Python 3) to decode content from bytes to str.

        Attachments

        1. libcloud.patch
          1 kB
          Arfrever Frehtes Taifersar Arahesis

          Activity

            People

            • Assignee:
              kami Tomaz Muraus
              Reporter:
              arfrever Arfrever Frehtes Taifersar Arahesis
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: