Skip to content

Commit fa7b9dd

Browse files
author
Yi-Ting Lee
committed
create context & action added to helper
1 parent 5c89c09 commit fa7b9dd

File tree

2 files changed

+56
-9
lines changed

2 files changed

+56
-9
lines changed

tests/integ/sagemaker/lineage/helpers.py

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# language governing permissions and limitations under the License.
1313
"""This module contains helper methods for tests of SageMaker Lineage"""
1414
from __future__ import absolute_import
15+
from urllib import response
1516

1617
import uuid
1718
from datetime import datetime
@@ -86,9 +87,12 @@ def visit(arn, visited: set):
8687

8788

8889
class LineageResourceHelper:
89-
def __init__(self):
90-
self.client = boto3.client("sagemaker", config=Config(connect_timeout=5, read_timeout=60, retries={'max_attempts': 20}))
90+
def __init__(self, sagemaker_session):
91+
self.client = sagemaker_session.sagemaker_client
9192
self.artifacts = []
93+
self.actions = []
94+
self.contexts = []
95+
self.trialComponents = []
9296
self.associations = []
9397

9498
def create_artifact(self, artifact_name, artifact_type="Dataset"):
@@ -106,6 +110,42 @@ def create_artifact(self, artifact_name, artifact_type="Dataset"):
106110

107111
return response["ArtifactArn"]
108112

113+
def create_action(self, action_name, action_type="ModelDeployment"):
114+
response = self.client.create_action(
115+
ActionName=action_name,
116+
Source={
117+
"SourceUri": "Test-action-" + action_name,
118+
"SourceTypes": [
119+
{"SourceIdType": "S3ETag", "Value": "Test-action-sourceId-value"},
120+
],
121+
},
122+
ActionType=action_type
123+
)
124+
self.actions.append(response["ActionArn"])
125+
126+
return response["ActionArn"]
127+
128+
def create_context(self, context_name, context_type="Endpoint"):
129+
response = self.client.create_context(
130+
ContextName=context_name,
131+
Source={
132+
"SourceUri": "Test-context-" + context_name,
133+
"SourceTypes": [
134+
{"SourceIdType": "S3ETag", "Value": "Test-context-sourceId-value"},
135+
],
136+
},
137+
ContextType=context_type
138+
)
139+
self.contexts.append(response["ContextArn"])
140+
141+
return response["ContextArn"]
142+
143+
def create_trialComponent(self, trialComponent_name, trialComponent_type="TrainingJob"):
144+
response = self.client.create_trial_component(
145+
TrialComponentName=trialComponent_name,
146+
147+
)
148+
109149
def create_association(self, source_arn, dest_arn, association_type="AssociatedWith"):
110150
response = self.client.add_association(
111151
SourceArn=source_arn, DestinationArn=dest_arn, AssociationType=association_type
@@ -130,3 +170,10 @@ def clean_all(self):
130170
time.sleep(0.5)
131171
except Exception as e:
132172
print("skipped " + str(e))
173+
174+
for action_arn in self.actions:
175+
try:
176+
self.client.delete_action(ActionArn=action_arn)
177+
time.sleep(0.5)
178+
except Exception as e:
179+
print("skipped " + str(e))

tests/integ/sagemaker/lineage/test_lineage_visualize.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
from tests.integ.sagemaker.lineage.helpers import name, names, retry, LineageResourceHelper
2424

2525

26-
def test_LineageResourceHelper():
26+
def test_LineageResourceHelper(sagemaker_session):
2727
# check if LineageResourceHelper works properly
28-
lineage_resource_helper = LineageResourceHelper()
28+
lineage_resource_helper = LineageResourceHelper(sagemaker_session=sagemaker_session)
2929
try:
3030
art1 = lineage_resource_helper.create_artifact(artifact_name=name())
3131
art2 = lineage_resource_helper.create_artifact(artifact_name=name())
@@ -35,9 +35,9 @@ def test_LineageResourceHelper():
3535
print(e)
3636
assert False
3737

38-
38+
@pytest.mark.skip("visualizer load test")
3939
def test_wide_graph_visualize(sagemaker_session):
40-
lineage_resource_helper = LineageResourceHelper()
40+
lineage_resource_helper = LineageResourceHelper(sagemaker_session=sagemaker_session)
4141
wide_graph_root_arn = lineage_resource_helper.create_artifact(artifact_name=name())
4242

4343
# create wide graph
@@ -46,10 +46,9 @@ def test_wide_graph_visualize(sagemaker_session):
4646
# \ \--> Artifact
4747
# \---> ...
4848
try:
49-
for i in range(3):
49+
for i in range(500):
5050
artifact_arn = lineage_resource_helper.create_artifact(artifact_name=name())
5151
lineage_resource_helper.create_association(source_arn=wide_graph_root_arn, dest_arn=artifact_arn)
52-
time.sleep(0.2)
5352
except Exception as e:
5453
print(e)
5554
lineage_resource_helper.clean_all()
@@ -66,8 +65,9 @@ def test_wide_graph_visualize(sagemaker_session):
6665

6766
lineage_resource_helper.clean_all()
6867

68+
@pytest.mark.skip("visualizer load test")
6969
def test_long_graph_visualize(sagemaker_session):
70-
lineage_resource_helper = LineageResourceHelper()
70+
lineage_resource_helper = LineageResourceHelper(sagemaker_session=sagemaker_session)
7171
long_graph_root_arn = lineage_resource_helper.create_artifact(artifact_name=name())
7272
last_arn = long_graph_root_arn
7373

0 commit comments

Comments
 (0)