Exemple #1
0
def test_address_space():
    a = AddressSpace(["192.168.0.0/24"])
    expected = {'addressPrefixes': ['192.168.0.0/24']}
    assert dump(a) == expected

    a = AddressSpace(addressPrefixes=["192.168.0.0/24"])
    expected = {'addressPrefixes': ['192.168.0.0/24']}
    assert dump(a) == expected
Exemple #2
0
def test_dump():

    assert dump("foo") == "foo"
    assert dump(2) == 2

    t = Template()
    d = dump(t)
    expected = {'$schema': 'https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#', 
                'contentVersion': '1.0.0.0',
                'resources': []}
    assert d == expected
Exemple #3
0
def test_security_rule():
    rule = SecurityRule(name="rule1",
                        protocol="*",
                        sourcePortRange="*",
                        destinationPortRange="*",
                        sourceAddressPrefix="*",
                        destinationAddressPrefix="*",
                        access="ALLOW",
                        priority=2000,
                        direction='Inbound')

    expected = {"name": "rule1",
                "properties": {
                    "protocol": "*",
                    "sourcePortRange": "*",
                    "destinationPortRange": "*",
                    "sourceAddressPrefix": "*",
                    "destinationAddressPrefix": "*",
                    "access": "ALLOW",
                    "priority": 2000,
                    "direction": "Inbound"
                }
                }

    assert dump(rule) == expected
Exemple #4
0
def test_network_security_group():
    nsg = NetworkSecurityGroup("nsg1")
    # FIXME properties.securityRules is required
    expected = {'apiVersion': '2016-03-30',
                'type': 'Microsoft.Network/networkSecurityGroups',
                'name': 'nsg1',
                'location': '[resourceGroup().location]'}

    assert dump(nsg) == expected

    rule = SecurityRule(name="rule1",
                        protocol="*",
                        sourcePortRange="*",
                        destinationPortRange="*",
                        sourceAddressPrefix="*",
                        destinationAddressPrefix="*",
                        access="ALLOW",
                        priority=2000,
                        direction='Inbound')

    nsg = NetworkSecurityGroup("nsg1", securityRules=[rule])

    expected = {'apiVersion': '2016-03-30',
                'type': 'Microsoft.Network/networkSecurityGroups',
                'name': 'nsg1',
                'location': '[resourceGroup().location]',
                'properties': {
                    'securityRules': [
                        {"name": "rule1",
                         "properties": {
                             "protocol": "*",
                             "sourcePortRange": "*",
                             "destinationPortRange": "*",
                             "sourceAddressPrefix": "*",
                             "destinationAddressPrefix": "*",
                             "access": "ALLOW",
                             "priority": 2000,
                             "direction": "Inbound"
                         }
                         }
                    ]
                }
                }
    assert dump(nsg) == expected
Exemple #5
0
def test_subnet():
    sn = Subnet("default", addressPrefix="192.168.0.1/24")

    expected = {
        "name": "default",
        "properties": {
            "addressPrefix": "192.168.0.1/24"
        }
    }
    assert dump(sn) == expected
Exemple #6
0
def test_network_interface_dns_setting():
    dns = NetworkInterfaceDnsSetting(dnsServers=["8.8.8.8"],
                                     internalDnsNameLabel="host.local")
    expected = {
        "dnsServers": [
            "8.8.8.8"
        ],
        "internalDnsNameLabel": "host.local"
    }

    assert dump(dns) == expected
Exemple #7
0
def test_vnet():
    vnet = VirtualNetwork(name="vnet1",
                          addressSpace=AddressSpace(["192.168.0.0/24"]))

    expected = {
        'apiVersion': '2016-03-30',
        'type': 'Microsoft.Network/virtualNetworks',
        'name': 'vnet1',
        'location': '[resourceGroup().location]',
        'properties': {
            'addressSpace': {
                'addressPrefixes': ['192.168.0.0/24']}}}
    assert dump(vnet) == expected
Exemple #8
0
def test_public_ip_address():
    ip = PublicIPAddress(name="testip",
                         publicIPAllocationMethod="Dynamic",
                         idleTimeoutInMinutes=4)

    expected = {
        "apiVersion": "2016-03-30",
        "type": "Microsoft.Network/publicIPAddresses",
        "name": "testip",
        "location": "[resourceGroup().location]",
        "properties": {
            "publicIPAllocationMethod": "Dynamic",
            "idleTimeoutInMinutes": 4
        }
    }
    assert dump(ip) == expected
Exemple #9
0
def test_datadisk():
    dd = DataDisk(name="datadisk0",
                  diskSizeGB=1000,
                  createOption="Empty",
                  caching="None",
                  lun=0,
                  vhd=VirtualHardDisk("uri"))

    expected = {
        "name": "datadisk0",
        "diskSizeGB": 1000,
        "lun": 0,
        "vhd": {
            "uri": "uri"
        },
        "caching": "None",
        "createOption": "Empty"
    }
    assert dump(dd) == expected
Exemple #10
0
def test_template():
    sa = StorageAccount(name="storage-1", location="westeurope", sku={"name": "Standard_RAGRS"}, kind='Storage')
    t = Template(resources=[sa])
    expected = {'$schema': 'https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#', 
                'contentVersion': '1.0.0.0', 
                'resources': [
                    {
                        "type": "Microsoft.Storage/storageAccounts",
                        "name": "storage-1",
                        "apiVersion": "2016-01-01",
                        "location": "westeurope",
                        "sku": {
                            "name": "Standard_RAGRS"
                        },
                        "kind": "Storage"
                    }
                    
                    ]}
    assert dump(t) == expected
Exemple #11
0
def test_osdisk():
    od = OSDisk(name="osdisk",
                image={"uri": "uri"},
                caching="None",
                createOption="FromImage",
                vhd=VirtualHardDisk("uri"),
                osType="Linux")

    expected = {
        "name": "osdisk",
        "vhd": {
            "uri": "uri"
        },
        "osType": "Linux",
        "image": {
            "uri": "uri"
        },
        "caching": "None",
        "createOption": "FromImage"
    }
    assert dump(od) == expected
Exemple #12
0
def test_ip_configuration():
    ipc = IpConfiguration(
        name="testhost",
        subnet=Id("test"),
        privateIPAllocationMethod="Static",
        privateIPAddress="192.168.0.2",
        publicIPAddress=Id("public_ip"))

    expected = {
        "name": "testhost",
        "properties": {
            "subnet": {
                "id": "test"
            },
            "privateIPAddress": "192.168.0.2",
            "privateIPAllocationMethod": "Static",
            "publicIPAddress": {
                "id": "public_ip"
            }
        }
    }
    assert dump(ipc) == expected
Exemple #13
0
def test_storage():
    sku = Sku(name="Standard_LRS")
    assert dump(sku) == {"name": "Standard_LRS"}

    sa = StorageAccount("teststorage", sku=sku, kind="Storage")
    assert dump(sa) == {
        'name': 'teststorage',
        'type': 'Microsoft.Storage/storageAccounts',
        'apiVersion': '2016-01-01',
        'location': "[resourceGroup().location]",
        'sku': {
            'name': 'Standard_LRS'
        },
        'kind': 'Storage'
    }

    sa = StorageAccount("teststorage",
                        sku=sku,
                        description="Test Account",
                        kind="Storage")
    assert dump(sa) == {
        'name': 'teststorage',
        'type': 'Microsoft.Storage/storageAccounts',
        'apiVersion': '2016-01-01',
        'location': "[resourceGroup().location]",
        'sku': {
            'name': 'Standard_LRS'
        },
        'description': 'Test Account',
        'kind': 'Storage'
    }

    sa = StorageAccount("teststorage",
                        sku=sku,
                        tags={"env": "Production"},
                        kind='Storage')
    assert dump(sa) == {
        'name': 'teststorage',
        'type': 'Microsoft.Storage/storageAccounts',
        'apiVersion': '2016-01-01',
        'location': "[resourceGroup().location]",
        'sku': {
            'name': 'Standard_LRS'
        },
        'tags': {
            'env': 'Production'
        },
        'kind': 'Storage'
    }

    sa = StorageAccount(name="storage-1",
                        location="westeurope",
                        sku={"name": "Standard_RAGRS"},
                        kind='Storage')
    expected = {
        "type": "Microsoft.Storage/storageAccounts",
        "apiVersion": "2016-01-01",
        "location": "westeurope",
        "name": "storage-1",
        "sku": {
            "name": "Standard_RAGRS"
        },
        "kind": "Storage"
    }
    assert dump(sa) == expected
Exemple #14
0
def test_resource():
    t = Resource()
    expected = {}
    assert dump(t) == expected
Exemple #15
0
def test_vhd():
    vhd = VirtualHardDisk(
        uri="https://storage.blob.core.windows.net/vhds/osdisk.vhd")

    expected = {"uri": "https://storage.blob.core.windows.net/vhds/osdisk.vhd"}
    assert dump(vhd) == expected
Exemple #16
0
def test_network_profile():
    network_profile = NetworkProfile([{"id": "resourceid"}])

    expected = {"networkInterfaces": [{"id": "resourceid"}]}
    assert dump(network_profile) == expected
Exemple #17
0
def test_id():
    i = Id("foo")
    expected = {
        "id": "foo"
    }
    assert dump(i) == expected