Exemple #1
0
def test_add_vim(adaptor: VimAdaptor, connection: Connection,
                 mocked_aws_resource_utilization):
    def add_vim(payload: dict):
        response = connection.call_sync(
            "infrastructure.management.compute.add", payload)
        assert response is not None
        return response.payload

    assert S({
        "request_status": "ERROR",
        "message": All(str, Contains("type"))
    }) == add_vim({})

    assert S({
        "request_status": "ERROR",
        "message": All(str, Contains("city"), Contains("access_key")),
    }) == add_vim({"type": "aws"})

    # Add OpenStack with missing tenant.external_network_id and
    # tenant.external_router_id
    assert S({
        "request_status":
        "ERROR",
        "message":
        All(str, Contains("external_network_id"),
            Contains("external_router_id")),
    }) == add_vim({
        "type": "openstack",
        "name": "OpenStack",
        "country": "my country",
        "city": "my city",
        "username": "******",
        "password": "******",
        "tenant": {
            "id": "tenant id"
        },
    })

    assert S({
        "request_status": "COMPLETED",
        "id": str
    }) == add_vim({
        "type": "aws",
        "name": "aws",
        "country": "my country",
        "city": "my city",
        "access_key": "access key",
        "secret_key": "secret key",
        "region": "region",
    })
Exemple #2
0
def test_contains():
    """Verify contains validation method."""
    schema = Schema({'color': Contains('red')})
    schema({'color': ['blue', 'red', 'yellow']})
    try:
        schema({'color': ['blue', 'yellow']})
    except Invalid as e:
        assert_equal(str(e),
                     "value is not allowed for dictionary value @ data['color']")
]

schemas = {
    'repos': [
        {
            Required('name'): str,
            'sortname': str,
            'singular': str,
            Required('type'): Any('repository', 'site', 'modules'),
            Required('desc'): str,
            'statsgroup': str,
            Required('family'): Any(*families),
            'ruleset': Any(Any(*rulesets), [Any(*rulesets)]),  # XXX: make required
            'color': str,
            'valid_till': date,
            'default_maintainer': All(str, Contains('@')),
            'update_period': Any(int, str),
            Required('minpackages'): int,
            Required('sources'): [
                {
                    Required('name'): Any(str, [str]),
                    'disabled': bool,

                    'subrepo': str,

                    Required('fetcher'): {
                        Required('class'): str,

                        'url': str,  # not Url(), as there may be rsync or cvs addresses

                        # git
Exemple #4
0
        Required('type'):
        Any('repository', 'site', 'modules'),
        Required('desc'):
        str,
        'statsgroup':
        str,
        Required('family'):
        Any(*families),
        'ruleset':
        Any(Any(*rulesets), [Any(*rulesets)]),  # XXX: make required
        'color':
        str,
        'valid_till':
        date,
        'default_maintainer':
        All(str, Contains('@')),
        'update_period':
        Any(int, str),
        Required('minpackages'):
        int,
        Required('sources'): [{
            Required('name'): Any(str, [str]),
            'disabled': bool,
            'subrepo': str,
            Required('fetcher'): {
                Required('class'): str,
                'url':
                str,  # not Url(), as there may be rsync or cvs addresses

                # git
                'branch': str,
        'singular':
        str,
        Required('type'):
        Any('repository', 'site', 'modules'),
        Required('desc'):
        str,
        Required('family'):
        Any(*families),
        'ruleset':
        Any(Any(*rulesets), [Any(*rulesets)]),  # XXX: make required
        'color':
        str,
        'valid_till':
        date,
        'default_maintainer':
        Any(bool, 'auto', All(str, Contains('@'))),
        Required('minpackages'):
        int,
        Required('sources'): [{
            Required('name'): Any(str, [str]),
            'disabled': bool,
            Required('fetcher'): str,
            Required('parser'): str,
            'url': str,  # not Url(), as there may be rsync or cvs addresses

            # git fetcher args
            'branch': str,
            'subrepo': str,
            'sparse_checkout': [str],

            # some common fetcher args