Пример #1
0
    def test_roger_deploy_with_no_registry_fails(self):
        settings = mock(Settings)
        appConfig = mock(AppConfig)
        roger_deploy = RogerDeploy()
        marathon = mock(Marathon)
        gitObj = mock(GitUtils)
        roger_deploy.rogerGitPullObject = mock(RogerGitPull)
        roger_deploy.rogerPushObject = mock(RogerPush)
        roger_deploy.rogerBuildObject = mock(RogerBuild)
        roger_deploy.dockerUtilsObject = mock(DockerUtils)
        roger_deploy.dockerObject = mock(Docker)
        roger_deploy.utils = mock(Utils)
        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_deploy.utils).getStatsClient().thenReturn(sc)
        when(roger_deploy.utils).get_identifier(any(), any(), any()).thenReturn(any())
        when(roger_deploy.utils).extract_app_name(any()).thenReturn("test")
        when(marathon).getCurrentImageVersion(
            any(), any(), any(), any()).thenReturn("testversion/v0.1.0")
        frameworkUtils = mock(FrameworkUtils)
        when(frameworkUtils).getFramework(data).thenReturn(marathon)
        when(settings).getConfigDir().thenReturn(any())
        when(settings).getCliDir().thenReturn(any())
        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.directory = ""
        args.secrets_file = ""
        args.environment = "dev"
        args.skip_push = False
        args.application = 'grafana_test_app'
        args.config_file = 'test.json'
        args.skip_build = True
        args.branch = None
        os.environ["ROGER_CONFIG_DIR"] = self.configs_dir

        roger_env = appConfig.getRogerEnv(self.configs_dir)
        del roger_env['registry']
        with self.assertRaises(ValueError):
            roger_deploy.main(settings, appConfig,
                              frameworkUtils, gitObj, mockedHooks, args)
Пример #2
0
    def test_incrementVersion(self):
        git_sha = "dwqjdqgwd7y12edq21"
        image_version_list = ['0.001', '0.2.034', '1.1.2', '1.002.1']
        roger_deploy = RogerDeploy()
        args = self.args
        args.directory = ""
        args.secrets_file = ""
        args.incr_patch = True
        args.incr_major = True

        assert roger_deploy.incrementVersion(
            git_sha, image_version_list, args) == 'dwqjdqgwd7y12edq21/v2.0.0'
        assert roger_deploy.incrementVersion(
            git_sha, image_version_list, args) == 'dwqjdqgwd7y12edq21/v2.0.0'
        assert roger_deploy.incrementVersion(
            git_sha, image_version_list, args) == 'dwqjdqgwd7y12edq21/v2.0.0'
Пример #3
0
    def test_incrementVersion(self):
        git_sha = "dwqjdqgwd7y12edq21"
        image_version_list = ['0.001', '0.2.034', '1.1.2', '1.002.1']
        roger_deploy = RogerDeploy()
        args = self.args
        args.directory = ""
        args.secrets_file = ""
        args.incr_patch = True
        args.incr_major = True

        assert roger_deploy.incrementVersion(
            git_sha, image_version_list, args) == 'dwqjdqgwd7y12edq21/v2.0.0'
        assert roger_deploy.incrementVersion(
            git_sha, image_version_list, args) == 'dwqjdqgwd7y12edq21/v2.0.0'
        assert roger_deploy.incrementVersion(
            git_sha, image_version_list, args) == 'dwqjdqgwd7y12edq21/v2.0.0'
Пример #4
0
 def test_tempDirCheck(self):
     work_dir = "./test_dir"
     roger_deploy = RogerDeploy()
     args = self.args
     args.directory = ""
     args.skip_push = False
     args.secrets_file = ""
     temp_dir_created = True
     roger_deploy.removeDirTree(work_dir, args, temp_dir_created)
     exists = os.path.exists(os.path.abspath(work_dir))
     assert exists is False
     os.makedirs(work_dir)
     exists = os.path.exists(os.path.abspath(work_dir))
     assert exists is True
     roger_deploy.removeDirTree(work_dir, args, temp_dir_created)
     exists = os.path.exists(os.path.abspath(work_dir))
     assert exists is False
    def test_roger_deploy_with_no_registry_fails(self):
        settings = mock(Settings)
        appConfig = mock(AppConfig)
        roger_deploy = RogerDeploy()
        marathon = mock(Marathon)
        gitObj = mock(GitUtils)
        roger_deploy.rogerGitPullObject = mock(RogerGitPull)
        roger_deploy.rogerPushObject = mock(RogerPush)
        roger_deploy.rogerBuildObject = mock(RogerBuild)
        roger_deploy.dockerUtilsObject = mock(DockerUtils)
        roger_deploy.dockerObject = mock(Docker)
        roger_deploy.utils = mock(Utils)
        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_deploy.utils).getStatsClient().thenReturn(sc)
        when(roger_deploy.utils).get_identifier(any(), any(), any()).thenReturn(any())
        when(roger_deploy.utils).extract_app_name(any()).thenReturn("test")
        when(marathon).getCurrentImageVersion(
            any(), any(), any(), any()).thenReturn("testversion/v0.1.0")
        frameworkUtils = mock(FrameworkUtils)
        when(frameworkUtils).getFramework(data).thenReturn(marathon)
        when(settings).getConfigDir().thenReturn(any())
        when(settings).getCliDir().thenReturn(any())
        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.directory = ""
        args.secrets_file = ""
        args.environment = "dev"
        args.skip_push = False
        args.application = 'grafana_test_app'
        args.config_file = 'test.json'
        args.skip_build = True
        args.branch = None
        os.environ["ROGER_CONFIG_DIR"] = self.configs_dir

        roger_env = appConfig.getRogerEnv(self.configs_dir)
        del roger_env['registry']
        with self.assertRaises(ValueError):
            roger_deploy.main(settings, appConfig,
                              frameworkUtils, gitObj, mockedHooks, args)
Пример #6
0
    def test_roger_deploy_with_no_app(self):
        try:
            raised_exception = False
            settings = mock(Settings)
            appConfig = mock(AppConfig)
            roger_deploy = RogerDeploy()
            marathon = mock(Marathon)
            gitObj = mock(GitUtils)
            mockedHooks = mock(Hooks)
            roger_deploy.rogerGitPullObject = mock(RogerGitPull)
            roger_deploy.rogerPushObject = mock(RogerPush)
            roger_deploy.rogerBuildObject = mock(RogerBuild)
            roger_deploy.dockerUtilsObject = mock(DockerUtils)
            roger_deploy.dockerObject = mock(Docker)
            roger_deploy.utils = mock(Utils)
            roger_env = self.roger_env
            config = self.config
            data = self.data

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

            when(marathon).getCurrentImageVersion(
                any(), any(), any()).thenReturn("testversion/v0.1.0")
            frameworkUtils = mock(FrameworkUtils)
            when(frameworkUtils).getFramework(data).thenReturn(marathon)
            when(settings).getConfigDir().thenReturn(any())
            when(settings).getCliDir().thenReturn(any())
            when(settings).getUser().thenReturn('test_user')
            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.directory = ""
            args.secrets_file = ""
            args.environment = "dev"
            args.skip_push = False
            args.application = ''
            args.config_file = 'test.json'
            args.skip_build = True
            args.branch = None
            os.environ["ROGER_CONFIG_DIR"] = self.configs_dir
        except:
            raised_exception = True
        self.assertFalse(raised_exception)
Пример #7
0
    def test_roger_deploy_with_no_app(self):
        try:
            raised_exception = False
            settings = mock(Settings)
            appConfig = mock(AppConfig)
            roger_deploy = RogerDeploy()
            marathon = mock(Marathon)
            gitObj = mock(GitUtils)
            mockedHooks = mock(Hooks)
            roger_deploy.rogerGitPullObject = mock(RogerGitPull)
            roger_deploy.rogerPushObject = mock(RogerPush)
            roger_deploy.rogerBuildObject = mock(RogerBuild)
            roger_deploy.dockerUtilsObject = mock(DockerUtils)
            roger_deploy.dockerObject = mock(Docker)
            roger_deploy.utils = mock(Utils)
            roger_env = self.roger_env
            config = self.config
            data = self.data

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

            when(marathon).getCurrentImageVersion(
                any(), any(), any()).thenReturn("testversion/v0.1.0")
            frameworkUtils = mock(FrameworkUtils)
            when(frameworkUtils).getFramework(data).thenReturn(marathon)
            when(settings).getConfigDir().thenReturn(any())
            when(settings).getCliDir().thenReturn(any())
            when(settings).getUser().thenReturn('test_user')
            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.directory = ""
            args.secrets_file = ""
            args.environment = "dev"
            args.skip_push = False
            args.application = ''
            args.config_file = 'test.json'
            args.skip_build = True
            args.branch = None
            os.environ["ROGER_CONFIG_DIR"] = self.configs_dir
        except:
            raised_exception = True
        self.assertFalse(raised_exception)
Пример #8
0
 def test_tempDirCheck(self):
     work_dir = "./test_dir"
     roger_deploy = RogerDeploy()
     args = self.args
     args.directory = ""
     args.skip_push = False
     args.secrets_file = ""
     temp_dir_created = True
     roger_deploy.removeDirTree(work_dir, args, temp_dir_created)
     exists = os.path.exists(os.path.abspath(work_dir))
     assert exists is False
     os.makedirs(work_dir)
     exists = os.path.exists(os.path.abspath(work_dir))
     assert exists is True
     roger_deploy.removeDirTree(work_dir, args, temp_dir_created)
     exists = os.path.exists(os.path.abspath(work_dir))
     assert exists is False
Пример #9
0
 def test_splitVersion(self):
     roger_deploy = RogerDeploy()
     assert roger_deploy.splitVersion("0.1.0") == (0, 1, 0)
     assert roger_deploy.splitVersion("2.0013") == (2, 13, 0)
Пример #10
0
    def test_rogerDeploy_with_skip_gitpull_true(self):
        settings = mock(Settings)
        appConfig = mock(AppConfig)
        roger_deploy = RogerDeploy()
        marathon = mock(Marathon)
        gitObj = mock(GitUtils)
        mockedHooks = mock(Hooks)
        roger_deploy.rogerGitPullObject = mock(RogerGitPull)
        roger_deploy.rogerPushObject = mock(RogerPush)
        roger_deploy.rogerBuildObject = mock(RogerBuild)
        roger_deploy.dockerUtilsObject = mock(DockerUtils)
        roger_deploy.dockerObject = mock(Docker)
        roger_deploy.utils = mock(Utils)

        roger_env = self.roger_env

        repo_name = 'roger'
        repo_url = 'test_url'
        random = 'test'

        config = self.config
        data = self.data
        when(marathon).getCurrentImageVersion(
            any(), any(), any()).thenReturn("testversion/v0.1.0")
        when(marathon).getName().thenReturn('Marathon')
        frameworkUtils = mock(FrameworkUtils)

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

        when(frameworkUtils).getFramework(data).thenReturn(marathon)
        when(settings).getConfigDir().thenReturn(any())
        when(settings).getCliDir().thenReturn(any())
        when(settings).getUser().thenReturn('test_user')
        when(appConfig).getRogerEnv(any()).thenReturn(roger_env)
        when(appConfig).getConfig(any(), any()).thenReturn(config)
        when(appConfig).getAppData(any(), any(), any()).thenReturn(data)

        when(appConfig).getRepoUrl(any()).thenReturn(repo_name)
        when(appConfig).getRepoName(any()).thenReturn(repo_name)

        when(mockedHooks).run_hook(any(), any(), any(), any(), any(), any()).thenReturn(0)

        when(gitObj).gitPull(any()).thenReturn(0)
        when(gitObj).gitShallowClone(any(), any()).thenReturn(0)
        when(gitObj).gitClone(any(), any()).thenReturn(0)
        when(gitObj).getGitSha(any(), any(), any()).thenReturn(random)

        when(roger_deploy.rogerGitPullObject).main(any(), any(), any(), any(), any()).thenReturn(0)
        when(roger_deploy.rogerPushObject).main(any(), any(), any(), any(), any()).thenReturn(0)

        args = self.args
        args.directory = ""
        args.secrets_file = ""
        args.environment = "dev"
        args.skip_push = True
        args.skip_gitpull = True
        args.application = 'grafana_test_app'
        args.config_file = 'test.json'
        args.skip_build = True
        args.branch = None
        args.verbose = False
        os.environ["ROGER_CONFIG_DIR"] = self.configs_dir
        roger_deploy.main(settings, appConfig, frameworkUtils, gitObj, mockedHooks, args)
        verify(roger_deploy.rogerGitPullObject, times=0).main(any(), any(), any(), any(), any())
Пример #11
0
 def test_splitVersion(self):
     roger_deploy = RogerDeploy()
     assert roger_deploy.splitVersion("0.1.0") == (0, 1, 0)
     assert roger_deploy.splitVersion("2.0013") == (2, 13, 0)
Пример #12
0
    def test_rogerDeploy_with_skip_gitpull_true(self):
        settings = mock(Settings)
        appConfig = mock(AppConfig)
        roger_deploy = RogerDeploy()
        marathon = mock(Marathon)
        gitObj = mock(GitUtils)
        mockedHooks = mock(Hooks)
        roger_deploy.rogerGitPullObject = mock(RogerGitPull)
        roger_deploy.rogerPushObject = mock(RogerPush)
        roger_deploy.rogerBuildObject = mock(RogerBuild)
        roger_deploy.dockerUtilsObject = mock(DockerUtils)
        roger_deploy.dockerObject = mock(Docker)
        roger_deploy.utils = mock(Utils)

        roger_env = self.roger_env

        repo_name = 'roger'
        repo_url = 'test_url'
        random = 'test'

        config = self.config
        data = self.data
        when(marathon).getCurrentImageVersion(
            any(), any(), any()).thenReturn("testversion/v0.1.0")
        when(marathon).getName().thenReturn('Marathon')
        frameworkUtils = mock(FrameworkUtils)

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

        when(frameworkUtils).getFramework(data).thenReturn(marathon)
        when(settings).getConfigDir().thenReturn(any())
        when(settings).getCliDir().thenReturn(any())
        when(settings).getUser().thenReturn('test_user')
        when(appConfig).getRogerEnv(any()).thenReturn(roger_env)
        when(appConfig).getConfig(any(), any()).thenReturn(config)
        when(appConfig).getAppData(any(), any(), any()).thenReturn(data)

        when(appConfig).getRepoUrl(any()).thenReturn(repo_name)
        when(appConfig).getRepoName(any()).thenReturn(repo_name)

        when(mockedHooks).run_hook(any(), any(), any(), any()).thenReturn(0)

        when(gitObj).gitPull(any()).thenReturn(0)
        when(gitObj).gitShallowClone(any(), any()).thenReturn(0)
        when(gitObj).gitClone(any(), any()).thenReturn(0)
        when(gitObj).getGitSha(any(), any(), any()).thenReturn(random)

        when(roger_deploy.rogerGitPullObject).main(any(), any(), any(), any(), any()).thenReturn(0)
        when(roger_deploy.rogerPushObject).main(any(), any(), any(), any(), any()).thenReturn(0)

        args = self.args
        args.directory = ""
        args.secrets_file = ""
        args.environment = "dev"
        args.skip_push = True
        args.skip_gitpull = True
        args.application = 'grafana_test_app'
        args.config_file = 'test.json'
        args.skip_build = True
        args.branch = None
        os.environ["ROGER_CONFIG_DIR"] = self.configs_dir
        roger_deploy.main(settings, appConfig, frameworkUtils, gitObj, mockedHooks, args)
        verify(roger_deploy.rogerGitPullObject, times=0).main(any(), any(), any(), any(), any())