Redshift - Pause/Resume clusters (#4693)
This commit is contained in:
parent
fb1a828fe3
commit
82588b2638
@ -3770,7 +3770,7 @@
|
|||||||
|
|
||||||
## redshift
|
## redshift
|
||||||
<details>
|
<details>
|
||||||
<summary>23% implemented</summary>
|
<summary>25% implemented</summary>
|
||||||
|
|
||||||
- [ ] accept_reserved_node_exchange
|
- [ ] accept_reserved_node_exchange
|
||||||
- [ ] add_partner
|
- [ ] add_partner
|
||||||
@ -3876,7 +3876,7 @@
|
|||||||
- [X] modify_snapshot_copy_retention_period
|
- [X] modify_snapshot_copy_retention_period
|
||||||
- [ ] modify_snapshot_schedule
|
- [ ] modify_snapshot_schedule
|
||||||
- [ ] modify_usage_limit
|
- [ ] modify_usage_limit
|
||||||
- [ ] pause_cluster
|
- [X] pause_cluster
|
||||||
- [ ] purchase_reserved_node_offering
|
- [ ] purchase_reserved_node_offering
|
||||||
- [ ] reboot_cluster
|
- [ ] reboot_cluster
|
||||||
- [ ] reject_data_share
|
- [ ] reject_data_share
|
||||||
@ -3884,7 +3884,7 @@
|
|||||||
- [ ] resize_cluster
|
- [ ] resize_cluster
|
||||||
- [X] restore_from_cluster_snapshot
|
- [X] restore_from_cluster_snapshot
|
||||||
- [ ] restore_table_from_cluster_snapshot
|
- [ ] restore_table_from_cluster_snapshot
|
||||||
- [ ] resume_cluster
|
- [X] resume_cluster
|
||||||
- [ ] revoke_cluster_security_group_ingress
|
- [ ] revoke_cluster_security_group_ingress
|
||||||
- [ ] revoke_endpoint_access
|
- [ ] revoke_endpoint_access
|
||||||
- [ ] revoke_snapshot_access
|
- [ ] revoke_snapshot_access
|
||||||
|
@ -129,7 +129,7 @@ redshift
|
|||||||
- [X] modify_snapshot_copy_retention_period
|
- [X] modify_snapshot_copy_retention_period
|
||||||
- [ ] modify_snapshot_schedule
|
- [ ] modify_snapshot_schedule
|
||||||
- [ ] modify_usage_limit
|
- [ ] modify_usage_limit
|
||||||
- [ ] pause_cluster
|
- [X] pause_cluster
|
||||||
- [ ] purchase_reserved_node_offering
|
- [ ] purchase_reserved_node_offering
|
||||||
- [ ] reboot_cluster
|
- [ ] reboot_cluster
|
||||||
- [ ] reject_data_share
|
- [ ] reject_data_share
|
||||||
@ -137,7 +137,7 @@ redshift
|
|||||||
- [ ] resize_cluster
|
- [ ] resize_cluster
|
||||||
- [X] restore_from_cluster_snapshot
|
- [X] restore_from_cluster_snapshot
|
||||||
- [ ] restore_table_from_cluster_snapshot
|
- [ ] restore_table_from_cluster_snapshot
|
||||||
- [ ] resume_cluster
|
- [X] resume_cluster
|
||||||
- [ ] revoke_cluster_security_group_ingress
|
- [ ] revoke_cluster_security_group_ingress
|
||||||
- [ ] revoke_endpoint_access
|
- [ ] revoke_endpoint_access
|
||||||
- [ ] revoke_snapshot_access
|
- [ ] revoke_snapshot_access
|
||||||
|
@ -261,6 +261,12 @@ class Cluster(TaggableResourceMixin, CloudFormationModel):
|
|||||||
def resource_id(self):
|
def resource_id(self):
|
||||||
return self.cluster_identifier
|
return self.cluster_identifier
|
||||||
|
|
||||||
|
def pause(self):
|
||||||
|
self.status = "paused"
|
||||||
|
|
||||||
|
def resume(self):
|
||||||
|
self.status = "available"
|
||||||
|
|
||||||
def to_json(self):
|
def to_json(self):
|
||||||
json_response = {
|
json_response = {
|
||||||
"MasterUsername": self.master_username,
|
"MasterUsername": self.master_username,
|
||||||
@ -637,6 +643,18 @@ class RedshiftBackend(BaseBackend):
|
|||||||
self.clusters[cluster_identifier] = cluster
|
self.clusters[cluster_identifier] = cluster
|
||||||
return cluster
|
return cluster
|
||||||
|
|
||||||
|
def pause_cluster(self, cluster_id):
|
||||||
|
if cluster_id not in self.clusters:
|
||||||
|
raise ClusterNotFoundError(cluster_identifier=cluster_id)
|
||||||
|
self.clusters[cluster_id].pause()
|
||||||
|
return self.clusters[cluster_id]
|
||||||
|
|
||||||
|
def resume_cluster(self, cluster_id):
|
||||||
|
if cluster_id not in self.clusters:
|
||||||
|
raise ClusterNotFoundError(cluster_identifier=cluster_id)
|
||||||
|
self.clusters[cluster_id].resume()
|
||||||
|
return self.clusters[cluster_id]
|
||||||
|
|
||||||
def describe_clusters(self, cluster_identifier=None):
|
def describe_clusters(self, cluster_identifier=None):
|
||||||
clusters = self.clusters.values()
|
clusters = self.clusters.values()
|
||||||
if cluster_identifier:
|
if cluster_identifier:
|
||||||
|
@ -159,6 +159,34 @@ class RedshiftResponse(BaseResponse):
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def pause_cluster(self):
|
||||||
|
cluster_id = self._get_param("ClusterIdentifier")
|
||||||
|
cluster = self.redshift_backend.pause_cluster(cluster_id).to_json()
|
||||||
|
return self.get_response(
|
||||||
|
{
|
||||||
|
"PauseClusterResponse": {
|
||||||
|
"PauseClusterResult": {"Cluster": cluster},
|
||||||
|
"ResponseMetadata": {
|
||||||
|
"RequestId": "384ac68d-3775-11df-8963-01868b7c937a"
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
def resume_cluster(self):
|
||||||
|
cluster_id = self._get_param("ClusterIdentifier")
|
||||||
|
cluster = self.redshift_backend.resume_cluster(cluster_id).to_json()
|
||||||
|
return self.get_response(
|
||||||
|
{
|
||||||
|
"ResumeClusterResponse": {
|
||||||
|
"ResumeClusterResult": {"Cluster": cluster},
|
||||||
|
"ResponseMetadata": {
|
||||||
|
"RequestId": "384ac68d-3775-11df-8963-01868b7c937a"
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
def restore_from_cluster_snapshot(self):
|
def restore_from_cluster_snapshot(self):
|
||||||
enhanced_vpc_routing = self._get_bool_param("EnhancedVpcRouting")
|
enhanced_vpc_routing = self._get_bool_param("EnhancedVpcRouting")
|
||||||
node_type = self._get_param("NodeType")
|
node_type = self._get_param("NodeType")
|
||||||
|
@ -2137,3 +2137,74 @@ def test_get_cluster_credentials():
|
|||||||
assert time.mktime(response["Expiration"].timetuple()) == pytest.approx(
|
assert time.mktime(response["Expiration"].timetuple()) == pytest.approx(
|
||||||
expected_expiration
|
expected_expiration
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@mock_redshift
|
||||||
|
def test_pause_cluster():
|
||||||
|
client = boto3.client("redshift", region_name="us-east-1")
|
||||||
|
response = client.create_cluster(
|
||||||
|
DBName="test",
|
||||||
|
ClusterIdentifier="test",
|
||||||
|
ClusterType="single-node",
|
||||||
|
NodeType="ds2.xlarge",
|
||||||
|
MasterUsername="user",
|
||||||
|
MasterUserPassword="password",
|
||||||
|
)
|
||||||
|
cluster = response["Cluster"]
|
||||||
|
cluster["ClusterIdentifier"].should.equal("test")
|
||||||
|
|
||||||
|
response = client.pause_cluster(ClusterIdentifier="test")
|
||||||
|
cluster = response["Cluster"]
|
||||||
|
cluster["ClusterIdentifier"].should.equal("test")
|
||||||
|
# Verify this call returns all properties
|
||||||
|
cluster["NodeType"].should.equal("ds2.xlarge")
|
||||||
|
cluster["ClusterStatus"].should.equal("paused")
|
||||||
|
cluster["ClusterVersion"].should.equal("1.0")
|
||||||
|
cluster["AllowVersionUpgrade"].should.equal(True)
|
||||||
|
cluster["Endpoint"]["Port"].should.equal(5439)
|
||||||
|
|
||||||
|
|
||||||
|
@mock_redshift
|
||||||
|
def test_pause_unknown_cluster():
|
||||||
|
client = boto3.client("redshift", region_name="us-east-1")
|
||||||
|
|
||||||
|
with pytest.raises(ClientError) as exc:
|
||||||
|
client.pause_cluster(ClusterIdentifier="test")
|
||||||
|
err = exc.value.response["Error"]
|
||||||
|
err["Code"].should.equal("ClusterNotFound")
|
||||||
|
err["Message"].should.equal("Cluster test not found.")
|
||||||
|
|
||||||
|
|
||||||
|
@mock_redshift
|
||||||
|
def test_resume_cluster():
|
||||||
|
client = boto3.client("redshift", region_name="us-east-1")
|
||||||
|
client.create_cluster(
|
||||||
|
DBName="test",
|
||||||
|
ClusterIdentifier="test",
|
||||||
|
ClusterType="single-node",
|
||||||
|
NodeType="ds2.xlarge",
|
||||||
|
MasterUsername="user",
|
||||||
|
MasterUserPassword="password",
|
||||||
|
)
|
||||||
|
|
||||||
|
client.pause_cluster(ClusterIdentifier="test")
|
||||||
|
response = client.resume_cluster(ClusterIdentifier="test")
|
||||||
|
cluster = response["Cluster"]
|
||||||
|
cluster["ClusterIdentifier"].should.equal("test")
|
||||||
|
# Verify this call returns all properties
|
||||||
|
cluster["NodeType"].should.equal("ds2.xlarge")
|
||||||
|
cluster["ClusterStatus"].should.equal("available")
|
||||||
|
cluster["ClusterVersion"].should.equal("1.0")
|
||||||
|
cluster["AllowVersionUpgrade"].should.equal(True)
|
||||||
|
cluster["Endpoint"]["Port"].should.equal(5439)
|
||||||
|
|
||||||
|
|
||||||
|
@mock_redshift
|
||||||
|
def test_resume_unknown_cluster():
|
||||||
|
client = boto3.client("redshift", region_name="us-east-1")
|
||||||
|
|
||||||
|
with pytest.raises(ClientError) as exc:
|
||||||
|
client.resume_cluster(ClusterIdentifier="test")
|
||||||
|
err = exc.value.response["Error"]
|
||||||
|
err["Code"].should.equal("ClusterNotFound")
|
||||||
|
err["Message"].should.equal("Cluster test not found.")
|
||||||
|
Loading…
Reference in New Issue
Block a user