def test_airflow_config_default(self):
     with env_vars(AIRFLOW_CONFIG=None):
         self.assertEqual(
             configuration.get_airflow_config('/home/airflow'),
             configuration.expand_env_var('/home/airflow/airflow.cfg'))
 def test_airflow_config_override(self):
     with env_vars(AIRFLOW_CONFIG='/path/to/airflow/airflow.cfg'):
         self.assertEqual(
             configuration.get_airflow_config('/home//airflow'),
             '/path/to/airflow/airflow.cfg')
Esempio n. 3
0
 def test_airflow_config_override(self):
     with unittest.mock.patch.dict(
             'os.environ', AIRFLOW_CONFIG='/path/to/airflow/airflow.cfg'):
         self.assertEqual(get_airflow_config('/home//airflow'),
                          '/path/to/airflow/airflow.cfg')
Esempio n. 4
0
 def test_airflow_config_default(self):
     with unittest.mock.patch.dict('os.environ'):
         if 'AIRFLOW_CONFIG' in os.environ:
             del os.environ['AIRFLOW_CONFIG']
         self.assertEqual(get_airflow_config('/home/airflow'),
                          expand_env_var('/home/airflow/airflow.cfg'))
 def test_airflow_config_override(self):
     with env_vars(AIRFLOW_CONFIG='/path/to/airflow/airflow.cfg'):
         self.assertEqual(
             configuration.get_airflow_config('/home//airflow'),
             '/path/to/airflow/airflow.cfg')
 def test_airflow_config_default(self):
     with env_vars(AIRFLOW_CONFIG=None):
         self.assertEqual(
             configuration.get_airflow_config('/home/airflow'),
             configuration.expand_env_var('/home/airflow/airflow.cfg'))
Esempio n. 7
0
def create_airflow_rest_connection():

    from airflow.contrib.auth.backends.password_auth import PasswordUser
    import base64
    import os

    session = settings.Session()
    exists = session.query(models.User).filter(models.User.username == 'application').scalar()

    if exists is None:

        LoggingMixin().log.info("creating 'application' user for mini-BRS...")

        # create 'application' user

        random_key = str(base64.urlsafe_b64encode(os.urandom(32)))
        user = PasswordUser(models.User())
        user.username = '******'
        user.email = '*****@*****.**'
        user.password = random_key
        session.add(user)
        session.commit()
        session.close()

        # create 'application' airflow connection
        rest = Connection(
            conn_id='rest',
            login='******',
            password=random_key
        )

        session = settings.Session()
        session.add(rest)
        session.commit()
        session.close()

        # create 'admin' user
        # admin_password = str(base64.urlsafe_b64encode(os.urandom(32)))

        config_parser = configuration.AirflowConfigParser()

        config_parser.read(
            configuration.get_airflow_config(
                        configuration.get_airflow_home()
                    )
        )

        u = config_parser.get(
            section='core',
            key='username'
        )

        p = config_parser.get(
            section='core',
            key='password'
        )

        user = PasswordUser(models.User())
        user.username = u
        user.email = '*****@*****.**'
        user.password = p
        user.superuser = True
        session = settings.Session()
        session.add(user)
        session.commit()
        session.close()

        config_parser.remove_option(
            section='core',
            option='username'
        )

        config_parser.remove_option(
            section='core',
            option='password'
        )

        file = open(configuration.get_airflow_config(configuration.get_airflow_home()), 'w')

        config_parser.write(file)

        file.close()