예제 #1
0
def test_call_reactor(regular_user, mocker):
    mock_service_account = mocker.patch(
        'portal.apps.system_creation.utils.service_account')
    mock_register_webhook = mocker.patch(
        'portal.apps.system_creation.utils.register_webhook')
    mock_register_webhook.return_value = "MOCK_WEBHOOK_URL"
    mock_service_account.return_value.actors.sendMessage.return_value = {
        "executionId": "mock.executionId"
    }
    variables = {"testvar_1": "testvalue_1"}
    result = call_reactor(regular_user,
                          "test.systemId",
                          "test.template",
                          variables,
                          force=False,
                          dryrun=False,
                          callback="test.callback",
                          callback_data=None)

    expected_message = {
        "username": "******",
        "force": False,
        "dryrun": False,
        "template": "test.template",
        "variables": variables,
        "webhook": "MOCK_WEBHOOK_URL"
    }
    mock_service_account.return_value.actors.sendMessage.assert_called_with(
        actorId="test.actorId", body=expected_message)
    assert result['executionId'] == "mock.executionId"
예제 #2
0
파일: dryrun.py 프로젝트: TACC/protx
def dryrun_failure(user):
    """
    A test function for dry run system creation failure

    This will dry run creation of a system, but should echo a failure that
    the "rootDir" variable in the template is missing
    """
    systemId = "data-tacc-work-{}".format(user.username)
    variables = {}
    callback = "portal.apps.system_creation.dryrun.DryrunCallback"
    callback_data = {"var1": "value1"}
    call_reactor(user,
                 systemId,
                 "work",
                 variables,
                 dryrun=True,
                 force=True,
                 callback=callback,
                 callback_data=callback_data)
예제 #3
0
파일: dryrun.py 프로젝트: TACC/protx
def dryrun_success(user):
    """
    A test function for dry run system creation

    This will dry run creation of a system using templates/data-tacc-work.j2 (in the
    abaco reactor repository) and echo a callback success once the dry run completes
    """
    systemId = "data-tacc-work-{}".format(user.username)
    variables = {"rootDir": "TEST_WORK_DIR"}
    callback = "portal.apps.system_creation.dryrun.DryrunCallback"
    callback_data = {"var1": "value1"}
    call_reactor(user,
                 systemId,
                 "work",
                 variables,
                 dryrun=True,
                 force=True,
                 callback=callback,
                 callback_data=callback_data)
예제 #4
0
    def handle(self, *args, **options):
        """Handle command."""
        systemId = options.get('system')
        
        agc = service_account()
        system = agc.systems.get(systemId=systemId)
        username = system['storage']['rootDir'].split('/')[-1]
        user, _ = get_user_model().objects.get_or_create(username=username)

        variables = {
            'name': system['name'],
            'systemId': systemId,
            'host': 'cloud.corral.tacc.utexas.edu',
            'description': system['description'],
            'site': system['site'],
            'rootDir': '/work/{tasdir}',
            'port': 2222,
        }
        _, variables = substitute_user_variables(user, system['name'], variables)

        result = call_reactor(
            user,
            systemId,
            'wma-storage',
            variables,
            force=True,
            dryrun=False,
            callback="portal.apps.system_creation.management.commands.cloud_corral.CloudCorralCallback",
            callback_data={
                "systemId": systemId,
                "originalHost": system['storage']['host']
            }
        )
        print(
            "KeyService creation reactor for {} has executionId {}".format(
                systemId,
                result['executionId']
            )
        )
예제 #5
0
    def handle(self, *args, **options):
        """Handle command."""
        username = options.get('username')

        user, created = get_user_model().objects.get_or_create(
            username=username)

        if created:
            logger.warn(
                "Username {} does not exist locally, creating a virtual user".
                format(username))

        storage_systems = get_user_storage_systems(
            user.username, settings.PORTAL_DATA_DEPOT_LOCAL_STORAGE_SYSTEMS)
        logger.debug("Unpacking systems to create: {}".format(storage_systems))

        # Create a list of tuples of systemId, variables from substitute_user_variables
        substituted = [
            substitute_user_variables(user, v['systemId'], v)
            for k, v in storage_systems.items()
        ]

        for systemId, variables in substituted:
            result = call_reactor(
                user,
                systemId,
                'wma-storage',
                variables,
                force=True,
                dryrun=False,
                callback=
                "portal.apps.system_creation.management.commands.force_system_creation.ForceSystemCreationCallback",
                callback_data={"systemId": systemId})
            logger.info(
                "Forced System Creation reactor for {} has executionId {}".
                format(systemId, result['executionId']))