Example #1
0
    def _update_mapping_conditions(self, discovered_netview, netview_id,
                                   participated):
        session = self._context.session
        mapping_conditions = dict()
        if participated:
            mapping_conditions = self._get_mapping_conditions(
                discovered_netview)
        discovered_condition_rows = []
        for condition_name in mapping_conditions:
            conditions = [netview_id + DELIMITER + condition_name + DELIMITER +
                          value for value in
                          mapping_conditions[condition_name]]
            discovered_condition_rows += conditions

        mapping_condition_rows = utils.find_in_list(
            'network_view_id', [netview_id], self.db_mapping_conditions)
        condition_rows = utils.get_composite_values_from_records(
            ['network_view_id', 'neutron_object_name', 'neutron_object_value'],
            mapping_condition_rows,
            DELIMITER)
        persisted_set = set(condition_rows)
        discovered_set = set(discovered_condition_rows)
        addable_set = discovered_set.difference(persisted_set)
        removable_set = persisted_set.difference(discovered_set)

        for condition_attr in addable_set:
            condition = condition_attr.split(DELIMITER)
            network_view_id = condition[0]
            neutron_object_name = condition[1]
            neutron_object_value = condition[2]
            dbi.add_mapping_condition(session,
                                      network_view_id,
                                      neutron_object_name,
                                      neutron_object_value)

        for condition_attr in removable_set:
            condition = condition_attr.split(DELIMITER)
            network_view_id = condition[0]
            neutron_object_name = condition[1]
            neutron_object_value = condition[2]
            dbi.remove_mapping_condition(session,
                                         network_view_id,
                                         neutron_object_name,
                                         neutron_object_value)
Example #2
0
    def _update_mapping_conditions(self, discovered_netview, netview_id,
                                   participated):
        session = self._context.session
        mapping_conditions = dict()
        if participated:
            mapping_conditions = self._get_mapping_conditions(
                discovered_netview)
        discovered_condition_rows = []
        for condition_name in mapping_conditions:
            conditions = [
                netview_id + DELIMITER + condition_name + DELIMITER + value
                for value in mapping_conditions[condition_name]
            ]
            discovered_condition_rows += conditions

        mapping_condition_rows = utils.find_in_list('network_view_id',
                                                    [netview_id],
                                                    self.db_mapping_conditions)
        condition_rows = utils.get_composite_values_from_records(
            ['network_view_id', 'neutron_object_name', 'neutron_object_value'],
            mapping_condition_rows, DELIMITER)
        persisted_set = set(condition_rows)
        discovered_set = set(discovered_condition_rows)
        addable_set = discovered_set.difference(persisted_set)
        removable_set = persisted_set.difference(discovered_set)

        for condition_attr in addable_set:
            condition = condition_attr.split(DELIMITER)
            network_view_id = condition[0]
            neutron_object_name = condition[1]
            neutron_object_value = condition[2]
            dbi.add_mapping_condition(session, network_view_id,
                                      neutron_object_name,
                                      neutron_object_value)

        for condition_attr in removable_set:
            condition = condition_attr.split(DELIMITER)
            network_view_id = condition[0]
            neutron_object_name = condition[1]
            neutron_object_value = condition[2]
            dbi.remove_mapping_condition(session, network_view_id,
                                         neutron_object_name,
                                         neutron_object_value)
    def test_mapping_management_mapping_conditions(self):
        # prepare grid
        self._create_default_grid()

        # prepare 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)

        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 conditions
        db_conditions = infoblox_db.get_mapping_conditions(self.ctx.session)
        self.assertEqual(0, len(db_conditions))

        expected_rows = []

        # test mapping condition additions
        neutron_object_name = const.EA_MAPPING_TENANT_ID
        neutron_object_value = '90fbad5a098a4b7cb98826128d5b40b3'
        expected_rows.append(netview_id + ':' + neutron_object_name +
                             ':' + neutron_object_value)
        infoblox_db.add_mapping_condition(self.ctx.session,
                                          netview_id,
                                          neutron_object_name,
                                          neutron_object_value)

        neutron_object_name = const.EA_MAPPING_SUBNET_CIDR
        neutron_object_values = ["12.12.1.0/24", "13.13.1.0/24"]
        for value in neutron_object_values:
            expected_rows.append(netview_id + ':' + neutron_object_name +
                                 ':' + value)
        infoblox_db.add_mapping_conditions(self.ctx.session,
                                           netview_id,
                                           neutron_object_name,
                                           neutron_object_values)

        db_conditions = infoblox_db.get_mapping_conditions(self.ctx.session)
        actual_rows = utils.get_composite_values_from_records(
            ['network_view_id', 'neutron_object_name', 'neutron_object_value'],
            db_conditions, ':')
        self.assertEqual(expected_rows, actual_rows)

        # test mapping condition removals
        # - remove Tenant ID Mapping condition
        condition_1 = expected_rows[0].split(':')
        condition_neutron_object_name = condition_1[1]
        condition_neutron_object_value = condition_1[2]
        infoblox_db.remove_mapping_condition(self.ctx.session,
                                             netview_id,
                                             condition_neutron_object_name,
                                             condition_neutron_object_value)

        db_conditions = infoblox_db.get_mapping_conditions(
            self.ctx.session,
            network_view_id=netview_id,
            grid_id=self.grid_id,
            neutron_object_name=condition_neutron_object_name)
        self.assertEqual([], db_conditions)

        # - remove two Tenant CIDR Mapping conditions
        condition_2 = expected_rows[1].split(':')
        condition_3 = expected_rows[2].split(':')
        condition_neutron_object_name = condition_2[1]
        condition_neutron_object_values = [condition_2[2], condition_3[2]]
        infoblox_db.remove_mapping_conditions(self.ctx.session,
                                              netview_id,
                                              condition_neutron_object_name,
                                              condition_neutron_object_values)

        db_conditions = infoblox_db.get_mapping_conditions(
            self.ctx.session,
            network_view_id=netview_id,
            grid_id=self.grid_id,
            neutron_object_name=condition_neutron_object_name)
        self.assertEqual([], db_conditions)

        db_conditions = infoblox_db.get_mapping_conditions(self.ctx.session)
        self.assertEqual([], db_conditions)
Example #4
0
    def test_mapping_management_mapping_conditions(self):
        # prepare grid
        self._create_default_grid()

        # prepare 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)

        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 conditions
        db_conditions = infoblox_db.get_mapping_conditions(self.ctx.session)
        self.assertEqual(0, len(db_conditions))

        expected_rows = []

        # test mapping condition additions
        neutron_object_name = const.EA_MAPPING_TENANT_ID
        neutron_object_value = '90fbad5a098a4b7cb98826128d5b40b3'
        expected_rows.append(netview_id + ':' + neutron_object_name + ':' +
                             neutron_object_value)
        infoblox_db.add_mapping_condition(self.ctx.session, netview_id,
                                          neutron_object_name,
                                          neutron_object_value)

        neutron_object_name = const.EA_MAPPING_SUBNET_CIDR
        neutron_object_values = ["12.12.1.0/24", "13.13.1.0/24"]
        for value in neutron_object_values:
            expected_rows.append(netview_id + ':' + neutron_object_name + ':' +
                                 value)
        infoblox_db.add_mapping_conditions(self.ctx.session, netview_id,
                                           neutron_object_name,
                                           neutron_object_values)

        db_conditions = infoblox_db.get_mapping_conditions(self.ctx.session)
        actual_rows = utils.get_composite_values_from_records(
            ['network_view_id', 'neutron_object_name', 'neutron_object_value'],
            db_conditions, ':')
        self.assertEqual(expected_rows, actual_rows)

        # test mapping condition removals
        # - remove Tenant ID Mapping condition
        condition_1 = expected_rows[0].split(':')
        condition_neutron_object_name = condition_1[1]
        condition_neutron_object_value = condition_1[2]
        infoblox_db.remove_mapping_condition(self.ctx.session, netview_id,
                                             condition_neutron_object_name,
                                             condition_neutron_object_value)

        db_conditions = infoblox_db.get_mapping_conditions(
            self.ctx.session,
            network_view_id=netview_id,
            grid_id=self.grid_id,
            neutron_object_name=condition_neutron_object_name)
        self.assertEqual([], db_conditions)

        # - remove two Tenant CIDR Mapping conditions
        condition_2 = expected_rows[1].split(':')
        condition_3 = expected_rows[2].split(':')
        condition_neutron_object_name = condition_2[1]
        condition_neutron_object_values = [condition_2[2], condition_3[2]]
        infoblox_db.remove_mapping_conditions(self.ctx.session, netview_id,
                                              condition_neutron_object_name,
                                              condition_neutron_object_values)

        db_conditions = infoblox_db.get_mapping_conditions(
            self.ctx.session,
            network_view_id=netview_id,
            grid_id=self.grid_id,
            neutron_object_name=condition_neutron_object_name)
        self.assertEqual([], db_conditions)

        db_conditions = infoblox_db.get_mapping_conditions(self.ctx.session)
        self.assertEqual([], db_conditions)