def make_test_appserver(instance=None):
    """
    Factory method to create an OpenEdXAppServer (and OpenStackServer).
    """
    if not instance:
        instance = OpenEdXInstanceFactory()
    if not instance.load_balancing_server:
        instance.load_balancing_server = LoadBalancingServer.objects.select_random()
        instance.save()
    return instance._create_owned_appserver()
Beispiel #2
0
def make_test_appserver(instance=None,
                        s3=False,
                        server=None,
                        organization=None,
                        status=None):  # noqa: MC0001
    """
    Factory method to create an OpenEdXAppServer (and OpenStackServer).

    Note that this method does not set the status of the VM (OpenStackServer)
    that is associated with the app server.
    Client code is expected to take care of that itself (if necessary).

    :param instance: The OpenEdx instance to create an AppServer for, if not
                     given will create a new instance.
    :param s3: Will configure S3 storage for the OpenEdXInstance the AppServer
               belongs to.
    :param server: The OpenStackServer to associate with this AppServer.
    :param organization: The organization that owns this AppServer.
    :param status: Will move an AppServer to the specified state
    :return: appserver for `instance`
    """
    if not instance:
        instance = OpenEdXInstanceFactory()
    if not instance.load_balancing_server:
        instance.load_balancing_server = LoadBalancingServer.objects.select_random(
        )
        instance.save()
    if s3:
        instance.storage_type = 's3'
        instance.s3_access_key = 'test'
        instance.s3_secret_access_key = 'test'
        instance.s3_bucket_name = 'test'
        instance.save()
    if organization:
        instance.ref.owner = organization
        instance.ref.save()
    appserver = instance._create_owned_appserver()

    if server:
        appserver.server = server
        appserver.save()

    if status == AppServerStatus.Running:
        _set_appserver_running(appserver)
    elif status == AppServerStatus.ConfiguringServer:
        _set_appserver_configuring_server(appserver)
    elif status == AppServerStatus.ConfigurationFailed:
        _set_appserver_configuration_failed(appserver)
    elif status == AppServerStatus.Error:
        _set_appserver_errored(appserver)
    elif status == AppServerStatus.Terminated:
        _set_appserver_terminated(appserver)

    return appserver
def make_test_appserver(instance=None):
    """
    Factory method to create an OpenEdXAppServer (and OpenStackServer).
    """
    if not instance:
        instance = OpenEdXInstanceFactory()
    if not instance.load_balancing_server:
        instance.load_balancing_server = LoadBalancingServer.objects.select_random(
        )
        instance.save()
    return instance._create_owned_appserver()
    def test_app_server_site_configuration_override(self):
        """
        Test that when the static content overrides contain html elements and attributes, there are no errors and the
        expected ansible SiteConfiguration variables are generated.
        """
        instance = OpenEdXInstanceFactory()
        configuration_extra_settings = {
            'EDXAPP_SITE_CONFIGURATION': [
                {
                    'values': {
                        'override': True,
                        'CONTACT_US_CUSTOM_LINK': '/random/place/',
                    },
                },
            ],
        }
        instance.configuration_extra_settings = yaml.dump(
            configuration_extra_settings,
            default_flow_style=False,
        )

        static_content_overrides = {
            'version': 0,
            'static_template_about_content': 'static_template_about_content',
            'homepage_overlay_html': 'homepage_overlay_html',
        }
        instance.static_content_overrides = static_content_overrides
        app_server = instance._create_owned_appserver()

        expected_variables = [
            {
                'values': {
                    'override': True,
                    'CONTACT_US_CUSTOM_LINK': '/random/place/',
                    'static_template_about_content':
                    'static_template_about_content',
                    'homepage_overlay_html': 'homepage_overlay_html',
                },
            },
        ]

        configuration_settings = yaml.load(app_server.configuration_settings,
                                           Loader=yaml.SafeLoader)
        self.assertEqual(configuration_settings['EDXAPP_SITE_CONFIGURATION'],
                         expected_variables)
 def test_app_server_site_configuration_override_complex(self):
     """
     Test that when the static content overrides contain html elements and attributes, there are no errors and the
     expected ansible SiteConfiguration variables are generated.
     """
     instance = OpenEdXInstanceFactory()
     instance.configuration_extra_settings = yaml.dump(
         {
             "EDXAPP_SITE_CONFIGURATION": [
                 {
                     "values": {
                         "SOME_SETTING": "some value",
                     },
                 },
                 {
                     "domain": "some-specific-site.com",
                     "values": {
                         "SPECIFIC_SETTING": "specific value",
                     },
                 },
                 {
                     "site_id": 3,
                     "values": {
                         "CONTACT_US_CUSTOM_LINK": "/custom-contact",
                     },
                 },
             ],
         },
         default_flow_style=False)
     instance.static_content_overrides = {
         'version': 0,
         'static_template_about_content': 'TEST override!',
         'homepage_overlay_html': 'Text override!',
     }
     app_server = instance._create_owned_appserver()
     expected_variables = [
         {
             "values": {
                 "SOME_SETTING": "some value",
                 "CONTACT_US_CUSTOM_LINK": "/contact",
                 'static_template_about_content': 'TEST override!',
                 'homepage_overlay_html': 'Text override!',
             },
         },
         {
             "domain": "some-specific-site.com",
             "values": {
                 "SPECIFIC_SETTING": "specific value",
                 "CONTACT_US_CUSTOM_LINK": "/contact",
                 'static_template_about_content': 'TEST override!',
                 'homepage_overlay_html': 'Text override!',
             },
         },
         {
             "site_id": 3,
             "values": {
                 "CONTACT_US_CUSTOM_LINK": "/custom-contact",
                 'static_template_about_content': 'TEST override!',
                 'homepage_overlay_html': 'Text override!',
             },
         },
     ]
     configuration_settings = yaml.load(app_server.configuration_settings,
                                        Loader=yaml.SafeLoader)
     self.assertEqual(configuration_settings['EDXAPP_SITE_CONFIGURATION'],
                      expected_variables)