int main(int argc, char *argv[]) { char *output; logfile(NULL, EUCA_LOG_TRACE, 4); log_prefix_set("%T %L %t9 |"); assert(diskutil_init(FALSE) == EUCA_OK); printf("%s: starting\n", argv[0]); output = execlp_output(TRUE, "/bin/echo", "hi", NULL); assert(output); printf("%s\n", output); free(output); output = execlp_output(TRUE, "echo", "there", NULL); assert(output); printf("%s\n", output); free(output); output = execlp_output(TRUE, "ls", "-l", "/", NULL); assert(output); printf("%s\n", output); free(output); output = execlp_output(TRUE, "foo", "bar", "baz", NULL); assert(output == NULL); output = execlp_output(TRUE, "sleep", "3", NULL); assert(output); assert(strlen(output) == 0); free(output); output = execlp_output(TRUE, "ls", "a-ridiculously-long-name-that-does-not-exist", NULL); assert(output == NULL); { // test diskutil_get_parts() struct partition_table_entry parts[5]; int n = diskutil_get_parts("/dev/sda", parts, 5); assert(n > 0); for (int i = 0; i < n; i++) { struct partition_table_entry *p = parts + i; assert(p->start_sector >= 0L); assert(p->end_sector > p->start_sector); assert(p->type[0] != '\0'); assert(p->filesystem[0] != '\0'); printf("%i %014lld %014lld %s %s\n", i, p->start_sector, p->end_sector, p->type, p->filesystem); } n = diskutil_get_parts("/dev/sda", parts, 1); assert(n == 1); } printf("%s: completed\n", argv[0]); }
int main (int argc, char * argv[]) { virConnectPtr conn = NULL; int dom_ids [MAXDOMS]; int num_doms = 0; char *hypervisor, hypervisorURL[32], cmd[1024]; char *eucahome=NULL; // logfile (NULL, EUCAFATAL); // suppress all messages if (argc != 2) { fprintf (stderr, "error: test_nc expects one parameter (name of hypervisor)\n"); exit (1); } hypervisor = argv[1]; if (!strcmp(hypervisor, "kvm")) { snprintf(hypervisorURL, 32, "qemu:///system"); } else if (!strcmp(hypervisor, "xen")) { snprintf(hypervisorURL, 32, "xen:///"); } else if (!strcmp(hypervisor, "not_configured")) { fprintf (stderr, "error: HYPERVISOR variable is not set in eucalyptus.conf\n"); exit (1); } else { fprintf (stderr, "error: hypervisor type (%s) is not recognized\n", hypervisor); exit (1); } // check that commands that NC needs are there if (system("perl --version")) { fprintf (stderr, "error: could not run perl\n"); exit (1); } eucahome = getenv (EUCALYPTUS_ENV_VAR_NAME); if (!eucahome) { eucahome = strdup (""); // root by default } else { eucahome = strdup(eucahome); } add_euca_to_path (eucahome); fprintf (stderr, "looking for system utilities...\n"); if (diskutil_init(FALSE)) // NC does not require GRUB for now exit (1); // check if euca2ools commands for bundle-instance are available fprintf (stderr, "ok\n\nlooking for euca2ools...\n"); static char * helpers_name [3] = { "euca-bundle-upload", "euca-check-bucket", "euca-delete-bundle" }; char * helpers_path [3]; // load paths from eucalyptus.conf or set to NULL helpers_path [0] = find_conf_value (eucahome, "NC_BUNDLE_UPLOAD_PATH"); helpers_path [1] = find_conf_value (eucahome, "NC_CHECK_BUCKET_PATH"); helpers_path [2] = find_conf_value (eucahome, "NC_DELETE_BUNDLE_PATH"); if (verify_helpers (helpers_name, helpers_path, 3) > 0) { if (verify_helpers (helpers_name, NULL, 3) > 0) { fprintf (stderr, "error: failed to find required euca2ools\n"); exit (1); } } // ensure hypervisor information is available fprintf (stderr, "ok\n\nchecking the hypervisor...\n"); if (!strcmp(hypervisor, "kvm")) { snprintf(cmd, 1024, "%s/usr/lib/eucalyptus/euca_rootwrap %s/usr/share/eucalyptus/get_sys_info", eucahome, eucahome); } else { snprintf(cmd, 1024, "%s/usr/lib/eucalyptus/euca_rootwrap %s/usr/share/eucalyptus/get_xen_info", eucahome, eucahome); } if (system(cmd)) { fprintf (stderr, "error: could not run '%s'\n", cmd); exit (1); } // check that libvirt can query the hypervisor conn = virConnectOpen (hypervisorURL); // NULL means local hypervisor if (conn == NULL) { print_libvirt_error (); fprintf (stderr, "error: failed to connect to hypervisor\n"); exit (1); } num_doms = virConnectListDomains (conn, dom_ids, MAXDOMS); if (num_doms < 0) { print_libvirt_error (); fprintf (stderr, "error: failed to query running domains\n"); exit (1); } fprintf (stdout, "NC test was successful\n"); return 0; }
//! //! Main entry point of the application //! //! @param[in] argc the number of parameter passed on the command line //! @param[in] argv the list of arguments //! //! @return Always return 0 //! int main(int argc, char *argv[]) { int dom_ids[MAXDOMS] = { 0 }; int num_doms = 0; char *eucahome = NULL; char *hypervisor = NULL; char rootWrap[EUCA_MAX_PATH] = ""; char cmd[EUCA_MAX_PATH] = ""; char hypervisorURL[32] = ""; virConnectPtr conn = NULL; // logfile (NULL, EUCAFATAL); // suppress all messages if (argc != 2) { fprintf(stderr, "error: test_nc expects one parameter (name of hypervisor)\n"); exit(1); } hypervisor = argv[1]; if (!strcmp(hypervisor, "kvm") || !strcmp(hypervisor, "qemu")) { snprintf(hypervisorURL, 32, "qemu:///system"); } else if (!strcmp(hypervisor, "xen")) { snprintf(hypervisorURL, 32, "xen:///"); } else if (!strcmp(hypervisor, "not_configured")) { fprintf(stderr, "error: HYPERVISOR variable is not set in eucalyptus.conf\n"); exit(1); } else { fprintf(stderr, "error: hypervisor type (%s) is not recognized\n", hypervisor); exit(1); } // check that commands that NC needs are there if (euca_execlp(NULL, "perl", "--version", NULL) != EUCA_OK) { fprintf(stderr, "error: could not run perl\n"); exit(1); } if ((eucahome = getenv(EUCALYPTUS_ENV_VAR_NAME)) == NULL) { eucahome = strdup(""); // root by default } else { eucahome = strdup(eucahome); // Sanitize this string if (euca_sanitize_path(eucahome) != EUCA_OK) { EUCA_FREE(eucahome); eucahome = strdup(""); } } add_euca_to_path(eucahome); fprintf(stderr, "looking for system utilities...\n"); if (diskutil_init(0)) { EUCA_FREE(eucahome); exit(1); } // ensure hypervisor information is available fprintf(stderr, "ok\n\nchecking the hypervisor...\n"); snprintf(rootWrap, sizeof(rootWrap), EUCALYPTUS_ROOTWRAP, eucahome); if (!strcmp(hypervisor, "kvm") || !strcmp(hypervisor, "qemu")) { snprintf(cmd, sizeof(cmd), EUCALYPTUS_HELPER_DIR "/get_sys_info", eucahome); } else { snprintf(cmd, sizeof(cmd), EUCALYPTUS_HELPER_DIR "/get_xen_info", eucahome); } if (euca_execlp(NULL, rootWrap, cmd, NULL) != EUCA_OK) { fprintf(stderr, "error: could not run '%s %s'\n", rootWrap, cmd); EUCA_FREE(eucahome); exit(1); } // check that libvirt can query the hypervisor // NULL means local hypervisor if ((conn = virConnectOpen(hypervisorURL)) == NULL) { print_libvirt_error(); fprintf(stderr, "error: failed to connect to hypervisor\n"); EUCA_FREE(eucahome); exit(1); } if ((num_doms = virConnectListDomains(conn, dom_ids, MAXDOMS)) < 0) { print_libvirt_error(); fprintf(stderr, "error: failed to query running domains\n"); EUCA_FREE(eucahome); exit(1); } fprintf(stdout, "NC test was successful\n"); EUCA_FREE(eucahome); return (0); }