示例#1
0
def test_compound_with_minion_id(minion_id):
    """
    Make sure that when a minion_id IS past, that it is contained in opts
    """
    mock_compound_match = MagicMock()
    target = "bar04"
    new_minion_id = "new_minion_id"

    with patch.object(
        salt.loader,
        "matchers",
        return_value={"compound_match.match": mock_compound_match},
    ) as matchers:
        match.compound(target, minion_id=new_minion_id)

        # The matcher should get called with minion_id
        matchers.assert_called_once()

        # The compound matcher should not get minion_id, no opts should be passed
        mock_compound_match.assert_called_once_with(
            target,
            minion_id="new_minion_id",
            opts={"extension_modules": "", "id": minion_id},
        )

        # Ensure that the id of the minion is bar03
        assert match.__opts__["id"] == minion_id
示例#2
0
def test_compound(minion_id):
    """
    Test issue #55149
    """
    mock_compound_match = MagicMock()
    target = "bar04"

    with patch.object(
            salt.loader,
            "matchers",
            return_value={"compound_match.match": mock_compound_match},
    ) as matchers:
        match.compound(target)

        # The matcher should get called with minion_id
        matchers.assert_called_once()
        assert len(matchers.call_args[0]) == 1
        assert matchers.call_args[0][0].get("id") == minion_id

        # The compound matcher should not get minion_id, no opts should be passed
        mock_compound_match.assert_called_once_with(target,
                                                    minion_id=None,
                                                    opts={
                                                        "extension_modules":
                                                        "",
                                                        "id": minion_id
                                                    })
示例#3
0
文件: match_test.py 项目: DaveQB/salt
    def test_compound(self, mock_matcher):
        '''
        Test for Return True if the minion ID matches the given compound target
        '''
        with patch.dict(match.__grains__, {'id': 101}):

            mock_matcher.side_effect = MagicMock()
            with patch.object(mock_matcher, 'compound_match', MagicMock()):
                self.assertTrue(match.compound('tgt'))

            mock_matcher.side_effect = MagicMock(return_value='B')
            self.assertFalse(match.compound('tgt'))
示例#4
0
    def test_compound(self, mock_matcher):
        '''
        Test for Return True if the minion ID matches the given compound target
        '''
        with patch.dict(match.__grains__, {'id': 101}):

            mock_matcher.side_effect = MagicMock()
            with patch.object(mock_matcher, 'compound_match', MagicMock()):
                self.assertTrue(match.compound('tgt'))

            mock_matcher.side_effect = MagicMock(return_value='B')
            self.assertFalse(match.compound('tgt'))
示例#5
0
    def test_compound(self):
        """
        Test issue #55149
        """
        mock_compound_match = MagicMock()
        target = "bar04"

        with patch.object(
                salt.loader,
                "matchers",
                return_value={"compound_match.match": mock_compound_match},
        ) as matchers:
            match.compound(target)

            # The matcher should get called with MINION_ID
            matchers.assert_called_once()
            self.assertEqual(len(matchers.call_args[0]), 1)
            self.assertEqual(matchers.call_args[0][0].get("id"), MINION_ID)

            # The compound matcher should not get MINION_ID, no opts should be passed
            mock_compound_match.assert_called_once_with(target)
示例#6
0
    def test_compound(self):
        '''
        Test issue #55149
        '''
        mock_compound_match = MagicMock()
        target = 'bar04'

        with patch.object(
                salt.loader,
                'matchers',
                return_value={'compound_match.match':
                              mock_compound_match}) as matchers:
            match.compound(target)

            # The matcher should get called with MINION_ID
            matchers.assert_called_once()
            self.assertEqual(len(matchers.call_args[0]), 1)
            self.assertEqual(matchers.call_args[0][0].get('id'), MINION_ID)

            # The compound matcher should not get MINION_ID, no opts should be passed
            mock_compound_match.assert_called_once_with(target)
示例#7
0
    def test_compound_with_minion_id(self):
        """
        Make sure that when a minion_id IS past, that it is contained in opts
        """
        mock_compound_match = MagicMock()
        target = "bar04"
        new_minion_id = "new_minion_id"

        with patch.object(
                salt.loader,
                "matchers",
                return_value={"compound_match.match": mock_compound_match},
        ) as matchers:
            match.compound(target, minion_id=new_minion_id)

            # The matcher should get called with MINION_ID
            matchers.assert_called_once()
            matchers_opts = matchers.call_args[0][0]
            self.assertEqual(matchers_opts.get("id"), new_minion_id)

            # The compound matcher should not get MINION_ID, no opts should be passed
            mock_compound_match.assert_called_once_with(target)
示例#8
0
    def test_compound_with_minion_id(self):
        '''
        Make sure that when a minion_id IS past, that it is contained in opts
        '''
        mock_compound_match = MagicMock()
        target = 'bar04'
        new_minion_id = 'new_minion_id'

        with patch.object(
                salt.loader,
                'matchers',
                return_value={'compound_match.match':
                              mock_compound_match}) as matchers:
            match.compound(target, minion_id=new_minion_id)

            # The matcher should get called with MINION_ID
            matchers.assert_called_once()
            matchers_opts = matchers.call_args[0][0]
            self.assertEqual(matchers_opts.get('id'), new_minion_id)

            # The compound matcher should not get MINION_ID, no opts should be passed
            mock_compound_match.assert_called_once_with(target)