示例#1
0
    def test_update_deploy_without_reals_success(self, test_patch):
        """Deploy update of one pool without reals with success by url.

            Method that factory in networkapi.plugins.factory.PluginFactory
            is mock to test the flow in deploys of pool by url.
        """

        mock = MockPlugin()
        mock.status(True)
        test_patch.return_value = mock

        name_file = 'api_pools/tests/sanity/json/mock/pool_3_put_created_' + \
            'without_reals.json'

        response = self.client.put(
            '/api/v3/pool/deploy/3/',
            data=json.dumps(self.load_json_file(name_file)),
            content_type='application/json',
            HTTP_AUTHORIZATION=self.get_http_authorization('test'))

        self.compare_status(200, response.status_code)

        response = self.client.get(
            '/api/v3/pool/3/',
            content_type='application/json',
            HTTP_AUTHORIZATION=self.get_http_authorization('test'))

        self.compare_status(200, response.status_code)

        self.compare_json(name_file, response.data)
    def test_create_deploy_with_mock_success_url(self, test_patch):
        """Deploy create of one pool with success by url.

            Method that factory in networkapi.plugins.factory.PluginFactory
            is mock to test the flow in deploys of pool by url.
        """
        mock = MockPlugin()
        mock.status(True)
        test_patch.return_value = mock

        name_file = 'api_pools/tests/sanity/json/mock/pool_2_created.json'

        response = self.client.post(
            '/api/v3/pool/deploy/2/',
            content_type='application/json',
            HTTP_AUTHORIZATION=self.get_http_authorization('test'))

        response = self.client.get(
            '/api/v3/pool/2/',
            content_type='application/json',
            HTTP_AUTHORIZATION=self.get_http_authorization('test'))

        self.compare_status(200, response.status_code)

        self.compare_json(name_file, response.data)
    def test_create_deploy_with_mock_success_url(self, test_patch):
        """Deploy create of one pool with success by url.

            Method that factory in networkapi.plugins.factory.PluginFactory
            is mock to test the flow in deploys of pool by url.
        """
        mock = MockPlugin()
        mock.status(True)
        test_patch.return_value = mock

        name_file = 'api_pools/tests/sanity/json/mock/pool_2_created.json'

        response = self.client.post(
            '/api/v3/pool/deploy/2/',
            content_type='application/json',
            HTTP_AUTHORIZATION=self.get_http_authorization('test'))

        response = self.client.get(
            '/api/v3/pool/2/',
            content_type='application/json',
            HTTP_AUTHORIZATION=self.get_http_authorization('test'))

        self.compare_status(200, response.status_code)

        self.compare_json(name_file, response.data)
示例#4
0
    def test_create_deploy_with_mock_error(self, test_patch):
        """
            Deploy create of one pool with error.
            Method that factory in networkapi.plugins.factory.PluginFactory
            is mock to test the flow in deploys of pool.
        """

        dp = self.load_json_file(
            'api_pools/tests/unit/json/test_pool_post_not_created.json')
        mock = MockPlugin()
        mock.status(False)
        test_patch.return_value = mock
        dp = dp.get('server_pools')
        self.assertRaises(Exception,
                          facade_pool_deploy.create_real_pool(dp, self.user))
    def test_delete_deploy_with_mock_error(self, test_patch):
        """
            Deploy delete of one pool with error.
            Method that factory in networkapi.plugins.factory.PluginFactory
            is mock to test the flow in deploys of pool.
        """

        dp = self.load_json_file(
            'api_pools/tests/unit/json/test_pool_delete_created.json')
        mock = MockPlugin()
        mock.status(False)
        test_patch.return_value = mock
        dp = dp.get('server_pools')
        self.assertRaises(
            Exception,
            facade_pool_deploy.delete_real_pool(dp, self.user)
        )
示例#6
0
    def test_update_deploy_with_mock_success(self, test_patch):
        """
            Deploy update of one pool with success.
            Method that factory in networkapi.plugins.factory.PluginFactory
            is mock to test the flow in deploys of pool.
        """

        dp = self.load_json_file(
            'api_pools/tests/unit/json/test_pool_put_created.json')
        test_patch.return_value = MockPlugin()
        dp = dp.get('server_pools')
        facade_pool_deploy.update_real_pool(dp, self.user)
    def test_update_deployed_pool_rm_half_reals_add_another(self, test_patch):
        """Tries to remove half of the reals in a deployed server pool and
        at same time adding a new real.
        """

        id = 41  # Pool with this ID has four members (IPs 53, 54, 55, 56)

        pool = self.client.get(
            '/api/v3/pool/%s/' % id,
            HTTP_AUTHORIZATION=self.get_http_authorization('test')).data

        self.assertEqual(4,
                         len(pool['server_pools'][0]['server_pool_members']),
                         'This server pool should have four members.')

        test_patch.return_value = MockPlugin()

        qt_reals = 3

        ipsv4 = [{
            'id': 53,
            'ip_formated': '10.0.0.53'
        }, {
            'id': 54,
            'ip_formated': '10.0.0.54'
        }, {
            'id': 57,
            'ip_formated': '10.0.0.57'
        }]

        server_pool_members = [
            self.build_server_pool_member(
                ip__id=ipsv4[i]['id'],
                ip__ip_formated=ipsv4[i]['ip_formated'],
                port_real=8) for i in range(qt_reals)
        ]

        pool['server_pools'][0]['server_pool_members'] = server_pool_members

        facade_pool_deploy.update_real_pool(pool['server_pools'], self.user)

        pool = self.client.get(
            '/api/v3/pool/%s/' % id,
            HTTP_AUTHORIZATION=self.get_http_authorization('test')) \
            .data['server_pools'][0]

        self.assertEqual(3, len(pool['server_pool_members']),
                         'This server pool should have three members.')
        self.assertEqual(True, pool['pool_created'],
                         'After deploy, flag created should be True.')
    def mock_delete_pool(self, id_pool, test_patch):

        pool = self.client.get(
            '/api/v3/pool/%s/' % id_pool,
            HTTP_AUTHORIZATION=self.get_http_authorization('test')).data

        test_patch.return_value = MockPlugin()

        facade_pool_deploy.delete_real_pool(pool['server_pools'], self.user)

        pool = self.client.get(
            '/api/v3/pool/%s/' % id_pool,
            HTTP_AUTHORIZATION=self.get_http_authorization('test')) \
            .data['server_pools'][0]

        self.assertEqual(False, pool['pool_created'],
                         'After undeploy, flag created should be False.')
    def test_update_deployed_pool_removing_half_of_reals(self, test_patch):
        """Tries to remove half of reals in a deployed server pool."""

        id = 40  # Pool with this ID has four members

        pool = self.client.get(
            '/api/v3/pool/%s/' % id,
            HTTP_AUTHORIZATION=self.get_http_authorization('test')).data

        self.assertEqual(4,
                         len(pool['server_pools'][0]['server_pool_members']),
                         'This server pool should have four members.')

        test_patch.return_value = MockPlugin()

        qt_reals = 2

        ipsv4 = [{
            'id': 49,
            'ip_formated': '10.0.0.49'
        }, {
            'id': 50,
            'ip_formated': '10.0.0.50'
        }]

        server_pool_members = [
            self.build_server_pool_member(
                ip__id=ipsv4[i]['id'],
                ip__ip_formated=ipsv4[i]['ip_formated'],
                port_real=8) for i in range(qt_reals)
        ]

        pool['server_pools'][0]['server_pool_members'] = server_pool_members

        facade_pool_deploy.update_real_pool(pool['server_pools'], self.user)

        pool = self.client.get(
            '/api/v3/pool/%s/' % id,
            HTTP_AUTHORIZATION=self.get_http_authorization('test')) \
            .data['server_pools'][0]

        self.assertEqual(2, len(pool['server_pool_members']),
                         'This server pool should have two members.')
        self.assertEqual(True, pool['pool_created'],
                         'After deploy, flag created should be True.')
    def test_update_deployed_pool_without_reals(self, test_patch):
        """Tries to update deployed pool without reals adding two reals to it.
        """

        id = 38

        pool = self.client.get(
            '/api/v3/pool/%s/' % id,
            HTTP_AUTHORIZATION=self.get_http_authorization('test')).data

        test_patch.return_value = MockPlugin()

        qt_reals = 2

        ipsv4 = [{
            'id': 45,
            'ip_formated': '10.0.0.45'
        }, {
            'id': 46,
            'ip_formated': '10.0.0.46'
        }]
        server_pool_members = [
            self.build_server_pool_member(
                ip__id=ipsv4[i]['id'],
                ip__ip_formated=ipsv4[i]['ip_formated'],
                port_real=8) for i in range(qt_reals)
        ]

        pool['server_pools'][0]['server_pool_members'] = server_pool_members

        facade_pool_deploy.update_real_pool(pool['server_pools'], self.user)

        pool = self.client.get(
            '/api/v3/pool/%s/' % id,
            HTTP_AUTHORIZATION=self.get_http_authorization('test'))\
            .data['server_pools'][0]

        self.assertEqual(2, len(pool['server_pool_members']),
                         'This server pool should have two members.')
        self.assertEqual(True, pool['pool_created'],
                         'After deploy, flag created should be True.')
    def test_update_deployed_pool_with_reals_removing_them(self, test_patch):
        """Tries to update pool with reals removing them."""

        id = 39

        pool = self.client.get(
            '/api/v3/pool/%s/' % id,
            HTTP_AUTHORIZATION=self.get_http_authorization('test')).data

        test_patch.return_value = MockPlugin()

        pool['server_pools'][0]['server_pool_members'] = []

        facade_pool_deploy.update_real_pool(pool['server_pools'], self.user)

        pool = self.client.get(
            '/api/v3/pool/%s/' % id,
            HTTP_AUTHORIZATION=self.get_http_authorization('test')) \
            .data['server_pools'][0]

        self.assertEqual(0, len(pool['server_pool_members']),
                         'This server pool should have zero members.')
        self.assertEqual(True, pool['pool_created'],
                         'After deploy, flag created should be True.')