Exemplo n.º 1
0
    def sync_grid(self):
        """Synchronize an active grid.

        Only one active grid should be kept where grid_status is set to 'ON'.
        """
        session = self._context.session
        grid_connection = self._grid_config.get_grid_connection()
        grid_connection_json = jsonutils.dumps(grid_connection)

        db_grids = dbi.get_grids(session)
        db_grid_ids = utils.get_values_from_records('grid_id', db_grids)

        # update the existing grid or add new grid
        if self._grid_config.grid_id in db_grid_ids:
            dbi.update_grid(session, self._grid_config.grid_id,
                            self._grid_config.grid_name, grid_connection_json,
                            const.GRID_STATUS_ON)
        else:
            dbi.add_grid(session, self._grid_config.grid_id,
                         self._grid_config.grid_name, grid_connection_json,
                         const.GRID_STATUS_ON, utils.get_hash())

        # deleting grids are delicate operation so we won't allow it
        # but we will set grid status to OFF to unused grids.
        persisted_set = set(db_grid_ids)
        disable_set = persisted_set.difference([self._grid_config.grid_id])
        disabling_grid_ids = list(disable_set)
        for grid_id in disabling_grid_ids:
            dbi.update_grid(session,
                            grid_id,
                            grid_status=const.GRID_STATUS_OFF)
        session.flush()
Exemplo n.º 2
0
    def sync_grid(self):
        """Synchronize an active grid.

        Only one active grid should be kept where grid_status is set to 'ON'.
        """
        session = self._context.session
        grid_connection = self._grid_config.get_grid_connection()
        grid_connection_json = jsonutils.dumps(grid_connection)

        db_grids = dbi.get_grids(session)
        db_grid_ids = utils.get_values_from_records('grid_id', db_grids)

        # update the existing grid or add new grid
        if self._grid_config.grid_id in db_grid_ids:
            dbi.update_grid(session,
                            self._grid_config.grid_id,
                            self._grid_config.grid_name,
                            grid_connection_json,
                            const.GRID_STATUS_ON)
        else:
            dbi.add_grid(session,
                         self._grid_config.grid_id,
                         self._grid_config.grid_name,
                         grid_connection_json,
                         const.GRID_STATUS_ON,
                         utils.get_hash())

        # deleting grids are delicate operation so we won't allow it
        # but we will set grid status to OFF to unused grids.
        persisted_set = set(db_grid_ids)
        disable_set = persisted_set.difference([self._grid_config.grid_id])
        disabling_grid_ids = list(disable_set)
        for grid_id in disabling_grid_ids:
            dbi.update_grid(session,
                            grid_id,
                            grid_status=const.GRID_STATUS_OFF)
        session.flush()
    def test_grid_management(self):
        grid_list = [{'grid_id': 100,
                      'grid_name': 'Test Grid 1000',
                      'grid_connection': '{}',
                      'grid_status': 'ON'},
                     {'grid_id': 200,
                      'grid_name': 'Test Grid 2000',
                      'grid_connection': '{}',
                      'grid_status': 'OFF'}]

        # expects no grid
        db_grids = infoblox_db.get_grids(self.ctx.session)
        self.assertEqual(0, len(db_grids))

        # test grid additions
        self._create_grids(grid_list)

        db_grids = infoblox_db.get_grids(self.ctx.session)
        actual_grid_rows = utils.get_composite_values_from_records(
            ['grid_id', 'grid_name', 'grid_connection', 'grid_status'],
            db_grids)
        expected_grid_rows = utils.get_composite_values_from_records(
            ['grid_id', 'grid_name', 'grid_connection', 'grid_status'],
            grid_list)
        self.assertEqual(expected_grid_rows, actual_grid_rows)

        # test grid retrieval by grid_id filter
        db_grids = infoblox_db.get_grids(self.ctx.session,
                                         grid_id=grid_list[0]['grid_id'])
        self.assertEqual(grid_list[0]['grid_id'], db_grids[0]['grid_id'])
        self.assertEqual(grid_list[0]['grid_name'], db_grids[0]['grid_name'])
        self.assertEqual(grid_list[0]['grid_connection'],
                         db_grids[0]['grid_connection'])
        self.assertEqual(grid_list[0]['grid_connection'],
                         db_grids[0]['grid_connection'])
        self.assertEqual(grid_list[0]['grid_status'],
                         db_grids[0]['grid_status'])

        db_grids = infoblox_db.get_grids(self.ctx.session,
                                         grid_id=grid_list[1]['grid_id'],
                                         grid_name=grid_list[0]['grid_name'])
        self.assertEqual([], db_grids)

        # test grid retrieval by grid_id and grid_name filters
        db_grids = infoblox_db.get_grids(self.ctx.session,
                                         grid_id=grid_list[1]['grid_id'],
                                         grid_name=grid_list[1]['grid_name'])
        self.assertEqual(grid_list[1]['grid_id'], db_grids[0]['grid_id'])
        self.assertEqual(grid_list[1]['grid_name'], db_grids[0]['grid_name'])
        self.assertEqual(grid_list[1]['grid_connection'],
                         db_grids[0]['grid_connection'])
        self.assertEqual(grid_list[1]['grid_connection'],
                         db_grids[0]['grid_connection'])
        self.assertEqual(grid_list[1]['grid_status'],
                         db_grids[0]['grid_status'])

        # test grid update
        grid_name_update = "Test Grid 1000 Enhanced"
        grid_connection_json = {
            "wapi_version": "2.0",
            "ssl_verify": False,
            "http_pool_connections": 100,
            "http_pool_maxsize": 100,
            "http_request_timeout": 120,
            "admin_user": {"name": "admin", "password": "******"}
        }
        grid_connection_json_string = jsonutils.dumps(grid_connection_json)

        infoblox_db.update_grid(self.ctx.session,
                                grid_list[0]['grid_id'],
                                grid_name_update,
                                grid_connection_json_string)
        db_grids = infoblox_db.get_grids(self.ctx.session,
                                         grid_list[0]['grid_id'])
        self.assertEqual(grid_name_update, db_grids[0]['grid_name'])
        self.assertEqual(grid_connection_json_string,
                         db_grids[0]['grid_connection'])

        # test grid removal
        infoblox_db.remove_grids(self.ctx.session, [grid_list[0]['grid_id']])

        db_grids = infoblox_db.get_grids(self.ctx.session,
                                         grid_list[0]['grid_id'])
        self.assertEqual(0, len(db_grids))

        # remove two grids
        self._create_grids([grid_list[0]])
        infoblox_db.remove_grids(self.ctx.session,
                                 [grid_list[0]['grid_id'],
                                  grid_list[1]['grid_id']])

        db_grids = infoblox_db.get_grids(self.ctx.session)
        self.assertEqual(0, len(db_grids))
Exemplo n.º 4
0
    def test_grid_management(self):
        grid_list = [{
            'grid_id': 100,
            'grid_name': 'Test Grid 1000',
            'grid_connection': '{}',
            'grid_status': 'ON'
        }, {
            'grid_id': 200,
            'grid_name': 'Test Grid 2000',
            'grid_connection': '{}',
            'grid_status': 'OFF'
        }]

        # expects no grid
        db_grids = infoblox_db.get_grids(self.ctx.session)
        self.assertEqual(0, len(db_grids))

        # test grid additions
        self._create_grids(grid_list)

        db_grids = infoblox_db.get_grids(self.ctx.session)
        actual_grid_rows = utils.get_composite_values_from_records(
            ['grid_id', 'grid_name', 'grid_connection', 'grid_status'],
            db_grids)
        expected_grid_rows = utils.get_composite_values_from_records(
            ['grid_id', 'grid_name', 'grid_connection', 'grid_status'],
            grid_list)
        self.assertEqual(expected_grid_rows, actual_grid_rows)

        # test grid retrieval by grid_id filter
        db_grids = infoblox_db.get_grids(self.ctx.session,
                                         grid_id=grid_list[0]['grid_id'])
        self.assertEqual(grid_list[0]['grid_id'], db_grids[0]['grid_id'])
        self.assertEqual(grid_list[0]['grid_name'], db_grids[0]['grid_name'])
        self.assertEqual(grid_list[0]['grid_connection'],
                         db_grids[0]['grid_connection'])
        self.assertEqual(grid_list[0]['grid_connection'],
                         db_grids[0]['grid_connection'])
        self.assertEqual(grid_list[0]['grid_status'],
                         db_grids[0]['grid_status'])

        db_grids = infoblox_db.get_grids(self.ctx.session,
                                         grid_id=grid_list[1]['grid_id'],
                                         grid_name=grid_list[0]['grid_name'])
        self.assertEqual([], db_grids)

        # test grid retrieval by grid_id and grid_name filters
        db_grids = infoblox_db.get_grids(self.ctx.session,
                                         grid_id=grid_list[1]['grid_id'],
                                         grid_name=grid_list[1]['grid_name'])
        self.assertEqual(grid_list[1]['grid_id'], db_grids[0]['grid_id'])
        self.assertEqual(grid_list[1]['grid_name'], db_grids[0]['grid_name'])
        self.assertEqual(grid_list[1]['grid_connection'],
                         db_grids[0]['grid_connection'])
        self.assertEqual(grid_list[1]['grid_connection'],
                         db_grids[0]['grid_connection'])
        self.assertEqual(grid_list[1]['grid_status'],
                         db_grids[0]['grid_status'])

        # test grid update
        grid_name_update = "Test Grid 1000 Enhanced"
        grid_connection_json = {
            "wapi_version": "2.0",
            "ssl_verify": False,
            "http_pool_connections": 100,
            "http_pool_maxsize": 100,
            "http_request_timeout": 120,
            "admin_user": {
                "name": "admin",
                "password": "******"
            }
        }
        grid_connection_json_string = jsonutils.dumps(grid_connection_json)

        infoblox_db.update_grid(self.ctx.session, grid_list[0]['grid_id'],
                                grid_name_update, grid_connection_json_string)
        db_grids = infoblox_db.get_grids(self.ctx.session,
                                         grid_list[0]['grid_id'])
        self.assertEqual(grid_name_update, db_grids[0]['grid_name'])
        self.assertEqual(grid_connection_json_string,
                         db_grids[0]['grid_connection'])

        # test grid removal
        infoblox_db.remove_grids(self.ctx.session, [grid_list[0]['grid_id']])

        db_grids = infoblox_db.get_grids(self.ctx.session,
                                         grid_list[0]['grid_id'])
        self.assertEqual(0, len(db_grids))

        # remove two grids
        self._create_grids([grid_list[0]])
        infoblox_db.remove_grids(
            self.ctx.session,
            [grid_list[0]['grid_id'], grid_list[1]['grid_id']])

        db_grids = infoblox_db.get_grids(self.ctx.session)
        self.assertEqual(0, len(db_grids))