Exemplo n.º 1
0
    def test_reboot_required(self):
        """
        Test that reboot required flag is set when all the required agent
        parameters are set.
        """
        self.agent._parse_options(["--config-path", self.agent_conf_dir])
        # Check that reboot required is false until we set all the params
        self.assertFalse(self.agent.reboot_required)

        req = ProvisionRequest()
        req.availability_zone = "test1"
        req.datastores = ["ds3", "ds4"]
        req.networks = ["Public"]
        addr = ServerAddress(host="localhost", port=2345)
        req.address = addr
        self.agent.update_config(req)
        # Verify that the bootstrap is still false as zk config is not
        # specified.
        self.assertFalse(self.agent.bootstrap_ready)
        self.assertTrue(self.agent.reboot_required)

        req = ProvisionRequest()
        req.availability_zone = "test1"
        req.datastores = ["ds3", "ds4"]
        req.networks = ["Public"]
        addr = ServerAddress(host="localhost", port=2345)
        req.address = addr
        self.agent.update_config(req)
        self.assertTrue(self.agent.reboot_required)
Exemplo n.º 2
0
    def test_report(self, client_class, time_class, chairman):
        """Test that resurrected and missing hosts get reported correctly"""
        client_class.side_effect = self.create_fake_client
        chairman.return_value.report_resurrected.return_value = \
            ReportResurrectedResponse(result=0)
        bar_client = MagicMock()
        baz_client = MagicMock()
        self._clients["bar"] = bar_client
        self._clients["baz"] = baz_client
        children = {
            "bar": ServerAddress("bar", 1234),
            "baz": ServerAddress("baz", 1234)
        }

        # first ping succeeds for bar and baz. they get reported resurrected.
        health_checker = HealthChecker("id", children, self.conf)
        time_class.return_value = 0.0
        health_checker._send_heartbeat()
        health_checker._send_report()
        req = ReportResurrectedRequest(hosts=['bar', 'baz'],
                                       schedulers=None,
                                       scheduler_id='id')
        chairman.return_value.report_resurrected.assert_called_once_with(req)
        self.assertFalse(chairman.return_value.report_missing.called)
        self.assertEquals(health_checker._resurrected_children,
                          set(["bar", "baz"]))
        self.assertEquals(health_checker._missing_children, set())

        # call _send_report again. this time nothing should get reported.
        chairman.reset_mock()
        health_checker._send_report()
        self.assertFalse(chairman.return_value.report_missing.called)
        self.assertFalse(chairman.return_value.report_resurrected.called)

        # bar goes missing.
        bar_client.ping.side_effect = Exception()
        health_checker._send_heartbeat()
        time_class.return_value = 100.0
        chairman.return_value.report_missing.return_value = \
            ReportMissingResponse(result=0)
        health_checker._send_report()
        req = ReportMissingRequest(hosts=['bar'],
                                   schedulers=None,
                                   scheduler_id='id')
        chairman.return_value.report_missing.assert_called_once_with(req)
        self.assertFalse(chairman.return_value.report_resurrected.called)

        # bar comes back
        chairman.reset_mock()
        bar_client.ping.side_effect = None
        time_class.return_value = 200.0
        health_checker._send_heartbeat()
        chairman.return_value.report_resurrected.return_value = \
            ReportResurrectedResponse(result=0)
        health_checker._send_report()
        req = ReportResurrectedRequest(hosts=['bar'],
                                       schedulers=None,
                                       scheduler_id='id')
        self.assertFalse(chairman.return_value.report_missing.called)
        chairman.return_value.report_resurrected.assert_called_once_with(req)
Exemplo n.º 3
0
    def test_config_change(self):
        # Test chairman config change
        chairman_callback1 = mock.MagicMock()
        chairman_callback2 = mock.MagicMock()

        chairman_server = [
            ServerAddress("192.168.0.1", 8835),
            ServerAddress("192.168.0.2", 8835),
        ]
        self.agent.on_config_change(self.agent.CHAIRMAN, chairman_callback1)
        self.agent.on_config_change(self.agent.CHAIRMAN, chairman_callback2)
        provision = ProvisionRequest(chairman_server=chairman_server)
        self.agent.update_config(provision)
        chairman_callback1.assert_called_once_with(chairman_server)
        chairman_callback2.assert_called_once_with(chairman_server)
        self.assertFalse(self.agent.reboot_required)

        # Test cpu_overcommit and memory_overcommit config change
        cpu_callback = mock.MagicMock()
        mem_callback = mock.MagicMock()

        provision.cpu_overcommit = 5.0
        provision.memory_overcommit = 6.0
        self.agent.on_config_change(self.agent.CPU_OVERCOMMIT, cpu_callback)
        self.agent.on_config_change(self.agent.MEMORY_OVERCOMMIT, mem_callback)
        self.agent.update_config(provision)
        cpu_callback.assert_called_once_with(5.0)
        mem_callback.assert_called_once_with(6.0)
Exemplo n.º 4
0
    def _provision_host(self, datastore):
        """ Provisions the agents on the remote hosts """
        req = ProvisionRequest()
        req.availability_zone = "test"
        req.datastores = [datastore]
        req.networks = ["VM Network"]
        req.address = ServerAddress(host="localhost", port=8835)
        req.chairman_server = [ServerAddress("localhost", 13000)]
        req.memory_overcommit = 2.0
        req.image_datastores = set(
            [ImageDatastore(name=datastore, used_for_vms=True)])
        res = self.agent_client.provision(req)

        # This will trigger a restart if the agent config changes, which
        # will happen the first time provision_hosts is called.
        self.assertEqual(res.result, ProvisionResultCode.OK)

        # If a restart is required subsequent calls will fail.
        # This is an indirect way to determine if a restart is required.
        host_config_request = Host.GetConfigRequest()
        res = self.host_client.get_host_config(host_config_request)

        if (res.result != GetConfigResultCode.OK):
            # Sleep for 15 s for the agent to reboot and come back up
            time.sleep(15)
Exemplo n.º 5
0
    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 test_reboot_required(self):
        """
        Test that reboot required flag is set when all the required agent
        parameters are set.
        """
        self.agent._parse_options(["--config-path", self.agent_conf_dir])
        # Check that reboot required is false until we set all the params
        self.assertFalse(self.agent.reboot_required)

        req = ProvisionRequest()
        req.datastores = ["ds3", "ds4"]
        req.stats_plugin_config = StatsPluginConfig()
        req.stats_plugin_config.enabled = False
        addr = ServerAddress(host="localhost", port=2345)
        req.address = addr
        self.agent.provision(req)
        # Verify that the bootstrap is still false as zk config is not
        # specified.
        self.assertFalse(self.agent.bootstrap_ready)
        self.assertTrue(self.agent.reboot_required)

        req = ProvisionRequest()
        req.datastores = ["ds3", "ds4"]
        addr = ServerAddress(host="localhost", port=2345)
        req.address = addr
        self.agent.provision(req)
        self.assertTrue(self.agent.reboot_required)
Exemplo n.º 7
0
 def test_basic(self):
     servers = [ServerAddress("server1", 1234),
                ServerAddress("server2", 1234)]
     listenerA = Listener()
     listenerB = Listener()
     serverset = StaticServerSet(servers)
     serverset.add_change_listener(listenerA)
     serverset.add_change_listener(listenerB)
     self.assertEqual(servers, listenerA.servers)
     self.assertEqual(servers, listenerB.servers)
Exemplo n.º 8
0
 def _update_agent_invalid_config(self):
     """
     Negative test case to update the agent with an invalid config
     """
     req = ProvisionRequest()
     req.availability_zone = "bootstrap_availability_zone_id"
     req.datastores = ["bootstrap_datastore"]
     req.networks = ["Bootstrap Network"]
     addr = ServerAddress(host="foobar", port=8835)
     req.address = addr
     req.chairman_server = [ServerAddress("h1", 13000),
                            ServerAddress("h2", 13000)]
     req.memory_overcommit = 0.5
     res = self.control_client.provision(req)
     self.assertEqual(res.result, ProvisionResultCode.INVALID_CONFIG)
Exemplo n.º 9
0
    def test_heartbeat(self, client_class, time_class):
        """Test that sequence number and timestamp get updated correctly
           after sending heartbeat."""
        client_class.side_effect = self.create_fake_client
        bar_client = MagicMock()
        baz_client = MagicMock()
        self._clients["bar"] = bar_client
        self._clients["baz"] = baz_client

        children = {
            "bar": ServerAddress("bar", 1234),
            "baz": ServerAddress("baz", 1234)
        }

        # make sure things are initialized properly
        time_class.return_value = 0.0
        health_checker = HealthChecker("id", children, self.conf)
        self.assertEquals(health_checker._seqnum, 0)
        self.assertEquals(len(health_checker._last_update), 2)
        self.assertEquals(health_checker._last_update["bar"], (0, 0.0))
        self.assertEquals(health_checker._last_update["baz"], (0, 0.0))

        # send a ping
        time_class.return_value = 10.0
        health_checker._send_heartbeat()
        self.assertEquals(health_checker._seqnum, 1)
        self.assertEquals(len(health_checker._last_update), 2)
        self.assertEquals(health_checker._last_update["bar"], (1, 10.0))
        self.assertEquals(health_checker._last_update["baz"], (1, 10.0))

        # send another ping. ping to baz fails.
        time_class.return_value = 20.0
        baz_client.ping.side_effect = Exception()
        health_checker._send_heartbeat()
        self.assertEquals(health_checker._seqnum, 2)
        self.assertEquals(len(health_checker._last_update), 2)
        self.assertEquals(health_checker._last_update["bar"], (2, 20.0))
        self.assertEquals(health_checker._last_update["baz"], (1, 10.0))

        # send another ping. ping to bar fails.
        time_class.return_value = 30.0
        bar_client.ping.side_effect = Exception()
        baz_client.ping.side_effect = None
        health_checker._send_heartbeat()
        self.assertEquals(health_checker._seqnum, 3)
        self.assertEquals(len(health_checker._last_update), 2)
        self.assertEquals(health_checker._last_update["bar"], (2, 20.0))
        self.assertEquals(health_checker._last_update["baz"], (3, 30.0))
Exemplo n.º 10
0
    def configure(self, hosts):
        """Configure the leaf scheduler.

        :param hosts: list of child hosts
        :type hosts: list of str
        """
        # Transfer children's constraints from list to set, so searching
        # elements are more efficient.
        self._hosts = []

        for host in hosts:
            self._hosts.append(ChildInfo.from_thrift(host))

        self._coalesce_resources(self._hosts)

        if self._health_checker:
            self._health_checker.stop()
        if self._enable_health_checker:
            # initialize health checker with the new set of children.
            agent_config = common.services.get(ServiceName.AGENT_CONFIG)
            children = dict((host.id, ServerAddress(host.address, host.port))
                            for host in self._hosts)
            self._health_checker = HealthChecker(self._scheduler_id, children,
                                                 agent_config)
            self._health_checker.start()
        self._configured = ConfigStates.INITIALIZED
    def test_host_config_after_provision(self):
        """
        Test if the agent returns the correct HostConfig
        after being provisioned
        """
        host_config_request = Host.GetConfigRequest()
        res = self.host_client.get_host_config(host_config_request)
        self.assertEqual(res.result, GetConfigResultCode.OK)

        hostConfig = res.hostConfig
        datastores = [ds.name for ds in hostConfig.datastores]
        containsDs = [
            ds for ds in self.get_all_datastores() if ds in datastores
        ]
        self.assertEqual(containsDs, self.get_all_datastores())
        networks = [net.id for net in hostConfig.networks]
        self.assertEqual(networks, self.vim_client.get_networks())
        self.assertEqual(hostConfig.address,
                         ServerAddress(host=self.server, port=8835))
        self.assertTrue(hostConfig.management_only)
        # get_host_config reports datastore id for image datastore  even if it
        # was provisioned with a datastore name.
        image_datastore_name = self.get_image_datastore()
        image_datastore_id = None
        for ds in hostConfig.datastores:
            if ds.name == image_datastore_name:
                image_datastore_id = ds.id
        self.assertEqual(
            list(hostConfig.image_datastore_ids)[0], image_datastore_id)
Exemplo n.º 12
0
    def _parse_chairman_list(self, chairman_list):
        """
        Converts a list of chairman with port config into a list of
        ServerAddress.
        Chairman list is persisted as a list of "ip:port"
        :param chairman_list: The list of chairman as a comma separated string.
        :rtype list of chairman service addresses of type ServerAddress
        """

        if not chairman_list:
            return []

        server_list = []
        for server in chairman_list:
            try:
                host, port = server.split(":")
                server_list.append(ServerAddress(host=host, port=int(port)))
            except ValueError:
                self._logger.warning(
                    "Failed to parse server %s, Invalid delemiter" % server)
                pass
            except AttributeError:
                self._logger.warning("Failed to parse chairman server %s" %
                                     server)
                pass

        return server_list
Exemplo n.º 13
0
    def test_place(self):
        handler = HostHandler(MagicMock())

        score = Score(100, 100)
        place_list = [MagicMock()]
        address = ServerAddress(host="localhost", port=1234)

        request = PlaceRequest(resource=Resource(self._sample_vm(), []))
        handler.hypervisor.placement_manager.place.return_value = (score,
                                                                   place_list)
        response = handler.place(request)
        assert_that(response.result, is_(PlaceResultCode.OK))
        assert_that(response.score, is_(score))
        assert_that(response.placementList.placements,
                    is_([item.to_thrift() for item in place_list]))
        assert_that(response.address, is_(address))

        common.services.get(ServiceName.MODE).set_mode(
            MODE.ENTERING_MAINTENANCE)
        response = handler.place(request)
        assert_that(response.result, is_(PlaceResultCode.INVALID_STATE))

        common.services.get(ServiceName.MODE).set_mode(MODE.MAINTENANCE)
        response = handler.place(request)
        assert_that(response.result, is_(PlaceResultCode.INVALID_STATE))
    def provision_hosts(self,
                        mem_overcommit=2.0,
                        datastores=None,
                        used_for_vms=True,
                        image_ds=None,
                        host_id=None,
                        deployment_id="test-deployment"):
        """ Provisions the agents on the remote hosts """
        if datastores is None:
            datastores = self.get_all_datastores()
            image_datastore = self.get_image_datastore()
        elif image_ds:
            image_datastore = image_ds
        else:
            image_datastore = datastores[0]

        req = ProvisionRequest()
        req.datastores = datastores
        req.address = ServerAddress(host=self.server, port=8835)
        req.memory_overcommit = mem_overcommit
        req.image_datastore_info = ImageDatastore(name=image_datastore,
                                                  used_for_vms=used_for_vms)
        req.image_datastores = set([req.image_datastore_info])
        req.management_only = True
        req.auth_enabled = False
        if host_id:
            req.host_id = host_id
        else:
            req.host_id = self.host_id

        if deployment_id:
            req.deployment_id = deployment_id
        else:
            req.deployment_id = self.deployment_id

        res = self.control_client.provision(req)

        # This will trigger a restart if the agent config changes, which
        # will happen the first time provision_hosts is called.
        self.assertEqual(res.result, ProvisionResultCode.OK)

        # Wait for up to 60 seconds for the agent to reboot.
        count = 0
        while count < 60:
            try:
                res = self.control_client.get_agent_status()
                if res.status == AgentStatusCode.OK:
                    # Agent is up
                    return
            except:
                logger.exception("Can't connect to agent")
            count += 1
            time.sleep(1)
            # Reconnect the clients
            self._close_agent_connections()
            self.client_connections()
        self.fail("Cannot connect to agent %s after provisioning" %
                  self.server)
        return host_id
Exemplo n.º 15
0
 def test_property_accessors(self):
     self.agent._parse_options([
         "--config-path", self.agent_conf_dir, "--availability-zone",
         "test", "--hostname", "localhost", "--port", "1234",
         "--datastores", "ds1, ds2", "--vm-network", "VM Network",
         "--wait-timeout", "5", "--chairman", "h1:1300, h2:1300"
     ])
     assert_that(self.agent.availability_zone, equal_to("test"))
     assert_that(self.agent.hostname, equal_to("localhost"))
     assert_that(self.agent.host_port, equal_to(1234))
     assert_that(self.agent.datastores, equal_to(["ds1", "ds2"]))
     assert_that(self.agent.networks, equal_to(["VM Network"]))
     assert_that(self.agent.wait_timeout, equal_to(5))
     assert_that(
         self.agent.chairman_list,
         equal_to([ServerAddress("h1", 1300),
                   ServerAddress("h2", 1300)]))
Exemplo n.º 16
0
def parse_address(value):
    """Deserialize the given thrift encoded string into a address tuple.

    :type value: str
    :rtype: tuple
    """
    address = ServerAddress()
    deserialize(address, value)
    return address.host, address.port
Exemplo n.º 17
0
def create_address(host, port):
    """Serialize the given address to thrift ServerAddress.

    :type host: str
    :type port: int
    :rtype: str
    """
    address = ServerAddress(host, port)
    return serialize(address)
def get_register_host_request(host, port, agent_id, networks, datastores,
                              image_datastore, availability_zone,
                              management_only=False):
    host_config = HostConfig(agent_id=agent_id, datastores=datastores,
                             address=ServerAddress(host, port=port),
                             networks=networks,
                             availability_zone=availability_zone,
                             image_datastore_ids=set([image_datastore]),
                             management_only=management_only)
    return RegisterHostRequest(agent_id, host_config)
Exemplo n.º 19
0
    def _update_agent_config(self):
        """
        Update the agent config using the bootstrap interface.
        Verifies that thrift requests after a config update return back
        SYSTEM_ERROR and the agent is stopped.
        :return the request we used to configure the host with.
        """
        req = ProvisionRequest()
        req.availability_zone = "bootstrap_availability_zone_id"
        req.datastores = ["bootstrap_datastore"]
        req.networks = ["Bootstrap Network"]
        addr = ServerAddress(host="foobar", port=8835)
        req.address = addr
        req.chairman_server = [ServerAddress("h1", 13000),
                               ServerAddress("h2", 13000)]
        req.memory_overcommit = 2.0
        res = self.control_client.provision(req)
        self.assertEqual(res.result, ProvisionResultCode.OK)

        # Now check that the agent went down and all requests fail until the
        # agent restarts.
        # Use a time greater than the restart poll thread.
        remaining_sleep_time = 15
        sleep_time = 0.5
        agent_restarted = False
        while 0 < remaining_sleep_time:
            try:
                res = self.control_client.get_agent_status()
                # Verify that the response is restarting
                self.assertEqual(res.status, AgentStatusCode.RESTARTING)
                time.sleep(sleep_time)
                remaining_sleep_time -= sleep_time
            except TTransport.TTransportException:
                agent_restarted = True
                break
            except:
                logger.debug("Caught exception, assuming restart: ",
                             exc_info=True)
                agent_restarted = True
                break
        self.assertTrue(agent_restarted)
        return req
 def _update_agent_invalid_config(self):
     """
     Negative test case to update the agent with an invalid config
     """
     req = ProvisionRequest()
     req.datastores = ["bootstrap_datastore"]
     addr = ServerAddress(host="foobar", port=8835)
     req.address = addr
     req.memory_overcommit = 0.5
     res = self.control_client.provision(req)
     self.assertEqual(res.result, ProvisionResultCode.INVALID_CONFIG)
Exemplo n.º 21
0
    def test_chairman_parsing(self):
        """Tests that the parsing logic for chairman works"""
        str_1 = "10.10.10.1:13000"
        str_2 = "10.10.10.2:13000"
        str_3 = "10.10.10.3:13000"
        invalid_str = "10.10.10.3;13000"
        srv_1 = ServerAddress(host="10.10.10.1", port=13000)
        srv_2 = ServerAddress(host="10.10.10.2", port=13000)
        srv_3 = ServerAddress(host="10.10.10.3", port=13000)

        # Test 1 check that we can parse a list of chairman services.
        chairman_str = [str_1, str_2, str_3]
        chairman_list = self.agent._parse_chairman_list(chairman_str)
        self.assertEqual(len(chairman_list), 3)
        self.assertEqual([srv_1, srv_2, srv_3], chairman_list)

        # Test 2 check that we can parse single chairman
        chairman_str = str_1
        chairman_list = self.agent._parse_chairman_list([chairman_str])
        self.assertEqual(len(chairman_list), 1)
        self.assertEqual([srv_1], chairman_list)

        # Test invalid input string - 2; one of the delimiters are invalid
        chairman_str = [str_1, str_2, invalid_str, str_3]
        chairman_list = self.agent._parse_chairman_list(chairman_str)
        self.assertEqual(len(chairman_list), 3)
        self.assertEqual([srv_1, srv_2, srv_3], chairman_list)

        # Test conversion from server address to string.
        chairman_str = self.agent._parse_chairman_server_address(
            [srv_1, srv_2, srv_3])
        self.assertEqual([str_1, str_2, str_3], chairman_str)

        # Handle empty list
        chairman_str = self.agent._parse_chairman_server_address([])
        self.assertEqual([], chairman_str)

        # Handle None
        chairman_str = self.agent._parse_chairman_server_address(None)
        self.assertEqual([], chairman_str)
Exemplo n.º 22
0
    def get_register_host_request(self, port=8080):
        """
        Generates a random register host request
            which has same datastore and same availability zone
        """
        host_id = str(uuid.uuid4())
        if not hasattr(self, "image_datastore"):
            self.image_datastore = str(uuid.uuid4())

        datastores = [Datastore(self.image_datastore)]
        networks = [Network("nw1", [NetworkType.VM])]
        host_config = HostConfig(agent_id=host_id,
                                 datastores=datastores,
                                 address=ServerAddress("127.0.0.1", port=port),
                                 networks=networks)
        host_config.availability_zone = "foo"
        host_config.image_datastore_ids = set(self.image_datastore)
        return RegisterHostRequest(host_id, host_config)
Exemplo n.º 23
0
    def test_slow_heartbeater(self, client_class, time_class, chairman):
        """Don't report missing if the current sequence number is equal to
           the sequence number of the last successful ping.
        """
        client_class.side_effect = self.create_fake_client
        bar_client = MagicMock()
        self._clients["bar"] = bar_client
        children = {"bar": ServerAddress("bar", 1234)}

        # send a ping. bar should get reported resurrected.
        health_checker = HealthChecker("id", children, self.conf)
        time_class.return_value = 0.0
        chairman.return_value.report_resurrected.return_value = \
            ReportResurrectedResponse(result=0)
        health_checker._send_heartbeat()
        health_checker._send_report()
        req = ReportResurrectedRequest(hosts=['bar'],
                                       schedulers=None,
                                       scheduler_id='id')
        chairman.return_value.report_resurrected.assert_called_once_with(req)
        self.assertFalse(chairman.return_value.report_missing.called)
        self.assertEquals(health_checker._resurrected_children, set(["bar"]))
        self.assertEquals(health_checker._missing_children, set())

        # call _send_report() again after 100 seconds. bar shouldn't get
        # reported missing since the heartbeater hasn't send another ping.
        time_class.return_value = 100.0
        chairman.reset_mock()
        health_checker._send_report()
        self.assertFalse(chairman.return_value.report_missing.called)
        self.assertFalse(chairman.return_value.report_resurrected.called)

        # ping fails. now the reporter should report bar missing.
        bar_client.ping.side_effect = Exception()
        chairman.return_value.report_missing.return_value = \
            ReportMissingResponse(result=0)
        health_checker._send_heartbeat()
        health_checker._send_report()
        req = ReportMissingRequest(hosts=['bar'],
                                   schedulers=None,
                                   scheduler_id='id')
        chairman.return_value.report_missing.assert_called_once_with(req)
        self.assertFalse(chairman.return_value.report_resurrected.called)
    def test_send_image_to_host(self):
        image_id = new_id() + "_test_xfer_image"
        image_id_2 = "%s_xfered" % image_id

        dst_image, _ = self._create_test_image(image_id)

        datastore = self._find_configured_datastore_in_host_config()
        transfer_image_request = TransferImageRequest(
            source_image_id=image_id,
            source_datastore_id=datastore.id,
            destination_host=ServerAddress(host=self.server, port=8835),
            destination_datastore_id=datastore.id,
            destination_image_id=image_id_2)
        res = self.host_client.transfer_image(transfer_image_request)
        self.assertEqual(res.result, TransferImageResultCode.OK)

        # clean up images created in test
        self._delete_image(dst_image)
        xfered_image = Image(image_id_2, datastore)
        self._delete_image(xfered_image)
    def setUp(self):
        self.hostname = "localhost"
        self.host_port = 1234
        self.availability_zone_id = "test"
        self.host_addr = ServerAddress(self.hostname, self.host_port)
        self.chairman_list = []
        self.agent_id = "foo"
        self.host_config = HostConfig(self.agent_id, self.availability_zone_id,
                                      [Datastore("bar")], self.host_addr,
                                      [Network("nw1")])
        self.registrant = ChairmanRegistrant(self.chairman_list)
        host_handler = MagicMock()
        host_handler.get_host_config_no_logging.return_value = \
            GetConfigResponse(hostConfig=self.host_config)
        common.services.register(Host.Iface, host_handler)
        self.request = RegisterHostRequest("foo", self.host_config)

        self.state_file = tempfile.mktemp()
        common.services.register(ServiceName.MODE,
                                 Mode(State(self.state_file)))
Exemplo n.º 26
0
    def test_chairman_failure(self, client_class, time_class, chairman):
        """Reporter should retry reporting if chairman fails."""
        client_class.side_effect = self.create_fake_client
        bar_client = MagicMock()
        self._clients["bar"] = bar_client
        children = {"bar": ServerAddress("bar", 1234)}

        # report_resurrected returns a non-zero value
        health_checker = HealthChecker("id", children, self.conf)
        time_class.return_value = 0.0
        health_checker._send_heartbeat()
        chairman.return_value.report_resurrected.return_value = \
            ReportResurrectedResponse(result=1)
        health_checker._send_report()
        req = ReportResurrectedRequest(hosts=['bar'],
                                       schedulers=None,
                                       scheduler_id='id')
        chairman.return_value.report_resurrected.assert_called_once_with(req)
        self.assertFalse(chairman.return_value.report_missing.called)

        # report_resurrected throws an exception
        chairman.reset_mock()
        chairman.return_value.report_resurrected.side_effect = Exception()
        health_checker._send_report()
        chairman.return_value.report_resurrected.assert_called_once_with(req)
        self.assertFalse(chairman.return_value.report_missing.called)

        # report succeeds
        chairman.reset_mock()
        chairman.return_value.report_resurrected.side_effect = None
        chairman.return_value.report_resurrected.return_value = \
            ReportResurrectedResponse(result=0)
        health_checker._send_report()
        chairman.return_value.report_resurrected.assert_called_once_with(req)
        self.assertFalse(chairman.return_value.report_missing.called)

        # report doesn't get called anymore.
        chairman.reset_mock()
        health_checker._send_report()
        self.assertFalse(chairman.return_value.report_resurrected.called)
        self.assertFalse(chairman.return_value.report_missing.called)
Exemplo n.º 27
0
    def test_agent_config_update(self):
        """ Test that updating the config using the RPC struct works """
        self.agent._parse_options([
            "--config-path", self.agent_conf_dir, "--availability-zone",
            "test", "--hostname", "localhost", "--port", "1234",
            "--datastores", "ds1, ds2"
        ])
        expected_image_ds = [{"name": "ds3", "used_for_vms": True}]

        # Without chairman config we can't be provision ready
        self.assertFalse(self.agent.bootstrap_ready)
        self.assertTrue(self.agent.provision_ready)
        self.assertFalse(self.agent.reboot_required)

        req = ProvisionRequest()
        req.availability_zone = "test1"
        req.datastores = ["ds3", "ds4"]
        req.networks = ["Public"]
        req.memory_overcommit = 1.5
        req.image_datastores = set([ImageDatastore("ds3", True)])
        addr = ServerAddress(host="localhost", port=2345)
        req.chairman_server = [
            ServerAddress("h1", 13000),
            ServerAddress("h2", 13000)
        ]
        req.address = addr
        req.host_id = "host1"
        self.agent.update_config(req)

        assert_that(self.agent.availability_zone, equal_to("test1"))
        assert_that(self.agent.hostname, equal_to("localhost"))
        assert_that(self.agent.host_port, equal_to(2345))
        assert_that(self.agent.datastores, equal_to(["ds3", "ds4"]))
        assert_that(self.agent.networks, equal_to(["Public"]))
        assert_that(
            self.agent.chairman_list,
            equal_to([ServerAddress("h1", 13000),
                      ServerAddress("h2", 13000)]))
        assert_that(self.agent.memory_overcommit, equal_to(1.5))
        assert_that(self.agent.image_datastores, equal_to(expected_image_ds))
        assert_that(self.agent.host_id, equal_to("host1"))

        self.assertTrue(self.agent.bootstrap_ready)
        self.assertTrue(self.agent.reboot_required)

        # Verify we are able to unset all the configuration.
        req = ProvisionRequest()

        self.agent.update_config(req)
        assert_that(self.agent.availability_zone, equal_to(None))
        assert_that(self.agent.hostname, equal_to(None))
        assert_that(self.agent.host_port, equal_to(8835))
        assert_that(self.agent.datastores, equal_to([]))
        assert_that(self.agent.networks, equal_to([]))
        assert_that(self.agent.chairman_list, equal_to([]))
        # Unsetting memory overcommit should set it to the default value.
        self.assertEqual(self.agent.memory_overcommit, 1.0)

        self.assertFalse(self.agent.bootstrap_ready)
        assert_that(self.agent.image_datastores, equal_to(expected_image_ds))
        assert_that(self.agent.host_id, equal_to(None))

        # Test an invalid update and verify the update doesn't have any side
        # effects.
        req = ProvisionRequest()
        req.availability_zone = "test1"
        req.datastores = ["ds3", "ds4"]
        req.networks = ["Public"]
        req.memory_overcommit = 0.5
        addr = ServerAddress(host="localhost", port=2345)
        req.chairman_server = [
            ServerAddress("h1", 13000),
            ServerAddress("h2", 13000)
        ]
        req.address = addr

        # Verify an exception is raised.
        self.assertRaises(InvalidConfig, self.agent.update_config, req)
        assert_that(self.agent.availability_zone, equal_to(None))
        assert_that(self.agent.hostname, equal_to(None))
        assert_that(self.agent.host_port, equal_to(8835))
        assert_that(self.agent.datastores, equal_to([]))
        assert_that(self.agent.networks, equal_to([]))
        assert_that(self.agent.chairman_list, equal_to([]))
        self.assertFalse(self.agent.bootstrap_ready)
        self.assertEqual(self.agent.memory_overcommit, 1.0)
    def test_agent_config_update(self):
        """ Test that updating the config using the RPC struct works """
        self.agent._parse_options(["--config-path", self.agent_conf_dir,
                                   "--hostname", "localhost",
                                   "--port", "1234",
                                   "--datastores", "ds1, ds2"])
        expected_image_ds = [{"name": "ds3", "used_for_vms": True}]

        self.assertFalse(self.agent.bootstrap_ready)
        self.assertTrue(self.agent.provision_ready)
        self.assertFalse(self.agent.reboot_required)

        req = ProvisionRequest()
        req.datastores = ["ds3", "ds4"]
        req.memory_overcommit = 1.5
        req.image_datastores = set([ImageDatastore("ds3", True)])
        addr = ServerAddress(host="localhost", port=2345)
        req.address = addr

        stats_plugin_config = StatsPluginConfig(
            stats_store_endpoint="10.0.0.100", stats_store_port=8081, stats_enabled=True)
        req.stats_plugin_config = stats_plugin_config

        req.host_id = "host1"
        req.deployment_id = "deployment1"
        self.agent.provision(req)

        assert_that(self.agent.stats_store_endpoint, equal_to("10.0.0.100"))
        assert_that(self.agent.stats_store_port, equal_to(8081))
        assert_that(self.agent.stats_enabled, equal_to(True))
        assert_that(self.agent.hostname, equal_to("localhost"))
        assert_that(self.agent.host_port, equal_to(2345))
        assert_that(self.agent.datastores, equal_to(["ds3", "ds4"]))
        assert_that(self.agent.memory_overcommit,
                    equal_to(1.5))
        assert_that(self.agent.image_datastores, equal_to(expected_image_ds))
        assert_that(self.agent.host_id, equal_to("host1"))
        assert_that(self.agent.deployment_id, equal_to("deployment1"))

        self.assertTrue(self.agent.bootstrap_ready)
        self.assertTrue(self.agent.reboot_required)

        # Verify we are able to unset all the configuration.
        req = ProvisionRequest()

        self.agent.provision(req)
        assert_that(self.agent.hostname, equal_to(None))
        assert_that(self.agent.host_port, equal_to(8835))
        assert_that(self.agent.datastores, equal_to([]))
        # Unsetting memory overcommit should set it to the default value.
        self.assertEqual(self.agent.memory_overcommit, 1.0)

        self.assertFalse(self.agent.bootstrap_ready)
        assert_that(self.agent.image_datastores, equal_to(expected_image_ds))
        assert_that(self.agent.host_id, equal_to(None))

        # Test an invalid update and verify the update doesn't have any side
        # effects.
        req = ProvisionRequest()
        req.datastores = ["ds3", "ds4"]
        req.memory_overcommit = 0.5
        addr = ServerAddress(host="localhost", port=2345)
        req.address = addr

        # Verify an exception is raised.
        self.assertRaises(InvalidConfig, self.agent.provision, req)
        assert_that(self.agent.hostname, equal_to(None))
        assert_that(self.agent.host_port, equal_to(8835))
        assert_that(self.agent.datastores, equal_to([]))
        self.assertFalse(self.agent.bootstrap_ready)
        self.assertEqual(self.agent.memory_overcommit, 1.0)
Exemplo n.º 29
0
 def on_server_added(self, address):
     self.servers.append(ServerAddress(address[0], address[1]))
Exemplo n.º 30
0
    def test_agent_config_set_availability_zone(self):
        """ Test that updating the config using the RPC struct works """
        self.agent._parse_options([
            "--config-path", self.agent_conf_dir, "--availability-zone",
            "test", "--hostname", "localhost", "--port", "1234",
            "--datastores", "ds1, ds2"
        ])
        expected_image_ds = [{"name": "ds3", "used_for_vms": True}]

        # Without chairman config we can't be ready
        self.assertFalse(self.agent.bootstrap_ready)
        self.assertTrue(self.agent.provision_ready)
        self.assertFalse(self.agent.reboot_required)

        req = ProvisionRequest()
        req.availability_zone = "test1"
        req.datastores = ["ds3", "ds4"]
        req.networks = ["Public"]
        req.memory_overcommit = 1.5
        req.image_datastores = set([ImageDatastore("ds3", True)])
        addr = ServerAddress(host="localhost", port=2345)
        req.chairman_server = [
            ServerAddress("h1", 13000),
            ServerAddress("h2", 13000)
        ]
        req.address = addr
        req.host_id = "host1"
        self.agent.update_config(req)

        assert_that(self.agent.availability_zone, equal_to("test1"))
        assert_that(self.agent.hostname, equal_to("localhost"))
        assert_that(self.agent.host_port, equal_to(2345))
        assert_that(self.agent.datastores, equal_to(["ds3", "ds4"]))
        assert_that(self.agent.networks, equal_to(["Public"]))
        assert_that(
            self.agent.chairman_list,
            equal_to([ServerAddress("h1", 13000),
                      ServerAddress("h2", 13000)]))
        assert_that(self.agent.memory_overcommit, equal_to(1.5))
        assert_that(self.agent.image_datastores, equal_to(expected_image_ds))
        assert_that(self.agent.host_id, equal_to("host1"))

        self.assertTrue(self.agent.bootstrap_ready)
        self.assertTrue(self.agent.reboot_required)

        # Verify we are able to update availability zone only.
        setZone = SetAvailabilityZoneRequest()
        setZone.availability_zone = "test2"

        self.agent.set_availability_zone(setZone)
        assert_that(self.agent.availability_zone, equal_to("test2"))
        assert_that(self.agent.hostname, equal_to("localhost"))
        assert_that(self.agent.host_port, equal_to(2345))
        assert_that(self.agent.datastores, equal_to(["ds3", "ds4"]))
        assert_that(self.agent.networks, equal_to(["Public"]))
        assert_that(
            self.agent.chairman_list,
            equal_to([ServerAddress("h1", 13000),
                      ServerAddress("h2", 13000)]))
        assert_that(self.agent.memory_overcommit, equal_to(1.5))
        assert_that(self.agent.image_datastores, equal_to(expected_image_ds))
        assert_that(self.agent.host_id, equal_to("host1"))

        self.assertTrue(self.agent.bootstrap_ready)
        self.assertTrue(self.agent.reboot_required)