Example #1
0
    def test_pack_alternatives_empty_dependencies(self):
        """
        test _pack_alternatives when dependencies is not
        set in the config.
        """
        ext_conf = copy.deepcopy(self.ext_conf)
        ext_conf["test"]["auto_detect"] = True
        ext_conf["test"].pop("dependencies")

        for lib in self.fake_libs.values():
            os.makedirs(lib)
            with salt.utils.files.fopen(os.path.join(lib, "__init__.py"), "w+") as fp_:
                fp_.write("test")

        patch_tops_py = patch(
            "salt.utils.thin.get_tops_python", return_value=self.fake_libs
        )

        exp_files = self.exp_files.copy()
        exp_files.extend(
            [
                os.path.join("yaml", "__init__.py"),
                os.path.join("tornado", "__init__.py"),
                os.path.join("msgpack", "__init__.py"),
            ]
        )
        with patch_tops_py:
            thin._pack_alternative(ext_conf, self.digest, self.tar)
            calls = self.tar.mock_calls
            for _file in exp_files:
                assert [x for x in calls if "{}".format(_file) in x.args]
Example #2
0
 def test_pack_alternatives_path_doesnot_exist(self):
     """
     test thin._pack_alternatives when the path
     doesnt exist. Check error log message
     and expect that because the directory
     does not exist jinja2 does not get
     added to the tar
     """
     bad_path = os.path.join(tempfile.gettempdir(), "doesnotexisthere")
     tops = copy.deepcopy(self.tops)
     tops["test"]["dependencies"] = [bad_path]
     with patch("salt.utils.thin.get_ext_tops", MagicMock(return_value=tops)):
         with TstSuiteLoggingHandler() as log_handler:
             thin._pack_alternative(self.ext_conf, self.digest, self.tar)
             msg = "ERROR:File path {} does not exist. Unable to add to salt-ssh thin".format(
                 bad_path
             )
             assert msg in log_handler.messages
     calls = self.tar.mock_calls
     for _file in self.exp_files:
         arg = [x for x in calls if "{}".format(_file) in x.args]
         kwargs = [
             x
             for x in calls
             if os.path.join("test", "pyall", _file) in x.kwargs["arcname"]
         ]
         if "jinja2" in _file:
             assert not arg
             assert not kwargs
         else:
             assert arg
             assert kwargs
Example #3
0
    def test_pack_alternatives_exclude(self):
        """
        test pack_alternatives when mixing
        manually set dependencies and auto
        detecting other modules.
        """
        patch_proc = patch(
            "salt.utils.thin.subprocess.Popen",
            self._popen(
                None,
                side_effect=[
                    (bts(self.fake_libs["distro"]), bts("")),
                    (bts(self.fake_libs["yaml"]), bts("")),
                    (bts(self.fake_libs["tornado"]), bts("")),
                    (bts(self.fake_libs["msgpack"]), bts("")),
                    (bts(""), bts("")),
                    (bts(""), bts("")),
                    (bts(""), bts("")),
                    (bts(""), bts("")),
                    (bts(""), bts("")),
                    (bts(""), bts("")),
                    (bts(""), bts("")),
                ],
            ),
        )

        patch_os = patch("os.path.exists", return_value=True)
        ext_conf = copy.deepcopy(self.ext_conf)
        ext_conf["test"]["auto_detect"] = True

        for lib in self.fake_libs.values():
            os.makedirs(lib)
            with salt.utils.files.fopen(os.path.join(lib, "__init__.py"), "w+") as fp_:
                fp_.write("test")

        exp_files = self.exp_files.copy()
        exp_files.extend(
            [
                os.path.join("yaml", "__init__.py"),
                os.path.join("tornado", "__init__.py"),
                os.path.join("msgpack", "__init__.py"),
            ]
        )

        patch_which = patch("salt.utils.path.which", return_value=True)

        with patch_os, patch_proc, patch_which:
            thin._pack_alternative(ext_conf, self.digest, self.tar)
            calls = self.tar.mock_calls
            for _file in exp_files:
                assert [x for x in calls if "{}".format(_file) in x.args]
Example #4
0
 def test_pack_alternatives(self):
     """
     test thin._pack_alternatives
     """
     with patch("salt.utils.thin.get_ext_tops", MagicMock(return_value=self.tops)):
         thin._pack_alternative(self.ext_conf, self.digest, self.tar)
         calls = self.tar.mock_calls
         for _file in self.exp_files:
             assert [x for x in calls if "{}".format(_file) in x.args]
             assert [
                 x
                 for x in calls
                 if os.path.join("test", "pyall", _file) in x.kwargs["arcname"]
             ]
Example #5
0
 def test_pack_alternatives_not_normalized(self):
     """
     test thin._pack_alternatives when the path
     is not normalized
     """
     tops = copy.deepcopy(self.tops)
     tops["test"]["dependencies"] = [self.jinja_fp + "/"]
     with patch("salt.utils.thin.get_ext_tops", MagicMock(return_value=tops)):
         thin._pack_alternative(self.ext_conf, self.digest, self.tar)
         calls = self.tar.mock_calls
         for _file in self.exp_files:
             assert [x for x in calls if "{}".format(_file) in x.args]
             assert [
                 x
                 for x in calls
                 if os.path.join("test", "pyall", _file) in x.kwargs["arcname"]
             ]