示例#1
0
def test_rhd_should_pass_data_file_to_hooks(hooks_dir, env_dump, mkstemp_path,
                                            var_name, hook_type):
    hooks._runHooksDir(None, hooks_dir.basename, hookType=hook_type)
    with open(env_dump, "rb") as f:
        env = pickle.load(f)

    assert env[var_name] == mkstemp_path
示例#2
0
def test_rhd_should_assemble_environment_for_hooks(hooks_dir, env_dump, vmconf,
                                                   params, expected):
    hooks._runHooksDir(u"", hooks_dir.basename, vmconf, params=params)
    with open(env_dump, "rb") as f:
        env = pickle.load(f)

    for k, v in expected.items():
        assert env[k] == v
示例#3
0
    def test_deviceVmConfProperties(self):
        with self._deviceCustomPropertiesTestFile() as dirName:
            vmconf = {'custom': {'customProperty': ' rocks more!'}}

            result = hooks._runHooksDir("oVirt",
                                        dirName,
                                        params={'customProperty': ' rocks!'},
                                        vmconf=vmconf)
            self.assertEqual(result, "oVirt rocks more!")
示例#4
0
文件: hooks_test.py 项目: nirs/vdsm
    def test_deviceVmConfProperties(self):
        with self._deviceCustomPropertiesTestFile() as dirName:
            vmconf = {
                'custom': {
                    'customProperty': ' rocks more!'}}

            result = hooks._runHooksDir("oVirt", dirName,
                                        params={'customProperty': ' rocks!'},
                                        vmconf=vmconf)
            self.assertEqual(result, "oVirt rocks more!")
示例#5
0
文件: hooks_test.py 项目: nirs/vdsm
    def test_runHooksDir(self):
        # Add an unicode value to the environment variables
        # to test whether the utf-8 recoding works properly
        os.environ["FAKE_GERRIT_USERNAME"] = "******"

        with self.tempScripts() as (dirName, scripts):
            Q = 3
            DOMXML = "algo"
            expectedResult = DOMXML
            for n in range(Q):
                expectedResult = expectedResult + str(n)
            res = hooks._runHooksDir(DOMXML, dirName)
            self.assertEqual(expectedResult, res)
示例#6
0
    def test_runHooksDir(self):
        # Add an unicode value to the environment variables
        # to test whether the utf-8 recoding works properly
        os.environ["FAKE_GERRIT_USERNAME"] = "******"

        with self.tempScripts() as (dirName, scripts):
            Q = 3
            DOMXML = "algo"
            expectedResult = DOMXML
            for n in range(Q):
                expectedResult = expectedResult + str(n)
            res = hooks._runHooksDir(DOMXML, dirName)
            self.assertEqual(expectedResult, res)
示例#7
0
 def test_deviceCustomProperties(self):
     with self._deviceCustomPropertiesTestFile() as dirName:
         result = hooks._runHooksDir("oVirt",
                                     dirName,
                                     params={'customProperty': ' rocks!'})
         self.assertEqual(result, "oVirt rocks!")
示例#8
0
def test_rhd_should_raise_hook_errors(hooks_dir, error):
    with pytest.raises(exception.HookError) as e:
        hooks._runHooksDir(u"", hooks_dir.basename)

    for err in error:
        assert err in str(e.value)
示例#9
0
文件: hooks_test.py 项目: nirs/vdsm
 def test_emptyDir(self):
     with namedTemporaryDir() as dirName:
         DOMXML = "algo"
         self.assertEqual(DOMXML, hooks._runHooksDir(DOMXML, dirName))
示例#10
0
def test_rhd_should_make_import_hooking_possible(hooks_dir, hooking_client):
    hooks._runHooksDir(u"", hooks_dir.basename)
示例#11
0
def test_rhd_should_report_hook_stderr(caplog, hooks_dir):
    caplog.set_level(logging.INFO)
    hooks._runHooksDir(u"", hooks_dir.basename)

    assert "1.sh" in "".join(msg for _, lvl, msg in caplog.record_tuples
                             if lvl == logging.INFO)
示例#12
0
def test_rhd_should_return_unmodified_data_when_no_hooks(hooks_dir):
    assert hooks._runHooksDir(u"algo", hooks_dir.basename) == u"algo"
示例#13
0
def test_rhd_should_report_invalid_hook_error_codes(caplog, hooks_dir):
    hooks._runHooksDir(u"", hooks_dir.basename, raiseError=False)

    assert "111" in "".join(msg for (_, lvl, msg) in caplog.record_tuples
                            if lvl == logging.WARNING)
示例#14
0
def test_rhd_should_handle_json_data(dummy_hook, hooks_dir, data, expected):
    result = hooks._runHooksDir(data,
                                hooks_dir.basename,
                                hookType=hooks._JSON_HOOK)
    assert result == expected
示例#15
0
 def test_emptyDir(self):
     with namedTemporaryDir() as dirName:
         DOMXML = "algo"
         self.assertEqual(DOMXML, hooks._runHooksDir(DOMXML, dirName))
示例#16
0
def test_rhd_should_run_hooks_in_order(hooks_dir):
    assert hooks._runHooksDir(u"", hooks_dir.basename) == u"1.sh\n2.sh\n3.sh\n"
示例#17
0
def test_rhd_should_run_a_hook(hooks_dir):
    assert hooks._runHooksDir(u"123", hooks_dir.basename) == u"123myhook.sh\n"
示例#18
0
def test_rhd_should_handle_hook_errors(hooks_dir, expected):
    assert hooks._runHooksDir(u"", hooks_dir.basename, raiseError=False) == \
        expected
示例#19
0
文件: hooks_test.py 项目: nirs/vdsm
 def test_deviceCustomProperties(self):
     with self._deviceCustomPropertiesTestFile() as dirName:
         result = hooks._runHooksDir("oVirt", dirName,
                                     params={'customProperty': ' rocks!'})
         self.assertEqual(result, "oVirt rocks!")