Beispiel #1
0
def redeploy(self, pool_dict, user_id):

    pool_id = pool_dict.get('id')
    msg = {
        'object_type': 'pool',
        'action': 'redeploy',
        'object_id': pool_id
    }
    self.update_state(
        state='PROGRESS',
        meta=msg
    )

    pool_obj = facade.get_pool_by_id(pool_id)
    locks_list = create_lock([pool_id], LOCK_POOL)

    user = Usuario.objects.get(id=user_id)

    try:
        facade_pool_deploy.update_real_pool([pool_dict], user)

    except Exception, exception:
        msg['message'] = 'Pool {} was not redeployed.'.format(pool_obj)
        msg['reason'] = str(exception)

        raise Exception(msg)
Beispiel #2
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_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 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 redeploy(self, pool_dict, user_id):

    pool_id = pool_dict.get('id')
    msg = {'object_type': 'pool', 'action': 'redeploy', 'object_id': pool_id}
    self.update_state(state='PROGRESS', meta=msg)

    pool_obj = facade.get_pool_by_id(pool_id)
    locks_list = create_lock([pool_id], LOCK_POOL)

    user = Usuario.objects.get(id=user_id)

    try:
        facade_pool_deploy.update_real_pool([pool_dict], user)

    except Exception, exception:
        msg['message'] = 'Pool {} was not redeployed.'.format(pool_obj)
        msg['reason'] = str(exception)

        raise Exception(msg)
    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.')
    def put(self, request, *args, **kwargs):
        """
        Updates pools by list in equipments
        """

        server_pools = request.DATA
        json_validate(SPECS.get('pool_put')).validate(server_pools)
        verify_ports(server_pools)
        locks_list = create_lock(server_pools.get('server_pools'), LOCK_POOL)
        try:
            response = facade_pool_deploy.update_real_pool(
                server_pools, request.user)
        except Exception, exception:
            log.error(exception)
            raise rest_exceptions.NetworkAPIException(exception)
Beispiel #10
0
    def put(self, request, *args, **kwargs):
        """
        Updates pools by list in equipments
        """

        server_pools = request.DATA
        json_validate(SPECS.get('pool_put')).validate(server_pools)
        verify_ports(server_pools)
        locks_list = create_lock(server_pools.get('server_pools'), LOCK_POOL)
        try:
            response = facade_pool_deploy.update_real_pool(
                server_pools.get('server_pools'), request.user)
        except Exception, exception:
            log.error(exception)
            raise rest_exceptions.NetworkAPIException(exception)