Пример #1
0
    def test_get(self):
        '''
        Test for Get data from the mine
         based on the target, function and expr_form
        '''
        with patch.dict(
                mine.__salt__, {
                    'match.glob': MagicMock(),
                    'match.pcre': MagicMock(),
                    'match.list': MagicMock(),
                    'match.grain': MagicMock(),
                    'match.grain_pcre': MagicMock(),
                    'match.ipcidr': MagicMock(),
                    'match.compound': MagicMock(),
                    'match.pillar': MagicMock(),
                    'match.pillar_pcre': MagicMock(),
                    'data.getval': MagicMock(return_value={})
                }):
            with patch.dict(mine.__opts__, {
                    'file_client': 'local',
                    'id': 'id'
            }):
                self.assertEqual(mine.get('tgt', 'fun'), {})

        with patch.dict(mine.__opts__, {'file_client': 'local1', 'id': 'id'}):
            with patch.object(mine, '_mine_get', return_value='A'):
                self.assertEqual(mine.get('tgt', 'fun'), 'A')
Пример #2
0
 def test_get_local_empty(self):
     """
     Tests getting function data from the local mine that does not exist.
     """
     with patch.dict(mine.__opts__, {"file_client": "local", "id": "webserver"}):
         ret_classic = mine.get("*", "funky.doodle")
         ret_dict = mine.get("*", ["funky.doodle"])
     self.assertEqual(ret_classic, {})
     self.assertEqual(ret_dict, {})
Пример #3
0
 def test_send_get_local(self):
     '''
     Tests sending an item to the mine in the minion's local cache,
     and then immediately fetching it again (since tests are executed unordered).
     Also verify that the stored mine cache has the correct structure (with ACL).
     '''
     with patch.dict(mine.__opts__, {
                 'file_client': 'local',
                 'id': 'webserver',
             }), \
             patch.dict(mine.__salt__, {
                 'network.ip_addrs': MagicMock(return_value='2001:db8::1:3'),
                 'foo.bar': MagicMock(return_value='baz'),
             }):
         ret = mine.send('ip_addr', mine_function='network.ip_addrs')
         mine.send('foo.bar')
     self.assertEqual(ret, 'FakeCache:StoreSuccess!')
     self.assertEqual(
         self.cache.fetch('minions/webserver', 'mine_cache'), {
             'ip_addr': {
                 salt.utils.mine.MINE_ITEM_ACL_DATA:
                 '2001:db8::1:3',
                 salt.utils.mine.MINE_ITEM_ACL_ID:
                 salt.utils.mine.MINE_ITEM_ACL_VERSION,
             },
             'foo.bar': {
                 salt.utils.mine.MINE_ITEM_ACL_DATA:
                 'baz',
                 salt.utils.mine.MINE_ITEM_ACL_ID:
                 salt.utils.mine.MINE_ITEM_ACL_VERSION,
             },
         })
     with patch.dict(mine.__opts__, {
             'file_client': 'local',
             'id': 'webserver',
     }):
         ret_single = mine.get('*', 'ip_addr')
         ret_single_dict = mine.get('*', ['ip_addr'])
         ret_multi = mine.get('*', 'ip_addr,foo.bar')
         ret_multi2 = mine.get('*', ['ip_addr', 'foo.bar'])
     self.assertEqual(ret_single, {'webserver': '2001:db8::1:3'})
     self.assertEqual(ret_single_dict,
                      {'ip_addr': {
                          'webserver': '2001:db8::1:3'
                      }})
     self.assertEqual(
         ret_multi, {
             'ip_addr': {
                 'webserver': '2001:db8::1:3'
             },
             'foo.bar': {
                 'webserver': 'baz'
             }
         })
     self.assertEqual(ret_multi, ret_multi2)
Пример #4
0
 def test_get_local_empty(self):
     '''
     Tests getting function data from the local mine that does not exist.
     '''
     with patch.dict(mine.__opts__, {
             'file_client': 'local',
             'id': 'webserver',
     }):
         ret_classic = mine.get('*', 'funky.doodle')
         ret_dict = mine.get('*', ['funky.doodle'])
     self.assertEqual(ret_classic, {})
     self.assertEqual(ret_dict, {})
Пример #5
0
 def test_get_master_exclude_minion(self):
     """
     Tests the exclude_minion-parameter for mine.get
     """
     _mine_get_ret = OrderedDict([("webserver", "value")])
     with patch.object(
         mine, "_mine_get", MagicMock(return_value=_mine_get_ret)
     ), patch.dict(mine.__opts__, {"file_client": "remote", "id": "webserver"}):
         self.assertEqual(
             mine.get("*", "foo.bar", exclude_minion=False), {"webserver": "value"}
         )
         self.assertEqual(mine.get("*", "foo.bar", exclude_minion=True), {})
Пример #6
0
 def test_get_local_classic(self):
     """
     Tests getting function data from the local mine that was stored without minion-side ACL.
     This verifies backwards compatible reads from a salt mine.
     """
     # Prefill minion cache with a non-ACL value
     self.cache.store("minions/webserver", "mine_cache", {"foobard": "barfood"})
     with patch.dict(mine.__opts__, {"file_client": "local", "id": "webserver"}):
         ret_classic = mine.get("*", "foobard")
         ret_dict = mine.get("*", ["foobard"])
     self.assertEqual(ret_classic, {"webserver": "barfood"})
     self.assertEqual(ret_dict, {"foobard": {"webserver": "barfood"}})
Пример #7
0
 def test_send_get_local(self):
     """
     Tests sending an item to the mine in the minion's local cache,
     and then immediately fetching it again (since tests are executed unordered).
     Also verify that the stored mine cache does not use ACL data structure
     without allow_tgt passed.
     """
     with patch.dict(mine.__opts__, {
             "file_client": "local",
             "id": "webserver"
     }), patch.dict(
             mine.__salt__,
         {
             "network.ip_addrs": MagicMock(return_value=self.ip_ret),
             "foo.bar": MagicMock(return_value=self.foo_ret),
         },
     ):
         ret = mine.send("ip_addr", mine_function="network.ip_addrs")
         mine.send("foo.bar")
     self.assertEqual(ret, "FakeCache:StoreSuccess!")
     self.assertEqual(
         self.cache.fetch("minions/webserver", "mine_cache"),
         {
             "ip_addr": self.ip_ret,
             "foo.bar": self.foo_ret
         },
     )
     with patch.dict(mine.__opts__, {
             "file_client": "local",
             "id": "webserver"
     }):
         ret_single = mine.get("*", "ip_addr")
         ret_single_dict = mine.get("*", ["ip_addr"])
         ret_multi = mine.get("*", "ip_addr,foo.bar")
         ret_multi2 = mine.get("*", ["ip_addr", "foo.bar"])
     self.assertEqual(ret_single, {"webserver": self.ip_ret})
     self.assertEqual(ret_single_dict,
                      {"ip_addr": {
                          "webserver": self.ip_ret
                      }})
     self.assertEqual(
         ret_multi,
         {
             "ip_addr": {
                 "webserver": self.ip_ret
             },
             "foo.bar": {
                 "webserver": self.foo_ret
             },
         },
     )
     self.assertEqual(ret_multi, ret_multi2)
Пример #8
0
 def test_get_master_exclude_minion(self):
     '''
     Tests the exclude_minion-parameter for mine.get
     '''
     _mine_get_ret = OrderedDict([('webserver', 'value')])
     with patch.object(mine, '_mine_get', MagicMock(return_value=_mine_get_ret)),\
             patch.dict(mine.__opts__, {
                 'file_client': 'remote',
                 'id': 'webserver',
             }):
         self.assertEqual(mine.get('*', 'foo.bar', exclude_minion=False),
                          {'webserver': 'value'})
         self.assertEqual(mine.get('*', 'foo.bar', exclude_minion=True), {})
Пример #9
0
 def test_get_local_classic(self):
     '''
     Tests getting function data from the local mine that was stored without minion-side ACL.
     This verifies backwards compatible reads from a salt mine.
     '''
     # Prefill minion cache with a non-ACL value
     self.cache.store('minions/webserver', 'mine_cache',
                      {'foobard': 'barfood'})
     with patch.dict(mine.__opts__, {
             'file_client': 'local',
             'id': 'webserver',
     }):
         ret_classic = mine.get('*', 'foobard')
         ret_dict = mine.get('*', ['foobard'])
     self.assertEqual(ret_classic, {'webserver': 'barfood'})
     self.assertEqual(ret_dict, {'foobard': {'webserver': 'barfood'}})
Пример #10
0
 def test_send_get_local(self):
     '''
     Tests sending an item to the mine in the minion's local cache,
     and then immediately fetching it again (since tests are executed unordered).
     Also verify that the stored mine cache does not use ACL data structure
     without allow_tgt passed.
     '''
     with patch.dict(mine.__opts__, {
                 'file_client': 'local',
                 'id': 'webserver',
             }), \
             patch.dict(mine.__salt__, {
                 'network.ip_addrs': MagicMock(return_value=self.ip_ret),
                 'foo.bar': MagicMock(return_value=self.foo_ret),
             }):
         ret = mine.send('ip_addr', mine_function='network.ip_addrs')
         mine.send('foo.bar')
     self.assertEqual(ret, 'FakeCache:StoreSuccess!')
     self.assertEqual(self.cache.fetch('minions/webserver', 'mine_cache'), {
         'ip_addr': self.ip_ret,
         'foo.bar': self.foo_ret,
     })
     with patch.dict(mine.__opts__, {
             'file_client': 'local',
             'id': 'webserver',
     }):
         ret_single = mine.get('*', 'ip_addr')
         ret_single_dict = mine.get('*', ['ip_addr'])
         ret_multi = mine.get('*', 'ip_addr,foo.bar')
         ret_multi2 = mine.get('*', ['ip_addr', 'foo.bar'])
     self.assertEqual(ret_single, {'webserver': self.ip_ret})
     self.assertEqual(ret_single_dict,
                      {'ip_addr': {
                          'webserver': self.ip_ret
                      }})
     self.assertEqual(
         ret_multi, {
             'ip_addr': {
                 'webserver': self.ip_ret
             },
             'foo.bar': {
                 'webserver': self.foo_ret
             }
         })
     self.assertEqual(ret_multi, ret_multi2)
Пример #11
0
def test_send_get_local(mock_cache):
    """
    Tests sending an item to the mine in the minion's local cache,
    and then immediately fetching it again (since tests are executed unordered).
    Also verify that the stored mine cache does not use ACL data structure
    without allow_tgt passed.
    """
    foo_ret = "baz"
    ip_ret = "2001:db8::1:3"
    with patch.dict(mine.__opts__, {
            "file_client": "local",
            "id": "webserver"
    }), patch.dict(
            mine.__salt__,
        {
            "network.ip_addrs": MagicMock(return_value=ip_ret),
            "foo.bar": MagicMock(return_value=foo_ret),
        },
    ):
        ret = mine.send("ip_addr", mine_function="network.ip_addrs")
        mine.send("foo.bar")
    assert ret == "FakeCache:StoreSuccess!"
    assert mock_cache.fetch("minions/webserver", "mine_cache") == {
        "ip_addr": ip_ret,
        "foo.bar": foo_ret,
    }
    with patch.dict(mine.__opts__, {
            "file_client": "local",
            "id": "webserver"
    }):
        ret_single = mine.get("*", "ip_addr")
        ret_single_dict = mine.get("*", ["ip_addr"])
        ret_multi = mine.get("*", "ip_addr,foo.bar")
        ret_multi2 = mine.get("*", ["ip_addr", "foo.bar"])
    assert ret_single == {"webserver": ip_ret}
    assert ret_single_dict == {"ip_addr": {"webserver": ip_ret}}
    assert ret_multi == {
        "ip_addr": {
            "webserver": ip_ret
        },
        "foo.bar": {
            "webserver": foo_ret
        },
    }
    assert ret_multi == ret_multi2
Пример #12
0
    def test_get(self):
        '''
        Test for Get data from the mine
         based on the target, function and expr_form
        '''
        with patch.dict(mine.__salt__, {'match.glob': MagicMock(),
                                        'match.pcre': MagicMock(),
                                        'match.list': MagicMock(),
                                        'match.grain': MagicMock(),
                                        'match.grain_pcre': MagicMock(),
                                        'match.ipcidr': MagicMock(),
                                        'match.compound': MagicMock(),
                                        'match.pillar': MagicMock(),
                                        'match.pillar_pcre': MagicMock(),
                                        'data.getval':
                                        MagicMock(return_value={})}):
            with patch.dict(mine.__opts__, {'file_client': 'local',
                                            'id': 'id'}):
                self.assertEqual(mine.get('tgt', 'fun'), {})

        with patch.dict(mine.__opts__, {'file_client': 'local1', 'id': 'id'}):
            with patch.object(mine, '_mine_get', return_value='A'):
                self.assertEqual(mine.get('tgt', 'fun'), 'A')
Пример #13
0
 def test_get_master(self):
     """
     Tests loading a mine item from the mine stored on the master.
     """
     mock_load = {
         "tgt_type": "qux",
         "tgt": self.foo_ret,
         "cmd": "_mine_get",
         "fun": "foo.bar",
         "id": "foo",
     }
     with patch.object(
         mine, "_mine_get", MagicMock(return_value=mock_load)
     ), patch.dict(mine.__opts__, {"file_client": "remote", "id": "foo"}):
         # Verify the correct load
         self.assertEqual(mine.get("*", "foo.bar"), mock_load)
Пример #14
0
 def test_send_get_acl_local(self):
     """
     Tests sending an item to the mine in the minion's local cache,
     including ACL information (useless when only working locally, but hey),
     and then immediately fetching it again (since tests are executed unordered).
     Also verify that the stored mine cache has the correct structure (with ACL)
     when using allow_tgt and no ACL without allow_tgt.
     """
     with patch.dict(mine.__opts__, {
             "file_client": "local",
             "id": "webserver"
     }), patch.dict(
             mine.__salt__,
         {
             "network.ip_addrs": MagicMock(return_value=self.ip_ret),
             "foo.bar": MagicMock(return_value=self.foo_ret),
         },
     ):
         ret = mine.send(
             "ip_addr",
             mine_function="network.ip_addrs",
             allow_tgt="web*",
             allow_tgt_type="glob",
         )
         mine.send("foo.bar")
     self.assertEqual(ret, "FakeCache:StoreSuccess!")
     self.assertEqual(
         self.cache.fetch("minions/webserver", "mine_cache"),
         {
             "ip_addr": {
                 salt.utils.mine.MINE_ITEM_ACL_DATA: self.ip_ret,
                 salt.utils.mine.MINE_ITEM_ACL_ID:
                 salt.utils.mine.MINE_ITEM_ACL_VERSION,
                 "allow_tgt": "web*",
                 "allow_tgt_type": "glob",
             },
             "foo.bar": self.foo_ret,
         },
     )
     with patch.dict(mine.__opts__, {
             "file_client": "local",
             "id": "webserver"
     }):
         ret_single = mine.get("*", "ip_addr")
     self.assertEqual(ret_single, {"webserver": self.ip_ret})
Пример #15
0
 def test_get_master(self):
     '''
     Tests loading a mine item from the mine stored on the master.
     '''
     mock_load = {
         'tgt_type': 'qux',
         'tgt': 'baz',
         'cmd': '_mine_get',
         'fun': 'foo.bar',
         'id': 'foo'
     }
     with patch.object(mine, '_mine_get', MagicMock(return_value=mock_load)),\
             patch.dict(mine.__opts__, {
                 'file_client': 'remote',
                 'id': 'foo',
             }):
         # Verify the correct load
         self.assertEqual(mine.get('*', 'foo.bar'), mock_load)
Пример #16
0
 def test_send_get_acl_local(self):
     '''
     Tests sending an item to the mine in the minion's local cache,
     including ACL information (useless when only working locally, but hey),
     and then immediately fetching it again (since tests are executed unordered).
     Also verify that the stored mine cache has the correct structure (with ACL).
     '''
     with patch.dict(mine.__opts__, {
                 'file_client': 'local',
                 'id': 'webserver',
             }), \
             patch.dict(mine.__salt__, {
                 'network.ip_addrs': MagicMock(return_value='2001:db8::1:3'),
                 'foo.bar': MagicMock(return_value='baz'),
             }):
         ret = mine.send('ip_addr',
                         mine_function='network.ip_addrs',
                         allow_tgt='web*',
                         allow_tgt_type='glob')
         mine.send('foo.bar')
     self.assertEqual(ret, 'FakeCache:StoreSuccess!')
     self.assertEqual(
         self.cache.fetch('minions/webserver', 'mine_cache'), {
             'ip_addr': {
                 salt.utils.mine.MINE_ITEM_ACL_DATA: '2001:db8::1:3',
                 salt.utils.mine.MINE_ITEM_ACL_ID:
                 salt.utils.mine.MINE_ITEM_ACL_VERSION,
                 'allow_tgt': 'web*',
                 'allow_tgt_type': 'glob',
             },
             'foo.bar': {
                 salt.utils.mine.MINE_ITEM_ACL_DATA:
                 'baz',
                 salt.utils.mine.MINE_ITEM_ACL_ID:
                 salt.utils.mine.MINE_ITEM_ACL_VERSION,
             },
         })
     with patch.dict(mine.__opts__, {
             'file_client': 'local',
             'id': 'webserver',
     }):
         ret_single = mine.get('*', 'ip_addr')
     self.assertEqual(ret_single, {'webserver': '2001:db8::1:3'})
Пример #17
0
def test_get_master():
    """
    Tests loading a mine item from the mine stored on the master.
    """
    foo_ret = "baz"
    mock_load = {
        "tgt_type": "qux",
        "tgt": foo_ret,
        "cmd": "_mine_get",
        "fun": "foo.bar",
        "id": "foo",
    }
    with patch.object(mine, "_mine_get",
                      MagicMock(return_value=mock_load)), patch.dict(
                          mine.__opts__, {
                              "file_client": "remote",
                              "id": "foo"
                          }):
        assert mine.get("*", "foo.bar") == mock_load