Ejemplo n.º 1
0
def node_update(context, node_id, values):
    '''Update a node with new property values.

    :param node_id: ID of the node to be updated.
    :param values: A dictionary of values to be updated on the node.
    :raises ClusterNotFound: The specified node does not exist in database.
    '''
    with session_for_write() as session:
        node = session.query(models.Node).get(node_id)
        if not node:
            raise exception.NodeNotFound(node=node_id)

        node.update(values)
        node.save(session)
        if 'status' in values and node.cluster_id is not None:
            cluster = session.query(models.Cluster).get(node.cluster_id)
            if cluster is not None:
                if values['status'] == 'ERROR':
                    cluster.status = 'WARNING'
                if 'status_reason' in values:
                    cluster.status_reason = _('Node %(node)s: %(reason)s') % {
                        'node': node.name,
                        'reason': values['status_reason']
                    }
                cluster.save(session)
Ejemplo n.º 2
0
    def test_local_error_name(self):
        ex = exception.NodeNotFound(node='A')
        self.assertEqual('NodeNotFound', self.rpcapi.local_error_name(ex))

        exr = self._to_remote_error(ex)
        self.assertEqual('NodeNotFound_Remote', exr.__class__.__name__)
        self.assertEqual('NodeNotFound', self.rpcapi.local_error_name(exr))
Ejemplo n.º 3
0
    def test_node_action_join_node_not_found(self, mock_enforce):
        self._mock_enforce_setup(mock_enforce, 'action', True)
        node_id = 'unknown-node'
        cluster_id = 'existing_cluster'
        body = {
            'join': {
                'cluster_id': cluster_id,
            }
        }
        req = self._put('/nodes/%(node_id)s/action' % {'node_id': node_id},
                        json.dumps(body))

        error = senlin_exc.NodeNotFound(node=node_id)
        mock_call = self.patchobject(rpc_client.EngineClient, 'call')
        mock_call.side_effect = shared.to_remote_error(error)

        resp = shared.request_with_middleware(fault.FaultWrapper,
                                              self.controller.action,
                                              req,
                                              tenant_id=self.project,
                                              node_id=node_id,
                                              body=body)

        self.assertEqual(404, resp.json['code'])
        self.assertEqual('NodeNotFound', resp.json['error']['type'])
Ejemplo n.º 4
0
    def load(cls, context, node_id=None, node=None, project_safe=True):
        '''Retrieve a node from database.'''
        if node is None:
            node = db_api.node_get(context, node_id, project_safe=project_safe)
            if node is None:
                raise exception.NodeNotFound(node=node_id)

        return cls._from_db_record(context, node)
Ejemplo n.º 5
0
    def load(cls, context, node_id=None, node=None, show_deleted=False):
        '''Retrieve a node from database.'''
        if node is None:
            node = db_api.node_get(context, node_id, show_deleted=show_deleted)
            if node is None:
                raise exception.NodeNotFound(node=node_id)

        return cls._from_db_record(context, node)
Ejemplo n.º 6
0
    def load(cls, context, node_id=None, db_node=None, project_safe=True):
        '''Retrieve a node from database.'''
        if db_node is None:
            db_node = no.Node.get(context, node_id, project_safe=project_safe)
            if db_node is None:
                raise exception.NodeNotFound(node=node_id)

        return cls._from_object(context, db_node)
Ejemplo n.º 7
0
    def test_node_recover_not_found(self, mock_find):
        mock_find.side_effect = exc.NodeNotFound(node='Bogus')

        ex = self.assertRaises(rpc.ExpectedException, self.eng.node_recover,
                               self.ctx, 'Bogus')

        self.assertEqual(exc.NodeNotFound, ex.exc_info[0])
        self.assertEqual('The node (Bogus) could not be found.',
                         six.text_type(ex.exc_info[1]))
        mock_find.assert_called_once_with(self.ctx, 'Bogus')
Ejemplo n.º 8
0
    def test_ignore_error_named(self):
        ex = exception.NodeNotFound(node='A')
        exr = self._to_remote_error(ex)

        self.rpcapi.ignore_error_named(ex, 'NodeNotFound')
        self.rpcapi.ignore_error_named(exr, 'NodeNotFound')
        self.assertRaises(exception.NodeNotFound,
                          self.rpcapi.ignore_error_named, ex, 'NotSupported')
        self.assertRaises(exception.NodeNotFound,
                          self.rpcapi.ignore_error_named, exr, 'NotSupported')
Ejemplo n.º 9
0
    def test_node_delete_not_found(self, mock_enforce):
        self._mock_enforce_setup(mock_enforce, 'delete', True)
        nid = 'aaaa-bbbb-cccc'
        req = self._delete('/nodes/%(node_id)s' % {'node_id': nid})

        error = senlin_exc.NodeNotFound(node=nid)
        mock_call = self.patchobject(rpc_client.EngineClient, 'call')
        mock_call.side_effect = shared.to_remote_error(error)

        resp = shared.request_with_middleware(fault.FaultWrapper,
                                              self.controller.delete,
                                              req, node_id=nid)

        self.assertEqual(404, resp.json['code'])
        self.assertEqual('NodeNotFound', resp.json['error']['type'])
Ejemplo n.º 10
0
    def test_node_get_not_found(self, mock_enforce):
        self._mock_enforce_setup(mock_enforce, 'get', True)
        node_id = 'non-existent-node'
        req = self._get('/nodes/%(node_id)s' % {'node_id': node_id})

        error = senlin_exc.NodeNotFound(node=node_id)
        mock_call = self.patchobject(rpc_client.EngineClient, 'call')
        mock_call.side_effect = shared.to_remote_error(error)

        resp = shared.request_with_middleware(fault.FaultWrapper,
                                              self.controller.get,
                                              req,
                                              tenant_id=self.project,
                                              node_id=node_id)

        self.assertEqual(404, resp.json['code'])
        self.assertEqual('NodeNotFound', resp.json['error']['type'])
Ejemplo n.º 11
0
    def test_node_action_recover_node_not_found(self, mock_enforce):
        self._mock_enforce_setup(mock_enforce, 'action', True)
        node_id = 'xxxx-yyyy'
        body = {'recover': {}}
        req = self._post('/nodes/%(node_id)s/actions' % {'node_id': node_id},
                         jsonutils.dumps(body))

        error = senlin_exc.NodeNotFound(node=node_id)
        mock_call = self.patchobject(rpc_client.EngineClient, 'call')
        mock_call.side_effect = shared.to_remote_error(error)

        resp = shared.request_with_middleware(fault.FaultWrapper,
                                              self.controller.action,
                                              req, node_id=node_id, body=body)

        self.assertEqual(404, resp.json['code'])
        self.assertEqual('NodeNotFound', resp.json['error']['type'])

        mock_call.assert_called_once_with(
            req.context,
            ('node_recover', {'identity': node_id, 'params': {}}))
Ejemplo n.º 12
0
    def test_node_update_not_found(self, mock_enforce):
        self._mock_enforce_setup(mock_enforce, 'update', True)
        nid = 'non-exist-node'
        body = {
            'node': {
                'name': 'test_node',
                'profile_id': 'xxxx-yyyy',
                'role': None,
                'metadata': {},
            }
        }

        req = self._patch('/nodes/%(node_id)s' % {'node_id': nid},
                          json.dumps(body))

        error = senlin_exc.NodeNotFound(node=nid)
        mock_call = self.patchobject(rpc_client.EngineClient,
                                     'call',
                                     side_effect=shared.to_remote_error(error))

        resp = shared.request_with_middleware(fault.FaultWrapper,
                                              self.controller.update,
                                              req,
                                              tenant_id=self.project,
                                              node_id=nid,
                                              body=body)

        mock_call.assert_called_with(req.context, ('node_update', {
            'identity': nid,
            'name': 'test_node',
            'profile_id': 'xxxx-yyyy',
            'role': None,
            'metadata': {},
        }))

        self.assertEqual(404, resp.json['code'])
        self.assertEqual('NodeNotFound', resp.json['error']['type'])