~glance-coresec/glance/trunk

« back to all changes in this revision

Viewing changes to glance/teller/backends/swift.py

  • Committer: jaypipes at gmail
  • Date: 2010-10-08 20:42:13 UTC
  • mto: This revision was merged to the branch mainline in revision 12.
  • Revision ID: jaypipes@gmail.com-20101008204213-oy424tgk853jaq6r
First round of cleaning up the unittests. Adds test suite runner, support for virtualenv setup and library dependencies, resolves issues with ImportErrors on cloudfiles, adds pymox/stubout support and splits the backend testing into distinct unittest cases.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
#    License for the specific language governing permissions and limitations
16
16
#    under the License.
17
17
 
18
 
import cloudfiles
19
18
from glance.teller.backends import Backend, BackendException
20
19
 
21
20
 
39
38
        if conn_class:
40
39
            pass # Use the provided conn_class
41
40
        else:
 
41
            # Import cloudfiles here because stubout will replace this call
 
42
            # with a faked swift client in the unittests, avoiding import
 
43
            # errors if the test system does not have cloudfiles installed
 
44
            import cloudfiles
42
45
            conn_class = cloudfiles
43
46
 
44
47
        swift_conn = conn_class.get_connection(username=user, api_key=api_key,
64
67
            3) reassemble authurl
65
68
        """
66
69
        path = parsed_uri.path.lstrip('//')
 
70
        netloc = parsed_uri.netloc
67
71
 
68
72
        try:
69
 
            creds, path = path.split('@')
 
73
            creds, netloc = netloc.split('@')
70
74
            user, api_key = creds.split(':')
71
75
            path_parts = path.split('/')
72
76
            file = path_parts.pop()
73
77
            container = path_parts.pop()
74
 
        except ValueError:
 
78
        except (ValueError, IndexError):
75
79
            raise BackendException(
76
80
                 "Expected four values to unpack in: swift:%s. "
77
81
                 "Should have received something like: %s."
80
84
        authurl = "https://%s" % '/'.join(path_parts)
81
85
 
82
86
        return user, api_key, authurl, container, file
83
 
 
84