예제 #1
0
    def test_get_result(self, _):
        """Result of task with given id and environment id is returned."""
        now = timeutils.utcnow()
        expected_environment_id = 'test_environment'
        expected_task_id = 'test_task'
        expected_result = {'test_result': 'test_result'}

        environment = models.Environment(
            id=expected_environment_id,
            name='test_environment', created=now, updated=now,
            tenant_id=self.tenant
        )

        task = models.Task(
            id=expected_task_id,
            started=now,
            finished=now,
            result=expected_result,
            environment_id=expected_environment_id
        )

        test_utils.save_models(environment, task)

        request = self._get(
            '/environments/{environment_id}/actions/{task_id}'
            .format(environment_id=expected_environment_id,
                    task_id=expected_task_id),
        )

        response = request.get_response(self.api)

        self.assertEqual(200, response.status_code)
        self.assertEqual(expected_result, response.json)
예제 #2
0
 def update_task(action, session, task, unit):
     session.state = states.SessionState.deploying
     task_info = models.Task()
     task_info.environment_id = session.environment_id
     task_info.description = dict(session.description.get('Objects'))
     task_info.action = task['action']
     status = models.Status()
     status.text = 'Action {0} is scheduled'.format(action[1]['name'])
     status.level = 'info'
     task_info.statuses.append(status)
     with unit.begin():
         unit.add(session)
         unit.add(task_info)
예제 #3
0
def update_task(action, session, task, unit):
    session.state = state.SessionState.deploying
    task_info = models.Task()
    task_info.environment_id = session.environment_id
    objects = session.description.get('Objects', None)
    if objects:
        task_info.description = token_sanitizer.TokenSanitizer().sanitize(
            dict(session.description.get('Objects')))
    task_info.action = task['action']
    status = models.Status()
    status.text = 'Action {0} is scheduled'.format(action)
    status.level = 'info'
    task_info.statuses.append(status)
    with unit.begin():
        unit.add(session)
        unit.add(task_info)
예제 #4
0
    def test_report_env_stats(self, mock_notifier):
        now = timeutils.utcnow()
        later = now + dt.timedelta(minutes=1)

        session = db_session.get_session()

        environment1 = models.Environment(
            name='test_environment1', tenant_id='test_tenant_id1',
            version=2, id='test_env_id_1',
            created=now,
            updated=later,
            description={
                'Objects': {
                    'applications': ['app1'],
                    'services': ['service1']
                }
            }
        )
        environment2 = models.Environment(
            name='test_environment2', tenant_id='test_tenant_id2',
            version=1, id='test_env_id_2',
            created=now,
            updated=later,
            description={
                'Objects': {
                    'applications': ['app2'],
                    'services': ['service3']
                }
            }
        )
        environment3 = models.Environment(
            name='test_environment3', tenant_id='test_tenant_id2',
            version=1, id='test_env_id_3',
            created=now,
            updated=later,
            description={}
        )

        session_1 = models.Session(
            environment=environment1, user_id='test_user_id',
            description={},
            state=states.SessionState.DEPLOYED,
            version=1
        )

        session_2 = models.Session(
            environment=environment2, user_id='test_user_id',
            description={},
            state=states.SessionState.DEPLOYED,
            version=0
        )

        session_3 = models.Session(
            environment=environment3, user_id='test_user_id',
            description={},
            state=states.SessionState.DEPLOY_FAILURE,
            version=1
        )

        task_1 = models.Task(
            id='task_id_1',
            environment=environment1,
            description={},
            created=now,
            started=now,
            updated=later,
            finished=later
        )

        task_2 = models.Task(
            id='task_id_2',
            environment=environment2,
            description={},
            created=now,
            started=now,
            updated=later,
            finished=later
        )

        task_3 = models.Task(
            id='task_id_3',
            environment=environment3,
            description={},
            created=now,
            started=now,
            updated=later,
            finished=later
        )

        status_1 = models.Status(
            id='status_id_1',
            task_id='task_id_1',
            text='Deployed',
            level='info'
        )

        status_2 = models.Status(
            id='status_id_2',
            task_id='task_id_2',
            text='Deployed',
            level='info'
        )

        status_3 = models.Status(
            id='status_id_3',
            task_id='task_id_3',
            text='Something was wrong',
            level='error'
        )

        session.add_all([environment1, environment2, environment3])
        session.add_all([session_1, session_2, session_3])
        session.add_all([task_1, task_2, task_3])
        session.add_all([status_1, status_2, status_3])

        session.flush()

        self.service.report_env_stats()

        self.assertEqual(mock_notifier.call_count, 2)

        dict_env_1 = {'version': 2,
                      'updated': later,
                      'tenant_id': u'test_tenant_id1',
                      'created': now,
                      'description_text': u'',
                      'status': 'ready',
                      'id': u'test_env_id_1',
                      'name': u'test_environment1'}

        dict_env_2 = {'version': 1,
                      'updated': later,
                      'tenant_id': u'test_tenant_id2',
                      'created': now,
                      'description_text': u'',
                      'status': 'ready',
                      'id': u'test_env_id_2',
                      'name': u'test_environment2'}

        calls = [mock.call('environment.exists', dict_env_1),
                 mock.call('environment.exists', dict_env_2)]

        mock_notifier.assert_has_calls(calls)