Пример #1
0
def test_dict_serde():
    instance = Instance("1.1.1.1", uid="i-123", port=2222, username="******", keypair="~/.ssh/key")

    data = instance.to_dict()

    instance2 = Instance.from_dict(data)
    assert instance2.ip == "1.1.1.1"
    assert instance2.uid == "i-123"
    assert instance2.port == 2222
    assert instance2.username == "user"
    assert instance2.keypair == "~/.ssh/key"
Пример #2
0
def test_instance():
    instance = Instance("0.0.0.0")
    assert instance.ip == "0.0.0.0"
    assert instance.port == 22

    instance = Instance("1.1.1.1",
                        uid="i-123",
                        port=2222,
                        username="******",
                        keypair="~/.ssh/key")
    assert instance.ip == "1.1.1.1"
    assert instance.uid == "i-123"
    assert instance.port == 2222
    assert instance.username == "user"
    assert instance.keypair == "~/.ssh/key"
Пример #3
0
def test_dict_serde():
    instance = Instance("1.1.1.1",
                        uid="i-123",
                        port=2222,
                        username="******",
                        keypair="~/.ssh/key")

    data = instance.to_dict()

    instance2 = Instance.from_dict(data)
    assert instance2.ip == "1.1.1.1"
    assert instance2.uid == "i-123"
    assert instance2.port == 2222
    assert instance2.username == "user"
    assert instance2.keypair == "~/.ssh/key"
Пример #4
0
def test_from_filepath(request, tmpdir):
    import os
    testname = request.node.name
    tempdir = tmpdir.mkdir("rootdir")
    fpath = os.path.join(tempdir.strpath, "{}.yaml".format(testname))

    cluster = Cluster("foo")
    username = "******"
    keypair = "~/.ssh/key"
    n = 5
    for i in range(n):
        instance = Instance(uid="%i" % i,
                            ip="{0}.{0}.{0}.{0}".format(i),
                            username=username,
                            keypair=keypair)
        cluster.append(instance)

    cluster.to_file(fpath)

    cluster2 = Cluster.from_filepath(fpath)

    assert len(cluster2.instances) == n
    assert len(cluster.instances) == len(cluster2.instances)
    for i, instance in enumerate(cluster2.instances):
        assert instance.uid == "%i" % i
        assert instance.ip == "{0}.{0}.{0}.{0}".format(i)
        assert instance.username == username
        assert instance.keypair == keypair
Пример #5
0
def test_append_instance():
    cluster = Cluster("foo")
    n = 5
    for i in range(n):
        instance = Instance(ip="%i" % i)
        cluster.append(instance)
    assert len(cluster.instances) == n

    assert cluster.head == cluster.instances[0]
Пример #6
0
def test_set_keypair():
    cluster = Cluster("foo")
    n = 5
    for i in range(n):
        instance = Instance(ip="%i" % i)
        cluster.append(instance)
        assert cluster.instances[i].keypair is None

    pkey = "ubuntu"
    cluster.set_keypair(pkey)

    for i in range(n):
        assert cluster.instances[i].keypair == pkey
Пример #7
0
def test_set_username():
    cluster = Cluster("foo")
    n = 5
    for i in range(n):
        instance = Instance(ip="%i" % i)
        cluster.append(instance)
        assert cluster.instances[i].username is None

    user = "******"
    cluster.set_username(user)

    for i in range(n):
        assert cluster.instances[i].username == user
Пример #8
0
def test_from_boto3(driver):
    from dask_ec2.ec2 import DEFAULT_SG_GROUP_NAME
    name = "test_launch"
    ami = "ami-a8d2d7ce"
    instance_type = "m3.2xlarge"
    keyname = "mykey"
    keypair = None  # Skip check
    volume_type = "gp2"
    volume_size = 500

    driver.ec2.create_key_pair(KeyName=keyname)
    instances = driver.launch(name=name,
                              image_id=ami,
                              instance_type=instance_type,
                              count=1,
                              keyname=keyname,
                              security_group_name=DEFAULT_SG_GROUP_NAME,
                              volume_type=volume_type,
                              volume_size=volume_size,
                              keypair=keypair,
                              check_ami=False)

    Instance.from_boto3_instance(instances[0])
Пример #9
0
def test_dict_serde():
    cluster = Cluster("foo")
    username = "******"
    keypair = "~/.ssh/key"
    n = 5
    for i in range(n):
        instance = Instance(uid="%i" % i,
                            ip="{0}.{0}.{0}.{0}".format(i),
                            username=username,
                            keypair=keypair)
        cluster.append(instance)

    data = cluster.to_dict()
    cluster2 = Cluster.from_dict(data)
    assert len(cluster2.instances) == n

    for i, instance in enumerate(cluster2.instances):
        assert instance.uid == "%i" % i
        assert instance.ip == "{0}.{0}.{0}.{0}".format(i)
        assert instance.username == username
        assert instance.keypair == keypair
Пример #10
0
def test_from_boto3(driver):
    from dask_ec2.ec2 import DEFAULT_SG_GROUP_NAME
    name = "test_launch"
    ami = "ami-d05e75b8"
    instance_type = "m3.2xlarge"
    keyname = "mykey"
    keypair = None    # Skip check
    volume_type = "gp2"
    volume_size = 500
    security_group = "another-sg"

    driver.ec2.create_key_pair(KeyName=keyname)
    instances = driver.launch(name=name,
                              image_id=ami,
                              instance_type=instance_type,
                              count=1,
                              keyname=keyname,
                              security_group_name=DEFAULT_SG_GROUP_NAME,
                              volume_type=volume_type,
                              volume_size=volume_size,
                              keypair=keypair,
                              check_ami=False)

    instance = Instance.from_boto3_instance(instances[0])