Beispiel #1
0
    def test_send(self):
        '''
        Test for Send a specific function to the mine.
        '''

        self.assertFalse(mine.send('func'))

        with patch.dict(mine.__salt__, {'func': 'func'}):
            with patch.object(salt.utils,
                              'arg_lookup',
                              return_value={'A': 'B'}):
                with patch.object(copy, 'deepcopy', return_value='A'):
                    with patch.object(salt.utils,
                                      'format_call',
                                      return_value='A'):
                        self.assertFalse(mine.send('func'), 'C')

        with patch.dict(
                mine.__salt__, {
                    'A': MagicMock(),
                    'data.update': MagicMock(return_value='update'),
                    'data.getval': MagicMock(return_value='old')
                }):
            with patch.object(salt.utils,
                              'arg_lookup',
                              return_value={'A': 'B'}):
                with patch.object(copy, 'deepcopy', return_value='A'):
                    with patch.object(salt.utils,
                                      'format_call',
                                      return_value={'args': 'a'}):
                        with patch.dict(mine.__opts__,
                                        {'file_client': 'local'}):
                            self.assertEqual(mine.send('0', mine_function='A'),
                                             'update')

        with patch.dict(
                mine.__salt__, {
                    'A': MagicMock(),
                    'data.update': MagicMock(return_value='update'),
                    'data.getval': MagicMock(return_value='old')
                }):
            with patch.object(salt.utils,
                              'arg_lookup',
                              return_value={'A': 'B'}):
                with patch.object(copy, 'deepcopy', return_value='A'):
                    with patch.object(salt.utils,
                                      'format_call',
                                      return_value={'args': 'a'}):
                        with patch.dict(mine.__opts__, {
                                'file_client': 'local1',
                                'id': 'id'
                        }):
                            with patch.object(mine,
                                              '_mine_send',
                                              return_value='A'):
                                self.assertEqual(
                                    mine.send('0', mine_function='A'), 'A')
Beispiel #2
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)
Beispiel #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 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)
Beispiel #4
0
    def test_send(self):
        '''
        Test for Send a specific function to the mine.
        '''

        self.assertFalse(mine.send('func'))

        with patch.dict(mine.__salt__, {'func': 'func'}):
            with patch.object(salt.utils,
                              'arg_lookup', return_value={'A': 'B'}):
                with patch.object(copy, 'deepcopy', return_value='A'):
                    with patch.object(salt.utils,
                                      'format_call', return_value='A'):
                        self.assertFalse(mine.send('func'), 'C')

        with patch.dict(mine.__salt__, {'A': MagicMock(),
                                        'data.update':
                                        MagicMock(return_value='update'),
                                        'data.getval':
                                        MagicMock(return_value='old')}):
            with patch.object(salt.utils,
                              'arg_lookup', return_value={'A': 'B'}):
                with patch.object(copy, 'deepcopy', return_value='A'):
                    with patch.object(salt.utils,
                                      'format_call',
                                      return_value={'args': 'a'}):
                        with patch.dict(mine.__opts__,
                                        {'file_client': 'local'}):
                            self.assertEqual(mine.send('0',
                                                       mine_function='A'),
                                             'update')

        with patch.dict(mine.__salt__, {'A': MagicMock(),
                                        'data.update':
                                        MagicMock(return_value='update'),
                                        'data.getval':
                                        MagicMock(return_value='old')}):
            with patch.object(salt.utils,
                              'arg_lookup', return_value={'A': 'B'}):
                with patch.object(copy, 'deepcopy', return_value='A'):
                    with patch.object(salt.utils,
                                      'format_call',
                                      return_value={'args': 'a'}):
                        with patch.dict(mine.__opts__,
                                        {'file_client': 'local1',
                                         'id': 'id'}):
                            with patch.object(mine,
                                              '_mine_send',
                                              return_value='A'):
                                self.assertEqual(mine.send('0',
                                                           mine_function='A'),
                                                 'A')
Beispiel #5
0
 def test_send_master_acl(self):
     """
     Tests sending an item to the mine stored on the master. Now with ACL.
     This is done by capturing the load that is sent to the master.
     """
     with patch.object(
             mine, "_mine_send",
             MagicMock(side_effect=lambda x, y: x)), patch.dict(
                 mine.__salt__,
                 {"foo.bar": MagicMock(return_value=self.foo_ret)
                  }), patch.dict(mine.__opts__, {
                      "file_client": "remote",
                      "id": "foo"
                  }):
         ret = mine.send("foo.bar",
                         allow_tgt="roles:web",
                         allow_tgt_type="grains")
     self.assertEqual(
         ret,
         {
             "id": "foo",
             "cmd": "_mine",
             "data": {
                 "foo.bar": {
                     salt.utils.mine.MINE_ITEM_ACL_DATA: self.foo_ret,
                     salt.utils.mine.MINE_ITEM_ACL_ID:
                     salt.utils.mine.MINE_ITEM_ACL_VERSION,
                     "allow_tgt": "roles:web",
                     "allow_tgt_type": "grains",
                 },
             },
             "clear": False,
         },
     )
Beispiel #6
0
 def test_send_master(self):
     """
     Tests sending an item to the mine stored on the master.
     This is done by capturing the load that is sent to the master.
     """
     with patch.object(
             mine, "_mine_send",
             MagicMock(side_effect=lambda x, y: x)), patch.dict(
                 mine.__salt__,
                 {"foo.bar": MagicMock(return_value=self.foo_ret)
                  }), patch.dict(mine.__opts__, {
                      "file_client": "remote",
                      "id": "foo"
                  }):
         ret = mine.send("foo.bar")
     self.assertEqual(
         ret,
         {
             "id": "foo",
             "cmd": "_mine",
             "data": {
                 "foo.bar": self.foo_ret
             },
             "clear": False,
         },
     )
Beispiel #7
0
 def test_send_master_acl(self):
     '''
     Tests sending an item to the mine stored on the master. Now with ACL.
     This is done by capturing the load that is sent to the master.
     '''
     with patch.object(mine, '_mine_send', MagicMock(side_effect=lambda x, y: x)),\
             patch.dict(mine.__salt__, {
                 'foo.bar': MagicMock(return_value='baz'),
             }), \
             patch.dict(mine.__opts__, {
                 'file_client': 'remote',
                 'id': 'foo',
             }):
         ret = mine.send('foo.bar',
                         allow_tgt='roles:web',
                         allow_tgt_type='grains')
     self.assertEqual(
         ret, {
             'id': 'foo',
             'cmd': '_mine',
             'data': {
                 'foo.bar': {
                     salt.utils.mine.MINE_ITEM_ACL_DATA: 'baz',
                     salt.utils.mine.MINE_ITEM_ACL_ID:
                     salt.utils.mine.MINE_ITEM_ACL_VERSION,
                     'allow_tgt': 'roles:web',
                     'allow_tgt_type': 'grains',
                 },
             },
             'clear': False,
         })
Beispiel #8
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})
Beispiel #9
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
Beispiel #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)
Beispiel #11
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'})
Beispiel #12
0
 def test_send_master(self):
     '''
     Tests sending an item to the mine stored on the master.
     This is done by capturing the load that is sent to the master.
     '''
     with patch.object(mine, '_mine_send', MagicMock(side_effect=lambda x, y: x)),\
             patch.dict(mine.__salt__, {
                 'foo.bar': MagicMock(return_value=self.foo_ret),
             }), \
             patch.dict(mine.__opts__, {
                 'file_client': 'remote',
                 'id': 'foo',
             }):
         ret = mine.send('foo.bar')
     self.assertEqual(
         ret, {
             'id': 'foo',
             'cmd': '_mine',
             'data': {
                 'foo.bar': self.foo_ret
             },
             'clear': False,
         })