import os
from nova_volume_testing.util.novaexerciser import Volume, Instance

if __name__ == "__main__":
    print "004 Test pre-existing volumes - Make sure volumes from before the "\
          "upgrade still work"
    if 'BOCK_TEST_VOLUMES' in os.environ:
        #
        # Make a list of volume id's, one from each line in the volumes file.
        # Then make a list of volume objects from each volume id.
        vol_list = [l.strip() for l in file(os.environ['BOCK_TEST_VOLUMES'])]
        volumes = [Volume(volume_id=v_id) for v_id in vol_list]

        if len(volumes) > 0:
            print 'Testing %s volumes' % len(volumes)

            instance = Instance()
            for volume in volumes:
                assert volume.attached() == False
                volume.attach(instance)
                assert volume.attached(instance) == True
                assert volume.check_mount_device() == True
                volume.detach()
                assert volume.attached() == False
            instance.delete()
        else:
            print "There are no volumes listed in %s" % \
                                            os.environ['BOCK_TEST_VOLUMES']
    else:
        print 'The environment variable BOCK_TEST_VOLUMES is not set'
          "instance, check the data"
    instance1 = Instance()
    instance2 = Instance()
    volume = Volume(size=1)

    assert volume.attached() == False

    volume.attach(instance1)
    assert volume.attached() == True
    assert volume.attached(instance1) == True

    volume.write_test_pattern()
    assert volume.check_test_pattern() == True
    assert volume.check_test_pattern(key=16) == False

    volume.detach()
    assert volume.attached() == False

    volume.attach(instance2)
    assert volume.attached(instance2) == True
    assert volume.check_test_pattern() == True
    volume.write_test_pattern(key=16)
    assert volume.check_test_pattern(key=16) == True

    volume.detach()
    assert volume.attached() == False

    volume.delete()
    instance1.delete()
    instance2.delete()
예제 #3
0
    volume.write_test_pattern(key=3)
    assert volume.check_test_pattern(key=3) == True
    assert snapvol.check_test_pattern(key=2) == True
    snapvol.detach()
    assert snapvol.attached() == False

    snapshot2 = Snapshot(snapvol)
    snapvol2 = Volume(snapshot=snapshot2)
    snapvol2.attach(instance)
    assert snapvol2.check_test_pattern(key=2) == True
    snapvol2.write_test_pattern(key=4)
    assert snapvol2.check_test_pattern(key=4) == True
    snapvol.attach(instance)
    assert snapvol.attached() == True
    assert snapvol.check_test_pattern(key=2) == True
    assert volume.check_test_pattern(key=3) == True

    volume.detach()
    assert volume.attached() == False
    snapvol.detach()
    assert snapvol.attached() == False
    snapvol2.detach()
    assert snapvol2.attached() == False

    snapvol2.delete()
    snapshot2.delete()
    snapvol.delete()
    snapshot.delete()
    volume.delete()
    instance.delete()
          "instance, check the data"
    instance1 = Instance()
    instance2 = Instance()
    volume = Volume(size=1)

    assert volume.attached() == False

    volume.attach(instance1)
    assert volume.attached() == True
    assert volume.attached(instance1) == True

    volume.write_test_pattern()
    assert volume.check_test_pattern() == True
    assert volume.check_test_pattern(key=16) == False

    volume.detach()
    assert volume.attached() == False

    volume.attach(instance2)
    assert volume.attached(instance2) == True
    assert volume.check_test_pattern() == True
    volume.write_test_pattern(key=16)
    assert volume.check_test_pattern(key=16) == True

    volume.detach()
    assert volume.attached() == False

    volume.delete()
    instance1.delete()
    instance2.delete()