Exemplo n.º 1
0
def test_launch_app__exception_run_instances():
    aws_ec2_ami_launcher = AwsEc2AMILauncher()
    aws_ec2_ami_launcher.ec2_client = MagicMock()
    app = {"app_name": "ghost"}
    response = MagicMock()
    aws_ec2_ami_launcher.ec2_client.run_instances.side_effect = Exception
    with pytest.raises(Exception):
        aws_ec2_ami_launcher.launch_app(app)
Exemplo n.º 2
0
def test_get_launch_returns_pending():
    aws_ec2_ami_launcher = AwsEc2AMILauncher()
    aws_ec2_ami_launcher.ec2_client = MagicMock()
    instance = {"State": {"Name": "pending"}}
    reservation = [{"Instances": [instance]}]
    response = MagicMock()
    response.get.return_value = reservation
    aws_ec2_ami_launcher.ec2_client.describe_instances.return_value = response
    assert aws_ec2_ami_launcher.get_launch_status(MagicMock()) == {
        "status": "pending"
    }
Exemplo n.º 3
0
def test_get_launch_returns_running():
    aws_ec2_ami_launcher = AwsEc2AMILauncher()
    aws_ec2_ami_launcher.ec2_client = MagicMock()
    instance = {"State": {"Name": "running"}, "PublicDnsName": '1.2.3.4'}
    reservation = [{"Instances": [instance]}]
    response = MagicMock()
    response.get.return_value = reservation
    aws_ec2_ami_launcher.ec2_client.describe_instances.return_value = response
    assert aws_ec2_ami_launcher.get_launch_status(MagicMock()) == {
        "status": "running",
        "url": "http://1.2.3.4"
    }
Exemplo n.º 4
0
def test_launch_app__runs_ok():
    aws_ec2_ami_launcher = AwsEc2AMILauncher()
    aws_ec2_ami_launcher.ec2_client = MagicMock()
    app = {"app_name": "ghost"}
    response = MagicMock()
    aws_ec2_ami_launcher.ec2_client.run_instances.return_value = response
    assert response["Instances"][0][
        "InstanceId"] == aws_ec2_ami_launcher.launch_app(app)
    image_id = aws_ec2_ami_launcher.REGISTERED_AMIS.get('ghost')
    aws_ec2_ami_launcher.ec2_client.run_instances.assert_called_with(
        ImageId=image_id,
        MinCount=ANY,
        MaxCount=ANY,
        InstanceType=ANY,
        KeyName=ANY)
Exemplo n.º 5
0
from cloud_handler.adapters import AwsEc2AMILauncher
from frontend_handlers.adapters import ApiFrontendAdapter
from launcher import Launcher

if __name__ == '__main__':
    aws_ec2_ami_adapter = AwsEc2AMILauncher()
    launcher = Launcher(aws_ec2_ami_adapter)
    api = ApiFrontendAdapter()
    api.add_launch_app_callback(launcher.launch_app)
    api.add_get_launch_status_callback(launcher.check_app_launch)
    api.run()


from time import sleep

from cloud_handler.adapters import AwsEc2AMILauncher
from entities import App

if __name__ == '__main__':
    ec2_ami_launcher = AwsEc2AMILauncher()
    app = App('ghost', None)
    launch_id = ec2_ami_launcher.launch_app(app.as_dict())
    print(launch_id)
    sleep(5)
    while True:
        response = ec2_ami_launcher.get_launch_status(launch_id)
        print(response)
        if response['status'] == 'running':
            break
        sleep(4)

Exemplo n.º 7
0
def test_get_launch_exception():
    aws_ec2_ami_launcher = AwsEc2AMILauncher()
    aws_ec2_ami_launcher.ec2_client = MagicMock()
    aws_ec2_ami_launcher.ec2_client.describe_instaces.side_effect = Exception
    with pytest.raises(Exception):
        assert aws_ec2_ami_launcher.get_launch_status(MagicMock())
Exemplo n.º 8
0
def test_awsec2amilauncher_constructor():
    aws_ec2_ami_launcher = AwsEc2AMILauncher()
Exemplo n.º 9
0
def test_launch_app__no_image_id():
    aws_ec2_ami_launcher = AwsEc2AMILauncher()
    aws_ec2_ami_launcher.ec2_client = MagicMock()
    app = {"app_name": "app_not_known"}
    assert aws_ec2_ami_launcher.launch_app(app) is None
    aws_ec2_ami_launcher.ec2_client.run_instances.assert_not_called()