def test_get_all(self): r = bmdb.bm_node_get_all(self.context) self.assertEquals(r, []) self._create_hosts() r = bmdb.bm_node_get_all(self.context) self.assertEquals(len(r), 3)
def test_get_by_service_host(self): self._create_hosts() r = bmdb.bm_node_get_all(self.context, service_host="host1") self.assertEquals(len(r), 1) self.assertEquals(r[0]['id'], self.h1['id']) r = bmdb.bm_node_get_all(self.context, service_host="host2") self.assertEquals(len(r), 2) ids = [x['id'] for x in r] self.assertIn(self.h2['id'], ids) self.assertIn(self.h3['id'], ids) r = bmdb.bm_node_get_all(self.context, service_host="host3") self.assertEquals(r, [])
def test_destroy(self): self._create_hosts() bmdb.bm_node_destroy(self.context, self.h1['id']) r = bmdb.bm_node_get(self.context, self.h1['id']) self.assertTrue(r is None) r = bmdb.bm_node_get_all(self.context) self.assertEquals(len(r), 2)
def _get_baremetal_node_by_instance_name(instance_name): context = nova_context.get_admin_context() for node in bmdb.bm_node_get_all(context, service_host=FLAGS.host): if not node['instance_uuid']: continue try: inst = db.instance_get_by_uuid(context, node['instance_uuid']) if inst['name'] == instance_name: return node except exception.InstanceNotFound: continue return None
def _get_baremetal_nodes(context): nodes = bmdb.bm_node_get_all(context, service_host=FLAGS.host) return nodes