def setUp(self):
     self.agent_conf_dir = mkdtemp(delete=True)
     state = State(os.path.join(self.agent_conf_dir, "state.json"))
     common.services.register(ServiceName.MODE, Mode(state))
     common.services.register(ServiceName.DATASTORE_TAGS,
                              DatastoreTags(state))
     self.agent = AgentConfig(["--config-path", self.agent_conf_dir])
    def test_persistence(self):
        """
        Test that we can process and persist config options.
        """
        self.agent._parse_options([
            "--chairman",
            "h1:13000, h2:13000", "--memory-overcommit", "1.5", "--datastore",
            ["datastore1"], "--in-uwsim", "--config-path", self.agent_conf_dir,
            "--utilization-transfer-ratio", "0.5"
        ])

        self.assertEqual(
            self.agent.chairman_list,
            [ServerAddress("h1", 13000),
             ServerAddress("h2", 13000)])
        self.assertEqual(self.agent.memory_overcommit, 1.5)
        self.assertEqual(self.agent.in_uwsim, True)
        self.assertEqual(self.agent.utilization_transfer_ratio, 0.5)
        self.agent._persist_config()

        # Simulate an agent restart.
        new_agent = AgentConfig(["--config-path", self.agent_conf_dir])
        self.assertEqual(
            new_agent.chairman_list,
            [ServerAddress("h1", 13000),
             ServerAddress("h2", 13000)])
        self.assertEqual(new_agent.memory_overcommit, 1.5)
        self.assertEqual(new_agent.in_uwsim, True)
        self.assertEqual(self.agent.utilization_transfer_ratio, 0.5)
    def __init__(self, id, networks, datastores, cpu, mem, disk, overcommit):
        self.id = id
        self.cpu = cpu
        self.mem = mem
        self.disk = disk
        self.parent = ""
        self.constraints = set()
        host_constraint = ResourceConstraint(ResourceConstraintType.HOST,
                                             ["host-" + str(id)])
        self.constraints.add(host_constraint)
        [self.constraints.add(net) for net in networks]
        [self.constraints.add(ds) for ds in datastores]
        self.address = ""
        self.port = ""
        conf_dir = mkdtemp(delete=True)
        state = State(os.path.join(conf_dir, "state.json"))
        common.services.register(ServiceName.MODE, Mode(state))
        self.hv = self._get_hypervisor_instance(
            id, cpu, mem, disk, [ds.values[0] for ds in datastores],
            [network.values[0] for network in networks], overcommit)

        # need agent_config for create/delete vm.
        agent_config = AgentConfig([
            "--config-path", conf_dir, "--hostname", "localhost", "--port",
            "1234", "--host-id", id
        ])
        common.services.register(ServiceName.AGENT_CONFIG, agent_config)
        super(Host, self).__init__(self.hv)
Example #4
0
 def test_hypervisor(self, password_mock, user_mock, update_mock, si_mock,
                     connect_mock):
     user_mock.return_value = "user"
     password_mock.return_value = "password"
     self.agent_config = AgentConfig(
         ["--config-path", self.agent_config_dir, "--hypervisor", "fake"])
     Hypervisor(self.agent_config)
Example #5
0
 def test_hypervisor_setter(self):
     self.agent_config = AgentConfig(
         ["--config-path", self.agent_config_dir, "--hypervisor", "fake"])
     hypervisor = Hypervisor(self.agent_config)
     hypervisor.set_cpu_overcommit(2.0)
     assert_that(hypervisor.cpu_overcommit, equal_to(2.0))
     hypervisor.set_memory_overcommit(3.0)
     assert_that(hypervisor.memory_overcommit, equal_to(3.0))
    def setUp(self):
        self.agent_conf_dir = mkdtemp(delete=True)
        state = State(os.path.join(self.agent_conf_dir, "state.json"))
        common.services.register(ServiceName.MODE, Mode(state))
        common.services.register(ServiceName.DATASTORE_TAGS,
                                 DatastoreTags(state))
        self.multi_agent = MultiAgent(2200, AgentConfig.DEFAULT_CONFIG_PATH,
                                      AgentConfig.DEFAULT_CONFIG_FILE)

        self.agent = AgentConfig(["--config-path", self.agent_conf_dir])
    def test_persistence(self):
        """
        Test that we can process and persist config options.
        """
        self.agent._parse_options(["--memory-overcommit", "1.5",
                                   "--datastore", ["datastore1"],
                                   "--config-path", self.agent_conf_dir,
                                   "--utilization-transfer-ratio", "0.5"])

        self.assertEqual(self.agent.memory_overcommit, 1.5)
        self.assertEqual(self.agent.utilization_transfer_ratio, 0.5)
        self.agent._persist_config()

        # Simulate an agent restart.
        new_agent = AgentConfig(["--config-path", self.agent_conf_dir])
        self.assertEqual(new_agent.memory_overcommit, 1.5)
        self.assertEqual(self.agent.utilization_transfer_ratio, 0.5)
Example #8
0
    def test_large_page_disable(self, vim_client_mock, monitor_mock,
                                get_env_mock):
        vim_client_mock.return_value = MagicMock()
        hypervisor = Hypervisor(self.agent_config)
        vim_client = hypervisor.hypervisor.vim_client
        assert_that(vim_client.set_large_page_support.called, is_(True))
        vim_client.set_large_page_support.assert_called_once_with(
            disable=False)
        vim_client.reset_mock()

        self.agent_config = AgentConfig([
            "--config-path", self.agent_config_dir, "--memory-overcommit",
            "1.5"
        ])
        hypervisor = Hypervisor(self.agent_config)
        vim_client = hypervisor.hypervisor.vim_client
        assert_that(vim_client.set_large_page_support.called, is_(True))
        vim_client.set_large_page_support.assert_called_once_with(disable=True)
        vim_client.reset_mock()
Example #9
0
 def setUp(self):
     self.services_helper = ServicesHelper()
     self.hv = None
     self.agent_config_dir = mkdtemp(delete=True)
     self.agent_config = AgentConfig(
         ["--config-path", self.agent_config_dir])
Example #10
0
 def test_unknown_hypervisor(self):
     self.agent_config = AgentConfig(
         ["--config-path", self.agent_config_dir, "--hypervisor", "dummy"])
     self.assertRaises(ValueError, Hypervisor, self.agent_config)
Example #11
0
 def setUp(self):
     self.services_helper = ServicesHelper()
     self.mock_options = MagicMock()
     self.agent_config_dir = mkdtemp(delete=True)
     self.agent_config = AgentConfig(
         ["--config-path", self.agent_config_dir, "--hypervisor", "esx"])
Example #12
0
 def setUp(self):
     self.agent_conf_dir = mkdtemp(delete=True)
     state = State(os.path.join(self.agent_conf_dir, "state.json"))
     common.services.register(ServiceName.MODE, Mode(state))
     common.services.register(ServiceName.REGISTRANT, mock.MagicMock())
     self.agent = AgentConfig(["--config-path", self.agent_conf_dir])