Added test of machine types.
Get, list and aggregatedList operations. Change-Id: I6a07ebefca539162f16451a579360cfbd9519685
This commit is contained in:
parent
2a925757fb
commit
54e55e4b47
@ -53,7 +53,7 @@ REQUIRED_NOVA_API_MICROVERSION = '2.3'
|
||||
_nova_api_version = None
|
||||
|
||||
|
||||
def service_session():
|
||||
def admin_session():
|
||||
auth = keystone_identity.Password(
|
||||
auth_url=CONF.keystone_url,
|
||||
username=CONF.keystone_authtoken['admin_user'],
|
||||
@ -126,8 +126,8 @@ def cinder(context, session=None):
|
||||
return _cinder
|
||||
|
||||
|
||||
def service_keystone(session=None):
|
||||
s = session if session else service_session()
|
||||
def keystone(context, session=None):
|
||||
s = session if session else create_session_for_context(context)
|
||||
client = keystone_client.Client(
|
||||
session=s,
|
||||
auth_url=CONF.keystone_url
|
||||
@ -135,15 +135,6 @@ def service_keystone(session=None):
|
||||
return client
|
||||
|
||||
|
||||
def keystone(context):
|
||||
session = create_session_for_context(context)
|
||||
client = keystone_client.Client(
|
||||
session=session,
|
||||
auth_url=CONF.keystone_url
|
||||
)
|
||||
return client
|
||||
|
||||
|
||||
def url_for(context, service_type):
|
||||
service_catalog = context.service_catalog
|
||||
if not service_catalog:
|
||||
|
@ -40,8 +40,8 @@ class Controller(object):
|
||||
if key in self._files:
|
||||
return self._files[key]
|
||||
|
||||
session = clients.service_session()
|
||||
keystone = clients.service_keystone(session)
|
||||
session = clients.admin_session()
|
||||
keystone = clients.keystone(None, session=session)
|
||||
if not keystone.has_service_catalog():
|
||||
keystone.authenticate(token=session.get_token())
|
||||
catalog = keystone.service_catalog.get_data()
|
||||
|
@ -34,7 +34,7 @@ class Controller(gce_common.Controller):
|
||||
# NOTE(Alex): Is not supported by Openstack
|
||||
"maximumPersistentDisks": 0,
|
||||
# NOTE(Alex): Is not supported by Openstack
|
||||
"maximumPersistentDisksSizeGb": 0,
|
||||
"maximumPersistentDisksSizeGb": '0',
|
||||
}
|
||||
|
||||
if "OS-FLV-EXT-DATA:ephemeral" in flavor:
|
||||
|
@ -32,8 +32,8 @@ class API(base_api.API):
|
||||
return self.KIND
|
||||
|
||||
def get_item(self, context, name, scope=None):
|
||||
session = clients.service_session()
|
||||
keystone = clients.service_keystone(session=session)
|
||||
session = clients.admin_session()
|
||||
keystone = clients.keystone(context, session=session)
|
||||
project = keystone.projects.get(context.project_id)
|
||||
result = utils.to_dict(project)
|
||||
result["keypair"] = self._get_gce_keypair(context)
|
||||
|
@ -29,8 +29,9 @@ class TestDiskTypes(test_base.GCETestCase):
|
||||
@property
|
||||
def disk_types(self):
|
||||
res = self.api.compute.diskTypes()
|
||||
self.assertIsNotNone(res,
|
||||
'Null regions object, api is not built properly')
|
||||
self.assertIsNotNone(
|
||||
res,
|
||||
'Null diskTypes object, api is not built properly')
|
||||
return res
|
||||
|
||||
def setUp(self):
|
||||
|
119
gceapi/tests/functional/api/test_machine_types.py
Normal file
119
gceapi/tests/functional/api/test_machine_types.py
Normal file
@ -0,0 +1,119 @@
|
||||
# Copyright 2015 United States Government as represented by the
|
||||
# Administrator of the National Aeronautics and Space Administration.
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# 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 express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import copy
|
||||
|
||||
from gceapi.tests.functional import test_base
|
||||
|
||||
|
||||
class TestMachineTypes(test_base.GCETestCase):
|
||||
@property
|
||||
def machine_types(self):
|
||||
res = self.api.compute.machineTypes()
|
||||
self.assertIsNotNone(
|
||||
res,
|
||||
'Null machineTypes object, api is not built properly')
|
||||
return res
|
||||
|
||||
def _get_machine_type(self, name):
|
||||
project_id = self.cfg.project_id
|
||||
zone = self.cfg.zone
|
||||
self.trace('Get machine type: project_id={} zone={} name={}'.format(
|
||||
project_id, zone, name))
|
||||
request = self.machine_types.get(project=project_id,
|
||||
zone=zone,
|
||||
machineType=name)
|
||||
result = request.execute()
|
||||
self.trace('Machine type: {}'.format(result))
|
||||
self.api.validate_schema(value=result, schema_name='MachineType')
|
||||
return result
|
||||
|
||||
def _list_machine_types(self, filter=None):
|
||||
project_id = self.cfg.project_id
|
||||
zone = self.cfg.zone
|
||||
self.trace('List machine types: project_id={} zone={} filter={}'.
|
||||
format(project_id, zone, filter))
|
||||
request = self.machine_types.list(project=project_id,
|
||||
zone=zone,
|
||||
filter=filter)
|
||||
result = request.execute()
|
||||
self.trace('Machine types: {}'.format(result))
|
||||
self.api.validate_schema(value=result, schema_name='MachineTypeList')
|
||||
return result
|
||||
|
||||
def _aggregated_list_machine_types(self, filter=None):
|
||||
project_id = self.cfg.project_id
|
||||
self.trace('Aggregated list machine types: project_id={} filter={}'.
|
||||
format(project_id, filter))
|
||||
request = self.machine_types.aggregatedList(project=project_id,
|
||||
filter=filter)
|
||||
result = request.execute()
|
||||
self.trace('Aggregated machine types: {}'.format(result))
|
||||
self.api.validate_schema(value=result,
|
||||
schema_name='MachineTypeAggregatedList')
|
||||
return result
|
||||
|
||||
def _get_expected_machine_type(self, options):
|
||||
mt = copy.deepcopy(options)
|
||||
mt.setdefault('kind', 'compute#machineType')
|
||||
mt.setdefault('id', '[0-9]+')
|
||||
# TODO(alexey-mr): not supported by OS GCE
|
||||
# mt.setdefault('creationTimestamp', '.*')
|
||||
mt.setdefault('description', '.*')
|
||||
mt.setdefault('guestCpus', '[0-9]+')
|
||||
mt.setdefault('memoryMb', '[0-9]+')
|
||||
# not returned by Google by default
|
||||
# mt.setdefault('imageSpaceGb', '[0-9]+')
|
||||
# mt.setdefault('scratchDisks', {})
|
||||
mt.setdefault('maximumPersistentDisks', '[0-9]+')
|
||||
mt.setdefault('maximumPersistentDisksSizeGb', '[0-9]+')
|
||||
zone = mt.get('zone', self.cfg.zone)
|
||||
# TODO(alexey-mr): GCE returns names but OS GCE return full url
|
||||
mt['zone'] = '.*{}'.format(zone)
|
||||
self_link = self.api.get_zone_url(
|
||||
resource='machineTypes/{}'.format(mt['name']),
|
||||
zone=zone)
|
||||
mt.setdefault('selfLink', self_link)
|
||||
return mt
|
||||
|
||||
def test_get_machine_type(self):
|
||||
name = self.cfg.machine_type
|
||||
result = self._get_machine_type(name)
|
||||
expected = self._get_expected_machine_type(options={'name': name})
|
||||
self.assertObject(expected, result)
|
||||
|
||||
def test_list_machine_types(self):
|
||||
name = self.cfg.machine_type
|
||||
result = self._list_machine_types()
|
||||
result = self.assertFind(name, result)
|
||||
expected = self._get_expected_machine_type(options={'name': name})
|
||||
self.assertObject(expected, result)
|
||||
|
||||
def test_aggregated_list_machine_types(self):
|
||||
result = self._aggregated_list_machine_types()
|
||||
self.assertIn('items', result)
|
||||
items = result['items']
|
||||
if len(items) == 0:
|
||||
self.fail('Empty aggregated machine types list')
|
||||
name = self.cfg.machine_type
|
||||
for zone, zone_list in items.items():
|
||||
result = self.assertFind(name, zone_list, key='machineTypes')
|
||||
options = {
|
||||
'name': name,
|
||||
'zone': zone.split('/')[-1]
|
||||
}
|
||||
expected = self._get_expected_machine_type(options)
|
||||
self.assertObject(expected, result)
|
@ -27,7 +27,7 @@ EXPECTED_FLAVORS = [{
|
||||
"memoryMb": 2048,
|
||||
"imageSpaceGb": 20,
|
||||
"maximumPersistentDisks": 0,
|
||||
"maximumPersistentDisksSizeGb": 0,
|
||||
"maximumPersistentDisksSizeGb": "0",
|
||||
"zone": "http://localhost/compute/v1beta15/projects/fake_project"
|
||||
"/zones/nova",
|
||||
"selfLink": "http://localhost/compute/v1beta15/projects/fake_project"
|
||||
@ -43,7 +43,7 @@ EXPECTED_FLAVORS = [{
|
||||
"memoryMb": 8192,
|
||||
"imageSpaceGb": 80,
|
||||
"maximumPersistentDisks": 0,
|
||||
"maximumPersistentDisksSizeGb": 0,
|
||||
"maximumPersistentDisksSizeGb": "0",
|
||||
"zone": "http://localhost/compute/v1beta15/projects/fake_project"
|
||||
"/zones/nova",
|
||||
"selfLink": "http://localhost/compute/v1beta15/projects/fake_project"
|
||||
|
Loading…
x
Reference in New Issue
Block a user