def _cleanup(session=None):
     if session is None:
         session = Session()
     session.query(Pool).filter(Pool.pool != Pool.DEFAULT_POOL_NAME).delete()
     session.commit()
     add_default_pool_if_not_exists()
     session.close()
Beispiel #2
0
    def setUp(self):
        if not os.path.isfile(
                '/.dockerenv') or os.environ.get('APT_DEPS_IMAGE') is None:
            raise unittest.SkipTest(
                """Adding/removing a user as part of a test is very bad for host os
(especially if the user already existed to begin with on the OS), therefore we check if we run inside a
the official docker container and only allow to run the test there. This is done by checking /.dockerenv
file (always present inside container) and checking for APT_DEPS_IMAGE variable.
""")
        self.grant_permissions()
        add_default_pool_if_not_exists()
        self.dagbag = models.DagBag(
            dag_folder=TEST_DAG_FOLDER,
            include_examples=False,
        )
        logger.info('Loaded DAGS:')
        logger.info(self.dagbag.dagbag_report())

        try:
            subprocess.check_output(
                ['sudo', 'useradd', '-m', TEST_USER, '-g',
                 str(os.getegid())])
        except OSError as e:
            if e.errno == errno.ENOENT:
                raise unittest.SkipTest(
                    "The 'useradd' command did not exist so unable to test "
                    "impersonation; Skipping Test. These tests can only be run on a "
                    "linux host that supports 'useradd'.")
            else:
                raise unittest.SkipTest(
                    "The 'useradd' command exited non-zero; Skipping tests. Does the "
                    "current user have permission to run 'useradd' without a password "
                    "prompt (check sudoers file)?")
Beispiel #3
0
    def setUp(self):
        check_original_docker_image()
        grant_permissions()
        add_default_pool_if_not_exists()
        self.dagbag = models.DagBag(
            dag_folder=TEST_DAG_CORRUPTED_FOLDER,
            include_examples=False,
        )
        logger.info('Loaded DAGS:')
        logger.info(self.dagbag.dagbag_report())

        create_user()
Beispiel #4
0
    def setUp(self):
        add_default_pool_if_not_exists()
        self.dagbag = models.DagBag(
            dag_folder=TEST_DAG_FOLDER,
            include_examples=False,
        )
        logger.info('Loaded DAGS:')
        logger.info(self.dagbag.dagbag_report())

        try:
            subprocess.check_output(
                ['sudo', 'useradd', '-m', TEST_USER, '-g',
                 str(os.getegid())])
        except OSError as e:
            if e.errno == errno.ENOENT:
                raise unittest.SkipTest(
                    "The 'useradd' command did not exist so unable to test "
                    "impersonation; Skipping Test. These tests can only be run on a "
                    "linux host that supports 'useradd'.")
            else:
                raise unittest.SkipTest(
                    "The 'useradd' command exited non-zero; Skipping tests. Does the "
                    "current user have permission to run 'useradd' without a password "
                    "prompt (check sudoers file)?")
Beispiel #5
0
def clear_db_pools():
    with create_session() as session:
        session.query(Pool).delete()
        add_default_pool_if_not_exists(session)
Beispiel #6
0
 def setUp(self):
     check_original_docker_image()
     grant_permissions()
     add_default_pool_if_not_exists()
     create_user()