Skip to content

Commit

Permalink
model resource unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
surajkota committed Sep 8, 2021
1 parent 8f94233 commit e5a41fd
Show file tree
Hide file tree
Showing 19 changed files with 545 additions and 13 deletions.
3 changes: 3 additions & 0 deletions pkg/resource/model/testdata/sdkapi/create/create_success.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"ModelArn": "arn:aws:sagemaker:us-west-2:123456789012:model/xgboost-model"
}
30 changes: 30 additions & 0 deletions pkg/resource/model/testdata/sdkapi/describe/describe_success.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"Containers": [
{
"ContainerHostname": "xgboost",
"Environment": {
"my_var": "my_value",
"my_var2": "my_value2"
},
"Image": "246618743249.dkr.ecr.us-west-2.amazonaws.com/sagemaker-xgboost:1.0-1-cpu-py3",
"ImageConfig": {
"RepositoryAccessMode": "Platform",
"RepositoryAuthConfig": {
"RepositoryCredentialsProviderArn": null
}
},
"Mode": "SingleModel",
"ModelDataUrl": "s3://source-data-bucket-592697580195-us-west-2/sagemaker/model/xgboost-mnist-model.tar.gz",
"ModelPackageName": null,
"MultiModelConfig": null
}
],
"CreationTime": "2021-09-06T17:58:24.933Z",
"EnableNetworkIsolation": false,
"ExecutionRoleArn": "arn:aws:iam::123456789012:role/ack-sagemaker-execution-role",
"InferenceExecutionConfig": null,
"ModelArn": "arn:aws:sagemaker:us-west-2:123456789012:model/xgboost-model",
"ModelName": "xgboost-model",
"PrimaryContainer": null,
"VpcConfig": null
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"Containers": null,
"CreationTime": "2021-09-06T17:50:53.793Z",
"EnableNetworkIsolation": false,
"ExecutionRoleArn": "arn:aws:iam::123456789012:role/ack-sagemaker-execution-role",
"InferenceExecutionConfig": null,
"ModelArn": "arn:aws:sagemaker:us-west-2:123456789012:model/xgboost-model",
"ModelName": "xgboost-model",
"PrimaryContainer": {
"ContainerHostname": "xgboost",
"Environment": {
"my_var": "my_value",
"my_var2": "my_value2"
},
"Image": "433757028032.dkr.ecr.us-west-2.amazonaws.com/xgboost:latest",
"ImageConfig": null,
"Mode": "MultiModel",
"ModelDataUrl": "s3://source-data-bucket-592697580195-us-west-2/sagemaker/model/xgboost-mnist-model.tar.gz",
"ModelPackageName": null,
"MultiModelConfig": {
"ModelCacheSetting" : "Disabled"
}
},
"VpcConfig": null
}
183 changes: 170 additions & 13 deletions pkg/resource/model/testdata/test_suite.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,173 @@ tests:
- name: "Model create tests"
description: "Part of model CRD tests."
scenarios:
- name: "Create=InvalidInput"
description: "Given one of the parameters is invalid, ko.Status shows a terminal condition"
given:
desired_state: "model/v1alpha1/m_invalid_before_create.yaml"
svc_api:
- operation: CreateModelWithContext
error:
code: InvalidParameterValue
message: "The model name must not include a special character."
invoke: Create
expect:
latest_state: "model/v1alpha1/m_invalid_create_attempted.yaml"
error: resource is in terminal condition
- name: "Create=InvalidInput"
description: "Given one of the parameters is invalid, ko.Status shows a terminal condition"
given:
desired_state: "v1alpha1/create/desired/invalid_before_create.yaml"
svc_api:
- operation: CreateModelWithContext
error:
code: InvalidParameterValue
message: "The model name must not include a special character."
invoke: Create
expect:
latest_state: "v1alpha1/create/observed/invalid_create_attempted.yaml"
error: resource is in terminal condition
- name: "Create=Valid"
description: "Create a new model successfully (ARN in status)."
given:
desired_state: "v1alpha1/create/desired/success_before_create.yaml"
svc_api:
- operation: CreateModelWithContext
output_fixture: "sdkapi/create/create_success.json"
invoke: Create
expect:
latest_state: "v1alpha1/create/observed/success_after_create.yaml"
error: nil
- name: "Create=ValidVariation2"
description: "Create a new model successfully. This test is similar to Create=Valid with different set of inputs"
given:
desired_state: "v1alpha1/create/desired/before_create_primary_container.yaml"
svc_api:
- operation: CreateModelWithContext
output_fixture: "sdkapi/create/create_success.json"
invoke: Create
expect:
latest_state: "v1alpha1/create/observed/success_created_primary_container.yaml"
error: nil
- name: "Model readOne tests"
description: "Testing the readOne operation"
scenarios:
- name: "ReadOne=MissingRequiredField"
description: "Testing readOne when required field is missing. No API call is made and returns error."
given:
desired_state: "v1alpha1/readone/desired/missing_required_field.yaml"
invoke: ReadOne
expect:
error: "resource not found"
- name: "ReadOne=NotFound"
description: "Testing readOne when Describe fails to find the resource on SageMaker"
given:
desired_state: "v1alpha1/readone/desired/after_create.yaml"
svc_api:
- operation: DescribeModelWithContext
error:
code: ValidationException
message: "Could not find model xgboost-model"
invoke: ReadOne
expect:
error: "resource not found"
- name: "ReadOne=Fail"
description: "This test checks if the condition is updated if describe fails and readOne returns error"
given:
desired_state: "v1alpha1/readone/desired/after_create.yaml"
svc_api:
- operation: DescribeModelWithContext
error:
code: ServiceUnavailable
message: "Server is down"
invoke: ReadOne
expect:
latest_state: "v1alpha1/readone/observed/error_on_describe.yaml"
error: "ServiceUnavailable: Server is down\n\tstatus code: 0, request id: "
- name: "ReadOne=AfterCreate"
description: "Testing readOne right after create, the status should have ARN."
given:
desired_state: "v1alpha1/readone/desired/after_create.yaml"
svc_api:
- operation: DescribeModelWithContext
output_fixture: "sdkapi/describe/describe_success.json"
invoke: ReadOne
expect:
latest_state: "v1alpha1/readone/observed/created.yaml"
- name: "ReadOne=AfterCreateVariation2"
description: "Testing readOne right after create, the status should have ARN."
given:
desired_state: "v1alpha1/create/observed/success_created_primary_container.yaml"
svc_api:
- operation: DescribeModelWithContext
output_fixture: "sdkapi/describe/success_primary_container.json"
invoke: ReadOne
expect:
latest_state: "v1alpha1/readone/observed/created_primary_container.yaml"
- name: "Model update tests"
description: "Testing the Update operation"
scenarios:
- name: "Update=NotSupported"
description: "This test checks if the contrller throws error for update"
given:
desired_state: "v1alpha1/update/desired/updated_base.yaml"
latest_state: "v1alpha1/update/desired/latest_post_create.yaml"
invoke: Update
expect:
latest_state: "v1alpha1/update/observed/error_on_update.yaml"
error: "not implemented"
# - name: "Update=StatusFailed"
# description: "Testing update is blocked if endpoint is in Failed status and terminal condition is set"
# given:
# desired_state: "v1alpha1/update/desired/update_common.yaml"
# latest_state: "v1alpha1/update/desired/latest_failed.yaml"
# invoke: Update
# expect:
# latest_state: "v1alpha1/update/observed/no_update_on_failed.yaml"
# error: "resource is in terminal condition"
# - name: "Update=NoRetryIfSameEndpointConfigName"
# description: "Testing update is blocked if an update failed previously with same endpointConfigName"
# given:
# desired_state: "v1alpha1/update/desired/inservice_post_update_fail.yaml"
# latest_state: "v1alpha1/update/desired/latest_update_failed_with_reason.yaml"
# invoke: Update
# expect:
# latest_state: "v1alpha1/update/observed/no_retry_on_failed_update.yaml"
# error: "resource is in terminal condition"
# - name: "Update=Fail"
# description: "This test checks if the recoverable condition is updated if update fails and returns error"
# given:
# desired_state: "v1alpha1/update/desired/update_common.yaml"
# latest_state: "v1alpha1/update/desired/latest_inservice_pre_update.yaml"
# svc_api:
# - operation: UpdateEndpointWithContext
# error:
# code: ServiceUnavailable
# message: "Server is down"
# invoke: Update
# expect:
# latest_state: "v1alpha1/update/observed/error_on_update.yaml"
# error: "ServiceUnavailable: Server is down\n\tstatus code: 0, request id: "
# - name: "Update=InService"
# description: "This test checks if update Endpoint is called and lastEndpointConfigNameForUpdate annotation is set"
# given:
# desired_state: "v1alpha1/update/desired/update_common.yaml"
# latest_state: "v1alpha1/update/desired/latest_inservice_pre_update.yaml"
# svc_api:
# - operation: UpdateEndpointWithContext
# output_fixture: "sdkapi/update/update_success.json"
# invoke: Update
# expect:
# latest_state: "v1alpha1/update/observed/update_attempted_success.yaml"
- name: "Model delete tests"
description: "Testing the delete operation"
scenarios:
- name: "Delete=Fail"
description: "This test checks if the condition is updated if delete fails and returns error"
given:
desired_state: "v1alpha1/readone/desired/after_create.yaml"
svc_api:
- operation: DeleteModelWithContext
error:
code: ServiceUnavailable
message: "Server is down"
invoke: Delete
expect:
latest_state: "v1alpha1/delete/observed/error_on_delete.yaml"
error: "ServiceUnavailable: Server is down\n\tstatus code: 0, request id: "
- name: "Delete=Successful"
description: "This test checks if the Model is deleted successfully"
given:
desired_state: "v1alpha1/readone/desired/after_create.yaml"
svc_api:
- operation: DeleteModelWithContext
invoke: Delete
expect:
error: nil
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
apiVersion: sagemaker.services.k8s.aws/v1alpha1
kind: Model
metadata:
name: xgboost-model
spec:
executionRoleARN: arn:aws:iam::123456789012:role/ack-sagemaker-execution-role
modelName: xgboost-model
primaryContainer:
containerHostname: xgboost
environment:
my_var: my_value
my_var2: my_value2
image: 433757028032.dkr.ecr.us-west-2.amazonaws.com/xgboost:latest
modelDataURL: s3://source-data-bucket-592697580195-us-west-2/sagemaker/model/xgboost-mnist-model.tar.gz
mode: MultiModel
multiModelConfig:
modelCacheSetting: Disabled
enableNetworkIsolation: false
tags:
- key: algorithm
value: xgboost
- key: environment
value: testing
- key: customer
value: test-user
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
apiVersion: sagemaker.services.k8s.aws/v1alpha1
kind: Model
metadata:
name: xgboost-model
spec:
containers:
- containerHostname: xgboost
environment:
my_var: my_value
my_var2: my_value2
image: 246618743249.dkr.ecr.us-west-2.amazonaws.com/sagemaker-xgboost:1.0-1-cpu-py3
imageConfig:
repositoryAccessMode: Platform
modelDataURL: s3://source-data-bucket-592697580195-us-west-2/sagemaker/model/xgboost-mnist-model.tar.gz
executionRoleARN: arn:aws:iam::123456789012:role/ack-sagemaker-execution-role
modelName: xgboost-model
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
apiVersion: sagemaker.services.k8s.aws/v1alpha1
kind: Model
metadata:
creationTimestamp: null
name: xgboost-model
spec:
containers:
- containerHostname: xgboost
environment:
my_var: my_value
my_var2: my_value2
image: 246618743249.dkr.ecr.us-west-2.amazonaws.com/sagemaker-xgboost:1.0-1-cpu-py3
imageConfig:
repositoryAccessMode: Platform
modelDataURL: s3://source-data-bucket-592697580195-us-west-2/sagemaker/model/xgboost-mnist-model.tar.gz
executionRoleARN: arn:aws:iam::123456789012:role/ack-sagemaker-execution-role
modelName: xgboost-model
status:
ackResourceMetadata:
arn: arn:aws:sagemaker:us-west-2:123456789012:model/xgboost-model
ownerAccountID: ""
conditions: []
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
apiVersion: sagemaker.services.k8s.aws/v1alpha1
kind: Model
metadata:
creationTimestamp: null
name: xgboost-model
spec:
enableNetworkIsolation: false
executionRoleARN: arn:aws:iam::123456789012:role/ack-sagemaker-execution-role
modelName: xgboost-model
primaryContainer:
containerHostname: xgboost
environment:
my_var: my_value
my_var2: my_value2
image: 433757028032.dkr.ecr.us-west-2.amazonaws.com/xgboost:latest
mode: MultiModel
modelDataURL: s3://source-data-bucket-592697580195-us-west-2/sagemaker/model/xgboost-mnist-model.tar.gz
multiModelConfig:
modelCacheSetting: Disabled
tags:
- key: algorithm
value: xgboost
- key: environment
value: testing
- key: customer
value: test-user
status:
ackResourceMetadata:
arn: arn:aws:sagemaker:us-west-2:123456789012:model/xgboost-model
ownerAccountID: ""
conditions: []
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
apiVersion: sagemaker.services.k8s.aws/v1alpha1
kind: Model
metadata:
creationTimestamp: null
name: xgboost-model
spec:
containers:
- containerHostname: xgboost
environment:
my_var: my_value
my_var2: my_value2
image: 246618743249.dkr.ecr.us-west-2.amazonaws.com/sagemaker-xgboost:1.0-1-cpu-py3
imageConfig:
repositoryAccessMode: Platform
modelDataURL: s3://source-data-bucket-592697580195-us-west-2/sagemaker/model/xgboost-mnist-model.tar.gz
executionRoleARN: arn:aws:iam::123456789012:role/ack-sagemaker-execution-role
modelName: xgboost-model
status:
ackResourceMetadata:
arn: arn:aws:sagemaker:us-west-2:123456789012:model/xgboost-model
ownerAccountID: ""
conditions:
- message: "ServiceUnavailable: Server is down\n\tstatus code: 0, request id: "
status: "True"
type: ACK.Recoverable
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
apiVersion: sagemaker.services.k8s.aws/v1alpha1
kind: Model
metadata:
creationTimestamp: null
name: xgboost-model
spec:
containers:
- containerHostname: xgboost
environment:
my_var: my_value
my_var2: my_value2
image: 246618743249.dkr.ecr.us-west-2.amazonaws.com/sagemaker-xgboost:1.0-1-cpu-py3
imageConfig:
repositoryAccessMode: Platform
modelDataURL: s3://source-data-bucket-592697580195-us-west-2/sagemaker/model/xgboost-mnist-model.tar.gz
executionRoleARN: arn:aws:iam::123456789012:role/ack-sagemaker-execution-role
modelName: xgboost-model
status:
ackResourceMetadata:
arn: arn:aws:sagemaker:us-west-2:123456789012:model/xgboost-model
ownerAccountID: ""
conditions: []
Loading

0 comments on commit e5a41fd

Please sign in to comment.