Fix baremetal get_available_nodes

Baremetal driver get_available_nodes was incorrectly returning only a
list of unprovisioned nodes, leading update_availabile_resources to
sometimes delete a baremetal node that had an instance provisioned
to it -- sometimes even while the provisioning was still in process.

Fix bug 1174952

Change-Id: I4f08a2f6539a5b6cd12245ac6b4dc308767ae0cd
This commit is contained in:
Devananda van der Veen 2013-04-30 14:34:56 -07:00
parent 98c4e04ac6
commit 112a2f11f8
2 changed files with 2 additions and 30 deletions

View File

@ -283,38 +283,10 @@ class BareMetalDriverWithDBTestCase(bm_db_base.BMDBTestCase):
node1 = self._create_node() node1 = self._create_node()
self.assertEqual(1, len(self.driver.get_available_nodes())) self.assertEqual(1, len(self.driver.get_available_nodes()))
node_info = bm_db_utils.new_bm_node(
id=456,
service_host='test_host',
cpus=2,
memory_mb=2048,
)
nic_info = [
{'address': 'cc:cc:cc', 'datapath_id': '0x1',
'port_no': 1},
{'address': 'dd:dd:dd', 'datapath_id': '0x2',
'port_no': 2},
]
node2 = self._create_node(node_info=node_info, nic_info=nic_info)
self.assertEqual(2, len(self.driver.get_available_nodes()))
self.assertEqual([node1['node']['uuid'], node2['node']['uuid']],
self.driver.get_available_nodes())
node1['instance']['hostname'] = 'test-host-1' node1['instance']['hostname'] = 'test-host-1'
node2['instance']['hostname'] = 'test-host-2'
self.driver.spawn(**node1['spawn_params']) self.driver.spawn(**node1['spawn_params'])
self.assertEqual(1, len(self.driver.get_available_nodes())) self.assertEqual(1, len(self.driver.get_available_nodes()))
self.assertEqual([node1['node']['uuid']],
self.driver.spawn(**node2['spawn_params'])
self.assertEqual(0, len(self.driver.get_available_nodes()))
self.driver.destroy(**node1['destroy_params'])
self.assertEqual(1, len(self.driver.get_available_nodes()))
self.driver.destroy(**node2['destroy_params'])
self.assertEqual(2, len(self.driver.get_available_nodes()))
self.assertEqual([node1['node']['uuid'], node2['node']['uuid']],
self.driver.get_available_nodes()) self.driver.get_available_nodes())
def test_list_instances(self): def test_list_instances(self):

View File

@ -486,4 +486,4 @@ class BareMetalDriver(driver.ComputeDriver):
def get_available_nodes(self): def get_available_nodes(self):
context = nova_context.get_admin_context() context = nova_context.get_admin_context()
return [str(n['uuid']) for n in return [str(n['uuid']) for n in
db.bm_node_get_unassociated(context, service_host=CONF.host)] db.bm_node_get_all(context, service_host=CONF.host)]