Merge "Unit Testcases for GCE Glance Driver"

This commit is contained in:
Jenkins 2017-06-13 03:07:16 +00:00 committed by Gerrit Code Review
commit c955bc4a04
6 changed files with 19287 additions and 0 deletions

View File

@ -0,0 +1,20 @@
{
"kind": "compute#image",
"id": "3747888464489608391",
"creationTimestamp": "2017-04-27T12:44:40.850-07:00",
"name": "centos-6-v20170426",
"description": "CentOS, CentOS, 6, x86_64 built on 2017-04-26",
"sourceType": "RAW",
"rawDisk": {
"source": "",
"containerType": "TAR"
},
"status": "READY",
"archiveSizeBytes": "4835135198",
"diskSizeGb": "10",
"licenses": [
"projects/centos-cloud/global/licenses/centos-6"
],
"family": "centos-6",
"selfLink": "projects/centos-cloud/global/images/centos-6-v20170426"
}

View File

@ -0,0 +1,12 @@
{
"type": "service_account",
"project_id": "omni-163105",
"private_key_id": "private_key_id",
"private_key": "-----BEGIN PRIVATE KEY-----\nstringofprivatekey2343\n-----END PRIVATE KEY-----\n",
"client_email": "random_email@developer.gserviceaccount.com",
"client_id": "12345678900987654321",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://accounts.google.com/o/oauth2/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/674783144440-compute%40developer.gserviceaccount.com"
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,33 @@
# Copyright (c) 2017 Platform9 Systems Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either expressed or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import os
from apiclient.http import HttpMock
from googleapiclient.discovery import build
DATA_DIR = os.path.dirname(os.path.abspath(__file__)) + '/data'
def get_gce_service(service_key):
http = HttpMock(DATA_DIR + '/service/service_data.json', {'status': '200'})
service = build('compute', 'v1', http=http, developerKey=service_key)
return service
def get_image(compute, project, name):
http = HttpMock(DATA_DIR + '/image/get_image.json', {'status': '200'})
request = compute.images().get(project=project, image=name)
response = request.execute(http=http)
return response

View File

@ -0,0 +1,68 @@
# Copyright (c) 2017 Platform9 Systems Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either expressed or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import os
import mock
from glance_store import exceptions
from glance_store import location
from glance_store.location import Location
from glance_store._drivers.gce import Store
from glance_store._drivers.gce import StoreLocation
from glance_store.tests.unit.gce import gce_mock
from glance_store.tests import base
from oslo_config import cfg
from oslo_utils import units
DATA_DIR = os.path.dirname(os.path.abspath(__file__)) + '/data'
class GCEGlanceTestCase(base.StoreBaseTest):
@mock.patch('glance_store._drivers.gceutils.get_gce_service')
def setUp(self, mock_service):
mock_service.side_effect = gce_mock.get_gce_service
super(GCEGlanceTestCase, self).setUp()
self.store = Store(cfg.CONF)
self.store.gce_zone = 'us-central1-c'
self.store.gce_project = 'omni-163105'
self.store.gce_svc_key = "{0}/omni.json".format(DATA_DIR)
@mock.patch('glance_store._drivers.gceutils.get_image')
def test_get_size(self, mock_get):
mock_get.side_effect = gce_mock.get_image
store_specs = {
'gce_project': 'omni-163105',
'gce_id': 'fake_gce_id',
'glance_id': 'fake_glance_id'
}
location = Location("gce", StoreLocation, cfg.CONF,
store_specs=store_specs)
size = self.store.get_size(location)
self.assertTrue(isinstance(size, int))
self.assertEqual(size, 10 * units.Gi)
def test_store_location_initialization(self):
location.SCHEME_TO_CLS_MAP["gce"] = {}
location.SCHEME_TO_CLS_MAP['gce']['location_class'] = StoreLocation
uri = "gce://%s/fake_gce_id/fake_glance_id" % (self.store.gce_project)
self.assertTrue(
isinstance(location.get_location_from_uri(uri), Location))
def test_store_location_initialization_with_invalid_url(self):
location.SCHEME_TO_CLS_MAP["scheme"] = {}
location.SCHEME_TO_CLS_MAP['scheme']['location_class'] = StoreLocation
uri = "scheme://%s/fake_gce_id/fake_glance_id" % (
self.store.gce_project)
self.assertRaises(exceptions.BadStoreUri,
location.get_location_from_uri, uri)