Example #1
0
int diskutil_init (int require_grub) // 0 = not required, 1 = required
{
    int ret = 0;

    if (require_grub > 0) require_grub = 1;
    if (initialized < 1+require_grub) { // if init was called without grub requirement, it will run again if grub is needed now
        bzero (helpers_path, sizeof (helpers_path));
        int missing_handlers = verify_helpers (helpers, helpers_path, LASTHELPER);
        if (helpers_path [GRUB])
            grub_version = 1;
        else
            missing_handlers--;

        if (helpers_path [GRUB_SETUP]) {// don't need it, but grub-setup only exists on v2
            if (grub_version != 1)
                grub_version = 2; // prefer 1 until 2 is implemented
        }
        else 
            missing_handlers--;

        if (require_grub && grub_version == 0) {
            logprintfl (EUCAERROR, "ERROR: cannot find either grub 1 or grub 2\n");
            ret = 1;   
        } else if (grub_version == 1) { 
            // grub 1 commands seem present, check for stage files, which we will be copying
            if (try_stage_dir ("/usr/lib/grub/x86_64-pc") ||
                try_stage_dir ("/usr/lib/grub/i386-pc") ||
                try_stage_dir ("/usr/lib/grub") ||
                try_stage_dir ("/boot/grub")) {
                logprintfl (EUCAINFO, "found grub 1 stage files in %s\n", stage_files_dir);
            } else if (require_grub) {
                logprintfl (EUCAERROR, "ERROR: failed to find grub 1 stage files (in /boot/grub et al)\n");
                ret = 1;
            }
        } else if (grub_version == 2) {
            logprintfl (EUCAINFO, "detected grub 2\n");
        }
        
        // flag missing handlers
        if (missing_handlers) {
            for (int i=0; i<LASTHELPER; i++) {
                if (helpers_path [i] == NULL && i!=GRUB && i!=GRUB_SETUP) {
                    logprintfl (EUCAERROR, "ERROR: missing a required handler: %s\n", helpers[i]);
                    ret = 1;
                }
            }
        }
        
        if (initialized < 1)
            loop_sem = sem_alloc (1, "mutex");
        initialized = 1 + require_grub;
    }
    
    return ret;
}
Example #2
0
//!
//!
//!
//! @param[in] require_grub FALSE = not required, TRUE = required
//!
//! @return EUCA_OK on success or EUCA_ERROR on failure
//!
int diskutil_init()
{
   int ret = EUCA_OK;
   int missing_handlers = 0;
   if (!initialized) {
        bzero(helpers_path, sizeof(helpers_path));
        missing_handlers = verify_helpers(helpers, helpers_path, LASTHELPER);
        if (missing_handlers) {
            for (int i = 0; i < LASTHELPER; i++) {
                if (helpers_path[i] == NULL) {
                    LOGERROR("ERROR: missing a required handler: %s\n", helpers[i]);
                    ret = EUCA_ERROR;
                }
            }
        }
        if (loop_sem == NULL)
            loop_sem = sem_alloc(1, IPC_MUTEX_SEMAPHORE);
        initialized = 1;
    }
    return (ret);
}
Example #3
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;
}