コード例 #1
0
    def test_poolmgr_get_pools(self, mock_pool, mock_api, mock_creds, mock_cfg):
        """Test get_pools"""

        mgr = PoolManager(mock_creds, cfg=mock_cfg)

        resp = mock.create_autospec(Response)
        resp.success = False
        resp.result = RestCallException(None, "test", None)
        mgr._client.list_pools.return_value = resp

        with self.assertRaises(RestCallException):
            mgr.get_pools()
        mgr._client.list_pools.assert_called_with()

        resp.success = True
        resp.result = {'pools':[]}
        pools = mgr.get_pools()
        mgr._client.list_pools.assert_called_with()
        self.assertEqual(pools, [])
        self.assertEqual(len(mgr), 0)

        resp.result = {'totalCount':1,
                       'pools':[{'id':'abc', 'targetDedicated':'1', 'state':'active'}]}

        pools = mgr.get_pools()
        mock_pool.assert_called_with(mgr._client, **resp.result['pools'][0])
        self.assertEqual(len(pools), 1)
コード例 #2
0
    def test_poolmgr_create_spec(self, mock_pool, mock_api, mock_creds, mock_cfg):
        """Test create_spec"""

        mgr = PoolManager(mock_creds, cfg=mock_cfg)
        spec = mgr.create_spec()
        mock_pool.assert_called_with(mock.ANY, 0, 1, False)

        spec = mgr.create_spec(target_size=3, max_tasks=3, communication=True)
        mock_pool.assert_called_with(mock.ANY, 3, 3, True)
コード例 #3
0
    def test_poolmgr_create_spec(self, mock_pool, mock_api, mock_creds,
                                 mock_cfg):
        """Test create_spec"""

        mgr = PoolManager(mock_creds, cfg=mock_cfg)
        spec = mgr.create_spec()
        mock_pool.assert_called_with(mock.ANY, 0, 1, False)

        spec = mgr.create_spec(target_size=3, max_tasks=3, communication=True)
        mock_pool.assert_called_with(mock.ANY, 3, 3, True)
コード例 #4
0
    def test_poolmgr_create(self, mock_get, mock_pool, mock_api, mock_creds, mock_cfg):
        """Test create_spec"""

        spec = mock.create_autospec(PoolSpecifier)
        mgr = PoolManager(mock_creds, cfg=mock_cfg)

        pool = mgr.create(spec)
        self.assertFalse(mock_pool.called)
        self.assertTrue(spec.start.called)

        pool = mgr.create()
        mock_pool.assert_called_with(mock.ANY, 0, 1, False)
        self.assertTrue(mock_get.called)
コード例 #5
0
    def test_poolmgr_get_pool(self, mock_pool, mock_api, mock_creds, mock_cfg):
        """Test get_pool"""

        mgr = PoolManager(mock_creds, cfg=mock_cfg)

        with self.assertRaises(ValueError):
            mgr.get_pool()

        resp = mock.create_autospec(Response)
        resp.success = False
        resp.result = RestCallException(None, "test", None)
        mgr._client.get_pool.return_value = resp

        with self.assertRaises(RestCallException):
            mgr.get_pool(url="http://test")
        mgr._client.get_pool.assert_called_with(url="http://test")

        resp.success = True
        resp.result = {'id': '1', 'autoPool': False, 'state': 'test'}
        job = mgr.get_pool(url="http://test")
        mgr._client.get_pool.assert_called_with(url="http://test")
        mock_pool.assert_called_with(mgr._client,
                                     id='1',
                                     autoPool=False,
                                     state="test")

        resp.result = {'id': '1', 'name': '2', 'type': '3', 'other': '4'}
        job = mgr.get_pool(poolid="test_id")
        mgr._client.get_pool.assert_called_with(pool_id="test_id")
コード例 #6
0
    def test_poolmgr_create(self, mock_get, mock_pool, mock_api, mock_creds,
                            mock_cfg):
        """Test create_spec"""

        spec = mock.create_autospec(PoolSpecifier)
        mgr = PoolManager(mock_creds, cfg=mock_cfg)

        pool = mgr.create(spec)
        self.assertFalse(mock_pool.called)
        self.assertTrue(spec.start.called)

        pool = mgr.create()
        mock_pool.assert_called_with(mock.ANY, 0, 1, False)
        self.assertTrue(mock_get.called)
コード例 #7
0
    def test_poolmgr_get_pool(self, mock_pool, mock_api, mock_creds, mock_cfg):
        """Test get_pool"""

        mgr = PoolManager(mock_creds, cfg=mock_cfg)

        with self.assertRaises(ValueError):
            mgr.get_pool()

        resp = mock.create_autospec(Response)
        resp.success = False
        resp.result = RestCallException(None, "test", None)
        mgr._client.get_pool.return_value = resp

        with self.assertRaises(RestCallException):
            mgr.get_pool(url="http://test")
        mgr._client.get_pool.assert_called_with(url="http://test")

        resp.success = True
        resp.result = {'id':'1', 'autoPool':False, 'state':'test'}
        job = mgr.get_pool(url="http://test")
        mgr._client.get_pool.assert_called_with(url="http://test")
        mock_pool.assert_called_with(mgr._client, id='1', autoPool=False, state="test")

        resp.result = {'id':'1', 'name':'2', 'type':'3', 'other':'4'}
        job = mgr.get_pool(poolid="test_id")
        mgr._client.get_pool.assert_called_with(pool_id="test_id")
コード例 #8
0
    def test_poolmgr_get_pools(self, mock_pool, mock_api, mock_creds,
                               mock_cfg):
        """Test get_pools"""

        mgr = PoolManager(mock_creds, cfg=mock_cfg)

        resp = mock.create_autospec(Response)
        resp.success = False
        resp.result = RestCallException(None, "test", None)
        mgr._client.list_pools.return_value = resp

        with self.assertRaises(RestCallException):
            mgr.get_pools()
        mgr._client.list_pools.assert_called_with()

        resp.success = True
        resp.result = {'pools': []}
        pools = mgr.get_pools()
        mgr._client.list_pools.assert_called_with()
        self.assertEqual(pools, [])
        self.assertEqual(len(mgr), 0)

        resp.result = {
            'totalCount': 1,
            'pools': [{
                'id': 'abc',
                'targetDedicated': '1',
                'state': 'active'
            }]
        }

        pools = mgr.get_pools()
        mock_pool.assert_called_with(mgr._client, **resp.result['pools'][0])
        self.assertEqual(len(pools), 1)
コード例 #9
0
    def test_poolmgr_clear_pools(self, mock_pool, mock_api, mock_creds,
                                 mock_cfg):
        """Test clear_pools"""

        mgr = PoolManager(mock_creds, cfg=mock_cfg)
        mgr.count = 1
        poolA = mock.create_autospec(Pool)
        mock_pool.return_value = [poolA]

        failed = mgr.clear_pools()
        self.assertEqual(failed, [])
        self.assertEqual(len(mgr), 0)
        self.assertTrue(poolA.delete.called)

        poolA.delete.side_effect = RestCallException(None, "test", None)
        mgr.count = 1
        failed = mgr.clear_pools()
        self.assertEqual(failed, [(poolA, poolA.delete.side_effect)])
        self.assertEqual(len(mgr), 1)

        mock_pool.side_effect = RestCallException(None, "test", None)
        with self.assertRaises(RestCallException):
            mgr.clear_pools()
コード例 #10
0
    def test_poolmgr_clear_pools(self, mock_pool, mock_api, mock_creds, mock_cfg):
        """Test clear_pools"""

        mgr = PoolManager(mock_creds, cfg=mock_cfg)
        mgr.count = 1
        poolA = mock.create_autospec(Pool)
        mock_pool.return_value = [poolA]

        failed = mgr.clear_pools()
        self.assertEqual(failed, [])
        self.assertEqual(len(mgr), 0)
        self.assertTrue(poolA.delete.called)

        poolA.delete.side_effect = RestCallException(None, "test", None)
        mgr.count = 1
        failed = mgr.clear_pools()
        self.assertEqual(failed, [(poolA, poolA.delete.side_effect)])
        self.assertEqual(len(mgr), 1)

        mock_pool.side_effect = RestCallException(None, "test", None)
        with self.assertRaises(RestCallException):
            mgr.clear_pools()