Beispiel #1
0
    def test_load_config_file(self, c_addoptionfile, config_home_ini, config_env):
        """Test loading configuration file."""

        config_env.return_value = None
        config_home_ini.return_value = None
        genie_config = GenieConf()
        genie_config.load_config_file(self.config_file)
        c_addoptionfile.assert_called_once_with(self.config_file)
Beispiel #2
0
    def test_load_config_file(self, c_addoptionfile, config_home_ini,
                              config_env):
        """Test loading configuration file."""

        config_env.return_value = None
        config_home_ini.return_value = None
        genie_config = GenieConf()
        genie_config.load_config_file(self.config_file)
        c_addoptionfile.assert_called_once_with(self.config_file)
Beispiel #3
0
    def test_username_config_file(self, config_home_ini, config_env):
        """Test configuration getting user specified from configuration file."""

        config_env.return_value = None
        config_home_ini.return_value = None
        os.environ['USER'] = '******'
        os.environ['genie_username'] = '******'
        genie_conf = GenieConf()
        genie_conf.load_config_file(self.config_file)
        assert_equals(genie_conf.genie.username, 'user_ini')
Beispiel #4
0
    def test_username_config_file(self, config_home_ini, config_env):
        """Test configuration getting user specified from configuration file."""

        config_env.return_value = None
        config_home_ini.return_value = None
        os.environ['USER'] = '******'
        os.environ['genie_username'] = '******'
        genie_conf = GenieConf()
        genie_conf.load_config_file(self.config_file)
        assert_equals(genie_conf.genie.username, 'user_ini')
Beispiel #5
0
    def test_session_adapters(self, config_home_ini, config_env):
        """Test configuration to_dict()."""

        config_env.return_value = None
        config_home_ini.return_value = None
        genie_conf = GenieConf()
        genie_conf.load_config_file(self.config_file)
        genie_conf.add_session_adapter('https://', {})
        self.assertEqual(genie_conf.session_adapters, {'https://': {}})

        assert_equals(
            genie_conf.to_dict(), {
                u'genie': {
                    u'url': u'http://foo:8080',
                    u'username': u'user_ini',
                    u'version': u'3'
                },
                'test_genie': {
                    u'from_env': u'from_ini_1',
                    u'from_cmd_line': u'from_ini_2',
                    u'from_ini': u'from_ini_3'
                }
            })
        genie_conf.remove_session_adapter('https://')
        self.assertEqual(genie_conf.session_adapters, {})
Beispiel #6
0
    def test_username_command_line(self, config_home_ini, config_env):
        """Test configuration getting user specified from command line."""

        with patch.object(sys, 'argv', ['--config', 'genie.username=user_cmdline_1']):
            config_env.return_value = None
            config_home_ini.return_value = None
            os.environ['USER'] = '******'
            os.environ['genie_username'] = '******'
            genie_conf = GenieConf()
            genie_conf.load_config_file(self.config_file)
            assert_equals(genie_conf.genie.username, 'user_cmdline_1')
Beispiel #7
0
    def test_username_command_line(self, config_home_ini, config_env):
        """Test configuration getting user specified from command line."""

        with patch.object(sys, 'argv',
                          ['--config', 'genie.username=user_cmdline_1']):
            config_env.return_value = None
            config_home_ini.return_value = None
            os.environ['USER'] = '******'
            os.environ['genie_username'] = '******'
            genie_conf = GenieConf()
            genie_conf.load_config_file(self.config_file)
            assert_equals(genie_conf.genie.username, 'user_cmdline_1')
Beispiel #8
0
    def test_username_os_user(self, config_home_ini, config_env):
        """Test configuration getting user specified from os user (USER environment variable)."""

        config_env.return_value = None
        config_home_ini.return_value = None
        os.environ['USER'] = '******'
        genie_conf = GenieConf()
        assert_equals(genie_conf.genie.username, 'os_user_env_4')
Beispiel #9
0
    def test_load_config_file_order_homedir(self, load_config_file,
                                            config_home_ini, config_env):
        """Test loading configuration file order with home directory."""

        config_env.return_value = None
        config_home_ini.return_value = self.config_file
        GenieConf()
        load_config_file.assert_called_once_with(self.config_file)
Beispiel #10
0
    def test_disable_adapter_timeout_conf(self):
        """Test Genie 3 adapter disable_adapter_timeout values."""

        for value in {'True', 'true', 'TRUE', True, '1', 1}:
            conf = GenieConf()
            conf.genie.set('disable_adapter_timeout', value)
            adapter = Genie3Adapter(conf=conf)
            assert_equals(True, adapter.disable_timeout)
Beispiel #11
0
    def test_load_config_file_order_multiple_config(self, load_config_file,
                                                    config_home_ini,
                                                    config_env):
        """Test loading configuration file order when specified in environment and from home directory. Only the environment config file should be loaded."""

        config_env.return_value = '/from/env/genie.ini'
        config_home_ini.return_value = '/from/home/genie.ini'
        GenieConf()
        load_config_file.assert_called_once_with('/from/env/genie.ini')
Beispiel #12
0
    def test_load_config_file_order_env(self, load_config_file,
                                        config_home_ini, config_env):
        """Test loading configuration file order with specified in environment variable."""

        C.initialize()
        config_env.return_value = self.config_file
        config_home_ini.return_value = None
        GenieConf()
        load_config_file.assert_called_once_with(self.config_file)
Beispiel #13
0
    def test_username_environment_variable(self, config_home_ini, config_env):
        """Test configuration getting user specified from GENIE_USERNAME environment variable."""

        config_env.return_value = None
        config_home_ini.return_value = None
        os.environ['USER'] = '******'
        os.environ['genie_username'] = '******'
        genie_conf = GenieConf()
        assert_equals(genie_conf.genie.username, 'genie_user_env_3')
Beispiel #14
0
    def test_to_dict(self, config_home_ini, config_env):
        """Test configuration to_dict()."""

        config_env.return_value = None
        config_home_ini.return_value = None
        genie_conf = GenieConf()
        genie_conf.load_config_file(self.config_file)
        assert_equals(
            genie_conf.to_dict(), {
                u'genie': {
                    u'url': u'http://foo:8080',
                    u'username': u'user_ini',
                    u'version': u'3'
                },
                'test_genie': {
                    u'from_env': u'from_ini_1',
                    u'from_cmd_line': u'from_ini_2',
                    u'from_ini': u'from_ini_3'
                }
            })
Beispiel #15
0
    def test_to_dict(self, config_home_ini, config_env):
        """Test configuration to_dict()."""

        config_env.return_value = None
        config_home_ini.return_value = None
        genie_conf = GenieConf()
        genie_conf.load_config_file(self.config_file)
        assert_equals(
            genie_conf.to_dict(),
            {
                u'genie': {
                    u'url': u'http://foo:8080',
                    u'username': u'user_ini',
                    u'version': u'3'
                },
                'test_genie': {
                    u'from_env': u'from_ini_1',
                    u'from_cmd_line': u'from_ini_2',
                    u'from_ini': u'from_ini_3'
                }
            }
        )
import logging

import yaml
from pygenie.client import Genie
from pygenie.conf import GenieConf

logging.basicConfig(level=logging.WARNING)

LOGGER = logging.getLogger(__name__)

def load_yaml(yaml_file):
    with open(yaml_file) as _file:
        return yaml.load(_file)

genie_conf = GenieConf()
genie_conf.genie.url = "http://genie:8080"

genie = Genie(genie_conf)

hadoop_application = load_yaml("applications/hadoop271.yml")
hadoop_application_id = genie.create_application(hadoop_application)
LOGGER.warn("Created Hadoop 2.7.1 application with id = [%s]" % hadoop_application_id)

spark_163_application = load_yaml("applications/spark163.yml")
spark_163_application_id = genie.create_application(spark_163_application)
LOGGER.warn("Created Spark 1.6.3 application with id = [%s]" % spark_163_application_id)

spark_201_application = load_yaml("applications/spark201.yml")
spark_201_application_id = genie.create_application(spark_201_application)
LOGGER.warn("Created Spark 2.0.1 application with id = [%s]" % spark_201_application_id)
Beispiel #17
0
 def setUp(self):
     conf = GenieConf()
     conf.genie.set('disable_adapter_timeout', 'True')
     self.adapter = Genie3Adapter(conf=conf)
Beispiel #18
0
import types
import unittest

import json
import os
import re
import responses

from mock import patch
from nose.tools import assert_equals
from pygenie.client import Genie
from pygenie.conf import GenieConf

GENIE_INI = os.path.join(os.path.dirname(os.path.realpath(__file__)),
                         'genie.ini')
GENIE_CONF = GenieConf().load_config_file(GENIE_INI)
GENIE_URL = GENIE_CONF.genie.url


# Used to generate basic responses from genie
@patch.dict('os.environ', {'GENIE_BYPASS_HOME_CONFIG': '1'})
class TestGenie(unittest.TestCase):
    """Test related to the bdp EMR library"""
    def setUp(self):
        self.genie = Genie(GENIE_CONF)
        self.cluster_name = 'test'
        self.path = re.compile(GENIE_URL + '/api/v3/.*')

    def test_properties(self):
        "Testing that relative paths exists as methods"
        assert self.genie.path_application