Ejemplo n.º 1
0
 def get_by_host_and_nodename(cls, context, host, nodename):
     try:
         db_compute = db.compute_node_get_by_host_and_nodename(
             context, host, nodename)
     except exception.ComputeHostNotFound:
         # FIXME(sbauza): Some old computes can still have no host record
         # We need to provide compatibility by using the old service_id
         # record.
         # We assume the compatibility as an extra penalty of one more DB
         # call but that's necessary until all nodes are upgraded.
         try:
             service = objects.Service.get_by_compute_host(context, host)
             db_computes = db.compute_nodes_get_by_service_id(
                 context, service.id)
         except exception.ServiceNotFound:
             # We need to provide the same exception upstream
             raise exception.ComputeHostNotFound(host=host)
         db_compute = None
         for compute in db_computes:
             if compute['hypervisor_hostname'] == nodename:
                 db_compute = compute
                 # We can avoid an extra call to Service object in
                 # _from_db_object
                 db_compute['host'] = service.host
                 break
         if not db_compute:
             raise exception.ComputeHostNotFound(host=host)
     return cls._from_db_object(context, cls(), db_compute)
Ejemplo n.º 2
0
    def test_get_first_node_by_host_for_old_compat_not_found(
            self, cn_get_all_by_host):
        cn_get_all_by_host.side_effect = exception.ComputeHostNotFound(
            host='fake')

        self.assertRaises(
            exception.ComputeHostNotFound,
            compute_node.ComputeNode.get_first_node_by_host_for_old_compat,
            self.context, 'fake')
Ejemplo n.º 3
0
def stub_host_power_action(context, host_name, action):
    if host_name == "notimplemented":
        raise NotImplementedError()
    elif host_name == "dummydest":
        # The host does not exist
        raise exception.ComputeHostNotFound(host=host_name)
    elif host_name == "service_not_available":
        # The service is not available
        raise exception.ComputeServiceUnavailable(host=host_name)
    return action
Ejemplo n.º 4
0
    def test_get_by_host_and_nodename_not_found(self, cn_get_by_h_and_n,
                                                svc_get_by_ch,
                                                cn_get_by_svc_id,
                                                svc_get_by_id):
        cn_get_by_h_and_n.side_effect = exception.ComputeHostNotFound(
            host='fake')
        fake_service = service.Service(id=123)
        fake_service.host = 'fake'
        another_node = fake_old_compute_node.copy()
        another_node['hypervisor_hostname'] = 'elsewhere'
        svc_get_by_ch.return_value = fake_service
        cn_get_by_svc_id.return_value = [another_node]
        svc_get_by_id.return_value = fake_service

        self.assertRaises(exception.ComputeHostNotFound,
                          compute_node.ComputeNode.get_by_host_and_nodename,
                          self.context, 'fake', 'vm.danplanet.com')
Ejemplo n.º 5
0
    def test_get_all_by_host_with_old_compute(self, cn_get_all_by_host,
                                              svc_get_by_ch, cn_get_by_svc_id,
                                              svc_get_by_id):
        cn_get_all_by_host.side_effect = exception.ComputeHostNotFound(
            host='fake')
        fake_service = service.Service(id=123)
        fake_service.host = 'fake'
        svc_get_by_ch.return_value = fake_service
        cn_get_by_svc_id.return_value = [fake_old_compute_node]
        svc_get_by_id.return_value = fake_service

        computes = compute_node.ComputeNodeList.get_all_by_host(
            self.context, 'fake')
        self.assertEqual(1, len(computes))
        # NOTE(sbauza): Result is still converted to new style Compute
        self.compare_obj(computes[0],
                         fake_compute_node,
                         subs=self.subs(),
                         comparators=self.comparators())
Ejemplo n.º 6
0
    def test_get_by_host_and_nodename_with_old_compute(self, cn_get_by_h_and_n,
                                                       svc_get_by_ch,
                                                       cn_get_by_svc_id,
                                                       svc_get_by_id):
        cn_get_by_h_and_n.side_effect = exception.ComputeHostNotFound(
            host='fake')
        fake_service = service.Service(id=123)
        fake_service.host = 'fake'
        svc_get_by_ch.return_value = fake_service
        cn_get_by_svc_id.return_value = [fake_old_compute_node]
        svc_get_by_id.return_value = fake_service

        compute = compute_node.ComputeNode.get_by_host_and_nodename(
            self.context, 'fake', 'vm.danplanet.com')
        # NOTE(sbauza): Result is still converted to new style Compute
        self.compare_obj(compute,
                         fake_compute_node,
                         subs=self.subs(),
                         comparators=self.comparators())
Ejemplo n.º 7
0
def stub_set_host_maintenance(context, host_name, mode):
    # We'll simulate success and failure by assuming
    # that 'host_c1' always succeeds, and 'host_c2'
    # always fails
    results = {True: "on_maintenance", False: "off_maintenance"}
    if host_name == "notimplemented":
        # The vm driver for this host doesn't support this feature
        raise NotImplementedError()
    elif host_name == "dummydest":
        # The host does not exist
        raise exception.ComputeHostNotFound(host=host_name)
    elif host_name == "service_not_available":
        # The service is not available
        raise exception.ComputeServiceUnavailable(host=host_name)
    elif host_name == "host_c2":
        # Simulate a failure
        return results[not mode]
    else:
        # Do the right thing
        return results[mode]
Ejemplo n.º 8
0
def stub_set_host_enabled(context, host_name, enabled):
    """Simulates three possible behaviours for VM drivers or compute
    drivers when enabling or disabling a host.

    'enabled' means new instances can go to this host
    'disabled' means they can't
    """
    results = {True: "enabled", False: "disabled"}
    if host_name == "notimplemented":
        # The vm driver for this host doesn't support this feature
        raise NotImplementedError()
    elif host_name == "dummydest":
        # The host does not exist
        raise exception.ComputeHostNotFound(host=host_name)
    elif host_name == "service_not_available":
        # The service is not available
        raise exception.ComputeServiceUnavailable(host=host_name)
    elif host_name == "host_c2":
        # Simulate a failure
        return results[not enabled]
    else:
        # Do the right thing
        return results[enabled]
Ejemplo n.º 9
0
 def get_all_by_host(cls, context, host, use_slave=False):
     try:
         db_computes = db.compute_node_get_all_by_host(
             context, host, use_slave)
     except exception.ComputeHostNotFound:
         # FIXME(sbauza): Some old computes can still have no host record
         # We need to provide compatibility by using the old service_id
         # record.
         # We assume the compatibility as an extra penalty of one more DB
         # call but that's necessary until all nodes are upgraded.
         try:
             service = objects.Service.get_by_compute_host(
                 context, host, use_slave)
             db_computes = db.compute_nodes_get_by_service_id(
                 context, service.id)
         except exception.ServiceNotFound:
             # We need to provide the same exception upstream
             raise exception.ComputeHostNotFound(host=host)
         # We can avoid an extra call to Service object in _from_db_object
         for db_compute in db_computes:
             db_compute['host'] = service.host
     return base.obj_make_list(context, cls(context), objects.ComputeNode,
                               db_computes)
Ejemplo n.º 10
0
def fake_compute_node_get(context, compute_id):
    for hyper in test_hypervisors.TEST_HYPERS_OBJ:
        if hyper.id == int(compute_id):
            return hyper
    raise exception.ComputeHostNotFound(host=compute_id)
Ejemplo n.º 11
0
 def stub_remove_host_from_aggregate(context, aggregate, host):
     raise exception.ComputeHostNotFound(host=host)
Ejemplo n.º 12
0
 def stub_add_host_to_aggregate(context, aggregate, host):
     raise exception.ComputeHostNotFound(host=host)
Ejemplo n.º 13
0
def fake_service_get_by_compute_host(self, context, host):
    if host == 'bad-host':
        raise exception.ComputeHostNotFound(host=host)
    else:
        return {'host_name': host, 'service': 'compute', 'zone': 'patron'}