Exemple #1
0
    def test_exit_status_unknown_argument(self):
        '''
        Ensure correct exit status when an unknown argument is passed to salt-minion.
        '''

        minion = testprogram.TestDaemonSaltMinion(
            name='unknown_argument',
            parent_dir=self._test_dir,
        )
        # Call setup here to ensure config and script exist
        minion.setup()
        stdout, stderr, status = minion.run(
            args=['-d', '--unknown-argument'],
            catch_stderr=True,
            with_retcode=True,
        )
        try:
            self.assert_exit_status(
                status,
                'EX_USAGE',
                message='unknown argument',
                stdout=stdout,
                stderr=tests.integration.utils.decode_byte_list(stderr))
        finally:
            # Although the start-up should fail, call shutdown() to set the
            # internal _shutdown flag and avoid the registered atexit calls to
            # cause timeout exeptions and respective traceback
            minion.shutdown()
Exemple #2
0
    def test_exit_status_unknown_user(self):
        '''
        Ensure correct exit status when the minion is configured to run as an unknown user.
        '''

        minion = testprogram.TestDaemonSaltMinion(
            name='unknown_user',
            configs={'minion': {
                'map': {
                    'user': '******'
                }
            }},
            parent_dir=self._test_dir,
        )
        # Call setup here to ensure config and script exist
        minion.setup()
        stdout, stderr, status = minion.run(
            args=['-d'],
            catch_stderr=True,
            with_retcode=True,
        )
        try:
            self.assert_exit_status(
                status,
                'EX_NOUSER',
                message='unknown user not on system',
                stdout=stdout,
                stderr=tests.integration.utils.decode_byte_list(stderr))
        finally:
            # Although the start-up should fail, call shutdown() to set the
            # internal _shutdown flag and avoid the registered atexit calls to
            # cause timeout exeptions and respective traceback
            minion.shutdown()
Exemple #3
0
    def test_exit_status_unknown_user(self):
        """
        Ensure correct exit status when the minion is configured to run as an unknown user.

        Skipped on windows because daemonization not supported
        """

        minion = testprogram.TestDaemonSaltMinion(
            name="unknown_user",
            configs={"minion": {"map": {"user": "******"}}},
            parent_dir=self._test_dir,
        )
        # Call setup here to ensure config and script exist
        minion.setup()
        stdout, stderr, status = minion.run(
            args=["-d"], catch_stderr=True, with_retcode=True,
        )
        try:
            self.assert_exit_status(
                status,
                "EX_NOUSER",
                message="unknown user not on system",
                stdout=stdout,
                stderr=tests.integration.utils.decode_byte_list(stderr),
            )
        finally:
            # Although the start-up should fail, call shutdown() to set the
            # internal _shutdown flag and avoid the registered atexit calls to
            # cause timeout exceptions and respective traceback
            minion.shutdown()
Exemple #4
0
    def _initscript_setup(self, minions):
        """Re-usable setup for running salt-minion tests"""

        _minions = []
        for mname in minions:
            pid_file = "salt-{0}.pid".format(mname)
            minion = testprogram.TestDaemonSaltMinion(
                name=mname,
                root_dir="init_script",
                config_dir=os.path.join("etc", mname),
                parent_dir=self._test_dir,
                pid_file=pid_file,
                configs={
                    "minion": {
                        "map": {
                            "pidfile": os.path.join("var", "run", pid_file),
                            "sock_dir": os.path.join("var", "run", "salt", mname),
                            "log_file": os.path.join("var", "log", "salt", mname),
                        },
                    },
                },
            )
            # Call setup here to ensure config and script exist
            minion.setup()
            _minions.append(minion)

        # Need salt-call, salt-minion for wrapper script
        salt_call = testprogram.TestProgramSaltCall(
            root_dir="init_script", parent_dir=self._test_dir
        )
        # Ensure that run-time files are generated
        salt_call.setup()
        sysconf_dir = os.path.dirname(_minions[0].abs_path(_minions[0].config_dir))
        cmd_env = {
            "PATH": ":".join(
                [salt_call.abs_path(salt_call.script_dir), os.getenv("PATH")]
            ),
            "SALTMINION_DEBUG": "1" if DEBUG else "",
            "SALTMINION_PYTHON": sys.executable,
            "SALTMINION_SYSCONFDIR": sysconf_dir,
            "SALTMINION_BINDIR": _minions[0].abs_path(_minions[0].script_dir),
        }

        default_dir = os.path.join(sysconf_dir, "default")
        if not os.path.exists(default_dir):
            os.makedirs(default_dir)
        with salt.utils.files.fopen(os.path.join(default_dir, "salt"), "w") as defaults:
            # Test suites is quite slow - extend the timeout
            defaults.write("TIMEOUT=60\n" "TICK=1\n")

        init_script = testprogram.TestProgram(
            name="init:salt-minion",
            program=os.path.join(RUNTIME_VARS.CODE_DIR, "pkg", "rpm", "salt-minion"),
            env=cmd_env,
        )

        return _minions, salt_call, init_script
Exemple #5
0
    def _initscript_setup(self, minions):
        '''Re-usable setup for running salt-minion tests'''

        _minions = []
        for mname in minions:
            pid_file = 'salt-{0}.pid'.format(mname)
            minion = testprogram.TestDaemonSaltMinion(
                name=mname,
                root_dir='init_script',
                config_dir=os.path.join('etc', mname),
                parent_dir=self._test_dir,
                pid_file=pid_file,
                configs={
                    'minion': {
                        'map': {
                            'pidfile': os.path.join('var', 'run', pid_file),
                            'sock_dir': os.path.join('var', 'run', 'salt', mname),
                            'log_file': os.path.join('var', 'log', 'salt', mname),
                        },
                    },
                },
            )
            # Call setup here to ensure config and script exist
            minion.setup()
            _minions.append(minion)

        # Need salt-call, salt-minion for wrapper script
        salt_call = testprogram.TestProgramSaltCall(root_dir='init_script', parent_dir=self._test_dir)
        # Ensure that run-time files are generated
        salt_call.setup()
        sysconf_dir = os.path.dirname(_minions[0].abs_path(_minions[0].config_dir))
        cmd_env = {
            'PATH': ':'.join([salt_call.abs_path(salt_call.script_dir), os.getenv('PATH')]),
            'SALTMINION_DEBUG': '1' if DEBUG else '',
            'SALTMINION_PYTHON': sys.executable,
            'SALTMINION_SYSCONFDIR': sysconf_dir,
            'SALTMINION_BINDIR': _minions[0].abs_path(_minions[0].script_dir),
        }

        default_dir = os.path.join(sysconf_dir, 'default')
        if not os.path.exists(default_dir):
            os.makedirs(default_dir)
        with salt.utils.files.fopen(os.path.join(default_dir, 'salt'), 'w') as defaults:
            # Test suites is quite slow - extend the timeout
            defaults.write(
                'TIMEOUT=60\n'
                'TICK=1\n'
            )

        init_script = testprogram.TestProgram(
            name='init:salt-minion',
            program=os.path.join(RUNTIME_VARS.CODE_DIR, 'pkg', 'rpm', 'salt-minion'),
            env=cmd_env,
        )

        return _minions, salt_call, init_script
Exemple #6
0
    def test_exit_status_correct_usage(self):
        """
        Ensure correct exit status when salt-minion starts correctly.

        Skipped on windows because daemonization not supported
        """

        minion = testprogram.TestDaemonSaltMinion(
            name="correct_usage", parent_dir=self._test_dir,
        )
        # Call setup here to ensure config and script exist
        minion.setup()
        stdout, stderr, status = minion.run(
            args=["-d"], catch_stderr=True, with_retcode=True,
        )
        self.assert_exit_status(
            status, "EX_OK", message="correct usage", stdout=stdout, stderr=stderr
        )
        minion.shutdown(wait_for_orphans=3)
Exemple #7
0
    def test_exit_status_correct_usage(self):
        '''
        Ensure correct exit status when salt-minion starts correctly.
        '''

        minion = testprogram.TestDaemonSaltMinion(
            name='correct_usage',
            parent_dir=self._test_dir,
        )
        # Call setup here to ensure config and script exist
        minion.setup()
        stdout, stderr, status = minion.run(
            args=['-d'],
            catch_stderr=True,
            with_retcode=True,
        )
        self.assert_exit_status(status,
                                'EX_OK',
                                message='correct usage',
                                stdout=stdout,
                                stderr=stderr)
        minion.shutdown(wait_for_orphans=3)