def run_command(opts=None, saltenv="base", **kwargs):
     """
     Now that we instantiate the client in the __init__, we need to mock it
     """
     if opts is None:
         opts = minion_opts
     loader = SaltCacheLoader(opts, saltenv, _file_client=mock_file_client)
     # Create a mock file client and attach it to the loader
     return loader
Ejemplo n.º 2
0
 def test_searchpath(self):
     '''
     The searchpath is based on the cachedir option and the saltenv parameter
     '''
     tmp = tempfile.gettempdir()
     opts = copy.deepcopy(self.opts)
     opts.update({'cachedir': tmp})
     loader = SaltCacheLoader(opts, saltenv='test')
     assert loader.searchpath == [os.path.join(tmp, 'files', 'test')]
Ejemplo n.º 3
0
def test_cache_loader_shutdown(minion_opts, mock_file_client):
    """
    The shudown method can be called without raising an exception when the
    file_client does not have a destroy method
    """
    assert not hasattr(mock_file_client, "destroy")
    loader = SaltCacheLoader(minion_opts, _file_client=mock_file_client)
    assert loader._file_client is mock_file_client
    # Shutdown method should not raise any exceptions
    loader.shutdown()
Ejemplo n.º 4
0
 def get_loader(self, opts=None, saltenv='base'):
     '''
     Now that we instantiate the client in the __init__, we need to mock it
     '''
     if opts is None:
         opts = self.opts
     with patch.object(SaltCacheLoader, 'file_client', Mock()):
         loader = SaltCacheLoader(opts, saltenv)
     # Create a mock file client and attach it to the loader
     MockFileClient(loader)
     return loader
Ejemplo n.º 5
0
 def test_mockclient(self):
     '''
     A MockFileClient is used that records all file request normally send to the master.
     '''
     loader = SaltCacheLoader({'cachedir': TEMPLATES_DIR}, 'test')
     fc = MockFileClient(loader)
     res = loader.get_source(None, 'hello_simple')
     assert len(res) == 3
     self.assertEqual(res[0], 'world\n')
     self.assertEqual(res[1], '%s/files/test/hello_simple' % TEMPLATES_DIR)
     assert res[2](), "Template up to date?"
     assert len(fc.requests)
     self.assertEqual(fc.requests[0]['path'], 'salt://hello_simple')
Ejemplo n.º 6
0
 def test_mockclient(self):
     '''
     A MockFileClient is used that records all file requests normally sent
     to the master.
     '''
     loader = SaltCacheLoader(self.opts, 'test')
     fc = MockFileClient(loader)
     res = loader.get_source(None, 'hello_simple')
     assert len(res) == 3
     # res[0] on Windows is unicode and use os.linesep so it works cross OS
     self.assertEqual(str(res[0]), 'world' + os.linesep)
     tmpl_dir = os.path.join(TEMPLATES_DIR, 'files', 'test', 'hello_simple')
     self.assertEqual(res[1], tmpl_dir)
     assert res[2](), 'Template up to date?'
     assert len(fc.requests)
     self.assertEqual(fc.requests[0]['path'], 'salt://hello_simple')
Ejemplo n.º 7
0
 def test_searchpath(self):
     '''
     The searchpath is based on the cachedir option and the env parameter
     '''
     loader = SaltCacheLoader({'cachedir': '/tmp'}, env='test')
     assert loader.searchpath == '/tmp/files/test'