コード例 #1
0
ファイル: conftest.py プロジェクト: microsoft/AzureTRE
def multi_step_resource_template(basic_shared_service_template):
    return ResourceTemplate(
        id="123",
        name="template1",
        description="description",
        version="0.1.0",
        resourceType=ResourceType.Workspace,
        current=True,
        required=[],
        properties={},
        customActions=[],
        pipeline=Pipeline(install=[
            PipelineStep(
                stepId="pre-step-1",
                stepTitle="Title for pre-step-1",
                resourceTemplateName=basic_shared_service_template.name,
                resourceType=basic_shared_service_template.resourceType,
                resourceAction="upgrade",
                properties=[
                    PipelineStepProperty(
                        name="display_name", type="string", value="new name")
                ]),
            PipelineStep(stepId="main"),
            PipelineStep(
                stepId="post-step-1",
                stepTitle="Title for post-step-1",
                resourceTemplateName=basic_shared_service_template.name,
                resourceType=basic_shared_service_template.resourceType,
                resourceAction="upgrade",
                properties=[
                    PipelineStepProperty(
                        name="display_name", type="string", value="old name")
                ])
        ]))
コード例 #2
0
def sample_resource_template() -> ResourceTemplate:
    return ResourceTemplate(id="123",
                            name="tre-user-resource",
                            description="description",
                            version="0.1.0",
                            resourceType=ResourceType.UserResource,
                            current=True,
                            required=['os_image', 'title'],
                            properties={
                                'title': {
                                    'type': 'string',
                                    'title': 'Title of the resource'
                                },
                                'os_image': {
                                    'type': 'string',
                                    'title': 'Windows image',
                                    'description': 'Select Windows image to use for VM',
                                    'enum': [
                                        'Windows 10',
                                        'Server 2019 Data Science VM'
                                    ],
                                    'updateable': False
                                },
                                'vm_size': {
                                    'type': 'string',
                                    'title': 'Windows image',
                                    'description': 'Select Windows image to use for VM',
                                    'enum': [
                                        'small',
                                        'large'
                                    ],
                                    'updateable': True
                                }
                            },
                            actions=[]).dict(exclude_none=True)
コード例 #3
0
def test_get_enriched_template_returns_the_enriched_template(get_current_mock, resource_repo):
    workspace_template = ResourceTemplate(id="abc", name="template1", description="", version="", resourceType=ResourceType.Workspace, current=True, required=[], properties={}, customActions=[])
    get_current_mock.return_value = workspace_template

    template = resource_repo._get_enriched_template("template1", ResourceType.Workspace)

    get_current_mock.assert_called_once_with('template1', ResourceType.Workspace, '')
    assert "display_name" in template["properties"]
コード例 #4
0
ファイル: conftest.py プロジェクト: microsoft/AzureTRE
def basic_shared_service_template(input_shared_service_template):
    return ResourceTemplate(
        id="1234-5678",
        name=input_shared_service_template.name,
        description=input_shared_service_template.json_schema["description"],
        version=input_shared_service_template.name,
        resourceType=ResourceType.SharedService,
        current=True,
        required=input_shared_service_template.json_schema["required"],
        properties=input_shared_service_template.json_schema["properties"],
        actions=input_shared_service_template.customActions)
コード例 #5
0
 def create_workspace_template(
         template_name: str = "base-workspace-template"):
     return ResourceTemplate(id="a7a7a7bd-7f4e-4a4e-b970-dc86a6b31dfb",
                             name=template_name,
                             description="base workspace bundle",
                             version="0.1.0",
                             resourceType=ResourceType.Workspace,
                             current=True,
                             type="object",
                             required=[],
                             properties={},
                             customActions=[])
コード例 #6
0
 def create_shared_service_template(template_name: str = "base-shared-service-template"):
     return ResourceTemplate(
         id="a7a7a7bd-7f4e-4a4e-b970-dc86a6b31dfb",
         name=template_name,
         description="base shared service",
         version="0.1.0",
         resourceType=ResourceType.SharedService,
         current=True,
         type="object",
         required=[],
         properties={},
         actions=[]
     )
コード例 #7
0
def sample_resource_template_as_dict(
        name: str,
        version: str = "1.0",
        resource_type: ResourceType = ResourceType.Workspace
) -> ResourceTemplate:
    return ResourceTemplate(id="a7a7a7bd-7f4e-4a4e-b970-dc86a6b31dfb",
                            name=name,
                            description="test",
                            version=version,
                            resourceType=resource_type,
                            current=False,
                            properties={},
                            customActions=[],
                            required=[]).dict()
コード例 #8
0
def test_validate_input_against_template_returns_template_version_if_template_is_valid(_, enriched_template_mock, resource_repo, workspace_input):
    enriched_template_mock.return_value = ResourceTemplate(id="123",
                                                           name="template1",
                                                           description="description",
                                                           version="0.1.0",
                                                           resourceType=ResourceType.Workspace,
                                                           current=True,
                                                           required=[],
                                                           properties={},
                                                           customActions=[]).dict()

    template = resource_repo.validate_input_against_template("template1", workspace_input, ResourceType.Workspace)

    assert template.version == "0.1.0"
コード例 #9
0
def test_validate_input_against_template_raises_value_error_if_payload_is_invalid(enriched_template_mock, resource_repo):
    enriched_template_mock.return_value = ResourceTemplate(id="123",
                                                           name="template1",
                                                           description="description",
                                                           version="0.1.0",
                                                           resourceType=ResourceType.Workspace,
                                                           current=True,
                                                           required=["display_name"],
                                                           properties={},
                                                           customActions=[]).dict()
    # missing display name
    workspace_input = WorkspaceInCreate(templateName="template1")

    with pytest.raises(ValidationError):
        resource_repo.validate_input_against_template("template1", workspace_input, ResourceType.Workspace)
コード例 #10
0
def get_sample_workspace_service_template_object(template_name: str = "tre-workspace-service") -> ResourceTemplate:
    return ResourceTemplate(
        id="a7a7a7bd-7f4e-4a4e-b970-dc86a6b31dfb",
        name=template_name,
        title="Workspace Service",
        description="workspace service bundle",
        version="0.1.0",
        resourceType=ResourceType.WorkspaceService,
        current=True,
        type="object",
        required=["display_name", "description"],
        properties={
            "display_name": Property(type="string"),
            "description": Property(type="string")
        },
        customActions=[CustomAction()]
    )
コード例 #11
0
ファイル: operations.py プロジェクト: microsoft/AzureTRE
    def create_operation_item(self, resource_id: str, status: Status,
                              action: str, message: str, resource_path: str,
                              resource_version: int, user: User,
                              resource_template: ResourceTemplate,
                              resource_repo: ResourceRepository) -> Operation:
        operation_id = self.create_operation_id()
        resource_template_dict = resource_template.dict(exclude_none=True)

        # if the template has a pipeline defined for this action, copy over all the steps to the ops document
        steps = self.build_step_list(
            steps=[],
            resource_template_dict=resource_template_dict,
            action=action,
            resource_repo=resource_repo,
            resource_id=resource_id,
            status=status,
            message=message)

        # if no pipeline is defined for this action, create a main step only
        if len(steps) == 0:
            steps.append(
                self.create_main_step(resource_template=resource_template_dict,
                                      action=action,
                                      resource_id=resource_id,
                                      status=status,
                                      message=message))

        timestamp = self.get_timestamp()
        operation = Operation(id=operation_id,
                              resourceId=resource_id,
                              resourcePath=resource_path,
                              resourceVersion=resource_version,
                              status=status,
                              createdWhen=timestamp,
                              updatedWhen=timestamp,
                              action=action,
                              message=message,
                              user=user,
                              steps=steps)

        self.save_item(operation)
        return operation
コード例 #12
0
def test_create_item_created_with_the_expected_type(uuid_mock, save_item_mock,
                                                    resource_template_repo,
                                                    input_workspace_template):
    uuid_mock.return_value = "1234"
    expected_type = ResourceType.WorkspaceService
    returned_template = resource_template_repo.create_template(
        input_workspace_template, expected_type)
    expected_resource_template = ResourceTemplate(
        id="1234",
        name=input_workspace_template.name,
        title=input_workspace_template.json_schema["title"],
        description=input_workspace_template.json_schema["description"],
        version=input_workspace_template.version,
        resourceType=expected_type,
        properties=input_workspace_template.json_schema["properties"],
        customActions=input_workspace_template.customActions,
        required=input_workspace_template.json_schema["required"],
        current=input_workspace_template.current)
    save_item_mock.assert_called_once_with(expected_resource_template)
    assert expected_resource_template == returned_template
コード例 #13
0
def test_create_shared_service_template_item_calls_create_item_with_the_correct_parameters(
        uuid_mock, save_item_mock, resource_template_repo,
        input_shared_service_template):
    uuid_mock.return_value = "1234"

    returned_template = resource_template_repo.create_template(
        input_shared_service_template, ResourceType.SharedService)

    expected_resource_template = ResourceTemplate(
        id="1234",
        name=input_shared_service_template.name,
        title=input_shared_service_template.json_schema["title"],
        description=input_shared_service_template.json_schema["description"],
        version=input_shared_service_template.version,
        resourceType=ResourceType.SharedService,
        properties=input_shared_service_template.json_schema["properties"],
        actions=input_shared_service_template.customActions,
        required=input_shared_service_template.json_schema["required"],
        current=input_shared_service_template.current,
    )
    save_item_mock.assert_called_once_with(expected_resource_template)
    assert expected_resource_template == returned_template
コード例 #14
0
def sample_nested_template() -> ResourceTemplate:
    return ResourceTemplate(
        id="123",
        name="template1",
        description="description",
        version="0.1.0",
        resourceType=ResourceType.Workspace,
        current=True,
        required=[],
        properties={
            'rules': {
                'type': 'array',
                'items': {
                    'type': 'object',
                    'required': [],
                    'properties': {
                        'protocol': {
                            'type': 'object',
                            'required': ['port'],
                            'items': {
                                'type': 'object',
                                'properties': {
                                    'port': {
                                        'type': 'string'
                                    },
                                    'method': {
                                        'type': 'string'
                                    }
                                }
                            }
                        }
                    }
                }
            }
        },
        customActions=[]
    ).dict(exclude_none=True)