Add mock api calls to the UI

This is an introductory commit that adds expected API
calls to tuskar-ui and has them return test data.  It
is intended as a base to allow further discussion, as
well as allow parallel development on the UI side and
API side.

There are many questions raised by this patch - for
example:

* what are the parameters of the tuskarclient api?
* can Ironic create a Node with a single api call?
* etc

But those fall out of scope of this particular patch,
and will be resolved in later patches.

Change-Id: I1273c8738b760ff36d5ad21e3982beb10457c011
This commit is contained in:
Tzu-Mainn Chen 2013-12-17 01:07:19 -05:00
parent 68836f4b35
commit 50b1ac52ee
10 changed files with 403 additions and 1677 deletions

View File

@ -20,4 +20,5 @@ pytz>=2010h
# for SECURE_KEY generation # for SECURE_KEY generation
lockfile>=0.8 lockfile>=0.8
python-ironicclient>=0.1.0
-e git://github.com/openstack/python-tuskarclient.git#egg=python-tuskarclient -e git://github.com/openstack/python-tuskarclient.git#egg=python-tuskarclient

File diff suppressed because it is too large Load Diff

View File

@ -16,6 +16,7 @@ from django.core import urlresolvers
from mock import patch # noqa from mock import patch # noqa
from tuskar_ui import api
from tuskar_ui.test import helpers as test from tuskar_ui.test import helpers as test
@ -30,9 +31,10 @@ class FreeNodesTests(test.BaseAdminViewTests):
super(FreeNodesTests, self).setUp() super(FreeNodesTests, self).setUp()
def test_index(self): def test_index(self):
free_nodes = self.baremetal_nodes.list() free_nodes = [api.Node(node)
for node in self.ironicclient_nodes.list()]
with patch('tuskar_ui.api.BaremetalNode', **{ with patch('tuskar_ui.api.Node', **{
'spec_set': ['list'], # Only allow these attributes 'spec_set': ['list'], # Only allow these attributes
'list.return_value': free_nodes, 'list.return_value': free_nodes,
}) as mock: }) as mock:
@ -46,7 +48,7 @@ class FreeNodesTests(test.BaseAdminViewTests):
free_nodes) free_nodes)
def test_index_nodes_list_exception(self): def test_index_nodes_list_exception(self):
with patch('tuskar_ui.api.BaremetalNode', **{ with patch('tuskar_ui.api.Node', **{
'spec_set': ['list'], 'spec_set': ['list'],
'list.side_effect': self.exceptions.tuskar, 'list.side_effect': self.exceptions.tuskar,
}) as mock: }) as mock:

View File

@ -28,9 +28,7 @@ class IndexView(horizon_tables.DataTableView):
def get_data(self): def get_data(self):
try: try:
# TODO(Jiri Tomasek): needs update when filtering by node type is free_nodes = tuskar.Node.list(self.request, associated=False)
# available
free_nodes = tuskar.BaremetalNode.list(self.request)
except Exception: except Exception:
free_nodes = [] free_nodes = []
redirect = urlresolvers.reverse( redirect = urlresolvers.reverse(

View File

@ -16,6 +16,7 @@ from django.core import urlresolvers
from mock import patch # noqa from mock import patch # noqa
from tuskar_ui import api
from tuskar_ui.test import helpers as test from tuskar_ui.test import helpers as test
@ -30,9 +31,10 @@ class ResourceNodesTests(test.BaseAdminViewTests):
super(ResourceNodesTests, self).setUp() super(ResourceNodesTests, self).setUp()
def test_index(self): def test_index(self):
resource_nodes = self.baremetal_nodes.list() resource_nodes = [api.Node(node)
for node in self.ironicclient_nodes.list()]
with patch('tuskar_ui.api.BaremetalNode', **{ with patch('tuskar_ui.api.Node', **{
'spec_set': ['list'], # Only allow these attributes 'spec_set': ['list'], # Only allow these attributes
'list.return_value': resource_nodes, 'list.return_value': resource_nodes,
}) as mock: }) as mock:
@ -47,7 +49,7 @@ class ResourceNodesTests(test.BaseAdminViewTests):
resource_nodes) resource_nodes)
def test_index_nodes_list_exception(self): def test_index_nodes_list_exception(self):
with patch('tuskar_ui.api.BaremetalNode', **{ with patch('tuskar_ui.api.Node', **{
'spec_set': ['list'], 'spec_set': ['list'],
'list.side_effect': self.exceptions.tuskar, 'list.side_effect': self.exceptions.tuskar,
}) as mock: }) as mock:

View File

@ -28,9 +28,7 @@ class IndexView(horizon_tables.DataTableView):
def get_data(self): def get_data(self):
try: try:
# TODO(Jiri Tomasek): needs update when filtering by node type is resource_nodes = tuskar.Node.list(self.request, associated=True)
# available
resource_nodes = tuskar.BaremetalNode.list(self.request)
except Exception: except Exception:
resource_nodes = [] resource_nodes = []
redirect = urlresolvers.reverse( redirect = urlresolvers.reverse(

View File

@ -12,21 +12,36 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
from django.template import defaultfilters as filters
from django.utils.translation import ugettext_lazy as _ # noqa from django.utils.translation import ugettext_lazy as _ # noqa
from horizon import tables from horizon import tables
class NodesTable(tables.DataTable): class NodesTable(tables.DataTable):
service_host = tables.Column(
"service_host", uuid = tables.Column("uuid",
verbose_name=_("Service Host"), verbose_name=_("UUID"))
link=("horizon:infrastructure:resources.management:detail")) mac_addresses = tables.Column("addresses",
mac_address = tables.Column("mac_address", verbose_name=_("MAC Address")) verbose_name=_("MAC Addresses"),
pm_address = tables.Column("pm_address", wrap_list=True,
verbose_name=_("Management Address")) filters=(filters.unordered_list,))
status = tables.Column("status", verbose_name=_("Status")) ipmi_address = tables.Column(lambda node: node.driver_info['ipmi_address'],
usage = tables.Column("usage", verbose_name=_("Usage")) verbose_name=_("IPMI Address"))
cpu = tables.Column(lambda node: node.properties['cpu'],
verbose_name=_("CPU"))
ram = tables.Column(lambda node: node.properties['ram'],
verbose_name=_("RAM (GB)"))
local_disk = tables.Column(lambda node: node.properties['local_disk'],
verbose_name=_("Local Disk (TB)"))
status = tables.Column("power_state",
verbose_name=_("Status"),
status=True,
status_choices=(
('on', True),
('off', False),
('rebooting', None)
))
class Meta: class Meta:
name = "nodes_table" name = "nodes_table"
@ -34,5 +49,8 @@ class NodesTable(tables.DataTable):
table_actions = () table_actions = ()
row_actions = () row_actions = ()
def get_object_id(self, datum):
return datum.uuid
def get_object_display(self, datum): def get_object_display(self, datum):
return datum.service_host return datum.uuid

View File

@ -14,735 +14,14 @@
from __future__ import absolute_import from __future__ import absolute_import
from novaclient.v1_1.contrib import baremetal # TODO(Tzu-Mainn Chen): uncomment once we add API tests
#from tuskar_ui import api
from tuskar_ui import api
from tuskar_ui.test import helpers as test from tuskar_ui.test import helpers as test
class TuskarApiTests(test.APITestCase): class TuskarAPITests(test.APITestCase):
def test_baremetal_node_create(self): def setUp(self):
baremetal_node = self.baremetalclient_nodes.first() super(TuskarAPITests, self).setUp()
self.mox.StubOutWithMock(baremetal.BareMetalNodeManager, 'create') # to be written!
baremetal.BareMetalNodeManager.create(
'node',
1,
1024,
10,
'aa:bb:cc:dd:ee:ff',
'0.0.0.0',
'user',
'password',
0).AndReturn(baremetal_node)
self.mox.ReplayAll()
ret_val = api.BaremetalNode.create(
self.request,
service_host='node',
cpus=1,
memory_mb=1024,
local_gb=10,
prov_mac_address='aa:bb:cc:dd:ee:ff',
pm_address='0.0.0.0',
pm_user='user',
pm_password='password',
terminal_port=0)
self.assertIsInstance(ret_val, api.BaremetalNode)
def test_baremetal_node_create_with_empty_pm(self):
"""Make sure that when pm_address, pm_user and terminal_port are not
provided (empty), their values are set to None, as this is required by
the baremetal VM.
"""
baremetal_node = self.baremetalclient_nodes.first()
self.mox.StubOutWithMock(baremetal.BareMetalNodeManager, 'create')
baremetal.BareMetalNodeManager.create(
'node', 1, 1024, 10,
'AA:BB:CC:DD:EE:FF',
None, None, '', None).AndReturn(baremetal_node)
self.mox.ReplayAll()
ret_val = api.BaremetalNode.create(
self.request, service_host='node', cpus=1,
memory_mb=1024, local_gb=10, prov_mac_address='AA:BB:CC:DD:EE:FF',
pm_address='', pm_user='', pm_password='', terminal_port='')
self.assertIsInstance(ret_val, api.BaremetalNode)
def test_baremetal_node_get(self):
baremetal_node = self.baremetalclient_nodes.first()
server = self.servers.first()
self.mox.StubOutWithMock(baremetal.BareMetalNodeManager, 'get')
baremetal.BareMetalNodeManager.get(
baremetal_node.id).AndReturn(baremetal_node)
novaclient = self.stub_novaclient()
novaclient.servers = self.mox.CreateMockAnything()
novaclient.servers.get(baremetal_node.instance_uuid).AndReturn(server)
self.mox.ReplayAll()
ret_val = api.BaremetalNode.get(self.request, baremetal_node.id)
self.assertIsInstance(ret_val, api.BaremetalNode)
def test_baremetal_node_list(self):
baremetal_nodes = self.baremetalclient_nodes_all.list()
self.mox.StubOutWithMock(baremetal.BareMetalNodeManager, 'list')
baremetal.BareMetalNodeManager.list().AndReturn(baremetal_nodes)
self.mox.ReplayAll()
ret_val = api.BaremetalNode.list(self.request)
for baremetal_node in ret_val:
self.assertIsInstance(baremetal_node, api.BaremetalNode)
def test_baremetal_node_list_unracked(self):
tuskarclient_nodes = self.tuskarclient_nodes.list()
baremetal_nodes = self.baremetalclient_nodes_all.list()
tuskarclient = self.stub_tuskarclient()
tuskarclient.nodes = self.mox.CreateMockAnything()
tuskarclient.nodes.list().AndReturn(tuskarclient_nodes)
self.mox.StubOutWithMock(baremetal.BareMetalNodeManager, 'list')
baremetal.BareMetalNodeManager.list().AndReturn(baremetal_nodes)
self.mox.ReplayAll()
ret_val = api.BaremetalNode.list_unracked(self.request)
for baremetal_node in ret_val:
self.assertIsInstance(baremetal_node, api.BaremetalNode)
self.assertEquals(1, len(ret_val))
def test_baremetal_node_running_instances(self):
baremetal_node = self.baremetal_nodes.first()
self.assertEquals(4, baremetal_node.running_instances)
def test_baremetal_node_remaining_capacity(self):
baremetal_node = self.baremetal_nodes.first()
self.assertEquals(96, baremetal_node.remaining_capacity)
def test_node_get(self):
tuskar_node = self.tuskarclient_nodes.first()
tuskarclient = self.stub_tuskarclient()
tuskarclient.nodes = self.mox.CreateMockAnything()
tuskarclient.nodes.get(tuskar_node.id).AndReturn(tuskar_node)
self.mox.ReplayAll()
ret_val = api.TuskarNode.get(self.request, tuskar_node.id)
self.assertIsInstance(ret_val, api.TuskarNode)
def test_node_list(self):
tuskarclient_nodes = self.tuskarclient_nodes.list()
tuskarclient = self.stub_tuskarclient()
tuskarclient.nodes = self.mox.CreateMockAnything()
tuskarclient.nodes.list().AndReturn(tuskarclient_nodes)
self.mox.ReplayAll()
ret_val = api.TuskarNode.list(self.request)
for tuskar_node in ret_val:
self.assertIsInstance(tuskar_node, api.TuskarNode)
def test_node_remove_from_rack(self):
tuskar_nodes = self.tuskar_nodes.list()
tuskar_node = tuskar_nodes[0]
rack = self.tuskar_racks.first()
self.mox.StubOutWithMock(api.Rack, 'get')
self.mox.StubOutWithMock(api.Rack, 'update')
self.mox.StubOutWithMock(api.Rack, 'list_tuskar_nodes')
api.Rack.get(self.request, rack.id).AndReturn(rack)
api.Rack.list_tuskar_nodes = tuskar_nodes
api.Rack.update(self.request, rack.id, {
'baremetal_nodes': [{'id': t_node.nova_baremetal_node_id}
for t_node in tuskar_nodes
if t_node.id != tuskar_node.id],
}).AndReturn(rack)
self.mox.ReplayAll()
tuskar_node.request = self.request
rack.request = self.request
tuskar_node.remove_from_rack(self.request)
def test_node_rack(self):
tuskar_node = self.tuskar_nodes.first()
rack = self.tuskarclient_racks.first()
tuskarclient = self.stub_tuskarclient()
tuskarclient.racks = self.mox.CreateMockAnything()
tuskarclient.racks.get(rack.id).AndReturn(rack)
self.mox.ReplayAll()
tuskar_node.request = self.request
self.assertIsInstance(tuskar_node.rack, api.Rack)
self.assertEquals('1', tuskar_node.rack_id)
def test_node_nova_baremetal_node(self):
tuskar_node = self.tuskar_nodes.first()
bm_node = self.baremetalclient_nodes.first()
self.mox.StubOutWithMock(baremetal.BareMetalNodeManager, 'get')
baremetal.BareMetalNodeManager.get(
tuskar_node.nova_baremetal_node_id).AndReturn(bm_node)
novaclient = self.stub_novaclient()
novaclient.servers = self.mox.CreateMockAnything()
novaclient.servers.list(True,
{'all_tenants': True,
'limit': 21}).AndReturn([])
self.mox.ReplayAll()
tuskar_node.request = self.request
baremetal_node = tuskar_node.nova_baremetal_node
self.assertIsInstance(baremetal_node, api.BaremetalNode)
self.assertEquals('11', baremetal_node.id)
def test_node_flavors(self):
tuskar_node = self.tuskar_nodes.first()
rack = self.tuskarclient_racks.first()
rc = self.tuskarclient_resource_classes.first()
flavors = self.tuskarclient_flavors.list()
tuskarclient = self.stub_tuskarclient()
tuskarclient.racks = self.mox.CreateMockAnything()
tuskarclient.racks.get(rack.id).AndReturn(rack)
tuskarclient.resource_classes = self.mox.CreateMockAnything()
tuskarclient.resource_classes.get(rc.id).AndReturn(rc)
tuskarclient.flavors = self.mox.CreateMockAnything()
tuskarclient.flavors.list(rc.id).AndReturn(flavors)
self.mox.ReplayAll()
tuskar_node.request = self.request
ret_val = tuskar_node.list_flavors
for flavor in ret_val:
self.assertIsInstance(flavor, api.Flavor)
self.assertEquals(2, len(ret_val))
def test_node_is_provisioned(self):
tuskar_node = self.tuskar_nodes.first()
tuskar_node.request = self.request
bm_node = self.baremetalclient_nodes.first()
self.mox.StubOutWithMock(baremetal.BareMetalNodeManager, 'get')
baremetal.BareMetalNodeManager.get(
tuskar_node.nova_baremetal_node_id).AndReturn(bm_node)
novaclient = self.stub_novaclient()
novaclient.servers = self.mox.CreateMockAnything()
novaclient.servers.list(True,
{'all_tenants': True,
'limit': 21}).AndReturn([])
self.mox.ReplayAll()
self.assertFalse(tuskar_node.is_provisioned)
def test_node_alerts(self):
tuskar_node = self.tuskar_nodes.first()
self.assertEquals([], tuskar_node.alerts)
def test_resource_class_list(self):
rcs = self.tuskarclient_resource_classes.list()
tuskarclient = self.stub_tuskarclient()
tuskarclient.resource_classes = self.mox.CreateMockAnything()
tuskarclient.resource_classes.list().AndReturn(rcs)
self.mox.ReplayAll()
ret_val = api.ResourceClass.list(self.request)
for rc in ret_val:
self.assertIsInstance(rc, api.ResourceClass)
def test_resource_class_get(self):
rc = self.tuskarclient_resource_classes.first()
tuskarclient = self.stub_tuskarclient()
tuskarclient.resource_classes = self.mox.CreateMockAnything()
tuskarclient.resource_classes.get(rc.id).AndReturn(rc)
self.mox.ReplayAll()
ret_val = api.ResourceClass.get(self.request, rc.id)
self.assertIsInstance(ret_val, api.ResourceClass)
def test_resource_class_create(self):
rc = self.tuskarclient_resource_classes.first()
tuskarclient = self.stub_tuskarclient()
tuskarclient.resource_classes = self.mox.CreateMockAnything()
tuskarclient.resource_classes.create(name='rclass1',
service_type='compute',
image_id=None,
flavors=[]).AndReturn(rc)
self.mox.ReplayAll()
ret_val = api.ResourceClass.create(self.request,
name='rclass1',
service_type='compute',
image_id=None,
flavors=[])
self.assertIsInstance(ret_val, api.ResourceClass)
def test_resource_class_update(self):
rc = self.tuskarclient_resource_classes.first()
tuskarclient = self.stub_tuskarclient()
tuskarclient.resource_classes = self.mox.CreateMockAnything()
tuskarclient.flavors = self.mox.CreateMockAnything()
tuskarclient.resource_classes.update(rc.id,
name='rclass1',
service_type='compute',
image_id=None,
flavors=[]).AndReturn(rc)
tuskarclient.flavors.list(rc.id).AndReturn([])
self.mox.ReplayAll()
ret_val = api.ResourceClass.update(self.request, rc.id,
name='rclass1',
service_type='compute',
image_id=None,
flavors=[])
self.assertIsInstance(ret_val, api.ResourceClass)
def test_resource_class_delete(self):
rc = self.tuskarclient_resource_classes.first()
tuskarclient = self.stub_tuskarclient()
tuskarclient.resource_classes = self.mox.CreateMockAnything()
tuskarclient.resource_classes.delete(rc.id)
self.mox.ReplayAll()
api.ResourceClass.delete(self.request, rc.id)
def test_resource_class_deletable(self):
rc = self.tuskar_resource_classes.first()
self.assertFalse(rc.deletable)
def test_resource_class_racks(self):
rc = self.tuskar_resource_classes.first()
racks = self.tuskarclient_racks.list()
tuskarclient = self.stub_tuskarclient()
tuskarclient.racks = self.mox.CreateMockAnything()
tuskarclient.racks.get('1').AndReturn(racks[0])
tuskarclient.racks.get('2').AndReturn(racks[1])
self.mox.ReplayAll()
for rack in rc.list_racks:
self.assertIsInstance(rack, api.Rack)
self.assertEquals(2, rc.racks_count)
def test_resource_class_all_racks(self):
rc = self.tuskar_resource_classes.first()
racks = self.tuskarclient_racks.list()
tuskarclient = self.stub_tuskarclient()
tuskarclient.racks = self.mox.CreateMockAnything()
tuskarclient.racks.list().AndReturn(racks)
self.mox.ReplayAll()
all_racks = rc.all_racks
for rack in all_racks:
self.assertIsInstance(rack, api.Rack)
self.assertEquals(3, len(all_racks))
def test_resource_class_racks_set(self):
rc = self.tuskar_resource_classes.first()
racks = self.tuskarclient_racks.list()
rack_ids = [rack.id for rack in racks]
rack_data = [{'id': rack_id} for rack_id in rack_ids]
tuskarclient = self.stub_tuskarclient()
tuskarclient.resource_classes = self.mox.CreateMockAnything()
tuskarclient.resource_classes.update(rc.id,
racks=[])
tuskarclient.resource_classes.update(rc.id,
racks=rack_data)
self.mox.ReplayAll()
rc.set_racks(self.request, rack_ids)
def test_resource_class_nodes(self):
rc = self.tuskar_resource_classes.first()
tuskar_nodes = self.tuskarclient_nodes.list()
tuskarclient = self.stub_tuskarclient()
tuskarclient.nodes = self.mox.CreateMockAnything()
tuskarclient.nodes.list().AndReturn(tuskar_nodes)
self.mox.ReplayAll()
rc.request = self.request
for tuskar_node in rc.tuskar_nodes:
self.assertIsInstance(tuskar_node, api.TuskarNode)
self.assertEquals(4, rc.nodes_count)
def test_resource_class_flavors(self):
rc = self.tuskar_resource_classes.first()
flavors = self.tuskarclient_flavors.list()
tuskarclient = self.stub_tuskarclient()
tuskarclient.flavors = self.mox.CreateMockAnything()
tuskarclient.flavors.list(rc.id).AndReturn(flavors)
self.mox.ReplayAll()
for f in rc.list_flavors:
self.assertIsInstance(f, api.Flavor)
self.assertEquals(2, len(rc.flavors_ids))
def test_resource_class_capacities(self):
rc = self.tuskar_resource_classes.first()
racks = self.tuskarclient_racks.list()
tuskarclient = self.stub_tuskarclient()
tuskarclient.racks = self.mox.CreateMockAnything()
tuskarclient.racks.get('1').AndReturn(racks[0])
tuskarclient.racks.get('2').AndReturn(racks[1])
self.mox.ReplayAll()
for capacity in rc.capacities:
self.assertIsInstance(capacity, api.Capacity)
self.assertEquals(2, len(rc.capacities))
def test_resource_class_total_instances(self):
rc = self.tuskar_resource_classes.first()
flavors = self.tuskarclient_flavors.list()
tuskarclient = self.stub_tuskarclient()
tuskarclient.flavors = self.mox.CreateMockAnything()
tuskarclient.flavors.list(rc.id).AndReturn(flavors)
self.mox.ReplayAll()
self.assertEquals(15, rc.total_instances)
def test_resource_class_remaining_capacity(self):
rc = self.tuskar_resource_classes.first()
flavors = self.tuskarclient_flavors.list()
tuskarclient = self.stub_tuskarclient()
tuskarclient.flavors = self.mox.CreateMockAnything()
tuskarclient.flavors.list(rc.id).AndReturn(flavors)
self.mox.ReplayAll()
self.assertEquals(85, rc.remaining_capacity)
def test_resource_class_vm_capacity(self):
rc = self.tuskar_resource_classes.first()
flavors = self.tuskarclient_flavors.list()
tuskarclient = self.stub_tuskarclient()
tuskarclient.flavors = self.mox.CreateMockAnything()
tuskarclient.flavors.list(rc.id).AndReturn(flavors)
self.mox.ReplayAll()
vm_capacity = rc.vm_capacity
self.assertIsInstance(vm_capacity, api.Capacity)
self.assertEquals(200, vm_capacity.value)
def test_resource_class_has_provisioned_rack(self):
rc1 = self.tuskar_resource_classes.list()[0]
rc2 = self.tuskar_resource_classes.list()[1]
racks = self.tuskarclient_racks.list()
tuskarclient = self.stub_tuskarclient()
tuskarclient.racks = self.mox.CreateMockAnything()
tuskarclient.racks.get('1').AndReturn(racks[0])
tuskarclient.racks.get('2').AndReturn(racks[1])
self.mox.ReplayAll()
self.assertTrue(rc1.has_provisioned_rack)
self.assertFalse(rc2.has_provisioned_rack)
def test_resource_class_aggregated_alerts(self):
rc = self.tuskar_resource_classes.list()[0]
rc.request = self.request
tuskar_nodes = self.tuskarclient_nodes.list()
tuskarclient = self.stub_tuskarclient()
tuskarclient.racks = self.mox.CreateMockAnything()
racks = self.tuskarclient_racks.list()
tuskarclient.racks.get('1').AndReturn(racks[0])
tuskarclient.racks.get('2').AndReturn(racks[1])
tuskarclient.nodes = self.mox.CreateMockAnything()
for tuskar_node in tuskar_nodes:
tuskarclient.nodes.get(tuskar_node.id).AndReturn(tuskar_node)
self.mox.ReplayAll()
for rack in rc.aggregated_alerts:
self.assertIsInstance(rack, api.Rack)
self.assertEquals(0, len(rc.aggregated_alerts))
def test_rack_list(self):
racks = self.tuskarclient_racks.list()
tuskarclient = self.stub_tuskarclient()
tuskarclient.racks = self.mox.CreateMockAnything()
tuskarclient.racks.list().AndReturn(racks)
self.mox.ReplayAll()
ret_val = api.Rack.list(self.request)
for rack in ret_val:
self.assertIsInstance(rack, api.Rack)
def test_rack_get(self):
rack = self.tuskarclient_racks.first()
tuskarclient = self.stub_tuskarclient()
tuskarclient.racks = self.mox.CreateMockAnything()
tuskarclient.racks.get(rack.id).AndReturn(rack)
self.mox.ReplayAll()
ret_val = api.Rack.get(self.request, rack.id)
self.assertIsInstance(ret_val, api.Rack)
def test_rack_create(self):
rack = self.tuskarclient_racks.first()
tuskarclient = self.stub_tuskarclient()
tuskarclient.racks = self.mox.CreateMockAnything()
tuskarclient.racks.create(name='rack1',
location='location',
subnet='192.168.1.0/24',
nodes=[],
resource_class={'id': 1},
slots=0).AndReturn(rack)
self.mox.ReplayAll()
ret_val = api.Rack.create(request=self.request,
name='rack1',
resource_class_id=1,
location='location',
subnet='192.168.1.0/24')
self.assertIsInstance(ret_val, api.Rack)
def test_rack_update(self):
rack = self.tuskarclient_racks.first()
tuskarclient = self.stub_tuskarclient()
tuskarclient.racks = self.mox.CreateMockAnything()
tuskarclient.racks.update(rack.id,
name='rack1').AndReturn(rack)
self.mox.ReplayAll()
ret_val = api.Rack.update(self.request,
rack.id,
{'name': 'rack1'})
self.assertIsInstance(ret_val, api.Rack)
def test_rack_delete(self):
rack = self.tuskarclient_racks.first()
tuskarclient = self.stub_tuskarclient()
tuskarclient.racks = self.mox.CreateMockAnything()
tuskarclient.racks.delete(rack.id)
self.mox.ReplayAll()
api.Rack.delete(self.request, rack.id)
def test_rack_nodes(self):
rack = self.tuskar_racks.first()
tuskar_nodes = self.tuskarclient_nodes.list()
tuskarclient = self.stub_tuskarclient()
tuskarclient.nodes = self.mox.CreateMockAnything()
for tuskar_node in tuskar_nodes:
tuskarclient.nodes.get(tuskar_node.id).AndReturn(tuskar_node)
self.mox.ReplayAll()
rack.request = self.request
for tuskar_node in rack.list_tuskar_nodes:
self.assertIsInstance(tuskar_node, api.TuskarNode)
self.assertEquals(4, len(rack.tuskar_node_ids))
self.assertEquals(4, rack.nodes_count)
def test_rack_resource_class(self):
rc = self.tuskarclient_resource_classes.first()
rack = self.tuskar_racks.first()
tuskarclient = self.stub_tuskarclient()
tuskarclient.resource_classes = self.mox.CreateMockAnything()
tuskarclient.resource_classes.get(rc.id).AndReturn(rc)
self.mox.ReplayAll()
self.assertIsInstance(rack.resource_class, api.ResourceClass)
self.assertEquals(rack.resource_class_id, '1')
def test_rack_capacities(self):
rack = self.tuskar_racks.first()
for capacity in rack.list_capacities:
self.assertIsInstance(capacity, api.Capacity)
self.assertEquals(2, len(rack.capacities))
def test_rack_vm_capacity(self):
rack = self.tuskar_racks.first()
rc = self.tuskarclient_resource_classes.first()
flavors = self.tuskarclient_flavors.list()
tuskarclient = self.stub_tuskarclient()
tuskarclient.resource_classes = self.mox.CreateMockAnything()
tuskarclient.resource_classes.get(rc.id).AndReturn(rc)
tuskarclient.flavors = self.mox.CreateMockAnything()
tuskarclient.flavors.list(rc.id).AndReturn(flavors)
self.mox.ReplayAll()
vm_capacity = rack.vm_capacity
self.assertIsInstance(vm_capacity, api.Capacity)
self.assertEquals(100, vm_capacity.value)
def test_rack_flavors(self):
rack = self.tuskar_racks.first()
rc = self.tuskarclient_resource_classes.first()
flavors = self.tuskarclient_flavors.list()
tuskarclient = self.stub_tuskarclient()
tuskarclient.resource_classes = self.mox.CreateMockAnything()
tuskarclient.resource_classes.get(rc.id).AndReturn(rc)
tuskarclient.flavors = self.mox.CreateMockAnything()
tuskarclient.flavors.list(rc.id).AndReturn(flavors)
self.mox.ReplayAll()
rack_flavors = rack.list_flavors
for f in rack_flavors:
self.assertIsInstance(f, api.Flavor)
self.assertEquals(2, len(rack_flavors))
def test_rack_total_instances(self):
rack = self.tuskar_racks.first()
rc = self.tuskarclient_resource_classes.first()
flavors = self.tuskarclient_flavors.list()
tuskarclient = self.stub_tuskarclient()
tuskarclient.resource_classes = self.mox.CreateMockAnything()
tuskarclient.resource_classes.get(rc.id).AndReturn(rc)
tuskarclient.flavors = self.mox.CreateMockAnything()
tuskarclient.flavors.list(rc.id).AndReturn(flavors)
self.mox.ReplayAll()
self.assertEquals(6, rack.total_instances)
def test_rack_remaining_capacity(self):
rack = self.tuskar_racks.first()
rc = self.tuskarclient_resource_classes.first()
flavors = self.tuskarclient_flavors.list()
tuskarclient = self.stub_tuskarclient()
tuskarclient.resource_classes = self.mox.CreateMockAnything()
tuskarclient.resource_classes.get(rc.id).AndReturn(rc)
tuskarclient.flavors = self.mox.CreateMockAnything()
tuskarclient.flavors.list(rc.id).AndReturn(flavors)
self.mox.ReplayAll()
self.assertEquals(94, rack.remaining_capacity)
def test_rack_is_provisioned(self):
rack1 = self.tuskar_racks.list()[0]
rack2 = self.tuskar_racks.list()[1]
self.assertTrue(rack1.is_provisioned)
self.assertFalse(rack2.is_provisioned)
def test_rack_is_provisioning(self):
rack1 = self.tuskar_racks.list()[0]
rack2 = self.tuskar_racks.list()[1]
self.assertFalse(rack1.is_provisioning)
self.assertTrue(rack2.is_provisioning)
def test_rack_provision(self):
tuskarclient = self.stub_tuskarclient()
tuskarclient.data_centers = self.mox.CreateMockAnything()
tuskarclient.data_centers.provision_all()
self.mox.ReplayAll()
api.Rack.provision_all(self.request)
def test_rack_aggregated_alerts(self):
rack = self.tuskar_racks.first()
rack.request = self.request
tuskar_nodes = self.tuskarclient_nodes.list()
tuskarclient = self.stub_tuskarclient()
tuskarclient.nodes = self.mox.CreateMockAnything()
for tuskar_node in tuskar_nodes:
tuskarclient.nodes.get(tuskar_node.id).AndReturn(tuskar_node)
self.mox.ReplayAll()
for tuskar_node in rack.aggregated_alerts:
self.assertIsInstance(tuskar_node, api.TuskarNode)
self.assertEquals(0, len(rack.aggregated_alerts))
def test_flavor_create(self):
flavor = self.tuskarclient_flavors.first()
tuskarclient = self.stub_tuskarclient()
tuskarclient.flavors = self.mox.CreateMockAnything()
tuskarclient.flavors.create(1,
name='nano',
max_vms=100,
capacities=[]).AndReturn(flavor)
self.mox.ReplayAll()
ret_val = api.Flavor.create(self.request,
resource_class_id=1,
name='nano',
max_vms=100,
capacities=[])
self.assertIsInstance(ret_val, api.Flavor)
def test_flavor_delete(self):
rc = self.tuskarclient_resource_classes.first()
flavor = self.tuskarclient_flavors.first()
tuskarclient = self.stub_tuskarclient()
tuskarclient.flavors = self.mox.CreateMockAnything()
tuskarclient.flavors.delete(rc.id, flavor.id)
self.mox.ReplayAll()
api.Flavor.delete(self.request,
resource_class_id=rc.id,
flavor_id=flavor.id)
def test_flavor_cpu(self):
flavor = self.tuskar_flavors.first()
cpu = flavor.cpu
self.assertIsInstance(cpu, api.Capacity)
self.assertEquals(64, cpu.value)
def test_flavor_memory(self):
flavor = self.tuskar_flavors.first()
memory = flavor.memory
self.assertIsInstance(memory, api.Capacity)
self.assertEquals(1024, memory.value)
def test_flavor_storage(self):
flavor = self.tuskar_flavors.first()
storage = flavor.storage
self.assertIsInstance(storage, api.Capacity)
self.assertEquals(1, storage.value)
def test_flavor_ephemeral_disk(self):
flavor = self.tuskar_flavors.first()
ephemeral_disk = flavor.ephemeral_disk
self.assertIsInstance(ephemeral_disk, api.Capacity)
self.assertEquals(0, ephemeral_disk.value)
def test_flavor_swap_disk(self):
flavor = self.tuskar_flavors.first()
swap_disk = flavor.swap_disk
self.assertIsInstance(swap_disk, api.Capacity)
self.assertEquals(2, swap_disk.value)

View File

@ -17,7 +17,6 @@ import os
from django.core.handlers import wsgi from django.core.handlers import wsgi
from django.utils import unittest from django.utils import unittest
from novaclient.v1_1.contrib import baremetal
from tuskarclient.v1 import client as tuskar_client from tuskarclient.v1 import client as tuskar_client
from openstack_dashboard.test import helpers as openstack_dashboard_helpers from openstack_dashboard.test import helpers as openstack_dashboard_helpers
@ -82,25 +81,16 @@ class APITestCase(openstack_dashboard_helpers.APITestCase):
# Store the original clients # Store the original clients
self._original_tuskarclient = tuskar_api.tuskarclient self._original_tuskarclient = tuskar_api.tuskarclient
self._original_baremetalclient = tuskar_api.baremetalclient
# Replace the clients with our stubs. # Replace the clients with our stubs.
tuskar_api.tuskarclient = lambda request: self.stub_tuskarclient() tuskar_api.tuskarclient = lambda request: self.stub_tuskarclient()
tuskar_api.baremetalclient = lambda request:\
self.stub_baremetalclient()
def tearDown(self): def tearDown(self):
super(APITestCase, self).tearDown() super(APITestCase, self).tearDown()
tuskar_api.tuskarclient = self._original_tuskarclient tuskar_api.tuskarclient = self._original_tuskarclient
tuskar_api.baremetalclient = self._original_baremetalclient
def stub_tuskarclient(self): def stub_tuskarclient(self):
if not hasattr(self, "tuskarclient"): if not hasattr(self, "tuskarclient"):
self.mox.StubOutWithMock(tuskar_client, 'Client') self.mox.StubOutWithMock(tuskar_client, 'Client')
self.tuskarclient = self.mox.CreateMock(tuskar_client.Client) self.tuskarclient = self.mox.CreateMock(tuskar_client.Client)
return self.tuskarclient return self.tuskarclient
def stub_baremetalclient(self):
if not hasattr(self, "baremetalclient"):
self.baremetalclient = baremetal.BareMetalNodeManager(None)
return self.baremetalclient

View File

@ -10,208 +10,131 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
from tuskar_ui import api
from openstack_dashboard.test.test_data import utils as test_data_utils from openstack_dashboard.test.test_data import utils as test_data_utils
from novaclient.v1_1.contrib import baremetal from heatclient.v1 import resources
from tuskarclient.v1 import flavors from heatclient.v1 import stacks
from tuskarclient.v1 import nodes as tuskar_nodes from ironicclient.v1 import chassis
from tuskarclient.v1 import racks from ironicclient.v1 import node
from tuskarclient.v1 import resource_classes from ironicclient.v1 import port
def data(TEST): def data(TEST):
# Flavors
TEST.tuskarclient_flavors = test_data_utils.TestDataContainer() # Stack
TEST.tuskar_flavors = test_data_utils.TestDataContainer() TEST.heatclient_stacks = test_data_utils.TestDataContainer()
flavor_1 = flavors.Flavor(flavors.FlavorManager(None), stack_1 = stacks.Stack(
stacks.StackManager(None),
{'id': '1', {'id': '1',
'name': 'nano', 'stack_name': 'overcloud',
'max_vms': 100, 'stack_status': 'RUNNING'})
'capacities': [ TEST.heatclient_stacks.add(stack_1)
{"name": "cpu",
"value": 64,
"unit": "CPU"},
{"name": "memory",
"value": 1024,
"unit": "MB"},
{"name": "storage",
"value": 1,
"unit": "GB"},
{"name": "ephemeral_disk",
"value": 0,
"unit": "GB"},
{"name": "swap_disk",
"value": 2,
"unit": "GB"}]})
flavor_2 = flavors.Flavor(flavors.FlavorManager(None),
{'id': '2',
'name': 'large',
'max_vms': 10,
'capacities': []})
TEST.tuskarclient_flavors.add(flavor_1, flavor_2)
TEST.tuskar_flavors.add(api.Flavor(flavor_1), api.Flavor(flavor_2))
# Resource Classes # Node
TEST.tuskarclient_resource_classes = test_data_utils.TestDataContainer() TEST.ironicclient_nodes = test_data_utils.TestDataContainer()
TEST.tuskar_resource_classes = test_data_utils.TestDataContainer() node_1 = node.Node(
resource_class_1 = resource_classes.ResourceClass( node.NodeManager(None),
resource_classes.ResourceClassManager(None), {'uuid': 'aa-11',
{'id': '1', 'chassis_id': 'chassis-id-1',
'service_type': 'compute', 'instance_uuid': 'aa',
'racks': [{'id': 1}, {'id': 2}], 'driver': 'pxe_ipmitool',
'name': 'rclass1'}) 'driver_info': {
resource_class_2 = resource_classes.ResourceClass( 'ipmi_address': '1.1.1.1',
resource_classes.ResourceClassManager(None), 'ipmi_username': 'admin',
{'id': '2', 'ipmi_password': 'password',
'service_type': 'compute', },
'racks': [], 'properties': {
'name': 'rclass2'}) 'cpu': '8',
TEST.tuskarclient_resource_classes.add(resource_class_1, resource_class_2) 'ram': '16',
TEST.tuskar_resource_classes.add(api.ResourceClass(resource_class_1), 'local_disk': '10',
api.ResourceClass(resource_class_2)) },
'power_state': 'on'})
node_2 = node.Node(
node.NodeManager(None),
{'uuid': 'bb-22',
'chassis_id': 'chassis-id-1',
'instance_uuid': 'bb',
'driver': 'pxe_ipmitool',
'driver_info': {
'ipmi_address': '2.2.2.2',
'ipmi_username': 'admin',
'ipmi_password': 'password',
},
'properties': {
'cpu': '16',
'ram': '32',
'local_disk': '100',
},
'power_state': 'on'})
node_3 = node.Node(
node.NodeManager(None),
{'uuid': 'cc-33',
'chassis_id': 'chassis-id-1',
'instance_uuid': None,
'driver': 'pxe_ipmitool',
'driver_info': {
'ipmi_address': '3.3.3.3',
'ipmi_username': 'admin',
'ipmi_password': 'password',
},
'properties': {
'cpu': '32',
'ram': '64',
'local_disk': '1',
},
'power_state': 'rebooting'})
TEST.ironicclient_nodes.add(node_1, node_2, node_3)
#Racks # Chassis
TEST.tuskarclient_racks = test_data_utils.TestDataContainer() TEST.ironicclient_chassis = test_data_utils.TestDataContainer()
TEST.tuskar_racks = test_data_utils.TestDataContainer() chassis_1 = chassis.Chassis(
rack_1 = racks.Rack(racks.RackManager(None), chassis.ChassisManager(None),
{'id': '1', {'uuid': 'chassis-id-1',
'name': 'rack1', 'description': 'default chassis'})
'location': 'location', TEST.ironicclient_chassis.add(chassis_1)
'subnet': '192.168.1.0/24',
'state': 'active',
'nodes': [
{'id': '1'},
{'id': '2'},
{'id': '3'},
{'id': '4'}],
'capacities': [
{"name": "total_cpu",
"value": "64",
"unit": "CPU"},
{"name": "total_memory",
"value": "1024",
"unit": "MB"}],
'resource_class': {'id': '1'}})
rack_2 = racks.Rack(racks.RackManager(None),
{'id': '2',
'name': 'rack2',
'location': 'location',
'subnet': '192.168.1.0/25',
'state': 'provisioning',
'nodes': [],
'capacities': [
{"name": "total_cpu",
"value": "1",
"unit": "CPU"},
{"name": "total_memory",
"value": "4",
"unit": "MB"}],
'resource_class': {'id': '1'}})
rack_3 = racks.Rack(racks.RackManager(None),
{'id': '3',
'name': 'rack3',
'location': 'location',
'subnet': '192.168.1.0/26',
'state': 'inactive',
'nodes': [],
'capacities': [
{"name": "total_cpu",
"value": "1",
"unit": "CPU"},
{"name": "total_memory",
"value": "2",
"unit": "MB"}],
})
TEST.tuskarclient_racks.add(rack_1, rack_2, rack_3)
TEST.tuskar_racks.add(api.Rack(rack_1), api.Rack(rack_2), api.Rack(rack_3))
# Nodes # Ports
TEST.tuskarclient_nodes = test_data_utils.TestDataContainer() TEST.ironicclient_ports = test_data_utils.TestDataContainer()
TEST.tuskar_nodes = test_data_utils.TestDataContainer() port_1 = port.Port(
port.PortManager(None),
{'id': '1-port-id',
'type': 'port',
'address': 'aa:aa:aa:aa:aa:aa'})
port_2 = port.Port(
port.PortManager(None),
{'id': '2-port-id',
'type': 'port',
'address': 'bb:bb:bb:bb:bb:bb'})
port_3 = port.Port(
port.PortManager(None),
{'id': '3-port-id',
'type': 'port',
'address': 'cc:cc:cc:cc:cc:cc'})
port_4 = port.Port(
port.PortManager(None),
{'id': '4-port-id',
'type': 'port',
'address': 'dd:dd:dd:dd:dd:dd'})
TEST.ironicclient_ports.add(port_1, port_2, port_3, port_4)
tuskar_node_1 = tuskar_nodes.Node( # Resource
tuskar_nodes.NodeManager(None), TEST.heatclient_resources = test_data_utils.TestDataContainer()
{'id': '1', resource_1 = resources.Resource(
'nova_baremetal_node_id': '11', resources.ResourceManager(None),
'rack': {"id": "1"}}) {'stack_id': '1',
tuskar_node_2 = tuskar_nodes.Node( 'resource_name': 'Compute',
tuskar_nodes.NodeManager(None), 'logical_resource_id': 'Compute',
{'id': '2', 'physical_resource_id': 'aa',
'nova_baremetal_node_id': '12', 'resource_status': 'CREATE_COMPLETE',
'rack': {"id": "1"}}) 'resource_type': 'AWS::EC2::Instance'})
tuskar_node_3 = tuskar_nodes.Node( resource_2 = resources.Resource(
tuskar_nodes.NodeManager(None), resources.ResourceManager(None),
{'id': '3', {'stack_id': '1',
'nova_baremetal_node_id': '13', 'resource_name': 'Control',
'rack': {"id": "1"}}) 'logical_resource_id': 'Control',
tuskar_node_4 = tuskar_nodes.Node( 'physical_resource_id': 'bb',
tuskar_nodes.NodeManager(None), 'resource_status': 'CREATE_COMPLETE',
{'id': '4', 'resource_type': 'AWS::EC2::Instance'})
'nova_baremetal_node_id': '14', TEST.heatclient_resources.add(resource_1, resource_2)
'rack': {"id": "1"}})
TEST.tuskarclient_nodes.add(tuskar_node_1, # ResourceCategory
tuskar_node_2,
tuskar_node_3,
tuskar_node_4)
TEST.tuskar_nodes.add(api.TuskarNode(tuskar_node_1),
api.TuskarNode(tuskar_node_2),
api.TuskarNode(tuskar_node_3),
api.TuskarNode(tuskar_node_4))
TEST.baremetalclient_nodes = test_data_utils.TestDataContainer()
TEST.baremetal_nodes = test_data_utils.TestDataContainer()
TEST.baremetalclient_unracked_nodes = test_data_utils.TestDataContainer()
TEST.baremetal_unracked_nodes = test_data_utils.TestDataContainer()
TEST.baremetalclient_nodes_all = test_data_utils.TestDataContainer()
TEST.baremetal_nodes_all = test_data_utils.TestDataContainer()
baremetal_node_1 = baremetal.BareMetalNode(
baremetal.BareMetalNodeManager(None),
{'instance_uuid': 'uuid_11',
'id': '11',
'name': 'node1',
'prov_mac_address': '00:B0:D0:86:AB:F7'})
baremetal_node_2 = baremetal.BareMetalNode(
baremetal.BareMetalNodeManager(None),
{'instance_uuid': 'uuid_12',
'id': '12',
'name': 'node2',
'prov_mac_address': '00:B0:D0:86:AB:F8'})
baremetal_node_3 = baremetal.BareMetalNode(
baremetal.BareMetalNodeManager(None),
{'instance_uuid': 'uuid_13',
'id': '13',
'name': 'node3',
'prov_mac_address': '00:B0:D0:86:AB:F9'})
baremetal_node_4 = baremetal.BareMetalNode(
baremetal.BareMetalNodeManager(None),
{'instance_uuid': 'uuid_14',
'id': '14',
'name': 'node4',
'prov_mac_address': '00:B0:D0:86:AB:F0'})
baremetal_node_5 = baremetal.BareMetalNode(
baremetal.BareMetalNodeManager(None),
{'instance_uuid': 'uuid_15',
'id': '15',
'name': 'node5',
'prov_mac_address': '00:B0:D0:86:AB:F1'})
TEST.baremetalclient_nodes.add(baremetal_node_1, baremetal_node_2,
baremetal_node_3, baremetal_node_4)
TEST.baremetal_nodes.add(api.BaremetalNode(baremetal_node_1),
api.BaremetalNode(baremetal_node_2),
api.BaremetalNode(baremetal_node_3),
api.BaremetalNode(baremetal_node_4))
TEST.baremetalclient_unracked_nodes.add(baremetal_node_5)
TEST.baremetal_unracked_nodes.add(api.TuskarNode(baremetal_node_5))
TEST.baremetalclient_nodes_all.add(baremetal_node_1, baremetal_node_2,
baremetal_node_3, baremetal_node_4,
baremetal_node_5)
TEST.baremetal_nodes_all.add(api.BaremetalNode(baremetal_node_1),
api.BaremetalNode(baremetal_node_2),
api.BaremetalNode(baremetal_node_3),
api.BaremetalNode(baremetal_node_4),
api.BaremetalNode(baremetal_node_5))