示例#1
0
def strat_directive_mock():
    return [
        sb.CacheNode('node-a', 'image-a', 'checksum-a'),
        sb.CacheNode('node-b', 'image-b', 'checksum-b'),
        sb.CacheNode('node-c', 'image-c', 'checksum-c'),
        sb.CacheNode('node-d', 'image-d', 'checksum-d'),
        sb.CacheNode('node-e', 'image-e', 'checksum-e'),
        sb.EjectNode('node-f'),
        sb.EjectNode('node-g'),
        sb.EjectNode('node-h'),
        sb.EjectNode('node-i'),
        sb.EjectNode('node-J'),
    ]
    def _ejection_test(self, env):
        """Are we ejecting nodes whose images are no longer in the current
        image list?
        """
        strategy = sps.SimpleProportionalStrategy()
        strategy.update_current_state(**env)
        directives = strategy.directives()
        if len(directives) == 0:
            directives = [sb.CacheNode('a', 'b', 'c')]
        ejection_directives = filter(
            lambda direct: isinstance(direct, sb.EjectNode), directives)
        ejected_node_uuids = sb.build_attribute_set(ejection_directives,
                                                    'node_uuid')
        for node in env['nodes']:
            # Make sure that cached nodes with invalid images are ejected.
            if node.cached_image_uuid == INVALID_IMAGE.uuid and node.cached:
                self.assertIn(node.node_uuid,
                              ejected_node_uuids,
                              ("A node with an invalid image UUID was not "
                               "ejected from the cache. Node UUID: %s" % (
                                   node.node_uuid)))

        # Ensure ejected nodes are marked as 'provisioned'.
        nodes_by_uuid = {node.node_uuid: node for node in env['nodes']}
        for node_uuid in ejected_node_uuids:
            self.assertTrue(nodes_by_uuid[node_uuid].provisioned)

        # Make sure the strategy is not trying to cache to ejected nodes.
        cache_directives = filter(
            lambda direct: isinstance(direct, sb.CacheNode), directives)
        cached_node_uuids = sb.build_attribute_set(cache_directives,
                                                   'node_uuid')
        self.assertEqual(
            0, len(cached_node_uuids.intersection(ejected_node_uuids)),
            "One or more ejected nodes scheduled to cache immediately!")
示例#3
0
 def test_issue_cache_node_bad_image(self, wrapper_call_mock):
     cache_node_action = strat_base.CacheNode('node_uuid', 'zzzz',
                                              'ubuntu-checksum')
     self.scout.issue_cache_node(cache_node_action)
     self.assertFalse(
         wrapper_call_mock.called,
         "The client should not have been called because "
         "a bad image uuid was passed!")
示例#4
0
 def test_issue_cache_node_good_image(self, wrapper_call_mock):
     cache_node_action = strat_base.CacheNode('node_uuid', 'aaaa',
                                              'ubuntu-checksum')
     expected_args = {
         'image_info': {
             'id': 'aaaa',
             'urls': [CONF.glance.api_endpoint + 'ubuntu_14_04_image.pxe'],
             'checksum': 'ubuntu-checksum'
         }
     }
     self.scout.issue_cache_node(cache_node_action)
     wrapper_call_mock.assert_called_once_with('node.vendor_passthru',
                                               node_id='node_uuid',
                                               method='cache_image',
                                               http_method='POST',
                                               args=expected_args)
def cache_nodes(nodes, num_nodes_needed, images):
    available_nodes = nodes_available_for_caching(nodes)

    # Choose the images to cache in advance, based on how many nodes we should
    # use for caching.
    chosen_images = sb.choose_weighted_images_forced_distribution(
        num_nodes_needed, images, nodes)

    # If we're not meeting or exceeding our proportion goal,
    # schedule (node, image) pairs to cache until we would meet
    # our proportion goal.
    nodes_to_cache = []
    random.shuffle(available_nodes)
    for n in range(0, num_nodes_needed):
        node = available_nodes.pop()
        image = chosen_images.pop()
        nodes_to_cache.append(
            sb.CacheNode(node.node_uuid, image.uuid, image.checksum))
    return nodes_to_cache