Climate to Blazar in Nova extensions

Renamed Climate to Blazar in the Nova extensions. The tests were renamed
too.

Change-Id: I30940a9096fbc9eedaaa68cb9b859c121a59e71e
Partial-Bug: #1311747
This commit is contained in:
Pablo Andres Fuente 2014-06-18 11:16:19 -03:00
parent cc776e87a8
commit c65c2557fa
5 changed files with 54 additions and 55 deletions

View File

@ -15,8 +15,8 @@
"""
Reservation extension parses instance creation request to find hints referring
to use Climate. If finds, create instance, shelve it not to use compute
capacity while instance is not used and sent lease creation request to Climate.
to use Blazar. If finds, create instance, shelve it not to use compute
capacity while instance is not used and sent lease creation request to Blazar.
"""
import json
@ -24,9 +24,9 @@ import time
import traceback
try:
from climateclient import client as climate_client
from climateclient import client as blazar_client
except ImportError:
climate_client = None
blazar_client = None
from nova.api.openstack import extensions
from nova.api.openstack import wsgi
@ -48,7 +48,7 @@ class ReservationController(wsgi.Controller):
@wsgi.extends
def create(self, req, resp_obj, body):
"""Support Climate usage for Nova VMs."""
"""Support Blazar usage for Nova VMs."""
scheduler_hints = body.get('server', {}).get('scheduler_hints', {})
lease_params = scheduler_hints.get('lease_params')
@ -96,13 +96,13 @@ class ReservationController(wsgi.Controller):
want_objects=True)
time.sleep(1)
# send lease creation request to Climate
# this operation should be last, because otherwise Climate
# send lease creation request to Blazar
# this operation should be last, because otherwise Blazar
# Manager may try unshelve instance when it's still active
climate_cl = self.get_climate_client(service_catalog,
user_roles, auth_token)
lease_transaction.set_params(instance_id, climate_cl, nova_ctx)
lease = climate_cl.lease.create(**lease_params)
blazar_cl = self.get_blazar_client(service_catalog,
user_roles, auth_token)
lease_transaction.set_params(instance_id, blazar_cl, nova_ctx)
lease = blazar_cl.lease.create(**lease_params)
try:
lease_transaction.set_lease_id(lease['id'])
@ -111,40 +111,39 @@ class ReservationController(wsgi.Controller):
_('Lease creation request failed.')
)
def get_climate_client(self, catalog, user_roles, auth_token):
if not climate_client:
raise ImportError(_('No Climate client installed to the '
def get_blazar_client(self, catalog, user_roles, auth_token):
if not blazar_client:
raise ImportError(_('No Blazar client installed to the '
'environment. Please install it to use '
'reservation for Nova instances.'))
climate_endpoints = None
blazar_endpoints = None
for service in catalog:
if service['type'] == 'reservation':
climate_endpoints = service['endpoints'][0]
if not climate_endpoints:
raise exception.NotFound(_('No Climate endpoint found in service '
blazar_endpoints = service['endpoints'][0]
if not blazar_endpoints:
raise exception.NotFound(_('No Blazar endpoint found in service '
'catalog.'))
climate_url = None
blazar_url = None
if 'admin' in user_roles:
climate_url = climate_endpoints.get('adminURL')
if climate_url is None:
climate_url = climate_endpoints.get('publicURL')
if climate_url is None:
raise exception.NotFound(_('No Climate URL found in service '
blazar_url = blazar_endpoints.get('adminURL')
if blazar_url is None:
blazar_url = blazar_endpoints.get('publicURL')
if blazar_url is None:
raise exception.NotFound(_('No Blazar URL found in service '
'catalog.'))
climate_cl = climate_client.Client(climate_url=climate_url,
auth_token=auth_token)
return climate_cl
blazar_cl = blazar_client.Client(climate_url=blazar_url,
auth_token=auth_token)
return blazar_cl
class LeaseTransaction(object):
def __init__(self):
self.lease_id = None
self.instance_id = None
self.climate_cl = None
self.blazar_cl = None
self.nova_ctx = None
def __enter__(self):
@ -157,7 +156,7 @@ class LeaseTransaction(object):
LOG.error(_('Error occurred while lease creation. '
'Traceback: \n%s') % msg)
if self.lease_id:
self.climate_cl.lease.delete(self.lease_id)
self.blazar_cl.lease.delete(self.lease_id)
api = compute.API()
api.delete(self.nova_ctx, api.get(self.nova_ctx, self.instance_id,
@ -166,9 +165,9 @@ class LeaseTransaction(object):
def set_lease_id(self, lease_id):
self.lease_id = lease_id
def set_params(self, instance_id, climate_cl, nova_ctx):
def set_params(self, instance_id, blazar_cl, nova_ctx):
self.instance_id = instance_id
self.climate_cl = climate_cl
self.blazar_cl = blazar_cl
self.nova_ctx = nova_ctx

View File

@ -13,7 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from climatenova.openstack.common import test
from blazarnova.openstack.common import test
class TestCase(test.BaseTestCase):

View File

@ -30,13 +30,13 @@ UUID = fakes.FAKE_UUID
CONF = cfg.CONF
CONF.import_opt('osapi_compute_ext_list', 'nova.api.openstack.compute.contrib')
CONF.import_opt('reservation_start_date',
'climatenova.api.extensions.default_reservation')
'blazarnova.api.extensions.default_reservation')
CONF.import_opt('reservation_length_hours',
'climatenova.api.extensions.default_reservation')
'blazarnova.api.extensions.default_reservation')
CONF.import_opt('reservation_length_days',
'climatenova.api.extensions.default_reservation')
'blazarnova.api.extensions.default_reservation')
CONF.import_opt('reservation_length_minutes',
'climatenova.api.extensions.default_reservation')
'blazarnova.api.extensions.default_reservation')
class InstanceWrapper(object):
@ -61,9 +61,9 @@ class BaseExtensionTestCase(test.TestCase):
self.flags(
osapi_compute_extension=[
'nova.api.openstack.compute.contrib.select_extensions',
'climatenova.api.extensions.default_reservation.'
'blazarnova.api.extensions.default_reservation.'
'Default_reservation',
'climatenova.api.extensions.reservation.Reservation'
'blazarnova.api.extensions.reservation.Reservation'
],
osapi_compute_ext_list=['Scheduler_hints'])

View File

@ -16,28 +16,28 @@
import mock
from nova.openstack.common import jsonutils
from climatenova.tests.api import extensions
from blazarnova.tests.api import extensions
class ClimateDefaultReservationTestCase(extensions.BaseExtensionTestCase):
"""Climate API extensions test case.
class BlazarDefaultReservationTestCase(extensions.BaseExtensionTestCase):
"""Blazar API extensions test case.
This test case provides tests for Default_reservation extension working
together with Reservation extension passing hints to Nova and
sending lease creation request to Climate.
sending lease creation request to Blazar.
"""
def setUp(self):
"""Set up testing environment."""
super(ClimateDefaultReservationTestCase, self).setUp()
super(BlazarDefaultReservationTestCase, self).setUp()
@mock.patch('climatenova.api.extensions.reservation.climate_client')
@mock.patch('blazarnova.api.extensions.reservation.blazar_client')
def test_create_with_default(self, mock_module):
"""Test extension work with default lease parameters."""
mock_module.Client.return_value = self.mock_client
# here we set no Climate related hints, so all lease info should be
# here we set no Blazar related hints, so all lease info should be
# default one - dates got from CONF and auto generated name
body = {
'server': {
@ -63,12 +63,12 @@ class ClimateDefaultReservationTestCase(extensions.BaseExtensionTestCase):
self.assertEqual(202, res.status_int)
@mock.patch('climatenova.api.extensions.reservation.climate_client')
@mock.patch('blazarnova.api.extensions.reservation.blazar_client')
def test_create_with_passed_args(self, mock_module):
"""Test extension work if some lease param would be passed."""
# here we pass non default lease name to Nova
# Default_reservation extension should not rewrite it,
# Reservation extension should pass it to Climate
# Reservation extension should pass it to Blazar
mock_module.Client.return_value = self.mock_client

View File

@ -16,28 +16,28 @@
import mock
from nova.openstack.common import jsonutils
from climatenova.tests.api import extensions
from blazarnova.tests.api import extensions
class ClimateReservationTestCase(extensions.BaseExtensionTestCase):
"""Climate API extensions test case.
class BlazarReservationTestCase(extensions.BaseExtensionTestCase):
"""Blazar API extensions test case.
This test case provides tests for Default_reservation extension working
together with Reservation extension passing hints to Nova and
sending lease creation request to Climate.
sending lease creation request to Blazar.
"""
def setUp(self):
"""Set up testing environment."""
super(ClimateReservationTestCase, self).setUp()
super(BlazarReservationTestCase, self).setUp()
self.flags(
osapi_compute_extension=[
'nova.api.openstack.compute.contrib.select_extensions',
'climatenova.api.extensions.reservation.Reservation'
'blazarnova.api.extensions.reservation.Reservation'
],
osapi_compute_ext_list=['Scheduler_hints'])
@mock.patch('climatenova.api.extensions.reservation.climate_client')
@mock.patch('blazarnova.api.extensions.reservation.blazar_client')
def test_create(self, mock_module):
"""Test extension work with passed lease parameters."""