Beispiel #1
0
    def test_ansible_failignore(self, heartbeat_active, get_playbooks,
                                manage_instance_services):
        """
        Ensure failures that are ignored aren't reflected in the instance
        """
        heartbeat_active.return_value = True
        get_playbooks.return_value = [
            Playbook(
                source_repo=os.path.join(os.path.dirname(__file__), 'ansible'),
                requirements_path='requirements.txt',
                playbook_path='playbooks/failignore.yml',
                version=None,
                variables='{}',
            )
        ]

        # Mocking the manage_services.yml playbook because the services it tries to manage
        # will not be installed in the appserver provisioned by the dummy failignore.yml
        # playbook.
        manage_instance_services.return_value = True

        instance = OpenEdXInstanceFactory(
            name='Integration - test_ansible_failignore',
            configuration_playbook_name='playbooks/failignore.yml')
        create_new_deployment(instance,
                              mark_active_on_success=True,
                              num_attempts=1)
        self.assert_server_ready(instance)
Beispiel #2
0
 def test_run_playbook_logging(self, mock_inventory_str, mock_run_playbook):
     """
     Ensure logging routines are working on _run_playbook method
     """
     stdout_r, stdout_w = os.pipe()
     stderr_r, stderr_w = os.pipe()
     with open(stdout_r,
               'rb', buffering=0) as stdout, open(stderr_r,
                                                  'rb',
                                                  buffering=0) as stderr:
         mock_run_playbook.return_value.__enter__.return_value.stdout = stdout
         mock_run_playbook.return_value.__enter__.return_value.stderr = stderr
         mock_run_playbook.return_value.__enter__.return_value.returncode = 0
         os.write(stdout_w, b'Hello\n')
         os.close(stdout_w)
         os.write(stderr_w, b'Hi\n')
         os.close(stderr_w)
         appserver = make_test_appserver()
         playbook = Playbook(source_repo='dummy',
                             playbook_path='dummy',
                             requirements_path='dummy',
                             version='dummy',
                             variables='dummy')
         log, returncode = appserver._run_playbook("/tmp/test/working/dir/",
                                                   playbook)
         self.assertCountEqual(log, ['Hello', 'Hi'])
         self.assertEqual(returncode, 0)
Beispiel #3
0
    def manage_services_playbook(self, action, services="all"):
        """
        Return a Playbook instance for creating LMS users.
        """
        playbook_settings = yaml.dump(
            {
                "supervisord_action": action,
                "services": services,
            },
            default_flow_style=False
        )
        playbook_path = os.path.join(
            self.MANAGE_SERVICES_PLAYBOOK_DIR,
            self.MANAGE_SERVICES_PLAYBOOK_NAME
        )
        requirements_path = os.path.join(
            self.MANAGE_SERVICES_PLAYBOOK_DIR,
            'requirements.txt'
        )

        return Playbook(
            source_repo=None,
            version=None,
            requirements_path=requirements_path,
            playbook_path=playbook_path,
            variables=playbook_settings,
        )
Beispiel #4
0
 def lms_user_creation_playbook(self):
     """
     Return a Playbook instance for creating LMS users.
     """
     return Playbook(
         source_repo=self.configuration_source_repo_url,
         requirements_path='requirements.txt',
         playbook_path=self.MANAGE_USERS_PLAYBOOK,
         version=self.configuration_version,
         variables=self.lms_user_settings,
     )
Beispiel #5
0
 def default_playbook(self):
     """
     Return a Playbook instance for the standard configuration playbook.
     """
     return Playbook(
         source_repo=self.configuration_source_repo_url,
         requirements_path='requirements.txt',
         playbook_path=self.CONFIGURATION_PLAYBOOK,
         version=self.configuration_version,
         variables=self.configuration_settings,
     )
Beispiel #6
0
 def enable_bulk_emails_playbook(self):
     """
     Return a Playbook instance for enabling the Bulk Email feature.
     """
     return Playbook(
         version=None,
         source_repo=os.path.join(settings.SITE_ROOT, 'playbooks/enable_bulk_emails'),
         requirements_path='requirements.txt',
         playbook_path='enable_bulk_emails.yml',
         variables='{}',
     )
Beispiel #7
0
    def manage_services_playbook(self, action, services="edxapp_worker:"):
        """
        Return a Playbook instance for creating LMS users.
        """
        playbook_settings = yaml.dump(
            {
                "supervisord_action": action,
                "services": services,
            },
            default_flow_style=False
        )

        return Playbook(
            version=None,
            source_repo=os.path.join(settings.SITE_ROOT, 'playbooks/manage_services'),
            requirements_path='requirements.txt',
            playbook_path='manage_services.yml',
            variables=playbook_settings,
        )
Beispiel #8
0
 def test_ansible_failignore(self, heartbeat_active, get_playbooks):
     """
     Ensure failures that are ignored aren't reflected in the instance
     """
     heartbeat_active.return_value = True
     get_playbooks.return_value = [
         Playbook(
             source_repo=os.path.join(os.path.dirname(__file__), 'ansible'),
             requirements_path='requirements.txt',
             playbook_path='playbooks/failignore.yml',
             version=None,
             variables='{}',
         )
     ]
     instance = OpenEdXInstanceFactory(
         name='Integration - test_ansible_failignore',
         configuration_playbook_name='playbooks/failignore.yml'
     )
     create_new_deployment(instance.ref.pk, mark_active_on_success=True, num_attempts=1)
     self.assert_server_ready(instance)
Beispiel #9
0
    def test_manage_instance_services(self, mocks, mock_consul):
        """
        Test if manage instance services is correctly running the playbook
        """
        instance = OpenEdXInstanceFactory(internal_lms_domain='test.activate.opencraft.co.uk')
        appserver_id = instance.spawn_appserver()
        appserver = instance.appserver_set.get(pk=appserver_id)
        expected_playbook = Playbook(
            version=None,
            source_repo=os.path.join(settings.SITE_ROOT, 'playbooks/manage_services'),
            playbook_path='manage_services.yml',
            requirements_path='requirements.txt',
            variables="services: 'edxapp_worker:'\nsupervisord_action: started\n"
        )

        appserver.manage_instance_services(active=True)

        self.assertEqual(mocks.mock_run_appserver_playbooks.call_count, 1)
        mocks.mock_run_appserver_playbooks.assert_called_once_with(
            playbook=expected_playbook,
            working_dir=expected_playbook.source_repo,
        )
Beispiel #10
0
    def test_manage_instance_services(self, mocks, mock_consul):
        """
        Test if manage instance services is correctly running the playbook
        """
        instance = OpenEdXInstanceFactory(internal_lms_domain='test.activate.opencraft.co.uk')
        appserver_id = instance.spawn_appserver()
        appserver = instance.appserver_set.get(pk=appserver_id)
        expected_playbook = Playbook(
            source_repo=None,
            playbook_path='playbooks/manage_services/manage_services.yml',
            requirements_path='playbooks/manage_services/requirements.txt',
            version=None,
            variables='services: all\nsupervisord_action: start\n'
        )

        appserver.manage_instance_services(active=True)

        self.assertEqual(mocks.mock_run_appserver_playbooks.call_count, 1)
        mocks.mock_run_appserver_playbooks.assert_called_once_with(
            playbook=expected_playbook,
            working_dir='/root/dir/'
        )