Exemple #1
0
 def _load_persisted_mappings(self):
     session = self._context.session
     self.db_network_views = dbi.get_network_views(session,
                                                   grid_id=self._grid_id)
     self.db_mapping_conditions = dbi.get_mapping_conditions(
         session, grid_id=self._grid_id)
     self.db_authority_members = dbi.get_mapping_members(
         session, grid_id=self._grid_id)
     self.db_service_members = dbi.get_service_members(
         session, grid_id=self._grid_id)
 def _load_persisted_mappings(self):
     session = self._context.session
     self.db_network_views = dbi.get_network_views(
         session, grid_id=self._grid_id)
     self.db_mapping_conditions = dbi.get_mapping_conditions(
         session, grid_id=self._grid_id)
     self.db_authority_members = dbi.get_mapping_members(
         session, grid_id=self._grid_id)
     self.db_service_members = dbi.get_service_members(
         session, grid_id=self._grid_id)
    def test_network_view_mapping_conditions_with_tenant_id_condition(self):
        user_id = 'test user'
        tenant_id = '80afaaba012acb9c12888128d5123a09'

        # prepare network
        network_name = 'Test Network'
        network = self.plugin_stub.create_network(tenant_id, network_name)

        # prepare subnet with cidr tat is not used in mapping conditions
        subnet_name = 'Test Subnet'
        subnet_cidr = '10.0.0.0/24'
        subnet = self.plugin_stub.create_subnet(tenant_id, subnet_name,
                                                network['id'], subnet_cidr)

        # make sure that no subnet cidr is used in mapping conditions
        db_conditions = dbi.get_mapping_conditions(
            self.ctx.session,
            grid_id=self.grid_id,
            neutron_object_value=subnet_cidr)
        self.assertEqual([], db_conditions)

        # make sure that tenant id is used in mapping condition once
        db_conditions = dbi.get_mapping_conditions(
            self.ctx.session,
            grid_id=self.grid_id,
            neutron_object_value=tenant_id)
        self.assertEqual(1, len(db_conditions))

        # test mapping where tenant id mapping is found
        ib_cxt = ib_context.InfobloxContext(self.ctx, user_id, network, subnet,
                                            self.grid_config, self.plugin)
        ib_cxt.connector = mock.Mock()
        ib_cxt.ibom = mock.Mock()
        ib_cxt.ip_allocator = mock.Mock()

        # validate the mapping network view
        expected_netview_id = db_conditions[0].network_view_id
        db_netviews = dbi.get_network_views(self.ctx.session,
                                            grid_id=self.grid_id)
        netview_row = utils.find_one_in_list('id', expected_netview_id,
                                             db_netviews)
        expected_netview = netview_row.network_view

        db_mapping_members = dbi.get_mapping_members(self.ctx.session,
                                                     expected_netview_id,
                                                     grid_id=self.grid_id)
        expected_member_id = db_mapping_members[0].member_id

        self.assertEqual(expected_netview_id,
                         ib_cxt.mapping.network_view_id)
        self.assertEqual(expected_netview,
                         ib_cxt.mapping.network_view)
        self.assertEqual(expected_member_id,
                         ib_cxt.mapping.authority_member.member_id)
Exemple #4
0
    def test_network_view_mapping_conditions_with_tenant_id_condition(self):
        user_id = 'test user'
        tenant_id = '80afaaba012acb9c12888128d5123a09'

        # prepare network
        network_name = 'Test Network'
        network = self.plugin_stub.create_network(tenant_id, network_name)

        # prepare subnet with cidr tat is not used in mapping conditions
        subnet_name = 'Test Subnet'
        subnet_cidr = '10.0.0.0/24'
        subnet = self.plugin_stub.create_subnet(tenant_id, subnet_name,
                                                network['id'], subnet_cidr)

        # make sure that no subnet cidr is used in mapping conditions
        db_conditions = dbi.get_mapping_conditions(
            self.ctx.session,
            grid_id=self.grid_id,
            neutron_object_value=subnet_cidr)
        self.assertEqual([], db_conditions)

        # make sure that tenant id is used in mapping condition once
        db_conditions = dbi.get_mapping_conditions(
            self.ctx.session,
            grid_id=self.grid_id,
            neutron_object_value=tenant_id)
        self.assertEqual(1, len(db_conditions))

        # test mapping where tenant id mapping is found
        ib_cxt = self._get_ib_context(user_id, network, subnet)
        ib_cxt.connector = mock.Mock()
        ib_cxt.ibom = mock.Mock()
        ib_cxt.ip_allocator = mock.Mock()

        # validate the mapping network view
        expected_netview_id = db_conditions[0].network_view_id
        db_netviews = dbi.get_network_views(self.ctx.session,
                                            grid_id=self.grid_id)
        netview_row = utils.find_one_in_list('id', expected_netview_id,
                                             db_netviews)
        expected_netview = netview_row.network_view

        db_mapping_members = dbi.get_mapping_members(self.ctx.session,
                                                     expected_netview_id,
                                                     grid_id=self.grid_id)
        expected_member_id = db_mapping_members[0].member_id

        self.assertEqual(expected_netview_id,
                         ib_cxt.mapping.network_view_id)
        self.assertEqual(expected_netview,
                         ib_cxt.mapping.network_view)
        self.assertEqual(expected_member_id,
                         ib_cxt.mapping.authority_member.member_id)
Exemple #5
0
 def _register_mapping_member(self):
     session = self.ib_cxt.context.session
     mapping_relation = utils.get_mapping_relation(
         self.ib_cxt.mapping.authority_member.member_type)
     mapping_members = dbi.get_mapping_members(
         session, self.ib_cxt.mapping.network_view_id,
         self.ib_cxt.mapping.authority_member.member_id, self.grid_id,
         mapping_relation)
     if not mapping_members:
         dbi.add_mapping_member(
             session, self.ib_cxt.mapping.network_view_id,
             self.ib_cxt.mapping.authority_member.member_id,
             mapping_relation)
Exemple #6
0
 def _register_mapping_member(self):
     session = self.ib_cxt.context.session
     mapping_relation = utils.get_mapping_relation(
         self.ib_cxt.mapping.authority_member.member_type)
     mapping_members = dbi.get_mapping_members(
         session,
         self.ib_cxt.mapping.network_view_id,
         self.ib_cxt.mapping.authority_member.member_id,
         self.grid_id,
         mapping_relation)
     if not mapping_members:
         dbi.add_mapping_member(
             session,
             self.ib_cxt.mapping.network_view_id,
             self.ib_cxt.mapping.authority_member.member_id,
             mapping_relation)
Exemple #7
0
    def _validate_member_mapping(self, network_view_json, network_json):
        db_members = dbi.get_members(self.ctx.session,
                                     grid_id=self.test_grid_config.grid_id)
        db_network_views = dbi.get_network_views(self.ctx.session)
        db_mapping_members = dbi.get_mapping_members(self.ctx.session)
        db_service_members = dbi.get_service_members(self.ctx.session)

        gm_row = utils.find_one_in_list('member_type',
                                        const.MEMBER_TYPE_GRID_MASTER,
                                        db_members)
        gm_member_id = gm_row.member_id

        dedicated_delegation_members = dict()
        for netview in network_view_json:
            netview_name = netview['name']
            if (netview.get('cloud_info')
                    and netview.get('cloud_info').get('delegated_member')):
                delegated_member = utils.find_one_in_list(
                    'member_name',
                    netview['cloud_info']['delegated_member']['name'],
                    db_members)
                dedicated_delegation_members[netview_name] = (
                    delegated_member.member_id)

        expected_mapping_members = []
        expected_service_members = []

        # get delegated authority members from network views
        for netview in dedicated_delegation_members:
            netview_row = utils.find_one_in_list('network_view', netview,
                                                 db_network_views)
            netview_id = netview_row.id
            authority_member = dedicated_delegation_members[netview]
            mapping_relation = const.MAPPING_RELATION_DELEGATED
            mapping_row_info = (netview_id + DELIMITER + authority_member +
                                DELIMITER + mapping_relation)
            expected_mapping_members.append(mapping_row_info)

        # get authority members from networks
        for network in network_json:
            netview = network['network_view']
            netview_row = utils.find_one_in_list('network_view', netview,
                                                 db_network_views)
            netview_id = netview_row.id

            mapping_relation = const.MAPPING_RELATION_GM_OWNED
            authority_member = gm_member_id
            if netview in dedicated_delegation_members:
                authority_member = dedicated_delegation_members[netview]
                mapping_relation = const.MAPPING_RELATION_DELEGATED
            elif (network.get('cloud_info')
                  and network['cloud_info'].get('delegated_member')):
                delegated_member = utils.find_one_in_list(
                    'member_name',
                    network['cloud_info']['delegated_member']['name'],
                    db_members)
                authority_member = delegated_member.member_id
                mapping_relation = const.MAPPING_RELATION_DELEGATED

            mapping_row_info = (netview_id + DELIMITER + authority_member +
                                DELIMITER + mapping_relation)
            if mapping_row_info not in expected_mapping_members:
                expected_mapping_members.append(mapping_row_info)

            if network.get('members'):
                for m in network['members']:
                    if m['_struct'] == 'dhcpmember':
                        dhcp_member = utils.find_one_in_list(
                            'member_name', m['name'], db_members)
                        mapping_row_info = (netview_id + DELIMITER +
                                            dhcp_member.member_id + DELIMITER +
                                            const.SERVICE_TYPE_DHCP)
                        if mapping_row_info not in expected_service_members:
                            expected_service_members.append(mapping_row_info)

            if network.get('options'):
                dns_membe_ips = []
                for option in network['options']:
                    if option.get('name') == 'domain-name-servers':
                        option_values = option.get('value')
                        if option_values:
                            dns_membe_ips = option_values.split(',')
                            break
                for membe_ip in dns_membe_ips:
                    dns_member = utils.find_one_in_list(
                        'member_ip', membe_ip, db_members)
                    mapping_row_info = (netview_id + DELIMITER +
                                        dns_member.member_id + DELIMITER +
                                        const.SERVICE_TYPE_DNS)
                    if mapping_row_info not in expected_service_members:
                        expected_service_members.append(mapping_row_info)

        actual_mapping_members = utils.get_composite_values_from_records(
            ['network_view_id', 'member_id', 'mapping_relation'],
            db_mapping_members)
        self.assertEqual(set(expected_mapping_members),
                         set(actual_mapping_members))

        actual_service_members = utils.get_composite_values_from_records(
            ['network_view_id', 'member_id', 'service'], db_service_members)
        self.assertEqual(set(expected_service_members),
                         set(actual_service_members))
    def test_mapping_management_mapping_members(self):
        # prepare grid
        self._create_default_grid()

        # prepare grid members
        self._create_simple_members()
        db_members = infoblox_db.get_members(self.ctx.session)
        gm_member = utils.find_one_in_list('member_type', 'GM', db_members)

        # prepare network views
        netview_dict = {'default': gm_member.member_id}
        self._create_network_views(netview_dict)

        # get network view id
        db_network_views = infoblox_db.get_network_views(self.ctx.session)
        netview_default_row = utils.find_one_in_list('network_view',
                                                     'default',
                                                     db_network_views)
        netview_id = netview_default_row.id

        # should be no mapping members
        db_mapping_members = infoblox_db.get_mapping_members(self.ctx.session)
        self.assertEqual(0, len(db_mapping_members))

        # test mapping member additions
        expected_rows = []
        member_id = db_members[0]['member_id']
        relation = const.MAPPING_RELATION_DELEGATED
        infoblox_db.add_mapping_member(self.ctx.session, netview_id, member_id,
                                       relation)
        expected_rows.append(netview_id + ':' + member_id + ':' + relation)

        member_id = db_members[1]['member_id']
        relation = const.MAPPING_RELATION_DELEGATED
        infoblox_db.add_mapping_member(self.ctx.session, netview_id, member_id,
                                       relation)
        expected_rows.append(netview_id + ':' + member_id + ':' + relation)

        db_mapping_members = infoblox_db.get_mapping_members(self.ctx.session)
        actual_rows = utils.get_composite_values_from_records(
            ['network_view_id', 'member_id', 'mapping_relation'],
            db_mapping_members, ':')
        self.assertEqual(expected_rows, actual_rows)

        # test mapping member update
        member_id = db_members[0]['member_id']
        relation = const.MAPPING_RELATION_GM_OWNED
        infoblox_db.update_mapping_member(self.ctx.session, netview_id,
                                          member_id, relation)
        expected_rows[0] = netview_id + ':' + member_id + ':' + relation

        db_mapping_members = infoblox_db.get_mapping_members(self.ctx.session)
        actual_rows = utils.get_composite_values_from_records(
            ['network_view_id', 'member_id', 'mapping_relation'],
            db_mapping_members, ':')
        self.assertEqual(expected_rows, actual_rows)

        # test mapping member removals
        member_id = db_members[0]['member_id']
        infoblox_db.remove_mapping_member(self.ctx.session, netview_id,
                                          member_id)
        db_mapping_members = infoblox_db.get_mapping_members(
            self.ctx.session, member_id=member_id)
        self.assertEqual([], db_mapping_members)
Exemple #9
0
    def test_mapping_management_mapping_members(self):
        # prepare grid
        self._create_default_grid()

        # prepare grid members
        self._create_simple_members()
        db_members = infoblox_db.get_members(self.ctx.session)
        gm_member = utils.find_one_in_list('member_type', 'GM', db_members)

        # prepare network views
        netview_dict = {'default': gm_member.member_id}
        self._create_network_views(netview_dict)

        # get network view id
        db_network_views = infoblox_db.get_network_views(self.ctx.session)
        netview_default_row = utils.find_one_in_list('network_view', 'default',
                                                     db_network_views)
        netview_id = netview_default_row.id

        # should be no mapping members
        db_mapping_members = infoblox_db.get_mapping_members(self.ctx.session)
        self.assertEqual(0, len(db_mapping_members))

        # test mapping member additions
        expected_rows = []
        member_id = db_members[0]['member_id']
        relation = const.MAPPING_RELATION_DELEGATED
        infoblox_db.add_mapping_member(self.ctx.session, netview_id, member_id,
                                       relation)
        expected_rows.append(netview_id + ':' + member_id + ':' + relation)

        member_id = db_members[1]['member_id']
        relation = const.MAPPING_RELATION_DELEGATED
        infoblox_db.add_mapping_member(self.ctx.session, netview_id, member_id,
                                       relation)
        expected_rows.append(netview_id + ':' + member_id + ':' + relation)

        db_mapping_members = infoblox_db.get_mapping_members(self.ctx.session)
        actual_rows = utils.get_composite_values_from_records(
            ['network_view_id', 'member_id', 'mapping_relation'],
            db_mapping_members, ':')
        self.assertEqual(expected_rows, actual_rows)

        # test mapping member update
        member_id = db_members[0]['member_id']
        relation = const.MAPPING_RELATION_GM_OWNED
        infoblox_db.update_mapping_member(self.ctx.session, netview_id,
                                          member_id, relation)
        expected_rows[0] = netview_id + ':' + member_id + ':' + relation

        db_mapping_members = infoblox_db.get_mapping_members(self.ctx.session)
        actual_rows = utils.get_composite_values_from_records(
            ['network_view_id', 'member_id', 'mapping_relation'],
            db_mapping_members, ':')
        self.assertEqual(expected_rows, actual_rows)

        # test mapping member removals
        member_id = db_members[0]['member_id']
        infoblox_db.remove_mapping_member(self.ctx.session, netview_id,
                                          member_id)
        db_mapping_members = infoblox_db.get_mapping_members(
            self.ctx.session, member_id=member_id)
        self.assertEqual([], db_mapping_members)
    def _validate_member_mapping(self, network_view_json, network_json):
        db_members = dbi.get_members(self.ctx.session,
                                     grid_id=self.test_grid_config.grid_id)
        db_network_views = dbi.get_network_views(self.ctx.session)
        db_mapping_members = dbi.get_mapping_members(self.ctx.session)
        db_service_members = dbi.get_service_members(self.ctx.session)

        gm_row = utils.find_one_in_list('member_type',
                                        const.MEMBER_TYPE_GRID_MASTER,
                                        db_members)
        gm_member_id = gm_row.member_id

        dedicated_delegation_members = dict()
        for netview in network_view_json:
            netview_name = netview['name']
            if (netview.get('cloud_info') and
                    netview.get('cloud_info').get('delegated_member')):
                delegated_member = utils.find_one_in_list(
                    'member_name',
                    netview['cloud_info']['delegated_member']['name'],
                    db_members)
                dedicated_delegation_members[netview_name] = (
                    delegated_member.member_id)

        expected_mapping_members = []
        expected_service_members = []

        # get delegated authority members from network views
        for netview in dedicated_delegation_members:
            netview_row = utils.find_one_in_list('network_view', netview,
                                                 db_network_views)
            netview_id = netview_row.id
            authority_member = dedicated_delegation_members[netview]
            mapping_relation = const.MAPPING_RELATION_DELEGATED
            mapping_row_info = (netview_id + DELIMITER + authority_member +
                                DELIMITER + mapping_relation)
            expected_mapping_members.append(mapping_row_info)

        # get authority members from networks
        for network in network_json:
            netview = network['network_view']
            netview_row = utils.find_one_in_list('network_view', netview,
                                                 db_network_views)
            netview_id = netview_row.id

            mapping_relation = const.MAPPING_RELATION_GM_OWNED
            authority_member = gm_member_id
            if netview in dedicated_delegation_members:
                authority_member = dedicated_delegation_members[netview]
                mapping_relation = const.MAPPING_RELATION_DELEGATED
            elif (network.get('cloud_info') and
                    network['cloud_info'].get('delegated_member')):
                delegated_member = utils.find_one_in_list(
                    'member_name',
                    network['cloud_info']['delegated_member']['name'],
                    db_members)
                authority_member = delegated_member.member_id
                mapping_relation = const.MAPPING_RELATION_DELEGATED

            mapping_row_info = (netview_id + DELIMITER + authority_member +
                                DELIMITER + mapping_relation)
            if mapping_row_info not in expected_mapping_members:
                expected_mapping_members.append(mapping_row_info)

            if network.get('members'):
                for m in network['members']:
                    if m['_struct'] == 'dhcpmember':
                        dhcp_member = utils.find_one_in_list(
                            'member_name', m['name'], db_members)
                        mapping_row_info = (netview_id + DELIMITER +
                                            dhcp_member.member_id + DELIMITER +
                                            const.SERVICE_TYPE_DHCP)
                        if mapping_row_info not in expected_service_members:
                            expected_service_members.append(mapping_row_info)

            if network.get('options'):
                dns_membe_ips = []
                for option in network['options']:
                    if option.get('name') == 'domain-name-servers':
                        option_values = option.get('value')
                        if option_values:
                            dns_membe_ips = option_values.split(',')
                            break
                for membe_ip in dns_membe_ips:
                    dns_member = utils.find_one_in_list(
                        'member_ip', membe_ip, db_members)
                    mapping_row_info = (netview_id + DELIMITER +
                                        dns_member.member_id + DELIMITER +
                                        const.SERVICE_TYPE_DNS)
                    if mapping_row_info not in expected_service_members:
                        expected_service_members.append(mapping_row_info)

        actual_mapping_members = utils.get_composite_values_from_records(
            ['network_view_id', 'member_id', 'mapping_relation'],
            db_mapping_members)
        self.assertEqual(set(expected_mapping_members),
                         set(actual_mapping_members))

        actual_service_members = utils.get_composite_values_from_records(
            ['network_view_id', 'member_id', 'service'],
            db_service_members)
        self.assertEqual(set(expected_service_members),
                         set(actual_service_members))