Exemplo n.º 1
0
def test_launch(get_parsed_doc, wait_for_stack_complete,
                print_stack, cloud_fixture, minimum_config_fixture):
    (get_cloud, get_hostname, create_security_group) = cloud_fixture
    cloud = get_cloud.return_value
    unique_name = get_hostname.return_value

    get_parsed_doc.return_value = '{"this": "should be", "json": "compatible"}'

    instance = Mock(name='instance')
    stack = Mock(name='stack')
    stack.get_instances.return_value = [instance]
    cloud.launch_stack.return_value = stack

    params = Mock(stack_name='stackname', template_uri=None,
                  template_params=None, create_images=False,
                  delete_after_complete=False, quiet=False)

    desired_template_uri = 'do-want-this'
    config.CLOUD.update({
        'ORCHESTRATION_TEMPLATE_URIS': {
            'default': 'dont-want-this',
            'stackname': desired_template_uri,
        }
    })
    launch(params)

    assert get_hostname.called
    assert_called_with(get_parsed_doc, unique_name, desired_template_uri,
                       'ORCHESTRATION_TEMPLATE_PARAMS', None)
    assert cloud.launch_stack.called
    assert instance.create_dns_entries_from_tag.called
    assert wait_for_stack_complete.called
    assert print_stack.called
Exemplo n.º 2
0
def test_delete_ok(cloud_fixture):

    image = Mock(image_name='image_name')
    cloud_fixture.get_image_by_name.return_value = image

    params = Mock(image_name='image_name')
    image_delete(params)

    assert_called_with(cloud_fixture.delete_image, image)
Exemplo n.º 3
0
def test_image_creation(cloud_fixture):
    (get_cloud, get_hostname, create_security_group) = cloud_fixture
    cloud = get_cloud.return_value

    instance = Mock(name='instance')
    cloud.get_instance_by_name.return_value = instance

    params = Mock(instance_name='instancename', image_name='imagename')
    image_create(params)

    assert_called_with(
        cloud.get_instance_by_name, 'instancename', 'imagename')
Exemplo n.º 4
0
def test_terminate(get_current_cloud, show_delete_progress):
    instance = Mock(name="instance")
    stack = Mock(name="stack")
    stack.get_instances.return_value = [instance]

    cloud = Mock(name="cloud")
    cloud.get_stack.return_value = stack
    get_current_cloud.return_value = cloud

    params = Mock(stack_name='stackname')
    terminate(params)

    assert_called_with(cloud.get_stack, 'stackname')
    assert instance.delete_dns_entries.called
    assert stack.delete.called
    assert show_delete_progress.called
Exemplo n.º 5
0
def test_arg_specified_url_source(req, minimum_config_fixture):
    """ Test that a user data file can be specified from cloud configuration
    and then rendered with config and argument based parameters"""

    hostname = 'staging-test-host-001'

    desired_subs = {
        'key_1': 'config_value_1',
        'key_2': 'argument_value_2',
        'hostname': hostname,
    }

    config_params = {
        'key_1': 'config_value_1',
        'key_2': 'config_value_2',
    }
    config_ud_url = 'http://this.should.not.be.requested.com/user-data.txt'
    config.get_cloud().update({
        'DEFAULT_USER_DATA': config_ud_url,
        'USER_DATA_PARAMS': config_params,
    })

    cli_params = csv_dict('key_2=argument_value_2')
    cli_uri = 'http://this.should.be.requested.com/user-data.txt'
    uri = config.get_cloud_config_value('DEFAULT_USER_DATA', override=cli_uri)

    ud_contents = ""
    for key in desired_subs.keys():
        ud_contents += "{{%s}} " % key
    req.return_value = Mock(text=ud_contents, status_code=200)

    user_data = get_parsed_document(entity_name=hostname,
                                    uri=uri,
                                    config_params_key='USER_DATA_PARAMS',
                                    additional_params=cli_params)

    assert_called_with(req, uri)
    for value in desired_subs.values():
        assert value in user_data
Exemplo n.º 6
0
def test_arg_specified_url_source(req, minimum_config_fixture):
    """ Test that a user data file can be specified from cloud configuration
    and then rendered with config and argument based parameters"""

    hostname = 'staging-test-host-001'

    desired_subs = {
        'key_1': 'config_value_1',
        'key_2': 'argument_value_2',
        'hostname': hostname,
    }

    config_params = {
        'key_1': 'config_value_1',
        'key_2': 'config_value_2',
    }
    config_ud_url = 'http://this.should.not.be.requested.com/user-data.txt'
    config.get_cloud().update({
        'DEFAULT_USER_DATA': config_ud_url,
        'USER_DATA_PARAMS': config_params,
    })

    cli_params = csv_dict('key_2=argument_value_2')
    cli_uri = 'http://this.should.be.requested.com/user-data.txt'
    uri = config.get_cloud_config_value('DEFAULT_USER_DATA', override=cli_uri)

    ud_contents = ""
    for key in desired_subs.keys():
        ud_contents += "{{%s}} " % key
    req.return_value = Mock(text=ud_contents, status_code=200)

    user_data = get_parsed_document(entity_name=hostname, uri=uri,
                                    config_params_key='USER_DATA_PARAMS',
                                    additional_params=cli_params)

    assert_called_with(req, uri)
    for value in desired_subs.values():
        assert value in user_data