Esempio n. 1
0
 def test_multi_appserver_partial_activation(self, mock_consul,
                                             mock_make_active):
     """
     Test the start_deployment task, and that it can be used to spawn multiple AppServer(s)
     for a new instance.
     """
     instance = OpenEdXInstanceFactory()
     instance.openedx_appserver_count = 3
     instance.save()
     make_test_deployment(instance, active=True)
     self.mock_make_appserver_active.s = Mock()
     self.mock_make_appserver_active.s.side_effect = make_appserver_active.s
     self.assertEqual(instance.appserver_set.count(), 3)
     self.assertTrue(
         all(instance.appserver_set.values_list('_is_active', flat=True)))
     deployment = OpenEdXDeployment.objects.create(
         instance_id=instance.ref.id)
     statuses = [
         (AppServerStatus.Running, ServerStatus.Ready.state_id),
         (AppServerStatus.ConfigurationFailed,
          ServerStatus.BuildFailed.state_id),
         (AppServerStatus.Running, ServerStatus.Ready.state_id),
     ]
     self.mock_spawn_appserver.side_effect = gen_appserver_side_effect(
         deployment, instance, statuses)
     tasks.start_deployment(
         instance.ref.id,
         deployment.pk,
         mark_active_on_success=False,
     ).get()
     self.assertEqual(self.mock_make_appserver_active.s.call_count, 0)
     self.assertEqual(mock_make_active.call_count, 0)
Esempio n. 2
0
 def test_new_deployment_cancelled(self, mock_consul):
     """
     Test the start_deployment() task, and that it can be used to spawn AppServer(s) for a new
     instance.
     """
     instance = OpenEdXInstanceFactory()
     instance.openedx_appserver_count = 1
     instance.save()
     deployment_id = OpenEdXDeployment.objects.create(
         instance_id=instance.ref.id, cancelled=True).pk
     tasks.start_deployment(instance.ref.id, deployment_id).get()
     self.assertEqual(self.mock_spawn_appserver.call_count, 0)
     self.assertEqual(self.mock_make_appserver_active.s.call_count, 0)
Esempio n. 3
0
 def test_multi_appserver_activation(self, mock_consul, mock_make_active):
     """
     Test the start_deployment task, and that it can be used to spawn multiple AppServer(s)
     for a new instance.
     """
     instance = OpenEdXInstanceFactory()
     instance.openedx_appserver_count = 3
     instance.save()
     make_test_deployment(instance, active=True)
     self.mock_make_appserver_active.s = Mock()
     self.mock_make_appserver_active.s.side_effect = make_appserver_active.s
     self.assertEqual(instance.appserver_set.count(), 3)
     appservers = list(instance.appserver_set.all())
     self.assertTrue(
         all(instance.appserver_set.values_list('_is_active', flat=True)))
     deployment = OpenEdXDeployment.objects.create(
         instance_id=instance.ref.id)
     statuses = [(AppServerStatus.Running, ServerStatus.Ready.state_id)] * 3
     self.mock_spawn_appserver.side_effect = gen_appserver_side_effect(
         deployment, instance, statuses)
     with self.assertLogs() as ctx:
         tasks.start_deployment(
             instance.ref.id,
             deployment.pk,
             mark_active_on_success=True,
         ).get()
     self.assertEqual(self.mock_make_appserver_active.s.call_count, 3)
     self.assertEqual(mock_make_active.call_count, 6)
     mock_make_active.assert_has_calls([
         call(active=True),
         call(active=True),
         call(active=True),
         call(active=False),
         call(active=False),
         call(active=False),
     ])
     for appserver in appservers:
         self.assertIn(
             f'INFO:instance.tasks:Deactivating {appserver} [{appserver.id}]',
             ctx.output)
Esempio n. 4
0
 def test_new_deployment(self, mock_consul):
     """
     Test the start_deployment() task, and that it can be used to spawn AppServer(s) for a new
     instance.
     """
     instance = OpenEdXInstanceFactory()
     instance.openedx_appserver_count = 3
     instance.save()
     deployment_id = OpenEdXDeployment.objects.create(
         instance_id=instance.ref.id).pk
     tasks.start_deployment(instance.ref.id, deployment_id).get()
     self.assertEqual(self.mock_spawn_appserver.call_count, 3)
     self.mock_spawn_appserver.assert_has_calls([
         call(
             instance,
             failure_tag=None,
             success_tag=None,
             num_attempts=1,
             deployment_id=deployment_id,
         ) for _ in range(3)
     ])
     # By default we don't mark_active_on_success:
     self.assertEqual(self.mock_make_appserver_active.s.call_count, 0)