Exemple #1
0
    def test_node_list2_empty(self, mock_load):
        mock_load.return_value = []

        req = orno.NodeListRequest()
        result = self.eng.node_list2(self.ctx, req.obj_to_primitive())

        self.assertEqual([], result)
        mock_load.assert_called_once_with(self.ctx, project_safe=True)
Exemple #2
0
    def test_node_list2_with_project_safe(self, mock_load):
        mock_load.return_value = []

        req = orno.NodeListRequest(project_safe=True)
        result = self.eng.node_list2(self.ctx, req.obj_to_primitive())
        self.assertEqual([], result)
        mock_load.assert_called_once_with(self.ctx, project_safe=True)
        mock_load.reset_mock()

        req = orno.NodeListRequest(project_safe=False)
        ex = self.assertRaises(rpc.ExpectedException, self.eng.node_list2,
                               self.ctx, req.obj_to_primitive())
        self.assertEqual(exc.Forbidden, ex.exc_info[0])

        self.ctx.is_admin = True
        req = orno.NodeListRequest(project_safe=False)
        result = self.eng.node_list2(self.ctx, req.obj_to_primitive())
        self.assertEqual([], result)
        mock_load.assert_called_once_with(self.ctx, project_safe=False)
        mock_load.reset_mock()
Exemple #3
0
    def test_node_list2(self, mock_load):
        obj_1 = mock.Mock()
        obj_1.to_dict.return_value = {'k': 'v1'}
        obj_2 = mock.Mock()
        obj_2.to_dict.return_value = {'k': 'v2'}
        mock_load.return_value = [obj_1, obj_2]

        req = orno.NodeListRequest()
        result = self.eng.node_list2(self.ctx, req.obj_to_primitive())

        self.assertEqual([{'k': 'v1'}, {'k': 'v2'}], result)
        mock_load.assert_called_once_with(self.ctx, project_safe=True)
Exemple #4
0
    def test_node_list2_cluster_not_found(self, mock_find):
        mock_find.side_effect = exc.ResourceNotFound(type='cluster',
                                                     id='BOGUS')

        req = orno.NodeListRequest(cluster_id='BOGUS', project_safe=True)

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

        self.assertEqual(exc.BadRequest, ex.exc_info[0])
        self.assertEqual(
            'The request is malformed: Cannot find the given '
            'cluster: BOGUS.', six.text_type(ex.exc_info[1]))
        mock_find.assert_called_once_with(self.ctx, 'BOGUS')
Exemple #5
0
    def test_node_list_with_cluster_id(self, mock_get, mock_find):
        obj_1 = mock.Mock()
        obj_1.to_dict.return_value = {'k': 'v1'}
        obj_2 = mock.Mock()
        obj_2.to_dict.return_value = {'k': 'v2'}
        mock_get.return_value = [obj_1, obj_2]
        mock_find.return_value = mock.Mock(id='CLUSTER_ID')

        req = orno.NodeListRequest(cluster_id='MY_CLUSTER_NAME',
                                   project_safe=True)
        result = self.eng.node_list(self.ctx, req.obj_to_primitive())

        self.assertEqual([{'k': 'v1'}, {'k': 'v2'}], result)
        mock_find.assert_called_once_with(self.ctx, 'MY_CLUSTER_NAME')
        mock_get.assert_called_once_with(self.ctx, cluster_id='CLUSTER_ID',
                                         project_safe=True)
Exemple #6
0
    def test_node_list_with_params(self, mock_get):
        obj_1 = mock.Mock()
        obj_1.to_dict.return_value = {'k': 'v1'}
        obj_2 = mock.Mock()
        obj_2.to_dict.return_value = {'k': 'v2'}
        mock_get.return_value = [obj_1, obj_2]

        MARKER_UUID = '2fd5b45f-bae4-4cdb-b283-a71e9f9805c7'
        req = orno.NodeListRequest(status=['ACTIVE'], sort='status',
                                   limit=123, marker=MARKER_UUID,
                                   project_safe=True)
        result = self.eng.node_list(self.ctx, req.obj_to_primitive())

        self.assertEqual([{'k': 'v1'}, {'k': 'v2'}], result)
        mock_get.assert_called_once_with(self.ctx, sort='status', limit=123,
                                         marker=MARKER_UUID, project_safe=True,
                                         filters={'status': ['ACTIVE']})
Exemple #7
0
 def test_node_list_request_body_full(self):
     params = {
         'cluster_id': '8c3c9af7-d768-4c5a-a21e-5261b22d749d',
         'name': ['node01'],
         'status': ['ACTIVE'],
         'limit': 3,
         'marker': 'f1ed0d50-7651-4599-a8cb-c86e9c7123f5',
         'sort': 'name:asc',
         'project_safe': False,
     }
     sot = nodes.NodeListRequest(**params)
     self.assertEqual('8c3c9af7-d768-4c5a-a21e-5261b22d749d',
                      sot.cluster_id)
     self.assertEqual(['node01'], sot.name)
     self.assertEqual(['ACTIVE'], sot.status)
     self.assertEqual(3, sot.limit)
     self.assertEqual('f1ed0d50-7651-4599-a8cb-c86e9c7123f5', sot.marker)
     self.assertEqual('name:asc', sot.sort)
     self.assertFalse(sot.project_safe)
Exemple #8
0
 def test_node_list_request_body_default(self):
     sot = nodes.NodeListRequest()
     sot.obj_set_defaults()
     self.assertTrue(sot.project_safe)