예제 #1
0
파일: stubs.py 프로젝트: amzn/amazon-ray
def put_parameter_cloudwatch_config(ssm_client_stub, cluster_name,
                                    section_name):
    ssm_config_param_name = helpers.get_ssm_param_name(cluster_name,
                                                       section_name)
    ssm_client_stub.add_response("put_parameter",
                                 expected_params={
                                     "Name": ssm_config_param_name,
                                     "Type": "String",
                                     "Value": ANY,
                                     "Overwrite": True,
                                     "Tier": ANY
                                 },
                                 service_response={})
예제 #2
0
def test_cloudwatch_agent_update_with_change_head_node(ec2_client_stub,
                                                       ssm_client_stub):
    # create test cluster head node ID and an associated cloudwatch helper
    node_id = "i-abc"
    is_head_node = True
    cloudwatch_helper = helpers.get_cloudwatch_helper(node_id)

    # given a directive to check for the Unified CloudWatch Agent status...
    # expect CloudWatch Agent is installed
    stubs.get_ec2_cwa_installed_tag_true(ec2_client_stub, node_id)
    # given a directive to update a cluster CloudWatch Agent Config with new
    # changes...
    # expect the stored the CloudWatch Agent Config is different from local
    # config
    cw_ssm_param_name = helpers.get_ssm_param_name(
        cloudwatch_helper.cluster_name, "agent")
    stubs.get_param_ssm_different(ssm_client_stub, cw_ssm_param_name)

    # given an updated CloudWatch Agent Config file...
    # expect to store the new CloudWatch Agent config as an SSM parameter
    cmd_id = stubs.put_parameter_cloudwatch_config(
        ssm_client_stub, cloudwatch_helper.cluster_name, "agent")

    # given an updated CloudWatch Agent Config file...
    # expect to update the node tag equal to updated config file sha1 hash
    # to reflect the changes in config file
    stubs.update_hash_tag_success(ec2_client_stub, node_id, "agent",
                                  cloudwatch_helper)
    # given that updated CloudWatch Agent Config is put to Parameter Store...
    # expect to send an SSM command to restart CloudWatch Agent on all nodes
    cmd_id = stubs.send_command_stop_cwa(ssm_client_stub, node_id)
    # given a SSM command to stop CloudWatch Agent sent to all nodes...
    # expect to wait for the command to complete successfully on every node
    stubs.list_command_invocations_success(ssm_client_stub, node_id, cmd_id)
    cmd_id = stubs.send_command_start_cwa(ssm_client_stub, node_id,
                                          cw_ssm_param_name)
    # given a SSM command to start CloudWatch Agent sent to all nodes...
    # expect to wait for the command to complete successfully on every node
    stubs.list_command_invocations_success(ssm_client_stub, node_id, cmd_id)

    # given our mocks and the example CloudWatch Agent config as input...
    # expect CloudWatch Agent configured to use updated file on each cluster
    # node successfully
    cloudwatch_helper._update_cloudwatch_config("agent", is_head_node)

    # expect no pending responses left in client stub queues
    ec2_client_stub.assert_no_pending_responses()
    ssm_client_stub.assert_no_pending_responses()
예제 #3
0
def test_cloudwatch_alarm_update_worker_node(ec2_client_stub, ssm_client_stub,
                                             cloudwatch_client_stub):
    # create test cluster worker node ID and an associated cloudwatch helper
    node_id = "i-abc"
    is_head_node = False
    cloudwatch_helper = helpers.get_cloudwatch_helper(node_id)

    # given a directive to check for the Unified CloudWatch Agent status...
    # expect CloudWatch Agent is installed
    stubs.get_ec2_cwa_installed_tag_true(ec2_client_stub, node_id)

    # given a directive to update a cluster CloudWatch Alarm Config with new
    # changes...
    # expect the stored the CloudWatch Alarm Config is different from local
    # config
    cw_ssm_param_name = helpers.get_ssm_param_name(
        cloudwatch_helper.cluster_name, "alarm")

    # given a directive to update a cluster CloudWatch Alarm Config with new
    # changes...
    # expect the stored the CloudWatch Alarm Config is different from local
    # config
    stubs.get_head_node_config_hash_different(ec2_client_stub, "alarm",
                                              cloudwatch_helper, node_id)
    stubs.get_cur_node_config_hash_different(ec2_client_stub, "alarm", node_id)

    # given an updated CloudWatch Alarm Config file...
    # expect to update the node tag equal to updated config file sha1 hash
    # to reflect the changes in config file
    stubs.update_hash_tag_success(ec2_client_stub, node_id, "alarm",
                                  cloudwatch_helper)
    stubs.get_param_ssm_same(ssm_client_stub, cw_ssm_param_name,
                             cloudwatch_helper, "alarm")

    # given a directive to create cluster CloudWatch Alarms...
    # expect to make a call to create alarms for each node in the cluster
    stubs.put_cluster_alarms_success(cloudwatch_client_stub, cloudwatch_helper)
    # given our mocks and the example CloudWatch Alarm config as input...
    # expect CloudWatch Alarm configured to use updated file on each cluster
    # node successfully
    cloudwatch_helper._update_cloudwatch_config("alarm", is_head_node)

    # expect no pending responses left in client stub queues
    ec2_client_stub.assert_no_pending_responses()
    ssm_client_stub.assert_no_pending_responses()
예제 #4
0
def test_cloudwatch_dashboard_update_head_node(
        ec2_client_stub, ssm_client_stub, cloudwatch_client_stub):
    # create test cluster head node ID and an associated cloudwatch helper
    node_id = "i-abc"
    is_head_node = True
    cloudwatch_helper = helpers.get_cloudwatch_helper(node_id)

    # given a directive to check for the Unified CloudWatch Agent status...
    # expect CloudWatch Agent is installed
    stubs.get_ec2_cwa_installed_tag_true(ec2_client_stub, node_id)

    # given a directive to update a cluster CloudWatch Dashboard Config
    # with new changes...
    # expect the stored the CloudWatch Dashboard Config is different from local
    # config
    cw_ssm_param_name = helpers.get_ssm_param_name(
        cloudwatch_helper.cluster_name, "dashboard")
    stubs.get_param_ssm_different(ssm_client_stub, cw_ssm_param_name)

    # given an updated CloudWatch Dashboard Config file...
    # expect to store the new CloudWatch Dashboard config as an SSM parameter
    stubs.put_parameter_cloudwatch_config(
        ssm_client_stub, cloudwatch_helper.cluster_name, "dashboard")

    # given an updated CloudWatch Dashboard Config file...
    # expect to update the node tag equal to updated config file sha1 hash
    # to reflect the changes in config file
    stubs.update_hash_tag_success(ec2_client_stub, node_id, "dashboard",
                                  cloudwatch_helper)

    # given a directive to create a cluster CloudWatch dashboard...
    # expect to make a call to create a dashboard for each node in the cluster
    stubs.put_cluster_dashboard_success(
        cloudwatch_client_stub,
        cloudwatch_helper,
    )
    # given our mocks and the example CloudWatch Dashboard config as input...
    # expect CloudWatch Dashboard configured to use updated file
    # on each cluster node successfully
    cloudwatch_helper._update_cloudwatch_config("dashboard", is_head_node)

    # expect no pending responses left in client stub queues
    ec2_client_stub.assert_no_pending_responses()
    ssm_client_stub.assert_no_pending_responses()
예제 #5
0
def test_cloudwatch_agent_update_without_change_head_node(
        ssm_client_stub, ec2_client_stub):
    # create test cluster head node ID and an associated cloudwatch helper
    node_id = "i-abc"
    is_head_node = True
    cloudwatch_helper = helpers.get_cloudwatch_helper(node_id)

    # given a directive to check for the Unified CloudWatch Agent status...
    # expect CloudWatch Agent is installed
    stubs.get_ec2_cwa_installed_tag_true(ec2_client_stub, node_id)

    # given a directive to update a cluster CloudWatch Agent Config without any
    # change...
    # expect the stored the CloudWatch Agent Config is same as local config
    cw_ssm_param_name = helpers.get_ssm_param_name(
        cloudwatch_helper.cluster_name, "agent")
    stubs.get_param_ssm_same(ssm_client_stub, cw_ssm_param_name,
                             cloudwatch_helper, "agent")

    # given our mocks and the same cloudwatch agent config as input...
    # expect no update performed on CloudWatch Agent Config
    cloudwatch_helper._update_cloudwatch_config("agent", is_head_node)
예제 #6
0
def test_cloudwatch_alarm_creation(cloudwatch_client_stub, ssm_client_stub):
    # create test cluster node IDs and an associated cloudwatch helper
    node_id = "i-abc"
    cloudwatch_helper = helpers.get_cloudwatch_helper(node_id)

    # given a directive to update a cluster CloudWatch Alarm Config without any
    # change...
    # expect the stored the CloudWatch Alarm Config is same as local config
    cw_ssm_param_name = helpers.get_ssm_param_name(
        cloudwatch_helper.cluster_name, "alarm")
    stubs.get_param_ssm_same(ssm_client_stub, cw_ssm_param_name,
                             cloudwatch_helper, "alarm")

    # given a directive to create cluster CloudWatch alarms...
    # expect to make a call to create alarms for each node in the cluster
    stubs.put_cluster_alarms_success(cloudwatch_client_stub, cloudwatch_helper)

    # given our mocks and the example CloudWatch Alarm config as input...
    # expect cluster alarms to be created successfully
    cloudwatch_helper._put_cloudwatch_alarm()

    # expect no pending responses left in the CloudWatch client stub queue
    cloudwatch_client_stub.assert_no_pending_responses()