Example #1
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++;
}
Example #2
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
}
int main(int argc, char** argv)
{
	
    WsManClient *cl;
    WsXmlDocH doc;
    client_opt_t *options = NULL;


    printf ("Test 1: Testin Identify Request:");
    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();


    doc = wsmc_action_identify(cl, options);
    if (!doc) {
           printf("\t\t\033[22;31mUNRESOLVED\033[m\n");
           goto CONTINUE;
    }
    char *xp = ws_xml_get_xpath_value(doc, "/s:Envelope/s:Body/wsmid:IdentifyResponse/wsmid:ProtocolVersion");
    if (xp)
    {
        if (strcmp(xp,XML_NS_WS_MAN ) == 0)
            printf("\t\t\033[22;32mPASSED\033[m\n");
        else
            printf("\t\t\033[22;31mFAILED\033[m\n");	
        u_free(xp);		            
    } else {
        printf("\t\t\033[22;31mFAILED\033[m\n");
    }        

    if (doc) {			
        ws_xml_destroy_doc(doc);
    }
CONTINUE:
    wsmc_options_destroy(options);
    wsmc_release(cl);

	
	return 0;
}
Example #4
0
/* This function guarantees that query is freed, even on failure */
int
hypervEnumAndPull(hypervPrivate *priv, virBufferPtr query, const char *root,
                  XmlSerializerInfo *serializerInfo, const char *resourceUri,
                  const char *className, hypervObject **list)
{
    int result = -1;
    WsSerializerContextH serializerContext;
    client_opt_t *options = NULL;
    char *query_string = NULL;
    filter_t *filter = NULL;
    WsXmlDocH response = NULL;
    char *enumContext = NULL;
    hypervObject *head = NULL;
    hypervObject *tail = NULL;
    WsXmlNodeH node = NULL;
    XML_TYPE_PTR data = NULL;
    hypervObject *object;

    if (virBufferCheckError(query) < 0) {
        virBufferFreeAndReset(query);
        return -1;
    }
    query_string = virBufferContentAndReset(query);

    if (list == NULL || *list != NULL) {
        virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
        VIR_FREE(query_string);
        return -1;
    }

    serializerContext = wsmc_get_serialization_context(priv->client);

    options = wsmc_options_init();

    if (options == NULL) {
        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                       _("Could not initialize options"));
        goto cleanup;
    }

    filter = filter_create_simple(WSM_WQL_FILTER_DIALECT, query_string);

    if (filter == NULL) {
        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                       _("Could not create filter"));
        goto cleanup;
    }

    response = wsmc_action_enumerate(priv->client, root, options, filter);

    if (hyperyVerifyResponse(priv->client, response, "enumeration") < 0)
        goto cleanup;

    enumContext = wsmc_get_enum_context(response);

    ws_xml_destroy_doc(response);
    response = NULL;

    while (enumContext != NULL && *enumContext != '\0') {
        response = wsmc_action_pull(priv->client, resourceUri, options,
                                    filter, enumContext);

        if (hyperyVerifyResponse(priv->client, response, "pull") < 0)
            goto cleanup;

        node = ws_xml_get_soap_body(response);

        if (node == NULL) {
            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                           _("Could not lookup SOAP body"));
            goto cleanup;
        }

        node = ws_xml_get_child(node, 0, XML_NS_ENUMERATION, WSENUM_PULL_RESP);

        if (node == NULL) {
            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                           _("Could not lookup pull response"));
            goto cleanup;
        }

        node = ws_xml_get_child(node, 0, XML_NS_ENUMERATION, WSENUM_ITEMS);

        if (node == NULL) {
            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                           _("Could not lookup pull response items"));
            goto cleanup;
        }

        if (ws_xml_get_child(node, 0, resourceUri, className) == NULL)
            break;

        data = ws_deserialize(serializerContext, node, serializerInfo,
                              className, resourceUri, NULL, 0, 0);

        if (data == NULL) {
            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                           _("Could not deserialize pull response item"));
            goto cleanup;
        }

        if (VIR_ALLOC(object) < 0)
            goto cleanup;

        object->serializerInfo = serializerInfo;
        object->data = data;

        data = NULL;

        if (head == NULL) {
            head = object;
        } else {
            tail->next = object;
        }

        tail = object;

        VIR_FREE(enumContext);
        enumContext = wsmc_get_enum_context(response);

        ws_xml_destroy_doc(response);
        response = NULL;
    }

    *list = head;
    head = NULL;

    result = 0;

 cleanup:
    if (options != NULL)
        wsmc_options_destroy(options);

    if (filter != NULL)
        filter_destroy(filter);

    if (data != NULL) {
#if WS_SERIALIZER_FREE_MEM_WORKS
        /* FIXME: ws_serializer_free_mem is broken in openwsman <= 2.2.6,
         *        see hypervFreeObject for a detailed explanation. */
        if (ws_serializer_free_mem(serializerContext, data,
                                   serializerInfo) < 0) {
            VIR_ERROR(_("Could not free deserialized data"));
        }
#endif
    }

    VIR_FREE(query_string);
    ws_xml_destroy_doc(response);
    VIR_FREE(enumContext);
    hypervFreeObject(priv, head);

    return result;
}
Example #5
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;
}
int main(int argc, char** argv)
{
	int i;
	WsManClient *cl;
	WsXmlDocH docp;
	client_opt_t *options = NULL;
	char *enumContext = NULL;
	//unsigned int id = 0;

	//wsman_debug_set_level(DEBUG_LEVEL_DEBUG);
    initialize_logging();
	//wsmc_add_handler(wsmc_handler, NULL);

	for (i = 0; i < ntests; i++)
	{
		printf ("Test %d: %s:", i + 1, tests[i].explanation);
		//printf ("------------------------------------------------\n");

    	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();
		options->flags = tests[i].flags;
		options->max_elements = tests[i].max_elements;
		if (tests[i].selectors != NULL)
			wsmc_add_selectors_from_str (options, tests[i].selectors);

		WsXmlDocH enum_response = wsmc_action_enumerate(cl, (char *)tests[i].resource_uri ,
			 options, NULL);
		if (!enum_response) {
               printf("\t\t\033[22;31mUNRESOLVED\033[m\n");
               goto CONTINUE;
        }			//wsman_output(enum_response);
		if ((char *)tests[i].expected_value != NULL) {
			    char *xp = ws_xml_get_xpath_value(enum_response,
                                   (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("\t\t\033[22;31mFAILED\033[m\n");
                    u_free(xp);
			    }
		}
		wsmc_free_enum_context(enumContext);
		enumContext = wsmc_get_enum_context(enum_response);
		ws_xml_destroy_doc(enum_response);

		while (enumContext != NULL)
		{
			docp = wsmc_action_pull(cl, (char *)tests[i].resource_uri,
                             options, NULL, enumContext);
            if (!docp) {
                printf("\t\t\033[22;31mUNRESOLVED\033[m\n");
                goto CONTINUE;
            }
			wsman_output(docp);
			wsmc_free_enum_context(enumContext);
			enumContext = wsmc_get_enum_context(docp);
			ws_xml_destroy_doc(docp);
		}
CONTINUE:
		wsmc_options_destroy(options);
    	wsmc_release(cl);
	}

	return 0;
}
Example #7
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
}