示例#1
0
 def _get_policy_offset_total(self):
     total_policy_offsets = 0
     policy_ids = {}
     blocks = self.melange_session.query(melange.IpBlocks).all()
     for block in blocks:
         if block.policy_id:
             if block.policy_id not in policy_ids.keys():
                 policy_ids[block.policy_id] = {}
             policy_ids[block.policy_id][block.id] = block.network_id
     octets = self.melange_session.query(melange.IpOctets).all()
     offsets = self.melange_session.query(melange.IpRanges).all()
     for policy, policy_block_ids in policy_ids.items():
         policy_octets = [o.octet for o in octets if o.policy_id == policy]
         policy_offsets = [(off.offset, off.length) for off in offsets
                           if off.policy_id == policy]
         policy_offsets = make_offset_lengths(policy_octets, policy_offsets)
         for block_id in policy_block_ids.keys():
             total_policy_offsets += len(policy_offsets)
     return total_policy_offsets
示例#2
0
 def _validate_policy_rules(self):
     offsets_count = self._get_policy_offset_total()
     qpolicy_rules_count = self.get_scalar(quarkmodels.IPPolicyRange.id,
                                           self.neutron_session)
     err_count = self.count_not_migrated("policy_rules")
     self._compare_after_migration("Offsets",
                                   offsets_count - err_count,
                                   "Policy Rules", qpolicy_rules_count)
     # first block in melange with a policy
     _block = self.melange_session.query(melange.IpBlocks).\
         filter(melange.IpBlocks.policy_id != None).first()
     # policy that matches the block:
     _policy = self.melange_session.query(melange.Policies).\
         filter(melange.Policies.id == _block.policy_id).first()
     # get the policy rules
     _octets = self.melange_session.query(melange.IpOctets).\
         filter(melange.IpOctets.policy_id == _policy.id).all()
     _ranges = self.melange_session.query(melange.IpRanges).\
         filter(melange.IpRanges.policy_id == _policy.id).all()
     tmp_octets = [o.octet for o in _octets]
     tmp_ranges = [(r.offset, r.length) for r in _ranges]
     # tmp store the converted, compressed policies:
     _expected = make_offset_lengths(tmp_octets, tmp_ranges)
     #get the matching quark policies:
     _q_network = self.neutron_session.query(quarkmodels.Network).\
         filter(quarkmodels.Network.id == _block.network_id).first()
     _q_policy = self.neutron_session.query(quarkmodels.IPPolicy).\
         filter(quarkmodels.IPPolicy.tenant_id ==
                _q_network.tenant_id).first()
     _actual = list()
     _q_policy_rules = self.neutron_session.query(
         quarkmodels.IPPolicyRange).\
         filter(quarkmodels.IPPolicyRange.ip_policy_id ==
                _q_policy.id).all()
     for range in _q_policy_rules:
         _actual.append((range.offset, range.length))
     self.assertItemsEqual(_expected, _actual)