Dmitry Tantsur d2d80fa9ef Manage image ID's for node profile
Kernel and ramdisk image ID's are stored for each node profile
in nova keys and should be managed via UI.

Only image ID is displayed in node profile list. Though
somewhat unfriendly, this is better for now than making
2 calls to Glance for every row. Separate node details page
will be introduced in the next patch to fix this issue.

Also this patch introduce abstraction over flavor to ease
writing code specific to node profiles.

Change-Id: Ie76651536e2d8b90e14c9000da0226743db91e88
2014-02-27 06:29:27 -05:00

110 lines
4.2 KiB
Python

# -*- coding: utf8 -*-
#
# 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 contextlib
from django.core import urlresolvers
from mock import patch, call # noqa
from horizon import exceptions
from openstack_dashboard.test.test_data import utils
from tuskar_ui.test import helpers as test
from tuskar_ui.test.test_data import tuskar_data
TEST_DATA = utils.TestDataContainer()
tuskar_data.data(TEST_DATA)
INDEX_URL = urlresolvers.reverse(
'horizon:infrastructure:node_profiles:index')
CREATE_URL = urlresolvers.reverse(
'horizon:infrastructure:node_profiles:create')
@contextlib.contextmanager
def _prepare_create():
flavor = TEST_DATA.novaclient_flavors.first()
all_flavors = TEST_DATA.novaclient_flavors.list()
images = TEST_DATA.glanceclient_images.list()
data = {'name': 'foobar',
'vcpus': 3,
'memory_mb': 1024,
'disk_gb': 40,
'arch': 'amd64',
'kernel_image_id': images[0].id,
'ramdisk_image_id': images[1].id}
with contextlib.nested(
patch('tuskar_ui.api.NodeProfile.create',
return_value=flavor),
patch('openstack_dashboard.api.glance.image_list_detailed',
return_value=(TEST_DATA.glanceclient_images.list(), False)),
# Inherited code calls this directly
patch('openstack_dashboard.api.nova.flavor_list',
return_value=all_flavors),
) as mocks:
yield mocks[0], data
class NodeProfilesTest(test.BaseAdminViewTests):
def test_index(self):
with patch('openstack_dashboard.api.nova.flavor_list',
return_value=TEST_DATA.novaclient_flavors.list()) as mock:
res = self.client.get(INDEX_URL)
self.assertEqual(mock.call_count, 1)
self.assertTemplateUsed(res,
'infrastructure/node_profiles/index.html')
def test_index_recoverable_failure(self):
with patch('openstack_dashboard.api.nova.flavor_list',
side_effect=exceptions.Conflict):
self.client.get(INDEX_URL)
# FIXME(dtantsur): I expected the following to work:
# self.assertMessageCount(error=1, warning=0)
def test_create_get(self):
with patch('openstack_dashboard.api.glance.image_list_detailed',
return_value=([], False)) as mock:
res = self.client.get(CREATE_URL)
self.assertEqual(mock.call_count, 2)
self.assertTemplateUsed(res,
'infrastructure/node_profiles/create.html')
def test_create_get_recoverable_failure(self):
with patch('openstack_dashboard.api.glance.image_list_detailed',
side_effect=exceptions.Conflict):
self.client.get(CREATE_URL)
self.assertMessageCount(error=1, warning=0)
def test_create_post_ok(self):
images = TEST_DATA.glanceclient_images.list()
with _prepare_create() as (create_mock, data):
res = self.client.post(CREATE_URL, data)
self.assertNoFormErrors(res)
self.assertRedirectsNoFollow(res, INDEX_URL)
request = create_mock.call_args_list[0][0][0]
self.assertListEqual(create_mock.call_args_list, [
call(request, name=u'foobar', memory=1024, vcpus=3, disk=40,
cpu_arch='amd64', kernel_image_id=images[0].id,
ramdisk_image_id=images[1].id)
])
def test_create_post_name_exists(self):
flavor = TEST_DATA.novaclient_flavors.first()
with _prepare_create() as (create_mock, data):
data['name'] = flavor.name
res = self.client.post(CREATE_URL, data)
self.assertFormErrors(res)