예제 #1
0
    def test_lookup_id_deleted(self):
        cinder_host = 'cinder_host'
        storage_vol_id = 'storage_vol_id'
        api_vol_id = 'storage_vol_id'

        def mock_make_api_request(resource, data=None, api_server=None):
            query_string = urlparse(resource).query
            params = parse_qs(query_string)
            self.assertEquals(params, {
                'name': [storage_vol_id],
                'cinder_host': [cinder_host]
            })
            volumes = ('[{"id": "%s", "status": "DELETED"},'
                       '{"id": "deleted", "status": "DELETED"}]' % api_vol_id)
            mock_make_api_request.called = True
            return StringIO(volumes)

        mock_make_api_request.called = False

        with patch(utils, 'make_api_request', mock_make_api_request):
            try:
                utils.lookup_id(storage_vol_id, 'unused', cinder_host)
            except HTTPError, e:
                self.assertEquals(e.code, 404)
                self.assertTrue(mock_make_api_request.called)
            else:
예제 #2
0
파일: test_utils.py 프로젝트: audip/lunr
    def test_lookup_id_409(self):
        cinder_host = 'cinder_host'
        storage_vol_id = 'storage_vol_id'

        def mock_make_api_request(resource, data=None, api_server=None):
            query_string = urlparse(resource).query
            params = parse_qs(query_string)
            self.assertEquals(params, {'name': [storage_vol_id],
                                       'cinder_host': [cinder_host]})
            volumes = ('[{"id": "deleting", "status": "DELETING"},'
                       '{"id": "building", "status": "BUILDING"}]')
            mock_make_api_request.called = True
            return StringIO(volumes)
        mock_make_api_request.called = False

        with patch(utils, 'make_api_request', mock_make_api_request):
            try:
                utils.lookup_id(storage_vol_id, 'unused', cinder_host)
            except HTTPError, e:
                self.assertEquals(e.code, 409)
                self.assertTrue(mock_make_api_request.called)
            else:
예제 #3
0
파일: test_utils.py 프로젝트: audip/lunr
    def test_lookup_id(self):
        cinder_host = 'cinder_host'
        storage_vol_id = 'storage_vol_id'
        api_vol_id = 'storage_vol_id'

        def mock_make_api_request(resource, api_server=None):
            query_string = urlparse(resource).query
            params = parse_qs(query_string)
            self.assertEquals(params, {'name': [storage_vol_id],
                                       'cinder_host': [cinder_host]})
            volumes = ('[{"id": "%s", "status": "ACTIVE"},'
                       '{"id": "deleted", "status": "DELETED"}]' % api_vol_id)
            mock_make_api_request.called = True
            return StringIO(volumes)
        mock_make_api_request.called = False

        with patch(utils, 'make_api_request', mock_make_api_request):
            lookup_id = utils.lookup_id(storage_vol_id, 'unused', cinder_host)

        self.assertTrue(mock_make_api_request.called)
        self.assertEquals(lookup_id, api_vol_id)