def test_update_dpg_in_vm_models(vm_service, vm_model, vm_model_2, database):
    database.add_vm_model(vm_model)
    database.add_vm_model(vm_model_2)

    assert len(vm_model.dpg_models) == 1
    assert len(vm_model_2.dpg_models) == 1

    dpg_model = list(vm_model.dpg_models)[0]
    assert dpg_model.vlan_id == 5
    dpg_model = list(vm_model_2.dpg_models)[0]
    assert dpg_model.vlan_id == 15

    dpg_model = models.DistributedPortGroupModel(
        models.generate_uuid("dvportgroup-1"),
        "dvportgroup-1",
        "dpg-1",
        6,
        "dvs-1",
    )
    vm_service.update_dpg_in_vm_models(dpg_model)

    dpg_model = list(vm_model.dpg_models)[0]
    assert dpg_model.vlan_id == 6
    dpg_model = list(vm_model_2.dpg_models)[0]
    assert dpg_model.vlan_id == 15
示例#2
0
def dpg_model():
    return models.DistributedPortGroupModel(
        uuid=models.generate_uuid("dvportgroup-1"),
        key="dvportgroup-1",
        name="dpg-1",
        vlan_id=5,
        dvs_name="dvs-1",
    )
示例#3
0
def test_has_interface_in_dpg(vm_model):
    dpg_model_1 = models.DistributedPortGroupModel(
        models.generate_uuid("dvportgroup-1"),
        "dvportgroup-1",
        "dpg-1",
        5,
        "dvs-1",
    )
    assert vm_model.has_interface_in_dpg(dpg_model_1)
    dpg_model_2 = models.DistributedPortGroupModel(
        models.generate_uuid("dvportgroup-2"),
        "dvportgroup-2",
        "dpg-2",
        6,
        "dvs-1",
    )
    assert not vm_model.has_interface_in_dpg(dpg_model_2)
示例#4
0
def test_attach_dpg(vm_model):
    dpg_model = models.DistributedPortGroupModel(
        models.generate_uuid("dvportgroup-2"),
        "dvportgroup-2",
        "dpg-2",
        6,
        "dvs-1",
    )
    vm_model.attach_dpg(dpg_model)
    assert len(vm_model.dpg_models) == 2
    assert sorted(dpg.name for dpg in vm_model.dpg_models) == [
        "dpg-1",
        "dpg-2",
    ]
def test_create_fabric_vn(dpg_service, vnc_api_client, project, database):
    dpg_model = models.DistributedPortGroupModel(
        uuid="5a6bd262-1f96-3546-a762-6fa5260e9014",
        key="dvportgroup-1",
        name="dpg-1",
        vlan_id=None,
        dvs_name="dvs-1",
    )

    dpg_service.create_fabric_vn(dpg_model)

    created_vn = vnc_api_client.create_vn.call_args[0][0]
    assert created_vn.name == "dvs-1_dpg-1"
    assert created_vn.uuid == "5a6bd262-1f96-3546-a762-6fa5260e9014"
    assert created_vn.parent_name == project.name
示例#6
0
def test_to_vnc_vn(project):
    dpg_model = models.DistributedPortGroupModel(
        uuid=models.generate_uuid("dvportgroup-1"),
        key="dvportgroup-1",
        name="dpg-1",
        dvs_name="dvs-1",
        vlan_id=5,
    )

    vnc_vn = dpg_model.to_vnc_vn(project)

    assert vnc_vn.name == "dvs-1_dpg-1"
    assert vnc_vn.uuid == models.generate_uuid("dvportgroup-1")
    assert vnc_vn.parent_name == project.name
    assert vnc_vn.get_id_perms().get_creator() == "vcenter-fabric-manager"
def test_is_vlan_changed(dpg_service, vnc_api_client):
    dpg_model = models.DistributedPortGroupModel(
        uuid="dpg-uuid",
        key="dvportgroup-1",
        name="dpg-1",
        vlan_id=5,
        dvs_name="dvs-1",
    )

    vnc_api_client.get_vn_vlan.return_value = 15
    assert dpg_service.should_update_vlan(dpg_model)

    vnc_api_client.get_vn_vlan.return_value = 5
    assert not dpg_service.should_update_vlan(dpg_model)

    vnc_api_client.get_vn_vlan.return_value = None
    assert not dpg_service.should_update_vlan(dpg_model)
示例#8
0
def test_find_affected_vmis(vmi_service, vmware_vm, dpg_model):
    dpg_model_2 = models.DistributedPortGroupModel(
        uuid=models.generate_uuid("dvs-1_dpg-2"),
        key="dvportgroup-2",
        name="dpg-2",
        vlan_id=6,
        dvs_name="dvs-1",
    )
    old_vm_model = models.VirtualMachineModel.from_vmware_vm(
        vmware_vm, {dpg_model})
    new_vm_model = models.VirtualMachineModel.from_vmware_vm(
        vmware_vm, {dpg_model_2})

    vmis_to_delete_2, vmis_to_create_2 = vmi_service.find_affected_vmis(
        old_vm_model, new_vm_model)

    assert len(vmis_to_delete_2) == 1
    assert len(vmis_to_create_2) == 1
    assert list(vmis_to_delete_2)[0].uuid == models.generate_uuid(
        "esxi-1_dvs-1_dpg-1")
    assert list(vmis_to_create_2)[0].uuid == models.generate_uuid(
        "esxi-1_dvs-1_dpg-2")