def hypervisor_search(self, context, host_name): """Search hypervisor with case sensitive hostname.""" nova = novaclient(context) msg = ("Call hypervisor search command to get list of matching " "host name '%(host_name)s'") LOG.info(msg, {'host_name': host_name}) try: hypervisors_list = nova.hypervisors.search(host_name) if host_name not in [host.hypervisor_hostname for host in hypervisors_list]: raise exception.HostNotFoundByName(host_name=host_name) except nova_exception.NotFound: raise exception.HostNotFoundByName(host_name=host_name)
def host_get_by_name(context, name): query = model_query(context, models.Host).filter_by(name=name).options( joinedload('failover_segment')) result = query.first() if not result: raise exception.HostNotFoundByName(host_name=name) return result
def test_create_host_not_found(self, mock_create): body = { "notification": { "hostname": "fake_host", "payload": { "instance_uuid": uuidsentinel.instance_uuid, "vir_domain_event": "STOPPED_FAILED", "event": "LIFECYCLE" }, "type": "VM", "generated_time": "2016-09-13T09:11:21.656788" } } mock_create.side_effect = exception.HostNotFoundByName( host_name="fake_host") self.assertRaises(exc.HTTPBadRequest, self.controller.create, self.req, body=body)
def test_create_host_not_found(self, mock_create): body = { "notification": { "hostname": "fake_host", "payload": { "event": "STOPPED", "host_status": "NORMAL", "cluster_status": "ONLINE" }, "type": "VM", "generated_time": "2016-09-13T09:11:21.656788" } } mock_create.side_effect = exception.HostNotFoundByName( host_name="fake_host") self.assertRaises(exc.HTTPBadRequest, self.controller.create, self.req, body=body)