Example #1
0
def test_netlease2():
    """Test network leases based on old commandline args 2"""

    arg = "publicnic;public;A2:AA:BB:2C:36:9A;Bridged;Static;"
    arg += "128.135.125.22;128.135.125.1;128.135.125.255;"
    arg += "255.255.255.0;128.135.247.50;tp-x002.ci.uchicago.edu"

    parser = wc_optparse.parsersetup()
    (opts, args) = parser.parse_args(["--networking", arg])

    p, c = get_pc(opts, realconfigs())
    c.log.debug("test_netlease2()")
    netlease_cls = c.get_class_by_keyword("NetworkLease")
    netlease = netlease_cls(p, c)

    # should validate without error
    netlease.validate()

    nic = netlease.obtain("vm1", "publicnic", "public")
    assert nic
    assert nic.name == "publicnic"
    assert nic.network == "public"
    assert nic.mac == "A2:AA:BB:2C:36:9A"
    assert nic.ip == "128.135.125.22"
    assert nic.gateway == "128.135.125.1"
    assert nic.broadcast == "128.135.125.255"
    assert nic.netmask == "255.255.255.0"
    assert nic.dns == "128.135.247.50"
    assert nic.hostname == "tp-x002.ci.uchicago.edu"
Example #2
0
def main(argv=None):
    if os.name != 'posix':
        print >> sys.stderr, "Only runs on POSIX systems."
        return 3

    parser = wc_optparse.parsersetup()

    if argv:
        (opts, args) = parser.parse_args(argv[1:])
    else:
        (opts, args) = parser.parse_args()

    try:
        dbgmsgs = wc_deprecated.deprecated_args(opts)

        # From here 'down' there is no concept of a commandline program, only
        # 'args' which could be coming from any kind of protocol based request.
        # To make such a thing, construct an opts objects with the expected
        # member names (see the wc_args module) and pass it in.

        wc_core.core(opts, dbgmsgs=dbgmsgs)

    except InvalidInput, e:
        msg = "Problem with input: %s" % e.msg
        print >> sys.stderr, msg
        return 1
Example #3
0
def main(argv=None):
    if os.name != 'posix':
        print >>sys.stderr, "Only runs on POSIX systems."
        return 3
        
    parser = wc_optparse.parsersetup()


    if argv:
        (opts, args) = parser.parse_args(argv[1:])
    else:
        (opts, args) = parser.parse_args()
        
    try:
        dbgmsgs = wc_deprecated.deprecated_args(opts)
        
        # From here 'down' there is no concept of a commandline program, only
        # 'args' which could be coming from any kind of protocol based request.
        # To make such a thing, construct an opts objects with the expected
        # member names (see the wc_args module) and pass it in.
        
        wc_core.core(opts, dbgmsgs=dbgmsgs)
        
    except InvalidInput, e:
        msg = "Problem with input: %s" % e.msg
        print >>sys.stderr, msg
        return 1
Example #4
0
def test_netlease2():
    """Test network leases based on old commandline args 2"""
    
    arg = "publicnic;public;A2:AA:BB:2C:36:9A;Bridged;Static;"
    arg += "128.135.125.22;128.135.125.1;128.135.125.255;"
    arg += "255.255.255.0;128.135.247.50;tp-x002.ci.uchicago.edu"
    
    parser = wc_optparse.parsersetup()
    (opts, args) = parser.parse_args(["--networking", arg])
    
    p,c = get_pc(opts, realconfigs())
    c.log.debug("test_netlease2()")
    netlease_cls = c.get_class_by_keyword("NetworkLease")
    netlease = netlease_cls(p,c)
    
    # should validate without error
    netlease.validate()
    
    nic = netlease.obtain("vm1", "publicnic", "public")
    assert nic
    assert nic.name == "publicnic"
    assert nic.network == "public"
    assert nic.mac == "A2:AA:BB:2C:36:9A"
    assert nic.ip == "128.135.125.22"
    assert nic.gateway == "128.135.125.1"
    assert nic.broadcast == "128.135.125.255"
    assert nic.netmask == "255.255.255.0"
    assert nic.dns == "128.135.247.50"
    assert nic.hostname == "tp-x002.ci.uchicago.edu"
Example #5
0
def test_real_procurement_propagate1():
    """Test the procurement adapter propagate awareness (positive)"""

    handle = "wrksp-411"
    createargs = [
        "--action",
        "create",
        "--name",
        handle,
        "--memory",
        "256",
        "--images",
        "scp://somehost/some-base-cluster-01.gz",
        "--imagemounts",
        "xvda1",
    ]
    parser = wc_optparse.parsersetup()
    (opts, args) = parser.parse_args(createargs)

    p, c = get_pc(opts, realconfigs())
    c.log.debug("test_real_procurement_propagate1()")

    procure_cls = c.get_class_by_keyword("ImageProcurement")
    procure = procure_cls(p, c)
    procure.validate()
    assert procure.lengthy_obtain()
Example #6
0
def test_real_procurement_unpropagate3():
    """Test that procurement adapter rejects blanksspace requests in unpropagate"""

    handle = "wrksp-414"
    createargs = [
        "--action",
        "unpropagate",
        "--name",
        handle,
        "--images",
        "scp://somehost/some-base-cluster-01.gz;;blankspace://blah-size-40",
    ]
    parser = wc_optparse.parsersetup()
    (opts, args) = parser.parse_args(createargs)

    p, c = get_pc(opts, realconfigs())
    c.log.debug("test_real_procurement_unpropagate3()")

    procure_cls = c.get_class_by_keyword("ImageProcurement")
    procure = procure_cls(p, c)
    procure.validate()

    invalid_input = False
    try:
        procure.lengthy_shutdown()
    except InvalidInput:
        invalid_input = True
    assert invalid_input
Example #7
0
def test_real_procurement_propagate3():
    """Test that an unknown propagation scheme will cause an error.
    """
    
    handle = "wrksp-412"
    relative_filename_testfile = "some-base-cluster-01.gz"
    createargs = ["--action", "create", 
                  "--name", handle,
                  "--memory", "256",
                  "--images", "zzfile://%s" % relative_filename_testfile,
                  "--imagemounts", "xvda1",
                 ]
    parser = wc_optparse.parsersetup()
    (opts, args) = parser.parse_args(createargs)
    
    p,c = get_pc(opts, realconfigs())
    c.log.debug("test_real_procurement_propagate3()")
    
    procure_cls = c.get_class_by_keyword("ImageProcurement")
    procure = procure_cls(p, c)
    procure.validate()
    
    try:
        filelist = [relative_filename_testfile]
        _create_fake_securedir_files(p, c, handle, filelist)
        
        invalid_input = False
        try:
            procure.lengthy_obtain()
        except InvalidInput:
            invalid_input = True
        assert invalid_input
        
    finally:
        _destroy_fake_securedir(p, c, handle)
Example #8
0
def test_image_compress1():
    """Test file compression"""

    createargs = [
        "--action", "unpropagate", "--name", "wrksp-929", "--images",
        "scp://somehost/some-base-cluster-01", "--unproptargets",
        "scp://somehost/some-newfile.gz", "--dryrun"
    ]
    parser = wc_optparse.parsersetup()
    (opts, args) = parser.parse_args(createargs)

    p, c = get_pc(opts, realconfigs())
    c.log.debug("test_image_compress1()")

    procure_cls = c.get_class_by_keyword("ImageProcurement")
    procure = procure_cls(p, c)
    procure.validate()
    local_file_set = procure.obtain()

    editing_cls = c.get_class_by_keyword("ImageEditing")
    editing = editing_cls(p, c)
    editing.validate()

    editing.process_after_shutdown(local_file_set)
    procure.process_after_shutdown(local_file_set)
Example #9
0
def test_image_editing1():
    """Test for image editing module task awareness"""

    handle = "wrksp-911"
    createargs = [
        "--action", "create", "--name", handle, "--images",
        "scp://somehost/some-base-cluster", "--mnttasks",
        "d69a9bda-399a-4016-aaee;/root/.ssh/authorized_keys;;3abc9086-d74b-46b0-a3e9;/var/nimbus-metadata-server-url",
        "--dryrun"
    ]
    parser = wc_optparse.parsersetup()
    (opts, args) = parser.parse_args(createargs)

    p, c = get_pc(opts, mockconfigs())
    c.log.debug("test_real_image_editing1()")

    editing_cls = c.get_class_by_keyword("ImageEditing")
    editing = editing_cls(p, c)
    editing.validate()

    procure_cls = c.get_class_by_keyword("ImageProcurement")
    procure = procure_cls(p, c)
    procure.validate()
    local_file_set = procure.obtain()

    editing.process_after_procurement(local_file_set)

    # TODO: could actually test for the existence of the task ... the mock
    # procurement adapter is actually making filesystem images.  But we'd first
    # need a tool to mount and check a filesystem.  And sudo would need to be
    # configured.

    # clean up
    procure.process_after_destroy(local_file_set)
Example #10
0
def test_notification3():
    """Test notification validation"""
    
    handle = "wrksp-104"
    createargs = ["--action", "unpropagate", 
                  "--name", handle,
                  "--images", "scp://somehost/some-base-cluster-01.gz",
                  "--notify", "nimbus@somehost:22/somepath",
                  "--dryrun"
                 ]
    parser = wc_optparse.parsersetup()
    (opts, args) = parser.parse_args(createargs)
    
    p,c = get_pc(opts, realconfigs())
    c.log.debug("test_notification3()")
    
    notify_cls = c.get_class_by_keyword("AsyncNotification")
    notify = notify_cls(p, c)
    
    # should throw no error
    notify.validate()
    
    notify.notify(handle, "propagate", 0, None)
    notify.notify(handle, "propagate", 1, "bad\nbad\nbad")
    
    programming_error = False
    try:
        notify.notify(handle, "XYZpropagate", 1, "bad\nbad")
    except ProgrammingError:
        programming_error = True
    assert programming_error
Example #11
0
def test_netlease1():
    """Test network leases based on old commandline args"""
    
    # a direct sample from logs, trailing null business (the very first
    # contextualization impl) is ignored entirely in the new workspace-control
    arg = "publicnic;public;A2:AA:BB:2C:36:9A;Bridged;Static;"
    arg += "128.135.125.22;128.135.125.1;128.135.125.255;"
    arg += "255.255.255.0;128.135.247.50;tp-x002.ci.uchicago.edu"
    arg += ";null;null;null;null"
    
    parser = wc_optparse.parsersetup()
    (opts, args) = parser.parse_args(["--networking", arg])
    
    p,c = get_pc(opts, realconfigs())
    c.log.debug("test_netlease1()")
    netlease_cls = c.get_class_by_keyword("NetworkLease")
    netlease = netlease_cls(p,c)
    
    # should validate without error
    netlease.validate()
    
    nic = netlease.obtain("vm1", "publicnic", "public")
    assert nic
    assert nic.name == "publicnic"
    assert nic.network == "public"
    assert nic.mac == "A2:AA:BB:2C:36:9A"
    assert nic.ip == "128.135.125.22"
    assert nic.gateway == "128.135.125.1"
    assert nic.broadcast == "128.135.125.255"
    assert nic.netmask == "255.255.255.0"
    assert nic.dns == "128.135.247.50"
    assert nic.hostname == "tp-x002.ci.uchicago.edu"
Example #12
0
def test_notification3():
    """Test notification validation"""

    handle = "wrksp-104"
    createargs = [
        "--action", "unpropagate", "--name", handle, "--images",
        "scp://somehost/some-base-cluster-01.gz", "--notify",
        "nimbus@somehost:22/somepath", "--dryrun"
    ]
    parser = wc_optparse.parsersetup()
    (opts, args) = parser.parse_args(createargs)

    p, c = get_pc(opts, realconfigs())
    c.log.debug("test_notification3()")

    notify_cls = c.get_class_by_keyword("AsyncNotification")
    notify = notify_cls(p, c)

    # should throw no error
    notify.validate()

    notify.notify(handle, "propagate", 0, None)
    notify.notify(handle, "propagate", 1, "bad\nbad\nbad")

    programming_error = False
    try:
        notify.notify(handle, "XYZpropagate", 1, "bad\nbad")
    except ProgrammingError:
        programming_error = True
    assert programming_error
Example #13
0
def test_real_procurement_propagate8():
    """Test that a mismatch of images and mountpoints will cause an error
    """
    
    handle = "wrksp-499"
    createargs = ["--action", "create", 
                  "--name", handle,
                  "--memory", "256",
                  "--images", "scp://somehost/some-base-cluster-01.gz",
                  "--imagemounts", "xvda1;;xvda2",
                 ]
    parser = wc_optparse.parsersetup()
    (opts, args) = parser.parse_args(createargs)
    
    p,c = get_pc(opts, realconfigs())
    c.log.debug("test_real_procurement_propagate8()")
    
    procure_cls = c.get_class_by_keyword("ImageProcurement")
    procure = procure_cls(p, c)
    procure.validate()
    
    invalid_input = False
    try:
        procure.lengthy_obtain()
    except InvalidInput:
        invalid_input = True
    assert invalid_input
Example #14
0
def test_image_editing1():
    """Test for image editing module task awareness"""
    
    handle = "wrksp-911"
    createargs = ["--action", "create", 
                  "--name", handle,
                  "--images", "scp://somehost/some-base-cluster",
                  "--mnttasks",
                  "d69a9bda-399a-4016-aaee;/root/.ssh/authorized_keys;;3abc9086-d74b-46b0-a3e9;/var/nimbus-metadata-server-url",
                  "--dryrun"
                 ]
    parser = wc_optparse.parsersetup()
    (opts, args) = parser.parse_args(createargs)
    
    p,c = get_pc(opts, mockconfigs())
    c.log.debug("test_real_image_editing1()")
    
    editing_cls = c.get_class_by_keyword("ImageEditing")
    editing = editing_cls(p, c)
    editing.validate()
    
    procure_cls = c.get_class_by_keyword("ImageProcurement")
    procure = procure_cls(p, c)
    procure.validate()
    local_file_set = procure.obtain()
    
    editing.process_after_procurement(local_file_set)
    
    # TODO: could actually test for the existence of the task ... the mock
    # procurement adapter is actually making filesystem images.  But we'd first
    # need a tool to mount and check a filesystem.  And sudo would need to be
    # configured.
    
    # clean up
    procure.process_after_destroy(local_file_set)
Example #15
0
def test_real_procurement_propagate2():
    """Test that a local file will not report propagation needed.
    """
    
    handle = "wrksp-412"
    relative_filename_testfile = "some-base-cluster-01.gz"
    createargs = ["--action", "create", 
                  "--name", handle,
                  "--memory", "256",
                  "--images", "file://%s" % relative_filename_testfile,
                  "--imagemounts", "xvda1",
                 ]
    parser = wc_optparse.parsersetup()
    (opts, args) = parser.parse_args(createargs)
    
    p,c = get_pc(opts, realconfigs())
    c.log.debug("test_real_procurement_propagate2()")
    
    procure_cls = c.get_class_by_keyword("ImageProcurement")
    procure = procure_cls(p, c)
    procure.validate()
    
    try:
        filelist = [relative_filename_testfile]
        _create_fake_securedir_files(p, c, handle, filelist)
        
        assert not procure.lengthy_obtain()
        
    finally:
        _destroy_fake_securedir(p, c, handle)
Example #16
0
def test_real_procurement_unpropagate2():
    """Test the procurement adapter unpropagate syntax (negative)"""

    handle = "wrksp-414"
    createargs = [
        "--action",
        "unpropagate",
        "--name",
        handle,
        "--images",
        "file://somehost/some-base-cluster-01.gz",
    ]
    parser = wc_optparse.parsersetup()
    (opts, args) = parser.parse_args(createargs)

    p, c = get_pc(opts, realconfigs())
    c.log.debug("test_real_procurement_unpropagate2()")

    procure_cls = c.get_class_by_keyword("ImageProcurement")
    procure = procure_cls(p, c)
    procure.validate()

    invalid_input = False
    try:
        procure.lengthy_shutdown()
    except InvalidInput:
        invalid_input = True
    assert invalid_input
Example #17
0
def test_real_procurement_propagate8():
    """Test that a mismatch of images and mountpoints will cause an error
    """

    handle = "wrksp-499"
    createargs = [
        "--action",
        "create",
        "--name",
        handle,
        "--memory",
        "256",
        "--images",
        "scp://somehost/some-base-cluster-01.gz",
        "--imagemounts",
        "xvda1;;xvda2",
    ]
    parser = wc_optparse.parsersetup()
    (opts, args) = parser.parse_args(createargs)

    p, c = get_pc(opts, realconfigs())
    c.log.debug("test_real_procurement_propagate8()")

    procure_cls = c.get_class_by_keyword("ImageProcurement")
    procure = procure_cls(p, c)
    procure.validate()

    invalid_input = False
    try:
        procure.lengthy_obtain()
    except InvalidInput:
        invalid_input = True
    assert invalid_input
Example #18
0
def test_image_compress1():
    """Test file compression"""
    
    createargs = ["--action", "unpropagate", 
                  "--name", "wrksp-929",
                  "--images", "scp://somehost/some-base-cluster-01",
                  "--unproptargets", "scp://somehost/some-newfile.gz",
                  "--dryrun"
                 ]
    parser = wc_optparse.parsersetup()
    (opts, args) = parser.parse_args(createargs)
    
    p,c = get_pc(opts, realconfigs())
    c.log.debug("test_image_compress1()")
    
    procure_cls = c.get_class_by_keyword("ImageProcurement")
    procure = procure_cls(p, c)
    procure.validate()
    local_file_set = procure.obtain()
    
    editing_cls = c.get_class_by_keyword("ImageEditing")
    editing = editing_cls(p, c)
    editing.validate()
    
    editing.process_after_shutdown(local_file_set)
    procure.process_after_shutdown(local_file_set)
Example #19
0
def test_real_procurement_propagate6():
    """Test that multiple image inputs are OK
    """

    handle = "wrksp-499"
    createargs = [
        "--action",
        "create",
        "--name",
        handle,
        "--memory",
        "256",
        "--images",
        "scp://somehost/some-base-cluster-01.gz;;scp://someotherhost/someother-base-cluster-01.gz",
        "--imagemounts",
        "xvda1;;xvda2",
    ]
    parser = wc_optparse.parsersetup()
    (opts, args) = parser.parse_args(createargs)

    p, c = get_pc(opts, realconfigs())
    c.log.debug("test_real_procurement_propagate6()")

    procure_cls = c.get_class_by_keyword("ImageProcurement")
    procure = procure_cls(p, c)
    procure.validate()

    assert procure.lengthy_obtain()
Example #20
0
def test_netlease1():
    """Test network leases based on old commandline args"""

    # a direct sample from logs, trailing null business (the very first
    # contextualization impl) is ignored entirely in the new workspace-control
    arg = "publicnic;public;A2:AA:BB:2C:36:9A;Bridged;Static;"
    arg += "128.135.125.22;128.135.125.1;128.135.125.255;"
    arg += "255.255.255.0;128.135.247.50;tp-x002.ci.uchicago.edu"
    arg += ";null;null;null;null"

    parser = wc_optparse.parsersetup()
    (opts, args) = parser.parse_args(["--networking", arg])

    p, c = get_pc(opts, realconfigs())
    c.log.debug("test_netlease1()")
    netlease_cls = c.get_class_by_keyword("NetworkLease")
    netlease = netlease_cls(p, c)

    # should validate without error
    netlease.validate()

    nic = netlease.obtain("vm1", "publicnic", "public")
    assert nic
    assert nic.name == "publicnic"
    assert nic.network == "public"
    assert nic.mac == "A2:AA:BB:2C:36:9A"
    assert nic.ip == "128.135.125.22"
    assert nic.gateway == "128.135.125.1"
    assert nic.broadcast == "128.135.125.255"
    assert nic.netmask == "255.255.255.0"
    assert nic.dns == "128.135.247.50"
    assert nic.hostname == "tp-x002.ci.uchicago.edu"
Example #21
0
def test_notification2():
    """Test notification validation (negative2)"""

    createargs = [
        "--action",
        "unpropagate",
        "--name",
        "wrksp-114",
        "--images",
        "scp://somehost/some-base-cluster-01.gz",
        "--notify",
        "nimbus@somehost:22",
    ]
    parser = wc_optparse.parsersetup()
    (opts, args) = parser.parse_args(createargs)

    p, c = get_pc(opts, realconfigs())
    c.log.debug("test_notification2()")

    notify_cls = c.get_class_by_keyword("AsyncNotification")
    notify = notify_cls(p, c)

    invalid_input = False
    try:
        notify.validate()
    except InvalidInput:
        invalid_input = True
    assert invalid_input
Example #22
0
def test_mock_create():
    """Test the create command with the libvirt mock adapter"""
    
    handle = "wrksp-393"
    createargs = ["--action", "create", 
                  "--name", handle,
                  "--memory", "256",
                 ]
    parser = wc_optparse.parsersetup()
    (opts, args) = parser.parse_args(createargs)
    
    p,c = get_pc(opts, mockconfigs())
    c.log.debug("test_mock_create()")
    
    procure_cls = c.get_class_by_keyword("ImageProcurement")
    procure = procure_cls(p, c)
    procure.validate()
    local_file_set = procure.obtain()
    
    kernelpr_cls = c.get_class_by_keyword("KernelProcurement")
    kernelprocure = kernelpr_cls(p,c)
    kernelprocure.validate()
    kernel = kernelprocure.kernel_files(local_file_set)
    
    netlease_cls = c.get_class_by_keyword("NetworkLease")
    netlease = netlease_cls(p, c)
    netlease.validate()
    nic = netlease.obtain(handle, "nic1", "public")
    nicset_cls = c.get_class_by_keyword("NICSet")
    nic_set = nicset_cls([nic])
    
    platform_cls = c.get_class_by_keyword("Platform")
    platform = platform_cls(p, c)
    platform.validate()
    platform.create(local_file_set, nic_set, kernel)

    running_vm = platform.info(handle)
    assert running_vm
    
    assert running_vm.wchandle == handle
    assert running_vm.maxmem == 262144
    assert running_vm.curmem == 262144
    assert running_vm.running
    assert not running_vm.blocked
    assert not running_vm.paused
    assert not running_vm.shutting_down
    assert not running_vm.shutoff
    assert not running_vm.crashed
    
    platform.destroy(running_vm)
    
    tmp = sys.stderr
    sys.stderr = sys.stdout
    running_vm = platform.info(handle)
    assert not running_vm
    sys.stderr = tmp
    
    # clean up
    procure.process_after_destroy(local_file_set)
Example #23
0
def test_cmdline_parameters3():
    """Test cmdline parameter intake booleans"""
    parser = wc_optparse.parsersetup()
    (opts, args) = parser.parse_args(["-a", "create", "--startpaused"])
    assert opts.startpaused == True

    (opts, args) = parser.parse_args(["-a", "create"])
    assert opts.startpaused == False
Example #24
0
def test_cmdline_parameters3():
    """Test cmdline parameter intake booleans"""
    parser = wc_optparse.parsersetup()
    (opts, args) = parser.parse_args(["-a", "create", "--startpaused"])
    assert opts.startpaused == True
    
    (opts, args) = parser.parse_args(["-a", "create"])
    assert opts.startpaused == False
Example #25
0
def test_cmdline_parameters():
    """Test cmdline parameter intake error"""
    parser = wc_optparse.parsersetup()
    exc_thrown = False
    tmp = sys.stderr
    sys.stderr = sys.stdout
    try:
        # requires argument, should fail:
        (opts, args) = parser.parse_args(["--action"])
    except SystemExit:
        exc_thrown = True
    assert exc_thrown
    sys.stderr = tmp
Example #26
0
def test_cmdline_parameters():
    """Test cmdline parameter intake error"""
    parser = wc_optparse.parsersetup()
    exc_thrown = False
    tmp = sys.stderr
    sys.stderr = sys.stdout
    try:
        # requires argument, should fail:
        (opts, args) = parser.parse_args(["--action"])
    except SystemExit:
        exc_thrown = True
    assert exc_thrown
    sys.stderr = tmp
Example #27
0
def netlease_errors_common(arg, test_description):
    parser = wc_optparse.parsersetup()
    (opts, args) = parser.parse_args(["--networking", arg])
    p,c = get_pc(opts, realconfigs())
    c.log.debug(test_description)
    netlease_cls = c.get_class_by_keyword("NetworkLease")
    netlease = netlease_cls(p,c)
    
    # should not validate
    invalid_input = False
    try:
        netlease.validate()
    except InvalidInput:
        invalid_input = True
    assert invalid_input
Example #28
0
def netlease_errors_common(arg, test_description):
    parser = wc_optparse.parsersetup()
    (opts, args) = parser.parse_args(["--networking", arg])
    p, c = get_pc(opts, realconfigs())
    c.log.debug(test_description)
    netlease_cls = c.get_class_by_keyword("NetworkLease")
    netlease = netlease_cls(p, c)

    # should not validate
    invalid_input = False
    try:
        netlease.validate()
    except InvalidInput:
        invalid_input = True
    assert invalid_input
Example #29
0
def test_image_decompress1():
    """Test file decompression"""
    
    # fake image procurement chooses the file names
    createargs = ["--action", "create", 
                  "--name", "wrksp-999",
                  "--dryrun"
                 ]
    parser = wc_optparse.parsersetup()
    (opts, args) = parser.parse_args(createargs)
    
    p,c = get_pc(opts, mockconfigs())
    c.log.debug("test_image_decompress1()")
    
    procure_cls = c.get_class_by_keyword("ImageProcurement")
    procure = procure_cls(p, c)
    procure.validate()
    local_file_set = procure.obtain()
    
    editing_cls = c.get_class_by_keyword("ImageEditing")
    editing = editing_cls(p, c)
    editing.validate()
    
    # compress each disk
    oldpaths = []
    for lf in local_file_set.flist():
        # test relies on specific impl method we know is there
        oldpaths.append(lf.path)
        lf.path = editing._gzip_file_inplace(lf.path)
    
    for i,lf in enumerate(local_file_set.flist()):
        #c.log.debug("old path: %s" % oldpaths[i])
        #c.log.debug("current path: %s" % lf.path)
        assert oldpaths[i] + ".gz" == lf.path
    
    # process incoming images
    editing.process_after_procurement(local_file_set)
    
    # see if it is now uncompressed
    for i,lf in enumerate(local_file_set.flist()):
        #c.log.debug("old path: %s" % oldpaths[i])
        #c.log.debug("current path: %s" % lf.path)
        assert oldpaths[i] == lf.path
    
    # clean up
    procure.process_after_destroy(local_file_set)
Example #30
0
def test_real_procurement_unpropagate1():
    """Test the procurement adapter unpropagate awareness (positive)"""
    
    handle = "wrksp-2133"
    createargs = ["--action", "unpropagate", 
                  "--name", handle,
                  "--images", "scp://somehost/some-base-cluster-01.gz",
                 ]
    parser = wc_optparse.parsersetup()
    (opts, args) = parser.parse_args(createargs)
    
    p,c = get_pc(opts, realconfigs())
    c.log.debug("test_real_procurement_unpropagate1()")
    
    procure_cls = c.get_class_by_keyword("ImageProcurement")
    procure = procure_cls(p, c)
    procure.validate()
    assert procure.lengthy_shutdown()
Example #31
0
def test_real_procurement_unpropagate4():
    """Test the procurement adapter unpropagate with new name"""

    handle = "wrksp-2133"
    createargs = [
        "--action", "unpropagate", "--name", handle, "--images",
        "http://somehost/some-base-cluster-01.gz", "--unproptargets",
        "scp://somehost/some-base-cluster-02.gz"
    ]
    parser = wc_optparse.parsersetup()
    (opts, args) = parser.parse_args(createargs)

    p, c = get_pc(opts, mockconfigs(basename="httpenabled.conf"))
    c.log.debug("test_real_procurement_unpropagate4()")

    procure_cls = c.get_class_by_keyword("ImageProcurement")
    procure = procure_cls(p, c)
    procure.validate()
    assert procure.lengthy_shutdown()
Example #32
0
def test_image_decompress1():
    """Test file decompression"""

    # fake image procurement chooses the file names
    createargs = ["--action", "create", "--name", "wrksp-999", "--dryrun"]
    parser = wc_optparse.parsersetup()
    (opts, args) = parser.parse_args(createargs)

    p, c = get_pc(opts, mockconfigs())
    c.log.debug("test_image_decompress1()")

    procure_cls = c.get_class_by_keyword("ImageProcurement")
    procure = procure_cls(p, c)
    procure.validate()
    local_file_set = procure.obtain()

    editing_cls = c.get_class_by_keyword("ImageEditing")
    editing = editing_cls(p, c)
    editing.validate()

    # compress each disk
    oldpaths = []
    for lf in local_file_set.flist():
        # test relies on specific impl method we know is there
        oldpaths.append(lf.path)
        lf.path = editing._gzip_file_inplace(lf.path)

    for i, lf in enumerate(local_file_set.flist()):
        #c.log.debug("old path: %s" % oldpaths[i])
        #c.log.debug("current path: %s" % lf.path)
        assert oldpaths[i] + ".gz" == lf.path

    # process incoming images
    editing.process_after_procurement(local_file_set)

    # see if it is now uncompressed
    for i, lf in enumerate(local_file_set.flist()):
        #c.log.debug("old path: %s" % oldpaths[i])
        #c.log.debug("current path: %s" % lf.path)
        assert oldpaths[i] == lf.path

    # clean up
    procure.process_after_destroy(local_file_set)
Example #33
0
def test_real_procurement_unpropagate4():
    """Test the procurement adapter unpropagate with new name"""
    
    handle = "wrksp-2133"
    createargs = ["--action", "unpropagate", 
                  "--name", handle,
                  "--images", "http://somehost/some-base-cluster-01.gz",
                  "--unproptargets", "scp://somehost/some-base-cluster-02.gz"
                 ]
    parser = wc_optparse.parsersetup()
    (opts, args) = parser.parse_args(createargs)
    
    p,c = get_pc(opts, mockconfigs(basename="httpenabled.conf"))
    c.log.debug("test_real_procurement_unpropagate4()")
    
    procure_cls = c.get_class_by_keyword("ImageProcurement")
    procure = procure_cls(p, c)
    procure.validate()
    assert procure.lengthy_shutdown()
Example #34
0
def test_real_procurement_propagate3():
    """Test that an unknown propagation scheme will cause an error.
    """

    handle = "wrksp-412"
    relative_filename_testfile = "some-base-cluster-01.gz"
    createargs = [
        "--action",
        "create",
        "--name",
        handle,
        "--memory",
        "256",
        "--images",
        "zzfile://%s" % relative_filename_testfile,
        "--imagemounts",
        "xvda1",
    ]
    parser = wc_optparse.parsersetup()
    (opts, args) = parser.parse_args(createargs)

    p, c = get_pc(opts, realconfigs())
    c.log.debug("test_real_procurement_propagate3()")

    procure_cls = c.get_class_by_keyword("ImageProcurement")
    procure = procure_cls(p, c)
    procure.validate()

    try:
        filelist = [relative_filename_testfile]
        _create_fake_securedir_files(p, c, handle, filelist)

        invalid_input = False
        try:
            procure.lengthy_obtain()
        except InvalidInput:
            invalid_input = True
        assert invalid_input

    finally:
        _destroy_fake_securedir(p, c, handle)
Example #35
0
def test_real_procurement_propagate6():
    """Test that multiple image inputs are OK
    """
    
    handle = "wrksp-499"
    createargs = ["--action", "create", 
                  "--name", handle,
                  "--memory", "256",
                  "--images", "scp://somehost/some-base-cluster-01.gz;;scp://someotherhost/someother-base-cluster-01.gz",
                  "--imagemounts", "xvda1;;xvda2",
                 ]
    parser = wc_optparse.parsersetup()
    (opts, args) = parser.parse_args(createargs)
    
    p,c = get_pc(opts, realconfigs())
    c.log.debug("test_real_procurement_propagate6()")
    
    procure_cls = c.get_class_by_keyword("ImageProcurement")
    procure = procure_cls(p, c)
    procure.validate()
    
    assert procure.lengthy_obtain()
Example #36
0
def test_notification2():
    """Test notification validation (negative2)"""
    
    createargs = ["--action", "unpropagate", 
                  "--name", "wrksp-114",
                  "--images", "scp://somehost/some-base-cluster-01.gz",
                  "--notify", "nimbus@somehost:22",
                 ]
    parser = wc_optparse.parsersetup()
    (opts, args) = parser.parse_args(createargs)
    
    p,c = get_pc(opts, realconfigs())
    c.log.debug("test_notification2()")
    
    notify_cls = c.get_class_by_keyword("AsyncNotification")
    notify = notify_cls(p, c)
    
    invalid_input = False
    try:
        notify.validate()
    except InvalidInput:
        invalid_input = True
    assert invalid_input
Example #37
0
def test_real_procurement_propagate2():
    """Test that a local file will not report propagation needed.
    """

    handle = "wrksp-412"
    relative_filename_testfile = "some-base-cluster-01.gz"
    createargs = [
        "--action",
        "create",
        "--name",
        handle,
        "--memory",
        "256",
        "--images",
        "file://%s" % relative_filename_testfile,
        "--imagemounts",
        "xvda1",
    ]
    parser = wc_optparse.parsersetup()
    (opts, args) = parser.parse_args(createargs)

    p, c = get_pc(opts, realconfigs())
    c.log.debug("test_real_procurement_propagate2()")

    procure_cls = c.get_class_by_keyword("ImageProcurement")
    procure = procure_cls(p, c)
    procure.validate()

    try:
        filelist = [relative_filename_testfile]
        _create_fake_securedir_files(p, c, handle, filelist)

        assert not procure.lengthy_obtain()

    finally:
        _destroy_fake_securedir(p, c, handle)
Example #38
0
def test_real_procurement_unpropagate3():
    """Test that procurement adapter rejects blanksspace requests in unpropagate"""
    
    handle = "wrksp-414"
    createargs = ["--action", "unpropagate", 
                  "--name", handle,
                  "--images", "scp://somehost/some-base-cluster-01.gz;;blankspace://blah-size-40",
                 ]
    parser = wc_optparse.parsersetup()
    (opts, args) = parser.parse_args(createargs)
    
    p,c = get_pc(opts, realconfigs())
    c.log.debug("test_real_procurement_unpropagate3()")
    
    procure_cls = c.get_class_by_keyword("ImageProcurement")
    procure = procure_cls(p, c)
    procure.validate()
    
    invalid_input = False
    try:
        procure.lengthy_shutdown()
    except InvalidInput:
        invalid_input = True
    assert invalid_input
Example #39
0
def test_real_procurement_unpropagate2():
    """Test the procurement adapter unpropagate syntax (negative)"""
    
    handle = "wrksp-414"
    createargs = ["--action", "unpropagate", 
                  "--name", handle,
                  "--images", "file://somehost/some-base-cluster-01.gz",
                 ]
    parser = wc_optparse.parsersetup()
    (opts, args) = parser.parse_args(createargs)
    
    p,c = get_pc(opts, realconfigs())
    c.log.debug("test_real_procurement_unpropagate2()")
    
    procure_cls = c.get_class_by_keyword("ImageProcurement")
    procure = procure_cls(p, c)
    procure.validate()
    
    invalid_input = False
    try:
        procure.lengthy_shutdown()
    except InvalidInput:
        invalid_input = True
    assert invalid_input
Example #40
0
def test_cmdline_parameters2():
    """Test cmdline parameter intake success"""
    parser = wc_optparse.parsersetup()
    (opts, args) = parser.parse_args(["-a", "create"])
    assert opts.action != None
Example #41
0
def test_mock_create():
    """Test the create command with the libvirt mock adapter"""

    handle = "wrksp-393"
    createargs = [
        "--action",
        "create",
        "--name",
        handle,
        "--memory",
        "256",
    ]
    parser = wc_optparse.parsersetup()
    (opts, args) = parser.parse_args(createargs)

    p, c = get_pc(opts, mockconfigs())
    c.log.debug("test_mock_create()")

    procure_cls = c.get_class_by_keyword("ImageProcurement")
    procure = procure_cls(p, c)
    procure.validate()
    local_file_set = procure.obtain()

    kernelpr_cls = c.get_class_by_keyword("KernelProcurement")
    kernelprocure = kernelpr_cls(p, c)
    kernelprocure.validate()
    kernel = kernelprocure.kernel_files(local_file_set)

    netlease_cls = c.get_class_by_keyword("NetworkLease")
    netlease = netlease_cls(p, c)
    netlease.validate()
    nic = netlease.obtain(handle, "nic1", "public")
    nicset_cls = c.get_class_by_keyword("NICSet")
    nic_set = nicset_cls([nic])

    platform_cls = c.get_class_by_keyword("Platform")
    platform = platform_cls(p, c)
    platform.validate()
    platform.create(local_file_set, nic_set, kernel)

    running_vm = platform.info(handle)
    assert running_vm

    assert running_vm.wchandle == handle
    assert running_vm.maxmem == 262144
    assert running_vm.curmem == 262144
    assert running_vm.running
    assert not running_vm.blocked
    assert not running_vm.paused
    assert not running_vm.shutting_down
    assert not running_vm.shutoff
    assert not running_vm.crashed

    platform.destroy(running_vm)

    tmp = sys.stderr
    sys.stderr = sys.stdout
    running_vm = platform.info(handle)
    assert not running_vm
    sys.stderr = tmp

    # clean up
    procure.process_after_destroy(local_file_set)
Example #42
0
def test_cmdline_parameters2():
    """Test cmdline parameter intake success"""
    parser = wc_optparse.parsersetup()
    (opts, args) = parser.parse_args(["-a", "create"])
    assert opts.action != None