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])
Exemple #2
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])
Exemple #3
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 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()