Example #1
0
    def test_prepare_custom_script(self):
        """
        This test is designed to verify the behavior based on the presence of
        custom script. Mainly needed for scenario where a custom script is
        expected, but was not properly copied. "CustomScriptNotFound" exception
        is raised in such cases.
        """
        # Custom script does not exist.
        preCust = PreCustomScript("random-vmw-test", self.tmpDir)
        self.assertEqual("random-vmw-test", preCust.scriptname)
        self.assertEqual(self.tmpDir, preCust.directory)
        self.assertEqual(self.tmp_path("random-vmw-test", self.tmpDir),
                         preCust.scriptpath)
        with self.assertRaises(CustomScriptNotFound):
            preCust.prepare_script()

        # Custom script exists.
        custScript = self.tmp_path("test-cust", self.tmpDir)
        util.write_file(custScript, "test-CR-strip/r/r")
        postCust = PostCustomScript("test-cust", self.tmpDir)
        self.assertEqual("test-cust", postCust.scriptname)
        self.assertEqual(self.tmpDir, postCust.directory)
        self.assertEqual(custScript, postCust.scriptpath)
        self.assertFalse(postCust.postreboot)
        postCust.prepare_script()
        # Check if all carraige returns are stripped from script.
        self.assertFalse("/r" in custScript)
Example #2
0
    def test_prepare_custom_script(self):
        """
        This test is designed to verify the behavior based on the presence of
        custom script. Mainly needed for scenario where a custom script is
        expected, but was not properly copied. "CustomScriptNotFound" exception
        is raised in such cases.
        """
        # Custom script does not exist.
        preCust = PreCustomScript("random-vmw-test", self.tmpDir)
        self.assertEqual("random-vmw-test", preCust.scriptname)
        self.assertEqual(self.tmpDir, preCust.directory)
        self.assertEqual(self.tmp_path("random-vmw-test", self.tmpDir),
                         preCust.scriptpath)
        with self.assertRaises(CustomScriptNotFound):
            preCust.prepare_script()

        # Custom script exists.
        custScript = self.tmp_path("test-cust", self.tmpDir)
        util.write_file(custScript, "test-CR-strip\r\r")
        with mock.patch.object(CustomScriptConstant,
                               "CUSTOM_TMP_DIR",
                               self.execDir):
            with mock.patch.object(CustomScriptConstant,
                                   "CUSTOM_SCRIPT",
                                   self.execScript):
                postCust = PostCustomScript("test-cust",
                                            self.tmpDir,
                                            self.tmpDir)
                self.assertEqual("test-cust", postCust.scriptname)
                self.assertEqual(self.tmpDir, postCust.directory)
                self.assertEqual(custScript, postCust.scriptpath)
                postCust.prepare_script()

                # Custom script is copied with exec privilege
                self.assertTrue(os.path.exists(self.execScript))
                st = os.stat(self.execScript)
                self.assertTrue(st.st_mode & stat.S_IEXEC)
                with open(self.execScript, "r") as f:
                    content = f.read()
                self.assertEqual(content, "test-CR-strip")
                # Check if all carraige returns are stripped from script.
                self.assertFalse("\r" in content)