Пример #1
0
    def test_snapshot_progress(self):
        client = cinderclient.CinderClient('fake',
                                           'fake',
                                           'http://auth:5000',
                                           'http://cinder:8776',
                                           tenant_id='fake',
                                           rax_auth=False)
        new_progress = "something%"

        def snapshot_progress_request(req):
            expected_url = 'http://cinder:8776/v1/fake/snapshots/snap2/action'
            self.assertEquals(req.get_full_url(), expected_url)
            self.assertEquals(req.get_method(), 'POST')
            data = json.dumps({'os-update_progress': new_progress})
            self.assertEquals(req.data, data)
            expected_headers = {
                'Content-type': 'application/json',
                'X-auth-token': 'fake',
            }
            self.assertEquals(req.headers, expected_headers)
            return MockResponse()

        self.urllib2.responses = iter(
            [_stub_auth_response, snapshot_progress_request])

        client.snapshot_progress('snap2', new_progress)

        self.assert_(snapshot_progress_request.called)
Пример #2
0
    def __init__(self, conf):
        self.volumes = VolumeHelper(conf)
        self.exports = ExportHelper(conf)
        self.backups = BackupHelper(conf)
        self.cgroups = CgroupHelper(conf)
        self.api_server = conf.string('storage', 'api_server',
                                      "http://localhost:8080")
        self.api_retry = conf.int('storage', 'api_retry', 1)

        # name of node registration
        self.name = conf.string('storage', 'name', socket.gethostname())
        self.affinity_group = conf.string('storage', 'affinity_group', '')

        # management interface
        self.management_host = conf.string('server:main', 'host', '0.0.0.0')
        if self.management_host == '0.0.0.0':
            self.management_host = my_ip(self.api_server)
        self.management_port = conf.int('server:main', 'port', 8081)

        # storage interface
        self.storage_host = conf.string('storage', 'host', '127.0.0.1')
        self.storage_port = conf.int('storage', 'port', 3260)
        self.volume_type = conf.string('storage', 'volume_type', 'vtype')

        # cinder
        self.cinder_args = cinderclient.get_args(conf)
        self.rax_auth = conf.bool('cinder', 'rax_auth', True)
        if self.rax_auth:
            self.client = cinderclient.CinderClient(**self.cinder_args)
        self.cinder_host = conf.string('storage', 'cinder_host',
                                       self.management_host)
Пример #3
0
    def test_delete_volume_metadata(self):
        client = cinderclient.CinderClient('fake',
                                           'fake',
                                           'http://auth:5000',
                                           'http://cinder:8776',
                                           tenant_id='fake',
                                           rax_auth=False)

        def metadata_request(req):
            expected_url = 'http://cinder:8776/v1/' \
                           'fake/volumes/volume_id/metadata/key'
            self.assertEquals(req.get_full_url(), expected_url)
            self.assertEquals(req.get_method(), 'DELETE')
            expected_headers = {
                'Content-type': 'application/json',
                'X-auth-token': 'fake',
            }
            self.assertEquals(req.headers, expected_headers)
            return MockResponse()

        self.urllib2.responses = iter([_stub_auth_response, metadata_request])

        client.delete_volume_metadata('volume_id', 'key')

        self.assert_(metadata_request.called)
Пример #4
0
    def test_auth_retry_fails_after_five_attempts(self):
        client = cinderclient.CinderClient('fake',
                                           'fake',
                                           'http://auth:5000',
                                           'http://cinder:8776',
                                           tenant_id='fake',
                                           rax_auth=False)

        def unauthorized_request(req):
            raise urllib2.HTTPError(req.get_full_url(), 401, 'Unauthorized',
                                    {}, StringIO())

        self.urllib2.responses = iter([
            _stub_auth_response,
            unauthorized_request,
            _stub_auth_response,
            unauthorized_request,
            _stub_auth_response,
            unauthorized_request,
            _stub_auth_response,
            unauthorized_request,
            _stub_auth_response,
            unauthorized_request,
        ])
        self.assertRaises(cinderclient.CinderError, client.update, 'volumes',
                          'fake', 'available')
        self.assertEquals(unauthorized_request.count, 5)
Пример #5
0
    def test_auth_retry(self):
        client = cinderclient.CinderClient('fake',
                                           'fake',
                                           'http://auth:5000',
                                           'http://cinder:8776',
                                           tenant_id='fake',
                                           rax_auth=False)

        def unauthorized_request(req):
            raise urllib2.HTTPError(req.get_full_url(), 401, 'Unauthorized',
                                    {}, StringIO())

        def update_request(req):
            return MockResponse()

        self.urllib2.responses = iter(
            [unauthorized_request, _stub_auth_response, update_request])

        # set invalid token
        client.token = 'invalid'
        client.update('volumes', 'fake', 'available')
        self.assert_(unauthorized_request.called)
        self.assert_(update_request.called)
        # new token should be validated
        self.assertEquals(client.token, 'fake')
Пример #6
0
    def test_force_delete_snapshot(self):
        client = cinderclient.CinderClient('fake',
                                           'fake',
                                           'http://auth:5000',
                                           'http://cinder:8776',
                                           tenant_id='fake',
                                           rax_auth=False)

        def force_delete_request(req):
            expected_url = 'http://cinder:8776/v1/fake/snapshots/snap2/action'
            self.assertEquals(req.get_full_url(), expected_url)
            self.assertEquals(req.get_method(), 'POST')
            expected_data = json.dumps({'os-force_delete': {}})
            self.assertEquals(req.data, expected_data)
            expected_headers = {
                'Content-type': 'application/json',
                'X-auth-token': 'fake',
            }
            self.assertEquals(req.headers, expected_headers)
            return MockResponse()

        self.urllib2.responses = iter(
            [_stub_auth_response, force_delete_request])

        client.force_delete('snapshots', 'snap2')

        self.assert_(force_delete_request.called)
Пример #7
0
    def test_update_volume(self):
        client = cinderclient.CinderClient('fake',
                                           'fake',
                                           'http://auth:5000',
                                           'http://cinder:8776',
                                           tenant_id='fake',
                                           rax_auth=False)

        def update_request(req):
            # should be volumes update
            expected_url = 'http://cinder:8776/v1/fake/volumes/vol1/action'
            self.assertEquals(req.get_full_url(), expected_url)
            self.assertEquals(req.get_method(), 'POST')
            expected_data = json.dumps(
                {'os-reset_status': {
                    'status': 'available',
                }})
            self.assertEquals(req.data, expected_data)
            expected_headers = {
                'Content-type': 'application/json',
                'X-auth-token': 'fake',
            }
            self.assertEquals(req.headers, expected_headers)
            return MockResponse()

        self.urllib2.responses = iter([_stub_auth_response, update_request])

        client.update('volumes', 'vol1', 'available')

        self.assert_(update_request.called)
Пример #8
0
    def test_keystone_auth(self):
        client = cinderclient.CinderClient('fake',
                                           'fake',
                                           'http://auth:5000',
                                           'http://cinder:8776',
                                           tenant_id='fake',
                                           rax_auth=False)

        def auth_request(req):
            expected_url = 'http://auth:5000/v2.0/tokens'
            self.assertEquals(req.get_full_url(), expected_url)
            self.assertEquals(req.get_method(), 'POST')
            expected_data = json.dumps({
                'auth': {
                    'passwordCredentials': {
                        'username': '******',
                        'password': '******',
                    },
                    'tenantId': 'fake',
                }
            })
            self.assertEquals(req.data, expected_data)
            expected_headers = {
                'Content-type': 'application/json',
                'Accept': 'application/json',
            }
            self.assertEquals(req.headers, expected_headers)
            return MockResponse({
                'access': {
                    'token': {
                        'id': 'fake',
                        'tenant': {
                            'id': 'fake',
                        }
                    }
                }
            })

        def update_request(req):
            expected_url = 'http://cinder:8776/v1/fake/volumes/fake/action'
            self.assertEquals(req.get_full_url(), expected_url)
            self.assertEquals(req.get_method(), 'POST')
            expected_data = json.dumps(
                {'os-reset_status': {
                    'status': 'available',
                }})
            self.assertEquals(req.data, expected_data)
            expected_headers = {
                'Content-type': 'application/json',
                'X-auth-token': 'fake',
            }
            self.assertEquals(req.headers, expected_headers)
            return MockResponse()

        self.urllib2.responses = iter([auth_request, update_request])

        client.update('volumes', 'fake', 'available')

        self.assert_(auth_request.called)
        self.assert_(update_request.called)
Пример #9
0
 def get_cinder(self, account=None):
     if self.rax_auth:
         return self.client
     else:
         return cinderclient.CinderClient(tenant_id=account,
                                          **self.cinder_args)