def test_unresolved_jinja_variable_fails(self):

        with open(self.configs_dir + '/roger_push_unresolved_jinja.json') as config:
            config = json.load(config)
        with open(self.configs_dir + '/roger-mesos-tools.config') as roger:
            roger_env = yaml.load(roger)
        data = config['apps']['container-vars']
        self.config = config
        self.roger_env = roger_env
        self.data = data

        settings = mock(Settings)
        appConfig = mock(AppConfig)
        roger_push = RogerPush()
        roger_push.utils = mock(Utils)
        marathon = mock(Marathon)
        mockedHooks = mock(Hooks)
        when(mockedHooks).run_hook(any(), any(), any(), any()).thenReturn(0)
        roger_env = self.roger_env
        config = self.config
        data = self.data

        sc = mock(StatsClient)
        when(sc).timing(any(), any()).thenReturn(any())
        when(roger_push.utils).getStatsClient().thenReturn(sc)
        when(roger_push.utils).get_identifier(any(), any(), any()).thenReturn(any())
        when(roger_push.utils).extract_app_name(any()).thenReturn("test")
        when(roger_push.utils).get_version().thenReturn(any())

        frameworkUtils = mock(FrameworkUtils)
        when(frameworkUtils).getFramework(data).thenReturn(marathon)
        when(marathon).getName().thenReturn('Marathon')
        when(settings).getComponentsDir().thenReturn(
            self.base_dir + "/tests/components")
        when(settings).getSecretsDir().thenReturn(
            self.base_dir + "/tests/secrets")
        when(settings).getTemplatesDir().thenReturn(
            self.base_dir + "/tests/templates")
        when(settings).getConfigDir().thenReturn(self.configs_dir)
        when(settings).getCliDir().thenReturn(self.base_dir)
        when(settings).getUser().thenReturn(any())
        when(appConfig).getRogerEnv(self.configs_dir).thenReturn(roger_env)
        when(appConfig).getConfig(self.configs_dir,
                                  "roger_push_unresolved_jinja.json").thenReturn(config)
        when(appConfig).getAppData(self.configs_dir,
                                   "roger_push_unresolved_jinja.json", "container-vars").thenReturn(data)

        args = self.args
        args.env = "dev"
        args.skip_push = False
        args.force_push = False
        args.secrets_dir = ""
        args.secrets_file = ""
        args.app_name = 'container-vars'
        args.config_file = 'roger_push_unresolved_jinja.json'
        args.directory = self.base_dir + '/tests/testrepo'
        args.image_name = 'tests/v0.1.0'
        args.verbose = False
        roger_push.main(settings, appConfig, frameworkUtils, mockedHooks, args)
        verify(frameworkUtils, times=0).put(any(), any(), any(), any())
示例#2
0
    def test_unresolved_jinja_variable_fails(self):

        with open(self.configs_dir + '/roger_push_unresolved_jinja.json') as config:
            config = json.load(config)
        with open(self.configs_dir + '/roger-mesos-tools.config') as roger:
            roger_env = yaml.load(roger)
        data = config['apps']['container-vars']
        self.config = config
        self.roger_env = roger_env
        self.data = data

        settings = mock(Settings)
        appConfig = mock(AppConfig)
        roger_push = RogerPush()
        roger_push.utils = mock(Utils)
        marathon = mock(Marathon)
        mockedHooks = mock(Hooks)
        when(mockedHooks).run_hook(any(), any(), any(), any(), any(), any()).thenReturn(0)
        roger_env = self.roger_env
        config = self.config
        data = self.data

        when(roger_push.utils).get_identifier(any(), any(), any()).thenReturn(any())
        when(roger_push.utils).extract_app_name(any()).thenReturn("test")
        when(roger_push.utils).get_version().thenReturn(any())

        frameworkUtils = mock(FrameworkUtils)
        when(frameworkUtils).getFramework(data).thenReturn(marathon)
        when(marathon).getName().thenReturn('Marathon')
        when(settings).getComponentsDir().thenReturn(
            self.base_dir + "/tests/components")
        when(settings).getSecretsDir().thenReturn(
            self.base_dir + "/tests/secrets")
        when(settings).getTemplatesDir().thenReturn(
            self.base_dir + "/tests/templates")
        when(settings).getConfigDir().thenReturn(self.configs_dir)
        when(settings).getCliDir().thenReturn(self.base_dir)
        when(settings).getUser().thenReturn(any())
        when(appConfig).getRogerEnv(self.configs_dir).thenReturn(roger_env)
        when(appConfig).getConfig(self.configs_dir,
                                  "roger_push_unresolved_jinja.json").thenReturn(config)
        when(appConfig).getAppData(self.configs_dir,
                                   "roger_push_unresolved_jinja.json", "container-vars").thenReturn(data)

        args = self.args
        args.env = "dev"
        args.skip_push = False
        args.force_push = False
        args.secrets_dir = ""
        args.secrets_file = ""
        args.app_name = 'container-vars'
        args.config_file = 'roger_push_unresolved_jinja.json'
        args.directory = self.base_dir + '/tests/testrepo'
        args.image_name = 'tests/v0.1.0'
        args.verbose = False
        roger_push.main(settings, appConfig, frameworkUtils, mockedHooks, args)
        verify(frameworkUtils, times=0).put(any(), any(), any(), any())
    def test_push_fails_with_validation_error(self):
        settings = mock(Settings)
        appConfig = mock(AppConfig)
        roger_push = RogerPush()
        roger_push.utils = mock(Utils)
        marathon = mock(Marathon)
        mockedHooks = mock(Hooks)
        roger_env = self.roger_env
        config = self.config
        data = self.data

        sc = mock(StatsClient)
        when(sc).timing(any(), any()).thenReturn(any())
        when(roger_push.utils).getStatsClient().thenReturn(sc)
        when(roger_push.utils).get_identifier(any(), any(), any()).thenReturn(any())
        when(roger_push.utils).extract_app_name(any()).thenReturn("test")
        when(roger_push.utils).modify_task_id(any()).thenReturn([any()])
        when(roger_push.utils).get_version().thenReturn(any())

        frameworkUtils = mock(FrameworkUtils)
        when(frameworkUtils).getFramework(data).thenReturn(marathon)
        when(marathon).getName().thenReturn('Marathon')
        when(marathon).put(any(), any(), any(),
                           any(), any()).thenReturn(["Response [200]", any()])
        when(marathon).runDeploymentChecks(any(), any()).thenReturn(True)
        when(settings).getComponentsDir().thenReturn(
            self.base_dir + "/tests/components")
        when(settings).getSecretsDir().thenReturn(
            self.base_dir + "/tests/secrets")
        when(settings).getTemplatesDir().thenReturn(
            self.base_dir + "/tests/templates")
        when(settings).getConfigDir().thenReturn(self.configs_dir)
        when(settings).getCliDir().thenReturn(self.base_dir)
        when(settings).getUser().thenReturn(any())
        when(mockedHooks).run_hook(any(), any(), any(), any()).thenReturn(0)
        when(appConfig).getRogerEnv(self.configs_dir).thenReturn(roger_env)
        when(appConfig).getConfig(any(), any()).thenReturn(config)
        when(appConfig).getAppData(any(), any(), any()).thenReturn(data)

        args = self.args
        args.env = "dev"
        args.secrets_file = ""
        args.skip_push = False
        args.force_push = False
        args.app_name = 'grafana_test_app'
        args.config_file = 'test.json'
        args.directory = self.base_dir + '/tests/testrepo'
        args.image_name = 'grafana/grafana:2.1.3'
        args.verbose = False
        raised_exception = False
        try:
            return_code = roger_push.main(settings, appConfig, frameworkUtils, mockedHooks, args)
        except (Exception) as e:
            raised_exception = True
        self.assertFalse(raised_exception)
        verify(frameworkUtils, times=0).put(any(), any(), any(), any())
示例#4
0
    def test_roger_push_grafana_test_app(self):
        settings = mock(Settings)
        appConfig = mock(AppConfig)
        roger_push = RogerPush()
        roger_push.utils = mock(Utils)
        marathon = mock(Marathon)
        mockedHooks = mock(Hooks)
        when(mockedHooks).run_hook(any(), any(), any(), any()).thenReturn(0)
        roger_env = self.roger_env
        config = self.config
        data = self.data
        sc = mock(StatsClient)

        when(sc).timing(any(), any()).thenReturn(any())
        when(roger_push.utils).getStatsClient().thenReturn(sc)
        when(roger_push.utils).get_identifier(any(), any(),
                                              any()).thenReturn(any())
        when(roger_push.utils).extract_app_name(any()).thenReturn("test")
        when(marathon).put(any(), any(),
                           any()).thenReturn("Response [200]", any())
        frameworkUtils = mock(FrameworkUtils)
        when(frameworkUtils).getFramework(data).thenReturn(marathon)
        when(marathon).getName().thenReturn('Marathon')
        when(settings).getComponentsDir().thenReturn(self.base_dir +
                                                     "/tests/components")
        when(settings).getSecretsDir().thenReturn(self.base_dir +
                                                  "/tests/secrets")
        when(settings).getTemplatesDir().thenReturn(self.base_dir +
                                                    "/tests/templates")
        when(settings).getConfigDir().thenReturn(self.configs_dir)
        when(settings).getCliDir().thenReturn(self.base_dir)
        when(settings).getUser().thenReturn(any())
        when(appConfig).getRogerEnv(any()).thenReturn(roger_env)
        when(appConfig).getConfig(any(), any()).thenReturn(config)
        when(appConfig).getAppData(any(), any(), any()).thenReturn(data)

        args = self.args
        args.env = "dev"
        args.secrets_file = ""
        args.skip_push = True
        args.app_name = 'grafana_test_app'
        args.config_file = 'test.json'
        args.directory = self.base_dir + '/tests/testrepo'
        args.image_name = 'grafana/grafana:2.1.3'
        roger_push.main(settings, appConfig, frameworkUtils, mockedHooks, args)
        with open(self.base_dir +
                  '/tests/templates/test-app-grafana.json') as output:
            output = json.load(output)
        assert output['container']['docker'][
            'image'] == "grafana/grafana:2.1.3"
        verify(settings).getConfigDir()
        verify(settings).getComponentsDir()
        verify(settings).getTemplatesDir()
        verify(settings).getSecretsDir()
        verify(frameworkUtils).getFramework(data)
示例#5
0
    def test_push_fails_with_validation_error(self):
        settings = mock(Settings)
        appConfig = mock(AppConfig)
        roger_push = RogerPush()
        roger_push.utils = mock(Utils)
        marathon = mock(Marathon)
        mockedHooks = mock(Hooks)
        roger_env = self.roger_env
        config = self.config
        data = self.data

        sc = mock(StatsClient)
        when(sc).timing(any(), any()).thenReturn(any())
        when(roger_push.utils).getStatsClient().thenReturn(sc)
        when(roger_push.utils).get_identifier(any(), any(),
                                              any()).thenReturn(any())
        when(roger_push.utils).extract_app_name(any()).thenReturn("test")
        when(roger_push.utils).modify_task_id(any()).thenReturn([any()])
        when(roger_push.utils).get_version().thenReturn(any())

        frameworkUtils = mock(FrameworkUtils)
        when(frameworkUtils).getFramework(data).thenReturn(marathon)
        when(marathon).getName().thenReturn('Marathon')
        when(marathon).put(any(), any(), any(), any(),
                           any()).thenReturn(["Response [200]",
                                              any()])
        when(marathon).runDeploymentChecks(any(), any()).thenReturn(True)
        when(settings).getComponentsDir().thenReturn(self.base_dir +
                                                     "/tests/components")
        when(settings).getSecretsDir().thenReturn(self.base_dir +
                                                  "/tests/secrets")
        when(settings).getTemplatesDir().thenReturn(self.base_dir +
                                                    "/tests/templates")
        when(settings).getConfigDir().thenReturn(self.configs_dir)
        when(settings).getCliDir().thenReturn(self.base_dir)
        when(settings).getUser().thenReturn(any())
        when(mockedHooks).run_hook(any(), any(), any(), any()).thenReturn(0)
        when(appConfig).getRogerEnv(self.configs_dir).thenReturn(roger_env)
        when(appConfig).getConfig(any(), any()).thenReturn(config)
        when(appConfig).getAppData(any(), any(), any()).thenReturn(data)

        args = self.args
        args.env = "dev"
        args.secrets_file = ""
        args.skip_push = False
        args.force_push = False
        args.app_name = 'grafana_test_app'
        args.config_file = 'test.json'
        args.directory = self.base_dir + '/tests/testrepo'
        args.image_name = 'grafana/grafana:2.1.3'
        return_code = roger_push.main(settings, appConfig, frameworkUtils,
                                      mockedHooks, args)
        verify(frameworkUtils, times=0).put(any(), any(), any(), any())
    def test_roger_push_with_correct_container_name(self):
        settings = mock(Settings)
        appConfig = mock(AppConfig)
        roger_push = RogerPush()
        roger_push.utils = mock(Utils)
        marathon = mock(Marathon)
        mockedHooks = mock(Hooks)
        frameworkUtils = mock(FrameworkUtils)
        roger_env = self.roger_env
        appdata = self.data
        config = self.config
        sc = mock(StatsClient)
        when(sc).timing(any(), any()).thenReturn(any())
        when(roger_push.utils).getStatsClient().thenReturn(sc)
        when(roger_push.utils).get_identifier(any(), any(), any()).thenReturn(any())
        when(roger_push.utils).extract_app_name(any()).thenReturn("test")
        when(frameworkUtils).getFramework(any()).thenReturn(marathon)
        when(marathon).getName().thenReturn('Marathon')
        when(settings).getComponentsDir().thenReturn(
            self.base_dir + "/tests/components")
        when(settings).getSecretsDir().thenReturn(
            self.base_dir + "/tests/secrets")
        when(settings).getTemplatesDir().thenReturn(
            self.base_dir + "/tests/templates")
        when(settings).getConfigDir().thenReturn(self.configs_dir)
        when(settings).getCliDir().thenReturn(self.base_dir)
        when(settings).getUser().thenReturn(any())
        when(appConfig).getRogerEnv(self.configs_dir).thenReturn(roger_env)
        when(mockedHooks).run_hook(any(), any(), any(), any()).thenReturn(0)
        when(appConfig).getRogerEnv(any()).thenReturn(roger_env)

        appdata["hooks"] = dict([("post_push", "some command")])
        when(appConfig).getAppData(any(), any(), any()).thenReturn(appdata)
        when(appConfig).getConfig(any(), any()).thenReturn(config)

        when(appConfig).getRogerEnv(self.configs_dir).thenReturn(roger_env)
        when(appConfig).getConfig(any(), any()).thenReturn(config)

        args = self.args
        args.env = "dev"
        args.secrets_file = ""
        args.skip_push = True
        args.app_name = 'grafana_test_app:grafana'
        args.config_file = 'test.json'
        args.image_name = 'grafana/grafana:2.1.3'
        args.verbose = False
        raised_exception = False
        try:
            roger_push.main(settings, appConfig, frameworkUtils, mockedHooks, args)
        except (Exception) as e:
            raised_exception = True
        self.assertFalse(raised_exception)
        verify(frameworkUtils).getFramework(any())
    def test_roger_push_grafana_test_app(self):
        settings = mock(Settings)
        appConfig = mock(AppConfig)
        roger_push = RogerPush()
        roger_push.utils = mock(Utils)
        marathon = mock(Marathon)
        mockedHooks = mock(Hooks)
        when(mockedHooks).run_hook(any(), any(), any(), any()).thenReturn(0)
        roger_env = self.roger_env
        config = self.config
        data = self.data
        sc = mock(StatsClient)

        when(sc).timing(any(), any()).thenReturn(any())
        when(roger_push.utils).getStatsClient().thenReturn(sc)
        when(roger_push.utils).get_identifier(any(), any(), any()).thenReturn(any())
        when(roger_push.utils).extract_app_name(any()).thenReturn("test")
        when(marathon).put(any(), any(), any()).thenReturn("Response [200]", any())
        frameworkUtils = mock(FrameworkUtils)
        when(frameworkUtils).getFramework(data).thenReturn(marathon)
        when(marathon).getName().thenReturn('Marathon')
        when(settings).getComponentsDir().thenReturn(
            self.base_dir + "/tests/components")
        when(settings).getSecretsDir().thenReturn(
            self.base_dir + "/tests/secrets")
        when(settings).getTemplatesDir().thenReturn(
            self.base_dir + "/tests/templates")
        when(settings).getConfigDir().thenReturn(self.configs_dir)
        when(settings).getCliDir().thenReturn(self.base_dir)
        when(settings).getUser().thenReturn(any())
        when(appConfig).getRogerEnv(any()).thenReturn(roger_env)
        when(appConfig).getConfig(any(), any()).thenReturn(config)
        when(appConfig).getAppData(any(), any(), any()).thenReturn(data)

        args = self.args
        args.env = "dev"
        args.secrets_file = ""
        args.skip_push = True
        args.app_name = 'grafana_test_app'
        args.config_file = 'test.json'
        args.directory = self.base_dir + '/tests/testrepo'
        args.image_name = 'grafana/grafana:2.1.3'
        args.verbose = False
        roger_push.main(settings, appConfig, frameworkUtils, mockedHooks, args)
        with open(self.base_dir + '/tests/templates/test-app-grafana.json') as output:
            output = json.load(output)
        assert output['container']['docker'][
            'image'] == "grafana/grafana:2.1.3"
        verify(settings).getConfigDir()
        verify(settings).getComponentsDir()
        verify(settings).getTemplatesDir()
        verify(settings).getSecretsDir()
        verify(frameworkUtils).getFramework(data)
示例#8
0
    def test_roger_push_with_correct_container_name(self):
        settings = mock(Settings)
        appConfig = mock(AppConfig)
        roger_push = RogerPush()
        roger_push.utils = mock(Utils)
        marathon = mock(Marathon)
        mockedHooks = mock(Hooks)
        frameworkUtils = mock(FrameworkUtils)
        roger_env = self.roger_env
        appdata = self.data
        config = self.config

        when(roger_push.utils).get_identifier(any(), any(), any()).thenReturn(any())
        when(roger_push.utils).extract_app_name(any()).thenReturn("test")
        when(frameworkUtils).getFramework(any()).thenReturn(marathon)
        when(marathon).getName().thenReturn('Marathon')
        when(settings).getComponentsDir().thenReturn(
            self.base_dir + "/tests/components")
        when(settings).getSecretsDir().thenReturn(
            self.base_dir + "/tests/secrets")
        when(settings).getTemplatesDir().thenReturn(
            self.base_dir + "/tests/templates")
        when(settings).getConfigDir().thenReturn(self.configs_dir)
        when(settings).getCliDir().thenReturn(self.base_dir)
        when(settings).getUser().thenReturn(any())
        when(appConfig).getRogerEnv(self.configs_dir).thenReturn(roger_env)
        when(mockedHooks).run_hook(any(), any(), any(), any(), any(), any()).thenReturn(0)
        when(appConfig).getRogerEnv(any()).thenReturn(roger_env)

        appdata["hooks"] = dict([("post_push", "some command")])
        when(appConfig).getAppData(any(), any(), any()).thenReturn(appdata)
        when(appConfig).getConfig(any(), any()).thenReturn(config)

        when(appConfig).getRogerEnv(self.configs_dir).thenReturn(roger_env)
        when(appConfig).getConfig(any(), any()).thenReturn(config)

        args = self.args
        args.env = "dev"
        args.secrets_file = ""
        args.skip_push = True
        args.app_name = 'grafana_test_app:grafana'
        args.config_file = 'test.json'
        args.image_name = 'grafana/grafana:2.1.3'
        args.verbose = False
        raised_exception = False
        try:
            roger_push.main(settings, appConfig, frameworkUtils, mockedHooks, args)
        except (Exception) as e:
            raised_exception = True
        self.assertFalse(raised_exception)
        verify(frameworkUtils).getFramework(any())
示例#9
0
    def test_roger_push_secrets_replaced(self):
        settings = mock(Settings)
        appConfig = mock(AppConfig)
        roger_push = RogerPush()
        roger_push.utils = mock(Utils)
        marathon = mock(Marathon)
        mockedHooks = mock(Hooks)
        roger_env = self.roger_env
        config = self.config
        data = self.data

        sc = mock(StatsClient)
        when(sc).timing(any(), any()).thenReturn(any())
        when(roger_push.utils).getStatsClient().thenReturn(sc)
        when(roger_push.utils).get_identifier(any(), any(),
                                              any()).thenReturn(any())
        when(roger_push.utils).extract_app_name(any()).thenReturn("test")

        when(marathon).put(any(), any(), any()).thenReturn("Response [200]")
        frameworkUtils = mock(FrameworkUtils)
        when(frameworkUtils).getFramework(data).thenReturn(marathon)
        when(marathon).getName().thenReturn('Marathon')
        when(settings).getComponentsDir().thenReturn(self.base_dir +
                                                     "/tests/components")
        when(settings).getSecretsDir().thenReturn(self.base_dir +
                                                  "/tests/secrets")
        when(settings).getTemplatesDir().thenReturn(self.base_dir +
                                                    "/tests/templates")
        when(settings).getConfigDir().thenReturn(self.configs_dir)
        when(settings).getCliDir().thenReturn(self.base_dir)
        when(settings).getUser().thenReturn(any())
        when(appConfig).getRogerEnv(any()).thenReturn(roger_env)
        when(appConfig).getConfig(any(), any()).thenReturn(config)
        when(appConfig).getAppData(any(), any(), any()).thenReturn(data)
        when(mockedHooks).run_hook(any(), any(), any(), any()).thenReturn(0)

        args = self.args
        args.env = "dev"
        args.secrets_file = ""
        args.skip_push = True
        args.app_name = 'grafana_test_app'
        args.config_file = 'test.json'
        args.directory = self.base_dir + '/tests/testrepo'
        args.image_name = 'grafana/grafana:2.1.3'
        exit_code = roger_push.main(settings, appConfig, frameworkUtils,
                                    mockedHooks, args)
        file_path = ("{0}/{1}/{2}".format(self.components_dir, args.env,
                                          args.config_file))
        assert (os.path.isfile(file_path) is not True)
    def test_roger_push_secrets_replaced(self):
        settings = mock(Settings)
        appConfig = mock(AppConfig)
        roger_push = RogerPush()
        roger_push.utils = mock(Utils)
        marathon = mock(Marathon)
        mockedHooks = mock(Hooks)
        roger_env = self.roger_env
        config = self.config
        data = self.data

        sc = mock(StatsClient)
        when(sc).timing(any(), any()).thenReturn(any())
        when(roger_push.utils).getStatsClient().thenReturn(sc)
        when(roger_push.utils).get_identifier(any(), any(), any()).thenReturn(any())
        when(roger_push.utils).extract_app_name(any()).thenReturn("test")

        when(marathon).put(any(), any(), any()).thenReturn("Response [200]")
        frameworkUtils = mock(FrameworkUtils)
        when(frameworkUtils).getFramework(data).thenReturn(marathon)
        when(marathon).getName().thenReturn('Marathon')
        when(settings).getComponentsDir().thenReturn(
            self.base_dir + "/tests/components")
        when(settings).getSecretsDir().thenReturn(
            self.base_dir + "/tests/secrets")
        when(settings).getTemplatesDir().thenReturn(
            self.base_dir + "/tests/templates")
        when(settings).getConfigDir().thenReturn(self.configs_dir)
        when(settings).getCliDir().thenReturn(self.base_dir)
        when(settings).getUser().thenReturn(any())
        when(appConfig).getRogerEnv(any()).thenReturn(roger_env)
        when(appConfig).getConfig(any(), any()).thenReturn(config)
        when(appConfig).getAppData(any(), any(), any()).thenReturn(data)
        when(mockedHooks).run_hook(any(), any(), any(), any()).thenReturn(0)

        args = self.args
        args.env = "dev"
        args.secrets_file = ""
        args.skip_push = True
        args.app_name = 'grafana_test_app'
        args.config_file = 'test.json'
        args.directory = self.base_dir + '/tests/testrepo'
        args.image_name = 'grafana/grafana:2.1.3'
        args.verbose = False
        exit_code = roger_push.main(
            settings, appConfig, frameworkUtils, mockedHooks, args)
        file_path = ("{0}/{1}/{2}".format(self.components_dir,
                                          args.env, args.config_file))
        assert (os.path.isfile(file_path) is not True)
示例#11
0
    def test_roger_push_calls_postpush_hook_when_present(self):
        settings = mock(Settings)
        appConfig = mock(AppConfig)
        roger_push = RogerPush()
        roger_push.utils = mock(Utils)
        marathon = mock(Marathon)
        mockedHooks = mock(Hooks)
        frameworkUtils = mock(FrameworkUtils)
        roger_env = self.roger_env
        appdata = self.data
        config = self.config

        sc = mock(StatsClient)
        when(sc).timing(any(), any()).thenReturn(any())
        when(roger_push.utils).getStatsClient().thenReturn(sc)
        when(roger_push.utils).get_identifier(any(), any(),
                                              any()).thenReturn(any())
        when(roger_push.utils).extract_app_name(any()).thenReturn("test")

        when(frameworkUtils).getFramework(any()).thenReturn(marathon)
        when(marathon).getName().thenReturn('Marathon')
        when(settings).getComponentsDir().thenReturn(self.base_dir +
                                                     "/tests/components")
        when(settings).getSecretsDir().thenReturn(self.base_dir +
                                                  "/tests/secrets")
        when(settings).getTemplatesDir().thenReturn(self.base_dir +
                                                    "/tests/templates")
        when(settings).getConfigDir().thenReturn(self.configs_dir)
        when(settings).getCliDir().thenReturn(self.base_dir)
        when(settings).getUser().thenReturn(any())
        when(appConfig).getRogerEnv(self.configs_dir).thenReturn(roger_env)
        when(mockedHooks).run_hook(any(), any(), any(), any()).thenReturn(0)
        when(appConfig).getRogerEnv(any()).thenReturn(roger_env)

        appdata["hooks"] = dict([("post_push", "some command")])
        when(appConfig).getAppData(any(), any(), any()).thenReturn(appdata)
        when(appConfig).getConfig(any(), any()).thenReturn(config)
        args = self.args
        args.config_file = 'any.json'
        args.app_name = 'any app'
        args.env = 'dev'
        args.image_name = 'tests/v0.1.0'
        args.directory = '/tmp'
        args.secrets_file = ""
        args.skip_push = True
        return_code = roger_push.main(settings, appConfig, frameworkUtils,
                                      mockedHooks, args)
        verify(mockedHooks).run_hook("post_push", any(), any(), any())
示例#12
0
    def test_roger_push_with_no_app_fails(self):
        settings = mock(Settings)
        appConfig = mock(AppConfig)
        roger_push = RogerPush()
        roger_push.utils = mock(Utils)
        marathon = mock(Marathon)
        mockedHooks = mock(Hooks)
        when(mockedHooks).run_hook(any(), any(), any()).thenReturn(0)
        roger_env = self.roger_env
        config = self.config
        data = self.data
        sc = mock(StatsClient)

        when(sc).timing(any(), any()).thenReturn(any())
        when(roger_push.utils).getStatsClient().thenReturn(sc)
        when(roger_push.utils).get_identifier(any(), any(),
                                              any()).thenReturn(any())
        when(roger_push.utils).extract_app_name(any()).thenReturn("test")
        when(marathon).put(any(), any(), any()).thenReturn("Response [200]")
        frameworkUtils = mock(FrameworkUtils)
        when(frameworkUtils).getFramework(data).thenReturn(marathon)
        when(settings).getComponentsDir().thenReturn(self.base_dir +
                                                     "/tests/components")
        when(settings).getSecretsDir().thenReturn(self.base_dir +
                                                  "/tests/secrets")
        when(settings).getTemplatesDir().thenReturn(self.base_dir +
                                                    "/tests/templates")
        when(settings).getConfigDir().thenReturn(self.configs_dir)
        when(settings).getCliDir().thenReturn(self.base_dir)
        when(settings).getUser().thenReturn(any())
        when(appConfig).getRogerEnv(any()).thenReturn(roger_env)
        when(appConfig).getConfig(any(), any()).thenReturn(config)
        when(appConfig).getAppData(any(), any(), any()).thenReturn(data)

        args = self.args
        args.app_name = ''
        args.config_file = 'test.json'
        args.env = 'some_test_env'
        with self.assertRaises(ValueError):
            roger_push.main(settings, appConfig, frameworkUtils, mockedHooks,
                            args)
    def test_roger_push_with_no_app_fails(self):
        settings = mock(Settings)
        appConfig = mock(AppConfig)
        roger_push = RogerPush()
        roger_push.utils = mock(Utils)
        marathon = mock(Marathon)
        mockedHooks = mock(Hooks)
        when(mockedHooks).run_hook(any(), any(), any()).thenReturn(0)
        roger_env = self.roger_env
        config = self.config
        data = self.data
        sc = mock(StatsClient)

        when(sc).timing(any(), any()).thenReturn(any())
        when(roger_push.utils).getStatsClient().thenReturn(sc)
        when(roger_push.utils).get_identifier(any(), any(), any()).thenReturn(any())
        when(roger_push.utils).extract_app_name(any()).thenReturn("test")
        when(marathon).put(any(), any(), any()).thenReturn("Response [200]")
        frameworkUtils = mock(FrameworkUtils)
        when(frameworkUtils).getFramework(data).thenReturn(marathon)
        when(settings).getComponentsDir().thenReturn(
            self.base_dir + "/tests/components")
        when(settings).getSecretsDir().thenReturn(
            self.base_dir + "/tests/secrets")
        when(settings).getTemplatesDir().thenReturn(
            self.base_dir + "/tests/templates")
        when(settings).getConfigDir().thenReturn(self.configs_dir)
        when(settings).getCliDir().thenReturn(self.base_dir)
        when(settings).getUser().thenReturn(any())
        when(appConfig).getRogerEnv(any()).thenReturn(roger_env)
        when(appConfig).getConfig(any(), any()).thenReturn(config)
        when(appConfig).getAppData(any(), any(), any()).thenReturn(data)

        args = self.args
        args.app_name = ''
        args.config_file = 'test.json'
        args.env = 'some_test_env'
        with self.assertRaises(ValueError):
            roger_push.main(settings, appConfig,
                            frameworkUtils, mockedHooks, args)
示例#14
0
    def test_container_resolution(self):
        settings = mock(Settings)
        appConfig = mock(AppConfig)
        roger_push = RogerPush()
        roger_push.utils = mock(Utils)
        marathon = mock(Marathon)
        mockedHooks = mock(Hooks)
        when(mockedHooks).run_hook(any(), any(), any(), any(), any(), any()).thenReturn(0)
        roger_env = self.roger_env
        config = self.test_config
        data = self.test_data

        when(roger_push.utils).get_identifier(any(), any(), any()).thenReturn(any())
        when(roger_push.utils).extract_app_name(any()).thenReturn("test")
        when(marathon).getName().thenReturn('Marathon')
        when(marathon).put(any(), any(), any()).thenReturn("Response [200]")
        when(marathon).put(any(), any(), any()).thenReturn("Response [200]")
        when(marathon).put(any(), any(), any()).thenReturn("Response [200]")
        frameworkUtils = mock(FrameworkUtils)
        when(frameworkUtils).getFramework(data).thenReturn(marathon)
        when(settings).getComponentsDir().thenReturn(
            self.base_dir + "/tests/components")
        when(settings).getSecretsDir().thenReturn(
            self.base_dir + "/tests/secrets")
        when(settings).getTemplatesDir().thenReturn(
            self.base_dir + "/tests/templates")
        when(settings).getConfigDir().thenReturn(self.configs_dir)
        when(settings).getCliDir().thenReturn(self.base_dir)
        when(settings).getUser().thenReturn(any())
        when(appConfig).getRogerEnv(self.configs_dir).thenReturn(roger_env)
        when(appConfig).getConfig(any(), any()).thenReturn(config)
        when(appConfig).getAppData(any(), any(), any()).thenReturn(data)

        args = self.args
        args.env = "dev"
        args.secrets_file = ""
        args.skip_push = True
        args.app_name = 'grafana_test_app'
        args.directory = self.base_dir + '/tests/testrepo'
        args.config_file = 'test.json'
        args.image_name = 'grafana/grafana:2.1.3'
        args.verbose = False
        roger_push.main(settings, appConfig, frameworkUtils, mockedHooks, args)
        with open(self.base_dir + '/tests/templates/test-app-grafana.json') as output:
            output = json.load(output)
        assert output['container']['docker'][
            'image'] == "grafana/grafana:2.1.3"
        assert output['cpus'] == 2
        assert output['mem'] == 1024
        assert output['uris'] == ["abc", "xyz", "$ENV_VAR"]
        with open(self.base_dir + '/tests/templates/test-app-grafana1.json') as output:
            output = json.load(output)
        assert output['container']['docker'][
            'image'] == "grafana/grafana:2.1.3"
        assert output['cpus'] == 0.5
        assert output['mem'] == 512
        with open(self.base_dir + '/tests/templates/test-app-grafana2.json') as output:
            output = json.load(output)
        assert output['container']['docker'][
            'image'] == "grafana/grafana:2.1.3"
        assert output['cpus'] == 1
        assert output['mem'] == 1024
示例#15
0
    def test_vars_single_container(self):
        settings = mock(Settings)
        appConfig = mock(AppConfig)
        marathon = mock(Marathon)
        mockedHooks = mock(Hooks)
        roger_push = RogerPush()
        roger_push.utils = mock(Utils)
        when(mockedHooks).run_hook(any(), any(), any(), any(), any(), any()).thenReturn(0)
        roger_env = self.roger_env
        config = self.config
        data = self.data

        frameworkUtils = mock(FrameworkUtils)
        when(frameworkUtils).getFramework(data).thenReturn(marathon)
        when(marathon).getName().thenReturn('Marathon')
        when(settings).getComponentsDir().thenReturn(
            self.base_dir + "/tests/components")
        when(settings).getSecretsDir().thenReturn(
            self.base_dir + "/tests/secrets")
        when(settings).getTemplatesDir().thenReturn(
            self.base_dir + "/tests/templates")

        when(roger_push.utils).get_identifier(any(), any(), any()).thenReturn(any())
        when(roger_push.utils).extract_app_name(any()).thenReturn("test")
        when(settings).getConfigDir().thenReturn(self.configs_dir)
        when(settings).getCliDir().thenReturn(self.base_dir)
        when(settings).getUser().thenReturn(any())
        when(appConfig).getRogerEnv(self.configs_dir).thenReturn(roger_env)
        when(appConfig).getConfig(self.configs_dir,
                                  "roger_single_container_var_tests.json").thenReturn(config)

        when(appConfig).getAppData(self.configs_dir,
                                   "roger_single_container_var_tests.json", "container-vars").thenReturn(data)

        args = self.args
        args.env = "dev"
        args.skip_push = True
        args.secrets_dir = ""

        args.app_name = 'container-vars'
        args.config_file = 'roger_single_container_var_tests.json'
        args.directory = self.base_dir + '/tests/testrepo'
        args.image_name = 'tests/v0.1.0'
        args.secrets_file = 'test'
        args.verbose = False

        roger_push.main(settings, appConfig, frameworkUtils, mockedHooks, args)

        with open(self.base_dir + '/tests/components/dev/roger-single-container-var-tests.json') as output:
            output = json.load(output)

        var1 = output["env"]["VAR_1"]
        var3 = output["env"]["VAR_3"]
        var4 = output["env"]["VAR_4"]

        print ("Expected Value -> Var1 : environment_value_1")
        print ("Actual Value   : {}".format(var1))

        print ("Expected Value -> Var3 : value_3")
        print ("Actual Value   : {}".format(var3))

        assert var3 == "value_3"
        assert var1 == "environment_value_1"