Example #1
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
Example #2
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
Example #3
0
    def test_exit_status_correct_usage(self):
        """
        Ensure correct exit status when salt-call starts correctly.
        """

        call = testprogram.TestProgramSaltCall(
            name="correct_usage", parent_dir=self._test_dir,
        )
        # Call setup here to ensure config and script exist
        call.setup()
        stdout, stderr, status = call.run(
            args=["--local", "test.true"], catch_stderr=True, with_retcode=True,
        )
        self.assert_exit_status(
            status, "EX_OK", message="correct usage", stdout=stdout, stderr=stderr
        )
Example #4
0
    def test_exit_status_correct_usage(self):
        '''
        Ensure correct exit status when salt-call starts correctly.
        '''

        call = testprogram.TestProgramSaltCall(
            name='correct_usage',
            parent_dir=self._test_dir,
        )
        # Call setup here to ensure config and script exist
        call.setup()
        stdout, stderr, status = call.run(
            args=['--local', 'test.true'],
            catch_stderr=True,
            with_retcode=True,
        )
        self.assert_exit_status(status,
                                'EX_OK',
                                message='correct usage',
                                stdout=stdout,
                                stderr=stderr)
Example #5
0
    def test_exit_status_unknown_argument(self):
        '''
        Ensure correct exit status when an unknown argument is passed to salt-call.
        '''

        call = testprogram.TestProgramSaltCall(
            name='unknown_argument',
            parent_dir=self._test_dir,
        )
        # Call setup here to ensure config and script exist
        call.setup()
        stdout, stderr, status = call.run(
            args=['--unknown-argument'],
            catch_stderr=True,
            with_retcode=True,
        )
        self.assert_exit_status(status,
                                'EX_USAGE',
                                message='unknown argument',
                                stdout=stdout,
                                stderr=stderr)