Esempio n. 1
0
def main(cfg):
    context = CVFMContext(cfg)
    context.configure_logger()
    zookeeper_client = context.build_zookeeper_client()

    logger.info("Waiting to be elected as master...")
    zookeeper_client.master_election(
        "/vcenter-fabric-manager",
        os.getpid(),
        run_vcenter_fabric_manager,
        context,
    )
Esempio n. 2
0
def test_context_handlers(handlers, services, patched_libs, config):
    context = CVFMContext(config)
    context.build()

    c_lib = patched_libs["controllers_lib"]
    c_lib.VmUpdatedHandler.assert_called_once_with(**services)
    c_lib.VmReconfiguredHandler.assert_called_once_with(**services)
    c_lib.VmRemovedHandler.assert_called_once_with(**services)
    c_lib.VmRenamedHandler.assert_called_once_with(**services)
    c_lib.HostChangeHandler.assert_called_once_with(**services)
    c_lib.DVPortgroupCreatedHandler.assert_called_once_with(**services)
    c_lib.DVPortgroupReconfiguredHandler.assert_called_once_with(**services)
    c_lib.DVPortgroupRenamedHandler.assert_called_once_with(**services)
    c_lib.DVPortgroupDestroyedHandler.assert_called_once_with(**services)

    c_lib.UpdateHandler.assert_called_once_with(list(handlers.values()))
Esempio n. 3
0
def test_context_start(monitors, patched_libs, config):
    context = CVFMContext(config)
    context.build()

    context.start_vmware_monitor()
    context.start_vnc_monitor()

    monitors["vmware_monitor"].start.assert_called_once()
    monitors["vnc_monitor"].start.assert_called_once()
Esempio n. 4
0
def test_context_clients(clients, patched_libs, config):
    context = CVFMContext(config)
    context.build()

    clients_lib = patched_libs["clients_lib"]
    clients_lib.VCenterAPIClient.assert_called_once_with(
        config["vcenter_config"])
    clients_lib.VNCAPIClient.assert_called_once_with(config["vnc_config"],
                                                     config["auth_config"])

    rabbit_lib = patched_libs["rabbit_lib"]
    rabbit_lib.VNCRabbitClient.assert_called_once_with(config["rabbit_config"])
    assert context.clients == {
        "vcenter_api_client": clients["vcenter_api_client"],
        "vnc_api_client": clients["vnc_api_client"],
        "vnc_rabbit_client": clients["vnc_rabbit_client"],
    }
Esempio n. 5
0
def test_context_monitors(monitors, controller, clients, update_handler,
                          patched_libs, config):
    context = CVFMContext(config)
    context.build()

    controllers_lib = patched_libs["controllers_lib"]
    controllers_lib.VMwareController.assert_called_once_with(
        context.synchronizer, update_handler, context.lock)
    monitors_lib = patched_libs["monitors_lib"]
    monitors_lib.VMwareMonitor.assert_called_once_with(
        controller, clients["vcenter_api_client"])
    monitors_lib.VNCMonitor.assert_called_once_with(
        controller, clients["vnc_rabbit_client"])
    assert context.monitors == {
        "vmware_monitor": monitors["vmware_monitor"],
        "vnc_monitor": monitors["vnc_monitor"],
    }
Esempio n. 6
0
def test_context_synchronizers(synchronizers, cvfm_synchronizer, services,
                               patched_libs, config):
    context = CVFMContext(config)
    context.build()

    s_lib = patched_libs["synchronizers_lib"]
    s_lib.VirtualMachineSynchronizer.assert_called_once_with(**services)
    s_lib.DistributedPortGroupSynchronizer.assert_called_once_with(**services)
    s_lib.VirtualPortGroupSynchronizer.assert_called_once_with(**services)
    s_lib.VirtualMachineInterfaceSynchronizer.assert_called_once_with(
        **services)
    s_lib.DistributedVirtualSwitchSynchronizer.assert_called_once_with(
        **services)
    s_lib.PhysicalInterfaceSynchronizer.assert_called_once_with(**services)

    s_lib.CVFMSynchronizer.assert_called_once_with(context.database,
                                                   **synchronizers)
    assert context.synchronizer == cvfm_synchronizer
Esempio n. 7
0
def test_context_services(services, patched_libs, config):
    context = CVFMContext(config)
    context.build()

    s_lib = patched_libs["services_lib"]
    s_kwargs = {
        "vcenter_api_client": context.clients["vcenter_api_client"],
        "vnc_api_client": context.clients["vnc_api_client"],
        "database": context.database,
    }
    s_lib.VirtualMachineService.assert_called_once_with(**s_kwargs)
    s_lib.VirtualMachineInterfaceService.assert_called_once_with(**s_kwargs)
    s_lib.DistributedPortGroupService.assert_called_once_with(**s_kwargs)
    s_lib.VirtualPortGroupService.assert_called_once_with(**s_kwargs)
    s_lib.DistributedVirtualSwitchService.assert_called_once_with(**s_kwargs)
    s_lib.PhysicalInterfaceService.assert_called_once_with(**s_kwargs)

    assert context.services == services
Esempio n. 8
0
def test_run_sandesh(sandesh, sandesh_handler, connection_state, patched_libs,
                     config):
    context = CVFMContext(config)
    context.build()

    context.run_sandesh()

    sandesh_handler.bind_handlers.assert_called_once()

    introspect_config = config["introspect_config"]
    sandesh.init_generator.assert_called_once_with(
        **{
            "module": "cvfm",
            "source": introspect_config["hostname"],
            "node_type": introspect_config["node_type_name"],
            "instance_id": introspect_config["instance_id"],
            "collectors": introspect_config["collectors"],
            "client_context": "cvfm_context",
            "http_port": introspect_config["introspect_port"],
            "sandesh_req_uve_pkg_list": ["cfgm_common", "cvfm"],
            "config": config["sandesh_config"],
        })

    connection_state.init.assert_called_once_with(
        sandesh=sandesh,
        hostname=introspect_config["hostname"],
        module_id=introspect_config["name"],
        instance_id=introspect_config["instance_id"],
        conn_status_cb=mock.ANY,
        uve_type_cls=mock.ANY,
        uve_data_type_cls=mock.ANY,
        table=introspect_config["table"],
    )