Пример #1
0
def testEmptyPostScript():
    reload(userchoices)
    
    def emptyPostBinSh(argv):
        assert 0, "there is no post-script, so we should not get here"
    fauxroot.EXEC_FUNCTIONS['/bin/sh'] = emptyPostBinSh

    context = applychoices.Context(applychoices.ProgressCallback())
    script.hostActionPostScript(context)

    del fauxroot.EXEC_FUNCTIONS['/bin/sh']
Пример #2
0
def testEmptyPostScript():
    reload(userchoices)

    def emptyPostBinSh(argv):
        assert 0, "there is no post-script, so we should not get here"

    fauxroot.EXEC_FUNCTIONS['/bin/sh'] = emptyPostBinSh

    context = applychoices.Context(applychoices.ProgressCallback())
    script.hostActionPostScript(context)

    del fauxroot.EXEC_FUNCTIONS['/bin/sh']
Пример #3
0
def testPostScript():
    reload(userchoices)

    # Setup our fake '/bin/sh' executable that just checks its args.
    def postBinSh(argv):
        assert argv[0] == '/bin/sh'
        assert argv[1] == '/tmp/ks-script'
        postBinSh.ran = True
        
        return 0
    postBinSh.ran = False
    fauxroot.EXEC_FUNCTIONS['/bin/sh'] = postBinSh

    # setup a temporary directory for testing
    tmproot = tempfile.mkdtemp(suffix='test_script')
    try:
        os.makedirs(os.path.join(tmproot, 'mnt/sysimage', 'tmp'))
        os.chroot(tmproot)

        # set a script to run.
        userchoices.addPostScript(script.Script(
            '''#! /bin/sh

            echo Hello, World!
            ''',
            '/bin/sh',
            True,
            0,
            False))
        context = applychoices.Context(applychoices.ProgressCallback())
        script.hostActionPostScript(context)
        assert postBinSh.ran, "the post script was not run?!"

        assert not os.path.exists(os.path.join(
            'mnt/sysimage', 'tmp', 'ks-script')), \
            "post script was not generated?"
    finally:
        fauxroot.FAUXROOT = None # clear out our fake chroot

        os.removedirs(os.path.join(tmproot, 'mnt/sysimage', 'tmp'))
        
        del fauxroot.EXEC_FUNCTIONS['/bin/sh']
Пример #4
0
def testPostScript():
    reload(userchoices)

    # Setup our fake '/bin/sh' executable that just checks its args.
    def postBinSh(argv):
        assert argv[0] == '/bin/sh'
        assert argv[1] == '/tmp/ks-script'
        postBinSh.ran = True

        return 0

    postBinSh.ran = False
    fauxroot.EXEC_FUNCTIONS['/bin/sh'] = postBinSh

    # setup a temporary directory for testing
    tmproot = tempfile.mkdtemp(suffix='test_script')
    try:
        os.makedirs(os.path.join(tmproot, 'mnt/sysimage', 'tmp'))
        os.chroot(tmproot)

        # set a script to run.
        userchoices.addPostScript(
            script.Script(
                '''#! /bin/sh

            echo Hello, World!
            ''', '/bin/sh', True, 0, False))
        context = applychoices.Context(applychoices.ProgressCallback())
        script.hostActionPostScript(context)
        assert postBinSh.ran, "the post script was not run?!"

        assert not os.path.exists(os.path.join(
            'mnt/sysimage', 'tmp', 'ks-script')), \
            "post script was not generated?"
    finally:
        fauxroot.FAUXROOT = None  # clear out our fake chroot

        os.removedirs(os.path.join(tmproot, 'mnt/sysimage', 'tmp'))

        del fauxroot.EXEC_FUNCTIONS['/bin/sh']