示例#1
0
    def sync(self):
        """Discovers and syncs networks between Neutron and Infoblox backend.

        The following information is discovered and synchronized.
        1. network views
        2. neutron network mapping conditions to NIOS network
        3. authority members that owns network views by either GM ownership or
           delegation to Cloud Platform Members (CPM).

        :return: None
        """
        session = self._context.session
        self.db_members = dbi.get_members(session, grid_id=self._grid_id)

        discovered_network_views = self._discover_network_views()
        if not discovered_network_views:
            return

        discovered_dns_views = self._discover_dns_views()
        dns_views = self.get_dns_views(discovered_dns_views)

        discovered_delegations = self._sync_network_views(
            discovered_network_views, dns_views)

        discovered_networks = self._discover_networks()
        self._sync_network_mapping(discovered_networks, discovered_delegations)
示例#2
0
 def discovered_grid_members(self):
     if self._discovered_grid_members is None:
         self._discovered_grid_members = dbi.get_members(
             self.context.session,
             grid_id=self.grid_id,
             member_status=const.MEMBER_STATUS_ON)
     return self._discovered_grid_members
示例#3
0
    def sync(self):
        """Discovers and syncs networks between Neutron and Infoblox backend.

        The following information is discovered and synchronized.
        1. network views
        2. neutron network mapping conditions to NIOS network
        3. authority members that owns network views by either GM ownership or
           delegation to Cloud Platform Members (CPM).

        :return: None
        """
        session = self._context.session
        self.db_members = dbi.get_members(session, grid_id=self._grid_id)

        discovered_network_views = self._discover_network_views()
        if not discovered_network_views:
            return

        discovered_dns_views = self._discover_dns_views()
        dns_views = self.get_dns_views(discovered_dns_views)

        discovered_delegations = self._sync_network_views(
            discovered_network_views, dns_views)

        discovered_networks = self._discover_networks()
        self._sync_network_mapping(discovered_networks, discovered_delegations)
示例#4
0
 def get_gm_member(self):
     session = self.context.session
     members = dbi.get_members(session,
                               grid_id=self.grid_id,
                               member_type=const.MEMBER_TYPE_GRID_MASTER,
                               member_status=const.MEMBER_STATUS_ON)
     if not members or len(members) != 1:
         raise exc.InfobloxCannotFindMember(member="GM")
     return members[0]
示例#5
0
 def get_gm_member(self):
     session = self.context.session
     members = dbi.get_members(session,
                               grid_id=self.grid_id,
                               member_type=const.MEMBER_TYPE_GRID_MASTER,
                               member_status=const.MEMBER_STATUS_ON)
     if not members or len(members) != 1:
         raise exc.InfobloxCannotFindMember(member="GM")
     return members[0]
示例#6
0
    def _resync(self, force_sync=False):
        self.grid_mgr.sync(force_sync)

        self._cached_grid_members = dbi.get_members(
            self.context.session, grid_id=self.grid_id,
            member_status=const.MEMBER_STATUS_ON)
        self._cached_network_views = dbi.get_network_views(
            self.context.session, grid_id=self.grid_id)
        self._cached_mapping_conditions = dbi.get_mapping_conditions(
            self.context.session, grid_id=self.grid_id)
示例#7
0
    def test_network_view_management(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)

        # should be no network views
        db_network_views = infoblox_db.get_network_views(self.ctx.session)
        self.assertEqual(0, len(db_network_views))

        # test network view additions
        netview_dict = {
            'default': gm_member.member_id,
            'hs-view-1': gm_member.member_id,
            'hs-view-2': gm_member.member_id,
            'hs-view-3': gm_member.member_id
        }
        self._create_network_views(netview_dict)

        db_network_views = infoblox_db.get_network_views(self.ctx.session)
        actual_rows = utils.get_values_from_records('network_view',
                                                    db_network_views)
        self.assertEqual(netview_dict.keys(), actual_rows)

        # test network view removals
        # - remove 'hs-view-1', 'hs-view-2'
        removing_list = [netview_dict['hs-view-1'], netview_dict['hs-view-2']]
        infoblox_db.remove_network_views_by_names(self.ctx.session,
                                                  removing_list, self.grid_id)

        db_network_views = infoblox_db.get_network_views(self.ctx.session)
        actual_rows = utils.get_values_from_records('network_view',
                                                    db_network_views)
        actual_set = set(actual_rows)
        expected_set = set(netview_dict.keys()).difference(removing_list)
        self.assertEqual(expected_set, actual_set)

        # - remove 'hs-view-3'
        removing_netview_name = 'hs-view-3'
        removing_netview = utils.find_one_in_list('network_view',
                                                  removing_netview_name,
                                                  db_network_views)
        removing_netview_id = removing_netview.id
        infoblox_db.remove_network_views(self.ctx.session,
                                         [removing_netview_id])

        actual_network_views = infoblox_db.get_network_views(
            self.ctx.session, network_view=removing_netview_name)
        self.assertEqual([], actual_network_views)
    def test_network_view_mapping_conditions_with_single_scope(self):
        user_id = 'test user'
        tenant_id = 'test-tenant'

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

        # check default network view when no mapping condition matches
        self.assertEqual('Single',
                         self.grid_config.default_network_view_scope)
        self.assertEqual('default', self.grid_config.default_network_view)

        # test default mapping as 'Single'
        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()

        # verify that 'default' view is used
        db_netviews = dbi.get_network_views(self.ctx.session,
                                            grid_id=self.grid_id)
        netview_row = utils.find_one_in_list('network_view', 'default',
                                             db_netviews)
        expected_netview_id = netview_row.id

        db_grid_members = dbi.get_members(self.ctx.session,
                                          grid_id=self.grid_id)
        member_row = utils.find_one_in_list('member_type', 'GM',
                                            db_grid_members)
        expected_member_name = member_row.member_name

        self.assertEqual(expected_netview_id,
                         ib_cxt.mapping.network_view_id)
        self.assertEqual('default',
                         ib_cxt.mapping.network_view)
        self.assertEqual(expected_member_name,
                         ib_cxt.mapping.authority_member.member_name)
    def test_network_view_management(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)

        # should be no network views
        db_network_views = infoblox_db.get_network_views(self.ctx.session)
        self.assertEqual(0, len(db_network_views))

        # test network view additions
        netview_dict = {'default': gm_member.member_id,
                        'hs-view-1': gm_member.member_id,
                        'hs-view-2': gm_member.member_id,
                        'hs-view-3': gm_member.member_id}
        self._create_network_views(netview_dict)

        db_network_views = infoblox_db.get_network_views(self.ctx.session)
        actual_rows = utils.get_values_from_records('network_view',
                                                    db_network_views)
        self.assertEqual(netview_dict.keys(), actual_rows)

        # test network view removals
        # - remove 'hs-view-1', 'hs-view-2'
        removing_list = [netview_dict['hs-view-1'], netview_dict['hs-view-2']]
        infoblox_db.remove_network_views_by_names(self.ctx.session,
                                                  removing_list,
                                                  self.grid_id)

        db_network_views = infoblox_db.get_network_views(self.ctx.session)
        actual_rows = utils.get_values_from_records('network_view',
                                                    db_network_views)
        actual_set = set(actual_rows)
        expected_set = set(netview_dict.keys()).difference(removing_list)
        self.assertEqual(expected_set, actual_set)

        # - remove 'hs-view-3'
        removing_netview_name = 'hs-view-3'
        removing_netview = utils.find_one_in_list('network_view',
                                                  removing_netview_name,
                                                  db_network_views)
        removing_netview_id = removing_netview.id
        infoblox_db.remove_network_views(self.ctx.session,
                                         [removing_netview_id])

        actual_network_views = infoblox_db.get_network_views(
            self.ctx.session, network_view=removing_netview_name)
        self.assertEqual([], actual_network_views)
示例#10
0
    def test_network_view_mapping_conditions_with_single_scope(self):
        user_id = 'test user'
        tenant_id = 'test-tenant'

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

        # check default network view when no mapping condition matches
        self.assertEqual('Single',
                         self.grid_config.default_network_view_scope)
        self.assertEqual('default', self.grid_config.default_network_view)

        # test default mapping as 'Single'
        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()

        # verify that 'default' view is used
        db_netviews = dbi.get_network_views(self.ctx.session,
                                            grid_id=self.grid_id)
        netview_row = utils.find_one_in_list('network_view', 'default',
                                             db_netviews)
        expected_netview_id = netview_row.id

        db_grid_members = dbi.get_members(self.ctx.session,
                                          grid_id=self.grid_id)
        member_row = utils.find_one_in_list('member_type', 'GM',
                                            db_grid_members)
        expected_member_name = member_row.member_name

        self.assertEqual(expected_netview_id,
                         ib_cxt.mapping.network_view_id)
        self.assertEqual('default',
                         ib_cxt.mapping.network_view)
        self.assertEqual(expected_member_name,
                         ib_cxt.mapping.authority_member.member_name)
示例#11
0
    def test_sync_member_with_cloud_support_without_member_licenses(self):
        member_mgr = member.GridMemberManager(self.test_grid_config)
        member_mgr.sync_grid()

        member_json = self.connector_fixture.get_object(
            base.FixtureResourceMap.FAKE_MEMBERS_WITH_CLOUD)
        self._mock_member_mgr(member_mgr, discover_members=member_json)

        member_mgr.sync_members()

        members = dbi.get_members(self.ctx.session)
        self.assertEqual(len(member_json), len(members))
        for m in members:
            if self.test_grid_config.grid_master_host == m['member_ip']:
                self.assertEqual('GM', m['member_type'])
            else:
                self.assertEqual('REGULAR', m['member_type'])
    def test_sync_member_with_cloud_support_without_member_licenses(self):
        member_mgr = member.GridMemberManager(self.test_grid_config)
        member_mgr.sync_grid()

        member_json = self.connector_fixture.get_object(
            base.FixtureResourceMap.FAKE_MEMBERS_WITH_CLOUD)
        self._mock_member_mgr(member_mgr, discover_members=member_json)

        member_mgr.sync_members()

        members = dbi.get_members(self.ctx.session)
        self.assertEqual(len(member_json), len(members))
        for m in members:
            if self.test_grid_config.grid_master_host == m['member_ip']:
                self.assertEqual('GM', m['member_type'])
            else:
                self.assertEqual('REGULAR', m['member_type'])
    def test_network_view_mapping(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
        network = models_v2.Network(name="Test Network", status="ON",
                                    admin_state_up=True)
        self.ctx.session.add(network)
        self.ctx.session.flush()

        # prepare network view
        netview_dict = {'hs-view-1': gm_member.member_id}
        self._create_network_views(netview_dict)

        db_network_views = infoblox_db.get_network_views(self.ctx.session)
        network_view_id = db_network_views[0].id

        # test associate network view
        network_id = network.id
        subnet_id = 'test-subnet-id'
        infoblox_db.associate_network_view(self.ctx.session, network_view_id,
                                           network_id, subnet_id)
        db_network_view_mappings = infoblox_db.get_network_view_mappings(
            self.ctx.session)
        self.assertEqual(network_id, db_network_view_mappings[0].network_id)
        self.assertEqual(subnet_id, db_network_view_mappings[0].subnet_id)

        db_network_views = infoblox_db.get_network_view_by_mapping(
            self.ctx.session,
            network_id=network_id,
            subnet_id=subnet_id)
        self.assertEqual(network_view_id, db_network_views[0].id)

        # test dissociate network view
        infoblox_db.dissociate_network_view(self.ctx.session, network_id,
                                            subnet_id)
        db_network_view_mappings = infoblox_db.get_network_view_mappings(
            self.ctx.session, network_id=network_id, subnet_id=subnet_id)
        self.assertEqual([], db_network_view_mappings)
    def test_network_view_mapping(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
        network = models_v2.Network(name="Test Network", status="ON",
                                    admin_state_up=True)
        self.ctx.session.add(network)
        self.ctx.session.flush()

        # prepare network view
        netview_dict = {'hs-view-1': gm_member.member_id}
        self._create_network_views(netview_dict)

        db_network_views = infoblox_db.get_network_views(self.ctx.session)
        network_view_id = db_network_views[0].id

        # test associate network view
        network_id = network.id
        subnet_id = 'test-subnet-id'
        infoblox_db.associate_network_view(self.ctx.session, network_view_id,
                                           network_id, subnet_id)
        db_network_view_mappings = infoblox_db.get_network_view_mappings(
            self.ctx.session)
        self.assertEqual(network_id, db_network_view_mappings[0].network_id)
        self.assertEqual(subnet_id, db_network_view_mappings[0].subnet_id)

        db_network_views = infoblox_db.get_network_view_by_mapping(
            self.ctx.session,
            network_id=network_id,
            subnet_id=subnet_id)
        self.assertEqual(network_view_id, db_network_views[0].id)

        # test dissociate network view
        infoblox_db.dissociate_network_view(self.ctx.session, network_id,
                                            subnet_id)
        db_network_view_mappings = infoblox_db.get_network_view_mappings(
            self.ctx.session, network_id=network_id, subnet_id=subnet_id)
        self.assertEqual([], db_network_view_mappings)
示例#15
0
    def test_sync_member_with_cloud_support_with_member_licenses(self):
        member_mgr = member.GridMemberManager(self.test_grid_config)
        member_mgr.sync_grid()

        member_json = self.connector_fixture.get_object(
            base.FixtureResourceMap.FAKE_MEMBERS_WITH_CLOUD)
        license_json = self.connector_fixture.get_object(
            base.FixtureResourceMap.FAKE_MEMBER_LICENSES)
        self._mock_member_mgr(member_mgr,
                              discover_members=member_json,
                              discover_member_licenses=license_json)

        member_mgr.sync_members()

        # member_type is computed base on member licenses. To prove correctness
        # of member types, we need to first figure out which member has
        # 'CLOUD_API' license. A member with 'CLOUD_API' is CPM; otherwise
        # 'REGULAR'. Grid master member is 'GM'
        cloud_member_list = []
        cloud_lecensed_members = utils.find_in_list('type', ['CLOUD_API'],
                                                    license_json)
        member_hwids = utils.get_values_from_records('hwid',
                                                     cloud_lecensed_members)
        for m in member_json:
            member_id_arg = str(self.test_grid_config.grid_id) + m['host_name']
            member_id = utils.get_hash(member_id_arg)
            member_hwid = m['node_info'][0].get('hwid')
            if member_hwid in member_hwids:
                cloud_member_list.append(member_id)

        # now we know member licenses so get members in db
        members = dbi.get_members(self.ctx.session)
        self.assertEqual(len(member_json), len(members))
        # verify member types
        for m in members:
            if self.test_grid_config.grid_master_host == m['member_ip']:
                self.assertEqual('GM', m['member_type'])
            else:
                if m['member_id'] in cloud_member_list:
                    self.assertEqual('CPM', m['member_type'])
                else:
                    self.assertEqual('REGULAR', m['member_type'])
    def test_sync_member_with_cloud_support_with_member_licenses(self):
        member_mgr = member.GridMemberManager(self.test_grid_config)
        member_mgr.sync_grid()

        member_json = self.connector_fixture.get_object(
            base.FixtureResourceMap.FAKE_MEMBERS_WITH_CLOUD)
        license_json = self.connector_fixture.get_object(
            base.FixtureResourceMap.FAKE_MEMBER_LICENSES)
        self._mock_member_mgr(member_mgr, discover_members=member_json,
                              discover_member_licenses=license_json)

        member_mgr.sync_members()

        # member_type is computed base on member licenses. To prove correctness
        # of member types, we need to first figure out which member has
        # 'CLOUD_API' license. A member with 'CLOUD_API' is CPM; otherwise
        # 'REGULAR'. Grid master member is 'GM'
        cloud_member_list = []
        cloud_lecensed_members = utils.find_in_list('type', ['CLOUD_API'],
                                                    license_json)
        member_hwids = utils.get_values_from_records('hwid',
                                                     cloud_lecensed_members)
        for m in member_json:
            member_id_arg = str(self.test_grid_config.grid_id) + m['host_name']
            member_id = utils.get_hash(member_id_arg)
            member_hwid = m['node_info'][0].get('hwid')
            if member_hwid in member_hwids:
                cloud_member_list.append(member_id)

        # now we know member licenses so get members in db
        members = dbi.get_members(self.ctx.session)
        self.assertEqual(len(member_json), len(members))
        # verify member types
        for m in members:
            if self.test_grid_config.grid_master_host == m['member_ip']:
                self.assertEqual('GM', m['member_type'])
            else:
                if m['member_id'] in cloud_member_list:
                    self.assertEqual('CPM', m['member_type'])
                else:
                    self.assertEqual('REGULAR', m['member_type'])
示例#17
0
    def test_grid_configuration_with_grid_member(self):
        # prepare grid members.
        self._prepare_grid_member()

        # check if GM exists
        db_members = dbi.get_members(self.ctx.session,
                                     grid_id=self.test_grid_config.grid_id,
                                     member_type='GM')
        self.assertEqual('GM', db_members[0]['member_type'])

        # get grid config from GM
        config_json = self.connector_fixture.get_object(
            base.FixtureResourceMap.FAKE_GRID_MASTER_GRID_CONFIGURATION)
        self.test_grid_config._discover_config = mock.Mock()
        self.test_grid_config._discover_config.return_value = config_json
        self.test_grid_config.sync()

        # verify if grid config object fields are set correctly
        expected = utils.get_ea_value('Default Network View Scope',
                                      config_json)
        self.assertEqual(expected,
                         self.test_grid_config.default_network_view_scope)
        expected = utils.get_ea_value('Default Network View', config_json)
        self.assertEqual(expected,
                         self.test_grid_config.default_network_view)
        expected = utils.get_ea_value('IP Allocation Strategy', config_json)
        self.assertEqual(expected,
                         self.test_grid_config.ip_allocation_strategy)
        expected = utils.get_ea_value('Default Domain Name Pattern',
                                      config_json)
        self.assertEqual(expected,
                         self.test_grid_config.default_domain_name_pattern)
        expected = utils.get_ea_value('Default Host Name Pattern',
                                      config_json)
        self.assertEqual(expected,
                         self.test_grid_config.default_host_name_pattern)
        expected = utils.get_ea_value('DNS Record Binding Types',
                                      config_json)
        self.assertEqual(expected,
                         self.test_grid_config.dns_record_binding_types)
示例#18
0
    def test_grid_configuration_with_grid_member(self):
        # prepare grid members.
        self._prepare_grid_member()

        # check if GM exists
        db_members = dbi.get_members(self.ctx.session,
                                     grid_id=self.test_grid_config.grid_id,
                                     member_type='GM')
        self.assertEqual('GM', db_members[0]['member_type'])

        # get grid config from GM
        config_json = self.connector_fixture.get_object(
            base.FixtureResourceMap.FAKE_GRID_MASTER_GRID_CONFIGURATION)
        self.test_grid_config._discover_config = mock.Mock()
        self.test_grid_config._discover_config.return_value = config_json
        self.test_grid_config.sync()

        # verify if grid config object fields are set correctly
        expected = utils.get_ea_value('Default Network View Scope',
                                      config_json)
        self.assertEqual(expected,
                         self.test_grid_config.default_network_view_scope)
        expected = utils.get_ea_value('Default Network View', config_json)
        self.assertEqual(expected, self.test_grid_config.default_network_view)
        expected = utils.get_ea_value('IP Allocation Strategy', config_json)
        self.assertEqual(expected,
                         self.test_grid_config.ip_allocation_strategy)
        expected = utils.get_ea_value('Default Domain Name Pattern',
                                      config_json)
        self.assertEqual(expected,
                         self.test_grid_config.default_domain_name_pattern)
        expected = utils.get_ea_value('Default Host Name Pattern', config_json)
        self.assertEqual(expected,
                         self.test_grid_config.default_host_name_pattern)
        expected = utils.get_ea_value('DNS Record Binding Types', config_json)
        self.assertEqual(expected,
                         self.test_grid_config.dns_record_binding_types)
示例#19
0
    def sync_members(self):
        """Synchronizes grid members.

        Members in the active grid are discovered from NIOS backend and
        grid members are in sync in neutron db. The members who are no longer
        in used are set to 'OFF' status.
        """
        session = self._context.session
        grid_id = self._grid_config.grid_id

        db_grids = dbi.get_grids(session)
        db_grid = utils.find_one_in_list('grid_id', grid_id, db_grids)
        gm_member_id = db_grid.gm_id

        db_members = dbi.get_members(session, grid_id=grid_id)
        gm_member = utils.find_one_in_list('member_id', gm_member_id,
                                           db_members)

        discovered_members = self._discover_members()
        if not discovered_members:
            return

        dns_member_settings = self._discover_dns_settings()
        dhcp_member_settings = self._discover_dhcp_settings()

        discovered_licenses = self._discover_member_licenses()

        discovered_member_ids = []

        for member in discovered_members:
            member_name = member['host_name']
            member_ip, member_ipv6 = self._get_lan1_ips(member)
            member_wapi = member_ip if member_ip else member_ipv6
            member_hwid = member['node_info'][0].get('hwid')
            member_status = self._get_member_status(
                member['node_info'][0]['service_status'])
            member_type = self._get_member_type(discovered_licenses,
                                                member_name,
                                                member_hwid)

            require_db_update = False
            if member_type == const.MEMBER_TYPE_GRID_MASTER:
                if gm_member:
                    require_db_update = True
                member_id = gm_member_id
                member_wapi = self._grid_config.grid_master_host
            else:
                # no need to process 'Is Cloud Member' flag for non GM members
                ea_is_cloud_member = utils.get_ea_value(
                    const.EA_IS_CLOUD_MEMBER, member)
                is_cloud_member = (types.Boolean()(ea_is_cloud_member)
                                   if ea_is_cloud_member else False)
                if not is_cloud_member:
                    continue

                db_member = utils.find_one_in_list('member_name', member_name,
                                                   db_members)
                if db_member:
                    require_db_update = True
                    member_id = db_member.member_id
                else:
                    member_id = utils.get_hash(str(grid_id) + member_name)

            member_dhcp_ip, member_dhcp_ipv6 = self._get_dhcp_ips(
                member, dhcp_member_settings)
            member_dns_ip, member_dns_ipv6 = self._get_dns_ips(
                member, dns_member_settings)

            if require_db_update:
                dbi.update_member(session,
                                  member_id,
                                  grid_id,
                                  member_name,
                                  member_ip,
                                  member_ipv6,
                                  member_type,
                                  member_status,
                                  member_dhcp_ip,
                                  member_dhcp_ipv6,
                                  member_dns_ip,
                                  member_dns_ipv6,
                                  member_wapi)
            else:
                dbi.add_member(session,
                               member_id,
                               grid_id,
                               member_name,
                               member_ip,
                               member_ipv6,
                               member_type,
                               member_status,
                               member_dhcp_ip,
                               member_dhcp_ipv6,
                               member_dns_ip,
                               member_dns_ipv6,
                               member_wapi)

            discovered_member_ids.append(member_id)

        # deleting members are delicate operation so we won't allow it
        # but we will set member status to OFF to unused members.
        db_member_ids = utils.get_values_from_records('member_id', db_members)
        persisted_set = set(db_member_ids)
        discovered_set = set(discovered_member_ids)
        disable_set = persisted_set.difference(discovered_set)
        disabling_member_ids = list(disable_set)
        for member_id in disabling_member_ids:
            dbi.update_member(session,
                              member_id,
                              grid_id,
                              member_status=const.MEMBER_STATUS_OFF)
        session.flush()
示例#20
0
    def test_get_next_dhcp_member(self):
        # prepare grid
        self._create_default_grid()

        # prepare grid members
        member_list = [{
            'member_id': 'm1',
            'member_name': 'm1.com',
            'member_ip': '10.10.1.1',
            'member_ipv6': None,
            'member_type': const.MEMBER_TYPE_GRID_MASTER,
            'member_status': 'ON'
        }, {
            'member_id': 'm2',
            'member_name': 'm2.com',
            'member_ip': '10.10.1.2',
            'member_ipv6': 'fd44:acb:5df6:1083::22',
            'member_type': const.MEMBER_TYPE_CP_MEMBER,
            'member_status': 'ON'
        }, {
            'member_id': 'm3',
            'member_name': 'm3.com',
            'member_ip': '10.10.1.3',
            'member_ipv6': None,
            'member_type': const.MEMBER_TYPE_CP_MEMBER,
            'member_status': 'ON'
        }, {
            'member_id': 'm4',
            'member_name': 'm4.com',
            'member_ip': '10.10.1.4',
            'member_ipv6': None,
            'member_type': const.MEMBER_TYPE_REGULAR_MEMBER,
            'member_status': 'ON'
        }]
        self._create_members(member_list, self.grid_id)

        db_members = infoblox_db.get_members(self.ctx.session,
                                             grid_id=self.grid_id)
        gm_member = utils.find_one_in_list('member_type', 'GM', db_members)
        m2_member = utils.find_one_in_list('member_id', 'm2', db_members)
        m3_member = utils.find_one_in_list('member_id', 'm3', db_members)
        m4_member = utils.find_one_in_list('member_id', 'm4', db_members)

        # create network views
        netview_dict = {
            'default': gm_member.member_id,
            'testview': m2_member.member_id
        }
        self._create_network_views(netview_dict)

        db_network_views = infoblox_db.get_network_views(self.ctx.session)
        netview_default = utils.find_one_in_list('network_view', 'default',
                                                 db_network_views)
        netview_testview = utils.find_one_in_list('network_view', 'testview',
                                                  db_network_views)

        # add mapping members
        # - m1 (gm) is the authority member for 'default' view
        # - m2 is the authority member for 'testview' view as CPM
        infoblox_db.add_mapping_member(self.ctx.session, netview_default.id,
                                       gm_member.member_id,
                                       const.MAPPING_RELATION_GM_OWNED)
        infoblox_db.add_mapping_member(self.ctx.session, netview_testview.id,
                                       m2_member.member_id,
                                       const.MAPPING_RELATION_DELEGATED)

        # add service members
        # - m4 is a member that serves DHCP/DNS for a network under
        #   the non-delegated view, 'default'
        # - m2 is the delegated member to the network view, 'testview'
        infoblox_db.add_service_member(self.ctx.session, netview_default.id,
                                       m4_member.member_id,
                                       const.SERVICE_TYPE_DHCP)
        infoblox_db.add_service_member(self.ctx.session, netview_default.id,
                                       m4_member.member_id,
                                       const.SERVICE_TYPE_DNS)
        infoblox_db.add_service_member(self.ctx.session, netview_default.id,
                                       m2_member.member_id,
                                       const.SERVICE_TYPE_DHCP)
        infoblox_db.add_service_member(self.ctx.session, netview_default.id,
                                       m2_member.member_id,
                                       const.SERVICE_TYPE_DNS)

        dhcp_member = infoblox_db.get_next_dhcp_member(self.ctx.session,
                                                       self.grid_id)

        # only available dhcp member should be 'm3'
        self.assertEqual(m3_member.member_id, dhcp_member.member_id)
    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))
示例#22
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))
示例#23
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)
示例#24
0
    def test_member_management(self):
        # prepare grid
        self._create_default_grid()

        member_list = [{
            'member_id': 'M_1000',
            'member_name': 'Member 1000',
            'member_ip': '10.10.1.12',
            'member_ipv6': None,
            'member_type': 'REGULAR',
            'member_status': 'ON'
        }, {
            'member_id': 'M_2000',
            'member_name': 'Member 2000',
            'member_ip': '10.10.1.22',
            'member_ipv6': 'fd44:acb:5df6:1083::22',
            'member_type': 'CPM',
            'member_status': 'ON'
        }]

        # expects no member
        db_members = infoblox_db.get_members(self.ctx.session)
        self.assertEqual(0, len(db_members))

        # test member additions
        self._create_members(member_list, self.grid_id)

        db_members = infoblox_db.get_members(self.ctx.session)
        actual_member_rows = utils.get_composite_values_from_records([
            'member_id', 'member_name', 'member_ip', 'member_ipv6',
            'member_type', 'member_status'
        ], db_members)
        expected_member_rows = utils.get_composite_values_from_records([
            'member_id', 'member_name', 'member_ip', 'member_ipv6',
            'member_type', 'member_status'
        ], member_list)
        self.assertEqual(expected_member_rows, actual_member_rows)

        # test member update
        member_name_update = "Member 1000 VM"
        member_ipv6_update = "fd44:acb:5df6:1083::12"
        infoblox_db.update_member(self.ctx.session,
                                  member_list[0]['member_id'],
                                  self.grid_id,
                                  member_name=member_name_update,
                                  member_ipv6=member_ipv6_update)
        db_members = infoblox_db.get_members(self.ctx.session,
                                             member_list[0]['member_id'],
                                             grid_id=self.grid_id)
        self.assertEqual(member_name_update, db_members[0]['member_name'])
        self.assertEqual(member_ipv6_update, db_members[0]['member_ipv6'])

        # test member removals
        infoblox_db.remove_members(self.ctx.session,
                                   [member_list[0]['member_id']])
        db_members = infoblox_db.get_members(self.ctx.session,
                                             member_list[0]['member_id'])
        self.assertEqual(0, len(db_members))

        self._create_members([member_list[0]], self.grid_id)
        db_members = infoblox_db.get_members(self.ctx.session)
        self.assertEqual(2, len(db_members))

        infoblox_db.remove_members(
            self.ctx.session,
            [member_list[0]['member_id'], member_list[1]['member_id']])
        db_members = infoblox_db.get_members(self.ctx.session)
        self.assertEqual(0, len(db_members))

        infoblox_db.remove_grids(self.ctx.session, [self.grid_id])
    def test_get_next_dhcp_member(self):
        # prepare grid
        self._create_default_grid()

        # prepare grid members
        member_list = [{'member_id': 'm1',
                        'member_name': 'm1.com',
                        'member_ip': '10.10.1.1',
                        'member_ipv6': None,
                        'member_type': const.MEMBER_TYPE_GRID_MASTER,
                        'member_status': 'ON'},
                       {'member_id': 'm2',
                        'member_name': 'm2.com',
                        'member_ip': '10.10.1.2',
                        'member_ipv6': 'fd44:acb:5df6:1083::22',
                        'member_type': const.MEMBER_TYPE_CP_MEMBER,
                        'member_status': 'ON'},
                       {'member_id': 'm3',
                        'member_name': 'm3.com',
                        'member_ip': '10.10.1.3',
                        'member_ipv6': None,
                        'member_type': const.MEMBER_TYPE_CP_MEMBER,
                        'member_status': 'ON'},
                       {'member_id': 'm4',
                        'member_name': 'm4.com',
                        'member_ip': '10.10.1.4',
                        'member_ipv6': None,
                        'member_type': const.MEMBER_TYPE_REGULAR_MEMBER,
                        'member_status': 'ON'}]
        self._create_members(member_list, self.grid_id)

        db_members = infoblox_db.get_members(self.ctx.session,
                                             grid_id=self.grid_id)
        gm_member = utils.find_one_in_list('member_type', 'GM', db_members)
        m2_member = utils.find_one_in_list('member_id', 'm2', db_members)
        m3_member = utils.find_one_in_list('member_id', 'm3', db_members)
        m4_member = utils.find_one_in_list('member_id', 'm4', db_members)

        # create network views
        netview_dict = {'default': gm_member.member_id,
                        'testview': m2_member.member_id}
        self._create_network_views(netview_dict)

        db_network_views = infoblox_db.get_network_views(self.ctx.session)
        netview_default = utils.find_one_in_list('network_view',
                                                 'default',
                                                 db_network_views)
        netview_testview = utils.find_one_in_list('network_view',
                                                  'testview',
                                                  db_network_views)

        # add mapping members
        # - m1 (gm) is the authority member for 'default' view
        # - m2 is the authority member for 'testview' view as CPM
        infoblox_db.add_mapping_member(self.ctx.session,
                                       netview_default.id,
                                       gm_member.member_id,
                                       const.MAPPING_RELATION_GM_OWNED)
        infoblox_db.add_mapping_member(self.ctx.session,
                                       netview_testview.id,
                                       m2_member.member_id,
                                       const.MAPPING_RELATION_DELEGATED)

        # add service members
        # - m4 is a member that serves DHCP/DNS for a network under
        #   the non-delegated view, 'default'
        # - m2 is the delegated member to the network view, 'testview'
        infoblox_db.add_service_member(self.ctx.session,
                                       netview_default.id,
                                       m4_member.member_id,
                                       const.SERVICE_TYPE_DHCP)
        infoblox_db.add_service_member(self.ctx.session,
                                       netview_default.id,
                                       m4_member.member_id,
                                       const.SERVICE_TYPE_DNS)
        infoblox_db.add_service_member(self.ctx.session,
                                       netview_default.id,
                                       m2_member.member_id,
                                       const.SERVICE_TYPE_DHCP)
        infoblox_db.add_service_member(self.ctx.session,
                                       netview_default.id,
                                       m2_member.member_id,
                                       const.SERVICE_TYPE_DNS)

        dhcp_member = infoblox_db.get_next_dhcp_member(self.ctx.session,
                                                       self.grid_id)

        # only available dhcp member should be 'm3'
        self.assertEqual(m3_member.member_id, dhcp_member.member_id)
    def test_service_member(self):
        # prepare grid
        self._create_default_grid()

        # prepare grid members
        member_list = [{'member_id': 'm1',
                        'member_name': 'm1.com',
                        'member_ip': '10.10.1.1',
                        'member_ipv6': None,
                        'member_type': const.MEMBER_TYPE_GRID_MASTER,
                        'member_status': 'ON'},
                       {'member_id': 'm2',
                        'member_name': 'm2.com',
                        'member_ip': '10.10.1.2',
                        'member_ipv6': 'fd44:acb:5df6:1083::22',
                        'member_type': const.MEMBER_TYPE_CP_MEMBER,
                        'member_status': 'ON'}]
        self._create_members(member_list, self.grid_id)

        db_members = infoblox_db.get_members(self.ctx.session,
                                             grid_id=self.grid_id)
        gm_member = utils.find_one_in_list('member_type', 'GM', db_members)
        m2_member = utils.find_one_in_list('member_id', 'm2', db_members)

        # create 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 = utils.find_one_in_list('network_view',
                                                 'default',
                                                 db_network_views)

        # test addition
        infoblox_db.add_service_member(self.ctx.session,
                                       netview_default.id,
                                       gm_member.member_id,
                                       const.SERVICE_TYPE_DHCP)

        infoblox_db.add_service_member(self.ctx.session,
                                       netview_default.id,
                                       m2_member.member_id,
                                       const.SERVICE_TYPE_DHCP)

        db_service_members = infoblox_db.get_service_members(
            self.ctx.session, netview_default.id)
        gm_dhcp_member = utils.find_one_in_list('member_id',
                                                gm_member.member_id,
                                                db_service_members)
        self.assertIsNotNone(gm_dhcp_member)
        m2_dhcp_member = utils.find_one_in_list('member_id',
                                                m2_member.member_id,
                                                db_service_members)
        self.assertIsNotNone(m2_dhcp_member)

        # test removal
        infoblox_db.remove_service_member(self.ctx.session, netview_default.id)
        db_service_members = infoblox_db.get_service_members(
            self.ctx.session, netview_default.id)
        gm_dhcp_member = utils.find_one_in_list('member_id',
                                                gm_member.member_id,
                                                db_service_members)
        self.assertIsNone(gm_dhcp_member)

        m2m_dhcp_member = utils.find_one_in_list('member_id',
                                                 m2_member.member_id,
                                                 db_service_members)
        self.assertIsNone(m2m_dhcp_member)
    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 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)
示例#29
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)
示例#30
0
    def sync_members(self):
        """Synchronizes grid members.

        Members in the active grid are discovered from NIOS backend and
        grid members are in sync in neutron db. The members who are no longer
        in used are set to 'OFF' status.
        """
        session = self._context.session
        grid_id = self._grid_config.grid_id

        db_grids = dbi.get_grids(session)
        db_grid = utils.find_one_in_list('grid_id', grid_id, db_grids)
        gm_member_id = db_grid.gm_id

        db_members = dbi.get_members(session, grid_id=grid_id)
        gm_member = utils.find_one_in_list('member_id', gm_member_id,
                                           db_members)

        discovered_members = self._discover_members()
        if not discovered_members:
            return

        dns_member_settings = self._discover_dns_settings()
        dhcp_member_settings = self._discover_dhcp_settings()

        discovered_licenses = self._discover_member_licenses()

        discovered_member_ids = []

        for member in discovered_members:
            member_name = member['host_name']
            member_ip, member_ipv6 = self._get_lan1_ips(member)
            member_wapi = member_ip if member_ip else member_ipv6
            member_hwid = member['node_info'][0].get('hwid')
            member_status = self._get_member_status(
                member['node_info'][0]['service_status'])
            member_type = self._get_member_type(discovered_licenses,
                                                member_name, member_hwid)

            require_db_update = False
            if member_type == const.MEMBER_TYPE_GRID_MASTER:
                if gm_member:
                    require_db_update = True
                member_id = gm_member_id
                member_wapi = self._grid_config.grid_master_host
            else:
                # no need to process 'Is Cloud Member' flag for non GM members
                ea_is_cloud_member = utils.get_ea_value(
                    const.EA_IS_CLOUD_MEMBER, member)
                is_cloud_member = (types.Boolean()(ea_is_cloud_member)
                                   if ea_is_cloud_member else False)
                if not is_cloud_member:
                    continue

                db_member = utils.find_one_in_list('member_name', member_name,
                                                   db_members)
                if db_member:
                    require_db_update = True
                    member_id = db_member.member_id
                else:
                    member_id = utils.get_hash(str(grid_id) + member_name)

            member_dhcp_ip, member_dhcp_ipv6 = self._get_dhcp_ips(
                member, dhcp_member_settings)
            member_dns_ip, member_dns_ipv6 = self._get_dns_ips(
                member, dns_member_settings)

            if require_db_update:
                dbi.update_member(session, member_id, grid_id, member_name,
                                  member_ip, member_ipv6, member_type,
                                  member_status, member_dhcp_ip,
                                  member_dhcp_ipv6, member_dns_ip,
                                  member_dns_ipv6, member_wapi)
            else:
                dbi.add_member(session, member_id, grid_id, member_name,
                               member_ip, member_ipv6, member_type,
                               member_status, member_dhcp_ip, member_dhcp_ipv6,
                               member_dns_ip, member_dns_ipv6, member_wapi)

            discovered_member_ids.append(member_id)

        # deleting members are delicate operation so we won't allow it
        # but we will set member status to OFF to unused members.
        db_member_ids = utils.get_values_from_records('member_id', db_members)
        persisted_set = set(db_member_ids)
        discovered_set = set(discovered_member_ids)
        disable_set = persisted_set.difference(discovered_set)
        disabling_member_ids = list(disable_set)
        for member_id in disabling_member_ids:
            dbi.update_member(session,
                              member_id,
                              grid_id,
                              member_status=const.MEMBER_STATUS_OFF)
        session.flush()
    def test_member_management(self):
        # prepare grid
        self._create_default_grid()

        member_list = [{'member_id': 'M_1000',
                        'member_name': 'Member 1000',
                        'member_ip': '10.10.1.12',
                        'member_ipv6': None,
                        'member_type': 'REGULAR',
                        'member_status': 'ON'},
                       {'member_id': 'M_2000',
                        'member_name': 'Member 2000',
                        'member_ip': '10.10.1.22',
                        'member_ipv6': 'fd44:acb:5df6:1083::22',
                        'member_type': 'CPM',
                        'member_status': 'ON'}]

        # expects no member
        db_members = infoblox_db.get_members(self.ctx.session)
        self.assertEqual(0, len(db_members))

        # test member additions
        self._create_members(member_list, self.grid_id)

        db_members = infoblox_db.get_members(self.ctx.session)
        actual_member_rows = utils.get_composite_values_from_records(
            ['member_id', 'member_name', 'member_ip', 'member_ipv6',
             'member_type', 'member_status'],
            db_members)
        expected_member_rows = utils.get_composite_values_from_records(
            ['member_id', 'member_name', 'member_ip', 'member_ipv6',
             'member_type', 'member_status'],
            member_list)
        self.assertEqual(expected_member_rows, actual_member_rows)

        # test member update
        member_name_update = "Member 1000 VM"
        member_ipv6_update = "fd44:acb:5df6:1083::12"
        infoblox_db.update_member(self.ctx.session,
                                  member_list[0]['member_id'],
                                  self.grid_id,
                                  member_name=member_name_update,
                                  member_ipv6=member_ipv6_update)
        db_members = infoblox_db.get_members(self.ctx.session,
                                             member_list[0]['member_id'],
                                             grid_id=self.grid_id)
        self.assertEqual(member_name_update, db_members[0]['member_name'])
        self.assertEqual(member_ipv6_update, db_members[0]['member_ipv6'])

        # test member removals
        infoblox_db.remove_members(self.ctx.session,
                                   [member_list[0]['member_id']])
        db_members = infoblox_db.get_members(self.ctx.session,
                                             member_list[0]['member_id'])
        self.assertEqual(0, len(db_members))

        self._create_members([member_list[0]], self.grid_id)
        db_members = infoblox_db.get_members(self.ctx.session)
        self.assertEqual(2, len(db_members))

        infoblox_db.remove_members(self.ctx.session,
                                   [member_list[0]['member_id'],
                                    member_list[1]['member_id']])
        db_members = infoblox_db.get_members(self.ctx.session)
        self.assertEqual(0, len(db_members))

        infoblox_db.remove_grids(self.ctx.session, [self.grid_id])
示例#32
0
    def test_service_member(self):
        # prepare grid
        self._create_default_grid()

        # prepare grid members
        member_list = [{
            'member_id': 'm1',
            'member_name': 'm1.com',
            'member_ip': '10.10.1.1',
            'member_ipv6': None,
            'member_type': const.MEMBER_TYPE_GRID_MASTER,
            'member_status': 'ON'
        }, {
            'member_id': 'm2',
            'member_name': 'm2.com',
            'member_ip': '10.10.1.2',
            'member_ipv6': 'fd44:acb:5df6:1083::22',
            'member_type': const.MEMBER_TYPE_CP_MEMBER,
            'member_status': 'ON'
        }]
        self._create_members(member_list, self.grid_id)

        db_members = infoblox_db.get_members(self.ctx.session,
                                             grid_id=self.grid_id)
        gm_member = utils.find_one_in_list('member_type', 'GM', db_members)
        m2_member = utils.find_one_in_list('member_id', 'm2', db_members)

        # create 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 = utils.find_one_in_list('network_view', 'default',
                                                 db_network_views)

        # test addition
        infoblox_db.add_service_member(self.ctx.session, netview_default.id,
                                       gm_member.member_id,
                                       const.SERVICE_TYPE_DHCP)

        infoblox_db.add_service_member(self.ctx.session, netview_default.id,
                                       m2_member.member_id,
                                       const.SERVICE_TYPE_DHCP)

        db_service_members = infoblox_db.get_service_members(
            self.ctx.session, netview_default.id)
        gm_dhcp_member = utils.find_one_in_list('member_id',
                                                gm_member.member_id,
                                                db_service_members)
        self.assertIsNotNone(gm_dhcp_member)
        m2_dhcp_member = utils.find_one_in_list('member_id',
                                                m2_member.member_id,
                                                db_service_members)
        self.assertIsNotNone(m2_dhcp_member)

        # test removal
        infoblox_db.remove_service_member(self.ctx.session, netview_default.id)
        db_service_members = infoblox_db.get_service_members(
            self.ctx.session, netview_default.id)
        gm_dhcp_member = utils.find_one_in_list('member_id',
                                                gm_member.member_id,
                                                db_service_members)
        self.assertIsNone(gm_dhcp_member)

        m2m_dhcp_member = utils.find_one_in_list('member_id',
                                                 m2_member.member_id,
                                                 db_service_members)
        self.assertIsNone(m2m_dhcp_member)
示例#33
0
 def discovered_grid_members(self):
     if self._discovered_grid_members is None:
         self._discovered_grid_members = dbi.get_members(
             self.context.session, grid_id=self.grid_id,
             member_status=const.MEMBER_STATUS_ON)
     return self._discovered_grid_members