def test_user_mdata(self):
        """
        We have a list of two grains, so there should be two mdata-get
        calls, resulting in 2 grains.
        """
        grains_exp_res = {
            "mdata": {
                "multi_text_data": "multi\nline\ntext",
                "simple_text_data": "some text data",
            },
        }

        which_mock = Mock(side_effect=["/usr/sbin/mdata-list", "/usr/sbin/mdata-get"])
        cmd_mock = Mock(
            side_effect=[
                "simple_text_data\nmulti_text_data",
                "some text data",
                "multi\nline\ntext",
            ]
        )
        with patch("salt.utils.path.which", which_mock), patch.dict(
            mdata.__salt__, {"cmd.run": cmd_mock}
        ):
            grains_res = mdata._user_mdata()

            self.assertEqual(grains_exp_res, grains_res)
Beispiel #2
0
    def test_user_mdata(self):
        '''
        We have a list of two grains, so there should be two mdata-get
        calls, resulting in 2 grains.
        '''
        grains_exp_res = {
            'mdata': {
                'multi_text_data': 'multi\nline\ntext',
                'simple_text_data': 'some text data',
            },
        }

        which_mock = Mock(side_effect=[
            "/usr/sbin/mdata-list",
            "/usr/sbin/mdata-get",
        ])
        cmd_mock = Mock(side_effect=[
            "simple_text_data\nmulti_text_data",
            "some text data",
            "multi\nline\ntext",
        ])
        with patch('salt.utils.path.which', which_mock), \
             patch.dict(mdata.__salt__, {'cmd.run': cmd_mock}):
            grains_res = mdata._user_mdata()

            self.assertEqual(grains_exp_res, grains_res)
    def test_user_mdata_missing_cmd_one(self):
        """
        When both or either of the commands is missing there should
        be no grain output.
        """
        grains_exp_res = {}

        which_mock = Mock(side_effect=["/usr/sbin/mdata-list", None])
        with patch("salt.utils.path.which", which_mock):
            grains_res = mdata._user_mdata()
            self.assertEqual(grains_exp_res, grains_res)
    def test_user_mdata_empty_list(self):
        """
        When there are no user grains, there are no mdata-get calls
        so there are also no grains.
        """
        grains_exp_res = {}

        which_mock = Mock(side_effect=["/usr/sbin/mdata-list", "/usr/sbin/mdata-get"])
        cmd_mock = Mock(side_effect=[""])
        with patch("salt.utils.path.which", which_mock), patch.dict(
            mdata.__salt__, {"cmd.run": cmd_mock}
        ):
            grains_res = mdata._user_mdata()
            self.assertEqual(grains_exp_res, grains_res)
Beispiel #5
0
    def test_user_mdata_missing_cmd_both(self):
        '''
        When both or either of the commands is missing there should
        be no grain output.
        '''
        grains_exp_res = {}

        which_mock = Mock(side_effect=[
            None,
            None,
        ])
        with patch('salt.utils.path.which', which_mock):
            grains_res = mdata._user_mdata()
            self.assertEqual(grains_exp_res, grains_res)