Esempio n. 1
0
    def test_stop_celery(self):
        """
        tests that stop_celery runs the correct command and writes to log
        """
        install_django_app = InstallDjangoApp(
            self.dist_version, self.log_file, self.log_level,
            venv=self.venv, git_repo=self.git_repo, celery_pid=self.celery_pid_path
        )
        cmd = [
            os.path.join(self.venv, 'bin', 'python'),
            '-m',
            'celery',
            'multi',
            'stopwait',
            'w1',
            '--pidfile=%s' % os.path.join(self.celery_pid_path, 'w1.pid'),
        ]
        cwd = os.path.join(self.app_home, self.app_name)
        msg = 'stopped celery and beat'
        func = 'stop_celery'
        args = (self.app_home,)

        # when celery is running
        os.makedirs(self.celery_pid_path, exist_ok=True)
        with open(os.path.join(self.celery_pid_path, 'w1.pid'), 'w') as pid:
            pid.write('celery pid')
        self.run_success([cmd], [msg], func, install_django_app.stop_celery, args)
        self.run_cwd(cwd, func, install_django_app.stop_celery, args)

        # when celery is not running
        if os.path.exists(os.path.join(self.celery_pid_path, 'w1.pid')):
            os.remove(os.path.join(self.celery_pid_path, 'w1.pid'))
        install_django_app.stop_celery(*args)
        self.log('INFO: did not stop celery, was not running')