def test_get_image(self):
        res = mock(requests.Response)
        url = 'https:/marathon-example.com/v2/apps/welcome'
        data = {'environments': {'dev': {
            'marathon_endpoint': 'https:/marathon-example.com'}}}
        image_data = {
            'app': {
            'container': {
            'docker': {
            'image': "registry.example.com:6000/0dajdhkfa8ecb64/v0.72.0"}}}}
        os.environ['ROGER_CONFIG_DIR'] = '/vagrant/config'
        username = '******'
        password = '******'
        config_dir = '/vagrant/config'
        config_file = 'test.yml'

        app_config_object = mock(AppConfig)
        when(app_config_object).getRogerEnv(config_dir).thenReturn(data)
        when(requests).get(url, auth=(username, password)).thenReturn(res)
        when(res).json().thenReturn(image_data)

        m = Marathon()
        img = m.get_image_name(
            username,
            password,
            'dev',
            'welcome',
            config_dir,
            config_file,
            app_config_object
        )
        assert img == image_data['app']['container']['docker']['image']
    def test_get_image(self):
        res = mock(requests.Response)
        url = 'https:/marathon-example.com/v2/apps/welcome'
        data = {
            'environments': {
                'dev': {
                    'marathon_endpoint': 'https:/marathon-example.com'
                }
            }
        }
        image_data = {
            'app': {
                'container': {
                    'docker': {
                        'image':
                        "registry.example.com:6000/0dajdhkfa8ecb64/v0.72.0"
                    }
                }
            }
        }
        os.environ['ROGER_CONFIG_DIR'] = '/vagrant/config'
        username = '******'
        password = '******'
        config_dir = '/vagrant/config'
        config_file = 'test.yml'

        app_config_object = mock(AppConfig)
        when(app_config_object).getRogerEnv(config_dir).thenReturn(data)
        when(requests).get(url, auth=(username, password)).thenReturn(res)
        when(res).json().thenReturn(image_data)

        m = Marathon()
        img = m.get_image_name(username, password, 'dev', 'welcome',
                               config_dir, config_file, app_config_object)
        assert img == image_data['app']['container']['docker']['image']
 def getFramework(self, data):
     if self.framework is not None:
         return self.framework
     else:
         if 'framework' in data:
             if data['framework'].lower() == "chronos":
                 return Chronos()
         return Marathon()
Beispiel #4
0
 def __init__(self,
              app_config=AppConfig(),
              settings=Settings(),
              framework_utils=FrameworkUtils(),
              framework=Marathon()):
     self._app_config = app_config
     self._settings = settings
     self._framework_utils = framework_utils
     self._framework = framework
     self._config_dir = None
     self._roger_env = None
     self._temp_dir = None
Beispiel #5
0
                        "Environment variable $ROGER_ENV is not set.Using the default set from roger-mesos-tools.config file"
                    )
                else:
                    print(
                        "Using value {} from environment variable $ROGER_ENV".
                        format(env_var))
                    environment = env_var
        else:
            environment = args.env

        if environment not in roger_env['environments']:
            raise ValueError(
                colored(
                    "Environment not found in roger-mesos-tools.config file.",
                    "red"))

        app_details = self.get_app_details(framework, proxyparser, environment,
                                           args, roger_env)
        self.print_app_details(app_details, args)


if __name__ == '__main__':
    settings = Settings()
    appconfig = AppConfig()
    framework = Marathon()
    proxyparser = ProxyParser()
    roger_ps = RogerPS()
    roger_ps.parser = roger_ps.parse_args()
    roger_ps.args = roger_ps.parser.parse_args()
    roger_ps.main(settings, appconfig, framework, proxyparser, roger_ps.args)
 def setUp(self):
     self.marathon = Marathon()
     self.appconfig = AppConfig()
class TestMarathon(unittest.TestCase):
    def setUp(self):
        self.marathon = Marathon()
        self.appconfig = AppConfig()

    def test_validateGroupDetails(self):
        group_details = {}
        message_list = []
        group_details['/test/app1'] = ('/http_prefix1', ['3000',
                                                         '3001'], False)
        group_details['/test/app2'] = ('/http_prefix2', ['9000',
                                                         '9001'], False)
        valid = self.marathon.validateGroupDetails(group_details, message_list)
        assert valid is True
        assert len(message_list) == 0
        message_list = []
        group_details['/test/app3'] = ('/http_prefix3', ['8000',
                                                         '9001'], False)
        valid = self.marathon.validateGroupDetails(group_details, message_list)
        assert valid is False
        assert len(message_list) == 1
        message_list = []
        group_details = {}
        group_details['/test/app3'] = ('/http_prefix3', ['8000',
                                                         '9001'], False)
        group_details['/test/app4'] = ('/http_prefix3', ['7000',
                                                         '7001'], False)
        valid = self.marathon.validateGroupDetails(group_details, message_list)
        assert valid is False
        assert len(message_list) == 1
        message_list = []
        group_details = {}
        # One of the conflicting apps have affinity = False, leads to a failed
        # validation for HTTP_PREFIX
        group_details['/test/app3'] = ('/http_prefix3', ['9000',
                                                         '9001'], False)
        group_details['/test/app5'] = ('/http_prefix3', ['8000', '8001'], True)
        valid = self.marathon.validateGroupDetails(group_details, message_list)
        assert valid is False
        assert len(message_list) == 1
        message_list = []
        group_details = {}
        group_details['/test/app3'] = ('/http_prefix3', ['9000', '9001'], True)
        group_details['/test/app5'] = ('/http_prefix3', ['8000', '8001'], True)
        valid = self.marathon.validateGroupDetails(group_details, message_list)
        assert valid is True
        assert len(message_list) == 1
        for message in message_list:
            print(message)

    @property
    def config_dir(self):
        os.environ['ROGER_CONFIG_DIR'] = '/vagrant/config'

    def test_get_image(self):
        res = mock(requests.Response)
        url = 'https:/marathon-example.com/v2/apps/welcome'
        data = {
            'environments': {
                'dev': {
                    'marathon_endpoint': 'https:/marathon-example.com'
                }
            }
        }
        image_data = {
            'app': {
                'container': {
                    'docker': {
                        'image':
                        "registry.example.com:6000/0dajdhkfa8ecb64/v0.72.0"
                    }
                }
            }
        }
        os.environ['ROGER_CONFIG_DIR'] = '/vagrant/config'
        username = '******'
        password = '******'
        config_dir = '/vagrant/config'
        config_file = 'test.yml'

        app_config_object = mock(AppConfig)
        when(app_config_object).getRogerEnv(config_dir).thenReturn(data)
        when(requests).get(url, auth=(username, password)).thenReturn(res)
        when(res).json().thenReturn(image_data)

        m = Marathon()
        img = m.get_image_name(username, password, 'dev', 'welcome',
                               config_dir, config_file, app_config_object)
        assert img == image_data['app']['container']['docker']['image']

    def tearDown(self):
        pass
 def setUp(self):
     self.marathon = Marathon()
     self.appconfig = AppConfig()
class TestMarathon(unittest.TestCase):

    def setUp(self):
        self.marathon = Marathon()
        self.appconfig = AppConfig()

    def test_validateGroupDetails(self):
        group_details = {}
        message_list = []
        group_details['/test/app1'] = ('/http_prefix1', ['3000', '3001'], False)
        group_details['/test/app2'] = ('/http_prefix2', ['9000', '9001'], False)
        valid = self.marathon.validateGroupDetails(group_details, message_list)
        assert valid is True
        assert len(message_list) == 0
        message_list = []
        group_details['/test/app3'] = ('/http_prefix3', ['8000', '9001'], False)
        valid = self.marathon.validateGroupDetails(group_details, message_list)
        assert valid is False
        assert len(message_list) == 1
        message_list = []
        group_details = {}
        group_details['/test/app3'] = ('/http_prefix3', ['8000', '9001'], False)
        group_details['/test/app4'] = ('/http_prefix3', ['7000', '7001'], False)
        valid = self.marathon.validateGroupDetails(group_details, message_list)
        assert valid is False
        assert len(message_list) == 1
        message_list = []
        group_details = {}
        # One of the conflicting apps have affinity = False, leads to a failed
        # validation for HTTP_PREFIX
        group_details['/test/app3'] = ('/http_prefix3', ['9000', '9001'], False)
        group_details['/test/app5'] = ('/http_prefix3', ['8000', '8001'], True)
        valid = self.marathon.validateGroupDetails(group_details, message_list)
        assert valid is False
        assert len(message_list) == 1
        message_list = []
        group_details = {}
        group_details['/test/app3'] = ('/http_prefix3', ['9000', '9001'], True)
        group_details['/test/app5'] = ('/http_prefix3', ['8000', '8001'], True)
        valid = self.marathon.validateGroupDetails(group_details, message_list)
        assert valid is True
        assert len(message_list) == 1
        for message in message_list:
            print(message)

    @property
    def config_dir(self):
        os.environ['ROGER_CONFIG_DIR'] = '/vagrant/config'

    def test_get_image(self):
        res = mock(requests.Response)
        url = 'https:/marathon-example.com/v2/apps/welcome'
        data = {'environments': {'dev': {
            'marathon_endpoint': 'https:/marathon-example.com'}}}
        image_data = {
            'app': {
            'container': {
            'docker': {
            'image': "registry.example.com:6000/0dajdhkfa8ecb64/v0.72.0"}}}}
        os.environ['ROGER_CONFIG_DIR'] = '/vagrant/config'
        username = '******'
        password = '******'
        config_dir = '/vagrant/config'
        config_file = 'test.yml'

        app_config_object = mock(AppConfig)
        when(app_config_object).getRogerEnv(config_dir).thenReturn(data)
        when(requests).get(url, auth=(username, password)).thenReturn(res)
        when(res).json().thenReturn(image_data)

        m = Marathon()
        img = m.get_image_name(
            username,
            password,
            'dev',
            'welcome',
            config_dir,
            config_file,
            app_config_object
        )
        assert img == image_data['app']['container']['docker']['image']

    def tearDown(self):
        pass