def test_annotated_cloudconfig_file_schema_annotates_and_adds_footer(self): """With schema_errors, error lines are annotated and a footer added.""" content = dedent("""\ #cloud-config # comment ntp: pools: [-99, 75] """).encode() expected = dedent("""\ #cloud-config # comment ntp: # E1 pools: [-99, 75] # E2,E3 # Errors: ------------- # E1: Some type error # E2: -99 is not a string # E3: 75 is not a string """) parsed_config = safe_load(content[13:]) schema_errors = [ ('ntp', 'Some type error'), ('ntp.pools.0', '-99 is not a string'), ('ntp.pools.1', '75 is not a string')] self.assertEqual( expected, annotated_cloudconfig_file(parsed_config, content, schema_errors))
def test_annotated_cloudconfig_file_schema_annotates_and_adds_footer(self): """With schema_errors, error lines are annotated and a footer added.""" content = dedent("""\ #cloud-config # comment ntp: pools: [-99, 75] """).encode() expected = dedent("""\ #cloud-config # comment ntp: # E1 pools: [-99, 75] # E2,E3 # Errors: ------------- # E1: Some type error # E2: -99 is not a string # E3: 75 is not a string """) parsed_config, schemamarks = load_with_marks(content[13:]) schema_errors = [ ("ntp", "Some type error"), ("ntp.pools.0", "-99 is not a string"), ("ntp.pools.1", "75 is not a string"), ] assert expected == annotated_cloudconfig_file(parsed_config, content, schema_errors, schemamarks=schemamarks)
def test_annotated_cloudconfig_file_annotates_separate_line_items(self): """Errors are annotated for lists with items on separate lines.""" content = dedent("""\ #cloud-config # comment ntp: pools: - -99 - 75 """).encode() expected = dedent("""\ ntp: pools: - -99 # E1 - 75 # E2 """) parsed_config, schemamarks = load_with_marks(content[13:]) schema_errors = [ ("ntp.pools.0", "-99 is not a string"), ("ntp.pools.1", "75 is not a string"), ] assert expected in annotated_cloudconfig_file(parsed_config, content, schema_errors, schemamarks=schemamarks)
def test_annotated_cloudconfig_file_no_schema_errors(self): """With no schema_errors, print the original content.""" content = b"ntp:\n pools: [ntp1.pools.com]\n" parse_cfg, schemamarks = load_with_marks(content) assert content == annotated_cloudconfig_file(parse_cfg, content, schema_errors=[], schemamarks=schemamarks)
def test_annotated_cloudconfig_file_with_non_dict_cloud_config(self): """Error when empty non-dict cloud-config is provided. OurJSON validation when user-data is None type generates a bunch schema validation errors of the format: ('', "None is not of type 'object'"). Ignore those symptoms and report the general problem instead. """ content = b"\n\n\n" expected = "\n".join([ content.decode(), "# Errors: -------------", "# E1: Cloud-config is not a YAML dict.\n\n", ]) assert expected == annotated_cloudconfig_file( None, content, schema_errors=[("", "None is not of type 'object'")], schemamarks={}, )
def test_annotated_cloudconfig_file_annotates_separate_line_items(self): """Errors are annotated for lists with items on separate lines.""" content = dedent("""\ #cloud-config # comment ntp: pools: - -99 - 75 """).encode() expected = dedent("""\ ntp: pools: - -99 # E1 - 75 # E2 """) parsed_config = safe_load(content[13:]) schema_errors = [('ntp.pools.0', '-99 is not a string'), ('ntp.pools.1', '75 is not a string')] self.assertIn( expected, annotated_cloudconfig_file(parsed_config, content, schema_errors))
def test_annotated_cloudconfig_file_annotates_separate_line_items(self): """Errors are annotated for lists with items on separate lines.""" content = dedent("""\ #cloud-config # comment ntp: pools: - -99 - 75 """).encode() expected = dedent("""\ ntp: pools: - -99 # E1 - 75 # E2 """) parsed_config = safe_load(content[13:]) schema_errors = [ ('ntp.pools.0', '-99 is not a string'), ('ntp.pools.1', '75 is not a string')] self.assertIn( expected, annotated_cloudconfig_file(parsed_config, content, schema_errors))
def test_annotated_cloudconfig_file_no_schema_errors(self): """With no schema_errors, print the original content.""" content = b"ntp:\n pools: [ntp1.pools.com]\n" self.assertEqual( content, annotated_cloudconfig_file({}, content, schema_errors=[]))
def test_annotated_cloudconfig_file_no_schema_errors(self): """With no schema_errors, print the original content.""" content = b'ntp:\n pools: [ntp1.pools.com]\n' self.assertEqual( content, annotated_cloudconfig_file({}, content, schema_errors=[]))