def test_generate_node_filter_more_labels(self):
     """Tests the _generate_node_filter function"""
     sel = GroupNodeSelector({
         'node_names': [],
         'node_labels':
         ['label1:label1', 'label2:enabled', 'control-plane: bicycle'],
         'node_tags': [],
         'rack_names': [],
     })
     nf = _generate_node_filter([sel])
     assert nf == {
         'filter_set': [{
             'filter_type': 'intersection',
             'node_names': [],
             'node_tags': [],
             'rack_names': [],
             'node_labels': {
                 'label1': 'label1',
                 'label2': 'enabled',
                 'control-plane': 'bicycle'
             }
         }],
         'filter_set_type':
         'union'
     }
Example #2
0
 def test_NodeLookup_lookup_client_forbidden(self, get_nodes):
     """Test the functionality of the setup and lookup functions"""
     nl = NodeLookup(mock.MagicMock(), {"design": "ref"}, retry_delay=0.1)
     sel = GroupNodeSelector({
         'node_names': [],
         'node_labels': [],
         'node_tags': [],
         'rack_names': [],
     })
     with pytest.raises(errors.ClientForbiddenError) as ex:
         resp = nl.lookup([sel])
     assert get_nodes.call_count == 1
Example #3
0
    def test_validate_selectors(self):
        """Tests the _validate_selectors function"""
        try:
            _validate_selectors([GroupNodeSelector({})])
            _validate_selectors([])
        except:
            # No exceptions expected.
            assert False

        with pytest.raises(InvalidDeploymentGroupNodeLookupError) as idgnle:
            _validate_selectors(None)
        assert "iterable of GroupNodeSelectors" in str(idgnle.value)

        with pytest.raises(InvalidDeploymentGroupNodeLookupError) as idgnle:
            _validate_selectors(["bad!"])
        assert "all input elements in the selectors" in str(idgnle.value)

        with pytest.raises(InvalidDeploymentGroupNodeLookupError) as idgnle:
            _validate_selectors(["bad!", "also bad!"])
        assert "all input elements in the selectors" in str(idgnle.value)

        with pytest.raises(InvalidDeploymentGroupNodeLookupError) as idgnle:
            _validate_selectors([GroupNodeSelector({}), "bad!"])
        assert "all input elements in the selectors" in str(idgnle.value)
Example #4
0
    def test_NodeLookup_lookup(self, *args):
        """Test the functionality of the setup and lookup functions"""
        nl = NodeLookup(mock.MagicMock(), {"design": "ref"})

        assert nl.design_ref == {"design": "ref"}
        assert nl.drydock_client

        sel = GroupNodeSelector({
            'node_names': [],
            'node_labels': ['label1:label1'],
            'node_tags': ['tag1', 'tag2'],
            'rack_names': ['rack3', 'rack1'],
        })

        resp = nl.lookup([sel])
        assert resp == ['node1', 'node2']
 def test_generate_node_filter_only_rack(self):
     """Tests the _generate_node_filter function"""
     sel = GroupNodeSelector({
         'node_names': [],
         'node_labels': [],
         'node_tags': [],
         'rack_names': ['RACK1', 'RACK2'],
     })
     nf = _generate_node_filter([sel])
     assert nf == {
         'filter_set': [{
             'filter_type': 'intersection',
             'node_names': [],
             'node_tags': [],
             'rack_names': ['RACK1', 'RACK2'],
             'node_labels': {}
         }],
         'filter_set_type':
         'union'
     }
Example #6
0
    def test_generate_node_filter(self):
        """Tests the _generate_node_filter function"""
        sel = GroupNodeSelector({
            'node_names': [],
            'node_labels': ['label1:label1'],
            'node_tags': ['tag1', 'tag2'],
            'rack_names': ['rack3', 'rack1'],
        })
        nf = _generate_node_filter([sel])
        assert nf == {
            'filter_set': [{
                'filter_type': 'intersection',
                'node_names': [],
                'node_tags': ['tag1', 'tag2'],
                'rack_names': ['rack3', 'rack1'],
                'node_labels': {
                    'label1': 'label1'
                }
            }],
            'filter_set_type':
            'union'
        }

        sel2 = GroupNodeSelector({
            'node_names': ['node1', 'node2', 'node3', 'node4', 'node5'],
            'node_labels': ['label1:label1', 'label2:label2'],
            'node_tags': ['tag1', 'tag2'],
            'rack_names': ['rack3', 'rack1'],
        })
        nf = _generate_node_filter([sel, sel2])
        assert nf == {
            'filter_set': [{
                'filter_type': 'intersection',
                'node_names': [],
                'node_tags': ['tag1', 'tag2'],
                'rack_names': ['rack3', 'rack1'],
                'node_labels': {
                    'label1': 'label1'
                }
            }, {
                'filter_type':
                'intersection',
                'node_names': ['node1', 'node2', 'node3', 'node4', 'node5'],
                'node_tags': ['tag1', 'tag2'],
                'rack_names': ['rack3', 'rack1'],
                'node_labels': {
                    'label1': 'label1',
                    'label2': 'label2'
                }
            }],
            'filter_set_type':
            'union'
        }

        sel3 = GroupNodeSelector({})
        sel4 = GroupNodeSelector({
            'node_names': [],
            'node_labels': [],
            'node_tags': [],
            'rack_names': [],
        })
        nf = _generate_node_filter([sel, sel3, sel4])
        assert nf == {
            'filter_set': [{
                'filter_type': 'intersection',
                'node_names': [],
                'node_tags': ['tag1', 'tag2'],
                'rack_names': ['rack3', 'rack1'],
                'node_labels': {
                    'label1': 'label1'
                }
            }],
            'filter_set_type':
            'union'
        }

        nf = _generate_node_filter([sel3, sel4])
        assert nf is None