def create_node(self, values): # ensure defaults are present for new nodes if not values.get('uuid'): values['uuid'] = utils.generate_uuid() node = models.Node() node.update(values) try: node.save() except db_exc.DBDuplicateEntry as exc: if 'ironic_node_id' in exc.columns: raise exception.InstanceAssociated( instance_uuid=values['ironic_node_id'], node=values['uuid']) raise exception.NodeAlreadyExists(uuid=values['uuid']) return node
def test_NodeAlreadyExists(self): self.assertRaises(exception.NodeAlreadyExists, lambda: self.raise_(exception.NodeAlreadyExists()))