예제 #1
0
    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
예제 #2
0
    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()
예제 #3
0
 def _fake_weighted_sum(functions, hosts, options):
     self.next_weight += 2.0
     host_state = hosts[0]
     return least_cost.WeightedHost(self.next_weight,
                                    host_state=host_state)
예제 #4
0
 def _return_hosts(*args, **kwargs):
     host_state = host_manager.HostState('host2', 'compute')
     return [least_cost.WeightedHost(1.0, host_state=host_state)]
예제 #5
0
 def test_dict_conversion_with_host_state(self):
     host_state = host_manager.HostState('somehost', 'sometopic')
     host = least_cost.WeightedHost('someweight', host_state)
     expected = {'weight': 'someweight', 'host': 'somehost'}
     self.assertDictMatch(host.to_dict(), expected)
예제 #6
0
 def test_dict_conversion_without_host_state(self):
     host = least_cost.WeightedHost('someweight')
     expected = {'weight': 'someweight'}
     self.assertDictMatch(host.to_dict(), expected)
예제 #7
0
 def _fake_make_weighted_host_from_blob(*args, **kwargs):
     self.from_blob_called = True
     return least_cost.WeightedHost(1, zone='x', blob='y')
예제 #8
0
 def _fake_schedule(*args, **kwargs):
     self.schedule_called = True
     return least_cost.WeightedHost(1, host='x')