Exemple #1
0
    def test_get_vm_netwokrs(self):
        vim_client = MagicMock()
        vim_client.get_networks.return_value = ["VM Network", "VM Network 2"]

        # Verify the function returns the actual network list.
        network_manager = NetworkManager(vim_client)
        networks = network_manager.get_vm_networks()
        self.assertEqual(networks, ["VM Network", "VM Network 2"])
Exemple #2
0
    def __init__(self, agent_config):
        self.logger = logging.getLogger(__name__)

        # If VimClient's housekeeping thread failed to update its own cache,
        # call errback to commit suicide. Watchdog will bring up the agent
        # again.
        self.host_client = Hypervisor.create_host_client(
            errback=lambda: suicide())
        self.host_client.connect_local()
        atexit.register(lambda client: client.disconnect(), self.host_client)

        self.datastore_manager = DatastoreManager(
            self, agent_config.datastores, agent_config.image_datastores)
        # datastore manager needs to update the cache when there is a change.
        self.host_client.add_update_listener(self.datastore_manager)
        self.vm_manager = VmManager(self.host_client, self.datastore_manager)
        self.disk_manager = DiskManager(self.host_client,
                                        self.datastore_manager)
        self.image_manager = ImageManager(self.host_client,
                                          self.datastore_manager)
        self.network_manager = NetworkManager(self.host_client)
        self.system = System(self.host_client)

        options = PlacementOption(agent_config.memory_overcommit,
                                  agent_config.cpu_overcommit,
                                  agent_config.image_datastores)
        self.placement_manager = PlacementManager(self, options)

        self.image_monitor = ImageMonitor(self.datastore_manager,
                                          self.image_manager, self.vm_manager)
        self.image_manager.monitor_for_cleanup()
        self.image_transferer = NfcImageTransferer(self.host_client)
        atexit.register(self.image_manager.cleanup)
Exemple #3
0
    def test_get_networks(self):
        """ Test normal get_network workflow:
        - call vim_client correctly.
        - collect network types and translate them to thrift representation
        correctly.
        """
        vim_client = MagicMock()
        vim_client.get_networks.return_value = ["VM Network", "VM Network 2"]
        network_manager = NetworkManager(vim_client)
        networks = network_manager.get_networks()

        assert_that(networks, has_length(2))
        # Verify 2 VM networks
        assert_that(networks, has_item(Network("VM Network",
                                               [NetworkType.VM])))
        assert_that(networks, has_item(Network("VM Network 2",
                                               [NetworkType.VM])))