Exemplo n.º 1
0
    def test_cluster_op_no_nodes_found(self, mock_find, mock_cluster,
                                       mock_nodes, mock_action):
        x_db_cluster = mock.Mock()
        mock_find.return_value = x_db_cluster
        x_schema = mock.Mock()
        x_profile = mock.Mock(OPERATIONS={'dance': x_schema})
        x_cluster = mock.Mock(id='12345678AB')
        x_cluster.rt = {'profile': x_profile}
        mock_cluster.return_value = x_cluster
        mock_nodes.return_value = []
        mock_action.return_value = 'ACTION_ID'
        filters = {'role': 'slave'}
        req = orco.ClusterOperationRequest(identity='FAKE_CLUSTER',
                                           operation='dance',
                                           filters=filters)

        ex = self.assertRaises(rpc.ExpectedException, self.eng.cluster_op,
                               self.ctx, req.obj_to_primitive())

        self.assertEqual(exc.BadRequest, ex.exc_info[0])
        self.assertEqual("No node (matching the filter) could be found.",
                         six.text_type(ex.exc_info[1]))
        mock_find.assert_called_once_with(self.ctx, 'FAKE_CLUSTER')
        mock_cluster.assert_called_once_with(self.ctx, db_cluster=x_db_cluster)
        mock_nodes.assert_called_once_with(self.ctx,
                                           '12345678AB',
                                           filters={'role': 'slave'})
        self.assertEqual(0, mock_action.call_count)
Exemplo n.º 2
0
    def test_cluster_op_bad_filters(self, mock_find, mock_cluster, mock_nodes,
                                    mock_action):
        x_db_cluster = mock.Mock()
        mock_find.return_value = x_db_cluster
        x_schema = mock.Mock()
        x_profile = mock.Mock(OPERATIONS={'dance': x_schema})
        x_cluster = mock.Mock(id='12345678AB')
        x_cluster.rt = {'profile': x_profile}
        mock_cluster.return_value = x_cluster
        mock_action.return_value = 'ACTION_ID'
        mock_nodes.return_value = ['NODE1', 'NODE2']
        filters = {'shape': 'round'}
        req = orco.ClusterOperationRequest(identity='FAKE_CLUSTER',
                                           operation='dance',
                                           filters=filters)

        ex = self.assertRaises(rpc.ExpectedException, self.eng.cluster_op,
                               self.ctx, req.obj_to_primitive())

        self.assertEqual(exc.BadRequest, ex.exc_info[0])
        self.assertEqual("Filter key 'shape' is unsupported.",
                         six.text_type(ex.exc_info[1]))
        mock_find.assert_called_once_with(self.ctx, 'FAKE_CLUSTER')
        mock_cluster.assert_called_once_with(self.ctx, db_cluster=x_db_cluster)
        self.assertEqual(0, x_schema.validate.call_count)
        self.assertEqual(0, mock_nodes.call_count)
        self.assertEqual(0, mock_action.call_count)
Exemplo n.º 3
0
    def test_cluster_op_no_filters(self, mock_find, mock_cluster, mock_nodes,
                                   mock_action, mock_start):
        x_db_cluster = mock.Mock()
        mock_find.return_value = x_db_cluster
        x_schema = mock.Mock()
        x_profile = mock.Mock(OPERATIONS={'dance': x_schema})
        x_cluster = mock.Mock(id='12345678AB')
        x_cluster.rt = {'profile': x_profile}
        mock_cluster.return_value = x_cluster
        mock_action.return_value = 'ACTION_ID'
        mock_nodes.return_value = ['NODE1', 'NODE2']
        req = orco.ClusterOperationRequest(identity='FAKE_CLUSTER',
                                           operation='dance')

        result = self.eng.cluster_op(self.ctx, req.obj_to_primitive())

        self.assertEqual({'action': 'ACTION_ID'}, result)
        mock_find.assert_called_once_with(self.ctx, 'FAKE_CLUSTER')
        mock_cluster.assert_called_once_with(self.ctx, db_cluster=x_db_cluster)
        self.assertEqual(0, x_schema.validate.call_count)
        mock_nodes.assert_called_once_with(self.ctx, '12345678AB')
        mock_action.assert_called_once_with(self.ctx,
                                            '12345678AB',
                                            consts.CLUSTER_OPERATION,
                                            name='cluster_dance_12345678',
                                            cause=consts.CAUSE_RPC,
                                            status=am.Action.READY,
                                            inputs={
                                                'operation': 'dance',
                                                'params': {},
                                                'nodes': ['NODE1', 'NODE2']
                                            })
        mock_start.assert_called_once_with()
Exemplo n.º 4
0
    def test_init(self):
        sot = clusters.ClusterOperationRequest(identity='foo',
                                               filters={'role': 'slave'},
                                               operation='dance',
                                               params={'style': 'tango'})

        self.assertEqual('foo', sot.identity)
        self.assertEqual('dance', sot.operation)
        self.assertEqual({'role': 'slave'}, sot.filters)
        self.assertEqual({'style': 'tango'}, sot.params)
Exemplo n.º 5
0
    def test_cluster_op_cluster_not_found(self, mock_find):
        mock_find.side_effect = exc.ResourceNotFound(type='cluster',
                                                     id='Bogus')
        req = orco.ClusterOperationRequest(identity='Bogus', operation='dance')
        ex = self.assertRaises(rpc.ExpectedException, self.eng.cluster_op,
                               self.ctx, req.obj_to_primitive())

        self.assertEqual(exc.ResourceNotFound, ex.exc_info[0])
        self.assertEqual("The cluster 'Bogus' could not be found.",
                         six.text_type(ex.exc_info[1]))
        mock_find.assert_called_once_with(self.ctx, 'Bogus')
Exemplo n.º 6
0
    def test_init_minimal(self):
        sot = clusters.ClusterOperationRequest(identity='foo',
                                               operation='dance')

        self.assertEqual('foo', sot.identity)
        self.assertEqual('dance', sot.operation)
        self.assertFalse(sot.obj_attr_is_set('filters'))
        self.assertFalse(sot.obj_attr_is_set('params'))
        sot.obj_set_defaults()
        self.assertEqual({}, sot.filters)
        self.assertEqual({}, sot.params)
Exemplo n.º 7
0
    def test_cluster_op_unsupported_operation(self, mock_find, mock_cluster):
        x_db_cluster = mock.Mock(id='12345678AB')
        mock_find.return_value = x_db_cluster
        x_schema = mock.Mock()
        x_profile = mock.Mock(OPERATIONS={'dance': x_schema}, type='cow')
        x_cluster = mock.Mock()
        x_cluster.rt = {'profile': x_profile}
        mock_cluster.return_value = x_cluster
        req = orco.ClusterOperationRequest(identity='node1', operation='swim')

        ex = self.assertRaises(rpc.ExpectedException, self.eng.cluster_op,
                               self.ctx, req.obj_to_primitive())

        self.assertEqual(exc.BadRequest, ex.exc_info[0])
        self.assertEqual(
            "The requested operation 'swim' is not supported "
            "by the profile type 'cow'.", six.text_type(ex.exc_info[1]))
        mock_find.assert_called_once_with(self.ctx, 'node1')
        mock_cluster.assert_called_once_with(self.ctx, db_cluster=x_db_cluster)
Exemplo n.º 8
0
    def test_cluster_op_bad_parameters(self, mock_find, mock_cluster):
        x_db_cluster = mock.Mock(id='12345678AB')
        mock_find.return_value = x_db_cluster
        x_schema = mock.Mock()
        x_schema.validate.side_effect = exc.ESchema(message='Boom')
        x_profile = mock.Mock(OPERATIONS={'dance': x_schema})
        x_cluster = mock.Mock()
        x_cluster.rt = {'profile': x_profile}
        mock_cluster.return_value = x_cluster
        req = orco.ClusterOperationRequest(identity='node1',
                                           operation='dance',
                                           params={'style': 'tango'})

        ex = self.assertRaises(rpc.ExpectedException, self.eng.cluster_op,
                               self.ctx, req.obj_to_primitive())

        self.assertEqual(exc.BadRequest, ex.exc_info[0])
        self.assertEqual("Boom.", six.text_type(ex.exc_info[1]))
        mock_find.assert_called_once_with(self.ctx, 'node1')
        mock_cluster.assert_called_once_with(self.ctx, db_cluster=x_db_cluster)
        x_schema.validate.assert_called_once_with({'style': 'tango'})