def ensure_test_volume_is_absent(self, parsed_args, ctx): '''Ensure the test volume is absent''' if self.volume_exists(parsed_args.volume_name): raise common.ExitCritical( "Test volume {.volume_name} exists (but shouldn't)".format( parsed_args))
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): super(KeystoneCommand, self).take_action(parsed_args) try: self.keystone = keystoneclient.client.Client( parsed_args.os_identity_api_version, session=self.auth.sess) except keystoneauth1.exceptions.ClientException as exc: raise common.ExitCritical('Failed to authenticate: {}'.format(exc))
def take_action(self, parsed_args): super(CinderCommand, self).take_action(parsed_args) try: self.cinder = cinderclient.client.Client( parsed_args.os_volume_api_version, session=self.auth.sess) except cinderclient.exceptions.ClientException as exc: raise common.ExitCritical( 'Failed to create Cinder client: {}'.format(exc))
def take_action(self, parsed_args): super(GlanceCommand, self).take_action(parsed_args) try: self.glance = glanceclient.client.Client( parsed_args.os_image_api_version, session=self.auth.sess) except glanceclient.exc.ClientException as exc: raise common.ExitCritical( 'Failed to create Glance client: {}'.format(exc))
def __init__(self, parsed_args): try: cfg = (os_client_config.config.OpenStackConfig().get_one_cloud( argparse=parsed_args)) sess = cfg.get_session() except (keystoneauth1.exceptions.ClientException, os_client_config.exceptions.OpenStackConfigException) as exc: raise common.ExitCritical('Failed to authenticate: {}'.format(exc)) self.cfg = cfg self.sess = sess
def delete_test_volume(self, parsed_args, ctx): '''Delete test volume''' try: volume = self.get_volume(parsed_args.volume_name) volume.delete() self.wait_for_status(volume, 'deleted', timeout=parsed_args.volume_delete_timeout) except cinderclient.exceptions.NoUniqueMatch: raise common.ExitCritical( 'Multiple volumes named {.volume_name}, aborting'.format( parsed_args)) except cinderclient.exceptions.NotFound: pass
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 ensure_test_volume_exists(self, parsed_args, ctx): '''Ensure the test volume exists''' if not self.volume_exists(parsed_args.volume_name): raise common.ExitCritical('Test volume {.volume_name} is missing ' '(but should exist)'.format(parsed_args))