def test_find_file(self): with patch.dict(roots.__opts__, {'file_roots': self.master_opts['file_roots'], 'fileserver_ignoresymlinks': False, 'fileserver_followsymlinks': False, 'file_ignore_regex': False, 'file_ignore_glob': False}): ret = roots.find_file('testfile') self.assertEqual('testfile', ret['rel']) full_path_to_file = os.path.join(integration.FILES, 'file', 'base', 'testfile') self.assertEqual(full_path_to_file, ret['path'])
def test_dynamic_file_roots(self): dyn_root_dir = tempfile.mkdtemp(dir=RUNTIME_VARS.TMP) top_sls = os.path.join(dyn_root_dir, "top.sls") with salt.utils.files.fopen(top_sls, "w") as fp_: fp_.write("{{saltenv}}:\n '*':\n - dynamo\n") dynamo_sls = os.path.join(dyn_root_dir, "dynamo.sls") with salt.utils.files.fopen(dynamo_sls, "w") as fp_: fp_.write("foo:\n test.nop\n") opts = {"file_roots": copy.copy(self.opts["file_roots"])} opts["file_roots"]["__env__"] = [dyn_root_dir] with patch.dict(roots.__opts__, opts): ret1 = roots.find_file("dynamo.sls", "dyn") ret2 = roots.file_list({"saltenv": "dyn"}) self.assertEqual("dynamo.sls", ret1["rel"]) self.assertIn("top.sls", ret2) self.assertIn("dynamo.sls", ret2)
def test_dynamic_file_roots(self): dyn_root_dir = tempfile.mkdtemp(dir=TMP) top_sls = os.path.join(dyn_root_dir, 'top.sls') with salt.utils.files.fopen(top_sls, 'w') as fp_: fp_.write("{{saltenv}}:\n '*':\n - dynamo\n") dynamo_sls = os.path.join(dyn_root_dir, 'dynamo.sls') with salt.utils.files.fopen(dynamo_sls, 'w') as fp_: fp_.write("foo:\n test.nop\n") opts = {'file_roots': copy.copy(self.opts['file_roots'])} opts['file_roots']['__env__'] = [dyn_root_dir] with patch.dict(roots.__opts__, opts): ret1 = roots.find_file('dynamo.sls', 'dyn') ret2 = roots.file_list({'saltenv': 'dyn'}) self.assertEqual('dynamo.sls', ret1['rel']) self.assertIn('top.sls', ret2) self.assertIn('dynamo.sls', ret2)
def test_find_file(self): with patch.dict( roots.__opts__, { "file_roots": self.master_opts["file_roots"], "fileserver_ignoresymlinks": False, "fileserver_followsymlinks": False, "file_ignore_regex": False, "file_ignore_glob": False, }, ): ret = roots.find_file("testfile") self.assertEqual("testfile", ret["rel"]) full_path_to_file = os.path.join(integration.FILES, "file", "base", "testfile") self.assertEqual(full_path_to_file, ret["path"])
def test_fileserver_roots_find_file_envs_path_substitution( env, temp_salt_minion, tmp_path ): """ Test fileserver access to a dynamic path using __env__ """ fn = "test.txt" opts = temp_salt_minion.config.copy() if env == "__env__": # __env__ saltenv will pass "dynamic" as saltenv and # expect to be routed to the "dynamic" directory actual_env = "dynamic" leaf_dir = actual_env else: # any other saltenv will pass saltenv normally and # expect to be routed to a static "__env__" directory actual_env = env leaf_dir = "__env__" envpath = tmp_path / leaf_dir envpath.mkdir(parents=True, exist_ok=True) filepath = envpath / fn filepath.touch() # Stop using OrderedDict once we drop Py3.5 support expected = OrderedDict() expected["rel"] = fn expected["path"] = str(filepath) # Stop using OrderedDict once we drop Py3.5 support opts["file_roots"] = OrderedDict() opts["file_roots"][env] = [str(tmp_path / leaf_dir)] with patch("salt.fileserver.roots.__opts__", opts, create=True): ret = roots.find_file(fn, saltenv=actual_env) ret.pop("stat") assert ret == expected
def test_find_file(self): ret = roots.find_file('testfile') self.assertEqual('testfile', ret['rel']) full_path_to_file = os.path.join(BASE_FILES, 'testfile') self.assertEqual(full_path_to_file, ret['path'])
def test_find_file(self): ret = roots.find_file("testfile") self.assertEqual("testfile", ret["rel"]) full_path_to_file = str(self.tmp_state_tree / "testfile") self.assertEqual(full_path_to_file, ret["path"])
def test_find_file(self): ret = roots.find_file("testfile") self.assertEqual("testfile", ret["rel"]) full_path_to_file = os.path.join(RUNTIME_VARS.BASE_FILES, "testfile") self.assertEqual(full_path_to_file, ret["path"])