def take_action(self, parsed_args): '''Check if the Glance API is responding.''' super(CheckObjectExists, self).take_action(parsed_args) try: swift = swiftclient.client.Connection(session=self.auth.sess) with common.Timer() as t: with common.Timer() as t: container = swift.get_object( parsed_args.container_name, parsed_args.object_name) except swiftclient.exceptions.ClientException as exc: if exc.http_status == 404: msg = 'Object {} in container {} does not exist'.format( parsed_args.object_name, parsed_args.container_name) else: msg = 'Failed to retrieve object {} fromContainer container {}: {}'.format( parsed_args.object_name, parsed_args.container_name, exc), return (common.RET_CRIT, msg, t) msg = 'Found object {} in container {} with {} bytes'.format( parsed_args.object_name, parsed_args.container_name, container[0]['content-length']) return (common.RET_OKAY, msg, t)
def take_action(self, parsed_args): '''Check if the named server exists.''' super(CheckServerExists, self).take_action(parsed_args) try: nova = novaclient.client.Client( parsed_args.os_compute_api_version, session=self.auth.sess) try: with common.Timer() as t: server = nova.servers.get(parsed_args.server_name) except novaclient.exceptions.NotFound: with common.Timer() as t: server = nova.servers.find(name=parsed_args.server_name) except novaclient.exceptions.NoUniqueMatch: return (common.RET_WARN, 'Too many matches for server {}'.format( parsed_args.server_name), t) except novaclient.exceptions.ClientException as exc: return (common.RET_CRIT, 'Failed to locate server {}: {}'.format( parsed_args.server_name, exc), t) msg = 'Found server {} with id {}'.format( server.name, server.id) return (common.RET_OKAY, msg, t)
def take_action(self, parsed_args): '''Check if a service of the given type exists in the service catalog and if it reponds to HTTP requests.''' super(CheckServiceAlive, self).take_action(parsed_args) try: endpoint_url = self.get_endpoint( service_type=parsed_args.service_type, service_name=parsed_args.service_name) with common.Timer() as t: res = requests.get(endpoint_url) except keystoneauth1.exceptions.EndpointNotFound: return (common.RET_CRIT, 'Service {} does not exist'.format( parsed_args.service_type), t) except requests.exceptions.ConnectionError: raise common.ExitCritical( 'Cannot connect to service {} at {}'.format( parsed_args.service_type, endpoint_url)) msg = 'Received status {} from service {} at {}'.format( res.status_code, parsed_args.service_type, endpoint_url) exitcode = common.RET_OKAY if res.status_code in parsed_args.status_warning: exitcode = common.RET_WARN elif res.status_code not in parsed_args.status_okay: exitcode = common.RET_CRIT return (exitcode, msg, t)
def take_action(self, parsed_args): '''Check if the named Cinder volume exists.''' super(CheckVolumeExists, self).take_action(parsed_args) try: try: with common.Timer() as t: volume = self.cinder.volumes.get(parsed_args.volume_name) except cinderclient.exceptions.NotFound: with common.Timer() as t: volume = self.cinder.volumes.find( name=parsed_args.volume_name) except cinderclient.exceptions.NoUniqueMatch: return (common.RET_WARN, 'Too many matches for name {}'.format( parsed_args.volume_name), t) except cinderclient.exceptions.ClientException as exc: return (common.RET_CRIT, 'Failed to list volumes: {}'.format(exc), t) msg = 'Found volume {} with id {}'.format(volume.name, volume.id) return (common.RET_OKAY, msg, t)
def take_action(self, parsed_args): '''Check if the Cinder API is responding.''' super(CheckAPI, self).take_action(parsed_args) try: with common.Timer() as t: volumes = self.cinder.volumes.list(limit=parsed_args.limit) except cinderclient.exceptions.ClientException as exc: return (common.RET_CRIT, 'Failed to list volumes: {}'.format(exc), t) msg = 'Found {} volumes'.format(len(volumes)) return (common.RET_OKAY, msg, t)
def take_action(self, parsed_args): '''Check if the Glance API is responding.''' super(CheckAPI, self).take_action(parsed_args) try: with common.Timer() as t: images = list(self.glance.images.list(limit=parsed_args.limit)) except glanceclient.exc.ClientException as exc: return (common.RET_CRIT, 'Failed to list images: {}'.format(exc), t) msg = 'Found {} images'.format(len(images)) return (common.RET_OKAY, msg, t)
def take_action(self, parsed_args): '''Check if the named flavor exists.''' super(CheckFlavorExists, self).take_action(parsed_args) try: nova = novaclient.client.Client( parsed_args.os_compute_api_version, session=self.auth.sess) try: with common.Timer() as t: flavor = nova.flavors.get(parsed_args.flavor_name) except novaclient.exceptions.NotFound: with common.Timer() as t: flavor = nova.flavors.find(name=parsed_args.flavor_name) except novaclient.exceptions.ClientException as exc: return (common.RET_CRIT, 'Failed to list servers: {}'.format(exc), t) msg = 'Found flavor {} with id {}'.format( flavor.name, flavor.id) return (common.RET_OKAY, msg, t)
def take_action(self, parsed_args): '''Check if the named image exists.''' super(CheckImageExists, self).take_action(parsed_args) try: try: with common.Timer() as t: image = self.glance.images.get(parsed_args.image_name) except glanceclient.exc.NotFound: with common.Timer() as t: images = [ image for image in self.glance.images.list() if image.name == parsed_args.image_name ] if not images: raise glanceclient.exc.NotFound(parsed_args.image_name) if len(images) > 1: raise NonUniqueMatch() image = images[0] except NonUniqueMatch: return (common.RET_WARN, 'Too many matches for image name {}'.format( parsed_args.image_name), t) except glanceclient.exc.NotFound as exc: return (common.RET_CRIT, 'Image named {} does not exist.'.format( parsed_args.image_name), t) except glanceclient.exc.ClientException as exc: return (common.RET_CRIT, 'Failed to list images: {}'.format(exc), t) msg = 'Found image {} with id {}'.format(image.name, image.id) return (common.RET_OKAY, msg, t)
def take_action(self, parsed_args): '''Check if Nova API is responding.''' super(CheckAPI, self).take_action(parsed_args) try: nova = novaclient.client.Client( parsed_args.os_compute_api_version, session=self.auth.sess) with common.Timer() as t: servers = nova.servers.list(limit=parsed_args.limit) except novaclient.exceptions.ClientException as exc: return (common.RET_CRIT, 'Failed to list servers: {}'.format(exc), t) msg = 'Found {} servers'.format(len(servers)) return (common.RET_OKAY, msg, t)
def take_action(self, parsed_args): '''Check if a service of the given type exists in the service catalog.''' super(CheckServiceExists, self).take_action(parsed_args) try: with common.Timer() as t: endpoint_url = self.get_endpoint( service_type=parsed_args.service_type, service_name=parsed_args.service_name) except keystoneauth1.exceptions.EndpointNotFound: return (common.RET_CRIT, 'Service {} does not exist'.format( parsed_args.service_type), t) msg = 'Service {} exists at {}'.format(parsed_args.service_type, endpoint_url) return (common.RET_OKAY, msg, t)
def take_action(self, parsed_args): '''Check if the Glance API is responding.''' super(CheckAPI, self).take_action(parsed_args) try: swift = swiftclient.client.Connection(session=self.auth.sess) with common.Timer() as t: # XXX: It looks like swiftclient ignores the limit # parameter. containers = swift.get_account( limit=parsed_args.limit) except swiftclient.exceptions.ClientException as exc: return (common.RET_CRIT, 'Failed to list containers: {}'.format(exc), t) msg = 'Found {} containers'.format(len(containers)) return (common.RET_OKAY, msg, t)
def take_action(self, parsed_args): '''Check if the named Cinder volume exists.''' super(CheckVolumeCreateDelete, self).take_action(parsed_args) test_plan = ( self.delete_old_test_volume, self.ensure_test_volume_is_absent, self.create_test_volume, self.ensure_test_volume_exists, self.delete_test_volume, self.ensure_test_volume_is_absent, ) with common.Timer() as t: try: ctx = lambda: None ctx.volume_created = False for step in test_plan: self.log.info('running step: {}'.format(step.__doc__)) step(parsed_args, ctx) except cinderclient.exceptions.ClientException as exc: raise common.ExitCritical('{} failed: {}'.format( step.__doc__, exc)) except common.TimeoutError: raise common.ExitCritical('{} timed out'.format(step.__doc__)) finally: try: if ctx.volume_created: self.delete_test_volume(parsed_args, ctx) except cinderclient.exceptions.ClientException as exc: raise common.ExitCritical( 'Failed to delete test volume: {}'.format(exc)) msg = 'Successfully created and deleted volume {.volume_name}'.format( parsed_args) return (common.RET_OKAY, msg, t)
def wait_for_status(self, volume, status, timeout=None): with common.Timer(timeout=timeout) as t: while self.volume_status(volume) != status: time.sleep(1) t.tick()