Ejemplo n.º 1
0
def created_subscription(step, server_id):

    world.tenant_id = TENANT_ID
    world.server_id = server_id
    world.headers = HEADERS

    world.rule_body = Rule_Utils.create_scale_specific_rule()

    # Create the rule in Policy Manager
    req = api_utils.create_rule(tenant_id=world.tenant_id, server_id=world.server_id, body=world.rule_body)

    assert_true(req.ok, HTTP_CODE_NOT_OK.format(req.status_code, req.content))

    # Save the Rule ID to obtain the Rule information after
    world.rule_id = req.json()[RULE_ID]

    req = api_utils.create_subscription(
        tenant_id=world.tenant_id,
        server_id=world.server_id,
        rule_id=world.rule_id,
        url=RULE_URL_DEFAULT,
        headers=world.headers,
    )

    assert_true(req.ok, HTTP_CODE_NOT_OK.format(req.status_code, req.content))
    print req.content
    world.subscription_id = req.json()[SUBSCRIPTION_ID]
Ejemplo n.º 2
0
def created_subscription(context, server_id):

    context.tenant_id = TENANT_ID
    context.server_id = server_id
    context.headers = HEADERS

    context.rule_body = Rule_Utils.create_scale_specific_rule()

    # Create the rule in Policy Manager
    req = api_utils.create_rule(tenant_id=context.tenant_id,
                                server_id=context.server_id,
                                body=context.rule_body)

    assert_true(req.ok, HTTP_CODE_NOT_OK.format(req.status_code, req.content))

    # Save the Rule ID to obtain the Rule information after
    context.rule_id = req.json()[RULE_ID]

    req = api_utils.create_subscription(tenant_id=context.tenant_id,
                                        server_id=context.server_id,
                                        rule_id=context.rule_id,
                                        url=RULE_URL_DEFAULT,
                                        headers=context.headers)

    assert_true(req.ok, HTTP_CODE_NOT_OK.format(req.status_code, req.content))
    print(req.content)
    context.subscription_id = req.json()[SUBSCRIPTION_ID]
Ejemplo n.º 3
0
def assert_rule_saved(step):

    assert_true(world.req.ok, HTTP_CODE_NOT_OK.format(world.req.status_code, world.req.content))
    response = world.req.json()
    assert_equals(response[SERVER_ID], world.server_id, INCORRECT_SERVER_ID.format(world.server_id,
                                                                                   response[SERVER_ID]))
    assert_in(RULE_ID, response.keys(), INVALID_JSON.format(response))
Ejemplo n.º 4
0
def assert_rule_saved(step):

    assert_true(world.req.ok, HTTP_CODE_NOT_OK.format(world.req.status_code, world.req.content))
    response = world.req.json()
    assert_equals(response[SERVER_ID], world.server_id, INCORRECT_SERVER_ID.format(world.server_id,
                                                                                   response[SERVER_ID]))
    assert_in(RULE_ID, response.keys(), INVALID_JSON.format(response))
Ejemplo n.º 5
0
def given_a_group1_of_servers_in_a_tenant(step, number_servers):

    world.number_servers = int(number_servers)
    world.servers_body = []

    for x in range(world.number_servers):
        world.rules = []
        server_id = Utils.id_generator(size=6)
        number_rules = random.randint(1, 5)

        for rule in range(number_rules):
            rule_body = Rule_Utils.create_scale_specific_rule()
            req = api_utils.create_rule(world.tenant_id,
                                        server_id,
                                        body=rule_body)
            assert_true(req.ok,
                        HTTP_CODE_NOT_OK.format(req.status_code, req.content))
            rule_id = req.json()[RULE_ID]
            world.rules.append(
                Rule_Utils.create_rule_body(action=None,
                                            rule_id=rule_id,
                                            condition=None,
                                            name=rule_body['name']))

        server_dict = {SERVER_ID: server_id, RULES: world.rules}
        world.servers_body.append(server_dict)
Ejemplo n.º 6
0
def assert_subscription_is_deleted(context):

    assert_true(context.req.ok, HTTP_CODE_NOT_OK.format(context.req.status_code, context.req.content))
    req = api_utils.retrieve_subscription(tenant_id=context.tenant_id, server_id=context.server_id,
                                          subscription_id=context.subscription_id, headers=context.headers)
    Utils.assert_error_code_error(response=req, expected_error_code='404',
                                  expected_fault_element=ITEM_NOT_FOUND_ERROR)
Ejemplo n.º 7
0
def then_i_obtain_zero_results(step):

    assert_true(
        world.req.ok,
        HTTP_CODE_NOT_OK.format(world.req.status_code, world.req.content))
    response = Utils.assert_json_format(world.req)
    assert_equals(response[SERVERS], [])
Ejemplo n.º 8
0
def then_i_obtain_the_server_list(step):

    assert_true(world.req.ok, HTTP_CODE_NOT_OK.format(world.req.status_code, world.req.content))
    response = Utils.assert_json_format(world.req)
    for results in world.servers_body:
        assert_in(results, response[SERVERS])
    Utils.delete_all_rules_from_tenant()
Ejemplo n.º 9
0
def then_i_obtain_the_server_list(step):

    assert_true(world.req.ok, HTTP_CODE_NOT_OK.format(world.req.status_code, world.req.content))
    response = Utils.assert_json_format(world.req)
    for results in world.servers_body:
        assert_in(results, response[SERVERS])
    Utils.delete_all_rules_from_tenant()
Ejemplo n.º 10
0
def assert_rule_is_deleted(context):

    assert_true(context.req.ok, HTTP_CODE_NOT_OK.format(context.req.status_code, context.req.content))

    req = api_utils.retrieve_rule(tenant_id=context.tenant_id, server_id=context.server_id, rule_id=context.rule_id,
                                  headers=context.headers)

    assert_equals(req.status_code, 404, ERROR_CODE_ERROR.format(req.status_code, 404))
Ejemplo n.º 11
0
def assert_subscription_created(context):

    assert_true(
        context.req.ok,
        HTTP_CODE_NOT_OK.format(context.req.status_code, context.req.content))
    response = Utils.assert_json_format(context.req)
    assert_equals(response[SERVER_ID], context.server_id)
    assert_in(SUBSCRIPTION_ID, response.keys())
Ejemplo n.º 12
0
def assert_subscription_information(step):

    assert_true(world.req.ok, HTTP_CODE_NOT_OK.format(world.req.status_code, world.req.content))
    response = Utils.assert_json_format(world.req)
    assert_equals(response[RULE_URL], RULE_URL_DEFAULT)
    assert_equals(response[SERVER_ID], world.server_id)
    assert_equals(response[SUBSCRIPTION_ID], world.subscription_id)
    assert_equals(response[RULE_ID], world.rule_id)
Ejemplo n.º 13
0
def assert_rule_information(step):

    assert_true(
        world.req.ok,
        HTTP_CODE_NOT_OK.format(world.req.status_code, world.req.content))
    response = Utils.assert_json_format(world.req)
    Rule_Utils.assert_rule_information(response=response,
                                       rule_id=world.rule_id,
                                       body=world.rule_body)
Ejemplo n.º 14
0
def assert_subscription_information(context):

    assert_true(
        context.req.ok,
        HTTP_CODE_NOT_OK.format(context.req.status_code, context.req.content))
    response = Utils.assert_json_format(context.req)
    assert_equals(response[RULE_URL], RULE_URL_DEFAULT)
    assert_equals(response[SERVER_ID], context.server_id)
    assert_equals(response[SUBSCRIPTION_ID], context.subscription_id)
    assert_equals(response[RULE_ID], context.rule_id)
Ejemplo n.º 15
0
def given_group1_of_rules_created_in_group2(step, number_rules, server_id):

    world.server_id = server_id
    world.number_rules = int(number_rules)
    for x in range(world.number_rules):
        rule_body = Rule_Utils.create_notify_specific_rule()
        req = api_utils.create_rule(world.tenant_id, world.server_id, body=rule_body)
        assert_true(req.ok, HTTP_CODE_NOT_OK.format(req.status_code, req.content))
        rule_id = req.json()[RULE_ID]
        world.rules.append(rule_body)
Ejemplo n.º 16
0
def given_group1_of_rules_created_in_group2(step, number_rules, server_id):

    world.server_id = server_id
    world.number_rules = int(number_rules)
    for x in range(world.number_rules):
        rule_body = Rule_Utils.create_notify_specific_rule()
        req = api_utils.create_rule(world.tenant_id, world.server_id, body=rule_body)
        assert_true(req.ok, HTTP_CODE_NOT_OK.format(req.status_code, req.content))
        rule_id = req.json()[RULE_ID]
        world.rules.append(rule_body)
Ejemplo n.º 17
0
def assert_rule_information(context):

    assert_true(
        context.req.ok,
        HTTP_CODE_NOT_OK.format(context.req.status_code, context.req.content))

    response = Utils.assert_json_format(context.req)
    Rule_Utils.assert_rule_information(response=response,
                                       rule_id=context.rule_id,
                                       body=context.rule_body)
Ejemplo n.º 18
0
def assert_subscription_is_deleted(step):

    assert_true(world.req.ok, HTTP_CODE_NOT_OK.format(world.req.status_code, world.req.content))
    req = api_utils.retrieve_subscription(
        tenant_id=world.tenant_id,
        server_id=world.server_id,
        subscription_id=world.subscription_id,
        headers=world.headers,
    )
    Utils.assert_error_code_error(response=req, expected_error_code="404", expected_fault_element=ITEM_NOT_FOUND_ERROR)
Ejemplo n.º 19
0
def assert_rule_is_deleted(step):

    assert_true(
        world.req.ok,
        HTTP_CODE_NOT_OK.format(world.req.status_code, world.req.content))
    req = api_utils.retrieve_rule(tenant_id=world.tenant_id,
                                  server_id=world.server_id,
                                  rule_id=world.rule_id,
                                  headers=world.headers)
    assert_equals(req.status_code, 404,
                  ERROR_CODE_ERROR.format(req.status_code, 404))
Ejemplo n.º 20
0
def created_rule(step, server_id):

    world.server_id = server_id
    world.rule_body = Rule_Utils.create_scale_specific_rule()

    #Create the rule in Policy Manager
    req = api_utils.create_rule(tenant_id=world.tenant_id, server_id=world.server_id, body=world.rule_body)

    assert_true(req.ok, HTTP_CODE_NOT_OK.format(req.status_code, req.content))

    #Save the Rule ID to obtain the Rule information after
    world.rule_id = req.json()[RULE_ID]
Ejemplo n.º 21
0
def created_rule(step, server_id):

    world.server_id = server_id
    world.rule_body = Rule_Utils.create_scale_specific_rule()

    #Create the rule in Policy Manager
    req = api_utils.create_rule(tenant_id=world.tenant_id, server_id=world.server_id, body=world.rule_body)

    assert_true(req.ok, HTTP_CODE_NOT_OK.format(req.status_code, req.content))

    #Save the Rule ID to obtain the Rule information after
    world.rule_id = req.json()[RULE_ID]
Ejemplo n.º 22
0
def assert_subscription_is_deleted(context):

    assert_true(
        context.req.ok,
        HTTP_CODE_NOT_OK.format(context.req.status_code, context.req.content))
    req = api_utils.retrieve_subscription(
        tenant_id=context.tenant_id,
        server_id=context.server_id,
        subscription_id=context.subscription_id,
        headers=context.headers)
    Utils.assert_error_code_error(response=req,
                                  expected_error_code='404',
                                  expected_fault_element=ITEM_NOT_FOUND_ERROR)
Ejemplo n.º 23
0
def create_rule(api_utils, tenant_id=TENANT_ID, server_id=None, rule_body=None, headers=HEADERS):

    """Method to subscribe a server to a specific rule not created.
    :param server_id: Server unique identifier
    :param headers: HTTP headers for the requests including authentication
    :param tenant_id: Tenant unique identifier
    :returns subscription_id: Subscription unique identifier
    """

    #Create the rule in Policy Manager
    req = api_utils.create_rule(tenant_id=tenant_id, server_id=server_id, body=rule_body, headers=headers)

    assert_true(req.ok, HTTP_CODE_NOT_OK.format(req.status_code))

    rule_id = req.json()[RULE_ID]
    return rule_id
Ejemplo n.º 24
0
def create_rule(api_utils, tenant_id=TENANT_ID, server_id=None, rule_body=None, headers=HEADERS):

    """Method to subscribe a server to a specific rule not created.
    :param server_id: Server unique identifier
    :param headers: HTTP headers for the requests including authentication
    :param tenant_id: Tenant unique identifier
    :returns subscription_id: Subscription unique identifier
    """

    # Create the rule in Policy Manager
    req = api_utils.create_rule(tenant_id=tenant_id, server_id=server_id, body=rule_body, headers=headers)

    assert_true(req.ok, HTTP_CODE_NOT_OK.format(req.status_code))

    rule_id = req.json()[RULE_ID]
    return rule_id
Ejemplo n.º 25
0
def given_a_group1_of_servers_in_a_tenant(step, number_servers):

    world.number_servers = int(number_servers)
    world.servers_body = []

    for x in range(world.number_servers):
        world.rules = []
        server_id = Utils.id_generator(size=6)
        number_rules = random.randint(1, 5)

        for rule in range(number_rules):
            rule_body = Rule_Utils.create_scale_specific_rule()
            req = api_utils.create_rule(world.tenant_id, server_id, body=rule_body)
            assert_true(req.ok, HTTP_CODE_NOT_OK.format(req.status_code, req.content))
            rule_id = req.json()[RULE_ID]
            world.rules.append(Rule_Utils.create_rule_body(action=None, rule_id=rule_id, condition=None,
                                                           name=rule_body['name']))

        server_dict = {SERVER_ID: server_id,
                       RULES: world.rules}
        world.servers_body.append(server_dict)
Ejemplo n.º 26
0
def assert_rule_information(context):

    assert_true(context.req.ok, HTTP_CODE_NOT_OK.format(context.req.status_code, context.req.content))

    response = Utils.assert_json_format(context.req)
    Rule_Utils.assert_rule_information(response=response, rule_id=context.rule_id, body=context.rule_body)
Ejemplo n.º 27
0
def then_i_obtain_zero_results(step):

    assert_true(world.req.ok, HTTP_CODE_NOT_OK.format(world.req.status_code, world.req.content))
    response = Utils.assert_json_format(world.req)
    assert_equals(response[SERVERS], [])
Ejemplo n.º 28
0
def assert_rule_information(step):

    assert_true(world.req.ok, HTTP_CODE_NOT_OK.format(world.req.status_code, world.req.content))
    response = Utils.assert_json_format(world.req)
    Rule_Utils.assert_rule_information(response=response, rule_id=world.rule_id, body=world.rule_body)
Ejemplo n.º 29
0
def assert_subscription_created(step):

    assert_true(world.req.ok, HTTP_CODE_NOT_OK.format(world.req.status_code, world.req.content))
    response = Utils.assert_json_format(world.req)
    assert_equals(response[SERVER_ID], world.server_id)
    assert_in(SUBSCRIPTION_ID, response.keys())
Ejemplo n.º 30
0
def then_the_context_is_updated(step):

    print world.req.content
    assert_true(world.req.ok, HTTP_CODE_NOT_OK.format(world.req.status_code))