From 786faec41bebcdb01acee8a5ba3b1a0de198c468 Mon Sep 17 00:00:00 2001 From: Tzu-Mainn Chen Date: Tue, 6 Aug 2013 12:04:13 -0400 Subject: test and node API cleanup * removed Node dummymodel * added baremetalclient and overcloudclient in tuskar.py (these may be moved later) * added stubs to tests which still tried to access tuskar API * minor code fixes --- openstack_dashboard/api/tuskar.py | 165 +++++---------------- .../infrastructure/fixtures/initial_data.json | 109 +++++--------- .../dashboards/infrastructure/models.py | 13 -- .../resource_management/racks/forms.py | 9 +- .../resource_management/racks/tests.py | 5 +- .../resource_management/racks/workflows.py | 13 +- .../resource_management/resource_classes/tests.py | 6 +- .../resource_classes/_detail_overview.html | 2 +- .../infrastructure/resource_management/tests.py | 28 ++-- openstack_dashboard/test/test_data/tuskar_data.py | 58 +++----- 10 files changed, 140 insertions(+), 268 deletions(-) diff --git a/openstack_dashboard/api/tuskar.py b/openstack_dashboard/api/tuskar.py index 18634004..6b1bc9c6 100644 --- a/openstack_dashboard/api/tuskar.py +++ b/openstack_dashboard/api/tuskar.py @@ -47,6 +47,23 @@ def tuskarclient(request): return c +def baremetalclient(request): + nc = nova.nova_client.Client(NOVA_BAREMETAL_CREDS['user'], + NOVA_BAREMETAL_CREDS['password'], + NOVA_BAREMETAL_CREDS['tenant'], + auth_url=NOVA_BAREMETAL_CREDS['auth_url'], + bypass_url=NOVA_BAREMETAL_CREDS['bypass_url']) + return baremetal.BareMetalNodeManager(nc) + + +def overcloudclient(request): + c = nova.nova_client.Client(OVERCLOUD_USERNAME, + OVERCLOUD_PASSWORD, + 'admin', + auth_url=OVERCLOUD_AUTH_URL) + return c + + class StringIdAPIResourceWrapper(base.APIResourceWrapper): # horizon DataTable class expects ids to be string, # if it's not string, then comparison in @@ -147,21 +164,11 @@ class Node(StringIdAPIResourceWrapper): dummy model. """ _attrs = ['id', 'pm_address', 'cpus', 'memory_mb', 'service_host', - 'local_gb', 'pm_user'] - - @classmethod - def manager(cls): - nc = nova.nova_client.Client( - NOVA_BAREMETAL_CREDS['user'], - NOVA_BAREMETAL_CREDS['password'], - NOVA_BAREMETAL_CREDS['tenant'], - auth_url=NOVA_BAREMETAL_CREDS['auth_url'], - bypass_url=NOVA_BAREMETAL_CREDS['bypass_url']) - return baremetal.BareMetalNodeManager(nc) + 'local_gb', 'pm_user'] @classmethod def get(cls, request, node_id): - node = cls(cls.manager().get(node_id)) + node = cls(baremetalclient(request).get(node_id)) node.request = request # FIXME ugly, fix after demo, make abstraction of instance details @@ -185,9 +192,9 @@ class Node(StringIdAPIResourceWrapper): .join([addr['addr'] for addr in addresses])) node.status = detail._apiresource._info['OS-EXT-STS:vm_state'] - node.power_mamanegemt = "" + node.power_management = "" if node.pm_user: - node.power_mamanegemt = node.pm_user + "/********" + node.power_management = node.pm_user + "/********" else: node.status = 'unprovisioned' @@ -195,20 +202,22 @@ class Node(StringIdAPIResourceWrapper): @classmethod def list(cls, request): - return cls.manager().list() + return [Node(n, request) for n in + baremetalclient(request).list()] @classmethod def list_unracked(cls, request): - return [cls(h) for h in dummymodels.Node.objects.all() if ( - h.rack_id is None)] + return [n for n in Node.list(request) if ( + n.rack is None)] @classmethod - def create(cls, request, name, mac_address, ip_address, status, - usage, rack): - node = dummymodels.Node(name=name, mac_address=mac_address, - ip_address=ip_address, status=status, - usage=usage, rack=rack) - node.save() + def create(cls, request, name, cpus, memory_mb, local_gb, prov_mac_address, + pm_address, pm_user, pm_password, terminal_port): + node = baremetalclient(request).create(name, cpus, memory_mb, + local_gb, prov_mac_address, + pm_address, pm_user, + pm_password, terminal_port) + return node @property def list_flavors(self): @@ -235,13 +244,6 @@ class Node(StringIdAPIResourceWrapper): return self._flavors - @property - def capacities(self): - if not hasattr(self, '_capacities'): - self._capacities = [Capacity(c) for c in - self._apiresource.capacities.all()] - return self._capacities - @property def rack(self): try: @@ -259,70 +261,6 @@ class Node(StringIdAPIResourceWrapper): LOG.debug(exceptions.error_color(msg)) return None - @property - def cpu(self): - if not hasattr(self, '_cpu'): - try: - cpu = dummymodels.Capacity.objects\ - .filter(node=self._apiresource)\ - .filter(name='cpu')[0] - except: - cpu = dummymodels.Capacity( - name='cpu', - value=_('Unable to retrieve ' - '(Is the node configured properly?)'), - unit='') - self._cpu = Capacity(cpu) - return self._cpu - - @property - def ram(self): - if not hasattr(self, '_ram'): - try: - ram = dummymodels.Capacity.objects\ - .filter(node=self._apiresource)\ - .filter(name='ram')[0] - except: - ram = dummymodels.Capacity( - name='ram', - value=_('Unable to retrieve ' - '(Is the node configured properly?)'), - unit='') - self._ram = Capacity(ram) - return self._ram - - @property - def storage(self): - if not hasattr(self, '_storage'): - try: - storage = dummymodels.Capacity.objects\ - .filter(node=self._apiresource)\ - .filter(name='storage')[0] - except: - storage = dummymodels.Capacity( - name='storage', - value=_('Unable to retrieve ' - '(Is the node configured properly?)'), - unit='') - self._storage = Capacity(storage) - return self._storage - - @property - def network(self): - if not hasattr(self, '_network'): - try: - network = dummymodels.Capacity.objects\ - .filter(node=self._apiresource)\ - .filter(name='network')[0] - except: - network = dummymodels.Capacity( - name='network', - value=_('Unable to retrieve ' - '(Is the node configured properly?)'), - unit='') - self._network = Capacity(network) - return self._network - @property def vm_capacity(self): if not hasattr(self, '_vm_capacity'): @@ -376,12 +314,9 @@ class Node(StringIdAPIResourceWrapper): if not hasattr(self, '_running_virtual_machines'): search_opts = {} search_opts['all_tenants'] = True - nova_client = nova.nova_client.Client(OVERCLOUD_USERNAME, - OVERCLOUD_PASSWORD, - 'admin', - auth_url=OVERCLOUD_AUTH_URL) self._running_virtual_machines = [s for s in - nova_client.servers.list(True, search_opts) + overcloudclient(self.request). + servers.list(True, search_opts) if s.hostId == self.id] return self._running_virtual_machines @@ -451,8 +386,6 @@ class Rack(StringIdAPIResourceWrapper): unicode(node['id']) for node in ( self._apiresource.nodes)] - ## FIXME: this will have to be rewritten to ultimately - ## fetch nodes from nova baremetal @property def list_nodes(self): if not hasattr(self, '_nodes'): @@ -463,28 +396,6 @@ class Rack(StringIdAPIResourceWrapper): def nodes_count(self): return len(self._apiresource.nodes) - # The idea here is to take a list of MAC addresses and assign them to - # our rack. I'm attaching this here so that we can take one list, versus - # potentially making a long series of API calls. - # The present implementation makes no attempt at optimization since this - # is likely short-lived until a real API is implemented. - @classmethod - def register_nodes(cls, rack_id, nodes_list): - for mac in nodes_list: - # search for MAC - try: - node = dummymodels.Node.objects.get(mac_address=mac) - if node is not None: - node.rack_id = rack_id - node.save() - except: - # FIXME: It is unclear what we're supposed to do in this case. - # I create a new Node, but it's possible we should not - # allow new entries here. - # FIXME: If this stays, we should probably add Capabilities - # here so that graphs work as expected. - Node.create(None, mac, mac, None, None, None, rack_id) - @property def resource_class(self): if not hasattr(self, '_resource_class'): @@ -594,6 +505,7 @@ class ResourceClass(StringIdAPIResourceWrapper): @classmethod def get(cls, request, resource_class_id): rc = cls(tuskarclient(request).resource_classes.get(resource_class_id)) + rc.request = request return rc @classmethod @@ -606,7 +518,7 @@ class ResourceClass(StringIdAPIResourceWrapper): @classmethod def list(cls, request): - return [cls(rc) for rc in ( + return [cls(rc, request) for rc in ( tuskarclient(request).resource_classes.list())] @classmethod @@ -736,7 +648,8 @@ class ResourceClass(StringIdAPIResourceWrapper): @property def nodes(self): if not hasattr(self, '_nodes'): - self._nodes = [rack.list_nodes for rack in self.list_racks] + nodes_lists = [rack.list_nodes for rack in self.list_racks] + self._nodes = [node for nodes in nodes_lists for node in nodes] return self._nodes @property @@ -745,7 +658,7 @@ class ResourceClass(StringIdAPIResourceWrapper): @property def racks_count(self): - return len(self.racks) + return len(self.list_racks) @property def vm_capacity(self): diff --git a/openstack_dashboard/dashboards/infrastructure/fixtures/initial_data.json b/openstack_dashboard/dashboards/infrastructure/fixtures/initial_data.json index fc204cd3..361a9fcf 100644 --- a/openstack_dashboard/dashboards/infrastructure/fixtures/initial_data.json +++ b/openstack_dashboard/dashboards/infrastructure/fixtures/initial_data.json @@ -7,74 +7,47 @@ {"pk": 6, "model": "infrastructure.flavortemplate", "fields": {"name": "large"}}, {"pk": 7, "model": "infrastructure.flavortemplate", "fields": {"name": "xlarge"}}, - {"pk": 1, "model": "infrastructure.node", "fields": {"name": "node1", "rack_id": 1, "mac_address": "00-B0-D0-86-AB-F7", "ip_address": "192.168.191.11", "status": "active", "usage": "20"}}, - {"pk": 2, "model": "infrastructure.node", "fields": {"name": "node2", "rack_id": 1, "mac_address": "00-B0-D0-86-AB-F8", "ip_address": "192.168.191.12", "status": "active", "usage": "30"}}, - {"pk": 3, "model": "infrastructure.node", "fields": {"name": "node3", "rack_id": 2, "mac_address": "00-B0-D0-86-AB-F9", "ip_address": "192.168.191.13", "status": "active", "usage": "40"}}, - {"pk": 4, "model": "infrastructure.node", "fields": {"name": "node4", "rack_id": 2, "mac_address": "00-B0-D0-86-AB-F0", "ip_address": "192.168.191.14", "status": "active", "usage": "50"}}, - {"pk": 5, "model": "infrastructure.node", "fields": {"name": "Unracked Node", "mac_address": "00-B0-D0-86-AB-F1"}}, - - {"pk": 1, "model": "infrastructure.capacity", "fields": {"value": 4, "unit": "GHz", "object_id": 1, "content_type": ["infrastructure", "node"], "name": "cpu"}}, - {"pk": 2, "model": "infrastructure.capacity", "fields": {"value": 4, "unit": "GHz", "object_id": 2, "content_type": ["infrastructure", "node"], "name": "cpu"}}, - {"pk": 3, "model": "infrastructure.capacity", "fields": {"value": 4, "unit": "GHz", "object_id": 3, "content_type": ["infrastructure", "node"], "name": "cpu"}}, - {"pk": 4, "model": "infrastructure.capacity", "fields": {"value": 4, "unit": "GHz", "object_id": 4, "content_type": ["infrastructure", "node"], "name": "cpu"}}, - {"pk": 5, "model": "infrastructure.capacity", "fields": {"value": 4, "unit": "GHz", "object_id": 5, "content_type": ["infrastructure", "node"], "name": "cpu"}}, - {"pk": 6, "model": "infrastructure.capacity", "fields": {"value": 32, "unit": "GB", "object_id": 1, "content_type": ["infrastructure", "node"], "name": "ram"}}, - {"pk": 7, "model": "infrastructure.capacity", "fields": {"value": 32, "unit": "GB", "object_id": 2, "content_type": ["infrastructure", "node"], "name": "ram"}}, - {"pk": 8, "model": "infrastructure.capacity", "fields": {"value": 32, "unit": "GB", "object_id": 3, "content_type": ["infrastructure", "node"], "name": "ram"}}, - {"pk": 9, "model": "infrastructure.capacity", "fields": {"value": 32, "unit": "GB", "object_id": 4, "content_type": ["infrastructure", "node"], "name": "ram"}}, - {"pk": 10, "model": "infrastructure.capacity", "fields": {"value": 32, "unit": "GB", "object_id": 5, "content_type": ["infrastructure", "node"], "name": "ram"}}, - {"pk": 11, "model": "infrastructure.capacity", "fields": {"value": 12, "unit": "TB", "object_id": 1, "content_type": ["infrastructure", "node"], "name": "storage"}}, - {"pk": 12, "model": "infrastructure.capacity", "fields": {"value": 12, "unit": "TB", "object_id": 2, "content_type": ["infrastructure", "node"], "name": "storage"}}, - {"pk": 13, "model": "infrastructure.capacity", "fields": {"value": 12, "unit": "TB", "object_id": 3, "content_type": ["infrastructure", "node"], "name": "storage"}}, - {"pk": 14, "model": "infrastructure.capacity", "fields": {"value": 12, "unit": "TB", "object_id": 4, "content_type": ["infrastructure", "node"], "name": "storage"}}, - {"pk": 15, "model": "infrastructure.capacity", "fields": {"value": 12, "unit": "TB", "object_id": 5, "content_type": ["infrastructure", "node"], "name": "storage"}}, - {"pk": 16, "model": "infrastructure.capacity", "fields": {"value": 90, "unit": "Gbps", "object_id": 1, "content_type": ["infrastructure", "node"], "name": "network"}}, - {"pk": 17, "model": "infrastructure.capacity", "fields": {"value": 90, "unit": "Gbps", "object_id": 2, "content_type": ["infrastructure", "node"], "name": "network"}}, - {"pk": 18, "model": "infrastructure.capacity", "fields": {"value": 90, "unit": "Gbps", "object_id": 3, "content_type": ["infrastructure", "node"], "name": "network"}}, - {"pk": 19, "model": "infrastructure.capacity", "fields": {"value": 90, "unit": "Gbps", "object_id": 4, "content_type": ["infrastructure", "node"], "name": "network"}}, - {"pk": 20, "model": "infrastructure.capacity", "fields": {"value": 90, "unit": "Gbps", "object_id": 5, "content_type": ["infrastructure", "node"], "name": "network"}}, - - {"pk": 21, "model": "infrastructure.capacity", "fields": {"value": 1, "unit": "", "object_id": 1, "content_type": ["infrastructure", "flavortemplate"], "name": "cpu"}}, - {"pk": 22, "model": "infrastructure.capacity", "fields": {"value": 64, "unit": "MB", "object_id": 1, "content_type": ["infrastructure", "flavortemplate"], "name": "memory"}}, - {"pk": 23, "model": "infrastructure.capacity", "fields": {"value": 0, "unit": "GB", "object_id": 1, "content_type": ["infrastructure", "flavortemplate"], "name": "storage"}}, - {"pk": 24, "model": "infrastructure.capacity", "fields": {"value": 0, "unit": "GB", "object_id": 1, "content_type": ["infrastructure", "flavortemplate"], "name": "ephemeral_disk"}}, - {"pk": 25, "model": "infrastructure.capacity", "fields": {"value": 0, "unit": "MB", "object_id": 1, "content_type": ["infrastructure", "flavortemplate"], "name": "swap_disk"}}, - - {"pk": 26, "model": "infrastructure.capacity", "fields": {"value": 1, "unit": "", "object_id": 2, "content_type": ["infrastructure", "flavortemplate"], "name": "cpu"}}, - {"pk": 27, "model": "infrastructure.capacity", "fields": {"value": 128, "unit": "MB", "object_id": 2, "content_type": ["infrastructure", "flavortemplate"], "name": "memory"}}, - {"pk": 28, "model": "infrastructure.capacity", "fields": {"value": 0, "unit": "GB", "object_id": 2, "content_type": ["infrastructure", "flavortemplate"], "name": "storage"}}, - {"pk": 29, "model": "infrastructure.capacity", "fields": {"value": 0, "unit": "GB", "object_id": 2, "content_type": ["infrastructure", "flavortemplate"], "name": "ephemeral_disk"}}, - {"pk": 30, "model": "infrastructure.capacity", "fields": {"value": 0, "unit": "MB", "object_id": 2, "content_type": ["infrastructure", "flavortemplate"], "name": "swap_disk"}}, - - {"pk": 31, "model": "infrastructure.capacity", "fields": {"value": 1, "unit": "", "object_id": 3, "content_type": ["infrastructure", "flavortemplate"], "name": "cpu"}}, - {"pk": 32, "model": "infrastructure.capacity", "fields": {"value": 512, "unit": "MB", "object_id": 3, "content_type": ["infrastructure", "flavortemplate"], "name": "memory"}}, - {"pk": 33, "model": "infrastructure.capacity", "fields": {"value": 1, "unit": "GB", "object_id": 3, "content_type": ["infrastructure", "flavortemplate"], "name": "storage"}}, - {"pk": 34, "model": "infrastructure.capacity", "fields": {"value": 0, "unit": "GB", "object_id": 3, "content_type": ["infrastructure", "flavortemplate"], "name": "ephemeral_disk"}}, - {"pk": 35, "model": "infrastructure.capacity", "fields": {"value": 0, "unit": "MB", "object_id": 3, "content_type": ["infrastructure", "flavortemplate"], "name": "swap_disk"}}, - - {"pk": 36, "model": "infrastructure.capacity", "fields": {"value": 1, "unit": "", "object_id": 4, "content_type": ["infrastructure", "flavortemplate"], "name": "cpu"}}, - {"pk": 37, "model": "infrastructure.capacity", "fields": {"value": 2048, "unit": "MB", "object_id": 4, "content_type": ["infrastructure", "flavortemplate"], "name": "memory"}}, - {"pk": 38, "model": "infrastructure.capacity", "fields": {"value": 20, "unit": "GB", "object_id": 4, "content_type": ["infrastructure", "flavortemplate"], "name": "storage"}}, - {"pk": 39, "model": "infrastructure.capacity", "fields": {"value": 0, "unit": "GB", "object_id": 4, "content_type": ["infrastructure", "flavortemplate"], "name": "ephemeral_disk"}}, - {"pk": 40, "model": "infrastructure.capacity", "fields": {"value": 0, "unit": "MB", "object_id": 4, "content_type": ["infrastructure", "flavortemplate"], "name": "swap_disk"}}, - - {"pk": 41, "model": "infrastructure.capacity", "fields": {"value": 2, "unit": "", "object_id": 5, "content_type": ["infrastructure", "flavortemplate"], "name": "cpu"}}, - {"pk": 42, "model": "infrastructure.capacity", "fields": {"value": 4096, "unit": "MB", "object_id": 5, "content_type": ["infrastructure", "flavortemplate"], "name": "memory"}}, - {"pk": 43, "model": "infrastructure.capacity", "fields": {"value": 40, "unit": "GB", "object_id": 5, "content_type": ["infrastructure", "flavortemplate"], "name": "storage"}}, - {"pk": 44, "model": "infrastructure.capacity", "fields": {"value": 0, "unit": "GB", "object_id": 5, "content_type": ["infrastructure", "flavortemplate"], "name": "ephemeral_disk"}}, - {"pk": 45, "model": "infrastructure.capacity", "fields": {"value": 0, "unit": "MB", "object_id": 5, "content_type": ["infrastructure", "flavortemplate"], "name": "swap_disk"}}, - - {"pk": 46, "model": "infrastructure.capacity", "fields": {"value": 4, "unit": "", "object_id": 6, "content_type": ["infrastructure", "flavortemplate"], "name": "cpu"}}, - {"pk": 47, "model": "infrastructure.capacity", "fields": {"value": 8192, "unit": "MB", "object_id": 6, "content_type": ["infrastructure", "flavortemplate"], "name": "memory"}}, - {"pk": 48, "model": "infrastructure.capacity", "fields": {"value": 80, "unit": "GB", "object_id": 6, "content_type": ["infrastructure", "flavortemplate"], "name": "storage"}}, - {"pk": 49, "model": "infrastructure.capacity", "fields": {"value": 0, "unit": "GB", "object_id": 6, "content_type": ["infrastructure", "flavortemplate"], "name": "ephemeral_disk"}}, - {"pk": 50, "model": "infrastructure.capacity", "fields": {"value": 0, "unit": "MB", "object_id": 6, "content_type": ["infrastructure", "flavortemplate"], "name": "swap_disk"}}, - - {"pk": 51, "model": "infrastructure.capacity", "fields": {"value": 8, "unit": "", "object_id": 7, "content_type": ["infrastructure", "flavortemplate"], "name": "cpu"}}, - {"pk": 52, "model": "infrastructure.capacity", "fields": {"value": 16384, "unit": "MB", "object_id": 7, "content_type": ["infrastructure", "flavortemplate"], "name": "memory"}}, - {"pk": 53, "model": "infrastructure.capacity", "fields": {"value": 160, "unit": "GB", "object_id": 7, "content_type": ["infrastructure", "flavortemplate"], "name": "storage"}}, - {"pk": 54, "model": "infrastructure.capacity", "fields": {"value": 0, "unit": "GB", "object_id": 7, "content_type": ["infrastructure", "flavortemplate"], "name": "ephemeral_disk"}}, - {"pk": 55, "model": "infrastructure.capacity", "fields": {"value": 0, "unit": "MB", "object_id": 7, "content_type": ["infrastructure", "flavortemplate"], "name": "swap_disk"}}, + {"pk": 1, "model": "infrastructure.capacity", "fields": {"value": 1, "unit": "", "object_id": 1, "content_type": ["infrastructure", "flavortemplate"], "name": "cpu"}}, + {"pk": 2, "model": "infrastructure.capacity", "fields": {"value": 64, "unit": "MB", "object_id": 1, "content_type": ["infrastructure", "flavortemplate"], "name": "memory"}}, + {"pk": 3, "model": "infrastructure.capacity", "fields": {"value": 0, "unit": "GB", "object_id": 1, "content_type": ["infrastructure", "flavortemplate"], "name": "storage"}}, + {"pk": 4, "model": "infrastructure.capacity", "fields": {"value": 0, "unit": "GB", "object_id": 1, "content_type": ["infrastructure", "flavortemplate"], "name": "ephemeral_disk"}}, + {"pk": 5, "model": "infrastructure.capacity", "fields": {"value": 0, "unit": "MB", "object_id": 1, "content_type": ["infrastructure", "flavortemplate"], "name": "swap_disk"}}, + + {"pk": 6, "model": "infrastructure.capacity", "fields": {"value": 1, "unit": "", "object_id": 2, "content_type": ["infrastructure", "flavortemplate"], "name": "cpu"}}, + {"pk": 7, "model": "infrastructure.capacity", "fields": {"value": 128, "unit": "MB", "object_id": 2, "content_type": ["infrastructure", "flavortemplate"], "name": "memory"}}, + {"pk": 8, "model": "infrastructure.capacity", "fields": {"value": 0, "unit": "GB", "object_id": 2, "content_type": ["infrastructure", "flavortemplate"], "name": "storage"}}, + {"pk": 9, "model": "infrastructure.capacity", "fields": {"value": 0, "unit": "GB", "object_id": 2, "content_type": ["infrastructure", "flavortemplate"], "name": "ephemeral_disk"}}, + {"pk": 10, "model": "infrastructure.capacity", "fields": {"value": 0, "unit": "MB", "object_id": 2, "content_type": ["infrastructure", "flavortemplate"], "name": "swap_disk"}}, + + {"pk": 11, "model": "infrastructure.capacity", "fields": {"value": 1, "unit": "", "object_id": 3, "content_type": ["infrastructure", "flavortemplate"], "name": "cpu"}}, + {"pk": 12, "model": "infrastructure.capacity", "fields": {"value": 512, "unit": "MB", "object_id": 3, "content_type": ["infrastructure", "flavortemplate"], "name": "memory"}}, + {"pk": 13, "model": "infrastructure.capacity", "fields": {"value": 1, "unit": "GB", "object_id": 3, "content_type": ["infrastructure", "flavortemplate"], "name": "storage"}}, + {"pk": 14, "model": "infrastructure.capacity", "fields": {"value": 0, "unit": "GB", "object_id": 3, "content_type": ["infrastructure", "flavortemplate"], "name": "ephemeral_disk"}}, + {"pk": 15, "model": "infrastructure.capacity", "fields": {"value": 0, "unit": "MB", "object_id": 3, "content_type": ["infrastructure", "flavortemplate"], "name": "swap_disk"}}, + + {"pk": 16, "model": "infrastructure.capacity", "fields": {"value": 1, "unit": "", "object_id": 4, "content_type": ["infrastructure", "flavortemplate"], "name": "cpu"}}, + {"pk": 17, "model": "infrastructure.capacity", "fields": {"value": 2048, "unit": "MB", "object_id": 4, "content_type": ["infrastructure", "flavortemplate"], "name": "memory"}}, + {"pk": 18, "model": "infrastructure.capacity", "fields": {"value": 20, "unit": "GB", "object_id": 4, "content_type": ["infrastructure", "flavortemplate"], "name": "storage"}}, + {"pk": 19, "model": "infrastructure.capacity", "fields": {"value": 0, "unit": "GB", "object_id": 4, "content_type": ["infrastructure", "flavortemplate"], "name": "ephemeral_disk"}}, + {"pk": 20, "model": "infrastructure.capacity", "fields": {"value": 0, "unit": "MB", "object_id": 4, "content_type": ["infrastructure", "flavortemplate"], "name": "swap_disk"}}, + + {"pk": 21, "model": "infrastructure.capacity", "fields": {"value": 2, "unit": "", "object_id": 5, "content_type": ["infrastructure", "flavortemplate"], "name": "cpu"}}, + {"pk": 22, "model": "infrastructure.capacity", "fields": {"value": 4096, "unit": "MB", "object_id": 5, "content_type": ["infrastructure", "flavortemplate"], "name": "memory"}}, + {"pk": 23, "model": "infrastructure.capacity", "fields": {"value": 40, "unit": "GB", "object_id": 5, "content_type": ["infrastructure", "flavortemplate"], "name": "storage"}}, + {"pk": 24, "model": "infrastructure.capacity", "fields": {"value": 0, "unit": "GB", "object_id": 5, "content_type": ["infrastructure", "flavortemplate"], "name": "ephemeral_disk"}}, + {"pk": 25, "model": "infrastructure.capacity", "fields": {"value": 0, "unit": "MB", "object_id": 5, "content_type": ["infrastructure", "flavortemplate"], "name": "swap_disk"}}, + + {"pk": 26, "model": "infrastructure.capacity", "fields": {"value": 4, "unit": "", "object_id": 6, "content_type": ["infrastructure", "flavortemplate"], "name": "cpu"}}, + {"pk": 27, "model": "infrastructure.capacity", "fields": {"value": 8192, "unit": "MB", "object_id": 6, "content_type": ["infrastructure", "flavortemplate"], "name": "memory"}}, + {"pk": 28, "model": "infrastructure.capacity", "fields": {"value": 80, "unit": "GB", "object_id": 6, "content_type": ["infrastructure", "flavortemplate"], "name": "storage"}}, + {"pk": 29, "model": "infrastructure.capacity", "fields": {"value": 0, "unit": "GB", "object_id": 6, "content_type": ["infrastructure", "flavortemplate"], "name": "ephemeral_disk"}}, + {"pk": 30, "model": "infrastructure.capacity", "fields": {"value": 0, "unit": "MB", "object_id": 6, "content_type": ["infrastructure", "flavortemplate"], "name": "swap_disk"}}, + + {"pk": 31, "model": "infrastructure.capacity", "fields": {"value": 8, "unit": "", "object_id": 7, "content_type": ["infrastructure", "flavortemplate"], "name": "cpu"}}, + {"pk": 32, "model": "infrastructure.capacity", "fields": {"value": 16384, "unit": "MB", "object_id": 7, "content_type": ["infrastructure", "flavortemplate"], "name": "memory"}}, + {"pk": 33, "model": "infrastructure.capacity", "fields": {"value": 160, "unit": "GB", "object_id": 7, "content_type": ["infrastructure", "flavortemplate"], "name": "storage"}}, + {"pk": 34, "model": "infrastructure.capacity", "fields": {"value": 0, "unit": "GB", "object_id": 7, "content_type": ["infrastructure", "flavortemplate"], "name": "ephemeral_disk"}}, + {"pk": 35, "model": "infrastructure.capacity", "fields": {"value": 0, "unit": "MB", "object_id": 7, "content_type": ["infrastructure", "flavortemplate"], "name": "swap_disk"}}, {"pk": 1, "model": "infrastructure.alert", "fields": {"message": "Switch is not accessible.", "object_id": "1", "object_type": "rack", "time": "2011-09-01T13:20:30+03:00"}}, {"pk": 2, "model": "infrastructure.alert", "fields": {"message": "Nova service is not running.", "object_id": "1", "object_type": "node", "time": "2011-09-01T13:20:30+03:00"}}, diff --git a/openstack_dashboard/dashboards/infrastructure/models.py b/openstack_dashboard/dashboards/infrastructure/models.py index 14fc982a..5ba1a384 100644 --- a/openstack_dashboard/dashboards/infrastructure/models.py +++ b/openstack_dashboard/dashboards/infrastructure/models.py @@ -46,16 +46,3 @@ class FlavorTemplate(models.Model): name = models.CharField(max_length=50, unique=True) capacities = generic.GenericRelation(Capacity) - - -class Node(models.Model): - class Meta: - db_table = 'infrastructure_node' - - name = models.CharField(max_length=50, unique=True) - rack_id = models.PositiveIntegerField(null=True) - mac_address = models.CharField(max_length=50, unique=True) - ip_address = models.CharField(max_length=50, unique=True, null=True) - status = models.CharField(max_length=50, null=True) - usage = models.IntegerField(max_length=50, null=True) - capacities = generic.GenericRelation(Capacity) diff --git a/openstack_dashboard/dashboards/infrastructure/resource_management/racks/forms.py b/openstack_dashboard/dashboards/infrastructure/resource_management/racks/forms.py index 3b3ce324..c77d2dd3 100644 --- a/openstack_dashboard/dashboards/infrastructure/resource_management/racks/forms.py +++ b/openstack_dashboard/dashboards/infrastructure/resource_management/racks/forms.py @@ -67,10 +67,11 @@ class UploadRack(forms.SelfHandlingForm): api.tuskar.ResourceClass.list(request)) for rack in racks: try: - r = api.tuskar.Rack.create(request, rack.name, - rclass_ids[rack.resource_class], rack.region, - rack.subnet) - api.tuskar.Rack.register_nodes(r, rack.nodes) + api.tuskar.Rack.create(request, rack.name, + rclass_ids[rack.resource_class], + rack.region, rack.subnet) + # FIXME: will have to handle nodes once proper attributes + # for nodes are added successes.append(rack.name) except: LOG.exception("Exception in processing rack CSV file.") diff --git a/openstack_dashboard/dashboards/infrastructure/resource_management/racks/tests.py b/openstack_dashboard/dashboards/infrastructure/resource_management/racks/tests.py index f17f9201..131f2cf1 100644 --- a/openstack_dashboard/dashboards/infrastructure/resource_management/racks/tests.py +++ b/openstack_dashboard/dashboards/infrastructure/resource_management/racks/tests.py @@ -13,7 +13,6 @@ from django.core.urlresolvers import reverse from django import http -from mox import IgnoreArg from mox import IsA from novaclient.v1_1.contrib import baremetal @@ -186,13 +185,11 @@ class RackViewTests(test.BaseAdminViewTests): self.assertEqual(resp.context['form']['uploaded_data'].value(), None) - @test.create_stubs({api.tuskar.Rack: ('create', 'register_nodes'), + @test.create_stubs({api.tuskar.Rack: ('create',), api.tuskar.ResourceClass: ('list',)}) def test_upload_rack_create(self): api.tuskar.Rack.create(IsA(http.request.HttpRequest), 'Rack1', '1', 'regionX', '192.168.111.0/24').AndReturn(None) - api.tuskar.Rack.register_nodes(IgnoreArg(), - IgnoreArg()).AndReturn(None) api.tuskar.ResourceClass.list( IsA(http.request.HttpRequest)).AndReturn( self.tuskar_resource_classes.list()) diff --git a/openstack_dashboard/dashboards/infrastructure/resource_management/racks/workflows.py b/openstack_dashboard/dashboards/infrastructure/resource_management/racks/workflows.py index 4c3651a8..1f197e55 100644 --- a/openstack_dashboard/dashboards/infrastructure/resource_management/racks/workflows.py +++ b/openstack_dashboard/dashboards/infrastructure/resource_management/racks/workflows.py @@ -162,13 +162,12 @@ class CreateRack(workflows.Workflow): def handle(self, request, data): try: if data['node_name'] is not None: - node = api - node = api.tuskar.Node.manager().create(data['node_name'], - data['cpus'], data['memory_mb'], - data['local_gb'], data['prov_mac_address'], - data['pm_address'], data['pm_user'], - data['pm_password'], data['terminal_port']) - + node = api.tuskar.Node.create( + request, data['node_name'], + data['cpus'], data['memory_mb'], + data['local_gb'], data['prov_mac_address'], + data['pm_address'], data['pm_user'], + data['pm_password'], data['terminal_port']) if node: node_id = node.id else: diff --git a/openstack_dashboard/dashboards/infrastructure/resource_management/resource_classes/tests.py b/openstack_dashboard/dashboards/infrastructure/resource_management/resource_classes/tests.py index 8c118cd6..3b4e2a76 100644 --- a/openstack_dashboard/dashboards/infrastructure/resource_management/resource_classes/tests.py +++ b/openstack_dashboard/dashboards/infrastructure/resource_management/resource_classes/tests.py @@ -23,16 +23,20 @@ class ResourceClassViewTests(test.BaseAdminViewTests): @test.create_stubs({ api.tuskar.FlavorTemplate: ('list',), - api.tuskar.Rack: ('list',) + api.tuskar.Rack: ('list',), + api.tuskar.ResourceClass: ('get',) }) def test_create_resource_class_get(self): all_templates = self.tuskar_flavor_templates.list() all_racks = self.tuskar_racks.list() + rc = self.tuskar_resource_classes.first() api.tuskar.FlavorTemplate.\ list(IsA(http.HttpRequest)).AndReturn(all_templates) api.tuskar.Rack.\ list(IsA(http.HttpRequest), True).AndReturn(all_racks) + api.tuskar.ResourceClass.\ + get(IsA(http.HttpRequest), rc.id).AndReturn(rc) self.mox.ReplayAll() url = reverse( diff --git a/openstack_dashboard/dashboards/infrastructure/resource_management/templates/resource_management/resource_classes/_detail_overview.html b/openstack_dashboard/dashboards/infrastructure/resource_management/templates/resource_management/resource_classes/_detail_overview.html index 8916e47e..a70be9be 100644 --- a/openstack_dashboard/dashboards/infrastructure/resource_management/templates/resource_management/resource_classes/_detail_overview.html +++ b/openstack_dashboard/dashboards/infrastructure/resource_management/templates/resource_management/resource_classes/_detail_overview.html @@ -8,7 +8,7 @@
{% trans "Racks" %}
-
{{ resource_class.racks|length }} {% trans "racks" %}
+
{{ resource_class.list_racks|length }} {% trans "racks" %}
{% trans "Nodes" %}
{{ resource_class.nodes|length }} {% trans "nodes" %}
diff --git a/openstack_dashboard/dashboards/infrastructure/resource_management/tests.py b/openstack_dashboard/dashboards/infrastructure/resource_management/tests.py index 612c48b0..59c0898d 100644 --- a/openstack_dashboard/dashboards/infrastructure/resource_management/tests.py +++ b/openstack_dashboard/dashboards/infrastructure/resource_management/tests.py @@ -29,23 +29,21 @@ class ResourceManagementTests(test.BaseAdminViewTests): @test.create_stubs({ api.tuskar.ResourceClass: ( + 'get', 'list', 'list_racks', 'nodes'), api.tuskar.FlavorTemplate: ( 'list',), + api.tuskar.Node: ( + 'list',), api.tuskar.Rack: ( 'list',)}) def test_index(self): - # FlavorTemplate stubs - flavors = self.tuskar_flavors.list() - - api.tuskar.FlavorTemplate.list(IsA(http.HttpRequest)).AndReturn( - flavors) - # FlavorTemplate stubs end # ResourceClass stubs - all_resource_classes = self.tuskar_resource_classes.list() + resource_classes = self.tuskar_resource_classes.list() + resource_class = self.tuskar_resource_classes.first() nodes = [] racks = [] @@ -54,15 +52,27 @@ class ResourceManagementTests(test.BaseAdminViewTests): api.tuskar.ResourceClass.list( IsA(http.HttpRequest)).\ - AndReturn(all_resource_classes) + AndReturn(resource_classes) + + api.tuskar.ResourceClass.get( + IsA(http.HttpRequest), resource_class.id).\ + AndReturn(resource_class) # ResourceClass stubs end # Rack stubs racks = self.tuskar_racks.list() api.tuskar.Rack.list(IsA(http.HttpRequest)).AndReturn(racks) + api.tuskar.Node.list(IsA(http.HttpRequest)).AndReturn(nodes) # Rack stubs end + # FlavorTemplate stubs + flavors = self.tuskar_flavors.list() + + api.tuskar.FlavorTemplate.list(IsA(http.HttpRequest)).AndReturn( + flavors) + # FlavorTemplate stubs end + self.mox.ReplayAll() url = reverse('horizon:infrastructure:resource_management:index') @@ -76,7 +86,7 @@ class ResourceManagementTests(test.BaseAdminViewTests): # ResourceClass asserts self.assertItemsEqual(res.context['resource_classes_table'].data, - all_resource_classes) + resource_classes) # ResourceClass asserts end # Rack asserts diff --git a/openstack_dashboard/test/test_data/tuskar_data.py b/openstack_dashboard/test/test_data/tuskar_data.py index 25e53d63..b6890cc5 100644 --- a/openstack_dashboard/test/test_data/tuskar_data.py +++ b/openstack_dashboard/test/test_data/tuskar_data.py @@ -10,6 +10,8 @@ # License for the specific language governing permissions and limitations # under the License. +from collections import namedtuple + from openstack_dashboard.api.tuskar import Capacity from openstack_dashboard.api.tuskar import Flavor from openstack_dashboard.api.tuskar import FlavorTemplate @@ -17,10 +19,6 @@ from openstack_dashboard.api.tuskar import Node from openstack_dashboard.api.tuskar import Rack from openstack_dashboard.api.tuskar import ResourceClass -from collections import namedtuple - -import openstack_dashboard.dashboards.infrastructure.models as dummymodels - from openstack_dashboard.test.test_data.utils import TestDataContainer @@ -135,37 +133,27 @@ def data(TEST): TEST.nodes = TestDataContainer() TEST.unracked_nodes = TestDataContainer() - node_1 = Node(dummymodels.Node(id="1", - name="node1", - rack_id=1, - mac_address="00-B0-D0-86-AB-F7", - ip_address="192.168.191.11", - status="active", - usage="20")) - node_2 = Node(dummymodels.Node(id="2", - name="node2", - rack_id=1, - mac_address="00-B0-D0-86-AB-F8", - ip_address="192.168.191.12", - status="active", - usage="20")) - node_3 = Node(dummymodels.Node(id="3", - name="node3", - rack_id=1, - mac_address="00-B0-D0-86-AB-F9", - ip_address="192.168.191.13", - status="active", - usage="20")) - node_4 = Node(dummymodels.Node(id="4", - name="node4", - rack_id=1, - mac_address="00-B0-D0-86-AB-F0", - ip_address="192.168.191.14", - status="active", - usage="20")) - node_5 = Node(dummymodels.Node(id="5", - name="node5", - mac_address="00-B0-D0-86-AB-F1")) + NodeStruct = namedtuple('RackStruct', 'id name prov_mac_address') + node_1 = Node(NodeStruct( + id="1", + name="node1", + prov_mac_address="00-B0-D0-86-AB-F7")) + node_2 = Node(NodeStruct( + id="2", + name="node2", + prov_mac_address="00-B0-D0-86-AB-F8")) + node_3 = Node(NodeStruct( + id="3", + name="node3", + prov_mac_address="00-B0-D0-86-AB-F9")) + node_4 = Node(NodeStruct( + id="4", + name="node4", + prov_mac_address="00-B0-D0-86-AB-F0")) + node_5 = Node(NodeStruct( + id="5", + name="node5", + prov_mac_address="00-B0-D0-86-AB-F1")) TEST.nodes.add(node_1, node_2, node_3, node_4) TEST.unracked_nodes.add(node_5) -- cgit v1.2.1