def create(cls, options=None): """ Creates a new record using the arguments passed via dictionary. """ cls.command_sub = 'create' if options is None: options = {} if options['file'] is None: tmpl = 'file content is required for {0}.creation' raise CLIError(tmpl.format(cls.__name__)) if options['file'] == REPORT_TEMPLATE_FILE: local_path = get_data_file(REPORT_TEMPLATE_FILE) else: local_path = '' # --- create file at remote machine --- # (_, layout) = mkstemp(text=True) chmod(layout, 0o700) if not local_path: with open(layout, 'w') as rt: rt.write(options['file']) # End - Special handling of temporary file else: with open(local_path, 'r') as file: file_data = file.read() with open(layout, 'w') as rt: rt.write(file_data) ssh.upload_file(local_file=layout, remote_file=layout) # -------------------------------------- # options['file'] = layout result = cls.execute(cls._construct_command(options), output_format='csv') # Extract new object ID if it was successfully created if len(result) > 0 and 'id' in result[0]: obj_id = result[0]['id'] # Fetch new object # Some Katello obj require the organization-id for subcommands info_options = {'id': obj_id} if cls.command_requires_org: if 'organization-id' not in options: tmpl = 'organization-id option is required for {0}.create' raise CLIError(tmpl.format(cls.__name__)) info_options['organization-id'] = options['organization-id'] new_obj = cls.info(info_options) # stdout should be a dictionary containing the object if len(new_obj) > 0: result = new_obj return result
def create(cls, options=None): """Create a content-view filter rule""" if (not options or 'content-view-filter' not in options and 'content-view-filter-id' not in options): raise CLIError( 'Could not find content_view_filter, please set one of options' ' "content-view-filter" or "content-view-filter-id".') cls.command_sub = 'create' result = cls.execute(cls._construct_command(options), output_format='csv') # Extract new CV filter rule ID if it was successfully created if len(result) > 0 and 'id' in result[0]: cvfr_id = result[0]['id'] # CV filter rule can only be fetched by specifying either # content-view-filter-id or content-view-filter + content-view-id. # Passing these options to info command info_options = { 'content-view-id': options.get('content-view-id'), 'content-view-filter': options.get('content-view-filter'), 'content-view-filter-id': options.get('content-view-filter-id'), 'id': cvfr_id, } result = cls.info(info_options) return result
def create(cls, options=None): """ Creates a new record using the arguments passed via dictionary. """ cls.command_sub = 'create' if options is None: options = {} result = cls.execute(cls._construct_command(options), output_format='csv') # Extract new object ID if it was successfully created if len(result) > 0 and 'id' in result[0]: obj_id = result[0]['id'] # Fetch new object # Some Katello obj require the organization-id for subcommands info_options = {'id': obj_id, 'template-id': options['template-id']} if cls.command_requires_org: if 'organization-id' not in options: tmpl = 'organization-id option is required for {0}.create' raise CLIError(tmpl.format(cls.__name__)) info_options['organization-id'] = options['organization-id'] new_obj = cls.info(info_options) # stdout should be a dictionary containing the object if len(new_obj) > 0: result = new_obj return result
def test_error_msg_is_exposed(self): """Check if message error is exposed to assertRaisesRegex""" msg = 'organization-id option is required for Foo.create' with pytest.raises(CLIError, match=msg): raise CLIError(msg)