Esempio n. 1
0
static void enumeration_test(void) {
    char *enumContext = NULL;
    static int i = 0;
    char *selectors = NULL;


    wsmc_reinit_conn(cl);
    options = wsmc_options_init();

    options->flags = tests[i].flags;

    if (tests[i].selectors) {
        selectors =
              u_strdup_printf(tests[i].selectors, host, host, host);
         wsmc_add_selectors_from_str(options, selectors);
    }

    options->max_elements = tests[i].max_elements;
    WsXmlDocH enum_response = wsmc_action_enumerate(cl,
                                (char *)tests[i].resource_uri, options, NULL);

    CU_ASSERT_TRUE(wsmc_get_response_code(cl) == tests[i].final_status);
    if (wsmc_get_response_code(cl) != tests[i].final_status) {
        if (verbose) {
            printf("\nExpected = %d\nReturned = %ld         ",
                   tests[i].final_status, wsmc_get_response_code(cl));
        }
        goto RETURN;
    }
    CU_ASSERT_PTR_NOT_NULL(enum_response);
    if (enum_response) {
        enumContext = wsmc_get_enum_context(enum_response);
    } else {
        goto RETURN;
    }
    check_response_header(enum_response, wsmc_get_response_code(cl),
       ENUM_ACTION_ENUMERATERESPONSE);

//if (i==11) ws_xml_dump_node_tree(stdout, ws_xml_get_doc_root(enum_response));

    handle_filters(enum_response, filters);
    handle_filters(enum_response, tests[i].common_filters);
    handle_filters(enum_response, tests[i].filters);

RETURN:
    u_free(selectors);
    if (enumContext) {
        wsmc_action_release(cl,
                       (char *)tests[i].resource_uri,
                       options,
                       enumContext);
    }
    if (enum_response) {
        ws_xml_destroy_doc(enum_response);
    }
    wsmc_options_destroy(options);
    i++; // decrease executed test number
}
Esempio n. 2
0
static void identify_test(void) {

    WsXmlDocH response;
    static int i = 0;
    char *xp = NULL;

    wsmc_reinit_conn(cl);
    options = wsmc_options_init();

    response = wsmc_action_identify(cl, options);
    CU_ASSERT_TRUE(wsmc_get_response_code(cl) == tests[i].final_status);

    CU_ASSERT_PTR_NOT_NULL(response);
    if (response == NULL) {
        goto RETURN;
    }

    if (tests[i].value1 != NULL) {
        xp = ws_xml_get_xpath_value(response, tests[i].expr1);
        CU_ASSERT_PTR_NOT_NULL(xp);
        if (xp) {
          CU_ASSERT_STRING_EQUAL(xp, tests[i].value1 );
        }
    }

RETURN:
    if (response) {
      ws_xml_destroy_doc(response);
    }
    u_free(xp);
    wsmc_options_destroy(options);
    i++;
}
Esempio n. 3
0
int
hyperyVerifyResponse(WsManClient *client, WsXmlDocH response,
                     const char *detail)
{
    int lastError = wsmc_get_last_error(client);
    int responseCode = wsmc_get_response_code(client);
    WsManFault *fault;

    if (lastError != WS_LASTERR_OK) {
        virReportError(VIR_ERR_INTERNAL_ERROR,
                       _("Transport error during %s: %s (%d)"),
                       detail, wsman_transport_get_last_error_string(lastError),
                       lastError);
        return -1;
    }

    /* Check the HTTP response code and report an error if it's not 200 (OK),
     * 400 (Bad Request) or 500 (Internal Server Error) */
    if (responseCode != 200 && responseCode != 400 && responseCode != 500) {
        virReportError(VIR_ERR_INTERNAL_ERROR,
                       _("Unexpected HTTP response during %s: %d"),
                       detail, responseCode);
        return -1;
    }

    if (response == NULL) {
        virReportError(VIR_ERR_INTERNAL_ERROR,
                       _("Empty response during %s"), detail);
        return -1;
    }

    if (wsmc_check_for_fault(response)) {
        fault = wsmc_fault_new();

        if (fault == NULL) {
            virReportOOMError();
            return -1;
        }

        wsmc_get_fault_data(response, fault);

        virReportError(VIR_ERR_INTERNAL_ERROR,
                       _("SOAP fault during %s: code '%s', subcode '%s', "
                         "reason '%s', detail '%s'"),
                       detail, NULLSTR(fault->code), NULLSTR(fault->subcode),
                       NULLSTR(fault->reason), NULLSTR(fault->fault_detail));

        wsmc_fault_destroy(fault);
        return -1;
    }

    return 0;
}
Esempio n. 4
0
int main(int argc, char** argv)
{
    int i;
    int choice = 0;
    WsManClient *cl;
    WsXmlDocH doc;
    client_opt_t *options = NULL;
    WsXmlDocH resource = NULL;
    if (getenv("OPENWSMAN_TEST_HOST")) {
        host = getenv("OPENWSMAN_TEST_HOST");
    }

    resource = wsmc_read_file("./requests/create.xml", "UTF-8", 0);
    if(argc > 1)
        choice = atoi(argv[1]);

    for (i = 0; i < ntests; i++)
    {
        if(choice && i != choice -1)
            continue;
        if (tests[i].selectors) {
            tests[i].selectors = u_strdup_printf(tests[i].selectors, host, host, host);
        }
        if (tests[i].expected_value) {
            tests[i].expected_value = u_strdup_printf(tests[i].expected_value, host, host, host);
        }

        printf ("Test %3d: %s ", i + 1, tests[i].explanation);
        cl = wsmc_create(
                 sd[0].server,
                 sd[0].port,
                 sd[0].path,
                 sd[0].scheme,
                 sd[0].username,
                 sd[0].password);
        wsmc_transport_init(cl, NULL);
        options = wsmc_options_init();

        if (tests[i].selectors != NULL)
            wsmc_add_selectors_from_str (options, tests[i].selectors);

        wsmc_set_action_option(options, FLAG_DUMP_REQUEST);

        doc = wsmc_action_create(cl, (char *)tests[i].resource_uri, options, resource);

        if (!doc) {
            printf("\t\t\033[22;31mUNRESOLVED\033[m\n");
            goto CONTINUE;
        }

        wsman_output(doc);

        if (tests[i].final_status != wsmc_get_response_code(cl)) {
            printf("Status = %ld \t\t\033[22;31mFAILED\033[m\n",
                   wsmc_get_response_code(cl));
            goto CONTINUE;
        }
        if ((char *)tests[i].expected_value != NULL)
        {
            char *xp = ws_xml_get_xpath_value(doc, (char *)tests[i].xpath_expression);
            if (xp)
            {
                if (strcmp(xp,(char *)tests[i].expected_value ) == 0)
                    printf("\t\t\033[22;32mPASSED\033[m\n");
                else
                    printf("%s = %s\t\033[22;31mFAILED\033[m\n",(char *)tests[i].xpath_expression, xp);
                u_free(xp);
            } else {
                printf(" No %s\t\033[22;31mFAILED\033[m\n", (char *)tests[i].xpath_expression);
                ws_xml_dump_node_tree(stdout, ws_xml_get_doc_root(doc));
            }
        } else {
            printf("\t\t\033[22;32mPASSED\033[m\n");
        }

        ws_xml_destroy_doc(doc);
CONTINUE:
        u_free(tests[i].selectors);
        u_free(tests[i].expected_value);
        wsmc_options_destroy(options);
        wsmc_release(cl);
    }
    return 0;
}
Esempio n. 5
0
static void transfer_put_test(void) {
    WsXmlDocH doc;
    char *xpf = NULL;
    char *xpd = NULL;
    static int i = 0; // executed test number.
    char *selectors = NULL;


    if (put_tests[i].selectors) {
        selectors =
              u_strdup_printf(put_tests[i].selectors, host, host, host);
    }

    options = wsmc_options_init();

    if (put_tests[i].selectors != NULL) {
       wsmc_add_selectors_from_str (options, selectors);
    }
    if (put_tests[i].properties != NULL) {
       wsmc_add_prop_from_str (options,
                                               put_tests[i].properties);
    }
    options->flags = put_tests[i].flags;


    doc = wsmc_action_get_and_put(cl, (char *)put_tests[i].resource_uri, options);
    //ws_xml_dump_node_tree(stdout, ws_xml_get_doc_root(doc));
    CU_ASSERT_TRUE(wsmc_get_response_code(cl) ==
                                               put_tests[i].final_status);
    if (wsmc_get_response_code(cl) !=
                            put_tests[i].final_status) {
        if (verbose) {
            printf("\nExpected = %d, Returned = %ld        ",
                           put_tests[i].final_status,
                           wsmc_get_response_code(cl));
         //   ws_xml_dump_node_tree(stdout, ws_xml_get_doc_root(doc));
        }
        goto RETURN;
    }
    CU_ASSERT_PTR_NOT_NULL(doc);
    if (!doc) {
        goto RETURN;
    }
    if (put_tests[i].expr1 == NULL) {
        goto RETURN;
    }
    CU_ASSERT_PTR_NOT_NULL(put_tests[i].value1);
    if (put_tests[i].value1 == NULL) {
        goto RETURN;
    }
    xpf = ws_xml_get_xpath_value(doc, put_tests[i].expr1);
    CU_ASSERT_PTR_NOT_NULL(xpf);
    if (!xpf) {
        goto RETURN;
    }
    CU_ASSERT_STRING_EQUAL(xpf, put_tests[i].value1);

    if (strcmp(xpf, put_tests[i].value1)) {
        if (verbose) {
            printf("Expected %s\nReturned %s       ",
                     put_tests[i].value1, xpf);
        }
         goto RETURN;
    }
    if (put_tests[i].expr2 == NULL) {
        goto RETURN;
    }
    xpd = ws_xml_get_xpath_value(doc, put_tests[i].expr2);
    CU_ASSERT_PTR_NOT_NULL(xpd);
    if (!xpd) {
        goto RETURN;
    }
    CU_ASSERT_PTR_NOT_NULL(put_tests[i].value2);
    if (put_tests[i].value2 == NULL) {
        goto RETURN;
    }
    CU_ASSERT_STRING_EQUAL(xpd, put_tests[i].value2 );
    if (strcmp(xpd, put_tests[i].value2)) {
        if (verbose) {
            printf("\nExpected %sReturned %s       ",
                     put_tests[i].value2, xpd);
        }
        goto RETURN;
    }
RETURN:
    u_free(xpf);
    u_free(xpd);
    if (doc) {
        ws_xml_destroy_doc(doc);
    }
    u_free(selectors);
    wsmc_options_destroy(options);
    i++; // increase executed test number
}