Exemplo n.º 1
0
    def test_bad_format(self):
        fn = tempfile.mkstemp()[1]
        contents = '{' \
                   '  "env1": {' \
                   '    "deployId": "1",' \
                   '    "deployStage": 3,'

        with open(fn, 'w') as f:
            f.write(contents)

        env_status = EnvStatus(fn)
        envs = env_status.load_envs()
        self.assertEqual(envs, {})
        os.remove(fn)
Exemplo n.º 2
0
    def test_bad_format(self):
        fn = tempfile.mkstemp()[1]
        contents = '{' \
                   '  "env1": {' \
                   '    "deployId": "1",' \
                   '    "deployStage": 3,'

        with open(fn, 'w') as f:
            f.write(contents)

        env_status = EnvStatus(fn)
        envs = env_status.load_envs()
        self.assertEqual(envs, {})
        os.remove(fn)
Exemplo n.º 3
0
    def test_load_dump_file(self):
        fn = tempfile.mkstemp()[1]
        env_status = EnvStatus(fn)
        status1 = DeployStatus()
        ping_report = {}
        ping_report['deployId'] = 'deploy1'
        ping_report['envId'] = 'envId1'
        ping_report['envName'] = 'env1'
        ping_report['stageName'] = 'beta'
        ping_report['deployStage'] = DeployStage.POST_RESTART
        ping_report['status'] = AgentStatus.AGENT_FAILED
        ping_report['errorCode'] = 1
        ping_report['errorMessage'] = 'Fail to open files'
        status1.report = PingReport(jsonValue=ping_report)
        status1.build_info = BuildInfo(commit='abc',
                                       build_url='http://google.com',
                                       build_id='234')

        status2 = DeployStatus()
        ping_report = {}
        ping_report['deployId'] = 'deploy2'
        ping_report['envId'] = 'envId2'
        ping_report['envName'] = 'env2'
        ping_report['stageName'] = 'prod'
        ping_report['deployStage'] = DeployStage.SERVING_BUILD
        ping_report['status'] = AgentStatus.SUCCEEDED
        status2.report = PingReport(jsonValue=ping_report)
        status2.build_info = BuildInfo(commit='bcd',
                                       build_url='http://pinterest.com',
                                       build_id='234')
        envs = {'env1': status1, 'env2': status2}
        env_status.dump_envs(envs)
        envs2 = env_status.load_envs()

        self.assertEqual(envs['env1'].report.status,
                         envs2['env1'].report.status)
        self.assertEqual(envs['env1'].report.errorMessage,
                         envs2['env1'].report.errorMessage)
        self.assertEqual(envs['env1'].build_info.build_commit,
                         envs2['env1'].build_info.build_commit)
        self.assertEqual(envs['env2'].report.deployStage,
                         envs2['env2'].report.deployStage)
        self.assertEqual(envs['env2'].build_info.build_url,
                         envs2['env2'].build_info.build_url)
        os.remove(fn)
Exemplo n.º 4
0
 def __init__(self, client, estatus=None, conf=None, executor=None, helper=None):
     self._response = None
     # a map maintains env_name -> deploy_status
     self._envs = {}
     self._config = conf or Config()
     self._executor = executor
     self._helper = helper or Helper(self._config)
     self._STATUS_FILE = self._config.get_env_status_fn()
     self._client = client
     self._env_status = estatus or EnvStatus(self._STATUS_FILE)
     # load environment deploy status file from local disk
     self.load_status_file()
Exemplo n.º 5
0
    def test_load_dump_file(self):
        fn = tempfile.mkstemp()[1]
        env_status = EnvStatus(fn)
        status1 = DeployStatus()
        ping_report = {}
        ping_report['deployId'] = 'deploy1'
        ping_report['envId'] = 'envId1'
        ping_report['envName'] = 'env1'
        ping_report['stageName'] = 'beta'
        ping_report['deployStage'] = DeployStage.POST_RESTART
        ping_report['status'] = AgentStatus.AGENT_FAILED
        ping_report['errorCode'] = 1
        ping_report['errorMessage'] = 'Fail to open files'
        status1.report = PingReport(jsonValue=ping_report)
        status1.build_info = BuildInfo(commit='abc', build_url='http://google.com', build_id='234')

        status2 = DeployStatus()
        ping_report = {}
        ping_report['deployId'] = 'deploy2'
        ping_report['envId'] = 'envId2'
        ping_report['envName'] = 'env2'
        ping_report['stageName'] = 'prod'
        ping_report['deployStage'] = DeployStage.SERVING_BUILD
        ping_report['status'] = AgentStatus.SUCCEEDED
        status2.report = PingReport(jsonValue=ping_report)
        status2.build_info = BuildInfo(commit='bcd', build_url='http://pinterest.com',
                                       build_id='234')
        envs = {
            'env1': status1,
            'env2': status2}
        env_status.dump_envs(envs)
        envs2 = env_status.load_envs()

        self.assertEqual(envs['env1'].report.status, envs2['env1'].report.status)
        self.assertEqual(envs['env1'].report.errorMessage, envs2['env1'].report.errorMessage)
        self.assertEqual(envs['env1'].build_info.build_commit,
                         envs2['env1'].build_info.build_commit)
        self.assertEqual(envs['env2'].report.deployStage, envs2['env2'].report.deployStage)
        self.assertEqual(envs['env2'].build_info.build_url, envs2['env2'].build_info.build_url)
        os.remove(fn)
Exemplo n.º 6
0
 def test_load_non_exist_file(self):
     fn = tempfile.mkstemp()[1]
     env_status = EnvStatus(fn)
     envs = env_status.load_envs()
     self.assertEqual(envs, {})
Exemplo n.º 7
0
 def test_load_non_exist_file(self):
     fn = tempfile.mkstemp()[1]
     env_status = EnvStatus(fn)
     envs = env_status.load_envs()
     self.assertEqual(envs, {})