def _adjust_child_weights(self, child_results, zones):
        """Apply the Scale and Offset values from the Zone definition
        to adjust the weights returned from the child zones. Returns
        a list of WeightedHost objects: [WeightedHost(), ...]
        """
        weighted_hosts = []
        for zone_id, result in child_results:
            if not result:
                continue

            for zone_rec in zones:
                if zone_rec['id'] != zone_id:
                    continue
                for item in result:
                    try:
                        offset = zone_rec['weight_offset']
                        scale = zone_rec['weight_scale']
                        raw_weight = item['weight']
                        cooked_weight = offset + scale * raw_weight

                        weighted_hosts.append(
                            least_cost.WeightedHost(host=None,
                                                    weight=cooked_weight,
                                                    zone=zone_id,
                                                    blob=item['blob']))
                    except KeyError:
                        LOG.exception(
                            _("Bad child zone scaling values "
                              "for Zone: %(zone_id)s") % locals())
        return weighted_hosts
    def _make_weighted_host_from_blob(self, blob):
        """Returns the decrypted blob as a WeightedHost object
        or None if invalid. Broken out for testing.
        """
        decryptor = crypto.decryptor(FLAGS.build_plan_encryption_key)
        try:
            json_entry = decryptor(blob)
            # Extract our WeightedHost values
            wh_dict = json.loads(json_entry)
            host = wh_dict.get('host', None)
            blob = wh_dict.get('blob', None)
            zone = wh_dict.get('zone', None)
            return least_cost.WeightedHost(wh_dict['weight'],
                                           host=host,
                                           blob=blob,
                                           zone=zone)

        except M2Crypto.EVP.EVPError:
            raise InvalidBlob()
Example #3
0
 def _fake_weighted_sum(functions, hosts, options):
     self.next_weight += 2.0
     host, hostinfo = hosts[0]
     return least_cost.WeightedHost(self.next_weight, host=host,
                                    hostinfo=hostinfo)
Example #4
0
 def _fake_make_weighted_host_from_blob(*args, **kwargs):
     self.from_blob_called = True
     return least_cost.WeightedHost(1, zone='x', blob='y')
Example #5
0
 def _fake_schedule(*args, **kwargs):
     self.schedule_called = True
     return least_cost.WeightedHost(1, host='x')